~hdlorean-watcher/hdlorean/watcher

« back to all changes in this revision

Viewing changes to src/gui/MainPage.py

  • Committer: Winterfuse
  • Date: 2008-04-26 18:37:39 UTC
  • mfrom: (86.4.65 testing)
  • Revision ID: adrianbn@gmail.com-20080426183739-4da142meii94zrzb
Baseline

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
#
8
8
#HDLorean is free software: you can redistribute it and/or modify
9
9
#it under the terms of the GNU General Public License as published by
10
 
#the Free Software Foundation, either version 3 of the License, or
11
 
#(at your option) any later version.
 
10
#the Free Software Foundation, either version 2 of the License.
12
11
 
13
12
#HDLorean is distributed in the hope that it will be useful,
14
13
#but WITHOUT ANY WARRANTY; without even the implied warranty of
31
30
#TODO mirar con cuidado (creo que sobra)
32
31
#import SaveBackup
33
32
import Search
34
 
import TempLine
35
33
import FromHD
36
34
import FromCD
37
35
import FromPC
38
36
import ToHD
39
37
import ToCD
40
38
import ToPC
41
 
import DBLog
42
39
import About
43
40
import Help
44
41
import List
54
51
import DebugWindow
55
52
import traceback
56
53
import urllib
 
54
import pynotify
57
55
 
58
56
class MainPage:
59
57
                
60
58
        __progressbar = gtk.ProgressBar(adjustment=None)
61
 
        __currentFilesList=None
62
59
        __allFilesList=None
63
60
        __ipath=None
64
61
        __idir=None
65
62
        __itime=None
66
 
 
67
63
        __sysTrayIcon=None
 
64
        ##@brief Flag which shows if the hdloreand.py daemon has been started
 
65
        #
 
66
        #
68
67
        __daemonStarted=False
 
68
 
69
69
        ## Progress bar in status bar class
70
70
        #
71
71
        # In this class there are some functions to manage the progress bar
72
72
        # @author Roberto Cano
73
73
        class ProgressBar:
74
74
                
75
 
                # Update the value of the progress bar so that we get
76
 
                # some movement
 
75
                ##@brief Update the value of the progress bar so that we get
 
76
                # some movement.
77
77
                def progress_timeout(pbobj):
78
78
                        if pbobj.activity_check.get_active():
79
79
                                pbobj.pbar.pulse()
90
90
                        # continues to get called
91
91
                        return True
92
92
 
93
 
        ## Refactored view class for the current files list
94
 
        #
95
 
        # @author Carlos Agra
96
 
        class CurrentFilesList:
97
 
                # Liststore & treeview for included directories & files
98
 
                __liststoreList = None
99
 
                __treeviewList = None
100
 
                # List of indexed directories & files
101
 
                __itemsAdded = []
102
 
                # @brief
103
 
                #
104
 
                # This method refresh the Liststores from the main treeview
105
 
                # @param
106
 
                # @return
107
 
                # @author Carlos Agra
108
 
                #FIXME Esto sirve para ALGOOOOOOO???????????????????????????????????????????????????????????????????
109
 
                def reloadList(self):
110
 
                        return
111
 
 
112
 
 
113
 
                        self.__itemsAdded = []
114
 
                        self.__liststoreList.clear()
115
 
                        if self.__proxy.hasSection("Lists"):
116
 
                                if self.__proxy.hasOption("Lists","whitelist"):
117
 
                                        __aux=self.__proxy.getWhiteList()                               
118
 
                                        __aux2=__aux.split(";")
119
 
                                        if __aux2[0]!= "":
120
 
                                                for i in __aux2:
121
 
                                                        self.__itemsAdded.append(i)
122
 
                                                        info = self.__proxy.getFileInfo(calendar.timegm(time.localtime()),i)
123
 
                                                        itt = self.__liststoreList.append([i,info[5],info[4],info[9]])  
124
 
                ## Constructor 
125
 
                # 
126
 
                # @param self
127
 
                # @param wTree The wTree containing the XML tree for the Glade file, passed from the MainPage
128
 
                # @param proxy The dbus-proxy used to connect to the HD Lorean backend
129
 
                # The constructor initializes the ListStore and TreeView components, and loads from the given wTree 
130
 
                # to avoid reopening the glade file
131
 
                
132
 
                def __init__(self,wTree,proxy):
133
 
                        self.__proxy = proxy
134
 
                        # Liststore & treeview for included directories & files
135
 
                        self.__liststoreList = gtk.ListStore(str,str,str,str)
136
 
                        self.__treeviewList = gtk.TreeView (self.__liststoreList)
137
 
                        ## Treeviews initializations
138
 
                        # Prepare the renderers
139
 
                        textrenderer = gtk.CellRendererText()
140
 
                        # Include initializations
141
 
                        self.__treeviewList = wTree.get_widget('treeviewList')
142
 
                        self.__treeviewList.set_model(self.__liststoreList)
143
 
                        self.__treeviewList.set_headers_visible(True)
144
 
                        # Add backup name
145
 
                        header, col, renderer = 'Name', 0, textrenderer
146
 
                        column = gtk.TreeViewColumn(header, renderer, text=col)
147
 
                        column.set_sort_column_id(col)
148
 
                        column.set_resizable(True)
149
 
                        self.__treeviewList.append_column(column)
150
 
                        # Add modify date
151
 
                        header, col,renderer = 'Modified', 1, textrenderer
152
 
                        column = gtk.TreeViewColumn(header, renderer, text=col)
153
 
                        column.set_sort_column_id(col)
154
 
                        column.set_resizable(True)
155
 
                        self.__treeviewList.append_column(column)
156
 
                        # Add Size
157
 
                        header, col, renderer = 'Size', 2, textrenderer
158
 
                        column = gtk.TreeViewColumn(header, renderer, text=col)
159
 
                        column.set_sort_column_id(col)
160
 
                        column.set_resizable(True)
161
 
                        self.__treeviewList.append_column(column)
162
 
                        # Add number of backups
163
 
                        header, col, renderer = 'Backups', 3, textrenderer
164
 
                        column = gtk.TreeViewColumn(header, renderer, text=col)
165
 
                        column.set_sort_column_id(col)
166
 
                        column.set_resizable(True)
167
 
                        self.__treeviewList.append_column(column)
168
93
        
169
 
                        # dictionary: connects the signals with the Main Window functions
170
 
                        dic = {"on_moreInfo_clicked" : self.moreInfo}
171
 
                        wTree.signal_autoconnect (dic)
172
 
                                        
173
 
                        #reload current files list
174
 
                        #self.reloadList()
175
 
                
176
 
 
177
 
                # @brief Call from more info button
178
 
                #
179
 
                # This method calls HDLorean
180
 
                # @param
181
 
                # @return
182
 
                # @author Roberto Cano Fernandez, Carlos Agra
183
 
                def moreInfo (self,widget):
184
 
                        #TODO by Carlos: cuando tengamos el archivo o directorio, pasárselo a TempLine para que muestre su info
185
 
                        #De momento sólo llama a la ventana que hizo Tabas
186
 
                        try:
187
 
                                # Returns a (TreeModel, TreeIter) tuple
188
 
                                model,itt = self.__treeviewList.get_selection().get_selected()          
189
 
                                selection = self.__liststoreList.get_value(itt, 0)      
190
 
                                #print selection        
191
 
                                app=TempLine.TempLine()
192
 
                        except:
193
 
                                #print "There is no folder selected"
194
 
                                pass
