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)
26 self["green"] = Label()
29 self["list"] = PluginList(self.list)
31 self["actions"] = ActionMap(["WizardActions"],
36 self.onFirstExecBegin.append(self.checkWarnings)
37 self.onShown.append(self.updateList)
39 def checkWarnings(self):
40 if len(plugins.warnings):
41 text = _("Some plugins are not available:\n")
42 for (pluginname, error) in plugins.warnings:
43 text += _("%s (%s)\n") % (pluginname, error)
44 plugins.resetWarnings()
45 self.session.open(MessageBox, text = text, type = MessageBox.TYPE_WARNING)
51 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]
57 self["list"].l.setList(self.list)
60 self.session.openWithCallback(self.PluginDownloadBrowserClosed, PluginDownloadBrowser, PluginDownloadBrowser.REMOVE)
63 self.session.openWithCallback(self.PluginDownloadBrowserClosed, PluginDownloadBrowser, PluginDownloadBrowser.DOWNLOAD)
65 def PluginDownloadBrowserClosed(self):
70 class PluginDownloadBrowser(Screen):
73 lastDownloadDate = None
75 def __init__(self, session, type):
76 Screen.__init__(self, session)
80 self.container = eConsoleAppContainer()
81 self.container.appClosed.append(self.runFinished)
82 self.container.dataAvail.append(self.dataAvail)
83 self.onLayoutFinish.append(self.startRun)
84 self.onShown.append(self.setWindowTitle)
87 self["list"] = PluginList(self.list)
90 self.installedplugins = []
92 if self.type == self.DOWNLOAD:
93 self["text"] = Label(_("Downloading plugin information. Please wait..."))
94 elif self.type == self.REMOVE:
95 self["text"] = Label(_("Getting plugin information. Please wait..."))
99 self.remainingdata = ""
101 self["actions"] = ActionMap(["WizardActions"],
108 sel = self["list"].l.getCurrentSelection()
114 if isinstance(sel, str): # category
115 if sel in self.expanded:
116 self.expanded.remove(sel)
118 self.expanded.append(sel)
121 if self.type == self.DOWNLOAD:
122 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to download\nthe plugin \"%s\"?") % sel.name)
123 elif self.type == self.REMOVE:
124 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to REMOVE\nthe plugin \"%s\"?") % sel.name)
126 def runInstall(self, val):
128 if self.type == self.DOWNLOAD:
129 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["ipkg install " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
130 elif self.type == self.REMOVE:
131 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["ipkg remove " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
133 def setWindowTitle(self):
134 if self.type == self.DOWNLOAD:
135 self.setTitle(_("Downloadable new plugins"))
136 elif self.type == self.REMOVE:
137 self.setTitle(_("Remove plugins"))
139 def startIpkgListInstalled(self):
140 self.container.execute("ipkg list_installed enigma2-plugin-*")
142 def startIpkgListAvailable(self):
143 self.container.execute("ipkg list enigma2-plugin-*")
146 self["list"].instance.hide()
147 if self.type == self.DOWNLOAD:
148 if not PluginDownloadBrowser.lastDownloadDate or (time() - PluginDownloadBrowser.lastDownloadDate) > 3600:
149 # Only update from internet once per hour
150 self.container.execute("ipkg update")
151 PluginDownloadBrowser.lastDownloadDate = time()
153 self.startIpkgListAvailable()
154 elif self.type == self.REMOVE:
156 self.startIpkgListInstalled()
158 def installFinished(self):
159 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
160 self.container.appClosed.remove(self.runFinished)
161 self.container.dataAvail.remove(self.dataAvail)
164 def runFinished(self, retval):
165 self.remainingdata = ""
168 if self.type == self.DOWNLOAD:
169 self.startIpkgListInstalled()
170 elif self.run == 1 and self.type == self.DOWNLOAD:
172 self.startIpkgListAvailable()
174 if len(self.pluginlist) > 0:
176 self["list"].instance.show()
178 self["text"].setText("No new plugins found")
180 def dataAvail(self, str):
181 #prepend any remaining data from the previous call
182 str = self.remainingdata + str
184 lines = str.split('\n')
185 #'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
187 #remember this data for next time
188 self.remainingdata = lines[-1]
191 self.remainingdata = ""
194 plugin = x.split(" - ", 2)
196 if self.run == 1 and self.type == self.DOWNLOAD:
197 if plugin[0] not in self.installedplugins:
198 self.installedplugins.append(plugin[0])
200 if plugin[0] not in self.installedplugins:
201 plugin.append(plugin[0][15:])
203 self.pluginlist.append(plugin)
205 def updateList(self):
207 expandableIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/expandable-plugins.png"))
208 expandedIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/expanded-plugins.png"))
209 verticallineIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/verticalline-plugins.png"))
212 for x in self.pluginlist:
213 split = x[3].split('-', 1)
216 if not self.plugins.has_key(split[0]):
217 self.plugins[split[0]] = []
219 self.plugins[split[0]].append((PluginDescriptor(name = x[3], description = x[2], icon = verticallineIcon), split[1]))
221 for x in self.plugins.keys():
222 if x in self.expanded:
223 list.append(PluginCategoryComponent(x, expandedIcon))
224 list.extend([PluginDownloadComponent(plugin[0], plugin[1]) for plugin in self.plugins[x]])
226 list.append(PluginCategoryComponent(x, expandableIcon))
228 self["list"].l.setList(list)
230 language.addCallback(languageChanged)