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