diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/tree.c | 119 |
1 files changed, 65 insertions, 54 deletions
diff --git a/apps/tree.c b/apps/tree.c index de630df4cc..5f54784515 100644 --- a/apps/tree.c +++ b/apps/tree.c | |||
@@ -106,6 +106,7 @@ extern unsigned char bitmap_icons_6x8[LastIcon][6]; | |||
106 | #endif /* HAVE_RECORDER_KEYPAD */ | 106 | #endif /* HAVE_RECORDER_KEYPAD */ |
107 | 107 | ||
108 | #define TREE_ATTR_M3U 0x80 /* unused by FAT attributes */ | 108 | #define TREE_ATTR_M3U 0x80 /* unused by FAT attributes */ |
109 | #define TREE_ATTR_MP3 0x40 /* unused by FAT attributes */ | ||
109 | 110 | ||
110 | static int compare(const void* e1, const void* e2) | 111 | static int compare(const void* e1, const void* e2) |
111 | { | 112 | { |
@@ -125,51 +126,45 @@ static int showdir(char *path, int start) | |||
125 | DIR *dir = opendir(path); | 126 | DIR *dir = opendir(path); |
126 | if(!dir) | 127 | if(!dir) |
127 | return -1; /* not a directory */ | 128 | return -1; /* not a directory */ |
129 | |||
128 | memset(dircacheptr,0,sizeof(dircacheptr)); | 130 | memset(dircacheptr,0,sizeof(dircacheptr)); |
129 | for ( i=0; i<MAX_FILES_IN_DIR; i++ ) { | 131 | for ( i=0; i<MAX_FILES_IN_DIR; i++ ) { |
130 | int len; | 132 | int len; |
131 | struct dirent *entry = readdir(dir); | 133 | struct dirent *entry = readdir(dir); |
134 | struct entry* dptr = &dircache[i]; | ||
132 | if (!entry) | 135 | if (!entry) |
133 | break; | 136 | break; |
134 | 137 | ||
135 | /* skip directories . and .. */ | 138 | /* skip directories . and .. */ |
136 | if (!strncmp(entry->d_name, ".", 1) || | 139 | if ((entry->attribute & ATTR_DIRECTORY) && |
137 | !strncmp(entry->d_name, "..", 2)) { | 140 | (!strncmp(entry->d_name, ".", 1) || |
141 | !strncmp(entry->d_name, "..", 2))) { | ||
138 | i--; | 142 | i--; |
139 | continue; | 143 | continue; |
140 | } | 144 | } |
141 | dircache[i].attr = entry->attribute; | 145 | dptr->attr = entry->attribute; |
142 | |||
143 | len = strlen(entry->d_name); | 146 | len = strlen(entry->d_name); |
144 | if ( global_settings.mp3filter ) { | ||
145 | 147 | ||
146 | /* filter hidden files and directories */ | 148 | /* mark mp3 and m3u files as such */ |
147 | if ( dircache[i].attr & ATTR_HIDDEN ) { | 149 | if ( !(dptr->attr & ATTR_DIRECTORY) && (len > 4) ) { |
148 | i--; | 150 | if (!strcasecmp(&entry->d_name[len-4], ".mp3")) |
149 | continue; | 151 | dptr->attr |= TREE_ATTR_MP3; |
150 | } | 152 | else |
153 | if (!strcasecmp(&entry->d_name[len-4], ".m3u")) | ||
154 | dptr->attr |= TREE_ATTR_M3U; | ||
155 | } | ||
151 | 156 | ||
152 | if ( !(dircache[i].attr & ATTR_DIRECTORY) ) { | 157 | /* filter hidden files and directories and non-mp3 or m3u files */ |
153 | /* if not an mp3 or m3u, skip this file */ | 158 | if ( global_settings.mp3filter && |
154 | if ( (len > 4) && | 159 | ((dptr->attr & ATTR_HIDDEN) || |
155 | (strcasecmp(&entry->d_name[len-4], ".m3u") && | 160 | !(dptr->attr & (ATTR_DIRECTORY|TREE_ATTR_MP3|TREE_ATTR_M3U))) ) { |
156 | strcasecmp(&entry->d_name[len-4], ".mp3"))) { | 161 | i--; |
157 | i--; | 162 | continue; |
158 | continue; | ||
159 | } | ||
160 | else if ( len > 4 ) { | ||
161 | /* mark m3u files as playlists */ | ||
162 | if ( !strcasecmp(&entry->d_name[len-4], ".m3u") ) | ||
163 | dircache[i].attr |= TREE_ATTR_M3U; | ||
164 | /* cut off .mp3 and .m3u extensions */ | ||
165 | entry->d_name[len-4] = 0; | ||
166 | } | ||
167 | } | ||
168 | } | 163 | } |
169 | 164 | ||
170 | strncpy(dircache[i].name,entry->d_name,TREE_MAX_FILENAMELEN); | 165 | strncpy(dptr->name,entry->d_name,TREE_MAX_FILENAMELEN); |
171 | dircache[i].name[TREE_MAX_FILENAMELEN-1]=0; | 166 | dptr->name[TREE_MAX_FILENAMELEN-1]=0; |
172 | dircacheptr[i] = &dircache[i]; | 167 | dircacheptr[i] = dptr; |
173 | } | 168 | } |
174 | filesindir = i; | 169 | filesindir = i; |
175 | closedir(dir); | 170 | closedir(dir); |
@@ -197,19 +192,29 @@ static int showdir(char *path, int start) | |||
197 | len = strlen(dircacheptr[i]->name); | 192 | len = strlen(dircacheptr[i]->name); |
198 | 193 | ||
199 | #ifdef HAVE_LCD_BITMAP | 194 | #ifdef HAVE_LCD_BITMAP |
200 | if ( !(dircacheptr[i]->attr & ATTR_DIRECTORY) ) { | 195 | if ( dircacheptr[i]->attr & ATTR_DIRECTORY ) |
201 | if ( (dircacheptr[i]->attr & TREE_ATTR_M3U) || | 196 | icon_type = Folder; |
202 | !strcasecmp(&dircacheptr[i]->name[len-4], ".m3u")) | 197 | else { |
198 | if ( dircacheptr[i]->attr & TREE_ATTR_M3U ) | ||
203 | icon_type = Playlist; | 199 | icon_type = Playlist; |
204 | else | 200 | else |
205 | icon_type = File; | 201 | icon_type = File; |
206 | } else | 202 | } |
207 | icon_type=Folder; | ||
208 | lcd_bitmap(bitmap_icons_6x8[icon_type], | 203 | lcd_bitmap(bitmap_icons_6x8[icon_type], |
209 | 6, MARGIN_Y+(i-start)*LINE_HEIGTH, 6, 8, true); | 204 | 6, MARGIN_Y+(i-start)*LINE_HEIGTH, 6, 8, true); |
210 | #endif | 205 | #endif |
211 | 206 | ||
212 | lcd_puts(LINE_X, LINE_Y+i-start, dircacheptr[i]->name); | 207 | /* if MP3 filter is on, cut off the extension */ |
208 | if (global_settings.mp3filter && | ||
209 | (dircacheptr[i]->attr & (TREE_ATTR_M3U|TREE_ATTR_MP3))) | ||
210 | { | ||
211 | char temp = dircacheptr[i]->name[len-4]; | ||
212 | dircacheptr[i]->name[len-4] = 0; | ||
213 | lcd_puts(LINE_X, LINE_Y+i-start, dircacheptr[i]->name); | ||
214 | dircacheptr[i]->name[len-4] = temp; | ||
215 | } | ||
216 | else | ||
217 | lcd_puts(LINE_X, LINE_Y+i-start, dircacheptr[i]->name); | ||
213 | } | 218 | } |
214 | 219 | ||
215 | return filesindir; | 220 | return filesindir; |
@@ -240,8 +245,7 @@ char* peek_next_track(int steps) | |||
240 | dircursor++; | 245 | dircursor++; |
241 | else | 246 | else |
242 | start++; | 247 | start++; |
243 | if ( !(dircacheptr[dircursor+start]->attr & ATTR_DIRECTORY) && | 248 | if ( dircacheptr[dircursor+start]->attr & TREE_ATTR_MP3 ) { |
244 | dircacheptr[dircursor+start]->name[strlen(dircacheptr[dircursor+start]->name)-1] == '3') { | ||
245 | snprintf(buf,sizeof buf,"%s/%s", | 249 | snprintf(buf,sizeof buf,"%s/%s", |
246 | currdir, dircacheptr[dircursor+start]->name ); | 250 | currdir, dircacheptr[dircursor+start]->name ); |
247 | return buf; | 251 | return buf; |
@@ -254,8 +258,7 @@ char* peek_next_track(int steps) | |||
254 | dircursor--; | 258 | dircursor--; |
255 | else | 259 | else |
256 | start--; | 260 | start--; |
257 | if ( !(dircacheptr[dircursor+start]->attr & ATTR_DIRECTORY) && | 261 | if ( dircacheptr[dircursor+start]->attr & TREE_ATTR_MP3 ) { |
258 | dircacheptr[dircursor+start]->name[strlen(dircacheptr[dircursor+start]->name)-1] == '3') { | ||
259 | snprintf(buf, sizeof(buf), "%s/%s", | 262 | snprintf(buf, sizeof(buf), "%s/%s", |
260 | currdir, dircacheptr[dircursor+start]->name); | 263 | currdir, dircacheptr[dircursor+start]->name); |
261 | return buf; | 264 | return buf; |
@@ -276,7 +279,6 @@ bool dirbrowse(char *root) | |||
276 | { | 279 | { |
277 | char buf[MAX_PATH]; | 280 | char buf[MAX_PATH]; |
278 | int i; | 281 | int i; |
279 | int button; | ||
280 | int rc; | 282 | int rc; |
281 | 283 | ||
282 | memcpy(currdir,root,sizeof(currdir)); | 284 | memcpy(currdir,root,sizeof(currdir)); |
@@ -285,16 +287,32 @@ bool dirbrowse(char *root) | |||
285 | return -1; /* root is not a directory */ | 287 | return -1; /* root is not a directory */ |
286 | 288 | ||
287 | put_cursorxy(0, CURSOR_Y + dircursor, true); | 289 | put_cursorxy(0, CURSOR_Y + dircursor, true); |
288 | if ( numentries ) | ||
289 | lcd_puts_scroll(LINE_X, LINE_Y+dircursor, | ||
290 | dircacheptr[start+dircursor]->name); | ||
291 | lcd_update(); | ||
292 | 290 | ||
293 | while(1) { | 291 | while(1) { |
294 | bool restore = false; | 292 | bool restore = false; |
295 | button = button_get(true); | ||
296 | 293 | ||
297 | switch(button) { | 294 | if ( numentries ) { |
295 | i = start+dircursor; | ||
296 | |||
297 | /* if MP3 filter is on, cut off the extension */ | ||
298 | if (global_settings.mp3filter && | ||
299 | (dircacheptr[i]->attr & | ||
300 | (TREE_ATTR_M3U|TREE_ATTR_MP3))) | ||
301 | { | ||
302 | int len = strlen(dircacheptr[i]->name); | ||
303 | char temp = dircacheptr[i]->name[len-4]; | ||
304 | dircacheptr[i]->name[len-4] = 0; | ||
305 | lcd_puts_scroll(LINE_X, LINE_Y+dircursor, | ||
306 | dircacheptr[i]->name); | ||
307 | dircacheptr[i]->name[len-4] = temp; | ||
308 | } | ||
309 | else | ||
310 | lcd_puts_scroll(LINE_X, LINE_Y+dircursor, | ||
311 | dircacheptr[i]->name); | ||
312 | } | ||
313 | lcd_update(); | ||
314 | |||
315 | switch ( button_get(true) ) { | ||
298 | case TREE_EXIT: | 316 | case TREE_EXIT: |
299 | if ( play_mode == 1 ) | 317 | if ( play_mode == 1 ) |
300 | play_mode = 0; | 318 | play_mode = 0; |
@@ -349,11 +367,8 @@ bool dirbrowse(char *root) | |||
349 | dircursor=0; | 367 | dircursor=0; |
350 | start=0; | 368 | start=0; |
351 | } else { | 369 | } else { |
352 | int len=strlen(dircacheptr[dircursor+start]->name); | ||
353 | lcd_stop_scroll(); | 370 | lcd_stop_scroll(); |
354 | if((len > 4) && | 371 | if(dircacheptr[dircursor+start]->attr & TREE_ATTR_M3U ) |
355 | !strcasecmp(&dircacheptr[dircursor+start]->name[len-4], | ||
356 | ".m3u")) | ||
357 | { | 372 | { |
358 | play_mode = 2; | 373 | play_mode = 2; |
359 | play_list(currdir, dircacheptr[dircursor+start]->name); | 374 | play_list(currdir, dircacheptr[dircursor+start]->name); |
@@ -491,10 +506,6 @@ bool dirbrowse(char *root) | |||
491 | } | 506 | } |
492 | 507 | ||
493 | lcd_stop_scroll(); | 508 | lcd_stop_scroll(); |
494 | if ( numentries ) | ||
495 | lcd_puts_scroll(LINE_X, LINE_Y+dircursor, | ||
496 | dircacheptr[start+dircursor]->name); | ||
497 | lcd_update(); | ||
498 | } | 509 | } |
499 | 510 | ||
500 | return false; | 511 | return false; |