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)
115 def showEventInformation(self):
116 from Screens.EventView import EventViewSimple
117 from ServiceReference import ServiceReference
118 evt = self["list"].getCurrentEvent()
120 self.session.open(EventViewSimple, evt, ServiceReference(self.getCurrent()))
124 # ouch. this should redraw our "Please wait..."-text.
125 # this is of course not the right way to do this.
126 self.delayTimer.start(10, 1)
129 def updateHDDData(self):
131 if self.selectedmovie is not None:
133 self["waitingtext"].instance.hide()
135 self["freeDiskSpace"].update()
140 self["list"].moveTo(self.selectedmovie)
142 def getCurrent(self):
143 return self["list"].getCurrent()
145 def movieSelected(self):
146 current = self.getCurrent()
147 if current is not None:
151 current = self.getCurrent()
152 if current is not None:
153 self.session.open(ChannelContextMenu, self, current)
158 def getTagDescription(self, tag):
159 # TODO: access the tag database
162 def updateTags(self):
163 # get a list of tags available in this list
164 self.tags = list(self["list"].tags)
166 # by default, we do not display any filtering options
170 # when tags are present, however, the first two are
171 # directly mapped to the second, third ("green", "yellow") buttons
172 if len(self.tags) > 0:
173 self.tag_first = self.getTagDescription(self.tags[0])
175 if len(self.tags) > 1:
176 self.tag_second = self.getTagDescription(self.tags[1])
178 self["key_green"].text = self.tag_first
179 self["key_yellow"].text = self.tag_second
181 # the rest is presented in a list, available on the
182 # fourth ("blue") button
183 if len(self.tags) > 2:
184 self["key_blue"].text = _("Other...")
186 self["key_blue"].text = ""
188 def reloadList(self):
189 self["list"].reload(self.current_ref, self.selected_tags)
190 title = _("Recorded files...")
191 if self.selected_tags is not None:
192 title += " - " + ','.join(self.selected_tags)
196 self.selected_tags = None
199 def showTagsN(self, n):
200 if len(self.tags) < n:
201 self.showTagWarning()
203 print "select tag #%d, %s, %s" % (n, self.tags[n - 1], ','.join(self.tags))
204 self.selected_tags = set([self.tags[n - 1]])
207 def showTagsFirst(self):
210 def showTagsSecond(self):
213 def tagChosen(self, tag):
215 self.selected_tags = set([tag[0]])
218 def showTagsMenu(self):
219 if len(self.tags) < 3:
220 self.showTagWarning()
222 list = [(tag, self.getTagDescription(tag)) for tag in self.tags ]
223 self.session.openWithCallback(self.tagChosen, ChoiceBox, title=_("Please select keyword to filter..."), list = list)
225 def showTagWarning(self):
227 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)