2009-06-01 09:55:11 +00:00
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2009-05-24
|
2011-04-12 08:04:01 +00:00
|
|
|
# Copyright 2011 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
|
|
|
|
2010-10-05 08:03:56 +00:00
|
|
|
import sys
|
2011-04-12 11:22:29 +00:00
|
|
|
from PyQt4.QtCore import QSize
|
2011-04-20 13:18:21 +00:00
|
|
|
from PyQt4.QtGui import (QVBoxLayout, QHBoxLayout, QLabel, QSizePolicy, QSpacerItem, QWidget,
|
|
|
|
QLineEdit, QApplication)
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2011-01-21 12:57:54 +00:00
|
|
|
from hscommon.trans import tr
|
2011-01-11 12:36:05 +00:00
|
|
|
from hscommon.util import tryint
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2010-08-14 17:52:23 +00:00
|
|
|
from core.scanner import ScanType
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2011-01-21 12:57:54 +00:00
|
|
|
from ..base.preferences_dialog import PreferencesDialogBase
|
2010-10-04 13:29:00 +00:00
|
|
|
from . import preferences
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
SCAN_TYPE_ORDER = [
|
2010-08-14 17:52:23 +00:00
|
|
|
ScanType.Filename,
|
|
|
|
ScanType.Contents,
|
2011-04-12 11:22:29 +00:00
|
|
|
ScanType.Folders,
|
2009-06-01 09:55:11 +00:00
|
|
|
]
|
|
|
|
|
2011-01-21 12:57:54 +00:00
|
|
|
class PreferencesDialog(PreferencesDialogBase):
|
2009-06-01 09:55:11 +00:00
|
|
|
def __init__(self, parent, app):
|
2011-01-21 12:57:54 +00:00
|
|
|
PreferencesDialogBase.__init__(self, parent, app)
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2011-04-12 11:22:29 +00:00
|
|
|
self.scanTypeComboBox.currentIndexChanged[int].connect(self.scanTypeChanged)
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2011-01-21 12:57:54 +00:00
|
|
|
def _setupPreferenceWidgets(self):
|
2011-04-20 13:18:21 +00:00
|
|
|
scanTypeLabels = [tr(s) for s in ["Filename", "Contents", "Folders"]]
|
|
|
|
self._setupScanTypeBox(scanTypeLabels)
|
2011-01-21 12:57:54 +00:00
|
|
|
self._setupFilterHardnessBox()
|
|
|
|
self.widgetsVLayout.addLayout(self.filterHardnessHLayout)
|
2010-10-04 13:29:00 +00:00
|
|
|
self.widget = QWidget(self)
|
|
|
|
self.widget.setMinimumSize(QSize(0, 136))
|
|
|
|
self.verticalLayout_4 = QVBoxLayout(self.widget)
|
2011-01-21 12:57:54 +00:00
|
|
|
self._setupAddCheckbox('wordWeightingBox', tr("Word weighting"), self.widget)
|
2010-10-04 13:29:00 +00:00
|
|
|
self.verticalLayout_4.addWidget(self.wordWeightingBox)
|
2011-01-21 12:57:54 +00:00
|
|
|
self._setupAddCheckbox('matchSimilarBox', tr("Match similar words"), self.widget)
|
2010-10-04 13:29:00 +00:00
|
|
|
self.verticalLayout_4.addWidget(self.matchSimilarBox)
|
2011-01-21 12:57:54 +00:00
|
|
|
self._setupAddCheckbox('mixFileKindBox', tr("Can mix file kind"), self.widget)
|
2010-10-04 13:29:00 +00:00
|
|
|
self.verticalLayout_4.addWidget(self.mixFileKindBox)
|
2011-01-21 12:57:54 +00:00
|
|
|
self._setupAddCheckbox('useRegexpBox', tr("Use regular expressions when filtering"), self.widget)
|
2010-10-04 13:29:00 +00:00
|
|
|
self.verticalLayout_4.addWidget(self.useRegexpBox)
|
2011-01-21 12:57:54 +00:00
|
|
|
self._setupAddCheckbox('removeEmptyFoldersBox', tr("Remove empty folders on delete or move"), self.widget)
|
2010-10-04 13:29:00 +00:00
|
|
|
self.verticalLayout_4.addWidget(self.removeEmptyFoldersBox)
|
|
|
|
self.horizontalLayout_2 = QHBoxLayout()
|
2011-01-21 12:57:54 +00:00
|
|
|
self._setupAddCheckbox('ignoreSmallFilesBox', tr("Ignore files smaller than"), self.widget)
|
2010-10-04 13:29:00 +00:00
|
|
|
self.horizontalLayout_2.addWidget(self.ignoreSmallFilesBox)
|
|
|
|
self.sizeThresholdEdit = QLineEdit(self.widget)
|
|
|
|
sizePolicy = QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
|
|
|
|
sizePolicy.setHorizontalStretch(0)
|
|
|
|
sizePolicy.setVerticalStretch(0)
|
|
|
|
sizePolicy.setHeightForWidth(self.sizeThresholdEdit.sizePolicy().hasHeightForWidth())
|
|
|
|
self.sizeThresholdEdit.setSizePolicy(sizePolicy)
|
|
|
|
self.sizeThresholdEdit.setMaximumSize(QSize(50, 16777215))
|
|
|
|
self.horizontalLayout_2.addWidget(self.sizeThresholdEdit)
|
|
|
|
self.label_6 = QLabel(self.widget)
|
2011-01-21 12:57:54 +00:00
|
|
|
self.label_6.setText(tr("KB"))
|
2010-10-04 13:29:00 +00:00
|
|
|
self.horizontalLayout_2.addWidget(self.label_6)
|
|
|
|
spacerItem1 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
|
|
|
|
self.horizontalLayout_2.addItem(spacerItem1)
|
|
|
|
self.verticalLayout_4.addLayout(self.horizontalLayout_2)
|
2011-01-21 12:57:54 +00:00
|
|
|
self._setupAddCheckbox('ignoreHardlinkMatches', tr("Ignore duplicates hardlinking to the same file"), self.widget)
|
2010-10-04 13:29:00 +00:00
|
|
|
self.verticalLayout_4.addWidget(self.ignoreHardlinkMatches)
|
2011-09-03 14:15:03 +00:00
|
|
|
self._setupAddCheckbox('debugModeBox', tr("Debug mode (restart required)"), self.widget)
|
2011-01-26 11:50:44 +00:00
|
|
|
self.verticalLayout_4.addWidget(self.debugModeBox)
|
2011-01-21 12:57:54 +00:00
|
|
|
self.widgetsVLayout.addWidget(self.widget)
|
|
|
|
self._setupBottomPart()
|
|
|
|
|
|
|
|
def _setupUi(self):
|
|
|
|
PreferencesDialogBase._setupUi(self)
|
2010-10-04 13:29:00 +00:00
|
|
|
|
2010-10-05 08:03:56 +00:00
|
|
|
if sys.platform == 'linux2':
|
2010-09-26 09:17:29 +00:00
|
|
|
# Under linux, whether it's a Qt layout bug or something else, the size threshold text edit
|
|
|
|
# doesn't have enough space, so we make the pref pane higher to compensate.
|
2011-01-27 10:22:10 +00:00
|
|
|
self.resize(self.width(), 490)
|
2011-01-27 10:11:23 +00:00
|
|
|
elif sys.platform == 'win32':
|
|
|
|
self.resize(self.width(), 420)
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2011-01-21 12:57:54 +00:00
|
|
|
def _load(self, prefs, setchecked):
|
2009-06-01 09:55:11 +00:00
|
|
|
scan_type_index = SCAN_TYPE_ORDER.index(prefs.scan_type)
|
|
|
|
self.scanTypeComboBox.setCurrentIndex(scan_type_index)
|
|
|
|
setchecked(self.matchSimilarBox, prefs.match_similar)
|
|
|
|
setchecked(self.wordWeightingBox, prefs.word_weighting)
|
|
|
|
setchecked(self.ignoreSmallFilesBox, prefs.ignore_small_files)
|
2010-08-11 14:39:06 +00:00
|
|
|
self.sizeThresholdEdit.setText(str(prefs.small_file_threshold))
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2011-01-21 12:57:54 +00:00
|
|
|
def _save(self, prefs, ischecked):
|
2009-06-01 09:55:11 +00:00
|
|
|
prefs.scan_type = SCAN_TYPE_ORDER[self.scanTypeComboBox.currentIndex()]
|
|
|
|
prefs.match_similar = ischecked(self.matchSimilarBox)
|
|
|
|
prefs.word_weighting = ischecked(self.wordWeightingBox)
|
|
|
|
prefs.ignore_small_files = ischecked(self.ignoreSmallFilesBox)
|
|
|
|
prefs.small_file_threshold = tryint(self.sizeThresholdEdit.text())
|
|
|
|
|
|
|
|
def resetToDefaults(self):
|
|
|
|
self.load(preferences.Preferences())
|
|
|
|
|
|
|
|
#--- Events
|
|
|
|
def scanTypeChanged(self, index):
|
|
|
|
scan_type = SCAN_TYPE_ORDER[self.scanTypeComboBox.currentIndex()]
|
2010-08-14 17:52:23 +00:00
|
|
|
word_based = scan_type == ScanType.Filename
|
2009-06-01 09:55:11 +00:00
|
|
|
self.filterHardnessSlider.setEnabled(word_based)
|
|
|
|
self.matchSimilarBox.setEnabled(word_based)
|
|
|
|
self.wordWeightingBox.setEnabled(word_based)
|
|
|
|
|
2010-10-04 13:29:00 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
from ..testapp import TestApp
|
|
|
|
app = QApplication([])
|
|
|
|
dgapp = TestApp()
|
|
|
|
dialog = PreferencesDialog(None, dgapp)
|
|
|
|
dialog.show()
|
2011-01-23 15:09:47 +00:00
|
|
|
sys.exit(app.exec_())
|