]>
Dogcows Code - chaz/homebank/blob - src/hb-xml.c
1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2018 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 // lower v0.6 : we must assume categories/payee exists
359 // and strong link to xfer
361 static void homebank_upgrade_lower_v06(void)
363 GList
*lst_acc
, *lnk_acc
;
368 DB( g_print("\n[hb-xml] homebank_upgrade_lower_v06\n") );
370 lst_acc
= g_hash_table_get_values(GLOBALS
->h_acc
);
371 lnk_acc
= g_list_first(lst_acc
);
372 while (lnk_acc
!= NULL
)
374 Account
*acc
= lnk_acc
->data
;
376 list
= g_queue_peek_head_link(acc
->txn_queue
);
379 Transaction
*entry
= list
->data
;
381 //also strong link internal xfer
382 if(entry
->paymode
== PAYMODE_INTXFER
&& entry
->kxfer
== 0)
384 Transaction
*child
= transaction_old_get_child_transfer(entry
);
387 transaction_xfer_change_to_child(entry
, child
);
391 da_transaction_consistency(entry
);
393 list
= g_list_next(list
);
395 lnk_acc
= g_list_next(lnk_acc
);
397 g_list_free(lst_acc
);
400 lrul
= list
= g_hash_table_get_values(GLOBALS
->h_rul
);
403 Assign
*entry
= list
->data
;
405 cat
= da_cat_get(entry
->kcat
);
408 DB( g_print(" !! fixing cat for rul: %d is unknow\n", entry
->kcat
) );
412 pay
= da_pay_get(entry
->kpay
);
415 DB( g_print(" !! fixing pay for rul: %d is unknow\n", entry
->kpay
) );
420 list
= g_list_next(list
);
426 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
429 static void homebank_load_xml_acc(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
431 Account
*entry
= da_acc_malloc();
434 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
436 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
438 if(!strcmp (attribute_names
[i
], "key" )) { entry
->key
= atoi(attribute_values
[i
]); }
439 else if(!strcmp (attribute_names
[i
], "flags" )) { entry
->flags
= atoi(attribute_values
[i
]); }
440 else if(!strcmp (attribute_names
[i
], "pos" )) { entry
->pos
= atoi(attribute_values
[i
]); }
441 else if(!strcmp (attribute_names
[i
], "type" )) { entry
->type
= atoi(attribute_values
[i
]); }
442 else if(!strcmp (attribute_names
[i
], "curr" )) { entry
->kcur
= atoi(attribute_values
[i
]); }
443 else if(!strcmp (attribute_names
[i
], "name" )) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->name
= g_strdup(attribute_values
[i
]); }
444 else if(!strcmp (attribute_names
[i
], "number" )) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->number
= g_strdup(attribute_values
[i
]); }
445 else if(!strcmp (attribute_names
[i
], "bankname")) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->bankname
= g_strdup(attribute_values
[i
]); }
446 else if(!strcmp (attribute_names
[i
], "initial" )) { entry
->initial
= g_ascii_strtod(attribute_values
[i
], NULL
); }
448 else if(!strcmp (attribute_names
[i
], "minimum" )) { entry
->minimum
= g_ascii_strtod(attribute_values
[i
], NULL
); }
449 else if(!strcmp (attribute_names
[i
], "cheque1" )) { entry
->cheque1
= atoi(attribute_values
[i
]); }
450 else if(!strcmp (attribute_names
[i
], "cheque2" )) { entry
->cheque2
= atoi(attribute_values
[i
]); }
451 else if(!strcmp (attribute_names
[i
], "notes" )) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->notes
= g_strdup(attribute_values
[i
]); }
454 //all attribute loaded: append
455 da_acc_insert(entry
);
459 static void homebank_load_xml_asg(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
461 Assign
*entry
= da_asg_malloc();
465 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
467 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
469 if(!strcmp (attribute_names
[i
], "key" )) { entry
->key
= atoi(attribute_values
[i
]); }
470 else if(!strcmp (attribute_names
[i
], "flags" )) { entry
->flags
= atoi(attribute_values
[i
]); }
471 else if(!strcmp (attribute_names
[i
], "field" )) { entry
->field
= atoi(attribute_values
[i
]); }
472 else if(!strcmp (attribute_names
[i
], "name" )) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->text
= g_strdup(attribute_values
[i
]); }
473 else if(!strcmp (attribute_names
[i
], "payee" )) { entry
->kpay
= atoi(attribute_values
[i
]); }
474 else if(!strcmp (attribute_names
[i
], "category")) { entry
->kcat
= atoi(attribute_values
[i
]); }
475 else if(!strcmp (attribute_names
[i
], "paymode" )) { entry
->paymode
= atoi(attribute_values
[i
]); }
477 else if(!strcmp (attribute_names
[i
], "exact" )) { exact
= atoi(attribute_values
[i
]); }
480 /* in v08 exact moved to flag */
481 if( ctx
->file_version
<= 0.7)
483 entry
->flags
= (ASGF_DOCAT
|ASGF_DOPAY
);
485 entry
->flags
|= ASGF_EXACT
;
488 //all attribute loaded: append
489 da_asg_append(entry
);
494 static void homebank_load_xml_pay(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
496 Payee
*entry
= da_pay_malloc();
499 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
501 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
503 if(!strcmp (attribute_names
[i
], "key" )) { entry
->key
= atoi(attribute_values
[i
]); }
504 //else if(!strcmp (attribute_names[i], "flags")) { entry->flags = atoi(attribute_values[i]); }
505 else if(!strcmp (attribute_names
[i
], "name" )) { entry
->name
= g_strdup(attribute_values
[i
]); }
506 else if(!strcmp (attribute_names
[i
], "category")) { entry
->kcat
= atoi(attribute_values
[i
]); }
507 else if(!strcmp (attribute_names
[i
], "paymode" )) { entry
->paymode
= atoi(attribute_values
[i
]); }
510 //all attribute loaded: append
511 da_pay_insert(entry
);
515 static void homebank_load_xml_prop(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
519 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
521 if(!strcmp (attribute_names
[i
], "title" )) { g_free(GLOBALS
->owner
); GLOBALS
->owner
= g_strdup(attribute_values
[i
]); }
522 else if(!strcmp (attribute_names
[i
], "curr" )) { GLOBALS
->kcur
= atoi(attribute_values
[i
]); }
523 else if(!strcmp (attribute_names
[i
], "car_category")) { GLOBALS
->vehicle_category
= atoi(attribute_values
[i
]); }
524 else if(!strcmp (attribute_names
[i
], "auto_smode" )) { GLOBALS
->auto_smode
= atoi(attribute_values
[i
]); }
525 else if(!strcmp (attribute_names
[i
], "auto_weekday")) { GLOBALS
->auto_weekday
= atoi(attribute_values
[i
]); }
526 else if(!strcmp (attribute_names
[i
], "auto_nbdays" )) { GLOBALS
->auto_nbdays
= atoi(attribute_values
[i
]); }
531 static void homebank_load_xml_cat(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
533 Category
*entry
= da_cat_malloc();
537 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
539 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
541 if(!strcmp (attribute_names
[i
], "key" )) { entry
->key
= atoi(attribute_values
[i
]); }
542 else if(!strcmp (attribute_names
[i
], "parent")) { entry
->parent
= atoi(attribute_values
[i
]); }
543 else if(!strcmp (attribute_names
[i
], "flags" )) { entry
->flags
= atoi(attribute_values
[i
]); }
544 else if(!strcmp (attribute_names
[i
], "name" )) { entry
->name
= g_strdup(attribute_values
[i
]); }
551 tmpname
= g_strdup_printf ("b%d", j
);
552 if(!(strcmp (attribute_names
[i
], tmpname
))) { entry
->budget
[j
] = g_ascii_strtod(attribute_values
[i
], NULL
); }
555 if(entry
->budget
[j
]) budget
= TRUE
;
558 entry
->flags
|= GF_BUDGET
;
562 //all attribute loaded: append
563 da_cat_insert( entry
);
567 static void homebank_load_xml_cur(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
569 Currency
*entry
= da_cur_malloc ();
572 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
574 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
576 if(!strcmp (attribute_names
[i
], "key" )) { entry
->key
= atoi(attribute_values
[i
]); }
577 else if(!strcmp (attribute_names
[i
], "flags" )) { entry
->flags
= atoi(attribute_values
[i
]); }
578 else if(!strcmp (attribute_names
[i
], "name" )) { entry
->name
= g_strdup(attribute_values
[i
]); }
579 else if(!strcmp (attribute_names
[i
], "iso" )) { entry
->iso_code
= g_strdup(attribute_values
[i
]); }
580 else if(!strcmp (attribute_names
[i
], "symb" )) { entry
->symbol
= g_strdup(attribute_values
[i
]); }
581 else if(!strcmp (attribute_names
[i
], "syprf" )) { entry
->sym_prefix
= atoi(attribute_values
[i
]); }
582 else if(!strcmp (attribute_names
[i
], "dchar" )) { entry
->decimal_char
= g_strdup(attribute_values
[i
]); }
583 else if(!strcmp (attribute_names
[i
], "gchar" )) { entry
->grouping_char
= g_strdup(attribute_values
[i
]); }
584 else if(!strcmp (attribute_names
[i
], "frac" )) { entry
->frac_digits
= atoi(attribute_values
[i
]); }
585 else if(!strcmp (attribute_names
[i
], "rate" )) { entry
->rate
= g_ascii_strtod(attribute_values
[i
], NULL
); }
586 else if(!strcmp (attribute_names
[i
], "mdate ")) { entry
->mdate
= atoi(attribute_values
[i
]); }
590 //all attribute loaded: append
591 da_cur_insert (entry
);
595 static void homebank_load_xml_tag(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
597 Tag
*entry
= da_tag_malloc();
600 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
602 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
604 if(!strcmp (attribute_names
[i
], "key" )) { entry
->key
= atoi(attribute_values
[i
]); }
605 //else if(!strcmp (attribute_names[i], "flags")) { entry->flags = atoi(attribute_values[i]); }
606 else if(!strcmp (attribute_names
[i
], "name" )) { entry
->name
= g_strdup(attribute_values
[i
]); }
609 //all attribute loaded: append
610 da_tag_insert(entry
);
614 static void homebank_load_xml_fav(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
616 Archive
*entry
= da_archive_malloc();
620 gboolean split
= FALSE
;
623 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
625 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
628 if(!strcmp (attribute_names
[i
], "amount" )) { entry
->amount
= g_ascii_strtod(attribute_values
[i
], NULL
); }
629 else if(!strcmp (attribute_names
[i
], "account" )) { entry
->kacc
= atoi(attribute_values
[i
]); }
630 else if(!strcmp (attribute_names
[i
], "dst_account")) { entry
->kxferacc
= atoi(attribute_values
[i
]); }
631 else if(!strcmp (attribute_names
[i
], "paymode" )) { entry
->paymode
= atoi(attribute_values
[i
]); }
632 else if(!strcmp (attribute_names
[i
], "st" )) { entry
->status
= atoi(attribute_values
[i
]); }
633 else if(!strcmp (attribute_names
[i
], "flags" )) { entry
->flags
= atoi(attribute_values
[i
]); }
634 else if(!strcmp (attribute_names
[i
], "payee" )) { entry
->kpay
= atoi(attribute_values
[i
]); }
635 else if(!strcmp (attribute_names
[i
], "category" )) { entry
->kcat
= atoi(attribute_values
[i
]); }
636 else if(!strcmp (attribute_names
[i
], "wording" )) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->memo
= g_strdup(attribute_values
[i
]); }
644 else if(!strcmp (attribute_names
[i
], "nextdate" )) { entry
->nextdate
= atoi(attribute_values
[i
]); }
645 else if(!strcmp (attribute_names
[i
], "every" )) { entry
->every
= atoi(attribute_values
[i
]); }
646 else if(!strcmp (attribute_names
[i
], "unit" )) { entry
->unit
= atoi(attribute_values
[i
]); }
647 else if(!strcmp (attribute_names
[i
], "limit" )) { entry
->limit
= atoi(attribute_values
[i
]); }
648 else if(!strcmp (attribute_names
[i
], "weekend" )) { entry
->weekend
= atoi(attribute_values
[i
]); }
649 else if(!strcmp (attribute_names
[i
], "gap" )) { entry
->daygap
= atoi(attribute_values
[i
]); }
650 else if(!strcmp (attribute_names
[i
], "scat" )) { scat
= (gchar
*)attribute_values
[i
]; split
= TRUE
; }
651 else if(!strcmp (attribute_names
[i
], "samt" )) { samt
= (gchar
*)attribute_values
[i
]; split
= TRUE
; }
652 else if(!strcmp (attribute_names
[i
], "smem" )) { smem
= (gchar
*)attribute_values
[i
]; split
= TRUE
; }
658 if (da_splits_parse(entry
->splits
, scat
, samt
, smem
) > 0)
660 entry
->flags
|= OF_SPLIT
; //Flag that Splits are active
664 //all attribute loaded: append
665 GLOBALS
->arc_list
= g_list_append(GLOBALS
->arc_list
, entry
);
669 static void homebank_load_xml_ope(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
671 Transaction
*entry
= da_transaction_malloc();
675 gboolean split
= FALSE
;
678 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
680 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
682 if(!strcmp (attribute_names
[i
], "date" )) { entry
->date
= atoi(attribute_values
[i
]); }
683 else if(!strcmp (attribute_names
[i
], "amount" )) { entry
->amount
= g_ascii_strtod(attribute_values
[i
], NULL
); }
684 else if(!strcmp (attribute_names
[i
], "account" )) { entry
->kacc
= atoi(attribute_values
[i
]); }
685 else if(!strcmp (attribute_names
[i
], "dst_account")) { entry
->kxferacc
= atoi(attribute_values
[i
]); }
686 else if(!strcmp (attribute_names
[i
], "paymode" )) { entry
->paymode
= atoi(attribute_values
[i
]); }
687 else if(!strcmp (attribute_names
[i
], "st" )) { entry
->status
= atoi(attribute_values
[i
]); }
688 else if(!strcmp (attribute_names
[i
], "flags" )) { entry
->flags
= atoi(attribute_values
[i
]); }
689 else if(!strcmp (attribute_names
[i
], "payee" )) { entry
->kpay
= atoi(attribute_values
[i
]); }
690 else if(!strcmp (attribute_names
[i
], "category" )) { entry
->kcat
= atoi(attribute_values
[i
]); }
691 else if(!strcmp (attribute_names
[i
], "wording" )) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->memo
= g_strdup(attribute_values
[i
]); }
692 else if(!strcmp (attribute_names
[i
], "info" )) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->info
= g_strdup(attribute_values
[i
]); }
693 else if(!strcmp (attribute_names
[i
], "tags" ))
695 if(attribute_values
[i
] != NULL
&& strlen(attribute_values
[i
]) > 0 && strcmp(attribute_values
[i
],"(null)") != 0 )
697 transaction_tags_parse(entry
, attribute_values
[i
]);
700 else if(!strcmp (attribute_names
[i
], "kxfer" )) { entry
->kxfer
= atoi(attribute_values
[i
]); }
701 else if(!strcmp (attribute_names
[i
], "scat" )) { scat
= (gchar
*)attribute_values
[i
]; split
= TRUE
; }
702 else if(!strcmp (attribute_names
[i
], "samt" )) { samt
= (gchar
*)attribute_values
[i
]; split
= TRUE
; }
703 else if(!strcmp (attribute_names
[i
], "smem" )) { smem
= (gchar
*)attribute_values
[i
]; split
= TRUE
; }
707 //if(entry->kcat < 0)
712 if (da_splits_parse(entry
->splits
, scat
, samt
, smem
) > 0)
714 entry
->flags
|= OF_SPLIT
; //Flag that Splits are active
718 //all attribute loaded: append
719 // for perf reason we use prepend here, the list will be reversed later
720 da_transaction_prepend(entry
);
727 start_element_handler (GMarkupParseContext
*context
,
728 const gchar
*element_name
,
729 const gchar
**attribute_names
,
730 const gchar
**attribute_values
,
734 ParseContext
*ctx
= user_data
;
735 //GtkUIManager *self = ctx->self;
737 //DB( g_print("** start element: %s\n", element_name) );
739 switch(element_name
[0])
743 if(!strcmp (element_name
, "account")) //account
745 homebank_load_xml_acc(ctx
, attribute_names
, attribute_values
);
747 else if(!strcmp (element_name
, "asg")) //assign
749 homebank_load_xml_asg(ctx
, attribute_names
, attribute_values
);
756 if(!strcmp (element_name
, "pay"))
758 homebank_load_xml_pay(ctx
, attribute_names
, attribute_values
);
760 else if(!strcmp (element_name
, "properties"))
762 homebank_load_xml_prop(ctx
, attribute_names
, attribute_values
);
769 if(!strcmp (element_name
, "cat"))
771 homebank_load_xml_cat(ctx
, attribute_names
, attribute_values
);
773 else if(!strcmp (element_name
, "cur"))
775 homebank_load_xml_cur(ctx
, attribute_names
, attribute_values
);
782 if(!strcmp (element_name
, "tags"))
784 homebank_load_xml_tag(ctx
, attribute_names
, attribute_values
);
791 if(!strcmp (element_name
, "fav"))
793 homebank_load_xml_fav(ctx
, attribute_names
, attribute_values
);
800 if(!strcmp (element_name
, "ope"))
802 homebank_load_xml_ope(ctx
, attribute_names
, attribute_values
);
812 end_element_handler (GMarkupParseContext *context,
813 const gchar *element_name,
817 ParseContext *ctx = user_data;
819 //DB( g_print("-- end element: %s\n", element_name) );
825 static GMarkupParser hb_parser
= {
826 start_element_handler
,
827 NULL
, //end_element_handler,
828 NULL
, //text_handler,
834 static gboolean
hb_xml_get_version(ParseContext
*ctx
, gchar
*buffer
)
838 ctx
->file_version
= 0.0;
839 ctx
->data_version
= 0;
841 /* v3.4 add :: prevent load of future file version */
842 v_buffer
= g_strstr_len(buffer
, 50, "<homebank v=");
843 if( v_buffer
== NULL
)
846 DB( g_print("- id line: --(%.50s)\n\n", v_buffer
) );
848 ctx
->file_version
= g_ascii_strtod(v_buffer
+13, NULL
); /* a little hacky, but works ! */
849 if( ctx
->file_version
== 0.0 )
850 ctx
->file_version
= 0.1;
851 else if( ctx
->file_version
== 5.0 ) //was a mistake
852 ctx
->file_version
= 1.0;
854 v_buffer
= g_strstr_len(buffer
+13, 50, "d=");
857 DB( g_print(" d=%s)\n\n", v_buffer
) );
859 ctx
->data_version
= atoi(v_buffer
+3);
866 ** XML load homebank file: hbfile
868 gint
homebank_load_xml(gchar
*filename
)
873 GError
*error
= NULL
;
875 GMarkupParseContext
*context
;
878 DB( g_print("\n[hb-xml] homebank_load_xml\n") );
881 if (!g_file_get_contents (filename
, &buffer
, &length
, &error
))
883 //g_message ("%s", error->message);
884 retval
= XML_IO_ERROR
;
885 g_error_free (error
);
889 if( hb_xml_get_version(&ctx
, buffer
) == FALSE
)
891 return XML_FILE_ERROR
;
894 if( ctx
.file_version
> FILE_VERSION
)
896 DB( g_print("- failed: version %f is not supported (max is %f)\n", ctx
.file_version
, FILE_VERSION
) );
897 return XML_VERSION_ERROR
;
901 DB( g_print("- file ok : v=%.1f data_v=%06d\n", ctx
.file_version
, ctx
.data_version
) );
903 /* 1st: validate the file is well in utf-8 */
904 DB( g_print("- ensure UTF-8\n") );
905 buffer
= homebank_utf8_ensure(buffer
);
907 /* then process the buffer */
909 GTimer
*t
= g_timer_new();
910 g_print("- start parse\n");
913 context
= g_markup_parse_context_new (&hb_parser
, 0, &ctx
, NULL
);
916 rc
= g_markup_parse_context_parse (context
, buffer
, length
, &error
);
919 g_print("failed: %s\n", error
->message
);
924 g_markup_parse_context_end_parse(context
, &error
);
927 g_print("failed: %s\n", error
->message
);
930 g_markup_parse_context_free (context
);
933 DB( g_print("- end parse : %f sec\n", g_timer_elapsed(t
, NULL
)) );
934 DB( g_timer_destroy (t
) );
936 /* file upgrade / bugfix */
937 // group a test for very old version
938 if( ctx
.file_version
<= 1.0 )
940 if( ctx
.file_version
<= 0.1 )
941 homebank_upgrade_to_v02();
942 if( ctx
.file_version
<= 0.2 )
943 homebank_upgrade_to_v03();
944 if( ctx
.file_version
<= 0.3 )
945 homebank_upgrade_to_v04();
946 if( ctx
.file_version
<= 0.4 )
947 homebank_upgrade_to_v05();
948 if( ctx
.file_version
<= 0.5 )
950 homebank_upgrade_to_v06();
951 homebank_upgrade_lower_v06();
953 if( ctx
.file_version
<= 0.6 )
955 homebank_upgrade_to_v07();
956 hbfile_sanity_check();
958 if( ctx
.file_version
<= 0.7 ) // <= 4.5
960 homebank_upgrade_to_v08();
962 if( ctx
.file_version
<= 0.8 ) // <= 4.6
964 hbfile_sanity_check();
966 if( ctx
.file_version
<= 0.9 ) // <= 4.6.3
968 hbfile_sanity_check();
969 homebank_upgrade_to_v10();
971 if( ctx
.file_version
<= 1.0 ) // <= 5.0.0
973 hbfile_sanity_check();
974 homebank_upgrade_to_v11();
978 //starting 5.0.4 data upgrade is done without changing file_version
979 //file version is changed only when the structure change
980 //don't start number below with 0 to avoid octal interpretation
981 if( ctx
.data_version
<= 50005 ) // <= 5.0.5
983 hbfile_sanity_check();
985 if( ctx
.file_version
<= 1.1 ) // <= 5.1.0
987 hbfile_sanity_check();
988 homebank_upgrade_to_v12();
990 if( ctx
.data_version
<= 50106 ) // < 5.1.6
992 homebank_upgrade_to_v12_7();
1004 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
1007 ** misc xml attributes methods
1009 static void hb_xml_append_txt(GString
*gstring
, gchar
*attrname
, gchar
*value
)
1011 if(value
!= NULL
&& *value
!= 0)
1013 gchar
*escaped
= g_markup_escape_text(value
, -1);
1014 g_string_append_printf(gstring
, "%s=\"%s\" ", attrname
, escaped
);
1020 append_escaped_text (GString
*str
,
1029 end
= text
+ length
;
1034 next
= g_utf8_next_char (p
);
1039 g_string_append (str
, "&");
1043 g_string_append (str
, "<");
1047 g_string_append (str
, ">");
1051 g_string_append (str
, "'");
1055 g_string_append (str
, """);
1059 c
= g_utf8_get_char (p
);
1060 if ((0x1 <= c
&& c
<= 0x8) ||
1061 (0xa <= c
&& c
<= 0xd) || //chnaged here from b<->c to a<->d
1062 (0xe <= c
&& c
<= 0x1f) ||
1063 (0x7f <= c
&& c
<= 0x84) ||
1064 (0x86 <= c
&& c
<= 0x9f))
1065 g_string_append_printf (str
, "&#x%x;", c
);
1067 g_string_append_len (str
, p
, next
- p
);
1075 // we override g_markup_escape_text from glib to encode \n (LF) & \r (CR)
1076 static void hb_xml_append_txt_crlf(GString
*gstring
, gchar
*attrname
, gchar
*value
)
1078 if(value
!= NULL
&& *value
!= 0)
1083 //gchar *escaped = g_markup_escape_text(value, -1);
1084 length
= strlen (value
);
1085 escaped
= g_string_sized_new (length
);
1086 append_escaped_text (escaped
, value
, length
);
1087 g_string_append_printf(gstring
, "%s=\"%s\" ", attrname
, escaped
->str
);
1088 g_string_free (escaped
, TRUE
);
1092 static void hb_xml_append_int0(GString
*gstring
, gchar
*attrname
, guint32 value
)
1094 g_string_append_printf(gstring
, "%s=\"%d\" ", attrname
, value
);
1097 static void hb_xml_append_int(GString
*gstring
, gchar
*attrname
, guint32 value
)
1101 hb_xml_append_int0(gstring
, attrname
, value
);
1105 static void hb_xml_append_amt(GString
*gstring
, gchar
*attrname
, gdouble amount
)
1107 char buf
[G_ASCII_DTOSTR_BUF_SIZE
];
1109 //we must use this, as fprintf use locale decimal settings and not '.'
1110 g_ascii_dtostr (buf
, sizeof (buf
), amount
);
1111 g_string_append_printf(gstring
, "%s=\"%s\" ", attrname
, buf
);
1115 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
1119 ** XML properties save
1121 static gint
homebank_save_xml_prop(GIOChannel
*io
)
1125 gint retval
= XML_OK
;
1126 GError
*error
= NULL
;
1128 title
= GLOBALS
->owner
== NULL
? "" : GLOBALS
->owner
;
1130 node
= g_string_sized_new(255);
1132 g_string_assign(node
, "<properties ");
1134 hb_xml_append_txt(node
, "title", title
);
1135 hb_xml_append_int(node
, "curr", GLOBALS
->kcur
);
1136 hb_xml_append_int(node
, "car_category", GLOBALS
->vehicle_category
);
1137 hb_xml_append_int0(node
, "auto_smode", GLOBALS
->auto_smode
);
1138 hb_xml_append_int(node
, "auto_weekday", GLOBALS
->auto_weekday
);
1139 hb_xml_append_int(node
, "auto_nbdays", GLOBALS
->auto_nbdays
);
1141 g_string_append(node
, "/>\n");
1144 g_io_channel_write_chars(io
, node
->str
, -1, NULL
, &error
);
1147 retval
= XML_IO_ERROR
;
1148 g_error_free(error
);
1151 g_string_free(node
, TRUE
);
1157 ** XML currency save
1159 static gint
homebank_save_xml_cur(GIOChannel
*io
)
1163 char buf1
[G_ASCII_DTOSTR_BUF_SIZE
];
1164 gint retval
= XML_OK
;
1166 list
= g_hash_table_get_values(GLOBALS
->h_cur
);
1167 while (list
!= NULL
)
1169 Currency
*item
= list
->data
;
1171 tmpstr
= g_markup_printf_escaped(
1172 "<cur key=\"%d\" flags=\"%d\" iso=\"%s\" name=\"%s\" symb=\"%s\" syprf=\"%d\" dchar=\"%s\" gchar=\"%s\" frac=\"%d\" rate=\"%s\" mdate=\"%d\"/>\n",
1180 item
->grouping_char
,
1182 g_ascii_dtostr (buf1
, sizeof (buf1
), item
->rate
),
1186 g_io_channel_write_chars(io
, tmpstr
, -1, NULL
, NULL
);
1189 list
= g_list_next(list
);
1199 static gint
homebank_save_xml_acc(GIOChannel
*io
)
1203 gint retval
= XML_OK
;
1204 GError
*error
= NULL
;
1206 node
= g_string_sized_new(255);
1208 lacc
= list
= account_glist_sorted(0);
1209 while (list
!= NULL
)
1211 Account
*item
= list
->data
;
1213 item
->flags
&= ~(AF_ADDED
|AF_CHANGED
); //delete flag
1215 g_string_assign(node
, "<account ");
1217 hb_xml_append_int(node
, "key", item
->key
);
1218 hb_xml_append_int(node
, "flags", item
->flags
);
1219 hb_xml_append_int(node
, "pos", item
->pos
);
1220 hb_xml_append_int(node
, "type", item
->type
);
1221 hb_xml_append_int(node
, "curr", item
->kcur
);
1222 hb_xml_append_txt(node
, "name", item
->name
);
1223 hb_xml_append_txt(node
, "number", item
->number
);
1224 hb_xml_append_txt(node
, "bankname", item
->bankname
);
1225 hb_xml_append_amt(node
, "initial", item
->initial
);
1227 hb_xml_append_amt(node
, "minimum", item
->minimum
);
1228 hb_xml_append_int(node
, "cheque1", item
->cheque1
);
1229 hb_xml_append_int(node
, "cheque2", item
->cheque2
);
1230 hb_xml_append_txt_crlf(node
, "notes", item
->notes
);
1232 g_string_append(node
, "/>\n");
1235 g_io_channel_write_chars(io
, node
->str
, -1, NULL
, &error
);
1239 retval
= XML_IO_ERROR
;
1240 g_error_free(error
);
1243 list
= g_list_next(list
);
1246 g_string_free(node
, TRUE
);
1253 static gint
homebank_save_xml_pay(GIOChannel
*io
)
1257 gint retval
= XML_OK
;
1258 GError
*error
= NULL
;
1260 node
= g_string_sized_new(255);
1262 lpay
= list
= payee_glist_sorted(0);
1263 while (list
!= NULL
)
1265 Payee
*item
= list
->data
;
1269 g_string_assign(node
, "<pay ");
1271 hb_xml_append_int(node
, "key", item
->key
);
1272 hb_xml_append_txt(node
, "name", item
->name
);
1273 hb_xml_append_int(node
, "category", item
->kcat
);
1274 hb_xml_append_int(node
, "paymode" , item
->paymode
);
1276 g_string_append(node
, "/>\n");
1279 g_io_channel_write_chars(io
, node
->str
, -1, NULL
, &error
);
1283 retval
= XML_IO_ERROR
;
1284 g_error_free(error
);
1288 list
= g_list_next(list
);
1291 g_string_free(node
, TRUE
);
1296 ** XML category save
1298 static gint
homebank_save_xml_cat(GIOChannel
*io
)
1302 char buf
[G_ASCII_DTOSTR_BUF_SIZE
];
1304 gint retval
= XML_OK
;
1305 GError
*error
= NULL
;
1307 node
= g_string_sized_new(255);
1309 lcat
= list
= category_glist_sorted(0);
1310 while (list
!= NULL
)
1312 Category
*item
= list
->data
;
1316 g_string_assign(node
, "<cat ");
1318 hb_xml_append_int(node
, "key", item
->key
);
1319 hb_xml_append_int(node
, "parent", item
->parent
);
1320 hb_xml_append_int(node
, "flags", item
->flags
);
1321 hb_xml_append_txt(node
, "name", item
->name
);
1325 if(item
->budget
[i
] != 0)
1327 g_string_append_printf(node
,"b%d=\"%s\" ", i
, g_ascii_dtostr (buf
, sizeof (buf
), item
->budget
[i
]));
1331 g_string_append(node
, "/>\n");
1334 g_io_channel_write_chars(io
, node
->str
, -1, NULL
, &error
);
1338 retval
= XML_IO_ERROR
;
1339 g_error_free(error
);
1343 list
= g_list_next(list
);
1346 g_string_free(node
, TRUE
);
1353 static gint
homebank_save_xml_tag(GIOChannel
*io
)
1357 gint retval
= XML_OK
;
1358 GError
*error
= NULL
;
1360 ltag
= list
= tag_glist_sorted(0);
1361 while (list
!= NULL
)
1363 Tag
*item
= list
->data
;
1367 tmpstr
= g_markup_printf_escaped("<tag key=\"%d\" name=\"%s\"/>\n",
1373 g_io_channel_write_chars(io
, tmpstr
, -1, NULL
, &error
);
1378 retval
= XML_IO_ERROR
;
1379 g_error_free(error
);
1382 list
= g_list_next(list
);
1392 static gint
homebank_save_xml_asg(GIOChannel
*io
)
1396 gint retval
= XML_OK
;
1397 GError
*error
= NULL
;
1399 node
= g_string_sized_new(255);
1401 lasg
= list
= assign_glist_sorted(0);
1402 while (list
!= NULL
)
1404 Assign
*item
= list
->data
;
1406 g_string_assign(node
, "<asg ");
1408 hb_xml_append_int(node
, "key" , item
->key
);
1409 hb_xml_append_int(node
, "flags" , item
->flags
);
1410 hb_xml_append_int(node
, "field" , item
->field
);
1411 hb_xml_append_txt(node
, "name" , item
->text
);
1412 hb_xml_append_int(node
, "payee" , item
->kpay
);
1413 hb_xml_append_int(node
, "category", item
->kcat
);
1414 hb_xml_append_int(node
, "paymode" , item
->paymode
);
1416 g_string_append(node
, "/>\n");
1419 g_io_channel_write_chars(io
, node
->str
, -1, NULL
, &error
);
1423 retval
= XML_IO_ERROR
;
1424 g_error_free(error
);
1427 list
= g_list_next(list
);
1430 g_string_free(node
, TRUE
);
1439 static gint
homebank_save_xml_arc(GIOChannel
*io
)
1443 gint retval
= XML_OK
;
1444 GError
*error
= NULL
;
1446 node
= g_string_sized_new(255);
1448 list
= g_list_first(GLOBALS
->arc_list
);
1449 while (list
!= NULL
)
1451 Archive
*item
= list
->data
;
1453 g_string_assign(node
, "<fav ");
1455 hb_xml_append_amt(node
, "amount", item
->amount
);
1456 hb_xml_append_int(node
, "account", item
->kacc
);
1457 hb_xml_append_int(node
, "dst_account", item
->kxferacc
);
1458 hb_xml_append_int(node
, "paymode", item
->paymode
);
1459 hb_xml_append_int(node
, "st", item
->status
);
1460 hb_xml_append_int(node
, "flags", item
->flags
);
1461 hb_xml_append_int(node
, "payee", item
->kpay
);
1462 hb_xml_append_int(node
, "category", item
->kcat
);
1463 hb_xml_append_txt(node
, "wording", item
->memo
);
1464 hb_xml_append_int(node
, "nextdate", item
->nextdate
);
1465 hb_xml_append_int(node
, "every", item
->every
);
1466 hb_xml_append_int(node
, "unit", item
->unit
);
1467 hb_xml_append_int(node
, "limit", item
->limit
);
1468 hb_xml_append_int(node
, "weekend", item
->weekend
);
1469 hb_xml_append_int(node
, "gap", item
->daygap
);
1471 if(da_splits_count(item
->splits
) > 0)
1473 gchar
*cats
, *amounts
, *memos
;
1475 da_splits_tostring(item
->splits
, &cats
, &amounts
, &memos
);
1476 g_string_append_printf(node
, "scat=\"%s\" ", cats
);
1477 g_string_append_printf(node
, "samt=\"%s\" ", amounts
);
1480 gchar
*escaped
= g_markup_escape_text(memos
, -1);
1481 g_string_append_printf(node
, "smem=\"%s\" ", escaped
);
1489 g_string_append(node
, "/>\n");
1492 g_io_channel_write_chars(io
, node
->str
, -1, NULL
, &error
);
1495 retval
= XML_IO_ERROR
;
1496 g_error_free(error
);
1499 list
= g_list_next(list
);
1501 g_string_free(node
, TRUE
);
1507 ** XML transaction save
1509 static gint
homebank_save_xml_ope(GIOChannel
*io
)
1511 GList
*lst_acc
, *lnk_acc
;
1515 gint retval
= XML_OK
;
1516 GError
*error
= NULL
;
1518 node
= g_string_sized_new(255);
1520 lst_acc
= g_hash_table_get_values(GLOBALS
->h_acc
);
1521 lnk_acc
= g_list_first(lst_acc
);
1522 while (lnk_acc
!= NULL
)
1524 Account
*acc
= lnk_acc
->data
;
1526 list
= g_queue_peek_head_link(acc
->txn_queue
);
1527 while (list
!= NULL
)
1529 Transaction
*item
= list
->data
;
1531 item
->flags
&= ~(OF_AUTO
|OF_ADDED
|OF_CHANGED
); //delete flag
1532 tagstr
= transaction_tags_tostring(item
);
1534 g_string_assign(node
, "<ope ");
1536 hb_xml_append_int(node
, "date", item
->date
);
1537 hb_xml_append_amt(node
, "amount", item
->amount
);
1538 hb_xml_append_int(node
, "account", item
->kacc
);
1539 hb_xml_append_int(node
, "dst_account", item
->kxferacc
);
1540 hb_xml_append_int(node
, "paymode", item
->paymode
);
1541 hb_xml_append_int(node
, "st", item
->status
);
1542 hb_xml_append_int(node
, "flags", item
->flags
);
1543 hb_xml_append_int(node
, "payee", item
->kpay
);
1544 hb_xml_append_int(node
, "category", item
->kcat
);
1545 hb_xml_append_txt(node
, "wording", item
->memo
);
1546 hb_xml_append_txt(node
, "info", item
->info
);
1547 hb_xml_append_txt(node
, "tags", tagstr
);
1548 hb_xml_append_int(node
, "kxfer", item
->kxfer
);
1550 if(da_splits_count(item
->splits
) > 0)
1552 gchar
*cats
, *amounts
, *memos
;
1554 da_splits_tostring(item
->splits
, &cats
, &amounts
, &memos
);
1555 g_string_append_printf(node
, "scat=\"%s\" ", cats
);
1556 g_string_append_printf(node
, "samt=\"%s\" ", amounts
);
1559 gchar
*escaped
= g_markup_escape_text(memos
, -1);
1560 g_string_append_printf(node
, "smem=\"%s\" ", escaped
);
1568 g_string_append(node
, "/>\n");
1573 g_io_channel_write_chars(io
, node
->str
, -1, NULL
, &error
);
1577 retval
= XML_IO_ERROR
;
1578 g_error_free(error
);
1581 list
= g_list_next(list
);
1584 lnk_acc
= g_list_next(lnk_acc
);
1586 g_list_free(lst_acc
);
1588 g_string_free(node
, TRUE
);
1593 ** XML save homebank file: hbfile
1595 gint
homebank_save_xml(gchar
*filename
)
1598 char buf1
[G_ASCII_DTOSTR_BUF_SIZE
];
1600 gint retval
= XML_OK
;
1601 GError
*error
= NULL
;
1603 io
= g_io_channel_new_file(filename
, "w", &error
);
1606 g_message("file error on: %s", filename
);
1607 retval
= XML_IO_ERROR
;
1610 g_print("failed: %s\n", error
->message
);
1612 g_error_free(error
);
1616 g_io_channel_write_chars(io
, "<?xml version=\"1.0\"?>\n", -1, NULL
, NULL
);
1618 outstr
= g_strdup_printf("<homebank v=\"%s\" d=\"%06d\">\n", g_ascii_dtostr (buf1
, sizeof (buf1
), FILE_VERSION
), HB_VERSION_NUM
);
1619 g_io_channel_write_chars(io
, outstr
, -1, NULL
, NULL
);
1622 retval
= homebank_save_xml_prop(io
);
1623 retval
= homebank_save_xml_cur(io
);
1624 retval
= homebank_save_xml_acc(io
);
1625 retval
= homebank_save_xml_pay(io
);
1626 retval
= homebank_save_xml_cat(io
);
1627 retval
= homebank_save_xml_tag(io
);
1628 retval
= homebank_save_xml_asg(io
);
1629 retval
= homebank_save_xml_arc(io
);
1630 retval
= homebank_save_xml_ope(io
);
1632 g_io_channel_write_chars(io
, "</homebank>\n", -1, NULL
, NULL
);
1634 g_io_channel_unref (io
);
This page took 0.120848 seconds and 5 git commands to generate.