1 from Screens.Screen import Screen
2 from Screens.MessageBox import MessageBox
3 from Components.ActionMap import NumberActionMap
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, configElement, configSequence, getConfigListEntry, configsequencearg, configElementBoolean
17 from Components.ConfigList import ConfigList
19 config.FritzCall = ConfigSubsection()
20 config.FritzCall.hostname = configElement("config.FritzCall.hostname", configSequence, [192,168,178,254], configsequencearg.get("IP"))
21 config.FritzCall.enable = configElementBoolean("config.FritzCall.enable", 0)
23 class FritzCallSetup(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
34 Screen.__init__(self, session)
35 self.onClose.append(self.abort)
37 # nun erzeugen wir eine liste von elementen fuer die menu liste.
39 self.list.append(getConfigListEntry(_("Call monitoring"), config.FritzCall.enable))
40 self.list.append(getConfigListEntry(_("Fritz!Box FON IP address"), config.FritzCall.hostname))
41 self["config"] = ConfigList(self.list)
44 self["setupActions"] = NumberActionMap(["SetupActions"],
46 "left": boundFunction(self["config"].handleKey, config.key["prevElement"]),
47 "right": boundFunction(self["config"].handleKey, config.key["nextElement"]),
48 "1": self.keyNumberGlobal,
49 "2": self.keyNumberGlobal,
50 "3": self.keyNumberGlobal,
51 "4": self.keyNumberGlobal,
52 "5": self.keyNumberGlobal,
53 "6": self.keyNumberGlobal,
54 "7": self.keyNumberGlobal,
55 "8": self.keyNumberGlobal,
56 "9": self.keyNumberGlobal,
57 "0": self.keyNumberGlobal,
59 "cancel": self.cancel,
63 def keyNumberGlobal(self, number):
64 if self["config"].getCurrent()[1].parent.enabled == True:
65 self["config"].handleKey(config.key[str(number)])
71 for x in self["config"].list:
73 if fritz_call is not None:
78 for x in self["config"].list:
82 class FritzProtocol(LineReceiver):
85 def lineReceived(self, line):
87 #15.07.06 00:38:54;CALL;1;4;<provider>;<callee>;
88 #15.07.06 00:38:58;DISCONNECT;1;0;
89 #15.07.06 00:39:22;RING;0;<caller>;<outgoing msn>;
90 #15.07.06 00:39:27;DISCONNECT;0;0;
93 (date, event) = a[0:2]
98 text = _("incoming call!\n%s calls on %s!") % (number, phone)
103 Notifications.AddNotification(MessageBox, text, type=MessageBox.TYPE_INFO, timeout=timeout)
105 class FritzClientFactory(ReconnectingClientFactory):
111 self.hangup_ok = False
113 def startedConnecting(self, connector):
114 Notifications.AddNotification(MessageBox, _("Connecting to Fritz!Box..."), type=MessageBox.TYPE_INFO, timeout=2)
116 def buildProtocol(self, addr):
117 Notifications.AddNotification(MessageBox, _("Connected to Fritz!Box!"), type=MessageBox.TYPE_INFO, timeout=2)
119 return FritzProtocol()
121 def clientConnectionLost(self, connector, reason):
122 if not self.hangup_ok:
123 Notifications.AddNotification(MessageBox, _("Disconnected from\nFritz!Box! (%s)\nretrying...") % reason.getErrorMessage(), type=MessageBox.TYPE_INFO, timeout=4)
124 ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
126 def clientConnectionFailed(self, connector, reason):
127 Notifications.AddNotification(MessageBox, _("Connection to Fritz!Box\nfailed! (%s)\nretrying...") % reason.getErrorMessage(), type=MessageBox.TYPE_INFO, timeout=4)
128 ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
138 if config.FritzCall.enable.value:
139 f = FritzClientFactory()
140 self.d = (f, reactor.connectTCP("%d.%d.%d.%d" % tuple(config.FritzCall.hostname.value), 1012, f))
146 if self.d is not None:
147 self.d[0].hangup_ok = True
148 self.d[0].stopTrying()
149 self.d[1].disconnect()
153 session.open(FritzCallSetup)
157 def autostart(reason, **kwargs):
160 # ouch, this is a hack
161 if kwargs.has_key("session"):
162 global my_global_session
163 my_global_session = kwargs["session"]
168 fritz_call = FritzCall()
170 fritz_call.shutdown()
173 def Plugins(**kwargs):
174 return [ PluginDescriptor(name="FritzCall", description="Display Fritzbox-Fon calls on screen", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=main),
175 PluginDescriptor(where = [PluginDescriptor.WHERE_SESSIONSTART, PluginDescriptor.WHERE_AUTOSTART], fnc = autostart) ]