2
* Copyright (C) 2002 Derek Atkins
4
* Authors: Derek Atkins <warlord@MIT.EDU>
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of version 2 of the GNU General Public
8
* License as published by the Free Software Foundation.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* General Public License for more details.
15
* You should have received a copy of the GNU General Public
16
* License along with this program; if not, write to the
17
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
* Boston, MA 02110-1301, USA.
28
#include "QueryCore.h"
30
#include "Account.h" /* for ACCOUNT_MATCH_ALL_TYPE */
31
#include "Transaction.h" /* for RECONCILED_MATCH_TYPE */
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"
43
static void grab_focus (GNCSearchCoreType *fe);
44
static void editable_enters (GNCSearchCoreType *fe);
45
static gboolean validate (GNCSearchCoreType *fe);
47
static void gnc_search_core_type_class_init (GNCSearchCoreTypeClass *class);
48
static void gnc_search_core_type_init (GNCSearchCoreType *gspaper);
49
static void gnc_search_core_type_finalize (GObject *obj);
51
typedef struct _GNCSearchCoreTypePrivate GNCSearchCoreTypePrivate;
53
struct _GNCSearchCoreTypePrivate {
58
(G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_SEARCH_CORE_TYPE, GNCSearchCoreTypePrivate))
60
static GtkObjectClass *parent_class;
62
static GHashTable *typeTable = NULL;
65
gnc_search_core_type_get_type (void)
67
static GType type = 0;
70
GTypeInfo type_info = {
71
sizeof (GNCSearchCoreTypeClass),
74
(GClassInitFunc)gnc_search_core_type_class_init,
77
sizeof (GNCSearchCoreType),
79
(GInstanceInitFunc)gnc_search_core_type_init
82
type = g_type_register_static (G_TYPE_OBJECT, "GNCSearchCoreType", &type_info, 0);
89
gnc_search_core_type_class_init (GNCSearchCoreTypeClass *klass)
91
GObjectClass *object_class;
93
object_class = G_OBJECT_CLASS (klass);
94
parent_class = g_type_class_peek_parent (klass);
96
object_class->finalize = gnc_search_core_type_finalize;
98
/* override methods */
99
klass->validate = validate;
100
klass->grab_focus = grab_focus;
101
klass->editable_enters = editable_enters;
103
g_type_class_add_private(klass, sizeof(GNCSearchCoreTypePrivate));
107
gnc_search_core_type_init (GNCSearchCoreType *o)
112
gnc_search_core_type_finalize (GObject *obj)
114
GNCSearchCoreType *o = (GNCSearchCoreType *)obj;
115
g_assert (GNC_IS_SEARCH_CORE_TYPE (o));
117
G_OBJECT_CLASS (parent_class)->finalize(obj);
121
* gnc_search_core_type_new:
123
* Create a new GNCSearchCoreType object.
125
* Return value: A new #GNCSearchCoreType object.
128
gnc_search_core_type_new (void)
130
GNCSearchCoreType *o;
132
o = g_object_new (GNC_TYPE_SEARCH_CORE_TYPE, NULL);
138
gnc_search_core_type_editable_enters (GNCSearchCoreType *fe)
140
GNC_SEARCH_CORE_TYPE_GET_CLASS (fe)->editable_enters (fe);
144
gnc_search_core_type_grab_focus (GNCSearchCoreType *fe)
146
GNC_SEARCH_CORE_TYPE_GET_CLASS (fe)->grab_focus (fe);
150
gnc_search_core_type_validate (GNCSearchCoreType *fe)
152
return GNC_SEARCH_CORE_TYPE_GET_CLASS (fe)->validate (fe);
156
* gnc_search_core_type_clone:
157
* @fe: search core_type
159
* Clones the GNCSearchCoreType @fe.
164
gnc_search_core_type_clone (GNCSearchCoreType *fe)
166
return GNC_SEARCH_CORE_TYPE_GET_CLASS (fe)->clone(fe);
170
* gnc_search_core_type_get_widget:
171
* @fe: search core_type
174
* Create a widget to represent this core_type.
179
gnc_search_core_type_get_widget (GNCSearchCoreType *fe)
181
return GNC_SEARCH_CORE_TYPE_GET_CLASS (fe)->get_widget(fe);
185
* gnc_search_core_type_get_predicate:
186
* @fe: search core_type
188
* Create a Predicate Data that matches this core_type
193
gnc_search_core_type_get_predicate (GNCSearchCoreType *fe)
195
return GNC_SEARCH_CORE_TYPE_GET_CLASS (fe)->get_predicate(fe);
199
* gnc_search_core_type_new_type_name:
200
* @type: search core_type type
202
* Create a new search core_type based on its type name.
207
gnc_search_core_type_new_type_name (const char *type)
209
GNCSearchCoreNew fcn;
211
g_return_val_if_fail (typeTable != NULL, NULL);
216
fcn = g_hash_table_lookup (typeTable, type);
220
g_warning("Unknown search type '%s'", type);
225
/* default implementations */
227
validate (GNCSearchCoreType *fe)
233
grab_focus (GNCSearchCoreType *fe)
239
editable_enters (GNCSearchCoreType *fe)
245
gnc_search_core_register_type (const char *type_name, GNCSearchCoreNew fcn)
247
g_return_if_fail (type_name || *type_name || fcn);
248
g_return_if_fail (typeTable);
250
g_hash_table_insert (typeTable, (char *) type_name, (gpointer) fcn);
256
gnc_search_core_register_type (QUERYCORE_STRING,
257
(GNCSearchCoreNew) gnc_search_string_new);
258
gnc_search_core_register_type (QUERYCORE_DATE,
259
(GNCSearchCoreNew) gnc_search_date_new);
260
gnc_search_core_register_type (QUERYCORE_INT64,
261
(GNCSearchCoreNew) gnc_search_int64_new);
262
gnc_search_core_register_type (QUERYCORE_DOUBLE,
263
(GNCSearchCoreNew) gnc_search_double_new);
264
gnc_search_core_register_type (QUERYCORE_NUMERIC,
265
(GNCSearchCoreNew) gnc_search_numeric_new);
266
gnc_search_core_register_type (QUERYCORE_DEBCRED,
268
gnc_search_numeric_debcred_new);
269
gnc_search_core_register_type (QUERYCORE_BOOLEAN,
270
(GNCSearchCoreNew) gnc_search_boolean_new);
271
gnc_search_core_register_type (GNC_ID_ACCOUNT,
272
(GNCSearchCoreNew) gnc_search_account_new);
273
gnc_search_core_register_type (ACCOUNT_MATCH_ALL_TYPE,
275
gnc_search_account_matchall_new);
276
gnc_search_core_register_type (RECONCILED_MATCH_TYPE,
277
(GNCSearchCoreNew) gnc_search_reconciled_new);
281
gnc_search_core_initialize (void)
283
g_return_if_fail (typeTable == NULL);
285
typeTable = g_hash_table_new (g_str_hash, g_str_equal);
290
gnc_search_core_finalize (void)
292
g_return_if_fail (typeTable != NULL);
294
g_hash_table_destroy (typeTable);