source: titan/titan/filelist.h @ 23267

Last change on this file since 23267 was 23267, checked in by nit, 11 years ago

[titan] cleanup

File size: 22.4 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, 2);
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, 2);
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, 2);
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, 2);
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        {
208                err("NULL detect");
209                return 1;
210        }
211
212        if(view == 2)
213                node->type |= GRID;
214        else
215                node->type &= ~(GRID);
216       
217
218        status.tmp = node->input;
219        switch(getconfigint("dirsort", NULL))
220        {
221                case 1: cmpfunc = ralphasort64; break;
222                case 2: cmpfunc = sizesort64; break;
223                case 3: cmpfunc = rsizesort64; break;
224                case 4: cmpfunc = datesort64; break;
225                case 5: cmpfunc = rdatesort64; break;
226                default: cmpfunc = oalphasort64; break;
227        }
228
229        count = scandir64(node->input , &filelist, 0, cmpfunc);
230        if(count < 0)
231        {
232                if(getconfig("failbackpath", NULL) != NULL)
233                {
234                        perr("scandir");
235                        count = scandir64(getconfig("failbackpath", NULL) , &filelist, 0, cmpfunc);
236                        changeinput(node, getconfig("failbackpath", NULL));
237                }
238                if(count < 0)
239                {
240                        perr("scandir");
241                        count = scandir64("/" , &filelist, 0, cmpfunc);
242                        changeinput(node, "/");
243                }
244                if(count < 0)
245                        return 1;
246        }
247
248        status.tmp = NULL;
249        parentdir = addscreennode(screen, NULL, child);
250
251        if(view == 2 && parentdir != NULL)
252        {
253                sumcount++;
254                pagecount++;
255                debug(913, "pdir: pagecount: %d", pagecount);
256                debug(913, "pdir: sumcount: %d", sumcount);
257
258                parentdir->picheight = 180;
259                parentdir->picwidth = 180;                             
260                parentdir->height = 230;
261                parentdir->width = 370;
262                parentdir->prozwidth = 0;
263                //parentdir->bgcol = 0xffffff;
264                parentdir->bgspace = 1;
265                parentdir->vspace = 10;
266                parentdir->hspace = 10;
267                parentdir->posx = posx;
268                //parentdir->fontcol = 0x0000ff;
269                parentdir->halign = CENTER;
270                parentdir->valign = TEXTBOTTOM;
271                posx += parentdir->width;
272               
273                tmpstr = ostrcat(tmpstr, "skin/ext_grid_changedir.png", 1, 0);
274                debug(913, "picpath: %s", tmpstr);
275                changepic(parentdir, tmpstr);
276                free(tmpstr); tmpstr = NULL;
277
278                parentdir->type = GRIDBR;
279                gridbr++;
280        }
281
282//      if(view == 2 || view == 3)
283//              m_lock(&status.mediadbmutex, 17);
284       
285        child = parentdir;
286
287        //if the dir is empty add backpath
288        if(count == 0)
289        {
290                free(filelist);
291                filelist = (struct dirent64**)malloc(1 * sizeof(struct dirent*));
292                struct dirent64* p = (struct dirent64*)malloc(sizeof(struct dirent64));
293                p->d_type = DT_DIR;
294                bcopy("..", p->d_name, 3);
295                filelist[0] = p;
296                count = 1;
297        }
298
299        tmpcount = count;
300        while(tmpcount--)
301        {
302                //check if link is a dir or wenn unknown (rarfs ...)
303                if(filelist[i]->d_type == DT_LNK || filelist[i]->d_type == DT_UNKNOWN)
304                {
305                        tmpstr = createpath(node->input, filelist[i]->d_name);
306                        if(isdir(tmpstr) == 1)
307                                filelist[i]->d_type = DT_DIR;
308
309                        //for nfs mounts if file type is unknown use stat
310                        if(filelist[i]->d_type == DT_UNKNOWN)
311                                filelist[i]->d_type = getfiletype(tmpstr);
312       
313                        free(tmpstr); tmpstr = NULL;
314                }
315
316                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))))
317                {
318                        if(ostrcmp(filelist[i]->d_name, "..") == 0)
319                        {
320                                oldchild = child;
321                                child = parentdir;
322                        }
323                        else
324                                child = addscreennode(screen, NULL, child);
325                        if(child != NULL)
326                        {
327                                if(view == 2)
328                                {
329                                        if(gridbr == 0) child->type = GRIDBR;
330
331                                        if(child != parentdir)
332                                        {
333                                                sumcount++;
334                                                pagecount++;
335                                                debug(913, "dir: pagecount: %d", pagecount);
336                                                debug(913, "dir: sumcount: %d", sumcount);
337                                               
338                                                debug(913, "filename: %s", filelist[i]->d_name);
339                                                child->picheight = 180;
340                                                child->picwidth = 180;
341                                                               
342                                                child->height = 230;
343                                                child->width = 370;
344                                                child->prozwidth = 0;
345                                                //child->bgcol = 0xffffff;
346                                                child->bgspace = 1;
347                                                child->vspace = 10;
348                                                child->hspace = 10;
349                                                //child->fontcol = 0x0000ff;
350                                                child->halign = CENTER;
351                                                child->valign = TEXTBOTTOM;
352       
353                                                child->posx = posx;
354                                                posx += child->width;
355
356                                                char* currentdir = getcurrentdir(node->input);
357
358                                                if(ostrcmp(filelist[i]->d_name, "autofs") == 0)
359                                                        tmpstr = ostrcat(tmpstr, "skin/ext_grid_autofs.png", 1, 0);
360                                                else if(ostrcmp(filelist[i]->d_name, "hdd") == 0)
361                                                        tmpstr = ostrcat(tmpstr, "skin/ext_grid_harddisk.png", 1, 0);
362                                                else if((ostrcmp(filelist[i]->d_name, "usb") == 0) || (ostrcmp(currentdir, "usb") == 0))
363                                                        tmpstr = ostrcat(tmpstr, "skin/ext_grid_usb.png", 1, 0);
364                                                else if((ostrcmp(filelist[i]->d_name, "net") == 0) || (ostrcmp(currentdir, "net") == 0))
365                                                        tmpstr = ostrcat(tmpstr, "skin/ext_grid_network.png", 1, 0);
366                                                else
367                                                {
368                                                        char* shortname = ostrcat(filelist[i]->d_name, NULL, 0, 0);
369                                                        string_tolower(shortname);
370                                                        string_removechar(shortname);
371                                                        strstrip(shortname);
372
373                                                        tmpstr = ostrcat(tmpstr, getconfig("mediadbpath", NULL), 1, 0);
374                                                        tmpstr = ostrcat(tmpstr, "/imdbfolder/", 1, 0);                                                                                                                                                 
375                                                        tmpstr = ostrcat(tmpstr, shortname, 1, 0);
376                                                        tmpstr = ostrcat(tmpstr, ".png", 1, 0);
377                                                        free(shortname); shortname = NULL;
378                                                                                                       
379                                                        if(!file_exist(tmpstr))
380                                                        {
381                                                                free(tmpstr); tmpstr = NULL;
382                                                                tmpstr = ostrcat(tmpstr, "skin/ext_grid_directory.png", 1, 0);
383                                                        }
384                                                }
385
386                                                free(currentdir); currentdir = NULL;
387
388                                                if(tmpstr != NULL)
389                                                {
390                                                        debug(913, "picpath: %s", tmpstr);
391                                                        debug(913, "dir: change pic");
392                                                        changepic(child, tmpstr);
393                                                        free(tmpstr); tmpstr = NULL;
394                                                }                                       
395                                                gridbr++;
396                                        }
397                                        if(gridbr >= 3)
398                                        {
399                                                gridbr = 0;
400                                                posx = 0;
401                                        }
402                                }                       
403                                else                           
404                                {
405                                        debug(913, "picpath: %s", node->pic);
406                                        if(node->pic != NULL)
407                                                changepic(child, node->pic);
408                                }
409                                changetext(child, filelist[i]->d_name);
410                                changename(child, filelist[i]->d_name);
411                                child->parentpointer = node;
412                                child->bordercol = node->bordercol;
413
414                                if(view != 2)
415                                {
416                                        child->valign = MIDDLE;
417                                        child->width = 100;                                                                                                                                     
418                                        child->prozwidth = 1;
419                                        child->height = node->fontsize + 2 + (node->bordersize * 2);
420                                        child->textposx = node->textposx;                               
421                                }
422                                else
423                                        child->textposx = 1;
424
425                                child->del = FILELISTDELMARK;
426                                tmpstr = createpath(node->input, child->text);
427                                changeinput(child, tmpstr);
428                                free(tmpstr); tmpstr = NULL;
429
430                                if(view > 3)
431                                {
432                                        child->filelist = (struct filelist*)calloc(1, sizeof(struct filelist));
433                                        if(child->filelist == NULL)
434                                        {
435                                                err("no mem");
436                                                continue;
437                                        }
438                                        child->filelist->type = filelist[i]->d_type;
439                                        child->filelist->view = view;
440
441                                        tmpstr = createpath(node->input, filelist[i]->d_name);
442                                        rpath = realpath(tmpstr, NULL);
443                                        if(view == 4) child->filelist->size = getfilesize(rpath);
444                                        else if(view == 5) child->filelist->date = getfiletime(rpath, 2);
445                                        free(rpath); rpath = NULL;
446                                        free(tmpstr); tmpstr = NULL;
447                                }
448                        }
449                        if(parentdir == child)
450                                child = oldchild;
451
452                }
453                i++;
454        }
455
456        tmpcount = count;
457        i=0;
458        while(tmpcount--)
459        {
460                if(filelist[i]->d_type != DT_DIR && filelist[i]->d_name != NULL && (status.showhiddenfiles == 1 || (status.showhiddenfiles == 0 && filelist[i]->d_name[0] != '.')))
461                {
462                        if(filelistfilter(node, filelist[i]->d_name) == 0)
463                        {
464                                child = addscreennode(screen, NULL, child);
465                                if(child != NULL)
466                                {
467                                        debug(913, "filename: %s", filelist[i]->d_name);
468                                        if(view == 2)
469                                        {
470                                                sumcount++;
471                                                pagecount++;
472                                                debug(913, "files: pagecount: %d", pagecount);
473                                                debug(913, "files: sumcount: %d", sumcount);
474
475                                                if(gridbr == 0) child->type = GRIDBR;
476       
477                                                child->picheight = 170;
478                                                child->picwidth = 140;
479                                                child->height = 230;
480                                                child->width = 370;
481                                                child->prozwidth = 0;
482                                                //child->bgcol = 0xffffff;
483                                                child->bgspace = 1;
484                                                child->vspace = 10;
485                                                child->hspace = 10;
486                                                //child->fontcol = 0x0000ff;
487                                                child->halign = CENTER;
488                                                child->valign = TEXTBOTTOM;
489       
490                                                child->posx = posx;
491                                                posx += child->width;
492
493                                                if(cmpfilenameext(filelist[i]->d_name, ".png") == 0)
494                                                {
495                                                        tmpstr = ostrcat(createpath(node->input, "/"), filelist[i]->d_name, 1, 0);
496//                                                      child->picheight = 210;
497//                                                      child->picwidth = 350;
498                                                        child->picwidth = 1;
499                                                        child->picheight = 1;
500                                                }
501                                                else if(cmpfilenameext(filelist[i]->d_name, ".jpg") == 0)
502                                                {
503                                                        if(status.thumbthread != NULL)
504                                                        {
505                                                                //check if thumb exists
506                                                                tmpstr = checkthumb(node->input, filelist[i]->d_name);
507                                                                if(tmpstr == NULL)
508                                                                {
509                                                                        addqueue(101, (void*)node->input, strlen(node->input) + 1, (void*)filelist[i]->d_name, strlen(filelist[i]->d_name) + 1, 0, NULL);
510                                                                        child->picheight = 180;
511                                                                        child->picwidth = 180;
512                                                                }
513                                                                else
514                                                                {
515                                                                        child->picwidth = 1;
516                                                                        child->picheight = 1;
517                                                                }
518                                                        }
519                                                        if(tmpstr == NULL) tmpstr = ostrcat(tmpstr, "skin/ext_grid_dummy.png", 1, 0);
520                                                }
521                                                else if(cmpfilenameext(filelist[i]->d_name, ".iso") == 0)
522                                                        tmpstr = ostrcat(tmpstr, "skin/ext_grid_iso.png", 1, 0);
523                                                else if(cmpfilenameext(filelist[i]->d_name, ".img") == 0)
524                                                        tmpstr = ostrcat(tmpstr, "skin/ext_grid_img.png", 1, 0);
525                                                else if(cmpfilenameext(filelist[i]->d_name, ".rar") == 0)
526                                                        tmpstr = ostrcat(tmpstr, "skin/ext_grid_rar.png", 1, 0);
527                                                else
528                                                {
529                                                        int fast = 0;
530                                                        if(fast == 1)
531                                                                tmpstr = ostrcat(tmpstr, changefilenameext(filelist[i]->d_name, ".jpg"), 1, 1);
532                                                        else
533                                                        {                                               
534//                                                              free(tmpstr), tmpstr = NULL;
535//                                                              tmpstr = ostrcat(node->input, "/", 0, 0);
536//                                                              tmpstr = ostrcat(tmpstr, filelist[i]->d_name, 1, 0);                                                           
537//                                                              struct mediadb* mnode = getmediadb(tmpstr, 0);
538                                                               
539                                                                struct mediadb* mnode = getmediadb(node->input, filelist[i]->d_name, 0);
540                                                                free(tmpstr), tmpstr = NULL;
541                                                                if(mnode != NULL)
542                                                                {
543                                                                        int musik = 0;
544                                                                        if(cmpfilenameext(filelist[i]->d_name, ".mp3") == 0)
545                                                                                musik = 1;
546                                                                        else if(cmpfilenameext(filelist[i]->d_name, ".flac") == 0)
547                                                                                musik = 1;
548                                                                        else if(cmpfilenameext(filelist[i]->d_name, ".ogg") == 0)
549                                                                                musik = 1;
550                                                                        else if(cmpfilenameext(filelist[i]->d_name, ".ra") == 0)
551                                                                                musik = 1;
552                                                                        else if(cmpfilenameext(filelist[i]->d_name, ".wav") == 0)
553                                                                                musik = 1;
554                                                               
555                                                                        if(mnode->id != NULL && ostrstr(mnode->id, "tt") == NULL)
556                                                                        {
557                                                                                child->picheight = 180;
558                                                                                child->picwidth = 300;
559                                                                        }
560
561                                                                        int len1 = strlen(mnode->title);
562                                                                        int len2 = strlen(mnode->actors);
563                                                                        if((mnode->title != NULL && len1 != 0 && musik == 0) || (mnode->actors != NULL && len2 != 0 && mnode->title != NULL && len1 != 0 && musik == 1))
564                                                                        {
565                                                                                if(musik == 1)
566                                                                                {
567                                                                                        tmpstr = ostrcat(tmpstr, mnode->actors, 1, 0);
568                                                                                        tmpstr = ostrcat(tmpstr, " - ", 1, 0);
569                                                                                        tmpstr = ostrcat(tmpstr, mnode->title, 1, 0);
570                                                                                }
571                                                                                else
572                                                                                {
573                                                                                        len1 = strlen(mnode->shortname);
574                                                                                        if(mnode->shortname != NULL && len1 != 0)
575                                                                                        {
576                                                                                                tmpstr = ostrcat(tmpstr, mnode->shortname, 1, 0);
577                                                                                        }
578                                                                                        else
579                                                                                                tmpstr = ostrcat(tmpstr, filelist[i]->d_name, 1, 0);
580                                                                                }
581       
582                                                                                len1 = strlen(mnode->fileinfo);         
583                                                                                if(mnode->fileinfo != NULL && len1 != 0)
584                                                                                {
585                                                                                        tmpstr = ostrcat(tmpstr, " (", 1, 0);
586                                                                                        tmpstr = ostrcat(tmpstr, mnode->fileinfo, 1, 0);
587                                                                                        tmpstr = ostrcat(tmpstr, ")", 1, 0);
588                                                                                }
589                                                                                       
590                                                                                changetext(child, tmpstr);
591                                                                                free(tmpstr), tmpstr = NULL;
592                                                                        }
593                                                                        else
594                                                                                changetext(child, filelist[i]->d_name);
595
596                                                                        if(mnode->id != NULL)
597                                                                        {
598                                                                                tmpstr = ostrcat(tmpstr, getconfig("mediadbpath", NULL), 1, 0);
599                                                                                tmpstr = ostrcat(tmpstr, "/", 1, 0);                                                                                                                                                   
600                                                                                tmpstr = ostrcat(tmpstr, mnode->id, 1, 0);
601// cover + thumb unscharf
602                                                                                if(musik == 1)
603                                                                                        tmpstr = ostrcat(tmpstr, "_cover.jpg", 1, 0);
604                                                                                else
605                                                                                        tmpstr = ostrcat(tmpstr, "_cover.jpg", 1, 0);
606                                                                        }
607
608                                                                }
609                                                                else
610                                                                        changetext(child, filelist[i]->d_name);                                                                                                                         
611                                                        }
612                                                       
613                                                        if(!file_exist(tmpstr))
614                                                        {
615                                                                free(tmpstr); tmpstr = NULL;
616                                                                child->picheight = 180;
617                                                                child->picwidth = 180;
618                                                                tmpstr = ostrcat(tmpstr, "skin/ext_grid_dummy.png", 1, 0);
619                                                        }
620                                                }
621                                                debug(913, "picpath: %s", tmpstr);
622                                                if(tmpstr != NULL)
623                                                {
624                                                        debug(913, "files: change pic");
625                                                        changepic(child, tmpstr);
626                                                        free(tmpstr); tmpstr = NULL;
627                                                }
628                                       
629                                                gridbr++;
630                                                if(gridbr >= 3)
631                                                {
632                                                        gridbr = 0;
633                                                        posx = 0;
634                                                }
635                                        }
636                                        else
637                                        {
638                                                tmpstr = ostrcat(tmpstr, "skin/ext_", 1, 0);
639//                                              tmpstr = ostrcat(tmpstr, string_tolower(getfilenameext(filelist[i]->d_name)), 1, 1);
640                                                tmpstr = ostrcat(tmpstr, string_tolower(getfilenamepng(filelist[i]->d_name)), 1, 1);
641                                                tmpstr = ostrcat(tmpstr, ".png", 1, 0);
642                                                debug(913, "picpath: %s", tmpstr);
643                                                if(tmpstr != NULL)
644                                                        changepic(child, tmpstr);
645                                                free(tmpstr); tmpstr = NULL;
646                                        }
647
648                                        child->bordercol = node->bordercol;
649                                        if(view != 2)
650                                        {
651                                                child->valign = MIDDLE;
652                                                child->width = 100;
653                                                child->prozwidth = 1;
654                                                child->height = node->fontsize + 2 + (node->bordersize * 2);
655                                                child->textposx = node->textposx;                       
656                                        }
657                                        else
658                                                child->textposx = 1;
659
660                                        if(view != 2)
661                                                changetext(child, filelist[i]->d_name);
662                                        changename(child, filelist[i]->d_name);
663                                       
664                                        child->parentpointer = node;
665
666                                        child->del = FILELISTDELMARK;
667                                        changeinput(child, NULL);
668
669                                        if(view > 3)
670                                        {
671                                                child->filelist = (struct filelist*)calloc(1, sizeof(struct filelist));
672                                                if(child->filelist == NULL)
673                                                {
674                                                        err("no mem");
675                                                        continue;
676                                                }
677                                                child->filelist->type = filelist[i]->d_type;
678                                                child->filelist->view = view;
679
680                                                tmpstr = createpath(node->input, filelist[i]->d_name);
681                                                rpath = realpath(tmpstr, NULL);
682                                                if(view == 4) child->filelist->size = getfilesize(rpath);
683                                                else if(view == 5) child->filelist->date = getfiletime(rpath, 2);
684                                                free(rpath); rpath = NULL;
685                                                free(tmpstr); tmpstr = NULL;
686                                        }
687                                        if(view == 3)
688                                        {
689                                                struct mediadb* mnode = getmediadb(node->input, filelist[i]->d_name, 0);
690                                                int musik = 0;
691                                                if(cmpfilenameext(filelist[i]->d_name, ".mp3") == 0)
692                                                        musik = 1;
693                                                else if(cmpfilenameext(filelist[i]->d_name, ".flac") == 0)
694                                                        musik = 1;
695                                                else if(cmpfilenameext(filelist[i]->d_name, ".ogg") == 0)
696                                                        musik = 1;
697                                                else if(cmpfilenameext(filelist[i]->d_name, ".ra") == 0)
698                                                        musik = 1;
699                                                else if(cmpfilenameext(filelist[i]->d_name, ".wav") == 0)
700                                                        musik = 1;
701
702                                                if(mnode != NULL)
703                                                {
704                                                        int len1 = strlen(mnode->title);
705                                                        int len2 = strlen(mnode->actors);
706                                                        if((mnode->title != NULL && len1 != 0 && musik == 0) || (mnode->actors != NULL && len2 != 0 && mnode->title != NULL && len1 != 0 && musik == 1))
707                                                        {
708                                                                if(musik == 1)
709                                                                {
710                                                                        tmpstr = ostrcat(tmpstr, mnode->actors, 1, 0);
711                                                                        tmpstr = ostrcat(tmpstr, " - ", 1, 0);
712                                                                        tmpstr = ostrcat(tmpstr, mnode->title, 1, 0);
713                                                                }
714                                                                else
715                                                                {
716                                                                        len1 = strlen(mnode->shortname);
717                                                                        if(mnode->shortname != NULL && len1 != 0)
718                                                                        {
719                                                                                tmpstr = ostrcat(tmpstr, mnode->shortname, 1, 0);
720                                                                        }
721                                                                        else
722                                                                                tmpstr = ostrcat(tmpstr, filelist[i]->d_name, 1, 0);                                                                   
723                                                                }
724
725                                                                len1 = strlen(mnode->fileinfo);                                                         
726                                                                if(mnode->fileinfo != NULL && len1 != 1)
727                                                                {
728                                                                        tmpstr = ostrcat(tmpstr, " (", 1, 0);
729                                                                        tmpstr = ostrcat(tmpstr, mnode->fileinfo, 1, 0);
730                                                                        tmpstr = ostrcat(tmpstr, ")", 1, 0);
731                                                                }
732                                                                changetext(child, tmpstr);
733                                                                free(tmpstr), tmpstr = NULL;
734                                                        }
735                                                        else
736                                                                changetext(child, filelist[i]->d_name);
737                                                }
738                                        }
739                                }
740                        }
741                }
742                free(filelist[i]);
743                i++;
744        }
745
746//      if(view == 2 || view == 3)
747//              m_unlock(&status.mediadbmutex, 17);     
748/*
749        for (i = 0; i <= pagecount; i++)
750        {
751                printf("delmarkedpic=%d\n", i + 1000);
752                delmarkedpic(i + 1000);
753        }
754*/
755        free(filelist);
756        return 0;
757}
758
759void getfilelist(struct skin* input, struct skin* filelistpath, struct skin* filelist, char* path, char* filemask, int tmpview, char* selection)
760{
761        char* tmpstr = NULL;
762
763        if(path == NULL || strlen(path) == 0 || !isdir(path))
764                tmpstr = strdup("/");
765        else
766                tmpstr = strdup(path);
767
768        filelist->aktline = 0;
769        filelist->aktpage = 0;
770
771        if(filemask == NULL)
772                changemask(filelist, "*");
773        else
774                changemask(filelist, filemask);
775
776        changeinput(filelist, tmpstr);
777        changetext(filelistpath, filelist->input);
778        free(tmpstr); tmpstr = NULL;
779
780        tmpstr = ostrcat(selection, NULL, 0, 0);
781
782        delmarkedscreennodes(input, FILELISTDELMARK);
783
784        if (tmpview == -1)
785                createfilelist(input, filelist, 0);
786        else
787                createfilelist(input, filelist, tmpview);
788
789        if(tmpstr != NULL)
790                setlistboxselection(filelist, tmpstr);
791        free(tmpstr); tmpstr = NULL;
792
793        drawscreen(input, 0, 0);
794}
795
796void getfilelistmax(struct skin* filelist, int* maxdirs, int* maxfiles)
797{
798        struct skin* node = filelist;
799
800        while(node != NULL)
801        {
802                if(node->del == FILELISTDELMARK)
803                {
804                        if(node->input != NULL)
805                                (*maxdirs)++;
806                        else
807                                (*maxfiles)++;
808                }
809                node = node->next;
810        }
811}
812
813struct skin* getfilelistrandom(struct skin* filelist, int maxdirs, int maxfiles)
814{
815        int count = 0;
816        struct skin* node = filelist;
817       
818        if(maxfiles < 1) return NULL;
819
820        int r = getrandom(maxfiles);
821        r++;
822
823        while(node != NULL)
824        {
825                if(node->del == FILELISTDELMARK && node->input == NULL)
826                {
827                        count++;
828                        if(count == r) break;
829                }
830
831                node = node->next;
832        }
833
834        return node;
835}
836
837#endif
Note: See TracBrowser for help on using the repository browser.