do some voodoo on the config list to store the connectedTo values properly (reset...
[enigma2.git] / lib / python / Screens / DefaultWizard.py
1 from Wizard import wizardManager
2 from Screens.WizardLanguage import WizardLanguage
3 from Tools.Directories import resolveFilename, SCOPE_DEFAULTDIR, SCOPE_DEFAULTPARTITIONMOUNTDIR, SCOPE_DEFAULTPARTITION
4
5 from Components.Pixmap import Pixmap, MovingPixmap
6 from Components.config import config, ConfigBoolean, configfile, ConfigYesNo, getConfigListEntry
7 from Components.DreamInfoHandler import DreamInfoHandler
8 from Components.PluginComponent import plugins
9 from Plugins.Plugin import PluginDescriptor
10 from os import system as os_system, path as os_path
11
12 config.misc.defaultchosen = ConfigBoolean(default = True)
13
14 class DefaultWizard(WizardLanguage, DreamInfoHandler):
15         def __init__(self, session, silent = True, showSteps = False, neededTag = None):
16                 DreamInfoHandler.__init__(self, self.statusCallback, neededTag = neededTag)
17                 self.silent = silent
18                 self.setDirectory()
19         
20                 WizardLanguage.__init__(self, session, showSteps = False)
21                 self["wizard"] = Pixmap()
22                 self["rc"] = MovingPixmap()
23                 self["arrowdown"] = MovingPixmap()
24                 self["arrowup"] = MovingPixmap()
25                 self["arrowup2"] = MovingPixmap()
26         
27         def setDirectory(self):
28                 os_system("mount %s %s" % (resolveFilename(SCOPE_DEFAULTPARTITION), resolveFilename(SCOPE_DEFAULTPARTITIONMOUNTDIR)))
29                 self.directory = resolveFilename(SCOPE_DEFAULTPARTITIONMOUNTDIR)
30                 self.xmlfile = "defaultwizard.xml"
31         
32         def markDone(self):
33                 config.misc.defaultchosen.value = 0
34                 config.misc.defaultchosen.save()
35                 configfile.save()
36                 
37         def statusCallback(self, status, progress):
38                 print "statusCallback:", status, progress
39                 if status == DreamInfoHandler.STATUS_DONE:
40                         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."))
41                         self.markDone()
42                         self.disableKeys = False
43
44         def getConfigList(self):
45                 self.packageslist = []
46                 configList = []
47                 self.fillPackagesList()
48                 self.packagesConfig = []
49                 for x in range(len(self.packageslist)):
50                         entry = ConfigYesNo()
51                         self.packagesConfig.append(entry)
52                         configList.append(getConfigListEntry(self.packageslist[x][0]["attributes"]["name"], entry))
53                 return configList
54
55         def selectionMade(self):
56                 print "selection made"
57                 #self.installPackage(int(index))
58                 self.indexList = []
59                 for x in range(len(self.packagesConfig)):
60                         if self.packagesConfig[x].value:
61                                 self.indexList.append(x)
62                 
63 class DreamPackageWizard(DefaultWizard):
64         def __init__(self, session, packagefile, silent = False):
65                 os_system("mkdir /tmp/package")
66                 os_system("tar xpzf %s -C /tmp/package" % packagefile)
67                 self.packagefile = packagefile
68                 DefaultWizard.__init__(self, session, silent)
69                 
70         def setDirectory(self):
71                 self.directory = "/tmp/package"
72                 self.xmlfile = "dreampackagewizard.xml"
73                 
74 class ImageDefaultInstaller(DreamInfoHandler):
75         def __init__(self):
76                 DreamInfoHandler.__init__(self, self.statusCallback, blocking = True)
77                 self.directory = resolveFilename(SCOPE_DEFAULTDIR)
78                 self.fillPackagesList()
79                 self.installPackage(0)
80                 
81         def statusCallback(self, status, progress):
82                 pass
83
84 def install(choice):
85         if choice is not None:
86                 #os_system("mkdir /tmp/package && tar xpzf %s ")
87                 choice[2].open(DreamPackageWizard, choice[1])
88
89 def filescan_open(list, session, **kwargs):
90         from Screens.ChoiceBox import ChoiceBox
91         print "open default wizard"
92         filelist = [(os_path.split(x.path)[1], x.path, session) for x in list]
93         print filelist
94         session.openWithCallback(install, ChoiceBox, title = _("Please choose he package..."), list=filelist)
95
96 def filescan(**kwargs):
97         from Components.Scanner import Scanner, ScanPath
98         from mimetypes import add_type
99         add_type("application/x-dream-package", "dmpkg")
100         return \
101                 Scanner(mimetypes = ["application/x-dream-package"], 
102                         paths_to_scan = 
103                                 [
104                                         ScanPath(path = "dmpkg", with_subdirs = True), 
105                                         ScanPath(path = "", with_subdirs = False), 
106                                 ], 
107                         name = "Dream-Package", 
108                         description = "Install settings, skins, software...", 
109                         openfnc = filescan_open, )
110
111 print "add dreampackage scanner plugin"
112 plugins.addPlugin(PluginDescriptor(name="Dream-Package", where = PluginDescriptor.WHERE_FILESCAN, fnc = filescan, internal = True))
113 print "added"
114
115 wizardManager.registerWizard(DefaultWizard, config.misc.defaultchosen.value, priority = 6)
116
117 if config.misc.defaultchosen.value:
118         print "Installing image defaults"
119         installer = ImageDefaultInstaller()
120         print "installing done!"