~tkluck/backintime/mountmonitor

« back to all changes in this revision

Viewing changes to gnome/snapshotsdialog.py

  • Committer: Timo Kluck
  • Date: 2009-11-26 22:25:01 UTC
  • mfrom: (585.1.47 trunk)
  • Revision ID: tkluck@netbook-tjk-20091126222501-6cfwq1jfud2c0m3j
* added kde support
 * removed accidentally added ¨feature¨ of a per-folder on-mount action (added by copy pasting code)
 * merge with current version in trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#    Back In Time
2
 
#    Copyright (C) 2008-2009 Oprea Dan
 
2
#    Copyright (C) 2008-2009 Oprea Dan, Bart de Koning, Richard Bailey
3
3
#
4
4
#    This program is free software; you can redistribute it and/or modify
5
5
#    it under the terms of the GNU General Public License as published by
24
24
import gtk
25
25
import gnomevfs
26
26
import gobject
27
 
import gtk.glade
28
27
import datetime
29
28
import gettext
30
29
 
38
37
_=gettext.gettext
39
38
 
40
39
 
41
 
class SnapshotsDialog:
42
 
        def __init__( self, snapshots, parent, path, snapshots_list, current_snapshot_id, icon_name ):
43
 
                self.snapshots = snapshots
44
 
                self.config = snapshots.config
45
 
 
46
 
                self.glade = gtk.glade.XML( os.path.join( self.config.get_app_path(), 'gnome', 'snapshotsdialog.glade' ), None, 'backintime' )
47
 
 
48
 
                self.path = None
49
 
                self.icon_name = None
50
 
 
51
 
                self.dialog = self.glade.get_widget( 'SnapshotsDialog' )
52
 
                self.dialog.set_transient_for( parent )
53
 
 
54
 
                signals = { 
55
 
                        'on_list_snapshots_cursor_changed' : self.on_list_snapshots_cursor_changed,
56
 
                        'on_list_snapshots_row_activated' : self.on_list_snapshots_row_activated,
57
 
                        'on_list_snapshots_popup_menu' : self.on_list_snapshots_popup_menu,
58
 
                        'on_list_snapshots_button_press_event': self.on_list_snapshots_button_press_event,
59
 
                        'on_list_snapshots_drag_data_get': self.on_list_snapshots_drag_data_get,
60
 
                        'on_btn_diff_with_clicked' : self.on_btn_diff_with_clicked,
61
 
                        'on_btn_copy_snapshot_clicked' : self.on_btn_copy_snapshot_clicked,
62
 
                        'on_btn_restore_snapshot_clicked' : self.on_btn_restore_snapshot_clicked
63
 
                        }
64
 
 
65
 
                #path
66
 
                self.edit_path = self.glade.get_widget( 'edit_path' )
67
 
 
68
 
                #diff
69
 
                self.edit_diff_cmd = self.glade.get_widget( 'edit_diff_cmd' )
70
 
                self.edit_diff_cmd_params = self.glade.get_widget( 'edit_diff_cmd_params' )
71
 
 
72
 
                diff_cmd = self.config.get_str_value( 'gnome.diff.cmd', 'meld' )
73
 
                diff_cmd_params = self.config.get_str_value( 'gnome.diff.params', '%1 %2' )
74
 
 
75
 
                self.edit_diff_cmd.set_text( diff_cmd )
76
 
                self.edit_diff_cmd_params.set_text( diff_cmd_params )
77
 
 
78
 
                #setup backup folders
79
 
                self.list_snapshots = self.glade.get_widget( 'list_snapshots' )
80
 
                self.list_snapshots.drag_source_set( gtk.gdk.BUTTON1_MASK | gtk.gdk.BUTTON3_MASK, gtk.target_list_add_uri_targets(), gtk.gdk.ACTION_COPY )
81
 
 
82
 
                self.glade.signal_autoconnect( signals )
83
 
                
84
 
                text_renderer = gtk.CellRendererText()
85
 
                column = gtk.TreeViewColumn( _('Snapshots') )
86
 
                column.pack_end( text_renderer, True )
87
 
                column.add_attribute( text_renderer, 'markup', 0 )
88
 
                column.set_sort_column_id( 0 )
89
 
                self.list_snapshots.append_column( column )
