Skip to content

Commit fb86465

Browse files
authored
fix(LogViewDialog): Remove Exclude, Copy and Decode context menu (bit-team#1578)
The context menu in the LogViewDialog is removed without replacement. - "Copy" is offered by Qt default context menu in this widget. - Translate to English: The function "Exclude" was not user-friendly and prone to errors. - "Decode" (only in SSH encrypted profiles) is still accessible via a check box in the same dialog window.
1 parent 73caea7 commit fb86465

File tree

2 files changed

+41
-89
lines changed

2 files changed

+41
-89
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Back In Time
22

33
Version 1.4.4-dev (development of upcoming release)
4+
* Removed: Context menu in LogViewDialog (#1578)
45
* Refactor: Replace Config.user() with getpass.getuser() (#1694)
56
* Fix: Validation of diff command settings in compare snapshots dialog (#1662) (@stcksmsh Kosta Vukicevic)
67
* Fix bug: Open symlinked folders in file view (#1476)

qt/logviewdialog.py

Lines changed: 40 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,40 @@
1-
# Back In Time
2-
# Copyright (C) 2008-2022 Oprea Dan, Bart de Koning, Richard Bailey, Germar Reitze
1+
# Back In Time
2+
# Copyright (C) 2008-2022 Oprea Dan, Bart de Koning, Richard Bailey,
3+
# Germar Reitze
34
#
4-
# This program is free software; you can redistribute it and/or modify
5-
# it under the terms of the GNU General Public License as published by
6-
# the Free Software Foundation; either version 2 of the License, or
7-
# (at your option) any later version.
5+
# This program is free software; you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation; either version 2 of the License, or
8+
# (at your option) any later version.
89
#
9-
# This program is distributed in the hope that it will be useful,
10-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
# GNU General Public License for more details.
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
1314
#
14-
# You should have received a copy of the GNU General Public License along
15-
# with this program; if not, write to the Free Software Foundation, Inc.,
16-
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17-
18-
19-
from PyQt6.QtGui import *
20-
from PyQt6.QtWidgets import *
21-
from PyQt6.QtCore import *
22-
15+
# You should have received a copy of the GNU General Public License along
16+
# with this program; if not, write to the Free Software Foundation, Inc.,
17+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
from PyQt6.QtGui import QFont
19+
from PyQt6.QtWidgets import (QDialog,
20+
QLabel,
21+
QPlainTextEdit,
22+
QVBoxLayout,
23+
QHBoxLayout,
24+
QComboBox,
25+
QDialogButtonBox,
26+
QCheckBox,
27+
)
28+
from PyQt6.QtCore import QFileSystemWatcher
2329
import qttools
2430
import snapshots
2531
import encfstools
2632
import snapshotlog
2733
import tools
28-
import messagebox
2934

3035

3136
class LogViewDialog(QDialog):
32-
# Workaround because of *-imports of Qt elements.
33-
# Remove as soon as possible.
34-
def __init__(self, parent, sid = None, systray = False):
37+
def __init__(self, parent, sid=None, systray=False):
3538
"""
3639
Instantiate a snapshot log file viewer
3740
@@ -46,7 +49,6 @@ def __init__(self, parent, sid = None, systray = False):
4649
else:
4750
super(LogViewDialog, self).__init__(parent)
4851

49-
5052
self.config = parent.config
5153
self.snapshots = parent.snapshots
5254
self.mainWindow = parent
@@ -71,15 +73,15 @@ def __init__(self, parent, sid = None, systray = False):
7173
self.mainLayout.addLayout(layout)
7274

7375
# profiles
74-
self.lblProfile = QLabel(_('Profile') + ':', self)
76+
self.lblProfile = QLabel(_('Profile:'), self)
7577
layout.addWidget(self.lblProfile)
7678

7779
self.comboProfiles = qttools.ProfileCombo(self)
7880
layout.addWidget(self.comboProfiles, 1)
7981
self.comboProfiles.currentIndexChanged.connect(self.profileChanged)
8082

8183
# snapshots
82-
self.lblSnapshots = QLabel(_('Snapshots') + ':', self)
84+
self.lblSnapshots = QLabel(_('Snapshots:'), self)
8385
layout.addWidget(self.lblSnapshots)
8486
self.comboSnapshots = qttools.SnapshotCombo(self)
8587
layout.addWidget(self.comboSnapshots, 1)
@@ -88,12 +90,13 @@ def __init__(self, parent, sid = None, systray = False):
8890
if self.sid is None:
8991
self.lblSnapshots.hide()
9092
self.comboSnapshots.hide()
93+
9194
if self.sid or systray:
9295
self.lblProfile.hide()
9396
self.comboProfiles.hide()
9497

9598
# filter
96-
layout.addWidget(QLabel(_('Filter') + ':'))
99+
layout.addWidget(QLabel(_('Filter:'), self))
97100

98101
self.comboFilter = QComboBox(self)
99102
layout.addWidget(self.comboFilter, 1)
@@ -122,12 +125,12 @@ def __init__(self, parent, sid = None, systray = False):
122125
#
123126
self.mainLayout.addWidget(QLabel(_('[E] Error, [I] Information, [C] Change')))
124127

125-
#decode path
128+
# decode path
126129
self.cbDecode = QCheckBox(_('decode paths'), self)
127130
self.cbDecode.stateChanged.connect(self.cbDecodeChanged)
128131
self.mainLayout.addWidget(self.cbDecode)
129132

130-
#buttons
133+
# buttons
131134
buttonBox = QDialogButtonBox(QDialogButtonBox.StandardButton.Close)
132135
self.mainLayout.addWidget(buttonBox)
133136
buttonBox.rejected.connect(self.close)
@@ -140,21 +143,22 @@ def __init__(self, parent, sid = None, systray = False):
140143
self.watcher = QFileSystemWatcher(self)
141144
if self.sid is None:
142145
# only watch if we show the last log
143-
log = self.config.takeSnapshotLogFile(self.comboProfiles.currentProfileID())
146+
log = self.config.takeSnapshotLogFile(
147+
self.comboProfiles.currentProfileID())
144148
self.watcher.addPath(log)
145-
self.watcher.fileChanged.connect(self.updateLog) # passes the path to the changed file to updateLog()
146-
147-
self.txtLogView.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
148-
self.txtLogView.customContextMenuRequested.connect(self.contextMenuClicked)
149+
# passes the path to the changed file to updateLog()
150+
self.watcher.fileChanged.connect(self.updateLog)
149151

150152
def cbDecodeChanged(self):
151153
if self.cbDecode.isChecked():
152154
if not self.decode:
153155
self.decode = encfstools.Decode(self.config)
156+
154157
else:
155-
if not self.decode is None:
158+
if self.decode is not None:
156159
self.decode.close()
157160
self.decode = None
161+
158162
self.updateLog()
159163

160164
def profileChanged(self, index):
@@ -176,59 +180,6 @@ def comboSnapshotsChanged(self, index):
176180
def comboFilterChanged(self, index):
177181
self.updateLog()
178182

179-
def contextMenuClicked(self, point):
180-
menu = QMenu()
181-
clipboard = qttools.createQApplication().clipboard()
182-
cursor = self.txtLogView.textCursor()
183-
184-
btnCopy = menu.addAction(_('Copy'))
185-
btnCopy.triggered.connect(lambda: clipboard.setText(cursor.selectedText()))
186-
btnCopy.setEnabled(cursor.hasSelection())
187-
188-
btnAddExclude = menu.addAction(_('Add to Exclude'))
189-
btnAddExclude.triggered.connect(self.btnAddExcludeClicked)
190-
btnAddExclude.setEnabled(cursor.hasSelection())
191-
192-
btnDecode = menu.addAction(_('Decode'))
193-
btnDecode.triggered.connect(self.btnDecodeClicked)
194-
btnDecode.setEnabled(cursor.hasSelection())
195-
btnDecode.setVisible(self.config.snapshotsMode() == 'ssh_encfs')
196-
197-
menu.exec(self.txtLogView.mapToGlobal(point))
198-
199-
def btnAddExcludeClicked(self):
200-
exclude = self.config.exclude()
201-
path = self.txtLogView.textCursor().selectedText().strip()
202-
if not path or path in exclude:
203-
return
204-
edit = QLineEdit(self)
205-
edit.setText(path)
206-
edit.setMinimumWidth(600)
207-
options = {
208-
'widget': edit,
209-
'retFunc': edit.text,
210-
'id': 'path'
211-
}
212-
confirm, opt = messagebox.warningYesNoOptions(
213-
self,
214-
_('Do you want to exclude this?'),
215-
(options, )
216-
)
217-
218-
if not confirm:
219-
return
220-
221-
exclude.append(opt['path'])
222-
self.config.setExclude(exclude)
223-
224-
def btnDecodeClicked(self):
225-
if not self.decode:
226-
self.decode = encfstools.Decode(self.config)
227-
cursor = self.txtLogView.textCursor()
228-
selection = cursor.selectedText().strip()
229-
plain = self.decode.path(selection)
230-
cursor.insertText(plain)
231-
232183
def updateProfiles(self):
233184
current_profile_id = self.config.currentProfile()
234185

@@ -263,7 +214,7 @@ def updateDecode(self):
263214
if self.cbDecode.isChecked():
264215
self.cbDecode.setChecked(False)
265216

266-
def updateLog(self, watchPath = None):
217+
def updateLog(self, watchPath=None):
267218
"""
268219
Show the log file of the current snapshot in the GUI
269220

0 commit comments

Comments
 (0)