/* GnomeOSKParser.c generated by valac 0.56.19, the Vala compiler
 * generated from GnomeOSKParser.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 <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <json-glib/json-glib.h>
#include <gdk/gdk.h>
#include <float.h>
#include <math.h>
#include <errno.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_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 _GalaDaemonGnomeOSKParserPrivate GalaDaemonGnomeOSKParserPrivate;
enum  {
	GALA_DAEMON_GNOME_OSK_PARSER_0_PROPERTY,
	GALA_DAEMON_GNOME_OSK_PARSER_NUM_PROPERTIES
};
static GParamSpec* gala_daemon_gnome_osk_parser_properties[GALA_DAEMON_GNOME_OSK_PARSER_NUM_PROPERTIES];
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#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;

#define GALA_DAEMON_TYPE_KEYBOARD_MODEL_BUILDER (gala_daemon_keyboard_model_builder_get_type ())
#define GALA_DAEMON_KEYBOARD_MODEL_BUILDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_DAEMON_TYPE_KEYBOARD_MODEL_BUILDER, GalaDaemonKeyboardModelBuilder))
#define GALA_DAEMON_KEYBOARD_MODEL_BUILDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_DAEMON_TYPE_KEYBOARD_MODEL_BUILDER, GalaDaemonKeyboardModelBuilderClass))
#define GALA_DAEMON_IS_KEYBOARD_MODEL_BUILDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_DAEMON_TYPE_KEYBOARD_MODEL_BUILDER))
#define GALA_DAEMON_IS_KEYBOARD_MODEL_BUILDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_DAEMON_TYPE_KEYBOARD_MODEL_BUILDER))
#define GALA_DAEMON_KEYBOARD_MODEL_BUILDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_DAEMON_TYPE_KEYBOARD_MODEL_BUILDER, GalaDaemonKeyboardModelBuilderClass))

typedef struct _GalaDaemonKeyboardModelBuilder GalaDaemonKeyboardModelBuilder;
typedef struct _GalaDaemonKeyboardModelBuilderClass GalaDaemonKeyboardModelBuilderClass;
#define _json_array_unref0(var) ((var == NULL) ? NULL : (var = (json_array_unref (var), NULL)))
#define _json_object_unref0(var) ((var == NULL) ? NULL : (var = (json_object_unref (var), NULL)))
typedef struct _GalaDaemonGnomeOskParserParseData GalaDaemonGnomeOskParserParseData;
#define _g_free0(var) (var = (g_free (var), NULL))

struct _GalaDaemonGnomeOSKParser {
	GObject parent_instance;
	GalaDaemonGnomeOSKParserPrivate * priv;
};

struct _GalaDaemonGnomeOSKParserClass {
	GObjectClass parent_class;
};

struct _GalaDaemonGnomeOSKParserPrivate {
	GHashTable* level_modes;
};

struct _GalaDaemonGnomeOskParserParseData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GalaDaemonGnomeOSKParser* self;
	guint8* data;
	gint data_length1;
	GalaDaemonKeyboardModel* result;
	JsonParser* parser;
	JsonParser* _tmp0_;
	JsonParser* _tmp1_;
	JsonObject* root;
	JsonParser* _tmp2_;
	JsonNode* _tmp3_;
	JsonObject* _tmp4_;
	JsonObject* _tmp5_;
	GalaDaemonKeyboardModelBuilder* builder;
	GalaDaemonKeyboardModelBuilder* _tmp6_;
	JsonArray* levels;
	JsonObject* _tmp7_;
	JsonArray* _tmp8_;
	JsonArray* _tmp9_;
	JsonArray* _tmp10_;
	GalaDaemonKeyboardModelBuilder* _tmp11_;
	GalaDaemonKeyboardModelBuilder* _tmp12_;
	GalaDaemonKeyboardModel* _tmp13_;
	GError* _inner_error0_;
};

static gint GalaDaemonGnomeOSKParser_private_offset;
static gpointer gala_daemon_gnome_osk_parser_parent_class = NULL;

VALA_EXTERN GType gala_daemon_gnome_osk_parser_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaDaemonGnomeOSKParser, g_object_unref)
static void _g_free0_ (gpointer var);
static void gala_daemon_gnome_osk_parser_parse_data_free (gpointer _data);
VALA_EXTERN GType gala_daemon_keyboard_model_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaDaemonKeyboardModel, g_object_unref)
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 gboolean gala_daemon_gnome_osk_parser_parse_co (GalaDaemonGnomeOskParserParseData* _data_);
VALA_EXTERN GType gala_daemon_keyboard_model_builder_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaDaemonKeyboardModelBuilder, g_object_unref)
VALA_EXTERN GalaDaemonKeyboardModelBuilder* gala_daemon_keyboard_model_builder_new (void);
VALA_EXTERN GalaDaemonKeyboardModelBuilder* gala_daemon_keyboard_model_builder_construct (GType object_type);
static void gala_daemon_gnome_osk_parser_parse_levels (GalaDaemonGnomeOSKParser* self,
                                                JsonArray* json,
                                                GalaDaemonKeyboardModelBuilder* builder,
                                                GError** error);
VALA_EXTERN GalaDaemonKeyboardModel* gala_daemon_keyboard_model_builder_end (GalaDaemonKeyboardModelBuilder* self);
static void gala_daemon_gnome_osk_parser_parse_level (GalaDaemonGnomeOSKParser* self,
                                               JsonObject* json,
                                               GalaDaemonKeyboardModelBuilder* builder,
                                               GError** error);
VALA_EXTERN void gala_daemon_keyboard_model_builder_begin_view (GalaDaemonKeyboardModelBuilder* self,
                                                    const gchar* name);
VALA_EXTERN void gala_daemon_keyboard_model_builder_set_view_default (GalaDaemonKeyboardModelBuilder* self);
static void gala_daemon_gnome_osk_parser_parse_row (GalaDaemonGnomeOSKParser* self,
                                             JsonArray* json,
                                             GalaDaemonKeyboardModelBuilder* builder,
                                             GError** error);
VALA_EXTERN void gala_daemon_keyboard_model_builder_end_view (GalaDaemonKeyboardModelBuilder* self);
VALA_EXTERN void gala_daemon_keyboard_model_builder_begin_row (GalaDaemonKeyboardModelBuilder* self);
static void gala_daemon_gnome_osk_parser_parse_key (GalaDaemonGnomeOSKParser* self,
                                             JsonObject* json,
                                             GalaDaemonKeyboardModelBuilder* builder,
                                             GError** error);
VALA_EXTERN void gala_daemon_keyboard_model_builder_end_row (GalaDaemonKeyboardModelBuilder* self);
VALA_EXTERN void gala_daemon_keyboard_model_builder_begin_key (GalaDaemonKeyboardModelBuilder* self);
VALA_EXTERN void gala_daemon_keyboard_model_builder_set_key_val_action (GalaDaemonKeyboardModelBuilder* self,
                                                            guint val);
VALA_EXTERN void gala_daemon_keyboard_model_builder_set_key_label (GalaDaemonKeyboardModelBuilder* self,
                                                       const gchar* label);
VALA_EXTERN void gala_daemon_keyboard_model_builder_set_key_left_offset (GalaDaemonKeyboardModelBuilder* self,
                                                             gdouble left_offset);
VALA_EXTERN void gala_daemon_keyboard_model_builder_set_key_width (GalaDaemonKeyboardModelBuilder* self,
                                                       gdouble width);
VALA_EXTERN void gala_daemon_keyboard_model_builder_set_key_height (GalaDaemonKeyboardModelBuilder* self,
                                                        gdouble height);
VALA_EXTERN void gala_daemon_keyboard_model_builder_set_key_icon_name (GalaDaemonKeyboardModelBuilder* self,
                                                           const gchar* icon_name);
VALA_EXTERN void gala_daemon_keyboard_model_builder_set_erase_action (GalaDaemonKeyboardModelBuilder* self);
VALA_EXTERN void gala_daemon_keyboard_model_builder_set_set_view_action (GalaDaemonKeyboardModelBuilder* self,
                                                             const gchar* view_name);
VALA_EXTERN void gala_daemon_keyboard_model_builder_set_latch_view_action (GalaDaemonKeyboardModelBuilder* self,
                                                               const gchar* view_name);
VALA_EXTERN void gala_daemon_keyboard_model_builder_set_hide_action (GalaDaemonKeyboardModelBuilder* self);
VALA_EXTERN void gala_daemon_keyboard_model_builder_end_key (GalaDaemonKeyboardModelBuilder* self);
VALA_EXTERN GalaDaemonGnomeOSKParser* gala_daemon_gnome_osk_parser_new (void);
VALA_EXTERN GalaDaemonGnomeOSKParser* gala_daemon_gnome_osk_parser_construct (GType object_type);
static void gala_daemon_gnome_osk_parser_finalize (GObject * obj);
static GType gala_daemon_gnome_osk_parser_get_type_once (void);

static inline gpointer
gala_daemon_gnome_osk_parser_get_instance_private (GalaDaemonGnomeOSKParser* self)
{
	return G_STRUCT_MEMBER_P (self, GalaDaemonGnomeOSKParser_private_offset);
}

static void
_g_free0_ (gpointer var)
{
	var = (g_free (var), NULL);
}

static void
gala_daemon_gnome_osk_parser_parse_data_free (gpointer _data)
{
	GalaDaemonGnomeOskParserParseData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GalaDaemonGnomeOskParserParseData, _data_);
}

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

void
gala_daemon_gnome_osk_parser_parse (GalaDaemonGnomeOSKParser* self,
                                    guint8* data,
                                    gint data_length1,
                                    GAsyncReadyCallback _callback_,
                                    gpointer _user_data_)
{
	GalaDaemonGnomeOskParserParseData* _data_;
	GalaDaemonGnomeOSKParser* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (GalaDaemonGnomeOskParserParseData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, gala_daemon_gnome_osk_parser_parse_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->data = data;
	_data_->data_length1 = data_length1;
	gala_daemon_gnome_osk_parser_parse_co (_data_);
}

GalaDaemonKeyboardModel*
gala_daemon_gnome_osk_parser_parse_finish (GalaDaemonGnomeOSKParser* self,
                                           GAsyncResult* _res_,
                                           GError** error)
{
	GalaDaemonKeyboardModel* result;
	GalaDaemonGnomeOskParserParseData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static gpointer
_json_object_ref0 (gpointer self)
{
	return self ? json_object_ref (self) : NULL;
}

static gpointer
_json_array_ref0 (gpointer self)
{
	return self ? json_array_ref (self) : NULL;
}

static gboolean
gala_daemon_gnome_osk_parser_parse_co (GalaDaemonGnomeOskParserParseData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = json_parser_new ();
	_data_->parser = _data_->_tmp0_;
	_data_->_tmp1_ = _data_->parser;
	json_parser_load_from_data (_data_->_tmp1_, (const gchar*) _data_->data, (gssize) _data_->data_length1, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->parser);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp2_ = _data_->parser;
	_data_->_tmp3_ = json_parser_get_root (_data_->_tmp2_);
	_data_->_tmp4_ = json_node_get_object (_data_->_tmp3_);
	_data_->_tmp5_ = _json_object_ref0 (_data_->_tmp4_);
	_data_->root = _data_->_tmp5_;
	_data_->_tmp6_ = gala_daemon_keyboard_model_builder_new ();
	_data_->builder = _data_->_tmp6_;
	_data_->_tmp7_ = _data_->root;
	_data_->_tmp8_ = json_object_get_array_member (_data_->_tmp7_, "levels");
	_data_->_tmp9_ = _json_array_ref0 (_data_->_tmp8_);
	_data_->levels = _data_->_tmp9_;
	_data_->_tmp10_ = _data_->levels;
	_data_->_tmp11_ = _data_->builder;
	gala_daemon_gnome_osk_parser_parse_levels (_data_->self, _data_->_tmp10_, _data_->_tmp11_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_json_array_unref0 (_data_->levels);
		_g_object_unref0 (_data_->builder);
		_json_object_unref0 (_data_->root);
		_g_object_unref0 (_data_->parser);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp12_ = _data_->builder;
	_data_->_tmp13_ = gala_daemon_keyboard_model_builder_end (_data_->_tmp12_);
	_data_->result = _data_->_tmp13_;
	_json_array_unref0 (_data_->levels);
	_g_object_unref0 (_data_->builder);
	_json_object_unref0 (_data_->root);
	_g_object_unref0 (_data_->parser);
	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 void
gala_daemon_gnome_osk_parser_parse_levels (GalaDaemonGnomeOSKParser* self,
                                           JsonArray* json,
                                           GalaDaemonKeyboardModelBuilder* builder,
                                           GError** error)
{
	GHashTable* _tmp0_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (json != NULL);
	g_return_if_fail (builder != NULL);
	_tmp0_ = self->priv->level_modes;
	g_hash_table_remove_all (_tmp0_);
	{
		guint i = 0U;
		i = (guint) 0;
		{
			gboolean _tmp1_ = FALSE;
			_tmp1_ = TRUE;
			while (TRUE) {
				JsonObject* level_node = NULL;
				JsonObject* _tmp3_;
				JsonObject* _tmp4_;
				gchar* level_name = NULL;
				JsonObject* _tmp5_;
				const gchar* _tmp6_;
				gchar* _tmp7_;
				gchar* level_mode = NULL;
				JsonObject* _tmp8_;
				const gchar* _tmp9_;
				gchar* _tmp10_;
				GHashTable* _tmp11_;
				const gchar* _tmp12_;
				gchar* _tmp13_;
				const gchar* _tmp14_;
				gchar* _tmp15_;
				if (!_tmp1_) {
					guint _tmp2_;
					_tmp2_ = i;
					i = _tmp2_ + 1;
				}
				_tmp1_ = FALSE;
				if (!(i < json_array_get_length (json))) {
					break;
				}
				_tmp3_ = json_array_get_object_element (json, i);
				_tmp4_ = _json_object_ref0 (_tmp3_);
				level_node = _tmp4_;
				_tmp5_ = level_node;
				_tmp6_ = json_object_get_string_member (_tmp5_, "level");
				_tmp7_ = g_strdup (_tmp6_);
				level_name = _tmp7_;
				_tmp8_ = level_node;
				_tmp9_ = json_object_get_string_member (_tmp8_, "mode");
				_tmp10_ = g_strdup (_tmp9_);
				level_mode = _tmp10_;
				_tmp11_ = self->priv->level_modes;
				_tmp12_ = level_name;
				_tmp13_ = g_strdup (_tmp12_);
				_tmp14_ = level_mode;
				_tmp15_ = g_strdup (_tmp14_);
				g_hash_table_insert (_tmp11_, _tmp13_, _tmp15_);
				_g_free0 (level_mode);
				_g_free0 (level_name);
				_json_object_unref0 (level_node);
			}
		}
	}
	{
		guint i = 0U;
		i = (guint) 0;
		{
			gboolean _tmp16_ = FALSE;
			_tmp16_ = TRUE;
			while (TRUE) {
				JsonObject* level_node = NULL;
				JsonObject* _tmp18_;
				JsonObject* _tmp19_;
				JsonObject* _tmp20_;
				if (!_tmp16_) {
					guint _tmp17_;
					_tmp17_ = i;
					i = _tmp17_ + 1;
				}
				_tmp16_ = FALSE;
				if (!(i < json_array_get_length (json))) {
					break;
				}
				_tmp18_ = json_array_get_object_element (json, i);
				_tmp19_ = _json_object_ref0 (_tmp18_);
				level_node = _tmp19_;
				_tmp20_ = level_node;
				gala_daemon_gnome_osk_parser_parse_level (self, _tmp20_, builder, &_inner_error0_);
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					g_propagate_error (error, _inner_error0_);
					_json_object_unref0 (level_node);
					return;
				}
				_json_object_unref0 (level_node);
			}
		}
	}
}

static void
gala_daemon_gnome_osk_parser_parse_level (GalaDaemonGnomeOSKParser* self,
                                          JsonObject* json,
                                          GalaDaemonKeyboardModelBuilder* builder,
                                          GError** error)
{
	gchar* level_name = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* level_mode = NULL;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	const gchar* _tmp4_;
	const gchar* _tmp5_;
	JsonArray* rows = NULL;
	JsonArray* _tmp6_;
	JsonArray* _tmp7_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (json != NULL);
	g_return_if_fail (builder != NULL);
	_tmp0_ = json_object_get_string_member (json, "level");
	_tmp1_ = g_strdup (_tmp0_);
	level_name = _tmp1_;
	_tmp2_ = json_object_get_string_member (json, "mode");
	_tmp3_ = g_strdup (_tmp2_);
	level_mode = _tmp3_;
	_tmp4_ = level_name;
	gala_daemon_keyboard_model_builder_begin_view (builder, _tmp4_);
	_tmp5_ = level_mode;
	if (g_strcmp0 (_tmp5_, "default") == 0) {
		gala_daemon_keyboard_model_builder_set_view_default (builder);
	}
	_tmp6_ = json_object_get_array_member (json, "rows");
	_tmp7_ = _json_array_ref0 (_tmp6_);
	rows = _tmp7_;
	{
		guint i = 0U;
		i = (guint) 0;
		{
			gboolean _tmp8_ = FALSE;
			_tmp8_ = TRUE;
			while (TRUE) {
				JsonArray* _tmp10_;
				JsonArray* row_node = NULL;
				JsonArray* _tmp11_;
				JsonArray* _tmp12_;
				JsonArray* _tmp13_;
				JsonArray* _tmp14_;
				if (!_tmp8_) {
					guint _tmp9_;
					_tmp9_ = i;
					i = _tmp9_ + 1;
				}
				_tmp8_ = FALSE;
				_tmp10_ = rows;
				if (!(i < json_array_get_length (_tmp10_))) {
					break;
				}
				_tmp11_ = rows;
				_tmp12_ = json_array_get_array_element (_tmp11_, i);
				_tmp13_ = _json_array_ref0 (_tmp12_);
				row_node = _tmp13_;
				_tmp14_ = row_node;
				gala_daemon_gnome_osk_parser_parse_row (self, _tmp14_, builder, &_inner_error0_);
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					g_propagate_error (error, _inner_error0_);
					_json_array_unref0 (row_node);
					_json_array_unref0 (rows);
					_g_free0 (level_mode);
					_g_free0 (level_name);
					return;
				}
				_json_array_unref0 (row_node);
			}
		}
	}
	gala_daemon_keyboard_model_builder_end_view (builder);
	_json_array_unref0 (rows);
	_g_free0 (level_mode);
	_g_free0 (level_name);
}

static void
gala_daemon_gnome_osk_parser_parse_row (GalaDaemonGnomeOSKParser* self,
                                        JsonArray* json,
                                        GalaDaemonKeyboardModelBuilder* builder,
                                        GError** error)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (json != NULL);
	g_return_if_fail (builder != NULL);
	gala_daemon_keyboard_model_builder_begin_row (builder);
	{
		guint i = 0U;
		i = (guint) 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				JsonObject* key_node = NULL;
				JsonObject* _tmp2_;
				JsonObject* _tmp3_;
				JsonObject* _tmp4_;
				if (!_tmp0_) {
					guint _tmp1_;
					_tmp1_ = i;
					i = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				if (!(i < json_array_get_length (json))) {
					break;
				}
				_tmp2_ = json_array_get_object_element (json, i);
				_tmp3_ = _json_object_ref0 (_tmp2_);
				key_node = _tmp3_;
				_tmp4_ = key_node;
				gala_daemon_gnome_osk_parser_parse_key (self, _tmp4_, builder, &_inner_error0_);
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					g_propagate_error (error, _inner_error0_);
					_json_object_unref0 (key_node);
					return;
				}
				_json_object_unref0 (key_node);
			}
		}
	}
	gala_daemon_keyboard_model_builder_end_row (builder);
}

static gchar
string_get (const gchar* self,
            glong index)
{
	gchar _tmp0_;
	gchar result;
	g_return_val_if_fail (self != NULL, '\0');
	_tmp0_ = ((gchar*) self)[index];
	result = _tmp0_;
	return result;
}

static gboolean
uint_try_parse (const gchar* str,
                guint* _result_,
                const gchar** unparsed,
                guint _base)
{
	guint _vala__result_ = 0U;
	const gchar* _vala_unparsed = NULL;
	gchar* endptr = NULL;
	gulong ulong_result = 0UL;
	gchar* _tmp0_ = NULL;
	gulong _tmp1_;
	gchar* _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	gulong _tmp6_;
	gboolean result;
	g_return_val_if_fail (str != NULL, FALSE);
	errno = 0;
	_tmp1_ = strtoul (str, &_tmp0_, (gint) _base);
	endptr = _tmp0_;
	ulong_result = _tmp1_;
	_tmp2_ = endptr;
	_tmp3_ = strlen (str);
	_tmp4_ = _tmp3_;
	if (_tmp2_ == (((gchar*) str) + _tmp4_)) {
		_vala_unparsed = "";
	} else {
		gchar* _tmp5_;
		_tmp5_ = endptr;
		_vala_unparsed = (const gchar*) _tmp5_;
	}
	_tmp6_ = ulong_result;
	if ((((gulong) 0) <= _tmp6_) && (_tmp6_ <= ((gulong) G_MAXUINT))) {
		gboolean _tmp7_ = FALSE;
		gboolean _tmp8_ = FALSE;
		_vala__result_ = (guint) ulong_result;
		if (errno != ERANGE) {
			_tmp8_ = errno != EINVAL;
		} else {
			_tmp8_ = FALSE;
		}
		if (_tmp8_) {
			const gchar* _tmp9_;
			gchar* _tmp10_;
			_tmp9_ = _vala_unparsed;
			_tmp10_ = endptr;
			_tmp7_ = _tmp9_ != _tmp10_;
		} else {
			_tmp7_ = FALSE;
		}
		result = _tmp7_;
		if (_result_) {
			*_result_ = _vala__result_;
		}
		if (unparsed) {
			*unparsed = _vala_unparsed;
		}
		return result;
	} else {
		_vala__result_ = G_MAXUINT;
		result = FALSE;
		if (_result_) {
			*_result_ = _vala__result_;
		}
		if (unparsed) {
			*unparsed = _vala_unparsed;
		}
		return result;
	}
}

static void
gala_daemon_gnome_osk_parser_parse_key (GalaDaemonGnomeOSKParser* self,
                                        JsonObject* json,
                                        GalaDaemonKeyboardModelBuilder* builder,
                                        GError** error)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (json != NULL);
	g_return_if_fail (builder != NULL);
	gala_daemon_keyboard_model_builder_begin_key (builder);
	if (json_object_has_member (json, "strings")) {
		JsonArray* strings = NULL;
		JsonArray* _tmp0_;
		JsonArray* _tmp1_;
		_tmp0_ = json_object_get_array_member (json, "strings");
		_tmp1_ = _json_array_ref0 (_tmp0_);
		strings = _tmp1_;
		{
			guint i = 0U;
			i = (guint) 0;
			{
				gboolean _tmp2_ = FALSE;
				_tmp2_ = TRUE;
				while (TRUE) {
					JsonArray* _tmp4_;
					gchar* str = NULL;
					JsonArray* _tmp5_;
					const gchar* _tmp6_;
					gchar* _tmp7_;
					if (!_tmp2_) {
						guint _tmp3_;
						_tmp3_ = i;
						i = _tmp3_ + 1;
					}
					_tmp2_ = FALSE;
					_tmp4_ = strings;
					if (!(i < json_array_get_length (_tmp4_))) {
						break;
					}
					_tmp5_ = strings;
					_tmp6_ = json_array_get_string_element (_tmp5_, i);
					_tmp7_ = g_strdup (_tmp6_);
					str = _tmp7_;
					if (i == ((guint) 0)) {
						const gchar* _tmp8_;
						const gchar* _tmp9_;
						_tmp8_ = str;
						gala_daemon_keyboard_model_builder_set_key_val_action (builder, gdk_unicode_to_keyval ((guint32) string_get (_tmp8_, (glong) 0)));
						_tmp9_ = str;
						gala_daemon_keyboard_model_builder_set_key_label (builder, _tmp9_);
					} else {
						_g_free0 (str);
						break;
					}
					_g_free0 (str);
				}
			}
		}
		_json_array_unref0 (strings);
	}
	if (json_object_has_member (json, "leftOffset")) {
		gala_daemon_keyboard_model_builder_set_key_left_offset (builder, json_object_get_double_member (json, "leftOffset"));
	}
	if (json_object_has_member (json, "width")) {
		gala_daemon_keyboard_model_builder_set_key_width (builder, json_object_get_double_member (json, "width"));
	}
	if (json_object_has_member (json, "height")) {
		gala_daemon_keyboard_model_builder_set_key_height (builder, json_object_get_double_member (json, "height"));
	}
	if (json_object_has_member (json, "label")) {
		gchar* label = NULL;
		const gchar* _tmp10_;
		gchar* _tmp11_;
		const gchar* _tmp12_;
		_tmp10_ = json_object_get_string_member (json, "label");
		_tmp11_ = g_strdup (_tmp10_);
		label = _tmp11_;
		_tmp12_ = label;
		gala_daemon_keyboard_model_builder_set_key_label (builder, _tmp12_);
		_g_free0 (label);
	}
	if (json_object_has_member (json, "iconName")) {
		gchar* icon_name = NULL;
		const gchar* _tmp13_;
		gchar* _tmp14_;
		const gchar* _tmp15_;
		_tmp13_ = json_object_get_string_member (json, "iconName");
		_tmp14_ = g_strdup (_tmp13_);
		icon_name = _tmp14_;
		_tmp15_ = icon_name;
		gala_daemon_keyboard_model_builder_set_key_icon_name (builder, _tmp15_);
		_g_free0 (icon_name);
	}
	if (json_object_has_member (json, "keyval")) {
		gchar* keyval_str = NULL;
		const gchar* _tmp16_;
		gchar* _tmp17_;
		guint keyval = 0U;
		const gchar* _tmp18_;
		guint _tmp19_ = 0U;
		gboolean _tmp20_;
		_tmp16_ = json_object_get_string_member (json, "keyval");
		_tmp17_ = g_strdup (_tmp16_);
		keyval_str = _tmp17_;
		_tmp18_ = keyval_str;
		_tmp20_ = uint_try_parse (_tmp18_, &_tmp19_, NULL, (guint) 0);
		keyval = _tmp19_;
		if (_tmp20_) {
			gala_daemon_keyboard_model_builder_set_key_val_action (builder, keyval);
		} else {
			const gchar* _tmp21_;
			gchar* _tmp22_;
			gchar* _tmp23_;
			GError* _tmp24_;
			GError* _tmp25_;
			_tmp21_ = keyval_str;
			_tmp22_ = g_strdup_printf ("Failed to parse key val %s", _tmp21_);
			_tmp23_ = _tmp22_;
			_tmp24_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, _tmp23_);
			_tmp25_ = _tmp24_;
			_g_free0 (_tmp23_);
			_inner_error0_ = _tmp25_;
			g_propagate_error (error, _inner_error0_);
			_g_free0 (keyval_str);
			return;
		}
		_g_free0 (keyval_str);
	}
	if (json_object_has_member (json, "action")) {
		gchar* action = NULL;
		const gchar* _tmp26_;
		gchar* _tmp27_;
		const gchar* _tmp28_;
		const gchar* _tmp29_;
		GQuark _tmp31_ = 0U;
		static GQuark _tmp30_label0 = 0;
		static GQuark _tmp30_label1 = 0;
		static GQuark _tmp30_label2 = 0;
		static GQuark _tmp30_label3 = 0;
		static GQuark _tmp30_label4 = 0;
		_tmp26_ = json_object_get_string_member (json, "action");
		_tmp27_ = g_strdup (_tmp26_);
		action = _tmp27_;
		_tmp28_ = action;
		_tmp29_ = _tmp28_;
		_tmp31_ = (NULL == _tmp29_) ? 0 : g_quark_from_string (_tmp29_);
		if (_tmp31_ == ((0 != _tmp30_label0) ? _tmp30_label0 : (_tmp30_label0 = g_quark_from_static_string ("delete")))) {
			switch (0) {
				default:
				{
					gala_daemon_keyboard_model_builder_set_erase_action (builder);
					break;
				}
			}
		} else if (_tmp31_ == ((0 != _tmp30_label1) ? _tmp30_label1 : (_tmp30_label1 = g_quark_from_static_string ("levelSwitch")))) {
			switch (0) {
				default:
				{
					gchar* level = NULL;
					const gchar* _tmp32_;
					gchar* _tmp33_;
					gchar* level_mode = NULL;
					GHashTable* _tmp34_;
					const gchar* _tmp35_;
					gconstpointer _tmp36_;
					gchar* _tmp37_;
					const gchar* _tmp38_;
					const gchar* _tmp39_;
					GQuark _tmp41_ = 0U;
					static GQuark _tmp40_label0 = 0;
					static GQuark _tmp40_label1 = 0;
					static GQuark _tmp40_label2 = 0;
					static GQuark _tmp40_label3 = 0;
					_tmp32_ = json_object_get_string_member (json, "level");
					_tmp33_ = g_strdup (_tmp32_);
					level = _tmp33_;
					_tmp34_ = self->priv->level_modes;
					_tmp35_ = level;
					_tmp36_ = g_hash_table_lookup (_tmp34_, _tmp35_);
					_tmp37_ = g_strdup ((const gchar*) _tmp36_);
					level_mode = _tmp37_;
					_tmp38_ = level_mode;
					_tmp39_ = _tmp38_;
					_tmp41_ = (NULL == _tmp39_) ? 0 : g_quark_from_string (_tmp39_);
					if (_tmp41_ == ((0 != _tmp40_label0) ? _tmp40_label0 : (_tmp40_label0 = g_quark_from_static_string (NULL)))) {
						switch (0) {
							default:
							{
								const gchar* _tmp42_;
								_tmp42_ = level;
								gala_daemon_keyboard_model_builder_set_set_view_action (builder, _tmp42_);
								break;
							}
						}
					} else if (_tmp41_ == ((0 != _tmp40_label1) ? _tmp40_label1 : (_tmp40_label1 = g_quark_from_static_string ("latched")))) {
						switch (0) {
							default:
							{
								const gchar* _tmp43_;
								_tmp43_ = level;
								gala_daemon_keyboard_model_builder_set_latch_view_action (builder, _tmp43_);
								break;
							}
						}
					} else if ((_tmp41_ == ((0 != _tmp40_label2) ? _tmp40_label2 : (_tmp40_label2 = g_quark_from_static_string ("default")))) || (_tmp41_ == ((0 != _tmp40_label3) ? _tmp40_label3 : (_tmp40_label3 = g_quark_from_static_string ("locked"))))) {
						switch (0) {
							default:
							{
								const gchar* _tmp44_;
								_tmp44_ = level;
								gala_daemon_keyboard_model_builder_set_set_view_action (builder, _tmp44_);
								break;
							}
						}
					}
					_g_free0 (level_mode);
					_g_free0 (level);
					break;
				}
			}
		} else if (_tmp31_ == ((0 != _tmp30_label2) ? _tmp30_label2 : (_tmp30_label2 = g_quark_from_static_string ("emoji")))) {
			switch (0) {
				default:
				{
					break;
				}
			}
		} else if (_tmp31_ == ((0 != _tmp30_label3) ? _tmp30_label3 : (_tmp30_label3 = g_quark_from_static_string ("languageMenu")))) {
			switch (0) {
				default:
				{
					break;
				}
			}
		} else if (_tmp31_ == ((0 != _tmp30_label4) ? _tmp30_label4 : (_tmp30_label4 = g_quark_from_static_string ("hide")))) {
			switch (0) {
				default:
				{
					gala_daemon_keyboard_model_builder_set_hide_action (builder);
					break;
				}
			}
		}
		_g_free0 (action);
	}
	gala_daemon_keyboard_model_builder_end_key (builder);
}

GalaDaemonGnomeOSKParser*
gala_daemon_gnome_osk_parser_construct (GType object_type)
{
	GalaDaemonGnomeOSKParser * self = NULL;
	self = (GalaDaemonGnomeOSKParser*) g_object_new (object_type, NULL);
	return self;
}

GalaDaemonGnomeOSKParser*
gala_daemon_gnome_osk_parser_new (void)
{
	return gala_daemon_gnome_osk_parser_construct (GALA_DAEMON_TYPE_GNOME_OSK_PARSER);
}

static void
gala_daemon_gnome_osk_parser_class_init (GalaDaemonGnomeOSKParserClass * klass,
                                         gpointer klass_data)
{
	gala_daemon_gnome_osk_parser_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GalaDaemonGnomeOSKParser_private_offset);
	G_OBJECT_CLASS (klass)->finalize = gala_daemon_gnome_osk_parser_finalize;
}

static void
gala_daemon_gnome_osk_parser_instance_init (GalaDaemonGnomeOSKParser * self,
                                            gpointer klass)
{
	GHashFunc _tmp0_;
	GEqualFunc _tmp1_;
	GHashTable* _tmp2_;
	self->priv = gala_daemon_gnome_osk_parser_get_instance_private (self);
	_tmp0_ = g_str_hash;
	_tmp1_ = g_str_equal;
	_tmp2_ = g_hash_table_new_full (_tmp0_, _tmp1_, _g_free0_, _g_free0_);
	self->priv->level_modes = _tmp2_;
}

static void
gala_daemon_gnome_osk_parser_finalize (GObject * obj)
{
	GalaDaemonGnomeOSKParser * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_DAEMON_TYPE_GNOME_OSK_PARSER, GalaDaemonGnomeOSKParser);
	_g_hash_table_unref0 (self->priv->level_modes);
	G_OBJECT_CLASS (gala_daemon_gnome_osk_parser_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
gala_daemon_gnome_osk_parser_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GalaDaemonGnomeOSKParserClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gala_daemon_gnome_osk_parser_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GalaDaemonGnomeOSKParser), 0, (GInstanceInitFunc) gala_daemon_gnome_osk_parser_instance_init, NULL };
	GType gala_daemon_gnome_osk_parser_type_id;
	gala_daemon_gnome_osk_parser_type_id = g_type_register_static (G_TYPE_OBJECT, "GalaDaemonGnomeOSKParser", &g_define_type_info, G_TYPE_FLAG_NONE);
	GalaDaemonGnomeOSKParser_private_offset = g_type_add_instance_private (gala_daemon_gnome_osk_parser_type_id, sizeof (GalaDaemonGnomeOSKParserPrivate));
	return gala_daemon_gnome_osk_parser_type_id;
}

GType
gala_daemon_gnome_osk_parser_get_type (void)
{
	static gsize gala_daemon_gnome_osk_parser_type_id__once = 0;
	if (g_once_init_enter (&gala_daemon_gnome_osk_parser_type_id__once)) {
		GType gala_daemon_gnome_osk_parser_type_id;
		gala_daemon_gnome_osk_parser_type_id = gala_daemon_gnome_osk_parser_get_type_once ();
		g_once_init_leave (&gala_daemon_gnome_osk_parser_type_id__once, gala_daemon_gnome_osk_parser_type_id);
	}
	return gala_daemon_gnome_osk_parser_type_id__once;
}

