1 from Screen import Screen
2 from Components.Language import language
3 from enigma import eConsoleAppContainer
5 from Components.ActionMap import ActionMap
6 from Components.PluginComponent import plugins
7 from Components.PluginList import *
8 from Components.Label import Label
9 from Screens.MessageBox import MessageBox
10 from Screens.Console import Console
11 from Plugins.Plugin import PluginDescriptor
12 from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE
13 from Tools.LoadPixmap import LoadPixmap
17 def languageChanged():
18 plugins.clearPluginList()
19 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
21 class PluginBrowser(Screen):
22 def __init__(self, session):
23 Screen.__init__(self, session)
25 self["red"] = Label(_("Remove Plugins"))
26 self["green"] = Label(_("Download Plugins"))
29 self["list"] = PluginList(self.list)
31 self["actions"] = ActionMap(["WizardActions", "ColorActions"],
36 "green": self.download
38 self.onFirstExecBegin.append(self.checkWarnings)
39 self.onShown.append(self.updateList)
41 def checkWarnings(self):
42 if len(plugins.warnings):
43 text = _("Some plugins are not available:\n")
44 for (pluginname, error) in plugins.warnings:
45 text += _("%s (%s)\n") % (pluginname, error)
46 plugins.resetWarnings()
47 self.session.open(MessageBox, text = text, type = MessageBox.TYPE_WARNING)
54 plugin = self["list"].l.getCurrentSelection()[0]
55 plugin(session=self.session)
58 self.pluginlist = plugins.getPlugins(PluginDescriptor.WHERE_PLUGINMENU)
59 self.list = [PluginEntryComponent(plugin) for plugin in self.pluginlist]
60 self["list"].l.setList(self.list)
63 self.session.openWithCallback(self.PluginDownloadBrowserClosed, PluginDownloadBrowser, PluginDownloadBrowser.REMOVE)
66 self.session.openWithCallback(self.PluginDownloadBrowserClosed, PluginDownloadBrowser, PluginDownloadBrowser.DOWNLOAD)
68 def PluginDownloadBrowserClosed(self):
73 class PluginDownloadBrowser(Screen):
76 lastDownloadDate = None
78 def __init__(self, session, type):
79 Screen.__init__(self, session)
83 self.container = eConsoleAppContainer()
84 self.container.appClosed.append(self.runFinished)
85 self.container.dataAvail.append(self.dataAvail)
86 self.onLayoutFinish.append(self.startRun)
87 self.onShown.append(self.setWindowTitle)
90 self["list"] = PluginList(self.list)
93 self.installedplugins = []
95 if self.type == self.DOWNLOAD:
96 self["text"] = Label(_("Downloading plugin information. Please wait..."))
97 elif self.type == self.REMOVE:
98 self["text"] = Label(_("Getting plugin information. Please wait..."))
102 self.remainingdata = ""
104 self["actions"] = ActionMap(["WizardActions"],
111 sel = self["list"].l.getCurrentSelection()
117 if isinstance(sel, str): # category
118 if sel in self.expanded:
119 self.expanded.remove(sel)
121 self.expanded.append(sel)
124 if self.type == self.DOWNLOAD:
125 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to download\nthe plugin \"%s\"?") % sel.name)
126 elif self.type == self.REMOVE:
127 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to REMOVE\nthe plugin \"%s\"?") % sel.name)
129 def runInstall(self, val):
131 if self.type == self.DOWNLOAD:
132 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["ipkg install " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
133 elif self.type == self.REMOVE:
134 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["ipkg remove " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
136 def setWindowTitle(self):
137 if self.type == self.DOWNLOAD:
138 self.setTitle(_("Downloadable new plugins"))
139 elif self.type == self.REMOVE:
140 self.setTitle(_("Remove plugins"))
142 def startIpkgListInstalled(self):
143 self.container.execute("ipkg list_installed enigma2-plugin-*")
145 def startIpkgListAvailable(self):
146 self.container.execute("ipkg list enigma2-plugin-*")
149 self["list"].instance.hide()
150 if self.type == self.DOWNLOAD:
151 if not PluginDownloadBrowser.lastDownloadDate or (time() - PluginDownloadBrowser.lastDownloadDate) > 3600:
152 # Only update from internet once per hour
153 self.container.execute("ipkg update")
154 PluginDownloadBrowser.lastDownloadDate = time()
156 self.startIpkgListAvailable()
157 elif self.type == self.REMOVE:
159 self.startIpkgListInstalled()
161 def installFinished(self):
162 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
163 self.container.appClosed.remove(self.runFinished)
164 self.container.dataAvail.remove(self.dataAvail)
167 def runFinished(self, retval):
168 self.remainingdata = ""
171 if self.type == self.DOWNLOAD:
172 self.startIpkgListInstalled()
173 elif self.run == 1 and self.type == self.DOWNLOAD:
175 self.startIpkgListAvailable()
177 if len(self.pluginlist) > 0:
179 self["list"].instance.show()
181 self["text"].setText("No new plugins found")
183 def dataAvail(self, str):
184 #prepend any remaining data from the previous call
185 str = self.remainingdata + str
187 lines = str.split('\n')
188 #'str' should end with '\n', so when splitting, the last line should be empty. If this is not the case, we received an incomplete line
190 #remember this data for next time
191 self.remainingdata = lines[-1]
194 self.remainingdata = ""
197 plugin = x.split(" - ", 2)
199 if self.run == 1 and self.type == self.DOWNLOAD:
200 if plugin[0] not in self.installedplugins:
201 self.installedplugins.append(plugin[0])
203 if plugin[0] not in self.installedplugins:
204 plugin.append(plugin[0][15:])
206 self.pluginlist.append(plugin)
208 def updateList(self):
210 expandableIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/expandable-plugins.png"))
211 expandedIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/expanded-plugins.png"))
212 verticallineIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/verticalline-plugins.png"))
215 for x in self.pluginlist:
216 split = x[3].split('-', 1)
219 if not self.plugins.has_key(split[0]):
220 self.plugins[split[0]] = []
222 self.plugins[split[0]].append((PluginDescriptor(name = x[3], description = x[2], icon = verticallineIcon), split[1]))
224 for x in self.plugins.keys():
225 if x in self.expanded:
226 list.append(PluginCategoryComponent(x, expandedIcon))
227 list.extend([PluginDownloadComponent(plugin[0], plugin[1]) for plugin in self.plugins[x]])
229 list.append(PluginCategoryComponent(x, expandableIcon))
231 self["list"].l.setList(list)
233 language.addCallback(languageChanged)