1 from Screen import Screen
2 from Components.Button import Button
3 from Components.ActionMap import HelpableActionMap, ActionMap
4 from Components.MenuList import MenuList
5 from Components.MovieList import MovieList
6 from Components.DiskInfo import DiskInfo
7 from Components.Pixmap import Pixmap
8 from Components.Label import Label
9 from Components.PluginComponent import plugins
10 from Components.config import config, ConfigSubsection, ConfigInteger, configfile
11 from Components.Sources.ServiceEvent import ServiceEvent
13 from Plugins.Plugin import PluginDescriptor
15 from Screens.MessageBox import MessageBox
16 from Screens.ChoiceBox import ChoiceBox
17 from Screens.HelpMenu import HelpableScreen
19 from Tools.Directories import *
20 from Tools.BoundFunction import boundFunction
22 from enigma import eServiceReference, eServiceCenter, eTimer, eSize
24 config.movielist = ConfigSubsection()
25 config.movielist.moviesort = ConfigInteger(default=MovieList.SORT_RECORDED)
26 config.movielist.listtype = ConfigInteger(default=MovieList.LISTTYPE_COMPACT_DESCRIPTION)
27 config.movielist.description = ConfigInteger(default=MovieList.HIDE_DESCRIPTION)
29 class MovieContextMenu(Screen):
30 def __init__(self, session, csel, service):
31 Screen.__init__(self, session)
33 self.service = service
35 self["actions"] = ActionMap(["OkCancelActions"],
37 "ok": self.okbuttonClick,
38 "cancel": self.cancelClick
41 menu = [(_("delete..."), self.delete)]
43 for p in plugins.getPlugins(PluginDescriptor.WHERE_MOVIELIST):
44 menu.append((p.description, boundFunction(self.execPlugin, p)))
46 if config.movielist.moviesort.value == MovieList.SORT_ALPHANUMERIC:
47 menu.append((_("sort by date"), boundFunction(self.sortBy, MovieList.SORT_RECORDED)))
49 menu.append((_("alphabetic sort"), boundFunction(self.sortBy, MovieList.SORT_ALPHANUMERIC)))
51 menu.append((_("list style default"), boundFunction(self.listType, MovieList.LISTTYPE_ORIGINAL)))
52 menu.append((_("list style compact with description"), boundFunction(self.listType, MovieList.LISTTYPE_COMPACT_DESCRIPTION)))
53 menu.append((_("list style compact"), boundFunction(self.listType, MovieList.LISTTYPE_COMPACT)))
54 menu.append((_("list style single line"), boundFunction(self.listType, MovieList.LISTTYPE_MINIMAL)))
56 if config.movielist.description.value == MovieList.SHOW_DESCRIPTION:
57 menu.append((_("hide extended description"), boundFunction(self.showDescription, MovieList.HIDE_DESCRIPTION)))
59 menu.append((_("show extended description"), boundFunction(self.showDescription, MovieList.SHOW_DESCRIPTION)))
60 self["menu"] = MenuList(menu)
62 def okbuttonClick(self):
63 self["menu"].getCurrent()[1]()
65 def cancelClick(self):
68 def sortBy(self, newType):
69 self.csel.saveflag = True
70 config.movielist.moviesort.value = newType
71 self.csel.selectedmovie = self.csel.getCurrent()
72 self.csel.setSortType(newType)
73 self.csel.reloadList()
77 def listType(self, newType):
78 self.csel.saveflag = True
79 config.movielist.listtype.value = newType
80 self.csel.setListType(newType)
81 self.csel.list.redrawList()
84 def showDescription(self, newType):
85 self.csel.saveflag = True
86 config.movielist.description.value = newType
87 self.csel.setDescriptionState(newType)
88 self.csel.updateDescription()
91 def execPlugin(self, plugin):
92 plugin(session=self.session, service=self.service)
95 serviceHandler = eServiceCenter.getInstance()
96 offline = serviceHandler.offlineOperations(self.service)
97 info = serviceHandler.info(self.service)
98 name = info and info.getName(self.service) or _("this recording")
100 if offline is not None:
102 if not offline.deleteFromDisk(1):
105 self.session.openWithCallback(self.deleteConfirmed, MessageBox, _("Do you really want to delete %s?") % (name))
107 self.session.openWithCallback(self.close, MessageBox, _("You cannot delete this!"), MessageBox.TYPE_ERROR)
109 def deleteConfirmed(self, confirmed):
113 serviceHandler = eServiceCenter.getInstance()
114 offline = serviceHandler.offlineOperations(self.service)
116 if offline is not None:
118 if not offline.deleteFromDisk(0):
122 self.session.openWithCallback(self.close, MessageBox, _("Delete failed!"), MessageBox.TYPE_ERROR)
124 list = self.csel["list"].removeService(self.service)
127 class SelectionEventInfo:
129 self["Service"] = ServiceEvent()
130 self.list.connectSelChanged(self.__selectionChanged)
131 self.timer = eTimer()
132 self.timer.timeout.get().append(self.updateEventInfo)
133 self.onShown.append(self.__selectionChanged)
135 def __selectionChanged(self):
136 if self.execing and config.movielist.description.value == MovieList.SHOW_DESCRIPTION:
137 self.timer.start(100, True)
139 def updateEventInfo(self):
140 serviceref = self.getCurrent()
141 self["Service"].newService(serviceref)
143 class MovieSelection(Screen, HelpableScreen, SelectionEventInfo):
144 def __init__(self, session, selectedmovie = None):
145 Screen.__init__(self, session)
146 HelpableScreen.__init__(self)
148 self.saveflag = False
151 self.selected_tags = None
153 self.current_ref = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + resolveFilename(SCOPE_HDD))
155 self.movemode = False
156 self.bouquet_mark_edit = False
158 self.delayTimer = eTimer()
159 self.delayTimer.timeout.get().append(self.updateHDDData)
161 self["waitingtext"] = Label(_("Please wait... Loading list..."))
163 # create optional description border and hide immediately
164 self["DescriptionBorder"] = Pixmap()
165 self["DescriptionBorder"].hide()
167 self["list"] = MovieList(None,
168 config.movielist.listtype.value,
169 config.movielist.moviesort.value,
170 config.movielist.description.value)
172 self.list = self["list"]
173 self.selectedmovie = selectedmovie
176 SelectionEventInfo.__init__(self)
178 self["key_red"] = Button(_("All..."))
179 self["key_green"] = Button("")
180 self["key_yellow"] = Button("")
181 self["key_blue"] = Button("")
183 #self["freeDiskSpace"] = DiskInfo(resolveFilename(SCOPE_HDD), DiskInfo.FREE, update=False)
184 self["freeDiskSpace"] = self.diskinfo = DiskInfo(resolveFilename(SCOPE_HDD), DiskInfo.FREE, update=False)
186 self["MovieSelectionActions"] = HelpableActionMap(self, "MovieSelectionActions",
188 "contextMenu": (self.doContext, _("menu")),
189 "showEventInfo": (self.showEventInformation, _("show event details")),
192 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
194 "red": (self.showAll, _("show all")),
195 "green": (self.showTagsFirst, _("show first tag")),
196 "yellow": (self.showTagsSecond, _("show second tag")),
197 "blue": (self.showTagsMenu, _("show tag menu")),
200 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
202 "cancel": (self.abort, _("exit movielist")),
203 "ok": (self.movieSelected, _("select movie")),
206 self.onShown.append(self.go)
209 def updateDescription(self):
210 if config.movielist.description.value == MovieList.SHOW_DESCRIPTION:
211 self["DescriptionBorder"].show()
212 self["list"].instance.resize(eSize(self.listWidth, self.listHeight-self["DescriptionBorder"].instance.size().height()))
214 self["Service"].newService(None)
215 self["DescriptionBorder"].hide()
216 self["list"].instance.resize(eSize(self.listWidth, self.listHeight))
218 def showEventInformation(self):
219 from Screens.EventView import EventViewSimple
220 from ServiceReference import ServiceReference
221 evt = self["list"].getCurrentEvent()
223 self.session.open(EventViewSimple, evt, ServiceReference(self.getCurrent()))
227 # ouch. this should redraw our "Please wait..."-text.
228 # this is of course not the right way to do this.
229 self.delayTimer.start(10, 1)
231 # as this workaround is here anyways we can wait until the skin is initialized
232 # and afterwards read out the information we need to draw the dynamic style
233 listsize = self["list"].instance.size()
234 self.listWidth = listsize.width()
235 self.listHeight = listsize.height()
236 self.updateDescription()
238 def updateHDDData(self):
240 if self.selectedmovie is not None:
242 self["waitingtext"].visible = False
243 self["freeDiskSpace"].update()
247 self["list"].moveTo(self.selectedmovie)
249 def getCurrent(self):
250 return self["list"].getCurrent()
252 def movieSelected(self):
253 current = self.getCurrent()
254 if current is not None:
259 current = self.getCurrent()
260 if current is not None:
261 self.session.open(MovieContextMenu, self, current)
267 def saveconfig(self):
268 if self.saveflag == True:
269 config.movielist.moviesort.save()
270 config.movielist.listtype.save()
271 config.movielist.description.save()
273 self.saveflag = False
275 def getTagDescription(self, tag):
276 # TODO: access the tag database
279 def updateTags(self):
280 # get a list of tags available in this list
281 self.tags = list(self["list"].tags)
283 # by default, we do not display any filtering options
287 # when tags are present, however, the first two are
288 # directly mapped to the second, third ("green", "yellow") buttons
289 if len(self.tags) > 0:
290 self.tag_first = self.getTagDescription(self.tags[0])
292 if len(self.tags) > 1:
293 self.tag_second = self.getTagDescription(self.tags[1])
295 self["key_green"].text = self.tag_first
296 self["key_yellow"].text = self.tag_second
298 # the rest is presented in a list, available on the
299 # fourth ("blue") button
300 if len(self.tags) > 2:
301 self["key_blue"].text = _("Other...")
303 self["key_blue"].text = ""
305 def setListType(self, type):
306 self["list"].setListType(type)
308 def setDescriptionState(self, val):
309 self["list"].setDescriptionState(val)
311 def setSortType(self, type):
312 self["list"].setSortType(type)
314 def reloadList(self):
315 self["list"].reload(self.current_ref, self.selected_tags)
316 title = _("Recorded files...")
317 if self.selected_tags is not None:
318 title += " - " + ','.join(self.selected_tags)
322 self.selected_tags = None
325 def showTagsN(self, n):
326 if len(self.tags) < n:
327 self.showTagWarning()
329 print "select tag #%d, %s, %s" % (n, self.tags[n - 1], ','.join(self.tags))
330 self.selected_tags = set([self.tags[n - 1]])
333 def showTagsFirst(self):
336 def showTagsSecond(self):
339 def tagChosen(self, tag):
341 self.selected_tags = set([tag[0]])
344 def showTagsMenu(self):
345 if len(self.tags) < 3:
346 self.showTagWarning()
348 list = [(tag, self.getTagDescription(tag)) for tag in self.tags ]
349 self.session.openWithCallback(self.tagChosen, ChoiceBox, title=_("Please select keyword to filter..."), list = list)
351 def showTagWarning(self):
353 self.session.open(MessageBox, _("You need to define some keywords first!\nPress the menu-key to define keywords.\nDo you want to define keywords now?"), MessageBox.TYPE_ERROR)