[InternetRadio] forgotten localized imports added, typo fix with argument of bindtext...
[enigma2-plugins.git] / internetradio / src / InternetRadioSetup.py
1 #
2 # InternetRadio E2
3 #
4 # Coded by Dr.Best (c) 2012
5 # Support: www.dreambox-tools.info
6 # E-Mail: dr.best@dreambox-tools.info
7 #
8 # This plugin is open source but it is NOT free software.
9 #
10 # This plugin may only be distributed to and executed on hardware which
11 # is licensed by Dream Multimedia GmbH.
12 # In other words:
13 # It's NOT allowed to distribute any parts of this plugin or its source code in ANY way
14 # to hardware which is NOT licensed by Dream Multimedia GmbH.
15 # It's NOT allowed to execute this plugin and its source code or even parts of it in ANY way
16 # on hardware which is NOT licensed by Dream Multimedia GmbH.
17 #
18 # If you want to use or modify the code or parts of it,
19 # you have to keep MY license and inform me about the modifications by mail.
20 #
21
22 from Screens.Screen import Screen
23 from Components.ActionMap import ActionMap
24 from Components.ConfigList import ConfigListScreen
25 from Components.Label import Label
26 from Components.config import config, getConfigListEntry, configfile
27 from Components.FileList import FileList
28 from Components.Sources.StaticText import StaticText
29
30 # for localized messages
31 from . import _
32
33 class InternetRadioSetup(Screen, ConfigListScreen):
34
35         skin = """
36                 <screen name="InternetRadioSetup" position="center,center" size="600,400" title="InternetRadio Setup" >
37                         <ePixmap pixmap="skin_default/buttons/red.png" position="10,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
38                         <ePixmap pixmap="skin_default/buttons/green.png" position="155,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
39                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="300,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
40                         <ePixmap pixmap="skin_default/buttons/blue.png" position="445,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
41                         <widget render="Label" source="key_red" position="10,0" size="140,40" zPosition="5" valign="center" halign="center" backgroundColor="red" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
42                         <widget render="Label" source="key_green" position="150,0" size="140,40" zPosition="5" valign="center" halign="center" backgroundColor="red" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
43                         <widget name="config" position="10,50" size="580,400" scrollbarMode="showOnDemand" />
44                 </screen>""" 
45
46         def __init__(self, session):
47                 Screen.__init__(self, session)
48
49                 self["key_red"] = StaticText(_("Cancel"))
50                 self["key_green"] = StaticText(_("OK"))
51
52                 self.list = [
53                         getConfigListEntry(_("Show in extension menu:"), config.plugins.internetradio.showinextensions),
54                         getConfigListEntry(_("Visualization"), config.plugins.internetradio.visualization),
55                         getConfigListEntry(_("Fullscreen Layout"), config.plugins.internetradio.fullscreenlayout),
56                         getConfigListEntry(_("Fullscreen auto activation"), config.plugins.internetradio.fullscreenautoactivation),
57                         getConfigListEntry(_("Show cover arts"), config.plugins.internetradio.googlecover),
58                         getConfigListEntry(_("Rip to single file, name is timestamped"), config.plugins.internetradio.riptosinglefile),
59                         getConfigListEntry(_("Create a directory for each stream"), config.plugins.internetradio.createdirforeachstream),
60                         getConfigListEntry(_("Add sequence number to output file"), config.plugins.internetradio.addsequenceoutputfile),
61                         ]
62                 self.dirname = getConfigListEntry(_("Recording location:"), config.plugins.internetradio.dirname)
63                 self.list.append(self.dirname)
64                 
65                 ConfigListScreen.__init__(self, self.list, session)
66                 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
67                 {
68                         "green": self.keySave,
69                         "cancel": self.keyClose,
70                         "ok": self.keySelect,
71                 }, -2)
72
73         def keySelect(self):
74                 cur = self["config"].getCurrent()
75                 if cur == self.dirname:
76                         self.session.openWithCallback(self.pathSelected,InternetRadioStreamripperRecordingPath,config.plugins.internetradio.dirname.value)
77
78         def pathSelected(self, res):
79                 if res is not None:
80                         config.plugins.internetradio.dirname.value = res
81
82         def keySave(self):
83                 for x in self["config"].list:
84                         x[1].save()
85                 configfile.save()
86                 self.close(True)
87
88         def keyClose(self):
89                 for x in self["config"].list:
90                         x[1].cancel()
91                 self.close(False)
92                 
93                 
94 class InternetRadioStreamripperRecordingPath(Screen):
95         skin = """<screen name="InternetRadioStreamripperRecordingPath" position="center,center" size="560,320" title="Select record path for streamripper">
96                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
97                         <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
98                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
99                         <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
100                         <widget name="target" position="0,60" size="540,22" valign="center" font="Regular;22" />
101                         <widget name="filelist" position="0,100" zPosition="1" size="560,220" scrollbarMode="showOnDemand"/>
102                         <widget render="Label" source="key_red" position="0,0" size="140,40" zPosition="5" valign="center" halign="center" backgroundColor="red" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
103                         <widget render="Label" source="key_green" position="140,0" size="140,40" zPosition="5" valign="center" halign="center" backgroundColor="red" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
104                 </screen>"""
105                 
106         def __init__(self, session, initDir):
107                 Screen.__init__(self, session)
108                 inhibitDirs = ["/bin", "/boot", "/dev", "/etc", "/lib", "/proc", "/sbin", "/sys", "/usr", "/var"]
109                 inhibitMounts = []
110                 self["filelist"] = FileList(initDir, showDirectories = True, showFiles = False, inhibitMounts = inhibitMounts, inhibitDirs = inhibitDirs)
111                 self["target"] = Label()
112                 self["actions"] = ActionMap(["WizardActions", "DirectionActions", "ColorActions", "EPGSelectActions"],
113                 {
114                         "back": self.cancel,
115                         "left": self.left,
116                         "right": self.right,
117                         "up": self.up,
118                         "down": self.down,
119                         "ok": self.ok,
120                         "green": self.green,
121                         "red": self.cancel
122                         
123                 }, -1)
124                 self["key_red"] = StaticText(_("Cancel"))
125                 self["key_green"] = StaticText(_("OK"))
126
127         def cancel(self):
128                 self.close(None)
129
130         def green(self):
131                 self.close(self["filelist"].getSelection()[0])
132
133         def up(self):
134                 self["filelist"].up()
135                 self.updateTarget()
136
137         def down(self):
138                 self["filelist"].down()
139                 self.updateTarget()
140
141         def left(self):
142                 self["filelist"].pageUp()
143                 self.updateTarget()
144
145         def right(self):
146                 self["filelist"].pageDown()
147                 self.updateTarget()
148
149         def ok(self):
150                 if self["filelist"].canDescent():
151                         self["filelist"].descent()
152                         self.updateTarget()
153
154         def updateTarget(self):
155                 currFolder = self["filelist"].getSelection()[0]
156                 if currFolder is not None:
157                         self["target"].setText(currFolder)
158                 else:
159                         self["target"].setText(_("Invalid Location"))