195
 
 
196
94
        ## Dual paned view containing all files recoverable through HD lorean
197
95
        #
198
96
        # Using a HPane. 
200
98
        class AllFilesList:
201
99
                
202
100
                # Paths TreeStore and treeview
203
 
                pathTreeStore = None
 
101
                __pathTreeStore = None
204
102
                __pathTreeView = None
205
 
                
 
103
                __selfMenu1 = None
 
104
                __wTree = None
 
105
                ##@brief Rows expanded.
 
106
                #
 
107
                #
 
108
                __rowsExpanded = []
 
109
                ##@brief Path row selected
 
110
                #
 
111
                #
 
112
                __pathRowSelected = None
 
113
                ##@brief Rows selected by the user.
 
114
                #
 
115
                #
 
116
                __rowsSelected = []
206
117
                # For a file, snapshots information ListStore and TreeView      
207
 
                backupsListStore = None
208
 
                backupsTreeView = None          
 
118
                __backupsListStore = None
 
119
                __backupsTreeView = None        
 
120
                __nPath = None  
 
121
                ##@brief List of paths passed to Preferences constructor to refresh properly.
 
122
                #
 
123
                #
209
124
                __pathPref = []
210
 
                # For inDepth algorithm
 
125
                # For __inDepth algorithm
211
126
                __dicTree = {}
212
 
                TARGETS = [('MY_TREE_MODEL_ROW', gtk.TARGET_SAME_WIDGET, 0),('text/plain', 0, 1),('TEXT', 0, 2),('STRING', 0, 3),]      
213
 
                TARGETS2 = [('MY_TREE_MODEL_ROW', gtk.TARGET_SAME_WIDGET, 0),('text/uri-list', 0, 0),('TEXT', 0, 2),('STRING', 0, 3),]  
 
127
                ##@brief Type of targets for the drag'n drop.
 
128
                #
 
129
                #
 
130
                __targets = [('MY_TREE_MODEL_ROW', gtk.TARGET_SAME_WIDGET, 0),('text/plain', 0, 1),('TEXT', 0, 2),('STRING', 0, 3),]    
 
131
                __backupsForLabel = None
 
132
                __selectedFileLabel = None
 
133
                __main = None
 
134
                ##@brief Constructor.
 
135
                # 
 
136
                # @param self
 
137
                # @param wTree The wTree containing the XML tree for the Glade file, passed from the MainPage
 
138
                # @param proxy The dbus-proxy used to connect to the HD Lorean backend
 
139
                # The constructor initializes the ListStore and TreeView components, and loads from the given wTree 
 
140
                # to avoid reopening the glade file             
 
141
                def __init__(self,wTree,proxy,main):
 
142
                        self.__main = main
 
143
                        self.__wTree = wTree
 
144
                        self.refreshTree(wTree,proxy,True)
 
145
 
 
146
                ##@brief gets the backupliststore.
 
147
                #
 
148
                # @param self
 
149
                # @return returns the backupsliststore object
 
150
                # @author Daniel Tabas
 
151
                def getBackupsListStore(self):
 
152
                        return self.__backupsListStore
 
153
                
 
154
                ##@brief gets the backupstreeview.
 
155
                #
 
156
                # @param self
 
157
                # @return returns the backupstreeview object
 
158
                # @author Daniel Tabas          
 
159
                def getBackupsTreeView(self):
 
160
                        return self.__backupsTreeView
 
161
 
214
162
                ##@brief Populate __dicTree with backward recursivity
215
163
                #
216
 
                #
217
 
                def processPath(self,path):
 
164
                # @param self
 
165
                # @param path path which is being processed.
 
166
                def __processPath(self,path):
218
167
                        parent, name = os.path.split(path)
219
168
                        if name:
220
 
                                self.processPath(parent)
 
169
                                self.__processPath(parent)
221
170
                                if path not in self.__dicTree:
222
171
                                        if os.path.isfile(path):
223
 
                                                self.__dicTree[path] = self.pathTreeStore.append(self.__dicTree[parent],[self.get_icon_pixbuf('STOCK_FILE'),name,path])
224
 
                                        else:
225
 
                                                self.__dicTree[path] = self.pathTreeStore.append(self.__dicTree[parent],[self.get_icon_pixbuf('STOCK_DIRECTORY'),name,path])
 
172
                                                self.__dicTree[path] = self.__pathTreeStore.append(self.__dicTree[parent],[self.__get_icon_pixbuf('STOCK_FILE'),name,path])
 
173
                                        elif os.path.isdir(path):
 
174
                                                self.__dicTree[path] = self.__pathTreeStore.append(self.__dicTree[parent],[self.__get_icon_pixbuf('STOCK_DIRECTORY'),name,path])
 
175
                                        else: 
 
176
                                                self.__dicTree[path] = self.__pathTreeStore.append(self.__dicTree[parent],[self.__get_icon_pixbuf('STOCK_SAVE'),name,path])
226
177
                        else:
227
178
                                if path not in self.__dicTree:
228
179
                                        if os.path.isfile(path):
229
 
                                                self.__dicTree[path] = self.pathTreeStore.append(None,[self.get_icon_pixbuf('STOCK_FILE'),parent,path])
 
180
                                                self.__dicTree[path] = self.__pathTreeStore.append(None,[self.__get_icon_pixbuf('STOCK_FILE'),parent,path])
 
181
                                        elif os.path.isdir(path):
 
182
                                                self.__dicTree[path] = self.__pathTreeStore.append(None,[self.__get_icon_pixbuf('STOCK_DIRECTORY'),parent,path])
230
183
                                        else:
231
 
                                                self.__dicTree[path] = self.pathTreeStore.append(None,[self.get_icon_pixbuf('STOCK_DIRECTORY'),parent,path])
 
184
                                                self.__dicTree[path] = self.__pathTreeStore.append(None,[self.__get_icon_pixbuf('STOCK_SAVE'),parent,path])
232
185
                
233
186
                ##@brief Buid the file tree of monitorized system
234
187
                #
235
 
                #
236
 
                def inDepth(self,list):
 
188
                # @param self
 
189
                # @param list
 
190
                def __inDepth(self,list):
237
191
                        self.__dicTree = {}
238
192
                        for entry in list:
239
 
                                self.processPath(entry[0])
 
193
                                self.__processPath(entry[0])
240
194
                                                
241
 
                ## Constructor 
242
 
                # 
 
195
                ##@brief Refresh the treeview of the left.
 
196
                #
243
197
                # @param self
244
 
                # @param wTree The wTree containing the XML tree for the Glade file, passed from the MainPage
245
 
                # @param proxy The dbus-proxy used to connect to the HD Lorean backend
246
 
                # The constructor initializes the ListStore and TreeView components, and loads from the given wTree 
247
 
                # to avoid reopening the glade file             
248
 
                def __init__(self,wTree,proxy):
249
 
                        self.refreshTree(wTree,proxy,True)
250
 
 
 
198
                # @param wTree The glade object.
 
199
                # @param proxy Dbus proxy to access to backend functions.
 
200
                # @param first Flag to show the function if it's the first time call.
251
201
                def refreshTree(self,wTree,proxy,first):
252
 
                        self.backupsForLabel = wTree.get_widget("backupsForLabel")
253
 
                        self.selectedFileLabel = wTree.get_widget("selectedFileLabel")
 
202
                        self.__backupsForLabel = wTree.get_widget("backupsForLabel")
 
203
                        self.__selectedFileLabel = wTree.get_widget("selectedFileLabel")
