]>
Dogcows Code - chaz/homebank/blob - src/hb-xml.c
da67dad488e9b9a95a3c5b901d6140914e56736b
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"
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 // lower v0.6 : we must assume categories/payee exists
361 // and strong link to xfer
363 static void homebank_upgrade_lower_v06(void)
365 GList
*lst_acc
, *lnk_acc
;
370 DB( g_print("\n[hb-xml] homebank_upgrade_lower_v06\n") );
372 lst_acc
= g_hash_table_get_values(GLOBALS
->h_acc
);
373 lnk_acc
= g_list_first(lst_acc
);
374 while (lnk_acc
!= NULL
)
376 Account
*acc
= lnk_acc
->data
;
378 list
= g_queue_peek_head_link(acc
->txn_queue
);
381 Transaction
*entry
= list
->data
;
383 //also strong link internal xfer
384 if(entry
->paymode
== PAYMODE_INTXFER
&& entry
->kxfer
== 0)
386 Transaction
*child
= transaction_old_get_child_transfer(entry
);
389 transaction_xfer_change_to_child(entry
, child
);
393 da_transaction_consistency(entry
);
395 list
= g_list_next(list
);
397 lnk_acc
= g_list_next(lnk_acc
);
399 g_list_free(lst_acc
);
402 lrul
= list
= g_hash_table_get_values(GLOBALS
->h_rul
);
405 Assign
*entry
= list
->data
;
407 cat
= da_cat_get(entry
->kcat
);
410 DB( g_print(" !! fixing cat for rul: %d is unknow\n", entry
->kcat
) );
414 pay
= da_pay_get(entry
->kpay
);
417 DB( g_print(" !! fixing pay for rul: %d is unknow\n", entry
->kpay
) );
422 list
= g_list_next(list
);
428 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
431 static void homebank_load_xml_acc(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
433 Account
*entry
= da_acc_malloc();
436 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
438 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
440 if(!strcmp (attribute_names
[i
], "key" )) { entry
->key
= atoi(attribute_values
[i
]); }
441 else if(!strcmp (attribute_names
[i
], "flags" )) { entry
->flags
= atoi(attribute_values
[i
]); }
442 else if(!strcmp (attribute_names
[i
], "pos" )) { entry
->pos
= atoi(attribute_values
[i
]); }
443 else if(!strcmp (attribute_names
[i
], "type" )) { entry
->type
= atoi(attribute_values
[i
]); }
444 else if(!strcmp (attribute_names
[i
], "curr" )) { entry
->kcur
= atoi(attribute_values
[i
]); }
445 else if(!strcmp (attribute_names
[i
], "name" )) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->name
= g_strdup(attribute_values
[i
]); }
446 else if(!strcmp (attribute_names
[i
], "number" )) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->number
= g_strdup(attribute_values
[i
]); }
447 else if(!strcmp (attribute_names
[i
], "bankname")) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->bankname
= g_strdup(attribute_values
[i
]); }
448 else if(!strcmp (attribute_names
[i
], "initial" )) { entry
->initial
= g_ascii_strtod(attribute_values
[i
], NULL
); }
450 else if(!strcmp (attribute_names
[i
], "minimum" )) { entry
->minimum
= g_ascii_strtod(attribute_values
[i
], NULL
); }
451 else if(!strcmp (attribute_names
[i
], "cheque1" )) { entry
->cheque1
= atoi(attribute_values
[i
]); }
452 else if(!strcmp (attribute_names
[i
], "cheque2" )) { entry
->cheque2
= atoi(attribute_values
[i
]); }
453 else if(!strcmp (attribute_names
[i
], "notes" )) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->notes
= g_strdup(attribute_values
[i
]); }
456 //all attribute loaded: append
457 da_acc_insert(entry
);
461 static void homebank_load_xml_asg(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
463 Assign
*entry
= da_asg_malloc();
467 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
469 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
471 if(!strcmp (attribute_names
[i
], "key" )) { entry
->key
= atoi(attribute_values
[i
]); }
472 else if(!strcmp (attribute_names
[i
], "flags" )) { entry
->flags
= atoi(attribute_values
[i
]); }
473 else if(!strcmp (attribute_names
[i
], "field" )) { entry
->field
= atoi(attribute_values
[i
]); }
474 else if(!strcmp (attribute_names
[i
], "name" )) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->text
= g_strdup(attribute_values
[i
]); }
475 else if(!strcmp (attribute_names
[i
], "payee" )) { entry
->kpay
= atoi(attribute_values
[i
]); }
476 else if(!strcmp (attribute_names
[i
], "category")) { entry
->kcat
= atoi(attribute_values
[i
]); }
477 else if(!strcmp (attribute_names
[i
], "paymode" )) { entry
->paymode
= atoi(attribute_values
[i
]); }
479 else if(!strcmp (attribute_names
[i
], "exact" )) { exact
= atoi(attribute_values
[i
]); }
482 /* in v08 exact moved to flag */
483 if( ctx
->file_version
<= 0.7)
485 entry
->flags
= (ASGF_DOCAT
|ASGF_DOPAY
);
487 entry
->flags
|= ASGF_EXACT
;
490 //all attribute loaded: append
491 da_asg_append(entry
);
496 static void homebank_load_xml_pay(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
498 Payee
*entry
= da_pay_malloc();
501 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
503 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
505 if(!strcmp (attribute_names
[i
], "key" )) { entry
->key
= atoi(attribute_values
[i
]); }
506 //else if(!strcmp (attribute_names[i], "flags")) { entry->flags = atoi(attribute_values[i]); }
507 else if(!strcmp (attribute_names
[i
], "name" )) { entry
->name
= g_strdup(attribute_values
[i
]); }
508 else if(!strcmp (attribute_names
[i
], "category")) { entry
->kcat
= atoi(attribute_values
[i
]); }
509 else if(!strcmp (attribute_names
[i
], "paymode" )) { entry
->paymode
= atoi(attribute_values
[i
]); }
512 //all attribute loaded: append
513 da_pay_insert(entry
);
517 static void homebank_load_xml_prop(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
521 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
523 if(!strcmp (attribute_names
[i
], "title" )) { g_free(GLOBALS
->owner
); GLOBALS
->owner
= g_strdup(attribute_values
[i
]); }
524 else if(!strcmp (attribute_names
[i
], "curr" )) { GLOBALS
->kcur
= atoi(attribute_values
[i
]); }
525 else if(!strcmp (attribute_names
[i
], "car_category")) { GLOBALS
->vehicle_category
= atoi(attribute_values
[i
]); }
526 else if(!strcmp (attribute_names
[i
], "auto_smode" )) { GLOBALS
->auto_smode
= atoi(attribute_values
[i
]); }
527 else if(!strcmp (attribute_names
[i
], "auto_weekday")) { GLOBALS
->auto_weekday
= atoi(attribute_values
[i
]); }
528 else if(!strcmp (attribute_names
[i
], "auto_nbdays" )) { GLOBALS
->auto_nbdays
= atoi(attribute_values
[i
]); }
533 static void homebank_load_xml_cat(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
535 Category
*entry
= da_cat_malloc();
539 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
541 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
543 if(!strcmp (attribute_names
[i
], "key" )) { entry
->key
= atoi(attribute_values
[i
]); }
544 else if(!strcmp (attribute_names
[i
], "parent")) { entry
->parent
= atoi(attribute_values
[i
]); }
545 else if(!strcmp (attribute_names
[i
], "flags" )) { entry
->flags
= atoi(attribute_values
[i
]); }
546 else if(!strcmp (attribute_names
[i
], "name" )) { entry
->name
= g_strdup(attribute_values
[i
]); }
553 tmpname
= g_strdup_printf ("b%d", j
);
554 if(!(strcmp (attribute_names
[i
], tmpname
))) { entry
->budget
[j
] = g_ascii_strtod(attribute_values
[i
], NULL
); }
557 if(entry
->budget
[j
]) budget
= TRUE
;
560 entry
->flags
|= GF_BUDGET
;
564 //all attribute loaded: append
565 da_cat_insert( entry
);
569 static void homebank_load_xml_cur(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
571 Currency
*entry
= da_cur_malloc ();
574 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
576 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
578 if(!strcmp (attribute_names
[i
], "key" )) { entry
->key
= atoi(attribute_values
[i
]); }
579 else if(!strcmp (attribute_names
[i
], "flags" )) { entry
->flags
= atoi(attribute_values
[i
]); }
580 else if(!strcmp (attribute_names
[i
], "name" )) { entry
->name
= g_strdup(attribute_values
[i
]); }
581 else if(!strcmp (attribute_names
[i
], "iso" )) { entry
->iso_code
= g_strdup(attribute_values
[i
]); }
582 else if(!strcmp (attribute_names
[i
], "symb" )) { entry
->symbol
= g_strdup(attribute_values
[i
]); }
583 else if(!strcmp (attribute_names
[i
], "syprf" )) { entry
->sym_prefix
= atoi(attribute_values
[i
]); }
584 else if(!strcmp (attribute_names
[i
], "dchar" )) { entry
->decimal_char
= g_strdup(attribute_values
[i
]); }
585 else if(!strcmp (attribute_names
[i
], "gchar" )) { entry
->grouping_char
= g_strdup(attribute_values
[i
]); }
586 else if(!strcmp (attribute_names
[i
], "frac" )) { entry
->frac_digits
= atoi(attribute_values
[i
]); }
587 else if(!strcmp (attribute_names
[i
], "rate" )) { entry
->rate
= g_ascii_strtod(attribute_values
[i
], NULL
); }
588 else if(!strcmp (attribute_names
[i
], "mdate ")) { entry
->mdate
= atoi(attribute_values
[i
]); }
592 //all attribute loaded: append
593 da_cur_insert (entry
);
597 static void homebank_load_xml_tag(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
599 Tag
*entry
= da_tag_malloc();
602 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
604 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
606 if(!strcmp (attribute_names
[i
], "key" )) { entry
->key
= atoi(attribute_values
[i
]); }
607 //else if(!strcmp (attribute_names[i], "flags")) { entry->flags = atoi(attribute_values[i]); }
608 else if(!strcmp (attribute_names
[i
], "name" )) { entry
->name
= g_strdup(attribute_values
[i
]); }
611 //all attribute loaded: append
612 da_tag_insert(entry
);
616 static void homebank_load_xml_fav(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
618 Archive
*entry
= da_archive_malloc();
622 gboolean split
= FALSE
;
625 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
627 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
630 if(!strcmp (attribute_names
[i
], "amount" )) { entry
->amount
= g_ascii_strtod(attribute_values
[i
], NULL
); }
631 else if(!strcmp (attribute_names
[i
], "account" )) { entry
->kacc
= atoi(attribute_values
[i
]); }
632 else if(!strcmp (attribute_names
[i
], "dst_account")) { entry
->kxferacc
= atoi(attribute_values
[i
]); }
633 else if(!strcmp (attribute_names
[i
], "paymode" )) { entry
->paymode
= atoi(attribute_values
[i
]); }
634 else if(!strcmp (attribute_names
[i
], "st" )) { entry
->status
= atoi(attribute_values
[i
]); }
635 else if(!strcmp (attribute_names
[i
], "flags" )) { entry
->flags
= atoi(attribute_values
[i
]); }
636 else if(!strcmp (attribute_names
[i
], "payee" )) { entry
->kpay
= atoi(attribute_values
[i
]); }
637 else if(!strcmp (attribute_names
[i
], "category" )) { entry
->kcat
= atoi(attribute_values
[i
]); }
638 else if(!strcmp (attribute_names
[i
], "wording" )) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->memo
= g_strdup(attribute_values
[i
]); }
646 else if(!strcmp (attribute_names
[i
], "nextdate" )) { entry
->nextdate
= atoi(attribute_values
[i
]); }
647 else if(!strcmp (attribute_names
[i
], "every" )) { entry
->every
= atoi(attribute_values
[i
]); }
648 else if(!strcmp (attribute_names
[i
], "unit" )) { entry
->unit
= atoi(attribute_values
[i
]); }
649 else if(!strcmp (attribute_names
[i
], "limit" )) { entry
->limit
= atoi(attribute_values
[i
]); }
650 else if(!strcmp (attribute_names
[i
], "weekend" )) { entry
->weekend
= atoi(attribute_values
[i
]); }
651 else if(!strcmp (attribute_names
[i
], "gap" )) { entry
->daygap
= atoi(attribute_values
[i
]); }
652 else if(!strcmp (attribute_names
[i
], "scat" )) { scat
= (gchar
*)attribute_values
[i
]; split
= TRUE
; }
653 else if(!strcmp (attribute_names
[i
], "samt" )) { samt
= (gchar
*)attribute_values
[i
]; split
= TRUE
; }
654 else if(!strcmp (attribute_names
[i
], "smem" )) { smem
= (gchar
*)attribute_values
[i
]; split
= TRUE
; }
660 if (da_splits_parse(entry
->splits
, scat
, samt
, smem
) > 0)
662 entry
->flags
|= OF_SPLIT
; //Flag that Splits are active
666 //all attribute loaded: append
667 GLOBALS
->arc_list
= g_list_append(GLOBALS
->arc_list
, entry
);
671 static void homebank_load_xml_ope(ParseContext
*ctx
, const gchar
**attribute_names
, const gchar
**attribute_values
)
673 Transaction
*entry
= da_transaction_malloc();
677 gboolean split
= FALSE
;
680 for (i
= 0; attribute_names
[i
] != NULL
; i
++)
682 //DB( g_print(" att='%s' val='%s'\n", attribute_names[i], attribute_values[i]) );
684 if(!strcmp (attribute_names
[i
], "date" )) { entry
->date
= atoi(attribute_values
[i
]); }
685 else if(!strcmp (attribute_names
[i
], "amount" )) { entry
->amount
= g_ascii_strtod(attribute_values
[i
], NULL
); }
686 else if(!strcmp (attribute_names
[i
], "account" )) { entry
->kacc
= atoi(attribute_values
[i
]); }
687 else if(!strcmp (attribute_names
[i
], "dst_account")) { entry
->kxferacc
= atoi(attribute_values
[i
]); }
688 else if(!strcmp (attribute_names
[i
], "paymode" )) { entry
->paymode
= atoi(attribute_values
[i
]); }
689 else if(!strcmp (attribute_names
[i
], "st" )) { entry
->status
= atoi(attribute_values
[i
]); }
690 else if(!strcmp (attribute_names
[i
], "flags" )) { entry
->flags
= atoi(attribute_values
[i
]); }
691 else if(!strcmp (attribute_names
[i
], "payee" )) { entry
->kpay
= atoi(attribute_values
[i
]); }
692 else if(!strcmp (attribute_names
[i
], "category" )) { entry
->kcat
= atoi(attribute_values
[i
]); }
693 else if(!strcmp (attribute_names
[i
], "wording" )) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->memo
= g_strdup(attribute_values
[i
]); }
694 else if(!strcmp (attribute_names
[i
], "info" )) { if(strcmp(attribute_values
[i
],"(null)") && attribute_values
[i
] != NULL
) entry
->info
= g_strdup(attribute_values
[i
]); }
695 else if(!strcmp (attribute_names
[i
], "tags" ))
697 if(attribute_values
[i
] != NULL
&& strlen(attribute_values
[i
]) > 0 && strcmp(attribute_values
[i
],"(null)") != 0 )
699 transaction_tags_parse(entry
, attribute_values
[i
]);
702 else if(!strcmp (attribute_names
[i
], "kxfer" )) { entry
->kxfer
= atoi(attribute_values
[i
]); }
703 else if(!strcmp (attribute_names
[i
], "scat" )) { scat
= (gchar
*)attribute_values
[i
]; split
= TRUE
; }
704 else if(!strcmp (attribute_names
[i
], "samt" )) { samt
= (gchar
*)attribute_values
[i
]; split
= TRUE
; }
705 else if(!strcmp (attribute_names
[i
], "smem" )) { smem
= (gchar
*)attribute_values
[i
]; split
= TRUE
; }
709 //if(entry->kcat < 0)
714 if (da_splits_parse(entry
->splits
, scat
, samt
, smem
) > 0)
716 entry
->flags
|= OF_SPLIT
; //Flag that Splits are active
720 //all attribute loaded: append
721 // for perf reason we use prepend here, the list will be reversed later
722 da_transaction_prepend(entry
);
729 start_element_handler (GMarkupParseContext
*context
,
730 const gchar
*element_name
,
731 const gchar
**attribute_names
,
732 const gchar
**attribute_values
,
736 ParseContext
*ctx
= user_data
;
737 //GtkUIManager *self = ctx->self;
739 //DB( g_print("** start element: %s\n", element_name) );
741 switch(element_name
[0])
745 if(!strcmp (element_name
, "account")) //account
747 homebank_load_xml_acc(ctx
, attribute_names
, attribute_values
);
749 else if(!strcmp (element_name
, "asg")) //assign
751 homebank_load_xml_asg(ctx
, attribute_names
, attribute_values
);
758 if(!strcmp (element_name
, "pay"))
760 homebank_load_xml_pay(ctx
, attribute_names
, attribute_values
);
762 else if(!strcmp (element_name
, "properties"))
764 homebank_load_xml_prop(ctx
, attribute_names
, attribute_values
);
771 if(!strcmp (element_name
, "cat"))
773 homebank_load_xml_cat(ctx
, attribute_names
, attribute_values
);
775 else if(!strcmp (element_name
, "cur"))
777 homebank_load_xml_cur(ctx
, attribute_names
, attribute_values
);
784 if(!strcmp (element_name
, "tags"))
786 homebank_load_xml_tag(ctx
, attribute_names
, attribute_values
);
793 if(!strcmp (element_name
, "fav"))
795 homebank_load_xml_fav(ctx
, attribute_names
, attribute_values
);
802 if(!strcmp (element_name
, "ope"))
804 homebank_load_xml_ope(ctx
, attribute_names
, attribute_values
);
814 end_element_handler (GMarkupParseContext *context,
815 const gchar *element_name,
819 ParseContext *ctx = user_data;
821 //DB( g_print("-- end element: %s\n", element_name) );
827 static GMarkupParser hb_parser
= {
828 start_element_handler
,
829 NULL
, //end_element_handler,
830 NULL
, //text_handler,
836 static gboolean
hb_xml_get_version(ParseContext
*ctx
, gchar
*buffer
)
840 ctx
->file_version
= 0.0;
841 ctx
->data_version
= 0;
843 /* v3.4 add :: prevent load of future file version */
844 v_buffer
= g_strstr_len(buffer
, 50, "<homebank v=");
845 if( v_buffer
== NULL
)
848 DB( g_print("- id line: --(%.50s)\n\n", v_buffer
) );
850 ctx
->file_version
= g_ascii_strtod(v_buffer
+13, NULL
); /* a little hacky, but works ! */
851 if( ctx
->file_version
== 0.0 )
852 ctx
->file_version
= 0.1;
853 else if( ctx
->file_version
== 5.0 ) //was a mistake
854 ctx
->file_version
= 1.0;
856 v_buffer
= g_strstr_len(buffer
+13, 50, "d=");
859 DB( g_print(" d=%s)\n\n", v_buffer
) );
861 ctx
->data_version
= atoi(v_buffer
+3);
868 ** XML load homebank file: hbfile
870 gint
homebank_load_xml(gchar
*filename
)
875 GError
*error
= NULL
;
877 GMarkupParseContext
*context
;
880 DB( g_print("\n[hb-xml] homebank_load_xml\n") );
882 GValue filename_val
= G_VALUE_INIT
;
883 ext_hook("load_file", EXT_STRING(&filename_val
, filename
), NULL
);
886 if (!g_file_get_contents (filename
, &buffer
, &length
, &error
))
888 //g_message ("%s", error->message);
889 retval
= XML_IO_ERROR
;
890 g_error_free (error
);
894 if( hb_xml_get_version(&ctx
, buffer
) == FALSE
)
896 return XML_FILE_ERROR
;
899 if( ctx
.file_version
> FILE_VERSION
)
901 DB( g_print("- failed: version %f is not supported (max is %f)\n", ctx
.file_version
, FILE_VERSION
) );
902 return XML_VERSION_ERROR
;
906 DB( g_print("- file ok : v=%.1f data_v=%06d\n", ctx
.file_version
, ctx
.data_version
) );
908 /* 1st: validate the file is well in utf-8 */
909 DB( g_print("- ensure UTF-8\n") );
910 buffer
= homebank_utf8_ensure(buffer
);
912 /* then process the buffer */
914 GTimer
*t
= g_timer_new();
915 g_print("- start parse\n");
918 context
= g_markup_parse_context_new (&hb_parser
, 0, &ctx
, NULL
);
921 rc
= g_markup_parse_context_parse (context
, buffer
, length
, &error
);
924 g_print("failed: %s\n", error
->message
);
929 g_markup_parse_context_end_parse(context
, &error
);
932 g_print("failed: %s\n", error
->message
);
935 g_markup_parse_context_free (context
);
938 DB( g_print("- end parse : %f sec\n", g_timer_elapsed(t
, NULL
)) );
939 DB( g_timer_destroy (t
) );
941 /* file upgrade / bugfix */
942 // group a test for very old version
943 if( ctx
.file_version
<= 1.0 )
945 if( ctx
.file_version
<= 0.1 )
946 homebank_upgrade_to_v02();
947 if( ctx
.file_version
<= 0.2 )
948 homebank_upgrade_to_v03();
949 if( ctx
.file_version
<= 0.3 )
950 homebank_upgrade_to_v04();
951 if( ctx
.file_version
<= 0.4 )
952 homebank_upgrade_to_v05();
953 if( ctx
.file_version
<= 0.5 )
955 homebank_upgrade_to_v06();
956 homebank_upgrade_lower_v06();
958 if( ctx
.file_version
<= 0.6 )
960 homebank_upgrade_to_v07();
961 hbfile_sanity_check();
963 if( ctx
.file_version
<= 0.7 ) // <= 4.5
965 homebank_upgrade_to_v08();
967 if( ctx
.file_version
<= 0.8 ) // <= 4.6
969 hbfile_sanity_check();
971 if( ctx
.file_version
<= 0.9 ) // <= 4.6.3
973 hbfile_sanity_check();
974 homebank_upgrade_to_v10();
976 if( ctx
.file_version
<= 1.0 ) // <= 5.0.0
978 hbfile_sanity_check();
979 homebank_upgrade_to_v11();
983 //starting 5.0.4 data upgrade is done without changing file_version
984 //file version is changed only when the structure change
985 //don't start number below with 0 to avoid octal interpretation
986 if( ctx
.data_version
<= 50005 ) // <= 5.0.5
988 hbfile_sanity_check();
990 if( ctx
.file_version
<= 1.1 ) // <= 5.1.0
992 hbfile_sanity_check();
993 homebank_upgrade_to_v12();
995 if( ctx
.data_version
<= 50106 ) // < 5.1.6
997 homebank_upgrade_to_v12_7();
1009 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
1012 ** misc xml attributes methods
1014 static void hb_xml_append_txt(GString
*gstring
, gchar
*attrname
, gchar
*value
)
1016 if(value
!= NULL
&& *value
!= 0)
1018 gchar
*escaped
= g_markup_escape_text(value
, -1);
1019 g_string_append_printf(gstring
, "%s=\"%s\" ", attrname
, escaped
);
1025 append_escaped_text (GString
*str
,
1034 end
= text
+ length
;
1039 next
= g_utf8_next_char (p
);
1044 g_string_append (str
, "&");
1048 g_string_append (str
, "<");
1052 g_string_append (str
, ">");
1056 g_string_append (str
, "'");
1060 g_string_append (str
, """);
1064 c
= g_utf8_get_char (p
);
1065 if ((0x1 <= c
&& c
<= 0x8) ||
1066 (0xa <= c
&& c
<= 0xd) || //chnaged here from b<->c to a<->d
1067 (0xe <= c
&& c
<= 0x1f) ||
1068 (0x7f <= c
&& c
<= 0x84) ||
1069 (0x86 <= c
&& c
<= 0x9f))
1070 g_string_append_printf (str
, "&#x%x;", c
);
1072 g_string_append_len (str
, p
, next
- p
);
1080 // we override g_markup_escape_text from glib to encode \n (LF) & \r (CR)
1081 static void hb_xml_append_txt_crlf(GString
*gstring
, gchar
*attrname
, gchar
*value
)
1083 if(value
!= NULL
&& *value
!= 0)
1088 //gchar *escaped = g_markup_escape_text(value, -1);
1089 length
= strlen (value
);
1090 escaped
= g_string_sized_new (length
);
1091 append_escaped_text (escaped
, value
, length
);
1092 g_string_append_printf(gstring
, "%s=\"%s\" ", attrname
, escaped
->str
);
1093 g_string_free (escaped
, TRUE
);
1097 static void hb_xml_append_int0(GString
*gstring
, gchar
*attrname
, guint32 value
)
1099 g_string_append_printf(gstring
, "%s=\"%d\" ", attrname
, value
);
1102 static void hb_xml_append_int(GString
*gstring
, gchar
*attrname
, guint32 value
)
1106 hb_xml_append_int0(gstring
, attrname
, value
);
1110 static void hb_xml_append_amt(GString
*gstring
, gchar
*attrname
, gdouble amount
)
1112 char buf
[G_ASCII_DTOSTR_BUF_SIZE
];
1114 //we must use this, as fprintf use locale decimal settings and not '.'
1115 g_ascii_dtostr (buf
, sizeof (buf
), amount
);
1116 g_string_append_printf(gstring
, "%s=\"%s\" ", attrname
, buf
);
1120 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
1124 ** XML properties save
1126 static gint
homebank_save_xml_prop(GIOChannel
*io
)
1130 gint retval
= XML_OK
;
1131 GError
*error
= NULL
;
1133 title
= GLOBALS
->owner
== NULL
? "" : GLOBALS
->owner
;
1135 node
= g_string_sized_new(255);
1137 g_string_assign(node
, "<properties ");
1139 hb_xml_append_txt(node
, "title", title
);
1140 hb_xml_append_int(node
, "curr", GLOBALS
->kcur
);
1141 hb_xml_append_int(node
, "car_category", GLOBALS
->vehicle_category
);
1142 hb_xml_append_int0(node
, "auto_smode", GLOBALS
->auto_smode
);
1143 hb_xml_append_int(node
, "auto_weekday", GLOBALS
->auto_weekday
);
1144 hb_xml_append_int(node
, "auto_nbdays", GLOBALS
->auto_nbdays
);
1146 g_string_append(node
, "/>\n");
1149 g_io_channel_write_chars(io
, node
->str
, -1, NULL
, &error
);
1152 retval
= XML_IO_ERROR
;
1153 g_error_free(error
);
1156 g_string_free(node
, TRUE
);
1162 ** XML currency save
1164 static gint
homebank_save_xml_cur(GIOChannel
*io
)
1168 char buf1
[G_ASCII_DTOSTR_BUF_SIZE
];
1169 gint retval
= XML_OK
;
1171 list
= g_hash_table_get_values(GLOBALS
->h_cur
);
1172 while (list
!= NULL
)
1174 Currency
*item
= list
->data
;
1176 tmpstr
= g_markup_printf_escaped(
1177 "<cur key=\"%d\" flags=\"%d\" iso=\"%s\" name=\"%s\" symb=\"%s\" syprf=\"%d\" dchar=\"%s\" gchar=\"%s\" frac=\"%d\" rate=\"%s\" mdate=\"%d\"/>\n",
1185 item
->grouping_char
,
1187 g_ascii_dtostr (buf1
, sizeof (buf1
), item
->rate
),
1191 g_io_channel_write_chars(io
, tmpstr
, -1, NULL
, NULL
);
1194 list
= g_list_next(list
);
1204 static gint
homebank_save_xml_acc(GIOChannel
*io
)
1208 gint retval
= XML_OK
;
1209 GError
*error
= NULL
;
1211 node
= g_string_sized_new(255);
1213 lacc
= list
= account_glist_sorted(0);
1214 while (list
!= NULL
)
1216 Account
*item
= list
->data
;
1218 item
->flags
&= ~(AF_ADDED
|AF_CHANGED
); //delete flag
1220 g_string_assign(node
, "<account ");
1222 hb_xml_append_int(node
, "key", item
->key
);
1223 hb_xml_append_int(node
, "flags", item
->flags
);
1224 hb_xml_append_int(node
, "pos", item
->pos
);
1225 hb_xml_append_int(node
, "type", item
->type
);
1226 hb_xml_append_int(node
, "curr", item
->kcur
);
1227 hb_xml_append_txt(node
, "name", item
->name
);
1228 hb_xml_append_txt(node
, "number", item
->number
);
1229 hb_xml_append_txt(node
, "bankname", item
->bankname
);
1230 hb_xml_append_amt(node
, "initial", item
->initial
);
1232 hb_xml_append_amt(node
, "minimum", item
->minimum
);
1233 hb_xml_append_int(node
, "cheque1", item
->cheque1
);
1234 hb_xml_append_int(node
, "cheque2", item
->cheque2
);
1235 hb_xml_append_txt_crlf(node
, "notes", item
->notes
);
1237 g_string_append(node
, "/>\n");
1240 g_io_channel_write_chars(io
, node
->str
, -1, NULL
, &error
);
1244 retval
= XML_IO_ERROR
;
1245 g_error_free(error
);
1248 list
= g_list_next(list
);
1251 g_string_free(node
, TRUE
);
1258 static gint
homebank_save_xml_pay(GIOChannel
*io
)
1262 gint retval
= XML_OK
;
1263 GError
*error
= NULL
;
1265 node
= g_string_sized_new(255);
1267 lpay
= list
= payee_glist_sorted(0);
1268 while (list
!= NULL
)
1270 Payee
*item
= list
->data
;
1274 g_string_assign(node
, "<pay ");
1276 hb_xml_append_int(node
, "key", item
->key
);
1277 hb_xml_append_txt(node
, "name", item
->name
);
1278 hb_xml_append_int(node
, "category", item
->kcat
);
1279 hb_xml_append_int(node
, "paymode" , item
->paymode
);
1281 g_string_append(node
, "/>\n");
1284 g_io_channel_write_chars(io
, node
->str
, -1, NULL
, &error
);
1288 retval
= XML_IO_ERROR
;
1289 g_error_free(error
);
1293 list
= g_list_next(list
);
1296 g_string_free(node
, TRUE
);
1301 ** XML category save
1303 static gint
homebank_save_xml_cat(GIOChannel
*io
)
1307 char buf
[G_ASCII_DTOSTR_BUF_SIZE
];
1309 gint retval
= XML_OK
;
1310 GError
*error
= NULL
;
1312 node
= g_string_sized_new(255);
1314 lcat
= list
= category_glist_sorted(0);
1315 while (list
!= NULL
)
1317 Category
*item
= list
->data
;
1321 g_string_assign(node
, "<cat ");
1323 hb_xml_append_int(node
, "key", item
->key
);
1324 hb_xml_append_int(node
, "parent", item
->parent
);
1325 hb_xml_append_int(node
, "flags", item
->flags
);
1326 hb_xml_append_txt(node
, "name", item
->name
);
1330 if(item
->budget
[i
] != 0)
1332 g_string_append_printf(node
,"b%d=\"%s\" ", i
, g_ascii_dtostr (buf
, sizeof (buf
), item
->budget
[i
]));
1336 g_string_append(node
, "/>\n");
1339 g_io_channel_write_chars(io
, node
->str
, -1, NULL
, &error
);
1343 retval
= XML_IO_ERROR
;
1344 g_error_free(error
);
1348 list
= g_list_next(list
);
1351 g_string_free(node
, TRUE
);
1358 static gint
homebank_save_xml_tag(GIOChannel
*io
)
1362 gint retval
= XML_OK
;
1363 GError
*error
= NULL
;
1365 ltag
= list
= tag_glist_sorted(0);
1366 while (list
!= NULL
)
1368 Tag
*item
= list
->data
;
1372 tmpstr
= g_markup_printf_escaped("<tag key=\"%d\" name=\"%s\"/>\n",
1378 g_io_channel_write_chars(io
, tmpstr
, -1, NULL
, &error
);
1383 retval
= XML_IO_ERROR
;
1384 g_error_free(error
);
1387 list
= g_list_next(list
);
1397 static gint
homebank_save_xml_asg(GIOChannel
*io
)
1401 gint retval
= XML_OK
;
1402 GError
*error
= NULL
;
1404 node
= g_string_sized_new(255);
1406 lasg
= list
= assign_glist_sorted(0);
1407 while (list
!= NULL
)
1409 Assign
*item
= list
->data
;
1411 g_string_assign(node
, "<asg ");
1413 hb_xml_append_int(node
, "key" , item
->key
);
1414 hb_xml_append_int(node
, "flags" , item
->flags
);
1415 hb_xml_append_int(node
, "field" , item
->field
);
1416 hb_xml_append_txt(node
, "name" , item
->text
);
1417 hb_xml_append_int(node
, "payee" , item
->kpay
);
1418 hb_xml_append_int(node
, "category", item
->kcat
);
1419 hb_xml_append_int(node
, "paymode" , item
->paymode
);
1421 g_string_append(node
, "/>\n");
1424 g_io_channel_write_chars(io
, node
->str
, -1, NULL
, &error
);
1428 retval
= XML_IO_ERROR
;
1429 g_error_free(error
);
1432 list
= g_list_next(list
);
1435 g_string_free(node
, TRUE
);
1444 static gint
homebank_save_xml_arc(GIOChannel
*io
)
1448 gint retval
= XML_OK
;
1449 GError
*error
= NULL
;
1451 node
= g_string_sized_new(255);
1453 list
= g_list_first(GLOBALS
->arc_list
);
1454 while (list
!= NULL
)
1456 Archive
*item
= list
->data
;
1458 g_string_assign(node
, "<fav ");
1460 hb_xml_append_amt(node
, "amount", item
->amount
);
1461 hb_xml_append_int(node
, "account", item
->kacc
);
1462 hb_xml_append_int(node
, "dst_account", item
->kxferacc
);
1463 hb_xml_append_int(node
, "paymode", item
->paymode
);
1464 hb_xml_append_int(node
, "st", item
->status
);
1465 hb_xml_append_int(node
, "flags", item
->flags
);
1466 hb_xml_append_int(node
, "payee", item
->kpay
);
1467 hb_xml_append_int(node
, "category", item
->kcat
);
1468 hb_xml_append_txt(node
, "wording", item
->memo
);
1469 hb_xml_append_int(node
, "nextdate", item
->nextdate
);
1470 hb_xml_append_int(node
, "every", item
->every
);
1471 hb_xml_append_int(node
, "unit", item
->unit
);
1472 hb_xml_append_int(node
, "limit", item
->limit
);
1473 hb_xml_append_int(node
, "weekend", item
->weekend
);
1474 hb_xml_append_int(node
, "gap", item
->daygap
);
1476 if(da_splits_count(item
->splits
) > 0)
1478 gchar
*cats
, *amounts
, *memos
;
1480 da_splits_tostring(item
->splits
, &cats
, &amounts
, &memos
);
1481 g_string_append_printf(node
, "scat=\"%s\" ", cats
);
1482 g_string_append_printf(node
, "samt=\"%s\" ", amounts
);
1485 gchar
*escaped
= g_markup_escape_text(memos
, -1);
1486 g_string_append_printf(node
, "smem=\"%s\" ", escaped
);
1494 g_string_append(node
, "/>\n");
1497 g_io_channel_write_chars(io
, node
->str
, -1, NULL
, &error
);
1500 retval
= XML_IO_ERROR
;
1501 g_error_free(error
);
1504 list
= g_list_next(list
);
1506 g_string_free(node
, TRUE
);
1512 ** XML transaction save
1514 static gint
homebank_save_xml_ope(GIOChannel
*io
)
1516 GList
*lst_acc
, *lnk_acc
;
1520 gint retval
= XML_OK
;
1521 GError
*error
= NULL
;
1523 node
= g_string_sized_new(255);
1525 lst_acc
= g_hash_table_get_values(GLOBALS
->h_acc
);
1526 lnk_acc
= g_list_first(lst_acc
);
1527 while (lnk_acc
!= NULL
)
1529 Account
*acc
= lnk_acc
->data
;
1531 list
= g_queue_peek_head_link(acc
->txn_queue
);
1532 while (list
!= NULL
)
1534 Transaction
*item
= list
->data
;
1536 item
->flags
&= ~(OF_AUTO
|OF_ADDED
|OF_CHANGED
); //delete flag
1537 tagstr
= transaction_tags_tostring(item
);
1539 g_string_assign(node
, "<ope ");
1541 hb_xml_append_int(node
, "date", item
->date
);
1542 hb_xml_append_amt(node
, "amount", item
->amount
);
1543 hb_xml_append_int(node
, "account", item
->kacc
);
1544 hb_xml_append_int(node
, "dst_account", item
->kxferacc
);
1545 hb_xml_append_int(node
, "paymode", item
->paymode
);
1546 hb_xml_append_int(node
, "st", item
->status
);
1547 hb_xml_append_int(node
, "flags", item
->flags
);
1548 hb_xml_append_int(node
, "payee", item
->kpay
);
1549 hb_xml_append_int(node
, "category", item
->kcat
);
1550 hb_xml_append_txt(node
, "wording", item
->memo
);
1551 hb_xml_append_txt(node
, "info", item
->info
);
1552 hb_xml_append_txt(node
, "tags", tagstr
);
1553 hb_xml_append_int(node
, "kxfer", item
->kxfer
);
1555 if(da_splits_count(item
->splits
) > 0)
1557 gchar
*cats
, *amounts
, *memos
;
1559 da_splits_tostring(item
->splits
, &cats
, &amounts
, &memos
);
1560 g_string_append_printf(node
, "scat=\"%s\" ", cats
);
1561 g_string_append_printf(node
, "samt=\"%s\" ", amounts
);
1564 gchar
*escaped
= g_markup_escape_text(memos
, -1);
1565 g_string_append_printf(node
, "smem=\"%s\" ", escaped
);
1573 g_string_append(node
, "/>\n");
1578 g_io_channel_write_chars(io
, node
->str
, -1, NULL
, &error
);
1582 retval
= XML_IO_ERROR
;
1583 g_error_free(error
);
1586 list
= g_list_next(list
);
1589 lnk_acc
= g_list_next(lnk_acc
);
1591 g_list_free(lst_acc
);
1593 g_string_free(node
, TRUE
);
1598 ** XML save homebank file: hbfile
1600 gint
homebank_save_xml(gchar
*filename
)
1603 char buf1
[G_ASCII_DTOSTR_BUF_SIZE
];
1605 gint retval
= XML_OK
;
1606 GError
*error
= NULL
;
1608 GValue filename_val
= G_VALUE_INIT
;
1609 ext_hook("save_file", EXT_STRING(&filename_val
, filename
), NULL
);
1611 io
= g_io_channel_new_file(filename
, "w", &error
);
1614 g_message("file error on: %s", filename
);
1615 retval
= XML_IO_ERROR
;
1618 g_print("failed: %s\n", error
->message
);
1620 g_error_free(error
);
1624 g_io_channel_write_chars(io
, "<?xml version=\"1.0\"?>\n", -1, NULL
, NULL
);
1626 outstr
= g_strdup_printf("<homebank v=\"%s\" d=\"%06d\">\n", g_ascii_dtostr (buf1
, sizeof (buf1
), FILE_VERSION
), HB_VERSION_NUM
);
1627 g_io_channel_write_chars(io
, outstr
, -1, NULL
, NULL
);
1630 retval
= homebank_save_xml_prop(io
);
1631 retval
= homebank_save_xml_cur(io
);
1632 retval
= homebank_save_xml_acc(io
);
1633 retval
= homebank_save_xml_pay(io
);
1634 retval
= homebank_save_xml_cat(io
);
1635 retval
= homebank_save_xml_tag(io
);
1636 retval
= homebank_save_xml_asg(io
);
1637 retval
= homebank_save_xml_arc(io
);
1638 retval
= homebank_save_xml_ope(io
);
1640 g_io_channel_write_chars(io
, "</homebank>\n", -1, NULL
, NULL
);
1642 g_io_channel_unref (io
);
This page took 0.123164 seconds and 4 git commands to generate.