1 | #ifndef FILELIST_H |
---|
2 | #define FILELIST_H |
---|
3 | |
---|
4 | int filelistfilter(struct skin* node, char* name) |
---|
5 | { |
---|
6 | int ret = 0, count = 0; |
---|
7 | |
---|
8 | if(node == NULL) |
---|
9 | return 1; |
---|
10 | |
---|
11 | char* tmpmatch = node->mask; |
---|
12 | char* tmpmatch1 = node->mask; |
---|
13 | |
---|
14 | char* tmpchar = NULL; |
---|
15 | |
---|
16 | if(node->mask != NULL) |
---|
17 | { |
---|
18 | tmpmatch--; |
---|
19 | do |
---|
20 | { |
---|
21 | tmpmatch++; |
---|
22 | if(*tmpmatch == ' ' || *tmpmatch == '\0') |
---|
23 | { |
---|
24 | tmpchar = strndup(tmpmatch1, count); |
---|
25 | if(tmpchar != NULL) |
---|
26 | { |
---|
27 | ret = fnmatch(tmpchar, name, FNM_CASEFOLD); |
---|
28 | free(tmpchar); |
---|
29 | if(ret == 0) return 0; |
---|
30 | } |
---|
31 | tmpmatch1 = tmpmatch + 1; |
---|
32 | count = -1; |
---|
33 | } |
---|
34 | count++; |
---|
35 | } |
---|
36 | while(*tmpmatch != '\0'); |
---|
37 | } |
---|
38 | |
---|
39 | return 1; |
---|
40 | } |
---|
41 | |
---|
42 | #ifdef SIMULATE |
---|
43 | int sizesort64(const struct dirent64** v1, const struct dirent64** v2) |
---|
44 | #else |
---|
45 | int sizesort64(const void* v1, const void* v2) |
---|
46 | #endif |
---|
47 | { |
---|
48 | char* tmpstr = NULL, *rpath = NULL; |
---|
49 | off64_t s1, s2; |
---|
50 | |
---|
51 | #ifdef SIMULATE |
---|
52 | tmpstr = createpath(status.tmp, (char*) (*v1)->d_name); |
---|
53 | #else |
---|
54 | tmpstr = createpath(status.tmp, (char*) (*(const struct dirent64**)v1)->d_name); |
---|
55 | #endif |
---|
56 | rpath = realpath(tmpstr, NULL); |
---|
57 | s1 = getfilesize(rpath); |
---|
58 | free(tmpstr); tmpstr = NULL; |
---|
59 | free(rpath); rpath = NULL; |
---|
60 | |
---|
61 | #ifdef SIMULATE |
---|
62 | tmpstr = createpath(status.tmp, (char*) (*v2)->d_name); |
---|
63 | #else |
---|
64 | tmpstr = createpath(status.tmp, (char*) (*(const struct dirent64**)v2)->d_name); |
---|
65 | #endif |
---|
66 | rpath = realpath(tmpstr, NULL); |
---|
67 | s2 = getfilesize(rpath); |
---|
68 | free(tmpstr); tmpstr = NULL; |
---|
69 | free(rpath); rpath = NULL; |
---|
70 | |
---|
71 | if(s1 > s2) return 1; |
---|
72 | if(s1 < s2) return -1; |
---|
73 | return 0; |
---|
74 | } |
---|
75 | |
---|
76 | #ifdef SIMULATE |
---|
77 | int rsizesort64(const struct dirent64** v1, const struct dirent64** v2) |
---|
78 | #else |
---|
79 | int rsizesort64(const void* v1, const void* v2) |
---|
80 | #endif |
---|
81 | { |
---|
82 | char* tmpstr = NULL, *rpath = NULL; |
---|
83 | off64_t s1, s2; |
---|
84 | |
---|
85 | #ifdef SIMULATE |
---|
86 | tmpstr = createpath(status.tmp, (char*) (*v1)->d_name); |
---|
87 | #else |
---|
88 | tmpstr = createpath(status.tmp, (char*) (*(const struct dirent64**)v1)->d_name); |
---|
89 | #endif |
---|
90 | rpath = realpath(tmpstr, NULL); |
---|
91 | s1 = getfilesize(rpath); |
---|
92 | free(tmpstr); tmpstr = NULL; |
---|
93 | free(rpath); rpath = NULL; |
---|
94 | |
---|
95 | #ifdef SIMULATE |
---|
96 | tmpstr = createpath(status.tmp, (char*) (*v2)->d_name); |
---|
97 | #else |
---|
98 | tmpstr = createpath(status.tmp, (char*) (*(const struct dirent64**)v2)->d_name); |
---|
99 | #endif |
---|
100 | rpath = realpath(tmpstr, NULL); |
---|
101 | s2 = getfilesize(rpath); |
---|
102 | free(tmpstr); tmpstr = NULL; |
---|
103 | free(rpath); rpath = NULL; |
---|
104 | |
---|
105 | if(s1 > s2) return -1; |
---|
106 | if(s1 < s2) return 1; |
---|
107 | return 0; |
---|
108 | } |
---|
109 | |
---|
110 | #ifdef SIMULATE |
---|
111 | int datesort64(const struct dirent64** v1, const struct dirent64** v2) |
---|
112 | #else |
---|
113 | int datesort64(const void* v1, const void* v2) |
---|
114 | #endif |
---|
115 | { |
---|
116 | char* tmpstr = NULL, *rpath = NULL; |
---|
117 | time_t t1, t2; |
---|
118 | |
---|
119 | #ifdef SIMULATE |
---|
120 | tmpstr = createpath(status.tmp, (char*) (*v1)->d_name); |
---|
121 | #else |
---|
122 | tmpstr = createpath(status.tmp, (char*) (*(const struct dirent64**)v1)->d_name); |
---|
123 | #endif |
---|
124 | rpath = realpath(tmpstr, NULL); |
---|
125 | t1 = getfiletime(rpath, 0); |
---|
126 | free(tmpstr); tmpstr = NULL; |
---|
127 | free(rpath); rpath = NULL; |
---|
128 | |
---|
129 | #ifdef SIMULATE |
---|
130 | tmpstr = createpath(status.tmp, (char*) (*v2)->d_name); |
---|
131 | #else |
---|
132 | tmpstr = createpath(status.tmp, (char*) (*(const struct dirent64**)v2)->d_name); |
---|
133 | #endif |
---|
134 | rpath = realpath(tmpstr, NULL); |
---|
135 | t2 = getfiletime(rpath, 0); |
---|
136 | free(tmpstr); tmpstr = NULL; |
---|
137 | free(rpath); rpath = NULL; |
---|
138 | |
---|
139 | if(t1 > t2) return -1; |
---|
140 | if(t1 < t2) return 1; |
---|
141 | return 0; |
---|
142 | } |
---|
143 | |
---|
144 | #ifdef SIMULATE |
---|
145 | int rdatesort64(const struct dirent64** v1, const struct dirent64** v2) |
---|
146 | #else |
---|
147 | int rdatesort64(const void* v1, const void* v2) |
---|
148 | #endif |
---|
149 | { |
---|
150 | char* tmpstr = NULL, *rpath = NULL; |
---|
151 | time_t t1, t2; |
---|
152 | |
---|
153 | #ifdef SIMULATE |
---|
154 | tmpstr = createpath(status.tmp, (char*) (*v1)->d_name); |
---|
155 | #else |
---|
156 | tmpstr = createpath(status.tmp, (char*) (*(const struct dirent64**)v1)->d_name); |
---|
157 | #endif |
---|
158 | rpath = realpath(tmpstr, NULL); |
---|
159 | t1 = getfiletime(rpath, 0); |
---|
160 | free(tmpstr); tmpstr = NULL; |
---|
161 | free(rpath); rpath = NULL; |
---|
162 | |
---|
163 | #ifdef SIMULATE |
---|
164 | tmpstr = createpath(status.tmp, (char*) (*v2)->d_name); |
---|
165 | #else |
---|
166 | tmpstr = createpath(status.tmp, (char*) (*(const struct dirent64**)v2)->d_name); |
---|
167 | #endif |
---|
168 | rpath = realpath(tmpstr, NULL); |
---|
169 | t2 = getfiletime(rpath, 0); |
---|
170 | free(tmpstr); tmpstr = NULL; |
---|
171 | free(rpath); rpath = NULL; |
---|
172 | |
---|
173 | if(t1 > t2) return 1; |
---|
174 | if(t1 < t2) return -1; |
---|
175 | return 0; |
---|
176 | } |
---|
177 | |
---|
178 | #ifdef SIMULATE |
---|
179 | int ralphasort64(const struct dirent64** v1, const struct dirent64** v2) |
---|
180 | #else |
---|
181 | int ralphasort64(const void* v1, const void* v2) |
---|
182 | #endif |
---|
183 | { |
---|
184 | int ret = 0; |
---|
185 | |
---|
186 | #ifdef SIMULATE |
---|
187 | ret = strcoll((*v1)->d_name, (*v2)->d_name); |
---|
188 | #else |
---|
189 | ret = strcoll((*(const struct dirent64**)v1)->d_name, (*(const struct dirent64**)v2)->d_name); |
---|
190 | #endif |
---|
191 | |
---|
192 | if(ret > 0) return -1; |
---|
193 | if(ret < 0) return 1; |
---|
194 | return 0; |
---|
195 | } |
---|
196 | |
---|
197 | //flag 0: listbox view |
---|
198 | //flag 1: grid view |
---|
199 | int createfilelist(struct skin* screen, struct skin* node, int flag) |
---|
200 | { |
---|
201 | debug(1000, "in"); |
---|
202 | struct dirent64 **filelist; |
---|
203 | int count, tmpcount, i = 0, gridbr = 0, posx = 0; |
---|
204 | struct skin *child = node, *oldchild = NULL, *parentdir = NULL; |
---|
205 | char *tmpstr = NULL; |
---|
206 | char *rpath = NULL; |
---|
207 | #ifdef SIMULATE |
---|
208 | int (*cmpfunc)(const struct dirent64**, const struct dirent64**); |
---|
209 | #else |
---|
210 | int (*cmpfunc)(const void*, const void*); |
---|
211 | #endif |
---|
212 | |
---|
213 | if(node->input == NULL) |
---|
214 | { |
---|
215 | debug(1000, "out -> NULL detect"); |
---|
216 | return 1; |
---|
217 | } |
---|
218 | |
---|
219 | if(status.filelistextend == 2) node->type |= GRID; |
---|
220 | |
---|
221 | status.tmp = node->input; |
---|
222 | switch(getconfigint("dirsort", NULL)) |
---|
223 | { |
---|
224 | case 1: cmpfunc = ralphasort64; break; |
---|
225 | case 2: cmpfunc = sizesort64; break; |
---|
226 | case 3: cmpfunc = rsizesort64; break; |
---|
227 | case 4: cmpfunc = datesort64; break; |
---|
228 | case 5: cmpfunc = rdatesort64; break; |
---|
229 | default: cmpfunc = alphasort64; break; |
---|
230 | } |
---|
231 | |
---|
232 | count = scandir64(node->input , &filelist, 0, cmpfunc); |
---|
233 | if(count < 0) |
---|
234 | { |
---|
235 | if(getconfig("failbackpath", NULL) != NULL) |
---|
236 | { |
---|
237 | perr("scandir"); |
---|
238 | count = scandir64(getconfig("failbackpath", NULL) , &filelist, 0, cmpfunc); |
---|
239 | changeinput(node, getconfig("failbackpath", NULL)); |
---|
240 | } |
---|
241 | if(count < 0) |
---|
242 | { |
---|
243 | perr("scandir"); |
---|
244 | count = scandir64("/" , &filelist, 0, cmpfunc); |
---|
245 | changeinput(node, "/"); |
---|
246 | } |
---|
247 | if(count < 0) |
---|
248 | return 1; |
---|
249 | } |
---|
250 | |
---|
251 | status.tmp = NULL; |
---|
252 | parentdir = addscreennode(screen, NULL, child); |
---|
253 | |
---|
254 | /* |
---|
255 | 0: fast (list) |
---|
256 | 1: big (list) |
---|
257 | 2: cover (grid) |
---|
258 | 3: default (liste + size) |
---|
259 | 4: details (liste + date) |
---|
260 | 5: fullcover (list) |
---|
261 | |
---|
262 | ? cover1 (list + imdb) |
---|
263 | ? cover2 (list + imdb) |
---|
264 | ? cover3 (list + imdb) |
---|
265 | */ |
---|
266 | int fontsize = 20; |
---|
267 | int fontspace = 2; |
---|
268 | int width = 0; |
---|
269 | int height = 0; |
---|
270 | |
---|
271 | // if(status.filelistextend == 0) |
---|
272 | // fontsize = 30, fontspace = 5; |
---|
273 | if(status.filelistextend == 1) |
---|
274 | fontsize = 35, fontspace = 5; |
---|
275 | else if(status.filelistextend == 2) |
---|
276 | fontsize = 20, fontspace = 5; |
---|
277 | else if(status.filelistextend == 3) |
---|
278 | fontsize = 30, fontspace = 5; |
---|
279 | else if(status.filelistextend == 4) |
---|
280 | fontsize = 25, fontspace = 5; |
---|
281 | else if(status.filelistextend == 5) |
---|
282 | { |
---|
283 | fontsize = 25, fontspace = 10; |
---|
284 | width = 600; |
---|
285 | height = 350; |
---|
286 | } |
---|
287 | |
---|
288 | if(status.filelistextend == 5) |
---|
289 | { |
---|
290 | node->height = height; |
---|
291 | node->width = width; |
---|
292 | node->bgcol = 0x474747; |
---|
293 | node->transparent = 40; |
---|
294 | node->prozwidth = 0; |
---|
295 | node->posx = 20; |
---|
296 | } |
---|
297 | |
---|
298 | if(status.filelistextend == 2 && parentdir != NULL) |
---|
299 | { |
---|
300 | parentdir->picheight = 180; |
---|
301 | parentdir->picwidth = 180; |
---|
302 | parentdir->height = 230; |
---|
303 | parentdir->width = 370; |
---|
304 | parentdir->prozwidth = 0; |
---|
305 | //parentdir->bgcol = 0xffffff; |
---|
306 | parentdir->bgspace = 1; |
---|
307 | parentdir->vspace = 10; |
---|
308 | parentdir->hspace = 10; |
---|
309 | parentdir->posx = posx; |
---|
310 | //parentdir->fontcol = 0x0000ff; |
---|
311 | parentdir->halign = CENTER; |
---|
312 | parentdir->valign = TEXTBOTTOM; |
---|
313 | parentdir->fontsize = fontsize; |
---|
314 | posx += parentdir->width; |
---|
315 | |
---|
316 | tmpstr = ostrcat(tmpstr, "skin/ext_grid_changedir.png", 1, 0); |
---|
317 | debug(10, "picpath: %s", tmpstr); |
---|
318 | changepic(parentdir, tmpstr); |
---|
319 | free(tmpstr); tmpstr = NULL; |
---|
320 | |
---|
321 | parentdir->type = GRIDBR; |
---|
322 | gridbr++; |
---|
323 | } |
---|
324 | |
---|
325 | child = parentdir; |
---|
326 | tmpcount = count; |
---|
327 | while(tmpcount--) |
---|
328 | { |
---|
329 | //check if link is a dir or wenn unknown (rarfs ...) |
---|
330 | if(filelist[i]->d_type == DT_LNK || filelist[i]->d_type == DT_UNKNOWN) |
---|
331 | { |
---|
332 | tmpstr = createpath(node->input, filelist[i]->d_name); |
---|
333 | if(isdir(tmpstr) == 1) |
---|
334 | filelist[i]->d_type = DT_DIR; |
---|
335 | |
---|
336 | free(tmpstr); tmpstr = NULL; |
---|
337 | } |
---|
338 | |
---|
339 | if(filelist[i]->d_type == DT_DIR && ostrcmp(filelist[i]->d_name, ".") != 0) |
---|
340 | { |
---|
341 | if(ostrcmp(filelist[i]->d_name, "..") == 0) |
---|
342 | { |
---|
343 | oldchild = child; |
---|
344 | child = parentdir; |
---|
345 | } |
---|
346 | else |
---|
347 | child = addscreennode(screen, NULL, child); |
---|
348 | if(child != NULL) |
---|
349 | { |
---|
350 | if(status.filelistextend != 0) |
---|
351 | child->fontsize = fontsize; |
---|
352 | if(status.filelistextend == 2) |
---|
353 | { |
---|
354 | if(gridbr == 0) child->type = GRIDBR; |
---|
355 | |
---|
356 | if(child != parentdir) |
---|
357 | { |
---|
358 | debug(10, "filename: %s", filelist[i]->d_name); |
---|
359 | child->picheight = 180; |
---|
360 | child->picwidth = 180; |
---|
361 | |
---|
362 | child->height = 230; |
---|
363 | child->width = 370; |
---|
364 | child->prozwidth = 0; |
---|
365 | //child->bgcol = 0xffffff; |
---|
366 | child->bgspace = 1; |
---|
367 | child->vspace = 10; |
---|
368 | child->hspace = 10; |
---|
369 | //child->fontcol = 0x0000ff; |
---|
370 | child->halign = CENTER; |
---|
371 | child->valign = TEXTBOTTOM; |
---|
372 | |
---|
373 | child->posx = posx; |
---|
374 | posx += child->width; |
---|
375 | |
---|
376 | if(ostrcmp(filelist[i]->d_name, "autofs") == 0) |
---|
377 | tmpstr = ostrcat(tmpstr, "skin/ext_grid_autofs.png", 1, 0); |
---|
378 | else if(ostrcmp(filelist[i]->d_name, "hdd") == 0) |
---|
379 | tmpstr = ostrcat(tmpstr, "skin/ext_grid_harddisk.png", 1, 0); |
---|
380 | else if((ostrcmp(filelist[i]->d_name, "usb") == 0) || (ostrcmp(getcurrentdir(node->input), "usb") == 0)) |
---|
381 | tmpstr = ostrcat(tmpstr, "skin/ext_grid_usb.png", 1, 0); |
---|
382 | else if((ostrcmp(filelist[i]->d_name, "net") == 0) || (ostrcmp(getcurrentdir(node->input), "net") == 0)) |
---|
383 | tmpstr = ostrcat(tmpstr, "skin/ext_grid_network.png", 1, 0); |
---|
384 | else |
---|
385 | { |
---|
386 | tmpstr = ostrcat(tmpstr, getconfig("imdb_directory", NULL), 1, 0); |
---|
387 | tmpstr = ostrcat(tmpstr, "/imdbfolder/", 1, 0); |
---|
388 | |
---|
389 | int fast = 0; |
---|
390 | if(fast == 1) |
---|
391 | { |
---|
392 | tmpstr = ostrcat(tmpstr, filelist[i]->d_name, 1, 0); |
---|
393 | tmpstr = ostrcat(tmpstr, ".png", 1, 0); |
---|
394 | } |
---|
395 | else |
---|
396 | { |
---|
397 | tmpstr = ostrcat(tmpstr, (filelist[i]->d_name), 1, 0); |
---|
398 | string_tolower(tmpstr); |
---|
399 | tmpstr = string_shortname(tmpstr, 2); |
---|
400 | string_removechar(tmpstr); |
---|
401 | string_remove_whitechars(tmpstr); |
---|
402 | tmpstr = ostrcat(tmpstr, ".png", 0, 0); |
---|
403 | } |
---|
404 | |
---|
405 | if(!file_exist(tmpstr)) |
---|
406 | { |
---|
407 | free(tmpstr); tmpstr = NULL; |
---|
408 | tmpstr = ostrcat(tmpstr, "skin/ext_grid_directory.png", 1, 0); |
---|
409 | } |
---|
410 | } |
---|
411 | |
---|
412 | if(tmpstr != NULL) |
---|
413 | { |
---|
414 | debug(10, "picpath: %s", tmpstr); |
---|
415 | changepic(child, tmpstr); |
---|
416 | free(tmpstr); tmpstr = NULL; |
---|
417 | } |
---|
418 | gridbr++; |
---|
419 | } |
---|
420 | if(gridbr >= 3) |
---|
421 | { |
---|
422 | gridbr = 0; |
---|
423 | posx = 0; |
---|
424 | } |
---|
425 | } |
---|
426 | else |
---|
427 | { |
---|
428 | debug(10, "picpath: %s", node->pic); |
---|
429 | if(node->pic != NULL) |
---|
430 | changepic(child, node->pic); |
---|
431 | } |
---|
432 | changetext(child, filelist[i]->d_name); |
---|
433 | changename(child, filelist[i]->d_name); |
---|
434 | child->parentpointer = node; |
---|
435 | child->bordercol = node->bordercol; |
---|
436 | |
---|
437 | |
---|
438 | if(status.filelistextend != 2) |
---|
439 | { |
---|
440 | child->valign = MIDDLE; |
---|
441 | child->width = 100; |
---|
442 | child->prozwidth = 1; |
---|
443 | if(status.filelistextend == 0) |
---|
444 | child->height = node->fontsize + 2 + (node->bordersize * 2); |
---|
445 | else |
---|
446 | child->height = child->fontsize + fontspace + (node->bordersize * 2); |
---|
447 | |
---|
448 | child->textposx = node->textposx; |
---|
449 | } |
---|
450 | else |
---|
451 | child->textposx = 1; |
---|
452 | |
---|
453 | child->del = FILELISTDELMARK; |
---|
454 | tmpstr = createpath(node->input, child->text); |
---|
455 | changeinput(child, tmpstr); |
---|
456 | free(tmpstr); tmpstr = NULL; |
---|
457 | |
---|
458 | if(status.filelistextend > 2) |
---|
459 | { |
---|
460 | child->filelist = (struct filelist*)malloc(sizeof(struct filelist)); |
---|
461 | if(child->filelist == NULL) |
---|
462 | { |
---|
463 | err("no mem"); |
---|
464 | continue; |
---|
465 | } |
---|
466 | memset(child->filelist, 0, sizeof(struct filelist)); |
---|
467 | child->filelist->type = DT_DIR; |
---|
468 | child->filelist->name = ostrcat(filelist[i]->d_name, "", 0, 0); |
---|
469 | child->filelist->path = createpath(node->input, ""); |
---|
470 | |
---|
471 | if(status.filelistextend == 5) |
---|
472 | { |
---|
473 | |
---|
474 | char* filename = NULL; |
---|
475 | filename = ostrcat(filename, filelist[i]->d_name, 1, 0); |
---|
476 | string_tolower(filename); |
---|
477 | filename = string_shortname(filename, 1); |
---|
478 | string_removechar(filename); |
---|
479 | string_toupper(filename); |
---|
480 | changetext(child, filename); |
---|
481 | string_tolower(filename); |
---|
482 | filename = string_shortname(filename, 2); |
---|
483 | string_remove_whitechars(filename); |
---|
484 | |
---|
485 | tmpstr = ostrcat(tmpstr, getconfig("imdb_directory", NULL), 1, 0); |
---|
486 | tmpstr = ostrcat(tmpstr, "/imdb/", 1, 0); |
---|
487 | tmpstr = ostrcat(tmpstr, filename, 1, 0); |
---|
488 | free(filename); filename = NULL; |
---|
489 | child->filelist->imdbpath = tmpstr; |
---|
490 | debug(10, "imdbpath: %s", tmpstr); |
---|
491 | // double free error, why ? |
---|
492 | // free(tmpstr); tmpstr = NULL; |
---|
493 | } |
---|
494 | |
---|
495 | tmpstr = createpath(node->input, filelist[i]->d_name); |
---|
496 | rpath = realpath(tmpstr, NULL); |
---|
497 | child->filelist->size = getfilesize(rpath); |
---|
498 | child->filelist->date = getfiletime(rpath, 0); |
---|
499 | free(tmpstr); tmpstr = NULL; |
---|
500 | free(rpath); rpath = NULL; |
---|
501 | } |
---|
502 | } |
---|
503 | if(parentdir == child) |
---|
504 | child = oldchild; |
---|
505 | |
---|
506 | } |
---|
507 | i++; |
---|
508 | } |
---|
509 | |
---|
510 | tmpcount = count; |
---|
511 | i=0; |
---|
512 | while(tmpcount--) |
---|
513 | { |
---|
514 | if(filelist[i]->d_type != DT_DIR) |
---|
515 | { |
---|
516 | if(filelistfilter(node, filelist[i]->d_name) == 0) |
---|
517 | { |
---|
518 | child = addscreennode(screen, NULL, child); |
---|
519 | if(child != NULL) |
---|
520 | { |
---|
521 | debug(10, "filename: %s", filelist[i]->d_name); |
---|
522 | if(status.filelistextend != 0) |
---|
523 | child->fontsize = fontsize; |
---|
524 | if(status.filelistextend == 2) |
---|
525 | { |
---|
526 | if(gridbr == 0) child->type = GRIDBR; |
---|
527 | |
---|
528 | child->picheight = 170; |
---|
529 | child->picwidth = 140; |
---|
530 | child->height = 230; |
---|
531 | child->width = 370; |
---|
532 | child->prozwidth = 0; |
---|
533 | //child->bgcol = 0xffffff; |
---|
534 | child->bgspace = 1; |
---|
535 | child->vspace = 10; |
---|
536 | child->hspace = 10; |
---|
537 | //child->fontcol = 0x0000ff; |
---|
538 | child->halign = CENTER; |
---|
539 | child->valign = TEXTBOTTOM; |
---|
540 | |
---|
541 | child->posx = posx; |
---|
542 | posx += child->width; |
---|
543 | |
---|
544 | if((cmpfilenameext(filelist[i]->d_name, ".jpg") == 0) || (cmpfilenameext(filelist[i]->d_name, ".png") == 0)) |
---|
545 | { |
---|
546 | tmpstr = ostrcat(createpath(node->input, "/"), filelist[i]->d_name, 1, 0); |
---|
547 | child->picheight = 210; |
---|
548 | child->picwidth = 350; |
---|
549 | } |
---|
550 | else if(cmpfilenameext(filelist[i]->d_name, ".iso") == 0) |
---|
551 | tmpstr = ostrcat(tmpstr, "skin/ext_grid_iso.png", 1, 0); |
---|
552 | else if(cmpfilenameext(filelist[i]->d_name, ".img") == 0) |
---|
553 | tmpstr = ostrcat(tmpstr, "skin/ext_grid_img.png", 1, 0); |
---|
554 | else if(cmpfilenameext(filelist[i]->d_name, ".rar") == 0) |
---|
555 | tmpstr = ostrcat(tmpstr, "skin/ext_grid_rar.png", 1, 0); |
---|
556 | else |
---|
557 | { |
---|
558 | int fast = 0; |
---|
559 | if(fast == 1) |
---|
560 | tmpstr = ostrcat(tmpstr, changefilenameext(filelist[i]->d_name, ".jpg"), 1, 0); |
---|
561 | else |
---|
562 | { |
---|
563 | char* filename = NULL; |
---|
564 | filename = ostrcat(filename, filelist[i]->d_name, 1, 0); |
---|
565 | string_tolower(filename); |
---|
566 | filename = string_shortname(filename, 2); |
---|
567 | string_removechar(filename); |
---|
568 | string_remove_whitechars(filename); |
---|
569 | |
---|
570 | tmpstr = ostrcat(tmpstr, getconfig("imdb_directory", NULL), 1, 0); |
---|
571 | tmpstr = ostrcat(tmpstr, "/imdb/", 1, 0); |
---|
572 | tmpstr = ostrcat(tmpstr, filename, 1, 0); |
---|
573 | free(filename); filename = NULL; |
---|
574 | tmpstr = ostrcat(tmpstr, ".jpg", 1, 0); |
---|
575 | } |
---|
576 | |
---|
577 | if(!file_exist(tmpstr)) |
---|
578 | { |
---|
579 | free(tmpstr); tmpstr = NULL; |
---|
580 | child->picheight = 180; |
---|
581 | child->picwidth = 180; |
---|
582 | tmpstr = ostrcat(tmpstr, "skin/ext_grid_dummy.png", 1, 0); |
---|
583 | } |
---|
584 | } |
---|
585 | debug(10, "picpath: %s", tmpstr); |
---|
586 | if(tmpstr != NULL) |
---|
587 | { |
---|
588 | changepic(child, tmpstr); |
---|
589 | free(tmpstr); tmpstr = NULL; |
---|
590 | } |
---|
591 | |
---|
592 | gridbr++; |
---|
593 | if(gridbr >= 3) |
---|
594 | { |
---|
595 | gridbr = 0; |
---|
596 | posx = 0; |
---|
597 | } |
---|
598 | } |
---|
599 | else |
---|
600 | { |
---|
601 | tmpstr = ostrcat(tmpstr, "skin/ext_", 1, 0); |
---|
602 | tmpstr = ostrcat(tmpstr, getfilenameext(filelist[i]->d_name), 1, 0); |
---|
603 | tmpstr = ostrcat(tmpstr, ".png", 1, 0); |
---|
604 | debug(10, "picpath: %s", tmpstr); |
---|
605 | if(tmpstr != NULL) |
---|
606 | changepic(child, tmpstr); |
---|
607 | free(tmpstr); tmpstr = NULL; |
---|
608 | } |
---|
609 | |
---|
610 | child->bordercol = node->bordercol; |
---|
611 | if(status.filelistextend != 2) |
---|
612 | { |
---|
613 | child->valign = MIDDLE; |
---|
614 | child->width = 100; |
---|
615 | child->prozwidth = 1; |
---|
616 | if(status.filelistextend == 0) |
---|
617 | child->height = node->fontsize + 2 + (node->bordersize * 2); |
---|
618 | else |
---|
619 | child->height = child->fontsize + fontspace + (node->bordersize * 2); |
---|
620 | |
---|
621 | child->textposx = node->textposx; |
---|
622 | } |
---|
623 | else |
---|
624 | child->textposx = 1; |
---|
625 | |
---|
626 | changetext(child, filelist[i]->d_name); |
---|
627 | changename(child, filelist[i]->d_name); |
---|
628 | |
---|
629 | child->parentpointer = node; |
---|
630 | |
---|
631 | child->del = FILELISTDELMARK; |
---|
632 | changeinput(child, NULL); |
---|
633 | |
---|
634 | if(status.filelistextend > 2) |
---|
635 | { |
---|
636 | child->filelist = (struct filelist*)malloc(sizeof(struct filelist)); |
---|
637 | if(child->filelist == NULL) |
---|
638 | { |
---|
639 | err("no mem"); |
---|
640 | continue; |
---|
641 | } |
---|
642 | memset(child->filelist, 0, sizeof(struct filelist)); |
---|
643 | child->filelist->type = DT_DIR; |
---|
644 | child->filelist->name = ostrcat(filelist[i]->d_name, "", 0, 0); |
---|
645 | child->filelist->path = createpath(node->input, ""); |
---|
646 | |
---|
647 | if(status.filelistextend == 5) |
---|
648 | { |
---|
649 | char* filename = NULL; |
---|
650 | filename = ostrcat(filename, filelist[i]->d_name, 1, 0); |
---|
651 | string_tolower(filename); |
---|
652 | filename = string_shortname(filename, 1); |
---|
653 | string_removechar(filename); |
---|
654 | string_toupper(filename); |
---|
655 | string_strip_whitechars(filename); |
---|
656 | changetext(child, filename); |
---|
657 | string_tolower(filename); |
---|
658 | filename = string_shortname(filename, 2); |
---|
659 | string_remove_whitechars(filename); |
---|
660 | |
---|
661 | tmpstr = ostrcat(tmpstr, getconfig("imdb_directory", NULL), 1, 0); |
---|
662 | tmpstr = ostrcat(tmpstr, "/imdb/", 1, 0); |
---|
663 | tmpstr = ostrcat(tmpstr, filename, 1, 0); |
---|
664 | free(filename); filename = NULL; |
---|
665 | debug(10, "imdbpath: %s", tmpstr); |
---|
666 | child->filelist->imdbpath = tmpstr; |
---|
667 | // double free error, why ? |
---|
668 | // free(tmpstr); tmpstr = NULL; |
---|
669 | } |
---|
670 | |
---|
671 | tmpstr = createpath(node->input, filelist[i]->d_name); |
---|
672 | rpath = realpath(tmpstr, NULL); |
---|
673 | child->filelist->size = getfilesize(rpath); |
---|
674 | child->filelist->date = getfiletime(rpath, 0); |
---|
675 | free(tmpstr); tmpstr = NULL; |
---|
676 | free(rpath); rpath = NULL; |
---|
677 | } |
---|
678 | } |
---|
679 | } |
---|
680 | } |
---|
681 | free(filelist[i]); |
---|
682 | i++; |
---|
683 | } |
---|
684 | |
---|
685 | free(filelist); |
---|
686 | debug(1000, "out"); |
---|
687 | return 0; |
---|
688 | } |
---|
689 | |
---|
690 | void getfilelist(struct skin* input, struct skin* filelistpath, struct skin* filelist, char* path, char* filemask, int tmpview, char* selection) |
---|
691 | { |
---|
692 | debug(1000, "in"); |
---|
693 | char* tmpstr = NULL; |
---|
694 | |
---|
695 | if(path == NULL || strlen(path) == 0 || !isdir(path)) |
---|
696 | tmpstr = strdup("/"); |
---|
697 | else |
---|
698 | tmpstr = strdup(path); |
---|
699 | |
---|
700 | filelist->aktline = 0; |
---|
701 | filelist->aktpage = 0; |
---|
702 | |
---|
703 | if(filemask == NULL) |
---|
704 | changemask(filelist,"*"); |
---|
705 | else |
---|
706 | changemask(filelist,filemask); |
---|
707 | |
---|
708 | changeinput(filelist, tmpstr); |
---|
709 | changetext(filelistpath, filelist->input); |
---|
710 | free(tmpstr); |
---|
711 | if(selection != NULL) |
---|
712 | setlistboxselection(filelist, selection); |
---|
713 | |
---|
714 | delmarkedscreennodes(input, FILELISTDELMARK); |
---|
715 | |
---|
716 | |
---|
717 | int view = 0; |
---|
718 | if (tmpview == -1) |
---|
719 | view = getconfigint("view", NULL); |
---|
720 | else |
---|
721 | view = tmpview; |
---|
722 | |
---|
723 | status.filelistextend = view; |
---|
724 | printf("getfilelist: view=%d status=%d\n", view, status.filelistextend); |
---|
725 | |
---|
726 | // clearscreen(input); |
---|
727 | createfilelist(input, filelist, 0); |
---|
728 | drawscreen(input, 0); |
---|
729 | debug(1000, "out"); |
---|
730 | } |
---|
731 | |
---|
732 | void getfilelistmax(struct skin* filelist, int* maxdirs, int* maxfiles) |
---|
733 | { |
---|
734 | struct skin* node = filelist; |
---|
735 | |
---|
736 | while(node != NULL) |
---|
737 | { |
---|
738 | if(node->del == FILELISTDELMARK) |
---|
739 | { |
---|
740 | if(node->input != NULL) |
---|
741 | (*maxdirs)++; |
---|
742 | else |
---|
743 | (*maxfiles)++; |
---|
744 | } |
---|
745 | node = node->next; |
---|
746 | } |
---|
747 | } |
---|
748 | |
---|
749 | struct skin* getfilelistrandom(struct skin* filelist, int maxdirs, int maxfiles) |
---|
750 | { |
---|
751 | int count = 0; |
---|
752 | struct skin* node = filelist; |
---|
753 | |
---|
754 | if(maxfiles < 1) return NULL; |
---|
755 | |
---|
756 | srand(time(NULL)); |
---|
757 | int r = rand() % maxfiles; |
---|
758 | r++; |
---|
759 | |
---|
760 | while(node != NULL) |
---|
761 | { |
---|
762 | if(node->del == FILELISTDELMARK && node->input == NULL) |
---|
763 | { |
---|
764 | count++; |
---|
765 | if(count == r) break; |
---|
766 | } |
---|
767 | |
---|
768 | node = node->next; |
---|
769 | } |
---|
770 | |
---|
771 | return node; |
---|
772 | } |
---|
773 | |
---|
774 | #endif |
---|