1 | #include "../../titan/struct.h" |
---|
2 | #include "../../titan/debug.h" |
---|
3 | #include "../../titan/header.h" |
---|
4 | #include "../../titan/list.h" |
---|
5 | |
---|
6 | char pluginname[] = "Stop if not used"; |
---|
7 | char plugindesc[] = "Auschalten der Box wenn in einem bestimmten Zeitraum keine Aktion erfolgte"; |
---|
8 | char pluginpic[] = "%pluginpath%/stopifnotused/stopifnotused.png"; |
---|
9 | |
---|
10 | int pluginaktiv = 0; |
---|
11 | int pluginversion = PLUGINVERSION; |
---|
12 | //int pluginversion = 999999; |
---|
13 | |
---|
14 | struct stimerthread* StopIfNotUsed = NULL; |
---|
15 | |
---|
16 | void StopIfNotUsed_thread() |
---|
17 | { |
---|
18 | int tostop = 0; |
---|
19 | sleep(30); |
---|
20 | status.lastrcaction = time(NULL); |
---|
21 | while (StopIfNotUsed->aktion != STOP) |
---|
22 | { |
---|
23 | if(status.standby != 1) |
---|
24 | { |
---|
25 | if(getconfig("stopifnotused_timetostop", NULL) == NULL) |
---|
26 | tostop = 120*60; |
---|
27 | else |
---|
28 | tostop = atoi(getconfig("stopifnotused_timetostop", NULL)) * 60; |
---|
29 | |
---|
30 | if((time(NULL) - status.lastrcaction) >= tostop && status.recording <= 0) |
---|
31 | { |
---|
32 | if (textbox(_("Message"), _("You have executed a defined period of no function.\n\nStop the box??? "), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 650, 200,15, 0) != 2) |
---|
33 | { |
---|
34 | if(getconfig("stopifnotused_stopaction", NULL) == NULL) |
---|
35 | { |
---|
36 | oshutdown(1, 1); |
---|
37 | break; |
---|
38 | } |
---|
39 | else if(atoi(getconfig("stopifnotused_stopaction", NULL)) == 1) |
---|
40 | { |
---|
41 | oshutdown(1, 1); |
---|
42 | break; |
---|
43 | } |
---|
44 | else |
---|
45 | { |
---|
46 | status.standby = 1; |
---|
47 | screenstandby(); |
---|
48 | } |
---|
49 | } |
---|
50 | } |
---|
51 | } |
---|
52 | sleep(10); |
---|
53 | } |
---|
54 | StopIfNotUsed = NULL; |
---|
55 | } |
---|
56 | |
---|
57 | //wird beim laden ausgefuehrt |
---|
58 | void init(void) |
---|
59 | { |
---|
60 | char* tmpstr = NULL; |
---|
61 | pluginaktiv = 1; |
---|
62 | |
---|
63 | tmpstr = createpluginpath("/stopifnotused/skin.xml", 0); |
---|
64 | readscreen(tmpstr, 117, 1); |
---|
65 | free(tmpstr); tmpstr = NULL; |
---|
66 | debug(10, "Stop if not used Plugin loadet !!!"); |
---|
67 | if(ostrcmp(getconfig("stopifnotused_autostart", NULL), "ja") == 0) |
---|
68 | StopIfNotUsed = addtimer(&StopIfNotUsed_thread, START, 10000, 1, NULL, NULL, NULL); |
---|
69 | } |
---|
70 | |
---|
71 | //wird beim entladen ausgefuehrt |
---|
72 | void deinit(void) |
---|
73 | { |
---|
74 | pluginaktiv = 0; |
---|
75 | debug(10, "Stop if not used removed !!!"); |
---|
76 | delmarkedscreen(117); |
---|
77 | } |
---|
78 | |
---|
79 | //wird in der Pluginverwaltung bzw Menue ausfeguehrt |
---|
80 | void start(void) |
---|
81 | { |
---|
82 | int rcret = 0; |
---|
83 | int running = 0; |
---|
84 | |
---|
85 | struct skin* notused_main = getscreen("notused_main"); |
---|
86 | struct skin* listbox = getscreennode(notused_main, "listbox"); |
---|
87 | struct skin* autostart = getscreennode(notused_main, "autostart"); |
---|
88 | struct skin* timetostop = getscreennode(notused_main, "timetostop"); |
---|
89 | struct skin* stopaction = getscreennode(notused_main, "stopaction"); |
---|
90 | struct skin* startstop = getscreennode(notused_main, "b3"); |
---|
91 | struct skin* tmp = NULL; |
---|
92 | |
---|
93 | |
---|
94 | addchoicebox(autostart, "ja", _("yes")); |
---|
95 | addchoicebox(autostart, "nein", _("no")); |
---|
96 | if(getconfig("stopifnotused_autostart", NULL) == NULL) |
---|
97 | setchoiceboxselection(autostart, "nein"); |
---|
98 | else |
---|
99 | setchoiceboxselection(autostart, getconfig("stopifnotused_autostart", NULL)); |
---|
100 | |
---|
101 | addchoicebox(timetostop, "30", _("30")); |
---|
102 | addchoicebox(timetostop, "60", _("60")); |
---|
103 | addchoicebox(timetostop, "90", _("90")); |
---|
104 | addchoicebox(timetostop, "120", _("120")); |
---|
105 | addchoicebox(timetostop, "180", _("180")); |
---|
106 | addchoicebox(timetostop, "240", _("240")); |
---|
107 | if(getconfig("stopifnotused_timetostop", NULL) == NULL) |
---|
108 | setchoiceboxselection(timetostop, "120"); |
---|
109 | else |
---|
110 | setchoiceboxselection(timetostop, getconfig("stopifnotused_timetostop", NULL)); |
---|
111 | |
---|
112 | addchoicebox(stopaction, "1", _("power off")); |
---|
113 | addchoicebox(stopaction, "2", _("standby")); |
---|
114 | if(getconfig("stopifnotused_stopaction", NULL) == NULL) |
---|
115 | setchoiceboxselection(stopaction, "1"); |
---|
116 | else |
---|
117 | setchoiceboxselection(stopaction, getconfig("stopifnotused_stopaction", NULL)); |
---|
118 | |
---|
119 | if(StopIfNotUsed == NULL) |
---|
120 | running = 0; |
---|
121 | else |
---|
122 | running = 1; |
---|
123 | |
---|
124 | if(running == 0) |
---|
125 | changetext(startstop, "Start"); |
---|
126 | else |
---|
127 | changetext(startstop, "Stop"); |
---|
128 | |
---|
129 | drawscreen(notused_main, 0, 0); |
---|
130 | addscreenrc(notused_main, listbox); |
---|
131 | |
---|
132 | tmp = listbox->select; |
---|
133 | |
---|
134 | while(1) |
---|
135 | { |
---|
136 | addscreenrc(notused_main, tmp); |
---|
137 | rcret = waitrc(notused_main, 0, 0); |
---|
138 | tmp = listbox->select; |
---|
139 | |
---|
140 | if(rcret == getrcconfigint("rcexit", NULL)) break; |
---|
141 | |
---|
142 | if(rcret == getrcconfigint("rcgreen", NULL)) |
---|
143 | { |
---|
144 | addconfig("stopifnotused_autostart", autostart->ret); |
---|
145 | addconfig("stopifnotused_timetostop", timetostop->ret); |
---|
146 | addconfig("stopifnotused_stopaction", stopaction->ret); |
---|
147 | break; |
---|
148 | } |
---|
149 | if(rcret == getrcconfigint("rcblue", NULL)) |
---|
150 | { |
---|
151 | if(running == 0) |
---|
152 | StopIfNotUsed = addtimer(&StopIfNotUsed_thread, START, 10000, 1, NULL, NULL, NULL); |
---|
153 | else |
---|
154 | StopIfNotUsed->aktion = STOP; |
---|
155 | break; |
---|
156 | } |
---|
157 | } |
---|
158 | |
---|
159 | delownerrc(notused_main); |
---|
160 | clearscreen(notused_main); |
---|
161 | } |
---|