Blob Blame History Raw
/* application.c generated by valac 0.40.8, the Vala compiler
 * generated from application.vala, do not modify */

/* vim:set et sts=4 sw=4:
 *
 * ibus - The Input Bus
 *
 * Copyright(c) 2011 Peng Huang <shawn.p.huang@gmail.com>
 * Copyright(c) 2017 Takao Fujiwara <takao.fujiwara1@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
 * USA
 */


#include <glib.h>
#include <glib-object.h>
#include <ibus.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>
#include <config.h>
#include <gtk/gtk.h>
#include <gio/gio.h>
#include <gdk/gdk.h>
#include <gobject/gvaluecollector.h>


#define TYPE_APPLICATION (application_get_type ())
#define APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_APPLICATION, Application))
#define APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_APPLICATION, ApplicationClass))
#define IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_APPLICATION))
#define IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_APPLICATION))
#define APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_APPLICATION, ApplicationClass))

typedef struct _Application Application;
typedef struct _ApplicationClass ApplicationClass;
typedef struct _ApplicationPrivate ApplicationPrivate;

#define TYPE_PANEL (panel_get_type ())
#define PANEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PANEL, Panel))
#define PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PANEL, PanelClass))
#define IS_PANEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PANEL))
#define IS_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PANEL))
#define PANEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PANEL, PanelClass))

typedef struct _Panel Panel;
typedef struct _PanelClass PanelClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _application_unref0(var) ((var == NULL) ? NULL : (var = (application_unref (var), NULL)))
typedef struct _ParamSpecApplication ParamSpecApplication;

struct _Application {
	GTypeInstance parent_instance;
	volatile int ref_count;
	ApplicationPrivate * priv;
};

struct _ApplicationClass {
	GTypeClass parent_class;
	void (*finalize) (Application *self);
};

struct _ApplicationPrivate {
	IBusBus* m_bus;
	Panel* m_panel;
};

struct _ParamSpecApplication {
	GParamSpec parent_instance;
};


static gpointer application_parent_class = NULL;

gpointer application_ref (gpointer instance);
void application_unref (gpointer instance);
GParamSpec* param_spec_application (const gchar* name,
                                    const gchar* nick,
                                    const gchar* blurb,
                                    GType object_type,
                                    GParamFlags flags);
void value_set_application (GValue* value,
                            gpointer v_object);
void value_take_application (GValue* value,
                             gpointer v_object);
gpointer value_get_application (const GValue* value);
GType application_get_type (void) G_GNUC_CONST;
GType panel_get_type (void) G_GNUC_CONST;
#define APPLICATION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_APPLICATION, ApplicationPrivate))
Application* application_new (gchar** argv,
                              int argv_length1);
Application* application_construct (GType object_type,
                                    gchar** argv,
                                    int argv_length1);
static void application_bus_connected (Application* self,
                                IBusBus* bus);
static void _application_bus_connected_ibus_bus_connected (IBusBus* _sender,
                                                    gpointer self);
static void application_bus_disconnected (Application* self,
                                   IBusBus* bus);
static void _application_bus_disconnected_ibus_bus_disconnected (IBusBus* _sender,
                                                          gpointer self);
static void application_init (Application* self);
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);
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);
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);
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);
gint application_run (Application* self);
Panel* panel_new (IBusBus* bus);
Panel* panel_construct (GType object_type,
                        IBusBus* bus);
void panel_load_settings (Panel* self);
void panel_disconnect_signals (Panel* self);
void application_main (gchar** argv,
                       int argv_length1);
static void application_finalize (Application * obj);


static void
_application_bus_connected_ibus_bus_connected (IBusBus* _sender,
                                               gpointer self)
{
	application_bus_connected ((Application*) self, _sender);
}


static void
_application_bus_disconnected_ibus_bus_disconnected (IBusBus* _sender,
                                                     gpointer self)
{
	application_bus_disconnected ((Application*) self, _sender);
}


Application*
application_construct (GType object_type,
                       gchar** argv,
                       int argv_length1)
{
	Application* self = NULL;
	IBusBus* _tmp0_;
	IBusBus* _tmp1_;
	IBusBus* _tmp2_;
	IBusBus* _tmp3_;
	self = (Application*) g_type_create_instance (object_type);
	bindtextdomain (GETTEXT_PACKAGE, GLIB_LOCALE_DIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	ibus_init ();
	gtk_init (&argv_length1, &argv);
	_tmp0_ = ibus_bus_new ();
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->m_bus);
	self->priv->m_bus = _tmp0_;
	_tmp1_ = self->priv->m_bus;
	g_signal_connect (_tmp1_, "connected", (GCallback) _application_bus_connected_ibus_bus_connected, self);
	_tmp2_ = self->priv->m_bus;
	g_signal_connect (_tmp2_, "disconnected", (GCallback) _application_bus_disconnected_ibus_bus_disconnected, self);
	_tmp3_ = self->priv->m_bus;
	if (ibus_bus_is_connected (_tmp3_)) {
		application_init (self);
	}
	return self;
}


Application*
application_new (gchar** argv,
                 int argv_length1)
{
	return application_construct (TYPE_APPLICATION, argv, argv_length1);
}


static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}


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)
{
	application_bus_name_acquired_cb ((Application*) self, connection, sender_name, object_path, interface_name, signal_name, parameters);
}


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)
{
	application_bus_name_lost_cb ((Application*) self, connection, sender_name, object_path, interface_name, signal_name, parameters);
}


