~ubuntu-branches/ubuntu/precise/deja-dup/precise-updates

« back to all changes in this revision

Viewing changes to widgets/ConfigChoice.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Terry
  • Date: 2010-01-10 10:03:06 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20100110100306-awjywmnuln6yusb9
Tags: upstream-13.5
ImportĀ upstreamĀ versionĀ 13.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ConfigChoice.c generated by valac, the Vala compiler
 
2
 * generated from ConfigChoice.vala, do not modify */
 
3
 
 
4
/* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 2 -*- */
 
5
/*
 
6
    This file is part of DĆ©jĆ  Dup.
 
7
    Ā© 2008,2009 Michael Terry <mike@mterry.name>
 
8
 
 
9
    DĆ©jĆ  Dup is free software: you can redistribute it and/or modify
 
10
    it under the terms of the GNU General Public License as published by
 
11
    the Free Software Foundation, either version 3 of the License, or
 
12
    (at your option) any later version.
 
13
 
 
14
    DĆ©jĆ  Dup is distributed in the hope that it will be useful,
 
15
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
    GNU General Public License for more details.
 
18
 
 
19
    You should have received a copy of the GNU General Public License
 
20
    along with DĆ©jĆ  Dup.  If not, see <http://www.gnu.org/licenses/>.
 
21
*/
 
22
 
 
23
#include <glib.h>
 
24
#include <glib-object.h>
 
25
#include <gtk/gtk.h>
 
26
#include <gconf/gconf-client.h>
 
27
#include <stdlib.h>
 
28
#include <string.h>
 
29
 
 
30
 
 
31
#define DEJA_DUP_TYPE_CONFIG_WIDGET (deja_dup_config_widget_get_type ())
 
32
#define DEJA_DUP_CONFIG_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DEJA_DUP_TYPE_CONFIG_WIDGET, DejaDupConfigWidget))
 
33
#define DEJA_DUP_CONFIG_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DEJA_DUP_TYPE_CONFIG_WIDGET, DejaDupConfigWidgetClass))
 
34
#define DEJA_DUP_IS_CONFIG_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DEJA_DUP_TYPE_CONFIG_WIDGET))
 
35
#define DEJA_DUP_IS_CONFIG_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DEJA_DUP_TYPE_CONFIG_WIDGET))
 
36
#define DEJA_DUP_CONFIG_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DEJA_DUP_TYPE_CONFIG_WIDGET, DejaDupConfigWidgetClass))
 
37
 
 
38
typedef struct _DejaDupConfigWidget DejaDupConfigWidget;
 
39
typedef struct _DejaDupConfigWidgetClass DejaDupConfigWidgetClass;
 
40
typedef struct _DejaDupConfigWidgetPrivate DejaDupConfigWidgetPrivate;
 
41
 
 
42
#define DEJA_DUP_TYPE_CONFIG_CHOICE (deja_dup_config_choice_get_type ())
 
43
#define DEJA_DUP_CONFIG_CHOICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DEJA_DUP_TYPE_CONFIG_CHOICE, DejaDupConfigChoice))
 
44
#define DEJA_DUP_CONFIG_CHOICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DEJA_DUP_TYPE_CONFIG_CHOICE, DejaDupConfigChoiceClass))
 
45
#define DEJA_DUP_IS_CONFIG_CHOICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DEJA_DUP_TYPE_CONFIG_CHOICE))
 
46
#define DEJA_DUP_IS_CONFIG_CHOICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DEJA_DUP_TYPE_CONFIG_CHOICE))
 
47
#define DEJA_DUP_CONFIG_CHOICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DEJA_DUP_TYPE_CONFIG_CHOICE, DejaDupConfigChoiceClass))
 
48
 
 
49
typedef struct _DejaDupConfigChoice DejaDupConfigChoice;
 
50
typedef struct _DejaDupConfigChoiceClass DejaDupConfigChoiceClass;
 
