Merge branch 'master' of git.opendreambox.org:/git/enigma2
[enigma2.git] / lib / python / Plugins / Extensions / MediaPlayer / settings.py
1 from Screens.Screen import Screen
2 from Screens.HelpMenu import HelpableScreen
3 from Components.Label import Label
4 from Components.FileList import FileList
5 from Components.MediaPlayer import PlayList
6 from Components.config import config, getConfigListEntry, ConfigSubsection, configfile, ConfigText, ConfigYesNo
7 from Components.ConfigList import ConfigListScreen
8 from Components.ActionMap import ActionMap
9
10 class ConfigDirectory(ConfigText):
11         def __init__(self, default="", visible_width=60):
12                 ConfigText.__init__(self, default, fixed_size = True, visible_width = visible_width)
13         def handleKey(self, key):
14                 pass
15         def getValue(self):
16                 if self.text == "":
17                         return None
18                 else:
19                         return ConfigText.getValue(self)
20         def setValue(self, val):
21                 if val == None:
22                         val = ""
23                 ConfigText.setValue(self, val)
24         def getMulti(self, selected):
25                 if self.text == "":
26                         return ("mtext"[1-selected:], _("List of Storage Devices"), range(0))
27                 else:
28                         return ConfigText.getMulti(self, selected)
29                 
30 config.mediaplayer = ConfigSubsection()
31 config.mediaplayer.repeat = ConfigYesNo(default=False)
32 config.mediaplayer.savePlaylistOnExit = ConfigYesNo(default=True)
33 config.mediaplayer.saveDirOnExit = ConfigYesNo(default=False)
34 config.mediaplayer.defaultDir = ConfigDirectory()
35
36 class DirectoryBrowser(Screen, HelpableScreen):
37         skin = """
38                 <screen name="DirectoryBrowser" position="160,62" size="450,376" title="Directory browser" >
39                         <ePixmap pixmap="skin_default/buttons/red.png" position="10,0" size="140,40" alphatest="on" />
40                         <ePixmap pixmap="skin_default/buttons/green.png" position="300,0" size="140,40" alphatest="on" />
41                         <widget source="key_red" render="Label" position="10,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
42                         <widget source="key_green" render="Label" position="300,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
43                         <widget name="filelist" position="0,44" size="440,322" scrollbarMode="showOnDemand" />
44                 </screen>"""
45         def __init__(self, session, currDir):
46                 from Components.Sources.StaticText import StaticText
47                 Screen.__init__(self, session)
48                 HelpableScreen.__init__(self)
49                 
50                 self["key_red"] = StaticText(_("Cancel"))
51                 self["key_green"] = StaticText(_("Use"))
52
53                 self.filelist = FileList(currDir, matchingPattern="")
54                 self["filelist"] = self.filelist
55
56                 self["FilelistActions"] = ActionMap(["SetupActions", "ColorActions"],
57                         {
58                                 "green": self.use,
59                                 "red": self.exit,
60                                 "ok": self.ok,
61                                 "cancel": self.exit
62                         })
63
64         def ok(self):
65                 if self.filelist.canDescent():
66                         self.filelist.descent()
67
68         def use(self):
69                 if self.filelist.canDescent() and len(self["filelist"].getFilename()) > len(self["filelist"].getCurrentDirectory()):
70                         self.filelist.descent()
71                 self.close(self["filelist"].getCurrentDirectory())
72
73         def exit(self):
74                 self.close(False)
75
76 class MediaPlayerSettings(Screen,ConfigListScreen):
77         skin = """
78                 <screen name="MediaPlayerSettings" position="160,150" size="450,200" title="Edit settings">
79                         <ePixmap pixmap="skin_default/buttons/red.png" position="10,0" size="140,40" alphatest="on" />
80                         <ePixmap pixmap="skin_default/buttons/green.png" position="300,0" size="140,40" alphatest="on" />
81                         <widget source="key_red" render="Label" position="10,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
82                         <widget source="key_green" render="Label" position="300,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
83                         <widget name="config" position="10,44" size="430,146" />
84                 </screen>"""
85
86         def __init__(self, session, parent):
87                 from Components.Sources.StaticText import StaticText
88                 Screen.__init__(self, session)
89                 self["key_red"] = StaticText(_("Cancel"))
90                 self["key_green"] = StaticText(_("Save"))
91
92                 ConfigListScreen.__init__(self, [])
93                 self.parent = parent
94                 self.initConfigList()
95                 config.mediaplayer.saveDirOnExit.addNotifier(self.initConfigList)
96
97                 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
98                 {
99                     "green": self.save,
100                     "red": self.cancel,
101                     "cancel": self.cancel,
102                     "ok": self.ok,
103                 }, -2)
104
105         def initConfigList(self, element=None):
106                 print "[initConfigList]", element
107                 try:
108                         self.list = []
109                         self.list.append(getConfigListEntry(_("repeat playlist"), config.mediaplayer.repeat))
110                         self.list.append(getConfigListEntry(_("save playlist on exit"), config.mediaplayer.savePlaylistOnExit))
111                         self.list.append(getConfigListEntry(_("save last directory on exit"), config.mediaplayer.saveDirOnExit))
112                         if not config.mediaplayer.saveDirOnExit.getValue():
113                                 self.list.append(getConfigListEntry(_("start directory"), config.mediaplayer.defaultDir))
114                         self["config"].setList(self.list)
115                 except KeyError:
116                         print "keyError"
117
118         def changedConfigList(self):
119                 self.initConfigList()
120
121         def ok(self):
122                 if self["config"].getCurrent()[1] == config.mediaplayer.defaultDir:
123                         self.session.openWithCallback(self.DirectoryBrowserClosed, DirectoryBrowser, self.parent.filelist.getCurrentDirectory())
124
125         def DirectoryBrowserClosed(self, path):
126                 print "PathBrowserClosed:" + str(path)
127                 if path != False:
128                         config.mediaplayer.defaultDir.setValue(path)
129
130         def save(self):
131                 for x in self["config"].list:
132                         x[1].save()
133                 self.close()
134
135         def cancel(self):
136                 self.close()
137