2016-05-25 02:53:03 +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
|
|
|
|
2013-10-20 19:15:09 +00:00
|
|
|
from PyQt5.QtCore import QSize
|
2014-10-13 19:08:59 +00:00
|
|
|
from PyQt5.QtWidgets import (
|
2016-05-25 02:53:03 +00:00
|
|
|
QVBoxLayout, QHBoxLayout, QLabel, QSizePolicy, QSpacerItem, QWidget, QLineEdit
|
2014-10-13 19:08:59 +00:00
|
|
|
)
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2011-09-22 13:32:09 +00:00
|
|
|
from hscommon.plat import ISWINDOWS, ISLINUX
|
2011-11-01 19:44:18 +00:00
|
|
|
from hscommon.trans import trget
|
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
|
|
|
|
2011-11-01 19:44:18 +00:00
|
|
|
tr = trget('ui')
|
|
|
|
|
2011-01-21 12:57:54 +00:00
|
|
|
class PreferencesDialog(PreferencesDialogBase):
|
|
|
|
def _setupPreferenceWidgets(self):
|
|
|
|
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)
|
2014-10-13 19:08:59 +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()
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-01-21 12:57:54 +00:00
|
|
|
def _setupUi(self):
|
|
|
|
PreferencesDialogBase._setupUi(self)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-09-22 13:32:09 +00:00
|
|
|
if ISLINUX:
|
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-09-27 15:24:18 +00:00
|
|
|
self.resize(self.width(), 530)
|
2011-09-22 13:32:09 +00:00
|
|
|
elif ISWINDOWS:
|
2011-09-27 15:24:18 +00:00
|
|
|
self.resize(self.width(), 440)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-01-21 12:57:54 +00:00
|
|
|
def _load(self, prefs, setchecked):
|
2009-06-01 09:55:11 +00:00
|
|
|
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))
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2016-05-29 01:54:25 +00:00
|
|
|
# Update UI state based on selected scan type
|
|
|
|
scan_type = prefs.scan_type
|
|
|
|
word_based = scan_type == ScanType.Filename
|
|
|
|
self.filterHardnessSlider.setEnabled(word_based)
|
|
|
|
self.matchSimilarBox.setEnabled(word_based)
|
|
|
|
self.wordWeightingBox.setEnabled(word_based)
|
|
|
|
|
2011-01-21 12:57:54 +00:00
|
|
|
def _save(self, prefs, ischecked):
|
2009-06-01 09:55:11 +00:00
|
|
|
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())
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
def resetToDefaults(self):
|
|
|
|
self.load(preferences.Preferences())
|
2014-10-13 19:08:59 +00:00
|
|
|
|