From ee28ca912ddd584536302f524bf241bd0f7edd5b Mon Sep 17 00:00:00 2001 From: Chris Shoemaker Date: Fri, 24 Feb 2006 05:53:35 +0000 Subject: [PATCH] Since QOF no longer keeps track of the "current" session, qof_session_destroy() no longer clears the current session when we destroy it. Therefore, explicitly call gnc_clear_current_session() when we want to destroy the current session. Also, avoid accidentally creating a new book and session if there is no open book/current session when we run the bill reminder. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13378 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/business/business-gnome/dialog-invoice.c | 1 + src/engine/gnc-session.c | 11 ++++++ src/engine/gnc-session.h | 2 +- src/gnome-utils/gnc-file.c | 40 +++++++++----------- 4 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/business/business-gnome/dialog-invoice.c b/src/business/business-gnome/dialog-invoice.c index 64ad9af324..5ed0431f53 100644 --- a/src/business/business-gnome/dialog-invoice.c +++ b/src/business/business-gnome/dialog-invoice.c @@ -2530,6 +2530,7 @@ gnc_invoice_remind_bills_due (void) GNCBook *book; gint days; + if (!gnc_current_session_exist()) return; book = qof_session_get_book(gnc_get_current_session()); days = gnc_gconf_get_float(GCONF_SECTION_BILL, "days_in_advance", NULL); diff --git a/src/engine/gnc-session.c b/src/engine/gnc-session.c index ebcdeb7308..0a99e9ec58 100644 --- a/src/engine/gnc-session.c +++ b/src/engine/gnc-session.c @@ -25,6 +25,7 @@ #include "qof.h" #include "gnc-session.h" #include "gnc-engine.h" +#include "TransLog.h" static QofSession * current_session = NULL; static QofLogModule log_module = GNC_MOD_ENGINE; @@ -54,3 +55,13 @@ gnc_set_current_session (QofSession *session) PINFO("Leak of current session."); current_session = session; } + +void gnc_clear_current_session() +{ + if (current_session) { + xaccLogDisable(); + qof_session_destroy(current_session); + xaccLogEnable(); + current_session = NULL; + } +} diff --git a/src/engine/gnc-session.h b/src/engine/gnc-session.h index 8533f580fb..37fd1d0367 100644 --- a/src/engine/gnc-session.h +++ b/src/engine/gnc-session.h @@ -4,6 +4,6 @@ #define gnc_session_get_url qof_session_get_url QofSession * gnc_get_current_session (void); +void gnc_clear_current_session(void); void gnc_set_current_session (QofSession *session); gboolean gnc_current_session_exist(void); - diff --git a/src/gnome-utils/gnc-file.c b/src/gnome-utils/gnc-file.c index b8ef167970..ef08dd5d09 100644 --- a/src/gnome-utils/gnc-file.c +++ b/src/gnome-utils/gnc-file.c @@ -501,26 +501,26 @@ gnc_file_new (void) if (!gnc_file_query_save (TRUE)) return; - session = gnc_get_current_session (); + if (gnc_current_session_exist()) { + session = gnc_get_current_session (); - /* close any ongoing file sessions, and free the accounts. - * disable events so we don't get spammed by redraws. */ - gnc_engine_suspend_events (); + /* close any ongoing file sessions, and free the accounts. + * disable events so we don't get spammed by redraws. */ + gnc_engine_suspend_events (); - qof_session_call_close_hooks(session); - gnc_hook_run(HOOK_BOOK_CLOSED, session); - - gnc_close_gui_component_by_session (session); - xaccLogDisable(); - qof_session_destroy (session); - xaccLogEnable(); + qof_session_call_close_hooks(session); + gnc_hook_run(HOOK_BOOK_CLOSED, session); + + gnc_close_gui_component_by_session (session); + gnc_clear_current_session(); + gnc_engine_resume_events (); + } /* start a new book */ gnc_get_current_session (); - + gnc_hook_run(HOOK_NEW_BOOK, NULL); - - gnc_engine_resume_events (); + gnc_gui_refresh_all (); /* Call this after re-enabling events. */ @@ -624,9 +624,7 @@ gnc_post_file_open (const char * filename) current_session = gnc_get_current_session(); qof_session_call_close_hooks(current_session); gnc_hook_run(HOOK_BOOK_CLOSED, current_session); - xaccLogDisable(); - qof_session_destroy (current_session); - xaccLogEnable(); + gnc_clear_current_session(); /* load the accounts from the users datafile */ /* but first, check to make sure we've got a session going. */ @@ -1064,9 +1062,7 @@ gnc_file_save_as (void) /* if we got to here, then we've successfully gotten a new session */ /* close up the old file session (if any) */ qof_session_swap_data (session, new_session); - xaccLogDisable(); - qof_session_destroy (session); - xaccLogEnable(); + gnc_clear_current_session(); session = NULL; /* XXX At this point, we should really mark the data in the new session @@ -1116,9 +1112,7 @@ gnc_file_quit (void) qof_session_call_close_hooks(session); gnc_hook_run(HOOK_BOOK_CLOSED, session); - xaccLogDisable(); - qof_session_destroy (session); - xaccLogEnable(); + gnc_clear_current_session(); gnc_get_current_session ();