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