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