1 | #ifndef POWEROFFTIMER_H |
---|
2 | #define POWEROFFTIMER_H |
---|
3 | |
---|
4 | void calcfixpowerofftime() |
---|
5 | { |
---|
6 | char* tmpstr = NULL, *fixtime = NULL; |
---|
7 | time_t akttime = time(NULL); |
---|
8 | struct tm* loctime = NULL; |
---|
9 | |
---|
10 | if(akttime < 1072224000) // 01.01.2004 |
---|
11 | return; |
---|
12 | |
---|
13 | fixtime = getconfig("fixshutdowntime", NULL); |
---|
14 | if(fixtime != NULL) |
---|
15 | { |
---|
16 | loctime = olocaltime(&akttime); |
---|
17 | tmpstr = strptime(fixtime, "%H:%M", loctime); |
---|
18 | if(tmpstr != NULL) |
---|
19 | { |
---|
20 | status.fixpowerofftime = mktime(loctime); |
---|
21 | if(status.fixpowerofftime <= akttime) |
---|
22 | status.fixpowerofftime += 86400; |
---|
23 | } |
---|
24 | } |
---|
25 | else |
---|
26 | status.fixpowerofftime = 1; |
---|
27 | free(loctime); loctime = NULL; |
---|
28 | } |
---|
29 | |
---|
30 | void checkshutdowntimer() |
---|
31 | { |
---|
32 | int mode = 0; |
---|
33 | if(status.standby != 0) return; |
---|
34 | |
---|
35 | if(status.fixpowerofftime == 0) |
---|
36 | calcfixpowerofftime(); |
---|
37 | |
---|
38 | time_t akttime = time(NULL); |
---|
39 | |
---|
40 | if(status.sd_timer != NULL && status.sd_timer->active && status.sd_timer->shutdown_time < akttime) |
---|
41 | mode = 1; |
---|
42 | |
---|
43 | if(status.fixpowerofftime > 1 && status.fixpowerofftime > akttime - 180 && status.fixpowerofftime < akttime) |
---|
44 | mode = 2; |
---|
45 | |
---|
46 | if(mode > 0) |
---|
47 | { |
---|
48 | if(status.fixpowerofftime > 1) status.fixpowerofftime += 86400; |
---|
49 | if(getconfigint("shutdowntimetype", NULL) == 0) |
---|
50 | { |
---|
51 | if(mode == 2) |
---|
52 | { |
---|
53 | mode = 0; |
---|
54 | oshutdown(1, 4); |
---|
55 | } |
---|
56 | else |
---|
57 | { |
---|
58 | mode = 0; |
---|
59 | oshutdown(1, 5); |
---|
60 | } |
---|
61 | } |
---|
62 | else |
---|
63 | { |
---|
64 | mode = 0; |
---|
65 | if(status.sd_timer != NULL) |
---|
66 | status.sd_timer->active = 0; |
---|
67 | status.standby = 2; |
---|
68 | screenstandby(); |
---|
69 | } |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | void free_shutdowntimervar() |
---|
74 | { |
---|
75 | if(status.sd_timer) |
---|
76 | { |
---|
77 | free(status.sd_timer); |
---|
78 | status.sd_timer = NULL; |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | void screenpowerofftimer(void) |
---|
83 | { |
---|
84 | if(status.sd_timer == NULL) //first call |
---|
85 | { |
---|
86 | status.sd_timer = (struct shutdowntimer*) malloc(sizeof(struct shutdowntimer)); |
---|
87 | if(!status.sd_timer) |
---|
88 | { |
---|
89 | err("can't allocate memory for variable"); |
---|
90 | return; |
---|
91 | } |
---|
92 | status.sd_timer->active = 0; |
---|
93 | status.sd_timer->shutdown_time = time(NULL); |
---|
94 | } |
---|
95 | |
---|
96 | int rcret = 0; |
---|
97 | struct skin* screen = getscreen("powerofftimerscreen"); |
---|
98 | struct skin* listbox = getscreennode(screen, "listbox"); |
---|
99 | struct skin* minutes = getscreennode(screen, "minutes"); |
---|
100 | struct skin* fixshutdowntime = getscreennode(screen, "fixshutdowntime"); |
---|
101 | struct skin* shutdowntimetype = getscreennode(screen, "mode"); |
---|
102 | long long secs = 0; |
---|
103 | |
---|
104 | if(status.sd_timer->active) //calculate minutes until previously scheduled shutdown |
---|
105 | { |
---|
106 | secs = status.sd_timer->shutdown_time - (long long)time(NULL); |
---|
107 | if(secs <= 0) secs = 1800; //oops, we should already be shut down or at least almost;) |
---|
108 | } |
---|
109 | int min = ((float)secs / 60 + 0.5); |
---|
110 | if(min > 1000) min = 999; |
---|
111 | char *tmpstr = (char*)malloc(4 * sizeof(char)); |
---|
112 | if(tmpstr != NULL) snprintf(tmpstr, 4, "%03d", min); |
---|
113 | changemask(minutes, "000"); |
---|
114 | changeinput(minutes, tmpstr); |
---|
115 | free(tmpstr); tmpstr = NULL; |
---|
116 | |
---|
117 | addchoicebox(shutdowntimetype, "0", _("DeepStandby")); |
---|
118 | addchoicebox(shutdowntimetype, "1", _("Standby")); |
---|
119 | setchoiceboxselection(shutdowntimetype, getconfig("shutdowntimetype", NULL)); |
---|
120 | |
---|
121 | changeinput(fixshutdowntime, "deaktiv\n22:00\n22:15\n22:30\n22:45\n23:00\n23:15\n23:30\n23:45\n00:00\n00:15\n00:30\n00:45\n01:00\n01:15\n01:30\n01:45\n02:00\n02:15\n02:30\n02:45\n03:00\n03:15\n03:30\n03:45\n04:00\n05:00\n06:00\n07:00\n08:00\n09:00\n10:00\n11:00\n12:00\n13:00\n14:00\n15:00\n16:00\n17:00\n18:00\n19:00\n20:00\n21:00"); |
---|
122 | changechoiceboxvalue(fixshutdowntime, "0\n22:00\n22:15\n22:30\n22:45\n23:00\n23:15\n23:30\n23:45\n00:00\n00:15\n00:30\n00:45\n01:00\n01:15\n01:30\n01:45\n02:00\n02:15\n02:30\n02:45\n03:00\n03:15\n03:30\n03:45\n04:00\n05:00\n06:00\n07:00\n08:00\n09:00\n10:00\n11:00\n12:00\n13:00\n14:00\n15:00\n16:00\n17:00\n18:00\n19:00\n20:00\n21:00"); |
---|
123 | setchoiceboxselection(fixshutdowntime, getconfig("fixshutdowntime", NULL)); |
---|
124 | |
---|
125 | listbox->aktline = 1; |
---|
126 | listbox->aktpage = 1; |
---|
127 | |
---|
128 | drawscreen(screen, 0, 0); |
---|
129 | addscreenrc(screen, listbox); |
---|
130 | |
---|
131 | struct skin* tmp = NULL; |
---|
132 | tmp = listbox->select; |
---|
133 | |
---|
134 | while(1) |
---|
135 | { |
---|
136 | addscreenrc(screen, tmp); |
---|
137 | rcret = waitrc(screen, 0, 0); |
---|
138 | tmp = listbox->select; |
---|
139 | if(rcret == getrcconfigint("rcexit", NULL)) //user pressed exit so no change |
---|
140 | break; |
---|
141 | if(rcret == getrcconfigint("rcred", NULL)) //red means "cancel shutdowntimer" |
---|
142 | { |
---|
143 | status.sd_timer->active = 0; |
---|
144 | status.sd_timer->shutdown_time = time(NULL); |
---|
145 | break; |
---|
146 | } |
---|
147 | if(rcret == getrcconfigint("rcok", NULL)) //ok means "activate shutdowntimer" |
---|
148 | { |
---|
149 | if(minutes->ret != NULL) |
---|
150 | { |
---|
151 | addconfigscreencheck("fixshutdowntime", fixshutdowntime, "0"); |
---|
152 | status.fixpowerofftime = 0; |
---|
153 | addconfigscreencheck("shutdowntimetype", shutdowntimetype, "0"); |
---|
154 | if(atoi(minutes->ret) == 0) break; |
---|
155 | status.sd_timer->shutdown_time = atoll(minutes->ret) * 60 + (long long)time(NULL); |
---|
156 | status.sd_timer->active = 1; |
---|
157 | debug(100, "found: time=%s, type=%d, secs=%lld, now=%ld", minutes->ret, getconfigint("shutdowntimetype", NULL), status.sd_timer->shutdown_time, time(NULL)); |
---|
158 | break; |
---|
159 | } |
---|
160 | } |
---|
161 | if(rcret == getrcconfigint("rcgreen", NULL)) //green means "use epg end time of current program" |
---|
162 | { |
---|
163 | struct epg* epgnode = getepgakt(status.aktservice->channel); |
---|
164 | if(epgnode != NULL) |
---|
165 | { |
---|
166 | min = (epgnode->endtime - time(NULL)) / 60 + 1; |
---|
167 | char *tmpstr = (char*)malloc(4 * sizeof(char)); |
---|
168 | if(tmpstr != NULL) snprintf(tmpstr, 4, "%03d", min); |
---|
169 | debug(100, "blue: %s %d", tmpstr, min); |
---|
170 | changeinput(minutes, tmpstr); |
---|
171 | free(tmpstr); tmpstr = NULL; |
---|
172 | drawscreen(screen, 0, 0); |
---|
173 | } |
---|
174 | } |
---|
175 | if(listbox->select != NULL && ostrcmp(listbox->select->name, "minutes") == 0) |
---|
176 | { |
---|
177 | if(rcret == getrcconfigint("rcff", NULL)) |
---|
178 | { |
---|
179 | if(minutes->ret != NULL) |
---|
180 | { |
---|
181 | int min = atoi(minutes->ret); |
---|
182 | min += 5; |
---|
183 | if(min > 999) min = 999; |
---|
184 | char *tmpstr = NULL; |
---|
185 | tmpstr = oitoa(min); |
---|
186 | changeinput(minutes, tmpstr); |
---|
187 | minutes->input = mask(minutes->input, 3, "0"); |
---|
188 | free(tmpstr); tmpstr = NULL; |
---|
189 | drawscreen(screen, 0, 0); |
---|
190 | } |
---|
191 | } |
---|
192 | if(rcret == getrcconfigint("rcfr", NULL)) |
---|
193 | { |
---|
194 | if(minutes->ret != NULL) |
---|
195 | { |
---|
196 | int min = atoi(minutes->ret); |
---|
197 | min -= 5; |
---|
198 | if(min < 0) min = 0; |
---|
199 | char *tmpstr = NULL; |
---|
200 | tmpstr = oitoa(min); |
---|
201 | changeinput(minutes, tmpstr); |
---|
202 | minutes->input = mask(minutes->input, 3, "0"); |
---|
203 | free(tmpstr); tmpstr = NULL; |
---|
204 | drawscreen(screen, 0, 0); |
---|
205 | } |
---|
206 | } |
---|
207 | if(rcret == getrcconfigint("rcsleep", NULL)) |
---|
208 | { |
---|
209 | if(minutes->ret != NULL) |
---|
210 | { |
---|
211 | int min = atoi(minutes->ret); |
---|
212 | min += 30; |
---|
213 | if(min > 180) min = 30; |
---|
214 | char *tmpstr = NULL; |
---|
215 | tmpstr = oitoa(min); |
---|
216 | changeinput(minutes, tmpstr); |
---|
217 | minutes->input = mask(minutes->input, 3, "0"); |
---|
218 | free(tmpstr); tmpstr = NULL; |
---|
219 | drawscreen(screen, 0, 0); |
---|
220 | } |
---|
221 | } |
---|
222 | } |
---|
223 | } |
---|
224 | |
---|
225 | delownerrc(screen); |
---|
226 | clearscreen(screen); |
---|
227 | } |
---|
228 | |
---|
229 | #endif |
---|