1 from Screen import Screen
2 from Components.Button import Button
3 from Components.ServiceList import ServiceList
4 from Components.ActionMap import ActionMap
5 from Components.MovieList import MovieList
6 from Components.DiskInfo import DiskInfo
7 from Components.Label import Label
8 from Components.PluginComponent import plugins
9 from Plugins.Plugin import PluginDescriptor
11 from Screens.MessageBox import MessageBox
12 from Screens.FixedMenu import FixedMenu
13 from Screens.ChoiceBox import ChoiceBox
15 from Tools.Directories import *
16 from Tools.BoundFunction import boundFunction
18 from enigma import eServiceReference, eServiceCenter, eTimer
20 class ChannelContextMenu(FixedMenu):
21 def __init__(self, session, csel, service):
23 self.service = service
25 menu = [(_("back"), self.close), (_("delete..."), self.delete)]
27 for p in plugins.getPlugins(PluginDescriptor.WHERE_MOVIELIST):
28 menu.append((p.description, boundFunction(self.execPlugin, p)))
30 FixedMenu.__init__(self, session, _("Movie Menu"), menu)
31 self.skinName = "Menu"
33 def execPlugin(self, plugin):
34 plugin(session=self.session, service=self.service)
37 serviceHandler = eServiceCenter.getInstance()
38 offline = serviceHandler.offlineOperations(self.service)
39 info = serviceHandler.info(self.service)
40 name = info and info.getName(self.service) or _("this recording")
42 if offline is not None:
44 if not offline.deleteFromDisk(1):
48 self.session.openWithCallback(self.deleteConfirmed, MessageBox, _("Do you really want to delete %s?") % (name))
50 self.session.openWithCallback(self.close, MessageBox, _("You cannot delete this!"), MessageBox.TYPE_ERROR)
52 def deleteConfirmed(self, confirmed):
56 serviceHandler = eServiceCenter.getInstance()
57 offline = serviceHandler.offlineOperations(self.service)
59 if offline is not None:
61 if not offline.deleteFromDisk(0):
65 self.session.openWithCallback(self.close, MessageBox, _("Delete failed!"), MessageBox.TYPE_ERROR)
67 list = self.csel["list"].removeService(self.service)
70 class MovieSelection(Screen):
71 def __init__(self, session, selectedmovie = None):
72 Screen.__init__(self, session)
75 self.selected_tags = None
77 self.current_ref = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + resolveFilename(SCOPE_HDD))
80 self.bouquet_mark_edit = False
82 self.delayTimer = eTimer()
83 self.delayTimer.timeout.get().append(self.updateHDDData)
85 self["waitingtext"] = Label(_("Please wait... Loading list..."))
87 self["list"] = MovieList(None)
88 self.list = self["list"]
89 self.selectedmovie = selectedmovie
91 self["key_red"] = Button(_("All..."))
92 self["key_green"] = Button("")
93 self["key_yellow"] = Button("")
94 self["key_blue"] = Button("")
96 #self["okbutton"] = Button("ok", [self.channelSelected])
97 self["freeDiskSpace"] = DiskInfo(resolveFilename(SCOPE_HDD), DiskInfo.FREE, update=False)
99 self["actions"] = ActionMap(["OkCancelActions", "MovieSelectionActions", "ColorActions"],
101 "cancel": self.abort,
102 "ok": self.movieSelected,
103 "showEventInfo": self.showEventInformation,
104 "contextMenu": self.doContext,
107 "green": self.showTagsFirst,
108 "yellow": self.showTagsSecond,
109 "blue": self.showTagsMenu,
111 self["actions"].csel = self
112 self.onShown.append(self.go)
114 self.lengthTimer = eTimer()
115 self.lengthTimer.timeout.get().append(self.updateLengthData)
118 def showEventInformation(self):
119 from Screens.EventView import EventViewSimple
120 from ServiceReference import ServiceReference
121 evt = self["list"].getCurrentEvent()
123 self.session.open(EventViewSimple, evt, ServiceReference(self.getCurrent()))
127 # ouch. this should redraw our "Please wait..."-text.
128 # this is of course not the right way to do this.
129 self.delayTimer.start(10, 1)
132 def updateHDDData(self):
134 if self.selectedmovie is not None:
136 self["waitingtext"].instance.hide()
138 self["freeDiskSpace"].update()
142 def updateLengthData(self):
143 self.list.updateLengthOfIndex(self.lengthPosition)
144 self.lengthPosition += 1
145 if self.lengthPosition < self.lengthLength:
146 self.lengthTimer.start(10, 1)
149 self["list"].moveTo(self.selectedmovie)
151 def getCurrent(self):
152 return self["list"].getCurrent()
154 def movieSelected(self):
155 self.lengthTimer.stop()
156 current = self.getCurrent()
157 if current is not None:
161 current = self.getCurrent()
162 if current is not None:
163 self.session.open(ChannelContextMenu, self, current)
168 def getTagDescription(self, tag):
169 # TODO: access the tag database
172 def updateTags(self):
173 # get a list of tags available in this list
174 self.tags = list(self["list"].tags)
176 # by default, we do not display any filtering options
180 # when tags are present, however, the first two are
181 # directly mapped to the second, third ("green", "yellow") buttons
182 if len(self.tags) > 0:
183 self.tag_first = self.getTagDescription(self.tags[0])
185 if len(self.tags) > 1:
186 self.tag_second = self.getTagDescription(self.tags[1])
188 self["key_green"].text = self.tag_first
189 self["key_yellow"].text = self.tag_second
191 # the rest is presented in a list, available on the
192 # fourth ("blue") button
193 if len(self.tags) > 2:
194 self["key_blue"].text = _("Other...")
196 self["key_blue"].text = ""
198 def reloadList(self):
199 self["list"].reload(self.current_ref, self.selected_tags)
200 self.lengthTimer.start(10, 1)
201 self.lengthPosition = 0
202 self.lengthLength = len(self["list"])
204 title = _("Recorded files...")
206 if self.selected_tags is not None:
207 title += " - " + ','.join(self.selected_tags)
212 self.selected_tags = None
215 def showTagsN(self, n):
216 if len(self.tags) < n:
217 self.showTagWarning()
219 print "select tag #%d, %s, %s" % (n, self.tags[n - 1], ','.join(self.tags))
220 self.selected_tags = set([self.tags[n - 1]])
223 def showTagsFirst(self):
226 def showTagsSecond(self):
229 def tagChosen(self, tag):
231 self.selected_tags = set([tag[0]])
234 def showTagsMenu(self):
235 if len(self.tags) < 3:
236 self.showTagWarning()
238 list = [(tag, self.getTagDescription(tag)) for tag in self.tags ]
239 self.session.openWithCallback(self.tagChosen, ChoiceBox, title=_("Please select keyword to filter..."), list = list)
241 def showTagWarning(self):
243 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)