[Gnucash-changes] r12975 - gnucash/trunk/src - Consolidate application lifecycle functions into src/gnome-utils,

Chris Shoemaker chris at cvs.gnucash.org
Tue Jan 24 20:36:28 EST 2006


Author: chris
Date: 2006-01-24 20:36:28 -0500 (Tue, 24 Jan 2006)
New Revision: 12975
Trac: http://svn.gnucash.org/trac/changeset/12975

Modified:
   gnucash/trunk/src/bin/gnucash-bin.c
   gnucash/trunk/src/business/business-gnome/business-gnome.scm
   gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c
   gnucash/trunk/src/gnome-utils/gnc-gnome-utils.h
   gnucash/trunk/src/gnome-utils/gnc-splash.c
   gnucash/trunk/src/gnome-utils/gnc-splash.h
   gnucash/trunk/src/gnome-utils/gw-gnome-utils-spec.scm
   gnucash/trunk/src/gnome/gw-gnc-spec.scm
   gnucash/trunk/src/gnome/top-level.c
   gnucash/trunk/src/gnome/top-level.h
   gnucash/trunk/src/scm/command-line.scm
   gnucash/trunk/src/scm/main.scm
   gnucash/trunk/src/scm/price-quotes.scm
Log:
   Consolidate application lifecycle functions into src/gnome-utils,
   leaving only the highest level of gui initialization in /gnome/top-level.c
   Process --loglevel command-line option from C.
   Move the running of the startup hook from guile to C.
   Distrubute bits of scheme from main.scm to the modules they're used in.
   Remove more obsoleted scheme.



Modified: gnucash/trunk/src/bin/gnucash-bin.c
===================================================================
--- gnucash/trunk/src/bin/gnucash-bin.c	2006-01-25 01:21:28 UTC (rev 12974)
+++ gnucash/trunk/src/bin/gnucash-bin.c	2006-01-25 01:36:28 UTC (rev 12975)
@@ -60,6 +60,7 @@
 static const char *add_quotes_file;
 static int nofile;
 static const char *file_to_load;
+static int loglevel;
 
 static void
 gnc_print_unstable_message(void)
@@ -215,7 +216,7 @@
          _("Show GnuCash version"), NULL},
         {"debug", '\0', POPT_ARG_NONE, &debugging, 0,
          _("Enable debugging mode"), NULL},
