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

/*
 * Copyright 2026 elementary, Inc. (https://elementary.io)
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 * Authored by: Leonhard Kargl <leo.kargl@proton.me>
 */

#include <glib-object.h>
#include <ibus.h>
#include <gio/gio.h>
#include <glib.h>
#include <stdlib.h>
#include <string.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
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define GALA_DAEMON_TYPE_MODEL_MANAGER (gala_daemon_model_manager_get_type ())
#define GALA_DAEMON_MODEL_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_DAEMON_TYPE_MODEL_MANAGER, GalaDaemonModelManager))
#define GALA_DAEMON_MODEL_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_DAEMON_TYPE_MODEL_MANAGER, GalaDaemonModelManagerClass))
#define GALA_DAEMON_IS_MODEL_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_DAEMON_TYPE_MODEL_MANAGER))
#define GALA_DAEMON_IS_MODEL_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_DAEMON_TYPE_MODEL_MANAGER))
#define GALA_DAEMON_MODEL_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_DAEMON_TYPE_MODEL_MANAGER, GalaDaemonModelManagerClass))

typedef struct _GalaDaemonModelManager GalaDaemonModelManager;
typedef struct _GalaDaemonModelManagerClass GalaDaemonModelManagerClass;
typedef struct _GalaDaemonModelManagerPrivate GalaDaemonModelManagerPrivate;

#define GALA_DAEMON_TYPE_KEYBOARD_MODEL (gala_daemon_keyboard_model_get_type ())
#define GALA_DAEMON_KEYBOARD_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_DAEMON_TYPE_KEYBOARD_MODEL, GalaDaemonKeyboardModel))
#define GALA_DAEMON_KEYBOARD_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_DAEMON_TYPE_KEYBOARD_MODEL, GalaDaemonKeyboardModelClass))
#define GALA_DAEMON_IS_KEYBOARD_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_DAEMON_TYPE_KEYBOARD_MODEL))
#define GALA_DAEMON_IS_KEYBOARD_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_DAEMON_TYPE_KEYBOARD_MODEL))
#define GALA_DAEMON_KEYBOARD_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_DAEMON_TYPE_KEYBOARD_MODEL, GalaDaemonKeyboardModelClass))

typedef struct _GalaDaemonKeyboardModel GalaDaemonKeyboardModel;
typedef struct _GalaDaemonKeyboardModelClass GalaDaemonKeyboardModelClass;
enum  {
	GALA_DAEMON_MODEL_MANAGER_0_PROPERTY,
	GALA_DAEMON_MODEL_MANAGER_CURRENT_MODEL_PROPERTY,
	GALA_DAEMON_MODEL_MANAGER_INPUT_PURPOSE_PROPERTY,
	GALA_DAEMON_MODEL_MANAGER_NUM_PROPERTIES
};
static GParamSpec* gala_daemon_model_manager_properties[GALA_DAEMON_MODEL_MANAGER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))
typedef struct _GalaDaemonModelManagerUpdateModelData GalaDaemonModelManagerUpdateModelData;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_bytes_unref0(var) ((var == NULL) ? NULL : (var = (g_bytes_unref (var), NULL)))

#define GALA_DAEMON_TYPE_GNOME_OSK_PARSER (gala_daemon_gnome_osk_parser_get_type ())
#define GALA_DAEMON_GNOME_OSK_PARSER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_DAEMON_TYPE_GNOME_OSK_PARSER, GalaDaemonGnomeOSKParser))
#define GALA_DAEMON_GNOME_OSK_PARSER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_DAEMON_TYPE_GNOME_OSK_PARSER, GalaDaemonGnomeOSKParserClass))
#define GALA_DAEMON_IS_GNOME_OSK_PARSER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_DAEMON_TYPE_GNOME_OSK_PARSER))
#define GALA_DAEMON_IS_GNOME_OSK_PARSER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_DAEMON_TYPE_GNOME_OSK_PARSER))
#define GALA_DAEMON_GNOME_OSK_PARSER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_DAEMON_TYPE_GNOME_OSK_PARSER, GalaDaemonGnomeOSKParserClass))

typedef struct _GalaDaemonGnomeOSKParser GalaDaemonGnomeOSKParser;
typedef struct _GalaDaemonGnomeOSKParserClass GalaDaemonGnomeOSKParserClass;
typedef struct _GalaDaemonModelManagerLoadModelData GalaDaemonModelManagerLoadModelData;

struct _GalaDaemonModelManager {
	GObject parent_instance;
	GalaDaemonModelManagerPrivate * priv;
};

struct _GalaDaemonModelManagerClass {
	GObjectClass parent_class;
};