90
 
 
91
 
                #display name, snapshot_id
92
 
                self.store_snapshots = gtk.ListStore( str, str )
93
 
                self.list_snapshots.set_model( self.store_snapshots )
94
 
 
95
 
                self.store_snapshots.set_sort_column_id( 0, gtk.SORT_DESCENDING )
96
 
 
97
 
                #setup diff with combo
98
 
                self.combo_diff_with = self.glade.get_widget( 'combo_diff_with' )
99
 
                text_renderer = gtk.CellRendererText()
100
 
                self.combo_diff_with.pack_start( text_renderer, True )
101
 
                self.combo_diff_with.add_attribute( text_renderer, 'markup', 0 )
102
 
                self.combo_diff_with.set_model( self.store_snapshots ) #use the same store
103
 
 
104
 
                #UPDATE
105
 
                self.path = path
106
 
                self.icon_name = icon_name
107
 
                self.update_snapshots( current_snapshot_id, snapshots_list )
108
 
 
109
 
        def update_toolbar( self ):
110
 
                if len( self.store_snapshots ) <= 0:
111
 
                        self.glade.get_widget( 'btn_copy_snapshot' ).set_sensitive( False )
112
 
                        self.glade.get_widget( 'btn_restore_snapshot' ).set_sensitive( False )
113
 
                else:
114
 
                        self.glade.get_widget( 'btn_copy_snapshot' ).set_sensitive( True )
115
 
 
116
 
                        iter = self.list_snapshots.get_selection().get_selected()[1]
117
 
                        if iter is None:
118
 
                                self.glade.get_widget( 'btn_restore_snapshot' ).set_sensitive( False )
119
 
                        else:
120
 
                                path = self.store_snapshots.get_value( iter, 1 )
121
 
                                self.glade.get_widget( 'btn_restore_snapshot' ).set_sensitive( len( path ) > 1 )
122
 
 
123
 
        def on_btn_restore_snapshot_clicked( self, button ):
124
 
                iter = self.list_snapshots.get_selection().get_selected()[1]
125
 
                if not iter is None:
126
 
                        button.set_sensitive( False )
127
 
                        gnometools.run_gtk_update_loop()
128
 
                        self.snapshots.restore( self.store_snapshots.get_value( iter, 1 ), self.path )
129
 
                        button.set_sensitive( True )
130
 
 
131
 
        def on_btn_copy_snapshot_clicked( self, button ):
132
 
                iter = self.list_snapshots.get_selection().get_selected()[1]
133
 
                if not iter is None:
134
 
                        path = self.snapshots.get_snapshot_path_to( self.store_snapshots.get_value( iter, 1 ), self.path )
135
 
                        clipboardtools.clipboard_copy_path( path )
 
40
class SnapshotsDialog(object):
 
41
 
 
42
    def __init__( self, snapshots, parent, path, snapshots_list, current_snapshot_id, icon_name ):
 
43
        self.snapshots = snapshots
 
44
        self.config = snapshots.config
 
45
        
 
46
        builder = gtk.Builder()
 
47
        self.builder = builder
 
48
 
 
49
        glade_file = os.path.join(self.config.get_app_path(), 'gnome',
 
50
                'snapshotsdialog.glade')
 
51
 
 
52
        builder.add_from_file(glade_file)
 
53
 
 
54
        self.path = None
 
55
        self.icon_name = None
 
56
 
 
57
        self.dialog = self.builder.get_object( 'SnapshotsDialog' )
 
58
        self.dialog.set_transient_for( parent )
 
59
 
 
60
        signals = { 
 
61
            'on_list_snapshots_cursor_changed' : self.on_list_snapshots_cursor_changed,
 
62
            'on_list_snapshots_row_activated' : self.on_list_snapshots_row_activated,
 
63
            'on_list_snapshots_popup_menu' : self.on_list_snapshots_popup_menu,
 
64
            'on_list_snapshots_button_press_event': self.on_list_snapshots_button_press_event,
 
65
            'on_list_snapshots_drag_data_get': self.on_list_snapshots_drag_data_get,
 
66
            'on_btn_diff_with_clicked' : self.on_btn_diff_with_clicked,
 
67
            'on_btn_copy_snapshot_clicked' : self.on_btn_copy_snapshot_clicked,
 
68
            'on_btn_restore_snapshot_clicked' : self.on_btn_restore_snapshot_clicked
 
69
            }
 
