2009-06-01 09:55:11 +00:00
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2009-04-25
|
2010-01-01 20:11:34 +00:00
|
|
|
# Copyright 2010 Hardcoded Software (http://www.hardcoded.net)
|
2009-08-05 08:59:46 +00:00
|
|
|
#
|
2010-09-30 10:17:41 +00:00
|
|
|
# This software is licensed under the "BSD" License as described in the "LICENSE" file,
|
2009-08-05 08:59:46 +00:00
|
|
|
# which should be included with this package. The terms are also available at
|
2010-09-30 10:17:41 +00:00
|
|
|
# http://www.hardcoded.net/licenses/bsd_license
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
import logging
|
2009-10-13 14:59:19 +00:00
|
|
|
import os
|
2009-06-01 09:55:11 +00:00
|
|
|
import os.path as op
|
|
|
|
|
2011-01-15 15:29:35 +00:00
|
|
|
from PyQt4.QtCore import QTimer, QObject, QCoreApplication, QUrl, QProcess, SIGNAL, pyqtSignal
|
|
|
|
from PyQt4.QtGui import QDesktopServices, QFileDialog, QDialog, QMessageBox, QApplication
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2010-11-20 11:42:15 +00:00
|
|
|
from jobprogress import job
|
|
|
|
from jobprogress.qt import Progress
|
2011-01-21 12:57:54 +00:00
|
|
|
from hscommon.trans import tr, trmsg
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2009-12-30 10:37:57 +00:00
|
|
|
from core.app import DupeGuru as DupeGuruBase, JOB_SCAN, JOB_LOAD, JOB_MOVE, JOB_COPY, JOB_DELETE
|
2011-01-21 12:57:54 +00:00
|
|
|
|
2009-10-30 11:41:14 +00:00
|
|
|
from qtlib.about_box import AboutBox
|
2011-01-15 15:29:35 +00:00
|
|
|
from qtlib.recent import Recent
|
2009-10-30 11:41:14 +00:00
|
|
|
from qtlib.reg import Registration
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2009-09-27 08:44:06 +00:00
|
|
|
from . import platform
|
2011-01-15 15:29:35 +00:00
|
|
|
from .result_window import ResultWindow
|
2009-09-27 08:44:06 +00:00
|
|
|
from .directories_dialog import DirectoriesDialog
|
2010-04-12 13:29:56 +00:00
|
|
|
from .problem_dialog import ProblemDialog
|
2011-01-15 15:29:35 +00:00
|
|
|
from .util import createActions
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
JOBID2TITLE = {
|
2011-01-21 12:57:54 +00:00
|
|
|
JOB_SCAN: tr("Scanning for duplicates"),
|
|
|
|
JOB_LOAD: tr("Loading"),
|
|
|
|
JOB_MOVE: tr("Moving"),
|
|
|
|
JOB_COPY: tr("Copying"),
|
|
|
|
JOB_DELETE: tr("Sending files to the recycle bin"),
|
2009-06-01 09:55:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class DupeGuru(DupeGuruBase, QObject):
|
|
|
|
LOGO_NAME = '<replace this>'
|
|
|
|
NAME = '<replace this>'
|
|
|
|
DELTA_COLUMNS = frozenset()
|
|
|
|
|
2010-09-29 14:49:50 +00:00
|
|
|
def __init__(self, data_module):
|
2010-08-11 14:39:06 +00:00
|
|
|
appdata = str(QDesktopServices.storageLocation(QDesktopServices.DataLocation))
|
2009-10-13 14:59:19 +00:00
|
|
|
if not op.exists(appdata):
|
|
|
|
os.makedirs(appdata)
|
2009-10-02 11:12:25 +00:00
|
|
|
# For basicConfig() to work, we have to be sure that no logging has taken place before this call.
|
|
|
|
logging.basicConfig(filename=op.join(appdata, 'debug.log'), level=logging.WARNING)
|
2010-09-29 14:49:50 +00:00
|
|
|
DupeGuruBase.__init__(self, data_module, appdata)
|
2009-06-01 09:55:11 +00:00
|
|
|
QObject.__init__(self)
|
|
|
|
self._setup()
|
|
|
|
|
|
|
|
#--- Private
|
|
|
|
def _setup(self):
|
2011-01-15 15:29:35 +00:00
|
|
|
self._setupActions()
|
2009-06-01 09:55:11 +00:00
|
|
|
self.prefs = self._create_preferences()
|
|
|
|
self.prefs.load()
|
|
|
|
self._update_options()
|
2011-01-17 16:15:16 +00:00
|
|
|
self.recentResults = Recent(self, 'recentResults')
|
|
|
|
self.recentResults.mustOpenItem.connect(self.load_from)
|
2011-01-15 15:29:35 +00:00
|
|
|
self.resultWindow = self._create_result_window()
|
|
|
|
self._progress = Progress(self.resultWindow)
|
|
|
|
self.directories_dialog = DirectoriesDialog(self.resultWindow, self)
|
|
|
|
self.details_dialog = self._create_details_dialog(self.resultWindow)
|
|
|
|
self.problemDialog = ProblemDialog(parent=self.resultWindow, app=self)
|
|
|
|
self.preferences_dialog = self._create_preferences_dialog(self.resultWindow)
|
|
|
|
self.about_box = AboutBox(self.resultWindow, self)
|
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
self.reg = Registration(self)
|
|
|
|
self.set_registration(self.prefs.registration_code, self.prefs.registration_email)
|
2010-09-29 14:49:50 +00:00
|
|
|
if not self.registered and self.unpaid_hours >= 1:
|
2009-10-01 09:45:49 +00:00
|
|
|
# The timer scheme is because if the nag is not shown before the application is
|
|
|
|
# completely initialized, the nag will be shown before the app shows up in the task bar
|
|
|
|
# In some circumstances, the nag is hidden by other window, which may make the user think
|
|
|
|
# that the application haven't launched.
|
2010-10-05 06:44:32 +00:00
|
|
|
QTimer.singleShot(0, self.reg.show_nag)
|
2011-01-15 15:29:35 +00:00
|
|
|
self.directories_dialog.show()
|
2009-06-01 09:55:11 +00:00
|
|
|
self.load()
|
|
|
|
|
|
|
|
self.connect(QCoreApplication.instance(), SIGNAL('aboutToQuit()'), self.application_will_terminate)
|
|
|
|
self.connect(self._progress, SIGNAL('finished(QString)'), self.job_finished)
|
|
|
|
|
2011-01-15 15:29:35 +00:00
|
|
|
def _setupActions(self):
|
|
|
|
# Setup actions that are common to both the directory dialog and the results window.
|
|
|
|
# (name, shortcut, icon, desc, func)
|
|
|
|
ACTIONS = [
|
2011-01-21 12:57:54 +00:00
|
|
|
('actionQuit', 'Ctrl+Q', '', tr("Quit"), self.quitTriggered),
|
|
|
|
('actionPreferences', 'Ctrl+P', '', tr("Preferences"), self.preferencesTriggered),
|
|
|
|
('actionShowHelp', 'F1', '', tr("dupeGuru Help"), self.showHelpTriggered),
|
|
|
|
('actionAbout', '', '', tr("About dupeGuru"), self.showAboutBoxTriggered),
|
|
|
|
('actionRegister', '', '', tr("Register dupeGuru"), self.registerTriggered),
|
|
|
|
('actionCheckForUpdate', '', '', tr("Check for Update"), self.checkForUpdateTriggered),
|
|
|
|
('actionOpenDebugLog', '', '', tr("Open Debug Log"), self.openDebugLogTriggered),
|
2011-01-15 15:29:35 +00:00
|
|
|
]
|
|
|
|
createActions(ACTIONS, self)
|
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
def _setup_as_registered(self):
|
|
|
|
self.prefs.registration_code = self.registration_code
|
|
|
|
self.prefs.registration_email = self.registration_email
|
2011-01-15 15:29:35 +00:00
|
|
|
self.actionRegister.setVisible(False)
|
2009-06-01 09:55:11 +00:00
|
|
|
self.about_box.registerButton.hide()
|
|
|
|
self.about_box.registeredEmailLabel.setText(self.prefs.registration_email)
|
|
|
|
|
|
|
|
def _update_options(self):
|
|
|
|
self.scanner.mix_file_kind = self.prefs.mix_file_kind
|
|
|
|
self.options['escape_filter_regexp'] = self.prefs.use_regexp
|
|
|
|
self.options['clean_empty_dirs'] = self.prefs.remove_empty_folders
|
2010-09-25 10:28:34 +00:00
|
|
|
self.options['ignore_hardlink_matches'] = self.prefs.ignore_hardlink_matches
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
#--- Virtual
|
|
|
|
def _create_details_dialog(self, parent):
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
2011-01-15 15:29:35 +00:00
|
|
|
def _create_result_window(self):
|
|
|
|
return ResultWindow(app=self)
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
def _create_preferences(self):
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
def _create_preferences_dialog(self, parent):
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
#--- Override
|
2010-02-06 11:36:43 +00:00
|
|
|
@staticmethod
|
|
|
|
def _open_path(path):
|
2010-08-11 14:39:06 +00:00
|
|
|
url = QUrl.fromLocalFile(str(path))
|
2010-02-06 11:36:43 +00:00
|
|
|
QDesktopServices.openUrl(url)
|
|
|
|
|
2010-02-06 14:31:35 +00:00
|
|
|
@staticmethod
|
|
|
|
def _reveal_path(path):
|
2010-02-09 14:24:57 +00:00
|
|
|
DupeGuru._open_path(path[:-1])
|
2010-02-06 14:31:35 +00:00
|
|
|
|
2010-09-25 13:37:18 +00:00
|
|
|
def _start_job(self, jobid, func, *args):
|
2009-06-01 09:55:11 +00:00
|
|
|
title = JOBID2TITLE[jobid]
|
|
|
|
try:
|
|
|
|
j = self._progress.create_job()
|
2010-09-25 13:37:18 +00:00
|
|
|
args = tuple([j] + list(args))
|
|
|
|
self._progress.run(jobid, title, func, args=args)
|
2009-06-01 09:55:11 +00:00
|
|
|
except job.JobInProgressError:
|
2011-01-21 12:57:54 +00:00
|
|
|
msg = trmsg("TaskHangingMsg")
|
2011-01-15 15:29:35 +00:00
|
|
|
QMessageBox.information(self.resultWindow, 'Action in progress', msg)
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2010-02-06 11:12:20 +00:00
|
|
|
def add_selected_to_ignore_list(self):
|
|
|
|
dupes = self.without_ref(self.selected_dupes)
|
|
|
|
if not dupes:
|
|
|
|
return
|
2011-01-21 12:57:54 +00:00
|
|
|
title = tr("Add to Ignore List")
|
|
|
|
msg = trmsg("IgnoreConfirmMsg").format(len(dupes))
|
2011-01-15 15:29:35 +00:00
|
|
|
if self.confirm(title, msg):
|
2010-02-06 11:12:20 +00:00
|
|
|
DupeGuruBase.add_selected_to_ignore_list(self)
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
def copy_or_move_marked(self, copy):
|
2011-01-21 12:57:54 +00:00
|
|
|
opname = tr("copy") if copy else tr("move")
|
|
|
|
title = trmsg("SelectCopyOrMoveDestinationMsg").format(opname)
|
2009-06-01 09:55:11 +00:00
|
|
|
flags = QFileDialog.ShowDirsOnly
|
2011-01-15 15:29:35 +00:00
|
|
|
destination = str(QFileDialog.getExistingDirectory(self.resultWindow, title, '', flags))
|
2009-06-01 09:55:11 +00:00
|
|
|
if not destination:
|
|
|
|
return
|
|
|
|
recreate_path = self.prefs.destination_type
|
|
|
|
DupeGuruBase.copy_or_move_marked(self, copy, destination, recreate_path)
|
|
|
|
|
2010-02-06 11:44:21 +00:00
|
|
|
def remove_selected(self):
|
|
|
|
dupes = self.without_ref(self.selected_dupes)
|
|
|
|
if not dupes:
|
|
|
|
return
|
2011-01-21 12:57:54 +00:00
|
|
|
title = tr("Remove duplicates")
|
|
|
|
msg = trmsg("FileRemovalConfirmMsg").format(len(dupes))
|
2011-01-15 15:29:35 +00:00
|
|
|
if self.confirm(title, msg):
|
2010-02-06 11:44:21 +00:00
|
|
|
DupeGuruBase.remove_selected(self)
|
|
|
|
|
2010-02-06 11:12:20 +00:00
|
|
|
#--- Public
|
|
|
|
def askForRegCode(self):
|
|
|
|
self.reg.ask_for_code()
|
|
|
|
|
2011-01-15 15:29:35 +00:00
|
|
|
def confirm(self, title, msg, default_button=QMessageBox.Yes):
|
|
|
|
active = QApplication.activeWindow()
|
|
|
|
buttons = QMessageBox.Yes | QMessageBox.No
|
|
|
|
answer = QMessageBox.question(active, title, msg, buttons, default_button)
|
|
|
|
return answer == QMessageBox.Yes
|
|
|
|
|
2010-04-13 08:02:09 +00:00
|
|
|
def invokeCustomCommand(self):
|
|
|
|
cmd = self.prefs.custom_command
|
|
|
|
if cmd:
|
|
|
|
self.invoke_command(cmd)
|
|
|
|
else:
|
2011-01-21 12:57:54 +00:00
|
|
|
msg = trmsg("NoCustomCommandMsg")
|
|
|
|
QMessageBox.warning(self.resultWindow, tr("Custom Command"), msg)
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
def show_details(self):
|
|
|
|
self.details_dialog.show()
|
|
|
|
|
2011-01-15 15:29:35 +00:00
|
|
|
def showResultsWindow(self):
|
|
|
|
self.resultWindow.show()
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2010-08-15 10:27:15 +00:00
|
|
|
#--- Signals
|
|
|
|
willSavePrefs = pyqtSignal()
|
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
#--- Events
|
|
|
|
def application_will_terminate(self):
|
2010-08-15 10:27:15 +00:00
|
|
|
self.willSavePrefs.emit()
|
|
|
|
self.prefs.save()
|
2009-06-07 07:18:59 +00:00
|
|
|
self.save()
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2011-01-15 15:29:35 +00:00
|
|
|
def checkForUpdateTriggered(self):
|
|
|
|
QProcess.execute('updater.exe', ['/checknow'])
|
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
def job_finished(self, jobid):
|
2010-02-12 14:39:29 +00:00
|
|
|
self._job_completed(jobid)
|
2010-04-12 13:29:56 +00:00
|
|
|
if jobid in (JOB_MOVE, JOB_COPY, JOB_DELETE):
|
|
|
|
if self.results.problems:
|
|
|
|
self.problemDialog.show()
|
|
|
|
else:
|
2011-01-21 12:57:54 +00:00
|
|
|
msg = trmsg("OperationSuccessMsg")
|
|
|
|
QMessageBox.information(self.resultWindow, tr("Operation Complete"), msg)
|
2010-01-13 09:39:27 +00:00
|
|
|
elif jobid == JOB_SCAN:
|
|
|
|
if not self.results.groups:
|
2011-01-21 12:57:54 +00:00
|
|
|
title = tr("Scan complete")
|
|
|
|
msg = trmsg("NoDuplicateFoundMsg")
|
2011-01-15 15:29:35 +00:00
|
|
|
QMessageBox.information(self.resultWindow, title, msg)
|
|
|
|
else:
|
|
|
|
self.showResultsWindow()
|
|
|
|
elif jobid == JOB_LOAD:
|
|
|
|
self.showResultsWindow()
|
|
|
|
|
|
|
|
def openDebugLogTriggered(self):
|
|
|
|
debugLogPath = op.join(self.appdata, 'debug.log')
|
|
|
|
self._open_path(debugLogPath)
|
|
|
|
|
|
|
|
def preferencesTriggered(self):
|
|
|
|
self.preferences_dialog.load()
|
|
|
|
result = self.preferences_dialog.exec_()
|
|
|
|
if result == QDialog.Accepted:
|
|
|
|
self.preferences_dialog.save()
|
|
|
|
self.prefs.save()
|
|
|
|
self._update_options()
|
|
|
|
|
|
|
|
def quitTriggered(self):
|
|
|
|
self.directories_dialog.close()
|
|
|
|
|
|
|
|
def registerTriggered(self):
|
|
|
|
self.reg.ask_for_code()
|
|
|
|
|
|
|
|
def showAboutBoxTriggered(self):
|
|
|
|
self.about_box.show()
|
|
|
|
|
|
|
|
def showHelpTriggered(self):
|
|
|
|
base_path = platform.HELP_PATH.format(self.EDITION)
|
|
|
|
url = QUrl.fromLocalFile(op.abspath(op.join(base_path, 'index.html')))
|
|
|
|
QDesktopServices.openUrl(url)
|
2009-06-01 09:55:11 +00:00
|
|
|
|