struct _GalaDaemonModelManagerPrivate {
	GalaDaemonKeyboardModel* _current_model;
	IBusInputPurpose _input_purpose;
	GSettings* settings;
};

struct _GalaDaemonModelManagerUpdateModelData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GalaDaemonModelManager* self;
	GVariant* input_sources;
	GSettings* _tmp0_;
	GVariant* _tmp1_;
	guint current_source_index;
	GSettings* _tmp2_;
	GVariant* current_source;
	GVariant* _tmp3_;
	GVariant* _tmp4_;
	gchar* type;
	gchar* id;
	GVariant* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* group_name;
	const gchar* _tmp8_;
	const gchar* _tmp9_;
	gchar* _tmp10_;
	gchar** eligible_models;
	const gchar* _tmp11_;
	gint _tmp12_;
	gchar** _tmp13_;
	gint eligible_models_length1;
	gint _eligible_models_size_;
	gchar** _tmp14_;
	gint _tmp14__length1;
	gchar** model_collection;
	gint model_collection_length1;
	gint _model_collection_size_;
	gint model_it;
	gchar* _tmp15_;
	gchar* model;
	const gchar* _tmp16_;
};

struct _GalaDaemonModelManagerLoadModelData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GalaDaemonModelManager* self;
	gchar* name;
	gboolean result;
	gchar* path;
	gchar* _tmp0_;
	GBytes* data;
	GBytes* _tmp1_;
	const gchar* _tmp2_;
	GBytes* _tmp3_;
	GBytes* _tmp4_;
	GError* e;
	GError* _tmp5_;
	const gchar* _tmp6_;
	GalaDaemonGnomeOSKParser* parser;
	GalaDaemonGnomeOSKParser* _tmp7_;
	GalaDaemonKeyboardModel* _tmp8_;
	GalaDaemonGnomeOSKParser* _tmp9_;
	GBytes* _tmp10_;
	gsize _tmp11_;
	guint8* _tmp12_;
	GalaDaemonKeyboardModel* _tmp13_;
	GError* _vala1_e;
	GError* _tmp14_;
	const gchar* _tmp15_;
	GError* _inner_error0_;
};

static gint GalaDaemonModelManager_private_offset;
static gpointer gala_daemon_model_manager_parent_class = NULL;

VALA_EXTERN GType gala_daemon_model_manager_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaDaemonModelManager, g_object_unref)
VALA_EXTERN GType gala_daemon_keyboard_model_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaDaemonKeyboardModel, g_object_unref)
static void gala_daemon_model_manager_update_model_data_free (gpointer _data);
static void gala_daemon_model_manager_update_model (GalaDaemonModelManager* self,
                                             GAsyncReadyCallback _callback_,
                                             gpointer _user_data_);
static void gala_daemon_model_manager_update_model_finish (GalaDaemonModelManager* self,
                                                    GAsyncResult* _res_);
static gboolean gala_daemon_model_manager_update_model_co (GalaDaemonModelManagerUpdateModelData* _data_);
static gchar* gala_daemon_model_manager_get_group_name (GalaDaemonModelManager* self,
                                                 const gchar* type,
                                                 const gchar* id);
static gchar** gala_daemon_model_manager_get_eligible_models (GalaDaemonModelManager* self,
                                                       const gchar* current_group_name,
                                                       gint* result_length1);
static void gala_daemon_model_manager_load_model (GalaDaemonModelManager* self,
                                           const gchar* name,
                                           GAsyncReadyCallback _callback_,
                                           gpointer _user_data_);
static gboolean gala_daemon_model_manager_load_model_finish (GalaDaemonModelManager* self,
                                                      GAsyncResult* _res_);
static void gala_daemon_model_manager_update_model_ready (GObject* source_object,
                                                   GAsyncResult* _res_,
                                                   gpointer _user_data_);
VALA_EXTERN IBusInputPurpose gala_daemon_model_manager_get_input_purpose (GalaDaemonModelManager* self);
static void _vala_array_add1 (gchar** * array,
                       gint* length,
                       gint* size,
                       gchar* value);
static void _vala_array_add2 (gchar** * array,
                       gint* length,
                       gint* size,
                       gchar* value);
static void gala_daemon_model_manager_load_model_data_free (gpointer _data);
static gboolean gala_daemon_model_manager_load_model_co (GalaDaemonModelManagerLoadModelData* _data_);
VALA_EXTERN GType gala_daemon_gnome_osk_parser_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaDaemonGnomeOSKParser, g_object_unref)
VALA_EXTERN GalaDaemonGnomeOSKParser* gala_daemon_gnome_osk_parser_new (void);
VALA_EXTERN GalaDaemonGnomeOSKParser* gala_daemon_gnome_osk_parser_construct (GType object_type);
VALA_EXTERN void gala_daemon_gnome_osk_parser_parse (GalaDaemonGnomeOSKParser* self,
                                         guint8* data,
                                         gint data_length1,
                                         GAsyncReadyCallback _callback_,
                                         gpointer _user_data_);
