1 | #ifndef POWEROFFTIMER_H |
---|
2 | #define POWEROFFTIMER_H |
---|
3 | |
---|
4 | void checkshutdowntimer() |
---|
5 | { |
---|
6 | if(status.sd_timer != NULL && status.sd_timer->active && status.sd_timer->shutdown_time < time(NULL)) |
---|
7 | { |
---|
8 | status.sd_timer->active = 0; |
---|
9 | if(status.sd_timer->type == 0) |
---|
10 | oshutdown(1, 0); |
---|
11 | else |
---|
12 | { |
---|
13 | status.standby = 2; |
---|
14 | screenstandby(); |
---|
15 | } |
---|
16 | } |
---|
17 | } |
---|
18 | |
---|
19 | void free_shutdowntimervar() |
---|
20 | { |
---|
21 | if(status.sd_timer) |
---|
22 | { |
---|
23 | free(status.sd_timer); |
---|
24 | status.sd_timer=NULL; |
---|
25 | } |
---|
26 | } |
---|
27 | |
---|
28 | void screenpowerofftimer(void) |
---|
29 | { |
---|
30 | if(status.sd_timer==NULL) //first call |
---|
31 | { |
---|
32 | status.sd_timer=(struct shutdowntimer*) malloc(sizeof(struct shutdowntimer)); |
---|
33 | if(!status.sd_timer) |
---|
34 | { |
---|
35 | err("can't allocate memory for variable"); |
---|
36 | return; |
---|
37 | } |
---|
38 | status.sd_timer->active=0; |
---|
39 | status.sd_timer->type=0; |
---|
40 | status.sd_timer->shutdown_time=time(NULL); |
---|
41 | } |
---|
42 | |
---|
43 | int rcret = 0; |
---|
44 | struct skin* screen = getscreen("powerofftimerscreen"); |
---|
45 | struct skin* listbox = getscreennode(screen, "listbox"); |
---|
46 | struct skin* minutes = getscreennode(screen, "minutes"); |
---|
47 | struct skin* mode = getscreennode(screen, "mode"); |
---|
48 | |
---|
49 | |
---|
50 | long long secs=0; |
---|
51 | if(status.sd_timer->active) //calculate minutes until previously scheduled shutdown |
---|
52 | { |
---|
53 | secs=status.sd_timer->shutdown_time-(long long)time(NULL); |
---|
54 | if(secs<=0) secs=1800; //oops, we should already be shut down or at least almost;) |
---|
55 | } |
---|
56 | int min=((float)secs/60 + 0.5); |
---|
57 | if(min>1000) min=999; |
---|
58 | char *tmpstr=(char *) malloc(4*sizeof(char)) ; |
---|
59 | snprintf(tmpstr,4,"%03d",min); |
---|
60 | changemask(minutes, "000"); |
---|
61 | changeinput(minutes,tmpstr); |
---|
62 | free(tmpstr); |
---|
63 | |
---|
64 | if(!status.sd_timer->type) //use old value as default |
---|
65 | { |
---|
66 | addchoicebox(mode, "0", _("DeepStandby")); |
---|
67 | addchoicebox(mode, "1", _("Standby")); |
---|
68 | } |
---|
69 | else |
---|
70 | { |
---|
71 | addchoicebox(mode, "1", _("Standby")); |
---|
72 | addchoicebox(mode, "0", _("DeepStandby")); |
---|
73 | } |
---|
74 | drawscreen(screen,0); |
---|
75 | addscreenrc(screen, listbox); |
---|
76 | listbox->aktline = 1; |
---|
77 | listbox->aktpage = 1; |
---|
78 | struct skin* tmp = NULL; |
---|
79 | tmp = listbox->select; |
---|
80 | |
---|
81 | while(1) |
---|
82 | { |
---|
83 | addscreenrc(screen, tmp); |
---|
84 | rcret = waitrc(screen, 0, 0); |
---|
85 | tmp = listbox->select; |
---|
86 | if(rcret==getrcconfigint("rcexit",NULL)) //user pressed exit so no change |
---|
87 | { |
---|
88 | //fprintf(stderr,"shutdowntimerscreen cancelled\n"); |
---|
89 | break; |
---|
90 | } |
---|
91 | if(rcret==getrcconfigint("rcred",NULL)) //red means "cancel shutdowntimer" |
---|
92 | { |
---|
93 | //fprintf(stderr,"shutdowntimer cancelled\n"); |
---|
94 | status.sd_timer->active=0; |
---|
95 | status.sd_timer->shutdown_time=time(NULL); |
---|
96 | break; |
---|
97 | } |
---|
98 | if(rcret==getrcconfigint("rcok",NULL)) //ok means "activate shutdowntimer" |
---|
99 | { |
---|
100 | if(atoi(minutes->ret)==0) break; |
---|
101 | status.sd_timer->shutdown_time=atoll(minutes->ret)*60+(long long)time(NULL); |
---|
102 | status.sd_timer->active=1; |
---|
103 | if(mode->ret != NULL) |
---|
104 | status.sd_timer->type=atoi(mode->ret); |
---|
105 | fprintf(stderr,"found: time=%s, type=%s, secs=%lld, now=%ld\n",minutes->ret,mode->ret,status.sd_timer->shutdown_time,time(NULL)); |
---|
106 | break; |
---|
107 | } |
---|
108 | if(rcret==getrcconfigint("rcblue",NULL)) //blue means "use epg end time of current program" |
---|
109 | { |
---|
110 | struct epg* epgnode = getepgakt(status.aktservice->channel); |
---|
111 | if(epgnode != NULL) |
---|
112 | { |
---|
113 | min = (epgnode->endtime-time(NULL))/60+1; |
---|
114 | char *tmpstr=(char *) malloc(4*sizeof(char)) ; |
---|
115 | snprintf(tmpstr,4,"%03d",min); |
---|
116 | fprintf(stderr,"blue: %s %d\n",tmpstr,min); |
---|
117 | changeinput(minutes,tmpstr); |
---|
118 | free(tmpstr); |
---|
119 | drawscreen(screen,0); |
---|
120 | } |
---|
121 | } |
---|
122 | } |
---|
123 | |
---|
124 | delownerrc(screen); |
---|
125 | clearscreen(screen); |
---|
126 | } |
---|
127 | |
---|
128 | #endif |
---|