12 _moduleLogger = logging.getLogger("connection")
15 class TheOneRingConnection(telepathy.server.Connection):
17 # Overriding a base class variable
18 _mandatory_parameters = {
23 # Overriding a base class variable
24 _optional_parameters = {
26 _parameter_defaults = {
29 def __init__(self, manager, parameters):
31 self.check_parameters(parameters)
32 account = unicode(parameters['username'])
34 telepathy.server.Connection.__init__(
36 constants._telepathy_protocol_name_,
38 constants._telepathy_implementation_name_
41 self._manager = weakref.proxy(manager)
43 parameters['username'].encode('utf-8'),
44 parameters['password'].encode('utf-8'),
46 self._callbackNumber = parameters['forward'].encode('utf-8')
47 self._channelManager = channel_manager.ChannelManager(self)
49 cookieFilePath = "%s/cookies.txt" % constants._data_path_
50 self._session = gvoice.session.Session(cookieFilePath)
52 self.set_self_handle(handle.create_handle(self, 'connection'))
54 _moduleLogger.info("Connection to the account %s created" % account)
56 _moduleLogger.exception("Failed to create Connection")
69 return self._credentials[0]
71 def handle(self, handleType, handleId):
72 self.check_handle(handleType, handleId)
73 return self._handles[handleType, handleId]
77 For org.freedesktop.telepathy.Connection
79 _moduleLogger.info("Connecting...")
81 telepathy.CONNECTION_STATUS_CONNECTING,
82 telepathy.CONNECTION_STATUS_REASON_REQUESTED
85 self.session.login(*self._credentials)
86 self.session.backend.set_callback_number(self._callbackNumber)
87 except gvoice.backend.NetworkError, e:
88 _moduleLogger.exception("Connection Failed")
90 telepathy.CONNECTION_STATUS_DISCONNECTED,
91 telepathy.CONNECTION_STATUS_REASON_NETWORK_ERROR
94 _moduleLogger.exception("Connection Failed")
96 telepathy.CONNECTION_STATUS_DISCONNECTED,
97 telepathy.CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED
100 _moduleLogger.info("Connected")
102 telepathy.CONNECTION_STATUS_CONNECTED,
103 telepathy.CONNECTION_STATUS_REASON_REQUESTED
106 def Disconnect(self):
108 For org.freedesktop.telepathy.Connection
109 @bug Not properly logging out. Cookie files need to be per connection and removed
111 _moduleLogger.info("Disconnecting")
113 self.session.logout()
114 _moduleLogger.info("Disconnected")
116 _moduleLogger.exception("Disconnecting Failed")
118 telepathy.CONNECTION_STATUS_DISCONNECTED,
119 telepathy.CONNECTION_STATUS_REASON_REQUESTED
122 def RequestChannel(self, type, handleType, handleId, suppressHandler):
124 For org.freedesktop.telepathy.Connection
126 @param type DBus interface name for base channel type
127 @param handleId represents a contact, list, etc according to handleType
129 @returns DBus object path for the channel created or retrieved
131 self.check_connected()
132 self.check_handle(handleType, handleId)
135 channelManager = self._channelManager
136 handle = self.handle(handleType, handleId)
138 if type == telepathy.CHANNEL_TYPE_CONTACT_LIST:
139 _moduleLogger.info("RequestChannel ContactList")
140 channel = channelManager.channel_for_list(handle, suppressHandler)
141 elif type == telepathy.CHANNEL_TYPE_TEXT:
142 _moduleLogger.info("RequestChannel Text")
143 channel = channelManager.channel_for_text(handle, None, suppressHandler)
144 elif type == telepathy.CHANNEL_TYPE_STREAMED_MEDIA:
145 _moduleLogger.info("RequestChannel Media")
146 channel = channelManager.channel_for_text(handle, None, suppressHandler)
148 raise telepathy.NotImplemented("unknown channel type %s" % type)
150 _moduleLogger.info("RequestChannel Object Path: %s" % channel._object_path)
151 return channel._object_path
153 def RequestHandles(self, handleType, names, sender):
155 For org.freedesktop.telepathy.Connection
156 Overiding telepathy.server.Connecton to allow custom handles
158 self.check_connected()
159 self.check_handle_type(handleType)
163 name = name.encode('utf-8')
164 if handleType == telepathy.HANDLE_TYPE_CONTACT:
165 _moduleLogger.info("RequestHandles Contact: %s" % name)
166 h = self._create_contact_handle(name)
167 elif handleType == telepathy.HANDLE_TYPE_LIST:
168 # Support only server side (immutable) lists
169 _moduleLogger.info("RequestHandles List: %s" % name)
170 h = handle.create_handle(self, 'list', name)
172 raise telepathy.NotAvailable('Handle type unsupported %d' % handleType)
174 self.add_client_handle(h, sender)
177 def _create_contact_handle(self, requestedHandleName):
179 @todo Determine if nay of this is really needed
181 requestedContactId, requestedContactName = handle.ContactHandle.from_handle_name(
184 h = handle.create_handle(self, 'contact', requestedContactId, requestedHandleName)
187 def _on_invite_text(self, contactId):
191 h = self._create_contact_handle(contactId)
193 channelManager = self._channelManager
194 channel = channelManager.channel_for_text(handle)