|
GnuCash 2.4.99
|
00001 /* 00002 * gncBusiness.c -- Business helper functions 00003 * Copyright (C) 2010 Christian Stimming 00004 * Author: Christian Stimming <christian@cstimming.de> 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License as 00008 * published by the Free Software Foundation; either version 2 of 00009 * the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, contact: 00018 * 00019 * Free Software Foundation Voice: +1-617-542-5942 00020 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 00021 * Boston, MA 02110-1301, USA gnu@gnu.org 00022 */ 00023 00024 #include "config.h" 00025 00026 #include "gncBusiness.h" 00027 #include "engine/gncOwner.h" 00028 00029 /* The initialization of the business objects is done in 00030 * cashobjects_register() of <engine/cashobjects.h>. */ 00031 00032 struct _get_list_userdata 00033 { 00034 GList *result; 00035 QofAccessFunc is_active_accessor_func; 00036 }; 00037 static void get_list_cb (QofInstance *inst, gpointer user_data) 00038 { 00039 struct _get_list_userdata* data = user_data; 00040 if (!data->is_active_accessor_func || data->is_active_accessor_func(inst, NULL)) 00041 data->result = g_list_prepend(data->result, inst); 00042 } 00043 00044 00045 GList * gncBusinessGetList (QofBook *book, const char *type_name, 00046 gboolean all_including_inactive) 00047 { 00048 struct _get_list_userdata data; 00049 data.result = NULL; 00050 data.is_active_accessor_func = NULL; 00051 00052 if (!all_including_inactive) 00053 { 00054 data.is_active_accessor_func = 00055 qof_class_get_parameter_getter(type_name, QOF_PARAM_ACTIVE); 00056 } 00057 00058 qof_object_foreach(type_name, book, &get_list_cb, &data); 00059 00060 return data.result; 00061 } 00062 00063 static void get_ownerlist_cb (QofInstance *inst, gpointer user_data) 00064 { 00065 struct _get_list_userdata* data = user_data; 00066 if (!data->is_active_accessor_func || data->is_active_accessor_func(inst, NULL)) 00067 { 00068 GncOwner *owner = gncOwnerNew(); 00069 qofOwnerSetEntity(owner, inst); 00070 data->result = g_list_prepend(data->result, owner); 00071 } 00072 } 00073 00074 GList * gncBusinessGetOwnerList (QofBook *book, const char *type_name, 00075 gboolean all_including_inactive) 00076 { 00077 struct _get_list_userdata data; 00078 data.result = NULL; 00079 data.is_active_accessor_func = NULL; 00080 00081 if (!all_including_inactive) 00082 { 00083 data.is_active_accessor_func = 00084 qof_class_get_parameter_getter(type_name, QOF_PARAM_ACTIVE); 00085 } 00086 00087 qof_object_foreach(type_name, book, &get_ownerlist_cb, &data); 00088 00089 return data.result; 00090 }
1.7.4