set permissions to 644 for data files
[enigma2.git] / lib / python / Plugins / Extensions / DVDBurn / TitleProperties.py
1 from Screens.Screen import Screen
2 from Screens.ChoiceBox import ChoiceBox
3 from Screens.InputBox import InputBox
4 from Screens.MessageBox import MessageBox
5 from Screens.HelpMenu import HelpableScreen
6 from Components.ActionMap import HelpableActionMap, ActionMap
7 from Components.Sources.List import List
8 from Components.Sources.StaticText import StaticText
9 from Components.Sources.Progress import Progress
10 from Components.FileList import FileList
11 from Components.Pixmap import Pixmap
12 from enigma import eListboxPythonMultiContent, gFont, RT_HALIGN_LEFT, ePicLoad
13 from Tools.Directories import fileExists, resolveFilename, SCOPE_PLUGINS, SCOPE_FONTS, SCOPE_HDD
14 from Components.config import config, getConfigListEntry, ConfigInteger, ConfigSubsection, ConfigSelection
15 from Components.ConfigList import ConfigListScreen
16 from Components.AVSwitch import AVSwitch
17 import DVDTitle
18
19 class TitleProperties(Screen,ConfigListScreen):
20         skin = """
21                 <screen position="90,83" size="560,445" title="Properties of current title" >
22                     <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
23                     <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
24                     <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
25                     <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
26                     <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
27                     <widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" transparent="1" />
28                     <widget source="serviceinfo" render="Label" position="10,46" size="350,144" font="Regular;18" />
29                     <widget name="thumbnail" position="370,46" size="180,144" alphatest="on" />
30                     <widget name="config" position="10,206" size="540,228" scrollbarMode="showOnDemand" />
31                 </screen>"""
32
33         def __init__(self, session, parent, project, title_idx):
34                 Screen.__init__(self, session)
35                 self.parent = parent
36                 self.project = project
37                 self.title_idx = title_idx
38
39                 self["key_red"] = StaticText(_("Cancel"))
40                 self["key_green"] = StaticText(_("OK"))
41                 self["key_blue"] = StaticText(_("Edit Title"))
42                 self["serviceinfo"] = StaticText()
43
44                 self["thumbnail"] = Pixmap()
45                 self.picload = ePicLoad()
46                 self.picload.PictureData.get().append(self.paintThumbPixmapCB)
47
48                 self.properties = project.titles[title_idx].properties
49                 ConfigListScreen.__init__(self, [])
50                 self.properties.crop = DVDTitle.ConfigFixedText("crop")
51                 self.properties.autochapter.addNotifier(self.initConfigList)
52                 self.properties.aspect.addNotifier(self.initConfigList)
53                 for audiotrack in self.properties.audiotracks:
54                         audiotrack.active.addNotifier(self.initConfigList)
55
56                 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
57                 {
58                     "green": self.exit,
59                     "red": self.cancel,
60                     "blue": self.editTitle,
61                     "cancel": self.cancel,
62                     "ok": self.ok,
63                 }, -2)
64                 
65                 self.onShown.append(self.update)
66
67         def initConfigList(self, element=None):
68                 try:
69                         self.properties.position = ConfigInteger(default = self.title_idx+1, limits = (1, len(self.project.titles)))
70                         title = self.project.titles[self.title_idx]
71                         self.list = []
72                         self.list.append(getConfigListEntry("DVD " + _("Track"), self.properties.position))
73                         self.list.append(getConfigListEntry("DVD " + _("Title"), self.properties.menutitle))
74                         self.list.append(getConfigListEntry("DVD " + _("Description"), self.properties.menusubtitle))
75                         if config.usage.setup_level.index >= 2: # expert+
76                                 for audiotrack in self.properties.audiotracks:
77                                         DVB_aud = audiotrack.DVB_lang.getValue() or audiotrack.pid.getValue()
78                                         self.list.append(getConfigListEntry(_("burn audio track (%s)") % DVB_aud, audiotrack.active))
79                                         if audiotrack.active.getValue():
80                                                 self.list.append(getConfigListEntry(_("audio track (%s) format") % DVB_aud, audiotrack.format))
81                                                 self.list.append(getConfigListEntry(_("audio track (%s) language") % DVB_aud, audiotrack.language))
82                                                 
83                                 self.list.append(getConfigListEntry("DVD " + _("Aspect Ratio"), self.properties.aspect))
84                                 if self.properties.aspect.getValue() == "16:9":
85                                         self.list.append(getConfigListEntry("DVD " + "widescreen", self.properties.widescreen))
86                                 else:
87                                         self.list.append(getConfigListEntry("DVD " + "widescreen", self.properties.crop))
88                         if len(title.chaptermarks) == 0:
89                                 self.list.append(getConfigListEntry(_("Auto chapter split every ? minutes (0=never)"), self.properties.autochapter))
90                         infotext = "DVB " + _("Title") + ': ' + title.DVBname + "\n" + _("Description") + ': ' + title.DVBdescr + "\n" + _("Channel") + ': ' + title.DVBchannel + '\n' + _("Begin time") + title.formatDVDmenuText(": $D.$M.$Y, $T\n", self.title_idx+1)
91                         chaptermarks = title.getChapterMarks(template="$h:$m:$s")
92                         chapters_count = len(chaptermarks)
93                         if chapters_count >= 1:
94                                 infotext += str(chapters_count+1) + ' ' + _("chapters") + ': '
95                                 infotext += ' / '.join(chaptermarks)
96                         self["serviceinfo"].setText(infotext)
97                         self["config"].setList(self.list)
98                 except AttributeError:
99                         pass
100
101         def editTitle(self):
102                 self.parent.editTitle()
103
104         def update(self):
105                 print "[onShown]"
106                 self.initConfigList()
107                 self.loadThumb()
108
109         def loadThumb(self):
110                 thumbfile = self.project.titles[self.title_idx].inputfile.rsplit('.',1)[0] + ".png"
111                 sc = AVSwitch().getFramebufferScale()
112                 self.picload.setPara((self["thumbnail"].instance.size().width(), self["thumbnail"].instance.size().height(), sc[0], sc[1], False, 1, "#00000000"))
113                 self.picload.startDecode(thumbfile)
114
115         def paintThumbPixmapCB(self, picInfo=None):
116                 ptr = self.picload.getData()
117                 if ptr != None:
118                         self["thumbnail"].instance.setPixmap(ptr.__deref__())
119
120         def changedConfigList(self):
121                 self.initConfigList()
122
123         def exit(self):
124                 self.applySettings()
125                 self.close()
126
127         def applySettings(self):
128                 for x in self["config"].list:
129                         x[1].save()
130                 current_pos = self.title_idx+1
131                 new_pos = self.properties.position.getValue()
132                 if new_pos != current_pos:
133                         print "title got repositioned from ", current_pos, "to", new_pos
134                         swaptitle = self.project.titles.pop(current_pos-1)
135                         self.project.titles.insert(new_pos-1, swaptitle)
136
137         def ok(self):
138                 #key = self.keydict[self["config"].getCurrent()[1]]
139                 #if key in self.project.filekeys:
140                         #self.session.openWithCallback(self.FileBrowserClosed, FileBrowser, key, self.settings)
141                 pass
142
143         def cancel(self):
144                 self.close()
145
146 from Tools.ISO639 import LanguageCodes
147 class LanguageChoices():
148         def __init__(self):
149                 from Components.Language import language as syslanguage
150                 syslang = syslanguage.getLanguage()[:2]
151                 self.langdict = { }
152                 self.choices = []
153                 for key, val in LanguageCodes.iteritems():
154                         if len(key) == 2:
155                                 self.langdict[key] = val[0]
156                 for key, val in self.langdict.iteritems():
157                         if key not in (syslang, 'en'):
158                                 self.langdict[key] = val
159                                 self.choices.append((key, val))
160                 self.choices.sort()
161                 self.choices.insert(0,("nolang", ("unspecified")))
162                 self.choices.insert(1,(syslang, self.langdict[syslang]))
163                 self.choices.insert(2,("en", self.langdict["en"]))
164
165         def getLanguage(self, DVB_lang):
166                 DVB_lang = DVB_lang.lower()
167                 for word in ("stereo", "audio", "description", "2ch", "dolby digital"):
168                         DVB_lang = DVB_lang.replace(word,"").strip()
169                 for key, val in LanguageCodes.iteritems():
170                         if DVB_lang.find(key.lower()) == 0:
171                                 if len(key) == 2:
172                                         return key
173                                 else:
174                                         DVB_lang = (LanguageCodes[key])[0]
175                         elif DVB_lang.find(val[0].lower()) > -1:
176                                 if len(key) == 2:
177                                         return key
178                                 else:
179                                         DVB_lang = (LanguageCodes[key])[0]
180                 for key, val in self.langdict.iteritems():
181                         if val == DVB_lang:
182                                 return key
183                 return "nolang"
184
185 languageChoices = LanguageChoices()