update pluginlist after downloading a plugin
[enigma2.git] / lib / python / Screens / PluginBrowser.py
1 from Screen import Screen
2
3 from enigma import eConsoleAppContainer
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
15
16 class PluginBrowser(Screen):
17         def __init__(self, session):
18                 Screen.__init__(self, session)
19                 
20                 self["red"] = Label(_("Delete"))
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                 
35         def save(self):
36                 #self.close()
37                 self.run()
38         
39         def run(self):
40                 plugin = self["list"].l.getCurrentSelection()[0]
41                 
42                 plugin(session=self.session)
43                 
44         def updateList(self):
45                 self.list = [ ]
46                 self.pluginlist = plugins.getPlugins(PluginDescriptor.WHERE_PLUGINMENU)
47                 for plugin in self.pluginlist:
48                         self.list.append(PluginEntryComponent(plugin))
49                 
50                 self["list"].l.setList(self.list)
51
52         def delete(self):
53                 pass
54         
55         def download(self):
56                 self.session.openWithCallback(self.updateList, PluginDownloadBrowser)
57
58 class PluginDownloadBrowser(Screen):
59         def __init__(self, session):
60                 Screen.__init__(self, session)
61                 
62                 self.container = eConsoleAppContainer()
63                 self.container.appClosed.get().append(self.runFinished)
64                 self.container.dataAvail.get().append(self.dataAvail)
65                 self.onLayoutFinish.append(self.startRun)
66                 
67                 self.list = []
68                 self["list"] = PluginList(self.list)
69                 self.pluginlist = []
70                 
71                 self["text"] = Label(_("Downloading plugin information. Please wait..."))
72                 
73                 self.run = 0
74                                 
75                 self["actions"] = ActionMap(["WizardActions"], 
76                 {
77                         "ok": self.go,
78                         "back": self.close,
79                 })
80                 
81         def go(self):
82                 print "plugin: installing:", self.pluginlist[self["list"].l.getCurrentSelectionIndex()]
83                 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to download\nthe plugin \"" + self.pluginlist[self["list"].l.getCurrentSelectionIndex()][3] + "\"?"))
84                 
85         def runInstall(self, val):
86                 if val:
87                         self.session.openWithCallback(self.installFinished, Console, ["ipkg install " + self.pluginlist[self["list"].l.getCurrentSelectionIndex()][0]])
88
89         def startRun(self):
90                 self["list"].instance.hide()
91                 self.container.execute("ipkg update")
92                 
93         def installFinished(self):
94                 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
95                 
96         def runFinished(self, retval):
97                 if self.run == 0:
98                         self.run = 1
99                         self.container.execute("ipkg list enigma2-plugin-*")
100                 else:
101                         if len(self.pluginlist) > 0:
102                                 self.updateList()
103                                 self["list"].instance.show()
104                         else:
105                                 self["text"].setText("No plugins found")
106
107         def dataAvail(self, str):
108                 for x in str.split('\n'):
109                         plugin = x.split(" - ")
110                         if len(plugin) == 3:
111                                 plugin.append(plugin[0][15:])
112
113                                 self.pluginlist.append(plugin)
114         
115         def updateList(self):
116                 for x in self.pluginlist:
117                         plugin = PluginDescriptor(name = x[3], description = x[2])
118                         self.list.append(PluginEntryComponent(plugin))
119                 
120                 self["list"].l.setList(self.list)
121