workaround for not working /etc/init.d/network script
[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                 info = serviceHandler.info(self.service)
39                 name = info and info.getName(self.service) or _("this recording")
40                 result = False
41                 if offline is not None:
42                         # simulate first
43                         if not offline.deleteFromDisk(1):
44                                 result = True
45                 
46                 if result == True:
47                         self.session.openWithCallback(self.deleteConfirmed, MessageBox, _("Do you really want to delete %s?") % (name))
48                 else:
49                         self.session.openWithCallback(self.close, MessageBox, _("You cannot delete this!"), MessageBox.TYPE_ERROR)
50
51         def deleteConfirmed(self, confirmed):
52                 if not confirmed:
53                         return self.close()
54                         
55                 serviceHandler = eServiceCenter.getInstance()
56                 offline = serviceHandler.offlineOperations(self.service)
57                 result = False
58                 if offline is not None:
59                         # really delete!
60                         if not offline.deleteFromDisk(0):
61                                 result = True
62                 
63                 if result == False:
64                         self.session.openWithCallback(self.close, MessageBox, _("Delete failed!"), MessageBox.TYPE_ERROR)
65                 else:
66                         list = self.csel["list"].removeService(self.service)
67                         self.close()
68  
69 class MovieSelection(Screen):
70         def __init__(self, session, selectedmovie = None):
71                 Screen.__init__(self, session)
72                 
73                 self.movemode = False
74                 self.bouquet_mark_edit = False
75                 
76                 self.delayTimer = eTimer()
77                 self.delayTimer.timeout.get().append(self.updateHDDData)
78                 
79                 self["waitingtext"] = Label(_("Please wait... Loading list..."))
80                 
81                 self["list"] = MovieList(None)
82                 self.list = self["list"]
83                 self.selectedmovie = selectedmovie
84                 
85                 #self["okbutton"] = Button("ok", [self.channelSelected])
86                 self["freeDiskSpace"] = DiskInfo(resolveFilename(SCOPE_HDD), DiskInfo.FREE, update=False)
87                 
88                 self["actions"] = ActionMap(["OkCancelActions", "MovieSelectionActions"],
89                         {
90                                 "cancel": self.abort,
91                                 "ok": self.movieSelected,
92                                 "showEventInfo": self.showEventInformation,
93                                 "contextMenu": self.doContext,
94                         })
95                 self["actions"].csel = self
96                 self.onShown.append(self.go)
97                 
98                 self.lengthTimer = eTimer()
99                 self.lengthTimer.timeout.get().append(self.updateLengthData)
100                 self.inited = False
101
102         def showEventInformation(self):
103                 from Screens.EventView import EventViewSimple
104                 from ServiceReference import ServiceReference
105                 evt = self["list"].getCurrentEvent()
106                 if evt:
107                         self.session.open(EventViewSimple, evt, ServiceReference(self.getCurrent()))
108
109         def go(self):
110                 if not self.inited:
111                 # ouch. this should redraw our "Please wait..."-text.
112                 # this is of course not the right way to do this.
113                         self.delayTimer.start(10, 1)
114                         self.inited=True
115
116         def updateHDDData(self):
117                 self["list"].reload(eServiceReference("2:0:1:0:0:0:0:0:0:0:" + resolveFilename(SCOPE_HDD)))
118                 if (self.selectedmovie is not None):
119                         self.moveTo()
120                 self["waitingtext"].instance.hide()
121                                                 
122                 self["freeDiskSpace"].update()
123                 
124                 self.lengthTimer.start(10, 1)
125                 self.lengthPosition = 0
126                 self.lengthLength = len(self["list"])
127                 
128         def updateLengthData(self):
129                 self.list.updateLengthOfIndex(self.lengthPosition)
130                 self.lengthPosition += 1
131                 if self.lengthPosition < self.lengthLength:
132                         self.lengthTimer.start(10, 1)
133
134         def moveTo(self):
135                 self["list"].moveTo(self.selectedmovie)
136
137         def getCurrent(self):
138                 return self["list"].getCurrent()
139
140         def movieSelected(self):
141                 self.lengthTimer.stop()
142                 current = self.getCurrent()
143                 if current is not None:
144                         self.close(current)
145
146         def doContext(self):
147                 current = self.getCurrent()
148                 if current is not None:
149                         self.session.open(ChannelContextMenu, self, current)
150
151         def abort(self):
152                 self.close(None)