r18464 - gnucash/trunk/src - Bug #537476: Fix currency trading account preference lookup

Christian Stimming cstim at code.gnucash.org
Fri Dec 4 15:26:48 EST 2009


Author: cstim
Date: 2009-12-04 15:26:48 -0500 (Fri, 04 Dec 2009)
New Revision: 18464
Trac: http://svn.gnucash.org/trac/changeset/18464

Added:
   gnucash/trunk/src/libqof/qof/qofbookslots.h
Modified:
   gnucash/trunk/src/app-utils/app-utils.scm
   gnucash/trunk/src/business/business-utils/business-utils.scm
   gnucash/trunk/src/engine/engine.i
   gnucash/trunk/src/libqof/qof/Makefile.am
   gnucash/trunk/src/libqof/qof/qofbook.c
Log:
Bug #537476: Fix currency trading account preference lookup

Patch by Mike Alexander:

There are a few values related to the trading accounts preference that are
needed in both Scheme and C code.  Since one of them was already defined in
Scheme before I started, I defined all of them there and tried to import them
to C.  This is obviously not a good idea, especially since the make check tests
don't even fire up Guile so Scheme code isn't available.  This patch changes
things around to define the values in C and import them to Scheme.

Modified: gnucash/trunk/src/app-utils/app-utils.scm
===================================================================
--- gnucash/trunk/src/app-utils/app-utils.scm	2009-12-04 15:45:47 UTC (rev 18463)
+++ gnucash/trunk/src/app-utils/app-utils.scm	2009-12-04 20:26:48 UTC (rev 18464)
@@ -257,7 +257,7 @@
 (export simple-obj-from-list)
 (export make-simple-obj)
 
-(define gnc:*kvp-option-path* '("options"))
+(define gnc:*kvp-option-path* (list BOOK-OPTIONS-NAME))
 (export gnc:*kvp-option-path*)
 
 (load-from-path "c-interface.scm")

Modified: gnucash/trunk/src/business/business-utils/business-utils.scm
===================================================================
--- gnucash/trunk/src/business/business-utils/business-utils.scm	2009-12-04 15:45:47 UTC (rev 18463)
+++ gnucash/trunk/src/business/business-utils/business-utils.scm	2009-12-04 20:26:48 UTC (rev 18464)
@@ -18,8 +18,8 @@
             gnc:*company-phone* gnc:*company-fax* gnc:*company-url*
             gnc:*company-email* gnc:*company-contact*)
 
-(define gnc:*book-label* (N_ "Accounts"))
-(define gnc:*trading-accounts* (N_ "Trading Accounts"))
+(define gnc:*book-label* ACCOUNT-OPTIONS-SECTION)
+(define gnc:*trading-accounts* TRADING-ACCOUNTS-OPTION)
 
 (export gnc:*book-label* gnc:*trading-accounts*)
 

Modified: gnucash/trunk/src/engine/engine.i
===================================================================
--- gnucash/trunk/src/engine/engine.i	2009-12-04 15:45:47 UTC (rev 18463)
+++ gnucash/trunk/src/engine/engine.i	2009-12-04 20:26:48 UTC (rev 18464)
@@ -114,6 +114,7 @@
 %ignore qof_query_run;
 %include <qofquery.h>
 %include <qofquerycore.h>
+%include <qofbookslots.h>
 
 gnc_numeric gnc_numeric_create(gint64 num, gint64 denom);
 gnc_numeric gnc_numeric_zero(void);
@@ -297,6 +298,10 @@
     SET_ENUM("TRANS-DATE-POSTED");
     SET_ENUM("TRANS-DESCRIPTION");
     SET_ENUM("TRANS-NUM");
+    
+    SET_ENUM("BOOK-OPTIONS-NAME");
+    SET_ENUM("ACCOUNT-OPTIONS-SECTION");
+    SET_ENUM("TRADING-ACCOUNTS-OPTION");
 
     SET_ENUM("ACCOUNT-CODE-");  /* sic */
 

Modified: gnucash/trunk/src/libqof/qof/Makefile.am
===================================================================
--- gnucash/trunk/src/libqof/qof/Makefile.am	2009-12-04 15:45:47 UTC (rev 18463)
+++ gnucash/trunk/src/libqof/qof/Makefile.am	2009-12-04 20:26:48 UTC (rev 18464)
@@ -2,14 +2,12 @@
 
 libgnc_qof_la_LDFLAGS= -version-info $(LIBQOF_LIBRARY_VERSION)
 libgnc_qof_la_LIBADD= \
