7407263d0b5d04a8029b43d0e196ede488a9558f
[enigma2.git] / lib / python / Plugins / Extensions / DVDBurn / ProjectSettings.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 enigma import eListboxPythonMultiContent, gFont, RT_HALIGN_LEFT
12 from Tools.Directories import fileExists, resolveFilename, SCOPE_PLUGINS, SCOPE_FONTS, SCOPE_HDD
13 from Components.config import config, getConfigListEntry
14 from Components.ConfigList import ConfigListScreen
15
16 class FileBrowser(Screen, HelpableScreen):
17         skin = """
18         <screen name="FileBrowser" position="100,100" size="520,376" title="DVD File Browser" >
19                 <widget name="filelist" position="0,0" size="520,376" scrollbarMode="showOnDemand" />
20         </screen>"""
21         def __init__(self, session, scope, settings):
22                 Screen.__init__(self, session)
23                 HelpableScreen.__init__(self)
24                 self.scope = scope
25                 pattern = ""
26                 currDir = "/"
27                 if self.scope == "project":
28                         currDir = self.getDir()
29                         pattern = "(?i)^.*\.(ddvdp\.xml)"
30                 elif self.scope == "menutemplate":
31                         currDir = self.getDir()
32                         pattern = "(?i)^.*\.(ddvdm\.xml)"
33                 if self.scope == "menubg":
34                         currDir = self.getDir(settings.menubg)
35                         pattern = "(?i)^.*\.(jpeg|jpg|jpe|png|bmp)"
36                 elif self.scope == "menuaudio":
37                         currDir = self.getDir(settings.menuaudio)
38                         pattern = "(?i)^.*\.(mp2|m2a|ac3)"
39                 elif self.scope == "vmgm":
40                         currDir = self.getDir(settings.vmgm)
41                         pattern = "(?i)^.*\.(mpg|mpeg)"
42                 elif self.scope == "font_face":
43                         currDir = self.getDir(settings.font_face, resolveFilename(SCOPE_FONTS))
44                         pattern = "(?i)^.*\.(ttf)"
45                 elif self.scope == "isopath":
46                         currDir = settings.isopath.getValue()
47                 elif self.scope == "image":
48                         currDir = resolveFilename(SCOPE_HDD)
49                         pattern = "(?i)^.*\.(iso)"
50
51                 self.filelist = FileList(currDir, matchingPattern=pattern)
52                 self["filelist"] = self.filelist
53
54                 self["FilelistActions"] = ActionMap(["OkCancelActions"],
55                         {
56                                 "ok": self.ok,
57                                 "cancel": self.exit
58                         })
59
60         def getDir(self, key=None, defaultDir=None):
61                 if key:
62                         settingDir = key.getValue()
63                         if len(settingDir) > 1:
64                                 return (settingDir.rstrip("/").rsplit("/",1))[0]
65                 return defaultDir or (resolveFilename(SCOPE_PLUGINS)+"Extensions/DVDBurn/")
66
67         def ok(self):
68                 if self.filelist.canDescent():
69                         self.filelist.descent()
70                         if self.scope == "image":
71                                 path = self["filelist"].getCurrentDirectory() or ""
72                                 if fileExists(path+"VIDEO_TS"):
73                                         self.close(path,self.scope)
74                 else:
75                         ret = self["filelist"].getCurrentDirectory() + '/' + self["filelist"].getFilename()
76                         self.close(ret,self.scope)
77
78         def exit(self):
79                 if self.scope == "isopath":
80                         self.close(self["filelist"].getCurrentDirectory(),self.scope)
81                 self.close(None,False)
82
83 class ProjectSettings(Screen,ConfigListScreen):
84         skin = """
85                 <screen position="90,83" size="560,445" title="Collection settings" >
86                     <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
87                     <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
88                     <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
89                     <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
90                     <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" />
91                     <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" />
92                     <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
93                     <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" />
94                     <widget name="config" position="10,50" size="540,276" scrollbarMode="showOnDemand" />
95                     <widget source="info" render="Label" position="20,350" size="520,90" font="Regular;16" />
96                 </screen>"""
97
98         def __init__(self, session, project = None):
99                 Screen.__init__(self, session)
100                 self.project = project
101                 
102                 self["key_red"] = StaticText(_("Cancel"))
103                 self["key_green"] = StaticText(_("OK"))
104                 self["key_yellow"] = StaticText(_("Load"))
105                 self["key_blue"] = StaticText(_("Save"))
106                 
107                 infotext = _("Available format variables") + ":\n$i=" + _("Track") + ", $t=" + _("Title") + ", $d=" + _("Description") + ", $l=" + _("length") + ", $c=" + _("chapters") + ",\n" + _("Record") + " $T=" + _("Begin time") + ", $Y=" + _("Year") + ", $M=" + _("month") + ", $D=" + _("day") + ",\n$A=" + _("audio tracks") + ", $C=" + _("Channel") + ", $f=" + _("filename")
108                 self["info"] = StaticText(infotext)
109
110                 self.settings = project.settings
111                 ConfigListScreen.__init__(self, [])
112                 self.initConfigList()
113                         
114                 self.keydict = {}
115                 for key, val in self.settings.dict().iteritems():
116                         self.keydict[val] = key
117                 
118                 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
119                 {
120                     "green": self.exit,
121                     "red": self.cancel,
122                     "blue": self.saveProject,
123                     "yellow": self.loadProject,
124                     "cancel": self.cancel,
125                     "ok": self.ok,
126                 }, -2)
127
128         def changedConfigList(self):
129                 key = self.keydict[self["config"].getCurrent()[1]]
130                 if key == "authormode" or key == "output":
131                         self.initConfigList()
132
133         def initConfigList(self):
134                 authormode = self.settings.authormode.getValue()
135                 output = self.settings.output.getValue()
136                 self.list = []
137                 self.list.append(getConfigListEntry(_("Collection name"), self.settings.name))
138                 self.list.append(getConfigListEntry(_("Authoring mode"), self.settings.authormode))
139                 self.list.append(getConfigListEntry(("Output"), self.settings.output))
140                 if output == "iso":
141                         self.list.append(getConfigListEntry(_("ISO path"), self.settings.isopath))
142                 if authormode.startswith("menu"):
143                         self.list.append(getConfigListEntry(_("Menu")+' '+_("template file"), self.settings.menutemplate))
144                         self.list.append(getConfigListEntry(_("Menu")+' '+_("Title"), self.project.menutemplate.settings.titleformat))
145                         self.list.append(getConfigListEntry(_("Menu")+' '+_("Subtitles"), self.project.menutemplate.settings.subtitleformat))
146                         self.list.append(getConfigListEntry(_("Menu")+' '+_("background image"), self.project.menutemplate.settings.menubg))
147                         #self.list.append(getConfigListEntry(_("Menu")+' '+_("headline")+' '+_("color"), self.settings.color_headline))
148                         #self.list.append(getConfigListEntry(_("Menu")+' '+_("text")+' '+_("color"), self.settings.color_button))
149                         #self.list.append(getConfigListEntry(_("Menu")+' '+_("highlighted button")+' '+_("color"), self.settings.color_highlight))
150                         #self.list.append(getConfigListEntry(_("Menu")+' '+_("font face"), self.settings.font_face))
151                         #self.list.append(getConfigListEntry(_("Font size")+' ('+_("headline")+', '+_("Title")+', '+_("Subtitles")+')', self.settings.font_size))
152                         #self.list.append(getConfigListEntry(_("Menu")+' '+_("spaces (top, between rows, left)"), self.settings.space))
153                         #self.list.append(getConfigListEntry(_("Menu")+' '+_("Audio"), self.settings.menuaudio))
154                 if authormode != "data_ts":
155                         self.list.append(getConfigListEntry(_("Titleset mode"), self.settings.titlesetmode))
156                         if self.settings.titlesetmode.getValue() == "single" or authormode == "just_linked":
157                                 self.list.append(getConfigListEntry(_("VMGM (intro trailer)"), self.settings.vmgm))
158                 else:
159                         self.list.append(getConfigListEntry(("DVD data format"), self.settings.dataformat))
160                 
161                 self["config"].setList(self.list)
162
163         def keyLeft(self):
164                 ConfigListScreen.keyLeft(self)
165                 key = self.keydict[self["config"].getCurrent()[1]]
166                 if key == "authormode" or key == "output" or key=="titlesetmode":
167                         self.initConfigList()
168
169         def keyRight(self):
170                 ConfigListScreen.keyRight(self)
171                 key = self.keydict[self["config"].getCurrent()[1]]
172                 if key == "authormode" or key == "output" or key=="titlesetmode":
173                         self.initConfigList()
174
175         def exit(self):
176                 self.applySettings()
177                 self.close(True)
178
179         def applySettings(self):
180                 for x in self["config"].list:
181                         x[1].save()
182                 
183         def ok(self):
184                 key = self.keydict[self["config"].getCurrent()[1]]
185                 if key in self.project.filekeys:
186                         self.session.openWithCallback(self.FileBrowserClosed, FileBrowser, key, self.settings)
187
188         def cancel(self):
189                 self.close(False)
190
191         def loadProject(self):
192                 self.session.openWithCallback(self.FileBrowserClosed, FileBrowser, "project", self.settings)
193
194         def saveProject(self):
195                 self.applySettings()
196                 ret = self.project.saveProject(resolveFilename(SCOPE_PLUGINS)+"Extensions/DVDBurn/")
197                 if ret.startswith:
198                         text = _("Save")+' '+_('OK')+':\n'+ret
199                         self.session.open(MessageBox,text,type = MessageBox.TYPE_INFO)
200                 else:
201                         text = _("Save")+' '+_('Error')
202                         self.session.open(MessageBox,text,type = MessageBox.TYPE_ERROR)
203
204         def FileBrowserClosed(self, path, scope):
205                 if scope == "menutemplate":
206                         if not self.project.menutemplate.loadTemplate(path):
207                                 self.session.open(MessageBox,self.project.error,MessageBox.TYPE_ERROR)
208                         else:
209                                 print "[ProjectSettings] menu template loaded"
210
211                 if scope in self.project.filekeys:
212                         self.settings.dict()[scope].setValue(path)
213                 elif scope == "project":
214                         if not self.project.loadProject(path):
215                                 self.session.open(MessageBox,self.project.error,MessageBox.TYPE_ERROR)
216                         else:
217                                 self.initConfigList()