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