1 from Screens.Screen import Screen
2 from Screens.MessageBox import MessageBox
3 from Components.ActionMap import ActionMap
4 from Plugins.Plugin import PluginDescriptor
5 from Tools import Notifications
7 from twisted.internet import reactor
8 from twisted.internet.protocol import ReconnectingClientFactory
9 from twisted.protocols.basic import LineReceiver
11 my_global_session = None
13 from Components.config import config, ConfigSubsection, ConfigIP, ConfigEnableDisable, getConfigListEntry
14 from Components.ConfigList import ConfigListScreen
16 config.plugins.FritzCall = ConfigSubsection()
17 config.plugins.FritzCall.hostname = ConfigIP(default = [192,168,178,254])
18 config.plugins.FritzCall.enable = ConfigEnableDisable(default = False)
20 class FritzCallSetup(ConfigListScreen, Screen):
22 <screen position="100,100" size="550,400" title="FritzCall Setup" >
23 <widget name="config" position="20,10" size="460,350" scrollbarMode="showOnDemand" />
27 def __init__(self, session, args = None):
28 Screen.__init__(self, session)
29 self.onClose.append(self.abort)
31 # nun erzeugen wir eine liste von elementen fuer die menu liste.
33 self.list.append(getConfigListEntry(_("Call monitoring"), config.plugins.FritzCall.enable))
34 self.list.append(getConfigListEntry(_("Fritz!Box FON IP address"), config.plugins.FritzCall.hostname))
35 ConfigListScreen.__init__(self, self.list)
38 self["setupActions"] = ActionMap(["SetupActions"],
41 "cancel": self.cancel,
49 for x in self["config"].list:
51 if fritz_call is not None:
56 for x in self["config"].list:
60 class FritzProtocol(LineReceiver):
63 def lineReceived(self, line):
65 #15.07.06 00:38:54;CALL;1;4;<provider>;<callee>;
66 #15.07.06 00:38:58;DISCONNECT;1;0;
67 #15.07.06 00:39:22;RING;0;<caller>;<outgoing msn>;
68 #15.07.06 00:39:27;DISCONNECT;0;0;
71 (date, event) = a[0:2]
77 text = _("incoming call!\n%s calls on %s!") % (number, phone)
79 elif event == "DISCONNECT":
80 Notifications.RemovePopup("FritzCall_%s" % line)
85 Notifications.AddPopup(text=text, type=MessageBox.TYPE_INFO, timeout=timeout, id="FritzCall_%s" % line)
87 class FritzClientFactory(ReconnectingClientFactory):
93 self.hangup_ok = False
95 def startedConnecting(self, connector):
96 Notifications.AddPopup(text=_("Connecting to Fritz!Box..."), type=MessageBox.TYPE_INFO, timeout=2, id="FritzCallConnect")
98 def buildProtocol(self, addr):
99 Notifications.AddPopup(text=_("Connected to Fritz!Box!"), type=MessageBox.TYPE_INFO, timeout=2, id="FritzCallConnect")
101 return FritzProtocol()
103 def clientConnectionLost(self, connector, reason):
104 if not self.hangup_ok:
105 Notifications.AddPopup(text=_("Disconnected from\nFritz!Box! (%s)\nretrying...") % reason.getErrorMessage(), type=MessageBox.TYPE_INFO, timeout=4, id="FritzCallConnect")
106 ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
108 def clientConnectionFailed(self, connector, reason):
109 Notifications.AddPopup(text=_("Connection to Fritz!Box\nfailed! (%s)\nretrying...") % reason.getErrorMessage(), type=MessageBox.TYPE_INFO, timeout=4, id="FritzCallConnect")
110 ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
120 if config.plugins.FritzCall.enable.value:
121 f = FritzClientFactory()
122 self.d = (f, reactor.connectTCP("%d.%d.%d.%d" % tuple(config.plugins.FritzCall.hostname.value), 1012, f))
128 if self.d is not None:
129 self.d[0].hangup_ok = True
130 self.d[0].stopTrying()
131 self.d[1].disconnect()
134 def main(session, **kwargs):
135 session.open(FritzCallSetup)
139 def autostart(reason, **kwargs):
142 # ouch, this is a hack
143 if kwargs.has_key("session"):
144 global my_global_session
145 my_global_session = kwargs["session"]
150 fritz_call = FritzCall()
152 fritz_call.shutdown()
155 def Plugins(**kwargs):
156 return [ PluginDescriptor(name="FritzCall", description="Display Fritzbox-Fon calls on screen", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=main),
157 PluginDescriptor(where = [PluginDescriptor.WHERE_SESSIONSTART, PluginDescriptor.WHERE_AUTOSTART], fnc = autostart) ]