~siretart/gnucash/ubuntu-fullsource

« back to all changes in this revision

Viewing changes to src/gnome-search/search-core-type.c

  • Committer: Reinhard Tartler
  • Date: 2008-08-03 07:25:46 UTC
  • Revision ID: siretart@tauware.de-20080803072546-y6p8xda8zpfi62ys
import gnucash_2.2.4.orig.tar.gz

The original tarball had the md5sum: 27e660297dc5b8ce574515779d05a5a5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 version 2 of the GNU General Public
 
8
 * License as published by the Free Software Foundation.
 
9
 *
 
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.
 
14
 *
 
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.
 
19
 */
 
20
 
 
21
#ifdef HAVE_CONFIG_H
 
22
#include <config.h>
 
23
#endif
 
24
 
 
25
#include <string.h>
 
26
#include <gtk/gtk.h>
 
27
 
 
28
#include "QueryCore.h"
 
29
#include "QueryNew.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 *class);
 
48
static void gnc_search_core_type_init   (GNCSearchCoreType *gspaper);
 
49
static void gnc_search_core_type_finalize       (GObject *obj);
 
50
 
 
51
typedef struct _GNCSearchCoreTypePrivate GNCSearchCoreTypePrivate;
 
52
 
 
53
struct _GNCSearchCoreTypePrivate {
 
54
  gpointer dummy;
 
55
};
 
56
 
 
57
#define _PRIVATE(o) \
 
58
   (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_SEARCH_CORE_TYPE, GNCSearchCoreTypePrivate))
 
59
 
 
60
static GtkObjectClass *parent_class;
 
61
 
 
62
static GHashTable *typeTable = NULL;
 
63
 
 
64
GType
 
65
gnc_search_core_type_get_type (void)
 
66
{
 
67
  static GType type = 0;
 
68
 
 
69
  if (type == 0) {
 
70
    GTypeInfo type_info = {
 
71
      sizeof (GNCSearchCoreTypeClass),
 
72
      NULL,
 
73
      NULL,
 
74
      (GClassInitFunc)gnc_search_core_type_class_init,
 
75
      NULL,
 
76
      NULL,
 
77
      sizeof (GNCSearchCoreType),
 
78
      0,
 
79
      (GInstanceInitFunc)gnc_search_core_type_init
 
80
    };
 
81
                
 
82
    type = g_type_register_static (G_TYPE_OBJECT, "GNCSearchCoreType", &type_info, 0);
 
83
  }
 
84
  
 
85
  return type;
 
86
}
 
87
 
 
88
static void
 
89
gnc_search_core_type_class_init (GNCSearchCoreTypeClass *klass)
 
90
{
 
91
  GObjectClass *object_class;
 
92
        
 
93
  object_class = G_OBJECT_CLASS (klass);
 
94
  parent_class = g_type_class_peek_parent (klass);
 
95
 
 
96
  object_class->finalize = gnc_search_core_type_finalize;
 
97
 
 
98
  /* override methods */
 
99
  klass->validate = validate;
 
100
  klass->grab_focus = grab_focus;
 
101
  klass->editable_enters = editable_enters;
 
102
 
 
103
  g_type_class_add_private(klass, sizeof(GNCSearchCoreTypePrivate));
 
104
}
 
105
 
 
106
static void
 
107
gnc_search_core_type_init (GNCSearchCoreType *o)
 
108
{
 
109
}
 
110
 
 
111
static void
 
112
gnc_search_core_type_finalize (GObject *obj)
 
113
{
 
114
  GNCSearchCoreType *o = (GNCSearchCoreType *)obj;
 
115
  g_assert (GNC_IS_SEARCH_CORE_TYPE (o));
 
116
 
 
117
  G_OBJECT_CLASS (parent_class)->finalize(obj);
 
118
}
 
119
 
 
120
/**
 
121
 * gnc_search_core_type_new:
 
122
 *
 
123
 * Create a new GNCSearchCoreType object.
 
124
 * 
 
125
 * Return value: A new #GNCSearchCoreType object.
 
126
 **/
 
127
GNCSearchCoreType *
 
128
gnc_search_core_type_new (void)
 
129
{
 
130
  GNCSearchCoreType *o;
 
131
 
 
132
  o = g_object_new (GNC_TYPE_SEARCH_CORE_TYPE, NULL);
 
133
 
 
134
  return o;
 
135
}
 
136
 
 
137
void
 
138
gnc_search_core_type_editable_enters (GNCSearchCoreType *fe)
 
139
{
 
140
  GNC_SEARCH_CORE_TYPE_GET_CLASS (fe)->editable_enters (fe);
 
141
}
 
142
 
 
143
void
 
144
gnc_search_core_type_grab_focus (GNCSearchCoreType *fe)
 