254
204
                        #Paths
255
 
                        self.pathTreeStore = gtk.TreeStore(gtk.gdk.Pixbuf, str,str)
 
205
                        self.__pathTreeStore = gtk.TreeStore(gtk.gdk.Pixbuf, str,str)
256
206
                        self.__pathTreeView = wTree.get_widget("pathTreeView")
257
 
                        self.__pathTreeView.set_model(self.pathTreeStore)
 
207
                        self.__pathTreeView.set_model(self.__pathTreeStore)
258
208
                
259
 
                        self.backupsListStore = gtk.ListStore(str,str,str,str,int,str)
260
 
                        self.backupsTreeView = wTree.get_widget("snapshotsTreeView")
261
 
                        self.backupsTreeView.set_reorderable(False)
262
 
                        self.backupsTreeView.set_model(self.backupsListStore)
 
209
                        self.__backupsListStore = gtk.ListStore(str,str,str,str,int,str)
 
210
                        self.__backupsTreeView = wTree.get_widget("snapshotsTreeView")
 
211
                        self.__backupsTreeView.set_reorderable(False)
 
212
                        self.__backupsTreeView.set_model(self.__backupsListStore)
 
213
                        self.__backupsTreeView.set_rubber_banding(True)
 
214
                        self.__backupsTreeView.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
 
215
                        
263
216
                        #Enable the selection callbacks
264
217
                        __pathSel = self.__pathTreeView.get_selection()
265
218
                        __pathSel.connect('changed', self.on_pathTree_selection_changed)
266
219
                        
267
 
                        __snapshotSel = self.backupsTreeView.get_selection()
 
220
                        __snapshotSel = self.__backupsTreeView.get_selection()
268
221
                        __snapshotSel.connect('changed', self.on_snapshotList_selection_changed)
269
222
                
270
223
                        #TODO refactor to use TreeViewColumn and append_column
271
224
                        # create the TreeViewColumn to display the data
272
225
                        if first:
273
 
                                self.__pathTreeView.enable_model_drag_source( gtk.gdk.BUTTON1_MASK,self.TARGETS,gtk.gdk.ACTION_DEFAULT|gtk.gdk.ACTION_MOVE)
274
 
                                self.__pathTreeView.enable_model_drag_dest(self.TARGETS,gtk.gdk.ACTION_DEFAULT)
275
 
                                self.__pathTreeView.connect("drag_data_received",self.drag_data_received_data)
276
 
                                self.backupsTreeView.enable_model_drag_source( gtk.gdk.BUTTON1_MASK,self.TARGETS2,gtk.gdk.ACTION_DEFAULT|gtk.gdk.ACTION_MOVE)
277
 
                                self.backupsTreeView.enable_model_drag_dest(self.TARGETS2,gtk.gdk.ACTION_DEFAULT)
278
 
                                self.backupsTreeView.drag_source_set(gtk.gdk.BUTTON1_MASK, [ ( "text/plain", 0, 80 ) ], gtk.gdk.ACTION_COPY)                    
279
 
                                self.backupsTreeView.connect("drag_data_get", self.drag_data_get_data)
280
 
                                #FIXME by Karl: aqui es donde se puede estar paqueteando si fallan los iconos           
 
226
                                self.__pathTreeView.enable_model_drag_source( gtk.gdk.BUTTON1_MASK,self.__targets,gtk.gdk.ACTION_DEFAULT|gtk.gdk.ACTION_MOVE)
 
227
                                self.__pathTreeView.enable_model_drag_dest(self.__targets,gtk.gdk.ACTION_DEFAULT)
 
228
                                self.__pathTreeView.connect("drag_data_received",self.dragDataReceivedData)
 
229
                                self.__pathTreeView.connect("row-expanded",self.rowExpanded)
 
230
                                self.__pathTreeView.connect("row-collapsed",self.rowCollapsed)
 
231
                                self.__pathTreeView.connect("button-press-event",self.pathPressCb)
 
232
                                self.__backupsTreeView.connect("button-press-event",self.buttonPressCb)
281
233
                                self.__pathCol = gtk.TreeViewColumn('Path')
282
234
                                render_pixbuf = gtk.CellRendererPixbuf()
283
235
                                self.__pathCol.pack_start(render_pixbuf, False)
296
248
                                self.__pathCol.pack_start(self.__pathCell, True)
297
249
                
298
250
                                # set the cell "text" attribute to column 0 - retrieve text
299
 
                                # from that column in pathTreeStore
300
 
                                self.__pathCol.add_attribute(self.__pathCell, 'text', 0)
 
251
                                # from that column in __pathTreeStore
 
252
                                # FIXME by Karl: eliminating Bug #212765 by deleting this instruction. La dejo comentada un tiempo por si acaso
 
253
                                #self.__pathCol.add_attribute(self.__pathCell, 'text', 0)
301
254
                                self.__snapshotsCol = gtk.TreeViewColumn('ID',gtk.CellRendererText(), text=0)
302
 
                                self.backupsTreeView.append_column(self.__snapshotsCol)         
 
255
                                self.__backupsTreeView.append_column(self.__snapshotsCol)               
303
256
                
304
257
                                
305
258
                                self.__snapshotsCol = gtk.TreeViewColumn('Date',gtk.CellRendererText(), text=1)
306
 
                                self.backupsTreeView.append_column(self.__snapshotsCol)         
 
259
                                self.__backupsTreeView.append_column(self.__snapshotsCol)               
307
260
                
308
261
                                self.__snapshotsCol = gtk.TreeViewColumn('Size',gtk.CellRendererText(), text=2)
309
 
                                self.backupsTreeView.append_column(self.__snapshotsCol)         
 
262
                                self.__backupsTreeView.append_column(self.__snapshotsCol)               
310
263
                
311
264
                
312
265
                                self.__snapshotsCol = gtk.TreeViewColumn('Operation',gtk.CellRendererText(), text=3)
313
 
                                self.backupsTreeView.append_column(self.__snapshotsCol)         
314
 
                
 
266
                                self.__backupsTreeView.append_column(self.__snapshotsCol)       
 
267
        
315
268
                        self.__proxy = proxy
316
269
                        rootDir = self.__proxy.getCompleteDirList("/")
317
 
                        self.inDepth(rootDir)
 
270
                        self.__inDepth(rootDir)
 
271
                        self.__expandPaths()
 
272
                        self.__selectOldPath()
 
273
 
 
274
                ## @brief Callback to the signal press button in the right treeview, in order to popup a menu.
 
275
                #
 
276
                #
 
277
                # @param self
 
278
                # @param widget
 
279
                # @param event
 
280
                # @return returns a boolean, to stop propagating the signal(para que no deseleccione vamos).
 
281
                # @author Daniel Tabas
 
282
                def buttonPressCb(self,widget,event):
 
283
                        if event.button == 3:
 
284
                                self.__menu1 = gtk.Menu()
 
285
                                menuItem = gtk.ImageMenuItem('Restore')
 
286
                                img = gtk.image_new_from_stock(gtk.STOCK_UNDO, gtk.ICON_SIZE_MENU)
 
287
                                menuItem.set_image(img)
 
288
                                menuItem.connect('activate', self.restCb,"Restore")
 
289
                                self.__menu1.append(menuItem)
 
290
                                menuItem = gtk.ImageMenuItem('Delete')
 
291
                                img = gtk.image_new_from_stock(gtk.STOCK_DELETE, gtk.ICON_SIZE_MENU)
 
