mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-09 21:22:39 -05:00
Added directory sorting
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@822 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
f88f91153f
commit
1fc4fee8cb
1 changed files with 30 additions and 18 deletions
48
apps/tree.c
48
apps/tree.c
|
|
@ -46,7 +46,8 @@ struct entry {
|
||||||
char name[TREE_MAX_FILENAMELEN];
|
char name[TREE_MAX_FILENAMELEN];
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct entry buffer[MAX_FILES_IN_DIR];
|
static struct entry dircache[MAX_FILES_IN_DIR];
|
||||||
|
static struct entry* dircacheptr[MAX_FILES_IN_DIR];
|
||||||
static int filesindir;
|
static int filesindir;
|
||||||
|
|
||||||
void browse_root(void)
|
void browse_root(void)
|
||||||
|
|
@ -77,6 +78,12 @@ extern unsigned char bitmap_icons_6x8[LastIcon][6];
|
||||||
|
|
||||||
#endif /* HAVE_LCD_BITMAP */
|
#endif /* HAVE_LCD_BITMAP */
|
||||||
|
|
||||||
|
static int compare(const void* e1, const void* e2)
|
||||||
|
{
|
||||||
|
return strncmp((*(struct entry**)e1)->name, (*(struct entry**)e2)->name,
|
||||||
|
TREE_MAX_FILENAMELEN);
|
||||||
|
}
|
||||||
|
|
||||||
static int showdir(char *path, int start)
|
static int showdir(char *path, int start)
|
||||||
{
|
{
|
||||||
static char lastdir[256] = {0};
|
static char lastdir[256] = {0};
|
||||||
|
|
@ -91,6 +98,7 @@ static int showdir(char *path, int start)
|
||||||
DIR *dir = opendir(path);
|
DIR *dir = opendir(path);
|
||||||
if(!dir)
|
if(!dir)
|
||||||
return -1; /* not a directory */
|
return -1; /* not a directory */
|
||||||
|
memset(dircacheptr,0,sizeof(dircacheptr));
|
||||||
for ( i=0; i<MAX_FILES_IN_DIR; i++ ) {
|
for ( i=0; i<MAX_FILES_IN_DIR; i++ ) {
|
||||||
struct dirent *entry = readdir(dir);
|
struct dirent *entry = readdir(dir);
|
||||||
if (!entry)
|
if (!entry)
|
||||||
|
|
@ -100,14 +108,16 @@ static int showdir(char *path, int start)
|
||||||
i--;
|
i--;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
buffer[i].file = !(entry->attribute & ATTR_DIRECTORY);
|
dircache[i].file = !(entry->attribute & ATTR_DIRECTORY);
|
||||||
strncpy(buffer[i].name,entry->d_name,TREE_MAX_FILENAMELEN);
|
strncpy(dircache[i].name,entry->d_name,TREE_MAX_FILENAMELEN);
|
||||||
buffer[i].name[TREE_MAX_FILENAMELEN-1]=0;
|
dircache[i].name[TREE_MAX_FILENAMELEN-1]=0;
|
||||||
|
dircacheptr[i] = &dircache[i];
|
||||||
}
|
}
|
||||||
filesindir = i;
|
filesindir = i;
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
strncpy(lastdir,path,sizeof(lastdir));
|
strncpy(lastdir,path,sizeof(lastdir));
|
||||||
lastdir[sizeof(lastdir)-1] = 0;
|
lastdir[sizeof(lastdir)-1] = 0;
|
||||||
|
qsort(dircacheptr,filesindir,sizeof(struct entry*),compare);
|
||||||
}
|
}
|
||||||
|
|
||||||
lcd_clear_display();
|
lcd_clear_display();
|
||||||
|
|
@ -122,10 +132,10 @@ static int showdir(char *path, int start)
|
||||||
if ( i >= filesindir )
|
if ( i >= filesindir )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
len = strlen(buffer[i].name);
|
len = strlen(dircacheptr[i]->name);
|
||||||
|
|
||||||
#ifdef HAVE_LCD_BITMAP
|
#ifdef HAVE_LCD_BITMAP
|
||||||
if ( buffer[i].file )
|
if ( dircacheptr[i]->file )
|
||||||
icon_type=File;
|
icon_type=File;
|
||||||
else
|
else
|
||||||
icon_type=Folder;
|
icon_type=Folder;
|
||||||
|
|
@ -134,12 +144,12 @@ static int showdir(char *path, int start)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(len < TREE_MAX_LEN_DISPLAY)
|
if(len < TREE_MAX_LEN_DISPLAY)
|
||||||
lcd_puts(LINE_X, LINE_Y+i-start, buffer[i].name);
|
lcd_puts(LINE_X, LINE_Y+i-start, dircacheptr[i]->name);
|
||||||
else {
|
else {
|
||||||
char storage = buffer[i].name[TREE_MAX_LEN_DISPLAY];
|
char storage = dircacheptr[i]->name[TREE_MAX_LEN_DISPLAY];
|
||||||
buffer[i].name[TREE_MAX_LEN_DISPLAY]=0;
|
dircacheptr[i]->name[TREE_MAX_LEN_DISPLAY]=0;
|
||||||
lcd_puts(LINE_X, LINE_Y+i-start, buffer[i].name);
|
lcd_puts(LINE_X, LINE_Y+i-start, dircacheptr[i]->name);
|
||||||
buffer[i].name[TREE_MAX_LEN_DISPLAY]=storage;
|
dircacheptr[i]->name[TREE_MAX_LEN_DISPLAY]=storage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -205,8 +215,8 @@ bool dirbrowse(char *root)
|
||||||
start = 0;
|
start = 0;
|
||||||
numentries = showdir(currdir, start);
|
numentries = showdir(currdir, start);
|
||||||
dircursor=0;
|
dircursor=0;
|
||||||
while ( (dircursor < TREE_MAX_ON_SCREEN) &&
|
while ( (dircursor < TREE_MAX_ON_SCREEN) &&
|
||||||
(strcmp(buffer[dircursor+start].name,buf)!=0))
|
(strcmp(dircacheptr[dircursor+start]->name,buf)))
|
||||||
dircursor++;
|
dircursor++;
|
||||||
if (dircursor==TREE_MAX_ON_SCREEN)
|
if (dircursor==TREE_MAX_ON_SCREEN)
|
||||||
dircursor=0;
|
dircursor=0;
|
||||||
|
|
@ -222,12 +232,14 @@ bool dirbrowse(char *root)
|
||||||
#endif
|
#endif
|
||||||
case BUTTON_PLAY:
|
case BUTTON_PLAY:
|
||||||
if ((currdir[0]=='/') && (currdir[1]==0)) {
|
if ((currdir[0]=='/') && (currdir[1]==0)) {
|
||||||
snprintf(buf,sizeof(buf),"%s%s",currdir,buffer[dircursor+start].name);
|
snprintf(buf,sizeof(buf),"%s%s",currdir,
|
||||||
|
dircacheptr[dircursor+start]->name);
|
||||||
} else {
|
} else {
|
||||||
snprintf(buf,sizeof(buf),"%s/%s",currdir,buffer[dircursor+start].name);
|
snprintf(buf,sizeof(buf),"%s/%s",currdir,
|
||||||
|
dircacheptr[dircursor+start]->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!buffer[dircursor+start].file) {
|
if (!dircacheptr[dircursor+start]->file) {
|
||||||
memcpy(currdir,buf,sizeof(currdir));
|
memcpy(currdir,buf,sizeof(currdir));
|
||||||
if ( dirlevel < MAX_DIR_LEVELS )
|
if ( dirlevel < MAX_DIR_LEVELS )
|
||||||
dirpos[dirlevel] = start+dircursor;
|
dirpos[dirlevel] = start+dircursor;
|
||||||
|
|
@ -235,7 +247,7 @@ bool dirbrowse(char *root)
|
||||||
dircursor=0;
|
dircursor=0;
|
||||||
start=0;
|
start=0;
|
||||||
} else {
|
} else {
|
||||||
playtune(currdir, buffer[dircursor+start].name);
|
playtune(currdir, dircacheptr[dircursor+start]->name);
|
||||||
#ifdef HAVE_LCD_BITMAP
|
#ifdef HAVE_LCD_BITMAP
|
||||||
lcd_setmargins(0, MARGIN_Y);
|
lcd_setmargins(0, MARGIN_Y);
|
||||||
lcd_setfont(0);
|
lcd_setfont(0);
|
||||||
|
|
@ -305,7 +317,7 @@ bool dirbrowse(char *root)
|
||||||
numentries = showdir(currdir, start);
|
numentries = showdir(currdir, start);
|
||||||
dircursor=0;
|
dircursor=0;
|
||||||
while ( (dircursor < TREE_MAX_ON_SCREEN) &&
|
while ( (dircursor < TREE_MAX_ON_SCREEN) &&
|
||||||
(strcmp(buffer[dircursor+start].name,buf)!=0))
|
(strcmp(dircacheptr[dircursor+start]->name,buf)))
|
||||||
dircursor++;
|
dircursor++;
|
||||||
if (dircursor==TREE_MAX_ON_SCREEN)
|
if (dircursor==TREE_MAX_ON_SCREEN)
|
||||||
dircursor=0;
|
dircursor=0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue