1 from Screen import Screen
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 class PluginBrowser(Screen):
18 def __init__(self, session):
19 Screen.__init__(self, session)
21 self["red"] = Label(_("Remove Plugins"))
22 self["green"] = Label(_("Download Plugins"))
25 self["list"] = PluginList(self.list)
28 self["actions"] = ActionMap(["WizardActions", "ColorActions"],
33 "green": self.download
35 self.onExecBegin.append(self.checkWarnings)
37 def checkWarnings(self):
38 if len(plugins.warnings):
39 text = _("Some plugins are not available:\n")
40 for (pluginname, error) in plugins.warnings:
41 text += _("%s (%s)\n") % (pluginname, error)
42 plugins.resetWarnings()
43 self.session.open(MessageBox, text = text, type = MessageBox.TYPE_WARNING)
50 plugin = self["list"].l.getCurrentSelection()[0]
52 plugin(session=self.session)
55 self.pluginlist = plugins.getPlugins(PluginDescriptor.WHERE_PLUGINMENU)
56 self.list = [PluginEntryComponent(plugin) for plugin in self.pluginlist]
58 self["list"].l.setList(self.list)
61 self.session.openWithCallback(self.updateList, PluginDownloadBrowser, PluginDownloadBrowser.REMOVE)
64 self.session.openWithCallback(self.updateList, PluginDownloadBrowser, PluginDownloadBrowser.DOWNLOAD)
66 class PluginDownloadBrowser(Screen):
69 lastDownloadDate = None
71 def __init__(self, session, type):
72 Screen.__init__(self, session)
76 self.container = eConsoleAppContainer()
77 self.container.appClosed.append(self.runFinished)
78 self.container.dataAvail.append(self.dataAvail)
79 self.onLayoutFinish.append(self.startRun)
80 self.onShown.append(self.setWindowTitle)
83 self["list"] = PluginList(self.list)
86 self.installedplugins = []
88 if self.type == self.DOWNLOAD:
89 self["text"] = Label(_("Downloading plugin information. Please wait..."))
90 elif self.type == self.REMOVE:
91 self["text"] = Label(_("Getting plugin information. Please wait..."))
95 self.remainingdata = ""
97 self["actions"] = ActionMap(["WizardActions"],
104 sel = self["list"].l.getCurrentSelection()
110 if isinstance(sel, str): # category
111 if sel in self.expanded:
112 self.expanded.remove(sel)
114 self.expanded.append(sel)
117 if self.type == self.DOWNLOAD:
118 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to download\nthe plugin \"%s\"?") % sel.name)
119 elif self.type == self.REMOVE:
120 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to REMOVE\nthe plugin \"%s\"?") % sel.name)
122 def runInstall(self, val):
124 if self.type == self.DOWNLOAD:
125 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["ipkg install " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
126 elif self.type == self.REMOVE:
127 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["ipkg remove " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
129 def setWindowTitle(self):
130 if self.type == self.DOWNLOAD:
131 self.setTitle(_("Downloadable new plugins"))
132 elif self.type == self.REMOVE:
133 self.setTitle(_("Remove plugins"))
135 def startIpkgListInstalled(self):
136 self.container.execute("ipkg list_installed enigma2-plugin-*")
139 self["list"].instance.hide()
140 if self.type == self.DOWNLOAD:
141 if not PluginDownloadBrowser.lastDownloadDate or (time() - PluginDownloadBrowser.lastDownloadDate) > 3600:
142 # Only update from internet once per hour
143 self.container.execute("ipkg update")
144 PluginDownloadBrowser.lastDownloadDate = time()
146 self.startIpkgListInstalled()
147 elif self.type == self.REMOVE:
149 self.startIpkgListInstalled()
151 def installFinished(self):
152 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
153 self.container.appClosed.remove(self.runFinished)
154 self.container.dataAvail.remove(self.dataAvail)
157 def runFinished(self, retval):
158 self.remainingdata = ""
161 if self.type == self.DOWNLOAD:
162 self.startIpkgListInstalled()
163 elif self.run == 1 and self.type == self.DOWNLOAD:
165 self.container.execute("ipkg list enigma2-plugin-*")
167 if len(self.pluginlist) > 0:
169 self["list"].instance.show()
171 self["text"].setText("No new plugins found")
173 def dataAvail(self, str):
174 #prepend any remaining data from the previous call
175 str = self.remainingdata + str
177 lines = str.split('\n')
178 #'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
180 #remember this data for next time
181 self.remainingdata = lines[-1]
184 self.remainingdata = ""
187 plugin = x.split(" - ")
189 if self.run == 1 and self.type == self.DOWNLOAD:
190 self.installedplugins.append(plugin[0])
192 if plugin[0] not in self.installedplugins:
193 plugin.append(plugin[0][15:])
195 self.pluginlist.append(plugin)
197 def updateList(self):
199 expandableIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/expandable-plugins.png"))
200 expandedIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/expanded-plugins.png"))
201 verticallineIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/verticalline-plugins.png"))
204 for x in self.pluginlist:
205 split = x[3].split('-', 1)
208 if not self.plugins.has_key(split[0]):
209 self.plugins[split[0]] = []
211 self.plugins[split[0]].append((PluginDescriptor(name = x[3], description = x[2], icon = verticallineIcon), split[1]))
213 for x in self.plugins.keys():
214 if x in self.expanded:
215 list.append(PluginCategoryComponent(x, expandedIcon))
216 list.extend([PluginDownloadComponent(plugin[0], plugin[1]) for plugin in self.plugins[x]])
218 list.append(PluginCategoryComponent(x, expandableIcon))
220 self["list"].l.setList(list)