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
14 from Tools.Directories import *
15 from Tools.BoundFunction import boundFunction
17 from enigma import eServiceReference, eServiceCenter, eTimer
19 class ChannelContextMenu(FixedMenu):
20 def __init__(self, session, csel, service):
22 self.service = service
24 menu = [(_("back"), self.close), (_("delete..."), self.delete)]
26 for p in plugins.getPlugins(PluginDescriptor.WHERE_MOVIELIST):
27 menu.append((p.description, boundFunction(self.execPlugin, p)))
29 FixedMenu.__init__(self, session, _("Movie Menu"), menu)
30 self.skinName = "Menu"
32 def execPlugin(self, plugin):
33 plugin(session=self.session, service=self.service)
36 serviceHandler = eServiceCenter.getInstance()
37 offline = serviceHandler.offlineOperations(self.service)
38 info = serviceHandler.info(self.service)
39 name = info and info.getName(self.service) or _("this recording")
41 if offline is not None:
43 if not offline.deleteFromDisk(1):
47 self.session.openWithCallback(self.deleteConfirmed, MessageBox, _("Do you really want to delete %s?") % (name))
49 self.session.openWithCallback(self.close, MessageBox, _("You cannot delete this!"), MessageBox.TYPE_ERROR)
51 def deleteConfirmed(self, confirmed):
55 serviceHandler = eServiceCenter.getInstance()
56 offline = serviceHandler.offlineOperations(self.service)
58 if offline is not None:
60 if not offline.deleteFromDisk(0):
64 self.session.openWithCallback(self.close, MessageBox, _("Delete failed!"), MessageBox.TYPE_ERROR)
66 list = self.csel["list"].removeService(self.service)
69 class MovieSelection(Screen):
70 def __init__(self, session, selectedmovie = None):
71 Screen.__init__(self, session)
74 self.selected_tags = None
76 self.current_ref = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + resolveFilename(SCOPE_HDD))
79 self.bouquet_mark_edit = False
81 self.delayTimer = eTimer()
82 self.delayTimer.timeout.get().append(self.updateHDDData)
84 self["waitingtext"] = Label(_("Please wait... Loading list..."))
86 self["list"] = MovieList(None)
87 self.list = self["list"]
88 self.selectedmovie = selectedmovie
90 self["key_red"] = Button(_("All..."))
91 self["key_green"] = Button("")
92 self["key_yellow"] = Button("")
93 self["key_blue"] = Button("")
95 #self["okbutton"] = Button("ok", [self.channelSelected])
96 self["freeDiskSpace"] = DiskInfo(resolveFilename(SCOPE_HDD), DiskInfo.FREE, update=False)
98 self["actions"] = ActionMap(["OkCancelActions", "MovieSelectionActions", "ColorActions"],
100 "cancel": self.abort,
101 "ok": self.movieSelected,
102 "showEventInfo": self.showEventInformation,
103 "contextMenu": self.doContext,
106 "yellow": self.showTagsFirst,
107 "green": self.showTagsSecond,
108 "blue": self.showTagsMenu,
110 self["actions"].csel = self
111 self.onShown.append(self.go)
113 self.lengthTimer = eTimer()
114 self.lengthTimer.timeout.get().append(self.updateLengthData)
117 def showEventInformation(self):
118 from Screens.EventView import EventViewSimple
119 from ServiceReference import ServiceReference
120 evt = self["list"].getCurrentEvent()
122 self.session.open(EventViewSimple, evt, ServiceReference(self.getCurrent()))
126 # ouch. this should redraw our "Please wait..."-text.
127 # this is of course not the right way to do this.
128 self.delayTimer.start(10, 1)
131 def updateHDDData(self):
133 if self.selectedmovie is not None:
135 self["waitingtext"].instance.hide()
137 self["freeDiskSpace"].update()
141 def updateLengthData(self):
142 self.list.updateLengthOfIndex(self.lengthPosition)
143 self.lengthPosition += 1
144 if self.lengthPosition < self.lengthLength:
145 self.lengthTimer.start(10, 1)
148 self["list"].moveTo(self.selectedmovie)
150 def getCurrent(self):
151 return self["list"].getCurrent()
153 def movieSelected(self):
154 self.lengthTimer.stop()
155 current = self.getCurrent()
156 if current is not None:
160 current = self.getCurrent()
161 if current is not None:
162 self.session.open(ChannelContextMenu, self, current)
167 def updateTags(self):
168 # get a list of tags available in this list
169 self.tags = list(self["list"].tags)
171 # by default, we do not display any filtering options
175 # when tags are present, however, the first two are
176 # directly mapped to the second, third ("green", "yellow") buttons
177 if len(self.tags) > 0:
178 self.tag_first = self.tags[0]
180 if len(self.tags) > 1:
181 self.tag_second = self.tags[1]
183 self["key_green"].text = self.tag_first
184 self["key_yellow"].text = self.tag_second
186 # the rest is presented in a list, available on the
187 # fourth ("blue") button
188 if len(self.tags) > 2:
189 self["key_blue"].text = _("Other...")
191 self["key_blue"].text = ""
193 def reloadList(self):
194 self["list"].reload(self.current_ref, self.selected_tags)
195 self.lengthTimer.start(10, 1)
196 self.lengthPosition = 0
197 self.lengthLength = len(self["list"])
200 self.selected_tags = None
203 def showTagsN(self, n):
204 if len(self.tags) < n:
205 self.showTagWarning()
207 self.selected_tags = set([self.tags[n - 1]])
210 def showTagsFirst(self):
213 def showTagsSecond(self):
216 def showTagsMenu(self):
217 if len(self.tags) < 3:
218 self.showTagWarning()
222 def showTagWarning(self):
223 print "select some tags first!"