292
                                menuItem.set_image(img)
 
293
                                menuItem.connect('activate', self.delCb,"Delete")
 
294
                                self.__menu1.append(menuItem)
 
295
                                self.__menu1.show_all()
 
296
                                self.__menu1.popup(None, None, None, 3, event.time)
 
297
                                return True
 
298
                
 
299
                ## @brief Callback to the signal press button in the right treeview, in order to popup a menu.
 
300
                #
 
301
                #
 
302
                # @param self
 
303
                # @param widget
 
304
                # @param event
 
305
                # @return returns a boolean, to stop propagating the signal(para que no deseleccione vamos).
 
306
                # @author Daniel Tabas
 
307
                def pathPressCb(self,widget,event):
 
308
                        if event.button == 3:
 
309
                                self.__menu1 = gtk.Menu()
 
310
                                menuItem = gtk.ImageMenuItem('Make Backup')
 
311
                                img = gtk.image_new_from_stock(gtk.STOCK_SAVE, gtk.ICON_SIZE_MENU)
 
312
                                menuItem.set_image(img)
 
313
                                menuItem.connect('activate', self.backupCb,"Make Backup")
 
314
                                self.__menu1.append(menuItem)
 
315
                                self.__menu1.show_all()
 
316
                                self.__menu1.popup(None, None, None, 3, event.time)
 
317
                                return True
 
318
 
 
319
                ## @brief Callback to save menu item
 
320
                #
 
321
                # @param self
 
322
                # @param widget
 
323
                # @param data
 
324
                # @author Daniel Tabas
 
325
                def backupCb(self,widget, data = None):
 
326
                        if data:
 
327
                                self.__main.saveBackup(self.__wTree)
 
328
 
 
329
                ## @brief Callback to restore menu item
 
330
                #
 
331
                # @param self
 
332
                # @param widget
 
333
                # @param data
 
334
                # @author Daniel Tabas
 
335
                def restCb(self,widget, data = None):
 
336
                        if data:
 
337
                                self.__main.restWithoutOver(self.__wTree)
 
338
 
 
339
                ## @brief Callback to delete menu item
 
340
                #
 
341
                # @param self
 
342
                # @param widget
 
343
                # @param data
 
344
                # @author Daniel Tabas
 
345
                def delCb(self,widget, data = None):
 
346
                        if data:
 
347
                                self.__main.deleteOne(self.__wTree)
 
348
 
 
349
 
 
350
                ## @brief Method that re-expand the rows that where expanded before the treeview collapsed
 
351
                #
 
352
                # @param self
 
353
                # @author Carlos Agra
 
354
                def __expandPaths(self):
 
355
                        for i in self.__rowsExpanded:
 
356
                                self.__pathTreeView.expand_to_path(i)
 
357
                                
 
358
                ## @brief Method that re-select the row that was selected before the treeview collapsed
 
359
                #
 
360
                # @param self
 
361
                # @author Carlos Agra
 
362
                def __selectOldPath(self):
 
363
                        if self.__pathRowSelected != None:
 
364
                                self.__pathTreeView.get_selection().select_path(self.__pathRowSelected)                                         
318
365
                
319
366
                #FIXME by Karl: método copy paste de otra aplicacion, para hacer trastadas con iconos
320
367
                ## Select an icon from the stock items of gtk           
321
368
                # 
322
369
                # @param self
323
370
                # @param stock The concrete icon from the stock that we will return
324
 
                def get_icon_pixbuf(self, stock):
 
371
                def __get_icon_pixbuf(self, stock):
325
372
                        return self.__pathTreeView.render_icon(stock_id=getattr(gtk, stock),
326
373
                                size=gtk.ICON_SIZE_MENU,
327
374
                                detail=None)    
328
375
                
329
 
                ## update the listModel containing the snapshots info
 
376
                ## @brief update the listModel containing the snapshots info.
330
377
                #       
331
 
                # @param self duh
332
 
                # @param selected The selected file path, given in a string
333
 
                #
334
 
                # For a given path, it checks through the proxy and updates the shown info, activating
 
378
                #For a given path, it checks through the proxy and updates the shown info, activating
335
379
                # the label if we have information to show as to provide some feedback. 
 
380
                #
 
381
                # @param self 
 
382
                # @param selected The selected file path, given in a string. 
336
383
                # @author Carlos Agra
337
384
                def updateSnapshotModel(self,selected):
338
385
                        historical = self.__proxy.getHistorical(selected)               
339
 
                        self.backupsListStore.clear()
 
386
                        self.__backupsListStore.clear()
340
387
                        if historical: 
341
 
                                self.backupsForLabel.set_sensitive(True)
342
 
                                self.selectedFileLabel.set_sensitive(True)
 
388
                                self.__backupsForLabel.set_sensitive(True)
 
389
                                self.__selectedFileLabel.set_sensitive(True)
343
390
                                id = 1
344
391
                                for backup in historical:
345
392
                                        sizeOfBackup = self.convertHumanReadable(backup[4])
346
 
                                        self.backupsListStore.append([str(id),backup[5],sizeOfBackup,backup[6],backup[-1],backup[1]])
 
393
                                        self.__backupsListStore.append([str(id),backup[5],sizeOfBackup,backup[6],backup[-1],backup[1]])
347
394
                                        id = id + 1
348
395
                
349
 
                ## convert a given bytes size to human readable size
 
396
                ## @brief Convert a given bytes size to human readable size.
350
397
                #       
351
398
                # @param self
352
 
                # @param size The size to convert
 
399
                # @param size The size to convert.
353
400
                # @author Carlos Agra
354
401
                def convertHumanReadable(self,size):
355
402
                        size = long(size)
356
 
                        if size != 0:
 
403
                        if size < 1024.0:
 
404
                                size = str(size)                                        
 
405
                                size = size + ' B'
 
406
                                return size                     
 
407
                        size = size / 1024.0
 
408
                        if size > 1024.0:
357
409
                                size = size / 1024.0
358
 
                                if size > 1024.0:
359
 
                                        size = size / 1024.0
360
 
                                        i = 0
361
 
                                        tam = ''
362
 
                                        size = str(size)
363
 
                                        while size[i] != '.':
364
 
                                                tam = tam + size[i]
365
 
                                                i = i + 1
366
 
                                        tam = tam + size [i] + size [i+1]                                       
367
 
                                        size = tam + ' MB'
368
 
                                else:
369
 
                                        i = 0
370
 
                                        tam = ''
371
 
                                        size = str(size)
372
 
                                        while size[i] != '.':
373
 
                                                tam = tam + size[i]
374
 
                                                i = i + 1
375
 
                                        tam = tam + size [i] + size [i+1] 
376
 
                                        size = tam + ' KB'
377
 
                                return size
 
410
                                i = 0
 
411
                                tam = ''
 
412
                                size = str(size)
 
413
                                while size[i] != '.':
 
414
                                        tam = tam + size[i]
 
415
                                        i = i + 1
 
416
                                tam = tam + size [i] + size [i+1]                                       
 
417
                                size = tam + ' MB'
378
418
                        else:
379
 
                                size = str(size) + ' KB'
380
 
                                return size
 
419
                                i = 0
 
420
                                tam = ''
 
421
                                size = str(size)
 
422
                                while size[i] != '.':
 
423
                                        tam = tam + size[i]
 
424
                                        i = i + 1
 
425
                                tam = tam + size [i] + size [i+1] 
 
426
                                size = tam + ' KB'
 
