deskbar-applet r1850 - in trunk: . deskbar/core deskbar/handlers deskbar/ui/preferences



Author: sebp
Date: Thu Jan 17 16:59:22 2008
New Revision: 1850
URL: http://svn.gnome.org/viewvc/deskbar-applet?rev=1850&view=rev

Log:
Fixed bug #452205: Deskbar does not notice when preferred browser changed for web searches (patch by aantny)

Modified:
   trunk/ChangeLog
   trunk/deskbar/core/CoreImpl.py
   trunk/deskbar/core/GconfStore.py
   trunk/deskbar/core/ModuleList.py
   trunk/deskbar/core/ModuleLoader.py
   trunk/deskbar/handlers/epiphany.py
   trunk/deskbar/ui/preferences/DeskbarPreferences.py

Modified: trunk/deskbar/core/CoreImpl.py
==============================================================================
--- trunk/deskbar/core/CoreImpl.py	(original)
+++ trunk/deskbar/core/CoreImpl.py	Thu Jan 17 16:59:22 2008
@@ -40,6 +40,10 @@
         
         self._module_installer = ModuleInstaller(self._module_loader)
         
+        self._gconf.connect("default-browser-changed", self._on_default_browser_changed)
+        #prevent double notifications
+        self.browser = None
+        
     def run(self):
         """
         Load modules, set keybinding and create L{deskbar.core.ThreadPool.ThreadPool}
@@ -336,14 +340,66 @@
                 else:
                     current_modules_set.add(mod.__class__.__name__)
         
-        #new_modules = enabled_modules_set - current_modules_set
-        #for mod in new_modules:
-            # FIXME: mod is a str but we need the class here
-            #self._module_loader.initialize_module_async( mod )
+        new_modules = enabled_modules_set - current_modules_set
+        for mod_name in new_modules:
+            iter, index = self._module_list.get_position_from_context(mod_name)
+            self.initialize_module(self._module_list[index][self._module_list.MODULE_CTX_COL])
         
         self.update_modules_priority(enabled_modules)
             
     def forward_query_ready(self, handler, query, matches):
         if query == self._last_query and matches != None and len(matches) > 0 and not self._stop_queries:
             self._emit_query_ready(matches)
+    
+    def update_gconf(self):
+         # Update the gconf enabled modules settings
+        enabled_modules = [mod.__class__.__name__ for mod in self._module_list if mod.is_enabled()]
+        self.set_enabled_modules(enabled_modules)
+    
+    def _on_default_browser_changed(self, gconfstore, new_browser):
+        new_browser = new_browser.split(" ")[0]
+        
+        if new_browser == "firefox":
+            new_browser = "mozilla"
+        
+        if new_browser == "epiphany":
+            old_browser = "mozilla"
+        elif new_browser == "mozilla":
+            old_browser = "epiphany"
+        else:
+            new_browser = "other"
+        
+        #Sometimes we get false notification events when the browser didn't really change. Ignore them.
+        if self.browser == new_browser:
+            return
+        
+        self.browser = new_browser
+                
+        #create a list of the modules that were enabled for the old browser so that we can enable them for the new browser 
+        enabled_browser_modules = []
+        for module in self._module_list:
+            # Check if the module is related to the old browser.
+            if module.__class__.__module__ == "epiphany" or module.__class__.__module__ == "mozilla":
+                if module.is_enabled() and new_browser != "other":
+                    enabled_browser_modules.append(module.__class__.__name__)
+                self.stop_module(module, async=False)
+                self._module_list.remove_module(module)
+                self._module_loader.emit("module-not-initialized", module)
+        
+        filename = None
+        for module in self._disabled_module_list:
+            if module[1].__module__ == new_browser:
+                if filename is None:
+                    filename = module[1].filename
+                self._disabled_module_list.remove_module(module[1])
+                
+        if filename is not None:
+            self._module_loader.load(filename)
+        
+        for module in enabled_browser_modules:
+            new_module_name = module.replace(old_browser.capitalize(), new_browser.capitalize())
+            new_module = self._module_list.get_module_instance_from_name(new_module_name)
+            # If async is True then self.update_gconf() may be run before the modules were initialized
+            self.initialize_module(new_module, async=False)
         
+        self.update_gconf()

Modified: trunk/deskbar/core/GconfStore.py
==============================================================================
--- trunk/deskbar/core/GconfStore.py	(original)
+++ trunk/deskbar/core/GconfStore.py	Thu Jan 17 16:59:22 2008
@@ -40,6 +40,8 @@
     GCONF_HIDE_AFTER_ACTION = GCONF_DIR + "/hide_after_action"
     
     GCONF_MAX_HISTORY_ITEMS = GCONF_DIR + "/max_history_items"
+    
+    GCONF_DEFAULT_BROWSER = "/desktop/gnome/url-handlers/http/command"
 
     __gsignals__ = {
         "keybinding-changed" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [gobject.TYPE_STRING]),
@@ -54,6 +56,7 @@
         "collapsed-rows-changed" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [gobject.TYPE_PYOBJECT]),
         "hide-after-action-changed" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [gobject.TYPE_BOOLEAN]),
         "max-history-items-changed" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [gobject.TYPE_INT]),
+        "default-browser-changed" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [gobject.TYPE_STRING]),
     }
 
     __instance = None
@@ -86,6 +89,7 @@
         self._client.notify_add(self.GCONF_COLLAPSED_CAT, lambda x, y, z, a: self.emit("collapsed-rows-changed", [i.get_string() for i in z.value.get_list()]))
         self._client.notify_add(self.GCONF_HIDE_AFTER_ACTION, lambda x, y, z, a: self.emit("hide-after-action-changed", z.value.get_bool()))
         self._client.notify_add(self.GCONF_TYPINGDELAY, lambda x, y, z, a: self.emit("max-history-items-changed", z.value.get_int()))
+        self._client.notify_add(self.GCONF_DEFAULT_BROWSER, lambda x, y, z, a: self.emit("default-browser-changed", z.value.get_string()))
     
     def get_client(self):
         return self._client
@@ -153,6 +157,9 @@
     def get_max_history_items(self):
         return self._client.get_int(self.GCONF_MAX_HISTORY_ITEMS)
            
+    def get_default_browser(self):      
+        return self._client.get_string(self.GCONF_DEFAULT_BROWSER)
+    
     def set_keybinding(self, binding):
         self._client.set_string(self.GCONF_KEYBINDING, binding)
     
@@ -199,4 +206,4 @@
         self._client.set_bool(self.GCONF_HIDE_AFTER_ACTION, val)
         
     def set_max_history_items(self, amount):
-        self._client.set_int(self.GCONF_MAX_HISTORY_ITEMS, int(amount))
\ No newline at end of file
+        self._client.set_int(self.GCONF_MAX_HISTORY_ITEMS, int(amount))

Modified: trunk/deskbar/core/ModuleList.py
==============================================================================
--- trunk/deskbar/core/ModuleList.py	(original)
+++ trunk/deskbar/core/ModuleList.py	Thu Jan 17 16:59:22 2008
@@ -116,7 +116,7 @@
     def remove_module(self, module):
         iter, index = self.get_position_from_context(module)
         if iter != None:
-            print 'Removing from modulelist:', module.handler
+            print 'Removing from modulelist:', module.INFOS['name']
             self.remove(iter)
         
     def module_changed(self, module):
@@ -188,6 +188,43 @@
         self.set_value(iter, self.ICON_COL, module.INFOS['icon'])
         self.set_value(iter, self.MODULE_CTX_COL, module)
         self.set_value(iter, self.ACTIVATABLE_COL, False)
+    
+    def get_position_from_context (self, module):
+        """
+        Returns a tuple C{(iter, index)}
+        
+        iter is a gtk.TreeIter pointing to the row containing the given
+        module module.
+        index is the index of the module in the list.
+        
+        If the module is not found return (None, None).
+        
+        @param module: The module to get the position for
+        @type module: Either a L{deskbar.interfaces.Module.Module} instance or the name of a module
+        
+        Note: This class stores the classes of disabled modules. It doesn't store actual module instances.
+        """
+        i = 0
+        iter = self.get_iter_first ()
+        while (iter is not None):
+            if isinstance(module, str):
+                # Search for module's name
+                if self[iter][self.MODULE_CTX_COL].__name__ == module:
+                    return (iter, i)
+            else:
+                if self[iter][self.MODULE_CTX_COL] == module:
+                    return (iter, i)
+                
+            iter = self.iter_next (iter)
+            i = i+1
+        
+        return (None, 0)
+    
+    def remove_module(self, module):
+        iter, index = self.get_position_from_context(module)
+        if iter != None:
+            print 'Removing from disabledModulelist:', module.__name__
+            self.remove(iter)
 
 gobject.type_register(DisabledModuleList)
 

Modified: trunk/deskbar/core/ModuleLoader.py
==============================================================================
--- trunk/deskbar/core/ModuleLoader.py	(original)
+++ trunk/deskbar/core/ModuleLoader.py	Thu Jan 17 16:59:22 2008
@@ -123,10 +123,13 @@
         
         for handler in mod.HANDLERS:
             module = getattr(mod, handler)
+            # Add a reference to the filename so that we can attempt to reload the module later
+            module.filename = filename
             if hasattr(module, "initialize") and hasattr( module, "INFOS"):
                 # Check that the given requirements for the handler are met
                 if not getattr(module, "has_requirements" )():
                     LOGGER.warning("Class %s in file %s has missing requirements. Skipping." % (handler, filename))
+                    module.class_instance = module
                     self.emit("module-not-initialized", module)
                 else:
                     valid_modules.append(module)

Modified: trunk/deskbar/handlers/epiphany.py
==============================================================================
--- trunk/deskbar/handlers/epiphany.py	(original)
+++ trunk/deskbar/handlers/epiphany.py	Thu Jan 17 16:59:22 2008
@@ -152,7 +152,18 @@
         matches = self._history.look_up(query)[:deskbar.DEFAULT_RESULTS_PER_HANDLER]
         self.set_priority_for_matches( matches )
         self._emit_query_ready(query, matches )
-        
+    
+    @staticmethod    
+    def has_requirements():
+        #    if deskbar.UNINSTALLED_DESKBAR:
+        #        return (deskbar.Handler.HANDLER_IS_HAPPY, None, None)
+        
+        if is_preferred_browser("epiphany"):
+            return True
+        else:
+            EpiphanyHistoryHandler.INSTRUCTIONS = _("Epiphany is not your preferred browser.")
+            return False
+
 class EpiphanyBookmarksParser(xml.sax.ContentHandler):
     def __init__(self, handler, cache):
         xml.sax.ContentHandler.__init__(self)

Modified: trunk/deskbar/ui/preferences/DeskbarPreferences.py
==============================================================================
--- trunk/deskbar/ui/preferences/DeskbarPreferences.py	(original)
+++ trunk/deskbar/ui/preferences/DeskbarPreferences.py	Thu Jan 17 16:59:22 2008
@@ -190,7 +190,7 @@
         self.dialog.connect("response", self.on_dialog_response)
     
     def on_dialog_response(self, dialog, response):
-        self.update_gconf()    
+        self._model.update_gconf()
         self.dialog.destroy()
         if self.newstuff != None:
             self.newstuff.close()
@@ -310,7 +310,7 @@
             self._model.stop_module (module, False)
         else:
             self._model.initialize_module (module, False)
-        self.update_gconf()
+        self._model.update_gconf()
        
     def on_newstuff_error(self, newstuff, error):
           """
@@ -421,8 +421,3 @@
         self.moduleview.scroll_to_iter(iter)
         self.set_buttons(self.moduleview.get_selection())
         self.moduleview.grab_focus()
-        
-    def update_gconf(self):
-         # Update the gconf enabled modules settings
-        enabled_modules = [mod.__class__.__name__ for mod in self.module_list if mod.is_enabled()]
-        self._model.set_enabled_modules(enabled_modules)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]