145
{
 
146
  GNC_SEARCH_CORE_TYPE_GET_CLASS (fe)->grab_focus (fe);
 
147
}
 
148
 
 
149
gboolean
 
150
gnc_search_core_type_validate (GNCSearchCoreType *fe)
 
151
{
 
152
  return GNC_SEARCH_CORE_TYPE_GET_CLASS (fe)->validate (fe);
 
153
}
 
154
 
 
155
/**
 
156
 * gnc_search_core_type_clone:
 
157
 * @fe: search core_type
 
158
 * 
 
159
 * Clones the GNCSearchCoreType @fe.
 
160
 * 
 
161
 * Return value: 
 
162
 **/
 
163
GNCSearchCoreType *
 
164
gnc_search_core_type_clone (GNCSearchCoreType *fe)
 
165
{
 
166
  return GNC_SEARCH_CORE_TYPE_GET_CLASS (fe)->clone(fe);
 
167
}
 
168
 
 
169
/**
 
170
 * gnc_search_core_type_get_widget:
 
171
 * @fe: search core_type
 
172
 * @node: xml node
 
173
 * 
 
174
 * Create a widget to represent this core_type.
 
175
 * 
 
176
 * Return value: 
 
177
 **/
 
178
GtkWidget *
 
179
gnc_search_core_type_get_widget (GNCSearchCoreType *fe)
 
180
{
 
181
  return GNC_SEARCH_CORE_TYPE_GET_CLASS (fe)->get_widget(fe);
 
182
}
 
183
 
 
184
/**
 
185
 * gnc_search_core_type_get_predicate:
 
186
 * @fe: search core_type
 
187
 * 
 
188
 * Create a Predicate Data that matches this core_type
 
189
 * 
 
190
 * Return value: 
 
191
 **/
 
192
QueryPredData_t
 
193
gnc_search_core_type_get_predicate (GNCSearchCoreType *fe)
 
194
{
 
195
  return GNC_SEARCH_CORE_TYPE_GET_CLASS (fe)->get_predicate(fe);
 
196
}
 
197
 
 
198
/**
 
199
 * gnc_search_core_type_new_type_name:
 
200
 * @type: search core_type type
 
201
 * 
 
202
 * Create a new search core_type based on its type name.
 
203
 * 
 
204
 * Return value: 
 
205
 **/
 
206
GNCSearchCoreType *
 
207
gnc_search_core_type_new_type_name (const char *type)
 
208
{
 
209
  GNCSearchCoreNew fcn;
 
210
 
 
211
  g_return_val_if_fail (typeTable != NULL, NULL);
 
212
 
 
213
  if (type == NULL)
 
214
    return NULL;
 
215
 
 
216
  fcn = g_hash_table_lookup (typeTable, type);
 
217
  if (fcn) {
 
218
    return ((fcn)());
 
219
  } else {
 
220
    g_warning("Unknown search type '%s'", type);
 
221
    return NULL;
 
222
  }
 
223
}
 
224
 
 
225
/* default implementations */
 
226
static gboolean
 
227
validate (GNCSearchCoreType *fe)
 
228
{
 
229
  return TRUE;
 
230
}
 
231
 
 
232
static void
 
233
grab_focus (GNCSearchCoreType *fe)
 
234
{
 
235
  return;
 
236
}
 
237
 
 
238
static void
 
239
editable_enters (GNCSearchCoreType *fe)
 
240
{
 
241
  return;
 
242
}
 
243
 
 
244
void
 
245
gnc_search_core_register_type (const char *type_name, GNCSearchCoreNew fcn)
 
246
{
 
247
  g_return_if_fail (type_name || *type_name || fcn);
 
248
  g_return_if_fail (typeTable);
 
249
 
 
250
  g_hash_table_insert (typeTable, (char *) type_name, (gpointer) fcn);
 
251
}
 
252
 
 
253
static void
 
254
init_table (void)
 
255
{
 
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,
 
267
                                 (GNCSearchCoreNew)
 
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,
 
274
                                 (GNCSearchCoreNew)
 
275
                                 gnc_search_account_matchall_new);
 
276
  gnc_search_core_register_type (RECONCILED_MATCH_TYPE,
 
277
                                 (GNCSearchCoreNew) gnc_search_reconciled_new);
 
278
}
 
279
 
 
280
void
 
281
gnc_search_core_initialize (void)
 
282
{
 
283
  g_return_if_fail (typeTable == NULL);
 
284
 
 
285
  typeTable = g_hash_table_new (g_str_hash, g_str_equal);
 
286
  init_table ();
 
287
}
 
288
 
 
289
void
 
290
gnc_search_core_finalize (void)
 
291
{
 
292
  g_return_if_fail (typeTable != NULL);
 
293
 
 
294
  g_hash_table_destroy (typeTable);
 
295
  typeTable = NULL;
 
296
}