/* gkbdlayout.c generated by valac 0.20.1, the Vala compiler
 * generated from gkbdlayout.vala, do not modify */

/* vim:set et sts=4 sw=4:
 *
 * ibus - The Input Bus
 *
 * Copyright 2012 Red Hat, Inc.
 * Copyright(c) 2012 Peng Huang <shawn.p.huang@gmail.com>
 * Copyright(c) 2012 Takao Fujiwara <tfujiwar@redhat.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 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 program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA  02111-1307  USA
 */

#include <glib.h>
#include <glib-object.h>
#include <libgnomekbd/gkbd-configuration.h>
#include <stdlib.h>
#include <string.h>
#include <gobject/gvaluecollector.h>


#define TYPE_GKBD_LAYOUT (gkbd_layout_get_type ())
#define GKBD_LAYOUT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GKBD_LAYOUT, GkbdLayout))
#define GKBD_LAYOUT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_GKBD_LAYOUT, GkbdLayoutClass))
#define IS_GKBD_LAYOUT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_GKBD_LAYOUT))
#define IS_GKBD_LAYOUT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_GKBD_LAYOUT))
#define GKBD_LAYOUT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_GKBD_LAYOUT, GkbdLayoutClass))

typedef struct _GkbdLayout GkbdLayout;
typedef struct _GkbdLayoutClass GkbdLayoutClass;
typedef struct _GkbdLayoutPrivate GkbdLayoutPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _ParamSpecGkbdLayout ParamSpecGkbdLayout;

struct _GkbdLayout {
	GTypeInstance parent_instance;
	volatile int ref_count;
	GkbdLayoutPrivate * priv;
};

struct _GkbdLayoutClass {
	GTypeClass parent_class;
	void (*finalize) (GkbdLayout *self);
};

struct _GkbdLayoutPrivate {
	GkbdConfiguration* m_config;
};

struct _ParamSpecGkbdLayout {
	GParamSpec parent_instance;
};


static gpointer gkbd_layout_parent_class = NULL;

gpointer gkbd_layout_ref (gpointer instance);
void gkbd_layout_unref (gpointer instance);
GParamSpec* param_spec_gkbd_layout (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void value_set_gkbd_layout (GValue* value, gpointer v_object);
void value_take_gkbd_layout (GValue* value, gpointer v_object);
gpointer value_get_gkbd_layout (const GValue* value);
GType gkbd_layout_get_type (void) G_GNUC_CONST;
#define GKBD_LAYOUT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_GKBD_LAYOUT, GkbdLayoutPrivate))
enum  {
	GKBD_LAYOUT_DUMMY_PROPERTY
};
static void gkbd_layout_config_changed_cb (GkbdLayout* self);
static void _gkbd_layout_config_changed_cb_gkbd_configuration_changed (GkbdConfiguration* _sender, gpointer self);
static void gkbd_layout_config_group_changed_cb (GkbdLayout* self, gint object);
static void _gkbd_layout_config_group_changed_cb_gkbd_configuration_group_changed (GkbdConfiguration* _sender, gint object, gpointer self);
GkbdLayout* gkbd_layout_new (void);
GkbdLayout* gkbd_layout_construct (GType object_type);
gchar** gkbd_layout_get_layouts (GkbdLayout* self, int* result_length1);
static gchar** _vala_array_dup2 (gchar** self, int length);
gchar** gkbd_layout_get_group_names (GkbdLayout* self, int* result_length1);
static gchar** _vala_array_dup3 (gchar** self, int length);
void gkbd_layout_lock_group (GkbdLayout* self, gint id);
void gkbd_layout_start_listen (GkbdLayout* self);
void gkbd_layout_stop_listen (GkbdLayout* self);
static void gkbd_layout_finalize (GkbdLayout* obj);
static gint _vala_array_length (gpointer array);


static void _gkbd_layout_config_changed_cb_gkbd_configuration_changed (GkbdConfiguration* _sender, gpointer self) {
	gkbd_layout_config_changed_cb (self);
}


static void _gkbd_layout_config_group_changed_cb_gkbd_configuration_group_changed (GkbdConfiguration* _sender, gint object, gpointer self) {
	gkbd_layout_config_group_changed_cb (self, object);
}


GkbdLayout* gkbd_layout_construct (GType object_type) {
	GkbdLayout* self = NULL;
	GkbdConfiguration* _tmp0_ = NULL;
	GkbdConfiguration* _tmp1_;
	self = (GkbdLayout*) g_type_create_instance (object_type);
	_tmp0_ = gkbd_configuration_get ();
	_g_object_unref0 (self->priv->m_config);
	self->priv->m_config = _tmp0_;
	_tmp1_ = self->priv->m_config;
	if (_tmp1_ != NULL) {
		GkbdConfiguration* _tmp2_;
		GkbdConfiguration* _tmp3_;
		_tmp2_ = self->priv->m_config;
		g_signal_connect (_tmp2_, "changed", (GCallback) _gkbd_layout_config_changed_cb_gkbd_configuration_changed, self);
		_tmp3_ = self->priv->m_config;
		g_signal_connect (_tmp3_, "group-changed", (GCallback) _gkbd_layout_config_group_changed_cb_gkbd_configuration_group_changed, self);
	}
	return self;
}


GkbdLayout* gkbd_layout_new (void) {
	return gkbd_layout_construct (TYPE_GKBD_LAYOUT);
}


static void gkbd_layout_config_changed_cb (GkbdLayout* self) {
	g_return_if_fail (self != NULL);
	g_signal_emit_by_name (self, "changed");
}


static void gkbd_layout_config_group_changed_cb (GkbdLayout* self, gint object) {
	gint _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = object;
	g_signal_emit_by_name (self, "group-changed", _tmp0_);
}


static gchar** _vala_array_dup2 (gchar** self, int length) {
	gchar** result;
	int i;
	result = g_new0 (gchar*, length + 1);
	for (i = 0; i < length; i++) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (self[i]);
		result[i] = _tmp0_;
	}
	return result;
}


