9 _moduleLogger = logging.getLogger(__name__)
12 DBUS_PROPERTIES = 'org.freedesktop.DBus.Properties'
15 class AccountManager(telepathy.client.interfacefactory.InterfaceFactory):
17 service_name = 'org.freedesktop.Telepathy.AccountManager'
18 object_path = '/org/freedesktop/Telepathy/AccountManager'
20 # Some versions of Mission Control are only activatable under this
21 # name, not under the generic AccountManager name
22 MC5_name = 'org.freedesktop.Telepathy.MissionControl5'
23 MC5_path = '/org/freedesktop/Telepathy/MissionControl5'
25 def __init__(self, bus=None):
30 obj = bus.get_object(self.service_name, self.object_path)
33 # try activating MissionControl5 (ugly work-around)
34 mc5 = bus.get_object(self.MC5_name, self.MC5_path)
37 obj = bus.get_object(self.service_name, self.object_path)
38 telepathy.client.interfacefactory.InterfaceFactory.__init__(self, obj, telepathy.interfaces.ACCOUNT_MANAGER)
40 self[DBUS_PROPERTIES].Get(
41 telepathy.interfaces.ACCOUNT_MANAGER,
43 reply_handler=self._on_get,
44 error_handler=self._on_error,
47 def _on_get(self, stuff):
48 self.get_valid_interfaces().update(stuff)
50 def _on_error(self, *args):
51 _moduleLogger.error(args)
54 class Account(telepathy.client.interfacefactory.InterfaceFactory):
56 def __init__(self, object_path, bus=None):
59 service_name = 'org.freedesktop.Telepathy.AccountManager'
61 obj = bus.get_object(service_name, object_path)
62 telepathy.client.interfacefactory.InterfaceFactory.__init__(self, obj, telepathy.interfaces.ACCOUNT)
64 self[DBUS_PROPERTIES].Get(
65 telepathy.interfaces.ACCOUNT,
67 reply_handler=self._on_get,
68 error_handler=self._on_error,
71 def _on_get(self, stuff):
72 self.get_valid_interfaces().update(stuff)
74 def _on_error(self, *args):
75 _moduleLogger.error(args)
78 def _process_acct_path(acct_path, target, message):
79 print "Account:", acct_path
80 acct = Account(acct_path)
81 conn = acct[DBUS_PROPERTIES].Get(telepathy.interfaces.ACCOUNT, 'Connection')
82 print "Connection:", conn
85 conn = telepathy.client.Connection(conn.replace('/', '.')[1:], conn)
86 conn.call_when_ready(lambda con: _show_conn(acct, acct_path, con, target, message))
89 def _show_conn(acct, path, conn, target, message):
91 print "\t", repr(acct)
92 print "\t", repr(conn)
95 telepathy.interfaces.CHANNEL+".ChannelType": telepathy.interfaces.CHANNEL_TYPE_TEXT,
96 telepathy.interfaces.CHANNEL+".TargetHandleType": telepathy.constants.HANDLE_TYPE_CONTACT,
97 telepathy.server.CHANNEL_INTERFACE+".TargetID": target,
99 conn[telepathy.server.CONNECTION_INTERFACE_REQUESTS].EnsureChannel(
102 lambda isYours, channelObjectPath, properties: _on_ensure(acct, conn, message, isYours, channelObjectPath, properties),
103 error_handler = _on_error,
107 def _on_ensure(acct, conn, message, yours, channelObjectPath, properties):
108 channel = telepathy.client.Channel(conn.service_name, channelObjectPath)
109 handle = properties[telepathy.server.CHANNEL_INTERFACE+".TargetHandle"]
110 channel[telepathy.server.CHANNEL_TYPE_TEXT].Send(
111 telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
113 reply_handler = lambda: _on_send(channel),
114 error_handler = _on_error,
118 def _on_send(channel):
120 channel[telepathy.server.CHANNEL].Close(
121 reply_handler = _on_channel_closed,
122 error_handler = _on_error,
126 def _on_channel_closed():
127 print "Channel Closed"
131 def _on_error(*args):
132 print "Command failed:", args
136 if __name__ == '__main__':
139 from dbus.mainloop.glib import DBusGMainLoop
142 message = " ".join(sys.argv[2:])
144 DBusGMainLoop(set_as_default=True)
146 am = AccountManager()
147 for acct_path in am[DBUS_PROPERTIES].Get(telepathy.interfaces.ACCOUNT_MANAGER, 'ValidAccounts'):
148 if acct_path.startswith("/org/freedesktop/Telepathy/Account/theonering"):
149 _process_acct_path(acct_path, target, message)
152 loop = gobject.MainLoop()