add possibility to view eventinfo in recorded movielist (move cursor to
[openblackhole/openblackhole-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.movemode = False
74                 self.bouquet_mark_edit = False
75                 
76                 self.delayTimer = eTimer()
77                 self.delayTimer.timeout.get().append(self.updateHDDData)
78                 
79                 self["waitingtext"] = Label(_("Please wait... Loading list..."))
80                 
81                 self["list"] = MovieList(None)
82                 self.list = self["list"]
83                 self.selectedmovie = selectedmovie
84                 
85                 #self["okbutton"] = Button("ok", [self.channelSelected])
86                 self["freeDiskSpace"] = DiskInfo(resolveFilename(SCOPE_HDD), DiskInfo.FREE, update=False)
87                 
88                 self["actions"] = ActionMap(["OkCancelActions", "MovieSelectionActions"],
89                         {
90                                 "cancel": self.abort,
91                                 "ok": self.movieSelected,
92                                 "showEventInfo": self.showEventInformation,
93                                 "contextMenu": self.doContext,
94                         })
95                 self["actions"].csel = self
96                 self.onShown.append(self.go)
97                 
98                 self.lengthTimer = eTimer()
99                 self.lengthTimer.timeout.get().append(self.updateLengthData)
100
101         def showEventInformation(self):
102                 from Screens.EventView import EventViewSimple
103                 from ServiceReference import ServiceReference
104                 evt = self["list"].getCurrentEvent()
105                 if evt:
106                         self.session.open(EventViewSimple, evt, ServiceReference(self.getCurrent()))
107
108         def go(self):
109                 # ouch. this should redraw our "Please wait..."-text.
110                 # this is of course not the right way to do this.
111                 self.delayTimer.start(10, 1)
112
113         def updateHDDData(self):
114                 self["list"].reload(eServiceReference("2:0:1:0:0:0:0:0:0:0:" + resolveFilename(SCOPE_HDD)))
115                 if (self.selectedmovie is not None):
116                         self.moveTo()
117                 self["waitingtext"].instance.hide()
118                                                 
119                 self["freeDiskSpace"].update()
120                 
121                 self.lengthTimer.start(10, 1)
122                 self.lengthPosition = 0
123                 self.lengthLength = len(self["list"])
124                 
125         def updateLengthData(self):
126                 self.list.updateLengthOfIndex(self.lengthPosition)
127                 self.lengthPosition += 1
128                 if self.lengthPosition < self.lengthLength:
129                         self.lengthTimer.start(10, 1)
130
131         def moveTo(self):
132                 self["list"].moveTo(self.selectedmovie)
133
134         def getCurrent(self):
135                 return self["list"].getCurrent()
136
137         def movieSelected(self):
138                 self.lengthTimer.stop()
139                 current = self.getCurrent()
140                 if current is not None:
141                         self.close(current)
142
143         def doContext(self):
144                 current = self.getCurrent()
145                 if current is not None:
146                         self.session.open(ChannelContextMenu, self, current)
147
148         def abort(self):
149                 self.close(None)