gchar** gkbd_layout_get_layouts (GkbdLayout* self, int* result_length1) {
	gchar** result = NULL;
	GkbdConfiguration* _tmp0_;
	GkbdConfiguration* _tmp3_;
	gchar** _tmp4_;
	gchar** _tmp5_ = NULL;
	gchar** _tmp6_;
	gint _tmp6__length1;
	gchar** _tmp7_;
	gint _tmp7__length1;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->m_config;
	if (_tmp0_ == NULL) {
		gchar** _tmp1_ = NULL;
		gchar** _tmp2_;
		gint _tmp2__length1;
		_tmp1_ = g_new0 (gchar*, 0 + 1);
		_tmp2_ = _tmp1_;
		_tmp2__length1 = 0;
		if (result_length1) {
			*result_length1 = _tmp2__length1;
		}
		result = _tmp2_;
		return result;
	}
	_tmp3_ = self->priv->m_config;
	_tmp5_ = _tmp4_ = gkbd_configuration_get_short_group_names (_tmp3_);
	_tmp6_ = (_tmp5_ != NULL) ? _vala_array_dup2 (_tmp5_, _vala_array_length (_tmp4_)) : ((gpointer) _tmp5_);
	_tmp6__length1 = _vala_array_length (_tmp4_);
	_tmp7_ = _tmp6_;
	_tmp7__length1 = _tmp6__length1;
	if (result_length1) {
		*result_length1 = _tmp7__length1;
	}
	result = _tmp7_;
	return result;
}


static gchar** _vala_array_dup3 (gchar** self, int length) {
	gchar** result;
	int i;
	result = g_new0 (gchar*, length + 1);
	for (i = 0; i < length; i++) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (self[i]);
		result[i] = _tmp0_;
	}
	return result;
}


gchar** gkbd_layout_get_group_names (GkbdLayout* self, int* result_length1) {
	gchar** result = NULL;
	GkbdConfiguration* _tmp0_;
	GkbdConfiguration* _tmp3_;
	gchar** _tmp4_;
	gchar** _tmp5_ = NULL;
	gchar** _tmp6_;
	gint _tmp6__length1;
	gchar** _tmp7_;
	gint _tmp7__length1;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->m_config;
	if (_tmp0_ == NULL) {
		gchar** _tmp1_ = NULL;
		gchar** _tmp2_;
		gint _tmp2__length1;
		_tmp1_ = g_new0 (gchar*, 0 + 1);
		_tmp2_ = _tmp1_;
		_tmp2__length1 = 0;
		if (result_length1) {
			*result_length1 = _tmp2__length1;
		}
		result = _tmp2_;
		return result;
	}
	_tmp3_ = self->priv->m_config;
	_tmp5_ = _tmp4_ = gkbd_configuration_get_group_names (_tmp3_);
	_tmp6_ = (_tmp5_ != NULL) ? _vala_array_dup3 (_tmp5_, _vala_array_length (_tmp4_)) : ((gpointer) _tmp5_);
	_tmp6__length1 = _vala_array_length (_tmp4_);
	_tmp7_ = _tmp6_;
	_tmp7__length1 = _tmp6__length1;
	if (result_length1) {
		*result_length1 = _tmp7__length1;
	}
	result = _tmp7_;
	return result;
}


void gkbd_layout_lock_group (GkbdLayout* self, gint id) {
	GkbdConfiguration* _tmp0_;
	GkbdConfiguration* _tmp1_;
	gint _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->m_config;
	if (_tmp0_ == NULL) {
		return;
	}
	_tmp1_ = self->priv->m_config;
	_tmp2_ = id;
	gkbd_configuration_lock_group (_tmp1_, (guint) _tmp2_);
}


void gkbd_layout_start_listen (GkbdLayout* self) {
	GkbdConfiguration* _tmp0_;
	GkbdConfiguration* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->m_config;
	if (_tmp0_ == NULL) {
		return;
	}
	_tmp1_ = self->priv->m_config;
	gkbd_configuration_start_listen (_tmp1_);
}


