]>
Dogcows Code - chaz/homebank/blob - src/hb-hbfile.c
1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2014 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/>.
21 #include "hb-hbfile.h"
22 #include "hb-archive.h"
23 #include "hb-transaction.h"
25 /****************************************************************************/
27 /****************************************************************************/
36 /* our global datas */
37 extern struct HomeBank
*GLOBALS
;
38 extern struct Preferences
*PREFS
;
42 gboolean
hbfile_file_hasbackup(gchar
*filepath
)
46 bakfilepath
= hb_filename_new_with_extention(GLOBALS
->xhb_filepath
, "xhb~");
47 GLOBALS
->xhb_hasbak
= g_file_test(bakfilepath
, G_FILE_TEST_EXISTS
);
49 //todo check here if need to return something
50 return GLOBALS
->xhb_hasbak
;
58 static gint hbfile_file_load_xhb(gchar *filepath)
69 static void hbfile_file_load_backup_xhb(void)
71 //todo: get from dialog.c, and split between dilaog.c/hbfile.c
84 void hbfile_change_basecurrency(guint32 key)
88 list = g_hash_table_get_values(GLOBALS->h_cur);
91 Currency *entry = list->data;
93 if(entry->key != GLOBALS->kcur)
96 list = g_list_next(list);
101 GLOBALS->changes_count++;
108 void hbfile_change_owner(gchar
*owner
)
110 g_free(GLOBALS
->owner
);
111 GLOBALS
->owner
= (owner
!= NULL
) ? owner
: NULL
;
115 void hbfile_change_filepath(gchar
*filepath
)
117 g_free(GLOBALS
->xhb_filepath
);
118 GLOBALS
->xhb_filepath
= (filepath
!= NULL
) ? filepath
: NULL
;
122 void hbfile_sanity_check(void)
126 DB( g_print("\n[hbfile] sanity_check\n") );
129 list
= g_list_first(GLOBALS
->ope_list
);
132 Transaction
*entry
= list
->data
;
134 da_transaction_consistency(entry
);
135 list
= g_list_next(list
);
139 list
= g_list_first(GLOBALS
->arc_list
);
142 Archive
*entry
= list
->data
;
144 da_archive_consistency(entry
);
145 list
= g_list_next(list
);
149 lxxx
= list
= g_hash_table_get_values(GLOBALS
->h_acc
);
152 Account
*item
= list
->data
;
154 da_acc_consistency(item
);
155 list
= g_list_next(list
);
160 lxxx
= list
= g_hash_table_get_values(GLOBALS
->h_pay
);
163 Payee
*item
= list
->data
;
165 da_pay_consistency(item
);
166 list
= g_list_next(list
);
171 lxxx
= list
= g_hash_table_get_values(GLOBALS
->h_cat
);
174 Category
*item
= list
->data
;
176 da_cat_consistency(item
);
177 list
= g_list_next(list
);
184 void hbfile_anonymize(void)
189 DB( g_print("\n[hbfile] anonymize\n") );
192 hbfile_change_owner(g_strdup("An0nym0us"));
193 GLOBALS
->changes_count
++;
194 GLOBALS
->hbfile_is_new
= TRUE
;
197 hbfile_change_filepath(g_build_filename(PREFS
->path_hbfile
, "anonymized.xhb", NULL
));
200 lxxx
= list
= g_hash_table_get_values(GLOBALS
->h_acc
);
203 Account
*item
= list
->data
;
205 item
->name
= g_strdup_printf("account %d", item
->key
);
206 g_free(item
->number
);
208 g_free(item
->bankname
);
209 item
->bankname
= NULL
;
211 GLOBALS
->changes_count
++;
212 list
= g_list_next(list
);
217 lxxx
= list
= g_hash_table_get_values(GLOBALS
->h_pay
);
220 Payee
*item
= list
->data
;
225 item
->name
= g_strdup_printf("payee %d", item
->key
);
226 GLOBALS
->changes_count
++;
228 list
= g_list_next(list
);
233 lxxx
= list
= g_hash_table_get_values(GLOBALS
->h_cat
);
236 Category
*item
= list
->data
;
241 item
->name
= g_strdup_printf("category %d", item
->key
);
242 GLOBALS
->changes_count
++;
244 list
= g_list_next(list
);
249 lxxx
= list
= g_hash_table_get_values(GLOBALS
->h_tag
);
252 Tag
*item
= list
->data
;
257 item
->name
= g_strdup_printf("tag %d", item
->key
);
258 GLOBALS
->changes_count
++;
260 list
= g_list_next(list
);
265 lxxx
= list
= g_hash_table_get_values(GLOBALS
->h_rul
);
268 Assign
*item
= list
->data
;
273 item
->name
= g_strdup_printf("assign %d", item
->key
);
274 GLOBALS
->changes_count
++;
276 list
= g_list_next(list
);
282 list
= g_list_first(GLOBALS
->arc_list
);
285 Archive
*item
= list
->data
;
287 g_free(item
->wording
);
288 item
->wording
= g_strdup_printf("archive %d", cnt
++);
289 GLOBALS
->changes_count
++;
291 //later split anonymize also
293 list
= g_list_next(list
);
297 list
= g_list_first(GLOBALS
->ope_list
);
300 Transaction
*item
= list
->data
;
305 g_free(item
->wording
);
306 item
->wording
= g_strdup_printf("memo %d", item
->date
);
307 GLOBALS
->changes_count
++;
309 if(item
->flags
& OF_SPLIT
)
311 for(i
=0;i
<TXN_MAX_SPLIT
;i
++)
313 split
= item
->splits
[i
];
314 if( split
== NULL
) break;
316 if(split
->memo
!= NULL
)
319 split
->memo
= g_strdup_printf("memo %d", i
);
320 GLOBALS
->changes_count
++;
326 list
= g_list_next(list
);
332 void hbfile_cleanup(gboolean file_clear
)
334 DB( g_print("\n[hbfile] cleanup\n") );
335 DB( g_print("- file clear is %d\n", file_clear
) );
344 g_hash_table_destroy(GLOBALS
->h_memo
);
345 da_archive_destroy(GLOBALS
->arc_list
);
346 da_transaction_destroy(GLOBALS
->ope_list
);
348 hbfile_change_owner(NULL
);
351 hbfile_change_filepath(NULL
);
356 void hbfile_setup(gboolean file_clear
)
359 DB( g_print("\n[hbfile] setup\n") );
360 DB( g_print("- file clear is %d\n", file_clear
) );
362 // Allocate data storage
370 GLOBALS
->h_memo
= g_hash_table_new_full(g_str_hash
, g_str_equal
, (GDestroyNotify
)g_free
, NULL
);
371 GLOBALS
->arc_list
= NULL
;
372 GLOBALS
->ope_list
= NULL
;
375 if(file_clear
== TRUE
)
377 //todo: maybe translate this also
378 hbfile_change_filepath(g_build_filename(PREFS
->path_hbfile
, "untitled.xhb", NULL
));
379 GLOBALS
->hbfile_is_new
= TRUE
;
381 DB( g_print("- path_hbfile is '%s'\n", PREFS
->path_hbfile
) );
382 DB( g_print("- xhb_filepath is '%s'\n", GLOBALS
->xhb_filepath
) );
386 GLOBALS
->hbfile_is_new
= FALSE
;
389 hbfile_change_owner(g_strdup(_("Unknown")));
393 GLOBALS
->vehicle_category
= 0;
395 GLOBALS
->auto_smode
= 1;
396 GLOBALS
->auto_nbdays
= 0;
397 GLOBALS
->auto_weekday
= 1;
399 GLOBALS
->changes_count
= 0;
401 GLOBALS
->xhb_hasbak
= FALSE
;
This page took 0.048779 seconds and 4 git commands to generate.