Missed some locations
[theonering] / src / connection.py
index 8c1be6b..304491d 100644 (file)
@@ -10,6 +10,9 @@ import channel_manager
 import simple_presence
 
 
+_moduleLogger = logging.getLogger("connection")
+
+
 class TheOneRingConnection(telepathy.server.Connection, simple_presence.SimplePresenceMixin):
 
        MANDATORY_PARAMETERS = {
@@ -45,9 +48,9 @@ class TheOneRingConnection(telepathy.server.Connection, simple_presence.SimplePr
 
                        self.set_self_handle(handle.create_handle(self, 'connection'))
 
-                       logging.info("Connection to the account %s created" % account)
+                       _moduleLogger.info("Connection to the account %s created" % account)
                except Exception, e:
-                       logging.exception("Failed to create Connection")
+                       _moduleLogger.exception("Failed to create Connection")
                        raise
 
        @property
@@ -70,21 +73,27 @@ class TheOneRingConnection(telepathy.server.Connection, simple_presence.SimplePr
                """
                For org.freedesktop.telepathy.Connection
                """
+               self.StatusChanged(
+                       telepathy.CONNECTION_STATUS_CONNECTING,
+                       telepathy.CONNECTION_STATUS_REASON_REQUESTED
+               )
                try:
-                       self.StatusChanged(
-                               telepathy.CONNECTION_STATUS_CONNECTING,
-                               telepathy.CONNECTION_STATUS_REASON_REQUESTED
-                       )
                        self._backend.login(*self._credentials)
+               except gv_backend.NetworkError:
                        self.StatusChanged(
-                               telepathy.CONNECTION_STATUS_CONNECTED,
-                               telepathy.CONNECTION_STATUS_REASON_REQUESTED
+                               telepathy.CONNECTION_STATUS_DISCONNECTED,
+                               telepathy.CONNECTION_STATUS_REASON_NETWORK_ERROR
                        )
                except Exception:
                        self.StatusChanged(
                                telepathy.CONNECTION_STATUS_DISCONNECTED,
                                telepathy.CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED
                        )
+               else:
+                       self.StatusChanged(
+                               telepathy.CONNECTION_STATUS_CONNECTED,
+                               telepathy.CONNECTION_STATUS_REASON_REQUESTED
+                       )
 
        def Disconnect(self):
                """
@@ -92,9 +101,13 @@ class TheOneRingConnection(telepathy.server.Connection, simple_presence.SimplePr
                """
                try:
                        self._backend.logout()
-                       logging.info("Disconnected")
+                       _moduleLogger.info("Disconnected")
                except Exception:
-                       logging.exception("Disconnecting Failed")
+                       _moduleLogger.exception("Disconnecting Failed")
+               self.StatusChanged(
+                       telepathy.CONNECTION_STATUS_DISCONNECTED,
+                       telepathy.CONNECTION_STATUS_REASON_REQUESTED
+               )
 
        def RequestChannel(self, type, handleType, handleId, suppressHandler):
                """