Remove all usage of gnc_get_current_session / book / whatever except

at the very top level when the dialog is originally created. Tell the
component manager to delete the dialog when the session is
destroyed. Remove support for an old
url-that-generates-a-price-edit-window trick.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13531 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
David Hampton 2006-03-08 02:26:53 +00:00
parent 408f7d2779
commit d6d1815a70
6 changed files with 61 additions and 86 deletions

View File

@ -1,5 +1,17 @@
2006-03-07 David Hampton <hampton@employees.org> 2006-03-07 David Hampton <hampton@employees.org>
* src/gnome-utils/gnc-file.c:
* src/gnome/dialog-price-editor.c:
* src/gnome/top-level.c:
* src/gnome/dialog-commodities.c:
* src/gnome/dialog-price-edit-db.c:
* src/gnc-ui.h: Remove all usage of gnc_get_current_session / book
/ whatever except at the very top level when the dialog is
originally created. Tell the component manager to delete the
dialog when the session is destroyed. Remove support for an old
url-that-generates-a-price-edit-window trick.
* src/engine/gnc-pricedb.c: Use the pointer to the commodity as a * src/engine/gnc-pricedb.c: Use the pointer to the commodity as a
hash key instead of looking up the commodity string and then hash key instead of looking up the commodity string and then
hashing that. Fixes 332678. hashing that. Fixes 332678.

View File

@ -107,9 +107,8 @@ typedef enum
GNC_PRICE_NEW, GNC_PRICE_NEW,
} GNCPriceEditType; } GNCPriceEditType;
GNCPrice* gnc_price_edit_dialog (gncUIWidget parent, GNCPrice *price, GNCPrice* gnc_price_edit_dialog (gncUIWidget parent, QofSession *session,
GNCPriceEditType type); GNCPrice *price, GNCPriceEditType type);
GNCPrice * gnc_price_edit_by_guid (GtkWidget * parent, const GUID * guid);
void gnc_prices_dialog (gncUIWidget parent); void gnc_prices_dialog (gncUIWidget parent);
void gnc_commodities_dialog (gncUIWidget parent); void gnc_commodities_dialog (gncUIWidget parent);

View File

