]>
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"
26 #include "ui-dialogs.h"
28 /****************************************************************************/
30 /****************************************************************************/
39 /* our global datas */
40 extern struct HomeBank
*GLOBALS
;
41 extern struct Preferences
*PREFS
;
44 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
47 // v0.1 to v0.2 : we must change account reference by making a +1 to its index references
48 static void homebank_upgrade_to_v02(void)
50 GList
*lst_acc
, *lnk_acc
;
52 GHashTable
*h_old_acc
;
55 DB( g_print("\n[hb-xml] homebank_upgrade_to_v02\n") );
57 //keep old hashtable with us
58 h_old_acc
= GLOBALS
->h_acc
;
61 lst_acc
= g_hash_table_get_values(h_old_acc
);
62 lnk_acc
= g_list_first(lst_acc
);
63 while (lnk_acc
!= NULL
)
65 Account
*acc
= lnk_acc
->data
;
71 list
= g_queue_peek_head_link(acc
->txn_queue
);
74 Transaction
*entry
= list
->data
;
77 list
= g_list_next(list
);
79 lnk_acc
= g_list_next(lnk_acc
);
83 //we loose some small memory here
84 g_hash_table_steal_all(h_old_acc
);
86 list
= g_list_first(GLOBALS
->arc_list
);
89 Archive
*entry
= list
->data
;
92 list
= g_list_next(list
);
96 // v0.2 to v0.3 : we must assume categories exists : bugs 303886, 303738
97 static void homebank_upgrade_to_v03(void)
99 GList
*lst_acc
, *lnk_acc
;
102 DB( g_print("\n[hb-xml] homebank_upgrade_to_v03\n") );
104 lst_acc
= g_hash_table_get_values(GLOBALS
->h_acc
);
105 lnk_acc
= g_list_first(lst_acc
);
106 while (lnk_acc
!= NULL
)
108 Account
*acc
= lnk_acc
->data
;
110 list
= g_queue_peek_head_link(acc
->txn_queue
);
113 Transaction
*entry
= list
->data
;
115 da_transaction_consistency(entry
);
116 list
= g_list_next(list
);
118 lnk_acc
= g_list_next(lnk_acc
);
120 g_list_free(lst_acc
);
123 list
= g_list_first(GLOBALS
->arc_list
);
126 Archive
*entry
= list
->data
;
128 da_archive_consistency(entry
);
129 list
= g_list_next(list
);
133 static void homebank_upgrade_to_v04(void)
135 DB( g_print("\n[hb-xml] homebank_upgrade_to_v04\n") );
137 GLOBALS
->arc_list
= da_archive_sort(GLOBALS
->arc_list
);
142 // we must assume kxferacc exists in archives for internal xfer : bug 528923
143 // if not, delete automation from the archive
144 static void homebank_upgrade_to_v05(void)
148 DB( g_print("\n[hb-xml] homebank_upgrade_to_v05\n") );
150 list
= g_list_first(GLOBALS
->arc_list
);
153 Archive
*entry
= list
->data
;
155 da_archive_consistency(entry
);
156 list
= g_list_next(list
);
161 // v0.5 to v0.6 : we must change kxferacc to 0 on non Xfer transactions
163 static void homebank_upgrade_to_v06(void)
165 GList
*lst_acc
, *lnk_acc
;
168 DB( g_print("\n[hb-xml] homebank_upgrade_to_v06\n") );
170 lst_acc
= g_hash_table_get_values(GLOBALS
->h_acc
);
171 lnk_acc
= g_list_first(lst_acc
);
172 while (lnk_acc
!= NULL
)
174 Account
*acc
= lnk_acc
->data
;
176 list
= g_queue_peek_head_link(acc
->txn_queue
);
179 Transaction
*entry
= list
->data
;
180 da_transaction_consistency(entry
);
181 list
= g_list_next(list
);
183 lnk_acc
= g_list_next(lnk_acc
);
185 g_list_free(lst_acc
);
188 list
= g_list_first(GLOBALS
->arc_list
);
191 Archive
*entry
= list
->data
;
192 da_archive_consistency(entry
);
193 list
= g_list_next(list
);
198 // v0.7 AF_BUDGET deleted instead of AF_NOBUDGET
199 static void homebank_upgrade_to_v07(void)
203 DB( g_print("\n[hb-xml] homebank_upgrade_to_v07\n") );
205 lacc
= list
= g_hash_table_get_values(GLOBALS
->h_acc
);
208 Account
*acc
= list
->data
;
210 if( acc
->flags
& AF_OLDBUDGET
) // budget include
212 acc
->flags
&= ~(AF_OLDBUDGET
);
216 acc
->flags
|= AF_NOBUDGET
;
219 list
= g_list_next(list
);
225 static void homebank_upgrade_to_v08(void)
227 GList
*lst_acc
, *lnk_acc
;
230 DB( g_print("\n[hb-xml] homebank_upgrade_to_v08\n") );
232 lst_acc
= g_hash_table_get_values(GLOBALS
->h_acc
);
233 lnk_acc
= g_list_first(lst_acc
);
234 while (lnk_acc
!= NULL
)
236 Account
*acc
= lnk_acc
->data
;
238 list
= g_queue_peek_head_link(acc
->txn_queue
);
241 Transaction
*entry
= list
->data
;
242 da_transaction_consistency(entry
);
243 list
= g_list_next(list
);
245 lnk_acc
= g_list_next(lnk_acc
);
247 g_list_free(lst_acc
);
253 static void homebank_upgrade_to_v10(void)
255 GList
*lst_acc
, *lnk_acc
;
258 DB( g_print("\n[hb-xml] homebank_upgrade_to_v10\n") );
260 lst_acc
= g_hash_table_get_values(GLOBALS
->h_acc
);
261 lnk_acc
= g_list_first(lst_acc
);
262 while (lnk_acc
!= NULL
)
264 Account
*acc
= lnk_acc
->data
;
266 list
= g_queue_peek_head_link(acc
->txn_queue
);
269 Transaction
*entry
= list
->data
;
271 entry
->status
= TXN_STATUS_NONE
;
272 if(entry
->flags
& OF_OLDVALID
)
273 entry
->status
= TXN_STATUS_RECONCILED
;
275 if(entry
->flags
& OF_OLDREMIND
)
276 entry
->status
= TXN_STATUS_REMIND
;
279 entry
->flags
&= ~(OF_OLDVALID
|OF_OLDREMIND
);
281 list
= g_list_next(list
);
283 lnk_acc
= g_list_next(lnk_acc
);
285 g_list_free(lst_acc
);
290 static void homebank_upgrade_to_v11(void)
294 DB( g_print("\n[hb-xml] homebank_upgrade_to_v11\n") );
296 list
= g_list_first(GLOBALS
->arc_list
);
299 Archive
*entry
= list
->data
;
301 entry
->status
= TXN_STATUS_NONE
;
302 if(entry
->flags
& OF_OLDVALID
)
303 entry
->status
= TXN_STATUS_RECONCILED
;
305 if(entry
->flags
& OF_OLDREMIND
)
306 entry
->status
= TXN_STATUS_REMIND
;
309 entry
->flags
&= ~(OF_OLDVALID
|OF_OLDREMIND
);
311 list
= g_list_next(list
);
317 // v0.6 to v0.7 : assign a default currency
318 static void homebank_upgrade_to_v12(void)
320 DB( g_print("\n[hb-xml] homebank_upgrade_to_v12\n") );
322 // set a base currency to the hbfile if not
323 DB( g_print("GLOBALS->kcur %d\n", GLOBALS
->kcur
) );
325 ui_dialog_upgrade_choose_currency();
329 static void homebank_upgrade_to_v12_7(void)
331 GList
*lst_acc
, *lnk_acc
;
333 DB( g_print("\n[hb-xml] homebank_upgrade_to_v12\n") );
335 //#1674045 exclude closed account from everywhere to
336 //keep continuity for user that don't want to change this
337 lst_acc
= g_hash_table_get_values(GLOBALS
->h_acc
);
338 lnk_acc
= g_list_first(lst_acc
);
339 while (lnk_acc
!= NULL
)
341 Account
*acc
= lnk_acc
->data
;
343 if( acc
->flags
& AF_CLOSED
)
345 if( !(acc
->flags
& AF_NOSUMMARY
) )
346 acc
->flags
|= AF_NOSUMMARY
;
347 if( !(acc
->flags
& AF_NOBUDGET
) )
348 acc
->flags
|= AF_NOBUDGET
;
349 if( !(acc
->flags
& AF_NOREPORT
) )
350 acc
->flags
|= AF_NOREPORT
;
352 lnk_acc
= g_list_next(lnk_acc
);
354 g_list_free(lst_acc
);
358 static void homebank_upgrade_to_v13(void)
363 DB( g_print("\n[hb-xml] homebank_upgrade_to_v13\n") );
365 //#1008629 assign a key to each archive
367 tmplist
= g_list_first(GLOBALS
->arc_list
);
368 while (tmplist
!= NULL
)
370 Archive
*item
= tmplist
->data
;
372 item
->key
= newkey
++;
373 tmplist
= g_list_next(tmplist
);
379 // lower v0.6 : we must assume categories/payee exists
380 // and strong link to xfer
382 static void homebank_upgrade_lower_v06(void)
384 GList
*lst_acc
, *lnk_acc
;
389 DB( g_print("\n[hb-xml] homebank_upgrade_lower_v06\n") );
391 lst_acc
= g_hash_table_get_values(GLOBALS
->h_acc
);
392 lnk_acc
= g_list_first(lst_acc
);
393 while (lnk_acc
!= NULL
)
395 Account
*acc
= lnk_acc
->data
;
397 list
= g_queue_peek_head_link(acc
->txn_queue
);
400 Transaction
*entry
= list
->data
;
402 //also strong link internal xfer
403 if(entry
->paymode
== PAYMODE_INTXFER
&& entry
->kxfer
== 0)
405 Transaction
*child
= transaction_old_get_child_transfer(entry
);
408 transaction_xfer_change_to_child(entry
, child
);
412 da_transaction_consistency(entry
);
414 list
= g_list_next(list
);
416 lnk_acc
= g_list_next(lnk_acc
);
418 g_list_free(lst_acc
);
421 lrul
= list
= g_hash_table_get_values(GLOBALS
->h_rul
);
424 Assign
*entry
= list
->data
;
426 cat
= da_cat_get(entry
->kcat
);
429 DB( g_print(" !! fixing cat for rul: %d is unknown\n", entry
->kcat
) );
433 pay
= da_pay_get(entry
->kpay
);
436 DB( g_print(" !! fixing pay for rul: %d is unknown\n", entry
->kpay
) );
441 list
= g_list_next(list
);
447 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
450 static void homebank_load_xml_acc(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
452 Account
*entry
= da_acc_malloc();
455 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
457 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
459 if(!strcmp (attribute_names
[i
], "key" )) { entry
->key
= atoi(attribute_values
[i
]); }
460 else if(!strcmp (attribute_names
[i
], "flags" )) { entry
->flags
= atoi(attribute_values
[i
]); }
461 else if(!strcmp (attribute_names
[i
], "pos" )) { entry
->pos
= atoi(attribute_values
[i
]); }
462 else if(!strcmp (attribute_names
[i
], "type" )) { entry
->type
= atoi(attribute_values
[i
]); }
463 else if(!strcmp (attribute_names
[i
], "curr" )) { entry
->kcur
= atoi(attribute_values
[i
]); }
464 else if(!strcmp (attribute_names
[i
], "name" )) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->name
= g_strdup(attribute_values
[i
]); }
465 else if(!strcmp (attribute_names
[i
], "number" )) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->number
= g_strdup(attribute_values
[i
]); }
466 else if(!strcmp (attribute_names
[i
], "bankname")) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->bankname
= g_strdup(attribute_values
[i
]); }
467 else if(!strcmp (attribute_names
[i
], "initial" )) { entry
->initial
= g_ascii_strtod(attribute_values
[i
], NULL
); }
469 else if(!strcmp (attribute_names
[i
], "minimum" )) { entry
->minimum
= g_ascii_strtod(attribute_values
[i
], NULL
); }
470 else if(!strcmp (attribute_names
[i
], "cheque1" )) { entry
->cheque1
= atoi(attribute_values
[i
]); }
471 else if(!strcmp (attribute_names
[i
], "cheque2" )) { entry
->cheque2
= atoi(attribute_values
[i
]); }
472 else if(!strcmp (attribute_names
[i
], "notes" )) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->notes
= g_strdup(attribute_values
[i
]); }
473 else if(!strcmp (attribute_names
[i
], "tpl" )) { entry
->karc
= atoi(attribute_values
[i
]); }
476 //all attribute loaded: append
477 da_acc_insert(entry
);
481 static void homebank_load_xml_asg(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
483 Assign
*entry
= da_asg_malloc();
487 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
489 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
491 if(!strcmp (attribute_names
[i
], "key" )) { entry
->key
= atoi(attribute_values
[i
]); }
492 else if(!strcmp (attribute_names
[i
], "flags" )) { entry
->flags
= atoi(attribute_values
[i
]); }
493 else if(!strcmp (attribute_names
[i
], "field" )) { entry
->field
= atoi(attribute_values
[i
]); }
494 else if(!strcmp (attribute_names
[i
], "name" )) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->text
= g_strdup(attribute_values
[i
]); }
495 else if(!strcmp (attribute_names
[i
], "payee" )) { entry
->kpay
= atoi(attribute_values
[i
]); }
496 else if(!strcmp (attribute_names
[i
], "category")) { entry
->kcat
= atoi(attribute_values
[i
]); }
497 else if(!strcmp (attribute_names
[i
], "paymode" )) { entry
->paymode
= atoi(attribute_values
[i
]); }
499 else if(!strcmp (attribute_names
[i
], "exact" )) { exact
= atoi(attribute_values
[i
]); }
502 /* in v08 exact moved to flag */
503 if( ctx
->file_version
<= 0.7)
505 entry
->flags
= (ASGF_DOCAT
|ASGF_DOPAY
);
507 entry
->flags
|= ASGF_EXACT
;
510 //all attribute loaded: append
511 da_asg_append(entry
);
516 static void homebank_load_xml_pay(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
518 Payee
*entry
= da_pay_malloc();
521 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
523 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
525 if(!strcmp (attribute_names
[i
], "key" )) { entry
->key
= atoi(attribute_values
[i
]); }
526 //else if(!strcmp (attribute_names[i], "flags")) { entry->flags = atoi(attribute_values[i]); }
527 else if(!strcmp (attribute_names
[i
], "name" )) { entry
->name
= g_strdup(attribute_values
[i
]); }
528 else if(!strcmp (attribute_names
[i
], "category")) { entry
->kcat
= atoi(attribute_values
[i
]); }
529 else if(!strcmp (attribute_names
[i
], "paymode" )) { entry
->paymode
= atoi(attribute_values
[i
]); }
532 //all attribute loaded: append
533 da_pay_insert(entry
);
537 static void homebank_load_xml_prop(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
541 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
543 if(!strcmp (attribute_names
[i
], "title" )) { g_free(GLOBALS
->owner
); GLOBALS
->owner
= g_strdup(attribute_values
[i
]); }
544 else if(!strcmp (attribute_names
[i
], "curr" )) { GLOBALS
->kcur
= atoi(attribute_values
[i
]); }
545 else if(!strcmp (attribute_names
[i
], "car_category")) { GLOBALS
->vehicle_category
= atoi(attribute_values
[i
]); }
546 else if(!strcmp (attribute_names
[i
], "auto_smode" )) { GLOBALS
->auto_smode
= atoi(attribute_values
[i
]); }
547 else if(!strcmp (attribute_names
[i
], "auto_weekday")) { GLOBALS
->auto_weekday
= atoi(attribute_values
[i
]); }
548 else if(!strcmp (attribute_names
[i
], "auto_nbdays" )) { GLOBALS
->auto_nbdays
= atoi(attribute_values
[i
]); }
553 static void homebank_load_xml_cat(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
555 Category
*entry
= da_cat_malloc();
559 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
561 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
563 if(!strcmp (attribute_names
[i
], "key" )) { entry
->key
= atoi(attribute_values
[i
]); }
564 else if(!strcmp (attribute_names
[i
], "parent")) { entry
->parent
= atoi(attribute_values
[i
]); }
565 else if(!strcmp (attribute_names
[i
], "flags" )) { entry
->flags
= atoi(attribute_values
[i
]); }
566 else if(!strcmp (attribute_names
[i
], "name" )) { entry
->name
= g_strdup(attribute_values
[i
]); }
573 tmpname
= g_strdup_printf ("b%d", j
);
574 if(!(strcmp (attribute_names
[i
], tmpname
))) { entry
->budget
[j
] = g_ascii_strtod(attribute_values
[i
], NULL
); }
577 if(entry
->budget
[j
]) budget
= TRUE
;
580 entry
->flags
|= GF_BUDGET
;
584 //all attribute loaded: append
585 da_cat_insert( entry
);
589 static void homebank_load_xml_cur(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
591 Currency
*entry
= da_cur_malloc ();
594 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
596 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
598 if(!strcmp (attribute_names
[i
], "key" )) { entry
->key
= atoi(attribute_values
[i
]); }
599 else if(!strcmp (attribute_names
[i
], "flags" )) { entry
->flags
= atoi(attribute_values
[i
]); }
600 else if(!strcmp (attribute_names
[i
], "name" )) { entry
->name
= g_strdup(attribute_values
[i
]); }
601 else if(!strcmp (attribute_names
[i
], "iso" )) { entry
->iso_code
= g_strdup(attribute_values
[i
]); }
602 else if(!strcmp (attribute_names
[i
], "symb" )) { entry
->symbol
= g_strdup(attribute_values
[i
]); }
603 else if(!strcmp (attribute_names
[i
], "syprf" )) { entry
->sym_prefix
= atoi(attribute_values
[i
]); }
604 else if(!strcmp (attribute_names
[i
], "dchar" )) { entry
->decimal_char
= g_strdup(attribute_values
[i
]); }
605 else if(!strcmp (attribute_names
[i
], "gchar" )) { entry
->grouping_char
= g_strdup(attribute_values
[i
]); }
606 else if(!strcmp (attribute_names
[i
], "frac" )) { entry
->frac_digits
= atoi(attribute_values
[i
]); }
607 else if(!strcmp (attribute_names
[i
], "rate" )) { entry
->rate
= g_ascii_strtod(attribute_values
[i
], NULL
); }
608 else if(!strcmp (attribute_names
[i
], "mdate ")) { entry
->mdate
= atoi(attribute_values
[i
]); }
612 //all attribute loaded: append
613 da_cur_insert (entry
);
617 /*static void homebank_load_xml_tag(ParseContext *ctx, const gchar **attribute_names, const gchar **attribute_values)
619 Tag *entry = da_tag_malloc();
622 for (i = 0; attribute_names[i] != NULL; i++)
624 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
626 if(!strcmp (attribute_names[i], "key" )) { entry->key = atoi(attribute_values[i]); }
627 //else if(!strcmp (attribute_names[i], "flags")) { entry->flags = atoi(attribute_values[i]); }
628 else if(!strcmp (attribute_names[i], "name" )) { entry->name = g_strdup(attribute_values[i]); }
631 //all attribute loaded: append
632 da_tag_insert(entry);
636 static void homebank_load_xml_fav(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
638 Archive
*entry
= da_archive_malloc();
642 gboolean split
= FALSE
;
645 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
647 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
649 if(!strcmp (attribute_names
[i
], "key" )) { entry
->key
= atoi(attribute_values
[i
]); }
650 else if(!strcmp (attribute_names
[i
], "amount" )) { entry
->amount
= g_ascii_strtod(attribute_values
[i
], NULL
); }
651 else if(!strcmp (attribute_names
[i
], "account" )) { entry
->kacc
= atoi(attribute_values
[i
]); }
652 else if(!strcmp (attribute_names
[i
], "dst_account")) { entry
->kxferacc
= atoi(attribute_values
[i
]); }
653 else if(!strcmp (attribute_names
[i
], "paymode" )) { entry
->paymode
= atoi(attribute_values
[i
]); }
654 else if(!strcmp (attribute_names
[i
], "st" )) { entry
->status
= atoi(attribute_values
[i
]); }
655 else if(!strcmp (attribute_names
[i
], "flags" )) { entry
->flags
= atoi(attribute_values
[i
]); }
656 else if(!strcmp (attribute_names
[i
], "payee" )) { entry
->kpay
= atoi(attribute_values
[i
]); }
657 else if(!strcmp (attribute_names
[i
], "category" )) { entry
->kcat
= atoi(attribute_values
[i
]); }
658 else if(!strcmp (attribute_names
[i
], "wording" )) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->memo
= g_strdup(attribute_values
[i
]); }
659 else if(!strcmp (attribute_names
[i
], "tags" ))
661 if(attribute_values
[i
] != NULL
&& strlen(attribute_values
[i
]) > 0 && strcmp(attribute_values
[i
],"(null)") != 0 )
663 entry
->tags
= tags_parse(attribute_values
[i
]);
666 else if(!strcmp (attribute_names
[i
], "nextdate" )) { entry
->nextdate
= atoi(attribute_values
[i
]); }
667 else if(!strcmp (attribute_names
[i
], "every" )) { entry
->every
= atoi(attribute_values
[i
]); }
668 else if(!strcmp (attribute_names
[i
], "unit" )) { entry
->unit
= atoi(attribute_values
[i
]); }
669 else if(!strcmp (attribute_names
[i
], "limit" )) { entry
->limit
= atoi(attribute_values
[i
]); }
670 else if(!strcmp (attribute_names
[i
], "weekend" )) { entry
->weekend
= atoi(attribute_values
[i
]); }
671 else if(!strcmp (attribute_names
[i
], "gap" )) { entry
->daygap
= atoi(attribute_values
[i
]); }
672 else if(!strcmp (attribute_names
[i
], "scat" )) { scat
= (gchar
*)attribute_values
[i
]; split
= TRUE
; }
673 else if(!strcmp (attribute_names
[i
], "samt" )) { samt
= (gchar
*)attribute_values
[i
]; split
= TRUE
; }
674 else if(!strcmp (attribute_names
[i
], "smem" )) { smem
= (gchar
*)attribute_values
[i
]; split
= TRUE
; }
680 entry
->splits
= da_split_new ();
681 if (da_splits_parse(entry
->splits
, scat
, samt
, smem
) > 0)
683 entry
->flags
|= OF_SPLIT
; //Flag that Splits are active
687 //all attribute loaded: append
688 //GLOBALS->arc_list = g_list_append(GLOBALS->arc_list, entry);
689 da_archive_append(entry
);
693 static void homebank_load_xml_ope(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
695 Transaction
*entry
= da_transaction_malloc();
699 gboolean split
= FALSE
;
702 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
704 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
706 if(!strcmp (attribute_names
[i
], "date" )) { entry
->date
= atoi(attribute_values
[i
]); }
707 else if(!strcmp (attribute_names
[i
], "amount" )) { entry
->amount
= g_ascii_strtod(attribute_values
[i
], NULL
); }
708 else if(!strcmp (attribute_names
[i
], "account" )) { entry
->kacc
= atoi(attribute_values
[i
]); }
709 else if(!strcmp (attribute_names
[i
], "dst_account")) { entry
->kxferacc
= atoi(attribute_values
[i
]); }
710 else if(!strcmp (attribute_names
[i
], "paymode" )) { entry
->paymode
= atoi(attribute_values
[i
]); }
711 else if(!strcmp (attribute_names
[i
], "st" )) { entry
->status
= atoi(attribute_values
[i
]); }
712 else if(!strcmp (attribute_names
[i
], "flags" )) { entry
->flags
= atoi(attribute_values
[i
]); }
713 else if(!strcmp (attribute_names
[i
], "payee" )) { entry
->kpay
= atoi(attribute_values
[i
]); }
714 else if(!strcmp (attribute_names
[i
], "category" )) { entry
->kcat
= atoi(attribute_values
[i
]); }
715 else if(!strcmp (attribute_names
[i
], "wording" )) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->memo
= g_strdup(attribute_values
[i
]); }
716 else if(!strcmp (attribute_names
[i
], "info" )) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->info
= g_strdup(attribute_values
[i
]); }
717 else if(!strcmp (attribute_names
[i
], "tags" ))
719 if(attribute_values
[i
] != NULL
&& strlen(attribute_values
[i
]) > 0 && strcmp(attribute_values
[i
],"(null)") != 0 )
721 entry
->tags
= tags_parse(attribute_values
[i
]);
724 else if(!strcmp (attribute_names
[i
], "kxfer" )) { entry
->kxfer
= atoi(attribute_values
[i
]); }
725 else if(!strcmp (attribute_names
[i
], "scat" )) { scat
= (gchar
*)attribute_values
[i
]; split
= TRUE
; }
726 else if(!strcmp (attribute_names
[i
], "samt" )) { samt
= (gchar
*)attribute_values
[i
]; split
= TRUE
; }
727 else if(!strcmp (attribute_names
[i
], "smem" )) { smem
= (gchar
*)attribute_values
[i
]; split
= TRUE
; }
731 //if(entry->kcat < 0)
736 entry
->splits
= da_split_new ();
737 if (da_splits_parse(entry
->splits
, scat
, samt
, smem
) > 0)
739 entry
->flags
|= OF_SPLIT
; //Flag that Splits are active
743 //all attribute loaded: append
744 // for perf reason we use prepend here, the list will be reversed later
745 da_transaction_prepend(entry
);
752 start_element_handler (GMarkupParseContext
*context
,
753 const gchar
*element_name
,
754 const gchar
**attribute_names
,
755 const gchar
**attribute_values
,
759 ParseContext
*ctx
= user_data
;
760 //GtkUIManager *self = ctx->self;
762 //DB( g_print("** start element: '%s'\n", element_name) );
764 switch(element_name
[0])
768 if(!strcmp (element_name
, "account")) //account
770 homebank_load_xml_acc(ctx
, attribute_names
, attribute_values
);
772 else if(!strcmp (element_name
, "asg")) //assign
774 homebank_load_xml_asg(ctx
, attribute_names
, attribute_values
);
781 if(!strcmp (element_name
, "pay"))
783 homebank_load_xml_pay(ctx
, attribute_names
, attribute_values
);
785 else if(!strcmp (element_name
, "properties"))
787 homebank_load_xml_prop(ctx
, attribute_names
, attribute_values
);
803 if(!strcmp (element_name
, "cat"))
805 homebank_load_xml_cat(ctx
, attribute_names
, attribute_values
);
807 else if(!strcmp (element_name
, "cur"))
809 homebank_load_xml_cur(ctx
, attribute_names
, attribute_values
);
814 //TODO: < 5.2 misstyped here, should be tag without a s
815 //commented > 5.2 useless not loaded, but no side effect
818 if(!strcmp (element_name, "tags"))
820 homebank_load_xml_tag(ctx, attribute_names, attribute_values);
827 if(!strcmp (element_name
, "fav"))
829 homebank_load_xml_fav(ctx
, attribute_names
, attribute_values
);
836 if(!strcmp (element_name
, "ope"))
838 homebank_load_xml_ope(ctx
, attribute_names
, attribute_values
);
848 end_element_handler (GMarkupParseContext *context,
849 const gchar *element_name,
853 ParseContext *ctx = user_data;
855 //DB( g_print("-- end element: %s\n", element_name) );
861 static GMarkupParser hb_parser
= {
862 start_element_handler
,
863 NULL
, //end_element_handler,
864 NULL
, //text_handler,
870 static gboolean
hb_xml_get_version(ParseContext
*ctx
, gchar
*buffer
)
874 ctx
->file_version
= 0.0;
875 ctx
->data_version
= 0;
877 /* v3.4 add :: prevent load of future file version */
878 v_buffer
= g_strstr_len(buffer
, 50, "<homebank v=");
879 if( v_buffer
== NULL
)
882 DB( g_print("- id line: --(%.50s)\n\n", v_buffer
) );
884 ctx
->file_version
= g_ascii_strtod(v_buffer
+13, NULL
); /* a little hacky, but works ! */
885 if( ctx
->file_version
== 0.0 )
886 ctx
->file_version
= 0.1;
887 else if( ctx
->file_version
== 5.0 ) //was a mistake
888 ctx
->file_version
= 1.0;
890 v_buffer
= g_strstr_len(buffer
+13, 50, "d=");
893 DB( g_print(" d=%s)\n\n", v_buffer
) );
895 ctx
->data_version
= atoi(v_buffer
+3);
902 ** XML load homebank file: hbfile
904 gint
homebank_load_xml(gchar
*filename
)
909 GError
*error
= NULL
;
911 GMarkupParseContext
*context
;
914 DB( g_print("\n[hb-xml] homebank_load_xml\n") );
917 if (!g_file_get_contents (filename
, &buffer
, &length
, &error
))
921 g_warning("unable to load file %s: %s", filename
, error
->message
);
923 retval
= XML_IO_ERROR
;
928 if( hb_xml_get_version(&ctx
, buffer
) == FALSE
)
930 return XML_FILE_ERROR
;
933 if( ctx
.file_version
> FILE_VERSION
)
935 DB( g_print("- failed: version %f is not supported (max is %f)\n", ctx
.file_version
, FILE_VERSION
) );
936 return XML_VERSION_ERROR
;
940 DB( g_print("- file ok : v=%.1f data_v=%06d\n", ctx
.file_version
, ctx
.data_version
) );
942 /* 1st: validate the file is well in utf-8 */
943 DB( g_print("- ensure UTF-8\n") );
944 buffer
= homebank_utf8_ensure(buffer
);
946 /* then process the buffer */
948 GTimer
*t
= g_timer_new();
949 g_print("- start parse\n");
952 context
= g_markup_parse_context_new (&hb_parser
, 0, &ctx
, NULL
);
955 rc
= g_markup_parse_context_parse (context
, buffer
, length
, &error
);
959 g_print("failed: %s\n", error
->message
);
960 g_error_free (error
);
967 g_markup_parse_context_end_parse(context
, &error
);
971 g_print("failed: %s\n", error
->message
);
972 g_error_free (error
);
976 g_markup_parse_context_free (context
);
979 DB( g_print("- end parse : %f sec\n", g_timer_elapsed(t
, NULL
)) );
980 DB( g_timer_destroy (t
) );
982 /* file upgrade / bugfix */
983 // group a test for very old version
984 if( ctx
.file_version
<= 1.0 )
986 if( ctx
.file_version
<= 0.1 )
987 homebank_upgrade_to_v02();
988 if( ctx
.file_version
<= 0.2 )
989 homebank_upgrade_to_v03();
990 if( ctx
.file_version
<= 0.3 )
991 homebank_upgrade_to_v04();
992 if( ctx
.file_version
<= 0.4 )
993 homebank_upgrade_to_v05();
994 if( ctx
.file_version
<= 0.5 )
996 homebank_upgrade_to_v06();
997 homebank_upgrade_lower_v06();
999 if( ctx
.file_version
<= 0.6 )
1001 homebank_upgrade_to_v07();
1002 hbfile_sanity_check();
1004 if( ctx
.file_version
<= 0.7 ) // <= 4.5
1006 homebank_upgrade_to_v08();
1008 if( ctx
.file_version
<= 0.8 ) // <= 4.6
1010 hbfile_sanity_check();
1012 if( ctx
.file_version
<= 0.9 ) // <= 4.6.3
1014 hbfile_sanity_check();
1015 homebank_upgrade_to_v10();
1017 if( ctx
.file_version
<= 1.0 ) // <= 5.0.0
1019 hbfile_sanity_check();
1020 homebank_upgrade_to_v11();
1024 //starting 5.0.4 data upgrade is done without changing file_version
1025 //file version is changed only when the structure change
1026 //don't start number below with 0 to avoid octal interpretation
1027 if( ctx
.data_version
<= 50005 ) // <= 5.0.5
1029 hbfile_sanity_check();
1031 if( ctx
.file_version
<= 1.1 ) // <= 5.1.0
1033 hbfile_sanity_check();
1034 homebank_upgrade_to_v12();
1036 if( ctx
.data_version
<= 50106 ) // < 5.1.6
1038 homebank_upgrade_to_v12_7();
1040 if( ctx
.file_version
< 1.3 ) // <= 5.2
1042 hbfile_sanity_check();
1043 homebank_upgrade_to_v13();
1045 if( ctx
.data_version
<= 50203 )
1047 hbfile_sanity_check();
1059 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
1062 ** misc xml attributes methods
1064 static void hb_xml_append_txt(GString
*gstring
, gchar
*attrname
, gchar
*value
)
1066 if(value
!= NULL
&& *value
!= 0)
1068 gchar
*escaped
= g_markup_escape_text(value
, -1);
1069 g_string_append_printf(gstring
, " %s=\"%s\"", attrname
, escaped
);
1075 append_escaped_text (GString
*str
,
1084 end
= text
+ length
;
1089 next
= g_utf8_next_char (p
);
1094 g_string_append (str
, "&");
1098 g_string_append (str
, "<");
1102 g_string_append (str
, ">");
1106 g_string_append (str
, "'");
1110 g_string_append (str
, """);
1114 c
= g_utf8_get_char (p
);
1115 if ((0x1 <= c
&& c
<= 0x8) ||
1116 (0xa <= c
&& c
<= 0xd) || //chnaged here from b<->c to a<->d
1117 (0xe <= c
&& c
<= 0x1f) ||
1118 (0x7f <= c
&& c
<= 0x84) ||
1119 (0x86 <= c
&& c
<= 0x9f))
1120 g_string_append_printf (str
, "&#x%x;", c
);
1122 g_string_append_len (str
, p
, next
- p
);
1130 // we override g_markup_escape_text from glib to encode \n (LF) & \r (CR)
1131 static void hb_xml_append_txt_crlf(GString
*gstring
, gchar
*attrname
, gchar
*value
)
1133 if(value
!= NULL
&& *value
!= 0)
1138 //gchar *escaped = g_markup_escape_text(value, -1);
1139 length
= strlen (value
);
1140 escaped
= g_string_sized_new (length
);
1141 append_escaped_text (escaped
, value
, length
);
1142 g_string_append_printf(gstring
, " %s=\"%s\"", attrname
, escaped
->str
);
1143 g_string_free (escaped
, TRUE
);
1147 static void hb_xml_append_int0(GString
*gstring
, gchar
*attrname
, guint32 value
)
1149 g_string_append_printf(gstring
, " %s=\"%d\"", attrname
, value
);
1152 static void hb_xml_append_int(GString
*gstring
, gchar
*attrname
, guint32 value
)
1156 hb_xml_append_int0(gstring
, attrname
, value
);
1160 static void hb_xml_append_amt(GString
*gstring
, gchar
*attrname
, gdouble amount
)
1162 char buf
[G_ASCII_DTOSTR_BUF_SIZE
];
1164 //we must use this, as fprintf use locale decimal settings and not '.'
1165 g_ascii_dtostr (buf
, sizeof (buf
), amount
);
1166 g_string_append_printf(gstring
, " %s=\"%s\"", attrname
, buf
);
1170 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
1174 ** XML properties save
1176 static gint
homebank_save_xml_prop(GIOChannel
*io
)
1180 gint retval
= XML_OK
;
1181 GError
*error
= NULL
;
1183 title
= GLOBALS
->owner
== NULL
? "" : GLOBALS
->owner
;
1185 node
= g_string_sized_new(255);
1187 g_string_assign(node
, "<properties");
1189 hb_xml_append_txt(node
, "title", title
);
1190 hb_xml_append_int(node
, "curr", GLOBALS
->kcur
);
1191 hb_xml_append_int(node
, "car_category", GLOBALS
->vehicle_category
);
1192 hb_xml_append_int0(node
, "auto_smode", GLOBALS
->auto_smode
);
1193 hb_xml_append_int(node
, "auto_weekday", GLOBALS
->auto_weekday
);
1194 hb_xml_append_int(node
, "auto_nbdays", GLOBALS
->auto_nbdays
);
1196 g_string_append(node
, "/>\n");
1199 g_io_channel_write_chars(io
, node
->str
, -1, NULL
, &error
);
1202 retval
= XML_IO_ERROR
;
1203 g_error_free(error
);
1206 g_string_free(node
, TRUE
);
1212 ** XML currency save
1214 static gint
homebank_save_xml_cur(GIOChannel
*io
)
1218 char buf1
[G_ASCII_DTOSTR_BUF_SIZE
];
1219 gint retval
= XML_OK
;
1221 list
= g_hash_table_get_values(GLOBALS
->h_cur
);
1222 while (list
!= NULL
)
1224 Currency
*item
= list
->data
;
1226 tmpstr
= g_markup_printf_escaped(
1227 "<cur key=\"%d\" flags=\"%d\" iso=\"%s\" name=\"%s\" symb=\"%s\" syprf=\"%d\" dchar=\"%s\" gchar=\"%s\" frac=\"%d\" rate=\"%s\" mdate=\"%d\"/>\n",
1235 item
->grouping_char
,
1237 g_ascii_dtostr (buf1
, sizeof (buf1
), item
->rate
),
1241 g_io_channel_write_chars(io
, tmpstr
, -1, NULL
, NULL
);
1244 list
= g_list_next(list
);
1254 static gint
homebank_save_xml_acc(GIOChannel
*io
)
1258 gint retval
= XML_OK
;
1259 GError
*error
= NULL
;
1261 node
= g_string_sized_new(255);
1263 lacc
= list
= account_glist_sorted(0);
1264 while (list
!= NULL
)
1266 Account
*item
= list
->data
;
1268 item
->flags
&= ~(AF_ADDED
|AF_CHANGED
); //delete flag
1270 g_string_assign(node
, "<account");
1272 hb_xml_append_int(node
, "key", item
->key
);
1273 hb_xml_append_int(node
, "flags", item
->flags
);
1274 hb_xml_append_int(node
, "pos", item
->pos
);
1275 hb_xml_append_int(node
, "type", item
->type
);
1276 hb_xml_append_int(node
, "curr", item
->kcur
);
1277 hb_xml_append_txt(node
, "name", item
->name
);
1278 hb_xml_append_txt(node
, "number", item
->number
);
1279 hb_xml_append_txt(node
, "bankname", item
->bankname
);
1280 hb_xml_append_amt(node
, "initial", item
->initial
);
1282 hb_xml_append_amt(node
, "minimum", item
->minimum
);
1283 hb_xml_append_int(node
, "cheque1", item
->cheque1
);
1284 hb_xml_append_int(node
, "cheque2", item
->cheque2
);
1285 hb_xml_append_txt_crlf(node
, "notes", item
->notes
);
1286 hb_xml_append_int(node
, "tpl", item
->karc
);
1289 g_string_append(node
, "/>\n");
1292 g_io_channel_write_chars(io
, node
->str
, -1, NULL
, &error
);
1296 retval
= XML_IO_ERROR
;
1297 g_error_free(error
);
1300 list
= g_list_next(list
);
1303 g_string_free(node
, TRUE
);
1310 static gint
homebank_save_xml_pay(GIOChannel
*io
)
1314 gint retval
= XML_OK
;
1315 GError
*error
= NULL
;
1317 node
= g_string_sized_new(255);
1319 lpay
= list
= payee_glist_sorted(0);
1320 while (list
!= NULL
)
1322 Payee
*item
= list
->data
;
1326 g_string_assign(node
, "<pay");
1328 hb_xml_append_int(node
, "key", item
->key
);
1329 hb_xml_append_txt(node
, "name", item
->name
);
1330 hb_xml_append_int(node
, "category", item
->kcat
);
1331 hb_xml_append_int(node
, "paymode" , item
->paymode
);
1333 g_string_append(node
, "/>\n");
1336 g_io_channel_write_chars(io
, node
->str
, -1, NULL
, &error
);
1340 retval
= XML_IO_ERROR
;
1341 g_error_free(error
);
1345 list
= g_list_next(list
);
1348 g_string_free(node
, TRUE
);
1353 ** XML category save
1355 static gint
homebank_save_xml_cat(GIOChannel
*io
)
1359 char buf
[G_ASCII_DTOSTR_BUF_SIZE
];
1361 gint retval
= XML_OK
;
1362 GError
*error
= NULL
;
1364 node
= g_string_sized_new(255);
1366 lcat
= list
= category_glist_sorted(0);
1367 while (list
!= NULL
)
1369 Category
*item
= list
->data
;
1373 g_string_assign(node
, "<cat");
1375 hb_xml_append_int(node
, "key", item
->key
);
1376 hb_xml_append_int(node
, "parent", item
->parent
);
1377 hb_xml_append_int(node
, "flags", item
->flags
);
1378 hb_xml_append_txt(node
, "name", item
->name
);
1382 if(item
->budget
[i
] != 0)
1384 g_string_append_printf(node
," b%d=\"%s\"", i
, g_ascii_dtostr (buf
, sizeof (buf
), item
->budget
[i
]));
1388 g_string_append(node
, "/>\n");
1391 g_io_channel_write_chars(io
, node
->str
, -1, NULL
, &error
);
1395 retval
= XML_IO_ERROR
;
1396 g_error_free(error
);
1400 list
= g_list_next(list
);
1403 g_string_free(node
, TRUE
);
1410 /*static gint homebank_save_xml_tag(GIOChannel *io)
1414 gint retval = XML_OK;
1415 GError *error = NULL;
1417 ltag = list = tag_glist_sorted(0);
1418 while (list != NULL)
1420 Tag *item = list->data;
1424 tmpstr = g_markup_printf_escaped("<tag key=\"%d\" name=\"%s\"/>\n",
1430 g_io_channel_write_chars(io, tmpstr, -1, NULL, &error);
1435 retval = XML_IO_ERROR;
1436 g_error_free(error);
1439 list = g_list_next(list);
1449 static gint
homebank_save_xml_asg(GIOChannel
*io
)
1453 gint retval
= XML_OK
;
1454 GError
*error
= NULL
;
1456 node
= g_string_sized_new(255);
1458 lasg
= list
= assign_glist_sorted(0);
1459 while (list
!= NULL
)
1461 Assign
*item
= list
->data
;
1463 g_string_assign(node
, "<asg");
1465 hb_xml_append_int(node
, "key" , item
->key
);
1466 hb_xml_append_int(node
, "flags" , item
->flags
);
1467 hb_xml_append_int(node
, "field" , item
->field
);
1468 hb_xml_append_txt(node
, "name" , item
->text
);
1469 hb_xml_append_int(node
, "payee" , item
->kpay
);
1470 hb_xml_append_int(node
, "category", item
->kcat
);
1471 hb_xml_append_int(node
, "paymode" , item
->paymode
);
1473 g_string_append(node
, "/>\n");
1476 g_io_channel_write_chars(io
, node
->str
, -1, NULL
, &error
);
1480 retval
= XML_IO_ERROR
;
1481 g_error_free(error
);
1484 list
= g_list_next(list
);
1487 g_string_free(node
, TRUE
);
1496 static gint
homebank_save_xml_arc(GIOChannel
*io
)
1501 gint retval
= XML_OK
;
1502 GError
*error
= NULL
;
1504 node
= g_string_sized_new(255);
1506 list
= g_list_first(GLOBALS
->arc_list
);
1507 while (list
!= NULL
)
1509 Archive
*item
= list
->data
;
1511 tagstr
= tags_tostring(item
->tags
);
1513 g_string_assign(node
, "<fav");
1515 hb_xml_append_int(node
, "key", item
->key
);
1516 hb_xml_append_amt(node
, "amount", item
->amount
);
1517 hb_xml_append_int(node
, "account", item
->kacc
);
1518 hb_xml_append_int(node
, "dst_account", item
->kxferacc
);
1519 hb_xml_append_int(node
, "paymode", item
->paymode
);
1520 hb_xml_append_int(node
, "st", item
->status
);
1521 hb_xml_append_int(node
, "flags", item
->flags
);
1522 hb_xml_append_int(node
, "payee", item
->kpay
);
1523 hb_xml_append_int(node
, "category", item
->kcat
);
1524 hb_xml_append_txt(node
, "wording", item
->memo
);
1525 hb_xml_append_txt(node
, "tags", tagstr
);
1526 hb_xml_append_int(node
, "nextdate", item
->nextdate
);
1527 hb_xml_append_int(node
, "every", item
->every
);
1528 hb_xml_append_int(node
, "unit", item
->unit
);
1529 hb_xml_append_int(node
, "limit", item
->limit
);
1530 hb_xml_append_int(node
, "weekend", item
->weekend
);
1531 hb_xml_append_int(node
, "gap", item
->daygap
);
1533 if(da_splits_length(item
->splits
) > 0)
1535 gchar
*cats
, *amounts
, *memos
;
1537 da_splits_tostring(item
->splits
, &cats
, &amounts
, &memos
);
1538 g_string_append_printf(node
, " scat=\"%s\"", cats
);
1539 g_string_append_printf(node
, " samt=\"%s\"", amounts
);
1542 gchar
*escaped
= g_markup_escape_text(memos
, -1);
1543 g_string_append_printf(node
, " smem=\"%s\"", escaped
);
1551 g_string_append(node
, "/>\n");
1556 g_io_channel_write_chars(io
, node
->str
, -1, NULL
, &error
);
1559 retval
= XML_IO_ERROR
;
1560 g_error_free(error
);
1563 list
= g_list_next(list
);
1565 g_string_free(node
, TRUE
);
1571 ** XML transaction save
1573 static gint
homebank_save_xml_ope(GIOChannel
*io
)
1575 GList
*lst_acc
, *lnk_acc
;
1579 gint retval
= XML_OK
;
1580 GError
*error
= NULL
;
1582 node
= g_string_sized_new(255);
1584 lst_acc
= g_hash_table_get_values(GLOBALS
->h_acc
);
1585 lnk_acc
= g_list_first(lst_acc
);
1586 while (lnk_acc
!= NULL
)
1588 Account
*acc
= lnk_acc
->data
;
1590 list
= g_queue_peek_head_link(acc
->txn_queue
);
1591 while (list
!= NULL
)
1593 Transaction
*item
= list
->data
;
1595 item
->flags
&= ~(OF_AUTO
|OF_ADDED
|OF_CHANGED
); //delete flag
1596 tagstr
= tags_tostring(item
->tags
);
1598 g_string_assign(node
, "<ope");
1600 hb_xml_append_int(node
, "date", item
->date
);
1601 hb_xml_append_amt(node
, "amount", item
->amount
);
1602 hb_xml_append_int(node
, "account", item
->kacc
);
1603 hb_xml_append_int(node
, "dst_account", item
->kxferacc
);
1604 hb_xml_append_int(node
, "paymode", item
->paymode
);
1605 hb_xml_append_int(node
, "st", item
->status
);
1606 hb_xml_append_int(node
, "flags", item
->flags
);
1607 hb_xml_append_int(node
, "payee", item
->kpay
);
1608 hb_xml_append_int(node
, "category", item
->kcat
);
1609 hb_xml_append_txt(node
, "wording", item
->memo
);
1610 hb_xml_append_txt(node
, "info", item
->info
);
1611 hb_xml_append_txt(node
, "tags", tagstr
);
1612 hb_xml_append_int(node
, "kxfer", item
->kxfer
);
1614 if(da_splits_length(item
->splits
) > 0)
1616 gchar
*cats
, *amounts
, *memos
;
1618 da_splits_tostring(item
->splits
, &cats
, &amounts
, &memos
);
1619 g_string_append_printf(node
, " scat=\"%s\"", cats
);
1620 g_string_append_printf(node
, " samt=\"%s\"", amounts
);
1623 gchar
*escaped
= g_markup_escape_text(memos
, -1);
1624 g_string_append_printf(node
, " smem=\"%s\"", escaped
);
1632 g_string_append(node
, "/>\n");
1637 g_io_channel_write_chars(io
, node
->str
, -1, NULL
, &error
);
1641 retval
= XML_IO_ERROR
;
1642 g_error_free(error
);
1645 list
= g_list_next(list
);
1648 lnk_acc
= g_list_next(lnk_acc
);
1650 g_list_free(lst_acc
);
1652 g_string_free(node
, TRUE
);
1657 ** XML save homebank file: hbfile
1659 gint
homebank_save_xml(gchar
*filename
)
1662 char buf1
[G_ASCII_DTOSTR_BUF_SIZE
];
1664 gint retval
= XML_OK
;
1665 GError
*error
= NULL
;
1667 io
= g_io_channel_new_file(filename
, "w", &error
);
1670 g_warning("unable to save file %s: %s", filename
, error
->message
);
1671 g_error_free(error
);
1672 return(XML_IO_ERROR
);
1675 g_io_channel_write_chars(io
, "<?xml version=\"1.0\"?>\n", -1, NULL
, NULL
);
1677 outstr
= g_strdup_printf("<homebank v=\"%s\" d=\"%06d\">\n", g_ascii_dtostr (buf1
, sizeof (buf1
), FILE_VERSION
), HB_VERSION_NUM
);
1678 g_io_channel_write_chars(io
, outstr
, -1, NULL
, NULL
);
1681 retval
= homebank_save_xml_prop(io
);
1682 retval
= homebank_save_xml_cur(io
);
1683 retval
= homebank_save_xml_acc(io
);
1684 retval
= homebank_save_xml_pay(io
);
1685 retval
= homebank_save_xml_cat(io
);
1686 //retval = homebank_save_xml_tag(io);
1687 retval
= homebank_save_xml_asg(io
);
1688 retval
= homebank_save_xml_arc(io
);
1690 retval
= homebank_save_xml_ope(io
);
1692 g_io_channel_write_chars(io
, "</homebank>\n", -1, NULL
, NULL
);
1694 g_io_channel_unref (io
);
This page took 0.117237 seconds and 4 git commands to generate.