12 class TheOneRingConnection(telepathy.server.Connection):
14 MANDATORY_PARAMETERS = {
18 OPTIONAL_PARAMETERS = {
20 PARAMETER_DEFAULTS = {
23 def __init__(self, manager, parameters):
25 self.check_parameters(parameters)
26 account = unicode(parameters['account'])
28 telepathy.server.Connection.__init__(
30 constants._telepathy_protocol_name_,
32 constants._telepathy_implementation_name_
35 self._manager = weakref.proxy(manager)
37 parameters['account'].encode('utf-8'),
38 parameters['password'].encode('utf-8'),
40 self._channelManager = channel_manager.ChannelManager(self)
42 cookieFilePath = "%s/cookies.txt" % constants._data_path_
43 self._backend = gv_backend.GVDialer(cookieFilePath)
45 self.set_self_handle(handle.create_handle(self, 'self'))
47 self.__disconnect_reason = telepathy.CONNECTION_STATUS_REASON_NONE_SPECIFIED
49 logging.info("Connection to the account %s created" % account)
51 logging.exception("Failed to create Connection")
59 def gvoice_backend(self):
66 def handle(self, handleType, handleId):
67 self.check_handle(handleType, handleId)
68 return self._handles[handleType, handleId]
72 org.freedesktop.telepathy.Connection
74 logging.info("Connecting")
75 self.__disconnect_reason = telepathy.CONNECTION_STATUS_REASON_NONE_SPECIFIED
77 self._backend.login(*self._credentials)
79 self.__disconnect_reason = telepathy.CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED
83 org.freedesktop.telepathy.Connection
85 logging.info("Disconnecting")
86 self.__disconnect_reason = telepathy.CONNECTION_STATUS_REASON_REQUESTED
87 self._backend.logout()
89 def RequestChannel(self, type, handleType, handleId, suppressHandler):
91 org.freedesktop.telepathy.Connection
92 @param type DBus interface name for base channel type
93 @param handleId represents a contact, list, etc according to handleType
95 @returns DBus object path for the channel created or retrieved
97 self.check_connected()
100 channelManager = self._channelManager
101 handle = self.handle(handleType, handleId)
103 if type == telepathy.CHANNEL_TYPE_CONTACT_LIST:
104 channel = channelManager.channel_for_list(handle, suppressHandler)
105 elif type == telepathy.CHANNEL_TYPE_TEXT:
106 if handleType != telepathy.HANDLE_TYPE_CONTACT:
107 raise telepathy.NotImplemented("Only Contacts are allowed")
108 contact = handle.contact
109 channel = channelManager.channel_for_text(handle, None, suppressHandler)
111 raise telepathy.NotImplemented("unknown channel type %s" % type)
113 return channel._object_path
115 def RequestHandles(self, handleType, names, sender):
117 org.freedesktop.telepathy.Connection
119 self.check_connected()
120 self.check_handleType(handleType)
124 name = name.encode('utf-8')
125 if handleType == telepathy.HANDLE_TYPE_CONTACT:
126 h = self._create_contact_handle(name)
127 elif handleType == telepathy.HANDLE_TYPE_LIST:
128 h = handle.create_handle(self, 'list', name)
129 elif handleType == telepathy.HANDLE_TYPE_GROUP:
130 h = handle.create_handle(self, 'group', name)
132 raise telepathy.NotAvailable('Handle type unsupported %d' % handleType)
134 self.add_client_handle(handle, sender)
137 def _create_contact_handle(self, name):
138 requestedContactId, requestedContactName = handle.field_split(name)
140 contacts = self._backend.get_contacts()
142 (contactId, contactName) for (contactId, contactName) in contacts
143 if contactName == name
146 if 0 < len(contactsFound):
147 contactId, contactName = contactsFound[0]
148 h = handle.create_handle(self, 'contact', contactId, contactName)
150 h = handle.create_handle(self, 'contact', requestedContactId, requestedContactName)