51
typedef struct _DejaDupConfigChoicePrivate DejaDupConfigChoicePrivate;
 
52
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
 
53
#define _g_free0(var) (var = (g_free (var), NULL))
 
54
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
 
55
 
 
56
struct _DejaDupConfigWidget {
 
57
        GtkEventBox parent_instance;
 
58
        DejaDupConfigWidgetPrivate * priv;
 
59
        GConfClient* client;
 
60
};
 
61
 
 
62
struct _DejaDupConfigWidgetClass {
 
63
        GtkEventBoxClass parent_class;
 
64
        void (*set_from_config) (DejaDupConfigWidget* self);
 
65
};
 
66
 
 
67
struct _DejaDupConfigChoice {
 
68
        DejaDupConfigWidget parent_instance;
 
69
        DejaDupConfigChoicePrivate * priv;
 
70
        GtkComboBox* combo;
 
71
        char* default_val;
 
72
        gint gconf_col;
 
73
};
 
74
 
 
75
struct _DejaDupConfigChoiceClass {
 
76
        DejaDupConfigWidgetClass parent_class;
 
77
        void (*handle_changed) (DejaDupConfigChoice* self);
 
78
};
 
79
 
 
80
 
 
81
static gpointer deja_dup_config_choice_parent_class = NULL;
 
82
 
 
83
GType deja_dup_config_widget_get_type (void);
 
84
GType deja_dup_config_choice_get_type (void);
 
85
enum  {
 
86
        DEJA_DUP_CONFIG_CHOICE_DUMMY_PROPERTY
 
87
};
 
88
void deja_dup_config_choice_handle_changed (DejaDupConfigChoice* self);
 
89
static void _deja_dup_config_choice_handle_changed_gtk_combo_box_changed (GtkComboBox* _sender, gpointer self);
 
90
void deja_dup_config_widget_set_from_config (DejaDupConfigWidget* self);
 
91
void deja_dup_config_choice_init (DejaDupConfigChoice* self, GtkTreeModel* model, gint gconf_col);
 
92
static GValue* _g_value_dup (GValue* self);
 
93
GValue* deja_dup_config_choice_get_current_value (DejaDupConfigChoice* self);
 
94
const char* deja_dup_config_widget_get_key (DejaDupConfigWidget* self);
 
95
static void deja_dup_config_choice_real_handle_changed (DejaDupConfigChoice* self);
 
96
static void deja_dup_config_choice_real_set_from_config (DejaDupConfigWidget* base);
 
97
DejaDupConfigChoice* deja_dup_config_choice_new (void);
 
98
DejaDupConfigChoice* deja_dup_config_choice_construct (GType object_type);
 
99
static GObject * deja_dup_config_choice_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
 
100
static void deja_dup_config_choice_finalize (GObject* obj);
 
101
static int _vala_strcmp0 (const char * str1, const char * str2);
 
102
 
 
103
 
 
104
 
 
105
static void _deja_dup_config_choice_handle_changed_gtk_combo_box_changed (GtkComboBox* _sender, gpointer self) {
 
106
        deja_dup_config_choice_handle_changed (self);
 
107
}
 
108
 
 
109
 
 
110
void deja_dup_config_choice_init (DejaDupConfigChoice* self, GtkTreeModel* model, gint gconf_col) {
 
111
        g_return_if_fail (self != NULL);
 
112
        g_return_if_fail (model != NULL);
 
113
        gtk_combo_box_set_model (self->combo, model);
 
114
        self->gconf_col = gconf_col;
 
115
        g_signal_connect_object (self->combo, "changed", (GCallback) _deja_dup_config_choice_handle_changed_gtk_combo_box_changed, self, 0);
 
116
        deja_dup_config_widget_set_from_config ((DejaDupConfigWidget*) self);
 
117
}
 
118
 
 
119
 
 
120
static GValue* _g_value_dup (GValue* self) {
 
121
        return g_boxed_copy (G_TYPE_VALUE, self);
 
122
}
 