427
                        return size
381
428
        
382
 
                ## Callback for a selection changed event in the paths tree
 
429
                ## @brief Callback for a selection changed event in the paths tree.
383
430
                #
384
431
                # When a selection in the treeView is changed, we get the file path and update the snapshots shown for it.
 
432
                #       
 
433
                # @param self
385
434
                # @param selection The new GTK selection object
386
435
                def on_pathTree_selection_changed(self, selection):
387
436
                        model, selection_iter = selection.get_selected()
388
 
                        
389
 
                        self.backupsForLabel.set_sensitive(False)               
390
 
                        self.selectedFileLabel.set_sensitive(False)
 
437
                        self.__backupsForLabel.set_sensitive(False)             
 
438
                        self.__selectedFileLabel.set_sensitive(False)
391
439
                
392
440
                        if (selection_iter and model):
393
441
                                #Something is selected so get the object
394
 
                                selected = model.get_value(selection_iter, 1)
 
442
                                selected = model.get_value(selection_iter, 2)
395
443
                                #updated selected info on the right pane
396
 
                                self.selectedFileLabel.set_text(selected)
 
444
                                self.__selectedFileLabel.set_text(selected)
397
445
                                selected = model.get_value(selection_iter, 2)
 
446
                                self.__nPath = selected
398
447
                                self.updateSnapshotModel(selected)
 
448
                                #We store the selected row to restore it later
 
449
                                self.__pathRowSelected = model.get_path(selection_iter)
 
450
                                newPath = str()
 
451
                                j=len(self.__pathRowSelected)
 
452
                                i=0
 
453
                                #Converting path to GtkTreePath
 
454
                                while i != j:
 
455
                                        number = str(self.__pathRowSelected[i])
 
456
                                        if i != j-1:
 
457
                                                number = number + ":"
 
458
                                        newPath = newPath + number
 
459
                                        i=i+1                                                           
 
460
                                self.__pathRowSelected = newPath                                
399
461
                        else: 
400
 
                                self.selectedFileLabel.set_text("")
 
462
                                self.__selectedFileLabel.set_text("")
 
463
 
 
464
                def getNPath(self):
 
465
                        return self.__nPath
401
466
                
402
 
                ## Callback for a selection changed event in the snapshots tree
403
 
                #
404
 
                # When we select a file... (TODO)
405
 
                # @param selection The new GTK selection object
 
467
                ## brief Callback for a selection changed event in the snapshots tree.
 
468
                #
 
469
                #This function stores the paths of the rows of the liststore which has been
 
470
                #selected by the user. 
 
471
                #
 
472
                # @param self
 
473
                # @param selection The new GTK selection object.
 
474
                # @author Daniel Tabas
406
475
                def on_snapshotList_selection_changed(self,selection):
407
 
                        model, selection_iter = selection.get_selected()
 
476
                        self.__rowsSelected = []
 
477
                        self.__rowsSelected = selection.get_selected_rows()[1]          
 
478
                
408
479
 
 
480
                ## @brief getter for the __rowsSelected atribute
 
481
                #
 
482
                # @param self
 
483
                # @return It returns a list of paths of the selected rows.
 
484
                # @author Daniel Tabas  
 
485
                def getRowsSelected(self):
 
486
                        return self.__rowsSelected
 
487
                
 
488
                ## @brief Getter of a field of one of the selected rows.
 
489
                #
 
490
                # @param self
 
491
                # @param row Integer to access to the __rowSelected list.
 
492
                # @param element Field of the row.
 
493
                # @return It returns the field selected of the row.
 
494
                # @author Daniel Tabas
 
495
                def getColumnSelected(self,row,element):
 
496
                        return self.__backupsTreeView.get_model().get_value(self.__backupsTreeView.get_model().get_iter(self.__rowsSelected[row]),element)
409
497
 
410
498
                ## @brief Method called when the drag_data_received event is captured, in order to do some drag & drop.
411
499
                #
418
506
                # @param info more info about the object
419
507
                # @param etime timestamp info of the drag
420
508
                # @author Daniel Tabas
421
 
                def drag_data_received_data(self, treeview, context, x, y, selection,info, etime):
 
509
                def dragDataReceivedData(self, treeview, context, x, y, selection,info, etime):
422
510
                        uri = selection.data.strip()
423
511
                        uri_splitted = uri.split()
424
512
                        for uri in uri_splitted:
425
 
                                if os.path.exists(uri.replace("file://","")):
 
513
                                if os.path.isdir(uri.replace("file://","")) or os.path.isfile(uri.replace("file://","")):
426
514
                                        path = urllib.unquote_plus(uri.replace("file://",""))
427
515
                                        self.__pathPref.append(path.encode("utf-8","strict").replace('\n',"").replace('\t',""))
428
516
                                        lista = self.__proxy.getWhiteList()
433
521
                                        l1=lista.replace('\n',"").replace('\t',"")
434
522
                                        self.__proxy.setWhiteList(l1.encode("utf-8","strict"))
435
523
                        return
436
 
 
437
 
                def drag_data_get_data(self, widget, context, selection, targetType, eventTime):
438
 
                        str = "probando"
439
 
                        print widget
440
 
                        print context
441
 
                        print targetType
442
 
                        print eventTime
443
 
                        print selection
444
 
                        print selection.target
445
 
                        ## TODO http://www.pygtk.org/docs/pygtk/class-gtkselectiondata.html
446
 
                        print selection.data
447
 
                        print selection.get_uris()
448
 
                        print selection.get_targets()
449
 
                        selection.set(selection.target, 8, str)
450
 
 
451
 
 
452
 
                ## Returns the path dragged into the treeview
 
524
                
 
525
                ## @brief Method called when a row in the path treeview is expanded, to store the information.
 
526
                #
 
527
                # @param self
 
528
                # @param treeview treeview in wich we capture row_expanded event
 
529
                # @param iter the iter of the row that is expanded
 
530
                # @param path the path that is expanded
 
531
                # @author Carlos Agra
 
532
                def rowExpanded(self,treeview, iter, path):
 
533
                        newPath = str()
 
534
                        j=len(path)
 
535
                        i=0
 
536
                        while i != j:
 
537
                                number = str(path[i])
 
538
                                if i != j-1:
 
539
                                        number = number + ":"
 
540
                                newPath = newPath + number
 
541
                                i=i+1
 
542
                        isInList = self.__rowsExpanded.count(newPath)
 
543
                        if isInList == 0:
 
544
                                self.__rowsExpanded.append(newPath)
 
545
                                
 
546
                ## @brief Method called when a row in the path treeview is Collapsed, to store the information.
 
547
                #
 
548
                # @param self
 
549
                # @param treeview treeview in wich we capture row_expanded event
 
550
                # @param iter the iter of the row that is expanded
 
551
                # @param path the path that is expanded
 
552
                # @author Carlos Agra
 
553
                def rowCollapsed(self,treeview, iter, path):
 
554
                        newPath = str()
 
555
                        j=len(path)
 
556
                        i=0
 
557
                        while i != j:
 
558
                                number = str(path[i])
 
559
                                if i != j-1:
 
560
                                        number = number + ":"
 
561
                                newPath = newPath + number
 
562
                                i=i+1
 
563
                        self.__rowsExpanded.remove(newPath)
 
564
                        itemsToDelete = []
 
565
                        for item in self.__rowsExpanded:
 
566
                                if item.startswith(newPath):
 
567
                                        itemsToDelete.append(item)
 
