source: titan/titan/filelist.h @ 15283

Last change on this file since 15283 was 15283, checked in by nit, 12 years ago

fix

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