VALA_EXTERN GalaDaemonKeyboardModel* gala_daemon_gnome_osk_parser_parse_finish (GalaDaemonGnomeOSKParser* self,
                                                                    GAsyncResult* _res_,
                                                                    GError** error);
static void gala_daemon_model_manager_load_model_ready (GObject* source_object,
                                                 GAsyncResult* _res_,
                                                 gpointer _user_data_);
static void gala_daemon_model_manager_set_current_model (GalaDaemonModelManager* self,
                                                  GalaDaemonKeyboardModel* value);
VALA_EXTERN GalaDaemonModelManager* gala_daemon_model_manager_new (void);
VALA_EXTERN GalaDaemonModelManager* gala_daemon_model_manager_construct (GType object_type);
VALA_EXTERN GalaDaemonKeyboardModel* gala_daemon_model_manager_get_current_model (GalaDaemonModelManager* self);
VALA_EXTERN void gala_daemon_model_manager_set_input_purpose (GalaDaemonModelManager* self,
                                                  IBusInputPurpose value);
static GObject * gala_daemon_model_manager_constructor (GType type,
                                                 guint n_construct_properties,
                                                 GObjectConstructParam * construct_properties);
static void _gala_daemon_model_manager_update_model_g_object_notify (GObject* _sender,
                                                              GParamSpec* pspec,
                                                              gpointer self);
static void _gala_daemon_model_manager_update_model_g_settings_changed (GSettings* _sender,
                                                                 const gchar* key,
                                                                 gpointer self);
static void gala_daemon_model_manager_finalize (GObject * obj);
static GType gala_daemon_model_manager_get_type_once (void);
static void _vala_gala_daemon_model_manager_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec);
static void _vala_gala_daemon_model_manager_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 GRegex* _tmp_regex_0 = NULL;

static inline gpointer
gala_daemon_model_manager_get_instance_private (GalaDaemonModelManager* self)
{
	return G_STRUCT_MEMBER_P (self, GalaDaemonModelManager_private_offset);
}

static void
gala_daemon_model_manager_update_model_data_free (gpointer _data)
{
	GalaDaemonModelManagerUpdateModelData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (GalaDaemonModelManagerUpdateModelData, _data_);
}

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

