This file is indexed.

/usr/share/backintime/qt4/snapshotsdialog.py is in backintime-qt4 1.1.12-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
#    Back In Time
#    Copyright (C) 2008-2016 Oprea Dan, Bart de Koning, Richard Bailey, Germar Reitze
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License along
#    with this program; if not, write to the Free Software Foundation, Inc.,
#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


import os
import gettext

from PyQt4.QtGui import *
from PyQt4.QtCore import *

import tools
import restoredialog
import messagebox
import qt4tools

_=gettext.gettext

if tools.check_command('meld'):
    DIFF_CMD = 'meld'
    DIFF_PARAMS = '%1 %2'
elif tools.check_command('kompare'):
    DIFF_CMD = 'kompare'
    DIFF_PARAMS = '%1 %2'
else:
    DIFF_CMD = 'false'
    DIFF_PARAMS = '%1 %2'

class DiffOptionsDialog( QDialog ):
    def __init__( self, parent ):
        super(DiffOptionsDialog, self).__init__(parent)
        self.config = parent.config

        import icon
        self.setWindowIcon(icon.DIFF_OPTIONS)
        self.setWindowTitle( _( 'Diff Options' ) )

        self.main_layout = QGridLayout(self)

        self.diff_cmd = self.config.get_str_value( 'qt4.diff.cmd', DIFF_CMD )
        self.diff_params = self.config.get_str_value( 'qt4.diff.params', DIFF_PARAMS )

        self.main_layout.addWidget( QLabel( _( 'Command:' ) ), 0, 0 )
        self.edit_command = QLineEdit( self.diff_cmd, self )
        self.main_layout.addWidget( self.edit_command, 0, 1 )

        self.main_layout.addWidget( QLabel( _( 'Parameters:' ) ), 1, 0 )
        self.edit_params = QLineEdit( self.diff_params, self )
        self.main_layout.addWidget( self.edit_params, 1, 1 )

        self.main_layout.addWidget( QLabel( _( 'Use %1 and %2 for path parameters' ) ), 2, 1 )

        button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
        QObject.connect(button_box, SIGNAL('accepted()'), self.accept)
        QObject.connect(button_box, SIGNAL('rejected()'), self.reject)
        self.main_layout.addWidget(button_box, 3, 0, 3, 2)

    def accept( self ):
        diff_cmd = str( self.edit_command.text().toUtf8() )
        diff_params = str( self.edit_params.text().toUtf8() )

        if diff_cmd != self.diff_cmd or diff_params != self.diff_params:
            self.config.set_str_value( 'qt4.diff.cmd', diff_cmd )
            self.config.set_str_value( 'qt4.diff.params', diff_params )
            self.config.save()

        super(DiffOptionsDialog, self).accept()


