~ubuntu-branches/debian/experimental/homebank/experimental

« back to all changes in this revision

Viewing changes to src/preferences.c

  • Committer: Bazaar Package Importer
  • Author(s): Francesco Namuri
  • Date: 2008-04-07 16:20:53 UTC
  • mfrom: (1.2.1 upstream) (2.1.5 hardy)
  • Revision ID: james.westby@ubuntu.com-20080407162053-uyoaw9ba5u6swbps
Tags: 3.8-1
* New upstream release.
* debian-copyright: updated copyright information. 
* debian/changelog: applied patch to sync with ubuntu's changelog. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  HomeBank -- Free, easy, personal accounting for everyone.
 
2
 *  Copyright (C) 1995-2008 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
#include "homebank.h"
 
21
#include "preferences.h"
 
22
#include "def_pref.h"
 
23
 
 
24
/****************************************************************************/
 
25
/* Debug macros                                                             */
 
26
/****************************************************************************/
 
27
#define MYDEBUG 0
 
28
 
 
29
#if MYDEBUG
 
30
#define DB(x) (x);
 
31
#else
 
32
#define DB(x);
 
33
#endif
 
34
 
 
35
/* our global datas */
 
36
extern struct HomeBank *GLOBALS;
 
37
extern struct Preferences *PREFS;
 
38
 
 
39
 
 
40
static void homebank_pref_init_monetary(void)
 
41
{
 
42
        DB( g_print("(preferences) monetary\n") );
 
43
 
 
44
 
 
45
#ifdef G_OS_UNIX
 
46
 
 
47
struct lconv *lc = localeconv();
 
48
 
 
49
        DB( g_print("(preferences) monetary unix\n") );
 
50
 
 
51
        DB( g_print("mon_decimal_point '%s'\n", lc->mon_decimal_point) );
 
52
        DB( g_print("mon_thousands_sep '%s'\n", lc->mon_thousands_sep) );
 
53
 
 
54
        DB( g_print("frac_digits '%d'\n", (gint)lc->frac_digits) );
 
55
 
 
56
        DB( g_print("currency_symbol '%s'\n", lc->currency_symbol) );
 
57
 
 
58
        DB( g_print("p_cs_precedes '%d'\n", lc->p_cs_precedes) );
 
59
 
 
60
        DB( g_print("n_cs_precedes '%d'\n", lc->n_cs_precedes) );
 
61
 
 
62
 
 
63
        
 
64
        if( lc->p_cs_precedes || lc->n_cs_precedes )
 
65
        {
 
66
                PREFS->base_cur.prefix_symbol = g_strdup(lc->currency_symbol);
 
67
                PREFS->base_cur.suffix_symbol = g_strdup("");
 
68
                DB( g_print("locale mon cs is a prefix\n") );
 
69
        }
 
70
        else
 
71
        {
 
72
                PREFS->base_cur.prefix_symbol = g_strdup("");
 
73
                PREFS->base_cur.suffix_symbol = g_strdup(lc->currency_symbol);
 
74
        }
 
75
 
 
76
        PREFS->base_cur.decimal_char  = g_strdup(lc->mon_decimal_point);        
 
77
        PREFS->base_cur.grouping_char = g_strdup(lc->mon_thousands_sep);        
 
78
        PREFS->base_cur.frac_digits   = lc->frac_digits;
 
79
 
 
80
 
 
81
#else
 
82
        #ifdef G_OS_WIN32
 
83
        //todo: to be really set by a win32 specialist from the registry...
 
84
        
 
85
        PREFS->base_cur.prefix_symbol = g_strdup("");;
 
86
        PREFS->base_cur.suffix_symbol = g_strdup("");;
 
87
        PREFS->base_cur.decimal_char  = g_strdup(".");
 
88
        PREFS->base_cur.grouping_char = g_strdup("");;
 
89
        PREFS->base_cur.frac_digits   = 2;
 
90
        #else
 
91
        PREFS->base_cur.prefix_symbol = g_strdup("");;
 
92
        PREFS->base_cur.suffix_symbol = g_strdup("");;
 
93
        PREFS->base_cur.decimal_char  = g_strdup(".");
 
94
        PREFS->base_cur.grouping_char = g_strdup("");;
 
95
        PREFS->base_cur.frac_digits   = 2;
 
96
        #endif
 
97
#endif
 
98
        
 
99
}
 
