remove unneeded (double) close
[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.list = self["list"]
81                 self.selectedmovie = selectedmovie
82                 
83                 #self["okbutton"] = Button("ok", [self.channelSelected])
84                 self["freeDiskSpace"] = DiskInfo(resolveFilename(SCOPE_HDD), DiskInfo.FREE, update=False)
85                 
86                 self["actions"] = ActionMap(["OkCancelActions", "MovieSelectionActions"],
87                         {
88                                 "cancel": self.abort,
89                                 "ok": self.movieSelected,
90                                 "contextMenu": self.doContext,
91                         })
92                 self["actions"].csel = self
93                 self.onShown.append(self.go)
94                 
95                 self.lengthTimer = eTimer()
96                 self.lengthTimer.timeout.get().append(self.updateLengthData)
97                 
98         def go(self):
99                 # ouch. this should redraw our "Please wait..."-text.
100                 # this is of course not the right way to do this.
101                 self.delayTimer.start(10, 1)
102
103         def updateHDDData(self):
104                 self["list"].reload(eServiceReference("2:0:1:0:0:0:0:0:0:0:" + resolveFilename(SCOPE_HDD)))
105                 if (self.selectedmovie is not None):
106                         self.moveTo()
107                 self["waitingtext"].instance.hide()
108                                                 
109                 self["freeDiskSpace"].update()
110                 
111                 self.lengthTimer.start(10, 1)
112                 self.lengthPosition = 0
113                 self.lengthLength = len(self["list"])
114                 
115         def updateLengthData(self):
116                 self.list.updateLengthOfIndex(self.lengthPosition)
117                 self.lengthPosition += 1
118                 if self.lengthPosition < self.lengthLength:
119                         self.lengthTimer.start(10, 1)
120
121         def moveTo(self):
122                 self["list"].moveTo(self.selectedmovie)
123
124         def getCurrent(self):
125                 return self["list"].getCurrent()
126
127         def movieSelected(self):
128                 self.lengthTimer.stop()
129                 current = self.getCurrent()
130                 if current is not None:
131                         self.close(current)
132
133         def doContext(self):
134                 current = self.getCurrent()
135                 if current is not None:
136                         self.session.open(ChannelContextMenu, self, current)
137
138         def abort(self):
139                 self.close(None)