Imported Upstream version 1.5.4
[platform/upstream/ibus.git] / ui / gtk3 / application.c
1 /* application.c generated by valac 0.20.1, the Vala compiler
2  * generated from application.vala, do not modify */
3
4 /* vim:set et sts=4 sw=4:
5  *
6  * ibus - The Input Bus
7  *
8  * Copyright(c) 2011 Peng Huang <shawn.p.huang@gmail.com>
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
23  * USA
24  */
25
26 #include <glib.h>
27 #include <glib-object.h>
28 #include <ibus.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <glib/gi18n-lib.h>
32 #include <config.h>
33 #include <gtk/gtk.h>
34 #include <gio/gio.h>
35 #include <gobject/gvaluecollector.h>
36
37
38 #define TYPE_APPLICATION (application_get_type ())
39 #define APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_APPLICATION, Application))
40 #define APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_APPLICATION, ApplicationClass))
41 #define IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_APPLICATION))
42 #define IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_APPLICATION))
43 #define APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_APPLICATION, ApplicationClass))
44
45 typedef struct _Application Application;
46 typedef struct _ApplicationClass ApplicationClass;
47 typedef struct _ApplicationPrivate ApplicationPrivate;
48
49 #define TYPE_PANEL (panel_get_type ())
50 #define PANEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PANEL, Panel))
51 #define PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PANEL, PanelClass))
52 #define IS_PANEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PANEL))
53 #define IS_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PANEL))
54 #define PANEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PANEL, PanelClass))
55
56 typedef struct _Panel Panel;
57 typedef struct _PanelClass PanelClass;
58 #define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
59 #define _application_unref0(var) ((var == NULL) ? NULL : (var = (application_unref (var), NULL)))
60 typedef struct _ParamSpecApplication ParamSpecApplication;
61
62 struct _Application {
63         GTypeInstance parent_instance;
64         volatile int ref_count;
65         ApplicationPrivate * priv;
66 };
67
68 struct _ApplicationClass {
69         GTypeClass parent_class;
70         void (*finalize) (Application *self);
71 };
72
73 struct _ApplicationPrivate {
74         IBusBus* m_bus;
75         Panel* m_panel;
76 };
77
78 struct _ParamSpecApplication {
79         GParamSpec parent_instance;
80 };
81
82
83 static gpointer application_parent_class = NULL;
84
85 gpointer application_ref (gpointer instance);
86 void application_unref (gpointer instance);
87 GParamSpec* param_spec_application (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
88 void value_set_application (GValue* value, gpointer v_object);
89 void value_take_application (GValue* value, gpointer v_object);
90 gpointer value_get_application (const GValue* value);
91 GType application_get_type (void) G_GNUC_CONST;
92 GType panel_get_type (void) G_GNUC_CONST;
93 #define APPLICATION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_APPLICATION, ApplicationPrivate))
94 enum  {
95         APPLICATION_DUMMY_PROPERTY
96 };
97 Application* application_new (gchar** argv, int argv_length1);
98 Application* application_construct (GType object_type, gchar** argv, int argv_length1);
99 static void application_bus_connected (Application* self, IBusBus* bus);
100 static void _application_bus_connected_ibus_bus_connected (IBusBus* _sender, gpointer self);
101 static void application_bus_disconnected (Application* self, IBusBus* bus);
102 static void _application_bus_disconnected_ibus_bus_disconnected (IBusBus* _sender, gpointer self);
103 static void application_init (Application* self);
104 static void application_bus_name_acquired_cb (Application* self, GDBusConnection* connection, const gchar* sender_name, const gchar* object_path, const gchar* interface_name, const gchar* signal_name, GVariant* parameters);
105 static void _application_bus_name_acquired_cb_gd_bus_signal_callback (GDBusConnection* connection, const gchar* sender_name, const gchar* object_path, const gchar* interface_name, const gchar* signal_name, GVariant* parameters, gpointer self);
106 static void application_bus_name_lost_cb (Application* self, GDBusConnection* connection, const gchar* sender_name, const gchar* object_path, const gchar* interface_name, const gchar* signal_name, GVariant* parameters);
107 static void _application_bus_name_lost_cb_gd_bus_signal_callback (GDBusConnection* connection, const gchar* sender_name, const gchar* object_path, const gchar* interface_name, const gchar* signal_name, GVariant* parameters, gpointer self);
108 gint application_run (Application* self);
109 Panel* panel_new (IBusBus* bus);
110 Panel* panel_construct (GType object_type, IBusBus* bus);
111 void panel_load_settings (Panel* self);
112 void application_main (gchar** argv, int argv_length1);
113 static void application_finalize (Application* obj);
114
115
116 static void _application_bus_connected_ibus_bus_connected (IBusBus* _sender, gpointer self) {
117         application_bus_connected (self, _sender);
118 }
119
120
121 static void _application_bus_disconnected_ibus_bus_disconnected (IBusBus* _sender, gpointer self) {
122         application_bus_disconnected (self, _sender);
123 }
124
125
126 Application* application_construct (GType object_type, gchar** argv, int argv_length1) {
127         Application* self = NULL;
128         IBusBus* _tmp0_;
129         IBusBus* _tmp1_;
130         IBusBus* _tmp2_;
131         IBusBus* _tmp3_;
132         gboolean _tmp4_ = FALSE;
133         self = (Application*) g_type_create_instance (object_type);
134         bindtextdomain (GETTEXT_PACKAGE, GLIB_LOCALE_DIR);
135         bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
136         ibus_init ();
137         gtk_init (&argv_length1, &argv);
138         _tmp0_ = ibus_bus_new ();
139         g_object_ref_sink (_tmp0_);
140         _g_object_unref0 (self->priv->m_bus);
141         self->priv->m_bus = _tmp0_;
142         _tmp1_ = self->priv->m_bus;
143         g_signal_connect (_tmp1_, "connected", (GCallback) _application_bus_connected_ibus_bus_connected, self);
144         _tmp2_ = self->priv->m_bus;
145         g_signal_connect (_tmp2_, "disconnected", (GCallback) _application_bus_disconnected_ibus_bus_disconnected, self);
146         _tmp3_ = self->priv->m_bus;
147         _tmp4_ = ibus_bus_is_connected (_tmp3_);
148         if (_tmp4_) {
149                 application_init (self);
150         }
151         return self;
152 }
153
154
155 Application* application_new (gchar** argv, int argv_length1) {
156         return application_construct (TYPE_APPLICATION, argv, argv_length1);
157 }
158
159
160 static gpointer _g_object_ref0 (gpointer self) {
161         return self ? g_object_ref (self) : NULL;
162 }
163
164
165 static void _application_bus_name_acquired_cb_gd_bus_signal_callback (GDBusConnection* connection, const gchar* sender_name, const gchar* object_path, const gchar* interface_name, const gchar* signal_name, GVariant* parameters, gpointer self) {
166         application_bus_name_acquired_cb (self, connection, sender_name, object_path, interface_name, signal_name, parameters);
167 }
168
169
170 static void _application_bus_name_lost_cb_gd_bus_signal_callback (GDBusConnection* connection, const gchar* sender_name, const gchar* object_path, const gchar* interface_name, const gchar* signal_name, GVariant* parameters, gpointer self) {
171         application_bus_name_lost_cb (self, connection, sender_name, object_path, interface_name, signal_name, parameters);
172 }
173
174
175 static void application_init (Application* self) {
176         IBusBus* _tmp0_;
177         GDBusConnection* _tmp1_ = NULL;
178         GDBusConnection* _tmp2_;
179         GDBusConnection* connection;
180         IBusBusNameFlag flags;
181         IBusBus* _tmp3_;
182         g_return_if_fail (self != NULL);
183         _tmp0_ = self->priv->m_bus;
184         _tmp1_ = ibus_bus_get_connection (_tmp0_);
185         _tmp2_ = _g_object_ref0 (_tmp1_);
186         connection = _tmp2_;
187         g_dbus_connection_signal_subscribe (connection, "org.freedesktop.DBus", "org.freedesktop.DBus", "NameAcquired", "/org/freedesktop/DBus", IBUS_SERVICE_PANEL, G_DBUS_SIGNAL_FLAGS_NONE, _application_bus_name_acquired_cb_gd_bus_signal_callback, application_ref (self), application_unref);
188         g_dbus_connection_signal_subscribe (connection, "org.freedesktop.DBus", "org.freedesktop.DBus", "NameLost", "/org/freedesktop/DBus", IBUS_SERVICE_PANEL, G_DBUS_SIGNAL_FLAGS_NONE, _application_bus_name_lost_cb_gd_bus_signal_callback, application_ref (self), application_unref);
189         flags = IBUS_BUS_NAME_FLAG_ALLOW_REPLACEMENT | IBUS_BUS_NAME_FLAG_REPLACE_EXISTING;
190         _tmp3_ = self->priv->m_bus;
191         ibus_bus_request_name (_tmp3_, IBUS_SERVICE_PANEL, (guint32) flags);
192         _g_object_unref0 (connection);
193 }
194
195
196 gint application_run (Application* self) {
197         gint result = 0;
198         g_return_val_if_fail (self != NULL, 0);
199         gtk_main ();
200         result = 0;
201         return result;
202 }
203
204
205 static void application_bus_name_acquired_cb (Application* self, GDBusConnection* connection, const gchar* sender_name, const gchar* object_path, const gchar* interface_name, const gchar* signal_name, GVariant* parameters) {
206         const gchar* _tmp0_;
207         IBusBus* _tmp1_;
208         Panel* _tmp2_;
209         Panel* _tmp3_;
210         g_return_if_fail (self != NULL);
211         g_return_if_fail (connection != NULL);
212         g_return_if_fail (sender_name != NULL);
213         g_return_if_fail (object_path != NULL);
214         g_return_if_fail (interface_name != NULL);
215         g_return_if_fail (signal_name != NULL);
216         g_return_if_fail (parameters != NULL);
217         _tmp0_ = signal_name;
218         g_debug ("application.vala:77: signal_name = %s", _tmp0_);
219         _tmp1_ = self->priv->m_bus;
220         _tmp2_ = panel_new (_tmp1_);
221         g_object_ref_sink (_tmp2_);
222         _g_object_unref0 (self->priv->m_panel);
223         self->priv->m_panel = _tmp2_;
224         _tmp3_ = self->priv->m_panel;
225         panel_load_settings (_tmp3_);
226 }
227
228
229 static void application_bus_name_lost_cb (Application* self, GDBusConnection* connection, const gchar* sender_name, const gchar* object_path, const gchar* interface_name, const gchar* signal_name, GVariant* parameters) {
230         const gchar* _tmp0_;
231         g_return_if_fail (self != NULL);
232         g_return_if_fail (connection != NULL);
233         g_return_if_fail (sender_name != NULL);
234         g_return_if_fail (object_path != NULL);
235         g_return_if_fail (interface_name != NULL);
236         g_return_if_fail (signal_name != NULL);
237         g_return_if_fail (parameters != NULL);
238         _tmp0_ = signal_name;
239         g_debug ("application.vala:88: signal_name = %s", _tmp0_);
240         _g_object_unref0 (self->priv->m_panel);
241         self->priv->m_panel = NULL;
242 }
243
244
245 static void application_bus_disconnected (Application* self, IBusBus* bus) {
246         g_return_if_fail (self != NULL);
247         g_return_if_fail (bus != NULL);
248         g_debug ("application.vala:93: connection is lost.");
249         gtk_main_quit ();
250 }
251
252
253 static void application_bus_connected (Application* self, IBusBus* bus) {
254         g_return_if_fail (self != NULL);
255         g_return_if_fail (bus != NULL);
256         application_init (self);
257 }
258
259
260 void application_main (gchar** argv, int argv_length1) {
261         gchar** _tmp0_;
262         gint _tmp0__length1;
263         Application* _tmp1_;
264         Application* app;
265         _tmp0_ = argv;
266         _tmp0__length1 = argv_length1;
267         _tmp1_ = application_new (_tmp0_, _tmp0__length1);
268         app = _tmp1_;
269         application_run (app);
270         _application_unref0 (app);
271 }
272
273
274 int main (int argc, char ** argv) {
275         g_type_init ();
276         application_main (argv, argc);
277         return 0;
278 }
279
280
281 static void value_application_init (GValue* value) {
282         value->data[0].v_pointer = NULL;
283 }
284
285
286 static void value_application_free_value (GValue* value) {
287         if (value->data[0].v_pointer) {
288                 application_unref (value->data[0].v_pointer);
289         }
290 }
291
292
293 static void value_application_copy_value (const GValue* src_value, GValue* dest_value) {
294         if (src_value->data[0].v_pointer) {
295                 dest_value->data[0].v_pointer = application_ref (src_value->data[0].v_pointer);
296         } else {
297                 dest_value->data[0].v_pointer = NULL;
298         }
299 }
300
301
302 static gpointer value_application_peek_pointer (const GValue* value) {
303         return value->data[0].v_pointer;
304 }
305
306
307 static gchar* value_application_collect_value (GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
308         if (collect_values[0].v_pointer) {
309                 Application* object;
310                 object = collect_values[0].v_pointer;
311                 if (object->parent_instance.g_class == NULL) {
312                         return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
313                 } else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
314                         return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
315                 }
316                 value->data[0].v_pointer = application_ref (object);
317         } else {
318                 value->data[0].v_pointer = NULL;
319         }
320         return NULL;
321 }
322
323
324 static gchar* value_application_lcopy_value (const GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
325         Application** object_p;
326         object_p = collect_values[0].v_pointer;
327         if (!object_p) {
328                 return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
329         }
330         if (!value->data[0].v_pointer) {
331                 *object_p = NULL;
332         } else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
333                 *object_p = value->data[0].v_pointer;
334         } else {
335                 *object_p = application_ref (value->data[0].v_pointer);
336         }
337         return NULL;
338 }
339
340
341 GParamSpec* param_spec_application (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags) {
342         ParamSpecApplication* spec;
343         g_return_val_if_fail (g_type_is_a (object_type, TYPE_APPLICATION), NULL);
344         spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
345         G_PARAM_SPEC (spec)->value_type = object_type;
346         return G_PARAM_SPEC (spec);
347 }
348
349
350 gpointer value_get_application (const GValue* value) {
351         g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_APPLICATION), NULL);
352         return value->data[0].v_pointer;
353 }
354
355
356 void value_set_application (GValue* value, gpointer v_object) {
357         Application* old;
358         g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_APPLICATION));
359         old = value->data[0].v_pointer;
360         if (v_object) {
361                 g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_APPLICATION));
362                 g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
363                 value->data[0].v_pointer = v_object;
364                 application_ref (value->data[0].v_pointer);
365         } else {
366                 value->data[0].v_pointer = NULL;
367         }
368         if (old) {
369                 application_unref (old);
370         }
371 }
372
373
374 void value_take_application (GValue* value, gpointer v_object) {
375         Application* old;
376         g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_APPLICATION));
377         old = value->data[0].v_pointer;
378         if (v_object) {
379                 g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_APPLICATION));
380                 g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
381                 value->data[0].v_pointer = v_object;
382         } else {
383                 value->data[0].v_pointer = NULL;
384         }
385         if (old) {
386                 application_unref (old);
387         }
388 }
389
390
391 static void application_class_init (ApplicationClass * klass) {
392         application_parent_class = g_type_class_peek_parent (klass);
393         APPLICATION_CLASS (klass)->finalize = application_finalize;
394         g_type_class_add_private (klass, sizeof (ApplicationPrivate));
395 }
396
397
398 static void application_instance_init (Application * self) {
399         self->priv = APPLICATION_GET_PRIVATE (self);
400         self->ref_count = 1;
401 }
402
403
404 static void application_finalize (Application* obj) {
405         Application * self;
406         self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_APPLICATION, Application);
407         _g_object_unref0 (self->priv->m_bus);
408         _g_object_unref0 (self->priv->m_panel);
409 }
410
411
412 GType application_get_type (void) {
413         static volatile gsize application_type_id__volatile = 0;
414         if (g_once_init_enter (&application_type_id__volatile)) {
415                 static const GTypeValueTable g_define_type_value_table = { value_application_init, value_application_free_value, value_application_copy_value, value_application_peek_pointer, "p", value_application_collect_value, "p", value_application_lcopy_value };
416                 static const GTypeInfo g_define_type_info = { sizeof (ApplicationClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) application_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Application), 0, (GInstanceInitFunc) application_instance_init, &g_define_type_value_table };
417                 static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
418                 GType application_type_id;
419                 application_type_id = g_type_register_fundamental (g_type_fundamental_next (), "Application", &g_define_type_info, &g_define_type_fundamental_info, 0);
420                 g_once_init_leave (&application_type_id__volatile, application_type_id);
421         }
422         return application_type_id__volatile;
423 }
424
425
426 gpointer application_ref (gpointer instance) {
427         Application* self;
428         self = instance;
429         g_atomic_int_inc (&self->ref_count);
430         return instance;
431 }
432
433
434 void application_unref (gpointer instance) {
435         Application* self;
436         self = instance;
437         if (g_atomic_int_dec_and_test (&self->ref_count)) {
438                 APPLICATION_GET_CLASS (self)->finalize (self);
439                 g_type_free_instance ((GTypeInstance *) self);
440         }
441 }
442
443
444