global: 'Dream Multimedia' -> 'Dream Property'
[enigma2-plugins.git] / namezap / src / plugin.py
1 # Plugin definition
2 from Plugins.Plugin import PluginDescriptor
3
4 from enigma import eServiceCenter, eServiceReference
5 from Components.Label import Label
6 from Screens import InfoBarGenerics
7 from Screens.InfoBar import InfoBar
8 from Components.config import config, ConfigSubsection, ConfigSelection
9
10 from NamezapSetup import NamezapSetup
11
12 config.plugins.namezap = ConfigSubsection()
13 config.plugins.namezap.style = ConfigSelection(choices = [
14                 ("number", _("Only Number")),
15                 ("name", _("Service Name")),
16                 ("both", _("Number and Name"))
17         ], default = "both"
18 )
19
20 NumberZap = InfoBarGenerics.NumberZap
21 class NameZap(NumberZap):
22         STYLE_NUMBER = 0
23         STYLE_NAME = 1
24         STYLE_BOTH = 2
25
26         skin = """<screen name="NameZap" position="center,center" size="270,60" title="Channel">
27                         <widget name="name" position="3,15" size="264,25" halign="left" font="Regular;23" />
28                 </screen>"""
29
30         def __init__(self, *args, **kwargs):
31                 NumberZap.__init__(self, *args, **kwargs)
32                 if InfoBar.instance is None:
33                         self.style = self.STYLE_NUMBER
34                 else:
35                         self.style = {"number": self.STYLE_NUMBER, "name": self.STYLE_NAME, "both": self.STYLE_BOTH}[config.plugins.namezap.style.value]
36
37                 if self.style == self.STYLE_NUMBER:
38                         self.skinName = "NumberZap"
39
40                 self["name"] = Label("")
41                 self.serviceHandler = eServiceCenter.getInstance()
42                 if self.style != self.STYLE_NUMBER:
43                         self.updateServiceName(int(self.field))
44
45         def keyNumberGlobal(self, number):
46                 NumberZap.keyNumberGlobal(self, number)
47                 if self.style != self.STYLE_NUMBER:
48                         self.updateServiceName(int(self.field))
49
50         def searchNumberHelper(self, serviceHandler, num, bouquet):
51                 servicelist = self.serviceHandler.list(bouquet)
52                 if not servicelist is None:
53                         while num:
54                                 serviceIterator = servicelist.getNext()
55                                 if not serviceIterator.valid(): #check end of list
56                                         break
57                                 playable = not (serviceIterator.flags & (eServiceReference.isMarker|eServiceReference.isDirectory))
58                                 if playable:
59                                         num -= 1;
60                         if not num: #found service with searched number ?
61                                 return serviceIterator, 0
62                 return None, num
63
64         def updateServiceName(self, number):
65                 bouquet = InfoBar.instance.servicelist.bouquet_root
66                 service = None
67                 serviceHandler = self.serviceHandler
68                 if not config.usage.multibouquet.value:
69                         service, number = self.searchNumberHelper(serviceHandler, number, bouquet)
70                 else:
71                         bouquetlist = serviceHandler.list(bouquet)
72                         if not bouquetlist is None:
73                                 while number:
74                                         bouquet = bouquetlist.getNext()
75                                         if not bouquet.valid(): #check end of list
76                                                 break
77                                         if bouquet.flags & eServiceReference.isDirectory:
78                                                 service, number = self.searchNumberHelper(serviceHandler, number, bouquet)
79                 if service is not None:
80                         info = serviceHandler.info(service)
81
82                         sname = info.getName(service).replace('\xc2\x86', '').replace('\xc2\x87', '')
83                         if self.style == self.STYLE_BOTH:
84                                 self["name"].setText("%s. %s" % (self.field, sname))
85                         else:
86                                 self["name"].setText(sname)
87                 else:
88                         sname = _("Unknown Service")
89                         if self.style == self.STYLE_BOTH:
90                                 self["name"].setText("%s. %s" % (self.field, sname))
91                         else:
92                                 self["name"].setText("%s (%s)" % (sname, self.field))
93
94 def autostart(reason, *args, **kwargs):
95         if reason == 0:
96                 InfoBarGenerics.NumberZap = NameZap
97
98 def main(session, *args, **kwargs):
99         session.open(NamezapSetup)
100
101 def menu(menuid):
102         if menuid != "services_recordings":
103                 return []
104         return [(_("NameZAP Setup"), main, "namezap_setup", None)]
105
106 def Plugins(**kwargs):
107         return [
108                 PluginDescriptor(
109                         where=PluginDescriptor.WHERE_AUTOSTART,
110                         fnc=autostart,
111                         needsRestart=False,
112                 ),
113                 PluginDescriptor(
114                         where=PluginDescriptor.WHERE_MENU,
115                         fnc=menu,
116                         needsRestart=False,
117                 ),
118         ]