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
74 self._backend.login(*self._credentials)
76 telepathy.CONNECTION_STATUS_CONNECTED,
77 telepathy.CONNECTION_STATUS_REASON_REQUESTED
79 logging.info("Connected")
82 telepathy.CONNECTION_STATUS_DISCONNECTED,
83 telepathy.CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED
85 logging.exception("Connecting Failed")
89 For org.freedesktop.telepathy.Connection
92 self._backend.logout()
93 logging.info("Disconnected")
95 logging.exception("Disconnecting Failed")
97 def RequestChannel(self, type, handleType, handleId, suppressHandler):
99 For org.freedesktop.telepathy.Connection
101 @param type DBus interface name for base channel type
102 @param handleId represents a contact, list, etc according to handleType
104 @returns DBus object path for the channel created or retrieved
106 self.check_connected()
109 channelManager = self._channelManager
110 handle = self.handle(handleType, handleId)
112 if type == telepathy.CHANNEL_TYPE_CONTACT_LIST:
113 channel = channelManager.channel_for_list(handle, suppressHandler)
114 elif type == telepathy.CHANNEL_TYPE_TEXT:
115 if handleType != telepathy.HANDLE_TYPE_CONTACT:
116 raise telepathy.NotImplemented("Only Contacts are allowed")
117 contact = handle.contact
118 channel = channelManager.channel_for_text(handle, None, suppressHandler)
120 raise telepathy.NotImplemented("unknown channel type %s" % type)
122 return channel._object_path
124 def RequestHandles(self, handleType, names, sender):
126 For org.freedesktop.telepathy.Connection
128 self.check_connected()
129 self.check_handleType(handleType)
133 name = name.encode('utf-8')
134 if handleType == telepathy.HANDLE_TYPE_CONTACT:
135 h = self._create_contact_handle(name)
136 elif handleType == telepathy.HANDLE_TYPE_LIST:
137 h = handle.create_handle(self, 'list', name)
138 elif handleType == telepathy.HANDLE_TYPE_GROUP:
139 h = handle.create_handle(self, 'group', name)
141 raise telepathy.NotAvailable('Handle type unsupported %d' % handleType)
143 self.add_client_handle(handle, sender)
146 def _create_contact_handle(self, name):
147 requestedContactId, requestedContactName = handle.field_split(name)
149 contacts = self._backend.get_contacts()
151 (contactId, contactName) for (contactId, contactName) in contacts
152 if contactName == name
155 if 0 < len(contactsFound):
156 contactId, contactName = contactsFound[0]
157 h = handle.create_handle(self, 'contact', contactId, contactName)
159 h = handle.create_handle(self, 'contact', requestedContactId, requestedContactName)