2016-05-29 01:54:25 +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
|
2011-01-21 12:57:54 +00:00
|
|
|
|
2013-10-20 19:15:09 +00:00
|
|
|
from PyQt5.QtCore import Qt, QSize
|
2014-10-13 19:08:59 +00:00
|
|
|
from PyQt5.QtWidgets import (
|
|
|
|
QDialog, QDialogButtonBox, QVBoxLayout, QHBoxLayout, QLabel, QComboBox,
|
|
|
|
QSlider, QSizePolicy, QSpacerItem, QCheckBox, QLineEdit, QMessageBox, QSpinBox
|
|
|
|
)
|
2011-01-21 12:57:54 +00:00
|
|
|
|
2011-11-01 19:44:18 +00:00
|
|
|
from hscommon.trans import trget
|
2011-09-23 14:29:25 +00:00
|
|
|
from qtlib.util import horizontalWrap
|
2016-05-26 01:07:30 +00:00
|
|
|
from qtlib.preferences import get_langnames
|
2011-01-21 12:57:54 +00:00
|
|
|
|
2016-06-01 01:22:50 +00:00
|
|
|
from .preferences import Preferences
|
|
|
|
|
2011-11-01 19:44:18 +00:00
|
|
|
tr = trget('ui')
|
|
|
|
|
2015-04-13 01:53:45 +00:00
|
|
|
SUPPORTED_LANGUAGES = [
|
2016-08-16 23:59:04 +00:00
|
|
|
'en', 'fr', 'de', 'el', 'zh_CN', 'cs', 'it', 'hy', 'ru', 'uk', 'pt_BR', 'vi', 'pl_PL', 'ko', 'es',
|
2015-07-20 17:18:14 +00:00
|
|
|
'nl',
|
2015-04-13 01:53:45 +00:00
|
|
|
]
|
2011-11-03 14:38:31 +00:00
|
|
|
|
2011-01-21 12:57:54 +00:00
|
|
|
class PreferencesDialogBase(QDialog):
|
2013-10-20 19:53:59 +00:00
|
|
|
def __init__(self, parent, app, **kwargs):
|
2011-01-21 12:57:54 +00:00
|
|
|
flags = Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowSystemMenuHint
|
2013-10-20 19:53:59 +00:00
|
|
|
super().__init__(parent, flags, **kwargs)
|
2011-01-21 12:57:54 +00:00
|
|
|
self.app = app
|
2016-05-26 01:07:30 +00:00
|
|
|
all_languages = get_langnames()
|
|
|
|
self.supportedLanguages = sorted(SUPPORTED_LANGUAGES, key=lambda lang: all_languages[lang])
|
2011-01-21 12:57:54 +00:00
|
|
|
self._setupUi()
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2013-10-20 19:15:09 +00:00
|
|
|
self.filterHardnessSlider.valueChanged['int'].connect(self.filterHardnessLabel.setNum)
|
2014-03-27 23:09:10 +00:00
|
|
|
self.buttonBox.clicked.connect(self.buttonClicked)
|
2011-01-21 12:57:54 +00:00
|
|
|
self.buttonBox.accepted.connect(self.accept)
|
|
|
|
self.buttonBox.rejected.connect(self.reject)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-01-21 12:57:54 +00:00
|
|
|
def _setupFilterHardnessBox(self):
|
|
|
|
self.filterHardnessHLayout = QHBoxLayout()
|
|
|
|
self.filterHardnessLabel = QLabel(self)
|
|
|
|
self.filterHardnessLabel.setText(tr("Filter Hardness:"))
|
|
|
|
self.filterHardnessLabel.setMinimumSize(QSize(0, 0))
|
|
|
|
self.filterHardnessHLayout.addWidget(self.filterHardnessLabel)
|
|
|
|
self.filterHardnessVLayout = QVBoxLayout()
|
|
|
|
self.filterHardnessVLayout.setSpacing(0)
|
|
|
|
self.filterHardnessHLayoutSub1 = QHBoxLayout()
|
|
|
|
self.filterHardnessHLayoutSub1.setSpacing(12)
|
|
|
|
self.filterHardnessSlider = QSlider(self)
|
|
|
|
sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
|
|
|
|
sizePolicy.setHorizontalStretch(0)
|
|
|
|
sizePolicy.setVerticalStretch(0)
|
|
|
|
sizePolicy.setHeightForWidth(self.filterHardnessSlider.sizePolicy().hasHeightForWidth())
|
|
|
|
self.filterHardnessSlider.setSizePolicy(sizePolicy)
|
|
|
|
self.filterHardnessSlider.setMinimum(1)
|
|
|
|
self.filterHardnessSlider.setMaximum(100)
|
|
|
|
self.filterHardnessSlider.setTracking(True)
|
|
|
|
self.filterHardnessSlider.setOrientation(Qt.Horizontal)
|
|
|
|
self.filterHardnessHLayoutSub1.addWidget(self.filterHardnessSlider)
|
|
|
|
self.filterHardnessLabel = QLabel(self)
|
|
|
|
self.filterHardnessLabel.setText("100")
|
|
|
|
self.filterHardnessLabel.setMinimumSize(QSize(21, 0))
|
|
|
|
self.filterHardnessHLayoutSub1.addWidget(self.filterHardnessLabel)
|
|
|
|
self.filterHardnessVLayout.addLayout(self.filterHardnessHLayoutSub1)
|
|
|
|
self.filterHardnessHLayoutSub2 = QHBoxLayout()
|
|
|
|
self.filterHardnessHLayoutSub2.setContentsMargins(-1, 0, -1, -1)
|
|
|
|
self.moreResultsLabel = QLabel(self)
|
|
|
|
self.moreResultsLabel.setText(tr("More Results"))
|
|
|
|
self.filterHardnessHLayoutSub2.addWidget(self.moreResultsLabel)
|
|
|
|
spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
|
|
|
|
self.filterHardnessHLayoutSub2.addItem(spacerItem)
|
|
|
|
self.fewerResultsLabel = QLabel(self)
|
|
|
|
self.fewerResultsLabel.setText(tr("Fewer Results"))
|
|
|
|
self.filterHardnessHLayoutSub2.addWidget(self.fewerResultsLabel)
|
|
|
|
self.filterHardnessVLayout.addLayout(self.filterHardnessHLayoutSub2)
|
|
|
|
self.filterHardnessHLayout.addLayout(self.filterHardnessVLayout)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-01-21 12:57:54 +00:00
|
|
|
def _setupBottomPart(self):
|
|
|
|
# The bottom part of the pref panel is always the same in all editions.
|
2011-09-23 14:29:25 +00:00
|
|
|
self.fontSizeLabel = QLabel(tr("Font size:"))
|
|
|
|
self.fontSizeSpinBox = QSpinBox()
|
|
|
|
self.fontSizeSpinBox.setMinimum(5)
|
|
|
|
self.widgetsVLayout.addLayout(horizontalWrap([self.fontSizeLabel, self.fontSizeSpinBox, None]))
|
2011-01-21 12:57:54 +00:00
|
|
|
self.languageLabel = QLabel(tr("Language:"), self)
|
|
|
|
self.languageComboBox = QComboBox(self)
|
2015-07-20 17:18:14 +00:00
|
|
|
for lang in self.supportedLanguages:
|
2016-05-26 01:07:30 +00:00
|
|
|
self.languageComboBox.addItem(get_langnames()[lang])
|
2011-09-23 14:29:25 +00:00
|
|
|
self.widgetsVLayout.addLayout(horizontalWrap([self.languageLabel, self.languageComboBox, None]))
|
2011-01-21 12:57:54 +00:00
|
|
|
self.copyMoveLabel = QLabel(self)
|
|
|
|
self.copyMoveLabel.setText(tr("Copy and Move:"))
|
|
|
|
self.widgetsVLayout.addWidget(self.copyMoveLabel)
|
|
|
|
self.copyMoveDestinationComboBox = QComboBox(self)
|
|
|
|
self.copyMoveDestinationComboBox.addItem(tr("Right in destination"))
|
|
|
|
self.copyMoveDestinationComboBox.addItem(tr("Recreate relative path"))
|
|
|
|
self.copyMoveDestinationComboBox.addItem(tr("Recreate absolute path"))
|
|
|
|
self.widgetsVLayout.addWidget(self.copyMoveDestinationComboBox)
|
|
|
|
self.customCommandLabel = QLabel(self)
|
|
|
|
self.customCommandLabel.setText(tr("Custom Command (arguments: %d for dupe, %r for ref):"))
|
|
|
|
self.widgetsVLayout.addWidget(self.customCommandLabel)
|
|
|
|
self.customCommandEdit = QLineEdit(self)
|
|
|
|
self.widgetsVLayout.addWidget(self.customCommandEdit)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-01-21 12:57:54 +00:00
|
|
|
def _setupAddCheckbox(self, name, label, parent=None):
|
|
|
|
if parent is None:
|
|
|
|
parent = self
|
|
|
|
cb = QCheckBox(parent)
|
|
|
|
cb.setText(label)
|
|
|
|
setattr(self, name, cb)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-01-21 12:57:54 +00:00
|
|
|
def _setupPreferenceWidgets(self):
|
|
|
|
# Edition-specific
|
|
|
|
pass
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-01-21 12:57:54 +00:00
|
|
|
def _setupUi(self):
|
2016-05-29 01:54:25 +00:00
|
|
|
self.setWindowTitle(tr("Options"))
|
2011-01-21 12:57:54 +00:00
|
|
|
self.resize(304, 263)
|
|
|
|
self.setSizeGripEnabled(False)
|
|
|
|
self.setModal(True)
|
|
|
|
self.mainVLayout = QVBoxLayout(self)
|
|
|
|
self.widgetsVLayout = QVBoxLayout()
|
|
|
|
self._setupPreferenceWidgets()
|
|
|
|
self.mainVLayout.addLayout(self.widgetsVLayout)
|
|
|
|
self.buttonBox = QDialogButtonBox(self)
|
|
|
|
self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok|QDialogButtonBox.RestoreDefaults)
|
|
|
|
self.mainVLayout.addWidget(self.buttonBox)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-01-21 12:57:54 +00:00
|
|
|
def _load(self, prefs, setchecked):
|
|
|
|
# Edition-specific
|
|
|
|
pass
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-01-21 12:57:54 +00:00
|
|
|
def _save(self, prefs, ischecked):
|
|
|
|
# Edition-specific
|
|
|
|
pass
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-01-21 12:57:54 +00:00
|
|
|
def load(self, prefs=None):
|
|
|
|
if prefs is None:
|
|
|
|
prefs = self.app.prefs
|
|
|
|
self.filterHardnessSlider.setValue(prefs.filter_hardness)
|
|
|
|
self.filterHardnessLabel.setNum(prefs.filter_hardness)
|
|
|
|
setchecked = lambda cb, b: cb.setCheckState(Qt.Checked if b else Qt.Unchecked)
|
|
|
|
setchecked(self.mixFileKindBox, prefs.mix_file_kind)
|
|
|
|
setchecked(self.useRegexpBox, prefs.use_regexp)
|
|
|
|
setchecked(self.removeEmptyFoldersBox, prefs.remove_empty_folders)
|
|
|
|
setchecked(self.ignoreHardlinkMatches, prefs.ignore_hardlink_matches)
|
2011-01-26 11:50:44 +00:00
|
|
|
setchecked(self.debugModeBox, prefs.debug_mode)
|
2011-01-21 12:57:54 +00:00
|
|
|
self.copyMoveDestinationComboBox.setCurrentIndex(prefs.destination_type)
|
|
|
|
self.customCommandEdit.setText(prefs.custom_command)
|
2011-09-23 14:29:25 +00:00
|
|
|
self.fontSizeSpinBox.setValue(prefs.tableFontSize)
|
2011-11-03 14:38:31 +00:00
|
|
|
try:
|
2015-07-20 17:18:14 +00:00
|
|
|
langindex = self.supportedLanguages.index(self.app.prefs.language)
|
2011-11-03 14:38:31 +00:00
|
|
|
except ValueError:
|
|
|
|
langindex = 0
|
2011-01-21 12:57:54 +00:00
|
|
|
self.languageComboBox.setCurrentIndex(langindex)
|
|
|
|
self._load(prefs, setchecked)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-01-21 12:57:54 +00:00
|
|
|
def save(self):
|
|
|
|
prefs = self.app.prefs
|
|
|
|
prefs.filter_hardness = self.filterHardnessSlider.value()
|
|
|
|
ischecked = lambda cb: cb.checkState() == Qt.Checked
|
|
|
|
prefs.mix_file_kind = ischecked(self.mixFileKindBox)
|
|
|
|
prefs.use_regexp = ischecked(self.useRegexpBox)
|
|
|
|
prefs.remove_empty_folders = ischecked(self.removeEmptyFoldersBox)
|
|
|
|
prefs.ignore_hardlink_matches = ischecked(self.ignoreHardlinkMatches)
|
2011-01-26 11:50:44 +00:00
|
|
|
prefs.debug_mode = ischecked(self.debugModeBox)
|
2011-01-21 12:57:54 +00:00
|
|
|
prefs.destination_type = self.copyMoveDestinationComboBox.currentIndex()
|
|
|
|
prefs.custom_command = str(self.customCommandEdit.text())
|
2011-09-23 14:29:25 +00:00
|
|
|
prefs.tableFontSize = self.fontSizeSpinBox.value()
|
2015-07-20 17:18:14 +00:00
|
|
|
lang = self.supportedLanguages[self.languageComboBox.currentIndex()]
|
2011-01-21 12:57:54 +00:00
|
|
|
oldlang = self.app.prefs.language
|
2015-07-20 17:18:14 +00:00
|
|
|
if oldlang not in self.supportedLanguages:
|
2011-01-21 12:57:54 +00:00
|
|
|
oldlang = 'en'
|
|
|
|
if lang != oldlang:
|
2011-11-04 18:37:07 +00:00
|
|
|
QMessageBox.information(self, "", tr("dupeGuru has to restart for language changes to take effect."))
|
2011-01-21 12:57:54 +00:00
|
|
|
self.app.prefs.language = lang
|
|
|
|
self._save(prefs, ischecked)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2016-06-01 01:22:50 +00:00
|
|
|
def resetToDefaults(self):
|
|
|
|
self.load(Preferences())
|
|
|
|
|
2011-01-21 12:57:54 +00:00
|
|
|
#--- Events
|
|
|
|
def buttonClicked(self, button):
|
|
|
|
role = self.buttonBox.buttonRole(button)
|
|
|
|
if role == QDialogButtonBox.ResetRole:
|
2014-10-13 19:08:59 +00:00
|
|
|
self.resetToDefaults()
|
|
|
|
|