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
46
self.glade = gtk.glade.XML( os.path.join( self.config.get_app_path(), 'gnome', 'snapshotsdialog.glade' ), None, 'backintime' )
51
self.dialog = self.glade.get_widget( 'SnapshotsDialog' )
52
self.dialog.set_transient_for( parent )
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
66
self.edit_path = self.glade.get_widget( 'edit_path' )
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' )
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' )
75
self.edit_diff_cmd.set_text( diff_cmd )
76
self.edit_diff_cmd_params.set_text( diff_cmd_params )
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 )
82
self.glade.signal_autoconnect( signals )
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 )
91
#display name, snapshot_id
92
self.store_snapshots = gtk.ListStore( str, str )
93
self.list_snapshots.set_model( self.store_snapshots )
95
self.store_snapshots.set_sort_column_id( 0, gtk.SORT_DESCENDING )
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
106
self.icon_name = icon_name
107
self.update_snapshots( current_snapshot_id, snapshots_list )
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 )
114
self.glade.get_widget( 'btn_copy_snapshot' ).set_sensitive( True )
116
iter = self.list_snapshots.get_selection().get_selected()[1]
118
self.glade.get_widget( 'btn_restore_snapshot' ).set_sensitive( False )
120
path = self.store_snapshots.get_value( iter, 1 )
121
self.glade.get_widget( 'btn_restore_snapshot' ).set_sensitive( len( path ) > 1 )
123
def on_btn_restore_snapshot_clicked( self, button ):
124
iter = self.list_snapshots.get_selection().get_selected()[1]
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 )
131
def on_btn_copy_snapshot_clicked( self, button ):
132
iter = self.list_snapshots.get_selection().get_selected()[1]
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):
42
def __init__( self, snapshots, parent, path, snapshots_list, current_snapshot_id, icon_name ):
43
self.snapshots = snapshots
44
self.config = snapshots.config
46
builder = gtk.Builder()
47
self.builder = builder
49
glade_file = os.path.join(self.config.get_app_path(), 'gnome',
50
'snapshotsdialog.glade')
52
builder.add_from_file(glade_file)
57
self.dialog = self.builder.get_object( 'SnapshotsDialog' )
58
self.dialog.set_transient_for( parent )
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
72
self.edit_path = self.builder.get_object( 'edit_path' )
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' )
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' )
81
self.edit_diff_cmd.set_text( diff_cmd )
82
self.edit_diff_cmd_params.set_text( diff_cmd_params )
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 )
88
### connect callbacks to widgets signals.
89
builder.connect_signals(signals)
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 )
98
#display name, snapshot_id
99
self.store_snapshots = gtk.ListStore( str, str )
100
self.list_snapshots.set_model( self.store_snapshots )
102
self.store_snapshots.set_sort_column_id( 0, gtk.SORT_DESCENDING )
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
113
self.icon_name = icon_name
114
self.update_snapshots( current_snapshot_id, snapshots_list )
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 )
121
self.builder.get_object( 'btn_copy_snapshot' ).set_sensitive( True )
123
iter = self.list_snapshots.get_selection().get_selected()[1]
125
self.builder.get_object( 'btn_restore_snapshot' ).set_sensitive( False )
127
path = self.store_snapshots.get_value( iter, 1 )
128
self.builder.get_object( 'btn_restore_snapshot' ).set_sensitive( len( path ) > 1 )
130
def on_btn_restore_snapshot_clicked( self, button ):
131
iter = self.list_snapshots.get_selection().get_selected()[1]
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 )
138
def on_btn_copy_snapshot_clicked( self, button ):
139
iter = self.list_snapshots.get_selection().get_selected()[1]
141
path = self.snapshots.get_snapshot_path_to( self.store_snapshots.get_value( iter, 1 ), self.path )
142
clipboardtools.clipboard_copy_path( path )
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]
140
path = self.store_snapshots.get_value( iter, 2 )
141
path = gnomevfs.escape_path_string(path)
142
selection_data.set_uris( [ 'file://' + path ] )
144
def on_list_snapshots_cursor_changed( self, list ):
145
self.update_toolbar()
147
def on_list_snapshots_button_press_event( self, list, event ):
148
if event.button != 3:
151
if len( self.store_snapshots ) <= 0:
154
path = self.list_snapshots.get_path_at_pos( int( event.x ), int( event.y ) )
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 )
163
def on_list_snapshots_popup_menu( self, list ):
164
self.showPopupMenu( list, 1, gtk.get_current_event_time() )
166
def show_popup_menu( self, list, button, time ):
167
iter = list.get_selection().get_selected()[1]
172
self.popup_menu = gtk.Menu()
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 )
179
self.popup_menu.append( gtk.SeparatorMenuItem() )
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 )
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 )
190
path = self.store_snapshots.get_value( iter, 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 )
197
self.popup_menu.append( gtk.SeparatorMenuItem() )
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 )
204
self.popup_menu.show_all()
205
self.popup_menu.popup( None, None, None, button, time )
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' ) )
210
def on_list_snapshots_jumpto_item( self, widget, data = None ):
211
self.dialog.response( gtk.RESPONSE_OK )
213
def on_list_snapshots_open_item( self, widget, data = None ):
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' ) )
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' ) )
222
def on_btn_diff_with_clicked( self, button ):
223
if len( self.store_snapshots ) < 1:
226
#get path from the list
227
iter = self.list_snapshots.get_selection().get_selected()[1]
230
path1 = self.snapshots.get_snapshot_path_to( self.store_snapshots.get_value( iter, 1 ), self.path )
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 )
235
#check if the 2 paths are different
237
messagebox.show_error( self.dialog, self.config, _('You can\'t compare a snapshot to itself') )
240
diff_cmd = self.edit_diff_cmd.get_text()
241
diff_cmd_params = self.edit_diff_cmd_params.get_text()
243
if not tools.check_command( diff_cmd ):
244
messagebox.show_error( self.dialog, self.config, _('Command not found: %s') % diff_cmd )
247
params = diff_cmd_params
248
params = params.replace( '%1', "\"%s\"" % path1 )
249
params = params.replace( '%2', "\"%s\"" % path2 )
251
cmd = diff_cmd + ' ' + params + ' &'
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 )
262
def update_snapshots( self, current_snapshot_id, snapshots_list ):
263
self.edit_path.set_text( self.path )
266
self.store_snapshots.clear()
268
path = self.snapshots.get_snapshot_path_to( current_snapshot_id, self.path )
269
isdir = os.path.isdir( path )
272
index_combo_diff_with = 0
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
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
294
if len( self.store_snapshots ) > 0:
295
iter = self.store_snapshots.get_iter_first()
297
self.list_snapshots.get_selection().select_iter( iter )
298
self.combo_diff_with.set_active( index_combo_diff_with )
300
self.glade.get_widget( 'btn_diff_with' ).set_sensitive( True )
301
self.combo_diff_with.set_sensitive( True )
303
self.glade.get_widget( 'btn_diff_with' ).set_sensitive( False )
304
self.combo_diff_with.set_sensitive( False )
306
self.list_snapshots.grab_focus()
307
self.update_toolbar()
309
def on_list_snapshots_row_activated( self, list, path, column ):
312
def open_item( self ):
313
iter = self.list_snapshots.get_selection().get_selected()[1]
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]
147
path = self.store_snapshots.get_value( iter, 2 )
148
path = gnomevfs.escape_path_string(path)
149
selection_data.set_uris( [ 'file://' + path ] )
151
def on_list_snapshots_cursor_changed( self, list ):
152
self.update_toolbar()
154
def on_list_snapshots_button_press_event( self, list, event ):
155
if event.button != 3:
158
if len( self.store_snapshots ) <= 0:
161
path = self.list_snapshots.get_path_at_pos( int( event.x ), int( event.y ) )
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 )
170
def on_list_snapshots_popup_menu( self, list ):
171
self.showPopupMenu( list, 1, gtk.get_current_event_time() )
173
def show_popup_menu( self, list, button, time ):
174
iter = list.get_selection().get_selected()[1]
179
self.popup_menu = gtk.Menu()
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 )
186
self.popup_menu.append( gtk.SeparatorMenuItem() )
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 )
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 )
197
path = self.store_snapshots.get_value( iter, 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 )
204
self.popup_menu.append( gtk.SeparatorMenuItem() )
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 )
211
self.popup_menu.show_all()
212
self.popup_menu.popup( None, None, None, button, time )
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' ) )
217
def on_list_snapshots_jumpto_item( self, widget, data = None ):
218
self.dialog.response( gtk.RESPONSE_OK )
220
def on_list_snapshots_open_item( self, widget, data = None ):
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' ) )
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' ) )
229
def on_btn_diff_with_clicked( self, button ):
230
if len( self.store_snapshots ) < 1:
233
#get path from the list
234
iter = self.list_snapshots.get_selection().get_selected()[1]
237
path1 = self.snapshots.get_snapshot_path_to( self.store_snapshots.get_value( iter, 1 ), self.path )
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 )
242
#check if the 2 paths are different
244
messagebox.show_error( self.dialog, self.config, _('You can\'t compare a snapshot to itself') )
247
diff_cmd = self.edit_diff_cmd.get_text()
248
diff_cmd_params = self.edit_diff_cmd_params.get_text()
250
if not tools.check_command( diff_cmd ):
251
messagebox.show_error( self.dialog, self.config, _('Command not found: %s') % diff_cmd )
254
params = diff_cmd_params
255
params = params.replace( '%1', "\"%s\"" % path1 )
256
params = params.replace( '%2', "\"%s\"" % path2 )
258
cmd = diff_cmd + ' ' + params + ' &'
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 )
269
def update_snapshots( self, current_snapshot_id, snapshots_list ):
270
self.edit_path.set_text( self.path )
273
self.store_snapshots.clear()
275
path = self.snapshots.get_snapshot_path_to( current_snapshot_id, self.path )
276
isdir = os.path.isdir( path )
279
index_combo_diff_with = 0
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
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
301
if len( self.store_snapshots ) > 0:
302
iter = self.store_snapshots.get_iter_first()
304
self.list_snapshots.get_selection().select_iter( iter )
305
self.combo_diff_with.set_active( index_combo_diff_with )
307
self.builder.get_object( 'btn_diff_with' ).set_sensitive( True )
308
self.combo_diff_with.set_sensitive( True )
310
self.builder.get_object( 'btn_diff_with' ).set_sensitive( False )
311
self.combo_diff_with.set_sensitive( False )
313
self.list_snapshots.grab_focus()
314
self.update_toolbar()
316
def on_list_snapshots_row_activated( self, list, path, column ):
319
def open_item( self ):
320
iter = self.list_snapshots.get_selection().get_selected()[1]
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 ):
317
328
cmd = "gnome-open \"%s\" &" % path
323
ret_val = self.dialog.run()
325
if gtk.RESPONSE_OK == ret_val: #go to
326
iter = self.list_snapshots.get_selection().get_selected()[1]
328
snapshot_id = self.store_snapshots.get_value( iter, 1 )
334
ret_val = self.dialog.run()
336
if gtk.RESPONSE_OK == ret_val: #go to
337
iter = self.list_snapshots.get_selection().get_selected()[1]
339
snapshot_id = self.store_snapshots.get_value( iter, 1 )
334
self.dialog.destroy()
345
self.dialog.destroy()