use number keys for predefined pip positions
[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                                 "contextMenu": self.doContext,
93                         })
94                 self["actions"].csel = self
95                 self.onShown.append(self.go)
96                 
97                 self.lengthTimer = eTimer()
98                 self.lengthTimer.timeout.get().append(self.updateLengthData)
99                 
100         def go(self):
101                 # ouch. this should redraw our "Please wait..."-text.
102                 # this is of course not the right way to do this.
103                 self.delayTimer.start(10, 1)
104
105         def updateHDDData(self):
106                 self["list"].reload(eServiceReference("2:0:1:0:0:0:0:0:0:0:" + resolveFilename(SCOPE_HDD)))
107                 if (self.selectedmovie is not None):
108                         self.moveTo()
109                 self["waitingtext"].instance.hide()
110                                                 
111                 self["freeDiskSpace"].update()
112                 
113                 self.lengthTimer.start(10, 1)
114                 self.lengthPosition = 0
115                 self.lengthLength = len(self["list"])
116                 
117         def updateLengthData(self):
118                 self.list.updateLengthOfIndex(self.lengthPosition)
119                 self.lengthPosition += 1
120                 if self.lengthPosition < self.lengthLength:
121                         self.lengthTimer.start(10, 1)
122
123         def moveTo(self):
124                 self["list"].moveTo(self.selectedmovie)
125
126         def getCurrent(self):
127                 return self["list"].getCurrent()
128
129         def movieSelected(self):
130                 self.lengthTimer.stop()
131                 current = self.getCurrent()
132                 if current is not None:
133                         self.close(current)
134
135         def doContext(self):
136                 current = self.getCurrent()
137                 if current is not None:
138                         self.session.open(ChannelContextMenu, self, current)
139
140         def abort(self):
141                 self.close(None)