10 import simple_presence
13 class TheOneRingConnection(telepathy.server.Connection, simple_presence.SimplePresenceMixin):
15 MANDATORY_PARAMETERS = {
19 OPTIONAL_PARAMETERS = {
21 PARAMETER_DEFAULTS = {
24 def __init__(self, manager, parameters):
26 self.check_parameters(parameters)
27 account = unicode(parameters['account'])
29 telepathy.server.Connection.__init__(
31 constants._telepathy_protocol_name_,
33 constants._telepathy_implementation_name_
36 self._manager = weakref.proxy(manager)
38 parameters['account'].encode('utf-8'),
39 parameters['password'].encode('utf-8'),
41 self._channelManager = channel_manager.ChannelManager(self)
43 cookieFilePath = "%s/cookies.txt" % constants._data_path_
44 self._backend = gv_backend.GVDialer(cookieFilePath)
46 self.set_self_handle(handle.create_handle(self, 'connection'))
48 logging.info("Connection to the account %s created" % account)
50 logging.exception("Failed to create Connection")
58 def gvoice_backend(self):
65 def handle(self, handleType, handleId):
66 self.check_handle(handleType, handleId)
67 return self._handles[handleType, handleId]
71 For org.freedesktop.telepathy.Connection
75 telepathy.CONNECTION_STATUS_CONNECTING,
76 telepathy.CONNECTION_STATUS_REASON_REQUESTED
78 self._backend.login(*self._credentials)
80 telepathy.CONNECTION_STATUS_CONNECTED,
81 telepathy.CONNECTION_STATUS_REASON_REQUESTED
85 telepathy.CONNECTION_STATUS_DISCONNECTED,
86 telepathy.CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED
91 For org.freedesktop.telepathy.Connection
94 self._backend.logout()
95 logging.info("Disconnected")
97 logging.exception("Disconnecting Failed")
99 def RequestChannel(self, type, handleType, handleId, suppressHandler):
101 For org.freedesktop.telepathy.Connection
103 @param type DBus interface name for base channel type
104 @param handleId represents a contact, list, etc according to handleType
106 @returns DBus object path for the channel created or retrieved
108 self.check_connected()
111 channelManager = self._channelManager
112 handle = self.handle(handleType, handleId)
114 if type == telepathy.CHANNEL_TYPE_CONTACT_LIST:
115 channel = channelManager.channel_for_list(handle, suppressHandler)
116 elif type == telepathy.CHANNEL_TYPE_TEXT:
117 if handleType != telepathy.HANDLE_TYPE_CONTACT:
118 raise telepathy.NotImplemented("Only Contacts are allowed")
119 contact = handle.contact
120 channel = channelManager.channel_for_text(handle, None, suppressHandler)
122 raise telepathy.NotImplemented("unknown channel type %s" % type)
124 return channel._object_path
126 def RequestHandles(self, handleType, names, sender):
128 For org.freedesktop.telepathy.Connection
130 self.check_connected()
131 self.check_handleType(handleType)
135 name = name.encode('utf-8')
136 if handleType == telepathy.HANDLE_TYPE_CONTACT:
137 h = self._create_contact_handle(name)
138 elif handleType == telepathy.HANDLE_TYPE_LIST:
139 h = handle.create_handle(self, 'list', name)
140 elif handleType == telepathy.HANDLE_TYPE_GROUP:
141 h = handle.create_handle(self, 'group', name)
143 raise telepathy.NotAvailable('Handle type unsupported %d' % handleType)
145 self.add_client_handle(handle, sender)
148 def _create_contact_handle(self, name):
149 requestedContactId, requestedContactName = handle.field_split(name)
151 contacts = self._backend.get_contacts()
153 (contactId, contactName) for (contactId, contactName) in contacts
154 if contactName == name
157 if 0 < len(contactsFound):
158 contactId, contactName = contactsFound[0]
159 h = handle.create_handle(self, 'contact', contactId, contactName)
161 h = handle.create_handle(self, 'contact', requestedContactId, requestedContactName)