[Gnucash-changes] r13531 - gnucash/trunk - Remove all usage of
gnc_get_current_session / book / whatever except
David Hampton
hampton at cvs.gnucash.org
Tue Mar 7 21:26:53 EST 2006
Author: hampton
Date: 2006-03-07 21:26:53 -0500 (Tue, 07 Mar 2006)
New Revision: 13531
Trac: http://svn.gnucash.org/trac/changeset/13531
Modified:
gnucash/trunk/ChangeLog
gnucash/trunk/src/gnc-ui.h
gnucash/trunk/src/gnome/dialog-commodities.c
gnucash/trunk/src/gnome/dialog-price-edit-db.c
gnucash/trunk/src/gnome/dialog-price-editor.c
gnucash/trunk/src/gnome/top-level.c
Log:
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.
Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog 2006-03-08 02:26:31 UTC (rev 13530)
+++ gnucash/trunk/ChangeLog 2006-03-08 02:26:53 UTC (rev 13531)
@@ -1,5 +1,17 @@
2006-03-07 David Hampton <hampton at 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
hash key instead of looking up the commodity string and then
hashing that. Fixes 332678.
Modified: gnucash/trunk/src/gnc-ui.h
===================================================================
--- gnucash/trunk/src/gnc-ui.h 2006-03-08 02:26:31 UTC (rev 13530)
+++ gnucash/trunk/src/gnc-ui.h 2006-03-08 02:26:53 UTC (rev 13531)
@@ -107,9 +107,8 @@
GNC_PRICE_NEW,
} GNCPriceEditType;
-GNCPrice* gnc_price_edit_dialog (gncUIWidget parent, GNCPrice *price,
- GNCPriceEditType type);
-GNCPrice * gnc_price_edit_by_guid (GtkWidget * parent, const GUID * guid);
+GNCPrice* gnc_price_edit_dialog (gncUIWidget parent, QofSession *session,
+ GNCPrice *price, GNCPriceEditType type);
void gnc_prices_dialog (gncUIWidget parent);
void gnc_commodities_dialog (gncUIWidget parent);
Modified: gnucash/trunk/src/gnome/dialog-commodities.c
===================================================================
--- gnucash/trunk/src/gnome/dialog-commodities.c 2006-03-08 02:26:31 UTC (rev 13530)
+++ gnucash/trunk/src/gnome/dialog-commodities.c 2006-03-08 02:26:53 UTC (rev 13531)
@@ -37,6 +37,7 @@
#include "gnc-ui-util.h"
#include "gnc-gconf-utils.h"
#include "gnc-gnome-utils.h"
+#include "gnc-session.h"
#define DIALOG_COMMODITIES_CM_CLASS "dialog-commodities"
@@ -48,6 +49,7 @@
typedef struct
{
GtkWidget * dialog;
+ QofSession *session;
QofBook *book;
GncTreeViewCommodity * commodity_tree;
@@ -104,7 +106,7 @@
if (commodity == NULL)
return;
- accounts = xaccGroupGetSubAccounts (gnc_get_current_group ());
+ accounts = xaccGroupGetSubAccounts (xaccGetAccountGroup(cd->book));
can_delete = TRUE;
do_delete = FALSE;
@@ -165,7 +167,7 @@
{
gnc_commodity_table *ct;
- ct = gnc_get_current_commodities ();
+ ct = gnc_book_get_commodity_table (cd->book);
for (node = prices; node; node = node->next)
gnc_pricedb_remove_price(pdb, node->data);
@@ -287,7 +289,8 @@
dialog = glade_xml_get_widget (xml, "Commodities 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);
glade_xml_signal_autoconnect_full(xml, gnc_glade_autoconnect_full_func, cd);
@@ -384,6 +387,7 @@
component_id = gnc_register_gui_component (DIALOG_COMMODITIES_CM_CLASS,
refresh_handler, close_handler,
cd);
+ gnc_gui_component_set_session (component_id, cd->session);
gtk_widget_grab_focus (GTK_WIDGET(cd->commodity_tree));
Modified: gnucash/trunk/src/gnome/dialog-price-edit-db.c
===================================================================
--- gnucash/trunk/src/gnome/dialog-price-edit-db.c 2006-03-08 02:26:31 UTC (rev 13530)
+++ gnucash/trunk/src/gnome/dialog-price-edit-db.c 2006-03-08 02:26:53 UTC (rev 13531)
@@ -39,6 +39,7 @@
#include "gnc-engine.h"
#include "gnc-gui-query.h"
#include "gnc-pricedb.h"
+#include "gnc-session.h"
#include "gnc-tree-view-price.h"
#include "gnc-ui.h"
#include "gnc-ui-util.h"
@@ -66,13 +67,14 @@
typedef struct
{
GtkWidget * dialog;
+ QofSession *session;
+ QofBook *book;
+ GNCPriceDB *price_db;
GncTreeViewPrice * price_tree;
GtkWidget * edit_button;
GtkWidget * remove_button;
-
- GNCPriceDB *price_db;
} PricesDialog;
@@ -131,7 +133,8 @@
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);
LEAVE(" ");
}
@@ -188,10 +191,7 @@
}
if (response == GTK_RESPONSE_YES) {
- GNCBook *book = gnc_get_current_book ();
- GNCPriceDB *pdb = gnc_book_get_pricedb (book);
-
- g_list_foreach(price_list, (GFunc)remove_helper, pdb);
+ g_list_foreach(price_list, (GFunc)remove_helper, pdb_dialog->price_db);
}
g_list_free(price_list);
LEAVE(" ");
@@ -218,8 +218,6 @@
result = gtk_dialog_run (GTK_DIALOG (dialog));
if (result == GTK_RESPONSE_OK)
{
- GNCBook *book = gnc_get_current_book ();
- GNCPriceDB *pdb = gnc_book_get_pricedb (book);
Timespec ts;
DEBUG("deleting prices");
@@ -231,7 +229,8 @@
button = glade_xml_get_widget (xml, "delete_last");
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);
@@ -251,14 +250,15 @@
price = price_list->data;
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(" ");
}
void
gnc_prices_dialog_get_quotes_clicked (GtkWidget *widget, gpointer data)
{
- GNCBook *book = gnc_get_current_book ();
+ PricesDialog *pdb_dialog = data;
SCM quotes_func;
SCM book_scm;
@@ -269,7 +269,7 @@
return;
}
- book_scm = gnc_book_to_scm (book);
+ book_scm = gnc_book_to_scm (pdb_dialog->book);
if (SCM_NFALSEP (scm_not (book_scm))) {
LEAVE("no book");
return;
@@ -353,8 +353,11 @@
dialog = glade_xml_get_widget (xml, "Prices 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);
/* parent */
@@ -366,7 +369,7 @@
/* price tree */
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,
"show-column-menu", TRUE,
NULL);
@@ -464,6 +467,7 @@
component_id = gnc_register_gui_component (DIALOG_PRICE_DB_CM_CLASS,
refresh_handler, close_handler,
pdb_dialog);
+ gnc_gui_component_set_session (component_id, pdb_dialog->session);
gtk_widget_grab_focus (GTK_WIDGET(pdb_dialog->price_tree));
Modified: gnucash/trunk/src/gnome/dialog-price-editor.c
===================================================================
--- gnucash/trunk/src/gnome/dialog-price-editor.c 2006-03-08 02:26:31 UTC (rev 13530)
+++ gnucash/trunk/src/gnome/dialog-price-editor.c 2006-03-08 02:26:53 UTC (rev 13531)
@@ -52,6 +52,9 @@
typedef struct
{
GtkWidget * dialog;
+ QofSession *session;
+ QofBook *book;
+ GNCPriceDB *price_db;
GtkWidget * commodity_edit;
GtkWidget * currency_edit;
@@ -221,8 +224,6 @@
pedit_dialog_response_cb (GtkDialog *dialog, gint response, gpointer data)
{
PriceEditDialog *pedit_dialog = data;
- GNCBook *book = gnc_get_current_book ();
- GNCPriceDB *pdb = gnc_book_get_pricedb (book);
const char *error_str;
if (response == GTK_RESPONSE_OK) {
@@ -234,7 +235,7 @@
pedit_dialog->changed = FALSE;
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 ();
}
@@ -247,8 +248,6 @@
static void
commodity_changed_cb (GNCGeneralSelect *gsl, gpointer data)
{
- GNCBook *book;
- GNCPriceDB *pdb;
gnc_commodity *commodity = NULL;
gnc_commodity *currency = NULL;
GList *price_list;
@@ -261,10 +260,8 @@
if(commodity)
{
- book = gnc_price_get_book (pedit_dialog->price);
- pdb = gnc_book_get_pricedb (book);
-
- price_list = gnc_pricedb_lookup_latest_any_currency (pdb, commodity);
+ price_list = gnc_pricedb_lookup_latest_any_currency
+ (pedit_dialog->price_db, commodity);
if(price_list)
{
currency = gnc_price_get_currency((GNCPrice *)price_list->data);
@@ -292,7 +289,9 @@
}
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;
GNCPrintAmountInfo print_info;
@@ -304,6 +303,10 @@
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");
pedit_dialog->dialog = dialog;
@@ -434,7 +437,10 @@
* Return: nothing *
\********************************************************************/
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;
gint component_id;
@@ -445,15 +451,15 @@
return(price);
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));
switch (type) {
case GNC_PRICE_NEW:
if (price) {
- price = gnc_price_clone(price, gnc_get_current_book ());
+ price = gnc_price_clone(price, pedit_dialog->book);
} else {
- price = gnc_price_create (gnc_get_current_book ());
+ price = gnc_price_create (pedit_dialog->book);
}
gnc_price_new_price_init(price);
pedit_dialog->new = TRUE;
@@ -471,28 +477,10 @@
component_id = gnc_register_gui_component (DIALOG_PRICE_EDIT_CM_CLASS,
refresh_handler, close_handler,
pedit_dialog);
+ gnc_gui_component_set_session (component_id, pedit_dialog->session);
gtk_widget_grab_focus (pedit_dialog->commodity_edit);
gtk_widget_show (pedit_dialog->dialog);
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));
-}
Modified: gnucash/trunk/src/gnome/top-level.c
===================================================================
--- gnucash/trunk/src/gnome/top-level.c 2006-03-08 02:26:31 UTC (rev 13530)
+++ gnucash/trunk/src/gnome/top-level.c 2006-03-08 02:26:53 UTC (rev 13531)
@@ -167,35 +167,6 @@
/* ============================================================== */
-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
* "new" state file associated with a specific book guid. It then
* iterates through this state information, calling a helper function
@@ -389,9 +360,6 @@
gnc_html_register_url_handler (URL_TYPE_REGISTER,
gnc_html_register_url_cb);
- gnc_html_register_url_handler (URL_TYPE_PRICE,
- gnc_html_price_url_cb);
-
gnc_ui_sx_initialize();
/* FIXME Remove this test code */
More information about the gnucash-changes
mailing list