123
 
 
124
 
 
125
static gpointer __g_value_dup0 (gpointer self) {
 
126
        return self ? _g_value_dup (self) : NULL;
 
127
}
 
128
 
 
129
 
 
130
GValue* deja_dup_config_choice_get_current_value (DejaDupConfigChoice* self) {
 
131
        GValue* result;
 
132
        GtkTreeIter iter = {0};
 
133
        g_return_val_if_fail (self != NULL, NULL);
 
134
        if (gtk_combo_box_get_active_iter (self->combo, &iter)) {
 
135
                GValue val = {0};
 
136
                GValue _tmp1_;
 
137
                GValue _tmp0_ = {0};
 
138
                GValue _tmp3_;
 
139
                GValue _tmp2_;
 
140
                GValue* _tmp4_;
 
141
                gtk_tree_model_get_value (gtk_combo_box_get_model (self->combo), &iter, self->gconf_col, &_tmp0_);
 
142
                val = (_tmp1_ = _tmp0_, G_IS_VALUE (&val) ? (g_value_unset (&val), NULL) : NULL, _tmp1_);
 
143
                result = (_tmp4_ = __g_value_dup0 ((_tmp3_ = _tmp2_ = val, &_tmp3_)), G_IS_VALUE (&_tmp2_) ? (g_value_unset (&_tmp2_), NULL) : NULL, _tmp4_);
 
144
                return result;
 
145
                G_IS_VALUE (&val) ? (g_value_unset (&val), NULL) : NULL;
 
146
        }
 
147
        result = NULL;
 
148
        return result;
 
149
}
 
150
 
 
151
 
 
152
static void deja_dup_config_choice_real_handle_changed (DejaDupConfigChoice* self) {
 
153
        GError * _inner_error_;
 
154
        GValue* val;
 
155
        const char* _tmp0_;
 
156
        char* strval;
 
157
        g_return_if_fail (self != NULL);
 
158
        _inner_error_ = NULL;
 
159
        val = deja_dup_config_choice_get_current_value (self);
 
160
        _tmp0_ = NULL;
 
161
        if (val == NULL) {
 
162
                _tmp0_ = "";
 
163
        } else {
 
164
                _tmp0_ = g_value_get_string (val);
 
165
        }
 
166
        strval = g_strdup (_tmp0_);
 
167
        {
 
168
                gconf_client_set_string (((DejaDupConfigWidget*) self)->client, deja_dup_config_widget_get_key ((DejaDupConfigWidget*) self), strval, &_inner_error_);
 
169
                if (_inner_error_ != NULL) {
 
170
                        goto __catch3_g_error;
 
171
                        goto __finally3;
 
172
                }
 
173
        }
 
174
        goto __finally3;
 
175
        __catch3_g_error:
 
176
        {
 
177
                GError * e;
 
178
                e = _inner_error_;
 
179
                _inner_error_ = NULL;
 
180
                {
 
181
                        g_warning ("ConfigChoice.vala:67: %s\n", e->message);
 
182
                        _g_error_free0 (e);
 
183
                }
 
184
        }
 
185
        __finally3:
 
186
        if (_inner_error_ != NULL) {
 
187
                _g_free0 (val);
 
188
                _g_free0 (strval);
 
189
                g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
190
                g_clear_error (&_inner_error_);
 
191
                return;
 
192
        }
 
193
        g_signal_emit_by_name (self, "choice-changed", strval);
 
194
        _g_free0 (val);
 
195
        _g_free0 (strval);
 
196
}
 
197
 
 
198
 
 
199
void deja_dup_config_choice_handle_changed (DejaDupConfigChoice* self) {
 
200
        DEJA_DUP_CONFIG_CHOICE_GET_CLASS (self)->handle_changed (self);
 
201
}
 
