10 _moduleLogger = logging.getLogger(__name__)
11 DBUS_PROPERTIES = 'org.freedesktop.DBus.Properties'
14 class NewChannelSignaller(object):
16 def __init__(self, on_new_channel):
17 self._sessionBus = dbus.SessionBus()
18 self._on_user_new_channel = on_new_channel
21 self._sessionBus.add_signal_receiver(
24 "org.freedesktop.Telepathy.Connection",
30 self._sessionBus.remove_signal_receiver(
33 "org.freedesktop.Telepathy.Connection",
38 @gtk_toolbox.log_exception(_moduleLogger)
40 self, channelObjectPath, channelType, handleType, handle, supressHandler
42 connObjectPath = channel_path_to_conn_path(channelObjectPath)
43 serviceName = path_to_service_name(channelObjectPath)
45 self._on_user_new_channel(
46 self._sessionBus, serviceName, connObjectPath, channelObjectPath, channelType
49 _moduleLogger.exception("Blocking exception from being passed up")
52 class ChannelClosed(object):
54 def __init__(self, bus, conn, chan, on_closed):
55 self.__on_closed = on_closed
57 chan[telepathy.interfaces.CHANNEL].connect_to_signal(
62 @gtk_toolbox.log_exception(_moduleLogger)
64 self.__on_closed(self)
67 class CallMonitor(gobject.GObject):
71 gobject.SIGNAL_RUN_LAST,
76 gobject.SIGNAL_RUN_LAST,
83 gobject.GObject.__init__(self)
84 self._isActive = False
85 self._newChannelMonitor = NewChannelSignaller(self._on_new_channel)
86 self._channelClosedMonitors = []
90 self._newChannelMonitor.start()
93 self._isActive = False
94 self._newChannelMonitor.stop()
96 def _on_new_channel(self, sessionBus, serviceName, connObjectPath, channelObjectPath, channelType):
97 if not self._isActive:
100 if channelType != telepathy.interfaces.CHANNEL_TYPE_STREAMED_MEDIA:
103 cmName = cm_from_path(connObjectPath)
104 conn = telepathy.client.Connection(serviceName, connObjectPath)
106 chan = telepathy.client.Channel(serviceName, channelObjectPath)
107 except dbus.exceptions.UnknownMethodException:
108 _moduleLogger.exception("Client might not have implemented a deprecated method")
111 missDetection = ChannelClosed(
112 sessionBus, conn, chan, self._on_close
114 self._outstandingRequests.append(missDetection)
115 if len(self._outstandingRequests) == 1:
116 self.emit("call_start")
118 def _on_close(self, channelCloseMonitor):
119 self._outstandingRequests.remove(channelCloseMonitor)
120 if not self._outstandingRequests:
121 self.emit("call_stop")
124 def channel_path_to_conn_path(channelObjectPath):
126 >>> channel_path_to_conn_path("/org/freedesktop/Telepathy/ConnectionManager/theonering/gv/USERNAME/Channel1")
127 '/org/freedesktop/Telepathy/ConnectionManager/theonering/gv/USERNAME'
129 return channelObjectPath.rsplit("/", 1)[0]
132 def path_to_service_name(path):
134 >>> path_to_service_name("/org/freedesktop/Telepathy/ConnectionManager/theonering/gv/USERNAME/Channel1")
135 'org.freedesktop.Telepathy.ConnectionManager.theonering.gv.USERNAME'
137 return ".".join(path[1:].split("/")[0:7])
140 def cm_from_path(path):
142 >>> cm_from_path("/org/freedesktop/Telepathy/ConnectionManager/theonering/gv/USERNAME/Channel1")
145 return path[1:].split("/")[4]