100
 
 
101
 
 
102
static void homebank_pref_update_to_tango_colors(void)
 
103
{
 
104
        if(PREFS->color_exp == OLD_EXP_COLOR)
 
105
                PREFS->color_exp = DEFAULT_EXP_COLOR;
 
106
 
 
107
        if(PREFS->color_inc == OLD_INC_COLOR)
 
108
                PREFS->color_inc  = DEFAULT_INC_COLOR;
 
109
        
 
110
        if(PREFS->color_warn == OLD_WARN_COLOR)
 
111
                PREFS->color_warn = DEFAULT_WARN_COLOR;
 
112
 
 
113
}
 
114
 
 
115
static void homebank_pref_init_wingeometry(struct WinGeometry *wg, gint l, gint t, gint w, gint h)
 
116
{
 
117
        wg->l = l;
 
118
        wg->t = t;
 
119
        wg->w = w;
 
120
        wg->h = h;
 
121
}
 
122
 
 
123
 
 
124
void homebank_pref_free(void)
 
125
{
 
126
        DB( g_print("(preferences) free\n") );
 
127
 
 
128
 
 
129
        g_free(PREFS->date_format);
 
130
 
 
131
        g_free(PREFS->path_wallet);
 
132
        g_free(PREFS->path_import);
 
133
        //g_free(PREFS->path_navigator);
 
134
 
 
135
        g_free(PREFS->base_cur.prefix_symbol);
 
136
        g_free(PREFS->base_cur.suffix_symbol);
 
137
        g_free(PREFS->base_cur.decimal_char);   
 
138
        g_free(PREFS->base_cur.grouping_char);  
 
139
 
 
140
        g_free(PREFS->minor_cur.prefix_symbol);
 
141
        g_free(PREFS->minor_cur.suffix_symbol);
 
142
        g_free(PREFS->minor_cur.decimal_char);  
 
143
        g_free(PREFS->minor_cur.grouping_char); 
 
144
 
 
145
        memset(PREFS, 0, sizeof(struct Preferences));
 
146
}
 
147
 
 
148
 
 
149
void homebank_pref_setdefault(void)
 