568
                        for item in itemsToDelete:
 
569
                                self.__rowsExpanded.remove(item)
 
570
                        
 
571
                
 
572
 
 
573
                ## @brief Returns the path dragged into the treeview.
453
574
                #
454
575
                # @param self
455
576
                # @return Returns an string with the path dragged
457
578
                def get_path(self):
458
579
                        return self.__pathPref
459
580
 
460
 
                ## Empty the list in witch we put the paths dragged into the treeview
 
581
                ## @brief Empty the list in witch we put the paths dragged into the treeview.
461
582
                #
462
583
                # @param self
463
584
                # @author Daniel Tabas
472
593
        # @param self The object pointer
473
594
        # @author Roberto Cano Fernandez, Daniel Tabas, Carlos Agra and Ezequiel Lara Gómez
474
595
        def __init__(self,n):
475
 
                self.__progressbar.set_orientation(gtk.PROGRESS_LEFT_TO_RIGHT)
476
596
                #instance of frontend proxy
477
597
                self.__proxy = FrontendProxy.FrontendProxy()
 
598
                self.__progressbar.set_orientation(gtk.PROGRESS_LEFT_TO_RIGHT)
478
599
                bus = dbus.SessionBus()
479
600
                bus.add_signal_receiver(self.__handlerUnexpected,'signalUnexpectedExit','com.hdlorean.Signals','com.hdlorean.Server','/hdlorean/signals')
480
601
                bus.add_signal_receiver(self.__handlerRefresh,'makeSnapshot','com.hdlorean.SignalsSch','com.hdlorean.Server','/hdlorean/signalsSch')
486
607
                # Contains the XML info of the .glade 
487
608
                self.wTree = gtk.glade.XML (self.gladefile)
488
609
 
489
 
                self.__currentFilesList = self.CurrentFilesList(self.wTree,self.__proxy)
490
 
                self.__allFilesList = self.AllFilesList(self.wTree,self.__proxy)
 
610
                self.__allFilesList = self.AllFilesList(self.wTree,self.__proxy,self)
491
611
 
492
612
                #disable unimplemented features (TODO!)
493
613
                self.wTree.get_widget('checkmenuViewAllSystem').set_sensitive(False)
524
644
                        "on_imagemenuAbout_activate" : self.about,
525
645
                        "on_imagemenuHelp_activate" : self.help,
526
646
                        "on_toolHelp_clicked" : self.help,
527
 
                        "on_mainPage_destroy" : self.destroyWind,
528
 
                        "on_imagemenuDBLog_activate" : self.dbLog,                      
 
647
                        "on_mainPage_destroy" : self.destroyWind
529
648
                }
530
649
                #connect class signals using the given dictionary
531
650
                self.wTree.signal_autoconnect (dic)
532
651
                self.window=self.wTree.get_widget('mainPage')
533
652
 
534
 
        #TODO añadir funcionalidad, aqui se iniciaria la ventana de debug
535
 
        def __handlerUnexpected(self,trace):            
536
 
                app=DebugWindow.DebugWindow(trace)
537
 
 
538
 
        def __handlerRefresh(self,a):
 
653
        ## @brief Shows information related to HDLorean in a popup
 
654
        # 
 
655
        # @param self
 
656
        # @param messages the list of messages to show, where messages[0] will be the title and the remaining elements the paths modified
 
657
        # @author Carlos Agra
 
658
 
 
659
        def showMessage(self,messages):
 
660
                if pynotify.init("HD Lorean notify"):
 
661
                        numMessages=len(messages)
 
662
                        if numMessages >= 1:
 
663
                                paths = str()
 
664
                                i = 1
 
665
                                while i != numMessages:
 
666
                                        paths = paths + messages[i]
 
667
                                        if i != numMessages -1:
 
668
                                                paths = paths + "\n"
 
669
                                        i=i+1                                                           
 
670
                                n = pynotify.Notification(messages[0], paths,gtk.STOCK_INFO)
 
671
                                n.attach_to_status_icon(self.__sysTrayIcon)
 
672
                                n.show()
 
673
                else:
 
674
                        print "there was a problem initializing the pynotify module"
 
675
 
 
676
 
 
677
        ## @brief Handler for the unexpected exit signal.
 
678
        # 
 
679
        # @param self
 
680
        # @param trace string with the trace to show in the debug window.
 
681
        # @author Daniel Tabas
 
682
        def __handlerUnexpected(self,trace):    
 
683
                strtrace="python ./InitDebug.py " +'"' +str(trace)+'"'
 
684
                tr = strtrace.replace('\n'," linea")
 
685
                os.system(tr)   
 
686
 
 
687
        ## @brief Handler for the refresh signal.
 
688
        # 
 
689
        # @param self
 
690
        # @author Daniel Tabas
 
691
        def __handlerRefresh(self):
539
692
                self.__allFilesList.refreshTree(self.wTree,self.__proxy,False)
540
693
 
 
694
        ## @brief Function that creates the systray icon.
 
695
        #
 
696
        # @param self
 
697
        # @author Daniel Tabas
541
698
        def __initDaemon(self):
542
699
                if self.__daemonStarted==False:
543
700
                        self.__sysTrayIcon = gtk.StatusIcon()
544
701
                        #gtk menu of the systray icon
545
702
                        self.__menu = gtk.Menu()
546
 
                        menuItem = gtk.ImageMenuItem(gtk.STOCK_STOP)
547
 
                        menuItem.connect('activate', self.stop, self.__sysTrayIcon)
548
 
                        self.__menu.append(menuItem)
549
 
                        menuItem = gtk.ImageMenuItem(gtk.STOCK_QUIT)
550
 
                        menuItem.connect('activate', self.quit_cb,  self.__sysTrayIcon)
551
 
                        self.__menu.append(menuItem)
552
 
                        self.__sysTrayIcon.connect('activate', self.activate_icon_cb, self.__sysTrayIcon)
553
 
                        self.__sysTrayIcon.connect('popup-menu', self.popup_menu_cb, self.__menu)
 
703
                        menuItem = gtk.ImageMenuItem('Close')
 
704
                        img = gtk.image_new_from_stock(gtk.STOCK_QUIT, gtk.ICON_SIZE_MENU)
 
705
                        menuItem.set_image(img)
 
706
                        menuItem.connect('activate', self.quitCb,  self.__sysTrayIcon)
 
707
                        self.__menu.append(menuItem)
 
708
                        menuItem = gtk.ImageMenuItem('Stop Daemon and Exit')
 
709
                        img = gtk.image_new_from_stock(gtk.STOCK_STOP, gtk.ICON_SIZE_MENU)
 
710
                        menuItem.set_image(img)
 
711
                        menuItem.connect('activate', self.stopCb, self.__sysTrayIcon)
 
712
                        self.__menu.append(menuItem)
 
713
                        self.__sysTrayIcon.connect('activate', self.activateIconCb, self.__sysTrayIcon)
 
714
                        self.__sysTrayIcon.connect('popup-menu', self.popupMenuCb, self.__menu)
554
715
                        self.__sysTrayIcon.set_from_file("../../share/images/HDLoreanHumo.png")
555
716
                        self.__sysTrayIcon.set_visible(True)
556
717
                        self.__sysTrayIcon.set_tooltip("HD Lorean Icon")        
557
718
                        self.__daemonStarted=True
558
719
 
559
 
 
560
 
# TODO modificar estas funciones
561
 
#################################################################################
562
 
 
563
 
        def delete_cb(self,widget, event, data = None):
