6 import dbus.mainloop.glib
7 dbus.mainloop.glib.DBusGMainLoop(set_as_default = True)
13 reg = telepathy.client.ManagerRegistry()
18 def get_connection_manager(reg):
19 cm = reg.GetManager('theonering')
28 def queue_action(self):
31 def append_action(self, action):
32 assert self._action is None
36 if self._action is None:
38 self._action.queue_action()
40 def _on_error(self, error):
43 def _on_generic_message(self, *args):
47 class QuitLoop(Action):
49 def __init__(self, loop):
50 super(QuitLoop, self).__init__()
53 def queue_action(self):
57 class DisplayParams(Action):
59 def __init__(self, cm):
60 super(DisplayParams, self).__init__()
63 def queue_action(self):
64 self._cm[telepathy.interfaces.CONN_MGR_INTERFACE].GetParameters(
66 reply_handler = self._on_done,
67 error_handler = self._on_error,
70 def _on_done(self, params):
71 super(DisplayParams, self)._on_done()
72 for name, flags, signature, default in params:
73 print "%s (%s)" % (name, signature),
75 if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_REQUIRED:
77 if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_REGISTER:
79 if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_SECRET:
81 if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_DBUS_PROPERTY:
82 print "dbus-property",
83 if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_HAS_DEFAULT:
84 print "has-default(%s)" % default,
89 class Connect(Action):
91 def __init__(self, cm, username, password, forward):
92 super(Connect, self).__init__()
95 self._username = username
96 self._password = password
97 self._forward = forward
103 def queue_action(self):
104 self._cm[telepathy.server.CONNECTION_MANAGER].RequestConnection(
107 'username': self._username,
108 'password': self._password,
109 'forward': self._forward,
111 reply_handler = self._on_connection_requested,
112 error_handler = self._on_error,
115 def _on_connection_requested(self, busName, objectPath):
116 self._conn = telepathy.client.Connection(busName, objectPath)
117 self._conn[telepathy.server.CONNECTION].connect_to_signal(
121 self._conn[telepathy.server.CONNECTION].Connect(
122 reply_handler = self._on_generic_message,
123 error_handler = self._on_error,
127 super(Connect, self)._on_done()
129 def _on_change(self, status, reason):
130 if status == telepathy.constants.CONNECTION_STATUS_DISCONNECTED:
131 print "Disconnected!"
133 elif status == telepathy.constants.CONNECTION_STATUS_CONNECTED:
137 print "Status: %r" % status
140 class Disconnect(Action):
142 def __init__(self, connAction):
143 super(Disconnect, self).__init__()
144 self._connAction = connAction
146 def queue_action(self):
147 self._connAction.conn[telepathy.server.CONNECTION].Disconnect(
148 reply_handler = self._on_done,
149 error_handler = self._on_error,
153 if __name__ == '__main__':
154 loop = gobject.MainLoop()
157 cm = get_connection_manager(reg)
162 dp = DisplayParams(cm)
163 lastAction.append_action(dp)
166 username = sys.argv[1]
167 password = sys.argv[2]
168 forward = sys.argv[3]
169 con = Connect(cm, username, password, forward)
170 lastAction.append_action(con)
173 dis = Disconnect(con)
174 lastAction.append_action(dis)
177 quitter = QuitLoop(loop)
178 lastAction.append_action(quitter)