File: mg-handler-none.c

package info (click to toggle)
mergeant 0.52-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 12,872 kB
  • ctags: 6,584
  • sloc: ansic: 63,372; xml: 23,218; sh: 10,895; makefile: 612; sql: 237
file content (381 lines) | stat: -rw-r--r-- 10,624 bytes parent folder | download | duplicates (2)
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
/* mg-handler-none.c
 *
 * Copyright (C) 2003 Vivien Malerba
 *
 * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */

#include "mg-handler-none.h"
#include "mg-entry-none.h"
#include <libmergeant/mg-server.h>

static void mg_handler_none_class_init (MgHandlerNoneClass * class);
static void mg_handler_none_init (MgHandlerNone * wid);
static void mg_handler_none_dispose (GObject   * object);


/* MgDataHandler interface */
static void         mg_handler_none_data_handler_init      (MgDataHandlerIface *iface);
static MgDataEntry *mg_handler_none_get_entry_from_value   (MgDataHandler *dh, const GdaValue *value, 
							    GdaValueType type);
static gchar       *mg_handler_none_get_sql_from_value     (MgDataHandler *dh, const GdaValue *value);
static gchar       *mg_handler_none_get_str_from_value     (MgDataHandler *dh, const GdaValue *value);
static GdaValue    *mg_handler_none_get_value_from_sql     (MgDataHandler *dh, const gchar *sql, 
							    GdaValueType type);
static GdaValue    *mg_handler_none_get_sane_init_value    (MgDataHandler * dh, GdaValueType type);

static guint        mg_handler_none_get_nb_gda_types       (MgDataHandler *dh);
static GdaValueType mg_handler_none_get_gda_type_index     (MgDataHandler *dh, guint index);
static gboolean     mg_handler_none_accepts_gda_type       (MgDataHandler * dh, GdaValueType type);

static const gchar *mg_handler_none_get_descr              (MgDataHandler *dh);
static const gchar *mg_handler_none_get_descr_detail       (MgDataHandler *dh);
static const gchar *mg_handler_none_get_version            (MgDataHandler *dh);
static gboolean     mg_handler_none_is_plugin              (MgDataHandler *dh);
static const gchar *mg_handler_none_get_plugin_name        (MgDataHandler *dh);
static const gchar *mg_handler_none_get_plugin_file        (MgDataHandler *dh);
static gchar       *mg_handler_none_get_key                (MgDataHandler *dh);


/* signals */
enum
{
	LAST_SIGNAL
};

static gint mg_handler_none_signals[LAST_SIGNAL] = { };

struct  _MgHandlerNonePriv {
	gchar          *detailled_descr;
	MgServer       *srv;
};

/* get a pointer to the parents to be able to call their destructor */
static GObjectClass *parent_class = NULL;

guint
mg_handler_none_get_type (void)
{
	static GType type = 0;

	if (!type) {
		static const GTypeInfo info = {
			sizeof (MgHandlerNoneClass),
			(GBaseInitFunc) NULL,
			(GBaseFinalizeFunc) NULL,
			(GClassInitFunc) mg_handler_none_class_init,
			NULL,
			NULL,
			sizeof (MgHandlerNone),
			0,
			(GInstanceInitFunc) mg_handler_none_init
		};		

		static const GInterfaceInfo data_entry_info = {
			(GInterfaceInitFunc) mg_handler_none_data_handler_init,
			NULL,
			NULL
		};

		type = g_type_register_static (MG_BASE_TYPE, "MgHandlerNone", &info, 0);
		g_type_add_interface_static (type, MG_DATA_HANDLER_TYPE, &data_entry_info);
	}
	return type;
}

static void
mg_handler_none_data_handler_init (MgDataHandlerIface *iface)
{
	iface->get_entry_from_value = mg_handler_none_get_entry_from_value;
	iface->get_sql_from_value = mg_handler_none_get_sql_from_value;
	iface->get_str_from_value = mg_handler_none_get_str_from_value;
	iface->get_value_from_sql = mg_handler_none_get_value_from_sql;
	iface->get_value_from_str = NULL;
	iface->get_sane_init_value = mg_handler_none_get_sane_init_value;
	iface->get_nb_gda_types = mg_handler_none_get_nb_gda_types;
	iface->accepts_gda_type = mg_handler_none_accepts_gda_type;
	iface->get_gda_type_index = mg_handler_none_get_gda_type_index;
	iface->get_descr = mg_handler_none_get_descr;
	iface->get_descr_detail = mg_handler_none_get_descr_detail;
	iface->get_version = mg_handler_none_get_version;
	iface->is_plugin = mg_handler_none_is_plugin;
	iface->get_plugin_name = mg_handler_none_get_plugin_name;
	iface->get_plugin_file = mg_handler_none_get_plugin_file;
	iface->get_key = mg_handler_none_get_key;
}


