fix disc size unit confusion
[enigma2.git] / lib / python / Plugins / Extensions / DVDBurn / TitleList.py
index 416c14e9123e1c8b657025abc75de68c42bd068b..83bafd747efdf00721eae344383f8ae6ed722c4c 100644 (file)
@@ -41,10 +41,10 @@ class TitleList(Screen, HelpableScreen):
                self["titleactions"] = HelpableActionMap(self, "DVDTitleList",
                        {
                                "addTitle": (self.addTitle, _("Add a new title"), _("Add title")),
-                               "titleProperties": (self.titleProperties, ("Properties of current title"), _("Title properties")),
+                               "titleProperties": (self.titleProperties, _("Properties of current title"), _("Title properties")),
                                "removeCurrentTitle": (self.removeCurrentTitle, _("Remove currently selected title"), _("Remove title")),
                                "settings": (self.settings, _("Collection settings"), _("Settings")),
-                               "burnProject": (self.burnProject, _("Burn DVD"), _("Burn DVD")),
+                               "burnProject": (self.askBurnProject, _("Burn DVD"), _("Burn DVD")),
                        })
 
                self["MovieSelectionActions"] = HelpableActionMap(self, "MovieSelectionActions",
@@ -57,9 +57,9 @@ class TitleList(Screen, HelpableScreen):
                                "cancel": self.leave
                        })
 
-               self["key_red"] = StaticText(_("Remove title"))
+               self["key_red"] = StaticText()
                self["key_green"] = StaticText(_("Add title"))
-               self["key_yellow"] = StaticText(_("Title properties"))
+               self["key_yellow"] = StaticText()
                self["key_blue"] = StaticText(_("Settings"))
 
                self["title_label"] = StaticText()
@@ -74,22 +74,33 @@ class TitleList(Screen, HelpableScreen):
 
                self["titles"] = List(list = [ ], enableWrapAround = True, item_height=30, fonts = [gFont("Regular", 20)])
                self.updateTitleList()
-               
+               self.previous_size = 0
+
+       def checkBackgroundJobs(self):
+               for job in job_manager.getPendingJobs():
+                       print "type(job):", type(job)
+                       print "Process.DVDJob:", Process.DVDJob
+                       if type(job) == Process.DVDJob:
+                               self.backgroundJob = job
+                               return
+               self.backgroundJob = None
+
        def showMenu(self):
                menu = []
+               self.checkBackgroundJobs()
+               if self.backgroundJob:
+                       j = self.backgroundJob
+                       menu.append(("%s: %s (%d%%)" % (j.getStatustext(), j.name, int(100*j.progress/float(j.end))), self.showBackgroundJob))
+               menu.append((_("DVD media toolbox"), self.toolbox))
+               menu.append((_("Preview menu"), self.previewMenu))
                if self.project.settings.output.getValue() == "dvd":
-                       menu.append((_("Burn DVD"), self.burnProject))
+                       if len(self["titles"].list):
+                               menu.append((_("Burn DVD"), self.burnProject))
                elif self.project.settings.output.getValue() == "iso":
                        menu.append((_("Create DVD-ISO"), self.burnProject))
                menu.append((_("Burn existing image to DVD"), self.selectImage))
-               menu.append((_("DVD media toolbox"), self.toolbox))
-               menu.append((_("Preview menu"), self.previewMenu))
-               menu.append((_("Collection settings"), self.settings))
-               menu.append(("Reset and renumerate title names", self.resetTitles))
                menu.append((_("Edit chapters of current title"), self.editTitle))
-               menu.append(("Properties of current title", self.titleProperties))
-               menu.append((_("Add a new title"), self.addTitle))
-               menu.append((_("Remove title"), self.removeCurrentTitle))
+               menu.append((_("Reset and renumerate title names"), self.resetTitles))
                menu.append((_("Exit"), self.leave))
                self.session.openWithCallback(self.menuCallback, ChoiceBox, title="", list=menu)
 
@@ -97,6 +108,11 @@ class TitleList(Screen, HelpableScreen):
                if choice:
                        choice[1]()
 
+       def showBackgroundJob(self):
+               job_manager.in_background = False
+               self.session.openWithCallback(self.JobViewCB, JobView, self.backgroundJob)
+               self.backgroundJob = None
+       
        def titleProperties(self):
                if self.getCurrentTitle():
                        self.session.openWithCallback(self.updateTitleList, TitleProperties.TitleProperties, self, self.project, self["titles"].getIndex())
@@ -172,8 +188,8 @@ class TitleList(Screen, HelpableScreen):
                self["title_label"].text = _("Table of content for collection") + " \"" + self.project.settings.name.getValue() + "\":"
 
        def loadTemplate(self):
