GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
search-core-type.c
1 /*
2  * Copyright (C) 2002 Derek Atkins
3  *
4  * Authors: Derek Atkins <[email protected]>
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_class_init (GNCSearchCoreTypeClass *klass);
48 static void gnc_search_core_type_init (GNCSearchCoreType *gspaper);
49 static void gnc_search_core_type_finalize (GObject *obj);
50 
52 
54 {
55  gpointer dummy;
56 };
57 
58 #define _PRIVATE(o) \
59  (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_SEARCH_CORE_TYPE, GNCSearchCoreTypePrivate))
60 
61 static GtkObjectClass *parent_class;
62 
63 static GHashTable *typeTable = NULL;
64 
65 GType
66 gnc_search_core_type_get_type (void)
67 {
68  static GType type = 0;
69 
70  if (type == 0)
71  {
72  GTypeInfo type_info =
73  {
74  sizeof (GNCSearchCoreTypeClass),
75  NULL,
76  NULL,
77  (GClassInitFunc)gnc_search_core_type_class_init,
78  NULL,
79  NULL,
80  sizeof (GNCSearchCoreType),
81  0,
82  (GInstanceInitFunc)gnc_search_core_type_init
83  };
84 
85  type = g_type_register_static (G_TYPE_OBJECT, "GNCSearchCoreType", &type_info, 0);
86  }
87 
88  return type;
89 }
90 
91 static void
92 gnc_search_core_type_class_init (GNCSearchCoreTypeClass *klass)
93 {
94  GObjectClass *object_class;
95 
96  object_class = G_OBJECT_CLASS (klass);
97  parent_class = g_type_class_peek_parent (klass);
98 
99  object_class->finalize = gnc_search_core_type_finalize;
100 
101  /* override methods */
102  klass->validate = validate;
103  klass->grab_focus = grab_focus;
104  klass->editable_enters = editable_enters;
105 
106  g_type_class_add_private(klass, sizeof(GNCSearchCoreTypePrivate));
107 }
108 
109 static void
110 gnc_search_core_type_init (GNCSearchCoreType *o)
111 {
112 }
113 
114 static void
115 gnc_search_core_type_finalize (GObject *obj)
116 {
118  g_assert (GNC_IS_SEARCH_CORE_TYPE (o));
119 
120  G_OBJECT_CLASS (parent_class)->finalize(obj);
121 }
122 
131 gnc_search_core_type_new (void)
132 {
134 
135  o = g_object_new (GNC_TYPE_SEARCH_CORE_TYPE, NULL);
136 
137  return o;
138 }
139 
140 void
141 gnc_search_core_type_editable_enters (GNCSearchCoreType *fe)
142 {
143  GNC_SEARCH_CORE_TYPE_GET_CLASS (fe)->editable_enters (fe);
144 }
145 
146 void
147 gnc_search_core_type_grab_focus (GNCSearchCoreType *fe)
148 {
149  GNC_SEARCH_CORE_TYPE_GET_CLASS (fe)->grab_focus (fe);
150 }
151 
152 gboolean
153 gnc_search_core_type_validate (GNCSearchCoreType *fe)
154 {
155  return GNC_SEARCH_CORE_TYPE_GET_CLASS (fe)->validate (fe);
156 }
157 
167 gnc_search_core_type_clone (GNCSearchCoreType *fe)
168 {
169  return GNC_SEARCH_CORE_TYPE_GET_CLASS (fe)->clone(fe);
170 }
171 
181 GtkWidget *
182 gnc_search_core_type_get_widget (GNCSearchCoreType *fe)
183 {
184  return GNC_SEARCH_CORE_TYPE_GET_CLASS (fe)->get_widget(fe);
185 }
186 
196 gnc_search_core_type_get_predicate (GNCSearchCoreType *fe)
197 {
198  return GNC_SEARCH_CORE_TYPE_GET_CLASS (fe)->get_predicate(fe);
199 }
200 
210 gnc_search_core_type_new_type_name (const char *type)
211 {
212  GNCSearchCoreNew fcn;
213 
214  g_return_val_if_fail (typeTable != NULL, NULL);
215 
216  if (type == NULL)
217  return NULL;
218 
219  fcn = g_hash_table_lookup (typeTable, type);
220  if (fcn)
221  {
222  return ((fcn)());
223  }
224  else
225  {
226  g_warning("Unknown search type '%s'", type);
227  return NULL;
228  }
229 }
230 
231 /* default implementations */
232 static gboolean
233 validate (GNCSearchCoreType *fe)
234 {
235  return TRUE;
236 }
237 
238 static void
239 grab_focus (GNCSearchCoreType *fe)
240 {
241  return;
242 }
243 
244 static void
245 editable_enters (GNCSearchCoreType *fe)
246 {
247  return;
248 }
249 
250 void
251 gnc_search_core_register_type (const char *type_name, GNCSearchCoreNew fcn)
252 {
253  g_return_if_fail (type_name || *type_name || fcn);
254  g_return_if_fail (typeTable);
255 
256  g_hash_table_insert (typeTable, (char *) type_name, (gpointer) fcn);
257 }
258 
259 static void
260 init_table (void)
261 {
262  gnc_search_core_register_type (QOF_TYPE_STRING,
263  (GNCSearchCoreNew) gnc_search_string_new);
264  gnc_search_core_register_type (QOF_TYPE_DATE,
265  (GNCSearchCoreNew) gnc_search_date_new);
266  gnc_search_core_register_type (QOF_TYPE_INT64,
267  (GNCSearchCoreNew) gnc_search_int64_new);
268  gnc_search_core_register_type (QOF_TYPE_DOUBLE,
269  (GNCSearchCoreNew) gnc_search_double_new);
270  gnc_search_core_register_type (QOF_TYPE_NUMERIC,
271  (GNCSearchCoreNew) gnc_search_numeric_new);
272  gnc_search_core_register_type (QOF_TYPE_DEBCRED,
273  (GNCSearchCoreNew)
274  gnc_search_numeric_debcred_new);
275  gnc_search_core_register_type (QOF_TYPE_BOOLEAN,
276  (GNCSearchCoreNew) gnc_search_boolean_new);
277  gnc_search_core_register_type (GNC_ID_ACCOUNT,
278  (GNCSearchCoreNew) gnc_search_account_new);
279  gnc_search_core_register_type (ACCOUNT_MATCH_ALL_TYPE,
280  (GNCSearchCoreNew)
281  gnc_search_account_matchall_new);
282  gnc_search_core_register_type (RECONCILED_MATCH_TYPE,
283  (GNCSearchCoreNew) gnc_search_reconciled_new);
284 }
285 
286 void
287 gnc_search_core_initialize (void)
288 {
289  g_return_if_fail (typeTable == NULL);
290 
291  typeTable = g_hash_table_new (g_str_hash, g_str_equal);
292  init_table ();
293 }
294 
295 void
296 gnc_search_core_finalize (void)
297 {
298  g_return_if_fail (typeTable != NULL);
299 
300  g_hash_table_destroy (typeTable);
301  typeTable = NULL;
302 }
Account handling public routines.
#define ACCOUNT_MATCH_ALL_TYPE
Definition: Account.h:1438
API for Transactions and Splits (journal entries)