fix no more working displaying of used tuner for foreground service
[enigma2.git] / lib / python / Screens / PluginBrowser.py
1 from Screen import Screen
2
3 from enigma import eConsoleAppContainer, loadPNG
4
5 from Components.MenuList import MenuList
6 from Components.ActionMap import ActionMap
7 from Components.PluginComponent import plugins
8 from Components.PluginList import *
9 from Components.config import config
10 from Components.Label import Label
11 from Screens.MessageBox import MessageBox
12 from Screens.Console import Console
13 from Plugins.Plugin import PluginDescriptor
14 from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE
15
16 class PluginBrowser(Screen):
17         def __init__(self, session):
18                 Screen.__init__(self, session)
19                 
20                 self["red"] = Label(_("Remove Plugins"))
21                 self["green"] = Label(_("Download Plugins"))
22                 
23                 self.list = []
24                 self["list"] = PluginList(self.list)
25                 self.updateList()
26                 
27                 self["actions"] = ActionMap(["WizardActions", "ColorActions"],
28                 {
29                         "ok": self.save,
30                         "back": self.close,
31                         "red": self.delete,
32                         "green": self.download
33                 })
34                 self.onExecBegin.append(self.checkWarnings)
35         
36         def checkWarnings(self):
37                 if len(plugins.warnings):
38                         text = _("Some plugins are not available:\n")
39                         for (pluginname, error) in plugins.warnings:
40                                 text += _("%s (%s)\n") % (pluginname, error)
41                         plugins.resetWarnings()
42                         self.session.open(MessageBox, text = text, type = MessageBox.TYPE_WARNING)
43
44         def save(self):
45                 #self.close()
46                 self.run()
47         
48         def run(self):
49                 plugin = self["list"].l.getCurrentSelection()[0]
50                 
51                 plugin(session=self.session)
52                 
53         def updateList(self):
54                 self.list = [ ]
55                 self.pluginlist = plugins.getPlugins(PluginDescriptor.WHERE_PLUGINMENU)
56                 for plugin in self.pluginlist:
57                         self.list.append(PluginEntryComponent(plugin))
58                 
59                 self["list"].l.setList(self.list)
60
61         def delete(self):
62                 self.session.openWithCallback(self.updateList, PluginDownloadBrowser, PluginDownloadBrowser.REMOVE)
63         
64         def download(self):
65                 self.session.openWithCallback(self.updateList, PluginDownloadBrowser, PluginDownloadBrowser.DOWNLOAD)
66
67 class PluginDownloadBrowser(Screen):
68         DOWNLOAD = 0
69         REMOVE = 1
70         
71         def __init__(self, session, type):
72                 Screen.__init__(self, session)
73                 
74                 self.type = type
75                 
76                 self.container = eConsoleAppContainer()
77                 self.container.appClosed.get().append(self.runFinished)
78                 self.container.dataAvail.get().append(self.dataAvail)
79                 self.onLayoutFinish.append(self.startRun)
80                 self.onShown.append(self.setWindowTitle)
81                 
82                 self.list = []
83                 self["list"] = PluginList(self.list)
84                 self.pluginlist = []
85                 self.expanded = []
86                 
87                 if self.type == self.DOWNLOAD:
88                         self["text"] = Label(_("Downloading plugin information. Please wait..."))
89                 elif self.type == self.REMOVE:
90                         self["text"] = Label(_("Getting plugin information. Please wait..."))
91                 
92                 self.run = 0
93                                 
94                 self["actions"] = ActionMap(["WizardActions"], 
95                 {
96                         "ok": self.go,
97                         "back": self.close,
98                 })
99                 
100         def go(self):
101                 if type(self["list"].l.getCurrentSelection()[0]) is str: # category
102                         if self["list"].l.getCurrentSelection()[0] in self.expanded:
103                                 self.expanded.remove(self["list"].l.getCurrentSelection()[0])
104                         else:
105                                 self.expanded.append(self["list"].l.getCurrentSelection()[0])
106                         self.updateList()
107                 else:
108                         if self.type == self.DOWNLOAD:
109                                 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to download\nthe plugin \"" + self["list"].l.getCurrentSelection()[0].name + "\"?"))
110                         elif self.type == self.REMOVE:
111                                 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to REMOVE\nthe plugin \"" + self["list"].l.getCurrentSelection()[0].name + "\"?"))
112
113         def runInstall(self, val):
114                 if val:
115                         if self.type == self.DOWNLOAD:
116                                 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["ipkg install " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
117                         elif self.type == self.REMOVE:
118                                 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["ipkg remove " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
119
120         def setWindowTitle(self):
121                 if self.type == self.DOWNLOAD:
122                         self.setTitle(_("Downloadable new plugins"))
123                 elif self.type == self.REMOVE:
124                         self.setTitle(_("Remove plugins"))
125
126         def startRun(self):
127                 self["list"].instance.hide()
128                 if self.type == self.DOWNLOAD:
129                         self.container.execute("ipkg update")
130                 elif self.type == self.REMOVE:
131                         self.run = 1
132                         self.container.execute("ipkg list_installed enigma2-plugin-*")
133                 
134         def installFinished(self):
135                 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
136                 self.close()
137                 
138         def runFinished(self, retval):
139                 if self.run == 0:
140                         self.run = 1
141                         if self.type == self.DOWNLOAD:
142                                 self.container.execute("ipkg list enigma2-plugin-*")
143                 else:
144                         if len(self.pluginlist) > 0:
145                                 self.updateList()
146                                 self["list"].instance.show()
147                         else:
148                                 self["text"].setText("No plugins found")
149
150         def dataAvail(self, str):
151                 for x in str.split('\n'):
152                         plugin = x.split(" - ")
153                         if len(plugin) == 3:
154                                 plugin.append(plugin[0][15:])
155
156                                 self.pluginlist.append(plugin)
157         
158         def updateList(self):
159                 self.list = []
160                 expandableIcon = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "expandable-plugins.png"))
161                 expandedIcon = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "expanded-plugins.png"))
162                 verticallineIcon = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "verticalline-plugins.png"))
163                 
164                 self.plugins = {}
165                 for x in self.pluginlist:
166                         split = x[3].split('-')
167                         if len(split) < 2:
168                                 continue
169                         if not self.plugins.has_key(split[0]):
170                                 self.plugins[split[0]] = []
171                                 
172                         self.plugins[split[0]].append((PluginDescriptor(name = x[3], description = x[2], icon = verticallineIcon), split[1]))
173                         
174                 for x in self.plugins.keys():
175                         if x in self.expanded:
176                                 self.list.append(PluginCategoryComponent(x, expandedIcon))
177                                 for plugin in self.plugins[x]:
178                                         self.list.append(PluginDownloadComponent(plugin[0], plugin[1]))
179                         else:
180                                 self.list.append(PluginCategoryComponent(x, expandableIcon))
181                 self["list"].l.setList(self.list)
182