~ubuntu-branches/ubuntu/karmic/mergeant/karmic

« back to all changes in this revision

Viewing changes to libmergeant/handlers/mg-entry-boolean.c

  • Committer: Bazaar Package Importer
  • Author(s): Gustavo R. Montesino
  • Date: 2007-11-29 08:44:48 UTC
  • mfrom: (2.1.4 hardy)
  • Revision ID: james.westby@ubuntu.com-20071129084448-6aon73d22bv6hzfw
Tags: 0.67-3
* Re-enable installation of the mime files in mergeant.install
* mergeant.dirs: create usr/share/mime/packages to make dh_installmime add
  the update-mime-database code snippets

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* mg-entry-boolean.c
2
 
 *
3
 
 * Copyright (C) 2003 Vivien Malerba
4
 
 *
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.
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
13
 
 * GNU General Public License for more details.
14
 
 *
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
18
 
 * USA
19
 
 */
20
 
 
21
 
#include "mg-entry-boolean.h"
22
 
#include <libmergeant/mg-data-handler.h>
23
 
 
24
 
/* 
25
 
 * Main static functions 
26
 
 */
27
 
static void mg_entry_boolean_class_init (MgEntryBooleanClass * class);
28
 
static void mg_entry_boolean_init (MgEntryBoolean * srv);
29
 
static void mg_entry_boolean_dispose (GObject   * object);
30
 
static void mg_entry_boolean_finalize (GObject   * object);
31
 
 
32
 
/* virtual functions */
33
 
static GtkWidget *create_entry (MgEntryWrapper *mgwrap);
34
 
static void       real_set_value (MgEntryWrapper *mgwrap, const GdaValue *value);
35
 
static GdaValue  *real_get_value (MgEntryWrapper *mgwrap);
36
 
static void       connect_signals(MgEntryWrapper *mgwrap, GCallback callback);
37
 
static gboolean   expand_in_layout (MgEntryWrapper *mgwrap);
38
 
 
39
 
 
40
 
/* get a pointer to the parents to be able to call their destructor */
41
 
static GObjectClass  *parent_class = NULL;
42
 
 
43
 
/* private structure */
44
 
struct _MgEntryBooleanPrivate
45
 
{
46
 
        GtkWidget *hbox;
47
 
        GtkWidget *check;
48
 
};
49
 
 
50
 
 
51
 
guint
52
 
mg_entry_boolean_get_type (void)
53
 
{
54
 
        static GType type = 0;
55
 
 
56
 
        if (!type) {
57
 
                static const GTypeInfo info = {
58
 
                        sizeof (MgEntryBooleanClass),
59
 
                        (GBaseInitFunc) NULL,
60
 
                        (GBaseFinalizeFunc) NULL,
61
 
                        (GClassInitFunc) mg_entry_boolean_class_init,
62
 
                        NULL,
63
 
                        NULL,
64
 
                        sizeof (MgEntryBoolean),
65
 
                        0,
66
 
                        (GInstanceInitFunc) mg_entry_boolean_init
67
 
                };
68
 
                
69
 
                type = g_type_register_static (MG_ENTRY_WRAPPER_TYPE, "MgEntryBoolean", &info, 0);
70
 
        }
71
 
        return type;
72
 
}
73
 
 
74
 
static void
75
 
mg_entry_boolean_class_init (MgEntryBooleanClass * class)
76
 
{
77
 
        GObjectClass   *object_class = G_OBJECT_CLASS (class);
78
 
 
79
 
        parent_class = g_type_class_peek_parent (class);
80
 
 
81
 
        object_class->dispose = mg_entry_boolean_dispose;
82
 
        object_class->finalize = mg_entry_boolean_finalize;
83
 
 
84
 
        MG_ENTRY_WRAPPER_CLASS (class)->create_entry = create_entry;
85
 
        MG_ENTRY_WRAPPER_CLASS (class)->real_set_value = real_set_value;
86
 
        MG_ENTRY_WRAPPER_CLASS (class)->real_get_value = real_get_value;
87
 
        MG_ENTRY_WRAPPER_CLASS (class)->connect_signals = connect_signals;
88
 
        MG_ENTRY_WRAPPER_CLASS (class)->expand_in_layout = expand_in_layout;
89
 
}
90
 
 
91
 
