source: titan/titan/linkedchannel.h @ 15746

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

[titan] fix subchannel

File size: 5.0 KB
Line 
1#ifndef LINKEDCHANNEL_H
2#define LINKEDCHANNEL_H
3
4struct linkedchannel* getlinkedchannel(struct channel* chnode, int serviceid, unsigned long transponderid)
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)
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;
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        tmp = NULL;
62        chnode = channel;
63        delmarkedscreennodes(linkedchannel, 1);
64        if(status.aktservice->channel != NULL)
65        {
66                if(status.aktservice->channel->linkedchannel == NULL)
67                {
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)
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
85                m_lock(&status.linkedchannelmutex, 14);
86                if(node == NULL)
87                        node = status.aktservice->channel->linkedchannel;
88                while(node != NULL)
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                                                }
118                                                tmpstr = ostrcat(tmpstr, epgnode->title, 1, 0);
119                                        }
120                                        changetext(tmp, tmpstr);
121                                        free(tmpstr); tmpstr = NULL;
122                                        tmp->handle = (char*)chnode;
123                                }
124                        }
125                        node = node->next;
126                }       
127                m_unlock(&status.linkedchannelmutex, 14);
128        }
129
130        if(treffer == 0) listbox->aktline = 1;
131
132        drawscreen(linkedchannel, 0);
133
134        while(1)
135        {
136                rcret = waitrc(linkedchannel, 2000, 0);
137       
138                if(rcret == RCTIMEOUT) goto start;
139       
140                if(rcret == getrcconfigint("rcexit", NULL)) break;
141                if(rcret == getrcconfigint("rcok", NULL))
142                {
143                        if(listbox->select != NULL && listbox->select->handle != NULL)
144                                servicecheckret(servicestart((struct channel*)listbox->select->handle, NULL, NULL, 0), 0);
145                        break;
146                }
147        }
148
149        free(buf);
150        delmarkedscreennodes(linkedchannel, 1);
151        delownerrc(linkedchannel);
152        clearscreen(linkedchannel);
153}
154
155struct linkedchannel* addlinkedchannel(struct channel* chnode, int serviceid, unsigned long transponderid, struct linkedchannel* last)
156{
157        debug(1000, "in");
158        struct linkedchannel *newnode = NULL, *prev = NULL, *node = NULL;
159
160        if(chnode == NULL)
161        {
162                debug(1000, "out -> NULL detect");
163                return NULL;
164        }
165
166        newnode = (struct linkedchannel*)malloc(sizeof(struct linkedchannel)); 
167        if(newnode == NULL)
168        {
169                err("no memory");
170                return NULL;
171        }
172
173        memset(newnode, 0, sizeof(struct linkedchannel));
174
175        newnode->serviceid = serviceid;
176        newnode->transponderid = transponderid;
177
178        m_lock(&status.linkedchannelmutex, 14);
179        node = chnode->linkedchannel;
180        if(last == NULL)
181        {
182                while(node != NULL)
183                {
184                        prev = node;
185                        node = node->next;
186                }
187        }
188        else
189        {
190                prev = last;
191                node = last->next;
192        }
193
194        if(prev == NULL)
195                chnode->linkedchannel = newnode;
196        else
197                prev->next = newnode;
198
199        newnode->next = node;
200
201        m_unlock(&status.linkedchannelmutex, 14);
202        debug(1000, "out");
203        return newnode;
204}
205
206void freelinkedchannel(struct channel* chnode)
207{
208        debug(1000, "in");
209        struct linkedchannel *node = NULL, *prev = NULL;
210
211        if(chnode == NULL)
212        {
213                debug(1000, "out -> NULL detect");
214                return;
215        }
216
217        m_lock(&status.linkedchannelmutex, 14);
218        node = chnode->linkedchannel;
219        prev = chnode->linkedchannel;
220
221        while(node != NULL)
222        {
223                prev = node;
224                node = node->next;
225                chnode->linkedchannel = node;
226
227                free(prev);
228                prev = NULL;
229
230        }
231        m_unlock(&status.linkedchannelmutex, 14);
232        debug(1000, "out");
233}
234
235#endif
Note: See TracBrowser for help on using the repository browser.