From a6498a3dd1db8b4379713ebda993dd6b3ec86b08 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Sat, 26 Sep 2009 19:33:44 -0500 Subject: [PATCH] Onward, ever onward --- src/channel/text.py | 2 +- src/connection.py | 39 ++++++++++++++++++++++++--------------- src/connection_manager.py | 5 +++++ src/handle.py | 4 ++-- src/location.py | 9 ++++++++- src/simple_presence.py | 13 ++++++++++--- 6 files changed, 50 insertions(+), 22 deletions(-) diff --git a/src/channel/text.py b/src/channel/text.py index 84f9c99..36f506f 100644 --- a/src/channel/text.py +++ b/src/channel/text.py @@ -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): diff --git a/src/connection.py b/src/connection.py index 9563899..3b17095 100644 --- a/src/connection.py +++ b/src/connection.py @@ -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) diff --git a/src/connection_manager.py b/src/connection_manager.py index 63e943a..68e9be6 100644 --- a/src/connection_manager.py +++ b/src/connection_manager.py @@ -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) diff --git a/src/handle.py b/src/handle.py index 022a093..69b782e 100644 --- a/src/handle.py +++ b/src/handle.py @@ -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, diff --git a/src/location.py b/src/location.py index 0a4594b..1965255 100644 --- a/src/location.py +++ b/src/location.py @@ -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}} diff --git a/src/simple_presence.py b/src/simple_presence.py index cd36856..4219e84 100644 --- a/src/simple_presence.py +++ b/src/simple_presence.py @@ -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) -- 1.7.9.5