void xaccAccountScrubColorNotSet (QofBook *book) { GValue value_s = G_VALUE_INIT; // get the run-once value qof_instance_get_kvp (QOF_INSTANCE (book), &value_s, 1, "remove-color-not-set-slots"); if (G_VALUE_HOLDS_STRING (&value_s) && (strcmp(g_value_get_string (&value_s), "true") == 0)) return; else { GValue value_b = G_VALUE_INIT; Account *root = gnc_book_get_root_account (book); GList *accts = gnc_account_get_descendants_sorted (root); GList *ptr; for (ptr = accts; ptr; ptr = g_list_next (ptr)) { const gchar *color = xaccAccountGetColor (ptr->data); if (g_strcmp0 (color, "Not Set") == 0) xaccAccountSetColor (ptr->data, ""); } g_list_free (accts); g_value_init (&value_b, G_TYPE_BOOLEAN); g_value_set_boolean (&value_b, TRUE); // set the run-once value qof_instance_set_kvp (QOF_INSTANCE (book), &value_b, 1, "remove-color-not-set-slots"); } }
/******************************************************* * 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(""); }