@ -37,6 +37,7 @@
#include "gnc-ui-util.h" #include "gnc-ui-util.h"
#include "gnc-gconf-utils.h" #include "gnc-gconf-utils.h"
#include "gnc-gnome-utils.h" #include "gnc-gnome-utils.h"
#include "gnc-session.h"
#define DIALOG_COMMODITIES_CM_CLASS "dialog-commodities" #define DIALOG_COMMODITIES_CM_CLASS "dialog-commodities"
@ -48,6 +49,7 @@
typedef struct typedef struct
{ {
GtkWidget * dialog; GtkWidget * dialog;
QofSession *session;
QofBook *book; QofBook *book;
GncTreeViewCommodity * commodity_tree; GncTreeViewCommodity * commodity_tree;
@ -104,7 +106,7 @@ remove_clicked (CommoditiesDialog *cd)
if (commodity == NULL) if (commodity == NULL)
return; return;
accounts = xaccGroupGetSubAccounts (gnc_get_current_group ()); accounts = xaccGroupGetSubAccounts (xaccGetAccountGroup(cd->book));
can_delete = TRUE; can_delete = TRUE;
do_delete = FALSE; do_delete = FALSE;
@ -165,7 +167,7 @@ remove_clicked (CommoditiesDialog *cd)
{ {
gnc_commodity_table *ct; gnc_commodity_table *ct;
ct = gnc_get_current_commodities (); ct = gnc_book_get_commodity_table (cd->book);
for (node = prices; node; node = node->next) for (node = prices; node; node = node->next)
gnc_pricedb_remove_price(pdb, node->data); gnc_pricedb_remove_price(pdb, node->data);
@ -287,7 +289,8 @@ gnc_commodities_dialog_create (GtkWidget * parent, CommoditiesDialog *cd)
dialog = glade_xml_get_widget (xml, "Commodities Dialog"); dialog = glade_xml_get_widget (xml, "Commodities Dialog");
cd->dialog = dialog; cd->dialog = dialog;
cd->book = gnc_get_current_book(); cd->session = gnc_get_current_session();
cd->book = qof_session_get_book(cd->session);
cd->show_currencies = gnc_gconf_get_bool(GCONF_SECTION, "include_iso", NULL); cd->show_currencies = gnc_gconf_get_bool(GCONF_SECTION, "include_iso", NULL);
glade_xml_signal_autoconnect_full(xml, gnc_glade_autoconnect_full_func, cd); glade_xml_signal_autoconnect_full(xml, gnc_glade_autoconnect_full_func, cd);
@ -384,6 +387,7 @@ gnc_commodities_dialog (GtkWidget * parent)
component_id = gnc_register_gui_component (DIALOG_COMMODITIES_CM_CLASS, component_id = gnc_register_gui_component (DIALOG_COMMODITIES_CM_CLASS,
refresh_handler, close_handler, refresh_handler, close_handler,
cd); cd);
gnc_gui_component_set_session (component_id, cd->session);
gtk_widget_grab_focus (GTK_WIDGET(cd->commodity_tree)); gtk_widget_grab_focus (GTK_WIDGET(cd->commodity_tree));

View File

@ -39,6 +39,7 @@
#include "gnc-engine.h" #include "gnc-engine.h"
#include "gnc-gui-query.h" #include "gnc-gui-query.h"
#include "gnc-pricedb.h" #include "gnc-pricedb.h"
#include "gnc-session.h"
#include "gnc-tree-view-price.h" #include "gnc-tree-view-price.h"
#include "gnc-ui.h" #include "gnc-ui.h"
#include "gnc-ui-util.h" #include "gnc-ui-util.h"
@ -66,13 +67,14 @@ void gnc_prices_dialog_get_quotes_clicked (GtkWidget *widget, gpointer data);
typedef struct typedef struct
{ {
GtkWidget * dialog; GtkWidget * dialog;
QofSession *session;
QofBook *book;
GNCPriceDB *price_db;
GncTreeViewPrice * price_tree; GncTreeViewPrice * price_tree;
GtkWidget * edit_button; GtkWidget * edit_button;
GtkWidget * remove_button; GtkWidget * remove_button;
GNCPriceDB *price_db;
} PricesDialog; } PricesDialog;
@ -131,7 +133,8 @@ gnc_prices_dialog_edit_clicked (GtkWidget *widget, gpointer data)
return; return;
} }
gnc_price_edit_dialog (pdb_dialog->dialog, price_list->data, GNC_PRICE_EDIT); gnc_price_edit_dialog (pdb_dialog->dialog, pdb_dialog->session,
price_list->data, GNC_PRICE_EDIT);
g_list_free(price_list); g_list_free(price_list);
LEAVE(" "); LEAVE(" ");
} }
@ -188,10 +191,7 @@ gnc_prices_dialog_remove_clicked (GtkWidget *widget, gpointer data)
} }
if (response == GTK_RESPONSE_YES) { if (response == GTK_RESPONSE_YES) {
GNCBook *book = gnc_get_current_book (); g_list_foreach(price_list, (GFunc)remove_helper, pdb_dialog->price_db);
GNCPriceDB *pdb = gnc_book_get_pricedb (book);
g_list_foreach(price_list, (GFunc)remove_helper, pdb);
} }
g_list_free(price_list); g_list_free(price_list);
LEAVE(" "); LEAVE(" ");
@ -218,8 +218,6 @@ gnc_prices_dialog_remove_old_clicked (GtkWidget *widget, gpointer data)
result = gtk_dialog_run (GTK_DIALOG (dialog)); result = gtk_dialog_run (GTK_DIALOG (dialog));
if (result == GTK_RESPONSE_OK) if (result == GTK_RESPONSE_OK)
{ {
GNCBook *book = gnc_get_current_book ();
GNCPriceDB *pdb = gnc_book_get_pricedb (book);
Timespec ts; Timespec ts;
DEBUG("deleting prices"); DEBUG("deleting prices");
@ -231,7 +229,8 @@ gnc_prices_dialog_remove_old_clicked (GtkWidget *widget, gpointer data)
button = glade_xml_get_widget (xml, "delete_last"); button = glade_xml_get_widget (xml, "delete_last");
delete_last = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)); delete_last = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
gnc_pricedb_remove_old_prices(pdb, ts, delete_user, delete_last); gnc_pricedb_remove_old_prices(pdb_dialog->price_db, ts,
delete_user, delete_last);
} }
gtk_widget_destroy(dialog); gtk_widget_destroy(dialog);
@ -251,14 +250,15 @@ gnc_prices_dialog_add_clicked (GtkWidget *widget, gpointer data)
price = price_list->data; price = price_list->data;
g_list_free(price_list); g_list_free(price_list);
} }
gnc_price_edit_dialog (pdb_dialog->dialog, price, GNC_PRICE_NEW); gnc_price_edit_dialog (pdb_dialog->dialog, pdb_dialog->session,
price, GNC_PRICE_NEW);
LEAVE(" "); LEAVE(" ");
} }
void void
gnc_prices_dialog_get_quotes_clicked (GtkWidget *widget, gpointer data) gnc_prices_dialog_get_quotes_clicked (GtkWidget *widget, gpointer data)
{ {
GNCBook *book = gnc_get_current_book (); PricesDialog *pdb_dialog = data;
SCM quotes_func; SCM quotes_func;
SCM book_scm; SCM book_scm;
@ -269,7 +269,7 @@ gnc_prices_dialog_get_quotes_clicked (GtkWidget *widget, gpointer data)
return; return;
} }
book_scm = gnc_book_to_scm (book); book_scm = gnc_book_to_scm (pdb_dialog->book);
if (SCM_NFALSEP (scm_not (book_scm))) { if (SCM_NFALSEP (scm_not (book_scm))) {
LEAVE("no book"); LEAVE("no book");
return; return;
@ -353,7 +353,10 @@ gnc_prices_dialog_create (GtkWidget * parent, PricesDialog *pdb_dialog)
dialog = glade_xml_get_widget (xml, "Prices Dialog"); dialog = glade_xml_get_widget (xml, "Prices Dialog");
pdb_dialog->dialog = dialog; pdb_dialog->dialog = dialog;
pdb_dialog->price_db = gnc_pricedb_get_db(gnc_get_current_book());
pdb_dialog->session = gnc_get_current_session();
pdb_dialog->book = qof_session_get_book(pdb_dialog->session);
pdb_dialog->price_db = gnc_pricedb_get_db(pdb_dialog->book);
glade_xml_signal_autoconnect_full(xml, gnc_glade_autoconnect_full_func, pdb_dialog); glade_xml_signal_autoconnect_full(xml, gnc_glade_autoconnect_full_func, pdb_dialog);
@ -366,7 +369,7 @@ gnc_prices_dialog_create (GtkWidget * parent, PricesDialog *pdb_dialog)
/* price tree */ /* price tree */
scrolled_window = glade_xml_get_widget (xml, "price_list_window"); scrolled_window = glade_xml_get_widget (xml, "price_list_window");
view = gnc_tree_view_price_new(gnc_get_current_book(), view = gnc_tree_view_price_new(pdb_dialog->book,
"gconf-section", GCONF_SECTION, "gconf-section", GCONF_SECTION,
"show-column-menu", TRUE, "show-column-menu", TRUE,
NULL); NULL);
@ -464,6 +467,7 @@ gnc_prices_dialog (GtkWidget * parent)
component_id = gnc_register_gui_component (DIALOG_PRICE_DB_CM_CLASS, component_id = gnc_register_gui_component (DIALOG_PRICE_DB_CM_CLASS,
refresh_handler, close_handler, refresh_handler, close_handler,
pdb_dialog); pdb_dialog);
gnc_gui_component_set_session (component_id, pdb_dialog->session);
gtk_widget_grab_focus (GTK_WIDGET(pdb_dialog->price_tree)); gtk_widget_grab_focus (GTK_WIDGET(pdb_dialog->price_tree));

View File

@ -52,6 +52,9 @@
typedef struct typedef struct
{ {
GtkWidget * dialog; GtkWidget * dialog;
QofSession *session;
QofBook *book;
GNCPriceDB *price_db;
GtkWidget * commodity_edit; GtkWidget * commodity_edit;
GtkWidget * currency_edit; GtkWidget * currency_edit;
@ -221,8 +224,6 @@ void
pedit_dialog_response_cb (GtkDialog *dialog, gint response, gpointer data) pedit_dialog_response_cb (GtkDialog *dialog, gint response, gpointer data)
{ {
PriceEditDialog *pedit_dialog = data; PriceEditDialog *pedit_dialog = data;
GNCBook *book = gnc_get_current_book ();
GNCPriceDB *pdb = gnc_book_get_pricedb (book);
const char *error_str; const char *error_str;
if (response == GTK_RESPONSE_OK) { if (response == GTK_RESPONSE_OK) {
@ -234,7 +235,7 @@ pedit_dialog_response_cb (GtkDialog *dialog, gint response, gpointer data)
pedit_dialog->changed = FALSE; pedit_dialog->changed = FALSE;
if (TRUE == pedit_dialog->new) if (TRUE == pedit_dialog->new)
gnc_pricedb_add_price (pdb, pedit_dialog->price); gnc_pricedb_add_price (pedit_dialog->price_db, pedit_dialog->price);
gnc_gui_refresh_all (); gnc_gui_refresh_all ();
} }
@ -247,8 +248,6 @@ pedit_dialog_response_cb (GtkDialog *dialog, gint response, gpointer data)
static void static void
commodity_changed_cb (GNCGeneralSelect *gsl, gpointer data) commodity_changed_cb (GNCGeneralSelect *gsl, gpointer data)
{ {
GNCBook *book;
GNCPriceDB *pdb;
gnc_commodity *commodity = NULL; gnc_commodity *commodity = NULL;
gnc_commodity *currency = NULL; gnc_commodity *currency = NULL;
GList *price_list; GList *price_list;
@ -261,10 +260,8 @@ commodity_changed_cb (GNCGeneralSelect *gsl, gpointer data)
if(commodity) if(commodity)
{ {
book = gnc_price_get_book (pedit_dialog->price); price_list = gnc_pricedb_lookup_latest_any_currency
pdb = gnc_book_get_pricedb (book); (pedit_dialog->price_db, commodity);
price_list = gnc_pricedb_lookup_latest_any_currency (pdb, commodity);
if(price_list) if(price_list)
{ {
currency = gnc_price_get_currency((GNCPrice *)price_list->data); currency = gnc_price_get_currency((GNCPrice *)price_list->data);
@ -292,7 +289,9 @@ pedit_data_changed_cb (GtkWidget *w, gpointer data)
} }
static void static void
gnc_price_pedit_dialog_create (GtkWidget * parent, PriceEditDialog *pedit_dialog) gnc_price_pedit_dialog_create (GtkWidget *parent,
PriceEditDialog *pedit_dialog,
QofSession *session)
{ {
GladeXML *xml; GladeXML *xml;
GNCPrintAmountInfo print_info; GNCPrintAmountInfo print_info;
@ -304,6 +303,10 @@ gnc_price_pedit_dialog_create (GtkWidget * parent, PriceEditDialog *pedit_dialog
xml = gnc_glade_xml_new ("price.glade", "Price Dialog"); xml = gnc_glade_xml_new ("price.glade", "Price Dialog");
pedit_dialog->session = session;
pedit_dialog->book = qof_session_get_book(pedit_dialog->session);
pedit_dialog->price_db = gnc_pricedb_get_db(pedit_dialog->book);
dialog = glade_xml_get_widget (xml, "Price Dialog"); dialog = glade_xml_get_widget (xml, "Price Dialog");
pedit_dialog->dialog = dialog; pedit_dialog->dialog = dialog;
@ -434,7 +437,10 @@ show_handler (const char *class, gint component_id,
* Return: nothing * * Return: nothing *
\********************************************************************/ \********************************************************************/
GNCPrice * GNCPrice *
gnc_price_edit_dialog (GtkWidget * parent, GNCPrice * price, GNCPriceEditType type) gnc_price_edit_dialog (GtkWidget * parent,
QofSession *session,
GNCPrice * price,
GNCPriceEditType type)
{ {
PriceEditDialog *pedit_dialog; PriceEditDialog *pedit_dialog;
gint component_id; gint component_id;
@ -445,15 +451,15 @@ gnc_price_edit_dialog (GtkWidget * parent, GNCPrice * price, GNCPriceEditType ty
return(price); return(price);
pedit_dialog = g_new0 (PriceEditDialog, 1); pedit_dialog = g_new0 (PriceEditDialog, 1);
gnc_price_pedit_dialog_create (parent, pedit_dialog); gnc_price_pedit_dialog_create (parent, pedit_dialog, session);
gnc_restore_window_size(GCONF_SECTION, GTK_WINDOW(pedit_dialog->dialog)); gnc_restore_window_size(GCONF_SECTION, GTK_WINDOW(pedit_dialog->dialog));
switch (type) { switch (type) {
case GNC_PRICE_NEW: case GNC_PRICE_NEW:
if (price) { if (price) {
price = gnc_price_clone(price, gnc_get_current_book ()); price = gnc_price_clone(price, pedit_dialog->book);
} else { } else {
price = gnc_price_create (gnc_get_current_book ()); price = gnc_price_create (pedit_dialog->book);
} }
gnc_price_new_price_init(price); gnc_price_new_price_init(price);
pedit_dialog->new = TRUE; pedit_dialog->new = TRUE;
@ -471,28 +477,10 @@ gnc_price_edit_dialog (GtkWidget * parent, GNCPrice * price, GNCPriceEditType ty
component_id = gnc_register_gui_component (DIALOG_PRICE_EDIT_CM_CLASS, component_id = gnc_register_gui_component (DIALOG_PRICE_EDIT_CM_CLASS,
refresh_handler, close_handler, refresh_handler, close_handler,
pedit_dialog); pedit_dialog);
gnc_gui_component_set_session (component_id, pedit_dialog->session);
gtk_widget_grab_focus (pedit_dialog->commodity_edit); gtk_widget_grab_focus (pedit_dialog->commodity_edit);
gtk_widget_show (pedit_dialog->dialog); gtk_widget_show (pedit_dialog->dialog);
return(price); return(price);
} }
/********************************************************************\
* gnc_price_edit_by_guid *
* opens up a window to edit price information *
* *
* Args: parent - the parent of the window to be created *
* Return: nothing *
\********************************************************************/
GNCPrice *
gnc_price_edit_by_guid (GtkWidget * parent, const GUID * guid)
{
GNCPrice *price;
price = gnc_price_lookup (guid, gnc_get_current_book ());
if (price == NULL)
return(NULL);
return(gnc_price_edit_dialog(parent, price, GNC_PRICE_EDIT));
}

View File

@ -167,35 +167,6 @@ gnc_html_register_url_cb (const char *location, const char *label,
/* ============================================================== */ /* ============================================================== */
static gboolean
gnc_html_price_url_cb (const char *location, const char *label,
gboolean new_window, GNCURLResult *result)
{
QofBook * book = gnc_get_current_book();
g_return_val_if_fail (location != NULL, FALSE);
g_return_val_if_fail (result != NULL, FALSE);
result->load_to_stream = FALSE;
/* href="gnc-register:guid=12345678901234567890123456789012" */
IF_TYPE ("price-guid=", GNC_ID_PRICE)
if (!gnc_price_edit_by_guid (NULL, &guid))
{
result->error_message = g_strdup_printf (_("No such price: %s"),
location);
return FALSE;
}
}
else
{
result->error_message = g_strdup_printf (_("Badly formed URL %s"),
location);
return FALSE;
}
return TRUE;
}
/** Restore all persistent program state. This function finds the /** Restore all persistent program state. This function finds the
* "new" state file associated with a specific book guid. It then * "new" state file associated with a specific book guid. It then
* iterates through this state information, calling a helper function * iterates through this state information, calling a helper function
@ -389,9 +360,6 @@ gnc_main_gui_init (void)
gnc_html_register_url_handler (URL_TYPE_REGISTER, gnc_html_register_url_handler (URL_TYPE_REGISTER,
gnc_html_register_url_cb); gnc_html_register_url_cb);
gnc_html_register_url_handler (URL_TYPE_PRICE,
gnc_html_price_url_cb);
gnc_ui_sx_initialize(); gnc_ui_sx_initialize();
/* FIXME Remove this test code */ /* FIXME Remove this test code */