GnuCash  5.6-150-g038405b370+
search-core-type.c
1 /*
2  * Copyright (C) 2002 Derek Atkins
3  *
4  * Authors: Derek Atkins <warlord@MIT.EDU>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public
17  * License along with this program; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25 
26 #include <string.h>
27 #include <gtk/gtk.h>
28 
29 #include "qof.h"
30 #include "Account.h" /* for ACCOUNT_MATCH_ALL_TYPE */
31 #include "Transaction.h" /* for RECONCILED_MATCH_TYPE */
32 
33 #include "search-core-type.h"
34 #include "search-string.h"
35 #include "search-reconciled.h"
36 #include "search-date.h"
37 #include "search-double.h"
38 #include "search-int64.h"
39 #include "search-numeric.h"
40 #include "search-boolean.h"
41 #include "search-account.h"
42 
43 static void grab_focus (GNCSearchCoreType *fe);
44 static void editable_enters (GNCSearchCoreType *fe);
45 static gboolean validate (GNCSearchCoreType *fe);
46 
47 static void gnc_search_core_type_finalize (GObject *obj);
48 
49 typedef struct _GNCSearchCoreTypePrivate GNCSearchCoreTypePrivate;
50 
52 {
53  gpointer dummy;
54 };
55 
56 G_DEFINE_TYPE_WITH_PRIVATE(GNCSearchCoreType, gnc_search_core_type, G_TYPE_OBJECT)
57 
58 #define _PRIVATE(o) \
59  ((GNCSearchCoreTypePrivate*)gnc_search_core_type_get_instance_private((GNCSearchCoreType*)o))
60 
61 static GHashTable *typeTable = NULL;
62 
63 static void
64 gnc_search_core_type_class_init (GNCSearchCoreTypeClass *klass)
65 {
66  GObjectClass *object_class;
67 
68  object_class = G_OBJECT_CLASS (klass);
69 
70  object_class->finalize = gnc_search_core_type_finalize;
71 
72  /* override methods */
73  klass->validate = validate;
74  klass->grab_focus = grab_focus;
75  klass->editable_enters = editable_enters;
76 }
77 
78 static void
79 gnc_search_core_type_init (GNCSearchCoreType *o)
80 {
81 }
82 
83 static void
84 gnc_search_core_type_finalize (GObject *obj)
85 {
86  GNCSearchCoreType *o = (GNCSearchCoreType *)obj;
87  g_assert (GNC_IS_SEARCH_CORE_TYPE (o));
88 
89  G_OBJECT_CLASS (gnc_search_core_type_parent_class)->finalize(obj);
90 }
91 
99 GNCSearchCoreType *
100 gnc_search_core_type_new (void)
101 {
102  GNCSearchCoreType *o;
103 
104  o = g_object_new (GNC_TYPE_SEARCH_CORE_TYPE, NULL);
105 
106  return o;
107 }
108 
109 void
110 gnc_search_core_type_editable_enters (GNCSearchCoreType *fe)
111 {
112  GNC_SEARCH_CORE_TYPE_GET_CLASS (fe)->editable_enters (fe);
113 }
114 
115 void
116 gnc_search_core_type_grab_focus (GNCSearchCoreType *fe)
117 {
118  GNC_SEARCH_CORE_TYPE_GET_CLASS (fe)->grab_focus (fe);
119 }
120 
121 void
122 gnc_search_core_type_pass_parent (GNCSearchCoreType *fe, gpointer parent)
123 {
124  GNC_SEARCH_CORE_TYPE_GET_CLASS (fe)->pass_parent (fe, parent);
125 }
126 
127 gboolean
128 gnc_search_core_type_validate (GNCSearchCoreType *fe)
129 {
130  return GNC_SEARCH_CORE_TYPE_GET_CLASS (fe)->validate (fe);
131 }
132 
141 GNCSearchCoreType *
142 gnc_search_core_type_clone (GNCSearchCoreType *fe)
143 {
144  return GNC_SEARCH_CORE_TYPE_GET_CLASS (fe)->clone(fe);
145 }
146 
156 GtkWidget *
157 gnc_search_core_type_get_widget (GNCSearchCoreType *fe)
158 {
159  return GNC_SEARCH_CORE_TYPE_GET_CLASS (fe)->get_widget(fe);
160 }
161 
170 QofQueryPredData*
171 gnc_search_core_type_get_predicate (GNCSearchCoreType *fe)
172 {
173  return GNC_SEARCH_CORE_TYPE_GET_CLASS (fe)->get_predicate(fe);
174 }
175 
184 GNCSearchCoreType *
185 gnc_search_core_type_new_type_name (const char *type)
186 {
187  GNCSearchCoreNew fcn;
188 
189  g_return_val_if_fail (typeTable != NULL, NULL);
190 
191  if (type == NULL)
192  return NULL;
193 
194  fcn = g_hash_table_lookup (typeTable, type);
195  if (fcn)
196  {
197  return ((fcn)());
198  }
199  else
200  {
201  g_warning("Unknown search type '%s'", type);
202  return NULL;
203  }
204 }
205 
206 /* default implementations */
207 static gboolean
208 validate (GNCSearchCoreType *fe)
209 {
210  return TRUE;
211 }
212 
213 static void
214 grab_focus (GNCSearchCoreType *fe)
215 {
216  return;
217 }
218 
219 static void
220 editable_enters (GNCSearchCoreType *fe)
221 {
222  return;
223 }
224 
225 void
226 gnc_search_core_register_type (const char *type_name, GNCSearchCoreNew fcn)
227 {
228  g_return_if_fail (type_name);
229  g_return_if_fail (*type_name);
230  g_return_if_fail (fcn);
231  g_return_if_fail (typeTable);
232 
233  g_hash_table_insert (typeTable, (char *) type_name, (gpointer) fcn);
234 }
235 
236 static void
237 init_table (void)
238 {
239  gnc_search_core_register_type (QOF_TYPE_STRING,
240  (GNCSearchCoreNew) gnc_search_string_new);
241  gnc_search_core_register_type (QOF_TYPE_DATE,
242  (GNCSearchCoreNew) gnc_search_date_new);
243  gnc_search_core_register_type (QOF_TYPE_INT64,
244  (GNCSearchCoreNew) gnc_search_int64_new);
245  gnc_search_core_register_type (QOF_TYPE_DOUBLE,
246  (GNCSearchCoreNew) gnc_search_double_new);
247  gnc_search_core_register_type (QOF_TYPE_NUMERIC,
248  (GNCSearchCoreNew) gnc_search_numeric_new);
249  gnc_search_core_register_type (QOF_TYPE_DEBCRED,
250  (GNCSearchCoreNew)
251  gnc_search_numeric_debcred_new);
252  gnc_search_core_register_type (QOF_TYPE_BOOLEAN,
253  (GNCSearchCoreNew) gnc_search_boolean_new);
254  gnc_search_core_register_type (GNC_ID_ACCOUNT,
255  (GNCSearchCoreNew) gnc_search_account_new);
256  gnc_search_core_register_type (ACCOUNT_MATCH_ALL_TYPE,
257  (GNCSearchCoreNew)
258  gnc_search_account_matchall_new);
259  gnc_search_core_register_type (RECONCILED_MATCH_TYPE,
260  (GNCSearchCoreNew) gnc_search_reconciled_new);
261 }
262 
263 void
264 gnc_search_core_initialize (void)
265 {
266  g_return_if_fail (typeTable == NULL);
267 
268  typeTable = g_hash_table_new (g_str_hash, g_str_equal);
269  init_table ();
270 }
271 
272 void
273 gnc_search_core_finalize (void)
274 {
275  g_return_if_fail (typeTable != NULL);
276 
277  g_hash_table_destroy (typeTable);
278  typeTable = NULL;
279 }
Account handling public routines.
#define ACCOUNT_MATCH_ALL_TYPE
This is the type-override when you want to match all accounts.
Definition: Account.h:1723
API for Transactions and Splits (journal entries)