summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Gordon <rockbox@jdgordon.info>2013-01-20 22:29:43 +1100
committerJonathan Gordon <rockbox@jdgordon.info>2013-01-20 22:44:03 +1100
commit70595a278a7bc7b2543f498bda4ddad84a7f7536 (patch)
tree605073acd1d8ebc7f7710f4a7229b328fa26926f
parente9f8846ce2b7967f9fa14f565b6970b900b1618e (diff)
downloadrockbox-70595a278a7bc7b2543f498bda4ddad84a7f7536.tar.gz
rockbox-70595a278a7bc7b2543f498bda4ddad84a7f7536.zip
filetree: Support ??? in viewers.config for unsupported filetypes
This will allow the user to set the file colour and icon for all unknown files in the file browser. Change-Id: I4e601f9d2ea31ac972d8066252bf80b6c0d22268
-rw-r--r--apps/filetypes.c50
1 files changed, 42 insertions, 8 deletions
diff --git a/apps/filetypes.c b/apps/filetypes.c
index 8a4cedc0ea..637bda458a 100644
--- a/apps/filetypes.c
+++ b/apps/filetypes.c
@@ -176,8 +176,21 @@ static struct file_type filetypes[MAX_FILETYPES];
176static int custom_filetype_icons[MAX_FILETYPES]; 176static int custom_filetype_icons[MAX_FILETYPES];
177static bool custom_icons_loaded = false; 177static bool custom_icons_loaded = false;
178#ifdef HAVE_LCD_COLOR 178#ifdef HAVE_LCD_COLOR
179static int custom_colors[MAX_FILETYPES+1]; 179static int custom_colors[MAX_FILETYPES];
180#endif 180#endif
181struct filetype_unknown {
182 enum themable_icons icon;
183#ifdef HAVE_LCD_COLOR
184 int color;
185#endif
186};
187static struct filetype_unknown unknown_file = {
188 .icon = Icon_NOICON,
189#ifdef HAVE_LCD_COLOR
190 .color = -1,
191#endif
192};
193
181/* index array to filetypes used in open with list. */ 194/* index array to filetypes used in open with list. */
182static int viewers[MAX_VIEWERS]; 195static int viewers[MAX_VIEWERS];
183static int filetype_count = 0; 196static int filetype_count = 0;
@@ -253,7 +266,7 @@ void read_color_theme_file(void) {
253 int fd; 266 int fd;
254 char *ext, *color; 267 char *ext, *color;
255 int i; 268 int i;
256 for (i = 0; i < MAX_FILETYPES+1; i++) { 269 for (i = 0; i < MAX_FILETYPES; i++) {
257 custom_colors[i] = -1; 270 custom_colors[i] = -1;
258 } 271 }
259 snprintf(buffer, MAX_PATH, THEME_DIR "/%s.colours", 272 snprintf(buffer, MAX_PATH, THEME_DIR "/%s.colours",
@@ -272,7 +285,7 @@ void read_color_theme_file(void) {
272 } 285 }
273 if (!strcasecmp(ext, "???")) 286 if (!strcasecmp(ext, "???"))
274 { 287 {
275 hex_to_rgb(color, &custom_colors[MAX_FILETYPES]); 288 hex_to_rgb(color, &unknown_file.color);
276 continue; 289 continue;
277 } 290 }
278 i = find_extension(ext); 291 i = find_extension(ext);
@@ -289,6 +302,7 @@ void read_viewer_theme_file(void)
289 int fd; 302 int fd;
290 char *ext, *icon; 303 char *ext, *icon;
291 int i; 304 int i;
305 int *icon_dest;
292 global_status.viewer_icon_count = 0; 306 global_status.viewer_icon_count = 0;
293 custom_icons_loaded = false; 307 custom_icons_loaded = false;
294 custom_filetype_icons[0] = Icon_Folder; 308 custom_filetype_icons[0] = Icon_Folder;
@@ -308,17 +322,24 @@ void read_viewer_theme_file(void)
308 continue; 322 continue;
309 i = find_extension(ext); 323 i = find_extension(ext);
310 if (i >= 0) 324 if (i >= 0)
325 icon_dest = &custom_filetype_icons[i];
326 else if (!strcmp(ext, "???"))
327 icon_dest = &unknown_file.icon;
328 else
329 icon_dest = NULL;
330
331 if (icon_dest)
311 { 332 {
312 if (*icon == '*') 333 if (*icon == '*')
313 custom_filetype_icons[i] = atoi(icon+1); 334 *icon_dest = atoi(icon+1);
314 else if (*icon == '-') 335 else if (*icon == '-')
315 custom_filetype_icons[i] = Icon_NOICON; 336 *icon_dest = Icon_NOICON;
316 else if (*icon >= '0' && *icon <= '9') 337 else if (*icon >= '0' && *icon <= '9')
317 { 338 {
318 int number = atoi(icon); 339 int number = atoi(icon);
319 if (number > global_status.viewer_icon_count) 340 if (number > global_status.viewer_icon_count)
320 global_status.viewer_icon_count++; 341 global_status.viewer_icon_count++;
321 custom_filetype_icons[i] = Icon_Last_Themeable + number; 342 *icon_dest = Icon_Last_Themeable + number;
322 } 343 }
323 } 344 }
324 } 345 }
@@ -424,6 +445,19 @@ static void read_config(int fd)
424 *e = '\0'; 445 *e = '\0';
425 plugin = s; 446 plugin = s;
426 447
448 if (!strcmp("???", extension))
449 {
450 /* get the icon */
451 s = e+1;
452 if (*s == '*')
453 unknown_file.icon = atoi(s+1);
454 else if (*s == '-')
455 unknown_file.icon = Icon_NOICON;
456 else if (*s >= '0' && *s <= '9')
457 unknown_file.icon = Icon_Last_Themeable + atoi(s);
458 continue;
459 }
460
427 /* ok, store this plugin/extension, check icon after */ 461 /* ok, store this plugin/extension, check icon after */
428 struct file_type *file_type = &filetypes[filetype_count]; 462 struct file_type *file_type = &filetypes[filetype_count];
429 file_type->extension = filetypes_strdup(extension); 463 file_type->extension = filetypes_strdup(extension);
@@ -486,7 +520,7 @@ int filetype_get_color(const char * name, int attr)
486 i = find_extension(extension); 520 i = find_extension(extension);
487 if (i >= 0) 521 if (i >= 0)
488 return custom_colors[i]; 522 return custom_colors[i];
489 return custom_colors[MAX_FILETYPES]; 523 return unknown_file.color;
490} 524}
491#endif 525#endif
492 526
@@ -494,7 +528,7 @@ int filetype_get_icon(int attr)
494{ 528{
495 int index = find_attr(attr); 529 int index = find_attr(attr);
496 if (index < 0) 530 if (index < 0)
497 return Icon_NOICON; 531 return unknown_file.icon;
498 if (custom_icons_loaded) 532 if (custom_icons_loaded)
499 return custom_filetype_icons[index]; 533 return custom_filetype_icons[index];
500 return filetypes[index].icon; 534 return filetypes[index].icon;