static void
gala_daemon_model_manager_update_model (GalaDaemonModelManager* self,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_)
{
	GalaDaemonModelManagerUpdateModelData* _data_;
	GalaDaemonModelManager* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (GalaDaemonModelManagerUpdateModelData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, gala_daemon_model_manager_update_model_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	gala_daemon_model_manager_update_model_co (_data_);
}

static void
gala_daemon_model_manager_update_model_finish (GalaDaemonModelManager* self,
                                               GAsyncResult* _res_)
{
	GalaDaemonModelManagerUpdateModelData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
gala_daemon_model_manager_update_model_ready (GObject* source_object,
                                              GAsyncResult* _res_,
                                              gpointer _user_data_)
{
	GalaDaemonModelManagerUpdateModelData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	gala_daemon_model_manager_update_model_co (_data_);
}

static gboolean
gala_daemon_model_manager_update_model_co (GalaDaemonModelManagerUpdateModelData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->priv->settings;
	_data_->_tmp1_ = g_settings_get_value (_data_->_tmp0_, "sources");
	_data_->input_sources = _data_->_tmp1_;
	_data_->_tmp2_ = _data_->self->priv->settings;
	_data_->current_source_index = g_settings_get_uint (_data_->_tmp2_, "current");
	_data_->_tmp3_ = _data_->input_sources;
	_data_->_tmp4_ = g_variant_get_child_value (_data_->_tmp3_, (gsize) _data_->current_source_index);
	_data_->current_source = _data_->_tmp4_;
	_data_->_tmp5_ = _data_->current_source;
	_data_->_tmp6_ = NULL;
	_data_->_tmp7_ = NULL;
	g_variant_get (_data_->_tmp5_, "(ss)", &_data_->_tmp6_, &_data_->_tmp7_, NULL);
	_g_free0 (_data_->type);
	_data_->type = _data_->_tmp6_;
	_g_free0 (_data_->id);
	_data_->id = _data_->_tmp7_;
	_data_->_tmp8_ = _data_->type;
	_data_->_tmp9_ = _data_->id;
	_data_->_tmp10_ = gala_daemon_model_manager_get_group_name (_data_->self, _data_->_tmp8_, _data_->_tmp9_);
	_data_->group_name = _data_->_tmp10_;
	_data_->_tmp11_ = _data_->group_name;
	_data_->_tmp12_ = 0;
	_data_->_tmp13_ = gala_daemon_model_manager_get_eligible_models (_data_->self, _data_->_tmp11_, &_data_->_tmp12_);
	_data_->eligible_models = _data_->_tmp13_;
	_data_->eligible_models_length1 = _data_->_tmp12_;
	_data_->_eligible_models_size_ = _data_->eligible_models_length1;
	_data_->_tmp14_ = _data_->eligible_models;
	_data_->_tmp14__length1 = _data_->eligible_models_length1;
	{
		_data_->model_collection_length1 = 0;
		_data_->_model_collection_size_ = 0;
		_data_->model_collection = _data_->_tmp14_;
		_data_->model_collection_length1 = _data_->_tmp14__length1;
		for (_data_->model_it = 0; _data_->model_it < _data_->model_collection_length1; _data_->model_it = _data_->model_it + 1) {
			_data_->_tmp15_ = g_strdup (_data_->model_collection[_data_->model_it]);
			_data_->model = _data_->_tmp15_;
			{
				_data_->_tmp16_ = _data_->model;
				_data_->_state_ = 1;
				gala_daemon_model_manager_load_model (_data_->self, _data_->_tmp16_, gala_daemon_model_manager_update_model_ready, _data_);
				return FALSE;
				_state_1:
				if (gala_daemon_model_manager_load_model_finish (_data_->self, _data_->_res_)) {
					_g_free0 (_data_->model);
					_data_->eligible_models = (_vala_array_free (_data_->eligible_models, _data_->eligible_models_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (_data_->group_name);
					_g_free0 (_data_->id);
					_g_free0 (_data_->type);
					_g_variant_unref0 (_data_->current_source);
					_g_variant_unref0 (_data_->input_sources);
					g_task_return_pointer (_data_->_async_result, _data_, NULL);
					if (_data_->_state_ != 0) {
						while (!g_task_get_completed (_data_->_async_result)) {
							g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
						}
					}
					g_object_unref (_data_->_async_result);
					return FALSE;
				}
				_g_free0 (_data_->model);
			}
		}
	}
	_data_->eligible_models = (_vala_array_free (_data_->eligible_models, _data_->eligible_models_length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (_data_->group_name);
	_g_free0 (_data_->id);
	_g_free0 (_data_->type);
	_g_variant_unref0 (_data_->current_source);
	_g_variant_unref0 (_data_->input_sources);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static gchar*
gala_daemon_model_manager_get_group_name (GalaDaemonModelManager* self,
                                          const gchar* type,
                                          const gchar* id)
{
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (type != NULL, NULL);
	g_return_val_if_fail (id != NULL, NULL);
	_tmp0_ = g_strdup (id);
	result = _tmp0_;
	return result;
}

static gboolean
string_contains (const gchar* self,
                 const gchar* needle)
{
	gchar* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (needle != NULL, FALSE);
	_tmp0_ = strstr ((gchar*) self, (gchar*) needle);
	result = _tmp0_ != NULL;
	return result;
}

static inline GRegex*
_thread_safe_regex_init (GRegex** re,
                         const gchar * pattern,
                         GRegexCompileFlags compile_flags)
{
	if (g_once_init_enter ((gsize*) re)) {
		GRegex* val = g_regex_new (pattern, compile_flags, 0, NULL);
		g_once_init_leave ((gsize*) re, (gsize) val);
	}
	return *re;
}

static void
_vala_array_add1 (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_add2 (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 gchar**
gala_daemon_model_manager_get_eligible_models (GalaDaemonModelManager* self,
                                               const gchar* current_group_name,
                                               gint* result_length1)
{
	IBusInputPurpose _tmp0_;
	gchar** groups = NULL;
	gchar* _tmp16_;
	gchar** _tmp17_;
	gint groups_length1;
	gint _groups_size_;
	gchar* _tmp25_;
	IBusInputPurpose _tmp26_;
	gchar** _tmp34_;
	gint _tmp34__length1;
	GError* _inner_error0_ = NULL;
	gchar** result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (current_group_name != NULL, NULL);
	_tmp0_ = self->priv->_input_purpose;
	switch (_tmp0_) {
		case IBUS_INPUT_PURPOSE_DIGITS:
		{
			gchar* _tmp1_;
			gchar** _tmp2_;
			gchar** _tmp3_;
			gint _tmp3__length1;
			_tmp1_ = g_strdup ("digits");
			_tmp2_ = g_new0 (gchar*, 1 + 1);
			_tmp2_[0] = _tmp1_;
			_tmp3_ = _tmp2_;
			_tmp3__length1 = 1;
			if (result_length1) {
				*result_length1 = _tmp3__length1;
			}
			result = _tmp3_;
			return result;
		}
		case IBUS_INPUT_PURPOSE_NUMBER:
		{
			gchar* _tmp4_;
			gchar** _tmp5_;
			gchar** _tmp6_;
			gint _tmp6__length1;
			_tmp4_ = g_strdup ("number");
			_tmp5_ = g_new0 (gchar*, 1 + 1);
			_tmp5_[0] = _tmp4_;
			_tmp6_ = _tmp5_;
			_tmp6__length1 = 1;
			if (result_length1) {
				*result_length1 = _tmp6__length1;
			}
			result = _tmp6_;
			return result;
		}
		case IBUS_INPUT_PURPOSE_PHONE:
		{
			gchar* _tmp7_;
			gchar** _tmp8_;
			gchar** _tmp9_;
			gint _tmp9__length1;
			_tmp7_ = g_strdup ("phone");
			_tmp8_ = g_new0 (gchar*, 1 + 1);
			_tmp8_[0] = _tmp7_;
			_tmp9_ = _tmp8_;
			_tmp9__length1 = 1;
			if (result_length1) {
				*result_length1 = _tmp9__length1;
			}
			result = _tmp9_;
			return result;
		}
		case IBUS_INPUT_PURPOSE_EMAIL:
		{
			gchar* _tmp10_;
			gchar** _tmp11_;
			gchar** _tmp12_;
			gint _tmp12__length1;
			_tmp10_ = g_strdup ("email");
			_tmp11_ = g_new0 (gchar*, 1 + 1);
			_tmp11_[0] = _tmp10_;
			_tmp12_ = _tmp11_;
			_tmp12__length1 = 1;
			if (result_length1) {
				*result_length1 = _tmp12__length1;
			}
			result = _tmp12_;
			return result;
		}
		case IBUS_INPUT_PURPOSE_URL:
		{
			gchar* _tmp13_;
			gchar** _tmp14_;
			gchar** _tmp15_;
			gint _tmp15__length1;
			_tmp13_ = g_strdup ("url");
			_tmp14_ = g_new0 (gchar*, 1 + 1);
			_tmp14_[0] = _tmp13_;
			_tmp15_ = _tmp14_;
			_tmp15__length1 = 1;
			if (result_length1) {
				*result_length1 = _tmp15__length1;
			}
			result = _tmp15_;
			return result;
		}
		default:
		{
			break;
		}
	}
	_tmp16_ = g_strdup (current_group_name);
	_tmp17_ = g_new0 (gchar*, 1 + 1);
	_tmp17_[0] = _tmp16_;
	groups = _tmp17_;
	groups_length1 = 1;
	_groups_size_ = groups_length1;
	if (string_contains (current_group_name, "+")) {
		{
			gchar* _tmp18_ = NULL;
			gint _tmp19_;
			gint _tmp20_;
			gchar* _tmp21_;
			gchar* _tmp22_;
			_tmp19_ = strlen (current_group_name);
			_tmp20_ = _tmp19_;
			_tmp21_ = g_regex_replace (_thread_safe_regex_init (&_tmp_regex_0, "\\+.*", 0), current_group_name, (gssize) _tmp20_, 0, "", 0, &_inner_error0_);
			_tmp18_ = _tmp21_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			_tmp22_ = _tmp18_;
			_tmp18_ = NULL;
			_vala_array_add1 (&groups, &groups_length1, &_groups_size_, _tmp22_);
			_g_free0 (_tmp18_);
		}
		goto __finally0;
		__catch0_g_error:
		{
			GError* e = NULL;
			GError* _tmp23_;
			const gchar* _tmp24_;
			e = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp23_ = e;
			_tmp24_ = _tmp23_->message;
			g_warning ("ModelManager.vala:73: Failed to parse group name: %s", _tmp24_);
			_g_error_free0 (e);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			groups = (_vala_array_free (groups, groups_length1, (GDestroyNotify) g_free), NULL);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
	}
	_tmp25_ = g_strdup ("us");
	_vala_array_add2 (&groups, &groups_length1, &_groups_size_, _tmp25_);
	_tmp26_ = self->priv->_input_purpose;
	if (_tmp26_ == IBUS_INPUT_PURPOSE_TERMINAL) {
		{
			gint i = 0;
			i = 0;
			{
				gboolean _tmp27_ = FALSE;
				_tmp27_ = TRUE;
				while (TRUE) {
					gchar** _tmp29_;
					gint _tmp29__length1;
					gchar** _tmp30_;
					gint _tmp30__length1;
					gchar** _tmp31_;
					gint _tmp31__length1;
					const gchar* _tmp32_;
					gchar* _tmp33_;
					if (!_tmp27_) {
						gint _tmp28_;
						_tmp28_ = i;
						i = _tmp28_ + 1;
					}
					_tmp27_ = FALSE;
					_tmp29_ = groups;
					_tmp29__length1 = groups_length1;
					if (!(i < _tmp29__length1)) {
						break;
					}
					_tmp30_ = groups;
					_tmp30__length1 = groups_length1;
					_tmp31_ = groups;
					_tmp31__length1 = groups_length1;
					_tmp32_ = _tmp31_[i];
					_tmp33_ = g_strconcat (_tmp32_, "-extended", NULL);
					_g_free0 (_tmp30_[i]);
					_tmp30_[i] = _tmp33_;
				}
			}
		}
	}
	_tmp34_ = groups;
	_tmp34__length1 = groups_length1;
	if (result_length1) {
		*result_length1 = _tmp34__length1;
	}
	result = _tmp34_;
	return result;
}

static void
gala_daemon_model_manager_load_model_data_free (gpointer _data)
{
	GalaDaemonModelManagerLoadModelData* _data_;
	_data_ = _data;
	_g_free0 (_data_->name);
	_g_object_unref0 (_data_->self);
	g_slice_free (GalaDaemonModelManagerLoadModelData, _data_);
}

static void
gala_daemon_model_manager_load_model (GalaDaemonModelManager* self,
                                      const gchar* name,
                                      GAsyncReadyCallback _callback_,
                                      gpointer _user_data_)
{
	GalaDaemonModelManagerLoadModelData* _data_;
	GalaDaemonModelManager* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (name != NULL);
	_data_ = g_slice_new0 (GalaDaemonModelManagerLoadModelData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, gala_daemon_model_manager_load_model_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = g_strdup (name);
	_g_free0 (_data_->name);
	_data_->name = _tmp1_;
	gala_daemon_model_manager_load_model_co (_data_);
}

static gboolean
gala_daemon_model_manager_load_model_finish (GalaDaemonModelManager* self,
                                             GAsyncResult* _res_)
{
	gboolean result;
	GalaDaemonModelManagerLoadModelData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	return result;
}

static void
gala_daemon_model_manager_load_model_ready (GObject* source_object,
                                            GAsyncResult* _res_,
                                            gpointer _user_data_)
{
	GalaDaemonModelManagerLoadModelData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	gala_daemon_model_manager_load_model_co (_data_);
}

static gboolean
gala_daemon_model_manager_load_model_co (GalaDaemonModelManagerLoadModelData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = g_strdup_printf ("/io/elementary/desktop/gala-daemon/osk-layouts/%s.json", _data_->name);
	_data_->path = _data_->_tmp0_;
	{
		_data_->_tmp2_ = _data_->path;
		_data_->_tmp3_ = g_resources_lookup_data (_data_->_tmp2_, G_RESOURCE_LOOKUP_FLAGS_NONE, &_data_->_inner_error0_);
		_data_->_tmp1_ = _data_->_tmp3_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp4_ = _data_->_tmp1_;
		_data_->_tmp1_ = NULL;
		_g_bytes_unref0 (_data_->data);
		_data_->data = _data_->_tmp4_;
		_g_bytes_unref0 (_data_->_tmp1_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp5_ = _data_->e;
		_data_->_tmp6_ = _data_->_tmp5_->message;
		g_warning ("ModelManager.vala:95: Failed to load keyboard model: %s", _data_->_tmp6_);
		_data_->result = FALSE;
		_g_error_free0 (_data_->e);
		_g_bytes_unref0 (_data_->data);
		_g_free0 (_data_->path);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_bytes_unref0 (_data_->data);
		_g_free0 (_data_->path);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp7_ = gala_daemon_gnome_osk_parser_new ();
	_data_->parser = _data_->_tmp7_;
	{
		_data_->_tmp9_ = _data_->parser;
		_data_->_tmp10_ = _data_->data;
		_data_->_tmp11_ = 0;
		_data_->_tmp12_ = g_bytes_get_data (_data_->_tmp10_, &_data_->_tmp11_);
		_data_->_state_ = 1;
		gala_daemon_gnome_osk_parser_parse (_data_->_tmp9_, _data_->_tmp12_, (gint) _data_->_tmp11_, gala_daemon_model_manager_load_model_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp13_ = gala_daemon_gnome_osk_parser_parse_finish (_data_->_tmp9_, _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp8_ = _data_->_tmp13_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch1_g_error;
		}
		gala_daemon_model_manager_set_current_model (_data_->self, _data_->_tmp8_);
		_data_->result = TRUE;
		_g_object_unref0 (_data_->_tmp8_);
		_g_object_unref0 (_data_->parser);
		_g_bytes_unref0 (_data_->data);
		_g_free0 (_data_->path);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	goto __finally1;
	__catch1_g_error:
	{
		_data_->_vala1_e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp14_ = _data_->_vala1_e;
		_data_->_tmp15_ = _data_->_tmp14_->message;
		g_warning ("ModelManager.vala:105: Failed to load keyboard model: %s", _data_->_tmp15_);
		_data_->result = FALSE;
		_g_error_free0 (_data_->_vala1_e);
		_g_object_unref0 (_data_->parser);
		_g_bytes_unref0 (_data_->data);
		_g_free0 (_data_->path);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	__finally1:
	_g_object_unref0 (_data_->parser);
	_g_bytes_unref0 (_data_->data);
	_g_free0 (_data_->path);
	g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
	g_clear_error (&_data_->_inner_error0_);
	g_object_unref (_data_->_async_result);
	return FALSE;
}

GalaDaemonModelManager*
gala_daemon_model_manager_construct (GType object_type)
{
	GalaDaemonModelManager * self = NULL;
	self = (GalaDaemonModelManager*) g_object_new (object_type, NULL);
	return self;
}

GalaDaemonModelManager*
gala_daemon_model_manager_new (void)
{
	return gala_daemon_model_manager_construct (GALA_DAEMON_TYPE_MODEL_MANAGER);
}

GalaDaemonKeyboardModel*
gala_daemon_model_manager_get_current_model (GalaDaemonModelManager* self)
{
	GalaDaemonKeyboardModel* result;
	GalaDaemonKeyboardModel* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_current_model;
	result = _tmp0_;
	return result;
}

static void
gala_daemon_model_manager_set_current_model (GalaDaemonModelManager* self,
                                             GalaDaemonKeyboardModel* value)
{
	GalaDaemonKeyboardModel* old_value;
	g_return_if_fail (self != NULL);
	old_value = gala_daemon_model_manager_get_current_model (self);
	if (old_value != value) {
		GalaDaemonKeyboardModel* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_current_model);
		self->priv->_current_model = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, gala_daemon_model_manager_properties[GALA_DAEMON_MODEL_MANAGER_CURRENT_MODEL_PROPERTY]);
	}
}

IBusInputPurpose
gala_daemon_model_manager_get_input_purpose (GalaDaemonModelManager* self)
{
	IBusInputPurpose result;
	g_return_val_if_fail (self != NULL, 0);
	result = self->priv->_input_purpose;
	return result;
}

void
gala_daemon_model_manager_set_input_purpose (GalaDaemonModelManager* self,
                                             IBusInputPurpose value)
{
	IBusInputPurpose old_value;
	g_return_if_fail (self != NULL);
	old_value = gala_daemon_model_manager_get_input_purpose (self);
	if (old_value != value) {
		self->priv->_input_purpose = value;
		g_object_notify_by_pspec ((GObject *) self, gala_daemon_model_manager_properties[GALA_DAEMON_MODEL_MANAGER_INPUT_PURPOSE_PROPERTY]);
	}
}

static void
_gala_daemon_model_manager_update_model_g_object_notify (GObject* _sender,
                                                         GParamSpec* pspec,
                                                         gpointer self)
{
	gala_daemon_model_manager_update_model ((GalaDaemonModelManager*) self, NULL, NULL);
}

static void
_gala_daemon_model_manager_update_model_g_settings_changed (GSettings* _sender,
                                                            const gchar* key,
                                                            gpointer self)
{
	gala_daemon_model_manager_update_model ((GalaDaemonModelManager*) self, NULL, NULL);
}

static GObject *
gala_daemon_model_manager_constructor (GType type,
                                       guint n_construct_properties,
                                       GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GalaDaemonModelManager * self;
	GSettings* _tmp0_;
	GSettings* _tmp1_;
	GSettings* _tmp2_;
	parent_class = G_OBJECT_CLASS (gala_daemon_model_manager_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_DAEMON_TYPE_MODEL_MANAGER, GalaDaemonModelManager);
	g_signal_connect_object ((GObject*) self, "notify::input-purpose", (GCallback) _gala_daemon_model_manager_update_model_g_object_notify, self, 0);
	_tmp0_ = g_settings_new ("org.gnome.desktop.input-sources");
	_g_object_unref0 (self->priv->settings);
	self->priv->settings = _tmp0_;
	_tmp1_ = self->priv->settings;
	g_signal_connect_object (_tmp1_, "changed::current", (GCallback) _gala_daemon_model_manager_update_model_g_settings_changed, self, 0);
	_tmp2_ = self->priv->settings;
	g_signal_connect_object (_tmp2_, "changed::sources", (GCallback) _gala_daemon_model_manager_update_model_g_settings_changed, self, 0);
	gala_daemon_model_manager_update_model (self, NULL, NULL);
	return obj;
}

static void
gala_daemon_model_manager_class_init (GalaDaemonModelManagerClass * klass,
                                      gpointer klass_data)
{
	gala_daemon_model_manager_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GalaDaemonModelManager_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_gala_daemon_model_manager_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gala_daemon_model_manager_set_property;
	G_OBJECT_CLASS (klass)->constructor = gala_daemon_model_manager_constructor;
	G_OBJECT_CLASS (klass)->finalize = gala_daemon_model_manager_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GALA_DAEMON_MODEL_MANAGER_CURRENT_MODEL_PROPERTY, gala_daemon_model_manager_properties[GALA_DAEMON_MODEL_MANAGER_CURRENT_MODEL_PROPERTY] = g_param_spec_object ("current-model", "current-model", "current-model", GALA_DAEMON_TYPE_KEYBOARD_MODEL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GALA_DAEMON_MODEL_MANAGER_INPUT_PURPOSE_PROPERTY, gala_daemon_model_manager_properties[GALA_DAEMON_MODEL_MANAGER_INPUT_PURPOSE_PROPERTY] = g_param_spec_enum ("input-purpose", "input-purpose", "input-purpose", ibus_input_purpose_get_type (), IBUS_INPUT_PURPOSE_FREE_FORM, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
gala_daemon_model_manager_instance_init (GalaDaemonModelManager * self,
                                         gpointer klass)
{
	self->priv = gala_daemon_model_manager_get_instance_private (self);
	self->priv->_input_purpose = IBUS_INPUT_PURPOSE_FREE_FORM;
}

static void
gala_daemon_model_manager_finalize (GObject * obj)
{
	GalaDaemonModelManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_DAEMON_TYPE_MODEL_MANAGER, GalaDaemonModelManager);
	_g_object_unref0 (self->priv->_current_model);
	_g_object_unref0 (self->priv->settings);
	G_OBJECT_CLASS (gala_daemon_model_manager_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
gala_daemon_model_manager_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GalaDaemonModelManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gala_daemon_model_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GalaDaemonModelManager), 0, (GInstanceInitFunc) gala_daemon_model_manager_instance_init, NULL };
	GType gala_daemon_model_manager_type_id;
	gala_daemon_model_manager_type_id = g_type_register_static (G_TYPE_OBJECT, "GalaDaemonModelManager", &g_define_type_info, G_TYPE_FLAG_NONE);
	GalaDaemonModelManager_private_offset = g_type_add_instance_private (gala_daemon_model_manager_type_id, sizeof (GalaDaemonModelManagerPrivate));
	return gala_daemon_model_manager_type_id;
}

GType
gala_daemon_model_manager_get_type (void)
{
	static gsize gala_daemon_model_manager_type_id__once = 0;
	if (g_once_init_enter (&gala_daemon_model_manager_type_id__once)) {
		GType gala_daemon_model_manager_type_id;
		gala_daemon_model_manager_type_id = gala_daemon_model_manager_get_type_once ();
		g_once_init_leave (&gala_daemon_model_manager_type_id__once, gala_daemon_model_manager_type_id);
	}
	return gala_daemon_model_manager_type_id__once;
}

static void
_vala_gala_daemon_model_manager_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec)
{
	GalaDaemonModelManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_DAEMON_TYPE_MODEL_MANAGER, GalaDaemonModelManager);
	switch (property_id) {
		case GALA_DAEMON_MODEL_MANAGER_CURRENT_MODEL_PROPERTY:
		g_value_set_object (value, gala_daemon_model_manager_get_current_model (self));
		break;
		case GALA_DAEMON_MODEL_MANAGER_INPUT_PURPOSE_PROPERTY:
		g_value_set_enum (value, gala_daemon_model_manager_get_input_purpose (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_gala_daemon_model_manager_set_property (GObject * object,
                                              guint property_id,
                                              const GValue * value,
                                              GParamSpec * pspec)
{
	GalaDaemonModelManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_DAEMON_TYPE_MODEL_MANAGER, GalaDaemonModelManager);
	switch (property_id) {
		case GALA_DAEMON_MODEL_MANAGER_CURRENT_MODEL_PROPERTY:
		gala_daemon_model_manager_set_current_model (self, g_value_get_object (value));
		break;
		case GALA_DAEMON_MODEL_MANAGER_INPUT_PURPOSE_PROPERTY:
		gala_daemon_model_manager_set_input_purpose (self, g_value_get_enum (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);
}

