source: titan/titan/rectimer.h @ 10958

Last change on this file since 10958 was 10958, checked in by nit, 12 years ago

[titan] change width/height from screendir

File size: 32.6 KB
Line 
1#ifndef RECTIMER_H
2#define RECTIMER_H
3
4void debugrectimer()
5{
6        struct rectimer* node = rectimer;
7
8        while(node != NULL)
9        {
10                printf("start: %lu end: %lu\n", node->begin, node->end);
11                node = node->next;
12        }
13}
14
15int checkrectimeradd(struct rectimer* recnode, char** ret)
16{
17        struct rectimer* node = rectimer;
18        int forerun = getconfigint("recforerun", NULL) * 60;
19        int overrun = getconfigint("recoverrun", NULL) * 60;
20
21        if(recnode == NULL)
22        {
23                *ret = "undefined error";
24                return 1;
25        }
26        if(recnode->begin == 0 || recnode->end == 0)
27        {
28                *ret = "Timer starttime or endtime not ok";
29                return 1;
30        }
31        if(recnode->end <= time(NULL))
32        {
33                *ret = "Timer endtime shorter than aktual time";
34                return 1;
35        }
36        if(recnode->end <= recnode->begin)
37        {
38                *ret = "Timer endtime shorter than start time";
39                return 1;
40        }
41        if(recnode->serviceid < 1)
42        {
43                *ret = "Timer service ID not ok";
44                return 1;
45        }
46        if(recnode->transponderid < 1)
47        {
48                *ret = "Timer transponder ID not ok";
49                return 1;
50        }
51
52        while(node != NULL)
53        {
54                if(recnode != node)
55                {
56                        if((recnode->begin - forerun >= node->begin - forerun && recnode->begin - forerun < node->end + overrun) || (recnode->end + overrun >= node->begin - forerun && recnode->end + overrun < node->end + overrun))
57                        {
58                                *ret = "Timer conflicts with other timer";
59                                return 2;
60                        }
61                }
62                node = node->next;
63        }
64
65        return 0;
66}
67
68void recrepeatecalc(struct rectimer* node)
69{
70        time_t daysec = 24 * 60 * 60;
71        struct tm* loctime = NULL;
72        int rectimerday = -1, rep = 0, i;
73
74        if(node->repeate == 0) return;
75
76        //get rectimer start day
77        loctime = olocaltime(&node->begin);
78        rectimerday = loctime->tm_wday - 1;
79        free(loctime); loctime = NULL;
80        if(rectimerday == -1) rectimerday = 6;
81
82        rep = (node->repeate & 0xff) | ((node->repeate  & 0xff) << 7);
83
84        for(i = 0; i < 7; i++)
85        {
86                node->begin = node->begin + daysec;
87                node->end = node->end + daysec;
88                rectimerday++;
89                if(rectimerday > 6) rectimerday = 0;
90                if(checkbit(rep, rectimerday) == 1)
91                        break;
92        }
93
94        //check if begin > akttime
95        while(node->begin < time(NULL))
96        {
97                for(i = 0; i < 7; i++)
98                {
99                        node->begin = node->begin + daysec;
100                        node->end = node->end + daysec;
101                        rectimerday++;
102                        if(rectimerday > 6) rectimerday = 0;
103                        if(checkbit(rep, rectimerday) == 1)
104                                break;
105                }
106        }
107}
108
109int checkrectimertime(struct rectimer* node)
110{
111        //don't load old timers
112        if(time(NULL) - node->end > 604800 && (node->status == 2 || node->status == 3))
113                return 1;
114
115        if(time(NULL) > node->end && node->repeate == 0 && node->status == 0)
116                return 1;
117
118        //recalc old repeat timer
119        if(time(NULL) > node->end && node->repeate != 0 && node->status == 0)
120                recrepeatecalc(node);
121
122        return 0;
123}
124
125void copyrectimer(struct rectimer* src, struct rectimer* dst)
126{
127        dst->name = ostrcat(src->name, "", 0, 0);
128        dst->begin = src->begin;
129        dst->end = src->end;
130        dst->repeate = src->repeate;
131        dst->afterevent = src->afterevent;
132        dst->disabled = src->disabled;
133        dst->justplay = src->justplay;
134        dst->recpath = ostrcat(src->recpath, "", 0, 0);
135        dst->servicetype = src->servicetype;
136        dst->channellist = ostrcat(src->channellist, "", 0, 0);
137        dst->serviceid = src->serviceid;
138        dst->transponderid = src->transponderid;
139}
140
141struct rectimer* addrectimernode(char* line, struct rectimer* last)
142{
143        debug(1000, "in");
144        char *ret = NULL;
145        struct rectimer *newnode = NULL, *prev = NULL, *node = rectimer;
146
147        newnode = (struct rectimer*)malloc(sizeof(struct rectimer));
148        if(newnode == NULL)
149        {
150                err("no memory");
151                return NULL;
152        }
153
154        memset(newnode, 0, sizeof(struct rectimer));
155        status.writerectimer = 1;
156
157        if(line != NULL)
158        {
159                ret = getxmlentry(line, " begin=");
160                if(ret != NULL)
161                {
162                        newnode->begin = atol(ret);
163                        free(ret);
164                }
165                ret = getxmlentry(line, " end=");
166                if(ret != NULL)
167                {
168                        newnode->end = atol(ret);
169                        free(ret);
170                }
171                ret = getxmlentry(line, " repeated=");
172                if(ret != NULL)
173                {
174                        newnode->repeate = atoi(ret);
175                        free(ret);
176                }
177                ret = getxmlentry(line, " afterevent=");
178                if(ret != NULL)
179                {
180                        newnode->afterevent = atoi(ret);
181                        free(ret);
182                }
183                ret = getxmlentry(line, " pincode=");
184                if(ret != NULL)
185                        newnode->pincode = ret;
186                ret = getxmlentry(line, " disabled=");
187                if(ret != NULL)
188                {
189                        newnode->disabled = atoi(ret);
190                        free(ret);
191                }
192                ret = getxmlentry(line, " justplay=");
193                if(ret != NULL)
194                {
195                        newnode->justplay = atoi(ret);
196                        free(ret);
197                }
198                ret = getxmlentry(line, " serviceid=");
199                if(ret != NULL)
200                {
201                        newnode->serviceid = atoi(ret);
202                        free(ret);
203                }
204                ret = getxmlentry(line, " transponderid=");
205                if(ret != NULL)
206                {
207                        newnode->transponderid = atol(ret);
208                        free(ret);
209                }
210                ret = getxmlentry(line, " status=");
211                if(ret != NULL)
212                {
213                        newnode->status = atol(ret);
214                        if(newnode->status == 1) newnode->status = 0;
215                        free(ret);
216                }
217                ret = getxmlentry(line, " name=");
218                if(ret != NULL)
219                        newnode->name = ret;
220                ret = getxmlentry(line, " recpath=");
221                if(ret != NULL)
222                        newnode->recpath = ret;
223                ret = getxmlentry(line, " channellist=");
224                if(ret != NULL)
225                        newnode->channellist = ret;
226                ret = getxmlentry(line, " errstr=");
227                if(ret != NULL)
228                        newnode->errstr = ret;
229
230                if(checkrectimertime(newnode) == 1)
231                {
232                        free(newnode);
233                        return NULL;
234                }
235        }
236        else
237                newnode->disabled = 1;
238
239        if(last == NULL)
240        {
241                while(node != NULL && newnode->begin <= node->begin)
242                {
243                        prev = node;
244                        node = node->next;
245                }
246        }
247        else
248        {
249                prev = last;
250                node = last->next;
251        }
252
253        if(prev == NULL)
254                rectimer = newnode;
255        else
256        {
257                prev->next = newnode;
258                newnode->prev = prev;
259        }
260        newnode->next = node;
261        if(node != NULL) node->prev = newnode;
262
263        debug(1000, "out");
264        return newnode;
265}
266
267struct rectimer* getrectimerbyservice(struct service* servicenode)
268{
269        struct rectimer* node = rectimer;       
270
271        while(node != NULL)
272        {
273                if(node->servicenode == servicenode)
274                        return node;
275
276                node = node->next;
277        }
278
279        return NULL;
280}
281
282void checkrectimer()
283{
284        int ret = 0, forerun = 0;
285        struct rectimer* node = rectimer, *newnode = NULL;
286        struct channel* chnode = NULL;
287        time_t t = time(NULL), begin = 0, end = 0;
288
289        forerun = getconfigint("recforerun", NULL) * 60;
290
291        m_lock(&status.rectimermutex, 1);
292       
293        while(node != NULL)
294        {
295                if(node->justplay == 1)
296                {
297                        begin = node->begin;
298                        end = node->end + 120;
299                }
300                else
301                {
302                        begin = node->begin - forerun;
303                        end = node->end;
304                }
305
306                if(t >= begin && t < end && node->disabled == 0 && node->status == 0)
307                {
308                        if(node->repeate != 0)
309                        {
310                                //copy repeate timer
311                                newnode = addrectimernode(NULL, NULL);
312                                if(newnode != NULL)
313                                {
314                                        copyrectimer(node, newnode);
315                                        recrepeatecalc(newnode);
316                                }
317                                node->repeate = 0;
318                                status.writerectimer = 1;
319                        }
320                        chnode = getchannel(node->serviceid, node->transponderid);
321                        if(node->justplay == 1)
322                        {
323                                ret = servicestart(chnode, NULL, node->channellist, 0);
324                                if(ret == 20 || ret == 22) ret = 0;
325                        }
326                        else
327                        {
328                                ret = recordstart(chnode, -1, 0, RECTIMER, node->end, node);
329                                if(ret == 14) ret = 0;
330                        }
331
332                        if(ret != 0)
333                        {
334                                node->status = 3;
335                                status.writerectimer = 1;
336                                break;
337                        }
338                        else
339                        {
340                                if(node->justplay == 1)
341                                        node->status = 2;
342                                else
343                                        node->status = 1;
344                                status.writerectimer = 1;
345                        }
346                }
347                if(t > node->end && node->status == 0 && node->end != 0)
348                {
349                        node->status = 3;
350                        free(node->errstr);
351                        node->errstr = ostrcat("not started akttime greater timer endtime", "", 0, 0);
352                        status.writerectimer = 1;
353                }
354                node = node->next;
355        }
356
357        m_unlock(&status.rectimermutex, 1);
358
359        if(node != NULL)
360        {
361                if(node->justplay == 1)
362                {
363                        char* retstr = servicecheckret(ret, 1);
364                        free(node->errstr);
365                        node->errstr = ostrcat(retstr, "", 0, 0);
366                        free(retstr); retstr = NULL;
367                }
368                else
369                {
370                        char* retstr = recordcheckret(NULL, ret, 15);
371                        free(node->errstr);
372                        node->errstr = ostrcat(retstr, "", 0, 0);
373                        free(retstr); retstr = NULL;
374                }
375                status.writerectimer = 1;
376        }
377
378        writerectimer(getconfig("rectimerfile", NULL), 0);
379}
380
381int addrectimer(char *buf)
382{
383        debug(1000, "in");
384        struct rectimer* node = NULL;
385        char* buf1 = buf;
386        char* line = NULL;
387
388        line = malloc(MINMALLOC);
389        if(line == NULL)
390        {
391                err("no memory");
392                return 1;
393        }
394
395        while(*buf != '\0')
396        {
397                buf++;
398                if(*buf == '\n' || *buf == '\0')
399                {
400                        if(*buf == '\n')
401                        {
402                                buf++;
403                                snprintf(line, buf - buf1, "%s", buf1);
404                        }
405                        else
406                                snprintf(line, buf - buf1 + 1, "%s", buf1);
407                        buf1 = buf;
408
409                        if(strstr(line, "<timer ") != NULL || strstr(line, "<log "))
410                                node = addrectimernode(line, node);
411                }
412        }
413        free(line);
414        debug(1000, "out");
415        return 0;
416}
417
418int readrectimer(char *filename)
419{
420        debug(1000, "in");
421        char *buf = NULL;
422
423        buf = readfiletomem(filename, 1);
424
425        if(buf != NULL)
426        {
427                addrectimer(buf);
428                //timers can change on load, so we save it
429                writerectimer(getconfig("rectimerfile", NULL), 0);
430                free(buf);
431        }
432        debug(1000, "out");
433        return 0;
434}
435
436//flag 0 = set mutex
437//flag 1 = don't set mutex
438void delrectimer(struct rectimer* rectimernode, int write, int flag)
439{
440        debug(1000, "in");
441        struct rectimer *node = rectimer, *prev = rectimer;
442
443        if(flag == 0)
444                m_lock(&status.rectimermutex, 1);
445
446        while(node != NULL)
447        {
448                if(node == rectimernode)
449                {
450                        status.writerectimer = 1;
451
452                        //record is aktiv (del from stopservice)
453                        if(node->servicenode != NULL)
454                        {
455                                node->status = 2;
456                                free(node->errstr);
457                                node->errstr = ostrcat("stopped from user", "", 0, 0);
458                                //stop recording
459                                node->servicenode->recendtime = 1;
460                                if(flag == 0)
461                                        m_unlock(&status.rectimermutex, 1);
462                                return;
463                        }
464
465                        if(node == rectimer)
466                        {
467                                rectimer = node->next;
468                                if(rectimer != NULL)
469                                        rectimer->prev = NULL;
470                        }
471                        else
472                        {
473                                prev->next = node->next;
474                                if(node->next != NULL)
475                                        node->next->prev = prev;
476                        }
477
478                        free(node->name);
479                        node->name = NULL;
480
481                        free(node->recpath);
482                        node->recpath = NULL;
483
484                        free(node->channellist);
485                        node->channellist = NULL;
486
487                        free(node->errstr);
488                        node->errstr = NULL;
489                       
490                        free(node->pincode);
491                        node->pincode = NULL;
492
493                        free(node);
494                        node = NULL;
495                        break;
496                }
497
498                prev = node;
499                node = node->next;
500        }
501
502        if(write == 1)
503                writerectimer(getconfig("rectimerfile", NULL), 1);
504
505        if(flag == 0)
506                m_unlock(&status.rectimermutex, 1);
507        debug(1000, "out");
508}
509
510void deloldrectimer()
511{
512        debug(1000, "in");
513        struct rectimer *node = rectimer, *prev = rectimer;
514
515        while(node != NULL)
516        {
517                prev = node;
518                node = node->next;
519                if(prev != NULL && checkrectimertime(prev) == 1)
520                        delrectimer(prev, 1, 0);
521        }
522        debug(1000, "out");
523}
524
525void freerectimer()
526{
527        debug(1000, "in");
528        struct rectimer *node = rectimer, *prev = rectimer;
529
530        while(node != NULL)
531        {
532                prev = node;
533                node = node->next;
534                if(prev != NULL)
535                        delrectimer(prev, 0, 0);
536        }
537        debug(1000, "out");
538}
539
540//flag 0: lock
541//flag 1: don't lock
542int writerectimer(const char *filename, int flag)
543{
544        debug(1000, "in");
545        FILE *fd = NULL;
546        struct rectimer *node = rectimer;
547        int ret = 0;
548        char* type = NULL;
549        time_t curtime = time(NULL), rectime = 0x7FFFFFFF;
550
551        if(status.writerectimer == 0) return 0;
552
553        if(flag == 0) m_lock(&status.rectimermutex, 1);
554
555        fd = fopen(filename, "w");
556        if(fd == NULL)
557        {
558                if(flag == 0) m_unlock(&status.rectimermutex, 1);
559                status.writerectimer = 0;
560                perr("can't open %s", filename);
561                return 1;
562        }
563
564        while(node != NULL)
565        {
566                //don't write for del marked or old timers
567                if(checkrectimertime(node) == 1)
568                {
569                        node = node->next;
570                        continue;
571                }
572
573                if(node->name == NULL) node->name = ostrcat(node->name, "", 1, 0);
574                if(node->channellist == NULL) node->channellist = ostrcat(node->channellist, "", 1, 0);
575                if(node->errstr == NULL) node->errstr = ostrcat(node->errstr, "", 1, 0);
576                if(node->pincode == NULL) node->pincode = ostrcat(node->pincode, "0000", 1, 0);
577                if(node->recpath == NULL) node->recpath = ostrcat(node->recpath, "", 1, 0);
578                if(node->status == 0 || node->status == 1)
579                        type = "timer";
580                else
581                        type = "log";
582
583                ret = fprintf(fd, "<%s begin=\"%lu\" end=\"%lu\" serviceid=\"%d\" transponderid=\"%lu\" channellist=\"%s\" repeated=\"%d\" name=\"%s\" afterevent=\"%d\" pincode=\"%s\" disabled=\"%d\" justplay=\"%d\", recpath=\"%s\", status=\"%d\" errstr=\"%s\">\n</%s>\n", type, node->begin, node->end, node->serviceid, node->transponderid, node->channellist, node->repeate, node->name, node->afterevent, node->pincode, node->disabled, node->justplay, node->recpath, node->status, node->errstr, type);
584
585                if(ret < 0)
586                {
587                        perr("writting file %s", filename);
588                }
589
590                //get wakeup time
591                if(node->status == 0 || node->status == 1)
592                {
593                        if(node->begin < rectime && node->begin > curtime)
594                                rectime = node->begin;
595                }
596                node = node->next;
597        }
598
599        fclose(fd);
600        //write wakeup time to proc
601        setwakeuptimerdev(rectime);
602
603        if(flag == 0) m_unlock(&status.rectimermutex, 1);
604
605        status.writerectimer = 0;
606        debug(1000, "out");
607        return 0;
608}
609
610int recrepeateget(struct skin* repeate, struct skin* repeatetype, struct skin* day, struct skin* mon, struct skin* tue, struct skin* wed, struct skin* thur, struct skin* fri, struct skin* sat, struct skin* sun)
611{
612        unsigned char ret = 0;
613
614        if(ostrcmp(repeate->ret, "0") == 0) return 0;
615
616        if(ostrcmp(repeatetype->ret, "0") == 0) return 127;
617        if(ostrcmp(repeatetype->ret, "1") == 0)
618        {
619                if(day->ret == NULL) return 1;
620                if(ostrcmp(day->ret, "0") == 0) return 1;
621                if(ostrcmp(day->ret, "1") == 0) return 2;
622                if(ostrcmp(day->ret, "2") == 0) return 4;
623                if(ostrcmp(day->ret, "3") == 0) return 8;
624                if(ostrcmp(day->ret, "4") == 0) return 16;
625                if(ostrcmp(day->ret, "5") == 0) return 32;
626                if(ostrcmp(day->ret, "6") == 0) return 64;
627        }
628        if(ostrcmp(repeatetype->ret, "2") == 0) return 31;
629        if(ostrcmp(repeatetype->ret, "3") == 0)
630        {
631                if(ostrcmp(mon->ret, "1") == 0) ret = setbit(ret, 0);
632                if(ostrcmp(tue->ret, "1") == 0) ret = setbit(ret, 1);
633                if(ostrcmp(wed->ret, "1") == 0) ret = setbit(ret, 2);
634                if(ostrcmp(thur->ret, "1") == 0) ret = setbit(ret, 3);
635                if(ostrcmp(fri->ret, "1") == 0) ret = setbit(ret, 4);
636                if(ostrcmp(sat->ret, "1") == 0) ret = setbit(ret, 5);
637                if(ostrcmp(sun->ret, "1") == 0) ret = setbit(ret, 6);
638                if(ret == 0) ret = 128;
639                return ret;
640        }
641
642        return 127;
643}
644
645void recjustplayhidden(int justplay, struct skin* end, struct skin* path, struct skin* after)
646{
647        if(justplay == 0)
648        {
649                end->hidden = NO;
650                path->hidden = NO;
651                after->hidden = NO;
652        }
653        else
654        {
655                end->hidden = YES;
656                path->hidden = YES;
657                after->hidden = YES;
658        }
659}
660
661void recrepeatehidden(int repeate, struct skin* repeatetype, struct skin* day, struct skin* mon, struct skin* tue, struct skin* wed, struct skin* thur, struct skin* fri, struct skin* sat, struct skin* sun)
662{
663        repeatetype->hidden = YES;
664        day->hidden = YES;
665        mon->hidden = YES;
666        tue->hidden = YES;
667        wed->hidden = YES;
668        thur->hidden = YES;
669        fri->hidden = YES;
670        sat->hidden = YES;
671        sun->hidden = YES;
672
673        if(repeate == 0) return;
674
675        if(repeate == 127) //dayly
676        {
677                repeatetype->hidden = NO;
678                setchoiceboxselection(repeatetype, "0");
679                return;
680        }
681        if(repeate == 31) //workday
682        {
683                repeatetype->hidden = NO;
684                setchoiceboxselection(repeatetype, "2");
685                return;
686        }
687        if(repeate == 1 || repeate == 2 || repeate == 4 || repeate == 8 || repeate == 16 || repeate == 32 || repeate == 64) //weekly
688        {
689                repeatetype->hidden = NO;
690                setchoiceboxselection(repeatetype, "1");
691                day->hidden = NO;
692                if(repeate == 1) setchoiceboxselection(day, "0");
693                else if(repeate == 2) setchoiceboxselection(day, "1");
694                else if(repeate == 4) setchoiceboxselection(day, "2");
695                else if(repeate == 8) setchoiceboxselection(day, "3");
696                else if(repeate == 16) setchoiceboxselection(day, "4");
697                else if(repeate == 32) setchoiceboxselection(day, "5");
698                else if(repeate == 64) setchoiceboxselection(day, "6");
699                return;
700        }
701
702        //user defined
703        repeatetype->hidden = NO;
704        setchoiceboxselection(repeatetype, "3");
705        mon->hidden = NO;
706        tue->hidden = NO;
707        wed->hidden = NO;
708        thur->hidden = NO;
709        fri->hidden = NO;
710        sat->hidden = NO;
711        sun->hidden = NO;
712        if(checkbit(repeate, 0) == 1) setchoiceboxselection(mon, "1");
713        if(checkbit(repeate, 1) == 1) setchoiceboxselection(tue, "1");
714        if(checkbit(repeate, 2) == 1) setchoiceboxselection(wed, "1");
715        if(checkbit(repeate, 3) == 1) setchoiceboxselection(thur, "1");
716        if(checkbit(repeate, 4) == 1) setchoiceboxselection(fri, "1");
717        if(checkbit(repeate, 5) == 1) setchoiceboxselection(sat, "1");
718        if(checkbit(repeate, 6) == 1) setchoiceboxselection(sun, "1");
719}
720
721//flag 0: don't del timer on exit
722//flag 1: del timer on exit
723void screenrectimerext(struct rectimer* node, int flag)
724{
725        int ret = 0, rcret = 0, edaylight = 0, bdaylight = 0, newnode = 0, tmpservicetype = 0, tmprepeate = 0;
726        struct skin* rectimerext = getscreen("rectimerext");
727        struct skin* listbox = getscreennode(rectimerext, "listbox");
728        struct skin* name = getscreennode(rectimerext, "name");
729        struct skin* justplay = getscreennode(rectimerext, "justplay");
730        struct skin* repeate = getscreennode(rectimerext, "repeate");
731        struct skin* repeatetype = getscreennode(rectimerext, "repeatetype");
732        struct skin* day = getscreennode(rectimerext, "day");
733        struct skin* mon = getscreennode(rectimerext, "mon");
734        struct skin* tue = getscreennode(rectimerext, "tue");
735        struct skin* wed = getscreennode(rectimerext, "wed");
736        struct skin* thur = getscreennode(rectimerext, "thur");
737        struct skin* fri = getscreennode(rectimerext, "fri");
738        struct skin* sat = getscreennode(rectimerext, "sat");
739        struct skin* sun = getscreennode(rectimerext, "sun");
740        struct skin* begin = getscreennode(rectimerext, "begin");
741        struct skin* end = getscreennode(rectimerext, "end");
742        struct skin* recchannel = getscreennode(rectimerext, "channel");
743        struct skin* path = getscreennode(rectimerext, "path");
744        struct skin* after = getscreennode(rectimerext, "after");
745        struct skin* pincode = getscreennode(rectimerext, "pincode");
746        struct skin* tmp = NULL;
747        char* tmpstr = NULL, *buf = NULL, *buf1 = NULL, *tmpchannellist = NULL;
748        struct tm* loctime = NULL;
749        time_t akttime = time(NULL);
750
751        if(node == NULL)
752        {
753                newnode = 1;
754                node = addrectimernode(NULL, NULL);
755                tmpservicetype = status.servicetype;
756                if(tmpservicetype == 0)
757                        tmpchannellist = ostrcat(getconfig("channellist", NULL), "", 0, 0);
758                else
759                        tmpchannellist = ostrcat(getconfig("rchannellist", NULL), "", 0, 0);
760        }
761        else
762        {
763                tmpservicetype = node->servicetype;
764                tmpchannellist = ostrcat(node->channellist, "", 0, 0);
765        }
766
767        if(node == NULL)
768        {
769                err("NULL detect");
770                return;
771        }
772
773        listbox->aktline = 1;
774        listbox->aktpage = -1;
775        begin->aktpage = 0;
776        end->aktpage = 0;
777        name->aktpage = 0;
778       
779        changeinput(name, node->name);
780
781        addchoicebox(justplay, "0", _("record"));
782        addchoicebox(justplay, "1", _("switch channel"));
783        if(newnode == 0)
784        {
785                tmpstr = oitoa(node->justplay);
786                setchoiceboxselection(justplay, tmpstr);
787                free(tmpstr); tmpstr = NULL;
788        }
789        else
790                setchoiceboxselection(justplay, "0");
791
792        addchoicebox(repeate, "0", _("once"));
793        addchoicebox(repeate, "1", _("repeate"));
794        if(newnode == 0)
795        {
796                tmprepeate = node->repeate;
797                if(node->repeate == 0)
798                        setchoiceboxselection(repeate, "0");
799                else
800                        setchoiceboxselection(repeate, "1");
801        }
802        else
803                setchoiceboxselection(repeate, "0");
804
805        addchoicebox(repeatetype, "0", _("daily"));
806        addchoicebox(repeatetype, "1", _("weekly"));
807        addchoicebox(repeatetype, "2", _("workdays"));
808        addchoicebox(repeatetype, "3", _("user defined"));
809        changeret(repeatetype, NULL);
810        setchoiceboxselection(repeatetype, "0");
811
812        addchoicebox(day, "0", _("Monday"));
813        addchoicebox(day, "1", _("Tuesday"));
814        addchoicebox(day, "2", _("Wednesday"));
815        addchoicebox(day, "3", _("Thursday"));
816        addchoicebox(day, "4", _("Friday"));
817        addchoicebox(day, "5", _("Saturday"));
818        addchoicebox(day, "6", _("Sunday"));
819        changeret(day, NULL);
820        setchoiceboxselection(day, "0");
821
822        addchoicebox(mon, "0", _("No"));
823        addchoicebox(mon, "1", _("Yes"));
824        changeret(mon, NULL);
825        setchoiceboxselection(mon, "0");
826
827        addchoicebox(tue, "0", _("No"));
828        addchoicebox(tue, "1", _("Yes"));
829        changeret(tue, NULL);
830        setchoiceboxselection(tue, "0");
831
832        addchoicebox(wed, "0", _("No"));
833        addchoicebox(wed, "1", _("Yes"));
834        changeret(wed, NULL);
835        setchoiceboxselection(wed, "0");
836
837        addchoicebox(thur, "0", _("No"));
838        addchoicebox(thur, "1", _("Yes"));
839        changeret(thur, NULL);
840        setchoiceboxselection(thur, "0");
841
842        addchoicebox(fri, "0", _("No"));
843        addchoicebox(fri, "1", _("Yes"));
844        changeret(fri, NULL);
845        setchoiceboxselection(fri, "0");
846
847        addchoicebox(sat, "0", _("No"));
848        addchoicebox(sat, "1", _("Yes"));
849        changeret(sat, NULL);
850        setchoiceboxselection(sat, "0");
851
852        addchoicebox(sun, "0", _("No"));
853        addchoicebox(sun, "1", _("Yes"));
854        changeret(sun, NULL);
855        setchoiceboxselection(sun, "0");
856
857        recrepeatehidden(node->repeate, repeatetype, day, mon, tue, wed, thur, fri, sat, sun);
858        recjustplayhidden(node->justplay, end, path, after);
859
860        buf = malloc(MINMALLOC);
861        if(buf == NULL)
862        {
863                err("no memory");
864                return;
865        }
866
867        changemask(begin, "00:00 00-00-0000");
868        if(newnode == 0)
869                loctime = localtime(&node->begin);
870        else
871                loctime = localtime(&akttime);
872        bdaylight = loctime->tm_isdst;
873        strftime(buf, MINMALLOC, "%H:%M %d-%m-%Y", loctime);
874        buf1 = ostrcat(buf, "", 0, 0);
875        changeinput(begin, buf1);
876        free(buf1); buf1 = NULL;
877
878        changemask(end, "00:00 00-00-0000");
879        if(newnode == 0)
880                loctime = localtime(&node->end);
881        else
882        {
883                akttime += 300;
884                loctime = localtime(&akttime);
885        }
886        edaylight = loctime->tm_isdst;
887        strftime(buf, MINMALLOC, "%H:%M %d-%m-%Y", loctime);
888        buf1 = ostrcat(buf, "", 1, 0);
889        changeinput(end, buf1);
890        free(buf1); buf1 = NULL;
891
892        changeinput(recchannel, NULL);
893        if(newnode == 0)
894        {
895                recchannel->handle = (char*)getchannel(node->serviceid, node->transponderid);
896                if(recchannel->handle != NULL)
897                        addchoicebox(recchannel, ((struct channel*)recchannel->handle)->name, ((struct channel*)recchannel->handle)->name);
898        }
899        else
900        {
901                if(status.aktservice->channel != NULL)
902                {
903                        addchoicebox(recchannel, status.aktservice->channel->name, status.aktservice->channel->name);
904                        recchannel->handle = (char*)status.aktservice->channel;
905                }
906        }
907
908        if(newnode == 0)
909                changeinput(path, node->recpath);
910        else
911                changeinput(path, getconfig("rec_path", NULL));
912
913        addchoicebox(after, "0", _("auto"));
914        addchoicebox(after, "1", _("nothing"));
915        addchoicebox(after, "2", _("standby"));
916        addchoicebox(after, "3", _("power off"));
917        if(newnode == 0)
918        {
919                tmpstr = oitoa(node->afterevent);
920                setchoiceboxselection(after, tmpstr);
921                free(tmpstr); tmpstr = NULL;
922        }
923        else
924                setchoiceboxselection(after, "0");
925               
926        changemask(pincode, "0000");
927        if(newnode == 0)
928                changeinput(pincode, node->pincode);
929        else
930                changeinput(pincode, "0000");
931
932        drawscreen(rectimerext, 0);
933        addscreenrc(rectimerext, listbox);
934
935        tmp = listbox->select;
936        while(1)
937        {
938                addscreenrc(rectimerext, tmp);
939                status.screencalc = 2;
940                rcret = waitrc(rectimerext, 0, 0);
941                status.screencalc = 0;
942                tmp = listbox->select;
943
944                if(listbox->select != NULL && listbox->select->ret != NULL && ostrcmp(listbox->select->name, "justplay") == 0)
945                {
946                        recjustplayhidden(atoi(listbox->select->ret), end, path, after);
947                }
948
949                tmprepeate = recrepeateget(repeate, repeatetype, day, mon, tue, wed, thur, fri, sat, sun);
950                if(listbox->select != NULL && (ostrcmp(listbox->select->name, "repeate") == 0 || ostrcmp(listbox->select->name, "repeatetype") == 0))
951                {
952                        recrepeatehidden(tmprepeate, repeatetype, day, mon, tue, wed, thur, fri, sat, sun);
953                }
954                drawscreen(rectimerext, 0);
955
956                if(rcret == getrcconfigint("rcexit", NULL))
957                {
958                        if(newnode == 1 || flag == 1) delrectimer(node, 1, 0);
959                        break;
960                }
961                if(rcret == getrcconfigint("rcok", NULL))
962                {
963                        if(listbox->select != NULL && ostrcmp(listbox->select->name, "path") == 0)
964                        {
965                                clearscreen(rectimerext);
966                                tmpstr = screendir(listbox->select->ret, "", NULL, NULL, NULL, "OK", 0, NULL, 0, NULL, 0, NULL, 0, 700, 0, 650, 0, 0);
967                                if(tmpstr != NULL)
968                                        changeinput(listbox->select, tmpstr);
969                                free(tmpstr); tmpstr = NULL;
970
971                                drawscreen(rectimerext, 0);
972                                continue;
973                        }
974                        if(listbox->select != NULL && ostrcmp(listbox->select->name, "channel") == 0)
975                        {
976                                clearscreen(rectimerext);
977                                int saveservicetype = status.servicetype;
978                                struct channel* tmpchnode = (struct channel*)recchannel->handle;
979
980                                status.servicetype = tmpservicetype;
981                                if(tmpservicetype == 0)
982                                {
983                                        addconfigtmp("channellist", tmpchannellist);
984                                        if(tmpchnode != NULL)
985                                        {
986                                                addconfiginttmp("serviceid", tmpchnode->serviceid);
987                                                addconfiginttmp("transponderid", tmpchnode->transponderid);
988                                        }
989                                }
990                                else
991                                {
992                                        addconfigtmp("rchannellist", tmpchannellist);
993                                        if(tmpchnode != NULL)
994                                        {
995                                                addconfiginttmp("rserviceid", tmpchnode->serviceid);
996                                                addconfiginttmp("rtransponderid", tmpchnode->transponderid);
997                                        }
998                                }
999
1000                                screenchannellist(&tmpchnode, &tmpchannellist, 1);
1001
1002                                recchannel->handle = (char*)tmpchnode;
1003
1004                                status.servicetype = saveservicetype;
1005                                delconfigtmp("channellist");
1006                                delconfigtmp("rchannellist");
1007                                delconfigtmp("serviceid");
1008                                delconfigtmp("rserviceid");
1009                                delconfigtmp("transponderid");
1010                                delconfigtmp("rtransponderid");
1011
1012                                if((struct channel*)recchannel->handle != NULL)
1013                                {
1014                                        changeinput(listbox->select, ((struct channel*)recchannel->handle)->name);
1015                                }
1016
1017                                drawscreen(rectimerext, 0);
1018                                continue;
1019                        }
1020
1021                        free(node->name); node->name = NULL;
1022                        node->name = ostrcat(name->ret, "", 0, 0);
1023                        if(justplay->ret != NULL)
1024                                node->justplay = atoi(justplay->ret);
1025                        if(begin->ret != NULL)
1026                        {
1027                                loctime->tm_isdst = bdaylight;
1028                                tmpstr = strptime(begin->ret, "%H:%M %d-%m-%Y", loctime);
1029                                if(tmpstr != NULL)
1030                                        node->begin = mktime(loctime);
1031                                node->begin -= (node->begin % 60);
1032                                if(node->justplay == 1)
1033                                        node->end = node->begin + 1;
1034                        }
1035                        if(end->ret != NULL && node->justplay == 0)
1036                        {
1037                                loctime->tm_isdst = edaylight;
1038                                tmpstr = strptime(end->ret, "%H:%M %d-%m-%Y", loctime);
1039                                if(tmpstr != NULL)
1040                                        node->end = mktime(loctime);
1041                                node->end -= (node->end % 60);
1042                        }
1043                        if(after->ret != NULL)
1044                                node->afterevent = atoi(after->ret);
1045                               
1046                        if(pincode->ret != NULL)
1047                                node->pincode = ostrcat(pincode->ret, NULL, 0, 0);
1048                        else
1049                                node->pincode = ostrcat("0000", NULL, 0, 0);
1050
1051                        if(tmprepeate > 127) tmprepeate = 0;
1052                        node->repeate = tmprepeate;
1053
1054                        free(node->recpath); node->recpath = NULL;
1055                        node->recpath = ostrcat(path->ret, "", 0, 0);
1056
1057                        free(node->channellist); node->channellist = NULL;
1058                        node->channellist = tmpchannellist;
1059
1060                        node->servicetype = tmpservicetype;
1061
1062                        if(recchannel->handle != NULL)
1063                        {
1064                                node->serviceid = ((struct channel*)recchannel->handle)->serviceid;
1065                                node->transponderid = ((struct channel*)recchannel->handle)->transponderid;
1066                        }
1067
1068                        char* checkret = NULL;
1069                        ret = checkrectimeradd(node, &checkret);
1070                        if(ret != 0)
1071                        {
1072                                if(ret == 2)
1073                                {
1074                                        ret = textbox(_("Message"), _(checkret), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0);
1075                                        if(ret == 2)
1076                                                ret = 99;
1077                                        else
1078                                                ret = 0;
1079                                }
1080                                if(ret == 1 || ret == 99)
1081                                {
1082                                        node->status = 3;
1083                                        node->errstr = ostrcat(node->errstr, checkret, 1, 0);
1084                                        if(ret == 1) textbox(_("Message"), _(checkret), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, NULL, 0, 600, 200, 0, 0);
1085                                }
1086                        }
1087                               
1088                        if(newnode == 1 || flag == 1) node->disabled = 0;
1089                        status.writerectimer = 1;
1090                        writerectimer(getconfig("rectimerfile", NULL), 0);
1091                        break;
1092                }
1093        }
1094
1095        delownerrc(rectimerext);
1096        clearscreen(rectimerext);
1097}
1098
1099//flag 0: show normal
1100//flag 1: show log
1101void screenrectimer()
1102{
1103        int rcret = 0, flag = 0;
1104        struct skin* recordtimer = getscreen("rectimer");
1105        struct skin* listbox = getscreennode(recordtimer, "listbox");
1106        struct skin* b1 = getscreennode(recordtimer, "b1");
1107        struct skin* b2 = getscreennode(recordtimer, "b2");
1108        struct skin* b3 = getscreennode(recordtimer, "b3");
1109        struct skin* b4 = getscreennode(recordtimer, "b4");
1110        struct skin* tmp = NULL;
1111        struct rectimer* rectimernode = NULL;
1112        struct tm *loctime = NULL;
1113        struct channel* chnode = NULL;
1114        char* buf = NULL, *tmpstr = NULL;
1115
1116        buf = malloc(MINMALLOC);
1117        if(buf == NULL)
1118        {
1119                err("no memory");
1120                return;
1121        }
1122
1123start:
1124        deloldrectimer();
1125
1126        tmp = NULL;
1127        listbox->aktpage = -1;
1128        listbox->select = NULL;
1129        rectimernode = rectimer;
1130
1131        while(rectimernode != NULL)
1132        {
1133                if((flag == 0 && (rectimernode->status == 2 || rectimernode->status == 3)) || (flag == 1 && (rectimernode->status == 0 || rectimernode->status == 1)))
1134                {
1135                        rectimernode = rectimernode->next;
1136                        continue;
1137                }
1138
1139                tmp = addlistbox(recordtimer, listbox, tmp, 1);
1140                if(tmp != NULL)
1141                {
1142                        loctime = localtime(&rectimernode->begin);
1143                        strftime(buf, MINMALLOC, "%d-%m-%Y %H:%M", loctime);
1144                        tmpstr = ostrcat(tmpstr, buf, 1, 0);
1145                        if(rectimernode->justplay == 0)
1146                        {
1147                                tmpstr = ostrcat(tmpstr, " - ", 1, 0);
1148                                loctime = localtime(&rectimernode->end);
1149                                strftime(buf, MINMALLOC, "%d-%m-%Y %H:%M", loctime);
1150                                tmpstr = ostrcat(tmpstr, buf, 1, 0);
1151                                tmpstr = ostrcat(tmpstr, " (rec - ", 1, 0);
1152                                if(rectimernode->repeate == 0)
1153                                        tmpstr = ostrcat(tmpstr, "once", 1, 0);
1154                                else
1155                                        tmpstr = ostrcat(tmpstr, "repeate", 1, 0);
1156                                tmpstr = ostrcat(tmpstr, ")", 1, 0);
1157                        }
1158                        else
1159                        {
1160                                tmpstr = ostrcat(tmpstr, " (switch - ", 1, 0);
1161                                if(rectimernode->repeate == 0)
1162                                        tmpstr = ostrcat(tmpstr, "once", 1, 0);
1163                                else
1164                                        tmpstr = ostrcat(tmpstr, "repeate", 1, 0);
1165                                tmpstr = ostrcat(tmpstr, ")", 1, 0);
1166                        }
1167
1168                        if(rectimernode->name != NULL)
1169                        {
1170                                tmpstr = ostrcat(tmpstr, "\n", 1, 0);
1171                                if(rectimernode->name == NULL || strlen(rectimernode->name) == 0)
1172                                        tmpstr = ostrcat(tmpstr, "---", 1, 0);
1173                                else
1174                                        tmpstr = ostrcat(tmpstr, rectimernode->name, 1, 0);
1175                        }
1176                        chnode = getchannel(rectimernode->serviceid, rectimernode->transponderid);
1177                        if(chnode != NULL && chnode->name != NULL && strlen(chnode->name) > 0)
1178                        {
1179                                tmpstr = ostrcat(tmpstr, " (", 1, 0);
1180                                tmpstr = ostrcat(tmpstr, chnode->name, 1, 0);
1181                                tmpstr = ostrcat(tmpstr, ")", 1, 0);
1182                        }
1183
1184                        if(rectimernode->status == 0)
1185                                tmpstr = ostrcat(tmpstr, _("\nwaiting"), 1, 0);
1186                        else if(rectimernode->status == 1)
1187                                tmpstr = ostrcat(tmpstr, _("\nrunning"), 1, 0);
1188                        else if(rectimernode->status == 2)
1189                                tmpstr = ostrcat(tmpstr, _("\nsuccess"), 1, 0);
1190                        else if(rectimernode->status == 3)
1191                                tmpstr = ostrcat(tmpstr, _("\nerror"), 1, 0);
1192
1193                        if(flag == 1 && rectimernode->errstr != NULL && strlen(rectimernode->errstr) != 0)
1194                        {
1195                                tmpstr = ostrcat(tmpstr, " (", 1, 0);
1196                                tmpstr = ostrcat(tmpstr, rectimernode->errstr, 1, 0);
1197                                tmpstr = ostrcat(tmpstr, ")", 1, 0);
1198                        }
1199                       
1200                        changetext(tmp, tmpstr);
1201                        free(tmpstr); tmpstr = NULL;
1202                        tmp->handle = (char*)rectimernode;
1203                        tmp->height = 110;
1204                        tmp->type = TEXTBOX;
1205
1206                        if(rectimernode->disabled == 1)
1207                                tmp->fontcol = convertcol("deaktivcol");
1208                }
1209                rectimernode = rectimernode->next;
1210        }
1211
1212        if(flag == 0)
1213        {
1214                b1->hidden = NO;
1215                b2->hidden = NO;
1216                b3->hidden = NO;
1217                b4->hidden = NO;
1218        }
1219        else
1220        {
1221                b1->hidden = YES;
1222                b2->hidden = YES;
1223                b3->hidden = YES;
1224                b4->hidden = YES;
1225        }
1226
1227        drawscreen(recordtimer, 0);
1228        addscreenrc(recordtimer, listbox);
1229
1230        while(1)
1231        {
1232                rcret = waitrc(recordtimer, 5000, 0);
1233
1234                if(flag == 0 && rcret == getrcconfigint("rcblue", NULL))
1235                {
1236                        flag = 1;
1237                        delmarkedscreennodes(recordtimer, 1);
1238                        goto start;
1239                }
1240                if(rcret == getrcconfigint("rcexit", NULL))
1241                {
1242                        if(flag == 0)
1243                                break;
1244                        else
1245                        {
1246                                flag = 0;
1247                                delmarkedscreennodes(recordtimer, 1);
1248                                goto start;
1249                        }
1250                }
1251                if(flag == 0 && rcret == getrcconfigint("rcgreen", NULL))
1252                {
1253                        clearscreen(recordtimer);
1254                        screenrectimerext(NULL, 0);
1255                        delmarkedscreennodes(recordtimer, 1);
1256                        goto start;
1257                }
1258                if(flag == 0 && listbox->select != NULL)
1259                {
1260                        if(rcret == getrcconfigint("rcok", NULL))
1261                        {
1262                                clearscreen(recordtimer);
1263                                screenrectimerext((struct rectimer*)listbox->select->handle, 0);
1264                                delmarkedscreennodes(recordtimer, 1);
1265                                goto start;
1266                        }
1267                        if(rcret == getrcconfigint("rcred", NULL))
1268                        {
1269                                delrectimer((struct rectimer*)listbox->select->handle, 1, 0);
1270                               
1271                                delmarkedscreennodes(recordtimer, 1);
1272                                goto start;
1273                        }
1274                        if(rcret == getrcconfigint("rcyellow", NULL))
1275                        {
1276                                if(((struct rectimer*)listbox->select->handle)->disabled == 1)
1277                                        ((struct rectimer*)listbox->select->handle)->disabled = 0;
1278                                else
1279                                        ((struct rectimer*)listbox->select->handle)->disabled = 1;
1280
1281                                delmarkedscreennodes(recordtimer, 1);
1282                                goto start;
1283                        }
1284                        if(rcret == RCTIMEOUT)
1285                        {
1286                                delmarkedscreennodes(recordtimer, 1);
1287                                goto start;
1288                        }
1289                }
1290        }
1291
1292        free(buf); buf = NULL;
1293        delmarkedscreennodes(recordtimer, 1);
1294        delownerrc(recordtimer);
1295        clearscreen(recordtimer);
1296}
1297
1298int addrecepg(struct channel* chnode, struct epg* epgnode, char* channellist)
1299{
1300        struct rectimer* node = NULL;
1301
1302        deloldrectimer();
1303
1304        if(chnode == NULL || epgnode == NULL)
1305                return 1;
1306
1307        node = addrectimernode(NULL, NULL);
1308        if(node != NULL)
1309        {
1310                node->name = ostrcat(epgnode->title, "", 0, 0);
1311                node->begin = epgnode->starttime;
1312                node->end = epgnode->endtime;
1313
1314                node->repeate = 0;
1315                node->afterevent = 0;
1316
1317                node->recpath = ostrcat(getconfig("rec_path", NULL), "", 0, 0);
1318                node->servicetype = status.servicetype;
1319                if(node->servicetype == 0)
1320                {
1321                        if(channellist == NULL)
1322                                node->channellist = ostrcat(getconfig("channellist", NULL), "", 0, 0);
1323                        else
1324                                node->channellist = ostrcat(channellist, "", 0, 0);
1325                }
1326                else
1327                {
1328                        if(channellist == NULL)
1329                                node->channellist = ostrcat(getconfig("rchannellist", NULL), "", 0, 0);
1330                        else
1331                                node->channellist = ostrcat(channellist, "", 0, 0);
1332                }
1333                node->serviceid = chnode->serviceid;
1334                node->transponderid = chnode->transponderid;
1335                screenrectimerext(node, 1);
1336        }
1337
1338        return 0;
1339}
1340
1341#endif
Note: See TracBrowser for help on using the repository browser.