Commits

elbaschid committed d64bc86

changed hierarchy of indicator menu; some more cleanup

  • Participants
  • Parent commits 4075e80

Comments (0)

Files changed (1)

File revelation_indicator.py

         self.clipboard = data.Clipboard()
         self.datafile = io.DataFile(datahandler.Revelation)
         self.entrystore = data.EntryStore()
-        self.entrysearch = data.EntrySearch(self.entrystore)
         #self.items = ui.ItemFactory(self.applet)
         self.locktimer = data.Timer()
 
         self.datafile.connect("content-changed", self.__cb_file_content_changed)
         self.locktimer.connect("ring", self.__cb_file_autolock)
 
-        self.entrysearch.folders = False
-    
+
     def __init_ui(self):
         self.menu = gtk.Menu()
 
         self.quit_item = gtk.MenuItem('Quit')
         self.quit_item.connect('activate', gtk.main_quit)
 
+        self.database_item = gtk.MenuItem(_('Database'))
+        self.database_item.set_sensitive(False)
+
+        self.menu.append(self.database_item)
+        self.menu.append(gtk.SeparatorMenuItem())
         self.menu.append(self.unlock_item)
         self.menu.append(self.lock_item)
-        #self.menu.append(self.reload_item)
-        #self.menu.append(self.start_revel_item)
+        self.menu.append(gtk.SeparatorMenuItem())
         self.menu.append(self.prefs_item)
         self.menu.append(self.about_item)
         self.menu.append(self.quit_item)
 #
         ##NOTE: some code removed
 
-        ## set up ui items
-        #self.entry = ui.Entry()
-        #self.entry.set_width_chars(14)
-        #self.entry.connect("activate", self.__cb_entry_activate)
-        #self.entry.connect("button_press_event", self.__cb_entry_buttonpress)
-        #self.entry.connect("key_press_event", lambda w,d=None: self.locktimer.reset())
-
         #self.icon = ui.Image()
         #self.eventbox = ui.EventBox(self.icon)
         #self.eventbox.connect("button_press_event", self.__cb_icon_buttonpress)
 
-        #self.hbox = ui.HBox(self.eventbox, self.entry)
-        #self.applet.add(self.hbox)
-        #
         ## handle Gnome Panel background
         #self.applet.connect("change-background",self.panel_bg)
 
         #self.entrymenu		= None
 
     def file_close(self):
+        logger.debug(_("closing unlocked database file."))
+        ##FIXME: check how this works and if it is necessary
         self.__close_popups()
         self.locktimer.stop()
 
+        ##FIXME: calling a revelation method?
         self.datafile.close()
         self.entrystore.clear()
-        self.entrymenu = None
+
+        ##TODO: reset the menu entry 
+        ##FIXME: is it required to remove subsubmenus first??
+        self.database_item.remove_submenu()
+        self.database_item.set_sensitive(False)
 
 
     def file_open(self, file, password = None):
+        logger.debug(_("opening database file."))
         try:
             return self.__file_load(file, password)
 
             ).run()
 
         except datahandler.PasswordError:
-                dialog.Error(
-                    None, 
-                    _('Incorrect password'), 
-                    _(
-                        'You entered an incorrect password for the file '
-                        '\'%s\', please try again.'
-                    ) % file
-                ).run()
-                self.file_open(file, None)
+            dialog.Error(
+                None, 
+                _('Incorrect password'), 
+                _(
+                    'You entered an incorrect password for the file '
+                    '\'%s\', please try again.'
+                ) % file
+            ).run()
+            self.file_open(file, None)
 
         except datahandler.VersionError:
-                dialog.Error(
-                    None, 
-                    _('Unknown data version'), 
-                    _('The file \'%s\' has a future version number, please upgrade Revelation to open it.') % file
-                ).run()
+            dialog.Error(
+                None, 
+                _('Unknown data version'), 
+                _('The file \'%s\' has a future version number, please upgrade Revelation to open it.') % file
+            ).run()
 
         except IOError:
-                dialog.Error(
-                    None, 
-                    _('Unable to open file'), 
-                    _('The file \'%s\' could not be opened. Make sure that the file exists, and that you have permissions to open it.') % file
-                ).run()
+            dialog.Error(
+                None, 
+                _('Unable to open file'), 
+                _('The file \'%s\' could not be opened. Make sure that the file exists, and that you have permissions to open it.') % file
+            ).run()
 
         return False
 
 
-    def file_reload(self):
-        if self.datafile.get_file() == None:
-                return
-
-        self.file_open(self.datafile.get_file(), self.datafile.get_password())
-
     def prefs(self):
         dialog.run_unique(Preferences, None, self.config)
 
     def __cb_config_file(self, key, value, data):
             "Config callback for file key changes"
 
-            self.file_close()
+            ###FIXME: is this really necessary???
+            ##self.file_close()
             ##TODO: fix this
             #self.applet.get_popup_component().set_prop("/commands/file-unlock", "sensitive", self.config.get("file") != "" and "1" or "0")
 
-
-    def __cb_config_show_searchentry(self, key, value, data):
-            "Config callback for show searchentry setting"
-
-            if value == True:
-                            self.entry.show()
-
-            else:
-                            self.entry.hide()
-
-    def __cb_entry_activate(self, widget, data = None):
-            "Callback for entry activation (pressing enter etc)"
-
-            self.entry_search(self.entry.get_text(), True)
-
-
-    def __cb_entry_buttonpress(self, widget, data = None):
-            "Callback for entry button presses"
-
-            self.locktimer.reset()
-
-            if data.button == 1:
-                ##TODO: fix this
-                #self.applet.request_focus(data.time)
-                pass
+            pass
 
 
     def __cb_file_autolock(self, widget, data = None):
