source: titan/titan/linkedchannel.h @ 44528

Last change on this file since 44528 was 27944, checked in by obi, 10 years ago

fix translate date > day name

File size: 6.3 KB
Line 
1#ifndef LINKEDCHANNEL_H
2#define LINKEDCHANNEL_H
3
4struct linkedchannel* getlinkedchannel(struct channel* chnode, int serviceid, uint64_t transponderid, time_t starttime, time_t endtime)
5{
6        if(chnode == NULL) return NULL;
7
8        m_lock(&status.linkedchannelmutex, 14);
9        struct linkedchannel* node = chnode->linkedchannel;
10
11        while(node != NULL)
12        {
13                if(node->serviceid == serviceid && node->transponderid == transponderid && node->starttime == starttime && node->endtime == endtime)
14                {
15                        m_unlock(&status.linkedchannelmutex, 14);
16                        return node;
17                }
18                node = node->next;
19        }
20
21        m_unlock(&status.linkedchannelmutex, 14);
22        return NULL;
23}
24
25struct linkedchannel* checklinkedchannel(struct channel* chnode, struct linkedchannel* lchannel)
26{
27        struct linkedchannel* node = NULL;
28
29        if(chnode != NULL)
30        {
31                node = chnode->linkedchannel;
32                while(node != NULL)
33                {
34                        if(node == lchannel)
35                                return node;
36                        node = node->next;
37                }
38        }
39        return NULL;
40}
41
42void screenlinkedchannel()
43{
44        int rcret = 0, treffer = 0, akttime = 0;
45        struct skin* linkedchannel = getscreen("linkedchannel");
46        struct skin* listbox = getscreennode(linkedchannel, "listbox");
47        struct skin* tmp = NULL;
48        struct linkedchannel* node = NULL;
49        struct channel* chnode = channel;
50        struct epg* epgnode = NULL;
51        char* tmpstr = NULL, *buf = NULL;
52        struct tm *loctime = NULL;
53
54        listbox->aktline = 1;
55        listbox->aktpage = -1;
56
57        buf = malloc(7);
58
59        addscreenrc(linkedchannel, listbox);
60start:
61        akttime = time(NULL);
62        tmp = NULL;
63        chnode = channel;
64        delmarkedscreennodes(linkedchannel, 1);
65        if(status.aktservice->channel != NULL)
66        {
67                m_lock(&status.linkedchannelmutex, 14);
68                while(chnode != NULL)
69                {
70                        node = chnode->linkedchannel;
71                        while(node != NULL)
72                        {
73                                if(node->serviceid == status.aktservice->channel->serviceid && node->transponderid == status.aktservice->channel->transponderid && akttime >= node->starttime && akttime < node->endtime)
74                                {
75                                        node = chnode->linkedchannel;
76                                        break;
77                                }
78                                node = node->next;
79                        }
80                        if(node != NULL) break;
81                        chnode = chnode->next;
82                }
83
84                if(node == NULL)
85                        node = status.aktservice->channel->linkedchannel;
86                while(node != NULL)
87                {
88                        if(akttime >= node->starttime && akttime < node->endtime)
89                        {
90                                chnode = getchannel(node->serviceid, node->transponderid);
91                                if(chnode != NULL)
92                                {
93                                        epgnode = getepgakt(chnode);
94                                        //don't show linked channel with start/end 1day
95                                        if(epgnode != NULL && epgnode->endtime - epgnode->starttime >= 86400)
96                                        {
97                                                node = node->next;
98                                                continue;
99                                        }
100                                        tmp = addlistbox(linkedchannel, listbox, tmp, 1);
101                                        if(tmp != NULL)
102                                        {
103                                                if(chnode == status.aktservice->channel)
104                                                        treffer = 1;
105                                                if(treffer == 0)
106                                                        listbox->aktline++;
107                                                tmpstr = ostrcat(tmpstr, chnode->name, 1, 0);
108                                                if(epgnode != NULL)
109                                                {
110                                                        tmpstr = ostrcat(tmpstr, " - ", 1, 0);
111                                                        if(buf != NULL)
112                                                        {
113                                                                loctime = olocaltime(&epgnode->starttime);
114                                                                ostrftime(buf, MINMALLOC, "%H:%M ", loctime);
115                                                                free(loctime); loctime = NULL;
116                                                                tmpstr = ostrcat(tmpstr, buf, 1, 0);
117                                                                tmpstr = translate_time(tmpstr, 0);
118                                                        }
119                                                        tmpstr = ostrcat(tmpstr, epgnode->title, 1, 0);
120                                                }
121                                                changetext(tmp, tmpstr);
122                                                free(tmpstr); tmpstr = NULL;
123                                                tmp->handle = (char*)chnode;
124                                        }
125                                }
126                        }
127                        node = node->next;
128                }       
129                m_unlock(&status.linkedchannelmutex, 14);
130        }
131
132        if(treffer == 0)
133        {
134                listbox->aktline = 1;
135                treffer = 1;
136        }
137
138        drawscreen(linkedchannel, 0, 0);
139
140        while(1)
141        {
142                rcret = waitrc(linkedchannel, 2000, 0);
143       
144                if(rcret == RCTIMEOUT) goto start;
145       
146                if(rcret == getrcconfigint("rcexit", NULL)) break;
147                if(rcret == getrcconfigint("rcok", NULL))
148                {
149                        if(listbox->select != NULL && listbox->select->handle != NULL)
150                                servicecheckret(servicestart((struct channel*)listbox->select->handle, NULL, NULL, 0), 0);
151                        break;
152                }
153        }
154
155        free(buf);
156        delmarkedscreennodes(linkedchannel, 1);
157        delownerrc(linkedchannel);
158        clearscreen(linkedchannel);
159}
160
161struct linkedchannel* addlinkedchannel(struct channel* chnode, int serviceid, uint64_t transponderid, time_t starttime, time_t endtime, struct linkedchannel* last)
162{
163        struct linkedchannel *newnode = NULL, *prev = NULL, *node = NULL;
164
165        if(chnode == NULL)
166        {
167                err("NULL detect");
168                return NULL;
169        }
170
171        newnode = (struct linkedchannel*)calloc(1, sizeof(struct linkedchannel));
172        if(newnode == NULL)
173        {
174                err("no memory");
175                return NULL;
176        }
177
178        newnode->serviceid = serviceid;
179        newnode->transponderid = transponderid;
180        newnode->starttime = starttime;
181        newnode->endtime = endtime;
182
183        m_lock(&status.linkedchannelmutex, 14);
184        node = chnode->linkedchannel;
185        if(last == NULL)
186        {
187                while(node != NULL)
188                {
189                        prev = node;
190                        node = node->next;
191                }
192        }
193        else
194        {
195                prev = last;
196                node = last->next;
197        }
198
199        if(prev == NULL)
200                chnode->linkedchannel = newnode;
201        else
202                prev->next = newnode;
203
204        newnode->next = node;
205
206        m_unlock(&status.linkedchannelmutex, 14);
207        return newnode;
208}
209
210//flag 0: lock
211//flag 1: nolock
212void dellinkedchannel(struct channel* chnode, struct linkedchannel* lnode, int flag)
213{
214        if(chnode == NULL)
215        {
216                err("NULL detect");
217                return;
218        }
219
220        if(flag == 0) m_lock(&status.linkedchannelmutex, 14);
221
222        struct linkedchannel *node = chnode->linkedchannel, *prev = chnode->linkedchannel;
223
224        while(node != NULL)
225        {
226                if(node == lnode)
227                {
228                        if(node == chnode->linkedchannel)
229                                chnode->linkedchannel = node->next;
230                        else
231                                prev->next = node->next;
232
233                        free(node);
234                        node = NULL;
235                        break;
236                }
237
238                prev = node;
239                node = node->next;
240        }
241        if(flag == 0) m_unlock(&status.linkedchannelmutex, 14);
242}
243
244void freelinkedchannel(struct channel* chnode)
245{
246        struct linkedchannel *node = NULL, *prev = NULL;
247
248        if(chnode == NULL)
249        {
250                err("NULL detect");
251                return;
252        }
253
254        m_lock(&status.linkedchannelmutex, 14);
255        node = chnode->linkedchannel;
256        prev = chnode->linkedchannel;
257
258        while(node != NULL)
259        {
260                prev = node;
261                node = node->next;
262                chnode->linkedchannel = node;
263
264                free(prev);
265                prev = NULL;
266        }
267        m_unlock(&status.linkedchannelmutex, 14);
268}
269
270void deloldlinkedchannel()
271{
272        struct channel* chnode = channel;
273        struct linkedchannel* node = NULL;
274
275        m_lock(&status.linkedchannelmutex, 14);
276        while(chnode != NULL)
277        {
278                if(chnode->linkedchannel != NULL)
279                {
280                        node = channel->linkedchannel;
281                        while(node != NULL)
282                        {
283                                if(node->endtime + 60 < time(NULL))
284                                        dellinkedchannel(chnode, node, 1);
285                                node = node->next;
286                        }
287                }
288                chnode = chnode->next;
289        }
290        m_unlock(&status.linkedchannelmutex, 14);
291}
292
293#endif
Note: See TracBrowser for help on using the repository browser.