This file is indexed.

/usr/share/backintime/gnome/snapshotsdialog.py is in backintime-gnome 1.0.34-0.1.

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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
#    Back In Time
#    Copyright (C) 2008-2009 Oprea Dan, Bart de Koning, Richard Bailey
#
#    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 os.path
import sys
import pygtk
pygtk.require("2.0")
import gtk
import gnomevfs
import gobject
import datetime
import gettext

import config
import tools
import messagebox
import gnometools
import restoredialog


_=gettext.gettext

class SnapshotsDialog(object):

    def __init__( self, snapshots, parent, path, snapshots_list, current_snapshot_id, icon_name, use_gloobus_preview ):
        self.snapshots = snapshots
        self.path = path
        self.snapshots_list = snapshots_list
        self.current_snapshot_id = current_snapshot_id
        self.icon_name = icon_name        
        self.config = snapshots.config
        self.use_gloobus_preview = use_gloobus_preview 
         
        builder = gtk.Builder()
        self.builder = builder
        self.builder.set_translation_domain('backintime')

        glade_file = os.path.join(self.config.get_app_path(), 'gnome', 'snapshotsdialog.glade')

        builder.add_from_file(glade_file)

        self.dialog = self.builder.get_object( 'SnapshotsDialog' )
        self.window = self.dialog
        self.dialog.set_transient_for( parent )

        signals = { 
            'on_list_snapshots_row_activated' : self.on_list_snapshots_row_activated,
            'on_list_snapshots_popup_menu' : self.on_list_snapshots_popup_menu,
            'on_list_snapshots_button_press_event': self.on_list_snapshots_button_press_event,
            'on_list_snapshots_drag_data_get': self.on_list_snapshots_drag_data_get,
            'on_list_snapshots_key_press_event' : self.on_list_snapshots_key_press_event,
            'on_btn_diff_with_clicked' : self.on_btn_diff_with_clicked,
            'on_btn_restore_clicked' : self.on_restore_this,
            'on_btn_delete_clicked' : self.on_btn_delete_clicked,
            'on_btn_select_all_clicked' : self.on_btn_select_all_clicked,
            'on_check_list_diff_toggled'  : self.on_check_list_diff_toggled,
            'on_check_list_equal_toggled'  : self.on_check_list_diff_toggled,
            'on_check_deep_check_toggled' : self.on_check_deep_check_toggled,
            'on_combo_equal_to_changed' : self.on_combo_equal_to_changed
        }
        
        #path
        self.edit_path = self.builder.get_object( 'edit_path' )
        
        #restore menu
        self.restore_menu = gtk.Menu()
        self.restore_menu.append(gnometools.new_menu_item(gtk.STOCK_UNDELETE, _('Restore'), self.on_restore_this))
        self.restore_menu.append(gnometools.new_menu_item(gtk.STOCK_UNDELETE, _('Restore to ...'), self.on_restore_this_to))
        self.restore_menu.show_all()
        
        self.btn_restore = self.builder.get_object('btn_restore')
        self.btn_restore.set_menu(self.restore_menu)

        #delete
        self.btn_delete = self.builder.get_object('btn_delete')

        #select all
        self.btn_select_all = self.builder.get_object('btn_select_all')

        #popup now
        #self.popup_now = gtk.Menu()
        
        #diff
        self.edit_diff_cmd = self.builder.get_object( 'edit_diff_cmd' )
        self.edit_diff_cmd_params = self.builder.get_object( 'edit_diff_cmd_params' )
        
        diff_cmd = self.config.get_str_value( 'gnome.diff.cmd', 'meld' )
        diff_cmd_params = self.config.get_str_value( 'gnome.diff.params', '%1 %2' )
        
        self.edit_diff_cmd.set_text( diff_cmd )
        self.edit_diff_cmd_params.set_text( diff_cmd_params )
        
        #setup backup folders
        self.list_snapshots = self.builder.get_object( 'list_snapshots' )
        
        # connect callbacks to widgets signals.
        builder.connect_signals(signals)
        
        text_renderer = gtk.CellRendererText()
        column = gtk.TreeViewColumn( _('Snapshots') )
        column.pack_end( text_renderer, True )
        column.add_attribute( text_renderer, 'markup', 0 )
        column.set_sort_column_id( 0 )
        self.list_snapshots.append_column( column )
        
        #display name, snapshot_id
        self.store_snapshots = gtk.ListStore( str, str )
        self.list_snapshots.set_model( self.store_snapshots )
        
        self.store_snapshots.set_sort_column_id( 0, gtk.SORT_DESCENDING )
        self.list_snapshots.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
        self.list_snapshots.get_selection().connect('changed', self.on_list_snapshots_cursor_changed)
        
        #setup diff with combo
        self.combo_diff_with = self.builder.get_object( 'combo_diff_with' )
        text_renderer = gtk.CellRendererText()
        self.combo_diff_with.pack_start( text_renderer, True )
        self.combo_diff_with.add_attribute( text_renderer, 'markup', 0 )
        self.combo_diff_with.set_model( self.store_snapshots ) #use the same store

        #setup equal to combo
        self.store_snapshots_combo_equal = gtk.ListStore( str, str )
        self.store_snapshots_combo_equal.set_sort_column_id( 0, gtk.SORT_DESCENDING )
        
        self.combo_equal_to = self.builder.get_object( 'combo_equal_to' )
        text_renderer = gtk.CellRendererText()
        self.combo_equal_to.pack_start( text_renderer, True )
        self.combo_equal_to.add_attribute( text_renderer, 'markup', 0 )
        self.combo_equal_to.set_model(self.store_snapshots_combo_equal)
        
        self.update_combo_equal_to()
        self.combo_equal_to.set_sensitive(False)

        # update snapshot list
        full_path = self.snapshots.get_snapshot_path_to( self.current_snapshot_id, self.path )
        if os.path.islink( full_path ):
            self.builder.get_object( 'check_deep_check' ).hide()
        elif os.path.isdir( full_path ):
            self.builder.get_object( 'check_list_diff' ).hide()
            self.builder.get_object('check_list_equal').hide()
            self.combo_equal_to.hide()
            self.builder.get_object( 'check_deep_check' ).hide()

        self.builder.get_object( 'check_deep_check' ).set_sensitive( False )

        self.update_snapshots()

    def update_toolbar( self ):
        snapshot_ids = self.get_list_snapshot_id(True)

        if len(snapshot_ids) <= 0:
            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.set_sensitive(enable_restore)
        self.btn_delete.set_sensitive(enable_delete)

    def on_restore_this( self, *args ):
        snapshot_id = self.get_list_snapshot_id()
        if not snapshot_id is None:
            gnometools.restore(self, snapshot_id, self.path )

    def on_restore_this_to( self, *args ):
        snapshot_id = self.get_list_snapshot_id()
        if not snapshot_id is None:
            gnometools.restore(self, snapshot_id, self.path, True )

    def on_list_snapshots_drag_data_get( self, widget, drag_context, selection_data, info, timestamp, user_param1 = None ):
        path = self.get_list_snapshot_id(index = 2)
        if not path is None:
            path = gnomevfs.escape_path_string(path)
            selection_data.set_uris( [ 'file://' + path ] )

    def on_list_snapshots_key_press_event( self, _list, event ):
        if 32 != event.keyval:
            return False

        if not self.use_gloobus_preview:
            return False

        self.open_item( True )
        return True

    def on_list_snapshots_cursor_changed( self, _list ):
        self.update_toolbar()

    def on_list_snapshots_button_press_event( self, _list, event ):
        if event.button != 3:
            return

        if len( self.store_snapshots ) <= 0:
            return

        path = self.list_snapshots.get_path_at_pos( int( event.x ), int( event.y ) )
        if path is None:
            return
        path = path[0]
    
        self.list_snapshots.get_selection().select_path( path )
        self.update_toolbar()
        self.show_popup_menu( self.list_snapshots, event.button, event.time )

    def on_list_snapshots_popup_menu( self, _list ):
        self.show_popup_menu( _list, 1, gtk.get_current_event_time() )

    def show_popup_menu( self, _list, button, time ):
        path = self.get_list_snapshot_id()
        if path is None:
            return

        #print "popup-menu"
        popup_menu = gtk.Menu()
        popup_menu.append(gnometools.new_menu_item( gtk.image_new_from_icon_name( self.icon_name, gtk.ICON_SIZE_MENU ), _('Open'), self.on_list_snapshots_row_activated ))
        popup_menu.append( gtk.SeparatorMenuItem() )
        popup_menu.append(gnometools.new_menu_item( gtk.STOCK_JUMP_TO, _('Jump to'), self.on_list_snapshots_jumpto_item ))

        if len( path ) > 1:
            popup_menu.append( gtk.SeparatorMenuItem() )
            popup_menu.append(gnometools.new_menu_item( gtk.STOCK_UNDELETE, _('Restore'), self.on_restore_this ))
            popup_menu.append(gnometools.new_menu_item( gtk.STOCK_UNDELETE, _('Restore to ...'), self.on_restore_this_to ))

        popup_menu.append(gtk.SeparatorMenuItem())
        popup_menu.append(gnometools.new_menu_item(None, _('Diff'), self.on_list_snapshots_diff_item) )

        popup_menu.show_all()
        popup_menu.popup( None, None, None, button, time )

    def on_list_snapshots_diff_item( self, widget, data = None ):
        self.on_btn_diff_with_clicked( self.builder.get_object( 'btn_diff_with' ) )

    def on_list_snapshots_jumpto_item( self, widget, data = None ):
        self.dialog.response( gtk.RESPONSE_OK )

    def on_list_snapshots_open_item( self, widget, data = None ):
        self.open_item()

    def on_btn_diff_with_clicked( self, button ):
        if len( self.store_snapshots ) < 1:
            return

        #get path from the list
        snapshot_id = self.get_list_snapshot_id()
        if snapshot_id is None:
            return
        path1 = self.snapshots.get_snapshot_path_to( snapshot_id, self.path )

        #get path from the combo
        path2 = self.snapshots.get_snapshot_path_to( self.store_snapshots.get_value( self.combo_diff_with.get_active_iter(), 1 ), self.path )

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

        diff_cmd = self.edit_diff_cmd.get_text()
        diff_cmd_params = self.edit_diff_cmd_params.get_text()

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

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

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

        #check if the command changed
        old_diff_cmd = self.config.get_str_value( 'gnome.diff.cmd', 'meld' )
        old_diff_cmd_params = self.config.get_str_value( 'gnome.diff.params', '%1 %2' )
        if diff_cmd != old_diff_cmd or diff_cmd_params != old_diff_cmd_params:
            self.config.set_str_value( 'gnome.diff.cmd', diff_cmd )
            self.config.set_str_value( 'gnome.diff.params', diff_cmd_params )
            self.config.save()

    def on_btn_delete_clicked(self, *args):
        snapshot_ids = self.get_list_snapshot_id(True)
        if len(snapshot_ids) == 0:
            return
        elif len(snapshot_ids) == 1:
            msg = _('Do you really want to delete "%(file)s" in snapshot "%(snapshot_id)s?\n') \
                    % {'file' : self.path, 'snapshot_id' : snapshot_ids[0]}
        else:
            msg = _('Do you really want to delete "%(file)s" in %(count)d snapshots?\n') \
                    % {'file' : self.path, 'count' : len(snapshot_ids)}
        msg += _('WARNING: This can not be revoked!')
        if gtk.RESPONSE_YES == messagebox.show_question(self.dialog, self.config, msg):
            for snapshot_id in snapshot_ids:
                self.snapshots.delete_path(snapshot_id, self.path)

            msg = _('Exclude "%s" from future snapshots?' % self.path)
            if gtk.RESPONSE_YES == messagebox.show_question(self.dialog, self.config, msg):
                exclude = self.config.get_exclude()
                exclude.append(self.path)
                self.config.set_exclude(exclude)
            self.update_combo_equal_to()
            self.update_snapshots()

    def on_check_list_diff_toggled( self, widget, data = None ):
        deep_btn = self.builder.get_object( 'check_deep_check' )
        diff_btn = self.builder.get_object('check_list_diff')
        equal_btn = self.builder.get_object('check_list_equal')

        if widget == diff_btn:
            equal_btn.set_sensitive(not widget.get_active())
        elif widget == equal_btn:
            diff_btn.set_sensitive(not widget.get_active())

        if diff_btn.get_active() or equal_btn.get_active() and tools.check_command("md5sum"):
            deep_btn.set_sensitive(True)
        else:
            deep_btn.set_active(False)
            deep_btn.set_sensitive( False )
        self.combo_equal_to.set_sensitive(equal_btn.get_active())
        self.update_snapshots()
        
    def on_check_deep_check_toggled( self, widget, data = None ):
        self.update_snapshots()

    def on_combo_equal_to_changed(self, *args):
        self.update_snapshots()

    def update_snapshots( self):
        self.edit_path.set_text( self.path )

        #fill snapshots
        self.store_snapshots.clear()
    
        counter = 0
        index_combo_diff_with = 0
        
        # filter snapshots for uniqueness (if requested)
        list_diff  = self.builder.get_object( 'check_list_diff' ).get_active()
        deep_check = self.builder.get_object( 'check_deep_check' ).get_active()
        list_equal_to = False
        if self.builder.get_object('check_list_equal').get_active():
            iter = self.combo_equal_to.get_active_iter()
            if not iter is None:
                list_equal_to = self.snapshots.get_snapshot_path_to( self.store_snapshots_combo_equal.get_value( iter, 1 ), self.path )
        
        snapshots_filtered = self.snapshots.filter_for( self.current_snapshot_id, self.path, self.snapshots_list, list_diff, deep_check, list_equal_to )
        
        for snapshot_id in snapshots_filtered:
            self.store_snapshots.append( [ gnometools.get_snapshot_display_markup( self.snapshots, snapshot_id ), snapshot_id ] )
            if snapshot_id == self.current_snapshot_id:
                index_combo_diff_with = counter
            counter += 1

        #select first item
        if len( self.store_snapshots ) > 0:
            iter = self.store_snapshots.get_iter_first()
            if not iter is None:
                self.list_snapshots.get_selection().select_iter( iter )
            self.combo_diff_with.set_active( index_combo_diff_with )
    
            self.builder.get_object( 'btn_diff_with' ).set_sensitive( True )
            self.combo_diff_with.set_sensitive( True )
        else:
            self.builder.get_object( 'btn_diff_with' ).set_sensitive( False )
            self.combo_diff_with.set_sensitive( False )

        self.list_snapshots.grab_focus()
        self.update_toolbar()

    def update_combo_equal_to(self):
        self.store_snapshots_combo_equal.clear()
        counter = 0
        index_combo_equal_to = 0
        snapshots_filtered = self.snapshots.filter_for(self.current_snapshot_id, self.path, self.snapshots_list)
        
        for snapshot_id in snapshots_filtered:
            self.store_snapshots_combo_equal.append( [ gnometools.get_snapshot_display_markup( self.snapshots, snapshot_id ), snapshot_id ] )
            if snapshot_id == self.current_snapshot_id:
                index_combo_equal_to = counter
            counter += 1
        
        self.combo_equal_to.set_active(index_combo_equal_to)

    def on_list_snapshots_row_activated( self, _list, path, column ):
        self.open_item()

    def open_item( self, use_gloobus_preview = False ):
        snapshot_id = self.get_list_snapshot_id()
        if snapshot_id is None:
            return
        
        path = self.snapshots.get_snapshot_path_to( snapshot_id, self.path )
        if not os.path.exists( path ):
            return

        if use_gloobus_preview:
            cmd = "gloobus-preview \"%s\" &" % path
        else:
            cmd = "gnome-open \"%s\" &" % path

        os.system( cmd )

    def get_list_snapshot_id(self, multiSelection = False, index = 1):
        paths = self.list_snapshots.get_selection().get_selected_rows()[1]
        if multiSelection:
            _list = []
            for path in paths:
                iter = self.store_snapshots.get_iter(path[0])
                if not iter is None:
                    _list.append(self.store_snapshots.get_value( iter, index ))
            return _list

        iter = self.store_snapshots.get_iter(paths[0][0])
        if iter is None:
            return None
        return self.store_snapshots.get_value(iter, index)

    def on_btn_select_all_clicked(self, *args):
        '''Select all except 'Now' '''
        def iterAllItems(self):
            iter = self.get_iter_first()
            while not iter is None:
                yield iter
                iter = self.iter_next(iter)

        self.list_snapshots.get_selection().unselect_all()
        for iter in iterAllItems(self.store_snapshots):
            if len(self.store_snapshots.get_value(iter, 1)) > 1:
                self.list_snapshots.get_selection().select_iter(iter)

    def run( self ):
        snapshot_id = None
        while True:
            ret_val = self.dialog.run()
            
            if gtk.RESPONSE_OK == ret_val: #go to
                snapshot_id = self.get_list_snapshot_id()
                break
            else:
                #cancel, close ...
                break

        self.dialog.destroy()
        return snapshot_id