1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2017 Maxime DOYEN
4 * This file is part of HomeBank.
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.
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.
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/>.
23 #include "hb-preferences.h"
24 #include "hb-filter.h"
25 #include "gtk-chart-colors.h"
31 /****************************************************************************/
33 /****************************************************************************/
42 /* our global datas */
43 extern struct HomeBank
*GLOBALS
;
44 extern struct Preferences
*PREFS
;
46 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
48 static void homebank_pref_init_monetary(void)
51 DB( g_print("\n[system] get currency code\n") );
54 struct lconv
*lc
= localeconv();
56 g_stpcpy (PREFS
->IntCurrSymbol
, lc
->int_curr_symbol
);
57 g_strstrip(PREFS
->IntCurrSymbol
);
59 DB( g_print("- stored '%s' from linux system\n", PREFS
->IntCurrSymbol
) );
63 #define BUFFER_SIZE 512
64 char buffer
[BUFFER_SIZE
];
65 //LPWSTR wcBuffer = buffer;
66 LPSTR wcBuffer
= buffer
;
69 //https://msdn.microsoft.com/en-us/library/windows/desktop/dd464799%28v=vs.85%29.aspx
72 iResult
= GetLocaleInfoA(LOCALE_USER_DEFAULT
, LOCALE_SINTLSYMBOL
, wcBuffer
, BUFFER_SIZE
);
75 DB( g_print("LOCALE_SINTLSYMBOL='%s'\n", buffer
) );
76 g_stpcpy (PREFS
->IntCurrSymbol
, buffer
);
77 g_strstrip(PREFS
->IntCurrSymbol
);
79 DB( g_print("- stored '%s' from windows system\n", PREFS
->IntCurrSymbol
) );
83 g_stpcpy (PREFS
->IntCurrSymbol
, "USD");
85 DB( g_print("- stored '%s' as default\n", PREFS
->IntCurrSymbol
) );
96 static void homebank_pref_init_monetary(void)
98 DB( g_print("\n[preferences] monetary\n") );
103 struct lconv *lc = localeconv();
105 DB( g_print("\n[preferences] monetary unix\n") );
107 DB( g_print("int_curr_symbol '%s'\n", lc->int_curr_symbol) );
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]) );
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]) );
118 DB( g_print("frac_digits '%d'\n", (gint)lc->frac_digits) );
120 DB( g_print("currency_symbol '%s'\n", lc->currency_symbol) );
122 DB( g_print("p_cs_precedes '%d'\n", lc->p_cs_precedes) );
124 DB( g_print("n_cs_precedes '%d'\n", lc->n_cs_precedes) );
126 //PREFS->base_cur.iso_code = g_strdup(g_strstrip(lc->int_curr_symbol));
128 if( lc->p_cs_precedes || lc->n_cs_precedes )
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") );
136 PREFS->base_cur.symbol = g_strdup(lc->currency_symbol);
137 PREFS->base_cur.sym_prefix = FALSE;
140 PREFS->base_cur.decimal_char = g_strdup(lc->mon_decimal_point);
142 PREFS->base_cur.grouping_char = g_strdup(lc->mon_thousands_sep);
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);
148 DB( g_print(" -> grouping_char: '%s'\n", PREFS->base_cur.grouping_char) );
150 PREFS->base_cur.frac_digits = lc->frac_digits;
153 if( PREFS->base_cur.frac_digits > MAX_FRAC_DIGIT )
155 PREFS->base_cur.frac_digits = 2;
156 g_free(PREFS->base_cur.decimal_char);
157 PREFS->base_cur.decimal_char = g_strdup(".");
163 #define BUFFER_SIZE 512
164 char buffer[BUFFER_SIZE];
165 //LPWSTR wcBuffer = buffer;
166 LPSTR wcBuffer = buffer;
170 //https://msdn.microsoft.com/en-us/library/windows/desktop/dd464799%28v=vs.85%29.aspx
175 //see g_locale_to_utf8 here
176 iResult = GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SCURRENCY, wcBuffer, BUFFER_SIZE);
179 DB( g_print("LOCALE_SCURRENCY='%s'\n", buffer) );
180 PREFS->base_cur.symbol = g_locale_to_utf8(buffer, -1, NULL, &toto, NULL);
184 //PREFS->base_cur.sym_prefix =
186 iResult = GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, wcBuffer, BUFFER_SIZE);
189 DB( g_print("LOCALE_SDECIMAL='%s'\n", buffer) );
190 PREFS->base_cur.decimal_char = g_locale_to_utf8(buffer, -1, NULL, &toto, NULL);
193 iResult = GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, wcBuffer, BUFFER_SIZE);
196 DB( g_print("LOCALE_STHOUSAND='%s'\n", buffer) );
197 PREFS->base_cur.grouping_char = g_locale_to_utf8(buffer, -1, NULL, &toto, NULL);
200 // LOCALE_ICURRDIGITS
201 PREFS->base_cur.frac_digits = 2;
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;
220 static void homebank_pref_init_wingeometry(struct WinGeometry
*wg
, gint l
, gint t
, gint w
, gint h
)
231 //vehicle_unit_distbyvol
232 //=> used for column title
234 static void _homebank_pref_init_measurement_units(void)
237 if(!PREFS
->vehicle_unit_ismile
)
239 PREFS
->vehicle_unit_dist
= "%d km";
240 PREFS
->vehicle_unit_100
= "100 km";
245 PREFS
->vehicle_unit_dist
= "%d mi.";
246 PREFS
->vehicle_unit_100
= "100 mi.";
250 if(!PREFS
->vehicle_unit_isgal
)
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");
258 //TRANSLATORS: miles per liter
259 PREFS
->vehicle_unit_distbyvol
= _("mi./l");
264 PREFS
->vehicle_unit_vol
= "%.2f gal.";
265 if(!PREFS
->vehicle_unit_ismile
)
266 PREFS
->vehicle_unit_distbyvol
= "km/gal.";
268 PREFS
->vehicle_unit_distbyvol
= "mi./gal.";
274 void homebank_pref_free(void)
276 DB( g_print("\n[preferences] free\n") );
279 g_free(PREFS
->date_format
);
281 g_free(PREFS
->color_exp
);
282 g_free(PREFS
->color_inc
);
283 g_free(PREFS
->color_warn
);
285 g_free(PREFS
->path_hbfile
);
286 g_free(PREFS
->path_import
);
287 g_free(PREFS
->path_export
);
288 //g_free(PREFS->path_navigator);
290 g_free(PREFS
->language
);
293 g_free(PREFS
->minor_cur
.symbol
);
294 g_free(PREFS
->minor_cur
.decimal_char
);
295 g_free(PREFS
->minor_cur
.grouping_char
);
297 g_strfreev(PREFS
->ext_path
);
298 g_list_free_full(PREFS
->ext_whitelist
, g_free
);
300 memset(PREFS
, 0, sizeof(struct Preferences
));
304 void homebank_pref_setdefault(void)
308 DB( g_print("\n[preferences] pref init\n") );
310 homebank_pref_free();
312 PREFS
->language
= NULL
;
314 PREFS
->date_format
= g_strdup(DEFAULT_FORMAT_DATE
);
316 PREFS
->path_hbfile
= g_strdup_printf("%s", g_get_home_dir ());
317 PREFS
->path_import
= g_strdup_printf("%s", g_get_home_dir ());
318 PREFS
->path_export
= g_strdup_printf("%s", g_get_home_dir ());
319 //PREFS->path_navigator = g_strdup(DEFAULT_PATH_NAVIGATOR);
321 PREFS
->showsplash
= TRUE
;
322 PREFS
->loadlast
= TRUE
;
323 PREFS
->appendscheduled
= FALSE
;
324 PREFS
->do_update_currency
= FALSE
;
326 PREFS
->heritdate
= FALSE
;
327 PREFS
->hidereconciled
= FALSE
;
328 PREFS
->showremind
= TRUE
;
330 PREFS
->toolbar_style
= 4; //text beside icons
331 PREFS
->custom_colors
= TRUE
;
332 PREFS
->color_exp
= g_strdup(DEFAULT_EXP_COLOR
);
333 PREFS
->color_inc
= g_strdup(DEFAULT_INC_COLOR
);
334 PREFS
->color_warn
= g_strdup(DEFAULT_WARN_COLOR
);
335 PREFS
->grid_lines
= GTK_TREE_VIEW_GRID_LINES_NONE
;
338 PREFS
->fisc_year_day
= 1;
339 PREFS
->fisc_year_month
= 1;
341 /* windows position/size */
342 homebank_pref_init_wingeometry(&PREFS
->wal_wg
, 0, 0, 1024, 600);
343 homebank_pref_init_wingeometry(&PREFS
->acc_wg
, 0, 0, 1024, 600);
344 homebank_pref_init_wingeometry(&PREFS
->sta_wg
, 0, 0, 800, 494);
345 homebank_pref_init_wingeometry(&PREFS
->tme_wg
, 0, 0, 800, 494);
346 homebank_pref_init_wingeometry(&PREFS
->ove_wg
, 0, 0, 800, 494);
347 homebank_pref_init_wingeometry(&PREFS
->bud_wg
, 0, 0, 800, 494);
348 homebank_pref_init_wingeometry(&PREFS
->cst_wg
, 0, 0, 800, 494);
350 homebank_pref_init_wingeometry(&PREFS
->txn_wg
, 0, 0, -1, -1);
352 homebank_pref_init_monetary();
354 PREFS
->wal_toolbar
= TRUE
;
355 PREFS
->wal_spending
= TRUE
;
356 PREFS
->wal_upcoming
= TRUE
;
357 PREFS
->wal_vpaned
= 600/2;
358 PREFS
->wal_hpaned
= 1024/2;
360 PREFS
->pnl_acc_col_acc_width
= -1;
361 PREFS
->pnl_acc_show_by
= 0;
362 PREFS
->pnl_upc_col_pay_width
= -1;
363 PREFS
->pnl_upc_col_mem_width
= -1;
368 PREFS->lst_ope_columns[i++] = LST_DSPOPE_STATUS;
369 PREFS->lst_ope_columns[i++] = LST_DSPOPE_DATE;
370 PREFS->lst_ope_columns[i++] = LST_DSPOPE_INFO;
371 PREFS->lst_ope_columns[i++] = LST_DSPOPE_PAYEE;
372 PREFS->lst_ope_columns[i++] = LST_DSPOPE_WORDING;
373 PREFS->lst_ope_columns[i++] = -LST_DSPOPE_AMOUNT;
374 PREFS->lst_ope_columns[i++] = LST_DSPOPE_EXPENSE;
375 PREFS->lst_ope_columns[i++] = LST_DSPOPE_INCOME;
376 PREFS->lst_ope_columns[i++] = LST_DSPOPE_CATEGORY;
377 PREFS->lst_ope_columns[i++] = LST_DSPOPE_TAGS;
379 PREFS
->lst_ope_columns
[i
++] = LST_DSPOPE_STATUS
; //always displayed
380 PREFS
->lst_ope_columns
[i
++] = LST_DSPOPE_DATE
; //always displayed
381 PREFS
->lst_ope_columns
[i
++] = LST_DSPOPE_INFO
;
382 PREFS
->lst_ope_columns
[i
++] = LST_DSPOPE_PAYEE
;
383 PREFS
->lst_ope_columns
[i
++] = LST_DSPOPE_CATEGORY
;
384 PREFS
->lst_ope_columns
[i
++] = LST_DSPOPE_TAGS
;
385 PREFS
->lst_ope_columns
[i
++] = LST_DSPOPE_CLR
;
386 PREFS
->lst_ope_columns
[i
++] = -LST_DSPOPE_AMOUNT
;
387 PREFS
->lst_ope_columns
[i
++] = LST_DSPOPE_EXPENSE
;
388 PREFS
->lst_ope_columns
[i
++] = LST_DSPOPE_INCOME
;
389 PREFS
->lst_ope_columns
[i
++] = LST_DSPOPE_BALANCE
;
390 PREFS
->lst_ope_columns
[i
++] = LST_DSPOPE_WORDING
;
392 PREFS
->lst_ope_sort_id
= LST_DSPOPE_DATE
;
393 PREFS
->lst_ope_sort_order
= GTK_SORT_ASCENDING
;
395 for( i
=0;i
<NUM_LST_DSPOPE
;i
++)
396 PREFS
->lst_ope_col_size
[i
] = -1;
398 //PREFS->base_cur.nbdecimal = 2;
399 //PREFS->base_cur.separator = TRUE;
401 PREFS
->date_range_wal
= FLT_RANGE_LASTMONTH
;
402 PREFS
->date_range_txn
= FLT_RANGE_LAST12MONTHS
;
403 PREFS
->date_future_nbdays
= 0;
404 PREFS
->date_range_rep
= FLT_RANGE_THISYEAR
;
407 PREFS
->dtex_nointro
= TRUE
;
408 //PREFS->dtex_datefmt
409 PREFS
->dtex_ofxname
= 1;
410 PREFS
->dtex_ofxmemo
= 2;
411 PREFS
->dtex_qifmemo
= TRUE
;
412 PREFS
->dtex_qifswap
= FALSE
;
414 //todo: add intelligence here
415 PREFS
->euro_active
= FALSE
;
417 PREFS
->euro_country
= 0;
418 PREFS
->euro_value
= 1.0;
420 da_cur_initformat(&PREFS
->minor_cur
);
422 //PREFS->euro_nbdec = 2;
423 //PREFS->euro_thsep = TRUE;
424 //PREFS->euro_symbol = g_strdup("??");
426 PREFS
->stat_byamount
= FALSE
;
427 PREFS
->stat_showdetail
= FALSE
;
428 PREFS
->stat_showrate
= FALSE
;
429 PREFS
->budg_showdetail
= FALSE
;
430 PREFS
->report_color_scheme
= CHART_COLMAP_HOMEBANK
;
432 //PREFS->chart_legend = FALSE;
434 PREFS
->vehicle_unit_ismile
= FALSE
;
435 PREFS
->vehicle_unit_isgal
= FALSE
;
437 gchar
** plugin_path
= g_new0(gchar
*, 4);
439 const gchar
* env
= g_getenv("HOMEBANK_PLUGINS");
441 if (g_path_is_absolute(env
)) {
442 plugin_path
[i
++] = g_strdup(env
);
444 gchar
* cur
= g_get_current_dir();
445 plugin_path
[i
++] = g_build_filename(cur
, env
, NULL
);
449 plugin_path
[i
++] = g_build_filename(homebank_app_get_config_dir(), "plugins", NULL
);
450 plugin_path
[i
++] = g_build_filename(homebank_app_get_pkglib_dir(), "plugins", NULL
);
451 PREFS
->ext_path
= plugin_path
;
452 PREFS
->ext_whitelist
= NULL
;
454 _homebank_pref_init_measurement_units();
460 ** load preference from homedir/.homebank (HB_DATA_PATH)
462 static void homebank_pref_get_wingeometry(
464 const gchar
*group_name
,
466 struct WinGeometry
*storage
)
468 if( g_key_file_has_key(key_file
, group_name
, key
, NULL
) )
473 wg
= g_key_file_get_integer_list(key_file
, group_name
, key
, &length
, NULL
);
474 memcpy(storage
, wg
, 5*sizeof(gint
));
476 // #606613 ensure left/top to be > 0
488 static void homebank_pref_get_boolean(
490 const gchar
*group_name
,
495 if( g_key_file_has_key(key_file
, group_name
, key
, NULL
) )
497 *storage
= g_key_file_get_boolean(key_file
, group_name
, key
, NULL
);
501 static void homebank_pref_get_integer(
503 const gchar
*group_name
,
508 DB( g_print(" search %s in %s\n", key
, group_name
) );
511 if( g_key_file_has_key(key_file
, group_name
, key
, NULL
) )
513 *storage
= g_key_file_get_integer(key_file
, group_name
, key
, NULL
);
515 DB( g_print(" store integer %d for %s at %x\n", *storage
, key
, *storage
) );
519 static void homebank_pref_get_guint32(
521 const gchar
*group_name
,
526 if( g_key_file_has_key(key_file
, group_name
, key
, NULL
) )
528 *storage
= g_key_file_get_integer(key_file
, group_name
, key
, NULL
);
532 static void homebank_pref_get_short(
534 const gchar
*group_name
,
539 if( g_key_file_has_key(key_file
, group_name
, key
, NULL
) )
541 *storage
= (gshort
)g_key_file_get_integer(key_file
, group_name
, key
, NULL
);
545 static void homebank_pref_get_string(
547 const gchar
*group_name
,
553 if( g_key_file_has_key(key_file
, group_name
, key
, NULL
) )
555 /* free any previous string */
556 if( *storage
!= NULL
)
558 //DB( g_print(" storage was not null, freeing\n") );
565 string
= g_key_file_get_string(key_file
, group_name
, key
, NULL
);
568 *storage
= g_strdup(string
);
570 //DB( g_print(" store '%s' for %s at %x\n", string, key, *storage) );
577 g_warning ("error: %s\n", error->message);
587 static void homebank_pref_currfmt_convert(Currency
*cur
, gchar
*prefix
, gchar
*suffix
)
590 if( (prefix
!= NULL
) && (strlen(prefix
) > 0) )
592 cur
->symbol
= g_strdup(prefix
);
593 cur
->sym_prefix
= TRUE
;
595 else if( (suffix
!= NULL
) )
597 cur
->symbol
= g_strdup(suffix
);
598 cur
->sym_prefix
= FALSE
;
603 gboolean
homebank_pref_load(void)
606 gboolean retval
= FALSE
;
607 gchar
*group
, *filename
;
609 GError
*error
= NULL
;
611 DB( g_print("\n[preferences] pref load\n") );
613 keyfile
= g_key_file_new();
616 filename
= g_build_filename(homebank_app_get_config_dir(), "preferences", NULL
);
618 DB( g_print(" - filename: %s\n", filename
) );
621 if(g_key_file_load_from_file (keyfile
, filename
, G_KEY_FILE_NONE
, NULL
))
626 DB( g_print(" -> ** General\n") );
628 //since 4.51 version is integer
629 homebank_pref_get_guint32 (keyfile
, group
, "Version", &version
);
630 if(version
== 0) // old double number
632 gdouble v
= g_key_file_get_double (keyfile
, group
, "Version", NULL
);
633 version
= (guint32
)(v
* 10);
636 DB( g_print(" - version: %d\n", version
) );
638 homebank_pref_get_string(keyfile
, group
, "Language", &PREFS
->language
);
640 homebank_pref_get_short(keyfile
, group
, "BarStyle" , &PREFS
->toolbar_style
);
642 if(version
<= 6 && PREFS
->toolbar_style
== 0) // force system to text beside
644 PREFS
->toolbar_style
= 4;
647 if(version
<= 2) // retrieve old settings
651 homebank_pref_get_guint32(keyfile
, group
, "ColorExp" , &color
);
652 g_free(PREFS
->color_exp
);
653 PREFS
->color_exp
= g_strdup_printf("#%06x", color
);
655 homebank_pref_get_guint32(keyfile
, group
, "ColorInc" , &color
);
656 g_free(PREFS
->color_inc
);
657 PREFS
->color_inc
= g_strdup_printf("#%06x", color
);
659 homebank_pref_get_guint32(keyfile
, group
, "ColorWarn", &color
);
660 g_free(PREFS
->color_warn
);
661 PREFS
->color_warn
= g_strdup_printf("#%06x", color
);
665 homebank_pref_get_boolean(keyfile
, group
, "CustomColors", &PREFS
->custom_colors
);
667 homebank_pref_get_string(keyfile
, group
, "ColorExp" , &PREFS
->color_exp
);
668 homebank_pref_get_string(keyfile
, group
, "ColorInc" , &PREFS
->color_inc
);
669 homebank_pref_get_string(keyfile
, group
, "ColorWarn", &PREFS
->color_warn
);
674 homebank_pref_get_boolean(keyfile
, group
, "RulesHint", &rules_hint
);
675 if( rules_hint
== TRUE
)
676 PREFS
->grid_lines
= GTK_TREE_VIEW_GRID_LINES_HORIZONTAL
;
680 homebank_pref_get_short(keyfile
, group
, "GridLines", &PREFS
->grid_lines
);
683 DB( g_print(" - color exp: %s\n", PREFS
->color_exp
) );
684 DB( g_print(" - color inc: %s\n", PREFS
->color_inc
) );
685 DB( g_print(" - color wrn: %s\n", PREFS
->color_warn
) );
688 homebank_pref_get_string(keyfile
, group
, "WalletPath", &PREFS
->path_hbfile
);
689 homebank_pref_get_string(keyfile
, group
, "ImportPath", &PREFS
->path_import
);
690 homebank_pref_get_string(keyfile
, group
, "ExportPath", &PREFS
->path_export
);
692 homebank_pref_get_boolean(keyfile
, group
, "ShowSplash", &PREFS
->showsplash
);
693 homebank_pref_get_boolean(keyfile
, group
, "LoadLast", &PREFS
->loadlast
);
694 homebank_pref_get_boolean(keyfile
, group
, "AppendScheduled", &PREFS
->appendscheduled
);
695 homebank_pref_get_boolean(keyfile
, group
, "UpdateCurrency", &PREFS
->do_update_currency
);
697 homebank_pref_get_boolean(keyfile
, group
, "HeritDate", &PREFS
->heritdate
);
698 homebank_pref_get_boolean(keyfile
, group
, "HideReconciled", &PREFS
->hidereconciled
);
699 homebank_pref_get_boolean(keyfile
, group
, "ShowRemind", &PREFS
->showremind
);
701 if( g_key_file_has_key(keyfile
, group
, "ColumnsOpe", NULL
) )
707 if(version
<= 2) //retrieve old 0.1 or 0.2 visibility boolean
709 bsrc
= g_key_file_get_boolean_list(keyfile
, group
, "ColumnsOpe", &length
, &error
);
710 if( length
== NUM_LST_DSPOPE
-1 )
713 for(i
=0; i
<NUM_LST_DSPOPE
-1 ; i
++)
715 PREFS
->lst_ope_columns
[i
] = (bsrc
[i
] == TRUE
) ? i
+1 : -(i
+1);
722 src
= g_key_file_get_integer_list(keyfile
, group
, "ColumnsOpe", &length
, &error
);
724 DB( g_print(" - length %d (max=%d)\n", length
, NUM_LST_DSPOPE
) );
726 if( length
== NUM_LST_DSPOPE
-1 )
728 DB( g_print(" - copying column order from pref file\n") );
729 memcpy(PREFS
->lst_ope_columns
, src
, length
*sizeof(gint
));
735 if( length
== NUM_LST_DSPOPE
-2 ) //1 less column before v4.5.1
737 DB( g_print(" - upgrade from v7\n") );
738 DB( g_print(" - copying column order from pref file\n") );
739 memcpy(PREFS
->lst_ope_columns
, src
, length
*sizeof(gint
));
740 //append balance column
741 PREFS
->lst_ope_columns
[10] = LST_DSPOPE_BALANCE
;
747 if( length
== NUM_LST_DSPOPE
-2 ) //1 less column before v4.5.1
749 DB( g_print(" - upgrade prior v5.0\n") );
750 DB( g_print(" - copying column order from pref file\n") );
751 gboolean added
= FALSE
;
752 for(i
=0,j
=0; i
<NUM_LST_DSPOPE
-1 ; i
++)
754 if( added
== FALSE
&&
755 (ABS(src
[i
]) == LST_DSPOPE_AMOUNT
||
756 ABS(src
[i
]) == LST_DSPOPE_EXPENSE
||
757 ABS(src
[i
]) == LST_DSPOPE_INCOME
) )
759 PREFS
->lst_ope_columns
[j
++] = LST_DSPOPE_CLR
;
762 PREFS
->lst_ope_columns
[j
++] = src
[i
];
774 if( g_key_file_has_key(keyfile
, group
, "ColumnsOpeWidth", NULL
) )
779 src
= g_key_file_get_integer_list(keyfile
, group
, "ColumnsOpeWidth", &length
, &error
);
781 DB( g_print(" - length %d (max=%d)\n", length
, NUM_LST_DSPOPE
) );
783 if( length
== NUM_LST_DSPOPE
-1 )
785 DB( g_print(" - copying column width from pref file\n") );
786 memcpy(PREFS
->lst_ope_col_size
, src
, length
*sizeof(gint
));
790 homebank_pref_get_integer(keyfile
, group
, "OpeSortId", &PREFS
->lst_ope_sort_id
);
791 homebank_pref_get_integer(keyfile
, group
, "OpeSortOrder", &PREFS
->lst_ope_sort_order
);
793 DB( g_print(" - set sort to %d %d\n", PREFS
->lst_ope_sort_id
, PREFS
->lst_ope_sort_order
) );
795 homebank_pref_get_short(keyfile
, group
, "FiscYearDay", &PREFS
->fisc_year_day
);
796 homebank_pref_get_short(keyfile
, group
, "FiscYearMonth", &PREFS
->fisc_year_month
);
801 DB( g_print(" -> ** Windows\n") );
803 homebank_pref_get_wingeometry(keyfile
, group
, "Wal", &PREFS
->wal_wg
);
804 homebank_pref_get_wingeometry(keyfile
, group
, "Acc", &PREFS
->acc_wg
);
805 homebank_pref_get_wingeometry(keyfile
, group
, "Sta", &PREFS
->sta_wg
);
806 homebank_pref_get_wingeometry(keyfile
, group
, "Tme", &PREFS
->tme_wg
);
807 homebank_pref_get_wingeometry(keyfile
, group
, "Ove", &PREFS
->ove_wg
);
808 homebank_pref_get_wingeometry(keyfile
, group
, "Bud", &PREFS
->bud_wg
);
809 homebank_pref_get_wingeometry(keyfile
, group
, "Car", &PREFS
->cst_wg
);
811 homebank_pref_get_wingeometry(keyfile
, group
, "Txn", &PREFS
->txn_wg
);
813 if(version
<= 7) //set maximize to 0
824 homebank_pref_get_integer(keyfile
, group
, "WalVPaned", &PREFS
->wal_vpaned
);
825 homebank_pref_get_integer(keyfile
, group
, "WalHPaned", &PREFS
->wal_hpaned
);
826 homebank_pref_get_boolean(keyfile
, group
, "WalToolbar", &PREFS
->wal_toolbar
);
827 homebank_pref_get_boolean(keyfile
, group
, "WalSpending", &PREFS
->wal_spending
);
828 homebank_pref_get_boolean(keyfile
, group
, "WalUpcoming", &PREFS
->wal_upcoming
);
833 DB( g_print(" -> ** Panels\n") );
835 homebank_pref_get_short(keyfile
, group
, "AccColAccW", &PREFS
->pnl_acc_col_acc_width
);
836 homebank_pref_get_short(keyfile
, group
, "AccShowBy" , &PREFS
->pnl_acc_show_by
);
838 homebank_pref_get_short(keyfile
, group
, "UpcColPayW", &PREFS
->pnl_upc_col_pay_width
);
839 homebank_pref_get_short(keyfile
, group
, "UpcColMemW", &PREFS
->pnl_upc_col_mem_width
);
844 DB( g_print(" -> ** Format\n") );
846 homebank_pref_get_string(keyfile
, group
, "DateFmt", &PREFS
->date_format
);
850 gboolean useimperial
;
852 homebank_pref_get_boolean(keyfile
, group
, "UKUnits", &useimperial
);
855 PREFS
->vehicle_unit_ismile
= TRUE
;
856 PREFS
->vehicle_unit_isgal
= TRUE
;
860 homebank_pref_get_boolean(keyfile
, group
, "UnitIsMile", &PREFS
->vehicle_unit_ismile
);
861 homebank_pref_get_boolean(keyfile
, group
, "UnitIsGal", &PREFS
->vehicle_unit_isgal
);
866 DB( g_print(" -> ** Filter\n") );
868 homebank_pref_get_integer(keyfile
, group
, "DateRangeWal", &PREFS
->date_range_wal
);
869 homebank_pref_get_integer(keyfile
, group
, "DateRangeTxn", &PREFS
->date_range_txn
);
870 homebank_pref_get_integer(keyfile
, group
, "DateFutureNbDays", &PREFS
->date_future_nbdays
);
871 homebank_pref_get_integer(keyfile
, group
, "DateRangeRep", &PREFS
->date_range_rep
);
875 // shift date range >= 5, since we inserted a new one at position 5
876 if(PREFS
->date_range_wal
>= FLT_RANGE_LASTYEAR
)
877 PREFS
->date_range_wal
++;
878 if(PREFS
->date_range_txn
>= FLT_RANGE_LASTYEAR
)
879 PREFS
->date_range_txn
++;
880 if(PREFS
->date_range_rep
>= FLT_RANGE_LASTYEAR
)
881 PREFS
->date_range_rep
++;
887 DB( g_print(" -> ** Euro\n") );
889 //homebank_pref_get_string(keyfile, group, "DefCurrency" , &PREFS->curr_default);
891 homebank_pref_get_boolean(keyfile
, group
, "Active", &PREFS
->euro_active
);
892 homebank_pref_get_integer(keyfile
, group
, "Country", &PREFS
->euro_country
);
894 gchar
*ratestr
= g_key_file_get_string (keyfile
, group
, "ChangeRate", NULL
);
895 if(ratestr
!= NULL
) PREFS
->euro_value
= g_ascii_strtod(ratestr
, NULL
);
899 homebank_pref_get_string(keyfile
, group
, "Symbol", &PREFS
->minor_cur
.symbol
);
900 PREFS
->minor_cur
.frac_digits
= g_key_file_get_integer (keyfile
, group
, "NBDec", NULL
);
902 //PREFS->euro_nbdec = g_key_file_get_integer (keyfile, group, "NBDec", NULL);
903 //PREFS->euro_thsep = g_key_file_get_boolean (keyfile, group, "Sep", NULL);
904 //gchar *tmpstr = g_key_file_get_string (keyfile, group, "Symbol", &error);
910 gchar
*prefix
= NULL
;
911 gchar
*suffix
= NULL
;
913 homebank_pref_get_string(keyfile
, group
, "PreSymbol", &prefix
);
914 homebank_pref_get_string(keyfile
, group
, "SufSymbol", &suffix
);
915 homebank_pref_currfmt_convert(&PREFS
->minor_cur
, prefix
, suffix
);
921 homebank_pref_get_string(keyfile
, group
, "Symbol", &PREFS
->minor_cur
.symbol
);
922 homebank_pref_get_boolean(keyfile
, group
, "IsPrefix", &PREFS
->minor_cur
.sym_prefix
);
924 homebank_pref_get_string(keyfile
, group
, "DecChar" , &PREFS
->minor_cur
.decimal_char
);
925 homebank_pref_get_string(keyfile
, group
, "GroupChar", &PREFS
->minor_cur
.grouping_char
);
926 homebank_pref_get_short(keyfile
, group
, "FracDigits", &PREFS
->minor_cur
.frac_digits
);
929 if( PREFS
->minor_cur
.frac_digits
> MAX_FRAC_DIGIT
)
930 PREFS
->minor_cur
.frac_digits
= MAX_FRAC_DIGIT
;
932 da_cur_initformat(&PREFS
->minor_cur
);
935 //PREFS->euro_symbol = g_locale_to_utf8(tmpstr, -1, NULL, NULL, NULL);
939 DB( g_print(" -> ** Report\n") );
941 homebank_pref_get_boolean(keyfile
, group
, "StatByAmount", &PREFS
->stat_byamount
);
942 homebank_pref_get_boolean(keyfile
, group
, "StatDetail", &PREFS
->stat_showdetail
);
943 homebank_pref_get_boolean(keyfile
, group
, "StatRate", &PREFS
->stat_showrate
);
944 homebank_pref_get_boolean(keyfile
, group
, "BudgDetail", &PREFS
->budg_showdetail
);
945 homebank_pref_get_integer(keyfile
, group
, "ColorScheme", &PREFS
->report_color_scheme
);
949 DB( g_print(" -> ** Exchange\n") );
951 //homebank_pref_get_boolean(keyfile, group, "DoIntro", &PREFS->dtex_nointro);
952 homebank_pref_get_integer(keyfile
, group
, "DateFmt", &PREFS
->dtex_datefmt
);
953 homebank_pref_get_integer(keyfile
, group
, "OfxName", &PREFS
->dtex_ofxname
);
954 homebank_pref_get_integer(keyfile
, group
, "OfxMemo", &PREFS
->dtex_ofxmemo
);
955 homebank_pref_get_boolean(keyfile
, group
, "QifMemo", &PREFS
->dtex_qifmemo
);
956 homebank_pref_get_boolean(keyfile
, group
, "QifSwap", &PREFS
->dtex_qifswap
);
960 //PREFS->chart_legend = g_key_file_get_boolean (keyfile, group, "Legend", NULL);
965 DB( g_print(" -> ** Plugins\n") );
967 gchar
** strv
= g_key_file_get_string_list(keyfile
, group
, "Path", NULL
, NULL
);
969 g_strfreev(PREFS
->ext_path
);
970 PREFS
->ext_path
= strv
;
973 strv
= g_key_file_get_string_list(keyfile
, group
, "Whitelist", NULL
, NULL
);
976 for (it
= strv
; it
&& *it
; ++it
) {
977 PREFS
->ext_whitelist
= g_list_append(PREFS
->ext_whitelist
, g_strdup(*it
));
987 gchar *contents = g_key_file_to_data (keyfile, &length, NULL);
988 //g_print(" keyfile:\n%s\n len=%d\n", contents, length);
995 g_key_file_free (keyfile
);
997 _homebank_pref_init_measurement_units();
1003 static void homebank_pref_set_string(
1005 const gchar
*group_name
,
1010 DB( g_print(" - homebank_pref_set_string :: group='%s' key='%s' value='%s'\n", group_name
, key
, string
) );
1012 if( string
!= NULL
&& *string
!= '\0')
1013 g_key_file_set_string (key_file
, group_name
, key
, string
);
1015 g_key_file_set_string (key_file
, group_name
, key
, "");
1021 ** save preference to homedir/.homebank (HB_DATA_PATH)
1023 gboolean
homebank_pref_save(void)
1026 gboolean retval
= FALSE
;
1027 gchar
*group
, *filename
;
1030 DB( g_print("\n[preferences] pref save\n") );
1032 keyfile
= g_key_file_new();
1036 DB( g_print(" -> ** general\n") );
1040 g_key_file_set_integer (keyfile
, group
, "Version", PREF_VERSION
);
1042 homebank_pref_set_string (keyfile
, group
, "Language", PREFS
->language
);
1044 g_key_file_set_integer (keyfile
, group
, "BarStyle", PREFS
->toolbar_style
);
1045 //g_key_file_set_integer (keyfile, group, "BarImageSize", PREFS->image_size);
1047 g_key_file_set_boolean (keyfile
, group
, "CustomColors", PREFS
->custom_colors
);
1048 g_key_file_set_string (keyfile
, group
, "ColorExp" , PREFS
->color_exp
);
1049 g_key_file_set_string (keyfile
, group
, "ColorInc" , PREFS
->color_inc
);
1050 g_key_file_set_string (keyfile
, group
, "ColorWarn", PREFS
->color_warn
);
1052 g_key_file_set_integer (keyfile
, group
, "GridLines", PREFS
->grid_lines
);
1054 homebank_pref_set_string (keyfile
, group
, "WalletPath" , PREFS
->path_hbfile
);
1055 homebank_pref_set_string (keyfile
, group
, "ImportPath" , PREFS
->path_import
);
1056 homebank_pref_set_string (keyfile
, group
, "ExportPath" , PREFS
->path_export
);
1057 //g_key_file_set_string (keyfile, group, "NavigatorPath", PREFS->path_navigator);
1059 g_key_file_set_boolean (keyfile
, group
, "ShowSplash", PREFS
->showsplash
);
1060 g_key_file_set_boolean (keyfile
, group
, "LoadLast", PREFS
->loadlast
);
1061 g_key_file_set_boolean (keyfile
, group
, "AppendScheduled", PREFS
->appendscheduled
);
1062 g_key_file_set_boolean (keyfile
, group
, "UpdateCurrency", PREFS
->do_update_currency
);
1064 g_key_file_set_boolean (keyfile
, group
, "HeritDate", PREFS
->heritdate
);
1065 g_key_file_set_boolean (keyfile
, group
, "HideReconciled", PREFS
->hidereconciled
);
1066 g_key_file_set_boolean (keyfile
, group
, "ShowRemind", PREFS
->showremind
);
1068 g_key_file_set_integer_list(keyfile
, group
, "ColumnsOpe", PREFS
->lst_ope_columns
, NUM_LST_DSPOPE
-1);
1069 g_key_file_set_integer_list(keyfile
, group
, "ColumnsOpeWidth", PREFS
->lst_ope_col_size
, NUM_LST_DSPOPE
-1);
1070 g_key_file_set_integer (keyfile
, group
, "OpeSortId" , PREFS
->lst_ope_sort_id
);
1071 g_key_file_set_integer (keyfile
, group
, "OpeSortOrder" , PREFS
->lst_ope_sort_order
);
1073 g_key_file_set_integer (keyfile
, group
, "FiscYearDay" , PREFS
->fisc_year_day
);
1074 g_key_file_set_integer (keyfile
, group
, "FiscYearMonth" , PREFS
->fisc_year_month
);
1077 DB( g_print(" -> ** windows\n") );
1080 g_key_file_set_integer_list(keyfile
, group
, "Wal", (gint
*)&PREFS
->wal_wg
, 5);
1081 g_key_file_set_integer_list(keyfile
, group
, "Acc", (gint
*)&PREFS
->acc_wg
, 5);
1082 g_key_file_set_integer_list(keyfile
, group
, "Sta", (gint
*)&PREFS
->sta_wg
, 5);
1083 g_key_file_set_integer_list(keyfile
, group
, "Tme", (gint
*)&PREFS
->tme_wg
, 5);
1084 g_key_file_set_integer_list(keyfile
, group
, "Ove", (gint
*)&PREFS
->ove_wg
, 5);
1085 g_key_file_set_integer_list(keyfile
, group
, "Bud", (gint
*)&PREFS
->bud_wg
, 5);
1086 g_key_file_set_integer_list(keyfile
, group
, "Car", (gint
*)&PREFS
->cst_wg
, 5);
1088 g_key_file_set_integer_list(keyfile
, group
, "Txn", (gint
*)&PREFS
->txn_wg
, 5);
1090 g_key_file_set_integer (keyfile
, group
, "WalVPaned" , PREFS
->wal_vpaned
);
1091 g_key_file_set_integer (keyfile
, group
, "WalHPaned" , PREFS
->wal_hpaned
);
1092 g_key_file_set_boolean (keyfile
, group
, "WalToolbar", PREFS
->wal_toolbar
);
1093 g_key_file_set_boolean (keyfile
, group
, "WalSpending", PREFS
->wal_spending
);
1094 g_key_file_set_boolean (keyfile
, group
, "WalUpcoming", PREFS
->wal_upcoming
);
1097 DB( g_print(" -> ** Panels\n") );
1100 g_key_file_set_integer(keyfile
, group
, "AccColAccW", PREFS
->pnl_acc_col_acc_width
);
1101 g_key_file_set_integer(keyfile
, group
, "AccShowBy" , PREFS
->pnl_acc_show_by
);
1103 g_key_file_set_integer(keyfile
, group
, "UpcColPayW", PREFS
->pnl_upc_col_pay_width
);
1104 g_key_file_set_integer(keyfile
, group
, "UpcColMemW", PREFS
->pnl_upc_col_mem_width
);
1107 DB( g_print(" -> ** format\n") );
1110 homebank_pref_set_string (keyfile
, group
, "DateFmt" , PREFS
->date_format
);
1112 //g_key_file_set_boolean (keyfile, group, "UKUnits" , PREFS->imperial_unit);
1113 g_key_file_set_boolean (keyfile
, group
, "UnitIsMile" , PREFS
->vehicle_unit_ismile
);
1114 g_key_file_set_boolean (keyfile
, group
, "UnitIsGal" , PREFS
->vehicle_unit_isgal
);
1117 DB( g_print(" -> ** filter\n") );
1120 g_key_file_set_integer (keyfile
, group
, "DateRangeWal", PREFS
->date_range_wal
);
1121 g_key_file_set_integer (keyfile
, group
, "DateRangeTxn", PREFS
->date_range_txn
);
1122 g_key_file_set_integer (keyfile
, group
, "DateFutureNbdays", PREFS
->date_future_nbdays
);
1123 g_key_file_set_integer (keyfile
, group
, "DateRangeRep", PREFS
->date_range_rep
);
1125 DB( g_print(" -> ** euro\n") );
1130 //homebank_pref_set_string(keyfile, group, "DefCurrency" , PREFS->curr_default);
1132 g_key_file_set_boolean (keyfile
, group
, "Active" , PREFS
->euro_active
);
1133 if( PREFS
->euro_active
)
1135 g_key_file_set_integer (keyfile
, group
, "Country", PREFS
->euro_country
);
1137 g_ascii_dtostr(ratestr
, 63, PREFS
->euro_value
);
1138 homebank_pref_set_string (keyfile
, group
, "ChangeRate", ratestr
);
1139 homebank_pref_set_string (keyfile
, group
, "Symbol" , PREFS
->minor_cur
.symbol
);
1140 g_key_file_set_boolean (keyfile
, group
, "IsPrefix" , PREFS
->minor_cur
.sym_prefix
);
1141 homebank_pref_set_string (keyfile
, group
, "DecChar" , PREFS
->minor_cur
.decimal_char
);
1142 homebank_pref_set_string (keyfile
, group
, "GroupChar" , PREFS
->minor_cur
.grouping_char
);
1143 g_key_file_set_integer (keyfile
, group
, "FracDigits", PREFS
->minor_cur
.frac_digits
);
1147 DB( g_print(" -> ** report\n") );
1150 g_key_file_set_boolean (keyfile
, group
, "StatByAmount", PREFS
->stat_byamount
);
1151 g_key_file_set_boolean (keyfile
, group
, "StatDetail" , PREFS
->stat_showdetail
);
1152 g_key_file_set_boolean (keyfile
, group
, "StatRate" , PREFS
->stat_showrate
);
1153 g_key_file_set_boolean (keyfile
, group
, "BudgDetail" , PREFS
->budg_showdetail
);
1154 g_key_file_set_integer (keyfile
, group
, "ColorScheme" , PREFS
->report_color_scheme
);
1158 //g_key_file_set_boolean (keyfile, group, "DoIntro", PREFS->dtex_nointro);
1159 g_key_file_set_integer (keyfile
, group
, "DateFmt", PREFS
->dtex_datefmt
);
1160 g_key_file_set_integer (keyfile
, group
, "OfxName", PREFS
->dtex_ofxname
);
1161 g_key_file_set_integer (keyfile
, group
, "OfxMemo", PREFS
->dtex_ofxmemo
);
1162 g_key_file_set_boolean (keyfile
, group
, "QifMemo", PREFS
->dtex_qifmemo
);
1163 g_key_file_set_boolean (keyfile
, group
, "QifSwap", PREFS
->dtex_qifswap
);
1167 //g_key_file_set_boolean (keyfile, group, "Legend", PREFS->chart_legend);
1171 g_key_file_set_string_list(keyfile
, group
, "Path", (const gchar
* const*)PREFS
->ext_path
, g_strv_length(PREFS
->ext_path
));
1173 gsize len
= g_list_length(PREFS
->ext_whitelist
);
1174 gchar
** strv
= g_new0(gchar
*, len
+ 1);
1177 for (i
= 0; i
< len
; ++i
) {
1178 strv
[i
] = g_list_nth_data(PREFS
->ext_whitelist
, i
);
1180 g_key_file_set_string_list(keyfile
, group
, "Whitelist", (const gchar
* const*)strv
, len
);
1184 //g_key_file_set_string (keyfile, group, "", PREFS->);
1185 //g_key_file_set_boolean (keyfile, group, "", PREFS->);
1186 //g_key_file_set_integer (keyfile, group, "", PREFS->);
1188 DB( g_print(" -> ** g_key_file_to_data\n") );
1190 gchar
*contents
= g_key_file_to_data (keyfile
, &length
, NULL
);
1192 //DB( g_print(" keyfile:\n%s\nlen=%d\n", contents, length) );
1194 filename
= g_build_filename(homebank_app_get_config_dir(), "preferences", NULL
);
1196 DB( g_print(" -> filename: %s\n", filename
) );
1198 g_file_set_contents(filename
, contents
, length
, NULL
);
1200 DB( g_print(" -> contents: %s\n", contents
) );
1202 DB( g_print(" -> freeing filename\n") );
1205 DB( g_print(" -> freeing buffer\n") );
1209 DB( g_print(" -> freeing keyfile\n") );
1211 g_key_file_free (keyfile
);
1214 _homebank_pref_init_measurement_units();