initial checkin of MerlinSkinThemes
[enigma2-plugins.git] / mytube / src / MyTubeSettings.py
1 from Components.config import config, getConfigListEntry
2 from Components.ActionMap import ActionMap
3 from Components.Button import Button
4 from Components.Label import Label
5 from Components.ConfigList import ConfigListScreen
6
7 from Screens.LocationBox import MovieLocationBox
8 from Screens.Screen import Screen
9
10 class MyTubeSettingsScreen(Screen, ConfigListScreen):
11         skin = """
12                 <screen name="MyTubeSettingsScreen" position="center,120" size="820,520" title="MyTube - Settings">
13                 <ePixmap pixmap="skin_default/buttons/red.png" position="10,5" size="200,40" alphatest="on"/>
14                 <ePixmap pixmap="skin_default/buttons/green.png" position="210,5" size="200,40" alphatest="on"/>
15                 <widget name="key_red" position="10,5" size="200,40" zPosition="1" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" shadowColor="black" shadowOffset="-2,-2"/>
16                 <widget name="key_green" position="210,5" size="200,40" zPosition="1" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" shadowColor="black" shadowOffset="-2,-2"/>
17                 <eLabel position="10,50" size="800,1" backgroundColor="grey"/>
18                 <widget name="config" position="10,60" size="800,450" enableWrapAround="1" scrollbarMode="showOnDemand"/>
19                 <widget name="title" position="0,0" size="0,0"/>
20         </screen>"""
21
22         def __init__(self, session, plugin_path):
23                 Screen.__init__(self, session)
24                 self.skin_path = plugin_path
25                 self.session = session
26
27                 self["shortcuts"] = ActionMap(["ShortcutActions", "WizardActions", "MediaPlayerActions"],
28                 {
29                         "ok": self.keyOK,
30                         "back": self.keyCancel,
31                         "red": self.keyCancel,
32                         "green": self.keySave,
33                         "up": self.keyUp,
34                         "down": self.keyDown,
35                         "left": self.keyLeft,
36                         "right": self.keyRight,
37                 }, -1)
38
39                 self["key_red"] = Button(_("Close"))
40                 self["key_green"] = Button(_("Save"))
41                 self["title"] = Label()
42
43                 self._configListEntries = []
44                 self.ProxyEntry = None
45                 self._cfgLoadFeedEntry = None
46                 self._cfgVideoDirname = None
47                 ConfigListScreen.__init__(self, self._configListEntries, session)
48                 self.createSetup()
49                 self.onLayoutFinish.append(self.layoutFinished)
50                 self.onShown.append(self.setWindowTitle)
51
52         def layoutFinished(self):
53                 self["title"].setText(_("MyTubePlayer settings"))
54
55         def setWindowTitle(self):
56                 self.setTitle(_("MyTubePlayer settings"))
57
58         def createSetup(self):
59                 self._cfgLoadFeedEntry = getConfigListEntry(_("Load feed on startup:"), config.plugins.mytube.general.loadFeedOnOpen)
60                 self._cfgVideoDirname = getConfigListEntry(_("Download location"), config.plugins.mytube.general.videodir)
61
62                 self._configListEntries = [
63                                 getConfigListEntry(_("Display search results by:"), config.plugins.mytube.search.orderBy),
64                                 getConfigListEntry(_("Filter restricted content:"), config.plugins.mytube.search.safeSearch),
65                                 getConfigListEntry(_("Search region:"), config.plugins.mytube.search.lr),
66                                 self._cfgLoadFeedEntry
67                         ]
68
69                 if config.plugins.mytube.general.loadFeedOnOpen.value:
70                         self._configListEntries.append(getConfigListEntry(_("Start with following feed:"), config.plugins.mytube.general.startFeed))
71
72                 self._configListEntries.extend([
73                                 getConfigListEntry(_("Videoplayer stop/exit behavior:"), config.plugins.mytube.general.on_movie_stop),
74                                 getConfigListEntry(_("Videobrowser exit behavior:"), config.plugins.mytube.general.on_exit)
75                         ])
76
77                 if config.usage.setup_level.index >= 2: # expert+
78                         self._configListEntries.append(self._cfgVideoDirname)
79                 self._configListEntries.extend([
80                                 getConfigListEntry(_("Clear history on Exit:"), config.plugins.mytube.general.clearHistoryOnClose),
81                                 getConfigListEntry(_("Auto paginate on last entry:"), config.plugins.mytube.general.AutoLoadFeeds),
82                                 getConfigListEntry(_("Reset tv-screen after playback:"), config.plugins.mytube.general.resetPlayService),
83                                 getConfigListEntry(_("Authenticate with Youtube"), config.plugins.mytube.general.authenticate),
84                         ])
85                 self["config"].list = self._configListEntries
86
87         def newConfig(self):
88                 print "newConfig", self["config"].getCurrent()
89                 if self["config"].getCurrent() == self._cfgLoadFeedEntry:
90                         self.createSetup()
91
92         def keyOK(self):
93                 cur = self["config"].getCurrent()
94                 if config.usage.setup_level.index >= 2 and cur == self._cfgVideoDirname:
95                         self.session.openWithCallback(
96                                 self.pathSelected,
97                                 MovieLocationBox,
98                                 _("Choose target folder"),
99                                 config.plugins.mytube.general.videodir.value,
100                                 minFree=100 # We require at least 100MB free space
101                         )
102                 else:
103                         self.keySave()
104
105         def pathSelected(self, res):
106                 if res is not None:
107                         if config.movielist.videodirs.value != config.plugins.mytube.general.videodir.choices:
108                                 config.plugins.mytube.general.videodir.setChoices(config.movielist.videodirs.value, default=res)
109                         config.plugins.mytube.general.videodir.value = res
110
111         def keyUp(self):
112                 self["config"].instance.moveSelection(self["config"].instance.moveUp)
113
114         def keyDown(self):
115                 self["config"].instance.moveSelection(self["config"].instance.moveDown)
116
117         def keyRight(self):
118                 ConfigListScreen.keyRight(self)
119                 self.newConfig()
120
121         def keyLeft(self):
122                 ConfigListScreen.keyLeft(self)
123                 self.newConfig()
124
125         def keyCancel(self):
126                 print "cancel"
127                 for x in self["config"].list:
128                         x[1].cancel()
129                 self.close()
130
131         def keySave(self):
132                 print "saving"
133                 for x in self["config"].list:
134                         x[1].save()
135                 config.plugins.mytube.save()
136                 self.close()