12 class TheOneRingConnection(telepathy.server.Connection):
14 _mandatory_parameters = {
19 def __init__(self, manager, parameters):
21 self.check_parameters(parameters)
22 account = unicode(parameters['account'])
24 telepathy.server.Connection.__init__(self, 'gvoice', account, 'theonering')
26 self._manager = weakref.proxy(manager)
28 parameters['account'].encode('utf-8'),
29 parameters['password'].encode('utf-8'),
31 self._channelManager = channel_manager.ChannelManager(self)
33 cookieFilePath = "%s/cookies.txt" % constants._data_path_
34 self._backend = gv_backend.GVDialer(cookieFilePath)
36 self.set_self_handle(handle.create_handle(self, 'self'))
38 self.__disconnect_reason = telepathy.CONNECTION_STATUS_REASON_NONE_SPECIFIED
39 self._initial_presence = None
40 self._initial_personal_message = None
42 logging.info("Connection to the account %s created" % account)
44 logging.exception("Failed to create Connection")
52 def gvoice_backend(self):
59 def handle(self, handleType, handleId):
60 self.check_handle(handleType, handleId)
61 return self._handles[handleType, handleId]
65 org.freedesktop.telepathy.Connection
67 logging.info("Connecting")
68 self.__disconnect_reason = telepathy.CONNECTION_STATUS_REASON_NONE_SPECIFIED
69 self._backend.login(*self._credentials)
73 org.freedesktop.telepathy.Connection
75 logging.info("Disconnecting")
76 self.__disconnect_reason = telepathy.CONNECTION_STATUS_REASON_REQUESTED
77 self._backend.logout()
79 def RequestChannel(self, type, handleType, handleId, suppressHandler):
81 org.freedesktop.telepathy.Connection
82 @param type DBus interface name for base channel type
83 @param handleId represents a contact, list, etc according to handleType
85 @returns DBus object path for the channel created or retrieved
87 self.check_connected()
90 channelManager = self._channelManager
91 handle = self.handle(handleType, handleId)
93 if type == telepathy.CHANNEL_TYPE_CONTACT_LIST:
94 channel = channelManager.channel_for_list(handle, suppressHandler)
95 elif type == telepathy.CHANNEL_TYPE_TEXT:
96 if handleType != telepathy.HANDLE_TYPE_CONTACT:
97 raise telepathy.NotImplemented("Only Contacts are allowed")
98 contact = handle.contact
99 channel = channelManager.channel_for_text(handle, None, suppressHandler)
101 raise telepathy.NotImplemented("unknown channel type %s" % type)
103 return channel._object_path
105 def RequestHandles(self, handleType, names, sender):
107 org.freedesktop.telepathy.Connection
109 self.check_connected()
110 self.check_handleType(handleType)
114 name = name.encode('utf-8')
115 if handleType == telepathy.HANDLE_TYPE_CONTACT:
116 h = self._create_contact_handle(name)
117 elif handleType == telepathy.HANDLE_TYPE_LIST:
118 h = handle.create_handle(self, 'list', name)
119 elif handleType == telepathy.HANDLE_TYPE_GROUP:
120 h = handle.create_handle(self, 'group', name)
122 raise telepathy.NotAvailable('Handle type unsupported %d' % handleType)
124 self.add_client_handle(handle, sender)
127 def _create_contact_handle(self, name):
128 requestedContactId, requestedContactName = handle.field_split(name)
130 contacts = self._backend.get_contacts()
132 (contactId, contactName) for (contactId, contactName) in contacts
133 if contactName == name
136 if 0 < len(contactsFound):
137 contactId, contactName = contactsFound[0]
138 h = handle.create_handle(self, 'contact', contactId, contactName)
140 h = handle.create_handle(self, 'contact', requestedContactId, requestedContactName)