202
 
 
203
 
 
204
static void deja_dup_config_choice_real_set_from_config (DejaDupConfigWidget* base) {
 
205
        DejaDupConfigChoice * self;
 
206
        GError * _inner_error_;
 
207
        char* confval;
 
208
        gboolean _tmp2_ = FALSE;
 
209
        gboolean valid = FALSE;
 
210
        GtkTreeIter iter = {0};
 
211
        self = (DejaDupConfigChoice*) base;
 
212
        _inner_error_ = NULL;
 
213
        confval = NULL;
 
214
        {
 
215
                const char* _tmp0_;
 
216
                char* _tmp1_;
 
217
                _tmp0_ = gconf_client_get_string (((DejaDupConfigWidget*) self)->client, deja_dup_config_widget_get_key ((DejaDupConfigWidget*) self), &_inner_error_);
 
218
                if (_inner_error_ != NULL) {
 
219
                        goto __catch4_g_error;
 
220
                        goto __finally4;
 
221
                }
 
222
                confval = (_tmp1_ = g_strdup (_tmp0_), _g_free0 (confval), _tmp1_);
 
223
        }
 
224
        goto __finally4;
 
225
        __catch4_g_error:
 
226
        {
 
227
                GError * e;
 
228
                e = _inner_error_;
 
229
                _inner_error_ = NULL;
 
230
                {
 
231
                        g_warning ("ConfigChoice.vala:80: %s\n", e->message);
 
232
                        _g_error_free0 (e);
 
233
                }
 
234
        }
 
235
        __finally4:
 
236
        if (_inner_error_ != NULL) {
 
237
                _g_free0 (confval);
 
238
                g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
239
                g_clear_error (&_inner_error_);
 
240
                return;
 
241
        }
 
242
        if (confval == NULL) {
 
243
                _tmp2_ = TRUE;
 
244
        } else {
 
245
                _tmp2_ = _vala_strcmp0 (confval, "") == 0;
 
246
        }
 
247
        if (_tmp2_) {
 
248
                char* _tmp3_;
 
249
                confval = (_tmp3_ = g_strdup (self->default_val), _g_free0 (confval), _tmp3_);
 
250
        }
 
251
        if (confval == NULL) {
 
252
                _g_free0 (confval);
 
253
                return;
 
254
        }
 
255
        valid = gtk_tree_model_get_iter_first (gtk_combo_box_get_model (self->combo), &iter);
 
256
        while (TRUE) {
 
257
                GValue val = {0};
 
258
                GValue _tmp5_;
 
259
                GValue _tmp4_ = {0};
 
260
                char* strval;
 
261
                if (!valid) {
 
262
                        break;
 
263
                }
 
264
                gtk_tree_model_get_value (gtk_combo_box_get_model (self->combo), &iter, self->gconf_col, &_tmp4_);
 
265
                val = (_tmp5_ = _tmp4_, G_IS_VALUE (&val) ? (g_value_unset (&val), NULL) : NULL, _tmp5_);
 
266
                strval = g_strdup (g_value_get_string (&val));
 
267
                if (_vala_strcmp0 (strval, confval) == 0) {
 
268
                        gtk_combo_box_set_active_iter (self->combo, &iter);
 
269
                        G_IS_VALUE (&val) ? (g_value_unset (&val), NULL) : NULL;
 
270
                        _g_free0 (strval);
 
271
                        break;
 
272
                }
 
273
                valid = gtk_tree_model_iter_next (gtk_combo_box_get_model (self->combo), &iter);
 
274
                G_IS_VALUE (&val) ? (g_value_unset (&val), NULL) : NULL;
 
275
                _g_free0 (strval);
 
276
        }
 
277
        _g_free0 (confval);
 
278
}
 
279
 
 
280
 
 
281
DejaDupConfigChoice* deja_dup_config_choice_construct (GType object_type) {
 
282
        DejaDupConfigChoice * self;
 
283
        self = g_object_newv (object_type, 0, NULL);
 
284
        return self;
 
285
}
 
