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)
27 self["actions"] = ActionMap(["WizardActions", "ColorActions"],
32 "green": self.download
34 self.onFirstExecBegin.append(self.checkWarnings)
35 self.onShown.append(self.updateList)
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]
51 plugin(session=self.session)
54 self.pluginlist = plugins.getPlugins(PluginDescriptor.WHERE_PLUGINMENU)
55 self.list = [PluginEntryComponent(plugin) for plugin in self.pluginlist]
56 self["list"].l.setList(self.list)
59 self.session.openWithCallback(self.PluginDownloadBrowserClosed, PluginDownloadBrowser, PluginDownloadBrowser.REMOVE)
62 self.session.openWithCallback(self.PluginDownloadBrowserClosed, PluginDownloadBrowser, PluginDownloadBrowser.DOWNLOAD)
64 def PluginDownloadBrowserClosed(self):
69 class PluginDownloadBrowser(Screen):
72 lastDownloadDate = None
74 def __init__(self, session, type):
75 Screen.__init__(self, session)
79 self.container = eConsoleAppContainer()
80 self.container.appClosed.append(self.runFinished)
81 self.container.dataAvail.append(self.dataAvail)
82 self.onLayoutFinish.append(self.startRun)
83 self.onShown.append(self.setWindowTitle)
86 self["list"] = PluginList(self.list)
89 self.installedplugins = []
91 if self.type == self.DOWNLOAD:
92 self["text"] = Label(_("Downloading plugin information. Please wait..."))
93 elif self.type == self.REMOVE:
94 self["text"] = Label(_("Getting plugin information. Please wait..."))
98 self.remainingdata = ""
100 self["actions"] = ActionMap(["WizardActions"],
107 sel = self["list"].l.getCurrentSelection()
113 if isinstance(sel, str): # category
114 if sel in self.expanded:
115 self.expanded.remove(sel)
117 self.expanded.append(sel)
120 if self.type == self.DOWNLOAD:
121 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to download\nthe plugin \"%s\"?") % sel.name)
122 elif self.type == self.REMOVE:
123 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to REMOVE\nthe plugin \"%s\"?") % sel.name)
125 def runInstall(self, val):
127 if self.type == self.DOWNLOAD:
128 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["ipkg install " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
129 elif self.type == self.REMOVE:
130 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["ipkg remove " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
132 def setWindowTitle(self):
133 if self.type == self.DOWNLOAD:
134 self.setTitle(_("Downloadable new plugins"))
135 elif self.type == self.REMOVE:
136 self.setTitle(_("Remove plugins"))
138 def startIpkgListInstalled(self):
139 self.container.execute("ipkg list_installed enigma2-plugin-*")
141 def startIpkgListAvailable(self):
142 self.container.execute("ipkg list enigma2-plugin-*")
145 self["list"].instance.hide()
146 if self.type == self.DOWNLOAD:
147 if not PluginDownloadBrowser.lastDownloadDate or (time() - PluginDownloadBrowser.lastDownloadDate) > 3600:
148 # Only update from internet once per hour
149 self.container.execute("ipkg update")
150 PluginDownloadBrowser.lastDownloadDate = time()
152 self.startIpkgListAvailable()
153 elif self.type == self.REMOVE:
155 self.startIpkgListInstalled()
157 def installFinished(self):
158 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
159 self.container.appClosed.remove(self.runFinished)
160 self.container.dataAvail.remove(self.dataAvail)
163 def runFinished(self, retval):
164 self.remainingdata = ""
167 if self.type == self.DOWNLOAD:
168 self.startIpkgListInstalled()
169 elif self.run == 1 and self.type == self.DOWNLOAD:
171 self.startIpkgListAvailable()
173 if len(self.pluginlist) > 0:
175 self["list"].instance.show()
177 self["text"].setText("No new plugins found")
179 def dataAvail(self, str):
180 #prepend any remaining data from the previous call
181 str = self.remainingdata + str
183 lines = str.split('\n')
184 #'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
186 #remember this data for next time
187 self.remainingdata = lines[-1]
190 self.remainingdata = ""
193 plugin = x.split(" - ", 2)
195 if self.run == 1 and self.type == self.DOWNLOAD:
196 if plugin[0] not in self.installedplugins:
197 self.installedplugins.append(plugin[0])
199 if plugin[0] not in self.installedplugins:
200 plugin.append(plugin[0][15:])
202 self.pluginlist.append(plugin)
204 def updateList(self):
206 expandableIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/expandable-plugins.png"))
207 expandedIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/expanded-plugins.png"))
208 verticallineIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/verticalline-plugins.png"))
211 for x in self.pluginlist:
212 split = x[3].split('-', 1)
215 if not self.plugins.has_key(split[0]):
216 self.plugins[split[0]] = []
218 self.plugins[split[0]].append((PluginDescriptor(name = x[3], description = x[2], icon = verticallineIcon), split[1]))
220 for x in self.plugins.keys():
221 if x in self.expanded:
222 list.append(PluginCategoryComponent(x, expandedIcon))
223 list.extend([PluginDownloadComponent(plugin[0], plugin[1]) for plugin in self.plugins[x]])
225 list.append(PluginCategoryComponent(x, expandableIcon))
227 self["list"].l.setList(list)