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