Merge branch 'bug_271_ac3pcm_delay_servicemp3' into experimental
[enigma2.git] / lib / python / Screens / DefaultWizard.py
1 from Wizard import wizardManager
2 from Screens.WizardLanguage import WizardLanguage
3 from Tools.Directories import pathExists, 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, mkdir
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                 if not pathExists("/tmp/package"):
66                         mkdir("/tmp/package")
67                 os_system("tar xpzf %s -C /tmp/package" % packagefile)
68                 self.packagefile = packagefile
69                 DefaultWizard.__init__(self, session, silent)
70                 
71         def setDirectory(self):
72                 self.directory = "/tmp/package"
73                 self.xmlfile = "dreampackagewizard.xml"
74                 
75 class ImageDefaultInstaller(DreamInfoHandler):
76         def __init__(self):
77                 DreamInfoHandler.__init__(self, self.statusCallback, blocking = True)
78                 self.directory = resolveFilename(SCOPE_DEFAULTDIR)
79                 self.fillPackagesList()
80                 self.installPackage(0)
81                 
82         def statusCallback(self, status, progress):
83                 pass
84
85 def install(choice):
86         if choice is not None:
87                 #os_system("mkdir /tmp/package && tar xpzf %s ")
88                 choice[2].open(DreamPackageWizard, choice[1])
89
90 def filescan_open(list, session, **kwargs):
91         from Screens.ChoiceBox import ChoiceBox
92         print "open default wizard"
93         filelist = [(os_path.split(x.path)[1], x.path, session) for x in list]
94         print filelist
95         session.openWithCallback(install, ChoiceBox, title = _("Please choose he package..."), list=filelist)
96
97 def filescan(**kwargs):
98         from Components.Scanner import Scanner, ScanPath
99         return \
100                 Scanner(mimetypes = ["application/x-dream-package"], 
101                         paths_to_scan = 
102                                 [
103                                         ScanPath(path = "dmpkg", with_subdirs = True), 
104                                         ScanPath(path = "", with_subdirs = False), 
105                                 ], 
106                         name = "Dream-Package", 
107                         description = _("Install settings, skins, software..."), 
108                         openfnc = filescan_open, )
109
110 print "add dreampackage scanner plugin"
111 plugins.addPlugin(PluginDescriptor(name="Dream-Package", where = PluginDescriptor.WHERE_FILESCAN, fnc = filescan, internal = True))
112 print "added"
113
114 wizardManager.registerWizard(DefaultWizard, config.misc.defaultchosen.value, priority = 6)
115
116 if config.misc.defaultchosen.value:
117         print "Installing image defaults"
118         installer = ImageDefaultInstaller()
119         print "installing done!"