150
{
 
151
 
 
152
        DB( g_print("(preferences) pref init\n") );
 
153
 
 
154
        homebank_pref_free();
 
155
 
 
156
        PREFS->date_format = g_strdup(DEFAULT_FORMAT_DATE);
 
157
 
 
158
        PREFS->path_wallet = g_strdup_printf("%s", g_get_home_dir ());
 
159
        PREFS->path_import = g_strdup_printf("%s", g_get_home_dir ());
 
160
        //PREFS->path_navigator = g_strdup(DEFAULT_PATH_NAVIGATOR);
 
161
 
 
162
 
 
163
        PREFS->color_exp  = DEFAULT_EXP_COLOR;
 
164
        PREFS->color_inc  = DEFAULT_INC_COLOR;
 
165
        PREFS->color_warn = DEFAULT_WARN_COLOR;
 
166
 
 
167
        //PREFS->runwizard = TRUE;
 
168
 
 
169
        DB( g_print(" + #%x\n", PREFS->color_exp) );
 
170
        DB( g_print(" + #%x\n", PREFS->color_inc) );
 
171
        DB( g_print(" + #%x\n", PREFS->color_warn) );
 
172
 
 
173
        /* windows position/size */
 
174
        homebank_pref_init_wingeometry(&PREFS->wal_wg, 0, 0, 640, 480);
 
175
        homebank_pref_init_wingeometry(&PREFS->acc_wg, 0, 0, 640, 480);
 
176
        homebank_pref_init_wingeometry(&PREFS->sta_wg, 0, 0, 640, 480);
 
177
        homebank_pref_init_wingeometry(&PREFS->ove_wg, 0, 0, 640, 480);
 
178
        homebank_pref_init_wingeometry(&PREFS->bud_wg, 0, 0, 640, 480);
 
179
        homebank_pref_init_wingeometry(&PREFS->car_wg, 0, 0, 640, 480);
 
180
 
 
181
        PREFS->acc_wg.l = 20;
 
182
        PREFS->acc_wg.t = 20;
 
183
        PREFS->acc_wg.w = 640;
 
184
        PREFS->acc_wg.h = 480;
 
185
 
 
186
        homebank_pref_init_monetary();
 
187
 
 
188
        PREFS->lst_ope_columns[COL_OPE_STATUS] = TRUE;
 
189
        PREFS->lst_ope_columns[COL_OPE_DATE] = TRUE;
 
190
        PREFS->lst_ope_columns[COL_OPE_INFO] = TRUE;
 
191
        PREFS->lst_ope_columns[COL_OPE_PAYEE] = TRUE;
 
192
        PREFS->lst_ope_columns[COL_OPE_WORDING] = TRUE;
 
193
        PREFS->lst_ope_columns[COL_OPE_AMOUNT] = FALSE;
 
194
        PREFS->lst_ope_columns[COL_OPE_EXPENSE] = TRUE;
 
195
        PREFS->lst_ope_columns[COL_OPE_INCOME] = TRUE;
 
196
        PREFS->lst_ope_columns[COL_OPE_CATEGORY] = TRUE;
 
197
 
 
198
        //PREFS->base_cur.nbdecimal = 2;
 
199
        //PREFS->base_cur.separator = TRUE;
 
200
 
 
201
        PREFS->filter_range = 7;
 
202
 
 
203
 
 
204
        //todo: add intelligence here
 
205
        PREFS->euro_active  = FALSE;
 
206
        
 
207
        //todo add intelligence here
 
208
        PREFS->minor_cur.prefix_symbol = g_strdup("");
 
209
        PREFS->minor_cur.suffix_symbol = g_strdup("??");
 
210
        PREFS->minor_cur.decimal_char  = g_strdup("."); 
 
211
        PREFS->minor_cur.grouping_char = g_strdup(" ");
 
212
        PREFS->minor_cur.frac_digits   = 2;
 
213
 
 
214
        
 
215
        PREFS->euro_country = 0;
 
216
        PREFS->euro_value   = 1.0;
 
217
        //PREFS->euro_nbdec   = 2;
 
218
        //PREFS->euro_thsep   = TRUE;
 
219
        //PREFS->euro_symbol    = g_strdup("??");
 
220
 
 
221
        PREFS->stat_byamount   = FALSE;
 
222
        PREFS->stat_showdetail = FALSE;
 
223
        PREFS->stat_showrate   = FALSE;
 
224
        PREFS->budg_showdetail = FALSE;
 
225
 
 
226
        PREFS->chart_legend = FALSE;
 
227
 
 
228
}
 
229
 
 
230
/*
 
231
** create the format string for monetary strfmon (major/minor)
 
232
*/
 
233
void homebank_pref_createformat(void)
 
