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):
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',
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:
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
def RequestHandles(self, handleType, names, sender):
"""
- org.freedesktop.telepathy.Connection
+ For org.freedesktop.telepathy.Connection
"""
self.check_connected()
self.check_handleType(handleType)
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:
return result
def disconnected(self, conn):
+ """
+ Overrides telepathy.server.ConnectionManager
+ """
result = telepathy.server.ConnectionManager.disconnected(self, conn)
gobject.timeout_add(5000, self.shutdown)
name = property(telepathy.server.Handle.get_name)
-class SelfHandle(TheOneRingHandle):
+class ConnectionHandle(TheOneRingHandle):
instance = None
_HANDLE_TYPE_MAPPING = {
- 'self': SelfHandle,
+ 'connection': ConnectionHandle,
'contact': ContactHandle,
'list': ListHandle,
'group': GroupHandle,
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}}
}
-class TheOneRingSimplePresence(telepathy.server.ConnectionInterfaceSimplePresence):
+class SimplePresenceMixin(telepathy.server.ConnectionInterfaceSimplePresence):
def __init__(self):
telepathy.server.ConnectionInterfaceSimplePresence.__init__(self)
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
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)