source: titan/titan/filelist.h @ 32387

Last change on this file since 32387 was 32387, checked in by nit, 9 years ago

fix

File size: 22.7 KB
Line 
1#ifndef FILELIST_H
2#define FILELIST_H
3
4int 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
44int 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)
52int 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)
80int 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)
107int 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)
134int 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)
161int 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)
175int 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
195int 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                                }
423                                else
424                                        child->textposx = 1;
425
426                                child->del = FILELISTDELMARK;
427                                tmpstr = createpath(node->input, child->text);
428                                changeinput(child, tmpstr);
429                                free(tmpstr); tmpstr = NULL;
430
431                                if(view > 3)
432                                {
433                                        child->filelist = (struct filelist*)calloc(1, sizeof(struct filelist));
434                                        if(child->filelist == NULL)
435                                        {
436                                                err("no mem");
437                                                continue;
438                                        }
439                                        child->filelist->type = filelist[i]->d_type;
440                                        child->filelist->view = view;
441
442                                        tmpstr = createpath(node->input, filelist[i]->d_name);
443                                        rpath = realpath(tmpstr, NULL);
444                                        if(view == 4) child->filelist->size = getfilesize(rpath);
445                                        else if(view == 5) child->filelist->date = getfiletime(rpath, 1);
446                                        free(rpath); rpath = NULL;
447                                        free(tmpstr); tmpstr = NULL;
448                                }
449                        }
450                        if(parentdir == child)
451                                child = oldchild;
452
453                }
454                i++;
455        }
456
457        tmpcount = count;
458        i=0;
459        while(tmpcount--)
460        {
461                if(filelist[i]->d_type != DT_DIR && filelist[i]->d_name != NULL && (status.showhiddenfiles == 1 || (status.showhiddenfiles == 0 && filelist[i]->d_name[0] != '.')))
462                {
463                        if(filelistfilter(node, filelist[i]->d_name) == 0)
464                        {
465                                child = addscreennode(screen, NULL, child);
466                                if(child != NULL)
467                                {
468                                        if(node->usesavebg == 3)
469                                        {
470                                                debug(555, "set child->usesavebg=%d to %d\n", child->usesavebg, node->usesavebg - 1);
471                                                child->usesavebg = node->usesavebg - 1;
472                                        }
473                                        debug(913, "filename: %s", filelist[i]->d_name);
474                                        if(view == 2)
475                                        {
476                                                sumcount++;
477                                                pagecount++;
478                                                debug(913, "files: pagecount: %d", pagecount);
479                                                debug(913, "files: sumcount: %d", sumcount);
480
481                                                if(gridbr == 0) child->type = GRIDBR;
482       
483                                                child->picheight = 170;
484                                                child->picwidth = 140;
485                                                child->height = 230;
486                                                child->width = 370;
487                                                child->prozwidth = 0;
488                                                //child->bgcol = 0xffffff;
489                                                child->bgspace = 1;
490                                                child->vspace = 10;
491                                                child->hspace = 10;
492                                                //child->fontcol = 0x0000ff;
493                                                child->halign = CENTER;
494                                                child->valign = TEXTBOTTOM;
495       
496                                                child->posx = posx;
497                                                posx += child->width;
498
499                                                if(cmpfilenameext(filelist[i]->d_name, ".png") == 0)
500                                                {
501                                                        tmpstr = ostrcat(createpath(node->input, "/"), filelist[i]->d_name, 1, 0);
502//                                                      child->picheight = 210;
503//                                                      child->picwidth = 350;
504                                                        child->picwidth = 1;
505                                                        child->picheight = 1;
506                                                }
507                                                else if(cmpfilenameext(filelist[i]->d_name, ".jpg") == 0)
508                                                {
509                                                        if(status.thumbthread != NULL)
510                                                        {
511                                                                //check if thumb exists
512                                                                tmpstr = checkthumb(node->input, filelist[i]->d_name);
513                                                                if(tmpstr == NULL)
514                                                                {
515                                                                        addqueue(101, (void*)node->input, strlen(node->input) + 1, (void*)filelist[i]->d_name, strlen(filelist[i]->d_name) + 1, 0, NULL);
516                                                                        child->picheight = 180;
517                                                                        child->picwidth = 180;
518                                                                }
519                                                                else
520                                                                {
521                                                                        child->picwidth = 1;
522                                                                        child->picheight = 1;
523                                                                }
524                                                        }
525                                                        if(tmpstr == NULL) tmpstr = ostrcat(tmpstr, "skin/ext_grid_dummy.png", 1, 0);
526                                                }
527                                                else if(cmpfilenameext(filelist[i]->d_name, ".iso") == 0)
528                                                        tmpstr = ostrcat(tmpstr, "skin/ext_grid_iso.png", 1, 0);
529                                                else if(cmpfilenameext(filelist[i]->d_name, ".img") == 0)
530                                                        tmpstr = ostrcat(tmpstr, "skin/ext_grid_img.png", 1, 0);
531                                                else if(cmpfilenameext(filelist[i]->d_name, ".rar") == 0)
532                                                        tmpstr = ostrcat(tmpstr, "skin/ext_grid_rar.png", 1, 0);
533                                                else
534                                                {
535                                                        int fast = 0;
536                                                        if(fast == 1)
537                                                                tmpstr = ostrcat(tmpstr, changefilenameext(filelist[i]->d_name, ".jpg"), 1, 1);
538                                                        else
539                                                        {                                               
540//                                                              free(tmpstr), tmpstr = NULL;
541//                                                              tmpstr = ostrcat(node->input, "/", 0, 0);
542//                                                              tmpstr = ostrcat(tmpstr, filelist[i]->d_name, 1, 0);                                                           
543//                                                              struct mediadb* mnode = getmediadb(tmpstr, 0);
544                                                               
545                                                                struct mediadb* mnode = getmediadb(node->input, filelist[i]->d_name, 0);
546                                                                free(tmpstr), tmpstr = NULL;
547                                                                if(mnode != NULL)
548                                                                {
549                                                                        int musik = 0;
550                                                                        if(cmpfilenameext(filelist[i]->d_name, ".mp3") == 0)
551                                                                                musik = 1;
552                                                                        else if(cmpfilenameext(filelist[i]->d_name, ".flac") == 0)
553                                                                                musik = 1;
554                                                                        else if(cmpfilenameext(filelist[i]->d_name, ".ogg") == 0)
555                                                                                musik = 1;
556                                                                        else if(cmpfilenameext(filelist[i]->d_name, ".ra") == 0)
557                                                                                musik = 1;
558                                                                        else if(cmpfilenameext(filelist[i]->d_name, ".wav") == 0)
559                                                                                musik = 1;
560                                                               
561                                                                        if(mnode->id != NULL && ostrstr(mnode->id, "tt") == NULL)
562                                                                        {
563                                                                                child->picheight = 180;
564                                                                                child->picwidth = 300;
565                                                                        }
566
567                                                                        int len1 = strlen(mnode->title);
568                                                                        int len2 = strlen(mnode->actors);
569                                                                        if((mnode->title != NULL && len1 != 0 && musik == 0) || (mnode->actors != NULL && len2 != 0 && mnode->title != NULL && len1 != 0 && musik == 1))
570                                                                        {
571                                                                                if(musik == 1)
572                                                                                {
573                                                                                        tmpstr = ostrcat(tmpstr, mnode->actors, 1, 0);
574                                                                                        tmpstr = ostrcat(tmpstr, " - ", 1, 0);
575                                                                                        tmpstr = ostrcat(tmpstr, mnode->title, 1, 0);
576                                                                                }
577                                                                                else
578                                                                                {
579                                                                                        len1 = strlen(mnode->shortname);
580                                                                                        if(mnode->shortname != NULL && len1 != 0)
581                                                                                        {
582                                                                                                tmpstr = ostrcat(tmpstr, mnode->shortname, 1, 0);
583                                                                                        }
584                                                                                        else
585                                                                                                tmpstr = ostrcat(tmpstr, filelist[i]->d_name, 1, 0);
586                                                                                }
587       
588                                                                                len1 = strlen(mnode->fileinfo);         
589                                                                                if(mnode->fileinfo != NULL && len1 != 0)
590                                                                                {
591                                                                                        tmpstr = ostrcat(tmpstr, " (", 1, 0);
592                                                                                        tmpstr = ostrcat(tmpstr, mnode->fileinfo, 1, 0);
593                                                                                        tmpstr = ostrcat(tmpstr, ")", 1, 0);
594                                                                                }
595                                                                                       
596                                                                                changetext(child, tmpstr);
597                                                                                free(tmpstr), tmpstr = NULL;
598                                                                        }
599                                                                        else
600                                                                                changetext(child, filelist[i]->d_name);
601
602                                                                        if(mnode->id != NULL)
603                                                                        {
604                                                                                tmpstr = ostrcat(tmpstr, getconfig("mediadbpath", NULL), 1, 0);
605                                                                                tmpstr = ostrcat(tmpstr, "/", 1, 0);                                                                                                                                                   
606                                                                                tmpstr = ostrcat(tmpstr, mnode->id, 1, 0);
607// cover + thumb unscharf
608                                                                                if(musik == 1)
609                                                                                        tmpstr = ostrcat(tmpstr, "_cover.jpg", 1, 0);
610                                                                                else
611                                                                                        tmpstr = ostrcat(tmpstr, "_cover.jpg", 1, 0);
612                                                                        }
613
614                                                                }
615                                                                else
616                                                                        changetext(child, filelist[i]->d_name);                                                                                                                         
617                                                        }
618                                                       
619                                                        if(!file_exist(tmpstr))
620                                                        {
621                                                                free(tmpstr); tmpstr = NULL;
622                                                                child->picheight = 180;
623                                                                child->picwidth = 180;
624                                                                tmpstr = ostrcat(tmpstr, "skin/ext_grid_dummy.png", 1, 0);
625                                                        }
626                                                }
627                                                debug(913, "picpath: %s", tmpstr);
628                                                if(tmpstr != NULL)
629                                                {
630                                                        debug(913, "files: change pic");
631                                                        changepic(child, tmpstr);
632                                                        free(tmpstr); tmpstr = NULL;
633                                                }
634                                       
635                                                gridbr++;
636                                                if(gridbr >= 3)
637                                                {
638                                                        gridbr = 0;
639                                                        posx = 0;
640                                                }
641                                        }
642                                        else
643                                        {
644                                                tmpstr = ostrcat(tmpstr, "skin/ext_", 1, 0);
645//                                              tmpstr = ostrcat(tmpstr, string_tolower(getfilenameext(filelist[i]->d_name)), 1, 1);
646                                                tmpstr = ostrcat(tmpstr, string_tolower(getfilenamepng(filelist[i]->d_name)), 1, 1);
647                                                tmpstr = ostrcat(tmpstr, ".png", 1, 0);
648                                                debug(913, "picpath: %s", tmpstr);
649                                                if(tmpstr != NULL)
650                                                        changepic(child, tmpstr);
651                                                free(tmpstr); tmpstr = NULL;
652                                        }
653
654                                        child->bordercol = node->bordercol;
655                                        if(view != 2)
656                                        {
657                                                child->valign = MIDDLE;
658                                                child->width = 100;
659                                                child->prozwidth = 1;
660                                                child->height = node->fontsize + 2 + (node->bordersize * 2);
661                                                child->textposx = node->textposx;                       
662                                        }
663                                        else
664                                                child->textposx = 1;
665
666                                        if(view != 2)
667                                                changetext(child, filelist[i]->d_name);
668                                        changename(child, filelist[i]->d_name);
669                                       
670                                        child->parentpointer = node;
671
672                                        child->del = FILELISTDELMARK;
673                                        changeinput(child, NULL);
674
675                                        if(view > 3)
676                                        {
677                                                child->filelist = (struct filelist*)calloc(1, sizeof(struct filelist));
678                                                if(child->filelist == NULL)
679                                                {
680                                                        err("no mem");
681                                                        continue;
682                                                }
683                                                child->filelist->type = filelist[i]->d_type;
684                                                child->filelist->view = view;
685
686                                                tmpstr = createpath(node->input, filelist[i]->d_name);
687                                                rpath = realpath(tmpstr, NULL);
688                                                if(view == 4) child->filelist->size = getfilesize(rpath);
689                                                else if(view == 5) child->filelist->date = getfiletime(rpath, 1);
690                                                free(rpath); rpath = NULL;
691                                                free(tmpstr); tmpstr = NULL;
692                                        }
693                                        if(view == 3)
694                                        {
695                                                struct mediadb* mnode = getmediadb(node->input, filelist[i]->d_name, 0);
696                                                int musik = 0;
697                                                if(cmpfilenameext(filelist[i]->d_name, ".mp3") == 0)
698                                                        musik = 1;
699                                                else if(cmpfilenameext(filelist[i]->d_name, ".flac") == 0)
700                                                        musik = 1;
701                                                else if(cmpfilenameext(filelist[i]->d_name, ".ogg") == 0)
702                                                        musik = 1;
703                                                else if(cmpfilenameext(filelist[i]->d_name, ".ra") == 0)
704                                                        musik = 1;
705                                                else if(cmpfilenameext(filelist[i]->d_name, ".wav") == 0)
706                                                        musik = 1;
707
708                                                if(mnode != NULL)
709                                                {
710                                                        int len1 = strlen(mnode->title);
711                                                        int len2 = strlen(mnode->actors);
712                                                        if((mnode->title != NULL && len1 != 0 && musik == 0) || (mnode->actors != NULL && len2 != 0 && mnode->title != NULL && len1 != 0 && musik == 1))
713                                                        {
714                                                                if(musik == 1)
715                                                                {
716                                                                        tmpstr = ostrcat(tmpstr, mnode->actors, 1, 0);
717                                                                        tmpstr = ostrcat(tmpstr, " - ", 1, 0);
718                                                                        tmpstr = ostrcat(tmpstr, mnode->title, 1, 0);
719                                                                }
720                                                                else
721                                                                {
722                                                                        len1 = strlen(mnode->shortname);
723                                                                        if(mnode->shortname != NULL && len1 != 0)
724                                                                        {
725                                                                                tmpstr = ostrcat(tmpstr, mnode->shortname, 1, 0);
726                                                                        }
727                                                                        else
728                                                                                tmpstr = ostrcat(tmpstr, filelist[i]->d_name, 1, 0);                                                                   
729                                                                }
730
731                                                                len1 = strlen(mnode->fileinfo);                                                         
732                                                                if(mnode->fileinfo != NULL && len1 != 1)
733                                                                {
734                                                                        tmpstr = ostrcat(tmpstr, " (", 1, 0);
735                                                                        tmpstr = ostrcat(tmpstr, mnode->fileinfo, 1, 0);
736                                                                        tmpstr = ostrcat(tmpstr, ")", 1, 0);
737                                                                }
738                                                                changetext(child, tmpstr);
739                                                                free(tmpstr), tmpstr = NULL;
740                                                        }
741                                                        else
742                                                                changetext(child, filelist[i]->d_name);
743                                                }
744                                        }
745                                }
746                        }
747                }
748                free(filelist[i]);
749                i++;
750        }
751
752//      if(view == 2 || view == 3)
753//              m_unlock(&status.mediadbmutex, 17);     
754/*
755        for (i = 0; i <= pagecount; i++)
756        {
757                printf("delmarkedpic=%d\n", i + 1000);
758                delmarkedpic(i + 1000);
759        }
760*/
761        free(filelist);
762        return 0;
763}
764
765void getfilelist(struct skin* input, struct skin* filelistpath, struct skin* filelist, char* path, char* filemask, int tmpview, char* selection)
766{
767        char* tmpstr = NULL;
768
769        if(path == NULL || strlen(path) == 0 || !isdir(path))
770                tmpstr = strdup("/");
771        else
772                tmpstr = strdup(path);
773
774        filelist->aktline = 0;
775        filelist->aktpage = 0;
776
777        if(filemask == NULL)
778                changemask(filelist, "*");
779        else
780                changemask(filelist, filemask);
781
782        changeinput(filelist, tmpstr);
783        changetext(filelistpath, filelist->input);
784        free(tmpstr); tmpstr = NULL;
785
786        tmpstr = ostrcat(selection, NULL, 0, 0);
787
788        delmarkedscreennodes(input, FILELISTDELMARK);
789
790        if(tmpview == -1)
791                createfilelist(input, filelist, 0);
792        else
793                createfilelist(input, filelist, tmpview);
794
795        if(tmpstr != NULL)
796                setlistboxselection(filelist, tmpstr);
797        free(tmpstr); tmpstr = NULL;
798
799        drawscreen(input, 0, 0);
800}
801
802void getfilelistmax(struct skin* filelist, int* maxdirs, int* maxfiles)
803{
804        struct skin* node = filelist;
805
806        while(node != NULL)
807        {
808                if(node->del == FILELISTDELMARK)
809                {
810                        if(node->input != NULL)
811                                (*maxdirs)++;
812                        else
813                                (*maxfiles)++;
814                }
815                node = node->next;
816        }
817}
818
819struct skin* getfilelistrandom(struct skin* filelist, int maxdirs, int maxfiles)
820{
821        int count = 0;
822        struct skin* node = filelist;
823       
824        if(maxfiles < 1) return NULL;
825
826        int r = getrandom(maxfiles);
827        r++;
828
829        while(node != NULL)
830        {
831                if(node->del == FILELISTDELMARK && node->input == NULL)
832                {
833                        count++;
834                        if(count == r) break;
835                }
836
837                node = node->next;
838        }
839
840        return node;
841}
842
843#endif
Note: See TracBrowser for help on using the repository browser.