234
{
 
235
 
 
236
        DB( g_print("(preferences) pref create format\n") );
 
237
 
 
238
/*
 
239
        if(PREFS->base_cur.grouping_char != NULL)
 
240
                g_snprintf(GLOBALS->fmt_maj_number, 15, "%%^.%dn", PREFS->base_cur.frac_digits);
 
241
        else
 
242
                g_snprintf(GLOBALS->fmt_maj_number, 15, "%%.%dn", PREFS->base_cur.frac_digits);
 
243
 
 
244
        DB( g_print("+ major is: '%s'\n", GLOBALS->fmt_maj_number) );
 
245
 
 
246
 
 
247
        if(PREFS->minor_cur.grouping_char != NULL)
 
248
                g_snprintf(GLOBALS->fmt_min_number, 15, "%s %%!^.%dn %s",
 
249
                        PREFS->minor_cur.prefix_symbol,
 
250
                        PREFS->minor_cur.frac_digits,
 
251
                        PREFS->minor_cur.suffix_symbol
 
252
                        );
 
253
        else
 
254
                g_snprintf(GLOBALS->fmt_min_number, 15, "%s %%!.%dn %s",
 
255
                        PREFS->minor_cur.prefix_symbol,
 
256
                        PREFS->minor_cur.frac_digits,
 
257
                        PREFS->minor_cur.suffix_symbol
 
258
                        );
 
259
 
 
260
        DB( g_print("+ minor is: '%s'\n", GLOBALS->fmt_min_number) );
 
261
*/
 
262
        /* new fmt */
 
263
        g_snprintf(PREFS->base_cur.format , 8-1, "%%.%df", PREFS->base_cur.frac_digits);
 
264
        g_snprintf(PREFS->minor_cur.format, 8-1, "%%.%df", PREFS->minor_cur.frac_digits);
 
265
 
 
266
}
 
267
 
 
268
/*
 
269
** load preference from homedir/.homebank
 
270
*/
 
271
static void homebank_pref_get_wingeometry(
 
272
        GKeyFile *key_file,
 
273
    const gchar *group_name,
 
274
    const gchar *key,
 
275
        struct WinGeometry *storage)
 
276
{
 
277
        if( g_key_file_has_key(key_file, group_name, key, NULL) )
 
278
        {
 
279
        gint *wg;
 
280
        gsize length;
 
281
        
 
282
                wg = g_key_file_get_integer_list(key_file, group_name, key, &length, NULL);
 
283
                memcpy(storage, wg, 4*sizeof(gint));
 
284
                g_free(wg);
 
285
        }
 
286
}
 
287
 
 
288
 
 
289
 
 
290
 
 
291
static void homebank_pref_get_boolean(
 
292
        GKeyFile *key_file,
 
293
    const gchar *group_name,
 
294
    const gchar *key,
 
295
        gboolean *storage)
 
296
{
 
297
 
 
298
        if( g_key_file_has_key(key_file, group_name, key, NULL) )
 
299
        {
 
300
                *storage = g_key_file_get_boolean(key_file, group_name, key, NULL);
 
301
        }
 
302
}
 
303
 
 
304
static void homebank_pref_get_integer(
 
305
        GKeyFile *key_file,
 
306
    const gchar *group_name,
 
307
    const gchar *key,
 
308
        gint *storage)
 
309
{
 
310
 
 
311
        if( g_key_file_has_key(key_file, group_name, key, NULL) )
 
312
        {
 
313
                *storage = g_key_file_get_integer(key_file, group_name, key, NULL);
 
314
        }
 
315
}
 
316
 
 
317
static void homebank_pref_get_guint32(
 
318
        GKeyFile *key_file,
 
319
    const gchar *group_name,
 
320
    const gchar *key,
 
321
        guint32 *storage)
 
322
{
 
323
 
 
324
        if( g_key_file_has_key(key_file, group_name, key, NULL) )
 
325
        {
 
326
                *storage = g_key_file_get_integer(key_file, group_name, key, NULL);
 
327
        }
 
328
}
 
329
 
 
330
static void homebank_pref_get_short(
 
331
        GKeyFile *key_file,
 
332
    const gchar *group_name,
 
333
    const gchar *key,
 
334
        gshort *storage)
 
335
{
 
336
 
 
337
        if( g_key_file_has_key(key_file, group_name, key, NULL) )
 
338
        {
 
339
                *storage = (gshort)g_key_file_get_integer(key_file, group_name, key, NULL);
 
340
        }
 
341
}
 
342
 
 
343
static void homebank_pref_get_string(
 
344
        GKeyFile *key_file,
 
345
    const gchar *group_name,
 
346
    const gchar *key,
 
347
        gchar **storage)
 
