static void placeholder_cell_data_func (GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data) { Account *account, *root; gboolean willbe_placeholder = FALSE; GncAccountMergeDisposition disp; g_return_if_fail (GTK_TREE_MODEL (model)); account = gnc_tree_view_account_get_account_from_iter (model, iter); root = gnc_book_get_root_account(gnc_get_current_book()); disp = determine_merge_disposition(root, account); switch (disp) { case GNC_ACCOUNT_MERGE_DISPOSITION_USE_EXISTING: { /* find the existing account, do whatever it is. */ gchar *full_name; Account *existing_acct; full_name = gnc_account_get_full_name(account); existing_acct = gnc_account_lookup_by_full_name(root, full_name); willbe_placeholder = xaccAccountGetPlaceholder(existing_acct); g_free(full_name); } break; case GNC_ACCOUNT_MERGE_DISPOSITION_CREATE_NEW: willbe_placeholder = xaccAccountGetPlaceholder(account); break; } gtk_cell_renderer_toggle_set_active(GTK_CELL_RENDERER_TOGGLE(cell), willbe_placeholder); }
static gboolean skip_cb (Account *account, gpointer x) { /* commented out as per Bug#340885 Comments 1 and 2, option (2). if (xaccAccountIsHidden(account)) return TRUE; */ return xaccAccountGetPlaceholder (account); }
static void balance_cell_data_func (GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data) { Account *account; gnc_numeric balance; const gchar *string; GNCPrintAmountInfo print_info; hierarchy_data *data = (hierarchy_data *)user_data; gboolean allow_value; g_return_if_fail (GTK_TREE_MODEL (model)); account = gnc_tree_view_account_get_account_from_iter (model, iter); balance = get_final_balance (data->balance_hash, account); if (gnc_numeric_zero_p (balance)) { string = ""; } else { print_info = gnc_account_print_info (account, FALSE); string = xaccPrintAmount (balance, print_info); } if (xaccAccountGetType(account) == ACCT_TYPE_EQUITY || xaccAccountGetType(account) == ACCT_TYPE_TRADING) { allow_value = FALSE; string = _("zero"); } else { GncAccountMergeDisposition disp; disp = determine_merge_disposition(gnc_book_get_root_account(gnc_get_current_book()), account); if (disp == GNC_ACCOUNT_MERGE_DISPOSITION_CREATE_NEW) { allow_value = !xaccAccountGetPlaceholder(account); } else { allow_value = FALSE; string = _("existing account"); } } g_object_set (G_OBJECT (cell), "text", string, "editable", allow_value, "sensitive", allow_value, NULL); }
void gnc_dialog_date_close_ok_cb (GtkWidget *widget, gpointer user_data) { DialogDateClose *ddc = user_data; if (ddc->acct_combo) { Account *acc; acc = gnc_account_sel_get_account( GNC_ACCOUNT_SEL(ddc->acct_combo) ); if (!acc) { gnc_error_dialog (GTK_WINDOW (ddc->dialog), "%s", _("No Account selected. Please try again.")); return; } if (xaccAccountGetPlaceholder (acc)) { gnc_error_dialog (GTK_WINDOW (ddc->dialog), "%s", _("Placeholder account selected. Please try again.")); return; } ddc->acct = acc; } if (ddc->post_date) *(ddc->ts2) = gnc_date_edit_get_date_ts (GNC_DATE_EDIT (ddc->post_date)); if (ddc->date) { if (ddc->terms) ddc->ts->tv_sec = gncBillTermComputeDueDate (ddc->terms, ddc->ts2->tv_sec); else *(ddc->ts) = gnc_date_edit_get_date_ts (GNC_DATE_EDIT (ddc->date)); } if (ddc->memo_entry && ddc->memo) *(ddc->memo) = gtk_editable_get_chars (GTK_EDITABLE (ddc->memo_entry), 0, -1); if (ddc->question_check) ddc->answer = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ddc->question_check)); ddc->retval = TRUE; }
static gboolean skip_income_acct_cb (Account *account, gpointer user_data) { GNCAccountType type; /* Don't add A/R, A/P, Bank, Cash, or Equity accounts */ type = xaccAccountGetType (account); if (type == ACCT_TYPE_PAYABLE || type == ACCT_TYPE_RECEIVABLE || type == ACCT_TYPE_CASH || type == ACCT_TYPE_BANK || type == ACCT_TYPE_EQUITY || type == ACCT_TYPE_TRADING) { return TRUE; } /* If this is a BILL, then leave out the incomes */ if (type == ACCT_TYPE_INCOME) return TRUE; /* Don't add placeholder accounts */ if (xaccAccountGetPlaceholder (account)) return TRUE; return FALSE; }
/** * Opens up a register window for a group of Accounts. * @param gsr the register window instance * @return A GNCPlaceholderType indicating presence and type of placeholder * accounts **/ static GNCPlaceholderType gnc_split_reg2_get_placeholder (GNCSplitReg2 *gsr) { Account *leader; GncTreeModelSplitReg *model; gboolean single_account; if (gsr == NULL) return PLACEHOLDER_NONE; model = gnc_ledger_display2_get_split_model_register (gsr->ledger); switch (model->type) { case GENERAL_JOURNAL2: case INCOME_LEDGER2: case PORTFOLIO_LEDGER2: case SEARCH_LEDGER2: single_account = FALSE; break; default: single_account = TRUE; break; } leader = gnc_ledger_display2_leader (gsr->ledger); if (leader == NULL) return PLACEHOLDER_NONE; if (single_account) { if (xaccAccountGetPlaceholder (leader)) return PLACEHOLDER_THIS; return PLACEHOLDER_NONE; } return xaccAccountGetDescendantPlaceholder (leader); }
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 int fill_account_list (StockSplitInfo *info, Account *selected_account) { GtkTreeRowReference *reference = NULL; GtkTreeView *view; GtkListStore *list; GtkTreeIter iter; GtkTreePath *path; GList *accounts; GList *node; gint rows = 0; gchar *full_name; view = GTK_TREE_VIEW(info->account_view); list = GTK_LIST_STORE(gtk_tree_view_get_model(view)); gtk_list_store_clear (list); accounts = gnc_account_get_descendants_sorted (gnc_get_current_root_account ()); for (node = accounts; node; node = node->next) { Account *account = node->data; GNCPrintAmountInfo print_info; const gnc_commodity *commodity; gnc_numeric balance; if (!xaccAccountIsPriced(account)) continue; balance = xaccAccountGetBalance (account); if (gnc_numeric_zero_p (balance)) continue; if (xaccAccountGetPlaceholder (account)) continue; commodity = xaccAccountGetCommodity (account); full_name = gnc_account_get_full_name (account); print_info = gnc_account_print_info (account, FALSE); gtk_list_store_append(list, &iter); gtk_list_store_set(list, &iter, SPLIT_COL_ACCOUNT, account, SPLIT_COL_FULLNAME, full_name, SPLIT_COL_MNEMONIC, gnc_commodity_get_mnemonic(commodity), SPLIT_COL_SHARES, xaccPrintAmount(balance, print_info), -1); if (account == selected_account) { path = gtk_tree_model_get_path(GTK_TREE_MODEL(list), &iter); reference = gtk_tree_row_reference_new(GTK_TREE_MODEL(list), path); gtk_tree_path_free(path); } g_free (full_name); rows++; } g_list_free(accounts); if (reference) { GtkTreeSelection* selection = gtk_tree_view_get_selection(view); path = gtk_tree_row_reference_get_path(reference); gtk_tree_row_reference_free(reference); if (path) { gtk_tree_selection_select_path(selection, path); gtk_tree_view_scroll_to_cell(view, path, NULL, TRUE, 0.5, 0.0); gtk_tree_path_free(path); } } return rows; }
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(""); }