summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorJonathan Gordon <rockbox@jdgordon.info>2007-08-12 02:10:45 +0000
committerJonathan Gordon <rockbox@jdgordon.info>2007-08-12 02:10:45 +0000
commiteff14cceec3c71a90c6a675b0bd7b297bd151e7a (patch)
treeed37fcf62fd857e313e7f4cbacb706127a0b3227 /apps
parentca42a2f0dd244b44468c79ac0a4b5c5d448218bf (diff)
downloadrockbox-eff14cceec3c71a90c6a675b0bd7b297bd151e7a.tar.gz
rockbox-eff14cceec3c71a90c6a675b0bd7b297bd151e7a.zip
Change the way the MAX_FILETYPES define works. It now allocates enough filetype icons as it needed last boot + 8, this means we should never have to edit the define again.
If you get the "filetypes array full" splash, do a clean reboot and it shuold go away. if it doesnt make sure you file a bug report and let us know you did reboot and it stayed there... it means that define does actually need increeasing. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14287 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/filetypes.c62
-rw-r--r--apps/settings.h8
-rw-r--r--apps/settings_list.c1
3 files changed, 46 insertions, 25 deletions
diff --git a/apps/filetypes.c b/apps/filetypes.c
index 785a317a7a..1e7224a4e2 100644
--- a/apps/filetypes.c
+++ b/apps/filetypes.c
@@ -41,20 +41,12 @@
41#include "icons.h" 41#include "icons.h"
42#include "logf.h" 42#include "logf.h"
43 43
44/* max filetypes (plugins & icons stored here) */
45#if CONFIG_CODEC == SWCODEC
46#define MAX_FILETYPES 80
47#else
48#define MAX_FILETYPES 48
49#endif
50
51/* a table for the know file types */ 44/* a table for the know file types */
52const struct filetype inbuilt_filetypes[] = { 45const struct filetype inbuilt_filetypes[] = {
53 { "mp3", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, 46 { "mp3", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
54 { "mp2", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, 47 { "mp2", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
55 { "mpa", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, 48 { "mpa", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
56#if CONFIG_CODEC == SWCODEC 49#if CONFIG_CODEC == SWCODEC
57 /* Temporary hack to allow playlist creation */
58 { "mp1", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, 50 { "mp1", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
59 { "ogg", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, 51 { "ogg", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
60 { "wma", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, 52 { "wma", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
@@ -104,7 +96,7 @@ const struct filetype inbuilt_filetypes[] = {
104 { "cue", FILE_ATTR_CUE, Icon_Bookmark, VOICE_EXT_CUESHEET }, 96 { "cue", FILE_ATTR_CUE, Icon_Bookmark, VOICE_EXT_CUESHEET },
105#ifdef BOOTFILE_EXT 97#ifdef BOOTFILE_EXT
106 { BOOTFILE_EXT, FILE_ATTR_MOD, Icon_Firmware, VOICE_EXT_AJZ }, 98 { BOOTFILE_EXT, FILE_ATTR_MOD, Icon_Firmware, VOICE_EXT_AJZ },
107#endif /* #ifndef SIMULATOR */ 99#endif /* #ifndef BOOTFILE_EXT */
108}; 100};
109 101
110void tree_get_filetypes(const struct filetype** types, int* count) 102void tree_get_filetypes(const struct filetype** types, int* count)
@@ -123,14 +115,14 @@ struct file_type {
123 char* plugin; /* Which plugin to use, NULL if unknown, or builtin */ 115 char* plugin; /* Which plugin to use, NULL if unknown, or builtin */
124 char* extension; /* NULL for none */ 116 char* extension; /* NULL for none */
125}; 117};
126static struct file_type filetypes[MAX_FILETYPES]; 118static struct file_type *filetypes;
127static int custom_filetype_icons[MAX_FILETYPES]; 119static int *custom_filetype_icons;
128static bool custom_icons_loaded = false; 120static bool custom_icons_loaded = false;
129#ifdef HAVE_LCD_COLOR 121#ifdef HAVE_LCD_COLOR
130static int custom_colors[MAX_FILETYPES+1]; 122static int *custom_colors;
131#endif 123#endif
132static int filetype_count = 0;
133static unsigned char heighest_attr = 0; 124static unsigned char heighest_attr = 0;
125static int max_types = 0, filetype_count;
134 126
135static char *filetypes_strdup(char* string) 127static char *filetypes_strdup(char* string)
136{ 128{
@@ -150,7 +142,10 @@ void read_color_theme_file(void) {
150 int fd; 142 int fd;
151 char *ext, *color; 143 char *ext, *color;
152 int i; 144 int i;
153 for (i = 0; i < MAX_FILETYPES+1; i++) { 145
146 if (max_types == 0)
147 return;
148 for (i = 0; i < filetype_count+1; i++) {
154 custom_colors[i] = -1; 149 custom_colors[i] = -1;
155 } 150 }
156 snprintf(buffer, MAX_PATH, "%s/%s.colours", THEME_DIR, 151 snprintf(buffer, MAX_PATH, "%s/%s.colours", THEME_DIR,
@@ -169,7 +164,7 @@ void read_color_theme_file(void) {
169 } 164 }
170 if (!strcasecmp(ext, "???")) 165 if (!strcasecmp(ext, "???"))
171 { 166 {
172 custom_colors[MAX_FILETYPES] = hex_to_rgb(color); 167 custom_colors[filetype_count] = hex_to_rgb(color);
173 continue; 168 continue;
174 } 169 }
175 for (i=1; i<filetype_count; i++) 170 for (i=1; i<filetype_count; i++)
@@ -195,6 +190,8 @@ void read_viewer_theme_file(void)
195 global_status.viewer_icon_count = 0; 190 global_status.viewer_icon_count = 0;
196 custom_icons_loaded = false; 191 custom_icons_loaded = false;
197 custom_filetype_icons[0] = Icon_Folder; 192 custom_filetype_icons[0] = Icon_Folder;
193 if (max_types == 0)
194 return;
198 for (i=1; i<filetype_count; i++) 195 for (i=1; i<filetype_count; i++)
199 { 196 {
200 custom_filetype_icons[i] = filetypes[i].icon; 197 custom_filetype_icons[i] = filetypes[i].icon;
@@ -236,6 +233,16 @@ void read_viewer_theme_file(void)
236 233
237void filetype_init(void) 234void filetype_init(void)
238{ 235{
236 max_types = global_status.filetype_count + 8; /* always make a bit more room
237 for more types */
238 filetypes = (struct file_type *)buffer_alloc(sizeof(struct file_type)*
239 max_types);
240 custom_filetype_icons = (int*)buffer_alloc(sizeof(int)*max_types);
241#ifdef HAVE_LCD_COLOR
242 /* the extra item here is for the unknown types
243 which use the last array element */
244 custom_colors = (int*)buffer_alloc(sizeof(int)*max_types+1);
245#endif
239 /* set the directory item first */ 246 /* set the directory item first */
240 filetypes[0].extension = NULL; 247 filetypes[0].extension = NULL;
241 filetypes[0].plugin = NULL; 248 filetypes[0].plugin = NULL;
@@ -251,6 +258,10 @@ void filetype_init(void)
251#ifdef HAVE_LCD_COLOR 258#ifdef HAVE_LCD_COLOR
252 read_color_theme_file(); 259 read_color_theme_file();
253#endif 260#endif
261 if (global_status.filetype_count == 0)
262 global_status.filetype_count = MAX_FILETYPES;
263 else global_status.filetype_count = filetype_count;
264 status_save();
254} 265}
255 266
256/* remove all white spaces from string */ 267/* remove all white spaces from string */
@@ -272,14 +283,14 @@ static void rm_whitespaces(char* str)
272static void read_builtin_types(void) 283static void read_builtin_types(void)
273{ 284{
274 int count = sizeof(inbuilt_filetypes)/sizeof(*inbuilt_filetypes), i; 285 int count = sizeof(inbuilt_filetypes)/sizeof(*inbuilt_filetypes), i;
275 for(i=0; i<count && (filetype_count < MAX_FILETYPES); i++) 286 for(i=0; i<count && (filetype_count<max_types); i++)
276 { 287 {
277 filetypes[filetype_count].extension = inbuilt_filetypes[i].extension; 288 filetypes[filetype_count].extension = inbuilt_filetypes[i].extension;
278 filetypes[filetype_count].plugin = NULL; 289 filetypes[filetype_count].plugin = NULL;
279 filetypes[filetype_count].attr = inbuilt_filetypes[i].tree_attr>>8; 290 filetypes[filetype_count].attr = inbuilt_filetypes[i].tree_attr>>8;
280 if (filetypes[filetype_count].attr > heighest_attr) 291 if (filetypes[filetype_count].attr > heighest_attr)
281 heighest_attr = filetypes[filetype_count].attr; 292 heighest_attr = filetypes[filetype_count].attr;
282 filetypes[filetype_count].icon = inbuilt_filetypes[i].icon; 293 filetypes[filetype_count].icon = inbuilt_filetypes[i].icon;
283 filetype_count++; 294 filetype_count++;
284 } 295 }
285} 296}
@@ -291,14 +302,15 @@ static void read_config(char* config_file)
291 int fd = open(config_file, O_RDONLY); 302 int fd = open(config_file, O_RDONLY);
292 if (fd < 0) 303 if (fd < 0)
293 return; 304 return;
294 /* config file is in the for 305 /* config file is in the form
295 <extension>,<plugin>,<icon code> 306 <extension>,<plugin>,<icon code>
296 ignore line if either of the first two are missing */ 307 ignore line if either of the first two are missing */
297 while (read_line(fd, line, 64) > 0) 308 while (read_line(fd, line, 64) > 0)
298 { 309 {
299 if (filetype_count >= MAX_FILETYPES) 310 if (filetype_count >= max_types)
300 { 311 {
301 gui_syncsplash(HZ, ID2P(LANG_FILETYPES_FULL)); 312 gui_syncsplash(HZ, ID2P(LANG_FILETYPES_FULL));
313 global_status.filetype_count = 0; /* make plenty of room for next reboot */
302 break; 314 break;
303 } 315 }
304 rm_whitespaces(line); 316 rm_whitespaces(line);
@@ -347,7 +359,7 @@ int filetype_get_attr(const char* file)
347 if (!extension) 359 if (!extension)
348 return 0; 360 return 0;
349 extension++; 361 extension++;
350 for (i=0; i<filetype_count; i++) 362 for (i=0; i<max_types; i++)
351 { 363 {
352 if (filetypes[i].extension && 364 if (filetypes[i].extension &&
353 !strcasecmp(extension, filetypes[i].extension)) 365 !strcasecmp(extension, filetypes[i].extension))
@@ -379,7 +391,7 @@ int filetype_get_color(const char * name, int attr)
379 return custom_colors[0]; 391 return custom_colors[0];
380 extension = strrchr(name, '.'); 392 extension = strrchr(name, '.');
381 if (!extension) 393 if (!extension)
382 return custom_colors[MAX_FILETYPES]; 394 return custom_colors[filetype_count];
383 extension++; 395 extension++;
384 396
385 for (i=1; i<filetype_count; i++) 397 for (i=1; i<filetype_count; i++)
@@ -388,7 +400,7 @@ int filetype_get_color(const char * name, int attr)
388 !strcasecmp(extension, filetypes[i].extension)) 400 !strcasecmp(extension, filetypes[i].extension))
389 return custom_colors[i]; 401 return custom_colors[i];
390 } 402 }
391 return custom_colors[MAX_FILETYPES]; 403 return custom_colors[filetype_count];
392} 404}
393#endif 405#endif
394 406
@@ -439,9 +451,9 @@ char * openwith_get_name(int selected_item, void * data, char * buffer)
439int filetype_list_viewers(const char* current_file) 451int filetype_list_viewers(const char* current_file)
440{ 452{
441 int i, count = 0, action; 453 int i, count = 0, action;
442 int items[MAX_FILETYPES]; 454 int items[64];
443 struct gui_synclist lists; 455 struct gui_synclist lists;
444 for (i=0; i<filetype_count && count < MAX_FILETYPES; i++) 456 for (i=0; i<filetype_count && count < 64; i++)
445 { 457 {
446 if (filetypes[i].plugin) 458 if (filetypes[i].plugin)
447 { 459 {
diff --git a/apps/settings.h b/apps/settings.h
index 39dabc72ce..276a8b3f87 100644
--- a/apps/settings.h
+++ b/apps/settings.h
@@ -145,6 +145,13 @@ extern const char * const trig_durations[TRIG_DURATION_COUNT];
145#define HAVE_LCD_CONTRAST 145#define HAVE_LCD_CONTRAST
146#endif 146#endif
147 147
148#if CONFIG_CODEC == SWCODEC
149#define MAX_FILETYPES 128
150#else
151#define MAX_FILETYPES 48
152#endif
153
154
148/* repeat mode options */ 155/* repeat mode options */
149enum 156enum
150{ 157{
@@ -308,6 +315,7 @@ struct system_status
308 relative to MIN_FREQ */ 315 relative to MIN_FREQ */
309#endif 316#endif
310 char last_screen; 317 char last_screen;
318 int filetype_count;
311 int viewer_icon_count; 319 int viewer_icon_count;
312}; 320};
313 321
diff --git a/apps/settings_list.c b/apps/settings_list.c
index 62daeb8c4d..5311c3e6c4 100644
--- a/apps/settings_list.c
+++ b/apps/settings_list.c
@@ -1248,6 +1248,7 @@ const struct settings_list settings[] = {
1248 3, "list_accel_wait", UNIT_SEC, 1, 10, 1, 1248 3, "list_accel_wait", UNIT_SEC, 1, 10, 1,
1249 scanaccel_formatter, scanaccel_getlang, NULL), 1249 scanaccel_formatter, scanaccel_getlang, NULL),
1250#endif /* HAVE_SCROLLWHEEL */ 1250#endif /* HAVE_SCROLLWHEEL */
1251 SYSTEM_SETTING(NVRAM(4),filetype_count, MAX_FILETYPES),
1251}; 1252};
1252 1253
1253const int nb_settings = sizeof(settings)/sizeof(*settings); 1254const int nb_settings = sizeof(settings)/sizeof(*settings);