2012-05-30 16:10:56 +00:00
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2012-05-30
|
2015-01-03 21:30:57 +00:00
|
|
|
# Copyright 2015 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
|
2012-05-30 16:10:56 +00:00
|
|
|
|
2013-10-20 19:15:09 +00:00
|
|
|
from PyQt5.QtCore import Qt
|
|
|
|
from PyQt5.QtWidgets import QDialog, QVBoxLayout, QLabel, QCheckBox, QDialogButtonBox
|
2012-05-30 16:10:56 +00:00
|
|
|
|
|
|
|
from hscommon.trans import trget
|
2012-08-01 16:36:23 +00:00
|
|
|
from qtlib.radio_box import RadioBox
|
2012-05-30 16:10:56 +00:00
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
tr = trget("ui")
|
|
|
|
|
2012-05-30 16:10:56 +00:00
|
|
|
|
|
|
|
class DeletionOptions(QDialog):
|
2013-10-20 19:53:59 +00:00
|
|
|
def __init__(self, parent, model, **kwargs):
|
2012-05-30 16:10:56 +00:00
|
|
|
flags = Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowSystemMenuHint
|
2013-10-20 19:53:59 +00:00
|
|
|
super().__init__(parent, flags, **kwargs)
|
2012-05-30 16:10:56 +00:00
|
|
|
self.model = model
|
2013-07-14 15:58:49 +00:00
|
|
|
self._setupUi()
|
2012-05-30 16:10:56 +00:00
|
|
|
self.model.view = self
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2013-12-06 20:48:01 +00:00
|
|
|
self.linkCheckbox.stateChanged.connect(self.linkCheckboxChanged)
|
2012-05-30 16:10:56 +00:00
|
|
|
self.buttonBox.accepted.connect(self.accept)
|
|
|
|
self.buttonBox.rejected.connect(self.reject)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2012-05-30 16:10:56 +00:00
|
|
|
def _setupUi(self):
|
|
|
|
self.setWindowTitle(tr("Deletion Options"))
|
2012-08-01 16:36:23 +00:00
|
|
|
self.resize(400, 270)
|
2012-05-30 16:10:56 +00:00
|
|
|
self.verticalLayout = QVBoxLayout(self)
|
|
|
|
self.msgLabel = QLabel()
|
|
|
|
self.verticalLayout.addWidget(self.msgLabel)
|
2012-08-01 16:36:23 +00:00
|
|
|
self.linkCheckbox = QCheckBox(tr("Link deleted files"))
|
|
|
|
self.verticalLayout.addWidget(self.linkCheckbox)
|
2014-10-13 19:08:59 +00:00
|
|
|
text = tr(
|
|
|
|
"After having deleted a duplicate, place a link targeting the reference file "
|
|
|
|
"to replace the deleted file."
|
|
|
|
)
|
2012-08-01 16:36:23 +00:00
|
|
|
self.linkMessageLabel = QLabel(text)
|
|
|
|
self.linkMessageLabel.setWordWrap(True)
|
|
|
|
self.verticalLayout.addWidget(self.linkMessageLabel)
|
2020-01-01 02:16:27 +00:00
|
|
|
self.linkTypeRadio = RadioBox(
|
|
|
|
items=[tr("Symlink"), tr("Hardlink")], spread=False
|
|
|
|
)
|
2012-08-01 16:36:23 +00:00
|
|
|
self.verticalLayout.addWidget(self.linkTypeRadio)
|
2013-07-14 15:58:49 +00:00
|
|
|
if not self.model.supports_links():
|
2012-08-02 19:42:02 +00:00
|
|
|
self.linkCheckbox.setEnabled(False)
|
2013-07-14 15:58:49 +00:00
|
|
|
self.linkCheckbox.setText(self.linkCheckbox.text() + tr(" (unsupported)"))
|
2012-05-30 16:10:56 +00:00
|
|
|
self.directCheckbox = QCheckBox(tr("Directly delete files"))
|
|
|
|
self.verticalLayout.addWidget(self.directCheckbox)
|
2014-10-13 19:08:59 +00:00
|
|
|
text = tr(
|
|
|
|
"Instead of sending files to trash, delete them directly. This option is usually "
|
|
|
|
"used as a workaround when the normal deletion method doesn't work."
|
|
|
|
)
|
2012-05-30 16:10:56 +00:00
|
|
|
self.directMessageLabel = QLabel(text)
|
|
|
|
self.directMessageLabel.setWordWrap(True)
|
|
|
|
self.verticalLayout.addWidget(self.directMessageLabel)
|
|
|
|
self.buttonBox = QDialogButtonBox()
|
|
|
|
self.buttonBox.addButton(tr("Proceed"), QDialogButtonBox.AcceptRole)
|
|
|
|
self.buttonBox.addButton(tr("Cancel"), QDialogButtonBox.RejectRole)
|
|
|
|
self.verticalLayout.addWidget(self.buttonBox)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
# --- Signals
|
2013-12-06 20:48:01 +00:00
|
|
|
def linkCheckboxChanged(self, changed: int):
|
|
|
|
self.model.link_deleted = bool(changed)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
# --- model --> view
|
2013-12-06 20:48:01 +00:00
|
|
|
def update_msg(self, msg: str):
|
2012-05-30 16:10:56 +00:00
|
|
|
self.msgLabel.setText(msg)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2012-05-30 16:10:56 +00:00
|
|
|
def show(self):
|
2012-08-01 16:36:23 +00:00
|
|
|
self.linkCheckbox.setChecked(self.model.link_deleted)
|
|
|
|
self.linkTypeRadio.selected_index = 1 if self.model.use_hardlinks else 0
|
2012-05-30 16:10:56 +00:00
|
|
|
self.directCheckbox.setChecked(self.model.direct)
|
|
|
|
result = self.exec()
|
2012-08-01 16:36:23 +00:00
|
|
|
self.model.link_deleted = self.linkCheckbox.isChecked()
|
|
|
|
self.model.use_hardlinks = self.linkTypeRadio.selected_index == 1
|
2012-05-30 16:10:56 +00:00
|
|
|
self.model.direct = self.directCheckbox.isChecked()
|
|
|
|
return result == QDialog.Accepted
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2013-12-06 20:48:01 +00:00
|
|
|
def set_hardlink_option_enabled(self, is_enabled: bool):
|
|
|
|
self.linkTypeRadio.setEnabled(is_enabled)
|