r19624 - gnucash/trunk/src - Add a function gncBusinessGetList() that existed previously until r6680 so that a list of all customers can be obtained.

Christian Stimming cstim at code.gnucash.org
Sat Oct 2 10:59:21 EDT 2010


Author: cstim
Date: 2010-10-02 10:59:21 -0400 (Sat, 02 Oct 2010)
New Revision: 19624
Trac: http://svn.gnucash.org/trac/changeset/19624

Added:
   gnucash/trunk/src/engine/gncBusiness.c
Modified:
   gnucash/trunk/src/business/business-core/test/test-customer.c
   gnucash/trunk/src/business/business-core/test/test-employee.c
   gnucash/trunk/src/business/business-core/test/test-vendor.c
   gnucash/trunk/src/engine/Makefile.am
   gnucash/trunk/src/engine/gncBusiness.h
Log:
Add a function gncBusinessGetList() that existed previously until r6680 so that a list of all customers can be obtained.

Modified: gnucash/trunk/src/business/business-core/test/test-customer.c
===================================================================
--- gnucash/trunk/src/business/business-core/test/test-customer.c	2010-10-02 14:59:05 UTC (rev 19623)
+++ gnucash/trunk/src/business/business-core/test/test-customer.c	2010-10-02 14:59:21 UTC (rev 19624)
@@ -110,7 +110,6 @@
         gncCustomerSetGUID (customer, &guid);
         do_test (guid_equal (&guid, gncCustomerGetGUID (customer)), "guid compare");
     }
-#if 0
     {
         GList *list;
 
@@ -124,7 +123,6 @@
         do_test (g_list_length (list) == 1, "correct length: active");
         g_list_free (list);
     }
-#endif
     {
         const char *str = get_random_string();
         const char *res;

Modified: gnucash/trunk/src/business/business-core/test/test-employee.c
===================================================================
--- gnucash/trunk/src/business/business-core/test/test-employee.c	2010-10-02 14:59:05 UTC (rev 19623)
+++ gnucash/trunk/src/business/business-core/test/test-employee.c	2010-10-02 14:59:21 UTC (rev 19624)
@@ -114,7 +114,6 @@
         gncEmployeeSetGUID (employee, &guid);
         do_test (guid_equal (&guid, qof_instance_get_guid(QOF_INSTANCE(employee))), "guid compare");
     }
-#if 0
     {
         GList *list;
 
@@ -128,7 +127,6 @@
         do_test (g_list_length (list) == 1, "correct length: active");
         g_list_free (list);
     }
-#endif
     {
         const char *str = get_random_string();
         const char *res;

Modified: gnucash/trunk/src/business/business-core/test/test-vendor.c
===================================================================
--- gnucash/trunk/src/business/business-core/test/test-vendor.c	2010-10-02 14:59:05 UTC (rev 19623)
+++ gnucash/trunk/src/business/business-core/test/test-vendor.c	2010-10-02 14:59:21 UTC (rev 19624)
@@ -115,7 +115,6 @@
         gncVendorSetGUID (vendor, &guid);
         do_test (guid_equal (&guid, qof_instance_get_guid(QOF_INSTANCE(vendor))), "guid compare");
     }
-#if 0
     {
         GList *list;
 
@@ -129,7 +128,6 @@
         do_test (g_list_length (list) == 1, "correct length: active");
         g_list_free (list);
     }
-#endif
     {
         const char *str = get_random_string();
         const char *res;

Modified: gnucash/trunk/src/engine/Makefile.am
===================================================================
--- gnucash/trunk/src/engine/Makefile.am	2010-10-02 14:59:05 UTC (rev 19623)
+++ gnucash/trunk/src/engine/Makefile.am	2010-10-02 14:59:21 UTC (rev 19624)
@@ -45,6 +45,7 @@
   policy.c \
   swig-business-core.c \
   gncBusGuile.c \
+  gncBusiness.c \
   gncAddress.c \
   gncBillTerm.c \
   gncCustomer.c \

Added: gnucash/trunk/src/engine/gncBusiness.c
===================================================================
--- gnucash/trunk/src/engine/gncBusiness.c	                        (rev 0)
+++ gnucash/trunk/src/engine/gncBusiness.c	2010-10-02 14:59:21 UTC (rev 19624)
@@ -0,0 +1,59 @@
+/*
+ * gncBusiness.c -- Business helper functions
+ * Copyright (C) 2010 Christian Stimming
+ * Author: Christian Stimming <christian at cstimming.de>
+ *
+ * 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
+ */
+
+#include "config.h"
+
+#include "gncBusiness.h"
+
+/* The initialization of the business objects is done in
+ * cashobjects_register() of <engine/cashobjects.h>. */
+
+struct _get_list_userdata
+{
+        GList *result;
+        QofAccessFunc is_active_accessor_func;
+};
+static void get_list_cb (QofInstance *inst, gpointer user_data)
+{
+    struct _get_list_userdata* data = user_data;
+    if (!data->is_active_accessor_func || data->is_active_accessor_func(inst, NULL))
+        data->result = g_list_prepend(data->result, inst);
+}
+
+GList * gncBusinessGetList (QofBook *book, const char *type_name,
+                            gboolean all_including_inactive)
+{
+    struct _get_list_userdata data;
+    data.result = NULL;
+    data.is_active_accessor_func = NULL;
+
+    if (!all_including_inactive)
+    {
+        data.is_active_accessor_func =
+            qof_class_get_parameter_getter(type_name, QOF_PARAM_ACTIVE);
+    }
+
+    qof_object_foreach(type_name, book, &get_list_cb, &data);
+
+    return data.result;
+}


Property changes on: gnucash/trunk/src/engine/gncBusiness.c
___________________________________________________________________
Added: svn:eol-style
   + LF

Modified: gnucash/trunk/src/engine/gncBusiness.h
===================================================================
--- gnucash/trunk/src/engine/gncBusiness.h	2010-10-02 14:59:05 UTC (rev 19623)
+++ gnucash/trunk/src/engine/gncBusiness.h	2010-10-02 14:59:21 UTC (rev 19624)
@@ -34,6 +34,8 @@
 #ifndef GNC_BUSINESS_H_
 #define GNC_BUSINESS_H_
 
+#include <glib.h>
+#include "qof.h"
 
 /* @deprecated backwards-compat definitions */
 #define GNC_BILLTERM_MODULE_NAME GNC_ID_BILLTERM
@@ -60,4 +62,10 @@
 # endif
 #endif
 
+/** Returns a GList of all objects of the given type_name in the given
+ * book. */
+GList * gncBusinessGetList (QofBook *book, const char *type_name,
+                            gboolean all_including_inactive);
+
+
 #endif /* GNC_BUSINESS_H_ */



More information about the gnucash-changes mailing list