Onward, ever onward
authorEd Page <eopage@byu.net>
Sun, 27 Sep 2009 00:33:44 +0000 (19:33 -0500)
committerEd Page <eopage@byu.net>
Sun, 27 Sep 2009 00:33:44 +0000 (19:33 -0500)
src/channel/text.py
src/connection.py
src/connection_manager.py
src/handle.py
src/location.py
src/simple_presence.py

index 84f9c99..36f506f 100644 (file)
@@ -27,7 +27,7 @@ class TheOneRingChannelText(
        def SetChatState(self, state):
                if state == telepathy.CHANNEL_CHAT_STATE_COMPOSING:
                        self._conversation.send_typing_notification()
-               h = handle.create_handle(self._conn_ref(), 'self')
+               h = handle.create_handle(self._conn_ref(), 'connection')
                self.ChatStateChanged(h, state)
 
        def Send(self, messageType, text):
index 9563899..3b17095 100644 (file)
@@ -7,9 +7,10 @@ import constants
 import gv_backend
 import handle
 import channel_manager
+import simple_presence
 
 
-class TheOneRingConnection(telepathy.server.Connection):
+class TheOneRingConnection(telepathy.server.Connection, simple_presence.SimplePresenceMixin):
 
        MANDATORY_PARAMETERS = {
                'account' : 's',
@@ -42,9 +43,7 @@ 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.set_self_handle(handle.create_handle(self, 'connection'))
 
                        logging.info("Connection to the account %s created" % account)
                except Exception, e:
@@ -69,26 +68,36 @@ 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
                try:
                        self._backend.login(*self._credentials)
-               except RuntimeError:
-                       self.__disconnect_reason = telepathy.CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED
+                       self.StatusChanged(
+                               telepathy.CONNECTION_STATUS_CONNECTED,
+                               telepathy.CONNECTION_STATUS_REASON_REQUESTED
+                       )
+                       logging.info("Connected")
+               except Exception:
+                       self.StatusChanged(
+                               telepathy.CONNECTION_STATUS_DISCONNECTED,
+                               telepathy.CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED
+                       )
+                       logging.exception("Connecting Failed")
 
        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()
+                       logging.info("Disconnected")
+               except Exception:
+                       logging.exception("Disconnecting Failed")
 
        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
 
@@ -114,7 +123,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)
index 63e943a..68e9be6 100644 (file)
@@ -18,6 +18,8 @@ class TheOneRingConnectionManager(telepathy.server.ConnectionManager):
 
        def GetParameters(self, proto):
                """
+               For org.freedesktop.telepathy.ConnectionManager
+
                @returns the mandatory and optional parameters for creating a connection
                """
                if proto not in self._protos:
@@ -53,6 +55,9 @@ class TheOneRingConnectionManager(telepathy.server.ConnectionManager):
                return result
 
        def disconnected(self, conn):
+               """
+               Overrides telepathy.server.ConnectionManager
+               """
                result = telepathy.server.ConnectionManager.disconnected(self, conn)
                gobject.timeout_add(5000, self.shutdown)
 
index 022a093..69b782e 100644 (file)
@@ -49,7 +49,7 @@ class TheOneRingHandle(telepathy.server.Handle):
        name = property(telepathy.server.Handle.get_name)
 
 
-class SelfHandle(TheOneRingHandle):
+class ConnectionHandle(TheOneRingHandle):
 
        instance = None
 
@@ -109,7 +109,7 @@ class GroupHandle(TheOneRingHandle):
 
 
 _HANDLE_TYPE_MAPPING = {
-       'self': SelfHandle,
+       'connection': ConnectionHandle,
        'contact': ContactHandle,
        'list': ListHandle,
        'group': GroupHandle,
index 0a4594b..1965255 100644 (file)
@@ -1,11 +1,18 @@
 import telepathy
 
 
-class TheOneRingLocation(telepathy.server.ConnectionInterfaceLocation):
+class LocationMixin(telepathy.server.ConnectionInterfaceLocation):
 
        def __init__(self):
                telepathy.server.ConnectionInterfaceLocation.__init__(self)
 
+       @property
+       def gvoice_backend(self):
+               """
+               @abstract
+               """
+               raise NotImplementedError()
+
        def GetLocations(self, contacts):
                """
                @returns {Contact: {Location Type: Location}}
index cd36856..4219e84 100644 (file)
@@ -13,7 +13,7 @@ class TheOneRingPresence(object):
        }
 
 
-class TheOneRingSimplePresence(telepathy.server.ConnectionInterfaceSimplePresence):
+class SimplePresenceMixin(telepathy.server.ConnectionInterfaceSimplePresence):
 
        def __init__(self):
                telepathy.server.ConnectionInterfaceSimplePresence.__init__(self)
@@ -22,6 +22,13 @@ class TheOneRingSimplePresence(telepathy.server.ConnectionInterfaceSimplePresenc
 
                self._implement_property_get(dbus_interface, {'Statuses' : self._get_statuses})
 
+       @property
+       def gvoice_backend(self):
+               """
+               @abstract
+               """
+               raise NotImplementedError()
+
        def GetPresences(self, contacts):
                """
                @todo Figure out how to know when its self and get whether busy or not
@@ -44,9 +51,9 @@ class TheOneRingSimplePresence(telepathy.server.ConnectionInterfaceSimplePresenc
                        raise telepathy.errors.InvalidArgument
 
                if status == TheOneRingPresence.ONLINE:
-                       self._conn.mark_dnd(True)
+                       self.gvoice_backend.mark_dnd(True)
                elif status == TheOneRingPresence.BUSY:
-                       self._conn.mark_dnd(False)
+                       self.gvoice_backend.mark_dnd(False)
                else:
                        raise telepathy.errors.InvalidArgument
                logging.info("Setting Presence to '%s'" % status)