Made ZapHistoryBrowser translateable and added german translation
[enigma2-plugins.git] / zaphistorybrowser / src / plugin.py
1 ##
2 ## Zap-History Browser
3 ## by AliAbdul
4 ##
5 from Components.ActionMap import ActionMap
6 from Components.Label import Label
7 from Components.Language import language
8 from Components.MenuList import MenuList
9 from enigma import eServiceCenter
10 from os import environ
11 from Plugins.Plugin import PluginDescriptor
12 from Screens.Screen import Screen
13 from Tools.Directories import resolveFilename, SCOPE_LANGUAGE
14 import gettext
15
16 ################################################
17
18 lang = language.getLanguage()
19 environ["LANGUAGE"] = lang[:2]\r
20 gettext.bindtextdomain("enigma2", resolveFilename(SCOPE_LANGUAGE))\r
21 gettext.textdomain("enigma2")\r
22 gettext.bindtextdomain("ZapHistoryBrowser", resolveFilename(SCOPE_LANGUAGE))
23
24 def _(txt):\r
25         t = gettext.dgettext("ZapHistoryBrowser", txt)\r
26         if t == txt:\r
27                 t = gettext.gettext(txt)\r
28         return t
29
30 ############################################
31
32 class TitleScreen(Screen):
33         def __init__(self, session, parent=None):\r
34                 Screen.__init__(self, session, parent)\r
35                 self.onLayoutFinish.append(self.setScreenTitle)\r
36 \r
37         def setScreenTitle(self):\r
38                 self.setTitle(_("Zap-History Browser"))
39
40 ################################################
41
42 class ZapHistoryBrowser(TitleScreen):
43         skin = """
44         <screen position="200,80" size="320,440" title="Zap-History Browser" >
45                 <ePixmap pixmap="skin_default/buttons/red.png" position="10,0" size="140,40" transparent="1" alphatest="on" />
46                 <ePixmap pixmap="skin_default/buttons/green.png" position="170,0" size="140,40" transparent="1" alphatest="on" />
47                 <widget name="key_red" position="10,0" zPosition="1" size="140,40" font="Regular;20" valign="center" halign="center" backgroundColor="#1f771f" transparent="1" />
48                 <widget name="key_green" position="170,0" zPosition="1" size="140,40" font="Regular;20" valign="center" halign="center" backgroundColor="#1f771f" transparent="1" />
49                 <widget name="list" position="0,40" size="320,400" scrollbarMode="showOnDemand" />
50         </screen>"""
51
52         def __init__(self, session, servicelist):
53                 TitleScreen.__init__(self, session)
54                 
55                 self.servicelist = servicelist
56                 self.serviceHandler = eServiceCenter.getInstance()
57                 
58                 self["list"] = MenuList([])
59                 self["key_red"] = Label(_("Clear"))
60                 self["key_green"] = Label(_("Delete"))
61                 
62                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
63                         {
64                                 "ok": self.zap,
65                                 "cancel": self.close,
66                                 "red": self.clear,
67                                 "green": self.delete
68                         }, prio=-1)
69                 
70                 self.onLayoutFinish.append(self.buildList)
71
72         def buildList(self):
73                 list = []
74                 for x in self.servicelist.history:
75                         if len(x) == 2:
76                                 #print "Single-Bouquet!!!"
77                                 ref = x[1]
78                         else:
79                                 #print "Multi-Bouquet!!!"
80                                 ref = x[2]
81                         info = self.serviceHandler.info(ref)
82                         name = info.getName(ref).replace('\xc2\x86', '').replace('\xc2\x87', '')
83                         list.append(name)
84                 list.reverse()
85                 self["list"].setList(list)
86
87         def zap(self):
88                 length = len(self.servicelist.history)
89                 if length > 0:
90                         self.servicelist.history_pos = (length - self["list"].getSelectionIndex()) - 1
91                         self.servicelist.setHistoryPath()
92
93         def clear(self):
94                 for i in range(0, len(self.servicelist.history)):
95                         del self.servicelist.history[0]
96                 self.buildList()
97
98         def delete(self):
99                 length = len(self.servicelist.history)
100                 if length > 0:
101                         idx = (length - self["list"].getSelectionIndex()) - 1
102                         del self.servicelist.history[idx]
103                         self.buildList()
104
105 ################################################
106
107 def main(session, servicelist, **kwargs):
108         session.open(ZapHistoryBrowser, servicelist)
109
110 def Plugins(**kwargs):
111         return PluginDescriptor(name=_("Zap-History Browser"), where=PluginDescriptor.WHERE_EXTENSIONSMENU, fnc=main)