70
 
 
71
        #path
 
72
        self.edit_path = self.builder.get_object( 'edit_path' )
 
73
 
 
74
        #diff
 
75
        self.edit_diff_cmd = self.builder.get_object( 'edit_diff_cmd' )
 
76
        self.edit_diff_cmd_params = self.builder.get_object( 'edit_diff_cmd_params' )
 
77
 
 
78
        diff_cmd = self.config.get_str_value( 'gnome.diff.cmd', 'meld' )
 
79
        diff_cmd_params = self.config.get_str_value( 'gnome.diff.params', '%1 %2' )
 
80
 
 
81
        self.edit_diff_cmd.set_text( diff_cmd )
 
82
        self.edit_diff_cmd_params.set_text( diff_cmd_params )
 
83
 
 
84
        #setup backup folders
 
85
        self.list_snapshots = self.builder.get_object( 'list_snapshots' )
 
86
        self.list_snapshots.drag_source_set( gtk.gdk.BUTTON1_MASK | gtk.gdk.BUTTON3_MASK, gtk.target_list_add_uri_targets(), gtk.gdk.ACTION_COPY )
 
87
 
 
88
        ### connect callbacks to widgets signals.
 
89
        builder.connect_signals(signals)
 
90
        
 
91
        text_renderer = gtk.CellRendererText()
 
92
        column = gtk.TreeViewColumn( _('Snapshots') )
 
93
        column.pack_end( text_renderer, True )
 
94
        column.add_attribute( text_renderer, 'markup', 0 )
 
95
        column.set_sort_column_id( 0 )
 
96
        self.list_snapshots.append_column( column )
 
97
 
 
98
        #display name, snapshot_id
 
99
        self.store_snapshots = gtk.ListStore( str, str )
 
100
        self.list_snapshots.set_model( self.store_snapshots )
 
101
 
 
102
        self.store_snapshots.set_sort_column_id( 0, gtk.SORT_DESCENDING )
 
103
 
 
104
        #setup diff with combo
 
105
        self.combo_diff_with = self.builder.get_object( 'combo_diff_with' )
 
106
        text_renderer = gtk.CellRendererText()
 
107
        self.combo_diff_with.pack_start( text_renderer, True )
 
108
        self.combo_diff_with.add_attribute( text_renderer, 'markup', 0 )
 
109
        self.combo_diff_with.set_model( self.store_snapshots ) #use the same store
 
110
 
 
111
        #UPDATE
 
112
        self.path = path
 
113
        self.icon_name = icon_name
 
114
        self.update_snapshots( current_snapshot_id, snapshots_list )
 
115
 
 
116
    def update_toolbar( self ):
 
117
        if len( self.store_snapshots ) <= 0:
 
118
            self.builder.get_object( 'btn_copy_snapshot' ).set_sensitive( False )
 
119
            self.builder.get_object( 'btn_restore_snapshot' ).set_sensitive( False )
 
120
        else:
 
121
            self.builder.get_object( 'btn_copy_snapshot' ).set_sensitive( True )
 
122
 
 
123
            iter = self.list_snapshots.get_selection().get_selected()[1]
 
124
            if iter is None:
 
125
                self.builder.get_object( 'btn_restore_snapshot' ).set_sensitive( False )
 
126
            else:
 
127
                path = self.store_snapshots.get_value( iter, 1 )
 
128
                self.builder.get_object( 'btn_restore_snapshot' ).set_sensitive( len( path ) > 1 )
 
129
 
 
130
    def on_btn_restore_snapshot_clicked( self, button ):
 
131
        iter = self.list_snapshots.get_selection().get_selected()[1]
 
132
        if not iter is None:
 
133
            button.set_sensitive( False )
 
134
            gnometools.run_gtk_update_loop()
 
135
            self.snapshots.restore( self.store_snapshots.get_value( iter, 1 ), self.path )
 
136
            button.set_sensitive( True )
 
137
 
 
138
    def on_btn_copy_snapshot_clicked( self, button ):
 
139
        iter = self.list_snapshots.get_selection().get_selected()[1]
 
