1 | #ifndef SOFTCAM_H |
---|
2 | #define SOFTCAM_H |
---|
3 | |
---|
4 | //char* swhichcam = NULL; |
---|
5 | struct clist *emulist[LISTHASHSIZE] = {NULL}; |
---|
6 | |
---|
7 | char* whichcam() |
---|
8 | { |
---|
9 | return command("emu.sh active"); |
---|
10 | } |
---|
11 | |
---|
12 | int checkrunningcam(char* emu) |
---|
13 | { |
---|
14 | char* check = NULL; |
---|
15 | char* cmd = NULL; |
---|
16 | int running = 0; |
---|
17 | |
---|
18 | cmd = ostrcat(emu, "\"" , 0, 0); |
---|
19 | cmd = ostrcat("emu.sh check \"" , cmd, 0, 1); |
---|
20 | check = command(cmd); |
---|
21 | free(cmd); |
---|
22 | if(ostrstr(check, "checkemu running") != 0) running = 1; |
---|
23 | free(check); |
---|
24 | return running; |
---|
25 | } |
---|
26 | |
---|
27 | void readmenu() |
---|
28 | { |
---|
29 | char* emuname = NULL; |
---|
30 | char* emuline = NULL; |
---|
31 | char* emush = NULL; |
---|
32 | char* cmd = NULL; |
---|
33 | char* checkactive = NULL; |
---|
34 | char* checkstate = NULL; |
---|
35 | int count = 0; |
---|
36 | int active = 0; |
---|
37 | int check = 0; |
---|
38 | |
---|
39 | // clear the list |
---|
40 | if(emulist != NULL) |
---|
41 | freelist(emulist); |
---|
42 | |
---|
43 | // search active cam |
---|
44 | //free(swhichcam); swhichcam = NULL; |
---|
45 | //swhichcam = whichcam(); |
---|
46 | |
---|
47 | // get the emu list |
---|
48 | emuline = command("emu.sh list"); |
---|
49 | if(emuline != NULL) |
---|
50 | { |
---|
51 | // split emulist lines |
---|
52 | emush = strtok(emuline, "\n"); |
---|
53 | |
---|
54 | while(emush != NULL) |
---|
55 | { |
---|
56 | active = 0; |
---|
57 | check = 0; |
---|
58 | |
---|
59 | // read emu infoname |
---|
60 | cmd = string_quote(emush); |
---|
61 | cmd = ostrcat("emu.sh infoname ", cmd, 0, 1); |
---|
62 | emuname = string_newline(command(cmd)); |
---|
63 | free(cmd); cmd = NULL; |
---|
64 | |
---|
65 | // check if cam is active |
---|
66 | cmd = string_quote(emush); |
---|
67 | cmd = ostrcat("emu.sh active ", cmd, 0, 1); |
---|
68 | checkactive = string_newline(command(cmd)); |
---|
69 | free(cmd); cmd = NULL; |
---|
70 | if(ostrcmp(emush, checkactive) == 0) |
---|
71 | { |
---|
72 | debug(100, "active emu = %s", emush); |
---|
73 | active = 1; |
---|
74 | } |
---|
75 | |
---|
76 | // check if emu is running |
---|
77 | cmd = string_quote(emush); |
---|
78 | cmd = ostrcat("emu.sh check ", cmd, 0, 1); |
---|
79 | checkstate = command(cmd); |
---|
80 | free(cmd); cmd = NULL; |
---|
81 | if(ostrstr(checkstate, "checkemu running") != 0) |
---|
82 | { |
---|
83 | debug(100, "running emu = %s", emush); |
---|
84 | check = 1; |
---|
85 | } |
---|
86 | |
---|
87 | // update emuname with status |
---|
88 | if(active == 1 && check == 1) |
---|
89 | { |
---|
90 | emuname = ostrcat(emuname, " (", 1, 0); |
---|
91 | emuname = ostrcat(emuname, _("started"), 1, 0); |
---|
92 | emuname = ostrcat(emuname, ") (", 1, 0); |
---|
93 | emuname = ostrcat(emuname, _("active"), 1, 0); |
---|
94 | emuname = ostrcat(emuname, ")", 1, 0); |
---|
95 | } |
---|
96 | else if(check == 1) |
---|
97 | { |
---|
98 | emuname = ostrcat(emuname, " (", 1, 0); |
---|
99 | emuname = ostrcat(emuname, _("started"), 1, 0); |
---|
100 | emuname = ostrcat(emuname, ")", 1, 0); |
---|
101 | } |
---|
102 | else if(active == 1) |
---|
103 | { |
---|
104 | emuname = ostrcat(emuname, " (", 1, 0); |
---|
105 | emuname = ostrcat(emuname, _("active"), 1, 0); |
---|
106 | emuname = ostrcat(emuname, ")", 1, 0); |
---|
107 | } |
---|
108 | |
---|
109 | debug(100, "emuname = %s", emuname); |
---|
110 | addlist(emulist, emuname, emush); |
---|
111 | free(emuname); emuname = NULL; |
---|
112 | free(checkactive); checkactive = NULL; |
---|
113 | free(checkstate); checkstate = NULL; |
---|
114 | emush = strtok(NULL, "\n"); |
---|
115 | count++; |
---|
116 | } |
---|
117 | } |
---|
118 | else |
---|
119 | addlist(emulist, _("Emu not found"), "emu0"); |
---|
120 | |
---|
121 | free(emuname); |
---|
122 | free(emuline); |
---|
123 | free(emush); |
---|
124 | free(cmd); |
---|
125 | free(checkactive); |
---|
126 | free(checkstate); |
---|
127 | } |
---|
128 | |
---|
129 | void fillmenubox() |
---|
130 | { |
---|
131 | struct clist* elist = NULL; |
---|
132 | struct skin* screen = getscreen("softcam"); |
---|
133 | struct skin* listbox = getscreennode(screen, "listbox"); |
---|
134 | struct skin* node = NULL; |
---|
135 | char* aktemu = NULL; |
---|
136 | int setselection = 0, i; |
---|
137 | |
---|
138 | delmarkedscreennodes(screen, 1); |
---|
139 | |
---|
140 | for(i = 0; i < LISTHASHSIZE; i++) |
---|
141 | { |
---|
142 | elist = emulist[i]; |
---|
143 | |
---|
144 | while(elist != NULL) |
---|
145 | { |
---|
146 | if(elist->value != NULL) |
---|
147 | { |
---|
148 | node = addlistbox(screen, listbox, node, 1); |
---|
149 | if(node != NULL) |
---|
150 | { |
---|
151 | changetext(node, _(elist->key)); |
---|
152 | changename(node, elist->value); |
---|
153 | node->height = 22; |
---|
154 | |
---|
155 | // change font color, depending emu is running/active |
---|
156 | if(ostrstr(node->text, "active") != 0) |
---|
157 | { |
---|
158 | node->fontcol = convertcol("emuaktivecol"); |
---|
159 | if(setselection == 0) |
---|
160 | { |
---|
161 | aktemu = elist->value; |
---|
162 | setselection = 1; |
---|
163 | } |
---|
164 | } |
---|
165 | else if(ostrstr(node->text, "started") != 0) |
---|
166 | { |
---|
167 | node->fontcol = convertcol("emurunningcol"); |
---|
168 | if(setselection == 0 || setselection == 1) |
---|
169 | { |
---|
170 | aktemu = elist->value; |
---|
171 | setselection = 2; |
---|
172 | } |
---|
173 | } |
---|
174 | else |
---|
175 | node->fontcol = listbox->fontcol; |
---|
176 | } |
---|
177 | } |
---|
178 | elist = elist->next; |
---|
179 | } |
---|
180 | } |
---|
181 | setlistboxselection(listbox, aktemu); |
---|
182 | debug(100, "set selection to %s", aktemu); |
---|
183 | } |
---|
184 | |
---|
185 | void activate(char* emu) |
---|
186 | { |
---|
187 | char* cmd = NULL; |
---|
188 | |
---|
189 | debug(100, "active emu= %s", emu); |
---|
190 | if(emu == NULL) return; |
---|
191 | |
---|
192 | cmd = ostrcat(emu, "\"" , 0, 0); |
---|
193 | cmd = ostrcat("emu.sh activate \"" , cmd, 0, 1); |
---|
194 | osystem(cmd, 20); |
---|
195 | free(cmd); |
---|
196 | readmenu(); |
---|
197 | fillmenubox(); |
---|
198 | } |
---|
199 | |
---|
200 | void deactivate(char* emu) |
---|
201 | { |
---|
202 | char* cmd = NULL; |
---|
203 | |
---|
204 | debug(100, "deaktivate emu= %s", emu); |
---|
205 | if(emu == NULL) return; |
---|
206 | |
---|
207 | cmd = ostrcat(emu, "\"" , 0, 0); |
---|
208 | cmd = ostrcat("emu.sh deactivate \"" , cmd, 0, 1); |
---|
209 | osystem(cmd, 20); |
---|
210 | free(cmd); |
---|
211 | readmenu(); |
---|
212 | fillmenubox(); |
---|
213 | } |
---|
214 | |
---|
215 | void startcam(char* emu) |
---|
216 | { |
---|
217 | char* cmd = NULL; |
---|
218 | |
---|
219 | debug(100, "startcam emu= %s", emu); |
---|
220 | if(emu == NULL) return; |
---|
221 | |
---|
222 | cmd = ostrcat(emu, "\"" , 0, 0); |
---|
223 | cmd = ostrcat("emu.sh start \"" , cmd, 0, 1); |
---|
224 | osystem(cmd, 20); |
---|
225 | free(cmd); |
---|
226 | readmenu(); |
---|
227 | fillmenubox(); |
---|
228 | } |
---|
229 | |
---|
230 | void stopcam(char* emu) |
---|
231 | { |
---|
232 | char* cmd = NULL; |
---|
233 | |
---|
234 | debug(100, "stopcam emu= %s", emu); |
---|
235 | if(emu == NULL) return; |
---|
236 | |
---|
237 | cmd = ostrcat(emu, "\"" , 0, 0); |
---|
238 | cmd = ostrcat("emu.sh stop \"" , cmd, 0, 1); |
---|
239 | osystem(cmd, 20); |
---|
240 | free(cmd); |
---|
241 | readmenu(); |
---|
242 | fillmenubox(); |
---|
243 | } |
---|
244 | |
---|
245 | void restartcam(char* emu) |
---|
246 | { |
---|
247 | char* cmd = NULL; |
---|
248 | |
---|
249 | debug(100, "restart emu= %s", emu); |
---|
250 | if(emu == NULL) return; |
---|
251 | |
---|
252 | cmd = ostrcat(emu, "\"" , 0, 0); |
---|
253 | cmd = ostrcat("emu.sh restart \"" , cmd, 0, 1); |
---|
254 | osystem(cmd, 20); |
---|
255 | free(cmd); |
---|
256 | readmenu(); |
---|
257 | fillmenubox(); |
---|
258 | } |
---|
259 | |
---|
260 | void readecminfo(struct skin* labelecminfo) |
---|
261 | { |
---|
262 | char* tmpstr = NULL; |
---|
263 | |
---|
264 | tmpstr = command("emu.sh ecminfo"); |
---|
265 | changetext(labelecminfo, _(tmpstr)); |
---|
266 | free(tmpstr); |
---|
267 | } |
---|
268 | |
---|
269 | void screensoftcam() |
---|
270 | { |
---|
271 | int rcret = 0; |
---|
272 | char* tmpstr = NULL; |
---|
273 | struct skin* loading = getscreen("loading"); |
---|
274 | struct skin* softcam = getscreen("softcam"); |
---|
275 | struct skin* listbox = getscreennode(softcam, "listbox"); |
---|
276 | struct skin* labelecminfo = getscreennode(softcam, "ecminfo"); |
---|
277 | struct skin* menutitle = getscreennode(softcam, "menutitle"); |
---|
278 | struct skin* b_red = getscreennode(softcam, "b1"); |
---|
279 | struct skin* b_green = getscreennode(softcam, "b2"); |
---|
280 | struct skin* b_yellow = getscreennode(softcam, "b3"); |
---|
281 | struct skin* b_blue = getscreennode(softcam, "b4"); |
---|
282 | struct skin* b_menu = getscreennode(softcam, "b7"); |
---|
283 | struct skin* pluginnode = NULL; |
---|
284 | void (*startplugin)(char*); |
---|
285 | |
---|
286 | drawscreen(loading, 0, 0); |
---|
287 | |
---|
288 | // show labels |
---|
289 | changetext(menutitle, _("Softcam selection:")); |
---|
290 | changetext(b_red, _("Deactivate")); |
---|
291 | changetext(b_green, _("Restart")); |
---|
292 | changetext(b_yellow, _("Refresh")); |
---|
293 | changetext(b_blue, _("Activate")); |
---|
294 | |
---|
295 | // read ecm inf0 |
---|
296 | readecminfo(labelecminfo); |
---|
297 | |
---|
298 | // read emulist |
---|
299 | readmenu(); |
---|
300 | |
---|
301 | // add emu's to selectionbox |
---|
302 | fillmenubox(); |
---|
303 | |
---|
304 | drawscreen(softcam, 2, 0); |
---|
305 | addscreenrc(softcam, listbox); |
---|
306 | int found = 0; |
---|
307 | |
---|
308 | if(listbox->select != NULL) |
---|
309 | { |
---|
310 | free(tmpstr), tmpstr = NULL; |
---|
311 | tmpstr = ostrcat(listbox->select->name, NULL, 0, 0); |
---|
312 | string_tolower(tmpstr); |
---|
313 | |
---|
314 | if(ostrstr(tmpstr, "oscam") != NULL) |
---|
315 | { |
---|
316 | b_menu->hidden = NO; |
---|
317 | found = 1; |
---|
318 | } |
---|
319 | else |
---|
320 | { |
---|
321 | b_menu->hidden = YES; |
---|
322 | found = 0; |
---|
323 | } |
---|
324 | free(tmpstr), tmpstr = NULL; |
---|
325 | } |
---|
326 | |
---|
327 | drawscreen(softcam, 0, 0); |
---|
328 | |
---|
329 | while(1) |
---|
330 | { |
---|
331 | rcret = waitrc(softcam, 4000, 2); |
---|
332 | if(rcret == getrcconfigint("rcexit", NULL)) break; |
---|
333 | if(listbox->select != NULL) |
---|
334 | { |
---|
335 | tmpstr = ostrcat(listbox->select->name, NULL, 0, 0); |
---|
336 | string_tolower(tmpstr); |
---|
337 | if(ostrstr(tmpstr, "oscam") != NULL) |
---|
338 | { |
---|
339 | b_menu->hidden = NO; |
---|
340 | found = 1; |
---|
341 | } |
---|
342 | else |
---|
343 | { |
---|
344 | b_menu->hidden = YES; |
---|
345 | found = 0; |
---|
346 | } |
---|
347 | free(tmpstr), tmpstr = NULL; |
---|
348 | } |
---|
349 | if(listbox->select != NULL && rcret == getrcconfigint("rcred", NULL)) |
---|
350 | { |
---|
351 | // deactivate or stop emu |
---|
352 | drawscreen(loading, 0, 0); |
---|
353 | |
---|
354 | // check if cam is active |
---|
355 | char* cmd = string_quote(listbox->select->name); |
---|
356 | cmd = ostrcat("emu.sh active ", cmd, 0, 1); |
---|
357 | if(ostrcmp(listbox->select->name, string_newline(command(cmd))) == 0) |
---|
358 | deactivate(listbox->select->name); |
---|
359 | else |
---|
360 | stopcam(listbox->select->name); |
---|
361 | free(cmd); cmd = NULL; |
---|
362 | } |
---|
363 | if(listbox->select != NULL && rcret == getrcconfigint("rcgreen", NULL)) |
---|
364 | { |
---|
365 | // restart emu |
---|
366 | drawscreen(loading, 0, 0); |
---|
367 | restartcam(listbox->select->name); |
---|
368 | } |
---|
369 | if(rcret == getrcconfigint("rcyellow", NULL)) |
---|
370 | { |
---|
371 | // refrech screen |
---|
372 | drawscreen(loading, 0, 0); |
---|
373 | readecminfo(labelecminfo); |
---|
374 | readmenu(); |
---|
375 | fillmenubox(); |
---|
376 | } |
---|
377 | if(listbox->select != NULL && rcret == getrcconfigint("rcblue", NULL)) |
---|
378 | { |
---|
379 | // activate emu |
---|
380 | drawscreen(loading, 0, 0); |
---|
381 | activate(listbox->select->name); |
---|
382 | } |
---|
383 | if(listbox->select != NULL && rcret == getrcconfigint("rcok", NULL)) |
---|
384 | { |
---|
385 | // start/stop emu, depending if emu already runs |
---|
386 | drawscreen(loading, 0, 0); |
---|
387 | if(checkrunningcam(listbox->select->name) == 1) |
---|
388 | stopcam(listbox->select->name); |
---|
389 | else |
---|
390 | startcam(listbox->select->name); |
---|
391 | } |
---|
392 | if(rcret == getrcconfigint("rcmenu", NULL) && found == 1) |
---|
393 | { |
---|
394 | pluginnode = getplugin("Reader Config"); |
---|
395 | |
---|
396 | if(pluginnode != NULL) |
---|
397 | { |
---|
398 | startplugin = dlsym(pluginnode->pluginhandle, "screenoscam"); |
---|
399 | if(startplugin != NULL) |
---|
400 | startplugin(listbox->select->name); |
---|
401 | } |
---|
402 | else |
---|
403 | textbox(_("Message"), _("Reader Config Plugin not installed !"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 10, 0); |
---|
404 | } |
---|
405 | if(rcret == RCTIMEOUT) |
---|
406 | { |
---|
407 | // update ecminfo |
---|
408 | readecminfo(labelecminfo); |
---|
409 | } |
---|
410 | drawscreen(softcam, 0, 0); |
---|
411 | } |
---|
412 | |
---|
413 | if(emulist != NULL) |
---|
414 | freelist(emulist); |
---|
415 | |
---|
416 | //free(swhichcam); swhichcam = NULL; |
---|
417 | delmarkedscreennodes(softcam, 1); |
---|
418 | delownerrc(softcam); |
---|
419 | clearscreen(softcam); |
---|
420 | } |
---|
421 | |
---|
422 | #endif |
---|