286
 
 
287
 
 
288
DejaDupConfigChoice* deja_dup_config_choice_new (void) {
 
289
        return deja_dup_config_choice_construct (DEJA_DUP_TYPE_CONFIG_CHOICE);
 
290
}
 
291
 
 
292
 
 
293
static GObject * deja_dup_config_choice_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
 
294
        GObject * obj;
 
295
        GObjectClass * parent_class;
 
296
        DejaDupConfigChoice * self;
 
297
        parent_class = G_OBJECT_CLASS (deja_dup_config_choice_parent_class);
 
298
        obj = parent_class->constructor (type, n_construct_properties, construct_properties);
 
299
        self = DEJA_DUP_CONFIG_CHOICE (obj);
 
300
        {
 
301
                GtkComboBox* _tmp0_;
 
302
                self->combo = (_tmp0_ = g_object_ref_sink ((GtkComboBox*) gtk_combo_box_new_text ()), _g_object_unref0 (self->combo), _tmp0_);
 
303
                gtk_container_add ((GtkContainer*) self, (GtkWidget*) self->combo);
 
304
        }
 
305
        return obj;
 
306
}
 
307
 
 
308
 
 
309
static void deja_dup_config_choice_class_init (DejaDupConfigChoiceClass * klass) {
 
310
        deja_dup_config_choice_parent_class = g_type_class_peek_parent (klass);
 
311
        DEJA_DUP_CONFIG_CHOICE_CLASS (klass)->handle_changed = deja_dup_config_choice_real_handle_changed;
 
312
        DEJA_DUP_CONFIG_WIDGET_CLASS (klass)->set_from_config = deja_dup_config_choice_real_set_from_config;
 
313
        G_OBJECT_CLASS (klass)->constructor = deja_dup_config_choice_constructor;
 
314
        G_OBJECT_CLASS (klass)->finalize = deja_dup_config_choice_finalize;
 
315
        g_signal_new ("choice_changed", DEJA_DUP_TYPE_CONFIG_CHOICE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING);
 
316
}
 
317
 
 
318
 
 
319
static void deja_dup_config_choice_instance_init (DejaDupConfigChoice * self) {
 
320
        self->default_val = NULL;
 
321
}
 
322
 
 
323
 
 
324
static void deja_dup_config_choice_finalize (GObject* obj) {
 
325
        DejaDupConfigChoice * self;
 
326
        self = DEJA_DUP_CONFIG_CHOICE (obj);
 
327
        _g_object_unref0 (self->combo);
 
328
        _g_free0 (self->default_val);
 
329
        G_OBJECT_CLASS (deja_dup_config_choice_parent_class)->finalize (obj);
 
330
}
 
331
 
 
332
 
 
333
GType deja_dup_config_choice_get_type (void) {
 
334
        static GType deja_dup_config_choice_type_id = 0;
 
335
        if (deja_dup_config_choice_type_id == 0) {
 
336
                static const GTypeInfo g_define_type_info = { sizeof (DejaDupConfigChoiceClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) deja_dup_config_choice_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DejaDupConfigChoice), 0, (GInstanceInitFunc) deja_dup_config_choice_instance_init, NULL };
 
337
                deja_dup_config_choice_type_id = g_type_register_static (DEJA_DUP_TYPE_CONFIG_WIDGET, "DejaDupConfigChoice", &g_define_type_info, 0);
 
338
        }
 
339
        return deja_dup_config_choice_type_id;
 
340
}
 
341
 
 
342
 
 
343
static int _vala_strcmp0 (const char * str1, const char * str2) {
 
344
        if (str1 == NULL) {
 
345
                return -(str1 != str2);
 
346
        }
 
347
        if (str2 == NULL) {
 
348
                return str1 != str2;
 
349
        }
 
350
        return strcmp (str1, str2);
 
351
}
 
352
 
 
353
 
 
354
 
 
355