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
This commit is contained in:
Christian Stimming 2010-10-02 14:59:33 +00:00
parent 382d6733d7
commit 1f2994b1d3
5 changed files with 59 additions and 6 deletions

View File

@ -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 <gncAddress.h>
%include <gncBillTerm.h>
%include <gncBusiness.h>
%include <gncCustomer.h>
%include <gncEmployee.h>
%include <gncEntry.h>

View File

@ -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 @@ 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;
}

View File

@ -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_ */

View File

@ -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 :
{

View File

@ -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);