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 (
|
2021-08-15 07:11:42 +00:00
|
|
|
QSpinBox,
|
2020-01-01 02:16:27 +00:00
|
|
|
QVBoxLayout,
|
|
|
|
QHBoxLayout,
|
|
|
|
QLabel,
|
|
|
|
QSizePolicy,
|
|
|
|
QSpacerItem,
|
|
|
|
QWidget,
|
2014-10-13 19:08:59 +00:00
|
|
|
)
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2011-11-01 19:44:18 +00:00
|
|
|
from hscommon.trans import trget
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2016-05-30 02:37:38 +00:00
|
|
|
from core.app import AppMode
|
2010-08-14 17:52:23 +00:00
|
|
|
from core.scanner import ScanType
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2016-06-01 01:59:31 +00:00
|
|
|
from ..preferences_dialog import PreferencesDialogBase
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
tr = trget("ui")
|
|
|
|
|
2011-11-01 19:44:18 +00:00
|
|
|
|
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)
|
2020-01-01 02:16:27 +00:00
|
|
|
self._setupAddCheckbox("wordWeightingBox", tr("Word weighting"), self.widget)
|
2010-10-04 13:29:00 +00:00
|
|
|
self.verticalLayout_4.addWidget(self.wordWeightingBox)
|
2021-08-15 09:10:18 +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)
|
2020-01-01 02:16:27 +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)
|
2021-08-15 09:10:18 +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)
|
2020-01-01 02:16:27 +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()
|
2021-08-15 09:10:18 +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)
|
2021-08-15 07:11:42 +00:00
|
|
|
self.sizeThresholdSpinBox = QSpinBox(self.widget)
|
2021-08-24 05:12:23 +00:00
|
|
|
size_policy = QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
|
|
|
|
size_policy.setHorizontalStretch(0)
|
|
|
|
size_policy.setVerticalStretch(0)
|
|
|
|
size_policy.setHeightForWidth(self.sizeThresholdSpinBox.sizePolicy().hasHeightForWidth())
|
|
|
|
self.sizeThresholdSpinBox.setSizePolicy(size_policy)
|
2021-08-28 02:28:06 +00:00
|
|
|
self.sizeThresholdSpinBox.setMaximumSize(QSize(300, 16777215))
|
2021-08-15 07:11:42 +00:00
|
|
|
self.sizeThresholdSpinBox.setRange(0, 1000000)
|
|
|
|
self.horizontalLayout_2.addWidget(self.sizeThresholdSpinBox)
|
2010-10-04 13:29:00 +00:00
|
|
|
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)
|
2021-08-24 05:12:23 +00:00
|
|
|
spacer_item1 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
|
|
|
|
self.horizontalLayout_2.addItem(spacer_item1)
|
2010-10-04 13:29:00 +00:00
|
|
|
self.verticalLayout_4.addLayout(self.horizontalLayout_2)
|
2021-08-27 10:35:54 +00:00
|
|
|
self.horizontalLayout_2a = QHBoxLayout()
|
|
|
|
self._setupAddCheckbox("ignoreLargeFilesBox", tr("Ignore files larger than"), self.widget)
|
|
|
|
self.horizontalLayout_2a.addWidget(self.ignoreLargeFilesBox)
|
|
|
|
self.sizeSaturationSpinBox = QSpinBox(self.widget)
|
|
|
|
size_policy = QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
|
|
|
|
self.sizeSaturationSpinBox.setSizePolicy(size_policy)
|
2021-08-28 02:28:06 +00:00
|
|
|
self.sizeSaturationSpinBox.setMaximumSize(QSize(300, 16777215))
|
2021-08-27 10:35:54 +00:00
|
|
|
self.sizeSaturationSpinBox.setRange(0, 1000000)
|
|
|
|
self.horizontalLayout_2a.addWidget(self.sizeSaturationSpinBox)
|
|
|
|
self.label_6a = QLabel(self.widget)
|
|
|
|
self.label_6a.setText(tr("MB"))
|
|
|
|
self.horizontalLayout_2a.addWidget(self.label_6a)
|
|
|
|
spacer_item3 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
|
|
|
|
self.horizontalLayout_2a.addItem(spacer_item3)
|
|
|
|
self.verticalLayout_4.addLayout(self.horizontalLayout_2a)
|
2021-06-21 17:03:21 +00:00
|
|
|
self.horizontalLayout_2b = QHBoxLayout()
|
|
|
|
self._setupAddCheckbox(
|
2021-08-15 07:11:42 +00:00
|
|
|
"bigFilePartialHashesBox",
|
|
|
|
tr("Partially hash files bigger than"),
|
|
|
|
self.widget,
|
2021-06-21 17:03:21 +00:00
|
|
|
)
|
|
|
|
self.horizontalLayout_2b.addWidget(self.bigFilePartialHashesBox)
|
2021-08-15 07:11:42 +00:00
|
|
|
self.bigSizeThresholdSpinBox = QSpinBox(self.widget)
|
2021-08-24 05:12:23 +00:00
|
|
|
self.bigSizeThresholdSpinBox.setSizePolicy(size_policy)
|
2021-08-28 02:28:06 +00:00
|
|
|
self.bigSizeThresholdSpinBox.setMaximumSize(QSize(300, 16777215))
|
2021-08-15 07:11:42 +00:00
|
|
|
self.bigSizeThresholdSpinBox.setRange(0, 1000000)
|
|
|
|
self.horizontalLayout_2b.addWidget(self.bigSizeThresholdSpinBox)
|
2021-06-21 17:03:21 +00:00
|
|
|
self.label_6b = QLabel(self.widget)
|
|
|
|
self.label_6b.setText(tr("MB"))
|
|
|
|
self.horizontalLayout_2b.addWidget(self.label_6b)
|
2021-08-24 05:12:23 +00:00
|
|
|
spacer_item2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
|
|
|
|
self.horizontalLayout_2b.addItem(spacer_item2)
|
2021-06-21 17:03:21 +00:00
|
|
|
self.verticalLayout_4.addLayout(self.horizontalLayout_2b)
|
2014-10-13 19:08:59 +00:00
|
|
|
self._setupAddCheckbox(
|
2020-01-01 02:16:27 +00:00
|
|
|
"ignoreHardlinkMatches",
|
|
|
|
tr("Ignore duplicates hardlinking to the same file"),
|
|
|
|
self.widget,
|
2014-10-13 19:08:59 +00:00
|
|
|
)
|
2010-10-04 13:29:00 +00:00
|
|
|
self.verticalLayout_4.addWidget(self.ignoreHardlinkMatches)
|
2021-08-15 09:10:18 +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
|
|
|
|
2020-07-20 03:04:25 +00:00
|
|
|
def _load(self, prefs, setchecked, section):
|
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)
|
2021-08-15 07:11:42 +00:00
|
|
|
self.sizeThresholdSpinBox.setValue(prefs.small_file_threshold)
|
2021-08-27 10:35:54 +00:00
|
|
|
setchecked(self.ignoreLargeFilesBox, prefs.ignore_large_files)
|
|
|
|
self.sizeSaturationSpinBox.setValue(prefs.large_file_threshold)
|
2021-06-21 17:03:21 +00:00
|
|
|
setchecked(self.bigFilePartialHashesBox, prefs.big_file_partial_hashes)
|
2021-08-15 07:11:42 +00:00
|
|
|
self.bigSizeThresholdSpinBox.setValue(prefs.big_file_size_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
|
2021-08-21 23:02:02 +00:00
|
|
|
scan_type = prefs.get_scan_type(AppMode.STANDARD)
|
|
|
|
word_based = scan_type == ScanType.FILENAME
|
2016-05-29 01:54:25 +00:00
|
|
|
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)
|
2021-08-15 07:11:42 +00:00
|
|
|
prefs.small_file_threshold = self.sizeThresholdSpinBox.value()
|
2021-08-27 10:35:54 +00:00
|
|
|
prefs.ignore_large_files = ischecked(self.ignoreLargeFilesBox)
|
|
|
|
prefs.large_file_threshold = self.sizeSaturationSpinBox.value()
|
2021-06-21 17:03:21 +00:00
|
|
|
prefs.big_file_partial_hashes = ischecked(self.bigFilePartialHashesBox)
|
2021-08-15 07:11:42 +00:00
|
|
|
prefs.big_file_size_threshold = self.bigSizeThresholdSpinBox.value()
|