static void refresh_details_page (StockSplitInfo *info) { GNCPrintAmountInfo print_info; gnc_commodity *commodity, *currency; Account *account; QofBook *book; GNCPriceDB *db; GList *prices; account = info->acct; g_return_if_fail (account != NULL); print_info = gnc_account_print_info (account, FALSE); gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (info->distribution_edit), print_info); gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT (info->distribution_edit), xaccAccountGetCommoditySCU (account)); commodity = xaccAccountGetCommodity (account); book = gnc_account_get_book (account); db = gnc_pricedb_get_db(book); prices = gnc_pricedb_lookup_latest_any_currency(db, commodity); if (prices) { /* Use the first existing price */ if (gnc_commodity_equiv (commodity, gnc_price_get_currency(prices->data))) currency = gnc_price_get_commodity(prices->data); else currency = gnc_price_get_currency(prices->data); } else { /* Take a wild guess. */ currency = gnc_default_currency (); } gnc_price_list_destroy(prices); gnc_currency_edit_set_currency (GNC_CURRENCY_EDIT (info->price_currency_edit), currency); }
static void remove_clicked (CommoditiesDialog *cd) { GNCPriceDB *pdb; GList *prices; gboolean can_delete; gnc_commodity *commodity; GtkWidget *dialog; const gchar *message, *warning; gint response; commodity = gnc_tree_view_commodity_get_selected_commodity (cd->commodity_tree); if (commodity == NULL) return; AccountList_t accounts = gnc_account_get_descendants (gnc_book_get_root_account(cd->book)); can_delete = TRUE; for (AccountList_t::const_iterator node = accounts.begin(); node != accounts.end(); node++) { Account *account = *node; if (commodity == xaccAccountGetCommodity (account)) { can_delete = FALSE; break; } } /* FIXME check for transaction references */ if (!can_delete) { const char *message = _("That commodity is currently used by " "at least one of your accounts. You may " "not delete it."); gnc_warning_dialog (cd->dialog, "%s", message); return; } pdb = gnc_pricedb_get_db (cd->book); prices = gnc_pricedb_get_prices(pdb, commodity, NULL); if (prices) { message = _("This commodity has price quotes. Are " "you sure you want to delete the selected " "commodity and its price quotes?"); warning = "delete_commodity2"; } else { message = _("Are you sure you want to delete the " "selected commodity?"); warning = "delete_commodity"; } dialog = gtk_message_dialog_new(GTK_WINDOW(cd->dialog), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, "%s", _("Delete commodity?")); gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), "%s", message); gtk_dialog_add_buttons(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_DELETE, GTK_RESPONSE_OK, (gchar *)NULL); response = gnc_dialog_run(GTK_DIALOG(dialog), warning); gtk_widget_destroy(dialog); if (response == GTK_RESPONSE_OK) { gnc_commodity_table *ct; ct = gnc_commodity_table_get_table (cd->book); for (GList *node = prices; node; node = node->next) gnc_pricedb_remove_price(pdb, node->data); gnc_commodity_table_remove (ct, commodity); gnc_commodity_destroy (commodity); commodity = NULL; } gnc_price_list_destroy(prices); gnc_gui_refresh_all (); }