140
        if not iter is None:
 
141
            path = self.snapshots.get_snapshot_path_to( self.store_snapshots.get_value( iter, 1 ), self.path )
 
142
            clipboardtools.clipboard_copy_path( path )
136
143
 
137
 
        def on_list_snapshots_drag_data_get( self, widget, drag_context, selection_data, info, timestamp, user_param1 = None ):
138
 
                iter = self.list_snapshots.get_selection().get_selected()[1]
139
 
                if not iter is None:
140
 
                        path = self.store_snapshots.get_value( iter, 2 )
141
 
                        path = gnomevfs.escape_path_string(path)
142
 
                        selection_data.set_uris( [ 'file://' + path ] )
143
 
 
144
 
        def on_list_snapshots_cursor_changed( self, list ):
145
 
                self.update_toolbar()
146
 
 
147
 
        def on_list_snapshots_button_press_event( self, list, event ):
148
 
                if event.button != 3:
149
 
                        return
150
 
 
151
 
                if len( self.store_snapshots ) <= 0:
152
 
                        return
153
 
 
154
 
                path = self.list_snapshots.get_path_at_pos( int( event.x ), int( event.y ) )
155
 
                if path is None:
156
 
                        return
157
 
                path = path[0]
158
 
        
159
 
                self.list_snapshots.get_selection().select_path( path )
160
 
                self.update_toolbar()
161
 
                self.show_popup_menu( self.list_snapshots, event.button, event.time )
162
 
 
163
 
        def on_list_snapshots_popup_menu( self, list ):
164
 
                self.showPopupMenu( list, 1, gtk.get_current_event_time() )
165
 
 
166
 
        def show_popup_menu( self, list, button, time ):
167
 
                iter = list.get_selection().get_selected()[1]
168
 
                if iter is None:
169
 
                        return
170
 
 
171
 
                #print "popup-menu"
172
 
                self.popup_menu = gtk.Menu()
173
 
 
174
 
                menu_item = gtk.ImageMenuItem( 'backintime.open' )
175
 
                menu_item.set_image( gtk.image_new_from_icon_name( self.icon_name, gtk.ICON_SIZE_MENU ) )
176
 
                menu_item.connect( 'activate', self.on_list_snapshots_open_item )
177
 
                self.popup_menu.append( menu_item )
178
 
 
179
 
                self.popup_menu.append( gtk.SeparatorMenuItem() )
180
 
 
181
 
                menu_item = gtk.ImageMenuItem( 'backintime.copy' )
182
 
                menu_item.set_image( gtk.image_new_from_stock( gtk.STOCK_COPY, gtk.ICON_SIZE_MENU ) )
183
 
                menu_item.connect( 'activate', self.on_list_snapshots_copy_item )
184
 
                self.popup_menu.append( menu_item )
185
 
 
186
 
                menu_item = gtk.ImageMenuItem( gtk.STOCK_JUMP_TO )
187
 
                menu_item.connect( 'activate', self.on_list_snapshots_jumpto_item )
188
 
                self.popup_menu.append( menu_item )
189
 
 
190
 
                path = self.store_snapshots.get_value( iter, 1 )
191
 
                if len( path ) > 1:
192
 
                        menu_item = gtk.ImageMenuItem( 'backintime.restore' )
193
 
                        menu_item.set_image( gtk.image_new_from_stock( gtk.STOCK_UNDELETE, gtk.ICON_SIZE_MENU ) )
194
 
                        menu_item.connect( 'activate', self.on_list_snapshots_restore_item )
195
 
                        self.popup_menu.append( menu_item )
196
 
 
197
 
                self.popup_menu.append( gtk.SeparatorMenuItem() )
198
 
 
199
 
                menu_item = gtk.ImageMenuItem( 'backintime.diff' )
200
 
                #menu_item.set_image( gtk.image_new_from_stock( gtk.STOCK_COPY, gtk.ICON_SIZE_MENU ) )
201
 
                menu_item.connect( 'activate', self.on_list_snapshots_diff_item )
202
 
                self.popup_menu.append( menu_item )
203
 
 
204
 
                self.popup_menu.show_all()
205
 
                self.popup_menu.popup( None, None, None, button, time )