void gkbd_layout_stop_listen (GkbdLayout* self) {
	GkbdConfiguration* _tmp0_;
	GkbdConfiguration* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->m_config;
	if (_tmp0_ == NULL) {
		return;
	}
	_tmp1_ = self->priv->m_config;
	gkbd_configuration_stop_listen (_tmp1_);
}


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


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


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


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


static gchar* value_gkbd_layout_collect_value (GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	if (collect_values[0].v_pointer) {
		GkbdLayout* 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 = gkbd_layout_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}


static gchar* value_gkbd_layout_lcopy_value (const GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	GkbdLayout** 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 = gkbd_layout_ref (value->data[0].v_pointer);
	}
	return NULL;
}


GParamSpec* param_spec_gkbd_layout (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags) {
	ParamSpecGkbdLayout* spec;
	g_return_val_if_fail (g_type_is_a (object_type, TYPE_GKBD_LAYOUT), 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_gkbd_layout (const GValue* value) {
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_GKBD_LAYOUT), NULL);
	return value->data[0].v_pointer;
}


void value_set_gkbd_layout (GValue* value, gpointer v_object) {
	GkbdLayout* old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_GKBD_LAYOUT));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_GKBD_LAYOUT));
		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;
		gkbd_layout_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		gkbd_layout_unref (old);
	}
}


void value_take_gkbd_layout (GValue* value, gpointer v_object) {
	GkbdLayout* old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_GKBD_LAYOUT));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_GKBD_LAYOUT));
		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) {
		gkbd_layout_unref (old);
	}
}


static void gkbd_layout_class_init (GkbdLayoutClass * klass) {
	gkbd_layout_parent_class = g_type_class_peek_parent (klass);
	GKBD_LAYOUT_CLASS (klass)->finalize = gkbd_layout_finalize;
	g_type_class_add_private (klass, sizeof (GkbdLayoutPrivate));
	g_signal_new ("changed", TYPE_GKBD_LAYOUT, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	g_signal_new ("group_changed", TYPE_GKBD_LAYOUT, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
}


static void gkbd_layout_instance_init (GkbdLayout * self) {
	self->priv = GKBD_LAYOUT_GET_PRIVATE (self);
	self->priv->m_config = NULL;
	self->ref_count = 1;
}


static void gkbd_layout_finalize (GkbdLayout* obj) {
	GkbdLayout * self;
	GkbdConfiguration* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_GKBD_LAYOUT, GkbdLayout);
	_tmp0_ = self->priv->m_config;
	if (_tmp0_ != NULL) {
		GkbdConfiguration* _tmp1_;
		guint _tmp2_ = 0U;
		GkbdConfiguration* _tmp3_;
		guint _tmp4_ = 0U;
		GkbdConfiguration* _tmp5_;
		_tmp1_ = self->priv->m_config;
		g_signal_parse_name ("changed", gkbd_configuration_get_type (), &_tmp2_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp1_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp2_, 0, NULL, (GCallback) _gkbd_layout_config_changed_cb_gkbd_configuration_changed, self);
		_tmp3_ = self->priv->m_config;
		g_signal_parse_name ("group-changed", gkbd_configuration_get_type (), &_tmp4_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp3_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp4_, 0, NULL, (GCallback) _gkbd_layout_config_group_changed_cb_gkbd_configuration_group_changed, self);
		_tmp5_ = self->priv->m_config;
		g_object_ref ((GObject*) _tmp5_);
		_g_object_unref0 (self->priv->m_config);
		self->priv->m_config = NULL;
	}
	_g_object_unref0 (self->priv->m_config);
}


GType gkbd_layout_get_type (void) {
	static volatile gsize gkbd_layout_type_id__volatile = 0;
	if (g_once_init_enter (&gkbd_layout_type_id__volatile)) {
		static const GTypeValueTable g_define_type_value_table = { value_gkbd_layout_init, value_gkbd_layout_free_value, value_gkbd_layout_copy_value, value_gkbd_layout_peek_pointer, "p", value_gkbd_layout_collect_value, "p", value_gkbd_layout_lcopy_value };
		static const GTypeInfo g_define_type_info = { sizeof (GkbdLayoutClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gkbd_layout_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GkbdLayout), 0, (GInstanceInitFunc) gkbd_layout_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 gkbd_layout_type_id;
		gkbd_layout_type_id = g_type_register_fundamental (g_type_fundamental_next (), "GkbdLayout", &g_define_type_info, &g_define_type_fundamental_info, 0);
		g_once_init_leave (&gkbd_layout_type_id__volatile, gkbd_layout_type_id);
	}
	return gkbd_layout_type_id__volatile;
}


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


void gkbd_layout_unref (gpointer instance) {
	GkbdLayout* self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		GKBD_LAYOUT_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}


static gint _vala_array_length (gpointer array) {
	int length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}



