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

/*
* Copyright 2017-2020 elementary, Inc. (https://elementary.io)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/

#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>
#include "keyboard.h"

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

#define KEYBOARD_TYPE_XKB_MODIFIER (keyboard_xkb_modifier_get_type ())
#define KEYBOARD_XKB_MODIFIER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), KEYBOARD_TYPE_XKB_MODIFIER, KeyboardXkbModifier))
#define KEYBOARD_XKB_MODIFIER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), KEYBOARD_TYPE_XKB_MODIFIER, KeyboardXkbModifierClass))
#define KEYBOARD_IS_XKB_MODIFIER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KEYBOARD_TYPE_XKB_MODIFIER))
#define KEYBOARD_IS_XKB_MODIFIER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), KEYBOARD_TYPE_XKB_MODIFIER))
#define KEYBOARD_XKB_MODIFIER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), KEYBOARD_TYPE_XKB_MODIFIER, KeyboardXkbModifierClass))

typedef struct _KeyboardXkbModifier KeyboardXkbModifier;
typedef struct _KeyboardXkbModifierClass KeyboardXkbModifierClass;
typedef struct _KeyboardXkbModifierPrivate KeyboardXkbModifierPrivate;
enum  {
	KEYBOARD_XKB_MODIFIER_0_PROPERTY,
	KEYBOARD_XKB_MODIFIER_GSETTINGS_KEY_PROPERTY,
	KEYBOARD_XKB_MODIFIER_GSETTINGS_SCHEMA_PROPERTY,
	KEYBOARD_XKB_MODIFIER_NAME_PROPERTY,
	KEYBOARD_XKB_MODIFIER_NUM_PROPERTIES
};
static GParamSpec* keyboard_xkb_modifier_properties[KEYBOARD_XKB_MODIFIER_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
enum  {
	KEYBOARD_XKB_MODIFIER_ACTIVE_COMMAND_UPDATED_SIGNAL,
	KEYBOARD_XKB_MODIFIER_NUM_SIGNALS
};
static guint keyboard_xkb_modifier_signals[KEYBOARD_XKB_MODIFIER_NUM_SIGNALS] = {0};

struct _KeyboardXkbModifier {
	GObject parent_instance;
	KeyboardXkbModifierPrivate * priv;
	gchar** option_descriptions;
	gint option_descriptions_length1;
	gint _option_descriptions_size_;
	gchar** xkb_option_commands;
	gint xkb_option_commands_length1;
	gint _xkb_option_commands_size_;
};

struct _KeyboardXkbModifierClass {
	GObjectClass parent_class;
};

struct _KeyboardXkbModifierPrivate {
	gchar* _gsettings_key;
	gchar* _gsettings_schema;
	gchar* _name;
	GSettings* settings;
	gchar* active_command;
	gchar* default_command;
};

static gint KeyboardXkbModifier_private_offset;
static gpointer keyboard_xkb_modifier_parent_class = NULL;

VALA_EXTERN GType keyboard_xkb_modifier_get_type (void) G_GNUC_CONST ;
VALA_EXTERN KeyboardXkbModifier* keyboard_xkb_modifier_new (const gchar* name,
                                                const gchar* schem,
                                                const gchar* key);
VALA_EXTERN KeyboardXkbModifier* keyboard_xkb_modifier_construct (GType object_type,
                                                      const gchar* name,
                                                      const gchar* schem,
                                                      const gchar* key);
VALA_EXTERN gchar* keyboard_xkb_modifier_get_active_command (KeyboardXkbModifier* self);
VALA_EXTERN void keyboard_xkb_modifier_update_from_gsettings (KeyboardXkbModifier* self);
VALA_EXTERN const gchar* keyboard_xkb_modifier_get_gsettings_key (KeyboardXkbModifier* self);
static gboolean _vala_string_array_contains (gchar* * stack,
                                      gssize stack_length,
                                      const gchar* needle);
VALA_EXTERN void keyboard_xkb_modifier_update_active_command (KeyboardXkbModifier* self,
                                                  const gchar* val);
static void _vala_array_add10 (gchar** * array,
                        gint* length,
                        gint* size,
                        gchar* value);
static void _vala_array_add11 (gchar** * array,
                        gint* length,
                        gint* size,
                        gchar* value);
static void _keyboard_xkb_modifier_update_from_gsettings_g_settings_changed (GSettings* _sender,
                                                                      const gchar* key,
                                                                      gpointer self);
VALA_EXTERN void keyboard_xkb_modifier_set_default_command (KeyboardXkbModifier* self,
                                                const gchar* val);
VALA_EXTERN void keyboard_xkb_modifier_append_xkb_option (KeyboardXkbModifier* self,
                                              const gchar* xkb_command,
                                              const gchar* description);
static void _vala_array_add12 (gchar** * array,
                        gint* length,
                        gint* size,
                        gchar* value);
static void _vala_array_add13 (gchar** * array,
                        gint* length,
                        gint* size,
                        gchar* value);
static void keyboard_xkb_modifier_set_gsettings_key (KeyboardXkbModifier* self,
                                              const gchar* value);
VALA_EXTERN const gchar* keyboard_xkb_modifier_get_gsettings_schema (KeyboardXkbModifier* self);
static void keyboard_xkb_modifier_set_gsettings_schema (KeyboardXkbModifier* self,
                                                 const gchar* value);
VALA_EXTERN const gchar* keyboard_xkb_modifier_get_name (KeyboardXkbModifier* self);
static void keyboard_xkb_modifier_set_name (KeyboardXkbModifier* self,
                                     const gchar* value);
static GObject * keyboard_xkb_modifier_constructor (GType type,
                                             guint n_construct_properties,
                                             GObjectConstructParam * construct_properties);
static void keyboard_xkb_modifier_finalize (GObject * obj);
static GType keyboard_xkb_modifier_get_type_once (void);
static void _vala_keyboard_xkb_modifier_get_property (GObject * object,
                                               guint property_id,
                                               GValue * value,
                                               GParamSpec * pspec);
static void _vala_keyboard_xkb_modifier_set_property (GObject * object,
                                               guint property_id,
                                               const GValue * value,
                                               GParamSpec * pspec);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static gssize _vala_array_length (gpointer array);

static inline gpointer
keyboard_xkb_modifier_get_instance_private (KeyboardXkbModifier* self)
{
	return G_STRUCT_MEMBER_P (self, KeyboardXkbModifier_private_offset);
}

KeyboardXkbModifier*
keyboard_xkb_modifier_construct (GType object_type,
                                 const gchar* name,
                                 const gchar* schem,
                                 const gchar* key)
{
	KeyboardXkbModifier * self = NULL;
	g_return_val_if_fail (name != NULL, NULL);
	g_return_val_if_fail (schem != NULL, NULL);
	g_return_val_if_fail (key != NULL, NULL);
	self = (KeyboardXkbModifier*) g_object_new (object_type, "name", name, "gsettings-schema", schem, "gsettings-key", key, NULL);
	return self;
}

KeyboardXkbModifier*
keyboard_xkb_modifier_new (const gchar* name,
                           const gchar* schem,
                           const gchar* key)
{
	return keyboard_xkb_modifier_construct (KEYBOARD_TYPE_XKB_MODIFIER, name, schem, key);
}

gchar*
keyboard_xkb_modifier_get_active_command (KeyboardXkbModifier* self)
{
	const gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->active_command;
	if (_tmp0_ == NULL) {
		const gchar* _tmp1_;
		gchar* _tmp2_;
		_tmp1_ = self->priv->default_command;
		_tmp2_ = g_strdup (_tmp1_);
		result = _tmp2_;
		return result;
	} else {
		const gchar* _tmp3_;
		gchar* _tmp4_;
		_tmp3_ = self->priv->active_command;
		_tmp4_ = g_strdup (_tmp3_);
		result = _tmp4_;
		return result;
	}
}

static gboolean
_vala_string_array_contains (gchar* * stack,
                             gssize stack_length,
                             const gchar* needle)
{
	gssize i;
	for (i = 0; i < stack_length; i++) {
		if (g_strcmp0 (stack[i], needle) == 0) {
			return TRUE;
		}
	}
	return FALSE;
}

void
keyboard_xkb_modifier_update_from_gsettings (KeyboardXkbModifier* self)
{
	gchar** xkb_options = NULL;
	GSettings* _tmp0_;
	const gchar* _tmp1_;
	gchar** _tmp2_;
	gchar** _tmp3_;
	gint xkb_options_length1;
	gint _xkb_options_size_;
	gboolean found = FALSE;
	gchar** _tmp4_;
	gint _tmp4__length1;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->settings;
	_tmp1_ = self->priv->_gsettings_key;
	_tmp3_ = _tmp2_ = g_settings_get_strv (_tmp0_, _tmp1_);
	xkb_options = _tmp3_;
	xkb_options_length1 = _vala_array_length (_tmp2_);
	_xkb_options_size_ = xkb_options_length1;
	found = FALSE;
	_tmp4_ = self->xkb_option_commands;
	_tmp4__length1 = self->xkb_option_commands_length1;
	{
		gchar** xkb_command_collection = NULL;
		gint xkb_command_collection_length1 = 0;
		gint _xkb_command_collection_size_ = 0;
		gint xkb_command_it = 0;
		xkb_command_collection = _tmp4_;
		xkb_command_collection_length1 = _tmp4__length1;
		for (xkb_command_it = 0; xkb_command_it < xkb_command_collection_length1; xkb_command_it = xkb_command_it + 1) {
			gchar* _tmp5_;
			gchar* xkb_command = NULL;
			_tmp5_ = g_strdup (xkb_command_collection[xkb_command_it]);
			xkb_command = _tmp5_;
			{
				gboolean command_is_valid = FALSE;
				const gchar* _tmp6_;
				command_is_valid = TRUE;
				_tmp6_ = xkb_command;
				if (g_strcmp0 (_tmp6_, "") != 0) {
					gchar** com_arr = NULL;
					const gchar* _tmp7_;
					gchar** _tmp8_;
					gchar** _tmp9_;
					gint com_arr_length1;
					gint _com_arr_size_;
					gchar** _tmp10_;
					gint _tmp10__length1;
					_tmp7_ = xkb_command;
					_tmp9_ = _tmp8_ = g_strsplit (_tmp7_, ",", 4);
					com_arr = _tmp9_;
					com_arr_length1 = _vala_array_length (_tmp8_);
					_com_arr_size_ = com_arr_length1;
					_tmp10_ = com_arr;
					_tmp10__length1 = com_arr_length1;
					{
						gchar** opt_collection = NULL;
						gint opt_collection_length1 = 0;
						gint _opt_collection_size_ = 0;
						gint opt_it = 0;
						opt_collection = _tmp10_;
						opt_collection_length1 = _tmp10__length1;
						for (opt_it = 0; opt_it < opt_collection_length1; opt_it = opt_it + 1) {
							gchar* _tmp11_;
							gchar* opt = NULL;
							_tmp11_ = g_strdup (opt_collection[opt_it]);
							opt = _tmp11_;
							{
								const gchar* _tmp12_;
								gchar** _tmp13_;
								gint _tmp13__length1;
								_tmp12_ = opt;
								_tmp13_ = xkb_options;
								_tmp13__length1 = xkb_options_length1;
								if (!_vala_string_array_contains (_tmp13_, _tmp13__length1, _tmp12_)) {
									command_is_valid = FALSE;
								}
								_g_free0 (opt);
							}
						}
					}
					if (command_is_valid) {
						const gchar* _tmp14_;
						_tmp14_ = xkb_command;
						keyboard_xkb_modifier_update_active_command (self, _tmp14_);
						found = TRUE;
						com_arr = (_vala_array_free (com_arr, com_arr_length1, (GDestroyNotify) g_free), NULL);
						_g_free0 (xkb_command);
						break;
					}
					com_arr = (_vala_array_free (com_arr, com_arr_length1, (GDestroyNotify) g_free), NULL);
				}
				_g_free0 (xkb_command);
			}
		}
	}
	if (!found) {
		const gchar* _tmp15_;
		_tmp15_ = self->priv->default_command;
		keyboard_xkb_modifier_update_active_command (self, _tmp15_);
	}
	xkb_options = (_vala_array_free (xkb_options, xkb_options_length1, (GDestroyNotify) g_free), NULL);
}

static void
_vala_array_add10 (gchar** * array,
                   gint* length,
                   gint* size,
                   gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static void
_vala_array_add11 (gchar** * array,
                   gint* length,
                   gint* size,
                   gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static void
_keyboard_xkb_modifier_update_from_gsettings_g_settings_changed (GSettings* _sender,
                                                                 const gchar* key,
                                                                 gpointer self)
{
	keyboard_xkb_modifier_update_from_gsettings ((KeyboardXkbModifier*) self);
}

void
keyboard_xkb_modifier_update_active_command (KeyboardXkbModifier* self,
                                             const gchar* val)
{
	gboolean _tmp0_ = FALSE;
	gchar** _tmp1_;
	gint _tmp1__length1;
	gchar* old_opt = NULL;
	gchar* _tmp3_;
	gboolean _tmp4_ = FALSE;
	const gchar* _tmp5_;
	gchar** new_xkb_options = NULL;
	gchar** _tmp8_;
	gint new_xkb_options_length1;
	gint _new_xkb_options_size_;
	gchar** old_xkb_options = NULL;
	GSettings* _tmp9_;
	const gchar* _tmp10_;
	gchar** _tmp11_;
	gchar** _tmp12_;
	gint old_xkb_options_length1;
	gint _old_xkb_options_size_;
	gchar** old_arr = NULL;
	const gchar* _tmp13_;
	gchar** _tmp14_;
	gchar** _tmp15_;
	gint old_arr_length1;
	gint _old_arr_size_;
	gchar** new_arr = NULL;
	gchar** _tmp16_;
	gchar** _tmp17_;
	gint new_arr_length1;
	gint _new_arr_size_;
	gchar** _tmp18_;
	gint _tmp18__length1;
	gchar** _tmp27_;
	gint _tmp27__length1;
	GSettings* _tmp33_;
	const gchar* _tmp34_;
	gchar* _tmp35_;
	guint _tmp36_;
	GQuark _tmp37_;
	GSettings* _tmp38_;
	const gchar* _tmp39_;
	gchar** _tmp40_;
	gint _tmp40__length1;
	GSettings* _tmp41_;
	const gchar* _tmp42_;
	gchar* _tmp43_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (val != NULL);
	_tmp1_ = self->xkb_option_commands;
	_tmp1__length1 = self->xkb_option_commands_length1;
	if (!_vala_string_array_contains (_tmp1_, _tmp1__length1, val)) {
		_tmp0_ = TRUE;
	} else {
		const gchar* _tmp2_;
		_tmp2_ = self->priv->active_command;
		_tmp0_ = g_strcmp0 (val, _tmp2_) == 0;
	}
	if (_tmp0_) {
		return;
	}
	_tmp3_ = keyboard_xkb_modifier_get_active_command (self);
	old_opt = _tmp3_;
	_tmp5_ = self->priv->active_command;
	if (g_strcmp0 (val, _tmp5_) != 0) {
		gchar** _tmp6_;
		gint _tmp6__length1;
		_tmp6_ = self->xkb_option_commands;
		_tmp6__length1 = self->xkb_option_commands_length1;
		_tmp4_ = _vala_string_array_contains (_tmp6_, _tmp6__length1, val);
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		gchar* _tmp7_;
		_tmp7_ = g_strdup (val);
		_g_free0 (self->priv->active_command);
		self->priv->active_command = _tmp7_;
	}
	_tmp8_ = g_new0 (gchar*, 0 + 1);
	new_xkb_options = _tmp8_;
	new_xkb_options_length1 = 0;
	_new_xkb_options_size_ = new_xkb_options_length1;
	_tmp9_ = self->priv->settings;
	_tmp10_ = self->priv->_gsettings_key;
	_tmp12_ = _tmp11_ = g_settings_get_strv (_tmp9_, _tmp10_);
	old_xkb_options = _tmp12_;
	old_xkb_options_length1 = _vala_array_length (_tmp11_);
	_old_xkb_options_size_ = old_xkb_options_length1;
	_tmp13_ = old_opt;
	_tmp15_ = _tmp14_ = g_strsplit (_tmp13_, ",", 4);
	old_arr = _tmp15_;
	old_arr_length1 = _vala_array_length (_tmp14_);
	_old_arr_size_ = old_arr_length1;
	_tmp17_ = _tmp16_ = g_strsplit (val, ",", 4);
	new_arr = _tmp17_;
	new_arr_length1 = _vala_array_length (_tmp16_);
	_new_arr_size_ = new_arr_length1;
	_tmp18_ = old_xkb_options;
	_tmp18__length1 = old_xkb_options_length1;
	{
		gchar** xkb_command_collection = NULL;
		gint xkb_command_collection_length1 = 0;
		gint _xkb_command_collection_size_ = 0;
		gint xkb_command_it = 0;
		xkb_command_collection = _tmp18_;
		xkb_command_collection_length1 = _tmp18__length1;
		for (xkb_command_it = 0; xkb_command_it < xkb_command_collection_length1; xkb_command_it = xkb_command_it + 1) {
			gchar* _tmp19_;
			gchar* xkb_command = NULL;
			_tmp19_ = g_strdup (xkb_command_collection[xkb_command_it]);
			xkb_command = _tmp19_;
			{
				gboolean _tmp20_ = FALSE;
				const gchar* _tmp21_;
				gchar** _tmp22_;
				gint _tmp22__length1;
				_tmp21_ = xkb_command;
				_tmp22_ = old_arr;
				_tmp22__length1 = old_arr_length1;
				if (!_vala_string_array_contains (_tmp22_, _tmp22__length1, _tmp21_)) {
					_tmp20_ = TRUE;
				} else {
					const gchar* _tmp23_;
					gchar** _tmp24_;
					gint _tmp24__length1;
					_tmp23_ = xkb_command;
					_tmp24_ = new_arr;
					_tmp24__length1 = new_arr_length1;
					_tmp20_ = _vala_string_array_contains (_tmp24_, _tmp24__length1, _tmp23_);
				}
				if (_tmp20_) {
					const gchar* _tmp25_;
					gchar* _tmp26_;
					_tmp25_ = xkb_command;
					_tmp26_ = g_strdup (_tmp25_);
					_vala_array_add10 (&new_xkb_options, &new_xkb_options_length1, &_new_xkb_options_size_, _tmp26_);
				}
				_g_free0 (xkb_command);
			}
		}
	}
	_tmp27_ = new_arr;
	_tmp27__length1 = new_arr_length1;
	{
		gchar** xkb_command_collection = NULL;
		gint xkb_command_collection_length1 = 0;
		gint _xkb_command_collection_size_ = 0;
		gint xkb_command_it = 0;
		xkb_command_collection = _tmp27_;
		xkb_command_collection_length1 = _tmp27__length1;
		for (xkb_command_it = 0; xkb_command_it < xkb_command_collection_length1; xkb_command_it = xkb_command_it + 1) {
			gchar* _tmp28_;
			gchar* xkb_command = NULL;
			_tmp28_ = g_strdup (xkb_command_collection[xkb_command_it]);
			xkb_command = _tmp28_;
			{
				const gchar* _tmp29_;
				gchar** _tmp30_;
				gint _tmp30__length1;
				_tmp29_ = xkb_command;
				_tmp30_ = new_xkb_options;
				_tmp30__length1 = new_xkb_options_length1;
				if (!_vala_string_array_contains (_tmp30_, _tmp30__length1, _tmp29_)) {
					const gchar* _tmp31_;
					gchar* _tmp32_;
					_tmp31_ = xkb_command;
					_tmp32_ = g_strdup (_tmp31_);
					_vala_array_add11 (&new_xkb_options, &new_xkb_options_length1, &_new_xkb_options_size_, _tmp32_);
				}
				_g_free0 (xkb_command);
			}
		}
	}
	_tmp33_ = self->priv->settings;
	_tmp34_ = self->priv->_gsettings_key;
	_tmp35_ = g_strconcat ("changed::", _tmp34_, NULL);
	g_signal_parse_name (_tmp35_, g_settings_get_type (), &_tmp36_, &_tmp37_, TRUE);
	g_signal_handlers_disconnect_matched (_tmp33_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp36_, _tmp37_, NULL, (GCallback) _keyboard_xkb_modifier_update_from_gsettings_g_settings_changed, self);
	_g_free0 (_tmp35_);
	_tmp38_ = self->priv->settings;
	_tmp39_ = self->priv->_gsettings_key;
	_tmp40_ = new_xkb_options;
	_tmp40__length1 = new_xkb_options_length1;
	g_settings_set_strv (_tmp38_, _tmp39_, _tmp40_);
	_tmp41_ = self->priv->settings;
	_tmp42_ = self->priv->_gsettings_key;
	_tmp43_ = g_strconcat ("changed::", _tmp42_, NULL);
	g_signal_connect_object (_tmp41_, _tmp43_, (GCallback) _keyboard_xkb_modifier_update_from_gsettings_g_settings_changed, self, 0);
	_g_free0 (_tmp43_);
	g_signal_emit (self, keyboard_xkb_modifier_signals[KEYBOARD_XKB_MODIFIER_ACTIVE_COMMAND_UPDATED_SIGNAL], 0);
	new_arr = (_vala_array_free (new_arr, new_arr_length1, (GDestroyNotify) g_free), NULL);
	old_arr = (_vala_array_free (old_arr, old_arr_length1, (GDestroyNotify) g_free), NULL);
	old_xkb_options = (_vala_array_free (old_xkb_options, old_xkb_options_length1, (GDestroyNotify) g_free), NULL);
	new_xkb_options = (_vala_array_free (new_xkb_options, new_xkb_options_length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (old_opt);
}

void
keyboard_xkb_modifier_set_default_command (KeyboardXkbModifier* self,
                                           const gchar* val)
{
	gchar** _tmp0_;
	gint _tmp0__length1;
	g_return_if_fail (self != NULL);
	g_return_if_fail (val != NULL);
	_tmp0_ = self->xkb_option_commands;
	_tmp0__length1 = self->xkb_option_commands_length1;
	if (_vala_string_array_contains (_tmp0_, _tmp0__length1, val)) {
		gchar* _tmp1_;
		_tmp1_ = g_strdup (val);
		_g_free0 (self->priv->default_command);
		self->priv->default_command = _tmp1_;
	} else {
		return;
	}
}

static void
_vala_array_add12 (gchar** * array,
                   gint* length,
                   gint* size,
                   gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static void
_vala_array_add13 (gchar** * array,
                   gint* length,
                   gint* size,
                   gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

void
keyboard_xkb_modifier_append_xkb_option (KeyboardXkbModifier* self,
                                         const gchar* xkb_command,
                                         const gchar* description)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (xkb_command != NULL);
	g_return_if_fail (description != NULL);
	_tmp0_ = g_strdup (xkb_command);
	_vala_array_add12 (&self->xkb_option_commands, &self->xkb_option_commands_length1, &self->_xkb_option_commands_size_, _tmp0_);
	_tmp1_ = g_strdup (description);
	_vala_array_add13 (&self->option_descriptions, &self->option_descriptions_length1, &self->_option_descriptions_size_, _tmp1_);
}

const gchar*
keyboard_xkb_modifier_get_gsettings_key (KeyboardXkbModifier* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_gsettings_key;
	result = _tmp0_;
	return result;
}

static void
keyboard_xkb_modifier_set_gsettings_key (KeyboardXkbModifier* self,
                                         const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = keyboard_xkb_modifier_get_gsettings_key (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_gsettings_key);
		self->priv->_gsettings_key = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, keyboard_xkb_modifier_properties[KEYBOARD_XKB_MODIFIER_GSETTINGS_KEY_PROPERTY]);
	}
}

const gchar*
keyboard_xkb_modifier_get_gsettings_schema (KeyboardXkbModifier* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_gsettings_schema;
	result = _tmp0_;
	return result;
}

static void
keyboard_xkb_modifier_set_gsettings_schema (KeyboardXkbModifier* self,
                                            const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = keyboard_xkb_modifier_get_gsettings_schema (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_gsettings_schema);
		self->priv->_gsettings_schema = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, keyboard_xkb_modifier_properties[KEYBOARD_XKB_MODIFIER_GSETTINGS_SCHEMA_PROPERTY]);
	}
}

const gchar*
keyboard_xkb_modifier_get_name (KeyboardXkbModifier* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_name;
	result = _tmp0_;
	return result;
}

static void
keyboard_xkb_modifier_set_name (KeyboardXkbModifier* self,
                                const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = keyboard_xkb_modifier_get_name (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_name);
		self->priv->_name = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, keyboard_xkb_modifier_properties[KEYBOARD_XKB_MODIFIER_NAME_PROPERTY]);
	}
}

static GObject *
keyboard_xkb_modifier_constructor (GType type,
                                   guint n_construct_properties,
                                   GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	KeyboardXkbModifier * self;
	const gchar* _tmp0_;
	GSettings* _tmp1_;
	GSettings* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	parent_class = G_OBJECT_CLASS (keyboard_xkb_modifier_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, KEYBOARD_TYPE_XKB_MODIFIER, KeyboardXkbModifier);
	_tmp0_ = self->priv->_gsettings_schema;
	_tmp1_ = g_settings_new (_tmp0_);
	_g_object_unref0 (self->priv->settings);
	self->priv->settings = _tmp1_;
	_tmp2_ = self->priv->settings;
	_tmp3_ = self->priv->_gsettings_key;
	_tmp4_ = g_strconcat ("changed::", _tmp3_, NULL);
	g_signal_connect_object (_tmp2_, _tmp4_, (GCallback) _keyboard_xkb_modifier_update_from_gsettings_g_settings_changed, self, 0);
	_g_free0 (_tmp4_);
	return obj;
}

static void
keyboard_xkb_modifier_class_init (KeyboardXkbModifierClass * klass,
                                  gpointer klass_data)
{
	keyboard_xkb_modifier_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &KeyboardXkbModifier_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_keyboard_xkb_modifier_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_keyboard_xkb_modifier_set_property;
	G_OBJECT_CLASS (klass)->constructor = keyboard_xkb_modifier_constructor;
	G_OBJECT_CLASS (klass)->finalize = keyboard_xkb_modifier_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), KEYBOARD_XKB_MODIFIER_GSETTINGS_KEY_PROPERTY, keyboard_xkb_modifier_properties[KEYBOARD_XKB_MODIFIER_GSETTINGS_KEY_PROPERTY] = g_param_spec_string ("gsettings-key", "gsettings-key", "gsettings-key", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), KEYBOARD_XKB_MODIFIER_GSETTINGS_SCHEMA_PROPERTY, keyboard_xkb_modifier_properties[KEYBOARD_XKB_MODIFIER_GSETTINGS_SCHEMA_PROPERTY] = g_param_spec_string ("gsettings-schema", "gsettings-schema", "gsettings-schema", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), KEYBOARD_XKB_MODIFIER_NAME_PROPERTY, keyboard_xkb_modifier_properties[KEYBOARD_XKB_MODIFIER_NAME_PROPERTY] = g_param_spec_string ("name", "name", "name", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	keyboard_xkb_modifier_signals[KEYBOARD_XKB_MODIFIER_ACTIVE_COMMAND_UPDATED_SIGNAL] = g_signal_new ("active-command-updated", KEYBOARD_TYPE_XKB_MODIFIER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
keyboard_xkb_modifier_instance_init (KeyboardXkbModifier * self,
                                     gpointer klass)
{
	gchar* _tmp0_;
	self->priv = keyboard_xkb_modifier_get_instance_private (self);
	_tmp0_ = g_strdup ("");
	self->priv->default_command = _tmp0_;
}

static void
keyboard_xkb_modifier_finalize (GObject * obj)
{
	KeyboardXkbModifier * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, KEYBOARD_TYPE_XKB_MODIFIER, KeyboardXkbModifier);
	_g_free0 (self->priv->_gsettings_key);
	_g_free0 (self->priv->_gsettings_schema);
	_g_free0 (self->priv->_name);
	self->option_descriptions = (_vala_array_free (self->option_descriptions, self->option_descriptions_length1, (GDestroyNotify) g_free), NULL);
	self->xkb_option_commands = (_vala_array_free (self->xkb_option_commands, self->xkb_option_commands_length1, (GDestroyNotify) g_free), NULL);
	_g_object_unref0 (self->priv->settings);
	_g_free0 (self->priv->active_command);
	_g_free0 (self->priv->default_command);
	G_OBJECT_CLASS (keyboard_xkb_modifier_parent_class)->finalize (obj);
}

static GType
keyboard_xkb_modifier_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (KeyboardXkbModifierClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) keyboard_xkb_modifier_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (KeyboardXkbModifier), 0, (GInstanceInitFunc) keyboard_xkb_modifier_instance_init, NULL };
	GType keyboard_xkb_modifier_type_id;
	keyboard_xkb_modifier_type_id = g_type_register_static (G_TYPE_OBJECT, "KeyboardXkbModifier", &g_define_type_info, 0);
	KeyboardXkbModifier_private_offset = g_type_add_instance_private (keyboard_xkb_modifier_type_id, sizeof (KeyboardXkbModifierPrivate));
	return keyboard_xkb_modifier_type_id;
}

GType
keyboard_xkb_modifier_get_type (void)
{
	static volatile gsize keyboard_xkb_modifier_type_id__once = 0;
	if (g_once_init_enter (&keyboard_xkb_modifier_type_id__once)) {
		GType keyboard_xkb_modifier_type_id;
		keyboard_xkb_modifier_type_id = keyboard_xkb_modifier_get_type_once ();
		g_once_init_leave (&keyboard_xkb_modifier_type_id__once, keyboard_xkb_modifier_type_id);
	}
	return keyboard_xkb_modifier_type_id__once;
}

static void
_vala_keyboard_xkb_modifier_get_property (GObject * object,
                                          guint property_id,
                                          GValue * value,
                                          GParamSpec * pspec)
{
	KeyboardXkbModifier * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, KEYBOARD_TYPE_XKB_MODIFIER, KeyboardXkbModifier);
	switch (property_id) {
		case KEYBOARD_XKB_MODIFIER_GSETTINGS_KEY_PROPERTY:
		g_value_set_string (value, keyboard_xkb_modifier_get_gsettings_key (self));
		break;
		case KEYBOARD_XKB_MODIFIER_GSETTINGS_SCHEMA_PROPERTY:
		g_value_set_string (value, keyboard_xkb_modifier_get_gsettings_schema (self));
		break;
		case KEYBOARD_XKB_MODIFIER_NAME_PROPERTY:
		g_value_set_string (value, keyboard_xkb_modifier_get_name (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_keyboard_xkb_modifier_set_property (GObject * object,
                                          guint property_id,
                                          const GValue * value,
                                          GParamSpec * pspec)
{
	KeyboardXkbModifier * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, KEYBOARD_TYPE_XKB_MODIFIER, KeyboardXkbModifier);
	switch (property_id) {
		case KEYBOARD_XKB_MODIFIER_GSETTINGS_KEY_PROPERTY:
		keyboard_xkb_modifier_set_gsettings_key (self, g_value_get_string (value));
		break;
		case KEYBOARD_XKB_MODIFIER_GSETTINGS_SCHEMA_PROPERTY:
		keyboard_xkb_modifier_set_gsettings_schema (self, g_value_get_string (value));
		break;
		case KEYBOARD_XKB_MODIFIER_NAME_PROPERTY:
		keyboard_xkb_modifier_set_name (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

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

