Missed some locations
[theonering] / src / connection.py
index 2dce28a..304491d 100644 (file)
@@ -7,21 +7,34 @@ import constants
 import gv_backend
 import handle
 import channel_manager
+import simple_presence
 
 
-class TheOneRingConnection(telepathy.server.Connection):
+_moduleLogger = logging.getLogger("connection")
 
-       _mandatory_parameters = {
+
+class TheOneRingConnection(telepathy.server.Connection, simple_presence.SimplePresenceMixin):
+
+       MANDATORY_PARAMETERS = {
                'account' : 's',
                'password' : 's'
        }
+       OPTIONAL_PARAMETERS = {
+       }
+       PARAMETER_DEFAULTS = {
+       }
 
        def __init__(self, manager, parameters):
                try:
                        self.check_parameters(parameters)
                        account = unicode(parameters['account'])
 
-                       telepathy.server.Connection.__init__(self, 'gvoice', account, 'theonering')
+                       telepathy.server.Connection.__init__(
+                               self,
+                               constants._telepathy_protocol_name_,
+                               account,
+                               constants._telepathy_implementation_name_
+                       )
 
                        self._manager = weakref.proxy(manager)
                        self._credentials = (
@@ -33,15 +46,11 @@ class TheOneRingConnection(telepathy.server.Connection):
                        cookieFilePath = "%s/cookies.txt" % constants._data_path_
                        self._backend = gv_backend.GVDialer(cookieFilePath)
 
-                       self.set_self_handle(handle.create_handle(self, 'self'))
-
-                       self.__disconnect_reason = telepathy.CONNECTION_STATUS_REASON_NONE_SPECIFIED
-                       self._initial_presence = None
-                       self._initial_personal_message = None
+                       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
@@ -62,23 +71,48 @@ class TheOneRingConnection(telepathy.server.Connection):
 
        def Connect(self):
                """
-               org.freedesktop.telepathy.Connection
+               For org.freedesktop.telepathy.Connection
                """
-               logging.info("Connecting")
-               self.__disconnect_reason = telepathy.CONNECTION_STATUS_REASON_NONE_SPECIFIED
-               self._backend.login(*self._credentials)
+               self.StatusChanged(
+                       telepathy.CONNECTION_STATUS_CONNECTING,
+                       telepathy.CONNECTION_STATUS_REASON_REQUESTED
+               )
+               try:
+                       self._backend.login(*self._credentials)
+               except gv_backend.NetworkError:
+                       self.StatusChanged(
+                               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):
                """
-               org.freedesktop.telepathy.Connection
+               For org.freedesktop.telepathy.Connection
                """
-               logging.info("Disconnecting")
-               self.__disconnect_reason = telepathy.CONNECTION_STATUS_REASON_REQUESTED
-               self._backend.logout()
+               try:
+                       self._backend.logout()
+                       _moduleLogger.info("Disconnected")
+               except Exception:
+                       _moduleLogger.exception("Disconnecting Failed")
+               self.StatusChanged(
+                       telepathy.CONNECTION_STATUS_DISCONNECTED,
+                       telepathy.CONNECTION_STATUS_REASON_REQUESTED
+               )
 
        def RequestChannel(self, type, handleType, handleId, suppressHandler):
                """
-               org.freedesktop.telepathy.Connection
+               For org.freedesktop.telepathy.Connection
+
                @param type DBus interface name for base channel type
                @param handleId represents a contact, list, etc according to handleType
 
@@ -104,7 +138,7 @@ class TheOneRingConnection(telepathy.server.Connection):
 
        def RequestHandles(self, handleType, names, sender):
                """
-               org.freedesktop.telepathy.Connection
+               For org.freedesktop.telepathy.Connection
                """
                self.check_connected()
                self.check_handleType(handleType)