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