2011-01-21 12:57:54 +00:00
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2011-01-21
|
2012-03-15 18:28:40 +00:00
|
|
|
# Copyright 2012 Hardcoded Software (http://www.hardcoded.net)
|
2011-01-21 12:57:54 +00:00
|
|
|
#
|
|
|
|
# This software is licensed under the "BSD" License as described in the "LICENSE" file,
|
|
|
|
# which should be included with this package. The terms are also available at
|
|
|
|
# http://www.hardcoded.net/licenses/bsd_license
|
|
|
|
|
|
|
|
from PyQt4.QtCore import SIGNAL, Qt, QSize
|
|
|
|
from PyQt4.QtGui import (QDialog, QDialogButtonBox, QVBoxLayout, QHBoxLayout, QLabel, QComboBox,
|
2011-09-23 14:29:25 +00:00
|
|
|
QSlider, QSizePolicy, QSpacerItem, QCheckBox, QLineEdit, QMessageBox, QSpinBox)
|
2011-01-21 12:57:54 +00:00
|
|
|
|
2011-09-22 13:32:09 +00:00
|
|
|
from hscommon.plat import ISOSX, ISLINUX
|
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
|
2012-01-03 22:03:53 +00:00
|
|
|
from qtlib.preferences import LANGNAMES
|
2011-01-21 12:57:54 +00:00
|
|
|
|
2011-11-01 19:44:18 +00:00
|
|
|
tr = trget('ui')
|
|
|
|
|
2012-01-18 01:15:09 +00:00
|
|
|
SUPPORTED_LANGUAGES = ['en', 'fr', 'de', 'zh_CN', 'cs', 'it', 'hy', 'ru', 'uk']
|
2011-11-03 14:38:31 +00:00
|
|
|
|
2011-01-21 12:57:54 +00:00
|
|
|
class PreferencesDialogBase(QDialog):
|
|
|
|
def __init__(self, parent, app):
|
|
|
|
flags = Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowSystemMenuHint
|
|
|
|
QDialog.__init__(self, parent, flags)
|
|
|
|
self.app = app
|
|
|
|
self._setupUi()
|
|
|
|
|
|
|
|
self.connect(self.filterHardnessSlider, SIGNAL("valueChanged(int)"), self.filterHardnessLabel.setNum)
|
|
|
|
self.connect(self.buttonBox, SIGNAL('clicked(QAbstractButton*)'), self.buttonClicked)
|
|
|
|
self.buttonBox.accepted.connect(self.accept)
|
|
|
|
self.buttonBox.rejected.connect(self.reject)
|
|
|
|
|
2011-04-20 13:18:21 +00:00
|
|
|
def _setupScanTypeBox(self, labels):
|
|
|
|
self.scanTypeHLayout = QHBoxLayout()
|
|
|
|
self.scanTypeLabel = QLabel(self)
|
|
|
|
self.scanTypeLabel.setText(tr("Scan Type:"))
|
|
|
|
self.scanTypeLabel.setMinimumSize(QSize(100, 0))
|
|
|
|
self.scanTypeLabel.setMaximumSize(QSize(100, 16777215))
|
|
|
|
self.scanTypeHLayout.addWidget(self.scanTypeLabel)
|
|
|
|
self.scanTypeComboBox = QComboBox(self)
|
|
|
|
for label in labels:
|
|
|
|
self.scanTypeComboBox.addItem(label)
|
|
|
|
self.scanTypeHLayout.addWidget(self.scanTypeComboBox)
|
|
|
|
self.widgetsVLayout.addLayout(self.scanTypeHLayout)
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
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)
|
2011-11-03 14:38:31 +00:00
|
|
|
for lang in SUPPORTED_LANGUAGES:
|
|
|
|
self.languageComboBox.addItem(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)
|
|
|
|
|
|
|
|
def _setupAddCheckbox(self, name, label, parent=None):
|
|
|
|
if parent is None:
|
|
|
|
parent = self
|
|
|
|
cb = QCheckBox(parent)
|
|
|
|
cb.setText(label)
|
|
|
|
setattr(self, name, cb)
|
|
|
|
|
|
|
|
def _setupPreferenceWidgets(self):
|
|
|
|
# Edition-specific
|
|
|
|
pass
|
|
|
|
|
|
|
|
def _setupUi(self):
|
|
|
|
self.setWindowTitle(tr("Preferences"))
|
|
|
|
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)
|
2011-09-22 13:32:09 +00:00
|
|
|
if (not ISOSX) and (not ISLINUX):
|
2011-01-23 14:49:59 +00:00
|
|
|
self.mainVLayout.removeWidget(self.ignoreHardlinkMatches)
|
2011-01-21 12:57:54 +00:00
|
|
|
self.ignoreHardlinkMatches.setHidden(True)
|
|
|
|
|
|
|
|
def _load(self, prefs, setchecked):
|
|
|
|
# Edition-specific
|
|
|
|
pass
|
|
|
|
|
|
|
|
def _save(self, prefs, ischecked):
|
|
|
|
# Edition-specific
|
|
|
|
pass
|
|
|
|
|
|
|
|
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:
|
|
|
|
langindex = SUPPORTED_LANGUAGES.index(self.app.prefs.language)
|
|
|
|
except ValueError:
|
|
|
|
langindex = 0
|
2011-01-21 12:57:54 +00:00
|
|
|
self.languageComboBox.setCurrentIndex(langindex)
|
|
|
|
self._load(prefs, setchecked)
|
|
|
|
|
|
|
|
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()
|
2011-11-03 14:38:31 +00:00
|
|
|
lang = SUPPORTED_LANGUAGES[self.languageComboBox.currentIndex()]
|
2011-01-21 12:57:54 +00:00
|
|
|
oldlang = self.app.prefs.language
|
2011-11-03 14:38:31 +00:00
|
|
|
if oldlang not in SUPPORTED_LANGUAGES:
|
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)
|
|
|
|
|
|
|
|
#--- Events
|
|
|
|
def buttonClicked(self, button):
|
|
|
|
role = self.buttonBox.buttonRole(button)
|
|
|
|
if role == QDialogButtonBox.ResetRole:
|
|
|
|
self.resetToDefaults()
|