static void
92
 
mg_entry_boolean_init (MgEntryBoolean * mg_entry_boolean)
93
 
{
94
 
        mg_entry_boolean->priv = g_new0 (MgEntryBooleanPrivate, 1);
95
 
        mg_entry_boolean->priv->hbox = NULL;
96
 
        mg_entry_boolean->priv->check = NULL;
97
 
}
98
 
 
99
 
/**
100
 
 * mg_entry_boolean_new
101
 
 * @dh: the data handler to be used by the new widget
102
 
 * @type: the requested data type (compatible with @dh)
103
 
 *
104
 
 * Creates a new widget which is mainly a GtkEntry
105
 
 *
106
 
 * Returns: the new widget
107
 
 */
108
 
GtkWidget *
109
 
mg_entry_boolean_new (MgDataHandler *dh, GdaValueType type)
110
 
{
111
 
        GObject *obj;
112
 
        MgEntryBoolean *mgbool;
113
 
 
114
 
        g_return_val_if_fail (dh && IS_MG_DATA_HANDLER (dh), NULL);
115
 
        g_return_val_if_fail (type != GDA_VALUE_TYPE_UNKNOWN, NULL);
116
 
        g_return_val_if_fail (mg_data_handler_accepts_gda_type (dh, type), NULL);
117
 
 
118
 
        obj = g_object_new (MG_ENTRY_BOOLEAN_TYPE, "handler", dh, NULL);
119
 
        mgbool = MG_ENTRY_BOOLEAN (obj);
120
 
        mg_data_entry_set_value_type (MG_DATA_ENTRY (mgbool), type);
121
 
 
122
 
        return GTK_WIDGET (obj);
123
 
}
124
 
 
125
 
 
126
 
static void
127
 
mg_entry_boolean_dispose (GObject   * object)
128
 
{
129
 
        MgEntryBoolean *mg_entry_boolean;
130
 
 
131
 
        g_return_if_fail (object != NULL);
132
 
        g_return_if_fail (IS_MG_ENTRY_BOOLEAN (object));
133
 
 
134
 
        mg_entry_boolean = MG_ENTRY_BOOLEAN (object);
135
 
        if (mg_entry_boolean->priv) {
136
 
 
137
 
        }
138
 
 
139
 
        /* parent class */
140
 
        parent_class->dispose (object);
141
 
}
142
 
 
143
 
static void
144
 
mg_entry_boolean_finalize (GObject   * object)
145
 
{
146
 
        MgEntryBoolean *mg_entry_boolean;
147
 
 
148
 
        g_return_if_fail (object != NULL);
149
 
        g_return_if_fail (IS_MG_ENTRY_BOOLEAN (object));
150
 
 
151
 
        mg_entry_boolean = MG_ENTRY_BOOLEAN (object);
152
 
        if (mg_entry_boolean->priv) {
153
 
 
154
 
                g_free (mg_entry_boolean->priv);
155
 
                mg_entry_boolean->priv = NULL;
156
 
        }
157
 
 
158
 
        /* parent class */
159
 
        parent_class->finalize (object);
160
 
}
161
 
 
162
 
static GtkWidget *
163
 
create_entry (MgEntryWrapper *mgwrap)
164
 
{
165
 
        GtkWidget *hbox, *cb, *label;
166
 
        MgEntryBoolean *mgbool;
167
 
 
168
 
        g_return_val_if_fail (mgwrap && IS_MG_ENTRY_BOOLEAN (mgwrap), NULL);
169
 
        mgbool = MG_ENTRY_BOOLEAN (mgwrap);
170
 
        g_return_val_if_fail (mgbool->priv, NULL);
171
 
 
172
 
        hbox = gtk_hbox_new (FALSE, 5);
173
 
        mgbool->priv->hbox = hbox;
174
 
 
175
 
        cb = gtk_check_button_new ();
176
 
        mgbool->priv->check = cb;
177
 
        gtk_box_pack_start (GTK_BOX (hbox), cb, FALSE, FALSE, 0);
178
 
        gtk_widget_show (cb);
179
 
 
180
 
        return hbox;
181
 
}
182
 
 
183
 
