1 | #ifndef MENULIST_H |
---|
2 | #define MENULIST_H |
---|
3 | |
---|
4 | void freemenulist(struct menulist* mlist, int delparam) |
---|
5 | { |
---|
6 | struct menulist *node = mlist, *prev = mlist; |
---|
7 | |
---|
8 | while(node != NULL) |
---|
9 | { |
---|
10 | prev = node; |
---|
11 | node = node->next; |
---|
12 | if(prev != NULL) |
---|
13 | { |
---|
14 | free(prev->name); |
---|
15 | prev->name = NULL; |
---|
16 | |
---|
17 | free(prev->text); |
---|
18 | prev->text = NULL; |
---|
19 | |
---|
20 | free(prev->pic); |
---|
21 | prev->pic = NULL; |
---|
22 | |
---|
23 | if(delparam == 1) |
---|
24 | { |
---|
25 | free(prev->param); |
---|
26 | prev->param = NULL; |
---|
27 | |
---|
28 | free(prev->param1); |
---|
29 | prev->param1 = NULL; |
---|
30 | |
---|
31 | free(prev->param2); |
---|
32 | prev->param2 = NULL; |
---|
33 | |
---|
34 | free(prev->param3); |
---|
35 | prev->param3 = NULL; |
---|
36 | } |
---|
37 | |
---|
38 | free(prev); |
---|
39 | prev = NULL; |
---|
40 | } |
---|
41 | } |
---|
42 | } |
---|
43 | |
---|
44 | void changemenulistparam(struct menulist* mlist, char* param, char* param1, char* param2, char* param3) |
---|
45 | { |
---|
46 | if(mlist != NULL) |
---|
47 | { |
---|
48 | free(mlist->param); |
---|
49 | mlist->param = ostrcat(param, NULL, 0, 0); |
---|
50 | |
---|
51 | free(mlist->param1); |
---|
52 | mlist->param1 = ostrcat(param1, NULL, 0, 0); |
---|
53 | |
---|
54 | free(mlist->param2); |
---|
55 | mlist->param2 = ostrcat(param2, NULL, 0, 0); |
---|
56 | |
---|
57 | free(mlist->param3); |
---|
58 | mlist->param3 = ostrcat(param3, NULL, 0, 0); |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | void setmenulistdefault(struct menulist* mlist, char* defaultentry) |
---|
63 | { |
---|
64 | while(mlist != NULL) |
---|
65 | { |
---|
66 | mlist->defaultentry = 0; |
---|
67 | if(ostrcmp(defaultentry, mlist->name) == 0) |
---|
68 | mlist->defaultentry = 1; |
---|
69 | mlist = mlist->next; |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | void addmenulistall(struct menulist** mlist, char* allname, char* pic, int deaktiv, char* defaultentry) |
---|
74 | { |
---|
75 | char* saveptr = NULL, *token = NULL, *tmpstr = NULL; |
---|
76 | |
---|
77 | tmpstr = ostrcat(allname, NULL, 0, 0); |
---|
78 | if(tmpstr == NULL) return; |
---|
79 | |
---|
80 | token = strtok_r(tmpstr, "\n", &saveptr); |
---|
81 | while(token != NULL) |
---|
82 | { |
---|
83 | if(ostrcmp(defaultentry, token) == 0) |
---|
84 | addmenulist(mlist, token, NULL, pic, deaktiv, 1); |
---|
85 | else |
---|
86 | addmenulist(mlist, token, NULL, pic, deaktiv, 0); |
---|
87 | token = strtok_r(NULL, "\n", &saveptr); |
---|
88 | } |
---|
89 | |
---|
90 | free(tmpstr); tmpstr = NULL; |
---|
91 | } |
---|
92 | |
---|
93 | struct menulist* getmenulist(struct menulist* mlist, char* name) |
---|
94 | { |
---|
95 | while(mlist != NULL) |
---|
96 | { |
---|
97 | if(ostrcmp(name, mlist->name) == 0) |
---|
98 | return mlist; |
---|
99 | mlist = mlist->next; |
---|
100 | } |
---|
101 | return NULL; |
---|
102 | } |
---|
103 | |
---|
104 | struct menulist* addmenulist(struct menulist** mlist, char* name, char* text, char* pic, int deaktiv, int defaultentry) |
---|
105 | { |
---|
106 | struct menulist *newnode = NULL, *prev = NULL, *node = *mlist; |
---|
107 | |
---|
108 | if(mlist == NULL) return NULL; |
---|
109 | |
---|
110 | newnode = (struct menulist*)malloc(sizeof(struct menulist)); |
---|
111 | if(newnode == NULL) |
---|
112 | { |
---|
113 | err("no memory"); |
---|
114 | return NULL; |
---|
115 | } |
---|
116 | |
---|
117 | memset(newnode, 0, sizeof(struct menulist)); |
---|
118 | |
---|
119 | newnode->name = ostrcat(name, NULL, 0, 0); |
---|
120 | newnode->text = ostrcat(text, NULL, 0, 0); |
---|
121 | newnode->pic = ostrcat(pic, NULL, 0, 0); |
---|
122 | newnode->deaktiv = deaktiv; |
---|
123 | newnode->defaultentry = defaultentry; |
---|
124 | |
---|
125 | while(node != NULL) |
---|
126 | { |
---|
127 | prev = node; |
---|
128 | node = node->next; |
---|
129 | } |
---|
130 | |
---|
131 | if(prev == NULL) |
---|
132 | *mlist = newnode; |
---|
133 | else |
---|
134 | prev->next = newnode; |
---|
135 | newnode->next = node; |
---|
136 | |
---|
137 | return newnode; |
---|
138 | } |
---|
139 | |
---|
140 | // showpng = 0 (no icon) |
---|
141 | // showpng = 1 (smal icon) |
---|
142 | // showpng = 2 (big icon) |
---|
143 | //flag 1: rcgreen = subchannel |
---|
144 | struct menulist* menulistboxext(struct menulist* mlist, char* paramskinname, char* skintitle, char* paramskinpath, char* defaultpic, int showpng, int* rcreturn, int flag) |
---|
145 | { |
---|
146 | int rcret = 0, fromthread = 0; |
---|
147 | struct skin* framebuffer = getscreen("framebuffer"); |
---|
148 | struct skin* tmp = NULL; |
---|
149 | struct menulist* ret = NULL; |
---|
150 | char* bg = NULL; |
---|
151 | char* skinname = NULL; |
---|
152 | char* skinpath = NULL; |
---|
153 | char* tmppic = NULL; |
---|
154 | char* tmpstr = NULL; |
---|
155 | |
---|
156 | if(pthread_self() != status.mainthread) |
---|
157 | { |
---|
158 | fromthread = 1; |
---|
159 | flag = 0; //in thread modus only flag 0 alowed (flag 1 not thread save) |
---|
160 | } |
---|
161 | |
---|
162 | if(paramskinname == NULL) |
---|
163 | skinname = ostrcat("menulist", NULL, 0, 0); |
---|
164 | else |
---|
165 | skinname = ostrcat(paramskinname, NULL, 0, 0); |
---|
166 | |
---|
167 | if(paramskinpath == NULL) |
---|
168 | skinpath = ostrcat("skin", NULL, 0, 0); |
---|
169 | else |
---|
170 | skinpath = ostrcat(paramskinpath, NULL, 0, 0); |
---|
171 | |
---|
172 | struct skin* screen = getscreen(skinname); |
---|
173 | struct skin* listbox = getscreennode(screen, "listbox"); |
---|
174 | struct skin* titletext = getscreennode(screen, "titletext"); |
---|
175 | |
---|
176 | listbox->aktpage = -1; |
---|
177 | listbox->aktline = 1; |
---|
178 | |
---|
179 | changetitle(screen, _(skintitle)); |
---|
180 | if(titletext != status.skinerr) changetext(titletext, _(skintitle)); |
---|
181 | |
---|
182 | while(mlist != NULL) |
---|
183 | { |
---|
184 | tmp = addlistbox(screen, listbox, tmp, 1); |
---|
185 | |
---|
186 | if(tmp != NULL) |
---|
187 | { |
---|
188 | changetext(tmp, _(mlist->name)); |
---|
189 | changename(tmp, mlist->name); |
---|
190 | |
---|
191 | if(mlist->text != NULL) |
---|
192 | { |
---|
193 | changetext2(tmp, _(mlist->text)); |
---|
194 | tmp->textposx2 = 270; |
---|
195 | tmp->type = TEXTBOX; |
---|
196 | tmp->wrap = YES; |
---|
197 | } |
---|
198 | |
---|
199 | tmp->handle = (char*)mlist; |
---|
200 | |
---|
201 | if(showpng > 0 && mlist->name != NULL) |
---|
202 | { |
---|
203 | tmp->textposx = 120; |
---|
204 | tmp->height = 50; |
---|
205 | tmp->valign = convertxmlentry("middle", 0); |
---|
206 | tmp->hspace = 5; |
---|
207 | |
---|
208 | if(showpng == 2) |
---|
209 | { |
---|
210 | tmp->valign = convertxmlentry("middle", 0); |
---|
211 | tmp->textposx = 250; |
---|
212 | tmp->height = 170; |
---|
213 | } |
---|
214 | |
---|
215 | if(showpng == 3) |
---|
216 | { |
---|
217 | tmp->valign = convertxmlentry("middle", 0); |
---|
218 | tmp->textposx = 100; |
---|
219 | tmp->height = 250; |
---|
220 | } |
---|
221 | |
---|
222 | if(mlist->pic == NULL) |
---|
223 | { |
---|
224 | mlist->pic = ostrcat(mlist->name, ".png", 0, 0); |
---|
225 | stringreplacechar(mlist->pic, ' ', '_'); |
---|
226 | stringreplacechar(mlist->pic, ':', '_'); |
---|
227 | stringreplacechar(mlist->pic, '/', '_'); |
---|
228 | string_tolower(mlist->pic); |
---|
229 | } |
---|
230 | |
---|
231 | if(mlist->pic != NULL) |
---|
232 | { |
---|
233 | if(mlist->pic[0] != '/') |
---|
234 | { |
---|
235 | tmppic = ostrcat(skinpath, "/", 0, 0); |
---|
236 | tmppic = ostrcat(tmppic, mlist->pic, 1, 0); |
---|
237 | } |
---|
238 | else |
---|
239 | tmppic = ostrcat(mlist->pic, NULL, 0, 0); |
---|
240 | |
---|
241 | tmpstr = changepicpath(tmppic); |
---|
242 | if(!file_exist(tmpstr)) |
---|
243 | { |
---|
244 | debug(10, "menu pic not found: %s", tmpstr); |
---|
245 | free(mlist->pic); mlist->pic = NULL; |
---|
246 | free(tmppic); tmppic = NULL; |
---|
247 | } |
---|
248 | free(tmpstr); tmpstr = NULL; |
---|
249 | } |
---|
250 | |
---|
251 | if(mlist->pic == NULL) |
---|
252 | { |
---|
253 | if(defaultpic == NULL) |
---|
254 | tmppic = ostrcat(getconfig("skinpath", NULL), "/skin/default.png", 0, 0); |
---|
255 | else |
---|
256 | tmppic = ostrcat(getconfig("skinpath", NULL), defaultpic, 0, 0); |
---|
257 | } |
---|
258 | |
---|
259 | changepic(tmp, tmppic); |
---|
260 | free(tmppic); tmppic = NULL; |
---|
261 | } |
---|
262 | |
---|
263 | if(mlist->deaktiv == 1) |
---|
264 | tmp->deaktivcol = convertcol("deaktivcol"); |
---|
265 | } |
---|
266 | |
---|
267 | if(mlist->defaultentry == 1) |
---|
268 | setlistboxselection(listbox, mlist->name); |
---|
269 | |
---|
270 | mlist = mlist->next; |
---|
271 | } |
---|
272 | |
---|
273 | if(fromthread == 1) |
---|
274 | { |
---|
275 | delrc(getrcconfigint("rcvolup", NULL), NULL, NULL); |
---|
276 | delrc(getrcconfigint("rcvoldown", NULL), NULL, NULL); |
---|
277 | delrc(getrcconfigint("rcmute", NULL), NULL, NULL); |
---|
278 | m_lock(&status.drawingmutex, 0); |
---|
279 | m_lock(&status.rcmutex, 10); |
---|
280 | setnodeattr(screen, framebuffer, 2); |
---|
281 | status.rcowner = screen; |
---|
282 | bg = savescreen(screen); |
---|
283 | drawscreen(screen, 0, 2); |
---|
284 | } |
---|
285 | else |
---|
286 | drawscreen(screen, 0, 0); |
---|
287 | |
---|
288 | addscreenrc(screen, listbox); |
---|
289 | |
---|
290 | while(1) |
---|
291 | { |
---|
292 | rcret = waitrc(screen, 0, 0); |
---|
293 | if(rcreturn != NULL) *rcreturn = rcret; |
---|
294 | |
---|
295 | if(rcret == getrcconfigint("rcexit", NULL)) break; |
---|
296 | if(flag == 1 && rcret == getrcconfigint("rcgreen", NULL)) |
---|
297 | { |
---|
298 | clearscreen(screen); |
---|
299 | screenlinkedchannel(); |
---|
300 | break; |
---|
301 | } |
---|
302 | if(rcret == getrcconfigint("rcok", NULL) || rcret == getrcconfigint("rcred", NULL) || rcret == getrcconfigint("rcgreen", NULL) || rcret == getrcconfigint("rcyellow", NULL) || rcret == getrcconfigint("rcblue", NULL) || rcret == getrcconfigint("rcmenu", NULL)) |
---|
303 | { |
---|
304 | if(rcreturn == NULL && rcret != getrcconfigint("rcok", NULL)) |
---|
305 | continue; |
---|
306 | |
---|
307 | if(listbox->select != NULL) |
---|
308 | ret = (struct menulist*)listbox->select->handle; |
---|
309 | break; |
---|
310 | } |
---|
311 | } |
---|
312 | |
---|
313 | free(skinname); skinname = NULL; |
---|
314 | free(skinpath); skinpath = NULL; |
---|
315 | delownerrc(screen); |
---|
316 | delmarkedscreennodes(screen, 1); |
---|
317 | |
---|
318 | if(fromthread == 1) |
---|
319 | { |
---|
320 | clearscreennolock(screen); |
---|
321 | restorescreen(bg, screen); |
---|
322 | blitfb(0); |
---|
323 | sleep(1); |
---|
324 | status.rcowner = NULL; |
---|
325 | m_unlock(&status.rcmutex, 3); |
---|
326 | m_unlock(&status.drawingmutex, 0); |
---|
327 | addrc(getrcconfigint("rcvolup", NULL), screenvolumeup, NULL, NULL); |
---|
328 | addrc(getrcconfigint("rcvoldown", NULL), screenvolumedown, NULL, NULL); |
---|
329 | addrc(getrcconfigint("rcmute", NULL), screenmute, NULL, NULL); |
---|
330 | } |
---|
331 | else |
---|
332 | clearscreen(screen); |
---|
333 | |
---|
334 | return ret; |
---|
335 | } |
---|
336 | |
---|
337 | struct menulist* menulistbox(struct menulist* mlist, char* paramskinname, char* skintitle, char* paramskinpath, char* defaultpic, int showpng, int flag) |
---|
338 | { |
---|
339 | return menulistboxext(mlist, paramskinname, skintitle, paramskinpath, defaultpic, showpng, NULL, flag); |
---|
340 | } |
---|
341 | #endif |
---|