From 1f2994b1d39971634a6ff340449d9f0bd22e9bae Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Sat, 2 Oct 2010 14:59:33 +0000 Subject: [PATCH] Add wrapper for obtaining a list of business objects as list of owners, and add SWIG wrappers so that scheme can use it. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@19625 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/business-core.i | 2 ++ src/engine/gncBusiness.c | 31 +++++++++++++++++++++++++++++++ src/engine/gncBusiness.h | 15 ++++++++++++++- src/engine/gncOwner.c | 11 +++++++---- src/engine/gncOwner.h | 6 +++++- 5 files changed, 59 insertions(+), 6 deletions(-) diff --git a/src/engine/business-core.i b/src/engine/business-core.i index c487dc199b..a2c625b226 100644 --- a/src/engine/business-core.i +++ b/src/engine/business-core.i @@ -78,6 +78,7 @@ static GncEmployee * gncEmployeeLookupFlip(GncGUID g, QofBook *b) 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 @@ GLIST_HELPER_INOUT(GncTaxTableEntryList, SWIGTYPE_p__gncTaxTableEntry); /* Parse the header files to generate wrappers */ %include %include +%include %include %include %include diff --git a/src/engine/gncBusiness.c b/src/engine/gncBusiness.c index deda3d0c4a..7d81e56d62 100644 --- a/src/engine/gncBusiness.c +++ b/src/engine/gncBusiness.c @@ -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 . */ @@ -40,6 +41,7 @@ static void get_list_cb (QofInstance *inst, gpointer user_data) data->result = g_list_prepend(data->result, inst); } + GList * gncBusinessGetList (QofBook *book, const char *type_name, gboolean all_including_inactive) { @@ -57,3 +59,32 @@ GList * gncBusinessGetList (QofBook *book, const char *type_name, 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; +} diff --git a/src/engine/gncBusiness.h b/src/engine/gncBusiness.h index 25b65a22d9..b9a960f406 100644 --- a/src/engine/gncBusiness.h +++ b/src/engine/gncBusiness.h @@ -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_ */ diff --git a/src/engine/gncOwner.c b/src/engine/gncOwner.c index 93ba5e7571..96fa29a9e7 100644 --- a/src/engine/gncOwner.c +++ b/src/engine/gncOwner.c @@ -102,13 +102,16 @@ GncOwnerType gncOwnerGetType (const GncOwner *owner) 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 : { diff --git a/src/engine/gncOwner.h b/src/engine/gncOwner.h index 312517d099..eb5f1da7d9 100644 --- a/src/engine/gncOwner.h +++ b/src/engine/gncOwner.h @@ -62,12 +62,16 @@ to QOF as they can be used by objects like GncInvoice. @{ */ /** 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);