static void
mg_handler_none_class_init (MgHandlerNoneClass * class)
{
	GObjectClass   *object_class = G_OBJECT_CLASS (class);
	
	parent_class = g_type_class_peek_parent (class);

	object_class->dispose = mg_handler_none_dispose;
}

static void
mg_handler_none_init (MgHandlerNone * hdl)
{
	/* Private structure */
	hdl->priv = g_new0 (MgHandlerNonePriv, 1);
	hdl->priv->detailled_descr = _("Default no-action handler");
	hdl->priv->srv = NULL;

	mg_base_set_name (MG_BASE (hdl), _("InternalNone"));
	mg_base_set_description (MG_BASE (hdl), _("Default representation for unhandled GDA data types"));
}

static void
mg_handler_none_dispose (GObject *object)
{
	MgHandlerNone *hdl;

	g_return_if_fail (object != NULL);
	g_return_if_fail (IS_MG_HANDLER_NONE (object));

	hdl = MG_HANDLER_NONE (object);

	if (hdl->priv) {
		mg_base_nullify_check (MG_BASE (object));

		if (hdl->priv->srv)
			g_object_remove_weak_pointer (G_OBJECT (hdl->priv->srv),
						      (gpointer *) & (hdl->priv->srv));

		g_free (hdl->priv);
		hdl->priv = NULL;
	}

	/* for the parent class */
	parent_class->dispose (object);
}

/**
 * mg_handler_none_new
 * @srv: a #MgServer object
 *
 * Creates a data handler for handling unhandled (bu other) gda data types.
 *
 * Returns: the new object
 */
GObject *
mg_handler_none_new (MgServer *srv)
{
	GObject *obj;
	MgHandlerNone *hdl;

	g_return_val_if_fail (srv && IS_MG_SERVER (srv), NULL);
	obj = g_object_new (MG_HANDLER_NONE_TYPE, NULL);
	hdl = MG_HANDLER_NONE (obj);

	g_object_add_weak_pointer (G_OBJECT (srv), (gpointer *) &(hdl->priv->srv));
	hdl->priv->srv = srv;

	return obj;
}


/* Interface implementation */
static MgDataEntry *
mg_handler_none_get_entry_from_value (MgDataHandler *iface, const GdaValue *value, GdaValueType type)
{
	MgHandlerNone *hdl;
	MgDataEntry *de;

	g_return_val_if_fail (iface && IS_MG_HANDLER_NONE (iface), NULL);
	hdl = MG_HANDLER_NONE (iface);
	g_return_val_if_fail (hdl->priv, NULL);

	/* no need to set a value since it only displays a textual message */
	de = MG_DATA_ENTRY (mg_entry_none_new (iface, type));

	return de;
}

static gchar *
mg_handler_none_get_sql_from_value (MgDataHandler *iface, const GdaValue *value)
{
	MgHandlerNone *hdl;

	g_return_val_if_fail (iface && IS_MG_HANDLER_NONE (iface), NULL);
	hdl = MG_HANDLER_NONE (iface);
	g_return_val_if_fail (hdl->priv, NULL);

	return NULL;
}

static gchar *
mg_handler_none_get_str_from_value (MgDataHandler *iface, const GdaValue *value)
{
	MgHandlerNone *hdl;

	g_return_val_if_fail (iface && IS_MG_HANDLER_NONE (iface), NULL);
	hdl = MG_HANDLER_NONE (iface);
	g_return_val_if_fail (hdl->priv, NULL);

	return NULL;
}

static GdaValue *
mg_handler_none_get_value_from_sql (MgDataHandler *iface, const gchar *sql, GdaValueType type)
{
	MgHandlerNone *hdl;

	g_return_val_if_fail (iface && IS_MG_HANDLER_NONE (iface), NULL);
	hdl = MG_HANDLER_NONE (iface);
	g_return_val_if_fail (hdl->priv, NULL);

	return gda_value_new_null ();
}

