MediaPlayer/settings.py: - use "Setup" Skin for MediaPlayerSettings but still allow...
[enigma2.git] / lib / python / Plugins / Extensions / MediaPlayer / settings.py
1 from Screens.Screen import Screen
2 from Screens.HelpMenu import HelpableScreen
3 from Components.FileList import FileList
4 from Components.Sources.StaticText import StaticText
5 from Components.MediaPlayer import PlayList
6 from Components.config import config, getConfigListEntry, ConfigSubsection, configfile, ConfigText, ConfigYesNo, ConfigDirectory
7 from Components.ConfigList import ConfigListScreen
8 from Components.ActionMap import ActionMap
9
10 config.mediaplayer = ConfigSubsection()
11 config.mediaplayer.repeat = ConfigYesNo(default=False)
12 config.mediaplayer.savePlaylistOnExit = ConfigYesNo(default=True)
13 config.mediaplayer.saveDirOnExit = ConfigYesNo(default=False)
14 config.mediaplayer.defaultDir = ConfigDirectory()
15
16 class DirectoryBrowser(Screen, HelpableScreen):
17
18         def __init__(self, session, currDir):
19                 Screen.__init__(self, session)
20                 # for the skin: first try MediaPlayerDirectoryBrowser, then FileBrowser, this allows individual skinning
21                 self.skinName = ["MediaPlayerDirectoryBrowser", "FileBrowser" ]
22
23                 HelpableScreen.__init__(self)
24
25                 self["key_red"] = StaticText(_("Cancel"))
26                 self["key_green"] = StaticText(_("Use"))
27
28                 self.filelist = FileList(currDir, matchingPattern="")
29                 self["filelist"] = self.filelist
30
31                 self["FilelistActions"] = ActionMap(["SetupActions", "ColorActions"],
32                         {
33                                 "green": self.use,
34                                 "red": self.exit,
35                                 "ok": self.ok,
36                                 "cancel": self.exit
37                         })
38                 self.onLayoutFinish.append(self.layoutFinished)
39
40         def layoutFinished(self):
41                 self.setTitle(_("Directory browser"))
42
43         def ok(self):
44                 if self.filelist.canDescent():
45                         self.filelist.descent()
46
47         def use(self):
48                 if self["filelist"].getCurrentDirectory() is not None:
49                         if self.filelist.canDescent() and self["filelist"].getFilename() and len(self["filelist"].getFilename()) > len(self["filelist"].getCurrentDirectory()):
50                                 self.filelist.descent()
51                                 self.close(self["filelist"].getCurrentDirectory())
52                 else:
53                                 self.close(self["filelist"].getFilename())
54
55         def exit(self):
56                 self.close(False)
57
58 class MediaPlayerSettings(Screen,ConfigListScreen):
59
60         def __init__(self, session, parent):
61                 Screen.__init__(self, session)
62                 # for the skin: first try MediaPlayerSettings, then Setup, this allows individual skinning
63                 self.skinName = ["MediaPlayerSettings", "Setup" ]
64                 self.setup_title = _("Edit settings")
65                 self.onChangedEntry = [ ]
66
67                 self["key_red"] = StaticText(_("Cancel"))
68                 self["key_green"] = StaticText(_("Save"))
69
70                 ConfigListScreen.__init__(self, [], session = session, on_change = self.changedEntry)
71                 self.parent = parent
72                 self.initConfigList()
73                 config.mediaplayer.saveDirOnExit.addNotifier(self.initConfigList)
74
75                 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
76                 {
77                     "green": self.save,
78                     "red": self.cancel,
79                     "cancel": self.cancel,
80                     "ok": self.ok,
81                 }, -2)
82
83         def layoutFinished(self):
84                 self.setTitle(self.setup_title)
85
86         def initConfigList(self, element=None):
87                 print "[initConfigList]", element
88                 try:
89                         self.list = []
90                         self.list.append(getConfigListEntry(_("repeat playlist"), config.mediaplayer.repeat))
91                         self.list.append(getConfigListEntry(_("save playlist on exit"), config.mediaplayer.savePlaylistOnExit))
92                         self.list.append(getConfigListEntry(_("save last directory on exit"), config.mediaplayer.saveDirOnExit))
93                         if not config.mediaplayer.saveDirOnExit.getValue():
94                                 self.list.append(getConfigListEntry(_("start directory"), config.mediaplayer.defaultDir))
95                         self["config"].setList(self.list)
96                 except KeyError:
97                         print "keyError"
98
99         def changedConfigList(self):
100                 self.initConfigList()
101
102         def ok(self):
103                 if self["config"].getCurrent()[1] == config.mediaplayer.defaultDir:
104                         self.session.openWithCallback(self.DirectoryBrowserClosed, DirectoryBrowser, self.parent.filelist.getCurrentDirectory())
105
106         def DirectoryBrowserClosed(self, path):
107                 print "PathBrowserClosed:" + str(path)
108                 if path != False:
109                         config.mediaplayer.defaultDir.setValue(path)
110
111         def save(self):
112                 for x in self["config"].list:
113                         x[1].save()
114                 self.close()
115
116         def cancel(self):
117                 self.close()
118
119         # for summary:
120         def changedEntry(self):
121                 for x in self.onChangedEntry:
122                         x()
123
124         def getCurrentEntry(self):
125                 return self["config"].getCurrent()[0]
126
127         def getCurrentValue(self):
128                 return str(self["config"].getCurrent()[1].getText())
129
130         def createSummary(self):
131                 from Screens.Setup import SetupSummary
132                 return SetupSummary