display "please wait" message in movieselection while hdd spins up
[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
9 from Screens.MessageBox import MessageBox
10 from Screens.FixedMenu import FixedMenu
11
12 from Tools.Directories import *
13
14 from enigma import eServiceReference, eServiceCenter, eTimer
15
16 class ChannelContextMenu(FixedMenu):
17         def __init__(self, session, csel, service):
18                 self.csel = csel
19                 self.service = service
20                 
21                 menu = [(_("back"), self.close), (_("delete..."), self.delete)]
22                 
23                 FixedMenu.__init__(self, session, _("Movie Menu"), menu)
24                 self.skinName = "Menu"
25
26         def delete(self):
27                 serviceHandler = eServiceCenter.getInstance()
28                 offline = serviceHandler.offlineOperations(self.service)
29                 result = False
30                 if offline is not None:
31                         # simulate first
32                         if not offline.deleteFromDisk(1):
33                                 result = True
34                 
35                 if result == True:
36                         self.session.openWithCallback(self.deleteConfirmed, MessageBox, _("Do you really want to delete this recording?"))
37                 else:
38                         self.session.openWithCallback(self.close, MessageBox, _("You cannot delete this!"), MessageBox.TYPE_ERROR)
39
40         def deleteConfirmed(self, confirmed):
41                 if not confirmed:
42                         return self.close()
43                         
44                 serviceHandler = eServiceCenter.getInstance()
45                 offline = serviceHandler.offlineOperations(self.service)
46                 result = False
47                 if offline is not None:
48                         # really delete!
49                         if not offline.deleteFromDisk(0):
50                                 result = True
51                 
52                 if result == False:
53                         self.session.openWithCallback(self.close, MessageBox, _("Delete failed!"), MessageBox.TYPE_ERROR)
54                 else:
55                         list = self.csel["list"]
56                         currentIndex = list.getCurrentIndex()
57                         list.moveDown()
58                         if list.getCurrentIndex() == currentIndex:
59                                 currentIndex -= 1
60                         list.reload()
61                         list.moveToIndex(currentIndex)
62                         self.close()
63  
64 class MovieSelection(Screen):
65         def __init__(self, session, selectedmovie = None):
66                 Screen.__init__(self, session)
67                 
68                 self.movemode = False
69                 self.bouquet_mark_edit = False
70                 
71                 self.delayTimer = eTimer()
72                 self.delayTimer.timeout.get().append(self.updateHDDData)
73                 self.delayTimer.start(0, 1)
74                 
75                 self["waitingtext"] = Label(_("Please wait... Loading list..."))
76                 
77                 self["list"] = MovieList(None)
78                 self.selectedmovie = selectedmovie
79                 
80                 #self["okbutton"] = Button("ok", [self.channelSelected])
81                 self["freeDiskSpace"] = DiskInfo(resolveFilename(SCOPE_HDD), DiskInfo.FREE, update=False)
82                 
83                 self["actions"] = ActionMap(["OkCancelActions", "ContextMenuActions"],
84                         {
85                                 "cancel": self.abort,
86                                 "ok": self.movieSelected,
87                                 "contextMenu": self.doContext,
88                         })
89                 self["actions"].csel = self
90
91         def updateHDDData(self):
92                 self["list"].reload(eServiceReference("2:0:1:0:0:0:0:0:0:0:" + resolveFilename(SCOPE_HDD)))
93                 if (self.selectedmovie is not None):
94                         self.moveTo()
95                 self["waitingtext"].instance.hide()
96                                                 
97                 self["freeDiskSpace"].update()
98
99         def moveTo(self):
100                 self["list"].moveTo(self.selectedmovie)
101
102         def getCurrent(self):
103                 return self["list"].getCurrent()[0]
104
105         def movieSelected(self):
106                 self.close(self.getCurrent())
107
108         def doContext(self):
109                 self.session.open(ChannelContextMenu, self, self.getCurrent())
110
111         def abort(self):
112                 self.close(None)