-        {"loglevel", '\0', POPT_ARG_INT, NULL, 0,
+        {"loglevel", '\0', POPT_ARG_INT, &loglevel, 0,
          _("Set the logging level from 0 (least) to 6 (most)"), 
          _("LOGLEVEL")},
         {"nofile", '\0', POPT_ARG_NONE, &nofile, 0,
@@ -257,24 +258,6 @@
 }
 
 static void
-shutdown(int status) 
-{
-    if (gnucash_ui_is_running()) {
-        if (!gnucash_ui_is_terminating()) {
-            if (gnc_file_query_save()) {
-                gnc_hook_run(HOOK_UI_SHUTDOWN, NULL);
-                gnc_gui_shutdown();
-            }
-        }
-    } else {
-        gnc_gui_destroy();
-        gnc_hook_run(HOOK_SHUTDOWN, NULL);
-        gnc_engine_shutdown();
-        exit(status);
-    }   
-}
-
-static void
 load_gnucash_modules()
 {
     int i, len;
@@ -334,10 +317,10 @@
 
     if (!SCM_NFALSEP(scm_result)) {
         g_error("Failed to add quotes to %s.", add_quotes_file);
-        shutdown(1);
+        gnc_shutdown(1);
     }
     gnc_engine_resume_events();
-    shutdown(0);
+    gnc_shutdown(0);
     return;
 }
 
@@ -360,17 +343,20 @@
     main_mod = scm_c_resolve_module("gnucash main");
     scm_set_current_module(main_mod);
 
-    /* TODO: After some more guile-extraction, this should happen
-       even before booting guile. */
-    gnc_gui_init();
+    /* TODO: After some more guile-extraction, this should happen even
+       before booting guile.  */
+    gnc_main_gui_init();
 
     load_gnucash_modules();
+    
+    qof_log_set_level_global(loglevel);
+
     load_system_config();
     load_user_config();
     gnc_hook_add_dangler(HOOK_UI_SHUTDOWN, (GFunc)gnc_file_quit, NULL);
 
     scm_c_eval_string("(gnc:main)");
-
+    gnc_hook_run(HOOK_STARTUP, NULL);
     
     if (!nofile && (fn = get_file_to_load())) {
         gnc_update_splash_screen(_("Loading data..."));
@@ -391,7 +377,7 @@
     gnc_ui_start_event_loop();
     gnc_hook_remove_dangler(HOOK_UI_SHUTDOWN, (GFunc)gnc_file_quit);
 
-    shutdown(0);
+    gnc_shutdown(0);
     return;
 }
 

Modified: gnucash/trunk/src/business/business-gnome/business-gnome.scm
===================================================================
--- gnucash/trunk/src/business/business-gnome/business-gnome.scm	2006-01-25 01:21:28 UTC (rev 12974)
+++ gnucash/trunk/src/business/business-gnome/business-gnome.scm	2006-01-25 01:36:28 UTC (rev 12975)
@@ -14,10 +14,17 @@
 (use-modules (gnucash report business-reports))
 (use-modules (gnucash main))		;for gnc:debug
 
+(export gnc:reload-module)
+
 (define top-level (N_ "_Business"))
 (define new-label (N_ "New"))
 (define find-label (N_ "Find"))
 
+(define (gnc:reload-module name)
+  (let ((m (current-module)))
+    (load-from-path name)
+    (set-current-module m)))
+
 (define (business-report-function)
   (gnc:add-extension
    (gnc:make-menu gnc:menuname-business-reports

Modified: gnucash/trunk/src/gnome/gw-gnc-spec.scm
===================================================================
--- gnucash/trunk/src/gnome/gw-gnc-spec.scm	2006-01-25 01:21:28 UTC (rev 12974)
+++ gnucash/trunk/src/gnome/gw-gnc-spec.scm	2006-01-25 01:36:28 UTC (rev 12975)
@@ -50,60 +50,12 @@
 
   (gw:wrap-function
    ws
-   'gnc:ui-is-running?
-   '<gw:bool>
-   "gnucash_ui_is_running"
-   '()
-   "Predicate to determine if the UI is running.")
-
-  (gw:wrap-function
-   ws
-   'gnc:ui-is-terminating?
-   '<gw:bool>
-   "gnucash_ui_is_terminating"
-   '()
-   "Predicate to determine if the UI is in the process of terminating.")
-
-  (gw:wrap-function
-   ws
    'gnc:new-user-dialog
    '<gw:void>
    "gnc_ui_new_user_dialog"
    '()
    "Show the new user dialog.")
 
-  (gw:wrap-function
-   ws
-   'gnc:update-splash-screen
-   '<gw:void>
-   "gnc_update_splash_screen"
-   '(((<gw:mchars> caller-owned const) string))
-   "Update the progress box on the splash screen dialog.")
-
-  (gw:wrap-function
-   ws
-   'gnc:destroy-splash-screen
-   '<gw:void>
-   "gnc_destroy_splash_screen"
-   '()
-   "Destroy the splash screen dialog.")
-
-  (gw:wrap-function
-   ws
-   'gnc:gui-shutdown
-   '<gw:void>
-   "gnc_gui_shutdown"
-   '()
-   "Shutdown the UI.")
-
-  (gw:wrap-function
-   ws
-   'gnc:gui-destroy
-   '<gw:void>
-   "gnc_gui_destroy"
-   '()
-   "Destroy the UI.")
-
   (gw:wrap-as-wct ws
                   '<gnc:ProgressDialog*>
                   "GNCProgressDialog *" "const GNCProgressDialog *")

Modified: gnucash/trunk/src/gnome/top-level.c
===================================================================
--- gnucash/trunk/src/gnome/top-level.c	2006-01-25 01:21:28 UTC (rev 12974)
+++ gnucash/trunk/src/gnome/top-level.c	2006-01-25 01:36:28 UTC (rev 12975)
@@ -26,10 +26,7 @@
 
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
-#include <popt.h>
 #include <stdlib.h>
-#include <g-wrap-wct.h>
-#include <X11/Xlib.h>
 
 #include "TransLog.h"
 #include "combocell.h"
@@ -57,8 +54,6 @@
 #include "gnc-plugin-budget.h"
 #include "gnc-plugin-page-register.h"
 #include "gnc-plugin-manager.h" /* FIXME Remove this line*/
-#include "gnc-icons.h" /* FIXME Remove this line*/
-#include "gnc-splash.h"
 #include "gnc-html.h"
 #include "gnc-gnome-utils.h"
 #include "gnc-report.h"
@@ -74,48 +69,12 @@
 #include "gnc-window.h"
 
 
-#define ACCEL_MAP_NAME "accelerator-map"
-
-/** PROTOTYPES ******************************************************/
-static void gnc_configure_date_format(void);
-
-
 /** GLOBALS *********************************************************/
 /* This static indicates the debugging module that this .o belongs to.  */
 static QofLogModule log_module = GNC_MOD_GUI;
 
-static int gnome_is_running = FALSE;
-static int splash_is_initialized = FALSE;
-static int gnome_is_initialized = FALSE;
-static int gnome_is_terminating = FALSE;
-
-
-gboolean
-gnucash_ui_is_running(void)
-{
-  return gnome_is_running;
-}
-
-gboolean 
-gnucash_ui_is_terminating(void)
-{
-  return gnome_is_terminating;
-}
-
-static void
-gnc_global_options_help_cb (GNCOptionWin *win, gpointer dat)
-{
-  gnc_gnome_help (HF_CUSTOM, HL_GLOBPREFS);
-}
-
-static void
-gnc_commodity_help_cb (void)
-{
-  gnc_gnome_help (HF_USAGE, HL_COMMODITY);
-}
-
 /* ============================================================== */
-/* HTML Hadler for reports. */
+/* HTML Handler for reports. */
 
 #define IF_TYPE(URL_TYPE_STR,ENTITY_TYPE)                                   \
   if (strncmp (URL_TYPE_STR, location, strlen (URL_TYPE_STR)) == 0)         \
@@ -236,50 +195,14 @@
   return TRUE;
 }
 
-/* ============================================================== */
-
 void
-gnc_gui_init_splash (void)
+gnc_main_gui_init (void)
 {
-  ENTER (" ");
-
-  if (!splash_is_initialized)
-  {
-    splash_is_initialized = TRUE;
-
-    /* put up splash screen */
-    gnc_show_splash_screen ();
-  }
-
-  LEAVE (" ");
-}
-
-void
-gnc_gui_init (void)
-{
     GncMainWindow *main_window;
-    gchar *map;
 
-    ENTER (" ");
-    
-    if (gnome_is_initialized) {
-        LEAVE("already initialized");
-        return;
-    }
-        
-    /* Make sure the splash (and hense gnome) was initialized */
-    if (!splash_is_initialized)
-        gnc_gui_init_splash();
+    ENTER(" ");
+    main_window = gnc_gui_init();
 
-    gnome_is_initialized = TRUE;
-
-    gnc_ui_util_init();
-    gnc_configure_date_format();
-    gnc_gconf_general_register_cb(
-        KEY_DATE_FORMAT, (GncGconfGeneralCb)gnc_configure_date_format, NULL);
-    gnc_gconf_general_register_any_cb(
-        (GncGconfGeneralAnyCb)gnc_gui_refresh_all, NULL);
-
     if (!gnucash_style_init())
       gnc_shutdown(1);
     gnucash_color_init();
@@ -290,23 +213,10 @@
     gnc_html_register_url_handler (URL_TYPE_PRICE,
                                    gnc_html_price_url_cb);
 
-    gnc_ui_commodity_set_help_callback (gnc_commodity_help_cb);
-
-    gnc_file_set_shutdown_callback (gnc_shutdown);
-
-    gnc_options_dialog_set_global_help_cb (gnc_global_options_help_cb, NULL);
-
     gnc_ui_sx_initialize();
 
-    main_window = gnc_main_window_new ();
-    gtk_widget_show (GTK_WIDGET (main_window));
-
     gnc_totd_dialog(GTK_WINDOW(main_window), TRUE);
 
-    map = gnc_build_dotgnucash_path(ACCEL_MAP_NAME);
-    gtk_accel_map_load(map);
-    g_free(map);
-
     /* FIXME Remove this test code */
     gnc_plugin_manager_add_plugin (
         gnc_plugin_manager_get (), gnc_plugin_account_tree_new ());
@@ -323,162 +233,11 @@
        Anyway... Oh, maybe... nah */
     gnc_plugin_manager_add_plugin (gnc_plugin_manager_get (),
                                    gnc_plugin_budget_new ());
-    gnc_load_stock_icons ();
     gnc_ui_hierarchy_druid_initialize();
 
     /* Run the ui startup hooks. */
     gnc_hook_run(HOOK_UI_STARTUP, NULL);
-
-    gnc_window_set_progressbar_window (GNC_WINDOW(main_window));
-
-    LEAVE (" ");
-
+    LEAVE(" ");
     return;
 }
-
-/* ============================================================== */
-
-void
-gnc_gui_shutdown (void)
-{
-  gchar *map;
-
-  if (gnome_is_running && !gnome_is_terminating)
-  {
-    gnome_is_terminating = TRUE;
-
-    map = gnc_build_dotgnucash_path(ACCEL_MAP_NAME);
-    gtk_accel_map_save(map);
-    g_free(map);
-
-    gtk_main_quit();
-
-    gnc_gnome_shutdown ();
-  }
-}
-
-/* ============================================================== */
-
-void
-gnc_gui_destroy (void)
-{
-  if (!gnome_is_initialized)
-    return;
-
-  gnc_extensions_shutdown ();
-}
-
-/* ============================================================== */
-
-static gboolean
-gnc_ui_check_events (gpointer not_used)
-{
-  QofSession *session;
-  gboolean force;
-
-  if (gtk_main_level() != 1)
-    return TRUE;
-
-  session = qof_session_get_current_session ();
-  if (!session)
-    return TRUE;
-
-  if (gnc_gui_refresh_suspended ())
-    return TRUE;
-
-  if (!qof_session_events_pending (session))
-    return TRUE;
-
-  gnc_suspend_gui_refresh ();
-
-  force = qof_session_process_events (session);
-
-  gnc_resume_gui_refresh ();
-
-  if (force)
-    gnc_gui_refresh_all ();
-
-  return TRUE;
-}
-
-static int
-gnc_x_error (Display        *display, XErrorEvent *error)
-{
-  if (error->error_code)
-  {
-    char buf[64];
-
-    XGetErrorText (display, error->error_code, buf, 63);
-
-    g_warning ("X-ERROR **: %s\n  serial %ld error_code %d "
-               "request_code %d minor_code %d\n", 
-               buf, 
-               error->serial, 
-               error->error_code, 
-               error->request_code,
-               error->minor_code);
-  }
-
-  return 0;
-}
-
-int
-gnc_ui_start_event_loop (void)
-{
-  guint id;
-
-  gnome_is_running = TRUE;
-
-  id = g_timeout_add_full (G_PRIORITY_DEFAULT_IDLE, 10000, /* 10 secs */
-                           gnc_ui_check_events, NULL, NULL);
-
-  XSetErrorHandler (gnc_x_error);
-
-  /* Enter gnome event loop */
-  gtk_main ();
-
-  g_source_remove (id);
-
-  gnome_is_running = FALSE;
-  gnome_is_terminating = FALSE;
-
-  return 0;
-}
-
-/* ============================================================== */
-
-/* gnc_configure_date_format
- *    sets dateFormat to the current value on the scheme side
- *
- * Args: Nothing
- * Returns: Nothing
- */
-static void 
-gnc_configure_date_format (void)
-{
-  char *format_code = gnc_gconf_get_string(GCONF_GENERAL, KEY_DATE_FORMAT, NULL);
-
-  QofDateFormat df;
-
-  if (format_code == NULL)
-    format_code = g_strdup("locale");
-  if (*format_code == '\0') {
-    g_free(format_code);
-    format_code = g_strdup("locale");
-  }
-
-  if (gnc_date_string_to_dateformat(format_code, &df))
-  {
-    PERR("Incorrect date format code");
-    if (format_code != NULL)
-      free(format_code);
-    return;
-  }
-
-  qof_date_format_set(df);
-
-  if (format_code != NULL)
-    free(format_code);
-}
-
 /****************** END OF FILE **********************/

Modified: gnucash/trunk/src/gnome/top-level.h
===================================================================
--- gnucash/trunk/src/gnome/top-level.h	2006-01-25 01:21:28 UTC (rev 12974)
+++ gnucash/trunk/src/gnome/top-level.h	2006-01-25 01:36:28 UTC (rev 12975)
@@ -25,12 +25,6 @@
 
 #include <glib.h>
 
-gboolean gnucash_ui_is_running (void);
-gboolean gnucash_ui_is_terminating (void);
-void gnc_gui_init_splash (void);
-void gnc_gui_init (void);
-void gnc_gui_shutdown (void);
-void gnc_gui_destroy (void);
-int gnc_ui_start_event_loop (void);
+void gnc_main_gui_init(void);
 
 #endif

Modified: gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c	2006-01-25 01:21:28 UTC (rev 12974)
+++ gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c	2006-01-25 01:36:28 UTC (rev 12975)
@@ -26,6 +26,7 @@
 #include <gnome.h>
 #include <libguile.h>
 #include <gconf/gconf.h>
+#include <X11/Xlib.h>
 
 #include "gnc-html-graph-gog.h"
 
@@ -36,12 +37,75 @@
 #include "gnc-html.h"
 #include "gnc-engine.h"
 #include "gnc-ui.h"
-
+#include "gnc-file.h"
+#include "gnc-hooks.h"
+#include "gnc-filepath-utils.h"
+#include "gnc-menu-extensions.h"
+#include "gnc-component-manager.h"
+#include "gnc-splash.h"
+#include "gnc-window.h"
+#include "gnc-icons.h"
+#include "dialog-options.h"
+#include "dialog-commodity.h"
+#include "gnc-ui-util.h"
 #include <gnc-dir.h>
 
 static QofLogModule log_module = GNC_MOD_GUI;
 static GnomeProgram *gnucash_program = NULL;
+static int gnome_is_running = FALSE;
+static int gnome_is_terminating = FALSE;
+static int gnome_is_initialized = FALSE;
 
+
+#define ACCEL_MAP_NAME "accelerator-map"
+
+static void
+gnc_global_options_help_cb (GNCOptionWin *win, gpointer dat)
+{
+  gnc_gnome_help (HF_CUSTOM, HL_GLOBPREFS);
+}
+
+static void
+gnc_commodity_help_cb (void)
+{
+  gnc_gnome_help (HF_USAGE, HL_COMMODITY);
+}
+
+/* gnc_configure_date_format
+ *    sets dateFormat to the current value on the scheme side
+ *
+ * Args: Nothing
+ * Returns: Nothing
+ */
+static void 
+gnc_configure_date_format (void)
+{
+  char *format_code = gnc_gconf_get_string(GCONF_GENERAL, 
+                                           KEY_DATE_FORMAT, NULL);
+
+  QofDateFormat df;
+
+  if (format_code == NULL)
+    format_code = g_strdup("locale");
+  if (*format_code == '\0') {
+    g_free(format_code);
+    format_code = g_strdup("locale");
+  }
+
+  if (gnc_date_string_to_dateformat(format_code, &df))
+  {
+    PERR("Incorrect date format code");
+    if (format_code != NULL)
+      free(format_code);
+    return;
+  }
+
+  qof_date_format_set(df);
+
+  if (format_code != NULL)
+    free(format_code);
+}
+
 char *
 gnc_gnome_locate_pixmap (const char *name)
 {
@@ -153,11 +217,6 @@
 }
 
 void
-gnc_gnome_shutdown (void)
-{
-}
-
-void
 gnc_gnome_help (const char *file_name, const char *anchor)
 {
   GError *error = NULL;
@@ -233,27 +292,171 @@
   return pixbuf;
 }
 
+static gboolean
+gnc_ui_check_events (gpointer not_used)
+{
+  QofSession *session;
+  gboolean force;
 
-/*  shutdown gnucash.  This function will call the Scheme side of
- *  GnuCash to initiate an orderly shutdown, and when that has
- *  finished it will exit the program.
- */
-void
-gnc_shutdown (int exit_status)
+  if (gtk_main_level() != 1)
+    return TRUE;
+
+  session = qof_session_get_current_session ();
+  if (!session)
+    return TRUE;
+
+  if (gnc_gui_refresh_suspended ())
+    return TRUE;
+
+  if (!qof_session_events_pending (session))
+    return TRUE;
+
+  gnc_suspend_gui_refresh ();
+
+  force = qof_session_process_events (session);
+
+  gnc_resume_gui_refresh ();
+
+  if (force)
+    gnc_gui_refresh_all ();
+
+  return TRUE;
+}
+
+static int
+gnc_x_error (Display *display, XErrorEvent *error)
 {
-  /*SCM scm_shutdown = gnc_scm_lookup("gnucash bootstrap", "gnc:shutdown");*/
-  SCM scm_shutdown = scm_c_eval_string("gnc:shutdown");
+  if (error->error_code)
+  {
+    char buf[64];
 
-  if(scm_procedure_p(scm_shutdown) != SCM_BOOL_F)
-  {
-    SCM scm_exit_code = scm_long2num(exit_status);    
-    scm_call_1(scm_shutdown, scm_exit_code);
+    XGetErrorText (display, error->error_code, buf, 63);
+
+    g_warning ("X-ERROR **: %s\n  serial %ld error_code %d "
+               "request_code %d minor_code %d\n", 
+               buf, 
+               error->serial, 
+               error->error_code, 
+               error->request_code,
+               error->minor_code);
   }
-  else
+
+  return 0;
+}
+
+int
+gnc_ui_start_event_loop (void)
+{
+  guint id;
+
+  gnome_is_running = TRUE;
+
+  id = g_timeout_add_full (G_PRIORITY_DEFAULT_IDLE, 10000, /* 10 secs */
+                           gnc_ui_check_events, NULL, NULL);
+
+  XSetErrorHandler (gnc_x_error);
+
+  /* Enter gnome event loop */
+  gtk_main ();
+
+  g_source_remove (id);
+
+  gnome_is_running = FALSE;
+  gnome_is_terminating = FALSE;
+
+  return 0;
+}
+
+GncMainWindow *
+gnc_gui_init(void)
+{
+    static GncMainWindow *main_window;
+    gchar *map;
+
+    if (gnome_is_initialized) {
+        return main_window;
+    }
+
+    gnc_gui_init_splash();
+
+    gnome_is_initialized = TRUE;
+
+    gnc_ui_util_init();
+    gnc_configure_date_format();
+
+    gnc_gconf_general_register_cb(
+        KEY_DATE_FORMAT, (GncGconfGeneralCb)gnc_configure_date_format, NULL);
+    gnc_gconf_general_register_any_cb(
+        (GncGconfGeneralAnyCb)gnc_gui_refresh_all, NULL);
+
+    gnc_ui_commodity_set_help_callback (gnc_commodity_help_cb);
+    gnc_file_set_shutdown_callback (gnc_shutdown);
+
+    gnc_options_dialog_set_global_help_cb (gnc_global_options_help_cb, NULL);
+
+    main_window = gnc_main_window_new ();
+    gtk_widget_show (GTK_WIDGET (main_window));
+    gnc_window_set_progressbar_window (GNC_WINDOW(main_window));
+
+    map = gnc_build_dotgnucash_path(ACCEL_MAP_NAME);
+    gtk_accel_map_load(map);
+    g_free(map);
+
+    gnc_load_stock_icons();
+
+    return main_window;
+}
+
+gboolean
+gnucash_ui_is_running(void)
+{
+  return gnome_is_running;
+}
+
+static void
+gnc_gui_destroy (void)
+{
+  if (!gnome_is_initialized)
+    return;
+
+  gnc_extensions_shutdown ();
+}
+
+static void
+gnc_gui_shutdown (void)
+{
+  gchar *map;
+
+  if (gnome_is_running && !gnome_is_terminating)
   {
-    /* Either guile is not running, or for some reason we
-       can't find gnc:shutdown. Either way, just exit. */
-    g_warning("couldn't find gnc:shutdown -- exiting anyway.");
-    exit(exit_status);
+    gnome_is_terminating = TRUE;
+
+    map = gnc_build_dotgnucash_path(ACCEL_MAP_NAME);
+    gtk_accel_map_save(map);
+    g_free(map);
+
+    gtk_main_quit();
   }
 }
+
+/*  shutdown gnucash.  This function will initiate an orderly
+ *  shutdown, and when that has finished it will exit the program.
+ */
+void
+gnc_shutdown (int exit_status)
+{
+    if (gnucash_ui_is_running()) {
+        if (!gnome_is_terminating) {
+            if (gnc_file_query_save()) {
+                gnc_hook_run(HOOK_UI_SHUTDOWN, NULL);
+                gnc_gui_shutdown();
+            }
+        }
+    } else {
+        gnc_gui_destroy();
+        gnc_hook_run(HOOK_SHUTDOWN, NULL);
+        gnc_engine_shutdown();
+        exit(exit_status);
+    }   
+}
+

Modified: gnucash/trunk/src/gnome-utils/gnc-gnome-utils.h
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-gnome-utils.h	2006-01-25 01:21:28 UTC (rev 12974)
+++ gnucash/trunk/src/gnome-utils/gnc-gnome-utils.h	2006-01-25 01:36:28 UTC (rev 12975)
@@ -36,14 +36,11 @@
 #define GNC_GNOME_UTILS_H
 
 #include <libgnome/libgnome.h>
+#include <gnc-main-window.h>
 
 /** Initialize the Gnome libraries. */
 void gnc_gnome_init (int argc, char **argv, const char * version);
 
-/** Shutdown/cleanup any gnome related libraries. */
-void gnc_gnome_shutdown (void);
-
-
 /** Given a pixmap/pixbuf file name, find the file in the pixmap
  *  directory associated with this application.  This routine will
  *  display an error message if it can't find the file.
@@ -139,14 +136,17 @@
 GdkPixbuf * gnc_gnome_get_gdkpixbuf (const char *name);
 
 
-/** Shutdown gnucash.  This function will call the Scheme side of
- *  GnuCash to initiate an orderly shutdown, and when that has
- *  finished it will exit the program.
+/** Shutdown gnucash.  This function will initiate an orderly
+ *  shutdown, and when that has finished it will exit the program.
  *
  *  @param exit_status The exit status for the program.
  */
 void gnc_shutdown (int exit_status);
 
+void gnc_gui_init_splash (void);
+GncMainWindow *gnc_gui_init (void);
+int gnc_ui_start_event_loop (void);
+gboolean gnucash_ui_is_running (void);
 
 #endif
 /** @} */

Modified: gnucash/trunk/src/gnome-utils/gnc-splash.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-splash.c	2006-01-25 01:21:28 UTC (rev 12974)
+++ gnucash/trunk/src/gnome-utils/gnc-splash.c	2006-01-25 01:36:28 UTC (rev 12975)
@@ -32,8 +32,8 @@
 
 static GtkWidget * splash = NULL;
 static GtkWidget * progress = NULL;
+static int splash_is_initialized = FALSE;
 
-
 static void
 splash_destroy_cb (GtkObject *object, gpointer user_data)
 {
@@ -41,6 +41,15 @@
 }
 
 void
+gnc_gui_init_splash (void)
+{
+  if (!splash_is_initialized) {
+    splash_is_initialized = TRUE;
+    gnc_show_splash_screen ();
+  }
+}
+
+void
 gnc_show_splash_screen (void)
 {
   GtkWidget *pixmap;

Modified: gnucash/trunk/src/gnome-utils/gnc-splash.h
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-splash.h	2006-01-25 01:21:28 UTC (rev 12974)
+++ gnucash/trunk/src/gnome-utils/gnc-splash.h	2006-01-25 01:36:28 UTC (rev 12975)
@@ -26,5 +26,6 @@
 void gnc_show_splash_screen (void);
 void gnc_destroy_splash_screen (void);
 void gnc_update_splash_screen (const gchar *string);
+void gnc_gui_init_splash (void);
 
 #endif

Modified: gnucash/trunk/src/gnome-utils/gw-gnome-utils-spec.scm
===================================================================
--- gnucash/trunk/src/gnome-utils/gw-gnome-utils-spec.scm	2006-01-25 01:21:28 UTC (rev 12974)
+++ gnucash/trunk/src/gnome-utils/gw-gnome-utils-spec.scm	2006-01-25 01:36:28 UTC (rev 12975)
@@ -46,17 +46,10 @@
       "#include <gnc-plugin-file-history.h>\n"
       "#include <gnc-ui.h>\n"
       "#include <print-session.h>\n"
+      "#include <gnc-splash.h>\n"
       )))
 
 
-  (gw:wrap-function
-   ws
-   'gnc:gnome-shutdown
-   '<gw:void>
-   "gnc_gnome_shutdown"
-   '()
-   "Shutdown the GnuCash gnome system.")
-
   (gw:wrap-as-wct ws '<gtk:Widget*> "GtkWidget*" "const GtkWidget*")
   (gw:wrap-as-wct ws '<gtk:Window*> "GtkWindow*" "const GtkWindow*")
   (gw:wrap-as-wct ws '<gnc:UIWidget> "gncUIWidget" "const gncUIWidget")
@@ -501,4 +494,21 @@
    "gnc_gnome_locate_data_file"
    '(((<gw:mchars> caller-owned const) name))
    "Find the file in the application data directory.")
+
+  (gw:wrap-function
+   ws
+   'gnc:ui-is-running?
+   '<gw:bool>
+   "gnucash_ui_is_running"
+   '()
+   "Predicate to determine if the UI is running.")
+
+  (gw:wrap-function
+   ws
+   'gnc:update-splash-screen
+   '<gw:void>
+   "gnc_update_splash_screen"
+   '(((<gw:mchars> caller-owned const) string))
+   "Update the progress box on the splash screen dialog.")
+
 )

Modified: gnucash/trunk/src/scm/command-line.scm
===================================================================
--- gnucash/trunk/src/scm/command-line.scm	2006-01-25 01:21:28 UTC (rev 12974)
+++ gnucash/trunk/src/scm/command-line.scm	2006-01-25 01:36:28 UTC (rev 12975)
@@ -22,7 +22,6 @@
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; Configuration variables
 
-(define gnc:*arg-no-file* #f)
 (define gnc:*loglevel* #f)
 
 (define gnc:*doc-path* #f)
@@ -67,13 +66,6 @@
 (define (gnc:initialize-config-vars)
   ;; We use a function so we don't do this at file load time.
   
-  (set! gnc:*arg-no-file*
-        (gnc:make-config-var
-         (N_ "Don't load any file, including autoloading the last file.")
-         (lambda (var value) (if (boolean? value) (list value) #f))
-         eq?
-         #f))
-  
   ;; Convert the temporary startup value into a config var.
   (let ((current-value gnc:*debugging?*))
     (set! 
@@ -133,13 +125,6 @@
          "LOGLEVEL"
          (N_ "Set the logging level from 0 (least) to 6 (most)"))
 
-   (list "nofile"
-         'boolean
-         (lambda (val)
-           (gnc:config-var-value-set! gnc:*arg-no-file* #f val))
-         #f
-         (N_ "Do not load the last file opened"))
-
    (list "doc-path"
          'string
          (lambda (val)

Modified: gnucash/trunk/src/scm/main.scm
===================================================================
--- gnucash/trunk/src/scm/main.scm	2006-01-25 01:21:28 UTC (rev 12974)
+++ gnucash/trunk/src/scm/main.scm	2006-01-25 01:36:28 UTC (rev 12975)
@@ -50,16 +50,12 @@
 (export gnc:error)
 (export gnc:msg)
 (export gnc:debug)
-(export build-path)
-(export gnc:use-module-here!)
-(export item-list->hash!)
 (export string-join)
 (export gnc:backtrace-if-exception)
 (export gnc:find-file)
 (export gnc:find-localized-file)
 (export gnc:main)
 (export gnc:safe-strcmp) ;; only used by aging.scm atm...
-(export gnc:reload-module)
 
 (re-export hash-fold)
 (re-export string-split)
@@ -93,16 +89,6 @@
 
 ;;(use-modules (ice-9 statprof))
 
-;;
-;; A flag: is this a development version?  This will flag whether or not
-;; to print out various 'development version' strings throughout the code.
-;; #t == development version, #f == stable version
-;;
-;; NOTE: You still need to comment out the message in
-;; tip_of_the_day.list.in by hand!
-;;
-(define gnc:*is-development-version?* #t)
-
 ;; These will be converted to config vars later (see command-line.scm)
 (define gnc:*debugging?* (if (getenv "GNC_DEBUG") #t #f))
 
@@ -137,11 +123,6 @@
         (b -1)
         (else 0)))))
 
-(define (gnc:reload-module name)
-  (let ((m (current-module)))
-    (load-from-path name)
-    (set-current-module m)))
-
 (if (not (defined? 'hash-fold))
     (define (hash-fold proc init table)
       (for-each 
@@ -152,35 +133,6 @@
           bin))
        (vector->list table))))
 
-(define (item-list->hash! lst hash
-			  getkey getval
-			  hashref hashset 
-			  list-duplicates?)
-  ;; Takes a list of the form (item item item item) and returns a hash
-  ;; formed by traversing the list, and getting the key and val from
-  ;; each item using the supplied get-key and get-val functions, and
-  ;; building a hash table from the result using the given hashref and
-  ;; hashset functions.  list-duplicates? determines whether or not in
-  ;; the resulting hash, the value for a given key is a list of all
-  ;; the values associated with that key in the input or just the
-  ;; first one encountered.
-
-  (define (handle-item item)
-    (let* ((key (getkey item))
-	   (val (getval item))
-	   (existing-val (hashref hash key)))
-
-      (if (not list-duplicates?)
-	  ;; ignore if not first value.
-	  (if (not existing-val) (hashset hash key val))
-	  ;; else result is list.
-	  (if existing-val
-	      (hashset hash key (cons val existing-val))
-	      (hashset hash key (list val))))))
-  
-  (for-each handle-item lst)
-  hash)
-
 (define (string-join lst joinstr)
   ;; This should avoid a bunch of unnecessary intermediate string-appends.
   ;; I'm presuming those are more expensive than cons...
@@ -207,6 +159,7 @@
           (set! parts (cons (substring str 0 last-char) parts))))    
     parts))
 
+;; only used by doc-path
 (define (gnc:flatten tree)
   (let ((result '()))
     (let loop ((remaining-items tree))
@@ -322,23 +275,8 @@
 
 (define (gnc:shutdown exit-status)
   (gnc:debug "Shutdown -- exit-status: " exit-status)
+  (exit exit-status)) ;; Temporary Stub until command-line.scm dies
 
-  (cond ((gnc:ui-is-running?)
-	 (if (not (gnc:ui-is-terminating?))
-             (if (gnc:file-query-save)
-                 (begin
-                   (gnc:hook-run-danglers gnc:*ui-shutdown-hook*)
-                   (gnc:gui-shutdown)))))
-        (else
-	 (gnc:gui-destroy)
-	 (gnc:hook-run-danglers gnc:*shutdown-hook*)
-         (gnc:engine-shutdown)
-	 (exit exit-status))))
-
-(define (gnc:gui-finish)
-  (gnc:debug "UI Shutdown hook.")
-  (gnc:file-quit))
-
 (define (gnc:strip-path path)
   (let* ((parts-in (string-split path #\/))
 	 (parts-out '()))
@@ -356,43 +294,6 @@
     ;; Put it back together
     (string-join (reverse parts-out) "/")))
 
-(define (gnc:normalize-path file)
-  (let* ((parts-in (string-split file #\/))
-	 (parts-out '()))
-
-    ;; Convert to a path based at the root.  If the filename starts
-    ;; with a '/' then the first component of the list is a null
-    ;; string.  If the path starts with foo:// then the first
-    ;; component will contain a ':' and the second will be null.
-    (cond ((string-null? (car parts-in))
-	   (gnc:strip-path file))
-	  ((and (string=? (car parts-in) "file:")
-		(string-null? (cadr parts-in)))
-	   (gnc:strip-path file))
-	  ((and (string-index (car parts-in) #\:)
-		(string-null? (cadr parts-in)))
-	   file)
-	  (else
-	   (gnc:strip-path (string-append (getenv "PWD") "/" file))))
-  )
-)
-
-(define (gnc:account-file-to-load)
-  (let ((ok (not (gnc:config-var-value-get gnc:*arg-no-file*)))
-        (file (if (pair? gnc:*command-line-remaining*)
-                  (car gnc:*command-line-remaining*)
-                  (gnc:history-get-last))))
-    (and ok (string? file) (gnc:normalize-path file))))
-
-(define (gnc:load-account-file)
-  (let ((file (gnc:account-file-to-load)))
-      (if file 
-	(begin
-	  (gnc:update-splash-screen (_ "Loading data..."))
-	  (and (not (gnc:file-open-file file))
-	       (gnc:hook-run-danglers gnc:*book-opened-hook* #f)))
-        (and (gnc:hook-run-danglers gnc:*book-opened-hook* #f)))))
-
 (define (gnc:main)
 
   ;;  (statprof-reset 0 50000) ;; 20 times/sec
@@ -430,11 +331,6 @@
     (list gnc:menuname-reports gnc:menuname-utility "")
     (lambda (window)
       (gnc:main-window-open-report (gnc:make-welcome-report) window))))
-  
-  (gnc:hook-run-danglers gnc:*startup-hook*)
-  
-  (if (gnc:config-var-value-get gnc:*loglevel*)
-      (gnc:set-log-level-global (gnc:config-var-value-get gnc:*loglevel*)))
-    
+
   ;;return to C
   )

Modified: gnucash/trunk/src/scm/price-quotes.scm
===================================================================
--- gnucash/trunk/src/scm/price-quotes.scm	2006-01-25 01:21:28 UTC (rev 12974)
+++ gnucash/trunk/src/scm/price-quotes.scm	2006-01-25 01:36:28 UTC (rev 12975)
@@ -47,6 +47,35 @@
 
 ;; (use-modules (srfi srfi-19)) when available (see below).
 
+(define (item-list->hash! lst hash
+			  getkey getval
+			  hashref hashset 
+			  list-duplicates?)
+  ;; Takes a list of the form (item item item item) and returns a hash
+  ;; formed by traversing the list, and getting the key and val from
+  ;; each item using the supplied get-key and get-val functions, and
+  ;; building a hash table from the result using the given hashref and
+  ;; hashset functions.  list-duplicates? determines whether or not in
+  ;; the resulting hash, the value for a given key is a list of all
+  ;; the values associated with that key in the input or just the
+  ;; first one encountered.
+
+  (define (handle-item item)
+    (let* ((key (getkey item))
+	   (val (getval item))
+	   (existing-val (hashref hash key)))
+
+      (if (not list-duplicates?)
+	  ;; ignore if not first value.
+	  (if (not existing-val) (hashset hash key val))
+	  ;; else result is list.
+	  (if existing-val
+	      (hashset hash key (cons val existing-val))
+	      (hashset hash key (list val))))))
+  
+  (for-each handle-item lst)
+  hash)
+
 (define (yahoo-get-historical-quotes symbol
                                      start-year start-month start-day
                                      end-year end-month end-day)



More information about the gnucash-changes mailing list