2016-06-01 01:22:50 +00:00
|
|
|
# Copyright 2016 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
|
|
|
|
|
2016-08-15 01:11:24 +00:00
|
|
|
from PyQt5.QtCore import QTimer, QObject, 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
|
|
|
|
2016-06-01 01:43:24 +00:00
|
|
|
from core.app import AppMode, DupeGuru as DupeGuruModel
|
2016-06-01 02:32:37 +00:00
|
|
|
import core.pe.photo
|
2009-09-27 08:44:06 +00:00
|
|
|
from . import platform
|
2016-06-01 01:22:50 +00:00
|
|
|
from .preferences import Preferences
|
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
|
2016-06-01 01:59:31 +00:00
|
|
|
from .se.details_dialog import DetailsDialog as DetailsDialogStandard
|
|
|
|
from .me.details_dialog import DetailsDialog as DetailsDialogMusic
|
|
|
|
from .pe.details_dialog import DetailsDialog as DetailsDialogPicture
|
|
|
|
from .se.preferences_dialog import PreferencesDialog as PreferencesDialogStandard
|
|
|
|
from .me.preferences_dialog import PreferencesDialog as PreferencesDialogMusic
|
|
|
|
from .pe.preferences_dialog import PreferencesDialog as PreferencesDialogPicture
|
|
|
|
from .pe.photo import File as PlatSpecificPhoto
|
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):
|
2016-06-01 01:22:50 +00:00
|
|
|
LOGO_NAME = 'logo_se'
|
|
|
|
NAME = 'dupeGuru'
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2013-10-20 19:53:59 +00:00
|
|
|
def __init__(self, **kwargs):
|
|
|
|
super().__init__(**kwargs)
|
2016-06-01 01:22:50 +00:00
|
|
|
self.prefs = Preferences()
|
2011-01-24 10:30:45 +00:00
|
|
|
self.prefs.load()
|
2016-06-01 01:22:50 +00:00
|
|
|
self.model = DupeGuruModel(view=self)
|
2009-06-01 09:55:11 +00:00
|
|
|
self._setup()
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
#--- Private
|
|
|
|
def _setup(self):
|
2016-06-01 02:32:37 +00:00
|
|
|
core.pe.photo.PLAT_SPECIFIC_PHOTO_CLASS = PlatSpecificPhoto
|
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)
|
2016-05-30 02:37:38 +00:00
|
|
|
self.resultWindow = None
|
|
|
|
self.details_dialog = None
|
2014-02-15 20:05:46 +00:00
|
|
|
self.directories_dialog = DirectoriesDialog(self)
|
2016-05-30 02:37:38 +00:00
|
|
|
self.progress_window = ProgressWindow(self.directories_dialog, self.model.progress_window)
|
|
|
|
self.problemDialog = ProblemDialog(parent=self.directories_dialog, model=self.model.problem_dialog)
|
|
|
|
self.ignoreListDialog = IgnoreListDialog(parent=self.directories_dialog, model=self.model.ignore_list_dialog)
|
|
|
|
self.deletionOptions = DeletionOptions(parent=self.directories_dialog, model=self.model.deletion_options)
|
|
|
|
self.about_box = AboutBox(self.directories_dialog, 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)
|
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),
|
2016-05-29 01:54:25 +00:00
|
|
|
('actionPreferences', 'Ctrl+P', '', tr("Options"), self.preferencesTriggered),
|
2012-03-14 16:47:21 +00:00
|
|
|
('actionIgnoreList', '', '', tr("Ignore List"), self.ignoreListTriggered),
|
2016-06-01 00:55:32 +00:00
|
|
|
('actionClearPictureCache', 'Ctrl+Shift+P', '', tr("Clear Picture Cache"), self.clearPictureCacheTriggered),
|
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):
|
2016-05-29 20:52:07 +00:00
|
|
|
self.model.options['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
|
2016-05-30 02:37:38 +00:00
|
|
|
self.model.options['scan_type'] = self.prefs.get_scan_type(self.model.app_mode)
|
2016-06-01 01:22:50 +00:00
|
|
|
self.model.options['min_match_percentage'] = self.prefs.filter_hardness
|
|
|
|
self.model.options['word_weighting'] = self.prefs.word_weighting
|
|
|
|
self.model.options['match_similar_words'] = self.prefs.match_similar
|
|
|
|
threshold = self.prefs.small_file_threshold if self.prefs.ignore_small_files else 0
|
|
|
|
self.model.options['size_threshold'] = threshold * 1024 # threshold is in KB. the scanner wants bytes
|
|
|
|
scanned_tags = set()
|
|
|
|
if self.prefs.scan_tag_track:
|
|
|
|
scanned_tags.add('track')
|
|
|
|
if self.prefs.scan_tag_artist:
|
|
|
|
scanned_tags.add('artist')
|
|
|
|
if self.prefs.scan_tag_album:
|
|
|
|
scanned_tags.add('album')
|
|
|
|
if self.prefs.scan_tag_title:
|
|
|
|
scanned_tags.add('title')
|
|
|
|
if self.prefs.scan_tag_genre:
|
|
|
|
scanned_tags.add('genre')
|
|
|
|
if self.prefs.scan_tag_year:
|
|
|
|
scanned_tags.add('year')
|
|
|
|
self.model.options['scanned_tags'] = scanned_tags
|
|
|
|
self.model.options['match_scaled'] = self.prefs.match_scaled
|
|
|
|
|
|
|
|
#--- Private
|
|
|
|
def _get_details_dialog_class(self):
|
|
|
|
if self.model.app_mode == AppMode.Picture:
|
|
|
|
return DetailsDialogPicture
|
|
|
|
elif self.model.app_mode == AppMode.Music:
|
|
|
|
return DetailsDialogMusic
|
|
|
|
else:
|
|
|
|
return DetailsDialogStandard
|
|
|
|
|
|
|
|
def _get_preferences_dialog_class(self):
|
|
|
|
if self.model.app_mode == AppMode.Picture:
|
|
|
|
return PreferencesDialogPicture
|
|
|
|
elif self.model.app_mode == AppMode.Music:
|
|
|
|
return PreferencesDialogMusic
|
|
|
|
else:
|
|
|
|
return PreferencesDialogStandard
|
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):
|
2016-05-30 02:37:38 +00:00
|
|
|
if self.details_dialog is not None:
|
|
|
|
self.details_dialog.show()
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-01-15 15:29:35 +00:00
|
|
|
def showResultsWindow(self):
|
2016-05-30 02:37:38 +00:00
|
|
|
if self.resultWindow is not None:
|
|
|
|
self.resultWindow.show()
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2016-08-15 01:11:24 +00:00
|
|
|
def shutdown(self):
|
|
|
|
self.willSavePrefs.emit()
|
|
|
|
self.prefs.save()
|
|
|
|
self.model.save()
|
|
|
|
QApplication.quit()
|
|
|
|
|
2010-08-15 10:27:15 +00:00
|
|
|
#--- Signals
|
|
|
|
willSavePrefs = pyqtSignal()
|
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
|
|
|
|
2016-06-01 00:55:32 +00:00
|
|
|
def clearPictureCacheTriggered(self):
|
|
|
|
title = tr("Clear Picture Cache")
|
|
|
|
msg = tr("Do you really want to remove all your cached picture analysis?")
|
|
|
|
if self.confirm(title, msg, QMessageBox.No):
|
|
|
|
self.model.clear_picture_cache()
|
|
|
|
active = QApplication.activeWindow()
|
|
|
|
QMessageBox.information(active, title, tr("Picture cache cleared."))
|
|
|
|
|
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):
|
2016-06-01 01:22:50 +00:00
|
|
|
preferences_dialog = self._get_preferences_dialog_class()(self.directories_dialog, self)
|
2016-05-30 02:37:38 +00:00
|
|
|
preferences_dialog.load()
|
|
|
|
result = preferences_dialog.exec()
|
2011-01-15 15:29:35 +00:00
|
|
|
if result == QDialog.Accepted:
|
2016-05-30 02:37:38 +00:00
|
|
|
preferences_dialog.save()
|
2011-01-15 15:29:35 +00:00
|
|
|
self.prefs.save()
|
|
|
|
self._update_options()
|
2016-05-30 02:37:38 +00:00
|
|
|
preferences_dialog.setParent(None)
|
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
|
|
|
|
2016-05-30 02:37:38 +00:00
|
|
|
def create_results_window(self):
|
|
|
|
"""Creates resultWindow and details_dialog depending on the selected ``app_mode``.
|
|
|
|
"""
|
|
|
|
if self.details_dialog is not None:
|
|
|
|
self.details_dialog.close()
|
|
|
|
self.details_dialog.setParent(None)
|
|
|
|
if self.resultWindow is not None:
|
|
|
|
self.resultWindow.close()
|
|
|
|
self.resultWindow.setParent(None)
|
2016-06-01 00:55:32 +00:00
|
|
|
self.resultWindow = ResultWindow(self.directories_dialog, self)
|
2016-06-01 01:22:50 +00:00
|
|
|
self.details_dialog = self._get_details_dialog_class()(self.resultWindow, self)
|
2016-05-30 02:37:38 +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
|