summaryrefslogtreecommitdiff
path: root/uisimulator
diff options
context:
space:
mode:
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 @@
34#define TREE_MAX_ON_SCREEN 7 34#define TREE_MAX_ON_SCREEN 7
35#define TREE_MAX_LEN_DISPLAY 17 /* max length that fits on screen */ 35#define TREE_MAX_LEN_DISPLAY 17 /* max length that fits on screen */
36 36
37int dircursor=0;
38
39void browse_root(void) { 37void browse_root(void) {
40 dirbrowse("/"); 38 dirbrowse("/");
41} 39}
@@ -52,6 +50,11 @@ struct entry {
52 50
53#ifdef HAVE_LCD_BITMAP 51#ifdef HAVE_LCD_BITMAP
54 52
53bool is_dir(char* path) {
54 DIR* dir = opendir(path);
55 return(dir!=0);
56}
57
55int static 58int static
56showdir(char *path, struct entry *buffer, int start) 59showdir(char *path, struct entry *buffer, int start)
57{ 60{
@@ -60,7 +63,7 @@ showdir(char *path, struct entry *buffer, int start)
60 struct dirent *entry; 63 struct dirent *entry;
61 64
62 if(!dir) 65 if(!dir)
63 return 0; /* no entries */ 66 return -1; /* not a directory */
64 67
65 i=start; 68 i=start;
66 while((entry = readdir(dir))) { 69 while((entry = readdir(dir))) {
@@ -92,7 +95,6 @@ showdir(char *path, struct entry *buffer, int start)
92 if(++i >= TREE_MAX_ON_SCREEN) 95 if(++i >= TREE_MAX_ON_SCREEN)
93 break; 96 break;
94 } 97 }
95 i--; /* number of files on screen */
96 98
97 closedir(dir); 99 closedir(dir);
98 100
@@ -105,13 +107,20 @@ bool dirbrowse(char *root)
105{ 107{
106 struct entry buffer[TREE_MAX_ON_SCREEN]; 108 struct entry buffer[TREE_MAX_ON_SCREEN];
107 int numentries; 109 int numentries;
110 char buf[255];
111 char currdir[255];
112 int dircursor=0;
113 int i;
108 114
109#ifdef HAVE_LCD_BITMAP 115#ifdef HAVE_LCD_BITMAP
110 lcd_clear_display(); 116 lcd_clear_display();
111 117
112 lcd_puts(0,0, "[Browse]", 0); 118 lcd_puts(0,0, "[Browse]", 0);
119 memcpy(currdir,root,sizeof(currdir));
113 120
114 numentries = showdir(root, buffer, 0); 121 numentries = showdir(root, buffer, 0);
122
123 if (numentries == -1) return -1; /* root is not a directory */
115 124
116 lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0); 125 lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
117 126
@@ -126,17 +135,49 @@ bool dirbrowse(char *root)
126 } 135 }
127 switch(key) { 136 switch(key) {
128 case BUTTON_OFF: 137 case BUTTON_OFF:
129 case BUTTON_LEFT:
130 return FALSE; 138 return FALSE;
131 break; 139 break;
132 140
141 case BUTTON_LEFT:
142 i=strlen(currdir);
143 if (i==1) {
144 return FALSE;
145 } else {
146 while (currdir[i-1]!='/') i--;
147 strcpy(buf,&currdir[i]);
148 if (i==1) currdir[i]=0;
149 else currdir[i-1]=0;
150
151 lcd_clear_display();
152 lcd_puts(0,0, "[Browse]", 0);
153 numentries = showdir(currdir, buffer, 0);
154 dircursor=0;
155 while ( (dircursor < TREE_MAX_ON_SCREEN) &&
156 (strcmp(buffer[dircursor].name,buf)!=0)) dircursor++;
157 lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
158 lcd_update();
159 }
160
161 break;
162
133 case BUTTON_RIGHT: 163 case BUTTON_RIGHT:
134 case BUTTON_PLAY: 164 case BUTTON_PLAY:
135 playtune(root, buffer[dircursor].name); 165 if ((currdir[0]=='/') && (currdir[1]==0)) {
166 sprintf(buf,"%s%s",currdir,buffer[dircursor].name);
167 } else {
168 sprintf(buf,"%s/%s",currdir,buffer[dircursor].name);
169 }
170
171 if (is_dir(buf)) {
172 memcpy(currdir,buf,sizeof(currdir));
173 dircursor=0;
174 } else {
175 playtune(currdir, buffer[dircursor].name);
176 }
136 177
137 lcd_clear_display(); 178 lcd_clear_display();
138 lcd_puts(0,0, "[Browse]", 0); 179 lcd_puts(0,0, "[Browse]", 0);
139 numentries = showdir(root, buffer, 0); 180 numentries = showdir(currdir, buffer, 0);
140 lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0); 181 lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
141 lcd_update(); 182 lcd_update();
142 break; 183 break;
@@ -150,7 +191,7 @@ bool dirbrowse(char *root)
150 } 191 }
151 break; 192 break;
152 case BUTTON_DOWN: 193 case BUTTON_DOWN:
153 if(dircursor < numentries) { 194 if(dircursor+1 < numentries) {
154 lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, " ", 0); 195 lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, " ", 0);
155 dircursor++; 196 dircursor++;
156 lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0); 197 lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);