diff options
Diffstat (limited to 'apps/plugins/euroconverter.c')
-rw-r--r-- | apps/plugins/euroconverter.c | 75 |
1 files changed, 26 insertions, 49 deletions
diff --git a/apps/plugins/euroconverter.c b/apps/plugins/euroconverter.c index 107f36e776..4d05f1a5ac 100644 --- a/apps/plugins/euroconverter.c +++ b/apps/plugins/euroconverter.c | |||
@@ -17,6 +17,7 @@ | |||
17 | * | 17 | * |
18 | ****************************************************************************/ | 18 | ****************************************************************************/ |
19 | #include "plugin.h" | 19 | #include "plugin.h" |
20 | #include "configfile.h" | ||
20 | 21 | ||
21 | #ifdef HAVE_LCD_CHARCELLS | 22 | #ifdef HAVE_LCD_CHARCELLS |
22 | 23 | ||
@@ -43,7 +44,7 @@ To do: | |||
43 | */ | 44 | */ |
44 | 45 | ||
45 | /* Name and path of the config file*/ | 46 | /* Name and path of the config file*/ |
46 | #define CFGFILE "/.rockbox/euroconverter.cfg" | 47 | #define CFGFILE "euroconverter.cfg" |
47 | 48 | ||
48 | /*Pattern for the converter*/ | 49 | /*Pattern for the converter*/ |
49 | static unsigned char pattern_euro[]={0x07, 0x08, 0x1E, 0x10, 0x1E, 0x08, 0x07}; /* € */ | 50 | static unsigned char pattern_euro[]={0x07, 0x08, 0x1E, 0x10, 0x1E, 0x08, 0x07}; /* € */ |
@@ -134,10 +135,30 @@ static unsigned char heuro,hhome; /*Handles for the new patterns*/ | |||
134 | 135 | ||
135 | static struct plugin_api* rb; | 136 | static struct plugin_api* rb; |
136 | 137 | ||
138 | static char *currency_str[12] = { | ||
139 | "France", | ||
140 | "Germany", | ||
141 | "Austria", | ||
142 | "Belgium", | ||
143 | "Spain", | ||
144 | "Finland", | ||
145 | "Irland", | ||
146 | "Italy", | ||
147 | "Luxemburg", | ||
148 | "Netherlands", | ||
149 | "Portugal", | ||
150 | "Greece" | ||
151 | }; | ||
152 | |||
137 | static int country; /*Country selected*/ | 153 | static int country; /*Country selected*/ |
138 | static int cur_pos; /*Cursor position*/ | 154 | static int cur_pos; /*Cursor position*/ |
139 | static long long inc; | 155 | static long long inc; |
140 | 156 | ||
157 | /* Persistent settings */ | ||
158 | static struct configdata config[] = { | ||
159 | { TYPE_ENUM, 0, 12, &country, "country", currency_str, NULL } | ||
160 | }; | ||
161 | |||
141 | 162 | ||
142 | /* 64bits*64 bits with 5 digits after the . */ | 163 | /* 64bits*64 bits with 5 digits after the . */ |
143 | static long long mul(long long a, long long b) | 164 | static long long mul(long long a, long long b) |
@@ -278,66 +299,20 @@ static void show_abbrev(void) | |||
278 | /* Save the config to disk */ | 299 | /* Save the config to disk */ |
279 | static void save_config(void) | 300 | static void save_config(void) |
280 | { | 301 | { |
281 | int fd; | 302 | configfile_save(CFGFILE, config, 1); |
282 | |||
283 | fd = rb->creat(CFGFILE,0); | ||
284 | if (fd < 0) | ||
285 | { | ||
286 | rb->lcd_clear_display(); | ||
287 | rb->splash(HZ, false, "Failed to save config"); | ||
288 | rb->sleep(HZ); | ||
289 | } | ||
290 | else | ||
291 | { | ||
292 | rb->fprintf(fd, "last currency: %d\n", country); | ||
293 | rb->close(fd); | ||
294 | } | ||
295 | return; | ||
296 | } | 303 | } |
297 | 304 | ||
298 | 305 | ||
299 | /* Load the config from disk */ | 306 | /* Load the config from disk */ |
300 | static void load_config(void) | 307 | static void load_config(void) |
301 | { | 308 | { |
302 | int fd; | 309 | configfile_load(CFGFILE, config, 1); |
303 | char line[128]; | ||
304 | char *name, *value; | ||
305 | |||
306 | fd = rb->open(CFGFILE, O_RDONLY); | ||
307 | if (fd < 0) | ||
308 | return; | ||
309 | |||
310 | rb->read_line(fd, line, 128); | ||
311 | rb->settings_parseline(line, &name, &value); | ||
312 | |||
313 | if(!rb->strcmp("last currency", name)) | ||
314 | country = rb->atoi(value); | ||
315 | |||
316 | if ((country>11)|| (country<0)) | ||
317 | country=0; | ||
318 | |||
319 | rb->close(fd); | ||
320 | return; | ||
321 | } | 310 | } |
322 | 311 | ||
323 | 312 | ||
324 | /*Currency choice*/ | 313 | /*Currency choice*/ |
325 | static void currency_menu(void) | 314 | static void currency_menu(void) |
326 | { | 315 | { |
327 | unsigned char *currency_str[12] = { | ||
328 | "France", | ||
329 | "Germany", | ||
330 | "Austria", | ||
331 | "Belgium", | ||
332 | "Spain", | ||
333 | "Finland", | ||
334 | "Irland", | ||
335 | "Italy", | ||
336 | "Luxemburg", | ||
337 | "Netherlands", | ||
338 | "Portugal", | ||
339 | "Greece" | ||
340 | }; | ||
341 | int c=country; | 316 | int c=country; |
342 | 317 | ||
343 | rb->lcd_clear_display(); | 318 | rb->lcd_clear_display(); |
@@ -448,6 +423,8 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
448 | cur_pos=3; | 423 | cur_pos=3; |
449 | inc=100000; | 424 | inc=100000; |
450 | 425 | ||
426 | configfile_init(rb); | ||
427 | |||
451 | load_config(); | 428 | load_config(); |
452 | 429 | ||
453 | /*Empty the event queue*/ | 430 | /*Empty the event queue*/ |