summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJörg Hohensohn <hohensoh@rockbox.org>2003-12-07 16:57:43 +0000
committerJörg Hohensohn <hohensoh@rockbox.org>2003-12-07 16:57:43 +0000
commit8b813d0b99bcda14d6101ea38cc8ebb498281675 (patch)
tree7a5b616628fa8fdcb945923d0697669c80cee758
parent7b7fc1e95f9ac3336dcc7212dab06b06dd3e1e07 (diff)
table-driven internal handling of file types, so we can have many of them
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4115 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/onplay.c12
-rw-r--r--apps/playlist.c2
-rw-r--r--apps/tree.c168
-rw-r--r--apps/tree.h24
4 files changed, 97 insertions, 109 deletions
diff --git a/apps/onplay.c b/apps/onplay.c
index 67793dffea..7598aa3125 100644
--- a/apps/onplay.c
+++ b/apps/onplay.c
@@ -59,7 +59,7 @@ static bool add_to_playlist(int position, bool queue)
if (new_playlist)
playlist_create(NULL, NULL);
- if (selected_file_attr & TREE_ATTR_MPA)
+ if ((selected_file_attr & TREE_ATTR_MASK) == TREE_ATTR_MPA)
playlist_insert_track(selected_file, position, queue);
else if (selected_file_attr & ATTR_DIRECTORY)
{
@@ -101,7 +101,7 @@ static bool add_to_playlist(int position, bool queue)
playlist_insert_directory(selected_file, position, queue, recurse);
}
- else if (selected_file_attr & TREE_ATTR_M3U)
+ else if ((selected_file_attr & TREE_ATTR_MASK) == TREE_ATTR_M3U)
playlist_insert_playlist(selected_file, position, queue);
if (new_playlist && (playlist_amount() > 0))
@@ -158,7 +158,7 @@ static bool playlist_options(void)
args[i].queue = true;
i++;
}
- else if ((selected_file_attr & TREE_ATTR_MPA) ||
+ else if (((selected_file_attr & TREE_ATTR_MASK) == TREE_ATTR_MPA) ||
(selected_file_attr & ATTR_DIRECTORY))
{
menu[i].desc = str(LANG_INSERT);
@@ -489,8 +489,8 @@ int onplay(char* file, int attr)
selected_file = file;
selected_file_attr = attr;
- if ((attr & TREE_ATTR_MPA) || (attr & ATTR_DIRECTORY) ||
- ((attr & TREE_ATTR_M3U) && (mpeg_status() & MPEG_STATUS_PLAY)))
+ if (((attr & TREE_ATTR_MASK) == TREE_ATTR_MPA) || (attr & ATTR_DIRECTORY) ||
+ (((attr & TREE_ATTR_MASK) == TREE_ATTR_M3U) && (mpeg_status() & MPEG_STATUS_PLAY)))
{
menu[i].desc = str(LANG_PLAYINDICES_PLAYLIST);
menu[i].function = playlist_options;
@@ -508,7 +508,7 @@ int onplay(char* file, int attr)
i++;
}
- if (attr & TREE_ATTR_MPA)
+ if ((attr & TREE_ATTR_MASK) == TREE_ATTR_MPA)
{
menu[i].desc = str(LANG_VBRFIX);
menu[i].function = vbr_fix;
diff --git a/apps/playlist.c b/apps/playlist.c
index 0843e937c4..ff6ef0ed37 100644
--- a/apps/playlist.c
+++ b/apps/playlist.c
@@ -468,7 +468,7 @@ static int add_directory_to_playlist(char *dirname, int *position, bool queue,
else
continue;
}
- else if (files[i].attr & TREE_ATTR_MPA)
+ else if ((files[i].attr & TREE_ATTR_MASK) == TREE_ATTR_MPA)
{
int insert_pos;
diff --git a/apps/tree.c b/apps/tree.c
index a71db78968..25f4434ef5 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -61,6 +61,38 @@
#define BOOTFILE "archos.mod"
#endif
+/* a table for the know file types */
+static struct
+{
+ char* extension; /* extension for which the file type is recognized */
+ int tree_attr; /* which identifier */
+ int icon; /* the icon which shall be used for it, -1 if unknown */
+ /* To have it extendable, there could be more useful stuff in here,
+ like handler functions, plugin name, etc. */
+} filetypes[] = {
+ { ".mp3", TREE_ATTR_MPA, File },
+ { ".mp2", TREE_ATTR_MPA, File },
+ { ".mpa", TREE_ATTR_MPA, File },
+ { ".m3u", TREE_ATTR_M3U, Playlist },
+ { ".cfg", TREE_ATTR_CFG, Config },
+ { ".wps", TREE_ATTR_WPS, Wps, },
+ { ".txt", TREE_ATTR_TXT, Text },
+ { ".lng", TREE_ATTR_LNG, Language },
+ { ".rock",TREE_ATTR_ROCK,Plugin },
+#ifdef HAVE_LCD_BITMAP
+ { ".fnt", TREE_ATTR_FONT,Font },
+ { ".ch8", TREE_ATTR_CH8, -1 },
+#endif
+#ifndef SIMULATOR
+#ifdef ARCHOS_RECORDER
+ { ".ucl", TREE_ATTR_UCL, Flashfile},
+ { ".ajz", TREE_ATTR_MOD, Mod_Ajz },
+#else
+ { ".mod", TREE_ATTR_MOD, Mod_Ajz },
+#endif
+#endif /* #ifndef SIMULATOR */
+};
+
/* Boot value of global_settings.max_files_in_dir */
static int max_files_in_dir;
@@ -284,38 +316,20 @@ struct entry* load_and_sort_directory(char *dirname, int *dirfilter,
dptr->attr = entry->attribute;
- /* mark mp? and m3u files as such */
- if ( !(dptr->attr & ATTR_DIRECTORY) && (len > 4) ) {
- if (!strcasecmp(&entry->d_name[len-4], ".mp3") ||
- (!strcasecmp(&entry->d_name[len-4], ".mp2")) ||
- (!strcasecmp(&entry->d_name[len-4], ".mpa")))
- dptr->attr |= TREE_ATTR_MPA;
- else if (!strcasecmp(&entry->d_name[len-4], ".m3u"))
- dptr->attr |= TREE_ATTR_M3U;
- else if (!strcasecmp(&entry->d_name[len-4], ".cfg"))
- dptr->attr |= TREE_ATTR_CFG;
- else if (!strcasecmp(&entry->d_name[len-4], ".wps"))
- dptr->attr |= TREE_ATTR_WPS;
- else if (!strcasecmp(&entry->d_name[len-4], ".txt"))
- dptr->attr |= TREE_ATTR_TXT;
- else if (!strcasecmp(&entry->d_name[len-4], ".lng"))
- dptr->attr |= TREE_ATTR_LNG;
-#ifdef HAVE_RECORDER_KEYPAD
- else if (!strcasecmp(&entry->d_name[len-4], ".fnt"))
- dptr->attr |= TREE_ATTR_FONT;
- else if (!strcasecmp(&entry->d_name[len-4], ".ajz"))
-#else
- else if (!strcasecmp(&entry->d_name[len-4], ".mod"))
-#endif
- dptr->attr |= TREE_ATTR_MOD;
- else if (!strcasecmp(&entry->d_name[len-5], ".rock"))
- dptr->attr |= TREE_ATTR_ROCK;
- else if (!strcasecmp(&entry->d_name[len-4], ".ucl"))
- dptr->attr |= TREE_ATTR_UCL;
-#ifdef HAVE_LCD_BITMAP
- else if (!strcasecmp(&entry->d_name[len-4], ".ch8"))
- dptr->attr |= TREE_ATTR_CH8;
-#endif
+ /* check for known file types */
+ if ( !(dptr->attr & ATTR_DIRECTORY) && (len > 4) )
+ {
+ unsigned j;
+ for (j=0; j<sizeof(filetypes)/sizeof(*filetypes); j++)
+ {
+ if (!strcasecmp(
+ &entry->d_name[len-strlen(filetypes[j].extension)],
+ filetypes[j].extension))
+ {
+ dptr->attr |= filetypes[j].tree_attr;
+ break;
+ }
+ }
}
/* memorize/compare details about the boot file */
@@ -330,17 +344,19 @@ struct entry* load_and_sort_directory(char *dirname, int *dirfilter,
}
/* filter out non-visible files */
- if ((*dirfilter == SHOW_PLAYLIST &&
- !(dptr->attr & (ATTR_DIRECTORY|TREE_ATTR_M3U))) ||
- (*dirfilter == SHOW_MUSIC &&
- !(dptr->attr & (ATTR_DIRECTORY|TREE_ATTR_MPA|TREE_ATTR_M3U))) ||
+ if (!(dptr->attr & ATTR_DIRECTORY) && (
+ (*dirfilter == SHOW_PLAYLIST &&
+ (dptr->attr & TREE_ATTR_MASK) != TREE_ATTR_M3U) ||
+ ((*dirfilter == SHOW_MUSIC &&
+ (dptr->attr & TREE_ATTR_MASK) != TREE_ATTR_MPA) &&
+ (dptr->attr & TREE_ATTR_MASK) != TREE_ATTR_M3U) ||
(*dirfilter == SHOW_SUPPORTED && !(dptr->attr & TREE_ATTR_MASK)) ||
- (*dirfilter == SHOW_WPS && !(dptr->attr & TREE_ATTR_WPS)) ||
- (*dirfilter == SHOW_CFG && !(dptr->attr & TREE_ATTR_CFG)) ||
- (*dirfilter == SHOW_LNG && !(dptr->attr & TREE_ATTR_LNG)) ||
- (*dirfilter == SHOW_MOD && !(dptr->attr & TREE_ATTR_MOD)) ||
- (*dirfilter == SHOW_FONT && !(dptr->attr & TREE_ATTR_FONT)) ||
- (*dirfilter == SHOW_PLUGINS && !(dptr->attr & TREE_ATTR_ROCK)))
+ (*dirfilter == SHOW_WPS && (dptr->attr & TREE_ATTR_MASK) != TREE_ATTR_WPS) ||
+ (*dirfilter == SHOW_CFG && (dptr->attr & TREE_ATTR_MASK) != TREE_ATTR_CFG) ||
+ (*dirfilter == SHOW_LNG && (dptr->attr & TREE_ATTR_MASK) != TREE_ATTR_LNG) ||
+ (*dirfilter == SHOW_MOD && (dptr->attr & TREE_ATTR_MASK) != TREE_ATTR_MOD) ||
+ (*dirfilter == SHOW_FONT && (dptr->attr & TREE_ATTR_MASK) != TREE_ATTR_FONT) ||
+ (*dirfilter == SHOW_PLUGINS && (dptr->attr & TREE_ATTR_MASK) != TREE_ATTR_ROCK)))
{
i--;
continue;
@@ -459,66 +475,38 @@ static int showdir(char *path, int start, int *dirfilter)
for ( i=start; i < start+tree_max_on_screen; i++ ) {
int len;
+ unsigned j;
if ( i >= filesindir )
break;
len = strlen(dircache[i].name);
- switch ( dircache[i].attr & TREE_ATTR_MASK ) {
- case ATTR_DIRECTORY:
- icon_type = Folder;
- break;
-
- case TREE_ATTR_M3U:
- icon_type = Playlist;
- break;
-
- case TREE_ATTR_MPA:
- icon_type = File;
- break;
-
- case TREE_ATTR_WPS:
- icon_type = Wps;
- break;
-
- case TREE_ATTR_CFG:
- icon_type = Config;
- break;
-
- case TREE_ATTR_TXT:
- icon_type = Text;
- break;
-
- case TREE_ATTR_LNG:
- icon_type = Language;
- break;
-
- case TREE_ATTR_MOD:
- icon_type = Mod_Ajz;
- break;
-
-#ifdef HAVE_LCD_BITMAP
- case TREE_ATTR_UCL:
- icon_type = Flashfile;
- break;
-#endif
-
- case TREE_ATTR_ROCK:
- icon_type = Plugin;
- break;
+ if (dircache[i].attr & ATTR_DIRECTORY)
+ {
+ icon_type = Folder;
+ }
+ else
+ {
+ /* search which icon to use */
+ icon_type = -1; /* default to none */
+ for (j=0; j<sizeof(filetypes)/sizeof(*filetypes); j++)
+ {
+ if ((dircache[i].attr & TREE_ATTR_MASK) == filetypes[j].tree_attr)
+ {
+ icon_type = filetypes[j].icon;
+ break;
+ }
+ }
-#ifdef HAVE_LCD_BITMAP
- case TREE_ATTR_FONT:
- icon_type = Font;
- break;
-#endif
- default:
+ if (icon_type == -1)
+ {
#ifdef HAVE_LCD_BITMAP
icon_type = 0;
#else
icon_type = Unknown;
#endif
+ }
}
if (icon_type && global_settings.show_icons) {
diff --git a/apps/tree.h b/apps/tree.h
index 3086c8914b..fdc9641917 100644
--- a/apps/tree.h
+++ b/apps/tree.h
@@ -27,18 +27,18 @@ struct entry {
};
/* using attribute not used by FAT */
-#define TREE_ATTR_MPA 0x40 /* mpeg audio file */
-#define TREE_ATTR_M3U 0x80 /* playlist */
-#define TREE_ATTR_WPS 0x100 /* wps config file */
-#define TREE_ATTR_MOD 0x200 /* firmware file */
-#define TREE_ATTR_CFG 0x400 /* config file */
-#define TREE_ATTR_TXT 0x500 /* text file */
-#define TREE_ATTR_FONT 0x800 /* font file */
-#define TREE_ATTR_LNG 0x1000 /* binary lang file */
-#define TREE_ATTR_ROCK 0x2000 /* binary rockbox plugin */
-#define TREE_ATTR_UCL 0x4000 /* rockbox flash image */
-#define TREE_ATTR_CH8 0x8000 /* chip-8 game */
-#define TREE_ATTR_MASK 0xffd0 /* which bits tree.c uses (above + DIR) */
+#define TREE_ATTR_MPA 0x0100 /* mpeg audio file */
+#define TREE_ATTR_M3U 0x0200 /* playlist */
+#define TREE_ATTR_WPS 0x0300 /* wps config file */
+#define TREE_ATTR_MOD 0x0400 /* firmware file */
+#define TREE_ATTR_CFG 0x0500 /* config file */
+#define TREE_ATTR_TXT 0x0600 /* text file */
+#define TREE_ATTR_FONT 0x0700 /* font file */
+#define TREE_ATTR_LNG 0x0800 /* binary lang file */
+#define TREE_ATTR_ROCK 0x0900 /* binary rockbox plugin */
+#define TREE_ATTR_UCL 0x0A00 /* rockbox flash image */
+#define TREE_ATTR_CH8 0x0B00 /* chip-8 game */
+#define TREE_ATTR_MASK 0xFFC0 /* which bits tree.c uses (above) */
void tree_init(void);
void browse_root(void);