1 from Screens.Screen import Screen
2 from Screens.MessageBox import MessageBox
3 from Components.ActionMap import ActionMap
4 from Components.Label import Label
5 from Plugins.Plugin import PluginDescriptor
6 from Tools import Notifications
8 from twisted.internet import reactor
9 from twisted.internet.protocol import ReconnectingClientFactory
10 from twisted.protocols.basic import LineReceiver
12 from enigma import eTimer
14 my_global_session = None
16 from Components.config import config, ConfigSubsection, ConfigIP, ConfigEnableDisable, getConfigListEntry
17 from Components.ConfigList import ConfigList, ConfigListScreen
19 config.plugins.FritzCall = ConfigSubsection()
20 config.plugins.FritzCall.hostname = ConfigIP(default = [192,168,178,254])
21 config.plugins.FritzCall.enable = ConfigEnableDisable(default = False)
23 class FritzCallSetup(ConfigListScreen, Screen):
25 <screen position="100,100" size="550,400" title="FritzCall Setup" >
26 <widget name="config" position="20,10" size="460,350" scrollbarMode="showOnDemand" />
30 def __init__(self, session, args = None):
31 from Tools.BoundFunction import boundFunction
33 Screen.__init__(self, session)
34 self.onClose.append(self.abort)
36 # nun erzeugen wir eine liste von elementen fuer die menu liste.
38 self.list.append(getConfigListEntry(_("Call monitoring"), config.plugins.FritzCall.enable))
39 self.list.append(getConfigListEntry(_("Fritz!Box FON IP address"), config.plugins.FritzCall.hostname))
40 ConfigListScreen.__init__(self, self.list)
43 self["setupActions"] = ActionMap(["SetupActions"],
46 "cancel": self.cancel,
54 for x in self["config"].list:
56 if fritz_call is not None:
61 for x in self["config"].list:
65 class FritzProtocol(LineReceiver):
68 def lineReceived(self, line):
70 #15.07.06 00:38:54;CALL;1;4;<provider>;<callee>;
71 #15.07.06 00:38:58;DISCONNECT;1;0;
72 #15.07.06 00:39:22;RING;0;<caller>;<outgoing msn>;
73 #15.07.06 00:39:27;DISCONNECT;0;0;
76 (date, event) = a[0:2]
82 text = _("incoming call!\n%s calls on %s!") % (number, phone)
84 elif event == "DISCONNECT":
85 Notifications.RemovePopup("FritzCall_%s" % line)
90 Notifications.AddPopup(text=text, type=MessageBox.TYPE_INFO, timeout=timeout, id="FritzCall_%s" % line)
92 class FritzClientFactory(ReconnectingClientFactory):
98 self.hangup_ok = False
100 def startedConnecting(self, connector):
101 Notifications.AddPopup(text=_("Connecting to Fritz!Box..."), type=MessageBox.TYPE_INFO, timeout=2, id="FritzCallConnect")
103 def buildProtocol(self, addr):
104 Notifications.AddPopup(text=_("Connected to Fritz!Box!"), type=MessageBox.TYPE_INFO, timeout=2, id="FritzCallConnect")
106 return FritzProtocol()
108 def clientConnectionLost(self, connector, reason):
109 if not self.hangup_ok:
110 Notifications.AddPopup(text=_("Disconnected from\nFritz!Box! (%s)\nretrying...") % reason.getErrorMessage(), type=MessageBox.TYPE_INFO, timeout=4, id="FritzCallConnect")
111 ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
113 def clientConnectionFailed(self, connector, reason):
114 Notifications.AddPopup(text=_("Connection to Fritz!Box\nfailed! (%s)\nretrying...") % reason.getErrorMessage(), type=MessageBox.TYPE_INFO, timeout=4, id="FritzCallConnect")
115 ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
125 if config.plugins.FritzCall.enable.value:
126 f = FritzClientFactory()
127 self.d = (f, reactor.connectTCP("%d.%d.%d.%d" % tuple(config.plugins.FritzCall.hostname.value), 1012, f))
133 if self.d is not None:
134 self.d[0].hangup_ok = True
135 self.d[0].stopTrying()
136 self.d[1].disconnect()
140 session.open(FritzCallSetup)
144 def autostart(reason, **kwargs):
147 # ouch, this is a hack
148 if kwargs.has_key("session"):
149 global my_global_session
150 my_global_session = kwargs["session"]
155 fritz_call = FritzCall()
157 fritz_call.shutdown()
160 def Plugins(**kwargs):
161 return [ PluginDescriptor(name="FritzCall", description="Display Fritzbox-Fon calls on screen", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=main),
162 PluginDescriptor(where = [PluginDescriptor.WHERE_SESSIONSTART, PluginDescriptor.WHERE_AUTOSTART], fnc = autostart) ]