206
 
 
207
 
        def on_list_snapshots_diff_item( self, widget, data = None ):
208
 
                self.on_btn_diff_with_clicked( self.glade.get_widget( 'btn_diff_with' ) )
209
 
 
210
 
        def on_list_snapshots_jumpto_item( self, widget, data = None ):
211
 
                self.dialog.response( gtk.RESPONSE_OK )
212
 
 
213
 
        def on_list_snapshots_open_item( self, widget, data = None ):
214
 
                self.open_item()
215
 
 
216
 
        def on_list_snapshots_restore_item( self, widget, data = None ):
217
 
                self.on_btn_restore_snapshot_clicked( self.glade.get_widget( 'btn_restore_snapshot' ) )
218
 
 
219
 
        def on_list_snapshots_copy_item( self, widget, data = None ):
220
 
                self.on_btn_copy_snapshot_clicked( self.glade.get_widget( 'btn_copy_snapshot' ) )
221
 
 
222
 
        def on_btn_diff_with_clicked( self, button ):
223
 
                if len( self.store_snapshots ) < 1:
224
 
                        return
225
 
 
226
 
                #get path from the list
227
 
                iter = self.list_snapshots.get_selection().get_selected()[1]
228
 
                if iter is None:
229
 
                        return
230
 
                path1 = self.snapshots.get_snapshot_path_to( self.store_snapshots.get_value( iter, 1 ), self.path )
231
 
 
232
 
                #get path from the combo
233
 
                path2 = self.snapshots.get_snapshot_path_to( self.store_snapshots.get_value( self.combo_diff_with.get_active_iter(), 1 ), self.path )
234
 
 
235
 
                #check if the 2 paths are different
236
 
                if path1 == path2:
237
 
                        messagebox.show_error( self.dialog, self.config, _('You can\'t compare a snapshot to itself') )
238
 
                        return
239
 
 
240
 
                diff_cmd = self.edit_diff_cmd.get_text()
241
 
                diff_cmd_params = self.edit_diff_cmd_params.get_text()
242
 
 
243
 
                if not tools.check_command( diff_cmd ):
244
 
                        messagebox.show_error( self.dialog, self.config, _('Command not found: %s') % diff_cmd )
245
 
                        return
246
 
 
247
 
                params = diff_cmd_params
248
 
                params = params.replace( '%1', "\"%s\"" % path1 )
249
 
                params = params.replace( '%2', "\"%s\"" % path2 )
250
 
 
251
 
                cmd = diff_cmd + ' ' + params + ' &'
252
 
                os.system( cmd  )
253
 
 
254
 
                #check if the command changed
255
 
                old_diff_cmd = self.config.get_str_value( 'gnome.diff.cmd', 'meld' )
256
 
                old_diff_cmd_params = self.config.get_str_value( 'gnome.diff.params', '%1 %2' )
257
 
                if diff_cmd != old_diff_cmd or diff_cmd_params != old_diff_cmd_params:
258
 
                        self.config.set_str_value( 'gnome.diff.cmd', diff_cmd )
259
 
                        self.config.set_str_value( 'gnome.diff.params', diff_cmd_params )
260
 
                        self.config.save()
261
 
 
262
 
        def update_snapshots( self, current_snapshot_id, snapshots_list ):
263
 
                self.edit_path.set_text( self.path )
264
 
 
265
 
                #fill snapshots
266
 
                self.store_snapshots.clear()
267
 
        
268
 
                path = self.snapshots.get_snapshot_path_to( current_snapshot_id, self.path )    
269
 
                isdir = os.path.isdir( path )
270
 
 
271
 
                counter = 0
272
 
                index_combo_diff_with = 0
273
 
                
274
 
                #add now
275
 
                path = self.path
276
 
                if os.path.exists( path ):
277
 
                        if os.path.isdir( path ) == isdir:
278
 
                                self.store_snapshots.append( [ gnometools.get_snapshot_display_markup( self.snapshots, '/' ), '/' ] )
279
 
                                if '/' == current_snapshot_id:
280
 
                                        indexComboDiffWith = counter
281
 
                                counter += 1
282
 
                                
283
 
                #add snapshots
284
 
                for snapshot in snapshots_list:
285
 
                        path = self.snapshots.get_snapshot_path_to( snapshot, self.path )
