r14969 - gnucash/branches/swig-redo/src - Move the code that loads old-style state files from guile into C.

Chris Shoemaker chris at cvs.gnucash.org
Mon Oct 9 20:01:55 EDT 2006


Author: chris
Date: 2006-10-09 20:01:54 -0400 (Mon, 09 Oct 2006)
New Revision: 14969
Trac: http://svn.gnucash.org/trac/changeset/14969

Modified:
   gnucash/branches/swig-redo/src/app-utils/gfec.c
   gnucash/branches/swig-redo/src/app-utils/gfec.h
   gnucash/branches/swig-redo/src/bin/gnucash-bin.c
   gnucash/branches/swig-redo/src/gnome/top-level.c
   gnucash/branches/swig-redo/src/scm/main-window.scm
Log:
Move the code that loads old-style state files from guile into C.
  Move some file evaluation code from gnucash-bin.c into gfec.c.

(This is only related to swigification insofar as it removes the need
to wrap some Session code.)



Modified: gnucash/branches/swig-redo/src/app-utils/gfec.c
===================================================================
--- gnucash/branches/swig-redo/src/app-utils/gfec.c	2006-10-10 00:00:17 UTC (rev 14968)
+++ gnucash/branches/swig-redo/src/app-utils/gfec.c	2006-10-10 00:01:54 UTC (rev 14969)
@@ -163,3 +163,26 @@
 
   return result;
 }
+
+static int error_in_scm_eval = FALSE;
+
+static void
+error_handler(const char *msg)
+{
+    g_warning(msg);
+    error_in_scm_eval = TRUE;
+}
+
+gboolean
+gfec_try_load(gchar *fn)
+{
+    g_message("looking for %s", fn);
+    if (g_file_test(fn, G_FILE_TEST_EXISTS)) {
+        g_message("trying to load %s", fn);
+        error_in_scm_eval = FALSE;
+        gfec_eval_file(fn, error_handler);
+        return !error_in_scm_eval;
+    }
+    return FALSE;
+}
+

Modified: gnucash/branches/swig-redo/src/app-utils/gfec.h
===================================================================
--- gnucash/branches/swig-redo/src/app-utils/gfec.h	2006-10-10 00:00:17 UTC (rev 14968)
+++ gnucash/branches/swig-redo/src/app-utils/gfec.h	2006-10-10 00:01:54 UTC (rev 14969)
@@ -10,6 +10,7 @@
 #define GFEC_H
 
 #include <libguile.h>
+#include <glib.h>
 #include "guile-mappings.h"
 
 typedef void (*gfec_error_handler)(const char *error_message);
@@ -17,5 +18,6 @@
 SCM gfec_eval_file(const char *file, gfec_error_handler error_handler);
 SCM gfec_eval_string(const char *str, gfec_error_handler error_handler);
 SCM gfec_apply(SCM proc, SCM arglist, gfec_error_handler error_handler);
+gboolean gfec_try_load(gchar *fn);
 
 #endif

Modified: gnucash/branches/swig-redo/src/bin/gnucash-bin.c
===================================================================
--- gnucash/branches/swig-redo/src/bin/gnucash-bin.c	2006-10-10 00:00:17 UTC (rev 14968)
+++ gnucash/branches/swig-redo/src/bin/gnucash-bin.c	2006-10-10 00:01:54 UTC (rev 14969)
@@ -97,29 +97,7 @@
         help_path = path;
 }
 
-static int error_in_scm_eval = FALSE;
-
-static void
-error_handler(const char *msg)
-{
-    g_warning(msg);
-    error_in_scm_eval = TRUE;
-}
-
 static gboolean
