2009-06-01 09:55:11 +00:00
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2009-04-25
|
2015-01-03 21:30:57 +00:00
|
|
|
# Copyright 2015 Hardcoded Software (http://www.hardcoded.net)
|
2014-10-13 19:08:59 +00:00
|
|
|
#
|
2015-01-03 21:33:16 +00:00
|
|
|
# This software is licensed under the "GPLv3" License as described in the "LICENSE" file,
|
2014-10-13 19:08:59 +00:00
|
|
|
# which should be included with this package. The terms are also available at
|
2015-01-03 21:33:16 +00:00
|
|
|
# http://www.gnu.org/licenses/gpl-3.0.html
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2011-01-23 15:09:47 +00:00
|
|
|
import sys
|
2009-06-01 09:55:11 +00:00
|
|
|
import os.path as op
|
|
|
|
|
2014-04-19 22:21:56 +00:00
|
|
|
from PyQt5.QtCore import QTimer, QObject, QCoreApplication, QUrl, pyqtSignal
|
2013-10-20 19:15:09 +00:00
|
|
|
from PyQt5.QtGui import QDesktopServices
|
|
|
|
from PyQt5.QtWidgets import QApplication, QFileDialog, QDialog, QMessageBox
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2011-11-01 19:44:18 +00:00
|
|
|
from hscommon.trans import trget
|
2013-10-12 17:54:13 +00:00
|
|
|
from hscommon import desktop
|
2009-06-01 09:55:11 +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
|
2013-10-12 17:54:13 +00:00
|
|
|
from qtlib.util import createActions
|
2014-10-13 19:08:59 +00:00
|
|
|
from qtlib.progress_window import ProgressWindow
|
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
|
2012-03-14 16:47:21 +00:00
|
|
|
from .ignore_list_dialog import IgnoreListDialog
|
2012-05-30 16:10:56 +00:00
|
|
|
from .deletion_options import DeletionOptions
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2011-11-01 19:44:18 +00:00
|
|
|
tr = trget('ui')
|
|
|
|
|
2011-09-20 19:06:29 +00:00
|
|
|
class DupeGuru(QObject):
|
2011-09-20 22:40:27 +00:00
|
|
|
MODELCLASS = None
|
2009-06-01 09:55:11 +00:00
|
|
|
LOGO_NAME = '<replace this>'
|
|
|
|
NAME = '<replace this>'
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-11-28 15:27:17 +00:00
|
|
|
DETAILS_DIALOG_CLASS = None
|
|
|
|
RESULT_WINDOW_CLASS = ResultWindow
|
|
|
|
RESULT_MODEL_CLASS = None
|
|
|
|
PREFERENCES_CLASS = None
|
|
|
|
PREFERENCES_DIALOG_CLASS = None
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2013-10-20 19:53:59 +00:00
|
|
|
def __init__(self, **kwargs):
|
|
|
|
super().__init__(**kwargs)
|
2011-11-28 15:27:17 +00:00
|
|
|
self.prefs = self.PREFERENCES_CLASS()
|
2011-01-24 10:30:45 +00:00
|
|
|
self.prefs.load()
|
2013-10-12 17:54:13 +00:00
|
|
|
self.model = self.MODELCLASS(view=self)
|
2009-06-01 09:55:11 +00:00
|
|
|
self._setup()
|
2011-09-23 14:29:25 +00:00
|
|
|
self.prefsChanged.emit(self.prefs)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
#--- Private
|
|
|
|
def _setup(self):
|
2011-01-15 15:29:35 +00:00
|
|
|
self._setupActions()
|
2009-06-01 09:55:11 +00:00
|
|
|
self._update_options()
|
2011-01-17 16:15:16 +00:00
|
|
|
self.recentResults = Recent(self, 'recentResults')
|
2011-09-20 19:06:29 +00:00
|
|
|
self.recentResults.mustOpenItem.connect(self.model.load_from)
|
2014-02-15 20:05:46 +00:00
|
|
|
self.directories_dialog = DirectoriesDialog(self)
|
|
|
|
self.resultWindow = self.RESULT_WINDOW_CLASS(self.directories_dialog, self)
|
2014-10-13 19:08:59 +00:00
|
|
|
self.progress_window = ProgressWindow(self.resultWindow, self.model.progress_window)
|
2011-11-28 15:27:17 +00:00
|
|
|
self.details_dialog = self.DETAILS_DIALOG_CLASS(self.resultWindow, self)
|
2012-01-16 14:29:57 +00:00
|
|
|
self.problemDialog = ProblemDialog(parent=self.resultWindow, model=self.model.problem_dialog)
|
2012-03-14 16:47:21 +00:00
|
|
|
self.ignoreListDialog = IgnoreListDialog(parent=self.resultWindow, model=self.model.ignore_list_dialog)
|
2012-05-30 16:10:56 +00:00
|
|
|
self.deletionOptions = DeletionOptions(parent=self.resultWindow, model=self.model.deletion_options)
|
2011-11-28 15:27:17 +00:00
|
|
|
self.preferences_dialog = self.PREFERENCES_DIALOG_CLASS(self.resultWindow, self)
|
2011-01-15 15:29:35 +00:00
|
|
|
self.about_box = AboutBox(self.resultWindow, self)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-01-15 15:29:35 +00:00
|
|
|
self.directories_dialog.show()
|
2011-09-20 19:06:29 +00:00
|
|
|
self.model.load()
|
2014-10-13 19:08:59 +00:00
|
|
|
|
|
|
|
# The timer scheme is because if the nag is not shown before the application is
|
2011-09-21 17:42:54 +00:00
|
|
|
# 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.
|
|
|
|
QTimer.singleShot(0, self.finishedLaunching)
|
2013-10-20 19:15:09 +00:00
|
|
|
QCoreApplication.instance().aboutToQuit.connect(self.application_will_terminate)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
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),
|
2012-03-14 16:47:21 +00:00
|
|
|
('actionIgnoreList', '', '', tr("Ignore List"), self.ignoreListTriggered),
|
2011-01-21 12:57:54 +00:00
|
|
|
('actionShowHelp', 'F1', '', tr("dupeGuru Help"), self.showHelpTriggered),
|
|
|
|
('actionAbout', '', '', tr("About dupeGuru"), self.showAboutBoxTriggered),
|
|
|
|
('actionOpenDebugLog', '', '', tr("Open Debug Log"), self.openDebugLogTriggered),
|
2011-01-15 15:29:35 +00:00
|
|
|
]
|
|
|
|
createActions(ACTIONS, self)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
def _update_options(self):
|
2011-09-20 19:06:29 +00:00
|
|
|
self.model.scanner.mix_file_kind = self.prefs.mix_file_kind
|
2015-04-05 13:17:35 +00:00
|
|
|
self.model.options['escape_filter_regexp'] = not self.prefs.use_regexp
|
2011-09-20 19:06:29 +00:00
|
|
|
self.model.options['clean_empty_dirs'] = self.prefs.remove_empty_folders
|
|
|
|
self.model.options['ignore_hardlink_matches'] = self.prefs.ignore_hardlink_matches
|
2012-03-10 19:32:56 +00:00
|
|
|
self.model.options['copymove_dest_type'] = self.prefs.destination_type
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-09-20 19:06:29 +00:00
|
|
|
#--- Public
|
2010-02-06 11:12:20 +00:00
|
|
|
def add_selected_to_ignore_list(self):
|
2012-03-10 15:58:08 +00:00
|
|
|
self.model.add_selected_to_ignore_list()
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2010-02-06 11:44:21 +00:00
|
|
|
def remove_selected(self):
|
2012-03-10 15:58:08 +00:00
|
|
|
self.model.remove_selected(self)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
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
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2010-04-13 08:02:09 +00:00
|
|
|
def invokeCustomCommand(self):
|
2012-03-10 15:58:08 +00:00
|
|
|
self.model.invoke_custom_command()
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
def show_details(self):
|
|
|
|
self.details_dialog.show()
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-01-15 15:29:35 +00:00
|
|
|
def showResultsWindow(self):
|
|
|
|
self.resultWindow.show()
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2010-08-15 10:27:15 +00:00
|
|
|
#--- Signals
|
|
|
|
willSavePrefs = pyqtSignal()
|
2011-09-23 14:29:25 +00:00
|
|
|
prefsChanged = pyqtSignal(object)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
#--- Events
|
2011-09-21 17:42:54 +00:00
|
|
|
def finishedLaunching(self):
|
2011-12-07 17:04:02 +00:00
|
|
|
if sys.getfilesystemencoding() == 'ascii':
|
|
|
|
# No need to localize this, it's a debugging message.
|
|
|
|
msg = "Something is wrong with the way your system locale is set. If the files you're "\
|
2014-10-13 19:08:59 +00:00
|
|
|
"scanning have accented letters, you'll probably get a crash. It is advised that "\
|
|
|
|
"you set your system locale properly."
|
2011-12-07 17:04:02 +00:00
|
|
|
QMessageBox.warning(self.directories_dialog, "Wrong Locale", msg)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
def application_will_terminate(self):
|
2010-08-15 10:27:15 +00:00
|
|
|
self.willSavePrefs.emit()
|
|
|
|
self.prefs.save()
|
2011-09-20 19:06:29 +00:00
|
|
|
self.model.save()
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2012-03-14 16:47:21 +00:00
|
|
|
def ignoreListTriggered(self):
|
|
|
|
self.model.ignore_list_dialog.show()
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-01-15 15:29:35 +00:00
|
|
|
def openDebugLogTriggered(self):
|
2011-09-20 19:06:29 +00:00
|
|
|
debugLogPath = op.join(self.model.appdata, 'debug.log')
|
2013-10-12 17:54:13 +00:00
|
|
|
desktop.open_path(debugLogPath)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-01-15 15:29:35 +00:00
|
|
|
def preferencesTriggered(self):
|
|
|
|
self.preferences_dialog.load()
|
2011-09-20 19:06:29 +00:00
|
|
|
result = self.preferences_dialog.exec()
|
2011-01-15 15:29:35 +00:00
|
|
|
if result == QDialog.Accepted:
|
|
|
|
self.preferences_dialog.save()
|
|
|
|
self.prefs.save()
|
|
|
|
self._update_options()
|
2011-09-23 14:29:25 +00:00
|
|
|
self.prefsChanged.emit(self.prefs)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-01-15 15:29:35 +00:00
|
|
|
def quitTriggered(self):
|
|
|
|
self.directories_dialog.close()
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-01-15 15:29:35 +00:00
|
|
|
def showAboutBoxTriggered(self):
|
|
|
|
self.about_box.show()
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-01-15 15:29:35 +00:00
|
|
|
def showHelpTriggered(self):
|
2011-11-30 16:06:08 +00:00
|
|
|
base_path = platform.HELP_PATH
|
2011-01-15 15:29:35 +00:00
|
|
|
url = QUrl.fromLocalFile(op.abspath(op.join(base_path, 'index.html')))
|
|
|
|
QDesktopServices.openUrl(url)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-09-20 19:06:29 +00:00
|
|
|
#--- model --> view
|
|
|
|
def get_default(self, key):
|
|
|
|
return self.prefs.get_value(key)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-09-20 19:06:29 +00:00
|
|
|
def set_default(self, key, value):
|
|
|
|
self.prefs.set_value(key, value)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-09-22 14:35:17 +00:00
|
|
|
def show_message(self, msg):
|
|
|
|
window = QApplication.activeWindow()
|
|
|
|
QMessageBox.information(window, '', msg)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2012-03-10 15:58:08 +00:00
|
|
|
def ask_yes_no(self, prompt):
|
|
|
|
return self.confirm('', prompt)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2012-03-09 18:47:28 +00:00
|
|
|
def show_results_window(self):
|
|
|
|
self.showResultsWindow()
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2012-03-09 18:47:28 +00:00
|
|
|
def show_problem_dialog(self):
|
|
|
|
self.problemDialog.show()
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2012-03-10 19:32:56 +00:00
|
|
|
def select_dest_folder(self, prompt):
|
|
|
|
flags = QFileDialog.ShowDirsOnly
|
|
|
|
return QFileDialog.getExistingDirectory(self.resultWindow, prompt, '', flags)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2012-07-31 20:46:51 +00:00
|
|
|
def select_dest_file(self, prompt, extension):
|
|
|
|
files = tr("{} file (*.{})").format(extension.upper(), extension)
|
2014-03-30 19:57:07 +00:00
|
|
|
destination, chosen_filter = QFileDialog.getSaveFileName(self.resultWindow, prompt, '', files)
|
|
|
|
if not destination.endswith('.{}'.format(extension)):
|
|
|
|
destination = '{}.{}'.format(destination, extension)
|
|
|
|
return destination
|