286
 
                        if os.path.exists( path ):
287
 
                                if os.path.isdir( path ) == isdir:
288
 
                                        self.store_snapshots.append( [ gnometools.get_snapshot_display_markup( self.snapshots, snapshot ), snapshot ] )
289
 
                                        if snapshot == current_snapshot_id:
290
 
                                                index_combo_diff_with = counter
291
 
                                        counter += 1
292
 
 
293
 
                #select first item
294
 
                if len( self.store_snapshots ) > 0:
295
 
                        iter = self.store_snapshots.get_iter_first()
296
 
                        if not iter is None:
297
 
                                self.list_snapshots.get_selection().select_iter( iter )
298
 
                        self.combo_diff_with.set_active( index_combo_diff_with )
299
 
        
300
 
                        self.glade.get_widget( 'btn_diff_with' ).set_sensitive( True )
301
 
                        self.combo_diff_with.set_sensitive( True )
302
 
                else:
303
 
                        self.glade.get_widget( 'btn_diff_with' ).set_sensitive( False )
304
 
                        self.combo_diff_with.set_sensitive( False )
305
 
 
306
 
                self.list_snapshots.grab_focus()
307
 
                self.update_toolbar()
308
 
 
309
 
        def on_list_snapshots_row_activated( self, list, path, column ):
310
 
                self.open_item()
311
 
 
312
 
        def open_item( self ):
313
 
                iter = self.list_snapshots.get_selection().get_selected()[1]
314
 
                if iter is None:
315
 
                        return
 
144
    def on_list_snapshots_drag_data_get( self, widget, drag_context, selection_data, info, timestamp, user_param1 = None ):
 
145
        iter = self.list_snapshots.get_selection().get_selected()[1]
 
146
        if not iter is None:
 
147
            path = self.store_snapshots.get_value( iter, 2 )
 
148
            path = gnomevfs.escape_path_string(path)
 
149
            selection_data.set_uris( [ 'file://' + path ] )
 
150
 
 
151
    def on_list_snapshots_cursor_changed( self, list ):
 
152
        self.update_toolbar()
 
153
 
 
154
    def on_list_snapshots_button_press_event( self, list, event ):
 
155
        if event.button != 3:
 
156
            return
 
157
 
 
158
        if len( self.store_snapshots ) <= 0:
 
159
            return
 
160
 
 
161
        path = self.list_snapshots.get_path_at_pos( int( event.x ), int( event.y ) )
 
162
        if path is None:
 
163
            return
 
164
        path = path[0]
 
165
    
 
166
        self.list_snapshots.get_selection().select_path( path )
 
167
        self.update_toolbar()
 
168
        self.show_popup_menu( self.list_snapshots, event.button, event.time )
 
169
 
 
170
    def on_list_snapshots_popup_menu( self, list ):
 
171
        self.showPopupMenu( list, 1, gtk.get_current_event_time() )
 
172
 
 
173
    def show_popup_menu( self, list, button, time ):
 
174
        iter = list.get_selection().get_selected()[1]
 
175
        if iter is None:
 
176
            return
 
177
 
 
178
        #print "popup-menu"
 
179
        self.popup_menu = gtk.Menu()
 
180
 
 
181
        menu_item = gtk.ImageMenuItem( 'backintime.open' )
 
182
        menu_item.set_image( gtk.image_new_from_icon_name( self.icon_name, gtk.ICON_SIZE_MENU ) )
 
183
        menu_item.connect( 'activate', self.on_list_snapshots_open_item )
 
184
        self.popup_menu.append( menu_item )
 
185
 
 
186
        self.popup_menu.append( gtk.SeparatorMenuItem() )
 
187
 
 
188
        menu_item = gtk.ImageMenuItem( 'backintime.copy' )
 
189
        menu_item.set_image( gtk.image_new_from_stock( gtk.STOCK_COPY, gtk.ICON_SIZE_MENU ) )
 
190
        menu_item.connect( 'activate', self.on_list_snapshots_copy_item )
 
191
        self.popup_menu.append( menu_item )
 
192
 
 
193
        menu_item = gtk.ImageMenuItem( gtk.STOCK_JUMP_TO )
 
194
        menu_item.connect( 'activate', self.on_list_snapshots_jumpto_item )
 
