pluginhider: initial checkin
[enigma2-plugins.git] / pluginhider / src / PluginHiderSetup.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.SelectionList import SelectionList, SelectionEntryComponent
11 from Components.Sources.StaticText import StaticText
12
13 # Configuration
14 from Components.config import config
15
16 from Components.PluginComponent import plugins
17 from Plugins.Plugin import PluginDescriptor
18
19 LIST_PLUGINS = 0
20 LIST_EXTENSIONS = 1
21 class PluginHiderSetup(Screen):
22         skin = """<screen name="PluginHiderSetup" title="PluginHider Setup" position="center,center" size="565,290">
23                 <ePixmap position="0,0" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
24                 <ePixmap position="140,0" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
25                 <ePixmap position="280,0" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
26                 <ePixmap position="420,0" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
27                 <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
28                 <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
29                 <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
30                 <widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
31                 <widget name="list" position="5,45" size="555,240" scrollbarMode="showOnDemand" />
32         </screen>"""
33
34         def __init__(self, session):
35                 Screen.__init__(self, session)
36
37                 # Initialize widgets
38                 self["key_green"] = StaticText(_("OK"))
39                 self["key_red"] = StaticText(_("Cancel"))
40                 self["key_yellow"] = StaticText(_("Plugins"))
41                 self["key_blue"] = StaticText(_("Extensions"))
42
43                 self["list"] = SelectionList([])
44                 self.selectedList = LIST_PLUGINS
45                 self.updateList()
46
47                 self["ColorActions"] = ActionMap(["OkCancelActions", "ColorActions"],
48                         {
49                                 "ok": self["list"].toggleSelection,
50                                 "red": self.cancel,
51                                 "green": self.save,
52                                 "yellow": self.plugins,
53                                 "blue": self.extensions,
54                         }, -1
55                 )
56
57                 self.onLayoutFinish.append(self.setCustomTitle)
58
59         def cancel(self):
60                 config.plugins.pluginhider.hideplugins.cancel()
61                 config.plugins.pluginhider.hideextensions.cancel()
62                 config.plugins.pluginhider.cancel()
63                 self.close()
64
65         def save(self):
66                 self.keepCurrent()
67                 config.plugins.pluginhider.hideplugins.save()
68                 config.plugins.pluginhider.hideextensions.save()
69                 config.plugins.pluginhider.save()
70                 self.close()
71
72         def plugins(self):
73                 self.keepCurrent()
74                 self.selectedList = LIST_PLUGINS
75                 self.updateList()
76
77         def extensions(self):
78                 self.keepCurrent()
79                 self.selectedList = LIST_EXTENSIONS
80                 self.updateList()
81
82         def setCustomTitle(self):
83                 self.setTitle(_("PluginHider Setup"))
84
85         def updateList(self):
86                 if hasattr(plugins, 'pluginHider_baseGetPlugins'):
87                         fnc = plugins.pluginHider_baseGetPlugins
88                 else:
89                         fnc = plugins.getPlugins
90
91                 if self.selectedList == LIST_PLUGINS:
92                         list = fnc([PluginDescriptor.WHERE_PLUGINMENU])
93                         selected = config.plugins.pluginhider.hideplugins.value
94                 else:
95                         list = fnc([PluginDescriptor.WHERE_EXTENSIONSMENU])
96                         selected = config.plugins.pluginhider.hideextensions.value
97
98                 res = []
99                 i = 0
100                 for plugin in list:
101                         if plugin.description:
102                                 name = "%s (%s)" % (plugin.name, plugin.description)
103                         else:
104                                 name = plugin.name
105
106                         res.append(SelectionEntryComponent(
107                                         name,
108                                         plugin.name,
109                                         i,
110                                         plugin.name in selected,
111                         ))
112                         i += 1
113                 self["list"].setList(res)
114                 if res:
115                         self["list"].moveToIndex(0)
116
117         def keepCurrent(self):
118                 selected = self["list"].getSelectionsList()
119                 if self.selectedList == LIST_PLUGINS:
120                         config.plugins.pluginhider.hideplugins.value = [x[1] for x in selected]
121                 else:
122                         config.plugins.pluginhider.hideextensions.value = [x[1] for x in selected]