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

/*-
 * Copyright (c) 2015 Wingpanel Developers (http://launchpad.net/wingpanel)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Library General Public License as published by
 * the Free Software Foundation, either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This 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 Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "keyboard.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <wingpanel-9.h>
#include <gio/gio.h>
#include <ibus.h>
#include <gtk/gtk.h>
#include <granite-7.h>
#include <glib-object.h>
#include <libxml/tree.h>
#include <libxml/parser.h>
#include <libxml/xpath.h>
#include <glib/gi18n-lib.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

enum  {
	KEYBOARD_WIDGETS_POPOVER_WIDGET_0_PROPERTY,
	KEYBOARD_WIDGETS_POPOVER_WIDGET_CURRENT_LANGUAGE_CODE_PROPERTY,
	KEYBOARD_WIDGETS_POPOVER_WIDGET_CURRENT_LAYOUT_VARIANT_PROPERTY,
	KEYBOARD_WIDGETS_POPOVER_WIDGET_SERVER_TYPE_PROPERTY,
	KEYBOARD_WIDGETS_POPOVER_WIDGET_NUM_PROPERTIES
};
static GParamSpec* keyboard_widgets_popover_widget_properties[KEYBOARD_WIDGETS_POPOVER_WIDGET_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)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))
#define _g_variant_iter_free0(var) ((var == NULL) ? NULL : (var = (g_variant_iter_free (var), NULL)))
#define _xmlFreeDoc0(var) ((var == NULL) ? NULL : (var = (xmlFreeDoc (var), NULL)))
#define _xmlXPathFreeContext0(var) ((var == NULL) ? NULL : (var = (xmlXPathFreeContext (var), NULL)))
#define _xmlXPathFreeObject0(var) ((var == NULL) ? NULL : (var = (xmlXPathFreeObject (var), NULL)))
#define _g_variant_type_free0(var) ((var == NULL) ? NULL : (var = (g_variant_type_free (var), NULL)))
enum  {
	KEYBOARD_WIDGETS_POPOVER_WIDGET_UPDATED_SIGNAL,
	KEYBOARD_WIDGETS_POPOVER_WIDGET_NUM_SIGNALS
};
static guint keyboard_widgets_popover_widget_signals[KEYBOARD_WIDGETS_POPOVER_WIDGET_NUM_SIGNALS] = {0};

struct _KeyboardWidgetsPopoverWidgetPrivate {
	gchar* _current_language_code;
	gchar* _current_layout_variant;
	WingpanelIndicatorManagerServerType _server_type;
	GSettings* settings;
	GList* engines;
	GtkListBox* xkb_box;
	GtkListBox* ibus_box;
	GtkRevealer* ibus_box_revealer;
	GtkRevealer* ibus_header_revealer;
	GraniteSwitchModelButton* ibus_header;
	IBusBus* bus;
};

static gint KeyboardWidgetsPopoverWidget_private_offset;
static gpointer keyboard_widgets_popover_widget_parent_class = NULL;

static void _g_object_unref0_ (gpointer var);
static inline void _g_list_free__g_object_unref0_ (GList* self);
static void keyboard_widgets_popover_widget_show_settings (KeyboardWidgetsPopoverWidget* self);
static void keyboard_widgets_popover_widget_show_keyboard_map (KeyboardWidgetsPopoverWidget* self);
static void keyboard_widgets_popover_widget_populate_layouts (KeyboardWidgetsPopoverWidget* self);
static void keyboard_widgets_popover_widget_set_ibus_engine (KeyboardWidgetsPopoverWidget* self,
                                                      const gchar* manager,
                                                      const gchar* source);
static void keyboard_widgets_popover_widget_set_active_layout_from_settings (KeyboardWidgetsPopoverWidget* self);
static void keyboard_widgets_popover_widget_action_change_layout (KeyboardWidgetsPopoverWidget* self,
                                                           GSimpleAction* action,
                                                           GVariant* parameter);
static void keyboard_widgets_popover_widget_set_active_layout (KeyboardWidgetsPopoverWidget* self,
                                                        guint32 index);
static GVariant* _variant_new1 (guint32 value);
static GVariant* _variant_new2 (guint32 value);
static void keyboard_widgets_popover_widget_set_active_layout_to_xkb (KeyboardWidgetsPopoverWidget* self);
static GVariant* _variant_new3 (guint32 value);
static void keyboard_widgets_popover_widget_set_layout_active_in_box (KeyboardWidgetsPopoverWidget* self,
                                                               GtkListBox* layout_box,
                                                               guint index,
                                                               gboolean clear);
static GObject * keyboard_widgets_popover_widget_constructor (GType type,
                                                       guint n_construct_properties,
                                                       GObjectConstructParam * construct_properties);
static void _vala_GValue_array_free (GValue * array,
                              gssize array_length);
static void _keyboard_widgets_popover_widget_show_keyboard_map_gtk_button_clicked (GtkButton* _sender,
                                                                            gpointer self);
static void _keyboard_widgets_popover_widget_show_settings_gtk_button_clicked (GtkButton* _sender,
                                                                        gpointer self);
static void _keyboard_widgets_popover_widget___lambda4_ (KeyboardWidgetsPopoverWidget* self);
static void __keyboard_widgets_popover_widget___lambda4__ibus_bus_connected (IBusBus* _sender,
                                                                      gpointer self);
static void _keyboard_widgets_popover_widget___lambda5_ (KeyboardWidgetsPopoverWidget* self);
static void __keyboard_widgets_popover_widget___lambda5__ibus_bus_disconnected (IBusBus* _sender,
                                                                         gpointer self);
static void _keyboard_widgets_popover_widget___lambda6_ (KeyboardWidgetsPopoverWidget* self);
static void __keyboard_widgets_popover_widget___lambda6__g_settings_changed (GSettings* _sender,
                                                                      const gchar* key,
                                                                      gpointer self);
static void _keyboard_widgets_popover_widget___lambda7_ (KeyboardWidgetsPopoverWidget* self);
static void __keyboard_widgets_popover_widget___lambda7__g_settings_changed (GSettings* _sender,
                                                                      const gchar* key,
                                                                      gpointer self);
static void _keyboard_widgets_popover_widget___lambda8_ (KeyboardWidgetsPopoverWidget* self);
static void __keyboard_widgets_popover_widget___lambda8__gtk_toggle_button_toggled (GtkToggleButton* _sender,
                                                                             gpointer self);
static void _keyboard_widgets_popover_widget_action_change_layout_g_simple_action_activate (GSimpleAction* _sender,
                                                                                     GVariant* parameter,
                                                                                     gpointer self);
static void keyboard_widgets_popover_widget_finalize (GObject * obj);
static GType keyboard_widgets_popover_widget_get_type_once (void);
static void _vala_keyboard_widgets_popover_widget_get_property (GObject * object,
                                                         guint property_id,
                                                         GValue * value,
                                                         GParamSpec * pspec);
static void _vala_keyboard_widgets_popover_widget_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_widgets_popover_widget_get_instance_private (KeyboardWidgetsPopoverWidget* self)
{
	return G_STRUCT_MEMBER_P (self, KeyboardWidgetsPopoverWidget_private_offset);
}

static void
_g_object_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}

static inline void
_g_list_free__g_object_unref0_ (GList* self)
{
	g_list_free_full (self, (GDestroyNotify) _g_object_unref0_);
}

KeyboardWidgetsPopoverWidget*
keyboard_widgets_popover_widget_construct (GType object_type,
                                           WingpanelIndicatorManagerServerType server_type)
{
	KeyboardWidgetsPopoverWidget * self = NULL;
	self = (KeyboardWidgetsPopoverWidget*) g_object_new (object_type, "server-type", server_type, NULL);
	return self;
}

KeyboardWidgetsPopoverWidget*
keyboard_widgets_popover_widget_new (WingpanelIndicatorManagerServerType server_type)
{
	return keyboard_widgets_popover_widget_construct (KEYBOARD_WIDGETS_TYPE_POPOVER_WIDGET, server_type);
}

static void
keyboard_widgets_popover_widget_show_settings (KeyboardWidgetsPopoverWidget* self)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	{
		g_app_info_launch_default_for_uri ("settings://input/keyboard/layout", NULL, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp0_;
		const gchar* _tmp1_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp0_ = e;
		_tmp1_ = _tmp0_->message;
		g_warning ("PopoverWidget.vala:159: %s", _tmp1_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != 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;
	}
}

static void
keyboard_widgets_popover_widget_show_keyboard_map (KeyboardWidgetsPopoverWidget* self)
{
	gchar* command = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = keyboard_widgets_popover_widget_get_current_with_variant (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_strconcat ("gkbd-keyboard-display \"--layout=", _tmp1_, NULL);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strconcat (_tmp3_, "\"", NULL);
	_tmp5_ = _tmp4_;
	_g_free0 (_tmp3_);
	_g_free0 (_tmp1_);
	command = _tmp5_;
	{
		GAppInfo* _tmp6_ = NULL;
		const gchar* _tmp7_;
		GAppInfo* _tmp8_;
		_tmp7_ = command;
		_tmp8_ = g_app_info_create_from_commandline (_tmp7_, NULL, G_APP_INFO_CREATE_NONE, &_inner_error0_);
		_tmp6_ = _tmp8_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		g_app_info_launch (_tmp6_, NULL, NULL, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (_tmp6_);
			goto __catch0_g_error;
		}
		_g_object_unref0 (_tmp6_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp9_;
		const gchar* _tmp10_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp9_ = e;
		_tmp10_ = _tmp9_->message;
		g_warning ("PopoverWidget.vala:169: Error launching keyboard layout display: %s", _tmp10_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_free0 (command);
		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;
	}
	_g_free0 (command);
}

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 gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static gchar*
string_replace (const gchar* self,
                const gchar* old,
                const gchar* replacement)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (old != NULL, NULL);
	g_return_val_if_fail (replacement != NULL, NULL);
	if ((*((gchar*) self)) == '\0') {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = (*((gchar*) old)) == '\0';
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = g_strcmp0 (old, replacement) == 0;
	}
	if (_tmp0_) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup (self);
		result = _tmp2_;
		return result;
	}
	{
		GRegex* regex = NULL;
		gchar* _tmp3_;
		gchar* _tmp4_;
		GRegex* _tmp5_;
		GRegex* _tmp6_;
		gchar* _tmp7_ = NULL;
		GRegex* _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		_tmp3_ = g_regex_escape_string (old, -1);
		_tmp4_ = _tmp3_;
		_tmp5_ = g_regex_new (_tmp4_, 0, 0, &_inner_error0_);
		_tmp6_ = _tmp5_;
		_g_free0 (_tmp4_);
		regex = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected 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;
		}
		_tmp8_ = regex;
		_tmp9_ = g_regex_replace_literal (_tmp8_, self, (gssize) -1, 0, replacement, 0, &_inner_error0_);
		_tmp7_ = _tmp9_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected 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;
		}
		_tmp10_ = _tmp7_;
		_tmp7_ = NULL;
		result = _tmp10_;
		_g_free0 (_tmp7_);
		_g_regex_unref0 (regex);
		return result;
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		g_clear_error (&_inner_error0_);
		g_assert_not_reached ();
	}
	__finally0:
	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;
}

static void
keyboard_widgets_popover_widget_populate_layouts (KeyboardWidgetsPopoverWidget* self)
{
	GtkRevealer* _tmp10_;
	GtkRevealer* _tmp11_;
	GVariant* source_list = NULL;
	GSettings* _tmp12_;
	GVariant* _tmp13_;
	IBusBus* _tmp14_;
	KeyboardWidgetsLayoutButton* layout_button = NULL;
	GVariantIter* iter = NULL;
	GVariant* _tmp17_;
	GVariantIter* _tmp18_;
	guint32 i = 0U;
	gchar* manager_type = NULL;
	gchar* source = NULL;
	GtkListBox* _tmp105_;
	GtkListBoxRow* _tmp106_;
	g_return_if_fail (self != NULL);
	while (TRUE) {
		GtkListBox* _tmp0_;
		GtkListBoxRow* _tmp1_;
		GtkListBox* _tmp2_;
		GtkListBox* _tmp3_;
		GtkListBoxRow* _tmp4_;
		_tmp0_ = self->priv->xkb_box;
		_tmp1_ = gtk_list_box_get_row_at_index (_tmp0_, 0);
		if (!(_tmp1_ != NULL)) {
			break;
		}
		_tmp2_ = self->priv->xkb_box;
		_tmp3_ = self->priv->xkb_box;
		_tmp4_ = gtk_list_box_get_row_at_index (_tmp3_, 0);
		gtk_list_box_remove (_tmp2_, (GtkWidget*) _tmp4_);
	}
	while (TRUE) {
		GtkListBox* _tmp5_;
		GtkListBoxRow* _tmp6_;
		GtkListBox* _tmp7_;
		GtkListBox* _tmp8_;
		GtkListBoxRow* _tmp9_;
		_tmp5_ = self->priv->ibus_box;
		_tmp6_ = gtk_list_box_get_row_at_index (_tmp5_, 0);
		if (!(_tmp6_ != NULL)) {
			break;
		}
		_tmp7_ = self->priv->ibus_box;
		_tmp8_ = self->priv->ibus_box;
		_tmp9_ = gtk_list_box_get_row_at_index (_tmp8_, 0);
		gtk_list_box_remove (_tmp7_, (GtkWidget*) _tmp9_);
	}
	_tmp10_ = self->priv->ibus_header_revealer;
	gtk_revealer_set_reveal_child (_tmp10_, FALSE);
	_tmp11_ = self->priv->ibus_box_revealer;
	gtk_revealer_set_reveal_child (_tmp11_, FALSE);
	_tmp12_ = self->priv->settings;
	_tmp13_ = g_settings_get_value (_tmp12_, "sources");
	source_list = _tmp13_;
	(self->priv->engines == NULL) ? NULL : (self->priv->engines = (_g_list_free__g_object_unref0_ (self->priv->engines), NULL));
	self->priv->engines = NULL;
	_tmp14_ = self->priv->bus;
	if (ibus_bus_is_connected (_tmp14_)) {
		IBusBus* _tmp15_;
		GList* _tmp16_;
		_tmp15_ = self->priv->bus;
		_tmp16_ = ibus_bus_list_engines (_tmp15_);
		(self->priv->engines == NULL) ? NULL : (self->priv->engines = (_g_list_free__g_object_unref0_ (self->priv->engines), NULL));
		self->priv->engines = _tmp16_;
		keyboard_widgets_popover_widget_set_ibus_engine (self, KEYBOARD_WIDGETS_POPOVER_WIDGET_XKB_MANAGER_TYPE, "");
	}
	layout_button = NULL;
	_tmp17_ = source_list;
	_tmp18_ = g_variant_iter_new (_tmp17_);
	iter = _tmp18_;
	i = (guint32) 0;
	while (TRUE) {
		GVariantIter* _tmp19_;
		gchar* _tmp20_ = NULL;
		gchar* _tmp21_ = NULL;
		gboolean _tmp22_;
		gchar* language = NULL;
		gchar* _tmp23_;
		gchar* layout_variant = NULL;
		gchar* button_label = NULL;
		const gchar* _tmp24_;
		const gchar* _tmp25_;
		GQuark _tmp27_ = 0U;
		static GQuark _tmp26_label0 = 0;
		static GQuark _tmp26_label1 = 0;
		const gchar* _tmp70_ = NULL;
		const gchar* _tmp71_;
		gchar* _tmp72_;
		const gchar* _tmp73_;
		GVariant* action_target = NULL;
		GVariant* _tmp81_;
		const gchar* _tmp82_ = NULL;
		const gchar* _tmp83_;
		const gchar* _tmp84_;
		gchar* _tmp85_;
		gchar* _tmp86_;
		GVariant* _tmp87_;
		const gchar* _tmp88_;
		gchar* _tmp89_;
		gchar* _tmp90_;
		const gchar* _tmp91_;
		gchar* _tmp92_;
		const gchar* _tmp93_;
		gchar* _tmp94_;
		KeyboardWidgetsLayoutButton* _tmp95_ = NULL;
		const gchar* _tmp96_;
		const gchar* _tmp97_;
		GQuark _tmp99_ = 0U;
		static GQuark _tmp98_label0 = 0;
		static GQuark _tmp98_label1 = 0;
		guint32 _tmp104_;
		_tmp19_ = iter;
		_tmp22_ = g_variant_iter_next (_tmp19_, "(ss)", &_tmp20_, &_tmp21_, NULL);
		_g_free0 (manager_type);
		manager_type = _tmp20_;
		_g_free0 (source);
		source = _tmp21_;
		if (!_tmp22_) {
			break;
		}
		_tmp23_ = g_strdup ("us");
		language = _tmp23_;
		layout_variant = NULL;
		button_label = NULL;
		_tmp24_ = manager_type;
		_tmp25_ = _tmp24_;
		_tmp27_ = (NULL == _tmp25_) ? 0 : g_quark_from_string (_tmp25_);
		if (_tmp27_ == ((0 != _tmp26_label0) ? _tmp26_label0 : (_tmp26_label0 = g_quark_from_static_string (KEYBOARD_WIDGETS_POPOVER_WIDGET_XKB_MANAGER_TYPE)))) {
			switch (0) {
				default:
				{
					const gchar* _tmp28_;
					const gchar* _tmp40_;
					const gchar* _tmp41_;
					gchar* _tmp42_;
					_tmp28_ = source;
					if (string_contains (_tmp28_, "+")) {
						gchar** layouts = NULL;
						const gchar* _tmp29_;
						gchar** _tmp30_;
						gchar** _tmp31_;
						gint layouts_length1;
						gint _layouts_size_;
						gchar** _tmp32_;
						gint _tmp32__length1;
						const gchar* _tmp33_;
						gchar* _tmp34_;
						gchar** _tmp35_;
						gint _tmp35__length1;
						const gchar* _tmp36_;
						gchar* _tmp37_;
						_tmp29_ = source;
						_tmp31_ = _tmp30_ = g_strsplit (_tmp29_, "+", 2);
						layouts = _tmp31_;
						layouts_length1 = _vala_array_length (_tmp30_);
						_layouts_size_ = layouts_length1;
						_tmp32_ = layouts;
						_tmp32__length1 = layouts_length1;
						_tmp33_ = _tmp32_[0];
						_tmp34_ = g_strdup (_tmp33_);
						_g_free0 (language);
						language = _tmp34_;
						_tmp35_ = layouts;
						_tmp35__length1 = layouts_length1;
						_tmp36_ = _tmp35_[1];
						_tmp37_ = g_strdup (_tmp36_);
						_g_free0 (layout_variant);
						layout_variant = _tmp37_;
						layouts = (_vala_array_free (layouts, layouts_length1, (GDestroyNotify) g_free), NULL);
					} else {
						const gchar* _tmp38_;
						gchar* _tmp39_;
						_tmp38_ = source;
						_tmp39_ = g_strdup (_tmp38_);
						_g_free0 (language);
						language = _tmp39_;
					}
					_tmp40_ = language;
					_tmp41_ = layout_variant;
					_tmp42_ = keyboard_widgets_popover_widget_get_name_for_xkb_layout (self, _tmp40_, _tmp41_);
					_g_free0 (button_label);
					button_label = _tmp42_;
					break;
				}
			}
		} else if (_tmp27_ == ((0 != _tmp26_label1) ? _tmp26_label1 : (_tmp26_label1 = g_quark_from_static_string (KEYBOARD_WIDGETS_POPOVER_WIDGET_IBUS_MANAGER_TYPE)))) {
			switch (0) {
				default:
				{
					GList* _tmp43_;
					GList* _tmp44_;
					_tmp43_ = self->priv->engines;
					if (_tmp43_ == NULL) {
						_g_free0 (button_label);
						_g_free0 (layout_variant);
						_g_free0 (language);
						continue;
					}
					_tmp44_ = self->priv->engines;
					{
						GList* engine_collection = NULL;
						GList* engine_it = NULL;
						engine_collection = _tmp44_;
						for (engine_it = engine_collection; engine_it != NULL; engine_it = engine_it->next) {
							IBusEngineDesc* _tmp45_;
							IBusEngineDesc* engine = NULL;
							_tmp45_ = _g_object_ref0 ((IBusEngineDesc*) engine_it->data);
							engine = _tmp45_;
							{
								gboolean _tmp46_ = FALSE;
								IBusEngineDesc* _tmp47_;
								_tmp47_ = engine;
								if (_tmp47_ != NULL) {
									IBusEngineDesc* _tmp48_;
									const gchar* _tmp49_;
									const gchar* _tmp50_;
									const gchar* _tmp51_;
									_tmp48_ = engine;
									_tmp49_ = ibus_engine_desc_get_name (_tmp48_);
									_tmp50_ = _tmp49_;
									_tmp51_ = source;
									_tmp46_ = g_strcmp0 (_tmp50_, _tmp51_) == 0;
								} else {
									_tmp46_ = FALSE;
								}
								if (_tmp46_) {
									const gchar* _tmp52_;
									IBusEngineDesc* _tmp63_;
									const gchar* _tmp64_;
									gchar* _tmp65_;
									IBusEngineDesc* _tmp66_;
									const gchar* _tmp67_;
									gchar* _tmp68_;
									_tmp52_ = source;
									if (string_contains (_tmp52_, "xkb")) {
										IBusEngineDesc* _tmp53_;
										const gchar* _tmp54_;
										gchar* _tmp55_;
										_tmp53_ = engine;
										_tmp54_ = ibus_engine_desc_get_longname (_tmp53_);
										_tmp55_ = g_strdup (_tmp54_);
										_g_free0 (button_label);
										button_label = _tmp55_;
									} else {
										gchar* lang_name = NULL;
										IBusEngineDesc* _tmp56_;
										const gchar* _tmp57_;
										gchar* _tmp58_;
										const gchar* _tmp59_;
										IBusEngineDesc* _tmp60_;
										const gchar* _tmp61_;
										gchar* _tmp62_;
										_tmp56_ = engine;
										_tmp57_ = ibus_engine_desc_get_language (_tmp56_);
										_tmp58_ = ibus_get_language_name (_tmp57_);
										lang_name = _tmp58_;
										_tmp59_ = lang_name;
										_tmp60_ = engine;
										_tmp61_ = ibus_engine_desc_get_longname (_tmp60_);
										_tmp62_ = g_strdup_printf ("%s (%s)", _tmp59_, _tmp61_);
										_g_free0 (button_label);
										button_label = _tmp62_;
										_g_free0 (lang_name);
									}
									_tmp63_ = engine;
									_tmp64_ = ibus_engine_desc_get_language (_tmp63_);
									_tmp65_ = g_strdup (_tmp64_);
									_g_free0 (language);
									language = _tmp65_;
									_tmp66_ = engine;
									_tmp67_ = ibus_engine_desc_get_layout_variant (_tmp66_);
									_tmp68_ = g_strdup (_tmp67_);
									_g_free0 (layout_variant);
									layout_variant = _tmp68_;
								}
								_g_object_unref0 (engine);
							}
						}
					}
					break;
				}
			}
		} else {
			switch (0) {
				default:
				{
					const gchar* _tmp69_;
					_tmp69_ = manager_type;
					g_warning ("PopoverWidget.vala:236: unrecognised input manager %s", _tmp69_);
					_g_free0 (button_label);
					_g_free0 (layout_variant);
					_g_free0 (language);
					continue;
				}
			}
		}
		_tmp71_ = layout_variant;
		_tmp70_ = _tmp71_;
		if (_tmp70_ == NULL) {
			_tmp70_ = "";
		}
		_tmp72_ = g_strdup (_tmp70_);
		_g_free0 (layout_variant);
		layout_variant = _tmp72_;
		_tmp73_ = button_label;
		if (_tmp73_ == NULL) {
			gchar* variant = NULL;
			gchar* _tmp74_;
			const gchar* _tmp75_;
			const gchar* _tmp78_;
			const gchar* _tmp79_;
			gchar* _tmp80_;
			_tmp74_ = g_strdup ("");
			variant = _tmp74_;
			_tmp75_ = layout_variant;
			if (g_strcmp0 (_tmp75_, "") != 0) {
				const gchar* _tmp76_;
				gchar* _tmp77_;
				_tmp76_ = layout_variant;
				_tmp77_ = g_strdup_printf (" (%s)", _tmp76_);
				_g_free0 (variant);
				variant = _tmp77_;
			}
			_tmp78_ = language;
			_tmp79_ = variant;
			_tmp80_ = g_strconcat (_tmp78_, _tmp79_, NULL);
			_g_free0 (button_label);
			button_label = _tmp80_;
			_g_free0 (variant);
		}
		_tmp81_ = g_variant_new ("u", i, NULL);
		g_variant_ref_sink (_tmp81_);
		action_target = _tmp81_;
		_tmp83_ = layout_variant;
		_tmp82_ = _tmp83_;
		if (_tmp82_ == NULL) {
			_tmp82_ = "";
		}
		_tmp84_ = button_label;
		_tmp85_ = string_replace (_tmp84_, "_", "__");
		_tmp86_ = _tmp85_;
		_tmp87_ = action_target;
		_tmp88_ = language;
		_tmp89_ = g_strdup (_tmp88_);
		_tmp90_ = g_strdup (_tmp82_);
		_tmp91_ = manager_type;
		_tmp92_ = g_strdup (_tmp91_);
		_tmp93_ = source;
		_tmp94_ = g_strdup (_tmp93_);
		_tmp95_ = keyboard_widgets_layout_button_new (_tmp86_, "manager.change-layout", _tmp87_);
		keyboard_widgets_layout_button_set_index (_tmp95_, i);
		keyboard_widgets_layout_button_set_language_code (_tmp95_, _tmp89_);
		_g_free0 (_tmp89_);
		keyboard_widgets_layout_button_set_layout_variant (_tmp95_, _tmp90_);
		_g_free0 (_tmp90_);
		keyboard_widgets_layout_button_set_manager_type (_tmp95_, _tmp92_);
		_g_free0 (_tmp92_);
		keyboard_widgets_layout_button_set_source (_tmp95_, _tmp94_);
		_g_free0 (_tmp94_);
		g_object_ref_sink (_tmp95_);
		_g_object_unref0 (layout_button);
		layout_button = _tmp95_;
		_g_free0 (_tmp86_);
		_tmp96_ = manager_type;
		_tmp97_ = _tmp96_;
		_tmp99_ = (NULL == _tmp97_) ? 0 : g_quark_from_string (_tmp97_);
		if (_tmp99_ == ((0 != _tmp98_label0) ? _tmp98_label0 : (_tmp98_label0 = g_quark_from_static_string (KEYBOARD_WIDGETS_POPOVER_WIDGET_XKB_MANAGER_TYPE)))) {
			switch (0) {
				default:
				{
					GtkListBox* _tmp100_;
					KeyboardWidgetsLayoutButton* _tmp101_;
					_tmp100_ = self->priv->xkb_box;
					_tmp101_ = layout_button;
					gtk_list_box_append (_tmp100_, (GtkWidget*) _tmp101_);
					break;
				}
			}
		} else if (_tmp99_ == ((0 != _tmp98_label1) ? _tmp98_label1 : (_tmp98_label1 = g_quark_from_static_string (KEYBOARD_WIDGETS_POPOVER_WIDGET_IBUS_MANAGER_TYPE)))) {
			switch (0) {
				default:
				{
					GtkListBox* _tmp102_;
					KeyboardWidgetsLayoutButton* _tmp103_;
					_tmp102_ = self->priv->ibus_box;
					_tmp103_ = layout_button;
					gtk_list_box_append (_tmp102_, (GtkWidget*) _tmp103_);
					break;
				}
			}
		} else {
			switch (0) {
				default:
				{
					g_assert_not_reached ();
				}
			}
		}
		_tmp104_ = i;
		i = _tmp104_ + 1;
		_g_variant_unref0 (action_target);
		_g_free0 (button_label);
		_g_free0 (layout_variant);
		_g_free0 (language);
	}
	_tmp105_ = self->priv->ibus_box;
	_tmp106_ = gtk_list_box_get_row_at_index (_tmp105_, 0);
	if (_tmp106_ != NULL) {
		GtkRevealer* _tmp107_;
		GtkRevealer* _tmp108_;
		GraniteSwitchModelButton* _tmp109_;
		gboolean _tmp110_;
		gboolean _tmp111_;
		_tmp107_ = self->priv->ibus_header_revealer;
		gtk_revealer_set_reveal_child (_tmp107_, TRUE);
		_tmp108_ = self->priv->ibus_box_revealer;
		_tmp109_ = self->priv->ibus_header;
		_tmp110_ = gtk_toggle_button_get_active ((GtkToggleButton*) _tmp109_);
		_tmp111_ = _tmp110_;
		gtk_revealer_set_reveal_child (_tmp108_, _tmp111_);
	}
	keyboard_widgets_popover_widget_set_active_layout_from_settings (self);
	_g_free0 (source);
	_g_free0 (manager_type);
	_g_variant_iter_free0 (iter);
	_g_object_unref0 (layout_button);
	_g_variant_unref0 (source_list);
}

gchar*
keyboard_widgets_popover_widget_get_xml_rules_file_path (KeyboardWidgetsPopoverWidget* self)
{
	const gchar* base_path = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_getenv ("XKB_CONFIG_ROOT");
	base_path = _tmp0_;
	_tmp1_ = base_path;
	if (_tmp1_ == NULL) {
		base_path = CONSTANTS_XKB_BASE;
	}
	_tmp2_ = base_path;
	_tmp3_ = g_build_filename (_tmp2_, "rules", KEYBOARD_WIDGETS_POPOVER_WIDGET_XKB_RULES_FILE, NULL);
	result = _tmp3_;
	return result;
}

static GVariant*
_variant_new1 (guint32 value)
{
	return g_variant_ref_sink (g_variant_new_uint32 (value));
}

static void
keyboard_widgets_popover_widget_action_change_layout (KeyboardWidgetsPopoverWidget* self,
                                                      GSimpleAction* action,
                                                      GVariant* parameter)
{
	guint32 current_source_index = 0U;
	guint32 _tmp0_ = 0U;
	GSettings* _tmp1_;
	GVariant* _tmp2_;
	GVariant* _tmp3_;
	gboolean _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	g_variant_get (parameter, "u", &_tmp0_, NULL);
	current_source_index = _tmp0_;
	keyboard_widgets_popover_widget_set_active_layout (self, current_source_index);
	_tmp1_ = self->priv->settings;
	_tmp2_ = g_settings_get_value (_tmp1_, "current");
	_tmp3_ = _tmp2_;
	_tmp4_ = _tmp3_ != current_source_index;
	_g_variant_unref0 (_tmp3_);
	if (_tmp4_) {
		GSettings* _tmp5_;
		GVariant* _tmp6_;
		_tmp5_ = self->priv->settings;
		_tmp6_ = _variant_new1 (current_source_index);
		g_settings_set_value (_tmp5_, "current", _tmp6_);
		_g_variant_unref0 (_tmp6_);
	}
}

static void
keyboard_widgets_popover_widget_set_ibus_engine (KeyboardWidgetsPopoverWidget* self,
                                                 const gchar* manager,
                                                 const gchar* source)
{
	const gchar* _tmp0_;
	GQuark _tmp2_ = 0U;
	static GQuark _tmp1_label0 = 0;
	static GQuark _tmp1_label1 = 0;
	g_return_if_fail (self != NULL);
	g_return_if_fail (manager != NULL);
	g_return_if_fail (source != NULL);
	_tmp0_ = manager;
	_tmp2_ = (NULL == _tmp0_) ? 0 : g_quark_from_string (_tmp0_);
	if (_tmp2_ == ((0 != _tmp1_label0) ? _tmp1_label0 : (_tmp1_label0 = g_quark_from_static_string (KEYBOARD_WIDGETS_POPOVER_WIDGET_XKB_MANAGER_TYPE)))) {
		switch (0) {
			default:
			{
				IBusBus* _tmp3_;
				_tmp3_ = self->priv->bus;
				ibus_bus_set_global_engine (_tmp3_, "xkb:us::eng");
				break;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label1) ? _tmp1_label1 : (_tmp1_label1 = g_quark_from_static_string (KEYBOARD_WIDGETS_POPOVER_WIDGET_IBUS_MANAGER_TYPE)))) {
		switch (0) {
			default:
			{
				IBusBus* _tmp4_;
				_tmp4_ = self->priv->bus;
				ibus_bus_set_global_engine (_tmp4_, source);
				break;
			}
		}
	} else {
		switch (0) {
			default:
			{
				g_warning ("PopoverWidget.vala:323: unrecognised input manager %s", manager);
				break;
			}
		}
	}
}

static const gchar*
string_to_string (const gchar* self)
{
	const gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	result = self;
	return result;
}

gchar*
keyboard_widgets_popover_widget_get_name_for_xkb_layout (KeyboardWidgetsPopoverWidget* self,
                                                         const gchar* language,
                                                         const gchar* variant)
{
	xmlDoc* doc = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	xmlDoc* _tmp2_;
	xmlDoc* _tmp3_;
	xmlDoc* _tmp4_;
	xmlXPathContext* cntx = NULL;
	xmlDoc* _tmp5_;
	xmlXPathContext* _tmp6_;
	gchar* xpath = NULL;
	gchar* _tmp7_;
	xmlXPathObject* res = NULL;
	xmlXPathContext* _tmp13_;
	const gchar* _tmp14_;
	xmlXPathObject* _tmp15_;
	xmlXPathObject* _tmp16_;
	gboolean _tmp18_ = FALSE;
	xmlXPathObject* _tmp19_;
	gchar* name = NULL;
	xmlNode* node = NULL;
	xmlXPathObject* _tmp24_;
	xmlNodeSet* _tmp25_;
	xmlNode* _tmp26_;
	xmlNode* _tmp27_;
	xmlXPathObject* _tmp32_;
	xmlDoc* _tmp33_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (language != NULL, NULL);
	g_debug ("PopoverWidget.vala:329: get_name_for_xkb_layout (%s, %s)", language, variant);
	_tmp0_ = keyboard_widgets_popover_widget_get_xml_rules_file_path (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = xmlParseFile (_tmp1_);
	_tmp3_ = _tmp2_;
	_g_free0 (_tmp1_);
	doc = _tmp3_;
	_tmp4_ = doc;
	if (_tmp4_ == NULL) {
		g_critical ("PopoverWidget.vala:332: '%s' not found or permissions incorrect\n", KEYBOARD_WIDGETS_POPOVER_WIDGET_XKB_RULES_FILE);
		result = NULL;
		return result;
	}
	_tmp5_ = doc;
	_tmp6_ = xmlXPathNewContext (_tmp5_);
	cntx = _tmp6_;
	_tmp7_ = g_strdup ("");
	xpath = _tmp7_;
	if (variant == NULL) {
		const gchar* _tmp8_;
		gchar* _tmp9_;
		_tmp8_ = string_to_string (language);
		_tmp9_ = g_strconcat ("/xkbConfigRegistry/layoutList/layout/configItem/name[text()='", _tmp8_, "']/../description", NULL);
		_g_free0 (xpath);
		xpath = _tmp9_;
	} else {
		const gchar* _tmp10_;
		const gchar* _tmp11_;
		gchar* _tmp12_;
		_tmp10_ = string_to_string (language);
		_tmp11_ = string_to_string (variant);
		_tmp12_ = g_strconcat ("/xkbConfigRegistry/layoutList/layout/configItem/name[text()='", _tmp10_, "']/../../variantList/variant/configItem/name[text()='", _tmp11_, "']/../description", NULL);
		_g_free0 (xpath);
		xpath = _tmp12_;
	}
	_tmp13_ = cntx;
	_tmp14_ = xpath;
	_tmp15_ = xmlXPathEvalExpression ((xmlChar*) _tmp14_, _tmp13_);
	res = _tmp15_;
	_tmp16_ = res;
	if (_tmp16_ == NULL) {
		xmlDoc* _tmp17_;
		_tmp17_ = doc;
		_xmlFreeDoc0 (_tmp17_);
		g_critical ("PopoverWidget.vala:349: Unable to parse '%s'", KEYBOARD_WIDGETS_POPOVER_WIDGET_XKB_RULES_FILE);
		result = NULL;
		_g_free0 (xpath);
		_xmlXPathFreeContext0 (cntx);
		return result;
	}
	_tmp19_ = res;
	if (_tmp19_->type != XPATH_NODESET) {
		_tmp18_ = TRUE;
	} else {
		xmlXPathObject* _tmp20_;
		xmlNodeSet* _tmp21_;
		_tmp20_ = res;
		_tmp21_ = _tmp20_->nodesetval;
		_tmp18_ = _tmp21_ == NULL;
	}
	if (_tmp18_) {
		xmlXPathObject* _tmp22_;
		xmlDoc* _tmp23_;
		_tmp22_ = res;
		_xmlXPathFreeObject0 (_tmp22_);
		_tmp23_ = doc;
		_xmlFreeDoc0 (_tmp23_);
		g_warning ("PopoverWidget.vala:356: No name for %s: %s found in '%s'", language, variant, KEYBOARD_WIDGETS_POPOVER_WIDGET_XKB_RULES_FILE);
		result = NULL;
		_g_free0 (xpath);
		_xmlXPathFreeContext0 (cntx);
		return result;
	}
	name = NULL;
	_tmp24_ = res;
	_tmp25_ = _tmp24_->nodesetval;
	_tmp26_ = xmlXPathNodeSetItem (_tmp25_, 0);
	node = _tmp26_;
	_tmp27_ = node;
	if (_tmp27_ != NULL) {
		xmlNode* _tmp28_;
		gchar* _tmp29_;
		gchar* _tmp30_;
		gchar* _tmp31_;
		_tmp28_ = node;
		_tmp29_ = (gchar*) xmlNodeGetContent (_tmp28_);
		_tmp30_ = _tmp29_;
		_tmp31_ = g_strdup (g_dgettext ("xkeyboard-config", _tmp30_));
		_g_free0 (name);
		name = _tmp31_;
		_g_free0 (_tmp30_);
	}
	_tmp32_ = res;
	_xmlXPathFreeObject0 (_tmp32_);
	_tmp33_ = doc;
	_xmlFreeDoc0 (_tmp33_);
	result = name;
	_g_free0 (xpath);
	_xmlXPathFreeContext0 (cntx);
	return result;
}

gchar*
keyboard_widgets_popover_widget_get_current_with_variant (KeyboardWidgetsPopoverWidget* self)
{
	const gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_current_layout_variant;
	if (g_strcmp0 (_tmp0_, "") != 0) {
		const gchar* _tmp1_;
		gchar* _tmp2_;
		gchar* _tmp3_;
		const gchar* _tmp4_;
		gchar* _tmp5_;
		gchar* _tmp6_;
		_tmp1_ = self->priv->_current_language_code;
		_tmp2_ = g_strconcat (_tmp1_, "\t", NULL);
		_tmp3_ = _tmp2_;
		_tmp4_ = self->priv->_current_layout_variant;
		_tmp5_ = g_strconcat (_tmp3_, _tmp4_, NULL);
		_tmp6_ = _tmp5_;
		_g_free0 (_tmp3_);
		result = _tmp6_;
		return result;
	} else {
		const gchar* _tmp7_;
		gchar* _tmp8_;
		_tmp7_ = self->priv->_current_language_code;
		_tmp8_ = g_strdup (_tmp7_);
		result = _tmp8_;
		return result;
	}
}

gchar*
keyboard_widgets_popover_widget_get_current_description (KeyboardWidgetsPopoverWidget* self)
{
	gchar* xkb_label = NULL;
	gchar* _tmp0_;
	gchar* ibus_label = NULL;
	gchar* _tmp1_;
	const gchar* _tmp32_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (_ ("Default keyboard layout"));
	xkb_label = _tmp0_;
	_tmp1_ = g_strdup ("");
	ibus_label = _tmp1_;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp2_ = FALSE;
			_tmp2_ = TRUE;
			while (TRUE) {
				GtkListBox* _tmp4_;
				GtkListBoxRow* _tmp5_;
				KeyboardWidgetsLayoutButton* layout_button = NULL;
				GtkListBox* _tmp6_;
				GtkListBoxRow* _tmp7_;
				GtkWidget* _tmp8_;
				KeyboardWidgetsLayoutButton* _tmp9_;
				KeyboardWidgetsLayoutButton* _tmp10_;
				gboolean _tmp11_;
				gboolean _tmp12_;
				if (!_tmp2_) {
					gint _tmp3_;
					_tmp3_ = i;
					i = _tmp3_ + 1;
				}
				_tmp2_ = FALSE;
				_tmp4_ = self->priv->xkb_box;
				_tmp5_ = gtk_list_box_get_row_at_index (_tmp4_, i);
				if (!(_tmp5_ != NULL)) {
					break;
				}
				_tmp6_ = self->priv->xkb_box;
				_tmp7_ = gtk_list_box_get_row_at_index (_tmp6_, i);
				_tmp8_ = gtk_list_box_row_get_child (_tmp7_);
				_tmp9_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp8_, KEYBOARD_WIDGETS_TYPE_LAYOUT_BUTTON, KeyboardWidgetsLayoutButton));
				layout_button = _tmp9_;
				_tmp10_ = layout_button;
				_tmp11_ = keyboard_widgets_layout_button_get_active (_tmp10_);
				_tmp12_ = _tmp11_;
				if (_tmp12_) {
					KeyboardWidgetsLayoutButton* _tmp13_;
					const gchar* _tmp14_;
					const gchar* _tmp15_;
					gchar* _tmp16_;
					_tmp13_ = layout_button;
					_tmp14_ = keyboard_widgets_layout_button_get_label (_tmp13_);
					_tmp15_ = _tmp14_;
					_tmp16_ = g_strdup_printf (_ ("Keyboard Layout: %s"), _tmp15_);
					_g_free0 (xkb_label);
					xkb_label = _tmp16_;
				}
				_g_object_unref0 (layout_button);
			}
		}
	}
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp17_ = FALSE;
			_tmp17_ = TRUE;
			while (TRUE) {
				GtkListBox* _tmp19_;
				GtkListBoxRow* _tmp20_;
				KeyboardWidgetsLayoutButton* layout_button = NULL;
				GtkListBox* _tmp21_;
				GtkListBoxRow* _tmp22_;
				GtkWidget* _tmp23_;
				KeyboardWidgetsLayoutButton* _tmp24_;
				KeyboardWidgetsLayoutButton* _tmp25_;
				gboolean _tmp26_;
				gboolean _tmp27_;
				if (!_tmp17_) {
					gint _tmp18_;
					_tmp18_ = i;
					i = _tmp18_ + 1;
				}
				_tmp17_ = FALSE;
				_tmp19_ = self->priv->ibus_box;
				_tmp20_ = gtk_list_box_get_row_at_index (_tmp19_, i);
				if (!(_tmp20_ != NULL)) {
					break;
				}
				_tmp21_ = self->priv->ibus_box;
				_tmp22_ = gtk_list_box_get_row_at_index (_tmp21_, i);
				_tmp23_ = gtk_list_box_row_get_child (_tmp22_);
				_tmp24_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp23_, KEYBOARD_WIDGETS_TYPE_LAYOUT_BUTTON, KeyboardWidgetsLayoutButton));
				layout_button = _tmp24_;
				_tmp25_ = layout_button;
				_tmp26_ = keyboard_widgets_layout_button_get_active (_tmp25_);
				_tmp27_ = _tmp26_;
				if (_tmp27_) {
					KeyboardWidgetsLayoutButton* _tmp28_;
					const gchar* _tmp29_;
					const gchar* _tmp30_;
					gchar* _tmp31_;
					_tmp28_ = layout_button;
					_tmp29_ = keyboard_widgets_layout_button_get_label (_tmp28_);
					_tmp30_ = _tmp29_;
					_tmp31_ = g_strdup_printf (_ ("Input Method: %s"), _tmp30_);
					_g_free0 (ibus_label);
					ibus_label = _tmp31_;
				}
				_g_object_unref0 (layout_button);
			}
		}
	}
	_tmp32_ = ibus_label;
	if (g_strcmp0 (_tmp32_, "") != 0) {
		const gchar* _tmp33_;
		const gchar* _tmp34_;
		gchar* _tmp35_;
		_tmp33_ = ibus_label;
		_tmp34_ = xkb_label;
		_tmp35_ = g_strdup_printf ("%s\n%s", _tmp33_, _tmp34_);
		result = _tmp35_;
		_g_free0 (ibus_label);
		_g_free0 (xkb_label);
		return result;
	} else {
		result = xkb_label;
		_g_free0 (ibus_label);
		return result;
	}
}

static GVariant*
_variant_new2 (guint32 value)
{
	return g_variant_ref_sink (g_variant_new_uint32 (value));
}

void
keyboard_widgets_popover_widget_next (KeyboardWidgetsPopoverWidget* self)
{
	GVariant* current = NULL;
	GSettings* _tmp0_;
	GVariant* _tmp1_;
	guint32 next = 0U;
	GVariant* _tmp2_;
	GSettings* _tmp3_;
	GVariant* _tmp4_;
	GVariant* _tmp5_;
	gboolean _tmp6_;
	GSettings* _tmp7_;
	GVariant* _tmp8_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->settings;
	_tmp1_ = g_settings_get_value (_tmp0_, "current");
	current = _tmp1_;
	_tmp2_ = current;
	next = g_variant_get_uint32 (_tmp2_) + 1;
	_tmp3_ = self->priv->settings;
	_tmp4_ = g_settings_get_value (_tmp3_, "sources");
	_tmp5_ = _tmp4_;
	_tmp6_ = ((gsize) next) >= g_variant_n_children (_tmp5_);
	_g_variant_unref0 (_tmp5_);
	if (_tmp6_) {
		next = (guint32) 0;
	}
	_tmp7_ = self->priv->settings;
	_tmp8_ = _variant_new2 (next);
	g_settings_set_value (_tmp7_, "current", _tmp8_);
	_g_variant_unref0 (_tmp8_);
	_g_variant_unref0 (current);
}

static void
keyboard_widgets_popover_widget_set_active_layout_from_settings (KeyboardWidgetsPopoverWidget* self)
{
	GSettings* _tmp0_;
	GVariant* _tmp1_;
	GVariant* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->settings;
	_tmp1_ = g_settings_get_value (_tmp0_, "current");
	_tmp2_ = _tmp1_;
	keyboard_widgets_popover_widget_set_active_layout (self, g_variant_get_uint32 (_tmp2_));
	_g_variant_unref0 (_tmp2_);
}

static GVariant*
_variant_new3 (guint32 value)
{
	return g_variant_ref_sink (g_variant_new_uint32 (value));
}

static void
keyboard_widgets_popover_widget_set_active_layout_to_xkb (KeyboardWidgetsPopoverWidget* self)
{
	g_return_if_fail (self != NULL);
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				GtkListBox* _tmp2_;
				GtkListBoxRow* _tmp3_;
				KeyboardWidgetsLayoutButton* layout_button = NULL;
				GtkListBox* _tmp4_;
				GtkListBoxRow* _tmp5_;
				GtkWidget* _tmp6_;
				KeyboardWidgetsLayoutButton* _tmp7_;
				KeyboardWidgetsLayoutButton* _tmp8_;
				gboolean _tmp9_;
				gboolean _tmp10_;
				if (!_tmp0_) {
					gint _tmp1_;
					_tmp1_ = i;
					i = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				_tmp2_ = self->priv->xkb_box;
				_tmp3_ = gtk_list_box_get_row_at_index (_tmp2_, i);
				if (!(_tmp3_ != NULL)) {
					break;
				}
				_tmp4_ = self->priv->xkb_box;
				_tmp5_ = gtk_list_box_get_row_at_index (_tmp4_, i);
				_tmp6_ = gtk_list_box_row_get_child (_tmp5_);
				_tmp7_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp6_, KEYBOARD_WIDGETS_TYPE_LAYOUT_BUTTON, KeyboardWidgetsLayoutButton));
				layout_button = _tmp7_;
				_tmp8_ = layout_button;
				_tmp9_ = keyboard_widgets_layout_button_get_active (_tmp8_);
				_tmp10_ = _tmp9_;
				if (_tmp10_) {
					GSettings* _tmp11_;
					KeyboardWidgetsLayoutButton* _tmp12_;
					guint32 _tmp13_;
					guint32 _tmp14_;
					GVariant* _tmp15_;
					KeyboardWidgetsLayoutButton* _tmp16_;
					const gchar* _tmp17_;
					const gchar* _tmp18_;
					_tmp11_ = self->priv->settings;
					_tmp12_ = layout_button;
					_tmp13_ = keyboard_widgets_layout_button_get_index (_tmp12_);
					_tmp14_ = _tmp13_;
					_tmp15_ = _variant_new3 (_tmp14_);
					g_settings_set_value (_tmp11_, "current", _tmp15_);
					_g_variant_unref0 (_tmp15_);
					_tmp16_ = layout_button;
					_tmp17_ = keyboard_widgets_layout_button_get_source (_tmp16_);
					_tmp18_ = _tmp17_;
					keyboard_widgets_popover_widget_set_ibus_engine (self, KEYBOARD_WIDGETS_POPOVER_WIDGET_XKB_MANAGER_TYPE, _tmp18_);
				}
				_g_object_unref0 (layout_button);
			}
		}
	}
}

static void
keyboard_widgets_popover_widget_set_active_layout (KeyboardWidgetsPopoverWidget* self,
                                                   guint32 index)
{
	GtkListBox* _tmp0_;
	GtkListBox* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->xkb_box;
	keyboard_widgets_popover_widget_set_layout_active_in_box (self, _tmp0_, (guint) index, FALSE);
	_tmp1_ = self->priv->ibus_box;
	keyboard_widgets_popover_widget_set_layout_active_in_box (self, _tmp1_, (guint) index, TRUE);
	g_signal_emit (self, keyboard_widgets_popover_widget_signals[KEYBOARD_WIDGETS_POPOVER_WIDGET_UPDATED_SIGNAL], 0);
}

static void
keyboard_widgets_popover_widget_set_layout_active_in_box (KeyboardWidgetsPopoverWidget* self,
                                                          GtkListBox* layout_box,
                                                          guint index,
                                                          gboolean clear)
{
	gboolean found = FALSE;
	KeyboardWidgetsLayoutButton* previously_active_button = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (layout_box != NULL);
	found = FALSE;
	previously_active_button = NULL;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				GtkListBoxRow* _tmp2_;
				KeyboardWidgetsLayoutButton* layout_button = NULL;
				GtkListBoxRow* _tmp3_;
				GtkWidget* _tmp4_;
				KeyboardWidgetsLayoutButton* _tmp5_;
				KeyboardWidgetsLayoutButton* _tmp6_;
				guint32 _tmp7_;
				guint32 _tmp8_;
				if (!_tmp0_) {
					gint _tmp1_;
					_tmp1_ = i;
					i = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				_tmp2_ = gtk_list_box_get_row_at_index (layout_box, i);
				if (!(_tmp2_ != NULL)) {
					break;
				}
				_tmp3_ = gtk_list_box_get_row_at_index (layout_box, i);
				_tmp4_ = gtk_list_box_row_get_child (_tmp3_);
				_tmp5_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, KEYBOARD_WIDGETS_TYPE_LAYOUT_BUTTON, KeyboardWidgetsLayoutButton));
				layout_button = _tmp5_;
				_tmp6_ = layout_button;
				_tmp7_ = keyboard_widgets_layout_button_get_index (_tmp6_);
				_tmp8_ = _tmp7_;
				if (_tmp8_ == ((guint32) index)) {
					KeyboardWidgetsLayoutButton* _tmp9_;
					KeyboardWidgetsLayoutButton* _tmp10_;
					const gchar* _tmp11_;
					const gchar* _tmp12_;
					KeyboardWidgetsLayoutButton* _tmp13_;
					const gchar* _tmp14_;
					const gchar* _tmp15_;
					IBusBus* _tmp16_;
					found = TRUE;
					_tmp9_ = layout_button;
					keyboard_widgets_layout_button_set_active (_tmp9_, TRUE);
					_tmp10_ = layout_button;
					_tmp11_ = keyboard_widgets_layout_button_get_language_code (_tmp10_);
					_tmp12_ = _tmp11_;
					keyboard_widgets_popover_widget_set_current_language_code (self, _tmp12_);
					_tmp13_ = layout_button;
					_tmp14_ = keyboard_widgets_layout_button_get_layout_variant (_tmp13_);
					_tmp15_ = _tmp14_;
					keyboard_widgets_popover_widget_set_current_layout_variant (self, _tmp15_);
					_tmp16_ = self->priv->bus;
					if (ibus_bus_is_connected (_tmp16_)) {
						KeyboardWidgetsLayoutButton* _tmp17_;
						const gchar* _tmp18_;
						const gchar* _tmp19_;
						KeyboardWidgetsLayoutButton* _tmp20_;
						const gchar* _tmp21_;
						const gchar* _tmp22_;
						_tmp17_ = layout_button;
						_tmp18_ = keyboard_widgets_layout_button_get_manager_type (_tmp17_);
						_tmp19_ = _tmp18_;
						_tmp20_ = layout_button;
						_tmp21_ = keyboard_widgets_layout_button_get_source (_tmp20_);
						_tmp22_ = _tmp21_;
						keyboard_widgets_popover_widget_set_ibus_engine (self, _tmp19_, _tmp22_);
					}
				} else {
					KeyboardWidgetsLayoutButton* _tmp23_;
					gboolean _tmp24_;
					gboolean _tmp25_;
					_tmp23_ = layout_button;
					_tmp24_ = keyboard_widgets_layout_button_get_active (_tmp23_);
					_tmp25_ = _tmp24_;
					if (_tmp25_) {
						KeyboardWidgetsLayoutButton* _tmp26_;
						_tmp26_ = layout_button;
						layout_button = NULL;
						_g_object_unref0 (previously_active_button);
						previously_active_button = _tmp26_;
					}
				}
				_g_object_unref0 (layout_button);
			}
		}
	}
	if (found) {
		KeyboardWidgetsLayoutButton* _tmp27_;
		_tmp27_ = previously_active_button;
		if (_tmp27_ != NULL) {
			KeyboardWidgetsLayoutButton* _tmp28_;
			_tmp28_ = previously_active_button;
			keyboard_widgets_layout_button_set_active (_tmp28_, FALSE);
		}
	} else {
		if (clear) {
			{
				gint i = 0;
				i = 0;
				{
					gboolean _tmp29_ = FALSE;
					_tmp29_ = TRUE;
					while (TRUE) {
						GtkListBoxRow* _tmp31_;
						KeyboardWidgetsLayoutButton* layout_button = NULL;
						GtkListBoxRow* _tmp32_;
						GtkWidget* _tmp33_;
						KeyboardWidgetsLayoutButton* _tmp34_;
						KeyboardWidgetsLayoutButton* _tmp35_;
						if (!_tmp29_) {
							gint _tmp30_;
							_tmp30_ = i;
							i = _tmp30_ + 1;
						}
						_tmp29_ = FALSE;
						_tmp31_ = gtk_list_box_get_row_at_index (layout_box, i);
						if (!(_tmp31_ != NULL)) {
							break;
						}
						_tmp32_ = gtk_list_box_get_row_at_index (layout_box, i);
						_tmp33_ = gtk_list_box_row_get_child (_tmp32_);
						_tmp34_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp33_, KEYBOARD_WIDGETS_TYPE_LAYOUT_BUTTON, KeyboardWidgetsLayoutButton));
						layout_button = _tmp34_;
						_tmp35_ = layout_button;
						keyboard_widgets_layout_button_set_active (_tmp35_, FALSE);
						_g_object_unref0 (layout_button);
					}
				}
			}
		}
	}
	_g_object_unref0 (previously_active_button);
}

gboolean
keyboard_widgets_popover_widget_has_multiple_layouts (KeyboardWidgetsPopoverWidget* self)
{
	GSettings* _tmp0_;
	GVariant* _tmp1_;
	GVariant* _tmp2_;
	gboolean _tmp3_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->settings;
	_tmp1_ = g_settings_get_value (_tmp0_, "sources");
	_tmp2_ = _tmp1_;
	_tmp3_ = g_variant_n_children (_tmp2_) > ((gsize) 1);
	_g_variant_unref0 (_tmp2_);
	result = _tmp3_;
	return result;
}

const gchar*
keyboard_widgets_popover_widget_get_current_language_code (KeyboardWidgetsPopoverWidget* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_current_language_code;
	result = _tmp0_;
	return result;
}

void
keyboard_widgets_popover_widget_set_current_language_code (KeyboardWidgetsPopoverWidget* self,
                                                           const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = keyboard_widgets_popover_widget_get_current_language_code (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_current_language_code);
		self->priv->_current_language_code = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, keyboard_widgets_popover_widget_properties[KEYBOARD_WIDGETS_POPOVER_WIDGET_CURRENT_LANGUAGE_CODE_PROPERTY]);
	}
}

const gchar*
keyboard_widgets_popover_widget_get_current_layout_variant (KeyboardWidgetsPopoverWidget* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_current_layout_variant;
	result = _tmp0_;
	return result;
}

void
keyboard_widgets_popover_widget_set_current_layout_variant (KeyboardWidgetsPopoverWidget* self,
                                                            const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = keyboard_widgets_popover_widget_get_current_layout_variant (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_current_layout_variant);
		self->priv->_current_layout_variant = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, keyboard_widgets_popover_widget_properties[KEYBOARD_WIDGETS_POPOVER_WIDGET_CURRENT_LAYOUT_VARIANT_PROPERTY]);
	}
}

WingpanelIndicatorManagerServerType
keyboard_widgets_popover_widget_get_server_type (KeyboardWidgetsPopoverWidget* self)
{
	WingpanelIndicatorManagerServerType result;
	g_return_val_if_fail (self != NULL, 0);
	result = self->priv->_server_type;
	return result;
}

static void
keyboard_widgets_popover_widget_set_server_type (KeyboardWidgetsPopoverWidget* self,
                                                 WingpanelIndicatorManagerServerType value)
{
	WingpanelIndicatorManagerServerType old_value;
	g_return_if_fail (self != NULL);
	old_value = keyboard_widgets_popover_widget_get_server_type (self);
	if (old_value != value) {
		self->priv->_server_type = value;
		g_object_notify_by_pspec ((GObject *) self, keyboard_widgets_popover_widget_properties[KEYBOARD_WIDGETS_POPOVER_WIDGET_SERVER_TYPE_PROPERTY]);
	}
}

static void
_vala_GValue_array_free (GValue * array,
                         gssize array_length)
{
	if (array != NULL) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			g_value_unset (&array[i]);
		}
	}
	g_free (array);
}

static void
_keyboard_widgets_popover_widget_show_keyboard_map_gtk_button_clicked (GtkButton* _sender,
                                                                       gpointer self)
{
	keyboard_widgets_popover_widget_show_keyboard_map ((KeyboardWidgetsPopoverWidget*) self);
}

static void
_keyboard_widgets_popover_widget_show_settings_gtk_button_clicked (GtkButton* _sender,
                                                                   gpointer self)
{
	keyboard_widgets_popover_widget_show_settings ((KeyboardWidgetsPopoverWidget*) self);
}

static void
_keyboard_widgets_popover_widget___lambda4_ (KeyboardWidgetsPopoverWidget* self)
{
	keyboard_widgets_popover_widget_populate_layouts (self);
}

static void
__keyboard_widgets_popover_widget___lambda4__ibus_bus_connected (IBusBus* _sender,
                                                                 gpointer self)
{
	_keyboard_widgets_popover_widget___lambda4_ ((KeyboardWidgetsPopoverWidget*) self);
}

static void
_keyboard_widgets_popover_widget___lambda5_ (KeyboardWidgetsPopoverWidget* self)
{
	keyboard_widgets_popover_widget_populate_layouts (self);
}

static void
__keyboard_widgets_popover_widget___lambda5__ibus_bus_disconnected (IBusBus* _sender,
                                                                    gpointer self)
{
	_keyboard_widgets_popover_widget___lambda5_ ((KeyboardWidgetsPopoverWidget*) self);
}

static void
_keyboard_widgets_popover_widget___lambda6_ (KeyboardWidgetsPopoverWidget* self)
{
	keyboard_widgets_popover_widget_populate_layouts (self);
}

static void
__keyboard_widgets_popover_widget___lambda6__g_settings_changed (GSettings* _sender,
                                                                 const gchar* key,
                                                                 gpointer self)
{
	_keyboard_widgets_popover_widget___lambda6_ ((KeyboardWidgetsPopoverWidget*) self);
}

static void
_keyboard_widgets_popover_widget___lambda7_ (KeyboardWidgetsPopoverWidget* self)
{
	keyboard_widgets_popover_widget_set_active_layout_from_settings (self);
	g_signal_emit (self, keyboard_widgets_popover_widget_signals[KEYBOARD_WIDGETS_POPOVER_WIDGET_UPDATED_SIGNAL], 0);
}

static void
__keyboard_widgets_popover_widget___lambda7__g_settings_changed (GSettings* _sender,
                                                                 const gchar* key,
                                                                 gpointer self)
{
	_keyboard_widgets_popover_widget___lambda7_ ((KeyboardWidgetsPopoverWidget*) self);
}

static void
_keyboard_widgets_popover_widget___lambda8_ (KeyboardWidgetsPopoverWidget* self)
{
	GraniteSwitchModelButton* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	_tmp0_ = self->priv->ibus_header;
	_tmp1_ = gtk_toggle_button_get_active ((GtkToggleButton*) _tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_) {
		GtkRevealer* _tmp3_;
		_tmp3_ = self->priv->ibus_box_revealer;
		gtk_revealer_set_reveal_child (_tmp3_, TRUE);
	} else {
		GtkRevealer* _tmp4_;
		_tmp4_ = self->priv->ibus_box_revealer;
		gtk_revealer_set_reveal_child (_tmp4_, FALSE);
		keyboard_widgets_popover_widget_set_active_layout_to_xkb (self);
	}
}

static void
__keyboard_widgets_popover_widget___lambda8__gtk_toggle_button_toggled (GtkToggleButton* _sender,
                                                                        gpointer self)
{
	_keyboard_widgets_popover_widget___lambda8_ ((KeyboardWidgetsPopoverWidget*) self);
}

static void
_keyboard_widgets_popover_widget_action_change_layout_g_simple_action_activate (GSimpleAction* _sender,
                                                                                GVariant* parameter,
                                                                                gpointer self)
{
	keyboard_widgets_popover_widget_action_change_layout ((KeyboardWidgetsPopoverWidget*) self, _sender, parameter);
}

static GObject *
keyboard_widgets_popover_widget_constructor (GType type,
                                             guint n_construct_properties,
                                             GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	KeyboardWidgetsPopoverWidget * self;
	IBusBus* _tmp0_;
	GtkListBox* _tmp1_;
	GraniteHeaderLabel* xkb_header = NULL;
	GtkListBox* _tmp2_;
	GtkWidget* _tmp3_;
	GraniteHeaderLabel* _tmp4_ = NULL;
	GraniteSwitchModelButton* _tmp5_ = NULL;
	GraniteSwitchModelButton* _tmp6_;
	GtkSeparator* ibus_separator = NULL;
	GtkSeparator* _tmp7_ = NULL;
	GtkBox* ibus_header_box = NULL;
	GtkBox* _tmp8_;
	GtkBox* _tmp9_;
	GtkSeparator* _tmp10_;
	GtkBox* _tmp11_;
	GraniteSwitchModelButton* _tmp12_;
	GtkBox* _tmp13_;
	GtkWidget* _tmp14_;
	GtkRevealer* _tmp15_ = NULL;
	GtkListBox* _tmp16_;
	GtkListBox* _tmp17_;
	GtkAccessibleProperty* _tmp18_;
	GtkAccessibleProperty* _tmp19_;
	gint _tmp19__length1;
	GraniteSwitchModelButton* _tmp20_;
	const gchar* _tmp21_;
	const gchar* _tmp22_;
	GValue _tmp23_ = {0};
	GValue* _tmp24_;
	GValue* _tmp25_;
	gint _tmp25__length1;
	GtkListBox* _tmp26_;
	GtkWidget* _tmp27_;
	GtkRevealer* _tmp28_ = NULL;
	GtkSeparator* separator = NULL;
	GtkSeparator* _tmp29_ = NULL;
	WingpanelPopoverMenuItem* map_button = NULL;
	gchar* _tmp30_;
	WingpanelPopoverMenuItem* _tmp31_ = NULL;
	WingpanelPopoverMenuItem* _tmp32_;
	GraniteHeaderLabel* _tmp33_;
	GtkListBox* _tmp34_;
	GtkRevealer* _tmp35_;
	GtkRevealer* _tmp36_;
	GtkSeparator* _tmp37_;
	WingpanelPopoverMenuItem* _tmp38_;
	WingpanelIndicatorManagerServerType _tmp39_;
	IBusBus* _tmp44_;
	IBusBus* _tmp45_;
	GSettings* _tmp46_;
	GSettings* _tmp47_;
	GSettings* _tmp48_;
	GraniteSwitchModelButton* _tmp49_;
	GSimpleAction* action_change_current_layout = NULL;
	GVariantType* _tmp50_;
	GVariantType* _tmp51_;
	GVariant* _tmp52_;
	GVariant* _tmp53_;
	GSimpleAction* _tmp54_;
	GSimpleAction* _tmp55_;
	GSimpleAction* _tmp56_;
	GSimpleActionGroup* actions = NULL;
	GSimpleActionGroup* _tmp57_;
	GSimpleActionGroup* _tmp58_;
	GSimpleAction* _tmp59_;
	GSimpleActionGroup* _tmp60_;
	parent_class = G_OBJECT_CLASS (keyboard_widgets_popover_widget_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, KEYBOARD_WIDGETS_TYPE_POPOVER_WIDGET, KeyboardWidgetsPopoverWidget);
	gtk_orientable_set_orientation ((GtkOrientable*) self, GTK_ORIENTATION_VERTICAL);
	ibus_init ();
	_tmp0_ = ibus_bus_new ();
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->bus);
	self->priv->bus = _tmp0_;
	_tmp1_ = (GtkListBox*) gtk_list_box_new ();
	g_object_ref_sink (_tmp1_);
	_g_object_unref0 (self->priv->xkb_box);
	self->priv->xkb_box = _tmp1_;
	_tmp2_ = self->priv->xkb_box;
	_tmp3_ = _g_object_ref0 ((GtkWidget*) _tmp2_);
	_tmp4_ = granite_header_label_new (_ ("Keyboard Layout"));
	granite_header_label_set_mnemonic_widget (_tmp4_, _tmp3_);
	_g_object_unref0 (_tmp3_);
	g_object_ref_sink (_tmp4_);
	xkb_header = _tmp4_;
	_tmp5_ = granite_switch_model_button_new (_ ("Input Method"));
	gtk_toggle_button_set_active ((GtkToggleButton*) _tmp5_, TRUE);
	g_object_ref_sink (_tmp5_);
	_g_object_unref0 (self->priv->ibus_header);
	self->priv->ibus_header = _tmp5_;
	_tmp6_ = self->priv->ibus_header;
	gtk_widget_add_css_class ((GtkWidget*) _tmp6_, GRANITE_STYLE_CLASS_H4_LABEL);
	_tmp7_ = (GtkSeparator*) gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
	gtk_widget_set_margin_top ((GtkWidget*) _tmp7_, 3);
	gtk_widget_set_margin_bottom ((GtkWidget*) _tmp7_, 3);
	g_object_ref_sink (_tmp7_);
	ibus_separator = _tmp7_;
	_tmp8_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	g_object_ref_sink (_tmp8_);
	ibus_header_box = _tmp8_;
	_tmp9_ = ibus_header_box;
	_tmp10_ = ibus_separator;
	gtk_box_append (_tmp9_, (GtkWidget*) _tmp10_);
	_tmp11_ = ibus_header_box;
	_tmp12_ = self->priv->ibus_header;
	gtk_box_append (_tmp11_, (GtkWidget*) _tmp12_);
	_tmp13_ = ibus_header_box;
	_tmp14_ = _g_object_ref0 ((GtkWidget*) _tmp13_);
	_tmp15_ = (GtkRevealer*) gtk_revealer_new ();
	gtk_revealer_set_child (_tmp15_, _tmp14_);
	_g_object_unref0 (_tmp14_);
	g_object_ref_sink (_tmp15_);
	_g_object_unref0 (self->priv->ibus_header_revealer);
	self->priv->ibus_header_revealer = _tmp15_;
	_tmp16_ = (GtkListBox*) gtk_list_box_new ();
	g_object_ref_sink (_tmp16_);
	_g_object_unref0 (self->priv->ibus_box);
	self->priv->ibus_box = _tmp16_;
	_tmp17_ = self->priv->ibus_box;
	_tmp18_ = g_new0 (GtkAccessibleProperty, 1);
	_tmp18_[0] = GTK_ACCESSIBLE_PROPERTY_LABEL;
	_tmp19_ = _tmp18_;
	_tmp19__length1 = 1;
	_tmp20_ = self->priv->ibus_header;
	_tmp21_ = granite_switch_model_button_get_text (_tmp20_);
	_tmp22_ = _tmp21_;
	g_value_init (&_tmp23_, G_TYPE_STRING);
	g_value_set_string (&_tmp23_, _tmp22_);
	_tmp24_ = g_new0 (GValue, 1);
	_tmp24_[0] = _tmp23_;
	_tmp25_ = _tmp24_;
	_tmp25__length1 = 1;
	gtk_accessible_update_property_value ((GtkAccessible*) _tmp17_, (gint) 1, _tmp19_, _tmp25_);
	_tmp25_ = (_vala_GValue_array_free (_tmp25_, _tmp25__length1), NULL);
	_tmp19_ = (g_free (_tmp19_), NULL);
	_tmp26_ = self->priv->ibus_box;
	_tmp27_ = _g_object_ref0 ((GtkWidget*) _tmp26_);
	_tmp28_ = (GtkRevealer*) gtk_revealer_new ();
	gtk_revealer_set_child (_tmp28_, _tmp27_);
	_g_object_unref0 (_tmp27_);
	g_object_ref_sink (_tmp28_);
	_g_object_unref0 (self->priv->ibus_box_revealer);
	self->priv->ibus_box_revealer = _tmp28_;
	_tmp29_ = (GtkSeparator*) gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
	gtk_widget_set_margin_top ((GtkWidget*) _tmp29_, 3);
	gtk_widget_set_margin_bottom ((GtkWidget*) _tmp29_, 3);
	g_object_ref_sink (_tmp29_);
	separator = _tmp29_;
	_tmp30_ = g_strdup (_ ("Show Keyboard Layout"));
	_tmp31_ = wingpanel_popover_menu_item_new ();
	wingpanel_popover_menu_item_set_text (_tmp31_, _tmp30_);
	_g_free0 (_tmp30_);
	g_object_ref_sink (_tmp31_);
	map_button = _tmp31_;
	_tmp32_ = map_button;
	g_signal_connect_object ((GtkButton*) _tmp32_, "clicked", (GCallback) _keyboard_widgets_popover_widget_show_keyboard_map_gtk_button_clicked, self, 0);
	_tmp33_ = xkb_header;
	gtk_box_append ((GtkBox*) self, (GtkWidget*) _tmp33_);
	_tmp34_ = self->priv->xkb_box;
	gtk_box_append ((GtkBox*) self, (GtkWidget*) _tmp34_);
	_tmp35_ = self->priv->ibus_header_revealer;
	gtk_box_append ((GtkBox*) self, (GtkWidget*) _tmp35_);
	_tmp36_ = self->priv->ibus_box_revealer;
	gtk_box_append ((GtkBox*) self, (GtkWidget*) _tmp36_);
	_tmp37_ = separator;
	gtk_box_append ((GtkBox*) self, (GtkWidget*) _tmp37_);
	_tmp38_ = map_button;
	gtk_box_append ((GtkBox*) self, (GtkWidget*) _tmp38_);
	_tmp39_ = self->priv->_server_type;
	if (_tmp39_ != WINGPANEL_INDICATOR_MANAGER_SERVER_TYPE_GREETER) {
		WingpanelPopoverMenuItem* settings_button = NULL;
		gchar* _tmp40_;
		WingpanelPopoverMenuItem* _tmp41_ = NULL;
		WingpanelPopoverMenuItem* _tmp42_;
		WingpanelPopoverMenuItem* _tmp43_;
		_tmp40_ = g_strdup (_ ("Keyboard Settings…"));
		_tmp41_ = wingpanel_popover_menu_item_new ();
		wingpanel_popover_menu_item_set_text (_tmp41_, _tmp40_);
		_g_free0 (_tmp40_);
		g_object_ref_sink (_tmp41_);
		settings_button = _tmp41_;
		_tmp42_ = settings_button;
		g_signal_connect_object ((GtkButton*) _tmp42_, "clicked", (GCallback) _keyboard_widgets_popover_widget_show_settings_gtk_button_clicked, self, 0);
		_tmp43_ = settings_button;
		gtk_box_append ((GtkBox*) self, (GtkWidget*) _tmp43_);
		_g_object_unref0 (settings_button);
	}
	_tmp44_ = self->priv->bus;
	g_signal_connect_object (_tmp44_, "connected", (GCallback) __keyboard_widgets_popover_widget___lambda4__ibus_bus_connected, self, 0);
	_tmp45_ = self->priv->bus;
	g_signal_connect_object (_tmp45_, "disconnected", (GCallback) __keyboard_widgets_popover_widget___lambda5__ibus_bus_disconnected, self, 0);
	_tmp46_ = g_settings_new ("org.gnome.desktop.input-sources");
	_g_object_unref0 (self->priv->settings);
	self->priv->settings = _tmp46_;
	_tmp47_ = self->priv->settings;
	g_signal_connect_object (_tmp47_, "changed::sources", (GCallback) __keyboard_widgets_popover_widget___lambda6__g_settings_changed, self, 0);
	_tmp48_ = self->priv->settings;
	g_signal_connect_object (_tmp48_, "changed::current", (GCallback) __keyboard_widgets_popover_widget___lambda7__g_settings_changed, self, G_CONNECT_AFTER);
	_tmp49_ = self->priv->ibus_header;
	g_signal_connect_object ((GtkToggleButton*) _tmp49_, "toggled", (GCallback) __keyboard_widgets_popover_widget___lambda8__gtk_toggle_button_toggled, self, 0);
	_tmp50_ = g_variant_type_new ("u");
	_tmp51_ = _tmp50_;
	_tmp52_ = g_variant_new_boolean (TRUE);
	g_variant_ref_sink (_tmp52_);
	_tmp53_ = _tmp52_;
	_tmp54_ = g_simple_action_new_stateful ("change-layout", _tmp51_, _tmp53_);
	_tmp55_ = _tmp54_;
	_g_variant_unref0 (_tmp53_);
	_g_variant_type_free0 (_tmp51_);
	action_change_current_layout = _tmp55_;
	_tmp56_ = action_change_current_layout;
	g_signal_connect_object (_tmp56_, "activate", (GCallback) _keyboard_widgets_popover_widget_action_change_layout_g_simple_action_activate, self, 0);
	_tmp57_ = g_simple_action_group_new ();
	actions = _tmp57_;
	_tmp58_ = actions;
	_tmp59_ = action_change_current_layout;
	g_action_map_add_action ((GActionMap*) _tmp58_, (GAction*) _tmp59_);
	_tmp60_ = actions;
	gtk_widget_insert_action_group ((GtkWidget*) self, "manager", (GActionGroup*) _tmp60_);
	keyboard_widgets_popover_widget_populate_layouts (self);
	_g_object_unref0 (actions);
	_g_object_unref0 (action_change_current_layout);
	_g_object_unref0 (map_button);
	_g_object_unref0 (separator);
	_g_object_unref0 (ibus_header_box);
	_g_object_unref0 (ibus_separator);
	_g_object_unref0 (xkb_header);
	return obj;
}

static void
keyboard_widgets_popover_widget_class_init (KeyboardWidgetsPopoverWidgetClass * klass,
                                            gpointer klass_data)
{
	keyboard_widgets_popover_widget_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &KeyboardWidgetsPopoverWidget_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_keyboard_widgets_popover_widget_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_keyboard_widgets_popover_widget_set_property;
	G_OBJECT_CLASS (klass)->constructor = keyboard_widgets_popover_widget_constructor;
	G_OBJECT_CLASS (klass)->finalize = keyboard_widgets_popover_widget_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), KEYBOARD_WIDGETS_POPOVER_WIDGET_CURRENT_LANGUAGE_CODE_PROPERTY, keyboard_widgets_popover_widget_properties[KEYBOARD_WIDGETS_POPOVER_WIDGET_CURRENT_LANGUAGE_CODE_PROPERTY] = g_param_spec_string ("current-language-code", "current-language-code", "current-language-code", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), KEYBOARD_WIDGETS_POPOVER_WIDGET_CURRENT_LAYOUT_VARIANT_PROPERTY, keyboard_widgets_popover_widget_properties[KEYBOARD_WIDGETS_POPOVER_WIDGET_CURRENT_LAYOUT_VARIANT_PROPERTY] = g_param_spec_string ("current-layout-variant", "current-layout-variant", "current-layout-variant", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), KEYBOARD_WIDGETS_POPOVER_WIDGET_SERVER_TYPE_PROPERTY, keyboard_widgets_popover_widget_properties[KEYBOARD_WIDGETS_POPOVER_WIDGET_SERVER_TYPE_PROPERTY] = g_param_spec_enum ("server-type", "server-type", "server-type", WINGPANEL_INDICATOR_MANAGER_TYPE_SERVER_TYPE, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	keyboard_widgets_popover_widget_signals[KEYBOARD_WIDGETS_POPOVER_WIDGET_UPDATED_SIGNAL] = g_signal_new ("updated", KEYBOARD_WIDGETS_TYPE_POPOVER_WIDGET, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
keyboard_widgets_popover_widget_instance_init (KeyboardWidgetsPopoverWidget * self,
                                               gpointer klass)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	self->priv = keyboard_widgets_popover_widget_get_instance_private (self);
	_tmp0_ = g_strdup ("");
	self->priv->_current_language_code = _tmp0_;
	_tmp1_ = g_strdup ("");
	self->priv->_current_layout_variant = _tmp1_;
}

static void
keyboard_widgets_popover_widget_finalize (GObject * obj)
{
	KeyboardWidgetsPopoverWidget * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, KEYBOARD_WIDGETS_TYPE_POPOVER_WIDGET, KeyboardWidgetsPopoverWidget);
	_g_free0 (self->priv->_current_language_code);
	_g_free0 (self->priv->_current_layout_variant);
	_g_object_unref0 (self->priv->settings);
	(self->priv->engines == NULL) ? NULL : (self->priv->engines = (_g_list_free__g_object_unref0_ (self->priv->engines), NULL));
	_g_object_unref0 (self->priv->xkb_box);
	_g_object_unref0 (self->priv->ibus_box);
	_g_object_unref0 (self->priv->ibus_box_revealer);
	_g_object_unref0 (self->priv->ibus_header_revealer);
	_g_object_unref0 (self->priv->ibus_header);
	_g_object_unref0 (self->priv->bus);
	G_OBJECT_CLASS (keyboard_widgets_popover_widget_parent_class)->finalize (obj);
}

static GType
keyboard_widgets_popover_widget_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (KeyboardWidgetsPopoverWidgetClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) keyboard_widgets_popover_widget_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (KeyboardWidgetsPopoverWidget), 0, (GInstanceInitFunc) keyboard_widgets_popover_widget_instance_init, NULL };
	GType keyboard_widgets_popover_widget_type_id;
	keyboard_widgets_popover_widget_type_id = g_type_register_static (gtk_box_get_type (), "KeyboardWidgetsPopoverWidget", &g_define_type_info, 0);
	KeyboardWidgetsPopoverWidget_private_offset = g_type_add_instance_private (keyboard_widgets_popover_widget_type_id, sizeof (KeyboardWidgetsPopoverWidgetPrivate));
	return keyboard_widgets_popover_widget_type_id;
}

GType
keyboard_widgets_popover_widget_get_type (void)
{
	static volatile gsize keyboard_widgets_popover_widget_type_id__once = 0;
	if (g_once_init_enter (&keyboard_widgets_popover_widget_type_id__once)) {
		GType keyboard_widgets_popover_widget_type_id;
		keyboard_widgets_popover_widget_type_id = keyboard_widgets_popover_widget_get_type_once ();
		g_once_init_leave (&keyboard_widgets_popover_widget_type_id__once, keyboard_widgets_popover_widget_type_id);
	}
	return keyboard_widgets_popover_widget_type_id__once;
}

static void
_vala_keyboard_widgets_popover_widget_get_property (GObject * object,
                                                    guint property_id,
                                                    GValue * value,
                                                    GParamSpec * pspec)
{
	KeyboardWidgetsPopoverWidget * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, KEYBOARD_WIDGETS_TYPE_POPOVER_WIDGET, KeyboardWidgetsPopoverWidget);
	switch (property_id) {
		case KEYBOARD_WIDGETS_POPOVER_WIDGET_CURRENT_LANGUAGE_CODE_PROPERTY:
		g_value_set_string (value, keyboard_widgets_popover_widget_get_current_language_code (self));
		break;
		case KEYBOARD_WIDGETS_POPOVER_WIDGET_CURRENT_LAYOUT_VARIANT_PROPERTY:
		g_value_set_string (value, keyboard_widgets_popover_widget_get_current_layout_variant (self));
		break;
		case KEYBOARD_WIDGETS_POPOVER_WIDGET_SERVER_TYPE_PROPERTY:
		g_value_set_enum (value, keyboard_widgets_popover_widget_get_server_type (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_keyboard_widgets_popover_widget_set_property (GObject * object,
                                                    guint property_id,
                                                    const GValue * value,
                                                    GParamSpec * pspec)
{
	KeyboardWidgetsPopoverWidget * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, KEYBOARD_WIDGETS_TYPE_POPOVER_WIDGET, KeyboardWidgetsPopoverWidget);
	switch (property_id) {
		case KEYBOARD_WIDGETS_POPOVER_WIDGET_CURRENT_LANGUAGE_CODE_PROPERTY:
		keyboard_widgets_popover_widget_set_current_language_code (self, g_value_get_string (value));
		break;
		case KEYBOARD_WIDGETS_POPOVER_WIDGET_CURRENT_LAYOUT_VARIANT_PROPERTY:
		keyboard_widgets_popover_widget_set_current_layout_variant (self, g_value_get_string (value));
		break;
		case KEYBOARD_WIDGETS_POPOVER_WIDGET_SERVER_TYPE_PROPERTY:
		keyboard_widgets_popover_widget_set_server_type (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);
}

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

