8 import util.go_utils as gobject_utils
12 _moduleLogger = logging.getLogger(__name__)
13 DBUS_PROPERTIES = 'org.freedesktop.DBus.Properties'
16 class WasMissedCall(object):
18 def __init__(self, bus, conn, chan, on_success, on_error):
19 self.__on_success = on_success
20 self.__on_error = on_error
22 self._requested = None
23 self._didMembersChange = False
24 self._didClose = False
25 self._didReport = False
27 self._onTimeout = gobject_utils.Timeout(self._on_timeout)
28 self._onTimeout.start(seconds=60)
30 chan[telepathy.interfaces.CHANNEL_INTERFACE_GROUP].connect_to_signal(
32 self._on_members_changed,
35 chan[telepathy.interfaces.CHANNEL].connect_to_signal(
40 chan[DBUS_PROPERTIES].GetAll(
41 telepathy.interfaces.CHANNEL_INTERFACE,
42 reply_handler = self._on_got_all,
43 error_handler = self._on_error,
47 self._report_error("by request")
49 def _report_missed_if_ready(self):
52 elif self._requested is not None and (self._didMembersChange or self._didClose):
54 self._report_error("wrong direction")
56 self._report_success()
58 self._report_error("members added")
61 self._report_error("closed too early")
63 def _report_success(self):
64 assert not self._didReport, "Double reporting a missed call"
65 self._didReport = True
66 self._onTimeout.cancel()
67 self.__on_success(self)
69 def _report_error(self, reason):
70 assert not self._didReport, "Double reporting a missed call"
71 self._didReport = True
72 self._onTimeout.cancel()
73 self.__on_error(self, reason)
75 @misc.log_exception(_moduleLogger)
76 def _on_got_all(self, properties):
77 self._requested = properties["Requested"]
78 self._report_missed_if_ready()
80 @misc.log_exception(_moduleLogger)
81 def _on_members_changed(self, message, added, removed, lp, rp, actor, reason):
83 self._didMembersChange = True
84 self._report_missed_if_ready()
86 @misc.log_exception(_moduleLogger)
89 self._report_missed_if_ready()
91 @misc.log_exception(_moduleLogger)
92 def _on_error(self, *args):
93 self._report_error(args)
95 @misc.log_exception(_moduleLogger)
96 def _on_timeout(self):
97 self._report_error("timeout")
101 class NewChannelSignaller(object):
103 def __init__(self, on_new_channel):
104 self._sessionBus = dbus.SessionBus()
105 self._on_user_new_channel = on_new_channel
108 self._sessionBus.add_signal_receiver(
109 self._on_new_channel,
111 "org.freedesktop.Telepathy.Connection",
117 self._sessionBus.remove_signal_receiver(
118 self._on_new_channel,
120 "org.freedesktop.Telepathy.Connection",
125 @misc.log_exception(_moduleLogger)
127 self, channelObjectPath, channelType, handleType, handle, supressHandler
129 connObjectPath = channel_path_to_conn_path(channelObjectPath)
130 serviceName = path_to_service_name(channelObjectPath)
132 self._on_user_new_channel(
133 self._sessionBus, serviceName, connObjectPath, channelObjectPath, channelType
136 _moduleLogger.exception("Blocking exception from being passed up")
139 class EnableSystemContactIntegration(object):
141 ACCOUNT_MGR_NAME = "org.freedesktop.Telepathy.AccountManager"
142 ACCOUNT_MGR_PATH = "/org/freedesktop/Telepathy/AccountManager"
143 ACCOUNT_MGR_IFACE_QUERY = "com.nokia.AccountManager.Interface.Query"
144 ACCOUNT_IFACE_COMPAT = "com.nokia.Account.Interface.Compat"
145 ACCOUNT_IFACE_COMPAT_PROFILE = "com.nokia.Account.Interface.Compat.Profile"
146 DBUS_PROPERTIES = 'org.freedesktop.DBus.Properties'
148 def __init__(self, profileName):
149 self._bus = dbus.SessionBus()
150 self._profileName = profileName
153 self._accountManager = self._bus.get_object(
154 self.ACCOUNT_MGR_NAME,
155 self.ACCOUNT_MGR_PATH,
157 self._accountManagerQuery = dbus.Interface(
158 self._accountManager,
159 dbus_interface=self.ACCOUNT_MGR_IFACE_QUERY,
162 self._accountManagerQuery.FindAccounts(
164 self.ACCOUNT_IFACE_COMPAT_PROFILE: self._profileName,
166 reply_handler = self._on_found_accounts_reply,
167 error_handler = self._on_error,
170 @misc.log_exception(_moduleLogger)
171 def _on_found_accounts_reply(self, accountObjectPaths):
172 for accountObjectPath in accountObjectPaths:
173 print accountObjectPath
174 account = self._bus.get_object(
175 self.ACCOUNT_MGR_NAME,
178 accountProperties = dbus.Interface(
180 self.DBUS_PROPERTIES,
182 accountProperties.Set(
183 self.ACCOUNT_IFACE_COMPAT,
184 "SecondaryVCardFields",
186 reply_handler = self._on_field_set,
187 error_handler = self._on_error,
190 @misc.log_exception(_moduleLogger)
191 def _on_field_set(self):
192 _moduleLogger.info("SecondaryVCardFields Set")
194 @misc.log_exception(_moduleLogger)
195 def _on_error(self, error):
196 _moduleLogger.error("%r" % (error, ))
199 def channel_path_to_conn_path(channelObjectPath):
201 >>> channel_path_to_conn_path("/org/freedesktop/Telepathy/ConnectionManager/theonering/gv/USERNAME/Channel1")
202 '/org/freedesktop/Telepathy/ConnectionManager/theonering/gv/USERNAME'
204 return channelObjectPath.rsplit("/", 1)[0]
207 def path_to_service_name(path):
209 >>> path_to_service_name("/org/freedesktop/Telepathy/ConnectionManager/theonering/gv/USERNAME/Channel1")
210 'org.freedesktop.Telepathy.ConnectionManager.theonering.gv.USERNAME'
212 return ".".join(path[1:].split("/")[0:7])
215 def cm_from_path(path):
217 >>> cm_from_path("/org/freedesktop/Telepathy/ConnectionManager/theonering/gv/USERNAME/Channel1")
220 return path[1:].split("/")[4]