348
{
 
349
gchar *string;
 
350
 
 
351
        if( g_key_file_has_key(key_file, group_name, key, NULL) )
 
352
        {
 
353
                /* free any previous string */
 
354
                if( *storage != NULL )
 
355
                {
 
356
                        DB( g_print(" storage was not null, freeing\n") );
 
357
                        
 
358
                        g_free(*storage);
 
359
                }
 
360
                
 
361
                *storage = NULL;
 
362
                
 
363
                string = g_key_file_get_string(key_file, group_name, key, NULL);
 
364
                if( string != "" )
 
365
                {
 
366
                        *storage = g_strdup(string);
 
367
                        
 
368
                        DB( g_print(" store '%s' for %s at %x\n", string, key, *storage) );
 
369
                }
 
370
        }
 
371
 
 
372
/*
 
373
        if (error)
 
374
    {
 
375
      g_warning ("error: %s\n", error->message);
 
376
      g_error_free(error);
 
377
      error = NULL;
 
378
    }
 
379
*/
 
380
 
 
381
 
 
382
}
 
383
 
 
384
 
 
385
gboolean homebank_pref_load(void)
 
386
{
 
387
GKeyFile *keyfile;
 
388
gboolean retval = FALSE;
 
389
gchar *group, *filename;
 
390
GError *error = NULL;
 
391
 
 
392
        DB( g_print("(preferences) pref load\n") );
 
393
 
 
394
        keyfile = g_key_file_new();
 
395
        if(keyfile)
 
396
        {
 
397
                filename = g_strdup_printf("%s/.homebank/preferences", g_get_home_dir ());
 
398
                if(g_key_file_load_from_file (keyfile, filename, G_KEY_FILE_NONE, NULL))
 
399
                {
 
400
 
 
401
                        group = "General";
 
402
 
 
403
                                gchar *version = g_key_file_get_string (keyfile, group, "Version", NULL);
 
404
                                DB( g_print(" version: %s\n", version) );
 
405
 
 
406
                                //todo x = strtoul(s, 0, 16); converti une chaine hexa en int
 
407
 
 
408
                                homebank_pref_get_short(keyfile, group, "BarStyle" , &PREFS->toolbar_style);
 
409
                                homebank_pref_get_guint32(keyfile, group, "ColorExp" , &PREFS->color_exp);
 
410
                                homebank_pref_get_guint32(keyfile, group, "ColorInc" , &PREFS->color_inc);
 
411
                                homebank_pref_get_guint32(keyfile, group, "ColorWarn", &PREFS->color_warn);
 
412
 
 
413
                                #if DOWIZARD == 1
 
414
                                homebank_pref_get_boolean(keyfile, group, "RunWizard", &PREFS->runwizard);
 
415
                                #endif
 
416
                                
 
417
                                homebank_pref_get_string(keyfile, group, "WalletPath", &PREFS->path_wallet);
 
418
                                homebank_pref_get_string(keyfile, group, "ImportPath", &PREFS->path_import);
 
419
                                //homebank_pref_get_string(keyfile, group, "NavigatorPath", &PREFS->path_navigator);
 
420
 
 
421
                                
 
422
                                if( g_key_file_has_key(keyfile, group, "ColumnsOpe", NULL) )
 
423
                                {
 
424
                                gint *pos;
 
425
                                gsize length;
 
426
 
 
427
                                        pos = g_key_file_get_boolean_list(keyfile, group, "ColumnsOpe",
 
428
                                                &length, &error);
 
429
 
 
430
                                        if( length == NUM_COL_OPE)
 
431
                                                memcpy(PREFS->lst_ope_columns, pos, length*sizeof(gboolean));
 
432
 
 
433
                                        g_free(pos);
 
434
                                }
 
435
 
 
436
                        group = "Windows";
 
437
 
 
438
                                homebank_pref_get_wingeometry(keyfile, group, "Wal", &PREFS->wal_wg);
 
439
                                homebank_pref_get_wingeometry(keyfile, group, "Acc", &PREFS->acc_wg);
 
440
                                homebank_pref_get_wingeometry(keyfile, group, "Sta", &PREFS->sta_wg);
 
441
                                homebank_pref_get_wingeometry(keyfile, group, "Ove", &PREFS->ove_wg);
 
442
                                homebank_pref_get_wingeometry(keyfile, group, "Bud", &PREFS->bud_wg);
 
443
                                homebank_pref_get_wingeometry(keyfile, group, "Car", &PREFS->car_wg);
 
444
 
 
445
                        group = "Format";
 
446
 
 
447
                                homebank_pref_get_string(keyfile, group, "DateFmt", &PREFS->date_format);
 
448
                        
 
449
                                if(!strcmp("0.1", version))
 
450
                                {
 
451
                                        //retrieve old 0.1 preferences
 
452
                                        homebank_pref_get_short(keyfile, group, "NumNbDec", &PREFS->base_cur.frac_digits);
 
453
                                        //PREFS->base_cur.separator = g_key_file_get_boolean (keyfile, group, "NumSep", NULL);
 
454
                                }
 
455
                                else
 
456
                                {
 
457
                                        homebank_pref_get_string(keyfile, group, "PreSymbol", &PREFS->base_cur.prefix_symbol);
 
458
                                        homebank_pref_get_string(keyfile, group, "SufSymbol", &PREFS->base_cur.suffix_symbol);
 
459
                                        homebank_pref_get_string(keyfile, group, "DecChar"  , &PREFS->base_cur.decimal_char);
 
460
                                        homebank_pref_get_string(keyfile, group, "GroupChar", &PREFS->base_cur.grouping_char);
 
461
                                        homebank_pref_get_short(keyfile, group, "FracDigits", &PREFS->base_cur.frac_digits);
 
462
                                }
 
463
 
 
464
                                homebank_pref_get_boolean(keyfile, group, "UKUnits", &PREFS->imperial_unit);
 
465
                                
 
466
 
 
467
                        group = "Filter";
 
468
 
 
469
                                homebank_pref_get_integer(keyfile, group, "DefRange", &PREFS->filter_range);
 
470
 
 
471
 
 
472
                        group = "Euro";
 
473
 
 
474
                                homebank_pref_get_boolean(keyfile, group, "Active", &PREFS->euro_active);
 
475
                                homebank_pref_get_integer(keyfile, group, "Country", &PREFS->euro_country);
 
476
 
 
477
                                gchar *ratestr = g_key_file_get_string (keyfile, group, "ChangeRate", NULL);
 
478
                                if(ratestr != NULL) PREFS->euro_value = g_ascii_strtod(ratestr, NULL);
 
479
                                
 
480
                                if(!strcmp("0.1", version))
 
481
                                {
 
482
                                        homebank_pref_get_string(keyfile, group, "Symbol", &PREFS->minor_cur.suffix_symbol);
 
483
                                        PREFS->minor_cur.frac_digits = g_key_file_get_integer (keyfile, group, "NBDec", NULL);
 
484
 
 
485
                                        //PREFS->euro_nbdec = g_key_file_get_integer (keyfile, group, "NBDec", NULL);
 
486
                                        //PREFS->euro_thsep = g_key_file_get_boolean (keyfile, group, "Sep", NULL);
 
487
                                        //gchar *tmpstr = g_key_file_get_string  (keyfile, group, "Symbol", &error);
 
488
                                }
 
489
                                else
 
490
                                {
 
491
                                        homebank_pref_get_string(keyfile, group, "PreSymbol", &PREFS->minor_cur.prefix_symbol);
 
492
                                        homebank_pref_get_string(keyfile, group, "SufSymbol", &PREFS->minor_cur.suffix_symbol);
 
493
                                        homebank_pref_get_string(keyfile, group, "DecChar"  , &PREFS->minor_cur.decimal_char);
 
494
                                        homebank_pref_get_string(keyfile, group, "GroupChar", &PREFS->minor_cur.grouping_char);
 
495
                                        homebank_pref_get_short(keyfile, group, "FracDigits", &PREFS->minor_cur.frac_digits);
 
496
                                }                       
 
497
 
 
498
                        //PREFS->euro_symbol = g_locale_to_utf8(tmpstr, -1, NULL, NULL, NULL);
 
499
 
 
500
                //report options
 
501
                        group = "Report";
 
502
 
 
503
                                homebank_pref_get_boolean(keyfile, group, "StatByAmount", &PREFS->stat_byamount);
 
504
                                homebank_pref_get_boolean(keyfile, group, "StatDetail", &PREFS->stat_showdetail);
 
505
                                homebank_pref_get_boolean(keyfile, group, "StatRate", &PREFS->stat_showrate);
 
506
                                homebank_pref_get_boolean(keyfile, group, "BudgDetail", &PREFS->budg_showdetail);
 
507
                
 
508
 
 
509
                        //group = "Chart";
 
510
                        //PREFS->chart_legend = g_key_file_get_boolean (keyfile, group, "Legend", NULL);
 
511
 
 
512
 
 
513
                        /*
 
514
                        #if MYDEBUG == 1
 
515
                        gsize length;
 
516
                        gchar *contents = g_key_file_to_data (keyfile, &length, NULL);
 
517
                        g_print(" keyfile:\n%s\n len=%d\n", contents, length);
 
518
                        g_free(contents);
 
519
                        #endif
 
520
                        */
 
521
 
 
522
                }
 
523
                g_free(filename);
 
524
                g_key_file_free (keyfile);
 
525
        }
 
526
 
 
527
        /* update to tango ;-) */
 
528
        homebank_pref_update_to_tango_colors();
 
529
 
 
530
        //homebank_pref_createformat();
 
531
 
 
532
        return retval;
 
533
}
 
