00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "config.h"
00025 #include <glib.h>
00026 #include "qof.h"
00027 #include "qofchoice.h"
00028
00029 static QofLogModule log_module = QOF_MOD_CHOICE;
00030 static GHashTable *qof_choice_table = NULL;
00031
00032
00033
00034 static gboolean qof_choice_is_initialized(void)
00035 {
00036 if(!qof_choice_table)
00037 {
00038 qof_choice_table = g_hash_table_new(g_str_hash, g_str_equal);
00039 }
00040 if(!qof_choice_table) { return FALSE; }
00041 return TRUE;
00042 }
00043
00044 gboolean qof_object_is_choice(QofIdTypeConst type)
00045 {
00046 gpointer value, check;
00047
00048 value = NULL;
00049 check = NULL;
00050 if(!qof_choice_is_initialized()) { return FALSE; }
00051 g_return_val_if_fail(type != NULL, FALSE);
00052 value = g_hash_table_lookup(qof_choice_table, type);
00053 if((GHashTable*)value) { return TRUE; }
00054 DEBUG (" QOF_TYPE_CHOICE setup failed for %s\n", type);
00055 return FALSE;
00056 }
00057
00058 gboolean
00059 qof_choice_create(char* type)
00060 {
00061 GHashTable *param_table;
00062
00063 g_return_val_if_fail(type != NULL, FALSE);
00064 g_return_val_if_fail(qof_choice_is_initialized() == TRUE, FALSE);
00065 param_table = g_hash_table_new(g_str_hash, g_str_equal);
00066 g_hash_table_insert(qof_choice_table, type, param_table);
00067 return TRUE;
00068 }
00069
00070 gboolean qof_choice_add_class(const char* select,
00071 char* option,
00072 char* param_name)
00073 {
00074 GHashTable *param_table;
00075 GList *option_list;
00076
00077 option_list = NULL;
00078 param_table = NULL;
00079 g_return_val_if_fail(select != NULL, FALSE);
00080 g_return_val_if_fail(qof_object_is_choice(select), FALSE);
00081 param_table = (GHashTable*)g_hash_table_lookup(qof_choice_table, select);
00082 g_return_val_if_fail(param_table, FALSE);
00083 option_list = (GList*)g_hash_table_lookup(param_table, param_name);
00084 option_list = g_list_append(option_list, option);
00085 g_hash_table_insert(param_table, param_name, option_list);
00086 return TRUE;
00087 }
00088
00089 GList* qof_object_get_choices(QofIdType type, QofParam *param)
00090 {
00091 GList *choices;
00092 GHashTable *param_table;
00093
00094 g_return_val_if_fail(type != NULL, NULL);
00095 g_return_val_if_fail(qof_choice_is_initialized() == TRUE, FALSE);
00096 choices = NULL;
00097 param_table = g_hash_table_lookup(qof_choice_table, type);
00098 choices = g_hash_table_lookup(param_table, param->param_name);
00099 return choices;
00100 }
00101
00102 gboolean qof_choice_check(const char* choice_obj,
00103 const char *param_name,
00104 const char* choice )
00105 {
00106 GList *choices, *result;
00107 GHashTable *param_table;
00108
00109 choices = result = NULL;
00110 g_return_val_if_fail(qof_object_is_choice(choice_obj), FALSE);
00111 param_table = g_hash_table_lookup(qof_choice_table, choice_obj);
00112 choices = g_hash_table_lookup(param_table, param_name);
00113 result = g_list_find(choices, choice);
00114 if(!result) { return FALSE; }
00115 return TRUE;
00116 }