10 import simple_presence
13 _moduleLogger = logging.getLogger("connection")
16 class TheOneRingConnection(telepathy.server.Connection, simple_presence.SimplePresenceMixin):
18 MANDATORY_PARAMETERS = {
22 OPTIONAL_PARAMETERS = {
24 PARAMETER_DEFAULTS = {
27 def __init__(self, manager, parameters):
29 self.check_parameters(parameters)
30 account = unicode(parameters['account'])
32 telepathy.server.Connection.__init__(
34 constants._telepathy_protocol_name_,
36 constants._telepathy_implementation_name_
39 self._manager = weakref.proxy(manager)
41 parameters['account'].encode('utf-8'),
42 parameters['password'].encode('utf-8'),
44 self._channelManager = channel_manager.ChannelManager(self)
46 cookieFilePath = "%s/cookies.txt" % constants._data_path_
47 self._backend = gv_backend.GVDialer(cookieFilePath)
49 self.set_self_handle(handle.create_handle(self, 'connection'))
51 _moduleLogger.info("Connection to the account %s created" % account)
53 _moduleLogger.exception("Failed to create Connection")
61 def gvoice_backend(self):
68 def handle(self, handleType, handleId):
69 self.check_handle(handleType, handleId)
70 return self._handles[handleType, handleId]
74 For org.freedesktop.telepathy.Connection
77 telepathy.CONNECTION_STATUS_CONNECTING,
78 telepathy.CONNECTION_STATUS_REASON_REQUESTED
81 self._backend.login(*self._credentials)
82 except gv_backend.NetworkError:
84 telepathy.CONNECTION_STATUS_DISCONNECTED,
85 telepathy.CONNECTION_STATUS_REASON_NETWORK_ERROR
89 telepathy.CONNECTION_STATUS_DISCONNECTED,
90 telepathy.CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED
94 telepathy.CONNECTION_STATUS_CONNECTED,
95 telepathy.CONNECTION_STATUS_REASON_REQUESTED
100 For org.freedesktop.telepathy.Connection
103 self._backend.logout()
104 _moduleLogger.info("Disconnected")
106 _moduleLogger.exception("Disconnecting Failed")
108 telepathy.CONNECTION_STATUS_DISCONNECTED,
109 telepathy.CONNECTION_STATUS_REASON_REQUESTED
112 def RequestChannel(self, type, handleType, handleId, suppressHandler):
114 For org.freedesktop.telepathy.Connection
116 @param type DBus interface name for base channel type
117 @param handleId represents a contact, list, etc according to handleType
119 @returns DBus object path for the channel created or retrieved
121 self.check_connected()
124 channelManager = self._channelManager
125 handle = self.handle(handleType, handleId)
127 if type == telepathy.CHANNEL_TYPE_CONTACT_LIST:
128 channel = channelManager.channel_for_list(handle, suppressHandler)
129 elif type == telepathy.CHANNEL_TYPE_TEXT:
130 if handleType != telepathy.HANDLE_TYPE_CONTACT:
131 raise telepathy.NotImplemented("Only Contacts are allowed")
132 contact = handle.contact
133 channel = channelManager.channel_for_text(handle, None, suppressHandler)
135 raise telepathy.NotImplemented("unknown channel type %s" % type)
137 return channel._object_path
139 def RequestHandles(self, handleType, names, sender):
141 For org.freedesktop.telepathy.Connection
143 self.check_connected()
144 self.check_handleType(handleType)
148 name = name.encode('utf-8')
149 if handleType == telepathy.HANDLE_TYPE_CONTACT:
150 h = self._create_contact_handle(name)
151 elif handleType == telepathy.HANDLE_TYPE_LIST:
152 h = handle.create_handle(self, 'list', name)
153 elif handleType == telepathy.HANDLE_TYPE_GROUP:
154 h = handle.create_handle(self, 'group', name)
156 raise telepathy.NotAvailable('Handle type unsupported %d' % handleType)
158 self.add_client_handle(handle, sender)
161 def _create_contact_handle(self, name):
162 requestedContactId, requestedContactName = handle.field_split(name)
164 contacts = self._backend.get_contacts()
166 (contactId, contactName) for (contactId, contactName) in contacts
167 if contactName == name
170 if 0 < len(contactsFound):
171 contactId, contactName = contactsFound[0]
172 h = handle.create_handle(self, 'contact', contactId, contactName)
174 h = handle.create_handle(self, 'contact', requestedContactId, requestedContactName)