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