1 | #include "../../titan/struct.h" |
---|
2 | #include "../../titan/debug.h" |
---|
3 | #include "../../titan/header.h" |
---|
4 | |
---|
5 | char pluginname[] = "Auto Timer"; |
---|
6 | char plugindesc[] = "Extensions"; |
---|
7 | char pluginpic[] = "%pluginpath%/autotimer/plugin.png"; |
---|
8 | |
---|
9 | int pluginaktiv = 0; |
---|
10 | int pluginversion = 999999; |
---|
11 | int autostart = 0; |
---|
12 | //struct skin* pluginmenu = NULL; |
---|
13 | //int pluginflag = 1; //don't show the plugin in pluginmanager |
---|
14 | |
---|
15 | struct rectimer *rectimer; |
---|
16 | |
---|
17 | struct searchoption |
---|
18 | { |
---|
19 | int starttime; |
---|
20 | int endtime; |
---|
21 | char* search; |
---|
22 | char* channelname; |
---|
23 | }; |
---|
24 | |
---|
25 | struct stimerthread* autotimerthread = NULL; |
---|
26 | |
---|
27 | |
---|
28 | void autotimer_thread() |
---|
29 | { |
---|
30 | char* tmpstr = NULL; |
---|
31 | char* buf = NULL; |
---|
32 | char* result = NULL; |
---|
33 | struct searchoption* search1 = NULL; |
---|
34 | struct channel *channel1 = NULL; |
---|
35 | struct epg* epgnode = NULL; |
---|
36 | struct tm *loctime = NULL; |
---|
37 | struct rectimer *node = NULL; |
---|
38 | struct rectimer* recnode = rectimer; |
---|
39 | int channelfind = 0; |
---|
40 | int epg_starttime = 0; |
---|
41 | //int epg_endtime = 0; |
---|
42 | int tageswechsel = 0; |
---|
43 | int write_note = 0; |
---|
44 | int i = 0; |
---|
45 | int konflikt = 0; |
---|
46 | |
---|
47 | buf = malloc(MINMALLOC); |
---|
48 | if(buf == NULL) |
---|
49 | { |
---|
50 | err("no mem"); |
---|
51 | return; |
---|
52 | } |
---|
53 | search1 = (struct searchoption*)calloc(1, sizeof(struct searchoption)); |
---|
54 | if(search1 == NULL) |
---|
55 | { |
---|
56 | err("no memory"); |
---|
57 | return; |
---|
58 | } |
---|
59 | search1->search = getconfig("at1_search", NULL); |
---|
60 | if(search1->search == NULL) |
---|
61 | { |
---|
62 | autotimerthread->aktion = STOP; |
---|
63 | } |
---|
64 | search1->channelname = getconfig("at1_channelname", NULL); |
---|
65 | if(search1->channelname == NULL) |
---|
66 | { |
---|
67 | autotimerthread->aktion = STOP; |
---|
68 | } |
---|
69 | tmpstr = ostrcat(tmpstr, getconfig("at1_starttime", NULL), 1, 0); |
---|
70 | if(tmpstr == NULL) |
---|
71 | { |
---|
72 | autotimerthread->aktion = STOP; |
---|
73 | } |
---|
74 | else |
---|
75 | { |
---|
76 | tmpstr[2] = '\0'; |
---|
77 | tmpstr[5] = '\0'; |
---|
78 | search1->starttime = (atoi(tmpstr) * 100) + atoi(tmpstr+3); |
---|
79 | } |
---|
80 | free(tmpstr); tmpstr = NULL; |
---|
81 | |
---|
82 | tmpstr = ostrcat(tmpstr, getconfig("at1_endtime", NULL), 1, 0); |
---|
83 | if(tmpstr == NULL) |
---|
84 | { |
---|
85 | autotimerthread->aktion = STOP; |
---|
86 | } |
---|
87 | else |
---|
88 | { |
---|
89 | tmpstr[2] = '\0'; |
---|
90 | tmpstr[5] = '\0'; |
---|
91 | search1->endtime = (atoi(tmpstr) * 100) + atoi(tmpstr+3); |
---|
92 | } |
---|
93 | free(tmpstr); tmpstr = NULL; |
---|
94 | |
---|
95 | if( search1->starttime > search1->endtime) { |
---|
96 | search1->endtime = search1->endtime + 2400; |
---|
97 | tageswechsel = 1; |
---|
98 | } |
---|
99 | |
---|
100 | channel1 = channel; |
---|
101 | channelfind = 0; |
---|
102 | while(channel1 != NULL) |
---|
103 | { |
---|
104 | if(ostrcmp(channel1->name, search1->channelname) == 0) |
---|
105 | break; |
---|
106 | |
---|
107 | channel1 = channel1->next; |
---|
108 | } |
---|
109 | if(channel1 == NULL) |
---|
110 | { |
---|
111 | autotimerthread->aktion = STOP; |
---|
112 | } |
---|
113 | |
---|
114 | while (autotimerthread->aktion != STOP && autostart > 0) |
---|
115 | { |
---|
116 | sleep(1); |
---|
117 | autostart = autostart - 1; |
---|
118 | } |
---|
119 | |
---|
120 | while (autotimerthread->aktion != STOP) |
---|
121 | { |
---|
122 | sleep(10); |
---|
123 | i = 0; |
---|
124 | node = NULL; |
---|
125 | write_note = 0; |
---|
126 | epgnode = getepgakt(channel1); |
---|
127 | while(epgnode != NULL) |
---|
128 | { |
---|
129 | result = NULL; |
---|
130 | loctime = olocaltime(&epgnode->starttime); |
---|
131 | strftime(buf, MINMALLOC, "%H%M", loctime); |
---|
132 | epg_starttime = atoi(buf); |
---|
133 | free(loctime); loctime = NULL; |
---|
134 | if(tageswechsel == 1 && epg_starttime < search1->starttime) |
---|
135 | epg_starttime = epg_starttime + 2400; |
---|
136 | if(epg_starttime >= search1->starttime && epg_starttime <= search1->endtime) |
---|
137 | { |
---|
138 | if(epgnode->title != NULL) |
---|
139 | result = ostrstrcase(epgnode->title, search1->search); |
---|
140 | if(result != NULL) |
---|
141 | { |
---|
142 | if(node == NULL) |
---|
143 | { |
---|
144 | node = addrectimernode(NULL, NULL); |
---|
145 | node->disabled = 1; |
---|
146 | } |
---|
147 | else if(node->disabled == 0) |
---|
148 | { |
---|
149 | node = addrectimernode(NULL, NULL); |
---|
150 | node->disabled = 1; |
---|
151 | } |
---|
152 | |
---|
153 | node->begin = epgnode->starttime; |
---|
154 | node->begin -= getconfigint("recforerun" , NULL) * 60; |
---|
155 | node->begin -= (node->begin % 60); |
---|
156 | node->end = epgnode->endtime; |
---|
157 | node->end += getconfigint("recoverrun" , NULL) * 60; |
---|
158 | node->end -= (node->end % 60); |
---|
159 | node->transponderid = channel1->transponderid; |
---|
160 | recnode = rectimer; |
---|
161 | konflikt = 0; |
---|
162 | while(recnode != NULL) |
---|
163 | { |
---|
164 | if(recnode != node && recnode->status < 2) |
---|
165 | { |
---|
166 | if((node->begin >= recnode->begin && node->begin < recnode->end) || (node->end >= recnode->begin && node->end < recnode->end)) |
---|
167 | { |
---|
168 | konflikt = 1; |
---|
169 | break; |
---|
170 | } |
---|
171 | } |
---|
172 | recnode = recnode->next; |
---|
173 | } |
---|
174 | |
---|
175 | if(konflikt == 0) |
---|
176 | { |
---|
177 | node->pincode = ostrcat("0000", NULL, 0, 0); |
---|
178 | node->recpath = ostrcat(NULL, getconfig("rec_path", NULL), 0, 0); |
---|
179 | node->afterevent = 0; |
---|
180 | node->repeate = 0; |
---|
181 | node->justplay = getconfigint("at1_event", NULL); |
---|
182 | node->afterevent = getconfigint("at1_afterevent", NULL); |
---|
183 | node->serviceid = channel1->serviceid; |
---|
184 | node->servicetype = channel1->servicetype; |
---|
185 | node->disabled = 0; |
---|
186 | node->name = ostrcat(epgnode->title, NULL, 0, 0); |
---|
187 | write_note = 1; |
---|
188 | } |
---|
189 | } |
---|
190 | } |
---|
191 | epgnode = epgnode->next; |
---|
192 | } |
---|
193 | if(node != NULL) |
---|
194 | { |
---|
195 | if(write_note == 1) |
---|
196 | { |
---|
197 | if(node->disabled == 1) |
---|
198 | delrectimer(node, 1, 0); |
---|
199 | else |
---|
200 | { |
---|
201 | status.writerectimer = 1; |
---|
202 | writerectimer(getconfig("rectimerfile", NULL), 0); |
---|
203 | } |
---|
204 | } |
---|
205 | else |
---|
206 | delrectimer(node, 0, 0); |
---|
207 | } |
---|
208 | while (autotimerthread->aktion != STOP && i < 43200) |
---|
209 | { |
---|
210 | sleep(2); |
---|
211 | } |
---|
212 | } |
---|
213 | free(buf); buf = NULL; |
---|
214 | search1->channelname = NULL; |
---|
215 | search1->search = NULL; |
---|
216 | free(search1); search1 = NULL; |
---|
217 | autotimerthread = NULL; |
---|
218 | return; |
---|
219 | } |
---|
220 | |
---|
221 | |
---|
222 | void autotimer_main() |
---|
223 | { |
---|
224 | autostart = 0; |
---|
225 | if(getconfigint("at1_running", NULL) == 1) |
---|
226 | { |
---|
227 | if(autotimerthread == NULL) |
---|
228 | autotimerthread = addtimer(&autotimer_thread, START, 10000, 1, NULL, NULL, NULL); |
---|
229 | } |
---|
230 | else |
---|
231 | { |
---|
232 | if(autotimerthread != NULL) |
---|
233 | autotimerthread->aktion = STOP; |
---|
234 | } |
---|
235 | } |
---|
236 | |
---|
237 | //wird beim laden ausgefuehrt |
---|
238 | void init(void) |
---|
239 | { |
---|
240 | char* tmpstr = NULL; |
---|
241 | pluginaktiv = 1; |
---|
242 | tmpstr = ostrcat(getconfig("pluginpath", NULL), "/autotimer/skin.xml", 0, 0); |
---|
243 | readscreen(tmpstr, 120, 1); |
---|
244 | free(tmpstr); tmpstr = NULL; |
---|
245 | debug(10, "Autot Timer Plugin loadet !!!"); |
---|
246 | if(getconfigint("at1_running", NULL) == 1) |
---|
247 | { |
---|
248 | if(autotimerthread == NULL) |
---|
249 | { |
---|
250 | autostart = 120; |
---|
251 | autotimerthread = addtimer(&autotimer_thread, START, 10000, 1, NULL, NULL, NULL); |
---|
252 | } |
---|
253 | } |
---|
254 | } |
---|
255 | |
---|
256 | //wird beim entladen ausgefuehrt |
---|
257 | void deinit(void) |
---|
258 | { |
---|
259 | if(autotimerthread != NULL) |
---|
260 | autotimerthread->aktion = STOP; |
---|
261 | delmarkedscreen(120); |
---|
262 | pluginaktiv = 0; |
---|
263 | debug(10, "Autot Timer removed !!!"); |
---|
264 | } |
---|
265 | |
---|
266 | //wird in der Pluginverwaltung bzw Menue ausfeguehrt |
---|
267 | void start(void) |
---|
268 | { |
---|
269 | char* tmpstr = NULL; |
---|
270 | int rcret; |
---|
271 | |
---|
272 | struct skin* autotimer = getscreen("autotimer"); |
---|
273 | struct skin* autotimer_listbox = getscreennode(autotimer, "listbox"); |
---|
274 | struct skin* autotimer_channel = getscreennode(autotimer, "channel"); |
---|
275 | struct skin* autotimer_search = getscreennode(autotimer, "search"); |
---|
276 | struct skin* autotimer_begin = getscreennode(autotimer, "begin"); |
---|
277 | struct skin* autotimer_event = getscreennode(autotimer, "event"); |
---|
278 | struct skin* autotimer_afterevent = getscreennode(autotimer, "afterevent"); |
---|
279 | struct skin* autotimer_end = getscreennode(autotimer, "end"); |
---|
280 | struct skin* autotimer_blue = getscreennode(autotimer, "blue"); |
---|
281 | struct skin* tmp = NULL; |
---|
282 | |
---|
283 | autostart = 0; |
---|
284 | |
---|
285 | if(autotimerthread == NULL) |
---|
286 | changetext(autotimer_blue, "start"); |
---|
287 | else |
---|
288 | changetext(autotimer_blue, "stop"); |
---|
289 | |
---|
290 | changemask(autotimer_channel, "abcdefghijklmnopqrstuvwxyz"); |
---|
291 | changeinput(autotimer_channel, getconfig("at1_channelname", NULL)); |
---|
292 | |
---|
293 | changemask(autotimer_search, "abcdefghijklmnopqrstuvwxyz"); |
---|
294 | changeinput(autotimer_search, getconfig("at1_search", NULL)); |
---|
295 | |
---|
296 | changemask(autotimer_begin, "00:00"); |
---|
297 | if(getconfig("at1_starttime", NULL)== NULL) |
---|
298 | changeinput(autotimer_begin, "00:00"); |
---|
299 | else |
---|
300 | changeinput(autotimer_begin, getconfig("at1_starttime", NULL)); |
---|
301 | |
---|
302 | changemask(autotimer_end, "00:00"); |
---|
303 | if(getconfig("at1_endtime", NULL) == NULL) |
---|
304 | changeinput(autotimer_end, "23:59"); |
---|
305 | else |
---|
306 | changeinput(autotimer_end, getconfig("at1_endtime", NULL)); |
---|
307 | |
---|
308 | addchoicebox(autotimer_event, "0", _("record")); |
---|
309 | addchoicebox(autotimer_event, "1", _("switch channel")); |
---|
310 | setchoiceboxselection(autotimer_event, getconfig("at1_event", NULL)); |
---|
311 | |
---|
312 | addchoicebox(autotimer_afterevent, "0", _("auto")); |
---|
313 | addchoicebox(autotimer_afterevent, "1", _("nothing")); |
---|
314 | addchoicebox(autotimer_afterevent, "2", _("standby")); |
---|
315 | addchoicebox(autotimer_afterevent, "3", _("power off")); |
---|
316 | setchoiceboxselection(autotimer_afterevent, getconfig("at1_afterevent", NULL)); |
---|
317 | |
---|
318 | drawscreen(autotimer, 0, 0); |
---|
319 | addscreenrc(autotimer, autotimer_listbox); |
---|
320 | tmp = autotimer_listbox->select; |
---|
321 | |
---|
322 | while(1) |
---|
323 | { |
---|
324 | addscreenrc(autotimer, tmp); |
---|
325 | rcret = waitrc(autotimer, 0, 0); |
---|
326 | tmp = autotimer_listbox->select; |
---|
327 | |
---|
328 | if (rcret == getrcconfigint("rcexit", NULL)) break; |
---|
329 | if (rcret == getrcconfigint("rcblue", NULL)) |
---|
330 | { |
---|
331 | if(autotimerthread != NULL) |
---|
332 | { |
---|
333 | autotimerthread->aktion = STOP; |
---|
334 | sleep(3); |
---|
335 | if(autotimerthread == NULL) |
---|
336 | { |
---|
337 | textbox(_("Stop AutoTimer"), _("AutoTimer succesfull stopped"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0); |
---|
338 | changetext(autotimer_blue, "start"); |
---|
339 | addconfigint("at1_running", 0); |
---|
340 | } |
---|
341 | else |
---|
342 | { |
---|
343 | textbox(_("Stop AutoTimer"), _("ERROR... AutoTimer not stopped"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0); |
---|
344 | addconfigint("at1_running", 1); |
---|
345 | } |
---|
346 | } |
---|
347 | else |
---|
348 | { |
---|
349 | addconfig("at1_channelname", autotimer_channel->ret); |
---|
350 | addconfig("at1_search", autotimer_search->ret); |
---|
351 | addconfig("at1_starttime", autotimer_begin->ret); |
---|
352 | addconfig("at1_endtime", autotimer_end->ret); |
---|
353 | addconfig("at1_event", autotimer_event->ret); |
---|
354 | addconfig("at1_afterevent", autotimer_afterevent->ret); |
---|
355 | autotimerthread = addtimer(&autotimer_thread, START, 10000, 1, NULL, NULL, NULL); |
---|
356 | sleep(1); |
---|
357 | if(autotimerthread != NULL) |
---|
358 | { |
---|
359 | textbox(_("Start AutoTimer"), _("AutoTimer succesfull started"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0); |
---|
360 | changetext(autotimer_blue, "stop"); |
---|
361 | addconfigint("at1_running", 1); |
---|
362 | } |
---|
363 | else |
---|
364 | { |
---|
365 | addconfigint("at1_running", 0); |
---|
366 | textbox(_("Start AutoTimer"), _("ERROR... AutoTimer not started"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0); |
---|
367 | } |
---|
368 | } |
---|
369 | } |
---|
370 | if (rcret == getrcconfigint("rcgreen", NULL)) |
---|
371 | { |
---|
372 | addconfig("at1_channelname", autotimer_channel->ret); |
---|
373 | addconfig("at1_search", autotimer_search->ret); |
---|
374 | addconfig("at1_starttime", autotimer_begin->ret); |
---|
375 | addconfig("at1_endtime", autotimer_end->ret); |
---|
376 | addconfig("at1_event", autotimer_event->ret); |
---|
377 | addconfig("at1_afterevent", autotimer_afterevent->ret); |
---|
378 | if(getconfigint("at1_running", NULL) == 1) |
---|
379 | { |
---|
380 | autotimerthread->aktion = STOP; |
---|
381 | sleep(2); |
---|
382 | if(autotimerthread == NULL) |
---|
383 | autotimerthread = addtimer(&autotimer_thread, START, 10000, 1, NULL, NULL, NULL); |
---|
384 | } |
---|
385 | textbox(_("Save Settings"), _("Settings succesfull saved"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0); |
---|
386 | } |
---|
387 | if (rcret == getrcconfigint("rcepg", NULL)) |
---|
388 | { |
---|
389 | if(status.aktservice->channel != NULL) |
---|
390 | { |
---|
391 | tmpstr = ostrcat(tmpstr, status.aktservice->channel->name, 1, 0); |
---|
392 | changeinput(autotimer_channel, tmpstr); |
---|
393 | tmpstr = NULL; |
---|
394 | } |
---|
395 | } |
---|
396 | |
---|
397 | |
---|
398 | drawscreen(autotimer, 0, 0); |
---|
399 | } |
---|
400 | delownerrc(autotimer); |
---|
401 | clearscreen(autotimer); |
---|
402 | } |
---|