← Back to team overview

gtg team mailing list archive

[Merge] lp:~izidor/gtg/bug932877 into lp:gtg

 

Izidor Matušov has proposed merging lp:~izidor/gtg/bug932877 into lp:gtg.

Requested reviews:
  Gtg developers (gtg)
Related bugs:
  Bug #932877 in Getting Things GNOME!: "User is not warned if gnote back-end fails to connect"
  https://bugs.launchpad.net/gtg/+bug/932877

For more details, see:
https://code.launchpad.net/~izidor/gtg/bug932877/+merge/108371

Handle the case when Tomboy or GNote are not installed. Also prevent loops when disabling backend when disabling backend when ....
-- 
https://code.launchpad.net/~izidor/gtg/bug932877/+merge/108371
Your team Gtg developers is requested to review the proposed merge of lp:~izidor/gtg/bug932877 into lp:gtg.
=== modified file 'GTG/backends/genericbackend.py'
--- GTG/backends/genericbackend.py	2012-05-01 11:04:39 +0000
+++ GTG/backends/genericbackend.py	2012-06-01 16:10:31 +0000
@@ -163,13 +163,14 @@
         @param disable: If disable is True, the backend won't
                         be automatically loaded when GTG starts
         '''
-        self._is_initialized = False
-        if disable:
-            self._parameters[self.KEY_ENABLED] = False
-            #we signal that we have been disabled
-            self._signal_manager.backend_state_changed(self.get_id())
-            self._signal_manager.backend_sync_ended(self.get_id())
-        syncing_thread = threading.Thread(target = self.sync).run()
+        if self._parameters[self.KEY_ENABLED]:
+            self._is_initialized = False
+            if disable:
+                self._parameters[self.KEY_ENABLED] = False
+                #we signal that we have been disabled
+                self._signal_manager.backend_state_changed(self.get_id())
+                self._signal_manager.backend_sync_ended(self.get_id())
+            syncing_thread = threading.Thread(target = self.sync).run()
 
     def save_state(self):
         '''

=== modified file 'GTG/backends/generictomboy.py'
--- GTG/backends/generictomboy.py	2012-05-01 11:04:39 +0000
+++ GTG/backends/generictomboy.py	2012-06-01 16:10:31 +0000
@@ -520,11 +520,15 @@
                                 self.tomboy_connection_is_ok:
                 return
             self.backend = backend
+            self.tomboy_connection_is_ok = True
             with GenericTomboy.DbusWatchdog(backend):
                 bus = dbus.SessionBus()
-                obj = bus.get_object(bus_name, bus_path)
-                self.tomboy = dbus.Interface(obj, bus_interface)
-            self.tomboy_connection_is_ok = True
+                try:
+                    obj = bus.get_object(bus_name, bus_path)
+                    self.tomboy = dbus.Interface(obj, bus_interface)
+                except dbus.DBusException:
+                    self.tomboy_failed()
+                    self.tomboy = None
 
         def __enter__(self):
             '''
@@ -533,6 +537,7 @@
             @returns: dbus.Interface
             '''
             return self.tomboy
+                
 
         def __exit__(self, exception_type, value, traceback):
             '''
@@ -545,15 +550,21 @@
             @param traceback: the traceback of the error
             @returns: False if some exception must be re-raised.
             '''
-            if isinstance(value, dbus.DBusException):
-                self.tomboy_connection_is_ok = False
-                self.backend.quit(disable = True)
-                BackendSignals().backend_failed(self.backend.get_id(), \
-                            BackendSignals.ERRNO_DBUS)
+            if isinstance(value, dbus.DBusException) or \
+                not self.tomboy_connection_is_ok:
+                self.tomboy_failed()
+                return True
             else:
                 return False
-            return True
+        
+        def tomboy_failed(self):
+            """ Handle failed tomboy connection.
 
+            Disable backend and show error in notification bar """
+            self.tomboy_connection_is_ok = False
+            BackendSignals().backend_failed(self.backend.get_id(),
+                BackendSignals.ERRNO_DBUS)
+            self.backend.quit(disable = True)
 
 
     class DbusWatchdog(Watchdog):
@@ -570,8 +581,8 @@
             @param backend: a Backend object
             '''
             self.backend = backend
-            super(GenericTomboy.DbusWatchdog, self).__init__(3, \
-                                    self._when_taking_too_long)
+            super(GenericTomboy.DbusWatchdog, self).__init__(
+                        3, self._when_taking_too_long)
 
         def _when_taking_too_long(self):
             '''
@@ -580,7 +591,6 @@
             '''
             Log.error("Dbus connection is taking too long for the Tomboy/Gnote"
                       "backend!")
+            BackendSignals().backend_failed(self.backend.get_id(),
+                            BackendSignals.ERRNO_DBUS)
             self.backend.quit(disable = True)
-            BackendSignals().backend_failed(self.backend.get_id(), \
-                            BackendSignals.ERRNO_DBUS)
-