]> Dogcows Code - chaz/homebank/blob - src/hb-preferences.c
Merge branch 'master' into ext-perl
[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 g_strfreev(PREFS->ext_path);
299 g_list_free_full(PREFS->ext_whitelist, g_free);
300
301 memset(PREFS, 0, sizeof(struct Preferences));
302 }
303
304
305 void homebank_pref_setdefault(void)
306 {
307 gint i;
308
309 DB( g_print("\n[preferences] pref init\n") );
310
311 homebank_pref_free();
312
313 PREFS->language = NULL;
314
315 PREFS->date_format = g_strdup(DEFAULT_FORMAT_DATE);
316
317 PREFS->path_hbfile = g_strdup_printf("%s", g_get_home_dir ());
318 PREFS->path_import = g_strdup_printf("%s", g_get_home_dir ());
319 PREFS->path_export = g_strdup_printf("%s", g_get_home_dir ());
320 //PREFS->path_navigator = g_strdup(DEFAULT_PATH_NAVIGATOR);
321
322 PREFS->showsplash = TRUE;
323 PREFS->loadlast = TRUE;
324 PREFS->appendscheduled = FALSE;
325 PREFS->do_update_currency = FALSE;
326
327 PREFS->bak_is_automatic = TRUE;
328 PREFS->bak_max_num_copies = 5;
329
330 PREFS->heritdate = FALSE;
331 PREFS->hidereconciled = FALSE;
332 PREFS->showremind = TRUE;
333 //#1673048
334 PREFS->txn_memoacp = TRUE;
335 PREFS->txn_memoacp_days = 365;
336
337 PREFS->toolbar_style = 4; //text beside icons
338 PREFS->custom_colors = TRUE;
339 PREFS->color_exp = g_strdup(DEFAULT_EXP_COLOR);
340 PREFS->color_inc = g_strdup(DEFAULT_INC_COLOR);
341 PREFS->color_warn = g_strdup(DEFAULT_WARN_COLOR);
342 PREFS->grid_lines = GTK_TREE_VIEW_GRID_LINES_NONE;
343
344 /* fiscal year */
345 PREFS->fisc_year_day = 1;
346 PREFS->fisc_year_month = 1;
347
348 /* windows position/size */
349 homebank_pref_init_wingeometry(&PREFS->wal_wg, 0, 0, 1024, 600);
350 homebank_pref_init_wingeometry(&PREFS->acc_wg, 0, 0, 1024, 600);
351 homebank_pref_init_wingeometry(&PREFS->sta_wg, 0, 0, 800, 494);
352 homebank_pref_init_wingeometry(&PREFS->tme_wg, 0, 0, 800, 494);
353 homebank_pref_init_wingeometry(&PREFS->ove_wg, 0, 0, 800, 494);
354 homebank_pref_init_wingeometry(&PREFS->bud_wg, 0, 0, 800, 494);
355 homebank_pref_init_wingeometry(&PREFS->cst_wg, 0, 0, 800, 494);
356
357 homebank_pref_init_wingeometry(&PREFS->txn_wg, 0, 0, -1, -1);
358
359 homebank_pref_init_monetary();
360
361 PREFS->wal_toolbar = TRUE;
362 PREFS->wal_spending = TRUE;
363 PREFS->wal_upcoming = TRUE;
364 PREFS->wal_vpaned = 600/2;
365 PREFS->wal_hpaned = 1024/2;
366
367 PREFS->pnl_acc_col_acc_width = -1;
368 PREFS->pnl_acc_show_by = 0;
369 PREFS->pnl_upc_col_pay_width = -1;
370 PREFS->pnl_upc_col_mem_width = -1;
371
372 i = 0;
373 PREFS->lst_impope_columns[i++] = LST_DSPOPE_DATE; //always displayed
374 PREFS->lst_impope_columns[i++] = LST_DSPOPE_MEMO;
375 PREFS->lst_impope_columns[i++] = LST_DSPOPE_AMOUNT;
376 PREFS->lst_impope_columns[i++] = LST_DSPOPE_INFO;
377 PREFS->lst_impope_columns[i++] = LST_DSPOPE_PAYEE;
378 PREFS->lst_impope_columns[i++] = LST_DSPOPE_CATEGORY;
379 PREFS->lst_impope_columns[i++] = -LST_DSPOPE_TAGS;
380 PREFS->lst_impope_columns[i++] = -LST_DSPOPE_CLR;
381 PREFS->lst_impope_columns[i++] = -LST_DSPOPE_STATUS; //always displayed
382 PREFS->lst_impope_columns[i++] = -LST_DSPOPE_EXPENSE;
383 PREFS->lst_impope_columns[i++] = -LST_DSPOPE_INCOME;
384 PREFS->lst_impope_columns[i++] = -LST_DSPOPE_BALANCE;
385 PREFS->lst_impope_columns[i++] = -LST_DSPOPE_ACCOUNT;
386
387 i = 0;
388 PREFS->lst_ope_columns[i++] = LST_DSPOPE_STATUS; //always displayed
389 PREFS->lst_ope_columns[i++] = LST_DSPOPE_DATE; //always displayed
390 PREFS->lst_ope_columns[i++] = LST_DSPOPE_INFO;
391 PREFS->lst_ope_columns[i++] = LST_DSPOPE_PAYEE;
392 PREFS->lst_ope_columns[i++] = LST_DSPOPE_CATEGORY;
393 PREFS->lst_ope_columns[i++] = LST_DSPOPE_TAGS;
394 PREFS->lst_ope_columns[i++] = LST_DSPOPE_CLR;
395 PREFS->lst_ope_columns[i++] = -LST_DSPOPE_AMOUNT;
396 PREFS->lst_ope_columns[i++] = LST_DSPOPE_EXPENSE;
397 PREFS->lst_ope_columns[i++] = LST_DSPOPE_INCOME;
398 PREFS->lst_ope_columns[i++] = LST_DSPOPE_BALANCE;
399 PREFS->lst_ope_columns[i++] = LST_DSPOPE_MEMO;
400 PREFS->lst_ope_columns[i++] = -LST_DSPOPE_ACCOUNT;
401
402 PREFS->lst_ope_sort_id = LST_DSPOPE_DATE;
403 PREFS->lst_ope_sort_order = GTK_SORT_ASCENDING;
404
405 for( i=0;i<NUM_LST_DSPOPE;i++)
406 PREFS->lst_ope_col_width[i] = -1;
407
408 //PREFS->base_cur.nbdecimal = 2;
409 //PREFS->base_cur.separator = TRUE;
410
411 //PREFS->date_range_wal = FLT_RANGE_LASTMONTH;
412 //PREFS->date_range_txn = FLT_RANGE_LAST12MONTHS;
413 //PREFS->date_range_rep = FLT_RANGE_THISYEAR;
414
415 //v5.2 change to let the example file show things
416 PREFS->date_range_wal = FLT_RANGE_ALLDATE;
417 PREFS->date_range_txn = FLT_RANGE_ALLDATE;
418 PREFS->date_range_rep = FLT_RANGE_ALLDATE;
419 PREFS->date_future_nbdays = 0;
420
421 //import/export
422 PREFS->dtex_nointro = TRUE;
423 PREFS->dtex_ucfirst = FALSE;
424 //PREFS->dtex_datefmt
425 PREFS->dtex_ofxname = 1;
426 PREFS->dtex_ofxmemo = 2;
427 PREFS->dtex_qifmemo = TRUE;
428 PREFS->dtex_qifswap = FALSE;
429
430 //todo: add intelligence here
431 PREFS->euro_active = FALSE;
432
433 PREFS->euro_country = 0;
434 PREFS->euro_value = 1.0;
435
436 da_cur_initformat(&PREFS->minor_cur);
437
438 //PREFS->euro_nbdec = 2;
439 //PREFS->euro_thsep = TRUE;
440 //PREFS->euro_symbol = g_strdup("??");
441
442 PREFS->stat_byamount = FALSE;
443 PREFS->stat_showdetail = FALSE;
444 PREFS->stat_showrate = FALSE;
445 PREFS->budg_showdetail = FALSE;
446 PREFS->report_color_scheme = CHART_COLMAP_HOMEBANK;
447
448 //PREFS->chart_legend = FALSE;
449
450 PREFS->vehicle_unit_ismile = FALSE;
451 PREFS->vehicle_unit_isgal = FALSE;
452
453 gchar** plugin_path = g_new0(gchar*, 4);
454 i = 0;
455 const gchar* env = g_getenv("HOMEBANK_PLUGINS");
456 if (env) {
457 if (g_path_is_absolute(env)) {
458 plugin_path[i++] = g_strdup(env);
459 } else {
460 gchar* cur = g_get_current_dir();
461 plugin_path[i++] = g_build_filename(cur, env, NULL);
462 g_free(cur);
463 }
464 }
465 plugin_path[i++] = g_build_filename(homebank_app_get_config_dir(), "plugins", NULL);
466 plugin_path[i++] = g_build_filename(homebank_app_get_pkglib_dir(), "plugins", NULL);
467 PREFS->ext_path = plugin_path;
468 PREFS->ext_whitelist = NULL;
469
470 _homebank_pref_init_measurement_units();
471
472 }
473
474
475 /*
476 ** load preference from homedir/.homebank (HB_DATA_PATH)
477 */
478 static void homebank_pref_get_wingeometry(
479 GKeyFile *key_file,
480 const gchar *group_name,
481 const gchar *key,
482 struct WinGeometry *storage)
483 {
484 if( g_key_file_has_key(key_file, group_name, key, NULL) )
485 {
486 gint *wg;
487 gsize length;
488
489 wg = g_key_file_get_integer_list(key_file, group_name, key, &length, NULL);
490 memcpy(storage, wg, 5*sizeof(gint));
491 g_free(wg);
492 // #606613 ensure left/top to be > 0
493 if(storage->l < 0)
494 storage->l = 0;
495
496 if(storage->t < 0)
497 storage->t = 0;
498 }
499 }
500
501
502
503
504 static void homebank_pref_get_boolean(
505 GKeyFile *key_file,
506 const gchar *group_name,
507 const gchar *key,
508 gboolean *storage)
509 {
510 DB( g_print(" search %s in %s\n", key, group_name) );
511
512 if( g_key_file_has_key(key_file, group_name, key, NULL) )
513 {
514 *storage = g_key_file_get_boolean(key_file, group_name, key, NULL);
515 DB( g_print(" stored boolean %d for %s at %x\n", *storage, key, *storage) );
516 }
517 }
518
519 static void homebank_pref_get_integer(
520 GKeyFile *key_file,
521 const gchar *group_name,
522 const gchar *key,
523 gint *storage)
524 {
525 DB( g_print(" search %s in %s\n", key, group_name) );
526
527 if( g_key_file_has_key(key_file, group_name, key, NULL) )
528 {
529 *storage = g_key_file_get_integer(key_file, group_name, key, NULL);
530 DB( g_print(" stored integer %d for %s at %x\n", *storage, key, *storage) );
531 }
532 }
533
534 static void homebank_pref_get_guint32(
535 GKeyFile *key_file,
536 const gchar *group_name,
537 const gchar *key,
538 guint32 *storage)
539 {
540 DB( g_print(" search %s in %s\n", key, group_name) );
541
542 if( g_key_file_has_key(key_file, group_name, key, NULL) )
543 {
544 *storage = g_key_file_get_integer(key_file, group_name, key, NULL);
545 DB( g_print(" stored guint32 %d for %s at %x\n", *storage, key, *storage) );
546 }
547 }
548
549 static void homebank_pref_get_short(
550 GKeyFile *key_file,
551 const gchar *group_name,
552 const gchar *key,
553 gshort *storage)
554 {
555 DB( g_print(" search %s in %s\n", key, group_name) );
556
557 if( g_key_file_has_key(key_file, group_name, key, NULL) )
558 {
559 *storage = (gshort)g_key_file_get_integer(key_file, group_name, key, NULL);
560 DB( g_print(" stored short %d for %s at %x\n", *storage, key, *storage) );
561 }
562 }
563
564 static void homebank_pref_get_string(
565 GKeyFile *key_file,
566 const gchar *group_name,
567 const gchar *key,
568 gchar **storage)
569 {
570 gchar *string;
571
572 if( g_key_file_has_key(key_file, group_name, key, NULL) )
573 {
574 /* free any previous string */
575 if( *storage != NULL )
576 {
577 //DB( g_print(" storage was not null, freeing\n") );
578
579 g_free(*storage);
580 }
581
582 *storage = NULL;
583
584 string = g_key_file_get_string(key_file, group_name, key, NULL);
585 if( string != NULL )
586 {
587 //*storage = g_strdup(string);
588 //leak
589 *storage = string; //already a new allocated string
590
591 //DB( g_print(" store '%s' for %s at %x\n", string, key, *storage) );
592 }
593 }
594
595 /*
596 if (error)
597 {
598 g_warning ("error: %s\n", error->message);
599 g_error_free(error);
600 error = NULL;
601 }
602 */
603
604
605 }
606
607
608 static void homebank_pref_currfmt_convert(Currency *cur, gchar *prefix, gchar *suffix)
609 {
610
611 if( (prefix != NULL) && (strlen(prefix) > 0) )
612 {
613 cur->symbol = g_strdup(prefix);
614 cur->sym_prefix = TRUE;
615 }
616 else if( (suffix != NULL) )
617 {
618 cur->symbol = g_strdup(suffix);
619 cur->sym_prefix = FALSE;
620 }
621 }
622
623
624 gboolean homebank_pref_load(void)
625 {
626 GKeyFile *keyfile;
627 gboolean retval = FALSE;
628 gchar *group, *filename;
629 guint32 version;
630 gboolean loaded;
631 GError *error = NULL;
632
633 DB( g_print("\n[preferences] pref load\n") );
634
635 keyfile = g_key_file_new();
636 if(keyfile)
637 {
638 filename = g_build_filename(homebank_app_get_config_dir(), "preferences", NULL );
639
640 DB( g_print(" - filename: %s\n", filename) );
641
642 error = NULL;
643 loaded = g_key_file_load_from_file (keyfile, filename, G_KEY_FILE_NONE, &error);
644 if( error )
645 {
646 g_warning("unable to load file %s: %s", filename, error->message);
647 g_error_free (error);
648 }
649
650 if( loaded == TRUE )
651 {
652
653 group = "General";
654
655 DB( g_print(" -> ** General\n") );
656
657 //since 4.51 version is integer
658 homebank_pref_get_guint32 (keyfile, group, "Version", &version);
659 if(version == 0) // old double number
660 {
661 gdouble v = g_key_file_get_double (keyfile, group, "Version", NULL);
662 version = (guint32)(v * 10);
663 }
664
665 DB( g_print(" - version: %d\n", version) );
666
667 homebank_pref_get_string(keyfile, group, "Language", &PREFS->language);
668
669 homebank_pref_get_short(keyfile, group, "BarStyle" , &PREFS->toolbar_style);
670
671 if(version <= 6 && PREFS->toolbar_style == 0) // force system to text beside
672 {
673 PREFS->toolbar_style = 4;
674 }
675
676 if(version <= 2) // retrieve old settings
677 {
678 guint32 color;
679
680 homebank_pref_get_guint32(keyfile, group, "ColorExp" , &color);
681 g_free(PREFS->color_exp);
682 PREFS->color_exp = g_strdup_printf("#%06x", color);
683
684 homebank_pref_get_guint32(keyfile, group, "ColorInc" , &color);
685 g_free(PREFS->color_inc);
686 PREFS->color_inc = g_strdup_printf("#%06x", color);
687
688 homebank_pref_get_guint32(keyfile, group, "ColorWarn", &color);
689 g_free(PREFS->color_warn);
690 PREFS->color_warn = g_strdup_printf("#%06x", color);
691 }
692 else
693 {
694 homebank_pref_get_boolean(keyfile, group, "CustomColors", &PREFS->custom_colors);
695
696 homebank_pref_get_string(keyfile, group, "ColorExp" , &PREFS->color_exp);
697 homebank_pref_get_string(keyfile, group, "ColorInc" , &PREFS->color_inc);
698 homebank_pref_get_string(keyfile, group, "ColorWarn", &PREFS->color_warn);
699
700 if( version <= 500 )
701 {
702 gboolean rules_hint;
703 homebank_pref_get_boolean(keyfile, group, "RulesHint", &rules_hint);
704 if( rules_hint == TRUE )
705 PREFS->grid_lines = GTK_TREE_VIEW_GRID_LINES_HORIZONTAL;
706
707 }
708 else
709 homebank_pref_get_short(keyfile, group, "GridLines", &PREFS->grid_lines);
710 }
711
712 DB( g_print(" - color exp: %s\n", PREFS->color_exp) );
713 DB( g_print(" - color inc: %s\n", PREFS->color_inc) );
714 DB( g_print(" - color wrn: %s\n", PREFS->color_warn) );
715
716
717 homebank_pref_get_string(keyfile, group, "WalletPath", &PREFS->path_hbfile);
718 homebank_pref_get_string(keyfile, group, "ImportPath", &PREFS->path_import);
719 homebank_pref_get_string(keyfile, group, "ExportPath", &PREFS->path_export);
720
721 homebank_pref_get_boolean(keyfile, group, "ShowSplash", &PREFS->showsplash);
722 homebank_pref_get_boolean(keyfile, group, "LoadLast", &PREFS->loadlast);
723 homebank_pref_get_boolean(keyfile, group, "AppendScheduled", &PREFS->appendscheduled);
724 homebank_pref_get_boolean(keyfile, group, "UpdateCurrency", &PREFS->do_update_currency);
725
726 homebank_pref_get_boolean(keyfile, group, "BakIsAutomatic", &PREFS->bak_is_automatic);
727 homebank_pref_get_short(keyfile, group, "BakMaxNumCopies", &PREFS->bak_max_num_copies);
728
729 homebank_pref_get_boolean(keyfile, group, "HeritDate", &PREFS->heritdate);
730 homebank_pref_get_boolean(keyfile, group, "HideReconciled", &PREFS->hidereconciled);
731 homebank_pref_get_boolean(keyfile, group, "ShowRemind", &PREFS->showremind);
732 homebank_pref_get_boolean(keyfile, group, "TxnMemoAcp", &PREFS->txn_memoacp);
733 homebank_pref_get_short(keyfile, group, "TxnMemoAcpDays", &PREFS->txn_memoacp_days);
734
735
736 if( g_key_file_has_key(keyfile, group, "ColumnsOpe", NULL) )
737 {
738 gboolean *bsrc;
739 gint *src, i, j;
740 gsize length;
741
742 if(version <= 2) //retrieve old 0.1 or 0.2 visibility boolean
743 {
744 bsrc = g_key_file_get_boolean_list(keyfile, group, "ColumnsOpe", &length, NULL);
745 if( length == NUM_LST_DSPOPE-1 )
746 {
747 //and convert
748 for(i=0; i<NUM_LST_DSPOPE-1 ; i++)
749 {
750 PREFS->lst_ope_columns[i] = (bsrc[i] == TRUE) ? i+1 : -(i+1);
751 }
752 }
753 g_free(bsrc);
754 }
755 else
756 {
757 src = g_key_file_get_integer_list(keyfile, group, "ColumnsOpe", &length, NULL);
758
759 DB( g_print(" - length %d (max=%d)\n", length, NUM_LST_DSPOPE) );
760
761 if( length == NUM_LST_DSPOPE )
762 {
763 DB( g_print(" - copying column order from pref file\n") );
764 memcpy(PREFS->lst_ope_columns, src, length*sizeof(gint));
765 }
766 else
767 {
768 if(version <= 7)
769 {
770 if( length == NUM_LST_DSPOPE-2 ) //1 less column before v4.5.1
771 {
772 DB( g_print(" - upgrade from v7\n") );
773 DB( g_print(" - copying column order from pref file\n") );
774 memcpy(PREFS->lst_ope_columns, src, length*sizeof(gint));
775 //append balance column
776 PREFS->lst_ope_columns[10] = LST_DSPOPE_BALANCE;
777 }
778 }
779
780 if(version < 500)
781 {
782 if( length == NUM_LST_DSPOPE-2 ) //1 less column before v4.5.1
783 {
784 DB( g_print(" - upgrade prior v5.0\n") );
785 DB( g_print(" - copying column order from pref file\n") );
786 gboolean added = FALSE;
787 for(i=0,j=0; i<NUM_LST_DSPOPE-1 ; i++)
788 {
789 if( added == FALSE &&
790 (ABS(src[i]) == LST_DSPOPE_AMOUNT ||
791 ABS(src[i]) == LST_DSPOPE_EXPENSE ||
792 ABS(src[i]) == LST_DSPOPE_INCOME) )
793 {
794 PREFS->lst_ope_columns[j++] = LST_DSPOPE_CLR;
795 added = TRUE;
796 }
797 PREFS->lst_ope_columns[j++] = src[i];
798 }
799 }
800 }
801
802 }
803
804 g_free(src);
805 }
806
807 }
808
809 if( g_key_file_has_key(keyfile, group, "ColumnsOpeWidth", NULL) )
810 {
811 gint *src;
812 gsize length;
813
814 src = g_key_file_get_integer_list(keyfile, group, "ColumnsOpeWidth", &length, NULL);
815
816 DB( g_print(" - length %d (max=%d)\n", length, NUM_LST_DSPOPE) );
817
818 if( length == NUM_LST_DSPOPE )
819 {
820 DB( g_print(" - copying column width from pref file\n") );
821 memcpy(PREFS->lst_ope_col_width, src, length*sizeof(gint));
822 }
823
824 //leak
825 g_free(src);
826
827 }
828
829 homebank_pref_get_integer(keyfile, group, "OpeSortId", &PREFS->lst_ope_sort_id);
830 homebank_pref_get_integer(keyfile, group, "OpeSortOrder", &PREFS->lst_ope_sort_order);
831
832 DB( g_print(" - set sort to %d %d\n", PREFS->lst_ope_sort_id, PREFS->lst_ope_sort_order) );
833
834 homebank_pref_get_short(keyfile, group, "FiscYearDay", &PREFS->fisc_year_day);
835 homebank_pref_get_short(keyfile, group, "FiscYearMonth", &PREFS->fisc_year_month);
836
837
838 group = "Windows";
839
840 DB( g_print(" -> ** Windows\n") );
841
842 homebank_pref_get_wingeometry(keyfile, group, "Wal", &PREFS->wal_wg);
843 homebank_pref_get_wingeometry(keyfile, group, "Acc", &PREFS->acc_wg);
844 homebank_pref_get_wingeometry(keyfile, group, "Sta", &PREFS->sta_wg);
845 homebank_pref_get_wingeometry(keyfile, group, "Tme", &PREFS->tme_wg);
846 homebank_pref_get_wingeometry(keyfile, group, "Ove", &PREFS->ove_wg);
847 homebank_pref_get_wingeometry(keyfile, group, "Bud", &PREFS->bud_wg);
848 homebank_pref_get_wingeometry(keyfile, group, "Car", &PREFS->cst_wg);
849
850 homebank_pref_get_wingeometry(keyfile, group, "Txn", &PREFS->txn_wg);
851
852 if(version <= 7) //set maximize to 0
853 {
854 PREFS->wal_wg.s = 0;
855 PREFS->acc_wg.s = 0;
856 PREFS->txn_wg.s = 0;
857 PREFS->sta_wg.s = 0;
858 PREFS->tme_wg.s = 0;
859 PREFS->ove_wg.s = 0;
860 PREFS->bud_wg.s = 0;
861 PREFS->cst_wg.s = 0;
862 }
863 homebank_pref_get_integer(keyfile, group, "WalVPaned", &PREFS->wal_vpaned);
864 homebank_pref_get_integer(keyfile, group, "WalHPaned", &PREFS->wal_hpaned);
865 homebank_pref_get_boolean(keyfile, group, "WalToolbar", &PREFS->wal_toolbar);
866 homebank_pref_get_boolean(keyfile, group, "WalSpending", &PREFS->wal_spending);
867 homebank_pref_get_boolean(keyfile, group, "WalUpcoming", &PREFS->wal_upcoming);
868
869 //since 5.1.3
870 group = "Panels";
871
872 DB( g_print(" -> ** Panels\n") );
873
874 homebank_pref_get_short(keyfile, group, "AccColAccW", &PREFS->pnl_acc_col_acc_width);
875 homebank_pref_get_short(keyfile, group, "AccShowBy" , &PREFS->pnl_acc_show_by);
876
877 homebank_pref_get_short(keyfile, group, "UpcColPayW", &PREFS->pnl_upc_col_pay_width);
878 homebank_pref_get_short(keyfile, group, "UpcColMemW", &PREFS->pnl_upc_col_mem_width);
879
880 homebank_pref_get_string(keyfile, group, "PnlLstTab", &PREFS->pnl_list_tab);
881
882 group = "Format";
883
884 DB( g_print(" -> ** Format\n") );
885
886 homebank_pref_get_string(keyfile, group, "DateFmt", &PREFS->date_format);
887
888 if(version < 460)
889 {
890 gboolean useimperial;
891
892 homebank_pref_get_boolean(keyfile, group, "UKUnits", &useimperial);
893 if(useimperial)
894 {
895 PREFS->vehicle_unit_ismile = TRUE;
896 PREFS->vehicle_unit_isgal = TRUE;
897 }
898 }
899
900 homebank_pref_get_boolean(keyfile, group, "UnitIsMile", &PREFS->vehicle_unit_ismile);
901 homebank_pref_get_boolean(keyfile, group, "UnitIsGal", &PREFS->vehicle_unit_isgal);
902
903
904 group = "Filter";
905
906 DB( g_print(" -> ** Filter\n") );
907
908 homebank_pref_get_integer(keyfile, group, "DateRangeWal", &PREFS->date_range_wal);
909 homebank_pref_get_integer(keyfile, group, "DateRangeTxn", &PREFS->date_range_txn);
910 homebank_pref_get_integer(keyfile, group, "DateFutureNbDays", &PREFS->date_future_nbdays);
911 homebank_pref_get_integer(keyfile, group, "DateRangeRep", &PREFS->date_range_rep);
912
913 if(version <= 7)
914 {
915 // shift date range >= 5, since we inserted a new one at position 5
916 if(PREFS->date_range_wal >= FLT_RANGE_LASTYEAR)
917 PREFS->date_range_wal++;
918 if(PREFS->date_range_txn >= FLT_RANGE_LASTYEAR)
919 PREFS->date_range_txn++;
920 if(PREFS->date_range_rep >= FLT_RANGE_LASTYEAR)
921 PREFS->date_range_rep++;
922 }
923
924
925 group = "Euro";
926
927 DB( g_print(" -> ** Euro\n") );
928
929 //homebank_pref_get_string(keyfile, group, "DefCurrency" , &PREFS->curr_default);
930
931 homebank_pref_get_boolean(keyfile, group, "Active", &PREFS->euro_active);
932 homebank_pref_get_integer(keyfile, group, "Country", &PREFS->euro_country);
933
934 gchar *ratestr = g_key_file_get_string (keyfile, group, "ChangeRate", NULL);
935 if(ratestr != NULL) PREFS->euro_value = g_ascii_strtod(ratestr, NULL);
936
937 if(version <= 1)
938 {
939 homebank_pref_get_string(keyfile, group, "Symbol", &PREFS->minor_cur.symbol);
940 PREFS->minor_cur.frac_digits = g_key_file_get_integer (keyfile, group, "NBDec", NULL);
941
942 //PREFS->euro_nbdec = g_key_file_get_integer (keyfile, group, "NBDec", NULL);
943 //PREFS->euro_thsep = g_key_file_get_boolean (keyfile, group, "Sep", NULL);
944 //gchar *tmpstr = g_key_file_get_string (keyfile, group, "Symbol", &error);
945 }
946 else
947 {
948 if(version < 460)
949 {
950 gchar *prefix = NULL;
951 gchar *suffix = NULL;
952
953 homebank_pref_get_string(keyfile, group, "PreSymbol", &prefix);
954 homebank_pref_get_string(keyfile, group, "SufSymbol", &suffix);
955 homebank_pref_currfmt_convert(&PREFS->minor_cur, prefix, suffix);
956 g_free(prefix);
957 g_free(suffix);
958 }
959 else
960 {
961 homebank_pref_get_string(keyfile, group, "Symbol", &PREFS->minor_cur.symbol);
962 homebank_pref_get_boolean(keyfile, group, "IsPrefix", &PREFS->minor_cur.sym_prefix);
963 }
964 homebank_pref_get_string(keyfile, group, "DecChar" , &PREFS->minor_cur.decimal_char);
965 homebank_pref_get_string(keyfile, group, "GroupChar", &PREFS->minor_cur.grouping_char);
966 homebank_pref_get_short(keyfile, group, "FracDigits", &PREFS->minor_cur.frac_digits);
967
968 //fix 378992/421228
969 if( PREFS->minor_cur.frac_digits > MAX_FRAC_DIGIT )
970 PREFS->minor_cur.frac_digits = MAX_FRAC_DIGIT;
971
972 da_cur_initformat(&PREFS->minor_cur);
973 }
974
975 //PREFS->euro_symbol = g_locale_to_utf8(tmpstr, -1, NULL, NULL, NULL);
976
977 group = "Report";
978
979 DB( g_print(" -> ** Report\n") );
980
981 homebank_pref_get_boolean(keyfile, group, "StatByAmount", &PREFS->stat_byamount);
982 homebank_pref_get_boolean(keyfile, group, "StatDetail", &PREFS->stat_showdetail);
983 homebank_pref_get_boolean(keyfile, group, "StatRate", &PREFS->stat_showrate);
984 homebank_pref_get_boolean(keyfile, group, "BudgDetail", &PREFS->budg_showdetail);
985 homebank_pref_get_integer(keyfile, group, "ColorScheme", &PREFS->report_color_scheme);
986
987 group = "Exchange";
988
989 DB( g_print(" -> ** Exchange\n") );
990
991 homebank_pref_get_boolean(keyfile, group, "DoIntro", &PREFS->dtex_nointro);
992 homebank_pref_get_boolean(keyfile, group, "UcFirst", &PREFS->dtex_ucfirst);
993 homebank_pref_get_integer(keyfile, group, "DateFmt", &PREFS->dtex_datefmt);
994 homebank_pref_get_integer(keyfile, group, "OfxName", &PREFS->dtex_ofxname);
995 homebank_pref_get_integer(keyfile, group, "OfxMemo", &PREFS->dtex_ofxmemo);
996 homebank_pref_get_boolean(keyfile, group, "QifMemo", &PREFS->dtex_qifmemo);
997 homebank_pref_get_boolean(keyfile, group, "QifSwap", &PREFS->dtex_qifswap);
998
999
1000 //group = "Chart";
1001 //PREFS->chart_legend = g_key_file_get_boolean (keyfile, group, "Legend", NULL);
1002
1003
1004 group = "Plugins";
1005 {
1006 DB( g_print(" -> ** Plugins\n") );
1007
1008 gchar** strv = g_key_file_get_string_list(keyfile, group, "Path", NULL, NULL);
1009 if (strv) {
1010 g_strfreev(PREFS->ext_path);
1011 PREFS->ext_path = strv;
1012 }
1013
1014 strv = g_key_file_get_string_list(keyfile, group, "Whitelist", NULL, NULL);
1015 if (strv) {
1016 gchar** it;
1017 for (it = strv; it && *it; ++it) {
1018 PREFS->ext_whitelist = g_list_append(PREFS->ext_whitelist, g_strdup(*it));
1019 }
1020 g_strfreev(strv);
1021 }
1022 }
1023
1024
1025 /*
1026 #if MYDEBUG == 1
1027 gsize length;
1028 gchar *contents = g_key_file_to_data (keyfile, &length, NULL);
1029 //g_print(" keyfile:\n%s\n len=%d\n", contents, length);
1030 g_free(contents);
1031 #endif
1032 */
1033
1034 }
1035 g_free(filename);
1036 g_key_file_free (keyfile);
1037
1038 _homebank_pref_init_measurement_units();
1039 }
1040
1041 return retval;
1042 }
1043
1044
1045 static void homebank_pref_set_string(
1046 GKeyFile *key_file,
1047 const gchar *group_name,
1048 const gchar *key,
1049 gchar *string)
1050 {
1051
1052 DB( g_print(" - homebank_pref_set_string :: group='%s' key='%s' value='%s'\n", group_name, key, string) );
1053
1054 if( string != NULL && *string != '\0')
1055 g_key_file_set_string (key_file, group_name, key, string);
1056 else
1057 g_key_file_set_string (key_file, group_name, key, "");
1058
1059 }
1060
1061
1062 /*
1063 ** save preference to homedir/.homebank (HB_DATA_PATH)
1064 */
1065 gboolean homebank_pref_save(void)
1066 {
1067 GKeyFile *keyfile;
1068 gboolean retval = FALSE;
1069 gchar *group, *filename;
1070 gsize length;
1071 GError *error = NULL;
1072
1073 DB( g_print("\n[preferences] pref save\n") );
1074
1075 keyfile = g_key_file_new();
1076 if(keyfile )
1077 {
1078
1079 DB( g_print(" -> ** general\n") );
1080
1081
1082 group = "General";
1083 g_key_file_set_integer (keyfile, group, "Version", PREF_VERSION);
1084
1085 homebank_pref_set_string (keyfile, group, "Language", PREFS->language);
1086
1087 g_key_file_set_integer (keyfile, group, "BarStyle", PREFS->toolbar_style);
1088 //g_key_file_set_integer (keyfile, group, "BarImageSize", PREFS->image_size);
1089
1090
1091
1092 g_key_file_set_boolean (keyfile, group, "CustomColors", PREFS->custom_colors);
1093 g_key_file_set_string (keyfile, group, "ColorExp" , PREFS->color_exp);
1094 g_key_file_set_string (keyfile, group, "ColorInc" , PREFS->color_inc);
1095 g_key_file_set_string (keyfile, group, "ColorWarn", PREFS->color_warn);
1096
1097 g_key_file_set_integer (keyfile, group, "GridLines", PREFS->grid_lines);
1098
1099 homebank_pref_set_string (keyfile, group, "WalletPath" , PREFS->path_hbfile);
1100 homebank_pref_set_string (keyfile, group, "ImportPath" , PREFS->path_import);
1101 homebank_pref_set_string (keyfile, group, "ExportPath" , PREFS->path_export);
1102 //g_key_file_set_string (keyfile, group, "NavigatorPath", PREFS->path_navigator);
1103
1104 g_key_file_set_boolean (keyfile, group, "BakIsAutomatic", PREFS->bak_is_automatic);
1105 g_key_file_set_integer (keyfile, group, "BakMaxNumCopies", PREFS->bak_max_num_copies);
1106
1107 g_key_file_set_boolean (keyfile, group, "ShowSplash", PREFS->showsplash);
1108 g_key_file_set_boolean (keyfile, group, "LoadLast", PREFS->loadlast);
1109 g_key_file_set_boolean (keyfile, group, "AppendScheduled", PREFS->appendscheduled);
1110 g_key_file_set_boolean (keyfile, group, "UpdateCurrency", PREFS->do_update_currency);
1111
1112 g_key_file_set_boolean (keyfile, group, "HeritDate", PREFS->heritdate);
1113 g_key_file_set_boolean (keyfile, group, "HideReconciled", PREFS->hidereconciled);
1114 g_key_file_set_boolean (keyfile, group, "ShowRemind", PREFS->showremind);
1115 g_key_file_set_boolean (keyfile, group, "TxnMemoAcp", PREFS->txn_memoacp);
1116 g_key_file_set_integer (keyfile, group, "TxnMemoAcpDays" , PREFS->txn_memoacp_days);
1117
1118 g_key_file_set_integer_list(keyfile, group, "ColumnsOpe", PREFS->lst_ope_columns, NUM_LST_DSPOPE);
1119 g_key_file_set_integer_list(keyfile, group, "ColumnsOpeWidth", PREFS->lst_ope_col_width, NUM_LST_DSPOPE);
1120 g_key_file_set_integer (keyfile, group, "OpeSortId" , PREFS->lst_ope_sort_id);
1121 g_key_file_set_integer (keyfile, group, "OpeSortOrder" , PREFS->lst_ope_sort_order);
1122
1123 g_key_file_set_integer (keyfile, group, "FiscYearDay" , PREFS->fisc_year_day);
1124 g_key_file_set_integer (keyfile, group, "FiscYearMonth" , PREFS->fisc_year_month);
1125
1126 // added v3.4
1127 DB( g_print(" -> ** windows\n") );
1128
1129 group = "Windows";
1130 g_key_file_set_integer_list(keyfile, group, "Wal", (gint *)&PREFS->wal_wg, 5);
1131 g_key_file_set_integer_list(keyfile, group, "Acc", (gint *)&PREFS->acc_wg, 5);
1132 g_key_file_set_integer_list(keyfile, group, "Sta", (gint *)&PREFS->sta_wg, 5);
1133 g_key_file_set_integer_list(keyfile, group, "Tme", (gint *)&PREFS->tme_wg, 5);
1134 g_key_file_set_integer_list(keyfile, group, "Ove", (gint *)&PREFS->ove_wg, 5);
1135 g_key_file_set_integer_list(keyfile, group, "Bud", (gint *)&PREFS->bud_wg, 5);
1136 g_key_file_set_integer_list(keyfile, group, "Car", (gint *)&PREFS->cst_wg, 5);
1137
1138 g_key_file_set_integer_list(keyfile, group, "Txn", (gint *)&PREFS->txn_wg, 5);
1139
1140 g_key_file_set_integer (keyfile, group, "WalVPaned" , PREFS->wal_vpaned);
1141 g_key_file_set_integer (keyfile, group, "WalHPaned" , PREFS->wal_hpaned);
1142 g_key_file_set_boolean (keyfile, group, "WalToolbar", PREFS->wal_toolbar);
1143 g_key_file_set_boolean (keyfile, group, "WalSpending", PREFS->wal_spending);
1144 g_key_file_set_boolean (keyfile, group, "WalUpcoming", PREFS->wal_upcoming);
1145
1146 //since 5.1.3
1147 DB( g_print(" -> ** Panels\n") );
1148
1149 group = "Panels";
1150 g_key_file_set_integer(keyfile, group, "AccColAccW", PREFS->pnl_acc_col_acc_width);
1151 g_key_file_set_integer(keyfile, group, "AccShowBy" , PREFS->pnl_acc_show_by);
1152
1153 g_key_file_set_integer(keyfile, group, "UpcColPayW", PREFS->pnl_upc_col_pay_width);
1154 g_key_file_set_integer(keyfile, group, "UpcColMemW", PREFS->pnl_upc_col_mem_width);
1155
1156 homebank_pref_set_string (keyfile, group, "PnlLstTab", PREFS->pnl_list_tab);
1157
1158 DB( g_print(" -> ** format\n") );
1159
1160 group = "Format";
1161 homebank_pref_set_string (keyfile, group, "DateFmt" , PREFS->date_format);
1162
1163 //g_key_file_set_boolean (keyfile, group, "UKUnits" , PREFS->imperial_unit);
1164 g_key_file_set_boolean (keyfile, group, "UnitIsMile" , PREFS->vehicle_unit_ismile);
1165 g_key_file_set_boolean (keyfile, group, "UnitIsGal" , PREFS->vehicle_unit_isgal);
1166
1167
1168 DB( g_print(" -> ** filter\n") );
1169
1170 group = "Filter";
1171 g_key_file_set_integer (keyfile, group, "DateRangeWal", PREFS->date_range_wal);
1172 g_key_file_set_integer (keyfile, group, "DateRangeTxn", PREFS->date_range_txn);
1173 g_key_file_set_integer (keyfile, group, "DateFutureNbDays", PREFS->date_future_nbdays);
1174 g_key_file_set_integer (keyfile, group, "DateRangeRep", PREFS->date_range_rep);
1175
1176 DB( g_print(" -> ** euro\n") );
1177
1178 //euro options
1179 group = "Euro";
1180
1181 //homebank_pref_set_string(keyfile, group, "DefCurrency" , PREFS->curr_default);
1182
1183 g_key_file_set_boolean (keyfile, group, "Active" , PREFS->euro_active);
1184 if( PREFS->euro_active )
1185 {
1186 g_key_file_set_integer (keyfile, group, "Country", PREFS->euro_country);
1187 gchar ratestr[64];
1188 g_ascii_dtostr(ratestr, 63, PREFS->euro_value);
1189 homebank_pref_set_string (keyfile, group, "ChangeRate", ratestr);
1190 homebank_pref_set_string (keyfile, group, "Symbol" , PREFS->minor_cur.symbol);
1191 g_key_file_set_boolean (keyfile, group, "IsPrefix" , PREFS->minor_cur.sym_prefix);
1192 homebank_pref_set_string (keyfile, group, "DecChar" , PREFS->minor_cur.decimal_char);
1193 homebank_pref_set_string (keyfile, group, "GroupChar" , PREFS->minor_cur.grouping_char);
1194 g_key_file_set_integer (keyfile, group, "FracDigits", PREFS->minor_cur.frac_digits);
1195 }
1196
1197 //report options
1198 DB( g_print(" -> ** report\n") );
1199
1200 group = "Report";
1201 g_key_file_set_boolean (keyfile, group, "StatByAmount", PREFS->stat_byamount);
1202 g_key_file_set_boolean (keyfile, group, "StatDetail" , PREFS->stat_showdetail);
1203 g_key_file_set_boolean (keyfile, group, "StatRate" , PREFS->stat_showrate);
1204 g_key_file_set_boolean (keyfile, group, "BudgDetail" , PREFS->budg_showdetail);
1205 g_key_file_set_integer (keyfile, group, "ColorScheme" , PREFS->report_color_scheme);
1206
1207
1208 group = "Exchange";
1209 g_key_file_set_boolean (keyfile, group, "DoIntro", PREFS->dtex_nointro);
1210 g_key_file_set_boolean (keyfile, group, "UcFirst", PREFS->dtex_ucfirst);
1211 g_key_file_set_integer (keyfile, group, "DateFmt", PREFS->dtex_datefmt);
1212 g_key_file_set_integer (keyfile, group, "OfxName", PREFS->dtex_ofxname);
1213 g_key_file_set_integer (keyfile, group, "OfxMemo", PREFS->dtex_ofxmemo);
1214 g_key_file_set_boolean (keyfile, group, "QifMemo", PREFS->dtex_qifmemo);
1215 g_key_file_set_boolean (keyfile, group, "QifSwap", PREFS->dtex_qifswap);
1216
1217
1218 //group = "Chart";
1219 //g_key_file_set_boolean (keyfile, group, "Legend", PREFS->chart_legend);
1220
1221 group = "Plugins";
1222 {
1223 g_key_file_set_string_list(keyfile, group, "Path", (const gchar* const*)PREFS->ext_path, g_strv_length(PREFS->ext_path));
1224
1225 gsize len = g_list_length(PREFS->ext_whitelist);
1226 gchar** strv = g_new0(gchar*, len + 1);
1227 guint i;
1228
1229 for (i = 0; i < len; ++i) {
1230 strv[i] = g_list_nth_data(PREFS->ext_whitelist, i);
1231 }
1232 g_key_file_set_string_list(keyfile, group, "Whitelist", (const gchar* const*)strv, len);
1233 g_free(strv);
1234 }
1235
1236 //g_key_file_set_string (keyfile, group, "", PREFS->);
1237 //g_key_file_set_boolean (keyfile, group, "", PREFS->);
1238 //g_key_file_set_integer (keyfile, group, "", PREFS->);
1239
1240 DB( g_print(" -> ** g_key_file_to_data\n") );
1241
1242 gchar *contents = g_key_file_to_data (keyfile, &length, NULL);
1243
1244 //DB( g_print(" keyfile:\n%s\nlen=%d\n", contents, length) );
1245
1246 filename = g_build_filename(homebank_app_get_config_dir(), "preferences", NULL );
1247
1248 DB( g_print(" -> filename: %s\n", filename) );
1249
1250 g_file_set_contents(filename, contents, length, &error);
1251 if( error )
1252 {
1253 g_warning("unable to save file %s: %s", filename, error->message);
1254 g_error_free (error);
1255 error = NULL;
1256 }
1257
1258 DB( g_print(" -> contents: %s\n", contents) );
1259
1260 DB( g_print(" -> freeing filename\n") );
1261 g_free(filename);
1262
1263 DB( g_print(" -> freeing buffer\n") );
1264
1265 g_free(contents);
1266
1267 DB( g_print(" -> freeing keyfile\n") );
1268
1269 g_key_file_free (keyfile);
1270 }
1271
1272 _homebank_pref_init_measurement_units();
1273
1274 return retval;
1275 }
1276
This page took 0.09271 seconds and 4 git commands to generate.