diff --git a/src/business/business-core/test/test-customer.c b/src/business/business-core/test/test-customer.c index ea921e256b..63b73b9bbf 100644 --- a/src/business/business-core/test/test-customer.c +++ b/src/business/business-core/test/test-customer.c @@ -110,7 +110,6 @@ test_customer (void) gncCustomerSetGUID (customer, &guid); do_test (guid_equal (&guid, gncCustomerGetGUID (customer)), "guid compare"); } -#if 0 { GList *list; @@ -124,7 +123,6 @@ test_customer (void) do_test (g_list_length (list) == 1, "correct length: active"); g_list_free (list); } -#endif { const char *str = get_random_string(); const char *res; diff --git a/src/business/business-core/test/test-employee.c b/src/business/business-core/test/test-employee.c index 9be9d50e46..8141b6286a 100644 --- a/src/business/business-core/test/test-employee.c +++ b/src/business/business-core/test/test-employee.c @@ -114,7 +114,6 @@ test_employee (void) 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 @@ test_employee (void) do_test (g_list_length (list) == 1, "correct length: active"); g_list_free (list); } -#endif { const char *str = get_random_string(); const char *res; diff --git a/src/business/business-core/test/test-vendor.c b/src/business/business-core/test/test-vendor.c index 2b0442cce5..8c40f0a29c 100644 --- a/src/business/business-core/test/test-vendor.c +++ b/src/business/business-core/test/test-vendor.c @@ -115,7 +115,6 @@ test_vendor (void) 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 @@ test_vendor (void) do_test (g_list_length (list) == 1, "correct length: active"); g_list_free (list); } -#endif { const char *str = get_random_string(); const char *res; diff --git a/src/engine/Makefile.am b/src/engine/Makefile.am index ff06879885..2819d8836c 100644 --- a/src/engine/Makefile.am +++ b/src/engine/Makefile.am @@ -45,6 +45,7 @@ libgncmod_engine_la_SOURCES = \ policy.c \ swig-business-core.c \ gncBusGuile.c \ + gncBusiness.c \ gncAddress.c \ gncBillTerm.c \ gncCustomer.c \ diff --git a/src/engine/gncBusiness.c b/src/engine/gncBusiness.c new file mode 100644 index 0000000000..deda3d0c4a --- /dev/null +++ b/src/engine/gncBusiness.c @@ -0,0 +1,59 @@ +/* + * gncBusiness.c -- Business helper functions + * Copyright (C) 2010 Christian Stimming + * Author: Christian Stimming + * + * 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@gnu.org + */ + +#include "config.h" + +#include "gncBusiness.h" + +/* The initialization of the business objects is done in + * cashobjects_register() of . */ + +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; +} diff --git a/src/engine/gncBusiness.h b/src/engine/gncBusiness.h index 84e460973c..25b65a22d9 100644 --- a/src/engine/gncBusiness.h +++ b/src/engine/gncBusiness.h @@ -34,6 +34,8 @@ #ifndef GNC_BUSINESS_H_ #define GNC_BUSINESS_H_ +#include +#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_ */