diff options
author | Jonathan Gordon <rockbox@jdgordon.info> | 2007-04-16 09:14:36 +0000 |
---|---|---|
committer | Jonathan Gordon <rockbox@jdgordon.info> | 2007-04-16 09:14:36 +0000 |
commit | 6a5cc0bd25bd468c79e453fa49f353edd824141a (patch) | |
tree | 8b406e8390550ff8b87eae3214309867574657f0 /apps/filetypes.c | |
parent | 7afe2e86931313653d4dedb6d5167c79c2822aba (diff) | |
download | rockbox-6a5cc0bd25bd468c79e453fa49f353edd824141a.tar.gz rockbox-6a5cc0bd25bd468c79e453fa49f353edd824141a.zip |
Customizable icons for all bitmap targets. (FS#7013)
http://www.rockbox.org/twiki/bin/view/Main/CustomIcons for info on format and how to load them
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13177 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/filetypes.c')
-rw-r--r-- | apps/filetypes.c | 103 |
1 files changed, 50 insertions, 53 deletions
diff --git a/apps/filetypes.c b/apps/filetypes.c index ca6578aa23..f91df19652 100644 --- a/apps/filetypes.c +++ b/apps/filetypes.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
23 | #include <stdbool.h> | 23 | #include <stdbool.h> |
24 | #include "string.h" | 24 | #include "string.h" |
25 | #include "atoi.h" | ||
25 | #include <ctype.h> | 26 | #include <ctype.h> |
26 | 27 | ||
27 | #include "sprintf.h" | 28 | #include "sprintf.h" |
@@ -55,7 +56,7 @@ | |||
55 | #define ROCK_EXTENSION "rock" | 56 | #define ROCK_EXTENSION "rock" |
56 | 57 | ||
57 | struct file_type { | 58 | struct file_type { |
58 | ICON_NO_CONST icon; /* the icon which shall be used for it, NOICON if unknown */ | 59 | int icon; /* the icon which shall be used for it, NOICON if unknown */ |
59 | bool viewer; /* true if the rock is in viewers, false if in rocks */ | 60 | bool viewer; /* true if the rock is in viewers, false if in rocks */ |
60 | unsigned char attr; /* FILETYPES_MASK >> 8 */ | 61 | unsigned char attr; /* FILETYPES_MASK >> 8 */ |
61 | char* plugin; /* Which plugin to use, NULL if unknown, or builtin */ | 62 | char* plugin; /* Which plugin to use, NULL if unknown, or builtin */ |
@@ -73,6 +74,38 @@ static char *filetypes_strdup(char* string) | |||
73 | } | 74 | } |
74 | static void read_builtin_types(void); | 75 | static void read_builtin_types(void); |
75 | static void read_config(char* config_file); | 76 | static void read_config(char* config_file); |
77 | #ifdef HAVE_LCD_BITMAP | ||
78 | void read_viewer_theme_file(void) | ||
79 | { | ||
80 | char buffer[MAX_PATH]; | ||
81 | int fd; | ||
82 | char *ext, *icon; | ||
83 | int i; | ||
84 | snprintf(buffer, MAX_PATH, "%s/%s.icons", ICON_DIR, | ||
85 | global_settings.viewers_icon_file); | ||
86 | fd = open(buffer, O_RDONLY); | ||
87 | if (fd < 0) | ||
88 | return; | ||
89 | while (read_line(fd, buffer, MAX_PATH) > 0) | ||
90 | { | ||
91 | if (!settings_parseline(buffer, &ext, &icon)) | ||
92 | continue; | ||
93 | for (i=0; i<filetype_count; i++) | ||
94 | { | ||
95 | if (filetypes[i].extension && !strcasecmp(ext, filetypes[i].extension)) | ||
96 | { | ||
97 | if (*icon == '*') | ||
98 | filetypes[i].icon = atoi(icon+1); | ||
99 | else if (*icon == '-') | ||
100 | filetypes[i].icon = Icon_NOICON; | ||
101 | else filetypes[i].icon = Icon_Last_Themeable + atoi(icon); | ||
102 | break; | ||
103 | } | ||
104 | } | ||
105 | } | ||
106 | close(fd); | ||
107 | } | ||
108 | #endif | ||
76 | 109 | ||
77 | void filetype_init(void) | 110 | void filetype_init(void) |
78 | { | 111 | { |
@@ -80,15 +113,14 @@ void filetype_init(void) | |||
80 | filetypes[0].extension = NULL; | 113 | filetypes[0].extension = NULL; |
81 | filetypes[0].plugin = NULL; | 114 | filetypes[0].plugin = NULL; |
82 | filetypes[0].attr = 0; | 115 | filetypes[0].attr = 0; |
83 | filetypes[0].icon = | 116 | filetypes[0].icon = Icon_Folder; |
84 | #ifdef HAVE_LCD_BITMAP | 117 | |
85 | (ICON_NO_CONST)&bitmap_icons_6x8[Icon_Folder]; | ||
86 | #else | ||
87 | (ICON_NO_CONST)Icon_Folder; | ||
88 | #endif | ||
89 | filetype_count = 1; | 118 | filetype_count = 1; |
90 | read_builtin_types(); | 119 | read_builtin_types(); |
91 | read_config(VIEWERS_CONFIG); | 120 | read_config(VIEWERS_CONFIG); |
121 | #ifdef HAVE_LCD_BITMAP | ||
122 | read_viewer_theme_file(); | ||
123 | #endif | ||
92 | } | 124 | } |
93 | 125 | ||
94 | /* remove all white spaces from string */ | 126 | /* remove all white spaces from string */ |
@@ -119,12 +151,7 @@ static void read_builtin_types(void) | |||
119 | filetypes[filetype_count].attr = types[i].tree_attr>>8; | 151 | filetypes[filetype_count].attr = types[i].tree_attr>>8; |
120 | if (filetypes[filetype_count].attr > heighest_attr) | 152 | if (filetypes[filetype_count].attr > heighest_attr) |
121 | heighest_attr = filetypes[filetype_count].attr; | 153 | heighest_attr = filetypes[filetype_count].attr; |
122 | filetypes[filetype_count].icon = | 154 | filetypes[filetype_count].icon = types[i].icon; |
123 | #ifdef HAVE_LCD_BITMAP | ||
124 | (ICON_NO_CONST)&bitmap_icons_6x8[types[i].icon]; | ||
125 | #else | ||
126 | (ICON_NO_CONST)types[i].icon; | ||
127 | #endif | ||
128 | filetype_count++; | 155 | filetype_count++; |
129 | } | 156 | } |
130 | } | 157 | } |
@@ -133,10 +160,6 @@ static void read_config(char* config_file) | |||
133 | { | 160 | { |
134 | char line[64], *s, *e; | 161 | char line[64], *s, *e; |
135 | char extension[8], plugin[32]; | 162 | char extension[8], plugin[32]; |
136 | #ifdef HAVE_LCD_BITMAP | ||
137 | char icon[ICON_LENGTH]; | ||
138 | int good_icon; | ||
139 | #endif | ||
140 | bool viewer; | 163 | bool viewer; |
141 | int fd = open(config_file, O_RDONLY); | 164 | int fd = open(config_file, O_RDONLY); |
142 | if (fd < 0) | 165 | if (fd < 0) |
@@ -181,44 +204,18 @@ static void read_config(char* config_file) | |||
181 | filetypes[filetype_count].plugin = filetypes_strdup(plugin); | 204 | filetypes[filetype_count].plugin = filetypes_strdup(plugin); |
182 | filetypes[filetype_count].viewer = viewer; | 205 | filetypes[filetype_count].viewer = viewer; |
183 | filetypes[filetype_count].attr = heighest_attr +1; | 206 | filetypes[filetype_count].attr = heighest_attr +1; |
207 | filetypes[filetype_count].icon = Icon_Questionmark; | ||
184 | heighest_attr++; | 208 | heighest_attr++; |
185 | /* get the icon */ | 209 | /* get the icon */ |
186 | #ifdef HAVE_LCD_BITMAP | 210 | #ifdef HAVE_LCD_BITMAP |
187 | s = e+1; | 211 | s = e+1; |
188 | good_icon = 1; | 212 | if (*s == '*') |
189 | if (strlen(s) == 12) | 213 | filetypes[filetype_count].icon = atoi(s+1); |
190 | { | 214 | else if (*s == '-') |
191 | int i, j; | 215 | filetypes[filetype_count].icon = Icon_NOICON; |
192 | char val[2]; | 216 | else filetypes[filetype_count].icon = Icon_Last_Themeable + atoi(s); |
193 | for (i = 0; good_icon && i < ICON_LENGTH; i++) | ||
194 | { | ||
195 | for (j=0; good_icon && j<2; j++) | ||
196 | { | ||
197 | val[j] = tolower(s[i*2+j]); | ||
198 | if (val[j] >= 'a' && val[j] <= 'f') | ||
199 | { | ||
200 | val[j] = val[j] - 'a' + 10; | ||
201 | } | ||
202 | else if (val[j] >= '0' && val[j] <= '9') | ||
203 | { | ||
204 | val[j] = val[j] - '0'; | ||
205 | } | ||
206 | else | ||
207 | good_icon = 0; | ||
208 | } | ||
209 | icon[i]=((val[0]<<4) | val[1]); | ||
210 | } | ||
211 | } | ||
212 | if (good_icon) | ||
213 | { | ||
214 | filetypes[filetype_count].icon = | ||
215 | (ICON_NO_CONST)buffer_alloc(ICON_LENGTH); | ||
216 | memcpy(filetypes[filetype_count].icon, icon, ICON_LENGTH); | ||
217 | } | ||
218 | else | ||
219 | filetypes[filetype_count].icon = NOICON; | ||
220 | #else | 217 | #else |
221 | filetypes[filetype_count].icon = Icon_Unknown; | 218 | filetypes[filetype_count].icon = Icon_NOICON; |
222 | #endif | 219 | #endif |
223 | filetype_count++; | 220 | filetype_count++; |
224 | } | 221 | } |
@@ -254,12 +251,12 @@ static int find_attr(int attr) | |||
254 | return -1; | 251 | return -1; |
255 | } | 252 | } |
256 | 253 | ||
257 | ICON filetype_get_icon(int attr) | 254 | int filetype_get_icon(int attr) |
258 | { | 255 | { |
259 | int index = find_attr(attr); | 256 | int index = find_attr(attr); |
260 | if (index < 0) | 257 | if (index < 0) |
261 | return NOICON; | 258 | return Icon_NOICON; |
262 | return (ICON)filetypes[index].icon; | 259 | return filetypes[index].icon; |
263 | } | 260 | } |
264 | 261 | ||
265 | char* filetype_get_plugin(const struct entry* file) | 262 | char* filetype_get_plugin(const struct entry* file) |