diff --git a/ChangeLog b/ChangeLog index 7e8aee1552..60c4a11dcf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2003-07-04 David Hampton + + * src/gnome/dialog-price-edit-db.c: Add a couple of extra checks + to prevent crashing if the commodity attached to a price quote has + disappeared. #111643 + + * src/gnome/dialog-commodities.c: Provide a new warning message + before deletion if a commodity has any quice quotes. If the user + deletes the commodity anyway, removed any quotes are based on the + commodity + + * src/engine/gnc-pricedb.c: Enhance the get prices routine to + handle a request with a NULL currency. + 2003-07-03 David Hampton * src/scm/price-quotes.scm: diff --git a/src/engine/gnc-pricedb.c b/src/engine/gnc-pricedb.c index 35c761a889..d9a8ea7289 100644 --- a/src/engine/gnc-pricedb.c +++ b/src/engine/gnc-pricedb.c @@ -870,8 +870,11 @@ add_price(GNCPriceDB *db, GNCPrice *p) g_hash_table_insert(currency_hash, currency, price_list); p->db = db; - LEAVE ("db=%p, pr=%p not-saved=%d do-free=%d", - db, p, p->not_saved, p->do_free); + LEAVE ("db=%p, pr=%p not-saved=%d do-free=%d commodity=%s/%s currency_hash=%p", + db, p, p->not_saved, p->do_free, + gnc_commodity_get_namespace(p->commodity), + gnc_commodity_get_mnemonic(p->commodity), + currency_hash); return TRUE; } @@ -1069,6 +1072,13 @@ gnc_pricedb_lookup_latest_any_currency(GNCPriceDB *db, } +static void +hash_values_helper(gpointer key, gpointer value, gpointer data) +{ + GList ** l = data; + *l = g_list_concat(*l, g_list_copy (value)); +} + GList * gnc_pricedb_get_prices(GNCPriceDB *db, gnc_commodity *commodity, @@ -1080,7 +1090,7 @@ gnc_pricedb_get_prices(GNCPriceDB *db, GHashTable *currency_hash; ENTER ("db=%p commodity=%p currency=%p", db, commodity, currency); - if(!db || !commodity || !currency) return NULL; + if(!db || !commodity) return NULL; if (db->book && db->book->backend && db->book->backend->price_lookup) { @@ -1095,10 +1105,14 @@ gnc_pricedb_get_prices(GNCPriceDB *db, currency_hash = g_hash_table_lookup(db->commodity_hash, commodity); if(!currency_hash) return NULL; - price_list = g_hash_table_lookup(currency_hash, currency); - if(!price_list) return NULL; - - result = g_list_copy (price_list); + if (currency) { + price_list = g_hash_table_lookup(currency_hash, currency); + if(!price_list) return NULL; + result = g_list_copy (price_list); + } else { + result = NULL; + g_hash_table_foreach(currency_hash, hash_values_helper, (gpointer)&result); + } for (node = result; node; node = node->next) gnc_price_ref (node->data); diff --git a/src/gnome/dialog-commodities.c b/src/gnome/dialog-commodities.c index ac8d733935..8aab3f593e 100644 --- a/src/gnome/dialog-commodities.c +++ b/src/gnome/dialog-commodities.c @@ -226,7 +226,10 @@ edit_clicked (GtkWidget *widget, gpointer data) static void remove_clicked (GtkWidget *widget, gpointer data) { + QofBook *book; + GNCPriceDB *pdb; GList *node; + GList *prices; GList *accounts; gboolean do_delete; gboolean can_delete; @@ -259,6 +262,20 @@ remove_clicked (GtkWidget *widget, gpointer data) "not delete it."); gnc_warning_dialog_parented (cd->dialog, message); + g_list_free (accounts); + return; + } + + book = xaccGroupGetBook (xaccAccountGetRoot (accounts->data)); + pdb = gnc_pricedb_get_db (book); + prices = gnc_pricedb_get_prices(pdb, cd->commodity, NULL); + if (prices) + { + const char *message = _("This commodity has price quotes. Are\n" + "you sure you want to delete the selected\n" + "commodity and its price quotes?"); + + do_delete = gnc_verify_dialog_parented (cd->dialog, TRUE, message); } else { @@ -272,6 +289,9 @@ remove_clicked (GtkWidget *widget, gpointer data) { gnc_commodity_table *ct = gnc_get_current_commodities (); + for (node = prices; node; node = node->next) + gnc_pricedb_remove_price(pdb, node->data); + gnc_commodity_table_remove (ct, cd->commodity); gnc_commodity_destroy (cd->commodity); cd->commodity = NULL; @@ -279,7 +299,9 @@ remove_clicked (GtkWidget *widget, gpointer data) gnc_commodities_load_commodities (cd); } + gnc_price_list_destroy(prices); g_list_free (accounts); + gnc_gui_refresh_all (); } static void diff --git a/src/gnome/dialog-price-edit-db.c b/src/gnome/dialog-price-edit-db.c index 00532a09c9..ee18e1d5ff 100644 --- a/src/gnome/dialog-price-edit-db.c +++ b/src/gnome/dialog-price-edit-db.c @@ -105,20 +105,24 @@ price_compare (gconstpointer a, gconstpointer b) comm_a = gnc_price_get_commodity (price_a); comm_b = gnc_price_get_commodity (price_b); - SAFE_STRCMP (gnc_commodity_get_namespace (comm_a), - gnc_commodity_get_namespace (comm_b)); + if (comm_a && comm_b){ + SAFE_STRCMP (gnc_commodity_get_namespace (comm_a), + gnc_commodity_get_namespace (comm_b)); - SAFE_STRCMP (gnc_commodity_get_mnemonic (comm_a), - gnc_commodity_get_mnemonic (comm_b)); + SAFE_STRCMP (gnc_commodity_get_mnemonic (comm_a), + gnc_commodity_get_mnemonic (comm_b)); + } comm_a = gnc_price_get_currency (price_a); comm_b = gnc_price_get_currency (price_b); - SAFE_STRCMP (gnc_commodity_get_namespace (comm_a), - gnc_commodity_get_namespace (comm_b)); + if (comm_a && comm_b){ + SAFE_STRCMP (gnc_commodity_get_namespace (comm_a), + gnc_commodity_get_namespace (comm_b)); - SAFE_STRCMP (gnc_commodity_get_mnemonic (comm_a), - gnc_commodity_get_mnemonic (comm_b)); + SAFE_STRCMP (gnc_commodity_get_mnemonic (comm_a), + gnc_commodity_get_mnemonic (comm_b)); + } ts_a = gnc_price_get_time (price_a); ts_b = gnc_price_get_time (price_b);