[RecordTimer] fix repeat timer issue.
[vuplus_dvbapp] / lib / python / Screens / TaskView.py
1 from Screen import Screen
2 from Components.ConfigList import ConfigListScreen
3 from Components.config import config, ConfigSubsection, ConfigSelection, getConfigListEntry
4 from Components.SystemInfo import SystemInfo
5 from Components.Task import job_manager
6 from InfoBarGenerics import InfoBarNotifications
7 import Screens.Standby
8 from Tools import Notifications
9
10 class JobView(InfoBarNotifications, Screen, ConfigListScreen):
11         def __init__(self, session, job, parent=None, cancelable = True, backgroundable = True, afterEventChangeable = True):
12                 from Components.Sources.StaticText import StaticText
13                 from Components.Sources.Progress import Progress
14                 from Components.Sources.Boolean import Boolean
15                 from Components.ActionMap import ActionMap
16                 Screen.__init__(self, session, parent)
17                 InfoBarNotifications.__init__(self)
18                 ConfigListScreen.__init__(self, [])
19                 self.parent = parent
20                 self.job = job
21
22                 self["job_name"] = StaticText(job.name)
23                 self["job_progress"] = Progress()
24                 self["job_task"] = StaticText()
25                 self["summary_job_name"] = StaticText(job.name)
26                 self["summary_job_progress"] = Progress()
27                 self["summary_job_task"] = StaticText()
28                 self["job_status"] = StaticText()
29                 self["finished"] = Boolean()
30                 self["cancelable"] = Boolean(cancelable)
31                 self["backgroundable"] = Boolean(backgroundable)
32
33                 self["key_blue"] = StaticText(_("Background"))
34
35                 self.onShow.append(self.windowShow)
36                 self.onHide.append(self.windowHide)
37
38                 self["setupActions"] = ActionMap(["ColorActions", "SetupActions"],
39                 {
40                     "green": self.ok,
41                     "red": self.abort,
42                     "blue": self.background,
43                     "cancel": self.ok,
44                     "ok": self.ok,
45                 }, -2)
46
47                 self.settings = ConfigSubsection()
48                 if SystemInfo["DeepstandbySupport"]:
49                         shutdownString = _("go to deep standby")
50                 else:
51                         shutdownString = _("shut down")
52                 self.settings.afterEvent = ConfigSelection(choices = [("nothing", _("do nothing")), ("close", _("Close")), ("standby", _("go to standby")), ("deepstandby", shutdownString)], default = self.job.afterEvent or "nothing")
53                 self.job.afterEvent = self.settings.afterEvent.getValue()
54                 self.afterEventChangeable = afterEventChangeable
55                 self.setupList()
56                 self.state_changed()
57
58         def setupList(self):
59                 if self.afterEventChangeable:
60                         self["config"].setList( [ getConfigListEntry(_("After event"), self.settings.afterEvent) ])
61                 else:
62                         self["config"].hide()
63                 self.job.afterEvent = self.settings.afterEvent.getValue()
64
65         def keyLeft(self):
66                 ConfigListScreen.keyLeft(self)
67                 self.setupList()
68
69         def keyRight(self):
70                 ConfigListScreen.keyRight(self)
71                 self.setupList()
72         
73         def windowShow(self):
74                 self.job.state_changed.append(self.state_changed)
75
76         def windowHide(self):
77                 if len(self.job.state_changed) > 0:
78                     self.job.state_changed.remove(self.state_changed)
79
80         def state_changed(self):
81                 j = self.job
82                 self["job_progress"].range = j.end
83                 self["summary_job_progress"].range = j.end
84                 self["job_progress"].value = j.progress
85                 self["summary_job_progress"].value = j.progress
86                 #print "JobView::state_changed:", j.end, j.progress
87                 self["job_status"].text = j.getStatustext()
88                 if j.status == j.IN_PROGRESS:
89                         self["job_task"].text = j.tasks[j.current_task].name
90                         self["summary_job_task"].text = j.tasks[j.current_task].name
91                 else:
92                         self["job_task"].text = ""
93                         self["summary_job_task"].text = j.getStatustext()
94                 if j.status in (j.FINISHED, j.FAILED):
95                         self.performAfterEvent()
96                         self["backgroundable"].boolean = False
97                         if j.status == j.FINISHED:
98                                 self["finished"].boolean = True
99                                 self["cancelable"].boolean = False
100                         elif j.status == j.FAILED:
101                                 self["cancelable"].boolean = True
102
103         def background(self):
104                 if self["backgroundable"].boolean == True:
105                         self.close(True)
106
107         def ok(self):
108                 if self.job.status in (self.job.FINISHED, self.job.FAILED):
109                         self.close(False)
110
111         def abort(self):
112                 if self.job.status == self.job.NOT_STARTED:
113                         job_manager.active_jobs.remove(self.job)
114                         self.close(False)
115                 elif self.job.status == self.job.IN_PROGRESS and self["cancelable"].boolean == True:
116                         self.job.cancel()
117                 else:
118                         self.close(False)
119
120         def performAfterEvent(self):
121                 self["config"].hide()
122                 if self.settings.afterEvent.getValue() == "nothing":
123                         return
124                 elif self.settings.afterEvent.getValue() == "close" and self.job.status == self.job.FINISHED:
125                         self.close(False)
126                 from Screens.MessageBox import MessageBox
127                 if self.settings.afterEvent.getValue() == "deepstandby":
128                         if not Screens.Standby.inTryQuitMainloop:
129                                 Notifications.AddNotificationWithCallback(self.sendTryQuitMainloopNotification, MessageBox, _("A sleep timer wants to shut down\nyour STB. Shutdown now?"), timeout = 20)
130                 elif self.settings.afterEvent.getValue() == "standby":
131                         if not Screens.Standby.inStandby:
132                                 Notifications.AddNotificationWithCallback(self.sendStandbyNotification, MessageBox, _("A sleep timer wants to set your\nSTB to standby. Do that now?"), timeout = 20)
133
134         def checkNotifications(self):
135                 InfoBarNotifications.checkNotifications(self)
136                 if Notifications.notifications == []:
137                         if self.settings.afterEvent.getValue() == "close" and self.job.status == self.job.FAILED:
138                                 self.close(False)
139                 
140         def sendStandbyNotification(self, answer):
141                 if answer:
142                         Notifications.AddNotification(Screens.Standby.Standby)
143
144         def sendTryQuitMainloopNotification(self, answer):
145                 if answer:
146                         Notifications.AddNotification(Screens.Standby.TryQuitMainloop, 1)