class SnapshotsDialog( QDialog ):
    def __init__( self, parent, snapshot_id, path ):
        super(SnapshotsDialog, self).__init__(parent)
        self.config = parent.config
        self.snapshots = parent.snapshots
        self.snapshots_list = parent.snapshots_list
        self.qapp = parent.qapp
        import icon

        self.snapshot_id = snapshot_id
        self.path = path

        self.setWindowIcon(icon.SNAPSHOTS)
        self.setWindowTitle(_('Snapshots'))

        self.main_layout = QVBoxLayout(self)

        #path
        self.edit_path = QLineEdit( self.path, self )
        self.edit_path.setReadOnly( True )
        self.main_layout.addWidget( self.edit_path )

        #list different snapshots only
        self.cb_only_different_snapshots = QCheckBox( _( 'List only different snapshots' ), self )
        self.main_layout.addWidget( self.cb_only_different_snapshots )
        QObject.connect( self.cb_only_different_snapshots, SIGNAL('stateChanged(int)'), self.cb_only_different_snapshots_changed )

        #list equal snapshots only
        layout = QHBoxLayout()
        self.main_layout.addLayout(layout)
        self.cb_only_equal_snapshots = QCheckBox(_('List only equal snapshots to: '), self)
        QObject.connect(self.cb_only_equal_snapshots, SIGNAL('stateChanged(int)'), self.cb_only_equal_snapshots_changed)
        layout.addWidget(self.cb_only_equal_snapshots)

        self.combo_equal_to = QComboBox(self)
        QObject.connect(self.combo_equal_to, SIGNAL('currentIndexChanged(int)'), self.on_combo_equal_to_changed)
        self.combo_equal_to.setEnabled(False)
        layout.addWidget(self.combo_equal_to)

        #deep check
        self.cb_only_different_snapshots_deep_check = QCheckBox( _( 'Deep check (more accurate, but slow)' ), self )
        self.main_layout.addWidget( self.cb_only_different_snapshots_deep_check )
        QObject.connect( self.cb_only_different_snapshots_deep_check, SIGNAL('stateChanged(int)'), self.cb_only_different_snapshots_deep_check_changed )

        #toolbar
        self.toolbar = QToolBar( self )
        self.toolbar.setFloatable( False )
        self.main_layout.addWidget( self.toolbar )

        #toolbar restore
        menu_restore = QMenu(self)
        action = menu_restore.addAction(icon.RESTORE, _('Restore') )
        QObject.connect( action, SIGNAL('triggered()'), self.restore_this )
        action = menu_restore.addAction(icon.RESTORE_TO, _('Restore to ...') )
        QObject.connect( action, SIGNAL('triggered()'), self.restore_this_to )

        self.btn_restore = self.toolbar.addAction(icon.RESTORE, _('Restore'))
        self.btn_restore.setMenu(menu_restore)
        QObject.connect( self.btn_restore, SIGNAL('triggered()'), self.restore_this )

        #btn delete
        self.btn_delete = self.toolbar.addAction(icon.DELETE_FILE, _('Delete'))
        QObject.connect(self.btn_delete, SIGNAL('triggered()'), self.on_btn_delete_clicked)

        #btn select_all
        self.btn_select_all = self.toolbar.addAction(icon.SELECT_ALL, _('Select All'))
        QObject.connect(self.btn_select_all, SIGNAL('triggered()'), self.on_btn_select_all_clicked)

        #snapshots list
        self.list_snapshots = qt4tools.TimeLine(self)
        self.main_layout.addWidget( self.list_snapshots )
        QObject.connect( self.list_snapshots, SIGNAL('itemSelectionChanged()'), self.on_list_snapshots_changed )
        QObject.connect( self.list_snapshots, SIGNAL('itemActivated(QTreeWidgetItem*, int)'), self.on_list_snapshots_executed )

        #diff
        layout = QHBoxLayout()
        self.main_layout.addLayout( layout )

        self.btn_diff = QPushButton( _('Diff'), self )
        layout.addWidget( self.btn_diff )
        QObject.connect( self.btn_diff, SIGNAL('clicked()'), self.on_btn_diff_clicked )

        self.combo_diff = QComboBox( self )
        layout.addWidget( self.combo_diff, 2 )

        #buttons
        button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
        self.btn_goto =   button_box.button(QDialogButtonBox.Ok)
        self.btn_cancel = button_box.button(QDialogButtonBox.Cancel)
        self.btn_goto.setText(_('Go To'))
        btn_diff_options = button_box.addButton(_('Diff Options'), QDialogButtonBox.HelpRole)
        btn_diff_options.setIcon(icon.DIFF_OPTIONS)

        self.main_layout.addWidget(button_box)

        QObject.connect(button_box, SIGNAL('accepted()'), self.accept)
        QObject.connect(button_box, SIGNAL('rejected()'), self.reject)
        QObject.connect(btn_diff_options, SIGNAL('clicked()'), self.on_btn_diff_options_clicked)

        #
        self.cb_only_different_snapshots_deep_check.setEnabled( False )

        full_path = self.snapshots.get_snapshot_path_to( self.snapshot_id, self.path )
        if os.path.islink( full_path ):
            self.cb_only_different_snapshots_deep_check.hide()
        elif os.path.isdir( full_path ):
            self.cb_only_different_snapshots.hide()
            self.cb_only_equal_snapshots.hide()
            self.combo_equal_to.hide()
            self.cb_only_different_snapshots_deep_check.hide()

        #update list and combobox
        self.update_snapshots_and_combo_equal_to()

    def add_snapshot_( self, snapshot_id ):
        name = self.snapshots.get_snapshot_display_name( snapshot_id )

        self.list_snapshots.addSnapshot(snapshot_id, name)

        #add to combo
        self.combo_diff.addItem( name, snapshot_id )

        if self.snapshot_id == snapshot_id:
            self.combo_diff.setCurrentIndex( self.combo_diff.count() - 1 )
        elif self.combo_diff.currentIndex() < 0:
            self.combo_diff.setCurrentIndex( 0 )

    def update_snapshots( self ):
        self.list_snapshots.clear()
        self.combo_diff.clear()

        combo_index = self.combo_equal_to.currentIndex()
        if self.cb_only_equal_snapshots.isChecked() and combo_index >= 0:
            equal_to_snapshot_id = str(self.combo_equal_to.itemData(combo_index))
            equal_to = self.snapshots.get_snapshot_path_to(equal_to_snapshot_id, self.path)
        else:
            equal_to = False
        snapshots_filtered = self.snapshots.filter_for(self.snapshot_id, self.path,
                                self.snapshots_list,
                                self.cb_only_different_snapshots.isChecked(),
                                self.cb_only_different_snapshots_deep_check.isChecked(),
                                equal_to)
        for snapshot_id in snapshots_filtered:
            self.add_snapshot_( snapshot_id )

        self.update_toolbar()

    def update_combo_equal_to(self):
        self.combo_equal_to.clear()
        snapshots_filtered = self.snapshots.filter_for(self.snapshot_id, self.path, self.snapshots_list)
        for snapshot_id in snapshots_filtered:
            name = self.snapshots.get_snapshot_display_name(snapshot_id)
            self.combo_equal_to.addItem(name, snapshot_id)

            if snapshot_id == self.snapshot_id:
                self.combo_equal_to.setCurrentIndex(self.combo_equal_to.count() - 1)
            elif self.combo_equal_to.currentIndex() < 0:
                self.combo_equal_to.setCurrentIndex(0)

    def update_snapshots_and_combo_equal_to(self):
        self.update_snapshots()
        self.update_combo_equal_to()

    def cb_only_different_snapshots_changed( self ):
        enabled = self.cb_only_different_snapshots.isChecked()
        self.cb_only_equal_snapshots.setEnabled(not enabled)
        self.cb_only_different_snapshots_deep_check.setEnabled( enabled )

        self.update_snapshots()

    def cb_only_equal_snapshots_changed( self ):
        enabled = self.cb_only_equal_snapshots.isChecked()
        self.combo_equal_to.setEnabled(enabled)
        self.cb_only_different_snapshots.setEnabled(not enabled)
        self.cb_only_different_snapshots_deep_check.setEnabled( enabled )

        self.update_snapshots()

    def cb_only_different_snapshots_deep_check_changed( self ):
        self.update_snapshots()

    def update_toolbar( self ):
        snapshot_ids = self.list_snapshots.selectedSnapshotIDs()

        if not snapshot_ids:
            enable_restore = False
            enable_delete = False
        elif len(snapshot_ids) == 1:
            enable_restore = len( snapshot_ids[0] ) > 1
            enable_delete = len( snapshot_ids[0] ) > 1
        else:
            enable_restore = False
            enable_delete = True
            for snapshot_id in snapshot_ids:
                if len(snapshot_id) <= 1:
                    enable_delete = False

        self.btn_restore.setEnabled(enable_restore)
        self.btn_delete.setEnabled(enable_delete)

    def restore_this( self ):
        snapshot_id = self.list_snapshots.currentSnapshotID()
        if len( snapshot_id ) > 1:
            restoredialog.restore( self, snapshot_id, self.path )

    def restore_this_to( self ):
        snapshot_id = self.list_snapshots.currentSnapshotID()
        if len( snapshot_id ) > 1:
            restoredialog.restore( self, snapshot_id, self.path, None )

    def on_list_snapshots_changed( self ):
        self.update_toolbar()

    def on_list_snapshots_executed( self, item, column):
        if self.qapp.keyboardModifiers() and Qt.ControlModifier:
            return

        snapshot_id = self.list_snapshots.currentSnapshotID()
        if not snapshot_id:
            return

        full_path = self.snapshots.get_snapshot_path_to( snapshot_id, self.path )
        if not os.path.exists( full_path ):
            return

        self.run = QDesktopServices.openUrl(QUrl(full_path ))

    def on_btn_diff_clicked( self ):
        snapshot_id = self.list_snapshots.currentSnapshotID()
        if not snapshot_id:
            return

        combo_index = self.combo_diff.currentIndex()
        if combo_index < 0:
            return

        snapshot2_id = str( self.combo_diff.itemData( combo_index ) )

        path1 = self.snapshots.get_snapshot_path_to( snapshot_id, self.path )
        path2 = self.snapshots.get_snapshot_path_to( snapshot2_id, self.path )

        #check if the 2 paths are different
        if path1 == path2:
            messagebox.critical( self, _('You can\'t compare a snapshot to itself') )
            return

        diff_cmd = self.config.get_str_value( 'qt4.diff.cmd', DIFF_CMD )
        diff_params = self.config.get_str_value( 'qt4.diff.params', DIFF_PARAMS )

        if not tools.check_command( diff_cmd ):
            messagebox.critical( self, _('Command not found: %s') % diff_cmd )
            return

        params = diff_params
        params = params.replace( '%1', "\"%s\"" % path1 )
        params = params.replace( '%2', "\"%s\"" % path2 )

        cmd = diff_cmd + ' ' + params + ' &'
        os.system( cmd  )

    def on_btn_diff_options_clicked( self ):
        DiffOptionsDialog( self ).exec_()

    def on_combo_equal_to_changed(self, index):
        self.update_snapshots()

    def on_btn_delete_clicked(self):
        items = self.list_snapshots.selectedItems()
        if not items:
            return
        elif len(items) == 1:
            msg = _('Do you really want to delete "%(file)s" in snapshot "%(snapshot_id)s?\n') \
                    % {'file' : self.path, 'snapshot_id' : items[0].snapshotID()}
        else:
            msg = _('Do you really want to delete "%(file)s" in %(count)d snapshots?\n') \
                    % {'file' : self.path, 'count' : len(items)}
        msg += _('WARNING: This can not be revoked!')
        if QMessageBox.Yes == messagebox.warningYesNo(self, msg):
            for item in items:
                item.setFlags(Qt.NoItemFlags)

            thread = RemoveFileThread(self, items)
            thread.started.connect(lambda: self.btn_goto.setDisabled(True))
            thread.finished.connect(lambda: self.btn_goto.setDisabled(False))
            thread.started.connect(lambda: self.btn_delete.setDisabled(True))
            thread.finished.connect(lambda: self.btn_delete.setDisabled(False))
            thread.finished.connect(self.update_snapshots_and_combo_equal_to)
            self.btn_cancel.clicked.connect(thread.terminate)
            thread.start()

            exclude = self.config.get_exclude()
            msg = _('Exclude "%s" from future snapshots?' % self.path)
            if self.path not in exclude and QMessageBox.Yes == messagebox.warningYesNo(self, msg):
                exclude.append(self.path)
                self.config.set_exclude(exclude)

    def on_btn_select_all_clicked(self):
        '''select all expect 'Now' '''
        self.list_snapshots.clearSelection()
        for item in self.list_snapshots.iterSnapshotItems():
            if len(item.snapshotID()) > 1:
                item.setSelected(True)

    def accept( self ):
        snapshot_id = self.list_snapshots.currentSnapshotID()
        if snapshot_id:
            self.snapshot_id = snapshot_id
        super(SnapshotsDialog, self).accept()

class RemoveFileThread(QThread):
    '''remove files in background thread so GUI will not freeze
    '''
    def __init__(self, parent, items):
        self.parent = parent
        self.config = parent.config
        self.snapshots = parent.snapshots
        self.items = items
        super(RemoveFileThread, self).__init__(parent)

    def run(self):
        #inhibit suspend/hibernate during delete
        self.config.inhibitCookie = tools.inhibitSuspend(toplevel_xid = self.config.xWindowId,
                                                         reason = 'deleting files')

        for item in self.items:
            self.snapshots.delete_path(item.snapshotID(), self.parent.path)
            try:
                item.setHidden(True)
            except RuntimeError:
                #item has been deleted
                #probably because user refreshed treeview
                pass

        #release inhibit suspend
        if self.config.inhibitCookie:
            self.config.inhibitCookie = tools.unInhibitSuspend(*self.config.inhibitCookie)