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