3
* Copyright (C) 2003 Vivien Malerba
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License as
7
* published by the Free Software Foundation; either version 2 of the
8
* License, or (at your option) any later version.
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
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21
#include "mg-handler-text.h"
22
/*#include "mg-entry-text.h"*/
23
#include <libmergeant/handlers/mg-entry-string.h>
24
#include <libmergeant/mg-server.h>
27
static void mg_handler_text_class_init (MgHandlerTextClass * class);
28
static void mg_handler_text_init (MgHandlerText * wid);
29
static void mg_handler_text_dispose (GObject * object);
31
/* plugin initialisation */
32
MgDataHandler* plugin_init (MgServer *srv, GModule *module);
34
/* MgDataHandler interface */
35
static void mg_handler_text_data_handler_init (MgDataHandlerIface *iface);
36
static MgDataEntry *mg_handler_text_get_entry_from_value (MgDataHandler *dh, const GdaValue *value,
38
static gchar *mg_handler_text_get_sql_from_value (MgDataHandler *dh, const GdaValue *value);
39
static gchar *mg_handler_text_get_str_from_value (MgDataHandler *dh, const GdaValue *value);
40
static GdaValue *mg_handler_text_get_value_from_sql (MgDataHandler *dh, const gchar *sql,
42
static GdaValue *mg_handler_text_get_sane_init_value (MgDataHandler * dh, GdaValueType type);
44
static guint mg_handler_text_get_nb_gda_types (MgDataHandler *dh);
45
static GdaValueType mg_handler_text_get_gda_type_index (MgDataHandler *dh, guint index);
46
static gboolean mg_handler_text_accepts_gda_type (MgDataHandler * dh, GdaValueType type);
48
static const gchar *mg_handler_text_get_descr (MgDataHandler *dh);
49
static const gchar *mg_handler_text_get_descr_detail (MgDataHandler *dh);
50
static const gchar *mg_handler_text_get_version (MgDataHandler *dh);
51
static gboolean mg_handler_text_is_plugin (MgDataHandler *dh);
52
static const gchar *mg_handler_text_get_plugin_name (MgDataHandler *dh);
53
static const gchar *mg_handler_text_get_plugin_file (MgDataHandler *dh);
54
static gchar *mg_handler_text_get_key (MgDataHandler *dh);
63
static gint mg_handler_text_signals[LAST_SIGNAL] = { };
65
struct _MgHandlerTextPriv {
66
gchar *detailled_descr;
68
GdaValueType *valid_gda_types;
70
MgDataHandler *string_handler;
75
/* get a pointer to the parents to be able to call their destructor */
76
static GObjectClass *parent_class = NULL;
79
mg_handler_text_get_type (void)
81
static GType type = 0;
84
static const GTypeInfo info = {
85
sizeof (MgHandlerTextClass),
87
(GBaseFinalizeFunc) NULL,
88
(GClassInitFunc) mg_handler_text_class_init,
91
sizeof (MgHandlerText),
93
(GInstanceInitFunc) mg_handler_text_init
96
static const GInterfaceInfo data_entry_info = {
97
(GInterfaceInitFunc) mg_handler_text_data_handler_init,
102
type = g_type_register_static (MG_BASE_TYPE, "MgHandlerText", &info, 0);
103
g_type_add_interface_static (type, MG_DATA_HANDLER_TYPE, &data_entry_info);
109
mg_handler_text_data_handler_init (MgDataHandlerIface *iface)
111
iface->get_entry_from_value = mg_handler_text_get_entry_from_value;
112
iface->get_sql_from_value = mg_handler_text_get_sql_from_value;
113
iface->get_str_from_value = mg_handler_text_get_str_from_value;
114
iface->get_value_from_sql = mg_handler_text_get_value_from_sql;
115
iface->get_value_from_str = NULL;
116
iface->get_sane_init_value = mg_handler_text_get_sane_init_value;
117
iface->get_nb_gda_types = mg_handler_text_get_nb_gda_types;
118
iface->accepts_gda_type = mg_handler_text_accepts_gda_type;
119
iface->get_gda_type_index = mg_handler_text_get_gda_type_index;
120
iface->get_descr = mg_handler_text_get_descr;
121
iface->get_descr_detail = mg_handler_text_get_descr_detail;
122
iface->get_version = mg_handler_text_get_version;
123
iface->is_plugin = mg_handler_text_is_plugin;
124
iface->get_plugin_name = mg_handler_text_get_plugin_name;
125
iface->get_plugin_file = mg_handler_text_get_plugin_file;
126
iface->get_key = mg_handler_text_get_key;
131
mg_handler_text_class_init (MgHandlerTextClass * class)
133
GObjectClass *object_class = G_OBJECT_CLASS (class);
135
parent_class = g_type_class_peek_parent (class);
137
object_class->dispose = mg_handler_text_dispose;
141
mg_handler_text_init (MgHandlerText * hdl)
143
/* Private structure */
144
hdl->priv = g_new0 (MgHandlerTextPriv, 1);
145
hdl->priv->detailled_descr = _("Data handler for string data types, presented as a text area");
146
hdl->priv->nb_gda_types = 1;
147
hdl->priv->valid_gda_types = g_new0 (GdaValueType, 1);
148
hdl->priv->valid_gda_types[0] = GDA_VALUE_TYPE_STRING;
149
hdl->priv->srv = NULL;
150
hdl->priv->string_handler = NULL;
151
hdl->priv->module = NULL;
153
mg_base_set_name (MG_BASE (hdl), mg_handler_text_get_plugin_name (MG_DATA_HANDLER (hdl)));
154
mg_base_set_description (MG_BASE (hdl), _("Text area representation"));
158
mg_handler_text_dispose (GObject *object)
162
g_return_if_fail (object != NULL);
163
g_return_if_fail (IS_MG_HANDLER_TEXT (object));
165
hdl = MG_HANDLER_TEXT (object);
168
mg_base_nullify_check (MG_BASE (object));
170
g_free (hdl->priv->valid_gda_types);
171
hdl->priv->valid_gda_types = NULL;
174
g_object_remove_weak_pointer (G_OBJECT (hdl->priv->srv),
175
(gpointer *) & (hdl->priv->srv));
181
/* for the parent class */
182
parent_class->dispose (object);
186
* Plugin initialization
189
plugin_init (MgServer *srv, GModule *module)
193
text = MG_HANDLER_TEXT (mg_handler_text_new (srv));
194
text->priv->module = module;
196
return MG_DATA_HANDLER (text);
201
* mg_handler_text_new
202
* @srv: a #MgServer object
204
* Creates a data handler for texts
206
* Returns: the new object
209
mg_handler_text_new (MgServer *srv)
214
g_return_val_if_fail (srv && IS_MG_SERVER (srv), NULL);
215
obj = g_object_new (MG_HANDLER_TEXT_TYPE, NULL);
216
hdl = MG_HANDLER_TEXT (obj);
218
g_object_add_weak_pointer (G_OBJECT (srv), (gpointer *) &(hdl->priv->srv));
219
hdl->priv->srv = srv;
221
/* get a pointer to the String Handler which we will use */
222
hdl->priv->string_handler = mg_server_get_handler_by_gda (srv, GDA_VALUE_TYPE_STRING);
223
g_assert (hdl->priv->string_handler);
229
/* Interface implementation */
231
mg_handler_text_get_entry_from_value (MgDataHandler *iface, const GdaValue *value, GdaValueType type)
235
GdaValueType real_type;
237
g_return_val_if_fail (iface && IS_MG_HANDLER_TEXT (iface), NULL);
238
hdl = MG_HANDLER_TEXT (iface);
239
g_return_val_if_fail (hdl->priv, NULL);
241
if (value && (gda_value_get_type (value) != GDA_VALUE_TYPE_NULL)) {
242
real_type = gda_value_get_type (value);
243
g_return_val_if_fail (mg_data_handler_accepts_gda_type (iface, type), NULL);
248
de = MG_DATA_ENTRY (mg_entry_string_new (iface, real_type));
249
g_object_set (G_OBJECT (de), "multiline", TRUE, NULL);
250
if (value && (gda_value_get_type (value) != GDA_VALUE_TYPE_NULL))
251
mg_data_entry_set_value (de, value);
253
mg_data_entry_set_value (de, NULL);
259
mg_handler_text_get_sql_from_value (MgDataHandler *iface, const GdaValue *value)
263
g_return_val_if_fail (iface && IS_MG_HANDLER_TEXT (iface), NULL);
264
hdl = MG_HANDLER_TEXT (iface);
265
g_return_val_if_fail (hdl->priv, NULL);
267
return mg_data_handler_get_sql_from_value (hdl->priv->string_handler, value);
271
mg_handler_text_get_str_from_value (MgDataHandler *iface, const GdaValue *value)
275
g_return_val_if_fail (iface && IS_MG_HANDLER_TEXT (iface), NULL);
276
hdl = MG_HANDLER_TEXT (iface);
277
g_return_val_if_fail (hdl->priv, NULL);
279
return mg_data_handler_get_str_from_value (hdl->priv->string_handler, value);
283
mg_handler_text_get_value_from_sql (MgDataHandler *iface, const gchar *sql, GdaValueType type)
287
g_return_val_if_fail (iface && IS_MG_HANDLER_TEXT (iface), NULL);
288
hdl = MG_HANDLER_TEXT (iface);
289
g_return_val_if_fail (hdl->priv, NULL);
291
return mg_data_handler_get_value_from_sql (hdl->priv->string_handler, sql, type);
295
mg_handler_text_get_sane_init_value (MgDataHandler *iface, GdaValueType type)
299
g_return_val_if_fail (iface && IS_MG_HANDLER_TEXT (iface), NULL);
300
hdl = MG_HANDLER_TEXT (iface);
301
g_return_val_if_fail (hdl->priv, NULL);
303
return mg_data_handler_get_sane_init_value (hdl->priv->string_handler, type);
307
mg_handler_text_get_nb_gda_types (MgDataHandler *iface)
311
g_return_val_if_fail (iface && IS_MG_HANDLER_TEXT (iface), 0);
312
hdl = MG_HANDLER_TEXT (iface);
313
g_return_val_if_fail (hdl->priv, 0);
315
return hdl->priv->nb_gda_types;
320
mg_handler_text_accepts_gda_type (MgDataHandler *iface, GdaValueType type)
324
gboolean found = FALSE;
326
g_return_val_if_fail (iface && IS_MG_HANDLER_TEXT (iface), FALSE);
327
g_return_val_if_fail (type != GDA_VALUE_TYPE_UNKNOWN, FALSE);
328
hdl = MG_HANDLER_TEXT (iface);
329
g_return_val_if_fail (hdl->priv, 0);
331
while (!found && (i < hdl->priv->nb_gda_types)) {
332
if (hdl->priv->valid_gda_types [i] == type)
341
mg_handler_text_get_gda_type_index (MgDataHandler *iface, guint index)
345
g_return_val_if_fail (iface && IS_MG_HANDLER_TEXT (iface), GDA_VALUE_TYPE_UNKNOWN);
346
hdl = MG_HANDLER_TEXT (iface);
347
g_return_val_if_fail (hdl->priv, GDA_VALUE_TYPE_UNKNOWN);
348
g_return_val_if_fail (index < hdl->priv->nb_gda_types, GDA_VALUE_TYPE_UNKNOWN);
350
return hdl->priv->valid_gda_types[index];
354
mg_handler_text_get_descr (MgDataHandler *iface)
358
g_return_val_if_fail (iface && IS_MG_HANDLER_TEXT (iface), NULL);
359
hdl = MG_HANDLER_TEXT (iface);
360
g_return_val_if_fail (hdl->priv, NULL);
362
return mg_base_get_description (MG_BASE (hdl));
366
mg_handler_text_get_descr_detail (MgDataHandler *iface)
370
g_return_val_if_fail (iface && IS_MG_HANDLER_TEXT (iface), NULL);
371
hdl = MG_HANDLER_TEXT (iface);
372
g_return_val_if_fail (hdl->priv, NULL);
374
return hdl->priv->detailled_descr;
378
mg_handler_text_get_version (MgDataHandler *iface)
382
g_return_val_if_fail (iface && IS_MG_HANDLER_TEXT (iface), NULL);
383
hdl = MG_HANDLER_TEXT (iface);
384
g_return_val_if_fail (hdl->priv, NULL);
386
return g_strdup ("V1R0");
390
mg_handler_text_is_plugin (MgDataHandler *iface)
394
g_return_val_if_fail (iface && IS_MG_HANDLER_TEXT (iface), FALSE);
395
hdl = MG_HANDLER_TEXT (iface);
396
g_return_val_if_fail (hdl->priv, FALSE);
402
mg_handler_text_get_plugin_name (MgDataHandler *iface)
406
g_return_val_if_fail (iface && IS_MG_HANDLER_TEXT (iface), NULL);
407
hdl = MG_HANDLER_TEXT (iface);
408
g_return_val_if_fail (hdl->priv, NULL);
410
return "Text Plugin";
414
mg_handler_text_get_plugin_file (MgDataHandler *iface)
418
g_return_val_if_fail (iface && IS_MG_HANDLER_TEXT (iface), NULL);
419
hdl = MG_HANDLER_TEXT (iface);
420
g_return_val_if_fail (hdl->priv, NULL);
422
if (hdl->priv->module)
423
return g_module_name (hdl->priv->module);
429
mg_handler_text_get_key (MgDataHandler *iface)
433
g_return_val_if_fail (iface && IS_MG_HANDLER_TEXT (iface), NULL);
434
hdl = MG_HANDLER_TEXT (iface);
435
g_return_val_if_fail (hdl->priv, NULL);
437
return g_strdup (mg_base_get_name (MG_BASE (hdl)));