summaryrefslogtreecommitdiff
path: root/apps/tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/tree.c')
-rw-r--r--apps/tree.c133
1 files changed, 41 insertions, 92 deletions
diff --git a/apps/tree.c b/apps/tree.c
index 140b226a01..8aa7eb0815 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -56,6 +56,7 @@
56#include "power.h" 56#include "power.h"
57#include "action.h" 57#include "action.h"
58#include "talk.h" 58#include "talk.h"
59#include "filetypes.h"
59 60
60#ifdef HAVE_LCD_BITMAP 61#ifdef HAVE_LCD_BITMAP
61#include "widgets.h" 62#include "widgets.h"
@@ -69,37 +70,24 @@
69extern bool language_changed; 70extern bool language_changed;
70 71
71/* a table for the know file types */ 72/* a table for the know file types */
72static struct 73struct filetype filetypes[] = {
73{
74 char* extension; /* extension for which the file type is recognized */
75 int tree_attr; /* which identifier */
76 int icon; /* the icon which shall be used for it, -1 if unknown */
77 int voiceclip; /* spoken extension */
78 /* To have it extendable, there could be more useful stuff in here,
79 like handler functions, plugin name, etc. */
80} filetypes[] = {
81 { ".mp3", TREE_ATTR_MPA, File, VOICE_EXT_MPA }, 74 { ".mp3", TREE_ATTR_MPA, File, VOICE_EXT_MPA },
82 { ".mp2", TREE_ATTR_MPA, File, VOICE_EXT_MPA }, 75 { ".mp2", TREE_ATTR_MPA, File, VOICE_EXT_MPA },
83 { ".mpa", TREE_ATTR_MPA, File, VOICE_EXT_MPA }, 76 { ".mpa", TREE_ATTR_MPA, File, VOICE_EXT_MPA },
84 { ".m3u", TREE_ATTR_M3U, Playlist, LANG_PLAYINDICES_PLAYLIST }, 77 { ".m3u", TREE_ATTR_M3U, Playlist, LANG_PLAYINDICES_PLAYLIST },
85 { ".cfg", TREE_ATTR_CFG, Config, VOICE_EXT_CFG }, 78 { ".cfg", TREE_ATTR_CFG, Config, VOICE_EXT_CFG },
86 { ".wps", TREE_ATTR_WPS, Wps, VOICE_EXT_WPS }, 79 { ".wps", TREE_ATTR_WPS, Wps, VOICE_EXT_WPS },
87 { ".txt", TREE_ATTR_TXT, Text, VOICE_EXT_TXT },
88 { ".lng", TREE_ATTR_LNG, Language, LANG_LANGUAGE }, 80 { ".lng", TREE_ATTR_LNG, Language, LANG_LANGUAGE },
89 { ".rock",TREE_ATTR_ROCK,Plugin, VOICE_EXT_ROCK }, 81 { ".rock",TREE_ATTR_ROCK,Plugin, VOICE_EXT_ROCK },
90#ifdef HAVE_LCD_BITMAP 82#ifdef HAVE_LCD_BITMAP
91 { ".fnt", TREE_ATTR_FONT,Font, VOICE_EXT_FONT }, 83 { ".fnt", TREE_ATTR_FONT,Font, VOICE_EXT_FONT },
92 { ".ch8", TREE_ATTR_CH8, Chip8, -1 },
93 { ".rvf", TREE_ATTR_RVF, Video, -1 },
94 { ".bmark",TREE_ATTR_BMARK, Bookmark, VOICE_EXT_BMARK }, 84 { ".bmark",TREE_ATTR_BMARK, Bookmark, VOICE_EXT_BMARK },
95#else 85#else
96 { ".bmark", TREE_ATTR_BMARK, -1, VOICE_EXT_BMARK }, 86 { ".bmark", TREE_ATTR_BMARK, -1, VOICE_EXT_BMARK },
97#endif 87#endif
98#ifndef SIMULATOR 88#ifndef SIMULATOR
99#ifdef HAVE_LCD_BITMAP 89#ifdef HAVE_LCD_BITMAP
100 { ".ucl", TREE_ATTR_UCL, Flashfile, VOICE_EXT_UCL },
101 { ".ajz", TREE_ATTR_MOD, Mod_Ajz, VOICE_EXT_AJZ }, 90 { ".ajz", TREE_ATTR_MOD, Mod_Ajz, VOICE_EXT_AJZ },
102 { ".jpg", TREE_ATTR_JPEG, Jpeg, -1 },
103#else 91#else
104 { ".mod", TREE_ATTR_MOD, Mod_Ajz, VOICE_EXT_AJZ }, 92 { ".mod", TREE_ATTR_MOD, Mod_Ajz, VOICE_EXT_AJZ },
105#endif 93#endif
@@ -136,6 +124,7 @@ static bool dirbrowse(char *root, int *dirfilter);
136 124
137void browse_root(void) 125void browse_root(void)
138{ 126{
127 filetype_init();
139#ifndef SIMULATOR 128#ifndef SIMULATOR
140 dirbrowse("/", &global_settings.dirfilter); 129 dirbrowse("/", &global_settings.dirfilter);
141#else 130#else
@@ -145,6 +134,11 @@ void browse_root(void)
145#endif 134#endif
146} 135}
147 136
137void tree_get_filetypes(struct filetype** types, int* count)
138{
139 *types = filetypes;
140 *count = sizeof(filetypes) / sizeof(*filetypes);
141}
148 142
149#ifdef HAVE_LCD_BITMAP 143#ifdef HAVE_LCD_BITMAP
150 144
@@ -359,19 +353,7 @@ struct entry* load_and_sort_directory(char *dirname, int *dirfilter,
359 353
360 /* check for known file types */ 354 /* check for known file types */
361 if ( !(dptr->attr & ATTR_DIRECTORY) && (len > 4) ) 355 if ( !(dptr->attr & ATTR_DIRECTORY) && (len > 4) )
362 { 356 dptr->attr |= filetype_get_attr(entry->d_name);
363 unsigned j;
364 for (j=0; j<sizeof(filetypes)/sizeof(*filetypes); j++)
365 {
366 if (!strcasecmp(
367 &entry->d_name[len-strlen(filetypes[j].extension)],
368 filetypes[j].extension))
369 {
370 dptr->attr |= filetypes[j].tree_attr;
371 break;
372 }
373 }
374 }
375 357
376 /* memorize/compare details about the boot file */ 358 /* memorize/compare details about the boot file */
377 if ((currdir[1] == 0) && !strcasecmp(entry->d_name, BOOTFILE)) { 359 if ((currdir[1] == 0) && !strcasecmp(entry->d_name, BOOTFILE)) {
@@ -391,7 +373,7 @@ struct entry* load_and_sort_directory(char *dirname, int *dirfilter,
391 ((*dirfilter == SHOW_MUSIC && 373 ((*dirfilter == SHOW_MUSIC &&
392 (dptr->attr & TREE_ATTR_MASK) != TREE_ATTR_MPA) && 374 (dptr->attr & TREE_ATTR_MASK) != TREE_ATTR_MPA) &&
393 (dptr->attr & TREE_ATTR_MASK) != TREE_ATTR_M3U) || 375 (dptr->attr & TREE_ATTR_MASK) != TREE_ATTR_M3U) ||
394 (*dirfilter == SHOW_SUPPORTED && !(dptr->attr & TREE_ATTR_MASK)) || 376 (*dirfilter == SHOW_SUPPORTED && !filetype_supported(dptr->attr)) ||
395 (*dirfilter == SHOW_WPS && (dptr->attr & TREE_ATTR_MASK) != TREE_ATTR_WPS) || 377 (*dirfilter == SHOW_WPS && (dptr->attr & TREE_ATTR_MASK) != TREE_ATTR_WPS) ||
396 (*dirfilter == SHOW_CFG && (dptr->attr & TREE_ATTR_MASK) != TREE_ATTR_CFG) || 378 (*dirfilter == SHOW_CFG && (dptr->attr & TREE_ATTR_MASK) != TREE_ATTR_CFG) ||
397 (*dirfilter == SHOW_LNG && (dptr->attr & TREE_ATTR_MASK) != TREE_ATTR_LNG) || 379 (*dirfilter == SHOW_LNG && (dptr->attr & TREE_ATTR_MASK) != TREE_ATTR_LNG) ||
@@ -444,12 +426,12 @@ static int recalc_screen_height(void)
444 426
445static int showdir(char *path, int start, int *dirfilter) 427static int showdir(char *path, int start, int *dirfilter)
446{ 428{
447 int icon_type = 0;
448 int i; 429 int i;
449 int tree_max_on_screen; 430 int tree_max_on_screen;
450 bool dir_buffer_full; 431 bool dir_buffer_full;
451 432
452#ifdef HAVE_LCD_BITMAP 433#ifdef HAVE_LCD_BITMAP
434 char* icon;
453 int line_height; 435 int line_height;
454 int fw, fh; 436 int fw, fh;
455 lcd_setfont(FONT_UI); 437 lcd_setfont(FONT_UI);
@@ -457,6 +439,7 @@ static int showdir(char *path, int start, int *dirfilter)
457 tree_max_on_screen = recalc_screen_height(); 439 tree_max_on_screen = recalc_screen_height();
458 line_height = fh; 440 line_height = fh;
459#else 441#else
442 int icon;
460 tree_max_on_screen = TREE_MAX_ON_SCREEN; 443 tree_max_on_screen = TREE_MAX_ON_SCREEN;
461#endif 444#endif
462 445
@@ -536,52 +519,24 @@ static int showdir(char *path, int start, int *dirfilter)
536#endif 519#endif
537 520
538 for ( i=start; i < start+tree_max_on_screen; i++ ) { 521 for ( i=start; i < start+tree_max_on_screen; i++ ) {
539 int len;
540 unsigned j;
541
542 if ( i >= filesindir ) 522 if ( i >= filesindir )
543 break; 523 break;
544 524
545 len = strlen(dircache[i].name); 525 icon = filetype_get_icon(dircache[i].attr);
546
547 if (dircache[i].attr & ATTR_DIRECTORY)
548 {
549 icon_type = Folder;
550 }
551 else
552 {
553 /* search which icon to use */
554 icon_type = -1; /* default to none */
555 for (j=0; j<sizeof(filetypes)/sizeof(*filetypes); j++)
556 {
557 if ((dircache[i].attr & TREE_ATTR_MASK) == filetypes[j].tree_attr)
558 {
559 icon_type = filetypes[j].icon;
560 break;
561 }
562 }
563
564 if (icon_type == -1)
565 {
566#ifdef HAVE_LCD_BITMAP
567 icon_type = 0;
568#else
569 icon_type = Unknown;
570#endif
571 }
572 }
573 526
574 if (icon_type && global_settings.show_icons) { 527 if (icon && global_settings.show_icons) {
575#ifdef HAVE_LCD_BITMAP 528#ifdef HAVE_LCD_BITMAP
576 int offset=0; 529 int offset=0;
577 if ( line_height > 8 ) 530 if ( line_height > 8 )
578 offset = (line_height - 8) / 2; 531 offset = (line_height - 8) / 2;
579 lcd_bitmap(bitmap_icons_6x8[icon_type], 532 lcd_bitmap(icon,
580 CURSOR_X * 6 + CURSOR_WIDTH, 533 CURSOR_X * 6 + CURSOR_WIDTH,
581 MARGIN_Y+(i-start)*line_height + offset, 534 MARGIN_Y+(i-start)*line_height + offset,
582 6, 8, true); 535 6, 8, true);
583#else 536#else
584 lcd_putc(LINE_X-1, i-start, icon_type); 537 if (icon < 0 )
538 icon = Unknown;
539 lcd_putc(LINE_X-1, i-start, icon);
585#endif 540#endif
586 } 541 }
587 542
@@ -1005,6 +960,9 @@ static bool dirbrowse(char *root, int *dirfilter)
1005 else 960 else
1006 currdir[i-1]=0; 961 currdir[i-1]=0;
1007 962
963 if (*dirfilter > NUM_FILTER_MODES && dirlevel < 1)
964 exit_func = true;
965
1008 dirlevel--; 966 dirlevel--;
1009 if ( dirlevel < MAX_DIR_LEVELS ) { 967 if ( dirlevel < MAX_DIR_LEVELS ) {
1010 dirstart = dirpos[dirlevel]; 968 dirstart = dirpos[dirlevel];
@@ -1018,8 +976,11 @@ static bool dirbrowse(char *root, int *dirfilter)
1018 976
1019 restore = true; 977 restore = true;
1020 } 978 }
1021 if (*dirfilter > NUM_FILTER_MODES) 979 else
1022 exit_func = true; 980 {
981 if (*dirfilter > NUM_FILTER_MODES && dirlevel < 1)
982 exit_func = true;
983 }
1023 break; 984 break;
1024 985
1025#ifdef HAVE_RECORDER_KEYPAD 986#ifdef HAVE_RECORDER_KEYPAD
@@ -1171,11 +1132,6 @@ static bool dirbrowse(char *root, int *dirfilter)
1171 reload_dir = true; 1132 reload_dir = true;
1172 break; 1133 break;
1173 1134
1174 case TREE_ATTR_TXT:
1175 plugin_load("/.rockbox/rocks/viewer.rock",buf);
1176 restore = true;
1177 break;
1178
1179 case TREE_ATTR_LNG: 1135 case TREE_ATTR_LNG:
1180 if(!lang_load(buf)) { 1136 if(!lang_load(buf)) {
1181 set_file(buf, global_settings.lang_file, 1137 set_file(buf, global_settings.lang_file,
@@ -1189,21 +1145,6 @@ static bool dirbrowse(char *root, int *dirfilter)
1189 break; 1145 break;
1190 1146
1191#ifdef HAVE_LCD_BITMAP 1147#ifdef HAVE_LCD_BITMAP
1192 /* chip-8 game */
1193 case TREE_ATTR_CH8:
1194 plugin_load("/.rockbox/rocks/chip8.rock",buf);
1195 break;
1196
1197 /* "movie" animation */
1198 case TREE_ATTR_RVF:
1199 plugin_load("/.rockbox/rocks/video.rock",buf);
1200 break;
1201
1202 /* JPEG image */
1203 case TREE_ATTR_JPEG:
1204 plugin_load("/.rockbox/rocks/jpeg.rock",buf);
1205 break;
1206
1207 case TREE_ATTR_FONT: 1148 case TREE_ATTR_FONT:
1208 font_load(buf); 1149 font_load(buf);
1209 set_file(buf, global_settings.font_file, 1150 set_file(buf, global_settings.font_file,
@@ -1224,11 +1165,6 @@ static bool dirbrowse(char *root, int *dirfilter)
1224 case TREE_ATTR_MOD: 1165 case TREE_ATTR_MOD:
1225 rolo_load(buf); 1166 rolo_load(buf);
1226 break; 1167 break;
1227
1228 /* ucl flash file */
1229 case TREE_ATTR_UCL:
1230 plugin_load("/.rockbox/rocks/rockbox_flash.rock",buf);
1231 break;
1232#endif 1168#endif
1233 1169
1234 /* plugin file */ 1170 /* plugin file */
@@ -1238,6 +1174,19 @@ static bool dirbrowse(char *root, int *dirfilter)
1238 else 1174 else
1239 restore = true; 1175 restore = true;
1240 break; 1176 break;
1177
1178 default:
1179 {
1180 char* plugin = filetype_get_plugin(file);
1181 if (plugin)
1182 {
1183 if (plugin_load(plugin,buf) == PLUGIN_USB_CONNECTED)
1184 reload_root = true;
1185 else
1186 restore = true;
1187 }
1188 break;
1189 }
1241 } 1190 }
1242 1191
1243 if ( play ) { 1192 if ( play ) {
@@ -1389,8 +1338,8 @@ static bool dirbrowse(char *root, int *dirfilter)
1389#endif 1338#endif
1390 restore = true; 1339 restore = true;
1391 } 1340 }
1392 break;
1393#endif 1341#endif
1342 break;
1394 1343
1395 case SYS_USB_CONNECTED: 1344 case SYS_USB_CONNECTED:
1396 status_set_playmode(STATUS_STOP); 1345 status_set_playmode(STATUS_STOP);