unify the two update plugins and add a menu to the new unified plugin
[enigma2.git] / lib / python / Plugins / update / plugin.py
index 90846f0410b9861a2a93c49148839e019d873613..a25eeb7e6694c8ebef7ef749e0219f74c05db14f 100644 (file)
@@ -2,11 +2,46 @@ from enigma import *
 from Screens.Screen import Screen
 from Screens.MessageBox import MessageBox
 from Components.ActionMap import ActionMap
-from Components.Label import Label
+from Components.ScrollLabel import ScrollLabel
 from Components.GUIComponent import *
+from Components.MenuList import MenuList
+from Plugins.Plugin import PluginDescriptor
 
 import os
 
+class UpdatePluginMenu(Screen):
+       skin = """
+               <screen position="200,100" size="300,250" title="Update..." >
+                       <widget name="menu" position="10,10" size="290,175" scrollbarMode="showOnDemand" />
+               </screen>"""
+               
+       def __init__(self, session, args = None):
+               self.skin = UpdatePluginMenu.skin
+               Screen.__init__(self, session)
+               
+               list = []
+               list.append((_("Upgrade"), "upgrade"))
+               list.append((_("Choose source"), None))
+               list.append((_("Packet management"), "ipkg"))
+               
+               self["menu"] = MenuList(list)
+                               
+               self["actions"] = ActionMap(["WizardActions", "DirectionActions"], 
+               {
+                       "ok": self.go,
+                       "back": self.close,
+               }, -1)
+               
+       def go(self):
+               if (self["menu"].l.getCurrentSelection()[1] == "upgrade"):
+                       self.session.openWithCallback(self.runUpgrade, MessageBox, _("Do you want to update your Dreambox?\nAfter pressing OK, please wait!"))
+               elif (self["menu"].l.getCurrentSelection()[1] == "ipkg"):
+                       self.session.open(Ipkg)
+       
+       def runUpgrade(self, result):
+               if result:
+                       self.session.open(Upgrade)
+       
 class Upgrade(Screen):
        skin = """
                <screen position="100,100" size="550,400" title="IPKG upgrade..." >
@@ -17,40 +52,32 @@ class Upgrade(Screen):
                self.skin = Upgrade.skin
                Screen.__init__(self, session)
 
-               self["text"] = Label(_("Please press OK!"))
+               self["text"] = ScrollLabel(_("Updating... Please wait... This can take some minutes..."))
                                
-               self["actions"] = ActionMap(["WizardActions"], 
+               self["actions"] = ActionMap(["WizardActions", "DirectionActions"], 
                {
                        "ok": self.go,
-                       "back": self.close
+                       "back": self.close,
+                       "up": self["text"].pageUp,
+                       "down": self["text"].pageDown
                }, -1)
                
-               self.update = True
                self.delayTimer = eTimer()
                self.delayTimer.timeout.get().append(self.doUpdateDelay)
+               # WARNING! Don't copy this code! this code could harm your children! It is ugly, bad and must be banned from this world!
+               # it only exists due to some lack of competence by the core system designers.
+               self.delayTimer.start(1, 1)
                
        def go(self):
-               if self.update:
-                       self.session.openWithCallback(self.doUpdate, MessageBox, _("Do you want to update your Dreambox?\nAfter pressing OK, please wait!"))            
-               else:
-                       self.close()
+               self.close()
        
        def doUpdateDelay(self):
-               lines = os.popen("ipkg update && ipkg upgrade", "r").readlines()
+               lines = os.popen("ipkg update && ipkg upgrade -force-defaults -force-overwrite", "r").readlines()
                string = ""
                for x in lines:
                        string += x
                self["text"].setText(_("Updating finished. Here is the result:") + "\n\n" + string)
-               self.update = False
                        
-       
-       def doUpdate(self, val = False):
-               if val == True:
-                       self["text"].setText(_("Updating... Please wait... This can take some minutes..."))
-                       self.delayTimer.start(0, 1)
-               else:
-                       self.close()
-
 RT_HALIGN_LEFT = 0
 RT_HALIGN_RIGHT = 1
 RT_HALIGN_CENTER = 2
@@ -159,23 +186,8 @@ class Ipkg(Screen):
                else:
                        self.close()
 
+def UpgradeMain(session):
+       session.open(UpdatePluginMenu)
 
-
-def autostart():
-       return
-       os.popen("ipkg update", "r")    
-#
-#def autoend():
-       #print "**************************** AUTOEND"
-
-def getPicturePaths():
-       return ["update.png", "update.png"]
-
-def getPlugins():
-       return [("Softwareupdate", "Updates your receiver's software", "screen", "Upgrade"),
-                       ("IPKG", "Updates your receiver's software", "screen", "Ipkg")]
-       
-def getMenuRegistrationList():
-       list = []
-       list.append(("setup", 2, "Softwareupdate", "Upgrade"))
-       return list
\ No newline at end of file
+def Plugins():
+       return PluginDescriptor(name="Softwareupdate", description="Updates your receiver's software", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=UpgradeMain)