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