-               filename = resolveFilename(SCOPE_PLUGINS)+"Extensions/DVDBurn/DreamboxDVDtemplate.ddvdp.xml"
-               if self.project.loadProject(filename):
+               filename = resolveFilename(SCOPE_PLUGINS)+"Extensions/DVDBurn/DreamboxDVD.ddvdp.xml"
+               if self.project.load(filename):
                        self["error_label"].hide()
                        return True
                else:
@@ -181,7 +197,13 @@ class TitleList(Screen, HelpableScreen):
                        self["error_label"].show()
                        return False
 
-       def burnProject(self):
+       def askBurnProject(self):
+               if len(self["titles"].list):
+                       self.session.openWithCallback(self.burnProject,MessageBox,text = _("Do you want to burn this collection to DVD medium?"), type = MessageBox.TYPE_YESNO)
+
+       def burnProject(self, answer=True):
+               if not answer:
+                       return
                if self.project.settings.authormode.getValue() == "data_ts":
                        job = Process.DVDdataJob(self.project)
                        job_manager.AddJob(job)
@@ -193,7 +215,7 @@ class TitleList(Screen, HelpableScreen):
                        job_manager.in_background = False
                        self.session.openWithCallback(self.JobViewCB, JobView, job)
 
-       def burnISO(self, path, scope):
+       def burnISO(self, path, scope, configRef):
                if path:
                        job = Process.DVDisoJob(self.project, path)
                        job_manager.AddJob(job)
@@ -210,30 +232,40 @@ class TitleList(Screen, HelpableScreen):
                
        def updateTitleList(self):
                res = [ ]
-               totalsize = 0
                for title in self.project.titles:
-                       a = [ title, (eListboxPythonMultiContent.TYPE_TEXT, 0, 10, 500, 50, 0, RT_HALIGN_LEFT, title.properties.menutitle.getValue())  ]
+                       a = [ title, (eListboxPythonMultiContent.TYPE_TEXT, 0, 5, 500, 25, 0, RT_HALIGN_LEFT, title.properties.menutitle.getValue())  ]
                        res.append(a)
-                       totalsize += title.estimatedDiskspace
                self["titles"].list = res
-               self.updateSize(totalsize)
-               
-       def updateSize(self, totalsize):
-               size = int((totalsize/1024)/1024)
-               max_SL = 4370
-               max_DL = 7950
-               if size > max_DL:
-                       percent = 100 * size / float(max_DL)
+               self.updateSize()
+               if len(res):
+                       self["key_red"].text = _("Remove title")
+                       self["key_yellow"].text = _("Title properties")
+               else:
+                       self["key_red"].text = ""
+                       self["key_yellow"].text = ""
+
+       def updateSize(self):
+               size = self.project.size/(1024*1024)
+               MAX_DL = self.project.MAX_DL-100
+               MAX_SL = self.project.MAX_SL-100
+               print "updateSize:", size, "MAX_DL:", MAX_DL, "MAX_SL:", MAX_SL
+               if size > MAX_DL:
+                       percent = 100 * size / float(MAX_DL)
                        self["space_label"].text = "%d MB - " % size + _("exceeds dual layer medium!") + " (%.2f%% " % (100-percent) + _("free") + ")"
                        self["space_bar"].value = int(percent)
-               elif size > max_SL:
-                       percent = 100 * size / float(max_DL)
+                       if self.previous_size < MAX_DL:
+                               self.session.open(MessageBox,text = _("exceeds dual layer medium!"), type = MessageBox.TYPE_ERROR)
+               elif size > MAX_SL:
+                       percent = 100 * size / float(MAX_DL)
                        self["space_label"].text = "%d MB  " % size + _("of a DUAL layer medium used.") + " (%.2f%% " % (100-percent) + _("free") + ")"
                        self["space_bar"].value = int(percent)
-               elif size < max_SL:
-                       percent = 100 * size / float(max_SL)
+                       if self.previous_size < MAX_SL:
+                               self.session.open(MessageBox,text = _("Your collection exceeds the size of a single layer medium, you will need a blank dual layer DVD!"), type = MessageBox.TYPE_INFO)
+               elif size < MAX_SL:
+                       percent = 100 * size / float(MAX_SL)
                        self["space_label"].text = "%d MB " % size + _("of a SINGLE layer medium used.") + " (%.2f%% " % (100-percent) + _("free") + ")"
                        self["space_bar"].value = int(percent)
+               self.previous_size = size
 
        def getCurrentTitle(self):
                t = self["titles"].getCurrent()