195
        self.popup_menu.append( menu_item )
 
196
 
 
197
        path = self.store_snapshots.get_value( iter, 1 )
 
198
        if len( path ) > 1:
 
199
            menu_item = gtk.ImageMenuItem( 'backintime.restore' )
 
200
            menu_item.set_image( gtk.image_new_from_stock( gtk.STOCK_UNDELETE, gtk.ICON_SIZE_MENU ) )
 
201
            menu_item.connect( 'activate', self.on_list_snapshots_restore_item )
 
202
            self.popup_menu.append( menu_item )
 
203
 
 
204
        self.popup_menu.append( gtk.SeparatorMenuItem() )
 
205
 
 
206
        menu_item = gtk.ImageMenuItem( 'backintime.diff' )
 
207
        #menu_item.set_image( gtk.image_new_from_stock( gtk.STOCK_COPY, gtk.ICON_SIZE_MENU ) )
 
208
        menu_item.connect( 'activate', self.on_list_snapshots_diff_item )
 
209
        self.popup_menu.append( menu_item )
 
210
 
 
211
        self.popup_menu.show_all()
 
212
        self.popup_menu.popup( None, None, None, button, time )
 
213
 
 
214
    def on_list_snapshots_diff_item( self, widget, data = None ):
 
215
        self.on_btn_diff_with_clicked( self.builder.get_object( 'btn_diff_with' ) )
 
216
 
 
217
    def on_list_snapshots_jumpto_item( self, widget, data = None ):
 
218
        self.dialog.response( gtk.RESPONSE_OK )
 
219
 
 
220
    def on_list_snapshots_open_item( self, widget, data = None ):
 
221
        self.open_item()
 
222
 
 
223
    def on_list_snapshots_restore_item( self, widget, data = None ):
 
224
        self.on_btn_restore_snapshot_clicked( self.builder.get_object( 'btn_restore_snapshot' ) )
 
225
 
 
226
    def on_list_snapshots_copy_item( self, widget, data = None ):
 
227
        self.on_btn_copy_snapshot_clicked( self.builder.get_object( 'btn_copy_snapshot' ) )
 
228
 
 
229
    def on_btn_diff_with_clicked( self, button ):
 
230
        if len( self.store_snapshots ) < 1:
 
231
            return
 
232
 
 
233
        #get path from the list
 
234
        iter = self.list_snapshots.get_selection().get_selected()[1]
 
235
        if iter is None:
 
236
            return
 
237
        path1 = self.snapshots.get_snapshot_path_to( self.store_snapshots.get_value( iter, 1 ), self.path )
 
238
 
 
239
        #get path from the combo
 
240
        path2 = self.snapshots.get_snapshot_path_to( self.store_snapshots.get_value( self.combo_diff_with.get_active_iter(), 1 ), self.path )
 
241
 
 
242
        #check if the 2 paths are different
 
243
        if path1 == path2:
 
244
            messagebox.show_error( self.dialog, self.config, _('You can\'t compare a snapshot to itself') )
 
245
            return
 
246
 
 
247
        diff_cmd = self.edit_diff_cmd.get_text()
 
248
        diff_cmd_params = self.edit_diff_cmd_params.get_text()
 
249
 
 
250
        if not tools.check_command( diff_cmd ):
 
251
            messagebox.show_error( self.dialog, self.config, _('Command not found: %s') % diff_cmd )
 
252
            return
 
253
 
 
254
        params = diff_cmd_params
 
255
        params = params.replace( '%1', "\"%s\"" % path1 )
 
256
        params = params.replace( '%2', "\"%s\"" % path2 )
 
257
 
 
258
        cmd = diff_cmd + ' ' + params + ' &'
 
259
        os.system( cmd  )
 
260
 
 
261
        #check if the command changed
 
262
        old_diff_cmd = self.config.get_str_value( 'gnome.diff.cmd', 'meld' )
 
263
        old_diff_cmd_params = self.config.get_str_value( 'gnome.diff.params', '%1 %2' )
 
264
        if diff_cmd != old_diff_cmd or diff_cmd_params != old_diff_cmd_params:
 
265
            self.config.set_str_value( 'gnome.diff.cmd', diff_cmd )
 