534
 
 
535
 
 
536
/*
 
537
** save preference to homedir/.homebank
 
538
*/
 
539
gboolean homebank_pref_save(void)
 
540
{
 
541
GKeyFile *keyfile;
 
542
gboolean retval = FALSE;
 
543
gchar *group, *filename;
 
544
guint length;
 
545
 
 
546
        DB( g_print("(preferences) pref save\n") );
 
547
 
 
548
        keyfile = g_key_file_new();
 
549
        if(keyfile )
 
550
        {
 
551
                group = "General";
 
552
                g_key_file_set_string  (keyfile, group, "Version", PREF_VERSION);
 
553
 
 
554
                g_key_file_set_integer (keyfile, group, "BarStyle", PREFS->toolbar_style);
 
555
                //g_key_file_set_integer (keyfile, group, "BarImageSize", PREFS->image_size);
 
556
 
 
557
                g_key_file_set_integer (keyfile, group, "ColorExp" , PREFS->color_exp);
 
558
                g_key_file_set_integer (keyfile, group, "ColorInc" , PREFS->color_inc);
 
559
                g_key_file_set_integer (keyfile, group, "ColorWarn", PREFS->color_warn);
 
560
 
 
561
                #if DOWIZARD == 1
 
562
                g_key_file_set_boolean (keyfile, group, "RunWizard", PREFS->runwizard);
 
563
                #endif
 
564
 
 
565
                g_key_file_set_string  (keyfile, group, "WalletPath"   , PREFS->path_wallet);
 
566
                g_key_file_set_string  (keyfile, group, "ImportPath"   , PREFS->path_import);
 
567
                //g_key_file_set_string  (keyfile, group, "NavigatorPath", PREFS->path_navigator);
 
568
 
 
569
                g_key_file_set_boolean_list(keyfile, group, "ColumnsOpe", PREFS->lst_ope_columns, NUM_COL_OPE);
 
570
 
 
571
                // added v3.4
 
572
                group = "Windows";
 
573
                g_key_file_set_integer_list(keyfile, group, "Wal", (gint *)&PREFS->wal_wg, 4);
 
574
                g_key_file_set_integer_list(keyfile, group, "Acc", (gint *)&PREFS->acc_wg, 4);
 
575
                g_key_file_set_integer_list(keyfile, group, "Sta", (gint *)&PREFS->sta_wg, 4);
 
576
                g_key_file_set_integer_list(keyfile, group, "Ove", (gint *)&PREFS->ove_wg, 4);
 
577
                g_key_file_set_integer_list(keyfile, group, "Bud", (gint *)&PREFS->bud_wg, 4);
 
578
                g_key_file_set_integer_list(keyfile, group, "Car", (gint *)&PREFS->car_wg, 4);
 
579
 
 
580
                group = "Format";
 
581
                g_key_file_set_string  (keyfile, group, "DateFmt"   , PREFS->date_format);
 
582
 
 
583
                g_key_file_set_string  (keyfile, group, "PreSymbol" , PREFS->base_cur.prefix_symbol);
 
584
                g_key_file_set_string  (keyfile, group, "SufSymbol" , PREFS->base_cur.suffix_symbol);
 
585
                g_key_file_set_string  (keyfile, group, "DecChar"   , PREFS->base_cur.decimal_char);
 
586
                g_key_file_set_string  (keyfile, group, "GroupChar" , PREFS->base_cur.grouping_char);
 
587
                g_key_file_set_integer (keyfile, group, "FracDigits", PREFS->base_cur.frac_digits);
 
588
 
 
589
                g_key_file_set_boolean (keyfile, group, "UKUnits" , PREFS->imperial_unit);
 
590
 
 
591
                group = "Filter";
 
592
                g_key_file_set_integer (keyfile, group, "DefRange", PREFS->filter_range);
 
593
 
 
594
        //euro options
 
595
                group = "Euro";
 
596
                g_key_file_set_boolean (keyfile, group, "Active" , PREFS->euro_active);
 
597
                g_key_file_set_integer (keyfile, group, "Country", PREFS->euro_country);
 
598
                gchar ratestr[64];
 
599
                g_ascii_dtostr(ratestr, 63, PREFS->euro_value);
 
600
                g_key_file_set_string  (keyfile, group, "ChangeRate", ratestr);
 
601
                g_key_file_set_string  (keyfile, group, "PreSymbol" , PREFS->minor_cur.prefix_symbol);
 
602
                g_key_file_set_string  (keyfile, group, "SufSymbol" , PREFS->minor_cur.suffix_symbol);
 
603
                g_key_file_set_string  (keyfile, group, "DecChar"   , PREFS->minor_cur.decimal_char);
 
604
                g_key_file_set_string  (keyfile, group, "GroupChar" , PREFS->minor_cur.grouping_char);
 
605
                g_key_file_set_integer (keyfile, group, "FracDigits", PREFS->minor_cur.frac_digits);
 
606
 
 
607
        //report options
 
608
                group = "Report";
 
609
                g_key_file_set_boolean (keyfile, group, "StatByAmount", PREFS->stat_byamount);
 
610
                g_key_file_set_boolean (keyfile, group, "StatDetail"  , PREFS->stat_showdetail);
 
611
                g_key_file_set_boolean (keyfile, group, "StatRate"    , PREFS->stat_showrate);
 
612
                g_key_file_set_boolean (keyfile, group, "BudgDetail"  , PREFS->budg_showdetail);
 
613
 
 
614
                //group = "Chart";
 
615
                //g_key_file_set_boolean (keyfile, group, "Legend", PREFS->chart_legend);
 
616
 
 
617
                //g_key_file_set_string  (keyfile, group, "", PREFS->);
 
618
                //g_key_file_set_boolean (keyfile, group, "", PREFS->);
 
619
                //g_key_file_set_integer (keyfile, group, "", PREFS->);
 
620
 
 
621
                gchar *contents = g_key_file_to_data (keyfile, &length, NULL);
 
622
 
 
623
                //DB( g_print(" keyfile:\n%s\nlen=%d\n", contents, length) );
 
624
 
 
625
                filename = g_strdup_printf("%s/.homebank/preferences", g_get_home_dir ());
 
626
                g_file_set_contents(filename, contents, length, NULL);
 
627
                g_free(filename);
 
628
 
 
629
                g_free(contents);
 
630
                g_key_file_free (keyfile);
 
631
        }
 
632
 
 
633
        return retval;
 
634
}
 
635