fix plugin call
[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                 result = False
39                 if offline is not None:
40                         # simulate first
41                         if not offline.deleteFromDisk(1):
42                                 result = True
43                 
44                 if result == True:
45                         self.session.openWithCallback(self.deleteConfirmed, MessageBox, _("Do you really want to delete this recording?"))
46                 else:
47                         self.session.openWithCallback(self.close, MessageBox, _("You cannot delete this!"), MessageBox.TYPE_ERROR)
48
49         def deleteConfirmed(self, confirmed):
50                 if not confirmed:
51                         return self.close()
52                         
53                 serviceHandler = eServiceCenter.getInstance()
54                 offline = serviceHandler.offlineOperations(self.service)
55                 result = False
56                 if offline is not None:
57                         # really delete!
58                         if not offline.deleteFromDisk(0):
59                                 result = True
60                 
61                 if result == False:
62                         self.session.openWithCallback(self.close, MessageBox, _("Delete failed!"), MessageBox.TYPE_ERROR)
63                 else:
64                         list = self.csel["list"].removeService(self.service)
65                         self.close()
66  
67 class MovieSelection(Screen):
68         def __init__(self, session, selectedmovie = None):
69                 Screen.__init__(self, session)
70                 
71                 self.movemode = False
72                 self.bouquet_mark_edit = False
73                 
74                 self.delayTimer = eTimer()
75                 self.delayTimer.timeout.get().append(self.updateHDDData)
76                 
77                 self["waitingtext"] = Label(_("Please wait... Loading list..."))
78                 
79                 self["list"] = MovieList(None)
80                 self.selectedmovie = selectedmovie
81                 
82                 #self["okbutton"] = Button("ok", [self.channelSelected])
83                 self["freeDiskSpace"] = DiskInfo(resolveFilename(SCOPE_HDD), DiskInfo.FREE, update=False)
84                 
85                 self["actions"] = ActionMap(["OkCancelActions", "MovieSelectionActions"],
86                         {
87                                 "cancel": self.abort,
88                                 "ok": self.movieSelected,
89                                 "contextMenu": self.doContext,
90                         })
91                 self["actions"].csel = self
92                 self.onShown.append(self.go)
93                 
94         def go(self):
95                 # ouch. this should redraw our "Please wait..."-text.
96                 # this is of course not the right way to do this.
97                 self.delayTimer.start(10, 1)
98
99         def updateHDDData(self):
100                 self["list"].reload(eServiceReference("2:0:1:0:0:0:0:0:0:0:" + resolveFilename(SCOPE_HDD)))
101                 if (self.selectedmovie is not None):
102                         self.moveTo()
103                 self["waitingtext"].instance.hide()
104                                                 
105                 self["freeDiskSpace"].update()
106
107         def moveTo(self):
108                 self["list"].moveTo(self.selectedmovie)
109
110         def getCurrent(self):
111                 l = self["list"].getCurrent()
112                 return l and l[0]
113
114         def movieSelected(self):
115                 current = self.getCurrent()
116                 if current is not None:
117                         self.close(current)
118
119         def doContext(self):
120                 current = self.getCurrent()
121                 if current is not None:
122                         self.session.open(ChannelContextMenu, self, current)
123
124         def abort(self):
125                 self.close(None)