-try_load(gchar *fn)
-{
-    g_message("looking for %s", fn);
-    if (g_file_test(fn, G_FILE_TEST_EXISTS)) {
-        g_message("trying to load %s", fn);
-        error_in_scm_eval = FALSE;
-        gfec_eval_file(fn, error_handler);
-        return !error_in_scm_eval;
-    }
-    return FALSE;
-}
-
-static gboolean
 try_load_config_array(const gchar *fns[])
 {
     gchar *filename;
@@ -127,7 +105,7 @@
 
     for (i = 0; fns[i]; i++) {
         filename = gnc_build_dotgnucash_path(fns[i]);
-        if (try_load(filename)) {
+        if (gfec_try_load(filename)) {
             g_free(filename);
             return TRUE;
         }
@@ -153,7 +131,7 @@
 
     update_message("loading system configuration");
     system_config = g_build_filename(config_path, "config", NULL);
-    is_system_config_loaded = try_load(system_config);
+    is_system_config_loaded = gfec_try_load(system_config);
     g_free(system_config);
 }
 

Modified: gnucash/branches/swig-redo/src/gnome/top-level.c
===================================================================
--- gnucash/branches/swig-redo/src/gnome/top-level.c	2006-10-10 00:00:17 UTC (rev 14968)
+++ gnucash/branches/swig-redo/src/gnome/top-level.c	2006-10-10 00:01:54 UTC (rev 14969)
@@ -44,6 +44,7 @@
 #include "gnc-file.h"
 #include "gnc-filepath-utils.h"
 #include "gnc-hooks.h"
+#include "gfec.h"
 #include "gnc-main-window.h"
 #include "gnc-menu-extensions.h"
 #include "gnc-plugin-menu-additions.h" /* FIXME Remove this line*/
@@ -68,7 +69,6 @@
 #include "window-report.h"
 #include "gnc-window.h"
 #include "gnc-gkeyfile-utils.h"
-#include <g-wrap-wct.h>
 
 
 /** GLOBALS *********************************************************/
@@ -197,6 +197,20 @@
   return TRUE;
 }
 
+static void
+gnc_main_window_book_open_handler(QofSession *session)
+{
+    gchar *filename, *statefile;
+
+    filename = gnc_html_encode_string(qof_session_get_url(session));
+    if (!filename) return;
+
+    statefile = gnc_build_book_path(filename);
+    g_free(filename);
+    gfec_try_load(statefile);
+    g_free(statefile);
+}
+
 /** 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
@@ -247,10 +261,8 @@
         
 #if (GNUCASH_MAJOR_VERSION < 2) || ((GNUCASH_MAJOR_VERSION == 2) && (GNUCASH_MINOR_VERSION == 0))
         /* See if there's an old style state file to be found */
-        scm_call_1(scm_c_eval_string("gnc:main-window-book-open-handler"),
-                   (session ? gw_wcp_assimilate_ptr(
-                        session, scm_c_eval_string("<gnc:Session*>")) :
-                    SCM_BOOL_F));
+        gnc_main_window_book_open_handler(session);
+
         /* At this point the reports have only been loaded into
            memory.  Now we create their ui component. */
         gnc_reports_show_all(session);

Modified: gnucash/branches/swig-redo/src/scm/main-window.scm
===================================================================
--- gnucash/branches/swig-redo/src/scm/main-window.scm	2006-10-10 00:00:17 UTC (rev 14968)
+++ gnucash/branches/swig-redo/src/scm/main-window.scm	2006-10-10 00:01:54 UTC (rev 14969)
@@ -28,25 +28,6 @@
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 
-(define (gnc:main-window-book-open-handler session)
-  (define (try-load file-suffix)
-    (let ((file (gnc:build-book-path file-suffix)))
-      ;; make sure the books directory is there 
-      (if (access? file F_OK)
-          (if (not (false-if-exception (primitive-load file)))
-              (begin
-                (gnc:warn "failure loading " file)
-                #f))
-          #f)))
-
-  (let* ((book-url (gnc:session-get-url session))
-	 (conf-file-name (gnc-html-encode-string book-url))
-	 (dead-reports '()))
-    (if conf-file-name 
-        (try-load conf-file-name))
-
-    ))
-
 (define (gnc:main-window-properties-cb)
   (let* ((book (gnc-get-current-book))
 	 (slots (gnc:book-get-slots book)))



More information about the gnucash-changes mailing list