fix debug
[enigma2.git] / lib / python / Screens / MovieSelection.py
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
10
11 from Screens.MessageBox import MessageBox
12 from Screens.FixedMenu import FixedMenu
13
14 from Tools.Directories import *
15 from Tools.BoundFunction import boundFunction
16
17 from enigma import eServiceReference, eServiceCenter, eTimer
18
19 class ChannelContextMenu(FixedMenu):
20         def __init__(self, session, csel, service):
21                 self.csel = csel
22                 self.service = service
23
24                 menu = [(_("back"), self.close), (_("delete..."), self.delete)]
25
26                 for p in plugins.getPlugins(PluginDescriptor.WHERE_MOVIELIST):
27                         menu.append((p.description, boundFunction(self.execPlugin, p)))
28
29                 FixedMenu.__init__(self, session, _("Movie Menu"), menu)
30                 self.skinName = "Menu"
31
32         def execPlugin(self, plugin):
33                 plugin(session=self.session, service=self.service)
34
35         def delete(self):
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")
40                 result = False
41                 if offline is not None:
42                         # simulate first
43                         if not offline.deleteFromDisk(1):
44                                 result = True
45                 
46                 if result == True:
47                         self.session.openWithCallback(self.deleteConfirmed, MessageBox, _("Do you really want to delete %s?") % (name))
48                 else:
49                         self.session.openWithCallback(self.close, MessageBox, _("You cannot delete this!"), MessageBox.TYPE_ERROR)
50
51         def deleteConfirmed(self, confirmed):
52                 if not confirmed:
53                         return self.close()
54                         
55                 serviceHandler = eServiceCenter.getInstance()
56                 offline = serviceHandler.offlineOperations(self.service)
57                 result = False
58                 if offline is not None:
59                         # really delete!
60                         if not offline.deleteFromDisk(0):
61                                 result = True
62                 
63                 if result == False:
64                         self.session.openWithCallback(self.close, MessageBox, _("Delete failed!"), MessageBox.TYPE_ERROR)
65                 else:
66                         list = self.csel["list"].removeService(self.service)
67                         self.close()
68  
69 class MovieSelection(Screen):
70         def __init__(self, session, selectedmovie = None):
71                 Screen.__init__(self, session)
72                 
73                 self.tags = [ ]
74                 self.selected_tags = None
75                 
76                 self.current_ref = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + resolveFilename(SCOPE_HDD))
77                 
78                 self.movemode = False
79                 self.bouquet_mark_edit = False
80                 
81                 self.delayTimer = eTimer()
82                 self.delayTimer.timeout.get().append(self.updateHDDData)
83                 
84                 self["waitingtext"] = Label(_("Please wait... Loading list..."))
85                 
86                 self["list"] = MovieList(None)
87                 self.list = self["list"]
88                 self.selectedmovie = selectedmovie
89                 
90                 self["key_red"] = Button(_("All..."))
91                 self["key_green"] = Button("")
92                 self["key_yellow"] = Button("")
93                 self["key_blue"] = Button("")
94                 
95                 #self["okbutton"] = Button("ok", [self.channelSelected])
96                 self["freeDiskSpace"] = DiskInfo(resolveFilename(SCOPE_HDD), DiskInfo.FREE, update=False)
97                 
98                 self["actions"] = ActionMap(["OkCancelActions", "MovieSelectionActions", "ColorActions"],
99                         {
100                                 "cancel": self.abort,
101                                 "ok": self.movieSelected,
102                                 "showEventInfo": self.showEventInformation,
103                                 "contextMenu": self.doContext,
104                                 
105                                 "red": self.showAll,
106                                 "yellow": self.showTagsFirst,
107                                 "green": self.showTagsSecond,
108                                 "blue": self.showTagsMenu,
109                         })
110                 self["actions"].csel = self
111                 self.onShown.append(self.go)
112                 
113                 self.lengthTimer = eTimer()
114                 self.lengthTimer.timeout.get().append(self.updateLengthData)
115                 self.inited = False
116
117         def showEventInformation(self):
118                 from Screens.EventView import EventViewSimple
119                 from ServiceReference import ServiceReference
120                 evt = self["list"].getCurrentEvent()
121                 if evt:
122                         self.session.open(EventViewSimple, evt, ServiceReference(self.getCurrent()))
123
124         def go(self):
125                 if not self.inited:
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)
129                         self.inited=True
130
131         def updateHDDData(self):
132                 self.reloadList()
133                 if self.selectedmovie is not None:
134                         self.moveTo()
135                 self["waitingtext"].instance.hide()
136
137                 self["freeDiskSpace"].update()
138
139                 self.updateTags()
140
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)
146
147         def moveTo(self):
148                 self["list"].moveTo(self.selectedmovie)
149
150         def getCurrent(self):
151                 return self["list"].getCurrent()
152
153         def movieSelected(self):
154                 self.lengthTimer.stop()
155                 current = self.getCurrent()
156                 if current is not None:
157                         self.close(current)
158
159         def doContext(self):
160                 current = self.getCurrent()
161                 if current is not None:
162                         self.session.open(ChannelContextMenu, self, current)
163
164         def abort(self):
165                 self.close(None)
166
167         def updateTags(self):
168                 # get a list of tags available in this list
169                 self.tags = list(self["list"].tags)
170                 
171                 # by default, we do not display any filtering options
172                 self.tag_first = ""
173                 self.tag_second = ""
174                 
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]
179                 
180                 if len(self.tags) > 1:
181                         self.tag_second = self.tags[1]
182                 
183                 self["key_green"].text = self.tag_first
184                 self["key_yellow"].text = self.tag_second
185                 
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...")
190                 else:
191                         self["key_blue"].text = ""
192
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"])
198
199         def showAll(self):
200                 self.selected_tags = None
201                 self.reloadList()
202
203         def showTagsN(self, n):
204                 if len(self.tags) < n:
205                         self.showTagWarning()
206                 else:
207                         self.selected_tags = set([self.tags[n - 1]])
208                         self.reloadList()
209
210         def showTagsFirst(self):
211                 self.showTagsN(1)
212
213         def showTagsSecond(self):
214                 self.showTagsN(2)
215
216         def showTagsMenu(self):
217                 if len(self.tags) < 3:
218                         self.showTagWarning()
219                 else:
220                         pass
221
222         def showTagWarning(self):
223                 print "select some tags first!"