static void
application_init (Application* self)
{
	GDBusConnection* connection = NULL;
	IBusBus* _tmp0_;
	GDBusConnection* _tmp1_;
	GDBusConnection* _tmp2_;
	IBusBusNameFlag flags = 0;
	IBusBus* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->m_bus;
	_tmp1_ = ibus_bus_get_connection (_tmp0_);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	connection = _tmp2_;
	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);
	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);
	flags = IBUS_BUS_NAME_FLAG_ALLOW_REPLACEMENT | IBUS_BUS_NAME_FLAG_REPLACE_EXISTING;
	_tmp3_ = self->priv->m_bus;
	ibus_bus_request_name (_tmp3_, IBUS_SERVICE_PANEL, (guint32) flags);
	_g_object_unref0 (connection);
}


gint
application_run (Application* self)
{
	gint result = 0;
	g_return_val_if_fail (self != NULL, 0);
	gtk_main ();
	result = 0;
	return result;
}


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)
{
	IBusBus* _tmp0_;
	Panel* _tmp1_;
	Panel* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (connection != NULL);
	g_return_if_fail (sender_name != NULL);
	g_return_if_fail (object_path != NULL);
	g_return_if_fail (interface_name != NULL);
	g_return_if_fail (signal_name != NULL);
	g_return_if_fail (parameters != NULL);
	g_debug ("application.vala:78: signal_name = %s", signal_name);
	_tmp0_ = self->priv->m_bus;
	_tmp1_ = panel_new (_tmp0_);
	g_object_ref_sink (_tmp1_);
	_g_object_unref0 (self->priv->m_panel);
	self->priv->m_panel = _tmp1_;
	_tmp2_ = self->priv->m_panel;
	panel_load_settings (_tmp2_);
}


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)
{
	Panel* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (connection != NULL);
	g_return_if_fail (sender_name != NULL);
	g_return_if_fail (object_path != NULL);
	g_return_if_fail (interface_name != NULL);
	g_return_if_fail (signal_name != NULL);
	g_return_if_fail (parameters != NULL);
	g_debug ("application.vala:95: signal_name = %s", signal_name);
	_tmp0_ = self->priv->m_panel;
	panel_disconnect_signals (_tmp0_);
	_g_object_unref0 (self->priv->m_panel);
	self->priv->m_panel = NULL;
}


static void
application_bus_disconnected (Application* self,
                              IBusBus* bus)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (bus != NULL);
	g_debug ("application.vala:103: connection is lost.");
	gtk_main_quit ();
}


static void
application_bus_connected (Application* self,
                           IBusBus* bus)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (bus != NULL);
	application_init (self);
}


void
application_main (gchar** argv,
                  int argv_length1)
{
	Application* app = NULL;
	Application* _tmp0_;
	g_unsetenv ("GDK_CORE_DEVICE_EVENTS");
	gdk_set_allowed_backends ("x11");
	_tmp0_ = application_new (argv, argv_length1);
	app = _tmp0_;
	application_run (app);
	_application_unref0 (app);
}


int
main (int argc,
      char ** argv)
{
	application_main (argv, argc);
	return 0;
}


static void
value_application_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}


static void
value_application_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		application_unref (value->data[0].v_pointer);
	}
}


static void
value_application_copy_value (const GValue* src_value,
                              GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = application_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}


static gpointer
value_application_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}


static gchar*
value_application_collect_value (GValue* value,
                                 guint n_collect_values,
                                 GTypeCValue* collect_values,
                                 guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		Application * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = application_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}


static gchar*
value_application_lcopy_value (const GValue* value,
                               guint n_collect_values,
                               GTypeCValue* collect_values,
                               guint collect_flags)
{
	Application ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = application_ref (value->data[0].v_pointer);
	}
	return NULL;
}


GParamSpec*
param_spec_application (const gchar* name,
                        const gchar* nick,
                        const gchar* blurb,
                        GType object_type,
                        GParamFlags flags)
{
	ParamSpecApplication* spec;
	g_return_val_if_fail (g_type_is_a (object_type, TYPE_APPLICATION), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}


gpointer
value_get_application (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_APPLICATION), NULL);
	return value->data[0].v_pointer;
}


void
value_set_application (GValue* value,
                       gpointer v_object)
{
	Application * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_APPLICATION));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_APPLICATION));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		application_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		application_unref (old);
	}
}


void
value_take_application (GValue* value,
                        gpointer v_object)
{
	Application * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_APPLICATION));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_APPLICATION));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		application_unref (old);
	}
}


static void
application_class_init (ApplicationClass * klass)
{
	application_parent_class = g_type_class_peek_parent (klass);
	((ApplicationClass *) klass)->finalize = application_finalize;
	g_type_class_add_private (klass, sizeof (ApplicationPrivate));
}


static void
application_instance_init (Application * self)
{
	self->priv = APPLICATION_GET_PRIVATE (self);
	self->ref_count = 1;
}


static void
application_finalize (Application * obj)
{
	Application * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_APPLICATION, Application);
	g_signal_handlers_destroy (self);
	_g_object_unref0 (self->priv->m_bus);
	_g_object_unref0 (self->priv->m_panel);
}


GType
application_get_type (void)
{
	static volatile gsize application_type_id__volatile = 0;
	if (g_once_init_enter (&application_type_id__volatile)) {
		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 };
		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 };
		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) };
		GType application_type_id;
		application_type_id = g_type_register_fundamental (g_type_fundamental_next (), "Application", &g_define_type_info, &g_define_type_fundamental_info, 0);
		g_once_init_leave (&application_type_id__volatile, application_type_id);
	}
	return application_type_id__volatile;
}


gpointer
application_ref (gpointer instance)
{
	Application * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}


void
application_unref (gpointer instance)
{
	Application * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		APPLICATION_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}