Merge branch 'master' of fraxinas@git.opendreambox.org:/git/enigma2
[enigma2.git] / lib / python / Screens / DefaultWizard.py
index 5d274b0eb556199b60f0e30260926e958a8f1fc5..9883dc8e9ef4259d9885a2ac0cbb017826252ac4 100644 (file)
@@ -1,27 +1,33 @@
-from Wizard import Wizard, wizardManager
-from Tools.Directories import crawlDirectory, resolveFilename, SCOPE_DEFAULTDIR
+from Wizard import wizardManager
+from Screens.WizardLanguage import WizardLanguage
+from Tools.Directories import pathExists, resolveFilename, SCOPE_DEFAULTDIR, SCOPE_DEFAULTPARTITIONMOUNTDIR, SCOPE_DEFAULTPARTITION
 
 from Components.Pixmap import Pixmap, MovingPixmap
-from Components.config import config, ConfigBoolean, configfile
-from Components.DreamInfoHandler import DreamInfoHandler, InfoHandler, InfoHandlerParseError
-import os
+from Components.config import config, ConfigBoolean, configfile, ConfigYesNo, getConfigListEntry
+from Components.DreamInfoHandler import DreamInfoHandler
+from Components.PluginComponent import plugins
+from Plugins.Plugin import PluginDescriptor
+from os import system as os_system, path as os_path, mkdir
 
 config.misc.defaultchosen = ConfigBoolean(default = True)
 
-import xml.sax
-
-class DefaultWizard(Wizard, DreamInfoHandler):
-       def __init__(self, session):
-               DreamInfoHandler.__init__(self, self.statusCallback)
-               self.directory = resolveFilename(SCOPE_DEFAULTDIR)
-               self.xmlfile = "defaultwizard.xml"
+class DefaultWizard(WizardLanguage, DreamInfoHandler):
+       def __init__(self, session, silent = True, showSteps = False, neededTag = None):
+               DreamInfoHandler.__init__(self, self.statusCallback, neededTag = neededTag)
+               self.silent = silent
+               self.setDirectory()
         
-               Wizard.__init__(self, session, showSteps = False)
+               WizardLanguage.__init__(self, session, showSteps = False)
                self["wizard"] = Pixmap()
                self["rc"] = MovingPixmap()
                self["arrowdown"] = MovingPixmap()
                self["arrowup"] = MovingPixmap()
                self["arrowup2"] = MovingPixmap()
+       
+       def setDirectory(self):
+               os_system("mount %s %s" % (resolveFilename(SCOPE_DEFAULTPARTITION), resolveFilename(SCOPE_DEFAULTPARTITIONMOUNTDIR)))
+               self.directory = resolveFilename(SCOPE_DEFAULTPARTITIONMOUNTDIR)
+               self.xmlfile = "defaultwizard.xml"
         
        def markDone(self):
                config.misc.defaultchosen.value = 0
@@ -31,19 +37,85 @@ class DefaultWizard(Wizard, DreamInfoHandler):
        def statusCallback(self, status, progress):
                print "statusCallback:", status, progress
                if status == DreamInfoHandler.STATUS_DONE:
-                       self["text"].setText(_("Finished"))
+                       self["text"].setText(_("The installation of the default settings is finished. You can now continue configuring your Dreambox by pressing the OK button on the remote control."))
                        self.markDone()
-                       os.system("killall -9 enigma2")
+                       self.disableKeys = False
 
-       def listDefaults(self):
+       def getConfigList(self):
                self.packageslist = []
+               configList = []
                self.fillPackagesList()
-               list = []
+               self.packagesConfig = []
                for x in range(len(self.packageslist)):
-                       list.append((self.packageslist[x][0]["attributes"]["name"], str(x)))
-               print "defaults list:", list
-               return list
-    
-       def selectionMade(self, index):
-               print "selected:", index
-               self.installPackage(int(index))
\ No newline at end of file
+                       entry = ConfigYesNo()
+                       self.packagesConfig.append(entry)
+                       configList.append(getConfigListEntry(self.packageslist[x][0]["attributes"]["name"], entry))
+               return configList
+
+       def selectionMade(self):
+               print "selection made"
+               #self.installPackage(int(index))
+               self.indexList = []
+               for x in range(len(self.packagesConfig)):
+                       if self.packagesConfig[x].value:
+                               self.indexList.append(x)
+
+class DreamPackageWizard(DefaultWizard):
+       def __init__(self, session, packagefile, silent = False):
+               if not pathExists("/tmp/package"):
+                       mkdir("/tmp/package")
+               os_system("tar xpzf %s -C /tmp/package" % packagefile)
+               self.packagefile = packagefile
+               DefaultWizard.__init__(self, session, silent)
+               
+       def setDirectory(self):
+               self.directory = "/tmp/package"
+               self.xmlfile = "dreampackagewizard.xml"
+               
+class ImageDefaultInstaller(DreamInfoHandler):
+       def __init__(self):
+               DreamInfoHandler.__init__(self, self.statusCallback, blocking = True)
+               self.directory = resolveFilename(SCOPE_DEFAULTDIR)
+               self.fillPackagesList()
+               self.installPackage(0)
+               
+       def statusCallback(self, status, progress):
+               pass
+
+def install(choice):
+       if choice is not None:
+               #os_system("mkdir /tmp/package && tar xpzf %s ")
+               choice[2].open(DreamPackageWizard, choice[1])
+
+def filescan_open(list, session, **kwargs):
+       from Screens.ChoiceBox import ChoiceBox
+       print "open default wizard"
+       filelist = [(os_path.split(x.path)[1], x.path, session) for x in list]
+       print filelist
+       session.openWithCallback(install, ChoiceBox, title = _("Please choose he package..."), list=filelist)
+
+def filescan(**kwargs):
+       from Components.Scanner import Scanner, ScanPath
+       from mimetypes import add_type
+       add_type("application/x-dream-package", "dmpkg")
+       return \
+               Scanner(mimetypes = ["application/x-dream-package"], 
+                       paths_to_scan = 
+                               [
+                                       ScanPath(path = "dmpkg", with_subdirs = True), 
+                                       ScanPath(path = "", with_subdirs = False), 
+                               ], 
+                       name = "Dream-Package", 
+                       description = "Install settings, skins, software...", 
+                       openfnc = filescan_open, )
+
+print "add dreampackage scanner plugin"
+plugins.addPlugin(PluginDescriptor(name="Dream-Package", where = PluginDescriptor.WHERE_FILESCAN, fnc = filescan, internal = True))
+print "added"
+
+wizardManager.registerWizard(DefaultWizard, config.misc.defaultchosen.value, priority = 6)
+
+if config.misc.defaultchosen.value:
+       print "Installing image defaults"
+       installer = ImageDefaultInstaller()
+       print "installing done!"