-  $(GUILE_LIBS) \
   $(GLIB_LIBS) \
   $(REGEX_LIBS) \
   $(top_builddir)/lib/libc/libc-missing.la
 
 AM_CPPFLAGS = \
   -I$(top_srcdir)/lib/libc \
-  $(GUILE_INCS) \
   $(GLIB_CFLAGS)
 
 libgnc_qof_la_SOURCES =  \
@@ -58,6 +56,7 @@
    qofinstance.h     \
    qofquery.h        \
    qofbook.h         \
+   qofbookslots.h    \
    qoflog.h          \
    qofobject.h       \
    qofquerycore.h    \

Modified: gnucash/trunk/src/libqof/qof/qofbook.c
===================================================================
--- gnucash/trunk/src/libqof/qof/qofbook.c	2009-12-04 15:45:47 UTC (rev 18463)
+++ gnucash/trunk/src/libqof/qof/qofbook.c	2009-12-04 20:26:48 UTC (rev 18464)
@@ -39,7 +39,6 @@
 #include <string.h>
 
 #include <glib.h>
-#include <libguile.h>
 
 #include "qof.h"
 #include "qofevent-p.h"
@@ -47,6 +46,7 @@
 #include "qofbook-p.h"
 #include "qofid-p.h"
 #include "qofobject-p.h"
+#include "qofbookslots.h"
 
 static QofLogModule log_module = QOF_MOD_ENGINE;
 
@@ -440,39 +440,17 @@
     return counter;
 }
 
-static char *get_scm_string(const char *str_name)
-{
-    SCM scm_string = scm_c_eval_string (str_name);
-    if (! SCM_STRINGP(scm_string))
-        return NULL;
-        
-    return g_strdup(SCM_STRING_CHARS(scm_string));
-}
-
 /* Determine whether this book uses trading accounts */
 gboolean qof_book_use_trading_accounts (const QofBook *book)
 {
-#if 0
-    static char *options_name = NULL;
-    static char *acct_section = NULL;
-    static char *trading_opt = NULL;
-    
     const char *opt;
     kvp_value *kvp_val;
     
-    if (options_name == NULL)
-    {
-        options_name = get_scm_string ("(car gnc:*kvp-option-path*)");
-        //acct_section = get_scm_string ("gnc:*book-label*");
-        //trading_opt = get_scm_string ("gnc:*trading-accounts*");
-        if (options_name == NULL || acct_section == NULL || trading_opt == NULL)
-        {
-            PWARN ("Unable to find trading account preference");
-        }
-    }
     
-    kvp_val = kvp_frame_get_slot_path (qof_book_get_slots (book), options_name, acct_section,
-                                       trading_opt, NULL);
+    kvp_val = kvp_frame_get_slot_path (qof_book_get_slots (book), 
+                                       BOOK_OPTIONS_NAME, 
+                                       ACCOUNT_OPTIONS_SECTION,
+                                       TRADING_ACCOUNTS_OPTION, NULL);
     if (kvp_val == NULL)
         return FALSE;
     
@@ -480,7 +458,6 @@
     
     if (opt && opt[0] == 't' && opt[1] == 0)
         return TRUE;
-#endif
     return FALSE;
 }
 

Added: gnucash/trunk/src/libqof/qof/qofbookslots.h
===================================================================
--- gnucash/trunk/src/libqof/qof/qofbookslots.h	                        (rev 0)
+++ gnucash/trunk/src/libqof/qof/qofbookslots.h	2009-12-04 20:26:48 UTC (rev 18464)
@@ -0,0 +1,33 @@
+/********************************************************************\
+ * qofbookslots.h -- Defines the names of slots used in the book.   *
+ * This program is free software; you can redistribute it and/or    *
+ * modify it under the terms of the GNU General Public License as   *
+ * published by the Free Software Foundation; either version 2 of   *
+ * the License, or (at your option) any later version.              *
+ *                                                                  *
+ * This program is distributed in the hope that it will be useful,  *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
+ * GNU General Public License for more details.                     *
+ *                                                                  *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/** @name Book parameter names
+
+ * These define the names used for the slots used to store book level parameters.
+ * They are defined here so swig will find them since they need to be available to 
+ * Scheme code too.
+ @{
+*/
+#define BOOK_OPTIONS_NAME       "options"
+#define ACCOUNT_OPTIONS_SECTION "Accounts"
+#define TRADING_ACCOUNTS_OPTION "Trading Accounts"
+
+/** @} */



More information about the gnucash-changes mailing list