remove some unneeded debug output
[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                 
74                 self["waitingtext"] = Label(_("Please wait... Loading list..."))
75                 
76                 self["list"] = MovieList(None)
77                 self.selectedmovie = selectedmovie
78                 
79                 #self["okbutton"] = Button("ok", [self.channelSelected])
80                 self["freeDiskSpace"] = DiskInfo(resolveFilename(SCOPE_HDD), DiskInfo.FREE, update=False)
81                 
82                 self["actions"] = ActionMap(["OkCancelActions", "ContextMenuActions"],
83                         {
84                                 "cancel": self.abort,
85                                 "ok": self.movieSelected,
86                                 "contextMenu": self.doContext,
87                         })
88                 self["actions"].csel = self
89                 self.onShown.append(self.go)
90                 
91         def go(self):
92                 self.delayTimer.start(0, 1)
93
94         def updateHDDData(self):
95                 self["list"].reload(eServiceReference("2:0:1:0:0:0:0:0:0:0:" + resolveFilename(SCOPE_HDD)))
96                 if (self.selectedmovie is not None):
97                         self.moveTo()
98                 self["waitingtext"].instance.hide()
99                                                 
100                 self["freeDiskSpace"].update()
101
102         def moveTo(self):
103                 self["list"].moveTo(self.selectedmovie)
104
105         def getCurrent(self):
106                 return self["list"].getCurrent()[0]
107
108         def movieSelected(self):
109                 self.close(self.getCurrent())
110
111         def doContext(self):
112                 self.session.open(ChannelContextMenu, self, self.getCurrent())
113
114         def abort(self):
115                 self.close(None)