[InternetRadio] initial commit of InternetRadio plugin (with music-visualization...
[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 class InternetRadioSetup(Screen, ConfigListScreen):
31
32         skin = """
33                 <screen name="InternetRadioSetup" position="center,center" size="600,400" title="InternetRadio Setup" >
34                         <ePixmap pixmap="skin_default/buttons/red.png" position="10,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
35                         <ePixmap pixmap="skin_default/buttons/green.png" position="155,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
36                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="300,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
37                         <ePixmap pixmap="skin_default/buttons/blue.png" position="445,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
38                         <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" />
39                         <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" />
40                         <widget name="config" position="10,50" size="580,400" scrollbarMode="showOnDemand" />
41                 </screen>""" 
42
43         def __init__(self, session):
44                 Screen.__init__(self, session)
45
46                 self["key_red"] = StaticText(_("Cancel"))
47                 self["key_green"] = StaticText(_("OK"))
48
49                 self.list = [
50                         getConfigListEntry(_("Show in extension menu:"), config.plugins.internetradio.showinextensions),
51                         getConfigListEntry(_("Visualization"), config.plugins.internetradio.visualization),
52                         getConfigListEntry(_("Fullscreen Layout"), config.plugins.internetradio.fullscreenlayout),
53                         getConfigListEntry(_("Fullscreen auto activation"), config.plugins.internetradio.fullscreenautoactivation),
54                         getConfigListEntry(_("Show cover arts"), config.plugins.internetradio.googlecover),
55                         getConfigListEntry(_("Rip to single file, name is timestamped"), config.plugins.internetradio.riptosinglefile),
56                         getConfigListEntry(_("Create a directory for each stream"), config.plugins.internetradio.createdirforeachstream),
57                         getConfigListEntry(_("Add sequence number to output file"), config.plugins.internetradio.addsequenceoutputfile),
58                         ]
59                 self.dirname = getConfigListEntry(_("Recording location:"), config.plugins.internetradio.dirname)
60                 self.list.append(self.dirname)
61                 
62                 ConfigListScreen.__init__(self, self.list, session)
63                 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
64                 {
65                         "green": self.keySave,
66                         "cancel": self.keyClose,
67                         "ok": self.keySelect,
68                 }, -2)
69
70         def keySelect(self):
71                 cur = self["config"].getCurrent()
72                 if cur == self.dirname:
73                         self.session.openWithCallback(self.pathSelected,InternetRadioStreamripperRecordingPath,config.plugins.internetradio.dirname.value)
74
75         def pathSelected(self, res):
76                 if res is not None:
77                         config.plugins.internetradio.dirname.value = res
78
79         def keySave(self):
80                 for x in self["config"].list:
81                         x[1].save()
82                 configfile.save()
83                 self.close(True)
84
85         def keyClose(self):
86                 for x in self["config"].list:
87                         x[1].cancel()
88                 self.close(False)
89                 
90                 
91 class InternetRadioStreamripperRecordingPath(Screen):
92         skin = """<screen name="InternetRadioStreamripperRecordingPath" position="center,center" size="560,320" title="Select record path for streamripper">
93                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
94                         <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
95                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
96                         <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
97                         <widget name="target" position="0,60" size="540,22" valign="center" font="Regular;22" />
98                         <widget name="filelist" position="0,100" zPosition="1" size="560,220" scrollbarMode="showOnDemand"/>
99                         <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" />
100                         <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" />
101                 </screen>"""
102                 
103         def __init__(self, session, initDir):
104                 Screen.__init__(self, session)
105                 inhibitDirs = ["/bin", "/boot", "/dev", "/etc", "/lib", "/proc", "/sbin", "/sys", "/usr", "/var"]
106                 inhibitMounts = []
107                 self["filelist"] = FileList(initDir, showDirectories = True, showFiles = False, inhibitMounts = inhibitMounts, inhibitDirs = inhibitDirs)
108                 self["target"] = Label()
109                 self["actions"] = ActionMap(["WizardActions", "DirectionActions", "ColorActions", "EPGSelectActions"],
110                 {
111                         "back": self.cancel,
112                         "left": self.left,
113                         "right": self.right,
114                         "up": self.up,
115                         "down": self.down,
116                         "ok": self.ok,
117                         "green": self.green,
118                         "red": self.cancel
119                         
120                 }, -1)
121                 self["key_red"] = StaticText(_("Cancel"))
122                 self["key_green"] = StaticText(_("OK"))
123
124         def cancel(self):
125                 self.close(None)
126
127         def green(self):
128                 self.close(self["filelist"].getSelection()[0])
129
130         def up(self):
131                 self["filelist"].up()
132                 self.updateTarget()
133
134         def down(self):
135                 self["filelist"].down()
136                 self.updateTarget()
137
138         def left(self):
139                 self["filelist"].pageUp()
140                 self.updateTarget()
141
142         def right(self):
143                 self["filelist"].pageDown()
144                 self.updateTarget()
145
146         def ok(self):
147                 if self["filelist"].canDescent():
148                         self["filelist"].descent()
149                         self.updateTarget()
150
151         def updateTarget(self):
152                 currFolder = self["filelist"].getSelection()[0]
153                 if currFolder is not None:
154                         self["target"].setText(currFolder)
155                 else:
156                         self["target"].setText(_("Invalid Location"))