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
00035 qof_choice_is_initialized (void)
00036 {
00037 if (!qof_choice_table)
00038 qof_choice_table = g_hash_table_new (g_str_hash, g_str_equal);
00039 if (!qof_choice_table)
00040 return FALSE;
00041 return TRUE;
00042 }
00043
00044 gboolean
00045 qof_object_is_choice (QofIdType type)
00046 {
00047 gpointer value, check;
00048
00049 value = NULL;
00050 check = NULL;
00051 if (!qof_choice_is_initialized ())
00052 return FALSE;
00053 g_return_val_if_fail (type != NULL, FALSE);
00054 value = g_hash_table_lookup (qof_choice_table, type);
00055 if ((GHashTable *) value)
00056 return TRUE;
00057 return FALSE;
00058 }
00059
00060 gboolean
00061 qof_choice_create (gchar *type)
00062 {
00063 GHashTable *param_table;
00064
00065 g_return_val_if_fail (type != NULL, FALSE);
00066 g_return_val_if_fail (qof_choice_is_initialized () == TRUE, FALSE);
00067 ENTER (" ");
00068 param_table = g_hash_table_new (g_str_hash, g_str_equal);
00069 g_hash_table_insert (qof_choice_table, type, param_table);
00070 LEAVE (" ");
00071 return TRUE;
00072 }
00073
00074 gboolean
00075 qof_choice_add_class (gchar *select, gchar *option, gchar *param_name)
00076 {
00077 GHashTable *param_table;
00078 GList *option_list;
00079
00080 option_list = NULL;
00081 param_table = NULL;
00082 g_return_val_if_fail (select != NULL, FALSE);
00083 g_return_val_if_fail (qof_object_is_choice (select), FALSE);
00084 param_table =
00085 (GHashTable *) g_hash_table_lookup (qof_choice_table, select);
00086 g_return_val_if_fail (param_table, FALSE);
00087 option_list = (GList *) g_hash_table_lookup (param_table, param_name);
00088 option_list = g_list_append (option_list, option);
00089 g_hash_table_insert (param_table, param_name, option_list);
00090 return TRUE;
00091 }
00092
00093 GList *
00094 qof_object_get_choices (QofIdType type, QofParam * param)
00095 {
00096 GList *choices;
00097 GHashTable *param_table;
00098
00099 g_return_val_if_fail (type != NULL, NULL);
00100 g_return_val_if_fail (qof_choice_is_initialized () == TRUE, FALSE);
00101 choices = NULL;
00102 param_table = g_hash_table_lookup (qof_choice_table, type);
00103 choices = g_hash_table_lookup (param_table, param->param_name);
00104 return choices;
00105 }
00106
00107 gboolean
00108 qof_choice_check (gchar *choice_obj, gchar *param_name, gchar *choice)
00109 {
00110 GList *choices, *result;
00111 GHashTable *param_table;
00112
00113 choices = result = NULL;
00114 g_return_val_if_fail (qof_object_is_choice (choice_obj), FALSE);
00115 param_table = g_hash_table_lookup (qof_choice_table, choice_obj);
00116 choices = g_hash_table_lookup (param_table, param_name);
00117 result = g_list_find (choices, choice);
00118 if (!result)
00119 return FALSE;
00120 return TRUE;
00121 }