summaryrefslogtreecommitdiffstats
path: root/uisimulator
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2002-05-06 06:17:07 +0000
committerDaniel Stenberg <daniel@haxx.se>2002-05-06 06:17:07 +0000
commitff2e651d29a807741ebc2995726cf70c87537192 (patch)
tree9ad6bef547b2926df184262382ce7e4c93aa09e4 /uisimulator
parent551d8368aa95f91de33ce07a6722705542f77e3a (diff)
downloadrockbox-ff2e651d29a807741ebc2995726cf70c87537192.tar.gz
rockbox-ff2e651d29a807741ebc2995726cf70c87537192.zip
Dave Chapman's browse subdirs too patch applied
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@455 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator')
-rw-r--r--uisimulator/tree.c59
1 files changed, 50 insertions, 9 deletions
diff --git a/uisimulator/tree.c b/uisimulator/tree.c
index 74da12e9c7..744bbc75b0 100644
--- a/uisimulator/tree.c
+++ b/uisimulator/tree.c
@@ -34,8 +34,6 @@
#define TREE_MAX_ON_SCREEN 7
#define TREE_MAX_LEN_DISPLAY 17 /* max length that fits on screen */
-int dircursor=0;
-
void browse_root(void) {
dirbrowse("/");
}
@@ -52,6 +50,11 @@ struct entry {
#ifdef HAVE_LCD_BITMAP
+bool is_dir(char* path) {
+ DIR* dir = opendir(path);
+ return(dir!=0);
+}
+
int static
showdir(char *path, struct entry *buffer, int start)
{
@@ -60,7 +63,7 @@ showdir(char *path, struct entry *buffer, int start)
struct dirent *entry;
if(!dir)
- return 0; /* no entries */
+ return -1; /* not a directory */
i=start;
while((entry = readdir(dir))) {
@@ -92,7 +95,6 @@ showdir(char *path, struct entry *buffer, int start)
if(++i >= TREE_MAX_ON_SCREEN)
break;
}
- i--; /* number of files on screen */
closedir(dir);
@@ -105,13 +107,20 @@ bool dirbrowse(char *root)
{
struct entry buffer[TREE_MAX_ON_SCREEN];
int numentries;
+ char buf[255];
+ char currdir[255];
+ int dircursor=0;
+ int i;
#ifdef HAVE_LCD_BITMAP
lcd_clear_display();
lcd_puts(0,0, "[Browse]", 0);
+ memcpy(currdir,root,sizeof(currdir));
- numentries = showdir(root, buffer, 0);
+ numentries = showdir(root, buffer, 0);
+
+ if (numentries == -1) return -1; /* root is not a directory */
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
@@ -126,17 +135,49 @@ bool dirbrowse(char *root)
}
switch(key) {
case BUTTON_OFF:
- case BUTTON_LEFT:
return FALSE;
break;
+ case BUTTON_LEFT:
+ i=strlen(currdir);
+ if (i==1) {
+ return FALSE;
+ } else {
+ while (currdir[i-1]!='/') i--;
+ strcpy(buf,&currdir[i]);
+ if (i==1) currdir[i]=0;
+ else currdir[i-1]=0;
+
+ lcd_clear_display();
+ lcd_puts(0,0, "[Browse]", 0);
+ numentries = showdir(currdir, buffer, 0);
+ dircursor=0;
+ while ( (dircursor < TREE_MAX_ON_SCREEN) &&
+ (strcmp(buffer[dircursor].name,buf)!=0)) dircursor++;
+ lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
+ lcd_update();
+ }
+
+ break;
+
case BUTTON_RIGHT:
case BUTTON_PLAY:
- playtune(root, buffer[dircursor].name);
+ if ((currdir[0]=='/') && (currdir[1]==0)) {
+ sprintf(buf,"%s%s",currdir,buffer[dircursor].name);
+ } else {
+ sprintf(buf,"%s/%s",currdir,buffer[dircursor].name);
+ }
+
+ if (is_dir(buf)) {
+ memcpy(currdir,buf,sizeof(currdir));
+ dircursor=0;
+ } else {
+ playtune(currdir, buffer[dircursor].name);
+ }
lcd_clear_display();
lcd_puts(0,0, "[Browse]", 0);
- numentries = showdir(root, buffer, 0);
+ numentries = showdir(currdir, buffer, 0);
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
lcd_update();
break;
@@ -150,7 +191,7 @@ bool dirbrowse(char *root)
}
break;
case BUTTON_DOWN:
- if(dircursor < numentries) {
+ if(dircursor+1 < numentries) {
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, " ", 0);
dircursor++;
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);