-            "Callback for autolocking the file"
+        "Callback for autolocking the file"
 
-            if self.config.get("autolock") == True:
-                    self.file_close()
+        if self.config.get("autolock") == True:
+            self.file_close()
 
 
     def __cb_file_content_changed(self, widget, data = None):
-            "Callback for changed file content"
+        "Callback for changed file content"
 
-            try:
-                    self.__file_load(self.datafile.get_file(), self.datafile.get_password())
+        try:
+            self.__file_load(self.datafile.get_file(), self.datafile.get_password())
 
-            except dialog.CancelError:
-                    pass
+        except dialog.CancelError:
+            pass
 
-            except datahandler.PasswordError:
-                    self.file_close()
+        except datahandler.PasswordError:
+            self.file_close()
 
-            except datahandler.Error:
-                    pass
+        except datahandler.Error:
+            pass
 
 
     def __cb_file_changed(self, widget, data = None):
-            "Callback for changed data file"
+        "Callback for changed data file"
 
-            pass
+        pass
 
-            ##FIXME:
-            #popup = self.applet.get_popup_component()
+        ##FIXME:
+        #popup = self.applet.get_popup_component()
 
-            #if self.datafile.get_file() == None:
-            #        self.entry.set_text("")
+        #if self.datafile.get_file() == None:
+        #        self.entry.set_text("")
 
-            #        popup.set_prop("/commands/file-unlock", "sensitive", self.config.get("file") != "" and "1" or "0")
-            #        popup.set_prop("/commands/file-lock", "sensitive", "0")
-            #        popup.set_prop("/commands/file-reload", "sensitive", "0")
+        #        popup.set_prop("/commands/file-unlock", "sensitive", self.config.get("file") != "" and "1" or "0")
+        #        popup.set_prop("/commands/file-lock", "sensitive", "0")
 
-            #        self.icon.set_from_stock(ui.STOCK_REVELATION_LOCKED, ui.ICON_SIZE_APPLET)
+        #        self.icon.set_from_stock(ui.STOCK_REVELATION_LOCKED, ui.ICON_SIZE_APPLET)
 
-            #else:
-            #        popup.set_prop("/commands/file-unlock", "sensitive", "0")
-            #        popup.set_prop("/commands/file-lock", "sensitive", "1")
-            #        popup.set_prop("/commands/file-reload", "sensitive", "1")
+        #else:
+        #        popup.set_prop("/commands/file-unlock", "sensitive", "0")
+        #        popup.set_prop("/commands/file-lock", "sensitive", "1")
 
-            #        self.icon.set_from_stock(ui.STOCK_REVELATION, ui.ICON_SIZE_APPLET)
+        #        self.icon.set_from_stock(ui.STOCK_REVELATION, ui.ICON_SIZE_APPLET)
+
 
     def __cb_popup_activate(self, widget, data = None):
         self.locktimer.reset()
         action = self.config.get("menuaction")
 
         if action == "show":
-                self.entry_show(data)
+            self.entry_show(data)
 
         elif action == "copy":
-                self.entry_copychain(data)
+            self.entry_copychain(data)
 
         elif self.__launcher_valid(data):
-                self.entry_goto(data)
+            self.entry_goto(data)
 
         else:
-                self.entry_show(data)
+            self.entry_show(data)
+
 
     def entry_show(self, e, focusafter = False):
         self.__close_popups()
         self.popup_entryview = EntryViewPopup(e, self.config, self.clipboard)
 
         if focusafter == True:
-                self.popup_entryview.connect("closed", lambda w: self.__focus_entry())
+            self.popup_entryview.connect("closed", lambda w: self.__focus_entry())
 
         def cb_goto(widget):
-                if self.__launcher_valid(e):
-                        self.entry_goto(e)
+            if self.__launcher_valid(e):
+                self.entry_goto(e)
 
-                self.popup_entryview.close()
+            self.popup_entryview.close()
 
         #self.popup_entryview.button_goto.connect("clicked", cb_goto)
         #self.popup_entryview.button_goto.set_sensitive(self.__launcher_valid(e))
         self.popup_entryview.show(x, y)
 
     def __close_popups(self):
-            "Closes any open popups"
+        "Closes any open popups"
 
-            self.locktimer.reset()
+        self.locktimer.reset()
 
-            if hasattr(self, "popup_entryview") == True and self.popup_entryview != None:
-                    self.popup_entryview.destroy()
+        if hasattr(self, "popup_entryview") == True and self.popup_entryview != None:
+            self.popup_entryview.destroy()
 
-            if hasattr(self, "popup_entrylist") == True and self.popup_entrylist != None:
-                    self.popup_entrylist.destroy()
-
-            if hasattr(self, "entrymenu") == True and self.entrymenu != None:
-                    self.entrymenu.hide()
+        if hasattr(self, "popup_entrylist") == True and self.popup_entrylist != None:
+            self.popup_entrylist.destroy()
 
 
     def __file_load(self, filename, password = None):
         self.entrystore.import_entry(entrystore, None)
 
         menu = self.__generate_entrymenu(self.entrystore)
-        entries_item = gtk.MenuItem('Entries')
-        entries_item.set_submenu(menu)
+        self.database_item.set_submenu(menu)
+        self.database_item.set_sensitive(True)
 
-        self.menu.append(entries_item)
         self.menu.show_all()
 
         self.locktimer.start(self.config.get("autolock_timeout") * 60)