564
 
                if data:
565
 
                        data.set_blinking(True)
566
 
                return False
567
 
 
568
 
        def quit_cb(self,widget, data = None):
 
720
        ## @brief handler for the quit menu.
 
721
        #
 
722
        # @param self
 
723
        # @param widget
 
724
        # @param data
 
725
        # @author Daniel Tabas
 
726
        def quitCb(self,widget, data = None):
569
727
                if data:
570
728
                        self.close(widget)
571
 
        
572
 
        def stop(self,widget,data = None):
 
729
 
 
730
        ## @brief handler for the stop menu.
 
731
        #
 
732
        # @param self
 
733
        # @param widget
 
734
        # @param data
 
735
        # @author Daniel Tabas  
 
736
        def stopCb(self,widget,data = None):
573
737
                if data:
574
738
                        self.quit(widget)
575
739
 
576
 
        def popup_menu_cb(self,widget, button, time, data = None):
 
740
 
 
741
        ## @brief handler for the left button press in the systray icon.
 
742
        #
 
743
        # @param self
 
744
        # @param widget
 
745
        # @param button
 
746
        # @param time
 
747
        # @param data
 
748
        # @author Daniel Tabas
 
749
        def popupMenuCb(self,widget, button, time, data = None):
577
750
                if button == 3:
578
751
                        if data:
579
752
                                data.show_all()
580
753
                                data.popup(None, None, None, 3, time)
581
754
                        pass
582
755
 
583
 
        def activate_icon_cb(self,widget, data = None):
 
756
 
 
757
        ## @brief handler for the stop menu.
 
758
        #
 
759
        # @param self
 
760
        # @param widget
 
761
        # @param data
 
762
        # @author Daniel Tabas  
 
763
        def activateIconCb(self,widget, data = None):
584
764
                if data:
585
765
                        if not self.window.get_property("visible"):             
586
766
                                self.window.destroy()
589
769
                        else:
590
770
                                self.window.destroy()
591
771
                                self.setNTimesPref(1)
 
772
 
592
773
        
593
774
 
594
 
###############################################################################
595
 
#       Status Bar percentage
596
 
        ## @brief Put a percentage value in the status bar
 
775
        ## @brief Put a percentage value in the status bar.
597
776
        #
598
777
        # This method takes an operation name and a progress percentage and place
599
778
        # both in the status bar. The idea is make a callback to this function once
601
780
        # @return nothing
602
781
        # @author Roberto Cano.
603
782
        def putPercentage(self,oper, perc):
604
 
                self.wTree.get_widget('mainPageStatus').pop(0)
605
 
                self.wTree.get_widget('mainPageStatus').push(0,"Porcentage of "+oper+" operation is: "+str(perc)+" %.")
606
 
        
607
 
        #Functions of main page, they are calls to the other windows of HD Lorean
608
 
 
609
 
        # @brief Open the DataBase Log Window
610
 
        #
611
 
        # This method calls DataBase Log Window
612
 
        # @param
613
 
        # @return
614
 
        # @author Carlos Agra
615
 
        def dbLog (self,widget):
616
 
                app=DBLog.DBLog()
617
 
 
618
 
        # @brief Call from more info button
619
 
        #
620
 
        # This method calls HDLorean
621
 
        # @param
622
 
        # @return
623
 
        # @author Roberto Cano Fernandez, Carlos Agra
624
 
        def moreInfo (self,widget):
625
 
                #TODO by Carlos: cuando tengamos el archivo o directorio, pasárselo a TempLine para que muestre su info
626
 
                #De momento sólo llama a la ventana que hizo Tabas
627
 
                #try:
628
 
                # Returns a (TreeModel, TreeIter) tuple
629
 
                model,itt = self.__treeviewList.get_selection().get_selected()          
630
 
                selection = self.__liststoreList.get_value(itt, 0)      
631
 
                app=TempLine.TempLine(selection)
632
 
                #except:
633
 
                #       print "There is no folder selected"
634
 
                #       pass
635
 
 
636
 
        # @brief
637
 
        #
638
 
        # This method
 
783
                if ((oper>=0) or (oper <=100)):
 
784
                        self.wTree.get_widget('mainPageStatus').pop(0)
 
785
                        self.wTree.get_widget('mainPageStatus').push(0,"Porcentage of "+oper+" operation is: "+str(perc)+" %.")
 
786
        
 
787
        
 
788
        ## @brief Close the app.
 
789
        #
 
790
        # 
639
791
        # @param
640
792
        # @return
641
793
        # @author
642
794
        def close(self,widget): 
643
795
                app=Close.Close()
644
796
 
 
797
 
 
798
        ## @brief Setter for the ntimespref atribute
 
799
        #
 
800
        # @param self
 
801
        # @param nTimes integer to set.
 
802
        # @author Daniel Tabas
645
803
        def setNTimesPref(self,nTimes):
646
804
                self._nTimesPref=nTimes
647
 
        # @brief
 
805
 
 
806
 
 
807
        ## @brief Init for the preferences window.
648
808
        #
649
 
        # This method
650
 
        # @param self duh
651
 
        # @param __nTimesPref Bugfix 
652
 
        # @return
653
 
        # @author
 
809
        # 
 
810
        # @param self 
 
811
        # @param __nTimesPref Flag to refresh correctly. 
 
812
        # @author Carlos Agra
654
813
        def preferences(self,widget):
655
 
                # TODO Try for this method, waiting for dbus messages...
656
 
                self.putPercentage("preferencias", 50)
657
814
                app=Preferences.Preferences(self.__nTimesPref,self.__allFilesList.get_path())
658
815
                self.__allFilesList.set_empty()
659
816
                self.__nTimesPref=self.__nTimesPref+1
660
817
                
661
818
        
662
 
        # @brief
 
819
        ## @brief Function that deletes one o more versions of a file.
663
820
        #
664
 
        # This method
665
 
        # @param
666
 
        # @return
667
 
        # @author
 
821
        # 
 
822
        # @param self
 
823
        # @param widget
 
824
        # @author Carlos Agra, Daniel Tabas
668
825
        def deleteOne(self,widget):
669
826
                self.wTree.get_widget('mainPageStatus').pop(0)
670
827
                self.wTree.get_widget('mainPageStatus').push(0,"Delete One Version")
671
 
                app=DeleteOne.DeleteOne()
 
828
                index = self.__allFilesList.getRowsSelected()
 
829
                tempPath = []
 
830
                if len(index)!=0:
 
831
                        for i in range(0,len(index)):
 
832
                                init_timestamp = self.__allFilesList.getColumnSelected(i,4)
 
833
                                path = self.__allFilesList.getColumnSelected(i,5)
 
834
                                tempPath.append(path)
 
835
                                finalpath = self.__proxy.deleteVersions(path,init_timestamp,0)
 
836
                        self.__allFilesList.updateSnapshotModel(path)
 
837
                        self.__allFilesList.refreshTree(self.wTree,self.__proxy,False)
 
838
                        self.wTree.get_widget('mainPageStatus').push(0,"Delete OK!")
 
839
                        self.showMessage(['HD Lorean','Delete OK of:']+tempPath)
 
840
                else:
 
841
                        self.wTree.get_widget('mainPageStatus').push(0,"Please select one row to be deleted")
672
842
 
673
 
        # @brief
 
843
        ## @brief Stop the daemon and exit.
674
844
        #
675
 
        # This method
676
 
        # @param
677
 
        # @return
678
 
        # @author
 
