]>
Dogcows Code - chaz/homebank/blob - src/hb-xml.c
1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2019 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-transaction.h"
28 #include "ui-dialogs.h"
30 /****************************************************************************/
32 /****************************************************************************/
41 /* our global datas */
42 extern struct HomeBank
*GLOBALS
;
43 extern struct Preferences
*PREFS
;
46 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
49 // v0.1 to v0.2 : we must change account reference by making a +1 to its index references
50 static void homebank_upgrade_to_v02(void)
52 GList
*lst_acc
, *lnk_acc
;
54 GHashTable
*h_old_acc
;
57 DB( g_print("\n[hb-xml] homebank_upgrade_to_v02\n") );
59 //keep old hashtable with us
60 h_old_acc
= GLOBALS
->h_acc
;
63 lst_acc
= g_hash_table_get_values(h_old_acc
);
64 lnk_acc
= g_list_first(lst_acc
);
65 while (lnk_acc
!= NULL
)
67 Account
*acc
= lnk_acc
->data
;
73 list
= g_queue_peek_head_link(acc
->txn_queue
);
76 Transaction
*entry
= list
->data
;
79 list
= g_list_next(list
);
81 lnk_acc
= g_list_next(lnk_acc
);
85 //we loose some small memory here
86 g_hash_table_steal_all(h_old_acc
);
88 list
= g_list_first(GLOBALS
->arc_list
);
91 Archive
*entry
= list
->data
;
94 list
= g_list_next(list
);
98 // v0.2 to v0.3 : we must assume categories exists : bugs 303886, 303738
99 static void homebank_upgrade_to_v03(void)
101 GList
*lst_acc
, *lnk_acc
;
104 DB( g_print("\n[hb-xml] homebank_upgrade_to_v03\n") );
106 lst_acc
= g_hash_table_get_values(GLOBALS
->h_acc
);
107 lnk_acc
= g_list_first(lst_acc
);
108 while (lnk_acc
!= NULL
)
110 Account
*acc
= lnk_acc
->data
;
112 list
= g_queue_peek_head_link(acc
->txn_queue
);
115 Transaction
*entry
= list
->data
;
117 da_transaction_consistency(entry
);
118 list
= g_list_next(list
);
120 lnk_acc
= g_list_next(lnk_acc
);
122 g_list_free(lst_acc
);
125 list
= g_list_first(GLOBALS
->arc_list
);
128 Archive
*entry
= list
->data
;
130 da_archive_consistency(entry
);
131 list
= g_list_next(list
);
135 static void homebank_upgrade_to_v04(void)
137 DB( g_print("\n[hb-xml] homebank_upgrade_to_v04\n") );
139 GLOBALS
->arc_list
= da_archive_sort(GLOBALS
->arc_list
);
144 // we must assume kxferacc exists in archives for internal xfer : bug 528923
145 // if not, delete automation from the archive
146 static void homebank_upgrade_to_v05(void)
150 DB( g_print("\n[hb-xml] homebank_upgrade_to_v05\n") );
152 list
= g_list_first(GLOBALS
->arc_list
);
155 Archive
*entry
= list
->data
;
157 da_archive_consistency(entry
);
158 list
= g_list_next(list
);
163 // v0.5 to v0.6 : we must change kxferacc to 0 on non Xfer transactions
165 static void homebank_upgrade_to_v06(void)
167 GList
*lst_acc
, *lnk_acc
;
170 DB( g_print("\n[hb-xml] homebank_upgrade_to_v06\n") );
172 lst_acc
= g_hash_table_get_values(GLOBALS
->h_acc
);
173 lnk_acc
= g_list_first(lst_acc
);
174 while (lnk_acc
!= NULL
)
176 Account
*acc
= lnk_acc
->data
;
178 list
= g_queue_peek_head_link(acc
->txn_queue
);
181 Transaction
*entry
= list
->data
;
182 da_transaction_consistency(entry
);
183 list
= g_list_next(list
);
185 lnk_acc
= g_list_next(lnk_acc
);
187 g_list_free(lst_acc
);
190 list
= g_list_first(GLOBALS
->arc_list
);
193 Archive
*entry
= list
->data
;
194 da_archive_consistency(entry
);
195 list
= g_list_next(list
);
200 // v0.7 AF_BUDGET deleted instead of AF_NOBUDGET
201 static void homebank_upgrade_to_v07(void)
205 DB( g_print("\n[hb-xml] homebank_upgrade_to_v07\n") );
207 lacc
= list
= g_hash_table_get_values(GLOBALS
->h_acc
);
210 Account
*acc
= list
->data
;
212 if( acc
->flags
& AF_OLDBUDGET
) // budget include
214 acc
->flags
&= ~(AF_OLDBUDGET
);
218 acc
->flags
|= AF_NOBUDGET
;
221 list
= g_list_next(list
);
227 static void homebank_upgrade_to_v08(void)
229 GList
*lst_acc
, *lnk_acc
;
232 DB( g_print("\n[hb-xml] homebank_upgrade_to_v08\n") );
234 lst_acc
= g_hash_table_get_values(GLOBALS
->h_acc
);
235 lnk_acc
= g_list_first(lst_acc
);
236 while (lnk_acc
!= NULL
)
238 Account
*acc
= lnk_acc
->data
;
240 list
= g_queue_peek_head_link(acc
->txn_queue
);
243 Transaction
*entry
= list
->data
;
244 da_transaction_consistency(entry
);
245 list
= g_list_next(list
);
247 lnk_acc
= g_list_next(lnk_acc
);
249 g_list_free(lst_acc
);
255 static void homebank_upgrade_to_v10(void)
257 GList
*lst_acc
, *lnk_acc
;
260 DB( g_print("\n[hb-xml] homebank_upgrade_to_v10\n") );
262 lst_acc
= g_hash_table_get_values(GLOBALS
->h_acc
);
263 lnk_acc
= g_list_first(lst_acc
);
264 while (lnk_acc
!= NULL
)
266 Account
*acc
= lnk_acc
->data
;
268 list
= g_queue_peek_head_link(acc
->txn_queue
);
271 Transaction
*entry
= list
->data
;
273 entry
->status
= TXN_STATUS_NONE
;
274 if(entry
->flags
& OF_OLDVALID
)
275 entry
->status
= TXN_STATUS_RECONCILED
;
277 if(entry
->flags
& OF_OLDREMIND
)
278 entry
->status
= TXN_STATUS_REMIND
;
281 entry
->flags
&= ~(OF_OLDVALID
|OF_OLDREMIND
);
283 list
= g_list_next(list
);
285 lnk_acc
= g_list_next(lnk_acc
);
287 g_list_free(lst_acc
);
292 static void homebank_upgrade_to_v11(void)
296 DB( g_print("\n[hb-xml] homebank_upgrade_to_v11\n") );
298 list
= g_list_first(GLOBALS
->arc_list
);
301 Archive
*entry
= list
->data
;
303 entry
->status
= TXN_STATUS_NONE
;
304 if(entry
->flags
& OF_OLDVALID
)
305 entry
->status
= TXN_STATUS_RECONCILED
;
307 if(entry
->flags
& OF_OLDREMIND
)
308 entry
->status
= TXN_STATUS_REMIND
;
311 entry
->flags
&= ~(OF_OLDVALID
|OF_OLDREMIND
);
313 list
= g_list_next(list
);
319 // v0.6 to v0.7 : assign a default currency
320 static void homebank_upgrade_to_v12(void)
322 DB( g_print("\n[hb-xml] homebank_upgrade_to_v12\n") );
324 // set a base currency to the hbfile if not
325 DB( g_print("GLOBALS->kcur %d\n", GLOBALS
->kcur
) );
327 ui_dialog_upgrade_choose_currency();
331 static void homebank_upgrade_to_v12_7(void)
333 GList
*lst_acc
, *lnk_acc
;
335 DB( g_print("\n[hb-xml] homebank_upgrade_to_v12\n") );
337 //#1674045 exclude closed account from everywhere to
338 //keep continuity for user that don't want to change this
339 lst_acc
= g_hash_table_get_values(GLOBALS
->h_acc
);
340 lnk_acc
= g_list_first(lst_acc
);
341 while (lnk_acc
!= NULL
)
343 Account
*acc
= lnk_acc
->data
;
345 if( acc
->flags
& AF_CLOSED
)
347 if( !(acc
->flags
& AF_NOSUMMARY
) )
348 acc
->flags
|= AF_NOSUMMARY
;
349 if( !(acc
->flags
& AF_NOBUDGET
) )
350 acc
->flags
|= AF_NOBUDGET
;
351 if( !(acc
->flags
& AF_NOREPORT
) )
352 acc
->flags
|= AF_NOREPORT
;
354 lnk_acc
= g_list_next(lnk_acc
);
356 g_list_free(lst_acc
);
360 static void homebank_upgrade_to_v13(void)
365 DB( g_print("\n[hb-xml] homebank_upgrade_to_v13\n") );
367 //#1008629 assign a key to each archive
369 tmplist
= g_list_first(GLOBALS
->arc_list
);
370 while (tmplist
!= NULL
)
372 Archive
*item
= tmplist
->data
;
374 item
->key
= newkey
++;
375 tmplist
= g_list_next(tmplist
);
381 // lower v0.6 : we must assume categories/payee exists
382 // and strong link to xfer
384 static void homebank_upgrade_lower_v06(void)
386 GList
*lst_acc
, *lnk_acc
;
391 DB( g_print("\n[hb-xml] homebank_upgrade_lower_v06\n") );
393 lst_acc
= g_hash_table_get_values(GLOBALS
->h_acc
);
394 lnk_acc
= g_list_first(lst_acc
);
395 while (lnk_acc
!= NULL
)
397 Account
*acc
= lnk_acc
->data
;
399 list
= g_queue_peek_head_link(acc
->txn_queue
);
402 Transaction
*entry
= list
->data
;
404 //also strong link internal xfer
405 if(entry
->paymode
== PAYMODE_INTXFER
&& entry
->kxfer
== 0)
407 Transaction
*child
= transaction_old_get_child_transfer(entry
);
410 transaction_xfer_change_to_child(entry
, child
);
414 da_transaction_consistency(entry
);
416 list
= g_list_next(list
);
418 lnk_acc
= g_list_next(lnk_acc
);
420 g_list_free(lst_acc
);
423 lrul
= list
= g_hash_table_get_values(GLOBALS
->h_rul
);
426 Assign
*entry
= list
->data
;
428 cat
= da_cat_get(entry
->kcat
);
431 DB( g_print(" !! fixing cat for rul: %d is unknown\n", entry
->kcat
) );
435 pay
= da_pay_get(entry
->kpay
);
438 DB( g_print(" !! fixing pay for rul: %d is unknown\n", entry
->kpay
) );
443 list
= g_list_next(list
);
449 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
452 static void homebank_load_xml_acc(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
454 Account
*entry
= da_acc_malloc();
457 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
459 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
461 if(!strcmp (attribute_names
[i
], "key" )) { entry
->key
= atoi(attribute_values
[i
]); }
462 else if(!strcmp (attribute_names
[i
], "flags" )) { entry
->flags
= atoi(attribute_values
[i
]); }
463 else if(!strcmp (attribute_names
[i
], "pos" )) { entry
->pos
= atoi(attribute_values
[i
]); }
464 else if(!strcmp (attribute_names
[i
], "type" )) { entry
->type
= atoi(attribute_values
[i
]); }
465 else if(!strcmp (attribute_names
[i
], "curr" )) { entry
->kcur
= atoi(attribute_values
[i
]); }
466 else if(!strcmp (attribute_names
[i
], "name" )) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->name
= g_strdup(attribute_values
[i
]); }
467 else if(!strcmp (attribute_names
[i
], "number" )) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->number
= g_strdup(attribute_values
[i
]); }
468 else if(!strcmp (attribute_names
[i
], "bankname")) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->bankname
= g_strdup(attribute_values
[i
]); }
469 else if(!strcmp (attribute_names
[i
], "initial" )) { entry
->initial
= g_ascii_strtod(attribute_values
[i
], NULL
); }
471 else if(!strcmp (attribute_names
[i
], "minimum" )) { entry
->minimum
= g_ascii_strtod(attribute_values
[i
], NULL
); }
472 else if(!strcmp (attribute_names
[i
], "cheque1" )) { entry
->cheque1
= atoi(attribute_values
[i
]); }
473 else if(!strcmp (attribute_names
[i
], "cheque2" )) { entry
->cheque2
= atoi(attribute_values
[i
]); }
474 else if(!strcmp (attribute_names
[i
], "notes" )) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->notes
= g_strdup(attribute_values
[i
]); }
475 else if(!strcmp (attribute_names
[i
], "tpl" )) { entry
->karc
= atoi(attribute_values
[i
]); }
478 //all attribute loaded: append
479 da_acc_insert(entry
);
483 static void homebank_load_xml_asg(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
485 Assign
*entry
= da_asg_malloc();
489 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
491 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
493 if(!strcmp (attribute_names
[i
], "key" )) { entry
->key
= atoi(attribute_values
[i
]); }
494 else if(!strcmp (attribute_names
[i
], "flags" )) { entry
->flags
= atoi(attribute_values
[i
]); }
495 else if(!strcmp (attribute_names
[i
], "field" )) { entry
->field
= atoi(attribute_values
[i
]); }
496 else if(!strcmp (attribute_names
[i
], "name" )) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->text
= g_strdup(attribute_values
[i
]); }
497 else if(!strcmp (attribute_names
[i
], "payee" )) { entry
->kpay
= atoi(attribute_values
[i
]); }
498 else if(!strcmp (attribute_names
[i
], "category")) { entry
->kcat
= atoi(attribute_values
[i
]); }
499 else if(!strcmp (attribute_names
[i
], "paymode" )) { entry
->paymode
= atoi(attribute_values
[i
]); }
501 else if(!strcmp (attribute_names
[i
], "exact" )) { exact
= atoi(attribute_values
[i
]); }
504 /* in v08 exact moved to flag */
505 if( ctx
->file_version
<= 0.7)
507 entry
->flags
= (ASGF_DOCAT
|ASGF_DOPAY
);
509 entry
->flags
|= ASGF_EXACT
;
512 //all attribute loaded: append
513 da_asg_append(entry
);
518 static void homebank_load_xml_pay(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
520 Payee
*entry
= da_pay_malloc();
523 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
525 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
527 if(!strcmp (attribute_names
[i
], "key" )) { entry
->key
= atoi(attribute_values
[i
]); }
528 //else if(!strcmp (attribute_names[i], "flags")) { entry->flags = atoi(attribute_values[i]); }
529 else if(!strcmp (attribute_names
[i
], "name" )) { entry
->name
= g_strdup(attribute_values
[i
]); }
530 else if(!strcmp (attribute_names
[i
], "category")) { entry
->kcat
= atoi(attribute_values
[i
]); }
531 else if(!strcmp (attribute_names
[i
], "paymode" )) { entry
->paymode
= atoi(attribute_values
[i
]); }
534 //all attribute loaded: append
535 da_pay_insert(entry
);
539 static void homebank_load_xml_prop(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
543 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
545 if(!strcmp (attribute_names
[i
], "title" )) { g_free(GLOBALS
->owner
); GLOBALS
->owner
= g_strdup(attribute_values
[i
]); }
546 else if(!strcmp (attribute_names
[i
], "curr" )) { GLOBALS
->kcur
= atoi(attribute_values
[i
]); }
547 else if(!strcmp (attribute_names
[i
], "car_category")) { GLOBALS
->vehicle_category
= atoi(attribute_values
[i
]); }
548 else if(!strcmp (attribute_names
[i
], "auto_smode" )) { GLOBALS
->auto_smode
= atoi(attribute_values
[i
]); }
549 else if(!strcmp (attribute_names
[i
], "auto_weekday")) { GLOBALS
->auto_weekday
= atoi(attribute_values
[i
]); }
550 else if(!strcmp (attribute_names
[i
], "auto_nbdays" )) { GLOBALS
->auto_nbdays
= atoi(attribute_values
[i
]); }
555 static void homebank_load_xml_cat(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
557 Category
*entry
= da_cat_malloc();
561 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
563 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
565 if(!strcmp (attribute_names
[i
], "key" )) { entry
->key
= atoi(attribute_values
[i
]); }
566 else if(!strcmp (attribute_names
[i
], "parent")) { entry
->parent
= atoi(attribute_values
[i
]); }
567 else if(!strcmp (attribute_names
[i
], "flags" )) { entry
->flags
= atoi(attribute_values
[i
]); }
568 else if(!strcmp (attribute_names
[i
], "name" )) { entry
->name
= g_strdup(attribute_values
[i
]); }
575 tmpname
= g_strdup_printf ("b%d", j
);
576 if(!(strcmp (attribute_names
[i
], tmpname
))) { entry
->budget
[j
] = g_ascii_strtod(attribute_values
[i
], NULL
); }
579 if(entry
->budget
[j
]) budget
= TRUE
;
582 entry
->flags
|= GF_BUDGET
;
586 //all attribute loaded: append
587 da_cat_insert( entry
);
591 static void homebank_load_xml_cur(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
593 Currency
*entry
= da_cur_malloc ();
596 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
598 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
600 if(!strcmp (attribute_names
[i
], "key" )) { entry
->key
= atoi(attribute_values
[i
]); }
601 else if(!strcmp (attribute_names
[i
], "flags" )) { entry
->flags
= atoi(attribute_values
[i
]); }
602 else if(!strcmp (attribute_names
[i
], "name" )) { entry
->name
= g_strdup(attribute_values
[i
]); }
603 else if(!strcmp (attribute_names
[i
], "iso" )) { entry
->iso_code
= g_strdup(attribute_values
[i
]); }
604 else if(!strcmp (attribute_names
[i
], "symb" )) { entry
->symbol
= g_strdup(attribute_values
[i
]); }
605 else if(!strcmp (attribute_names
[i
], "syprf" )) { entry
->sym_prefix
= atoi(attribute_values
[i
]); }
606 else if(!strcmp (attribute_names
[i
], "dchar" )) { entry
->decimal_char
= g_strdup(attribute_values
[i
]); }
607 else if(!strcmp (attribute_names
[i
], "gchar" )) { entry
->grouping_char
= g_strdup(attribute_values
[i
]); }
608 else if(!strcmp (attribute_names
[i
], "frac" )) { entry
->frac_digits
= atoi(attribute_values
[i
]); }
609 else if(!strcmp (attribute_names
[i
], "rate" )) { entry
->rate
= g_ascii_strtod(attribute_values
[i
], NULL
); }
610 else if(!strcmp (attribute_names
[i
], "mdate ")) { entry
->mdate
= atoi(attribute_values
[i
]); }
614 //all attribute loaded: append
615 da_cur_insert (entry
);
619 /*static void homebank_load_xml_tag(ParseContext *ctx, const gchar **attribute_names, const gchar **attribute_values)
621 Tag *entry = da_tag_malloc();
624 for (i = 0; attribute_names[i] != NULL; i++)
626 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
628 if(!strcmp (attribute_names[i], "key" )) { entry->key = atoi(attribute_values[i]); }
629 //else if(!strcmp (attribute_names[i], "flags")) { entry->flags = atoi(attribute_values[i]); }
630 else if(!strcmp (attribute_names[i], "name" )) { entry->name = g_strdup(attribute_values[i]); }
633 //all attribute loaded: append
634 da_tag_insert(entry);
638 static void homebank_load_xml_fav(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
640 Archive
*entry
= da_archive_malloc();
644 gboolean split
= FALSE
;
647 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
649 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
651 if(!strcmp (attribute_names
[i
], "key" )) { entry
->key
= atoi(attribute_values
[i
]); }
652 else if(!strcmp (attribute_names
[i
], "amount" )) { entry
->amount
= g_ascii_strtod(attribute_values
[i
], NULL
); }
653 else if(!strcmp (attribute_names
[i
], "account" )) { entry
->kacc
= atoi(attribute_values
[i
]); }
654 else if(!strcmp (attribute_names
[i
], "dst_account")) { entry
->kxferacc
= atoi(attribute_values
[i
]); }
655 else if(!strcmp (attribute_names
[i
], "paymode" )) { entry
->paymode
= atoi(attribute_values
[i
]); }
656 else if(!strcmp (attribute_names
[i
], "st" )) { entry
->status
= atoi(attribute_values
[i
]); }
657 else if(!strcmp (attribute_names
[i
], "flags" )) { entry
->flags
= atoi(attribute_values
[i
]); }
658 else if(!strcmp (attribute_names
[i
], "payee" )) { entry
->kpay
= atoi(attribute_values
[i
]); }
659 else if(!strcmp (attribute_names
[i
], "category" )) { entry
->kcat
= atoi(attribute_values
[i
]); }
660 else if(!strcmp (attribute_names
[i
], "wording" )) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->memo
= g_strdup(attribute_values
[i
]); }
661 else if(!strcmp (attribute_names
[i
], "tags" ))
663 if(attribute_values
[i
] != NULL
&& strlen(attribute_values
[i
]) > 0 && strcmp(attribute_values
[i
],"(null)") != 0 )
665 entry
->tags
= tags_parse(attribute_values
[i
]);
668 else if(!strcmp (attribute_names
[i
], "nextdate" )) { entry
->nextdate
= atoi(attribute_values
[i
]); }
669 else if(!strcmp (attribute_names
[i
], "every" )) { entry
->every
= atoi(attribute_values
[i
]); }
670 else if(!strcmp (attribute_names
[i
], "unit" )) { entry
->unit
= atoi(attribute_values
[i
]); }
671 else if(!strcmp (attribute_names
[i
], "limit" )) { entry
->limit
= atoi(attribute_values
[i
]); }
672 else if(!strcmp (attribute_names
[i
], "weekend" )) { entry
->weekend
= atoi(attribute_values
[i
]); }
673 else if(!strcmp (attribute_names
[i
], "gap" )) { entry
->daygap
= atoi(attribute_values
[i
]); }
674 else if(!strcmp (attribute_names
[i
], "scat" )) { scat
= (gchar
*)attribute_values
[i
]; split
= TRUE
; }
675 else if(!strcmp (attribute_names
[i
], "samt" )) { samt
= (gchar
*)attribute_values
[i
]; split
= TRUE
; }
676 else if(!strcmp (attribute_names
[i
], "smem" )) { smem
= (gchar
*)attribute_values
[i
]; split
= TRUE
; }
682 entry
->splits
= da_split_new ();
683 if (da_splits_parse(entry
->splits
, scat
, samt
, smem
) > 0)
685 entry
->flags
|= OF_SPLIT
; //Flag that Splits are active
689 //all attribute loaded: append
690 //GLOBALS->arc_list = g_list_append(GLOBALS->arc_list, entry);
691 da_archive_append(entry
);
695 static void homebank_load_xml_ope(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
697 Transaction
*entry
= da_transaction_malloc();
701 gboolean split
= FALSE
;
704 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
706 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
708 if(!strcmp (attribute_names
[i
], "date" )) { entry
->date
= atoi(attribute_values
[i
]); }
709 else if(!strcmp (attribute_names
[i
], "amount" )) { entry
->amount
= g_ascii_strtod(attribute_values
[i
], NULL
); }
710 else if(!strcmp (attribute_names
[i
], "account" )) { entry
->kacc
= atoi(attribute_values
[i
]); }
711 else if(!strcmp (attribute_names
[i
], "dst_account")) { entry
->kxferacc
= atoi(attribute_values
[i
]); }
712 else if(!strcmp (attribute_names
[i
], "paymode" )) { entry
->paymode
= atoi(attribute_values
[i
]); }
713 else if(!strcmp (attribute_names
[i
], "st" )) { entry
->status
= atoi(attribute_values
[i
]); }
714 else if(!strcmp (attribute_names
[i
], "flags" )) { entry
->flags
= atoi(attribute_values
[i
]); }
715 else if(!strcmp (attribute_names
[i
], "payee" )) { entry
->kpay
= atoi(attribute_values
[i
]); }
716 else if(!strcmp (attribute_names
[i
], "category" )) { entry
->kcat
= atoi(attribute_values
[i
]); }
717 else if(!strcmp (attribute_names
[i
], "wording" )) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->memo
= g_strdup(attribute_values
[i
]); }
718 else if(!strcmp (attribute_names
[i
], "info" )) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->info
= g_strdup(attribute_values
[i
]); }
719 else if(!strcmp (attribute_names
[i
], "tags" ))
721 if(attribute_values
[i
] != NULL
&& strlen(attribute_values
[i
]) > 0 && strcmp(attribute_values
[i
],"(null)") != 0 )
723 entry
->tags
= tags_parse(attribute_values
[i
]);
726 else if(!strcmp (attribute_names
[i
], "kxfer" )) { entry
->kxfer
= atoi(attribute_values
[i
]); }
727 else if(!strcmp (attribute_names
[i
], "scat" )) { scat
= (gchar
*)attribute_values
[i
]; split
= TRUE
; }
728 else if(!strcmp (attribute_names
[i
], "samt" )) { samt
= (gchar
*)attribute_values
[i
]; split
= TRUE
; }
729 else if(!strcmp (attribute_names
[i
], "smem" )) { smem
= (gchar
*)attribute_values
[i
]; split
= TRUE
; }
733 //if(entry->kcat < 0)
738 entry
->splits
= da_split_new ();
739 if (da_splits_parse(entry
->splits
, scat
, samt
, smem
) > 0)
741 entry
->flags
|= OF_SPLIT
; //Flag that Splits are active
745 //all attribute loaded: append
746 // for perf reason we use prepend here, the list will be reversed later
747 da_transaction_prepend(entry
);
754 start_element_handler (GMarkupParseContext
*context
,
755 const gchar
*element_name
,
756 const gchar
**attribute_names
,
757 const gchar
**attribute_values
,
761 ParseContext
*ctx
= user_data
;
762 //GtkUIManager *self = ctx->self;
764 //DB( g_print("** start element: '%s'\n", element_name) );
766 switch(element_name
[0])
770 if(!strcmp (element_name
, "account")) //account
772 homebank_load_xml_acc(ctx
, attribute_names
, attribute_values
);
774 else if(!strcmp (element_name
, "asg")) //assign
776 homebank_load_xml_asg(ctx
, attribute_names
, attribute_values
);
783 if(!strcmp (element_name
, "pay"))
785 homebank_load_xml_pay(ctx
, attribute_names
, attribute_values
);
787 else if(!strcmp (element_name
, "properties"))
789 homebank_load_xml_prop(ctx
, attribute_names
, attribute_values
);
805 if(!strcmp (element_name
, "cat"))
807 homebank_load_xml_cat(ctx
, attribute_names
, attribute_values
);
809 else if(!strcmp (element_name
, "cur"))
811 homebank_load_xml_cur(ctx
, attribute_names
, attribute_values
);
816 //TODO: < 5.2 misstyped here, should be tag without a s
817 //commented > 5.2 useless not loaded, but no side effect
820 if(!strcmp (element_name, "tags"))
822 homebank_load_xml_tag(ctx, attribute_names, attribute_values);
829 if(!strcmp (element_name
, "fav"))
831 homebank_load_xml_fav(ctx
, attribute_names
, attribute_values
);
838 if(!strcmp (element_name
, "ope"))
840 homebank_load_xml_ope(ctx
, attribute_names
, attribute_values
);
850 end_element_handler (GMarkupParseContext *context,
851 const gchar *element_name,
855 ParseContext *ctx = user_data;
857 //DB( g_print("-- end element: %s\n", element_name) );
863 static GMarkupParser hb_parser
= {
864 start_element_handler
,
865 NULL
, //end_element_handler,
866 NULL
, //text_handler,
872 static gboolean
hb_xml_get_version(ParseContext
*ctx
, gchar
*buffer
)
876 ctx
->file_version
= 0.0;
877 ctx
->data_version
= 0;
879 /* v3.4 add :: prevent load of future file version */
880 v_buffer
= g_strstr_len(buffer
, 50, "<homebank v=");
881 if( v_buffer
== NULL
)
884 DB( g_print("- id line: --(%.50s)\n\n", v_buffer
) );
886 ctx
->file_version
= g_ascii_strtod(v_buffer
+13, NULL
); /* a little hacky, but works ! */
887 if( ctx
->file_version
== 0.0 )
888 ctx
->file_version
= 0.1;
889 else if( ctx
->file_version
== 5.0 ) //was a mistake
890 ctx
->file_version
= 1.0;
892 v_buffer
= g_strstr_len(buffer
+13, 50, "d=");
895 DB( g_print(" d=%s)\n\n", v_buffer
) );
897 ctx
->data_version
= atoi(v_buffer
+3);
904 ** XML load homebank file: hbfile
906 gint
homebank_load_xml(gchar
*filename
)
911 GError
*error
= NULL
;
913 GMarkupParseContext
*context
;
916 DB( g_print("\n[hb-xml] homebank_load_xml\n") );
918 GValue filename_val
= G_VALUE_INIT
;
919 ext_hook("load_file", EXT_STRING(&filename_val
, filename
), NULL
);
922 if (!g_file_get_contents (filename
, &buffer
, &length
, &error
))
926 g_warning("unable to load file %s: %s", filename
, error
->message
);
928 retval
= XML_IO_ERROR
;
933 if( hb_xml_get_version(&ctx
, buffer
) == FALSE
)
935 return XML_FILE_ERROR
;
938 if( ctx
.file_version
> FILE_VERSION
)
940 DB( g_print("- failed: version %f is not supported (max is %f)\n", ctx
.file_version
, FILE_VERSION
) );
941 return XML_VERSION_ERROR
;
945 DB( g_print("- file ok : v=%.1f data_v=%06d\n", ctx
.file_version
, ctx
.data_version
) );
947 /* 1st: validate the file is well in utf-8 */
948 DB( g_print("- ensure UTF-8\n") );
949 buffer
= homebank_utf8_ensure(buffer
);
951 /* then process the buffer */
953 GTimer
*t
= g_timer_new();
954 g_print("- start parse\n");
957 context
= g_markup_parse_context_new (&hb_parser
, 0, &ctx
, NULL
);
960 rc
= g_markup_parse_context_parse (context
, buffer
, length
, &error
);
964 g_print("failed: %s\n", error
->message
);
965 g_error_free (error
);
972 g_markup_parse_context_end_parse(context
, &error
);
976 g_print("failed: %s\n", error
->message
);
977 g_error_free (error
);
981 g_markup_parse_context_free (context
);
984 DB( g_print("- end parse : %f sec\n", g_timer_elapsed(t
, NULL
)) );
985 DB( g_timer_destroy (t
) );
987 /* file upgrade / bugfix */
988 // group a test for very old version
989 if( ctx
.file_version
<= 1.0 )
991 if( ctx
.file_version
<= 0.1 )
992 homebank_upgrade_to_v02();
993 if( ctx
.file_version
<= 0.2 )
994 homebank_upgrade_to_v03();
995 if( ctx
.file_version
<= 0.3 )
996 homebank_upgrade_to_v04();
997 if( ctx
.file_version
<= 0.4 )
998 homebank_upgrade_to_v05();
999 if( ctx
.file_version
<= 0.5 )
1001 homebank_upgrade_to_v06();
1002 homebank_upgrade_lower_v06();
1004 if( ctx
.file_version
<= 0.6 )
1006 homebank_upgrade_to_v07();
1007 hbfile_sanity_check();
1009 if( ctx
.file_version
<= 0.7 ) // <= 4.5
1011 homebank_upgrade_to_v08();
1013 if( ctx
.file_version
<= 0.8 ) // <= 4.6
1015 hbfile_sanity_check();
1017 if( ctx
.file_version
<= 0.9 ) // <= 4.6.3
1019 hbfile_sanity_check();
1020 homebank_upgrade_to_v10();
1022 if( ctx
.file_version
<= 1.0 ) // <= 5.0.0
1024 hbfile_sanity_check();
1025 homebank_upgrade_to_v11();
1029 //starting 5.0.4 data upgrade is done without changing file_version
1030 //file version is changed only when the structure change
1031 //don't start number below with 0 to avoid octal interpretation
1032 if( ctx
.data_version
<= 50005 ) // <= 5.0.5
1034 hbfile_sanity_check();
1036 if( ctx
.file_version
<= 1.1 ) // <= 5.1.0
1038 hbfile_sanity_check();
1039 homebank_upgrade_to_v12();
1041 if( ctx
.data_version
<= 50106 ) // < 5.1.6
1043 homebank_upgrade_to_v12_7();
1045 if( ctx
.file_version
< 1.3 ) // <= 5.2
1047 hbfile_sanity_check();
1048 homebank_upgrade_to_v13();
1050 if( ctx
.data_version
<= 50203 )
1052 hbfile_sanity_check();
1064 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
1067 ** misc xml attributes methods
1069 static void hb_xml_append_txt(GString
*gstring
, gchar
*attrname
, gchar
*value
)
1071 if(value
!= NULL
&& *value
!= 0)
1073 gchar
*escaped
= g_markup_escape_text(value
, -1);
1074 g_string_append_printf(gstring
, " %s=\"%s\"", attrname
, escaped
);
1080 append_escaped_text (GString
*str
,
1089 end
= text
+ length
;
1094 next
= g_utf8_next_char (p
);
1099 g_string_append (str
, "&");
1103 g_string_append (str
, "<");
1107 g_string_append (str
, ">");
1111 g_string_append (str
, "'");
1115 g_string_append (str
, """);
1119 c
= g_utf8_get_char (p
);
1120 if ((0x1 <= c
&& c
<= 0x8) ||
1121 (0xa <= c
&& c
<= 0xd) || //chnaged here from b<->c to a<->d
1122 (0xe <= c
&& c
<= 0x1f) ||
1123 (0x7f <= c
&& c
<= 0x84) ||
1124 (0x86 <= c
&& c
<= 0x9f))
1125 g_string_append_printf (str
, "&#x%x;", c
);
1127 g_string_append_len (str
, p
, next
- p
);
1135 // we override g_markup_escape_text from glib to encode \n (LF) & \r (CR)
1136 static void hb_xml_append_txt_crlf(GString
*gstring
, gchar
*attrname
, gchar
*value
)
1138 if(value
!= NULL
&& *value
!= 0)
1143 //gchar *escaped = g_markup_escape_text(value, -1);
1144 length
= strlen (value
);
1145 escaped
= g_string_sized_new (length
);
1146 append_escaped_text (escaped
, value
, length
);
1147 g_string_append_printf(gstring
, " %s=\"%s\"", attrname
, escaped
->str
);
1148 g_string_free (escaped
, TRUE
);
1152 static void hb_xml_append_int0(GString
*gstring
, gchar
*attrname
, guint32 value
)
1154 g_string_append_printf(gstring
, " %s=\"%d\"", attrname
, value
);
1157 static void hb_xml_append_int(GString
*gstring
, gchar
*attrname
, guint32 value
)
1161 hb_xml_append_int0(gstring
, attrname
, value
);
1165 static void hb_xml_append_amt(GString
*gstring
, gchar
*attrname
, gdouble amount
)
1167 char buf
[G_ASCII_DTOSTR_BUF_SIZE
];
1169 //we must use this, as fprintf use locale decimal settings and not '.'
1170 g_ascii_dtostr (buf
, sizeof (buf
), amount
);
1171 g_string_append_printf(gstring
, " %s=\"%s\"", attrname
, buf
);
1175 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
1179 ** XML properties save
1181 static gint
homebank_save_xml_prop(GIOChannel
*io
)
1185 gint retval
= XML_OK
;
1186 GError
*error
= NULL
;
1188 title
= GLOBALS
->owner
== NULL
? "" : GLOBALS
->owner
;
1190 node
= g_string_sized_new(255);
1192 g_string_assign(node
, "<properties");
1194 hb_xml_append_txt(node
, "title", title
);
1195 hb_xml_append_int(node
, "curr", GLOBALS
->kcur
);
1196 hb_xml_append_int(node
, "car_category", GLOBALS
->vehicle_category
);
1197 hb_xml_append_int0(node
, "auto_smode", GLOBALS
->auto_smode
);
1198 hb_xml_append_int(node
, "auto_weekday", GLOBALS
->auto_weekday
);
1199 hb_xml_append_int(node
, "auto_nbdays", GLOBALS
->auto_nbdays
);
1201 g_string_append(node
, "/>\n");
1204 g_io_channel_write_chars(io
, node
->str
, -1, NULL
, &error
);
1207 retval
= XML_IO_ERROR
;
1208 g_error_free(error
);
1211 g_string_free(node
, TRUE
);
1217 ** XML currency save
1219 static gint
homebank_save_xml_cur(GIOChannel
*io
)
1223 char buf1
[G_ASCII_DTOSTR_BUF_SIZE
];
1224 gint retval
= XML_OK
;
1226 list
= g_hash_table_get_values(GLOBALS
->h_cur
);
1227 while (list
!= NULL
)
1229 Currency
*item
= list
->data
;
1231 tmpstr
= g_markup_printf_escaped(
1232 "<cur key=\"%d\" flags=\"%d\" iso=\"%s\" name=\"%s\" symb=\"%s\" syprf=\"%d\" dchar=\"%s\" gchar=\"%s\" frac=\"%d\" rate=\"%s\" mdate=\"%d\"/>\n",
1240 item
->grouping_char
,
1242 g_ascii_dtostr (buf1
, sizeof (buf1
), item
->rate
),
1246 g_io_channel_write_chars(io
, tmpstr
, -1, NULL
, NULL
);
1249 list
= g_list_next(list
);
1259 static gint
homebank_save_xml_acc(GIOChannel
*io
)
1263 gint retval
= XML_OK
;
1264 GError
*error
= NULL
;
1266 node
= g_string_sized_new(255);
1268 lacc
= list
= account_glist_sorted(0);
1269 while (list
!= NULL
)
1271 Account
*item
= list
->data
;
1273 item
->flags
&= ~(AF_ADDED
|AF_CHANGED
); //delete flag
1275 g_string_assign(node
, "<account");
1277 hb_xml_append_int(node
, "key", item
->key
);
1278 hb_xml_append_int(node
, "flags", item
->flags
);
1279 hb_xml_append_int(node
, "pos", item
->pos
);
1280 hb_xml_append_int(node
, "type", item
->type
);
1281 hb_xml_append_int(node
, "curr", item
->kcur
);
1282 hb_xml_append_txt(node
, "name", item
->name
);
1283 hb_xml_append_txt(node
, "number", item
->number
);
1284 hb_xml_append_txt(node
, "bankname", item
->bankname
);
1285 hb_xml_append_amt(node
, "initial", item
->initial
);
1287 hb_xml_append_amt(node
, "minimum", item
->minimum
);
1288 hb_xml_append_int(node
, "cheque1", item
->cheque1
);
1289 hb_xml_append_int(node
, "cheque2", item
->cheque2
);
1290 hb_xml_append_txt_crlf(node
, "notes", item
->notes
);
1291 hb_xml_append_int(node
, "tpl", item
->karc
);
1294 g_string_append(node
, "/>\n");
1297 g_io_channel_write_chars(io
, node
->str
, -1, NULL
, &error
);
1301 retval
= XML_IO_ERROR
;
1302 g_error_free(error
);
1305 list
= g_list_next(list
);
1308 g_string_free(node
, TRUE
);
1315 static gint
homebank_save_xml_pay(GIOChannel
*io
)
1319 gint retval
= XML_OK
;
1320 GError
*error
= NULL
;
1322 node
= g_string_sized_new(255);
1324 lpay
= list
= payee_glist_sorted(0);
1325 while (list
!= NULL
)
1327 Payee
*item
= list
->data
;
1331 g_string_assign(node
, "<pay");
1333 hb_xml_append_int(node
, "key", item
->key
);
1334 hb_xml_append_txt(node
, "name", item
->name
);
1335 hb_xml_append_int(node
, "category", item
->kcat
);
1336 hb_xml_append_int(node
, "paymode" , item
->paymode
);
1338 g_string_append(node
, "/>\n");
1341 g_io_channel_write_chars(io
, node
->str
, -1, NULL
, &error
);
1345 retval
= XML_IO_ERROR
;
1346 g_error_free(error
);
1350 list
= g_list_next(list
);
1353 g_string_free(node
, TRUE
);
1358 ** XML category save
1360 static gint
homebank_save_xml_cat(GIOChannel
*io
)
1364 char buf
[G_ASCII_DTOSTR_BUF_SIZE
];
1366 gint retval
= XML_OK
;
1367 GError
*error
= NULL
;
1369 node
= g_string_sized_new(255);
1371 lcat
= list
= category_glist_sorted(0);
1372 while (list
!= NULL
)
1374 Category
*item
= list
->data
;
1378 g_string_assign(node
, "<cat");
1380 hb_xml_append_int(node
, "key", item
->key
);
1381 hb_xml_append_int(node
, "parent", item
->parent
);
1382 hb_xml_append_int(node
, "flags", item
->flags
);
1383 hb_xml_append_txt(node
, "name", item
->name
);
1387 if(item
->budget
[i
] != 0)
1389 g_string_append_printf(node
," b%d=\"%s\"", i
, g_ascii_dtostr (buf
, sizeof (buf
), item
->budget
[i
]));
1393 g_string_append(node
, "/>\n");
1396 g_io_channel_write_chars(io
, node
->str
, -1, NULL
, &error
);
1400 retval
= XML_IO_ERROR
;
1401 g_error_free(error
);
1405 list
= g_list_next(list
);
1408 g_string_free(node
, TRUE
);
1415 /*static gint homebank_save_xml_tag(GIOChannel *io)
1419 gint retval = XML_OK;
1420 GError *error = NULL;
1422 ltag = list = tag_glist_sorted(0);
1423 while (list != NULL)
1425 Tag *item = list->data;
1429 tmpstr = g_markup_printf_escaped("<tag key=\"%d\" name=\"%s\"/>\n",
1435 g_io_channel_write_chars(io, tmpstr, -1, NULL, &error);
1440 retval = XML_IO_ERROR;
1441 g_error_free(error);
1444 list = g_list_next(list);
1454 static gint
homebank_save_xml_asg(GIOChannel
*io
)
1458 gint retval
= XML_OK
;
1459 GError
*error
= NULL
;
1461 node
= g_string_sized_new(255);
1463 lasg
= list
= assign_glist_sorted(0);
1464 while (list
!= NULL
)
1466 Assign
*item
= list
->data
;
1468 g_string_assign(node
, "<asg");
1470 hb_xml_append_int(node
, "key" , item
->key
);
1471 hb_xml_append_int(node
, "flags" , item
->flags
);
1472 hb_xml_append_int(node
, "field" , item
->field
);
1473 hb_xml_append_txt(node
, "name" , item
->text
);
1474 hb_xml_append_int(node
, "payee" , item
->kpay
);
1475 hb_xml_append_int(node
, "category", item
->kcat
);
1476 hb_xml_append_int(node
, "paymode" , item
->paymode
);
1478 g_string_append(node
, "/>\n");
1481 g_io_channel_write_chars(io
, node
->str
, -1, NULL
, &error
);
1485 retval
= XML_IO_ERROR
;
1486 g_error_free(error
);
1489 list
= g_list_next(list
);
1492 g_string_free(node
, TRUE
);
1501 static gint
homebank_save_xml_arc(GIOChannel
*io
)
1506 gint retval
= XML_OK
;
1507 GError
*error
= NULL
;
1509 node
= g_string_sized_new(255);
1511 list
= g_list_first(GLOBALS
->arc_list
);
1512 while (list
!= NULL
)
1514 Archive
*item
= list
->data
;
1516 tagstr
= tags_tostring(item
->tags
);
1518 g_string_assign(node
, "<fav");
1520 hb_xml_append_int(node
, "key", item
->key
);
1521 hb_xml_append_amt(node
, "amount", item
->amount
);
1522 hb_xml_append_int(node
, "account", item
->kacc
);
1523 hb_xml_append_int(node
, "dst_account", item
->kxferacc
);
1524 hb_xml_append_int(node
, "paymode", item
->paymode
);
1525 hb_xml_append_int(node
, "st", item
->status
);
1526 hb_xml_append_int(node
, "flags", item
->flags
);
1527 hb_xml_append_int(node
, "payee", item
->kpay
);
1528 hb_xml_append_int(node
, "category", item
->kcat
);
1529 hb_xml_append_txt(node
, "wording", item
->memo
);
1530 hb_xml_append_txt(node
, "tags", tagstr
);
1531 hb_xml_append_int(node
, "nextdate", item
->nextdate
);
1532 hb_xml_append_int(node
, "every", item
->every
);
1533 hb_xml_append_int(node
, "unit", item
->unit
);
1534 hb_xml_append_int(node
, "limit", item
->limit
);
1535 hb_xml_append_int(node
, "weekend", item
->weekend
);
1536 hb_xml_append_int(node
, "gap", item
->daygap
);
1538 if(da_splits_length(item
->splits
) > 0)
1540 gchar
*cats
, *amounts
, *memos
;
1542 da_splits_tostring(item
->splits
, &cats
, &amounts
, &memos
);
1543 g_string_append_printf(node
, " scat=\"%s\"", cats
);
1544 g_string_append_printf(node
, " samt=\"%s\"", amounts
);
1547 gchar
*escaped
= g_markup_escape_text(memos
, -1);
1548 g_string_append_printf(node
, " smem=\"%s\"", escaped
);
1556 g_string_append(node
, "/>\n");
1561 g_io_channel_write_chars(io
, node
->str
, -1, NULL
, &error
);
1564 retval
= XML_IO_ERROR
;
1565 g_error_free(error
);
1568 list
= g_list_next(list
);
1570 g_string_free(node
, TRUE
);
1576 ** XML transaction save
1578 static gint
homebank_save_xml_ope(GIOChannel
*io
)
1580 GList
*lst_acc
, *lnk_acc
;
1584 gint retval
= XML_OK
;
1585 GError
*error
= NULL
;
1587 node
= g_string_sized_new(255);
1589 lst_acc
= g_hash_table_get_values(GLOBALS
->h_acc
);
1590 lnk_acc
= g_list_first(lst_acc
);
1591 while (lnk_acc
!= NULL
)
1593 Account
*acc
= lnk_acc
->data
;
1595 list
= g_queue_peek_head_link(acc
->txn_queue
);
1596 while (list
!= NULL
)
1598 Transaction
*item
= list
->data
;
1600 item
->flags
&= ~(OF_AUTO
|OF_ADDED
|OF_CHANGED
); //delete flag
1601 tagstr
= tags_tostring(item
->tags
);
1603 g_string_assign(node
, "<ope");
1605 hb_xml_append_int(node
, "date", item
->date
);
1606 hb_xml_append_amt(node
, "amount", item
->amount
);
1607 hb_xml_append_int(node
, "account", item
->kacc
);
1608 hb_xml_append_int(node
, "dst_account", item
->kxferacc
);
1609 hb_xml_append_int(node
, "paymode", item
->paymode
);
1610 hb_xml_append_int(node
, "st", item
->status
);
1611 hb_xml_append_int(node
, "flags", item
->flags
);
1612 hb_xml_append_int(node
, "payee", item
->kpay
);
1613 hb_xml_append_int(node
, "category", item
->kcat
);
1614 hb_xml_append_txt(node
, "wording", item
->memo
);
1615 hb_xml_append_txt(node
, "info", item
->info
);
1616 hb_xml_append_txt(node
, "tags", tagstr
);
1617 hb_xml_append_int(node
, "kxfer", item
->kxfer
);
1619 if(da_splits_length(item
->splits
) > 0)
1621 gchar
*cats
, *amounts
, *memos
;
1623 da_splits_tostring(item
->splits
, &cats
, &amounts
, &memos
);
1624 g_string_append_printf(node
, " scat=\"%s\"", cats
);
1625 g_string_append_printf(node
, " samt=\"%s\"", amounts
);
1628 gchar
*escaped
= g_markup_escape_text(memos
, -1);
1629 g_string_append_printf(node
, " smem=\"%s\"", escaped
);
1637 g_string_append(node
, "/>\n");
1642 g_io_channel_write_chars(io
, node
->str
, -1, NULL
, &error
);
1646 retval
= XML_IO_ERROR
;
1647 g_error_free(error
);
1650 list
= g_list_next(list
);
1653 lnk_acc
= g_list_next(lnk_acc
);
1655 g_list_free(lst_acc
);
1657 g_string_free(node
, TRUE
);
1662 ** XML save homebank file: hbfile
1664 gint
homebank_save_xml(gchar
*filename
)
1667 char buf1
[G_ASCII_DTOSTR_BUF_SIZE
];
1669 gint retval
= XML_OK
;
1670 GError
*error
= NULL
;
1672 GValue filename_val
= G_VALUE_INIT
;
1673 ext_hook("save_file", EXT_STRING(&filename_val
, filename
), NULL
);
1675 io
= g_io_channel_new_file(filename
, "w", &error
);
1678 g_warning("unable to save file %s: %s", filename
, error
->message
);
1679 g_error_free(error
);
1680 return(XML_IO_ERROR
);
1683 g_io_channel_write_chars(io
, "<?xml version=\"1.0\"?>\n", -1, NULL
, NULL
);
1685 outstr
= g_strdup_printf("<homebank v=\"%s\" d=\"%06d\">\n", g_ascii_dtostr (buf1
, sizeof (buf1
), FILE_VERSION
), HB_VERSION_NUM
);
1686 g_io_channel_write_chars(io
, outstr
, -1, NULL
, NULL
);
1689 retval
= homebank_save_xml_prop(io
);
1690 retval
= homebank_save_xml_cur(io
);
1691 retval
= homebank_save_xml_acc(io
);
1692 retval
= homebank_save_xml_pay(io
);
1693 retval
= homebank_save_xml_cat(io
);
1694 //retval = homebank_save_xml_tag(io);
1695 retval
= homebank_save_xml_asg(io
);
1696 retval
= homebank_save_xml_arc(io
);
1698 retval
= homebank_save_xml_ope(io
);
1700 g_io_channel_write_chars(io
, "</homebank>\n", -1, NULL
, NULL
);
1702 g_io_channel_unref (io
);
This page took 0.108921 seconds and 4 git commands to generate.