266
            self.config.set_str_value( 'gnome.diff.params', diff_cmd_params )
 
267
            self.config.save()
 
268
 
 
269
    def update_snapshots( self, current_snapshot_id, snapshots_list ):
 
270
        self.edit_path.set_text( self.path )
 
271
 
 
272
        #fill snapshots
 
273
        self.store_snapshots.clear()
 
274
    
 
275
        path = self.snapshots.get_snapshot_path_to( current_snapshot_id, self.path )    
 
276
        isdir = os.path.isdir( path )
 
277
 
 
278
        counter = 0
 
279
        index_combo_diff_with = 0
 
280
        
 
281
        #add now
 
282
        path = self.path
 
283
        if os.path.lexists( path ):
 
284
            if os.path.isdir( path ) == isdir:
 
285
                self.store_snapshots.append( [ gnometools.get_snapshot_display_markup( self.snapshots, '/' ), '/' ] )
 
286
                if '/' == current_snapshot_id:
 
287
                    indexComboDiffWith = counter
 
288
                counter += 1
 
289
                
 
290
        #add snapshots
 
291
        for snapshot in snapshots_list:
 
292
            path = self.snapshots.get_snapshot_path_to( snapshot, self.path )
 
293
            if os.path.lexists( path ):
 
294
                if os.path.isdir( path ) == isdir:
 
295
                    self.store_snapshots.append( [ gnometools.get_snapshot_display_markup( self.snapshots, snapshot ), snapshot ] )
 
296
                    if snapshot == current_snapshot_id:
 
297
                        index_combo_diff_with = counter
 
298
                    counter += 1
 
299
 
 
300
        #select first item
 
301
        if len( self.store_snapshots ) > 0:
 
302
            iter = self.store_snapshots.get_iter_first()
 
303
            if not iter is None:
 
304
                self.list_snapshots.get_selection().select_iter( iter )
 
305
            self.combo_diff_with.set_active( index_combo_diff_with )
 
306
    
 
307
            self.builder.get_object( 'btn_diff_with' ).set_sensitive( True )
 
308
            self.combo_diff_with.set_sensitive( True )
 
309
        else:
 
310
            self.builder.get_object( 'btn_diff_with' ).set_sensitive( False )
 
311
            self.combo_diff_with.set_sensitive( False )
 
312
 
 
313
        self.list_snapshots.grab_focus()
 
314
        self.update_toolbar()
 
315
 
 
316
    def on_list_snapshots_row_activated( self, list, path, column ):
 
317
        self.open_item()
 
318
 
 
319
    def open_item( self ):
 
320
                iter = self.list_snapshots.get_selection().get_selected()[1]
 
321
                if iter is None:
 
322
                        return
 
323
        
316
324
                path = self.snapshots.get_snapshot_path_to( self.store_snapshots.get_value( iter, 1 ), self.path )
 
325
                if not os.path.exists( path ):
 
326
                        return
 
327
 
317
328
                cmd = "gnome-open \"%s\" &" % path
318
329
                os.system( cmd )
319
330
 
320
 
        def run( self ):
321
 
                snapshot_id = None
322
 
                while True:
323
 
                        ret_val = self.dialog.run()
324
 
                        
325
 
                        if gtk.RESPONSE_OK == ret_val: #go to
326
 
                                iter = self.list_snapshots.get_selection().get_selected()[1]
327
 
                                if not iter is None:
328
 
                                        snapshot_id = self.store_snapshots.get_value( iter, 1 )
329
 
                                break
330
 
                        else:
331
 
                                #cancel, close ...
332
 
                                break
 
331
    def run( self ):
 
332
        snapshot_id = None
 
333
        while True:
 
334
            ret_val = self.dialog.run()
 
335
            
 
336
            if gtk.RESPONSE_OK == ret_val: #go to
 
337
                iter = self.list_snapshots.get_selection().get_selected()[1]
 
338
                if not iter is None:
 
339
                    snapshot_id = self.store_snapshots.get_value( iter, 1 )
 
340
                break
 
341
            else:
 
342
                #cancel, close ...
 
343
                break
333
344
 
334
 
                self.dialog.destroy()
335
 
                return snapshot_id
 
345
        self.dialog.destroy()
 
346
        return snapshot_id
336
347