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
3
4
#
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.
8
9
#
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.
13
14
#
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
23
29
import qttools
24
30
import snapshots
25
31
import encfstools
26
32
import snapshotlog
27
33
import tools
28
- import messagebox
29
34
30
35
31
36
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 ):
35
38
"""
36
39
Instantiate a snapshot log file viewer
37
40
@@ -46,7 +49,6 @@ def __init__(self, parent, sid = None, systray = False):
46
49
else :
47
50
super (LogViewDialog , self ).__init__ (parent )
48
51
49
-
50
52
self .config = parent .config
51
53
self .snapshots = parent .snapshots
52
54
self .mainWindow = parent
@@ -71,15 +73,15 @@ def __init__(self, parent, sid = None, systray = False):
71
73
self .mainLayout .addLayout (layout )
72
74
73
75
# profiles
74
- self .lblProfile = QLabel (_ ('Profile' ) + ':' , self )
76
+ self .lblProfile = QLabel (_ ('Profile:' ) , self )
75
77
layout .addWidget (self .lblProfile )
76
78
77
79
self .comboProfiles = qttools .ProfileCombo (self )
78
80
layout .addWidget (self .comboProfiles , 1 )
79
81
self .comboProfiles .currentIndexChanged .connect (self .profileChanged )
80
82
81
83
# snapshots
82
- self .lblSnapshots = QLabel (_ ('Snapshots' ) + ':' , self )
84
+ self .lblSnapshots = QLabel (_ ('Snapshots:' ) , self )
83
85
layout .addWidget (self .lblSnapshots )
84
86
self .comboSnapshots = qttools .SnapshotCombo (self )
85
87
layout .addWidget (self .comboSnapshots , 1 )
@@ -88,12 +90,13 @@ def __init__(self, parent, sid = None, systray = False):
88
90
if self .sid is None :
89
91
self .lblSnapshots .hide ()
90
92
self .comboSnapshots .hide ()
93
+
91
94
if self .sid or systray :
92
95
self .lblProfile .hide ()
93
96
self .comboProfiles .hide ()
94
97
95
98
# filter
96
- layout .addWidget (QLabel (_ ('Filter' ) + ':' ))
99
+ layout .addWidget (QLabel (_ ('Filter:' ), self ))
97
100
98
101
self .comboFilter = QComboBox (self )
99
102
layout .addWidget (self .comboFilter , 1 )
@@ -122,12 +125,12 @@ def __init__(self, parent, sid = None, systray = False):
122
125
#
123
126
self .mainLayout .addWidget (QLabel (_ ('[E] Error, [I] Information, [C] Change' )))
124
127
125
- #decode path
128
+ # decode path
126
129
self .cbDecode = QCheckBox (_ ('decode paths' ), self )
127
130
self .cbDecode .stateChanged .connect (self .cbDecodeChanged )
128
131
self .mainLayout .addWidget (self .cbDecode )
129
132
130
- #buttons
133
+ # buttons
131
134
buttonBox = QDialogButtonBox (QDialogButtonBox .StandardButton .Close )
132
135
self .mainLayout .addWidget (buttonBox )
133
136
buttonBox .rejected .connect (self .close )
@@ -140,21 +143,22 @@ def __init__(self, parent, sid = None, systray = False):
140
143
self .watcher = QFileSystemWatcher (self )
141
144
if self .sid is None :
142
145
# 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 ())
144
148
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 )
149
151
150
152
def cbDecodeChanged (self ):
151
153
if self .cbDecode .isChecked ():
152
154
if not self .decode :
153
155
self .decode = encfstools .Decode (self .config )
156
+
154
157
else :
155
- if not self .decode is None :
158
+ if self .decode is not None :
156
159
self .decode .close ()
157
160
self .decode = None
161
+
158
162
self .updateLog ()
159
163
160
164
def profileChanged (self , index ):
@@ -176,59 +180,6 @@ def comboSnapshotsChanged(self, index):
176
180
def comboFilterChanged (self , index ):
177
181
self .updateLog ()
178
182
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
-
232
183
def updateProfiles (self ):
233
184
current_profile_id = self .config .currentProfile ()
234
185
@@ -263,7 +214,7 @@ def updateDecode(self):
263
214
if self .cbDecode .isChecked ():
264
215
self .cbDecode .setChecked (False )
265
216
266
- def updateLog (self , watchPath = None ):
217
+ def updateLog (self , watchPath = None ):
267
218
"""
268
219
Show the log file of the current snapshot in the GUI
269
220
0 commit comments