845
        # 
 
846
        # @param self
 
847
        # @param widget
 
848
        # @author 
679
849
        def quit(self,widget):
680
850
                #self.__proxy.stopDaemon()              
681
851
                app=CloseAndStop.CloseAndStop(self.__proxy)             
682
852
 
683
 
        # @brief
 
853
        ## @brief
684
854
        #
685
855
        # This method
686
856
        # @param
692
862
                app=DeleteSome.DeleteSome()
693
863
 
694
864
 
695
 
        # @brief Restore the selected backup (by its timestamp) and put it in the
 
865
        ## @brief Restore the selected backup (by its timestamp) and put it in the
696
866
        # selected folder, overwriting the previous files.
697
867
        #
698
868
        # @param timestamp The timestamp of the snapshot we want to recover
703
873
        def restWithoutOver(self,widget):
704
874
                #aqui ira la llamada a lo del porcentaje
705
875
                # ni guarra de si esto funcionaria asi
706
 
                #FIXME if  (ipath is  None) or (idir is None) or (itime is None):               
707
 
                        model,itt = self.__allFilesList.backupsTreeView.get_selection().get_selected()
708
 
                        if (model is not None) and (itt is not None):
709
 
                                timestamp = self.__allFilesList.backupsListStore.get_value(itt, 4)
710
 
                                path = self.__allFilesList.backupsListStore.get_value(itt, 5)
711
 
                                dialog = gtk.FileChooserDialog("Recover path", None, gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK))
712
 
                                dialog.set_current_folder(os.environ['HOME'])
713
 
                                # if there's no input path or input directory to restore open the choose dialog (menu button was pressed)
714
 
                        
715
 
                                if dialog.run() == gtk.RESPONSE_OK:
 
876
                #FIXME if  (ipath is  None) or (idir is None) or (itime is None):
 
877
                self.wTree.get_widget('mainPageStatus').pop(0)          
 
878
                index = self.__allFilesList.getRowsSelected()
 
879
                if len(index)!=0:
 
880
                        dialog = gtk.FileChooserDialog("Recover path", None, gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK))
 
881
                        dialog.set_current_folder(os.environ['HOME'])
 
882
                        if dialog.run() == gtk.RESPONSE_OK:
716
883
                                        directory = dialog.get_filename()
717
884
                                        dialog.destroy()
718
 
                                        finalpath = self.__proxy.recoverBackups(timestamp,[path],directory)
719
 
                                        os.system("xdg-open '"+finalpath+"'")
720
 
                                        return directory
721
 
                                else:
 
885
                        else:
 
886
                                        self.wTree.get_widget('mainPageStatus').push(0,"Restore cancelled")
722
887
                                        #directory = None
723
888
                                        dialog.destroy()
724
889
                                        return None
725
 
                #FIXME else:
726
 
                        #FIXME finalpath=self.__proxy.recoverBackups(itime,[ipath],idir)
727
 
                                
728
 
                
 
890
                        for i in range(0,len(index)): 
 
891
                                self.wTree.get_widget('mainPageStatus').push(0,"Restoring...")
 
892
                                timestamp = self.__allFilesList.getColumnSelected(i,4)
 
893
                                path = self.__allFilesList.getColumnSelected(i,5)
 
894
                                # if there's no input path or input directory to restore open the choose dialog (menu button was pressed)
 
895
                                finalpath = self.__proxy.recoverBackups(timestamp,[path],directory)
 
896
                                os.system("xdg-open '"+finalpath+"'")
 
897
                        self.wTree.get_widget('mainPageStatus').push(0,"Restore OK!")
 
898
                        self.showMessage(['HD Lorean','Restore succesful of:',path])
729
899
                        #return directory
 
900
                        
 
901
                else:
 
902
                        self.wTree.get_widget('mainPageStatus').push(0,"Please select a row of the list")
 
903
        #FIXME else:
 
904
                #FIXME finalpath=self.__proxy.recoverBackups(itime,[ipath],idir)
 
905
                        
 
906
        
 
907
                #return directory
730
908
 
731
909
 
732
910
 
734
912
                #       app=RestWithoutOver.RestWithoutOver()
735
913
 
736
914
 
737
 
        # @brief Restore the selected backup (by its timestamp) and put it in the
 
915
        ## @brief Restore the selected backup (by its timestamp) and put it in the
738
916
        # selected folder, overwriting the previous files.
739
917
        #
740
918
        # @param timestamp The timestamp of the snapshot we want to recover
744
922
        def restOverwriting(self,timestamp, r_path):
745
923
                self.wTree.get_widget('mainPageStatus').pop(0)
746
924
                self.wTree.get_widget('mainPageStatus').push(0,"Restore overwritting")
747
 
                model,itt = self.backupsTreeView.get_selection().get_selected()
 
925
                model,itt = self.getBackupsTreeView().get_selection().get_selected()
748
926
                if (model is not None) and (itt is not None):
749
927
                        selection = self.__liststoreList.get_value(itt, 0)
750
928
                        self.__proxy.recoverSnapshot(timestamp,r_path)
753
931
                #TODO: Move it to overwrite.
754
932
        
755
933
 
 
934
        ## @brief Backup the selected folder or all the watched files.
 
935
        # 
 
936
        #
 
937
        # @param self
 
938
        # @param widget
 
939
        # @author 
756
940
        def saveBackup(self,widget):
757
941
                self.wTree.get_widget('mainPageStatus').pop(0)
758
942
                self.wTree.get_widget('mainPageStatus').push(0,"Save backup")
759
 
                self.__proxy.snapshotRequest("USER")
760
 
        #TODO mirar con cuidado (deprecada???)
761
 
        #       app=SaveBackup.SaveBackup()
762
 
                #FIXME comentado esto de momento para que no estalle, no se si vale para algo
763
 
                #model,itt =self.__allFilesList.pathTreeStore.get_selection().get_selected()
764
 
                #if (model is not None) and (itt is not None):
765
 
                        #Something is selected so get the object
766
 
                #       selected = model.get_value(selection_iter, 0)
767
 
                        #updated selected info on the right pane        
768
 
                #       print "Eze mola"        
769
 
                #       print selected
 
943
                nPath = self.__allFilesList.getNPath()
 
944
                if nPath is not None:
 
945
                        #TODO cambiar esto por la funcion nueva que le he pedido a adri
 
946
                        self.__proxy.concreteSnapshotRequest("USER",nPath)
 
947
                        #TODO si falla que pasa? ademas sale esto mucho antes de que termine, tema de hilos
 
948
                        self.wTree.get_widget('mainPageStatus').push(0,"Backup saved OK!")
 
949
                        self.showMessage(['HD Lorean','Backup of following path OK:',nPath])
 
950
                else:
 
951
                        self.__proxy.snapshotRequest("USER")
 
952
                        #TODO si falla que pasa? ademas sale esto mucho antes de que termine, tema de hilos
 
953
                        self.wTree.get_widget('mainPageStatus').push(0,"Backup saved OK!")
 
954
                        self.showMessage(['HD Lorean','Backup done OK'])
 
955
        
770
956
 
771
 
        # @brief
 
957
        ## @brief
772
958
        #
773
959
        # This method
774
960
        # @param
871
1057
                self.wTree.get_widget('mainPageStatus').pop(0)
872
1058
                self.wTree.get_widget('mainPageStatus').push(0,"Help")
873
1059
                app=Help.Help()
 
1060
                
874
1061
        # @brief
875
1062
        #
876
1063
        # This method