6 import dbus.mainloop.glib
7 dbus.mainloop.glib.DBusGMainLoop(set_as_default = True)
12 DBUS_PROPERTIES = 'org.freedesktop.DBus.Properties'
16 reg = telepathy.client.ManagerRegistry()
21 def get_connection_manager(reg):
22 cm = reg.GetManager('theonering')
31 def queue_action(self):
34 def append_action(self, action):
35 assert self._action is None
39 if self._action is None:
41 self._action.queue_action()
43 def _on_error(self, error):
46 def _on_generic_message(self, *args):
50 class DummyAction(Action):
52 def queue_action(self):
53 gobject.idle_add(self._on_done)
56 class QuitLoop(Action):
58 def __init__(self, loop):
59 super(QuitLoop, self).__init__()
62 def queue_action(self):
66 class DisplayParams(Action):
68 def __init__(self, cm):
69 super(DisplayParams, self).__init__()
72 def queue_action(self):
73 self._cm[telepathy.interfaces.CONN_MGR_INTERFACE].GetParameters(
75 reply_handler = self._on_done,
76 error_handler = self._on_error,
79 def _on_done(self, params):
80 print "Connection Parameters:"
81 for name, flags, signature, default in params:
82 print "\t%s (%s)" % (name, signature),
84 if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_REQUIRED:
86 if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_REGISTER:
88 if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_SECRET:
90 if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_DBUS_PROPERTY:
91 print "dbus-property",
92 if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_HAS_DEFAULT:
93 print "has-default(%s)" % default,
96 super(DisplayParams, self)._on_done()
99 class Connect(Action):
101 def __init__(self, cm, username, password, forward):
102 super(Connect, self).__init__()
105 self._username = username
106 self._password = password
107 self._forward = forward
113 def queue_action(self):
114 self._cm[telepathy.server.CONNECTION_MANAGER].RequestConnection(
117 'username': self._username,
118 'password': self._password,
119 'forward': self._forward,
121 reply_handler = self._on_connection_requested,
122 error_handler = self._on_error,
125 def _on_connection_requested(self, busName, objectPath):
126 self._conn = telepathy.client.Connection(busName, objectPath)
127 self._conn[telepathy.server.CONNECTION].connect_to_signal(
131 self._conn[telepathy.server.CONNECTION].Connect(
132 reply_handler = self._on_generic_message,
133 error_handler = self._on_error,
137 super(Connect, self)._on_done()
139 def _on_change(self, status, reason):
140 if status == telepathy.constants.CONNECTION_STATUS_DISCONNECTED:
141 print "Disconnected!"
143 elif status == telepathy.constants.CONNECTION_STATUS_CONNECTED:
146 elif status == telepathy.constants.CONNECTION_STATUS_CONNECTING:
149 print "Status: %r" % status
152 class SimplePresenceOptions(Action):
154 def __init__(self, connAction):
155 super(SimplePresenceOptions, self).__init__()
156 self._connAction = connAction
158 def queue_action(self):
159 self._connAction.conn[DBUS_PROPERTIES].Get(
160 telepathy.server.CONNECTION_INTERFACE_SIMPLE_PRESENCE,
162 reply_handler = self._on_done,
163 error_handler = self._on_error,
166 def _on_done(self, statuses):
167 print "\tAvailable Statuses"
168 for (key, value) in statuses.iteritems():
169 print "\t\t - %s" % key
170 super(SimplePresenceOptions, self)._on_done()
173 class NullHandle(object):
184 class UserHandle(Action):
186 def __init__(self, connAction):
187 super(UserHandle, self).__init__()
188 self._connAction = connAction
197 return [self._handle]
199 def queue_action(self):
200 self._connAction.conn[telepathy.server.CONNECTION].GetSelfHandle(
201 reply_handler = self._on_done,
202 error_handler = self._on_error,
205 def _on_done(self, handle):
206 self._handle = handle
207 super(UserHandle, self)._on_done()
210 class RequestHandle(Action):
212 def __init__(self, connAction, handleType, handleNames):
213 super(RequestHandle, self).__init__()
214 self._connAction = connAction
216 self._handleType = handleType
217 self._handleNames = handleNames
225 return [self._handle]
227 def queue_action(self):
228 self._connAction.conn[telepathy.server.CONNECTION].RequestHandles(
231 reply_handler = self._on_done,
232 error_handler = self._on_error,
235 def _on_done(self, handles):
236 self._handle = handles[0]
237 super(RequestHandle, self)._on_done()
240 class RequestChannel(Action):
242 def __init__(self, connAction, handleAction, channelType, handleType):
243 super(RequestChannel, self).__init__()
244 self._connAction = connAction
245 self._handleAction = handleAction
247 self._channelType = channelType
248 self._handleType = handleType
254 def queue_action(self):
255 self._connAction.conn[telepathy.server.CONNECTION].RequestChannel(
258 self._handleAction.handle,
260 reply_handler = self._on_done,
261 error_handler = self._on_error,
264 def _on_done(self, channelObjectPath):
265 self._channel = channelObjectPath
266 super(RequestChannel, self)._on_done()
269 class ContactHandles(Action):
271 def __init__(self, connAction):
272 super(UserHandle, self).__init__()
273 self._connAction = connAction
280 def queue_action(self):
283 def _on_done(self, handle):
284 super(UserHandle, self)._on_done()
287 class SimplePresenceStatus(Action):
289 def __init__(self, connAction, handleAction):
290 super(SimplePresenceStatus, self).__init__()
291 self._connAction = connAction
292 self._handleAction = handleAction
294 def queue_action(self):
295 self._connAction.conn[telepathy.server.CONNECTION_INTERFACE_SIMPLE_PRESENCE].GetPresences(
296 self._handleAction.handles,
297 reply_handler = self._on_done,
298 error_handler = self._on_error,
301 def _on_done(self, aliases):
303 for hid, (presenceType, presence, presenceMessage) in aliases.iteritems():
304 print "\t\t%s:" % hid, presenceType, presence, presenceMessage
305 super(SimplePresenceStatus, self)._on_done()
308 class Aliases(Action):
310 def __init__(self, connAction, handleAction):
311 super(Aliases, self).__init__()
312 self._connAction = connAction
313 self._handleAction = handleAction
315 def queue_action(self):
316 self._connAction.conn[telepathy.server.CONNECTION_INTERFACE_ALIASING].RequestAliases(
317 self._handleAction.handles,
318 reply_handler = self._on_done,
319 error_handler = self._on_error,
322 def _on_done(self, aliases):
324 for alias in aliases:
326 super(Aliases, self)._on_done()
329 class Disconnect(Action):
331 def __init__(self, connAction):
332 super(Disconnect, self).__init__()
333 self._connAction = connAction
335 def queue_action(self):
336 self._connAction.conn[telepathy.server.CONNECTION].Disconnect(
337 reply_handler = self._on_done,
338 error_handler = self._on_error,
342 if __name__ == '__main__':
343 loop = gobject.MainLoop()
346 cm = get_connection_manager(reg)
348 nullHandle = NullHandle()
350 dummy = DummyAction()
355 dp = DisplayParams(cm)
356 lastAction.append_action(dp)
360 username = sys.argv[1]
361 password = sys.argv[2]
362 forward = sys.argv[3]
363 con = Connect(cm, username, password, forward)
364 lastAction.append_action(con)
368 spo = SimplePresenceOptions(con)
369 lastAction.append_action(spo)
374 lastAction.append_action(uh)
377 ua = Aliases(con, uh)
378 lastAction.append_action(ua)
381 sps = SimplePresenceStatus(con, uh)
382 lastAction.append_action(sps)
386 rclh = RequestHandle(con, telepathy.HANDLE_TYPE_LIST, ["subscribe"])
387 lastAction.append_action(rclh)
390 rclc = RequestChannel(
393 telepathy.CHANNEL_TYPE_CONTACT_LIST,
394 telepathy.HANDLE_TYPE_LIST,
396 lastAction.append_action(rclc)
399 # @todo get aliases for contacts
402 rch = RequestHandle(con, telepathy.HANDLE_TYPE_CONTACT, ["18005558355"]) #(1-800-555-TELL)
403 lastAction.append_action(rch)
408 smHandleType = telepathy.HANDLE_TYPE_CONTACT
410 smHandle = nullHandle
411 smHandleType = telepathy.HANDLE_TYPE_NONE
412 rsmc = RequestChannel(
415 telepathy.CHANNEL_TYPE_STREAMED_MEDIA,
418 lastAction.append_action(rsmc)
423 dis = Disconnect(con)
424 lastAction.append_action(dis)
427 quitter = QuitLoop(loop)
428 lastAction.append_action(quitter)
431 firstAction.queue_action()