static GdaValue *
mg_handler_none_get_sane_init_value (MgDataHandler *iface, GdaValueType type)
{
	MgHandlerNone *hdl;
	GdaValue *value;

	g_return_val_if_fail (iface && IS_MG_HANDLER_NONE (iface), NULL);
	hdl = MG_HANDLER_NONE (iface);
	g_return_val_if_fail (hdl->priv, NULL);

	value = gda_value_new_null ();
	return value;
}

static guint
mg_handler_none_get_nb_gda_types (MgDataHandler *iface)
{
	MgHandlerNone *hdl;

	g_return_val_if_fail (iface && IS_MG_HANDLER_NONE (iface), 0);
	hdl = MG_HANDLER_NONE (iface);
	g_return_val_if_fail (hdl->priv, 0);

	return GDA_VALUE_TYPE_UNKNOWN;
}


static gboolean
mg_handler_none_accepts_gda_type (MgDataHandler *iface, GdaValueType type)
{
	MgHandlerNone *hdl;

	g_return_val_if_fail (iface && IS_MG_HANDLER_NONE (iface), FALSE);
	g_return_val_if_fail (type != GDA_VALUE_TYPE_UNKNOWN, FALSE);
	hdl = MG_HANDLER_NONE (iface);
	g_return_val_if_fail (hdl->priv, 0);

	return TRUE;
}

static GdaValueType
mg_handler_none_get_gda_type_index (MgDataHandler *iface, guint index)
{
	MgHandlerNone *hdl;

	g_return_val_if_fail (iface && IS_MG_HANDLER_NONE (iface), GDA_VALUE_TYPE_UNKNOWN);
	hdl = MG_HANDLER_NONE (iface);
	g_return_val_if_fail (hdl->priv, GDA_VALUE_TYPE_UNKNOWN);

	return index;
}

static const gchar *
mg_handler_none_get_descr (MgDataHandler *iface)
{
	MgHandlerNone *hdl;

	g_return_val_if_fail (iface && IS_MG_HANDLER_NONE (iface), NULL);
	hdl = MG_HANDLER_NONE (iface);
	g_return_val_if_fail (hdl->priv, NULL);

	return mg_base_get_description (MG_BASE (hdl));
}

static const gchar *
mg_handler_none_get_descr_detail (MgDataHandler *iface)
{
	MgHandlerNone *hdl;

	g_return_val_if_fail (iface && IS_MG_HANDLER_NONE (iface), NULL);
	hdl = MG_HANDLER_NONE (iface);
	g_return_val_if_fail (hdl->priv, NULL);

	return hdl->priv->detailled_descr;
}

static const gchar *
mg_handler_none_get_version (MgDataHandler *iface)
{
	MgHandlerNone *hdl;

	g_return_val_if_fail (iface && IS_MG_HANDLER_NONE (iface), NULL);
	hdl = MG_HANDLER_NONE (iface);
	g_return_val_if_fail (hdl->priv, NULL);
	
	return g_strdup ("Internal");
}

static gboolean
mg_handler_none_is_plugin (MgDataHandler *iface)
{
	MgHandlerNone *hdl;

	g_return_val_if_fail (iface && IS_MG_HANDLER_NONE (iface), FALSE);
	hdl = MG_HANDLER_NONE (iface);
	g_return_val_if_fail (hdl->priv, FALSE);

	return FALSE;
}

static const gchar *
mg_handler_none_get_plugin_name (MgDataHandler *iface)
{
	MgHandlerNone *hdl;

	g_return_val_if_fail (iface && IS_MG_HANDLER_NONE (iface), NULL);
	hdl = MG_HANDLER_NONE (iface);
	g_return_val_if_fail (hdl->priv, NULL);
	
	return NULL;
}

static const gchar *
mg_handler_none_get_plugin_file (MgDataHandler *iface)
{
	MgHandlerNone *hdl;

	g_return_val_if_fail (iface && IS_MG_HANDLER_NONE (iface), NULL);
	hdl = MG_HANDLER_NONE (iface);
	g_return_val_if_fail (hdl->priv, NULL);
	
	return NULL;
}

static gchar *
mg_handler_none_get_key (MgDataHandler *iface)
{
	MgHandlerNone *hdl;

	g_return_val_if_fail (iface && IS_MG_HANDLER_NONE (iface), NULL);
	hdl = MG_HANDLER_NONE (iface);
	g_return_val_if_fail (hdl->priv, NULL);
	
	return g_strdup (mg_base_get_name (MG_BASE (hdl)));
}