ecasa: add download functionality and basic slideshow.
[enigma2-plugins.git] / ecasa / src / EcasaSetup.py
1 # GUI (Screens)
2 from Screens.Screen import Screen
3 from Components.ConfigList import ConfigListScreen
4
5 # GUI (Summary)
6 from Screens.Setup import SetupSummary
7
8 # GUI (Components)
9 from Components.ActionMap import ActionMap
10 from Components.Sources.StaticText import StaticText
11
12 # Configuration
13 from Components.config import config, getConfigListEntry
14
15 class EcasaSetup(Screen, ConfigListScreen):
16         skin = """<screen name="EcasaSetup" position="center,center" size="565,370">
17                 <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
18                 <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
19                 <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
20                 <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
21                 <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
22                 <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
23                 <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
24                 <widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
25                 <widget name="config" position="5,50" size="555,250" scrollbarMode="showOnDemand" />
26                 <ePixmap pixmap="skin_default/div-h.png" position="0,301" zPosition="1" size="565,2" />
27                 <widget source="help" render="Label" position="5,305" size="555,63" font="Regular;21" />
28         </screen>"""
29
30         def __init__(self, session):
31                 Screen.__init__(self, session)
32
33                 # Summary
34                 self.setup_title = _("eCasa Setup")
35                 self.onChangedEntry = []
36
37                 ConfigListScreen.__init__(
38                         self,
39                         [
40                                 getConfigListEntry(_("Google Username"), config.plugins.ecasa.google_username, _("Username to use for authentication with google. Leave empty for unauthenticated use.")),
41                                 getConfigListEntry(_("Google Password"), config.plugins.ecasa.google_password, _("Password to the google account.")),
42                                 getConfigListEntry(_("Albums of"), config.plugins.ecasa.user, _("Show albums for this user by default. Use \"default\" for currently logged in user.")),
43                                 getConfigListEntry(_("Search results"), config.plugins.ecasa.searchlimit, _("Number of search results to display at most.")),
44                                 getConfigListEntry(_("Slideshow interval"), config.plugins.ecasa.slideshow_interval, _("Interval in slideshow before new picture is being shown.")),
45                                 #getConfigListEntry(_("Cache directory"), config.plugins.ecasa.cache, _("Directory used to store cached images.")),
46                                 getConfigListEntry(_("Cache size"), config.plugins.ecasa.cachesize, _("Size of local picture cache. If the maximum size is reached the cleanup process will delete the oldest existing pictured after the plugin was closed.")),
47                         ],
48                         session = session,
49                         on_change = self.changed
50                 )
51                 def selectionChanged():
52                         if self["config"].current:
53                                 self["config"].current[1].onDeselect(self.session)
54                         self["config"].current = self["config"].getCurrent()
55                         if self["config"].current:
56                                 self["config"].current[1].onSelect(self.session)
57                         for x in self["config"].onSelectionChanged:
58                                 x()
59                 self["config"].selectionChanged = selectionChanged
60                 self["config"].onSelectionChanged.append(self.updateHelp)
61
62                 # Initialize widgets
63                 self["key_green"] = StaticText(_("OK"))
64                 self["key_red"] = StaticText(_("Cancel"))
65                 self["key_yellow"] = StaticText("")
66                 self["key_blue"] = StaticText("")
67                 self["help"] = StaticText()
68
69                 # Define Actions
70                 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
71                         {
72                                 "cancel": self.keyCancel,
73                                 "save": self.keySave,
74                         }
75                 )
76
77                 # Trigger change
78                 self.changed()
79
80                 self.onLayoutFinish.append(self.setCustomTitle)
81
82         def setCustomTitle(self):
83                 self.setTitle(_("eCasa Setup"))
84
85         def updateHelp(self):
86                 cur = self["config"].getCurrent()
87                 if cur:
88                         self["help"].text = cur[2]
89
90         def changed(self):
91                 for x in self.onChangedEntry:
92                         x()
93
94         def getCurrentEntry(self):
95                 return self["config"].getCurrent()[0]
96
97         def getCurrentValue(self):
98                 return str(self["config"].getCurrent()[1].getText())
99
100         def createSummary(self):
101                 return SetupSummary