static void
184
 
real_set_value (MgEntryWrapper *mgwrap, const GdaValue *value)
185
 
{
186
 
        MgEntryBoolean *mgbool;
187
 
 
188
 
        g_return_if_fail (mgwrap && IS_MG_ENTRY_BOOLEAN (mgwrap));
189
 
        mgbool = MG_ENTRY_BOOLEAN (mgwrap);
190
 
        g_return_if_fail (mgbool->priv);
191
 
 
192
 
        if (value) {
193
 
                if (gda_value_is_null (value)) {
194
 
                        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (mgbool->priv->check), FALSE);
195
 
                        gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (mgbool->priv->check), TRUE);
196
 
                }
197
 
                else {
198
 
                        gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (mgbool->priv->check), FALSE);
199
 
                        if (gda_value_get_boolean (value)) 
200
 
                                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (mgbool->priv->check), TRUE);
201
 
                        else 
202
 
                                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (mgbool->priv->check), FALSE);
203
 
                }
204
 
        }
205
 
        else {
206
 
                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (mgbool->priv->check), FALSE);
207
 
                gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (mgbool->priv->check), TRUE);
208
 
        }
209
 
}
210
 
 
211
 
static GdaValue *
212
 
real_get_value (MgEntryWrapper *mgwrap)
213
 
{
214
 
        GdaValue *value;
215
 
        MgEntryBoolean *mgbool;
216
 
        MgDataHandler *dh;
217
 
        const gchar *str;
218
 
 
219
 
        g_return_val_if_fail (mgwrap && IS_MG_ENTRY_BOOLEAN (mgwrap), NULL);
220
 
        mgbool = MG_ENTRY_BOOLEAN (mgwrap);
221
 
        g_return_val_if_fail (mgbool->priv, NULL);
222
 
 
223
 
        dh = mg_data_entry_get_handler (MG_DATA_ENTRY (mgwrap));
224
 
        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (mgbool->priv->check)))
225
 
                str = "TRUE";
226
 
        else
227
 
                str = "FALSE";
228
 
        value = mg_data_handler_get_value_from_sql (dh, str, mg_data_entry_get_value_type (MG_DATA_ENTRY (mgwrap)));
229
 
 
230
 
        return value;
231
 
}
232
 
 
233
 
static void check_toggled_cb (GtkToggleButton *toggle, MgEntryBoolean *mgbool);
234
 
static void
235
 
connect_signals(MgEntryWrapper *mgwrap, GCallback callback)
236
 
{
237
 
        MgEntryBoolean *mgbool;
238
 
 
239
 
        g_return_if_fail (mgwrap && IS_MG_ENTRY_BOOLEAN (mgwrap));
240
 
        mgbool = MG_ENTRY_BOOLEAN (mgwrap);
241
 
        g_return_if_fail (mgbool->priv);
242
 
 
243
 
        g_signal_connect (G_OBJECT (mgbool->priv->check), "toggled",
244
 
                          callback, mgwrap);
245
 
        g_signal_connect (G_OBJECT (mgbool->priv->check), "toggled",
246
 
                          G_CALLBACK (check_toggled_cb), mgwrap);
247
 
}
248
 
 
249
 
static void
250
 
check_toggled_cb (GtkToggleButton *toggle, MgEntryBoolean *mgbool)
251
 
{
252
 
        gtk_toggle_button_set_inconsistent (toggle, FALSE);
253
 
}
254
 
 
255
 
static gboolean
256
 
expand_in_layout (MgEntryWrapper *mgwrap)
257
 
{
258
 
        return FALSE;
259
 
}