]> Dogcows Code - chaz/homebank/blob - src/hb-preferences.c
Merge branch 'upstream'
[chaz/homebank] / src / hb-preferences.c
1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2019 Maxime DOYEN
3 *
4 * This file is part of HomeBank.
5 *
6 * HomeBank is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * HomeBank is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20
21 #include "homebank.h"
22
23 #include "hb-preferences.h"
24 #include "hb-filter.h"
25 #include "gtk-chart-colors.h"
26
27 #ifdef G_OS_WIN32
28 #include <windows.h>
29 #endif
30
31 /****************************************************************************/
32 /* Debug macros */
33 /****************************************************************************/
34 #define MYDEBUG 0
35
36 #if MYDEBUG
37 #define DB(x) (x);
38 #else
39 #define DB(x);
40 #endif
41
42 /* our global datas */
43 extern struct HomeBank *GLOBALS;
44 extern struct Preferences *PREFS;
45
46 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
47
48 static void homebank_pref_init_monetary(void)
49 {
50
51 DB( g_print("\n[system] get currency code\n") );
52
53 #ifdef G_OS_UNIX
54 struct lconv *lc = localeconv();
55
56 g_stpcpy (PREFS->IntCurrSymbol, lc->int_curr_symbol);
57 g_strstrip(PREFS->IntCurrSymbol);
58
59 DB( g_print("- stored '%s' from linux system\n", PREFS->IntCurrSymbol) );
60 #else
61
62 #ifdef G_OS_WIN32
63 #define BUFFER_SIZE 512
64 char buffer[BUFFER_SIZE];
65 //LPWSTR wcBuffer = buffer;
66 LPSTR wcBuffer = buffer;
67 int iResult;
68
69 //https://msdn.microsoft.com/en-us/library/windows/desktop/dd464799%28v=vs.85%29.aspx
70
71 //LOCALE_SINTLSYMBOL
72 iResult = GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SINTLSYMBOL, wcBuffer, BUFFER_SIZE);
73 if(iResult > 0)
74 {
75 DB( g_print("LOCALE_SINTLSYMBOL='%s'\n", buffer) );
76 g_stpcpy (PREFS->IntCurrSymbol, buffer);
77 g_strstrip(PREFS->IntCurrSymbol);
78
79 DB( g_print("- stored '%s' from windows system\n", PREFS->IntCurrSymbol) );
80 }
81 #else
82
83 g_stpcpy (PREFS->IntCurrSymbol, "USD");
84
85 DB( g_print("- stored '%s' as default\n", PREFS->IntCurrSymbol) );
86
87 #endif
88
89 #endif
90
91
92 }
93
94
95 /*
96 static void homebank_pref_init_monetary(void)
97 {
98 DB( g_print("\n[preferences] monetary\n") );
99
100
101 #ifdef G_OS_UNIX
102
103 struct lconv *lc = localeconv();
104
105 DB( g_print("\n[preferences] monetary unix\n") );
106
107 DB( g_print("int_curr_symbol '%s'\n", lc->int_curr_symbol) );
108
109 DB( g_print("mon_decimal_point is utf8: %d\n", g_utf8_validate(lc->mon_decimal_point, -1, NULL)) );
110 DB( g_print("mon_decimal_point '%s'\n", lc->mon_decimal_point) );
111 DB( g_print("mon_decimal_point %x %x %x %x\n", lc->mon_decimal_point[0], lc->mon_decimal_point[1], lc->mon_decimal_point[2], lc->mon_decimal_point[3]) );
112
113 DB( g_print("mon_thousands_sep is utf8: %d\n", g_utf8_validate(lc->mon_thousands_sep, -1, NULL)) );
114 DB( g_print("mon_thousands_sep '%s'\n", lc->mon_thousands_sep) );
115 DB( g_print("mon_thousands_sep %x %x %x %x\n", lc->mon_thousands_sep[0], lc->mon_thousands_sep[1], lc->mon_thousands_sep[2], lc->mon_thousands_sep[3]) );
116
117
118 DB( g_print("frac_digits '%d'\n", (gint)lc->frac_digits) );
119
120 DB( g_print("currency_symbol '%s'\n", lc->currency_symbol) );
121
122 DB( g_print("p_cs_precedes '%d'\n", lc->p_cs_precedes) );
123
124 DB( g_print("n_cs_precedes '%d'\n", lc->n_cs_precedes) );
125
126 //PREFS->base_cur.iso_code = g_strdup(g_strstrip(lc->int_curr_symbol));
127
128 if( lc->p_cs_precedes || lc->n_cs_precedes )
129 {
130 PREFS->base_cur.symbol = g_strdup(lc->currency_symbol);
131 PREFS->base_cur.sym_prefix = TRUE;
132 DB( g_print("locale mon cs is a prefix\n") );
133 }
134 else
135 {
136 PREFS->base_cur.symbol = g_strdup(lc->currency_symbol);
137 PREFS->base_cur.sym_prefix = FALSE;
138 }
139
140 PREFS->base_cur.decimal_char = g_strdup(lc->mon_decimal_point);
141
142 PREFS->base_cur.grouping_char = g_strdup(lc->mon_thousands_sep);
143
144 //todo:fix
145 //PREFS->base_cur.grouping_char = g_locale_to_utf8(lc->mon_thousands_sep, -1, NULL, NULL, NULL);
146 //PREFS->base_cur.grouping_char = g_convert (lc->mon_thousands_sep, -1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL);
147
148 DB( g_print(" -> grouping_char: '%s'\n", PREFS->base_cur.grouping_char) );
149
150 PREFS->base_cur.frac_digits = lc->frac_digits;
151
152 //fix 378992/421228
153 if( PREFS->base_cur.frac_digits > MAX_FRAC_DIGIT )
154 {
155 PREFS->base_cur.frac_digits = 2;
156 g_free(PREFS->base_cur.decimal_char);
157 PREFS->base_cur.decimal_char = g_strdup(".");
158 }
159
160 #else
161 #ifdef G_OS_WIN32
162
163 #define BUFFER_SIZE 512
164 char buffer[BUFFER_SIZE];
165 //LPWSTR wcBuffer = buffer;
166 LPSTR wcBuffer = buffer;
167 int iResult;
168 gsize toto;
169
170 //https://msdn.microsoft.com/en-us/library/windows/desktop/dd464799%28v=vs.85%29.aspx
171
172 //LOCALE_SINTLSYMBOL
173
174
175 //see g_locale_to_utf8 here
176 iResult = GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SCURRENCY, wcBuffer, BUFFER_SIZE);
177 if(iResult > 0)
178 {
179 DB( g_print("LOCALE_SCURRENCY='%s'\n", buffer) );
180 PREFS->base_cur.symbol = g_locale_to_utf8(buffer, -1, NULL, &toto, NULL);
181 }
182
183 // LOCALE_ICURRENCY
184 //PREFS->base_cur.sym_prefix =
185
186 iResult = GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, wcBuffer, BUFFER_SIZE);
187 if(iResult > 0)
188 {
189 DB( g_print("LOCALE_SDECIMAL='%s'\n", buffer) );
190 PREFS->base_cur.decimal_char = g_locale_to_utf8(buffer, -1, NULL, &toto, NULL);
191 }
192
193 iResult = GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, wcBuffer, BUFFER_SIZE);
194 if(iResult > 0)
195 {
196 DB( g_print("LOCALE_STHOUSAND='%s'\n", buffer) );
197 PREFS->base_cur.grouping_char = g_locale_to_utf8(buffer, -1, NULL, &toto, NULL);
198 }
199
200 // LOCALE_ICURRDIGITS
201 PREFS->base_cur.frac_digits = 2;
202
203 #else
204
205 PREFS->base_cur.iso_code = g_strdup("USD");
206 PREFS->base_cur.symbol = NULL; //g_strdup("");
207 PREFS->base_cur.sym_prefix = FALSE;
208 PREFS->base_cur.decimal_char = g_strdup(".");
209 PREFS->base_cur.grouping_char = NULL; //g_strdup("");
210 PREFS->base_cur.frac_digits = 2;
211
212 #endif
213 #endif
214
215 }
216 */
217
218
219
220 static void homebank_pref_init_wingeometry(struct WinGeometry *wg, gint l, gint t, gint w, gint h)
221 {
222 wg->l = l;
223 wg->t = t;
224 wg->w = w;
225 wg->h = h;
226 wg->s = 0;
227 }
228
229
230 //vehicle_unit_100
231 //vehicle_unit_distbyvol
232 //=> used for column title
233
234 static void _homebank_pref_init_measurement_units(void)
235 {
236 // unit is kilometer
237 if(!PREFS->vehicle_unit_ismile)
238 {
239 PREFS->vehicle_unit_dist = "%d km";
240 PREFS->vehicle_unit_100 = "100 km";
241 }
242 // unit is miles
243 else
244 {
245 PREFS->vehicle_unit_dist = "%d mi.";
246 PREFS->vehicle_unit_100 = "100 mi.";
247 }
248
249 // unit is Liters
250 if(!PREFS->vehicle_unit_isgal)
251 {
252 //TRANSLATORS: format a liter number with l/L as abbreviation
253 PREFS->vehicle_unit_vol = _("%.2f l");
254 if(!PREFS->vehicle_unit_ismile)
255 //TRANSLATORS: kilometer per liter
256 PREFS->vehicle_unit_distbyvol = _("km/l");
257 else
258 //TRANSLATORS: miles per liter
259 PREFS->vehicle_unit_distbyvol = _("mi./l");
260 }
261 // unit is gallon
262 else
263 {
264 PREFS->vehicle_unit_vol = "%.2f gal.";
265 if(!PREFS->vehicle_unit_ismile)
266 PREFS->vehicle_unit_distbyvol = "km/gal.";
267 else
268 PREFS->vehicle_unit_distbyvol = "mi./gal.";
269 }
270
271 }
272
273
274 void homebank_pref_free(void)
275 {
276 DB( g_print("\n[preferences] free\n") );
277
278
279 g_free(PREFS->date_format);
280
281 g_free(PREFS->color_exp);
282 g_free(PREFS->color_inc);
283 g_free(PREFS->color_warn);
284
285 g_free(PREFS->path_hbfile);
286 g_free(PREFS->path_import);
287 g_free(PREFS->path_export);
288 //g_free(PREFS->path_navigator);
289
290 g_free(PREFS->language);
291
292 g_free(PREFS->pnl_list_tab);
293
294 g_free(PREFS->minor_cur.symbol);
295 g_free(PREFS->minor_cur.decimal_char);
296 g_free(PREFS->minor_cur.grouping_char);
297
298 memset(PREFS, 0, sizeof(struct Preferences));
299 }
300
301
302 void homebank_pref_setdefault(void)
303 {
304 gint i;
305
306 DB( g_print("\n[preferences] pref init\n") );
307
308 homebank_pref_free();
309
310 PREFS->language = NULL;
311
312 PREFS->date_format = g_strdup(DEFAULT_FORMAT_DATE);
313
314 PREFS->path_hbfile = g_strdup_printf("%s", g_get_home_dir ());
315 PREFS->path_import = g_strdup_printf("%s", g_get_home_dir ());
316 PREFS->path_export = g_strdup_printf("%s", g_get_home_dir ());
317 //PREFS->path_navigator = g_strdup(DEFAULT_PATH_NAVIGATOR);
318
319 PREFS->showsplash = TRUE;
320 PREFS->loadlast = TRUE;
321 PREFS->appendscheduled = FALSE;
322 PREFS->do_update_currency = FALSE;
323
324 PREFS->bak_is_automatic = TRUE;
325 PREFS->bak_max_num_copies = 5;
326
327 PREFS->heritdate = FALSE;
328 PREFS->hidereconciled = FALSE;
329 PREFS->showremind = TRUE;
330 //#1673048
331 PREFS->txn_memoacp = TRUE;
332 PREFS->txn_memoacp_days = 365;
333
334 PREFS->toolbar_style = 4; //text beside icons
335 PREFS->custom_colors = TRUE;
336 PREFS->color_exp = g_strdup(DEFAULT_EXP_COLOR);
337 PREFS->color_inc = g_strdup(DEFAULT_INC_COLOR);
338 PREFS->color_warn = g_strdup(DEFAULT_WARN_COLOR);
339 PREFS->grid_lines = GTK_TREE_VIEW_GRID_LINES_NONE;
340
341 /* fiscal year */
342 PREFS->fisc_year_day = 1;
343 PREFS->fisc_year_month = 1;
344
345 /* windows position/size */
346 homebank_pref_init_wingeometry(&PREFS->wal_wg, 0, 0, 1024, 600);
347 homebank_pref_init_wingeometry(&PREFS->acc_wg, 0, 0, 1024, 600);
348 homebank_pref_init_wingeometry(&PREFS->sta_wg, 0, 0, 800, 494);
349 homebank_pref_init_wingeometry(&PREFS->tme_wg, 0, 0, 800, 494);
350 homebank_pref_init_wingeometry(&PREFS->ove_wg, 0, 0, 800, 494);
351 homebank_pref_init_wingeometry(&PREFS->bud_wg, 0, 0, 800, 494);
352 homebank_pref_init_wingeometry(&PREFS->cst_wg, 0, 0, 800, 494);
353
354 homebank_pref_init_wingeometry(&PREFS->txn_wg, 0, 0, -1, -1);
355
356 homebank_pref_init_monetary();
357
358 PREFS->wal_toolbar = TRUE;
359 PREFS->wal_spending = TRUE;
360 PREFS->wal_upcoming = TRUE;
361 PREFS->wal_vpaned = 600/2;
362 PREFS->wal_hpaned = 1024/2;
363
364 PREFS->pnl_acc_col_acc_width = -1;
365 PREFS->pnl_acc_show_by = 0;
366 PREFS->pnl_upc_col_pay_width = -1;
367 PREFS->pnl_upc_col_mem_width = -1;
368
369 i = 0;
370 PREFS->lst_impope_columns[i++] = LST_DSPOPE_DATE; //always displayed
371 PREFS->lst_impope_columns[i++] = LST_DSPOPE_MEMO;
372 PREFS->lst_impope_columns[i++] = LST_DSPOPE_AMOUNT;
373 PREFS->lst_impope_columns[i++] = LST_DSPOPE_INFO;
374 PREFS->lst_impope_columns[i++] = LST_DSPOPE_PAYEE;
375 PREFS->lst_impope_columns[i++] = LST_DSPOPE_CATEGORY;
376 PREFS->lst_impope_columns[i++] = -LST_DSPOPE_TAGS;
377 PREFS->lst_impope_columns[i++] = -LST_DSPOPE_CLR;
378 PREFS->lst_impope_columns[i++] = -LST_DSPOPE_STATUS; //always displayed
379 PREFS->lst_impope_columns[i++] = -LST_DSPOPE_EXPENSE;
380 PREFS->lst_impope_columns[i++] = -LST_DSPOPE_INCOME;
381 PREFS->lst_impope_columns[i++] = -LST_DSPOPE_BALANCE;
382 PREFS->lst_impope_columns[i++] = -LST_DSPOPE_ACCOUNT;
383
384 i = 0;
385 PREFS->lst_ope_columns[i++] = LST_DSPOPE_STATUS; //always displayed
386 PREFS->lst_ope_columns[i++] = LST_DSPOPE_DATE; //always displayed
387 PREFS->lst_ope_columns[i++] = LST_DSPOPE_INFO;
388 PREFS->lst_ope_columns[i++] = LST_DSPOPE_PAYEE;
389 PREFS->lst_ope_columns[i++] = LST_DSPOPE_CATEGORY;
390 PREFS->lst_ope_columns[i++] = LST_DSPOPE_TAGS;
391 PREFS->lst_ope_columns[i++] = LST_DSPOPE_CLR;
392 PREFS->lst_ope_columns[i++] = -LST_DSPOPE_AMOUNT;
393 PREFS->lst_ope_columns[i++] = LST_DSPOPE_EXPENSE;
394 PREFS->lst_ope_columns[i++] = LST_DSPOPE_INCOME;
395 PREFS->lst_ope_columns[i++] = LST_DSPOPE_BALANCE;
396 PREFS->lst_ope_columns[i++] = LST_DSPOPE_MEMO;
397 PREFS->lst_ope_columns[i++] = -LST_DSPOPE_ACCOUNT;
398
399 PREFS->lst_ope_sort_id = LST_DSPOPE_DATE;
400 PREFS->lst_ope_sort_order = GTK_SORT_ASCENDING;
401
402 for( i=0;i<NUM_LST_DSPOPE;i++)
403 PREFS->lst_ope_col_width[i] = -1;
404
405 //PREFS->base_cur.nbdecimal = 2;
406 //PREFS->base_cur.separator = TRUE;
407
408 //PREFS->date_range_wal = FLT_RANGE_LASTMONTH;
409 //PREFS->date_range_txn = FLT_RANGE_LAST12MONTHS;
410 //PREFS->date_range_rep = FLT_RANGE_THISYEAR;
411
412 //v5.2 change to let the example file show things
413 PREFS->date_range_wal = FLT_RANGE_ALLDATE;
414 PREFS->date_range_txn = FLT_RANGE_ALLDATE;
415 PREFS->date_range_rep = FLT_RANGE_ALLDATE;
416 PREFS->date_future_nbdays = 0;
417
418 //import/export
419 PREFS->dtex_nointro = TRUE;
420 PREFS->dtex_ucfirst = FALSE;
421 //PREFS->dtex_datefmt
422 PREFS->dtex_ofxname = 1;
423 PREFS->dtex_ofxmemo = 2;
424 PREFS->dtex_qifmemo = TRUE;
425 PREFS->dtex_qifswap = FALSE;
426
427 //todo: add intelligence here
428 PREFS->euro_active = FALSE;
429
430 PREFS->euro_country = 0;
431 PREFS->euro_value = 1.0;
432
433 da_cur_initformat(&PREFS->minor_cur);
434
435 //PREFS->euro_nbdec = 2;
436 //PREFS->euro_thsep = TRUE;
437 //PREFS->euro_symbol = g_strdup("??");
438
439 PREFS->stat_byamount = FALSE;
440 PREFS->stat_showdetail = FALSE;
441 PREFS->stat_showrate = FALSE;
442 PREFS->budg_showdetail = FALSE;
443 PREFS->report_color_scheme = CHART_COLMAP_HOMEBANK;
444
445 //PREFS->chart_legend = FALSE;
446
447 PREFS->vehicle_unit_ismile = FALSE;
448 PREFS->vehicle_unit_isgal = FALSE;
449
450 _homebank_pref_init_measurement_units();
451
452 }
453
454
455 /*
456 ** load preference from homedir/.homebank (HB_DATA_PATH)
457 */
458 static void homebank_pref_get_wingeometry(
459 GKeyFile *key_file,
460 const gchar *group_name,
461 const gchar *key,
462 struct WinGeometry *storage)
463 {
464 if( g_key_file_has_key(key_file, group_name, key, NULL) )
465 {
466 gint *wg;
467 gsize length;
468
469 wg = g_key_file_get_integer_list(key_file, group_name, key, &length, NULL);
470 memcpy(storage, wg, 5*sizeof(gint));
471 g_free(wg);
472 // #606613 ensure left/top to be > 0
473 if(storage->l < 0)
474 storage->l = 0;
475
476 if(storage->t < 0)
477 storage->t = 0;
478 }
479 }
480
481
482
483
484 static void homebank_pref_get_boolean(
485 GKeyFile *key_file,
486 const gchar *group_name,
487 const gchar *key,
488 gboolean *storage)
489 {
490 DB( g_print(" search %s in %s\n", key, group_name) );
491
492 if( g_key_file_has_key(key_file, group_name, key, NULL) )
493 {
494 *storage = g_key_file_get_boolean(key_file, group_name, key, NULL);
495 DB( g_print(" stored boolean %d for %s at %x\n", *storage, key, *storage) );
496 }
497 }
498
499 static void homebank_pref_get_integer(
500 GKeyFile *key_file,
501 const gchar *group_name,
502 const gchar *key,
503 gint *storage)
504 {
505 DB( g_print(" search %s in %s\n", key, group_name) );
506
507 if( g_key_file_has_key(key_file, group_name, key, NULL) )
508 {
509 *storage = g_key_file_get_integer(key_file, group_name, key, NULL);
510 DB( g_print(" stored integer %d for %s at %x\n", *storage, key, *storage) );
511 }
512 }
513
514 static void homebank_pref_get_guint32(
515 GKeyFile *key_file,
516 const gchar *group_name,
517 const gchar *key,
518 guint32 *storage)
519 {
520 DB( g_print(" search %s in %s\n", key, group_name) );
521
522 if( g_key_file_has_key(key_file, group_name, key, NULL) )
523 {
524 *storage = g_key_file_get_integer(key_file, group_name, key, NULL);
525 DB( g_print(" stored guint32 %d for %s at %x\n", *storage, key, *storage) );
526 }
527 }
528
529 static void homebank_pref_get_short(
530 GKeyFile *key_file,
531 const gchar *group_name,
532 const gchar *key,
533 gshort *storage)
534 {
535 DB( g_print(" search %s in %s\n", key, group_name) );
536
537 if( g_key_file_has_key(key_file, group_name, key, NULL) )
538 {
539 *storage = (gshort)g_key_file_get_integer(key_file, group_name, key, NULL);
540 DB( g_print(" stored short %d for %s at %x\n", *storage, key, *storage) );
541 }
542 }
543
544 static void homebank_pref_get_string(
545 GKeyFile *key_file,
546 const gchar *group_name,
547 const gchar *key,
548 gchar **storage)
549 {
550 gchar *string;
551
552 if( g_key_file_has_key(key_file, group_name, key, NULL) )
553 {
554 /* free any previous string */
555 if( *storage != NULL )
556 {
557 //DB( g_print(" storage was not null, freeing\n") );
558
559 g_free(*storage);
560 }
561
562 *storage = NULL;
563
564 string = g_key_file_get_string(key_file, group_name, key, NULL);
565 if( string != NULL )
566 {
567 //*storage = g_strdup(string);
568 //leak
569 *storage = string; //already a new allocated string
570
571 //DB( g_print(" store '%s' for %s at %x\n", string, key, *storage) );
572 }
573 }
574
575 /*
576 if (error)
577 {
578 g_warning ("error: %s\n", error->message);
579 g_error_free(error);
580 error = NULL;
581 }
582 */
583
584
585 }
586
587
588 static void homebank_pref_currfmt_convert(Currency *cur, gchar *prefix, gchar *suffix)
589 {
590
591 if( (prefix != NULL) && (strlen(prefix) > 0) )
592 {
593 cur->symbol = g_strdup(prefix);
594 cur->sym_prefix = TRUE;
595 }
596 else if( (suffix != NULL) )
597 {
598 cur->symbol = g_strdup(suffix);
599 cur->sym_prefix = FALSE;
600 }
601 }
602
603
604 gboolean homebank_pref_load(void)
605 {
606 GKeyFile *keyfile;
607 gboolean retval = FALSE;
608 gchar *group, *filename;
609 guint32 version;
610 gboolean loaded;
611 GError *error = NULL;
612
613 DB( g_print("\n[preferences] pref load\n") );
614
615 keyfile = g_key_file_new();
616 if(keyfile)
617 {
618 filename = g_build_filename(homebank_app_get_config_dir(), "preferences", NULL );
619
620 DB( g_print(" - filename: %s\n", filename) );
621
622 error = NULL;
623 loaded = g_key_file_load_from_file (keyfile, filename, G_KEY_FILE_NONE, &error);
624 if( error )
625 {
626 g_warning("unable to load file %s: %s", filename, error->message);
627 g_error_free (error);
628 }
629
630 if( loaded == TRUE )
631 {
632
633 group = "General";
634
635 DB( g_print(" -> ** General\n") );
636
637 //since 4.51 version is integer
638 homebank_pref_get_guint32 (keyfile, group, "Version", &version);
639 if(version == 0) // old double number
640 {
641 gdouble v = g_key_file_get_double (keyfile, group, "Version", NULL);
642 version = (guint32)(v * 10);
643 }
644
645 DB( g_print(" - version: %d\n", version) );
646
647 homebank_pref_get_string(keyfile, group, "Language", &PREFS->language);
648
649 homebank_pref_get_short(keyfile, group, "BarStyle" , &PREFS->toolbar_style);
650
651 if(version <= 6 && PREFS->toolbar_style == 0) // force system to text beside
652 {
653 PREFS->toolbar_style = 4;
654 }
655
656 if(version <= 2) // retrieve old settings
657 {
658 guint32 color;
659
660 homebank_pref_get_guint32(keyfile, group, "ColorExp" , &color);
661 g_free(PREFS->color_exp);
662 PREFS->color_exp = g_strdup_printf("#%06x", color);
663
664 homebank_pref_get_guint32(keyfile, group, "ColorInc" , &color);
665 g_free(PREFS->color_inc);
666 PREFS->color_inc = g_strdup_printf("#%06x", color);
667
668 homebank_pref_get_guint32(keyfile, group, "ColorWarn", &color);
669 g_free(PREFS->color_warn);
670 PREFS->color_warn = g_strdup_printf("#%06x", color);
671 }
672 else
673 {
674 homebank_pref_get_boolean(keyfile, group, "CustomColors", &PREFS->custom_colors);
675
676 homebank_pref_get_string(keyfile, group, "ColorExp" , &PREFS->color_exp);
677 homebank_pref_get_string(keyfile, group, "ColorInc" , &PREFS->color_inc);
678 homebank_pref_get_string(keyfile, group, "ColorWarn", &PREFS->color_warn);
679
680 if( version <= 500 )
681 {
682 gboolean rules_hint;
683 homebank_pref_get_boolean(keyfile, group, "RulesHint", &rules_hint);
684 if( rules_hint == TRUE )
685 PREFS->grid_lines = GTK_TREE_VIEW_GRID_LINES_HORIZONTAL;
686
687 }
688 else
689 homebank_pref_get_short(keyfile, group, "GridLines", &PREFS->grid_lines);
690 }
691
692 DB( g_print(" - color exp: %s\n", PREFS->color_exp) );
693 DB( g_print(" - color inc: %s\n", PREFS->color_inc) );
694 DB( g_print(" - color wrn: %s\n", PREFS->color_warn) );
695
696
697 homebank_pref_get_string(keyfile, group, "WalletPath", &PREFS->path_hbfile);
698 homebank_pref_get_string(keyfile, group, "ImportPath", &PREFS->path_import);
699 homebank_pref_get_string(keyfile, group, "ExportPath", &PREFS->path_export);
700
701 homebank_pref_get_boolean(keyfile, group, "ShowSplash", &PREFS->showsplash);
702 homebank_pref_get_boolean(keyfile, group, "LoadLast", &PREFS->loadlast);
703 homebank_pref_get_boolean(keyfile, group, "AppendScheduled", &PREFS->appendscheduled);
704 homebank_pref_get_boolean(keyfile, group, "UpdateCurrency", &PREFS->do_update_currency);
705
706 homebank_pref_get_boolean(keyfile, group, "BakIsAutomatic", &PREFS->bak_is_automatic);
707 homebank_pref_get_short(keyfile, group, "BakMaxNumCopies", &PREFS->bak_max_num_copies);
708
709 homebank_pref_get_boolean(keyfile, group, "HeritDate", &PREFS->heritdate);
710 homebank_pref_get_boolean(keyfile, group, "HideReconciled", &PREFS->hidereconciled);
711 homebank_pref_get_boolean(keyfile, group, "ShowRemind", &PREFS->showremind);
712 homebank_pref_get_boolean(keyfile, group, "TxnMemoAcp", &PREFS->txn_memoacp);
713 homebank_pref_get_short(keyfile, group, "TxnMemoAcpDays", &PREFS->txn_memoacp_days);
714
715
716 if( g_key_file_has_key(keyfile, group, "ColumnsOpe", NULL) )
717 {
718 gboolean *bsrc;
719 gint *src, i, j;
720 gsize length;
721
722 if(version <= 2) //retrieve old 0.1 or 0.2 visibility boolean
723 {
724 bsrc = g_key_file_get_boolean_list(keyfile, group, "ColumnsOpe", &length, NULL);
725 if( length == NUM_LST_DSPOPE-1 )
726 {
727 //and convert
728 for(i=0; i<NUM_LST_DSPOPE-1 ; i++)
729 {
730 PREFS->lst_ope_columns[i] = (bsrc[i] == TRUE) ? i+1 : -(i+1);
731 }
732 }
733 g_free(bsrc);
734 }
735 else
736 {
737 src = g_key_file_get_integer_list(keyfile, group, "ColumnsOpe", &length, NULL);
738
739 DB( g_print(" - length %d (max=%d)\n", length, NUM_LST_DSPOPE) );
740
741 if( length == NUM_LST_DSPOPE )
742 {
743 DB( g_print(" - copying column order from pref file\n") );
744 memcpy(PREFS->lst_ope_columns, src, length*sizeof(gint));
745 }
746 else
747 {
748 if(version <= 7)
749 {
750 if( length == NUM_LST_DSPOPE-2 ) //1 less column before v4.5.1
751 {
752 DB( g_print(" - upgrade from v7\n") );
753 DB( g_print(" - copying column order from pref file\n") );
754 memcpy(PREFS->lst_ope_columns, src, length*sizeof(gint));
755 //append balance column
756 PREFS->lst_ope_columns[10] = LST_DSPOPE_BALANCE;
757 }
758 }
759
760 if(version < 500)
761 {
762 if( length == NUM_LST_DSPOPE-2 ) //1 less column before v4.5.1
763 {
764 DB( g_print(" - upgrade prior v5.0\n") );
765 DB( g_print(" - copying column order from pref file\n") );
766 gboolean added = FALSE;
767 for(i=0,j=0; i<NUM_LST_DSPOPE-1 ; i++)
768 {
769 if( added == FALSE &&
770 (ABS(src[i]) == LST_DSPOPE_AMOUNT ||
771 ABS(src[i]) == LST_DSPOPE_EXPENSE ||
772 ABS(src[i]) == LST_DSPOPE_INCOME) )
773 {
774 PREFS->lst_ope_columns[j++] = LST_DSPOPE_CLR;
775 added = TRUE;
776 }
777 PREFS->lst_ope_columns[j++] = src[i];
778 }
779 }
780 }
781
782 }
783
784 g_free(src);
785 }
786
787 }
788
789 if( g_key_file_has_key(keyfile, group, "ColumnsOpeWidth", NULL) )
790 {
791 gint *src;
792 gsize length;
793
794 src = g_key_file_get_integer_list(keyfile, group, "ColumnsOpeWidth", &length, NULL);
795
796 DB( g_print(" - length %d (max=%d)\n", length, NUM_LST_DSPOPE) );
797
798 if( length == NUM_LST_DSPOPE )
799 {
800 DB( g_print(" - copying column width from pref file\n") );
801 memcpy(PREFS->lst_ope_col_width, src, length*sizeof(gint));
802 }
803
804 //leak
805 g_free(src);
806
807 }
808
809 homebank_pref_get_integer(keyfile, group, "OpeSortId", &PREFS->lst_ope_sort_id);
810 homebank_pref_get_integer(keyfile, group, "OpeSortOrder", &PREFS->lst_ope_sort_order);
811
812 DB( g_print(" - set sort to %d %d\n", PREFS->lst_ope_sort_id, PREFS->lst_ope_sort_order) );
813
814 homebank_pref_get_short(keyfile, group, "FiscYearDay", &PREFS->fisc_year_day);
815 homebank_pref_get_short(keyfile, group, "FiscYearMonth", &PREFS->fisc_year_month);
816
817
818 group = "Windows";
819
820 DB( g_print(" -> ** Windows\n") );
821
822 homebank_pref_get_wingeometry(keyfile, group, "Wal", &PREFS->wal_wg);
823 homebank_pref_get_wingeometry(keyfile, group, "Acc", &PREFS->acc_wg);
824 homebank_pref_get_wingeometry(keyfile, group, "Sta", &PREFS->sta_wg);
825 homebank_pref_get_wingeometry(keyfile, group, "Tme", &PREFS->tme_wg);
826 homebank_pref_get_wingeometry(keyfile, group, "Ove", &PREFS->ove_wg);
827 homebank_pref_get_wingeometry(keyfile, group, "Bud", &PREFS->bud_wg);
828 homebank_pref_get_wingeometry(keyfile, group, "Car", &PREFS->cst_wg);
829
830 homebank_pref_get_wingeometry(keyfile, group, "Txn", &PREFS->txn_wg);
831
832 if(version <= 7) //set maximize to 0
833 {
834 PREFS->wal_wg.s = 0;
835 PREFS->acc_wg.s = 0;
836 PREFS->txn_wg.s = 0;
837 PREFS->sta_wg.s = 0;
838 PREFS->tme_wg.s = 0;
839 PREFS->ove_wg.s = 0;
840 PREFS->bud_wg.s = 0;
841 PREFS->cst_wg.s = 0;
842 }
843 homebank_pref_get_integer(keyfile, group, "WalVPaned", &PREFS->wal_vpaned);
844 homebank_pref_get_integer(keyfile, group, "WalHPaned", &PREFS->wal_hpaned);
845 homebank_pref_get_boolean(keyfile, group, "WalToolbar", &PREFS->wal_toolbar);
846 homebank_pref_get_boolean(keyfile, group, "WalSpending", &PREFS->wal_spending);
847 homebank_pref_get_boolean(keyfile, group, "WalUpcoming", &PREFS->wal_upcoming);
848
849 //since 5.1.3
850 group = "Panels";
851
852 DB( g_print(" -> ** Panels\n") );
853
854 homebank_pref_get_short(keyfile, group, "AccColAccW", &PREFS->pnl_acc_col_acc_width);
855 homebank_pref_get_short(keyfile, group, "AccShowBy" , &PREFS->pnl_acc_show_by);
856
857 homebank_pref_get_short(keyfile, group, "UpcColPayW", &PREFS->pnl_upc_col_pay_width);
858 homebank_pref_get_short(keyfile, group, "UpcColMemW", &PREFS->pnl_upc_col_mem_width);
859
860 homebank_pref_get_string(keyfile, group, "PnlLstTab", &PREFS->pnl_list_tab);
861
862 group = "Format";
863
864 DB( g_print(" -> ** Format\n") );
865
866 homebank_pref_get_string(keyfile, group, "DateFmt", &PREFS->date_format);
867
868 if(version < 460)
869 {
870 gboolean useimperial;
871
872 homebank_pref_get_boolean(keyfile, group, "UKUnits", &useimperial);
873 if(useimperial)
874 {
875 PREFS->vehicle_unit_ismile = TRUE;
876 PREFS->vehicle_unit_isgal = TRUE;
877 }
878 }
879
880 homebank_pref_get_boolean(keyfile, group, "UnitIsMile", &PREFS->vehicle_unit_ismile);
881 homebank_pref_get_boolean(keyfile, group, "UnitIsGal", &PREFS->vehicle_unit_isgal);
882
883
884 group = "Filter";
885
886 DB( g_print(" -> ** Filter\n") );
887
888 homebank_pref_get_integer(keyfile, group, "DateRangeWal", &PREFS->date_range_wal);
889 homebank_pref_get_integer(keyfile, group, "DateRangeTxn", &PREFS->date_range_txn);
890 homebank_pref_get_integer(keyfile, group, "DateFutureNbDays", &PREFS->date_future_nbdays);
891 homebank_pref_get_integer(keyfile, group, "DateRangeRep", &PREFS->date_range_rep);
892
893 if(version <= 7)
894 {
895 // shift date range >= 5, since we inserted a new one at position 5
896 if(PREFS->date_range_wal >= FLT_RANGE_LASTYEAR)
897 PREFS->date_range_wal++;
898 if(PREFS->date_range_txn >= FLT_RANGE_LASTYEAR)
899 PREFS->date_range_txn++;
900 if(PREFS->date_range_rep >= FLT_RANGE_LASTYEAR)
901 PREFS->date_range_rep++;
902 }
903
904
905 group = "Euro";
906
907 DB( g_print(" -> ** Euro\n") );
908
909 //homebank_pref_get_string(keyfile, group, "DefCurrency" , &PREFS->curr_default);
910
911 homebank_pref_get_boolean(keyfile, group, "Active", &PREFS->euro_active);
912 homebank_pref_get_integer(keyfile, group, "Country", &PREFS->euro_country);
913
914 gchar *ratestr = g_key_file_get_string (keyfile, group, "ChangeRate", NULL);
915 if(ratestr != NULL) PREFS->euro_value = g_ascii_strtod(ratestr, NULL);
916
917 if(version <= 1)
918 {
919 homebank_pref_get_string(keyfile, group, "Symbol", &PREFS->minor_cur.symbol);
920 PREFS->minor_cur.frac_digits = g_key_file_get_integer (keyfile, group, "NBDec", NULL);
921
922 //PREFS->euro_nbdec = g_key_file_get_integer (keyfile, group, "NBDec", NULL);
923 //PREFS->euro_thsep = g_key_file_get_boolean (keyfile, group, "Sep", NULL);
924 //gchar *tmpstr = g_key_file_get_string (keyfile, group, "Symbol", &error);
925 }
926 else
927 {
928 if(version < 460)
929 {
930 gchar *prefix = NULL;
931 gchar *suffix = NULL;
932
933 homebank_pref_get_string(keyfile, group, "PreSymbol", &prefix);
934 homebank_pref_get_string(keyfile, group, "SufSymbol", &suffix);
935 homebank_pref_currfmt_convert(&PREFS->minor_cur, prefix, suffix);
936 g_free(prefix);
937 g_free(suffix);
938 }
939 else
940 {
941 homebank_pref_get_string(keyfile, group, "Symbol", &PREFS->minor_cur.symbol);
942 homebank_pref_get_boolean(keyfile, group, "IsPrefix", &PREFS->minor_cur.sym_prefix);
943 }
944 homebank_pref_get_string(keyfile, group, "DecChar" , &PREFS->minor_cur.decimal_char);
945 homebank_pref_get_string(keyfile, group, "GroupChar", &PREFS->minor_cur.grouping_char);
946 homebank_pref_get_short(keyfile, group, "FracDigits", &PREFS->minor_cur.frac_digits);
947
948 //fix 378992/421228
949 if( PREFS->minor_cur.frac_digits > MAX_FRAC_DIGIT )
950 PREFS->minor_cur.frac_digits = MAX_FRAC_DIGIT;
951
952 da_cur_initformat(&PREFS->minor_cur);
953 }
954
955 //PREFS->euro_symbol = g_locale_to_utf8(tmpstr, -1, NULL, NULL, NULL);
956
957 group = "Report";
958
959 DB( g_print(" -> ** Report\n") );
960
961 homebank_pref_get_boolean(keyfile, group, "StatByAmount", &PREFS->stat_byamount);
962 homebank_pref_get_boolean(keyfile, group, "StatDetail", &PREFS->stat_showdetail);
963 homebank_pref_get_boolean(keyfile, group, "StatRate", &PREFS->stat_showrate);
964 homebank_pref_get_boolean(keyfile, group, "BudgDetail", &PREFS->budg_showdetail);
965 homebank_pref_get_integer(keyfile, group, "ColorScheme", &PREFS->report_color_scheme);
966
967 group = "Exchange";
968
969 DB( g_print(" -> ** Exchange\n") );
970
971 homebank_pref_get_boolean(keyfile, group, "DoIntro", &PREFS->dtex_nointro);
972 homebank_pref_get_boolean(keyfile, group, "UcFirst", &PREFS->dtex_ucfirst);
973 homebank_pref_get_integer(keyfile, group, "DateFmt", &PREFS->dtex_datefmt);
974 homebank_pref_get_integer(keyfile, group, "OfxName", &PREFS->dtex_ofxname);
975 homebank_pref_get_integer(keyfile, group, "OfxMemo", &PREFS->dtex_ofxmemo);
976 homebank_pref_get_boolean(keyfile, group, "QifMemo", &PREFS->dtex_qifmemo);
977 homebank_pref_get_boolean(keyfile, group, "QifSwap", &PREFS->dtex_qifswap);
978
979
980 //group = "Chart";
981 //PREFS->chart_legend = g_key_file_get_boolean (keyfile, group, "Legend", NULL);
982
983
984 /*
985 #if MYDEBUG == 1
986 gsize length;
987 gchar *contents = g_key_file_to_data (keyfile, &length, NULL);
988 //g_print(" keyfile:\n%s\n len=%d\n", contents, length);
989 g_free(contents);
990 #endif
991 */
992
993 }
994 g_free(filename);
995 g_key_file_free (keyfile);
996
997 _homebank_pref_init_measurement_units();
998 }
999
1000 return retval;
1001 }
1002
1003
1004 static void homebank_pref_set_string(
1005 GKeyFile *key_file,
1006 const gchar *group_name,
1007 const gchar *key,
1008 gchar *string)
1009 {
1010
1011 DB( g_print(" - homebank_pref_set_string :: group='%s' key='%s' value='%s'\n", group_name, key, string) );
1012
1013 if( string != NULL && *string != '\0')
1014 g_key_file_set_string (key_file, group_name, key, string);
1015 else
1016 g_key_file_set_string (key_file, group_name, key, "");
1017
1018 }
1019
1020
1021 /*
1022 ** save preference to homedir/.homebank (HB_DATA_PATH)
1023 */
1024 gboolean homebank_pref_save(void)
1025 {
1026 GKeyFile *keyfile;
1027 gboolean retval = FALSE;
1028 gchar *group, *filename;
1029 gsize length;
1030 GError *error = NULL;
1031
1032 DB( g_print("\n[preferences] pref save\n") );
1033
1034 keyfile = g_key_file_new();
1035 if(keyfile )
1036 {
1037
1038 DB( g_print(" -> ** general\n") );
1039
1040
1041 group = "General";
1042 g_key_file_set_integer (keyfile, group, "Version", PREF_VERSION);
1043
1044 homebank_pref_set_string (keyfile, group, "Language", PREFS->language);
1045
1046 g_key_file_set_integer (keyfile, group, "BarStyle", PREFS->toolbar_style);
1047 //g_key_file_set_integer (keyfile, group, "BarImageSize", PREFS->image_size);
1048
1049
1050
1051 g_key_file_set_boolean (keyfile, group, "CustomColors", PREFS->custom_colors);
1052 g_key_file_set_string (keyfile, group, "ColorExp" , PREFS->color_exp);
1053 g_key_file_set_string (keyfile, group, "ColorInc" , PREFS->color_inc);
1054 g_key_file_set_string (keyfile, group, "ColorWarn", PREFS->color_warn);
1055
1056 g_key_file_set_integer (keyfile, group, "GridLines", PREFS->grid_lines);
1057
1058 homebank_pref_set_string (keyfile, group, "WalletPath" , PREFS->path_hbfile);
1059 homebank_pref_set_string (keyfile, group, "ImportPath" , PREFS->path_import);
1060 homebank_pref_set_string (keyfile, group, "ExportPath" , PREFS->path_export);
1061 //g_key_file_set_string (keyfile, group, "NavigatorPath", PREFS->path_navigator);
1062
1063 g_key_file_set_boolean (keyfile, group, "BakIsAutomatic", PREFS->bak_is_automatic);
1064 g_key_file_set_integer (keyfile, group, "BakMaxNumCopies", PREFS->bak_max_num_copies);
1065
1066 g_key_file_set_boolean (keyfile, group, "ShowSplash", PREFS->showsplash);
1067 g_key_file_set_boolean (keyfile, group, "LoadLast", PREFS->loadlast);
1068 g_key_file_set_boolean (keyfile, group, "AppendScheduled", PREFS->appendscheduled);
1069 g_key_file_set_boolean (keyfile, group, "UpdateCurrency", PREFS->do_update_currency);
1070
1071 g_key_file_set_boolean (keyfile, group, "HeritDate", PREFS->heritdate);
1072 g_key_file_set_boolean (keyfile, group, "HideReconciled", PREFS->hidereconciled);
1073 g_key_file_set_boolean (keyfile, group, "ShowRemind", PREFS->showremind);
1074 g_key_file_set_boolean (keyfile, group, "TxnMemoAcp", PREFS->txn_memoacp);
1075 g_key_file_set_integer (keyfile, group, "TxnMemoAcpDays" , PREFS->txn_memoacp_days);
1076
1077 g_key_file_set_integer_list(keyfile, group, "ColumnsOpe", PREFS->lst_ope_columns, NUM_LST_DSPOPE);
1078 g_key_file_set_integer_list(keyfile, group, "ColumnsOpeWidth", PREFS->lst_ope_col_width, NUM_LST_DSPOPE);
1079 g_key_file_set_integer (keyfile, group, "OpeSortId" , PREFS->lst_ope_sort_id);
1080 g_key_file_set_integer (keyfile, group, "OpeSortOrder" , PREFS->lst_ope_sort_order);
1081
1082 g_key_file_set_integer (keyfile, group, "FiscYearDay" , PREFS->fisc_year_day);
1083 g_key_file_set_integer (keyfile, group, "FiscYearMonth" , PREFS->fisc_year_month);
1084
1085 // added v3.4
1086 DB( g_print(" -> ** windows\n") );
1087
1088 group = "Windows";
1089 g_key_file_set_integer_list(keyfile, group, "Wal", (gint *)&PREFS->wal_wg, 5);
1090 g_key_file_set_integer_list(keyfile, group, "Acc", (gint *)&PREFS->acc_wg, 5);
1091 g_key_file_set_integer_list(keyfile, group, "Sta", (gint *)&PREFS->sta_wg, 5);
1092 g_key_file_set_integer_list(keyfile, group, "Tme", (gint *)&PREFS->tme_wg, 5);
1093 g_key_file_set_integer_list(keyfile, group, "Ove", (gint *)&PREFS->ove_wg, 5);
1094 g_key_file_set_integer_list(keyfile, group, "Bud", (gint *)&PREFS->bud_wg, 5);
1095 g_key_file_set_integer_list(keyfile, group, "Car", (gint *)&PREFS->cst_wg, 5);
1096
1097 g_key_file_set_integer_list(keyfile, group, "Txn", (gint *)&PREFS->txn_wg, 5);
1098
1099 g_key_file_set_integer (keyfile, group, "WalVPaned" , PREFS->wal_vpaned);
1100 g_key_file_set_integer (keyfile, group, "WalHPaned" , PREFS->wal_hpaned);
1101 g_key_file_set_boolean (keyfile, group, "WalToolbar", PREFS->wal_toolbar);
1102 g_key_file_set_boolean (keyfile, group, "WalSpending", PREFS->wal_spending);
1103 g_key_file_set_boolean (keyfile, group, "WalUpcoming", PREFS->wal_upcoming);
1104
1105 //since 5.1.3
1106 DB( g_print(" -> ** Panels\n") );
1107
1108 group = "Panels";
1109 g_key_file_set_integer(keyfile, group, "AccColAccW", PREFS->pnl_acc_col_acc_width);
1110 g_key_file_set_integer(keyfile, group, "AccShowBy" , PREFS->pnl_acc_show_by);
1111
1112 g_key_file_set_integer(keyfile, group, "UpcColPayW", PREFS->pnl_upc_col_pay_width);
1113 g_key_file_set_integer(keyfile, group, "UpcColMemW", PREFS->pnl_upc_col_mem_width);
1114
1115 homebank_pref_set_string (keyfile, group, "PnlLstTab", PREFS->pnl_list_tab);
1116
1117 DB( g_print(" -> ** format\n") );
1118
1119 group = "Format";
1120 homebank_pref_set_string (keyfile, group, "DateFmt" , PREFS->date_format);
1121
1122 //g_key_file_set_boolean (keyfile, group, "UKUnits" , PREFS->imperial_unit);
1123 g_key_file_set_boolean (keyfile, group, "UnitIsMile" , PREFS->vehicle_unit_ismile);
1124 g_key_file_set_boolean (keyfile, group, "UnitIsGal" , PREFS->vehicle_unit_isgal);
1125
1126
1127 DB( g_print(" -> ** filter\n") );
1128
1129 group = "Filter";
1130 g_key_file_set_integer (keyfile, group, "DateRangeWal", PREFS->date_range_wal);
1131 g_key_file_set_integer (keyfile, group, "DateRangeTxn", PREFS->date_range_txn);
1132 g_key_file_set_integer (keyfile, group, "DateFutureNbDays", PREFS->date_future_nbdays);
1133 g_key_file_set_integer (keyfile, group, "DateRangeRep", PREFS->date_range_rep);
1134
1135 DB( g_print(" -> ** euro\n") );
1136
1137 //euro options
1138 group = "Euro";
1139
1140 //homebank_pref_set_string(keyfile, group, "DefCurrency" , PREFS->curr_default);
1141
1142 g_key_file_set_boolean (keyfile, group, "Active" , PREFS->euro_active);
1143 if( PREFS->euro_active )
1144 {
1145 g_key_file_set_integer (keyfile, group, "Country", PREFS->euro_country);
1146 gchar ratestr[64];
1147 g_ascii_dtostr(ratestr, 63, PREFS->euro_value);
1148 homebank_pref_set_string (keyfile, group, "ChangeRate", ratestr);
1149 homebank_pref_set_string (keyfile, group, "Symbol" , PREFS->minor_cur.symbol);
1150 g_key_file_set_boolean (keyfile, group, "IsPrefix" , PREFS->minor_cur.sym_prefix);
1151 homebank_pref_set_string (keyfile, group, "DecChar" , PREFS->minor_cur.decimal_char);
1152 homebank_pref_set_string (keyfile, group, "GroupChar" , PREFS->minor_cur.grouping_char);
1153 g_key_file_set_integer (keyfile, group, "FracDigits", PREFS->minor_cur.frac_digits);
1154 }
1155
1156 //report options
1157 DB( g_print(" -> ** report\n") );
1158
1159 group = "Report";
1160 g_key_file_set_boolean (keyfile, group, "StatByAmount", PREFS->stat_byamount);
1161 g_key_file_set_boolean (keyfile, group, "StatDetail" , PREFS->stat_showdetail);
1162 g_key_file_set_boolean (keyfile, group, "StatRate" , PREFS->stat_showrate);
1163 g_key_file_set_boolean (keyfile, group, "BudgDetail" , PREFS->budg_showdetail);
1164 g_key_file_set_integer (keyfile, group, "ColorScheme" , PREFS->report_color_scheme);
1165
1166
1167 group = "Exchange";
1168 g_key_file_set_boolean (keyfile, group, "DoIntro", PREFS->dtex_nointro);
1169 g_key_file_set_boolean (keyfile, group, "UcFirst", PREFS->dtex_ucfirst);
1170 g_key_file_set_integer (keyfile, group, "DateFmt", PREFS->dtex_datefmt);
1171 g_key_file_set_integer (keyfile, group, "OfxName", PREFS->dtex_ofxname);
1172 g_key_file_set_integer (keyfile, group, "OfxMemo", PREFS->dtex_ofxmemo);
1173 g_key_file_set_boolean (keyfile, group, "QifMemo", PREFS->dtex_qifmemo);
1174 g_key_file_set_boolean (keyfile, group, "QifSwap", PREFS->dtex_qifswap);
1175
1176
1177 //group = "Chart";
1178 //g_key_file_set_boolean (keyfile, group, "Legend", PREFS->chart_legend);
1179
1180 //g_key_file_set_string (keyfile, group, "", PREFS->);
1181 //g_key_file_set_boolean (keyfile, group, "", PREFS->);
1182 //g_key_file_set_integer (keyfile, group, "", PREFS->);
1183
1184 DB( g_print(" -> ** g_key_file_to_data\n") );
1185
1186 gchar *contents = g_key_file_to_data (keyfile, &length, NULL);
1187
1188 //DB( g_print(" keyfile:\n%s\nlen=%d\n", contents, length) );
1189
1190 filename = g_build_filename(homebank_app_get_config_dir(), "preferences", NULL );
1191
1192 DB( g_print(" -> filename: %s\n", filename) );
1193
1194 g_file_set_contents(filename, contents, length, &error);
1195 if( error )
1196 {
1197 g_warning("unable to save file %s: %s", filename, error->message);
1198 g_error_free (error);
1199 error = NULL;
1200 }
1201
1202 DB( g_print(" -> contents: %s\n", contents) );
1203
1204 DB( g_print(" -> freeing filename\n") );
1205 g_free(filename);
1206
1207 DB( g_print(" -> freeing buffer\n") );
1208
1209 g_free(contents);
1210
1211 DB( g_print(" -> freeing keyfile\n") );
1212
1213 g_key_file_free (keyfile);
1214 }
1215
1216 _homebank_pref_init_measurement_units();
1217
1218 return retval;
1219 }
1220
This page took 0.089209 seconds and 4 git commands to generate.