r19625 - gnucash/trunk/src/engine - Add wrapper for obtaining a list of business objects as list of owners, and add SWIG wrappers so that scheme can use it.

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


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

Modified:
   gnucash/trunk/src/engine/business-core.i
   gnucash/trunk/src/engine/gncBusiness.c
   gnucash/trunk/src/engine/gncBusiness.h
   gnucash/trunk/src/engine/gncOwner.c
   gnucash/trunk/src/engine/gncOwner.h
Log:
Add wrapper for obtaining a list of business objects as list of owners, and add SWIG wrappers so that scheme can use it.

Modified: gnucash/trunk/src/engine/business-core.i
===================================================================
--- gnucash/trunk/src/engine/business-core.i	2010-10-02 14:59:21 UTC (rev 19624)
+++ gnucash/trunk/src/engine/business-core.i	2010-10-02 14:59:33 UTC (rev 19625)
@@ -78,6 +78,7 @@
 
 GLIST_HELPER_INOUT(EntryList, SWIGTYPE_p__gncEntry);
 GLIST_HELPER_INOUT(GncTaxTableEntryList, SWIGTYPE_p__gncTaxTableEntry);
+GLIST_HELPER_INOUT(OwnerList, SWIGTYPE_p__gncOwner);
 
 %typemap(in) GncAccountValue * "$1 = gnc_scm_to_account_value_ptr($input);"
 %typemap(out) GncAccountValue * "$result = gnc_account_value_ptr_to_scm($1);"
@@ -115,6 +116,7 @@
 /* Parse the header files to generate wrappers */
 %include <gncAddress.h>
 %include <gncBillTerm.h>
+%include <gncBusiness.h>
 %include <gncCustomer.h>
 %include <gncEmployee.h>
 %include <gncEntry.h>

Modified: gnucash/trunk/src/engine/gncBusiness.c
===================================================================
--- gnucash/trunk/src/engine/gncBusiness.c	2010-10-02 14:59:21 UTC (rev 19624)
+++ gnucash/trunk/src/engine/gncBusiness.c	2010-10-02 14:59:33 UTC (rev 19625)
@@ -24,6 +24,7 @@
 #include "config.h"
 
 #include "gncBusiness.h"
+#include "engine/gncOwner.h"
 
 /* The initialization of the business objects is done in
  * cashobjects_register() of <engine/cashobjects.h>. */
@@ -40,6 +41,7 @@
         data->result = g_list_prepend(data->result, inst);
 }
 
+
 GList * gncBusinessGetList (QofBook *book, const char *type_name,
                             gboolean all_including_inactive)
 {
@@ -57,3 +59,32 @@
 
     return data.result;
 }
+
+static void get_ownerlist_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))
+    {
+        GncOwner *owner = gncOwnerCreate();
+        qofOwnerSetEntity(owner, inst);
+        data->result = g_list_prepend(data->result, owner);
+    }
+}
+
+GList * gncBusinessGetOwnerList (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_ownerlist_cb, &data);
+
+    return data.result;
+}

Modified: gnucash/trunk/src/engine/gncBusiness.h
===================================================================
--- gnucash/trunk/src/engine/gncBusiness.h	2010-10-02 14:59:21 UTC (rev 19624)
+++ gnucash/trunk/src/engine/gncBusiness.h	2010-10-02 14:59:33 UTC (rev 19625)
@@ -64,8 +64,21 @@
 
 /** Returns a GList of all objects of the given type_name in the given
  * book. */
-GList * gncBusinessGetList (QofBook *book, const char *type_name,
+GList * gncBusinessGetList (QofBook *book, QofIdTypeConst type_name,
                             gboolean all_including_inactive);
 
+/** For SWIG: A GList containing GncOwner. */
+typedef GList OwnerList;
 
+/** Returns a GList of all objects of the given type_name in the given
+ * book, but each object is wrapped in a GncOwner object.
+ *
+ * The wrapping was done by qofOwnerSetEntity(), hence the owner will
+ * contain data only for {CUSTOMER, JOB, VERNDOR, EMPLOYEE}, otherwise
+ * the owner will be of type GNC_OWNER_NONE and not contain the
+ * original data. */
+OwnerList * gncBusinessGetOwnerList (QofBook *book, QofIdTypeConst type_name,
+                                     gboolean all_including_inactive);
+
+
 #endif /* GNC_BUSINESS_H_ */

Modified: gnucash/trunk/src/engine/gncOwner.c
===================================================================
--- gnucash/trunk/src/engine/gncOwner.c	2010-10-02 14:59:21 UTC (rev 19624)
+++ gnucash/trunk/src/engine/gncOwner.c	2010-10-02 14:59:33 UTC (rev 19625)
@@ -102,13 +102,16 @@
     return owner->type;
 }
 
-QofIdType
+QofIdTypeConst
 qofOwnerGetType(const GncOwner *owner)
 {
-    QofIdType type;
+    return gncOwnerTypeToQofIdType(owner->type);
+}
 
-    type = NULL;
-    switch (owner->type)
+QofIdTypeConst gncOwnerTypeToQofIdType(GncOwnerType t)
+{
+    QofIdTypeConst type = NULL;
+    switch (t)
     {
     case GNC_OWNER_NONE :
     {

Modified: gnucash/trunk/src/engine/gncOwner.h
===================================================================
--- gnucash/trunk/src/engine/gncOwner.h	2010-10-02 14:59:21 UTC (rev 19624)
+++ gnucash/trunk/src/engine/gncOwner.h	2010-10-02 14:59:33 UTC (rev 19625)
@@ -62,12 +62,16 @@
 @{
 */
 /** return the type for the collection. */
-QofIdType qofOwnerGetType(const GncOwner *owner);
+QofIdTypeConst qofOwnerGetType(const GncOwner *owner);
 /** return the owner itself as an entity. */
 QofInstance* qofOwnerGetOwner (const GncOwner *owner);
 /** set the owner from the entity. */
 void qofOwnerSetEntity (GncOwner *owner, QofInstance *ent);
 
+/** Returns the QofIdType of the given GncOwnerType, or NULL if no
+ * suitable one exists. */
+QofIdTypeConst gncOwnerTypeToQofIdType(GncOwnerType t);
+
 gboolean
 gncOwnerRegister(void);
 



More information about the gnucash-changes mailing list