use new DeepstandbySupport SystemInfo entry at some places... this fixes bug #307
[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 InfoBarGenerics import InfoBarNotifications
6 import Screens.Standby
7 from Tools import Notifications
8
9 class JobView(InfoBarNotifications, Screen, ConfigListScreen):
10         def __init__(self, session, job, parent=None, cancelable = True, backgroundable = True, afterEvent = 0):
11                 from Components.Sources.StaticText import StaticText
12                 from Components.Sources.Progress import Progress
13                 from Components.Sources.Boolean import Boolean
14                 from Components.ActionMap import ActionMap
15                 Screen.__init__(self, session, parent)
16                 InfoBarNotifications.__init__(self)
17                 ConfigListScreen.__init__(self, [])
18                 self.parent = parent
19                 self.job = job
20
21                 self["job_name"] = StaticText(job.name)
22                 self["job_progress"] = Progress()
23                 self["job_task"] = StaticText()
24                 self["summary_job_name"] = StaticText(job.name)
25                 self["summary_job_progress"] = Progress()
26                 self["summary_job_task"] = StaticText()
27                 self["job_status"] = StaticText()
28                 self["finished"] = Boolean()
29                 self["cancelable"] = Boolean(cancelable)
30                 self["backgroundable"] = Boolean(backgroundable)
31
32                 self["key_blue"] = StaticText(_("Background"))
33
34                 self.onShow.append(self.windowShow)
35                 self.onHide.append(self.windowHide)
36
37                 self["setupActions"] = ActionMap(["ColorActions", "SetupActions"],
38                 {
39                     "green": self.ok,
40                     "red": self.abort,
41                     "blue": self.background,
42                     "cancel": self.ok,
43                     "ok": self.ok,
44                 }, -2)
45
46                 self.afterevents = [ "nothing", "standby", "deepstandby", "close" ]
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.afterevents[afterEvent])
53                 self.setupList()
54                 self.state_changed()
55
56         def setupList(self):
57                 self["config"].setList( [ getConfigListEntry(_("After event"), self.settings.afterEvent) ])
58                 
59         def keyLeft(self):
60                 ConfigListScreen.keyLeft(self)
61                 self.setupList()
62
63         def keyRight(self):
64                 ConfigListScreen.keyRight(self)
65                 self.setupList()
66         
67         def windowShow(self):
68                 self.job.state_changed.append(self.state_changed)
69
70         def windowHide(self):
71                 if len(self.job.state_changed) > 0:
72                     self.job.state_changed.remove(self.state_changed)
73
74         def state_changed(self):
75                 j = self.job
76                 self["job_progress"].range = j.end
77                 self["summary_job_progress"].range = j.end
78                 self["job_progress"].value = j.progress
79                 self["summary_job_progress"].value = j.progress
80                 #print "JobView::state_changed:", j.end, j.progress
81                 self["job_status"].text = j.getStatustext()
82                 if j.status == j.IN_PROGRESS:
83                         self["job_task"].text = j.tasks[j.current_task].name
84                         self["summary_job_task"].text = j.tasks[j.current_task].name
85                 else:
86                         self["job_task"].text = ""
87                         self["summary_job_task"].text = j.getStatustext()
88                 if j.status in (j.FINISHED, j.FAILED):
89                         self.performAfterEvent()
90                         self["backgroundable"].boolean = False
91                         if j.status == j.FINISHED:
92                                 self["finished"].boolean = True
93                                 self["cancelable"].boolean = False
94                         elif j.status == j.FAILED:
95                                 self["cancelable"].boolean = True
96
97         def background(self):
98                 if self["backgroundable"].boolean == True:
99                         self.close(True)
100
101         def ok(self):
102                 if self.job.status in (self.job.FINISHED, self.job.FAILED):
103                         self.close(False)
104
105         def abort(self):
106                 if self.job.status in (self.job.FINISHED, self.job.FAILED):
107                         self.close(False)
108                 if self["cancelable"].boolean == True:
109                         self.job.cancel()
110
111         def performAfterEvent(self):
112                 self["config"].hide()
113                 if self.settings.afterEvent.getValue() == "nothing":
114                         return
115                 elif self.settings.afterEvent.getValue() == "close":
116                         self.abort()
117                 from Screens.MessageBox import MessageBox
118                 if self.settings.afterEvent.getValue() == "deepstandby":
119                         if not Screens.Standby.inTryQuitMainloop:
120                                 Notifications.AddNotificationWithCallback(self.sendTryQuitMainloopNotification, MessageBox, _("A sleep timer wants to shut down\nyour Dreambox. Shutdown now?"), timeout = 20)
121                 elif self.settings.afterEvent.getValue() == "standby":
122                         if not Screens.Standby.inStandby:
123                                 Notifications.AddNotificationWithCallback(self.sendStandbyNotification, MessageBox, _("A sleep timer wants to set your\nDreambox to standby. Do that now?"), timeout = 20)
124
125         def sendStandbyNotification(self, answer):
126                 if answer:
127                         Notifications.AddNotification(Screens.Standby.Standby)
128
129         def sendTryQuitMainloopNotification(self, answer):
130                 if answer:
131                         Notifications.AddNotification(Screens.Standby.TryQuitMainloop, 1)