static void compare_account_trees( QofBook* book_1, QofBook* book_2 ) { Account* root_1 = gnc_book_get_root_account( book_1 ); Account* root_2 = gnc_book_get_root_account( book_2 ); xaccAccountSetHidden( root_1, xaccAccountGetHidden( root_1 ) ); do_test( xaccAccountEqual( root_1, root_2, FALSE ), "Accounts trees match" ); }
static void fill_model (FindAccountDialog *facc_dialog, Account *account) { GtkTreeModel *model; GtkTreeIter iter; gchar *fullname = gnc_account_get_full_name (account); gint splits = xaccAccountCountSplits (account, TRUE); gnc_numeric total = xaccAccountGetBalanceInCurrency (account, NULL, TRUE); PINFO("Add to Store: Account '%s'", fullname); model = gtk_tree_view_get_model (GTK_TREE_VIEW(facc_dialog->view)); gtk_list_store_append (GTK_LIST_STORE(model), &iter); gtk_list_store_set (GTK_LIST_STORE(model), &iter, ACC_FULL_NAME, fullname, ACCOUNT, account, PLACE_HOLDER, (xaccAccountGetPlaceholder (account) == TRUE ? GTK_STOCK_YES : NULL), HIDDEN, (xaccAccountGetHidden (account) == TRUE ? GTK_STOCK_YES : NULL), NOT_USED, (splits == 0 ? GTK_STOCK_YES : NULL), BAL_ZERO, (gnc_numeric_zero_p (total) == TRUE ? GTK_STOCK_YES : NULL), -1); g_free (fullname); }
static gchar* node_and_account_equal (xmlNodePtr node, Account* act) { xmlNodePtr mark; while (g_strcmp0 ((char*)node->name, "text") == 0) { node = node->next; } if (!check_dom_tree_version (node, "2.0.0")) { return g_strdup ("version wrong. Not 2.0.0 or not there"); } if (!node->name || g_strcmp0 ((char*)node->name, "gnc:account")) { return g_strdup ("Name of toplevel node is bad"); } for (mark = node->xmlChildrenNode; mark; mark = mark->next) { if (g_strcmp0 ((char*)mark->name, "text") == 0) { } else if (g_strcmp0 ((char*)mark->name, "act:name") == 0) { if (!equals_node_val_vs_string (mark, xaccAccountGetName (act))) { return g_strdup ("names differ"); } } else if (g_strcmp0 ((char*)mark->name, "act:id") == 0) { if (!equals_node_val_vs_guid (mark, xaccAccountGetGUID (act))) { return g_strdup ("ids differ"); } } else if (g_strcmp0 ((char*)mark->name, "act:type") == 0) { gchar* txt; GNCAccountType type; txt = dom_tree_to_text (mark); if (!txt) { return g_strdup ("couldn't get type string"); } else if (!xaccAccountStringToType (txt, &type)) { g_free (txt); return g_strdup ("couldn't convert type string to int"); } else if (type != xaccAccountGetType (act)) { g_free (txt); return g_strdup ("types differ"); } else { g_free (txt); } } else if (g_strcmp0 ((char*)mark->name, "act:commodity") == 0) { /* This is somewhat BS, because if the commodity isn't a currency (and therefore built in) there isn't a corresponding currency in the XML, skip the test. jralls 2010-11-02 */ if (xaccAccountGetCommodity (act) == NULL) continue; if (!equals_node_val_vs_commodity ( mark, xaccAccountGetCommodity (act), gnc_account_get_book (act))) { return g_strdup ("commodities differ"); } } else if (g_strcmp0 ((char*)mark->name, "act:code") == 0) { if (!equals_node_val_vs_string (mark, xaccAccountGetCode (act))) { return g_strdup ("codes differ"); } } else if (g_strcmp0 ((char*)mark->name, "act:description") == 0) { if (!equals_node_val_vs_string ( mark, xaccAccountGetDescription (act))) { return g_strdup ("descriptions differ"); } } else if (g_strcmp0 ((char*)mark->name, "act:slots") == 0) { /* xaccAccountDeleteOldData (act); */ if (!equals_node_val_vs_kvp_frame (mark, qof_instance_get_slots (QOF_INSTANCE (act)))) { return g_strdup ("slots differ"); } } else if (g_strcmp0 ((char*)mark->name, "act:parent") == 0) { if (!equals_node_val_vs_guid ( mark, xaccAccountGetGUID (gnc_account_get_parent (act)))) { return g_strdup ("parent ids differ"); } } else if (g_strcmp0 ((char*)mark->name, "act:commodity-scu") == 0) { if (!equals_node_val_vs_int (mark, xaccAccountGetCommoditySCU (act))) { return g_strdup ("commodity scus differ"); } } else if (g_strcmp0 ((char*)mark->name, "act:hidden") == 0) { if (!equals_node_val_vs_boolean (mark, xaccAccountGetHidden (act))) { return g_strdup ("Hidden flags differ"); } } else if (g_strcmp0 ((char*)mark->name, "act:placeholder") == 0) { if (!equals_node_val_vs_boolean (mark, xaccAccountGetPlaceholder (act))) { return g_strdup ("Placeholder flags differ"); } } else if (g_strcmp0 ((char*)mark->name, "act:security") == 0) { return NULL; // This tag is ignored. } else { return g_strdup_printf ("unknown node in dom tree: %s", mark->name); } } return NULL; }
/******************************************************* * csv_tree_export * * write a list of accounts settings to a text file *******************************************************/ void csv_tree_export (CsvExportInfo *info) { FILE *fh; Account *root; Account *acc; GList *accts, *ptr; ENTER(""); DEBUG("File name is : %s", info->file_name); /* Get list of Accounts */ root = gnc_book_get_root_account (gnc_get_current_book()); accts = gnc_account_get_descendants_sorted (root); info->failed = FALSE; /* Open File for writing */ fh = g_fopen (info->file_name, "w"); if (fh != NULL) { gchar *header; gchar *part1; gchar *part2; const gchar *currentSel; gchar *end_sep; gchar *mid_sep; int i; /* Set up separators */ if (info->use_quotes) { end_sep = "\""; mid_sep = g_strconcat ("\"", info->separator_str, "\"", NULL); } else { end_sep = ""; mid_sep = g_strconcat (info->separator_str, NULL); } /* Header string, 'eol = end of line marker' */ header = g_strconcat (end_sep, _("type"), mid_sep, _("full_name"), mid_sep, _("name"), mid_sep, _("code"), mid_sep, _("description"), mid_sep, _("color"), mid_sep, _("notes"), mid_sep, _("commoditym"), mid_sep, _("commodityn"), mid_sep, _("hidden"), mid_sep, _("tax"), mid_sep, _("place_holder"), end_sep, EOLSTR, NULL); DEBUG("Header String: %s", header); /* Write header line */ if (!write_line_to_file (fh, header)) { info->failed = TRUE; g_free (mid_sep); g_free (header); return; } g_free (header); /* Go through list of accounts */ for (ptr = accts, i = 0; ptr; ptr = g_list_next (ptr), i++) { gchar *fullname = NULL; gchar *str_temp = NULL; acc = ptr->data; DEBUG("Account being processed is : %s", xaccAccountGetName (acc)); /* Type */ currentSel = xaccAccountTypeEnumAsString (xaccAccountGetType (acc)); part1 = g_strconcat (end_sep, currentSel, mid_sep, NULL); /* Full Name */ fullname = gnc_account_get_full_name (acc); str_temp = csv_test_field_string (info, fullname); part2 = g_strconcat (part1, str_temp, mid_sep, NULL); g_free (str_temp); g_free (fullname); g_free (part1); /* Name */ currentSel = xaccAccountGetName (acc); str_temp = csv_test_field_string (info, currentSel); part1 = g_strconcat (part2, str_temp, mid_sep, NULL); g_free (str_temp); g_free (part2); /* Code */ currentSel = xaccAccountGetCode (acc) ? xaccAccountGetCode (acc) : ""; str_temp = csv_test_field_string (info, currentSel); part2 = g_strconcat (part1, str_temp, mid_sep, NULL); g_free (str_temp); g_free (part1); /* Description */ currentSel = xaccAccountGetDescription (acc) ? xaccAccountGetDescription (acc) : ""; str_temp = csv_test_field_string (info, currentSel); part1 = g_strconcat (part2, str_temp, mid_sep, NULL); g_free (str_temp); g_free (part2); /* Color */ currentSel = xaccAccountGetColor (acc) ? xaccAccountGetColor (acc) : "" ; str_temp = csv_test_field_string (info, currentSel); part2 = g_strconcat (part1, str_temp, mid_sep, NULL); g_free (str_temp); g_free (part1); /* Notes */ currentSel = xaccAccountGetNotes (acc) ? xaccAccountGetNotes (acc) : "" ; str_temp = csv_test_field_string (info, currentSel); part1 = g_strconcat (part2, str_temp, mid_sep, NULL); g_free (str_temp); g_free (part2); /* Commodity Mnemonic */ currentSel = gnc_commodity_get_mnemonic (xaccAccountGetCommodity (acc)); str_temp = csv_test_field_string (info, currentSel); part2 = g_strconcat (part1, str_temp, mid_sep, NULL); g_free (str_temp); g_free (part1); /* Commodity Namespace */ currentSel = gnc_commodity_get_namespace (xaccAccountGetCommodity (acc)); str_temp = csv_test_field_string (info, currentSel); part1 = g_strconcat (part2, str_temp, mid_sep, NULL); g_free (str_temp); g_free (part2); /* Hidden */ currentSel = xaccAccountGetHidden (acc) ? "T" : "F" ; part2 = g_strconcat (part1, currentSel, mid_sep, NULL); g_free (part1); /* Tax */ currentSel = xaccAccountGetTaxRelated (acc) ? "T" : "F" ; part1 = g_strconcat (part2, currentSel, mid_sep, NULL); g_free (part2); /* Place Holder / end of line marker */ currentSel = xaccAccountGetPlaceholder (acc) ? "T" : "F" ; part2 = g_strconcat (part1, currentSel, end_sep, EOLSTR, NULL); g_free (part1); DEBUG("Account String: %s", part2); /* Write to file */ if (!write_line_to_file (fh, part2)) { info->failed = TRUE; break; } g_free (part2); } g_free (mid_sep); } else info->failed = TRUE; if (fh) fclose (fh); g_list_free (accts); LEAVE(""); }