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 void gsr2_redraw_all_cb (GncTreeViewSplitReg *view, gpointer user_data) { GNCSplitReg2 *gsr = user_data; gnc_commodity * commodity; GNCPrintAmountInfo print_info; gnc_numeric amount = gnc_numeric_zero(); Account *leader; gboolean reverse; gboolean euro; if ( gsr->summarybar == NULL ) return; leader = gnc_ledger_display2_leader( gsr->ledger ); commodity = xaccAccountGetCommodity( leader ); /* no EURO converson, if account is already EURO or no EURO currency */ if (commodity != NULL) euro = (gnc_is_euro_currency( commodity ) && (strncasecmp(gnc_commodity_get_mnemonic(commodity), "EUR", 3))); else euro = FALSE; print_info = gnc_account_print_info( leader, TRUE ); reverse = gnc_reverse_balance( leader ); gsr2_update_summary_label( gsr->balance_label, xaccAccountGetPresentBalance, leader, print_info, commodity, reverse, euro ); gsr2_update_summary_label( gsr->cleared_label, xaccAccountGetClearedBalance, leader, print_info, commodity, reverse, euro ); gsr2_update_summary_label( gsr->reconciled_label, xaccAccountGetReconciledBalance, leader, print_info, commodity, reverse, euro ); gsr2_update_summary_label( gsr->future_label, xaccAccountGetBalance, leader, print_info, commodity, reverse, euro ); gsr2_update_summary_label( gsr->projectedminimum_label, xaccAccountGetProjectedMinimumBalance, leader, print_info, commodity, reverse, euro ); /* Print the summary share amount */ if (gsr->shares_label != NULL) { char string[256]; print_info = gnc_account_print_info( leader, TRUE ); amount = xaccAccountGetBalance( leader ); if ( reverse ) amount = gnc_numeric_neg( amount ); xaccSPrintAmount( string, amount, print_info ); gnc_set_label_color( gsr->shares_label, amount ); gtk_label_set_text( GTK_LABEL(gsr->shares_label), string ); } /* Print the summary share value */ if (gsr->value_label != NULL) { char string[256]; gnc_commodity *currency = gnc_default_currency (); print_info = gnc_commodity_print_info (currency, TRUE); xaccSPrintAmount (string, amount, print_info); gnc_set_label_color (gsr->value_label, amount); gtk_label_set_text (GTK_LABEL (gsr->value_label), string); } }