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

/*
 * Copyright (c) 2024-2025 focus-timer contributors
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#include <glib-object.h>
#include "ft_core.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "ft_ui.h"
#include <gtk/gtk.h>
#include <gio/gio.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

typedef struct _FtVariableItem FtVariableItem;
typedef struct _FtVariableItemClass FtVariableItemClass;
typedef struct _FtVariableItemPrivate FtVariableItemPrivate;
enum  {
	FT_VARIABLE_ITEM_0_PROPERTY,
	FT_VARIABLE_ITEM_DISPLAY_NAME_PROPERTY,
	FT_VARIABLE_ITEM_NAME_PROPERTY,
	FT_VARIABLE_ITEM_DESCRIPTION_PROPERTY,
	FT_VARIABLE_ITEM_VALUE_TYPE_PROPERTY,
	FT_VARIABLE_ITEM_NUM_PROPERTIES
};
static GParamSpec* ft_variable_item_properties[FT_VARIABLE_ITEM_NUM_PROPERTIES];
#define _ft_variable_spec_unref0(var) ((var == NULL) ? NULL : (var = (ft_variable_spec_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _FtFormatItem FtFormatItem;
typedef struct _FtFormatItemClass FtFormatItemClass;
typedef struct _FtFormatItemPrivate FtFormatItemPrivate;
enum  {
	FT_FORMAT_ITEM_0_PROPERTY,
	FT_FORMAT_ITEM_DISPLAY_NAME_PROPERTY,
	FT_FORMAT_ITEM_NAME_PROPERTY,
	FT_FORMAT_ITEM_NUM_PROPERTIES
};
static GParamSpec* ft_format_item_properties[FT_FORMAT_ITEM_NUM_PROPERTIES];
enum  {
	FT_VARIABLE_POPOVER_0_PROPERTY,
	FT_VARIABLE_POPOVER_NUM_PROPERTIES
};
static GParamSpec* ft_variable_popover_properties[FT_VARIABLE_POPOVER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
typedef struct _Block27Data Block27Data;
enum  {
	FT_VARIABLE_POPOVER_SELECTED_SIGNAL,
	FT_VARIABLE_POPOVER_NUM_SIGNALS
};
static guint ft_variable_popover_signals[FT_VARIABLE_POPOVER_NUM_SIGNALS] = {0};
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _FtVariableItem {
	GObject parent_instance;
	FtVariableItemPrivate * priv;
};

struct _FtVariableItemClass {
	GObjectClass parent_class;
};

struct _FtVariableItemPrivate {
	FtVariableSpec* spec;
	gchar* _display_name;
};

struct _FtFormatItem {
	GObject parent_instance;
	FtFormatItemPrivate * priv;
};

struct _FtFormatItemClass {
	GObjectClass parent_class;
};

struct _FtFormatItemPrivate {
	gchar* _display_name;
	gchar* _name;
};

struct _FtVariablePopoverPrivate {
	GtkStack* stack;
	GtkListView* variables_listview;
	GtkListView* formats_listview;
	GtkLabel* variable_name_label;
	GtkLabel* variable_description_label;
	GtkSingleSelection* variables_model;
	GtkSingleSelection* formats_model;
};

struct _Block27Data {
	int _ref_count_;
	FtVariablePopover* self;
	GtkListItem* list_item;
	GtkCheckButton* check_button;
	gulong toggled_id;
};

static gint FtVariableItem_private_offset;
static gpointer ft_variable_item_parent_class = NULL;
static gint FtFormatItem_private_offset;
static gpointer ft_format_item_parent_class = NULL;
static gint FtVariablePopover_private_offset;
static gpointer ft_variable_popover_parent_class = NULL;
static GHashTable* ft_variable_popover_last_used_formats;
static GHashTable* ft_variable_popover_last_used_formats = NULL;

VALA_EXTERN FtVariableItem* ft_variable_item_new (FtVariableSpec* spec);
VALA_EXTERN FtVariableItem* ft_variable_item_construct (GType object_type,
                                            FtVariableSpec* spec);
VALA_EXTERN const gchar* ft_variable_item_get_display_name (FtVariableItem* self);
VALA_EXTERN const gchar* ft_variable_item_get_name (FtVariableItem* self);
VALA_EXTERN const gchar* ft_variable_item_get_description (FtVariableItem* self);
VALA_EXTERN GType ft_variable_item_get_value_type (FtVariableItem* self);
static void ft_variable_item_finalize (GObject * obj);
static GType ft_variable_item_get_type_once (void);
static void _vala_ft_variable_item_get_property (GObject * object,
                                          guint property_id,
                                          GValue * value,
                                          GParamSpec * pspec);
VALA_EXTERN FtFormatItem* ft_format_item_new (const gchar* variable_format);
VALA_EXTERN FtFormatItem* ft_format_item_construct (GType object_type,
                                        const gchar* variable_format);
VALA_EXTERN const gchar* ft_format_item_get_display_name (FtFormatItem* self);
VALA_EXTERN const gchar* ft_format_item_get_name (FtFormatItem* self);
static void ft_format_item_finalize (GObject * obj);
static GType ft_format_item_get_type_once (void);
static void _vala_ft_format_item_get_property (GObject * object,
                                        guint property_id,
                                        GValue * value,
                                        GParamSpec * pspec);
static void ft_variable_popover_selected (FtVariablePopover* self,
                                   const gchar* variable_name,
                                   const gchar* variable_format_name);
static gchar* ft_variable_popover_get_preferred_format (FtVariablePopover* self,
                                                 GType value_type);
static void _g_free0_ (gpointer var);
static guint ft_variable_popover_index_format (FtVariablePopover* self,
                                        const gchar* format_name);
static GListModel* ft_variable_popover_create_variables_model (FtVariablePopover* self);
static GListModel* ft_variable_popover_create_formats_model (FtVariablePopover* self,
                                                      GType value_type);
static gchar* ft_variable_popover_get_variable_display_name (GtkListItem* item);
static void ft_variable_popover_setup_format_item (FtVariablePopover* self,
                                            GObject* object);
static void _ft_variable_popover_setup_format_item_gtk_signal_list_item_factory_setup (GtkSignalListItemFactory* _sender,
                                                                                GObject* object,
                                                                                gpointer self);
static void ft_variable_popover_bind_format_item (FtVariablePopover* self,
                                           GObject* object);
static Block27Data* block27_data_ref (Block27Data* _data27_);
static void block27_data_unref (void * _userdata_);
static void __lambda77_ (Block27Data* _data27_);
static void ___lambda77__gtk_check_button_toggled (GtkCheckButton* _sender,
                                            gpointer self);
static void __lambda78_ (Block27Data* _data27_,
                  GObject* obj,
                  GParamSpec* pspec);
static void ___lambda78__g_object_notify (GObject* _sender,
                                   GParamSpec* pspec,
                                   gpointer self);
static void _ft_variable_popover_bind_format_item_gtk_signal_list_item_factory_bind (GtkSignalListItemFactory* _sender,
                                                                              GObject* object,
                                                                              gpointer self);
static void ft_variable_popover_unbind_format_item (FtVariablePopover* self,
                                             GObject* object);
static void _ft_variable_popover_unbind_format_item_gtk_signal_list_item_factory_unbind (GtkSignalListItemFactory* _sender,
                                                                                  GObject* object,
                                                                                  gpointer self);
static void ft_variable_popover_on_back_button_clicked (FtVariablePopover* self);
static void _ft_variable_popover_on_back_button_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                     gpointer self);
static void ft_variable_popover_on_insert_variable_button_clicked (FtVariablePopover* self);
static void _ft_variable_popover_on_insert_variable_button_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                                gpointer self);
static void ft_variable_popover_on_formats_model_selection_changed (FtVariablePopover* self);
static void ft_variable_popover_on_variables_model_selection_changed (FtVariablePopover* self,
                                                               guint position,
                                                               guint n_items);
static void _ft_variable_popover_on_formats_model_selection_changed_gtk_selection_model_selection_changed (GtkSelectionModel* _sender,
                                                                                                    guint position,
                                                                                                    guint n_items,
                                                                                                    gpointer self);
static void ft_variable_popover_real_closed (GtkPopover* base);
static void ft_variable_popover_real_dispose (GObject* base);
static void _ft_variable_popover_on_variables_model_selection_changed_gtk_selection_model_selection_changed (GtkSelectionModel* _sender,
                                                                                                      guint position,
                                                                                                      guint n_items,
                                                                                                      gpointer self);
static void g_cclosure_user_marshal_VOID__STRING_STRING (GClosure * closure,
                                                  GValue * return_value,
                                                  guint n_param_values,
                                                  const GValue * param_values,
                                                  gpointer invocation_hint,
                                                  gpointer marshal_data);
static GObject * ft_variable_popover_constructor (GType type,
                                           guint n_construct_properties,
                                           GObjectConstructParam * construct_properties);
static void ft_variable_popover_finalize (GObject * obj);
static GType ft_variable_popover_get_type_once (void);
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 inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
ft_variable_item_get_instance_private (FtVariableItem* self)
{
	return G_STRUCT_MEMBER_P (self, FtVariableItem_private_offset);
}

static gpointer
_ft_variable_spec_ref0 (gpointer self)
{
	return self ? ft_variable_spec_ref (self) : NULL;
}

FtVariableItem*
ft_variable_item_construct (GType object_type,
                            FtVariableSpec* spec)
{
	FtVariableItem * self = NULL;
	FtVariableSpec* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	g_return_val_if_fail (spec != NULL, NULL);
	self = (FtVariableItem*) g_object_new (object_type, NULL);
	_tmp0_ = _ft_variable_spec_ref0 (spec);
	_ft_variable_spec_unref0 (self->priv->spec);
	self->priv->spec = _tmp0_;
	_tmp1_ = spec->name;
	_tmp2_ = ft_to_camel_case (_tmp1_);
	_g_free0 (self->priv->_display_name);
	self->priv->_display_name = _tmp2_;
	return self;
}

FtVariableItem*
ft_variable_item_new (FtVariableSpec* spec)
{
	return ft_variable_item_construct (FT_TYPE_VARIABLE_ITEM, spec);
}

const gchar*
ft_variable_item_get_display_name (FtVariableItem* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_display_name;
	result = _tmp0_;
	return result;
}

const gchar*
ft_variable_item_get_name (FtVariableItem* self)
{
	const gchar* result;
	FtVariableSpec* _tmp0_;
	const gchar* _tmp1_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->spec;
	_tmp1_ = _tmp0_->name;
	result = _tmp1_;
	return result;
}

const gchar*
ft_variable_item_get_description (FtVariableItem* self)
{
	const gchar* result;
	FtVariableSpec* _tmp0_;
	const gchar* _tmp1_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->spec;
	_tmp1_ = _tmp0_->description;
	result = _tmp1_;
	return result;
}

GType
ft_variable_item_get_value_type (FtVariableItem* self)
{
	GType result;
	FtVariableSpec* _tmp0_;
	g_return_val_if_fail (self != NULL, G_TYPE_INVALID);
	_tmp0_ = self->priv->spec;
	result = _tmp0_->value_type;
	return result;
}

static void
ft_variable_item_class_init (FtVariableItemClass * klass,
                             gpointer klass_data)
{
	ft_variable_item_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FtVariableItem_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_ft_variable_item_get_property;
	G_OBJECT_CLASS (klass)->finalize = ft_variable_item_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_VARIABLE_ITEM_DISPLAY_NAME_PROPERTY, ft_variable_item_properties[FT_VARIABLE_ITEM_DISPLAY_NAME_PROPERTY] = g_param_spec_string ("display-name", "display-name", "display-name", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_VARIABLE_ITEM_NAME_PROPERTY, ft_variable_item_properties[FT_VARIABLE_ITEM_NAME_PROPERTY] = g_param_spec_string ("name", "name", "name", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_VARIABLE_ITEM_DESCRIPTION_PROPERTY, ft_variable_item_properties[FT_VARIABLE_ITEM_DESCRIPTION_PROPERTY] = g_param_spec_string ("description", "description", "description", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_VARIABLE_ITEM_VALUE_TYPE_PROPERTY, ft_variable_item_properties[FT_VARIABLE_ITEM_VALUE_TYPE_PROPERTY] = g_param_spec_gtype ("value-type", "value-type", "value-type", G_TYPE_NONE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
ft_variable_item_instance_init (FtVariableItem * self,
                                gpointer klass)
{
	self->priv = ft_variable_item_get_instance_private (self);
}

static void
ft_variable_item_finalize (GObject * obj)
{
	FtVariableItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_VARIABLE_ITEM, FtVariableItem);
	_ft_variable_spec_unref0 (self->priv->spec);
	_g_free0 (self->priv->_display_name);
	G_OBJECT_CLASS (ft_variable_item_parent_class)->finalize (obj);
}

static GType
ft_variable_item_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtVariableItemClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_variable_item_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtVariableItem), 0, (GInstanceInitFunc) ft_variable_item_instance_init, NULL };
	GType ft_variable_item_type_id;
	ft_variable_item_type_id = g_type_register_static (G_TYPE_OBJECT, "FtVariableItem", &g_define_type_info, 0);
	FtVariableItem_private_offset = g_type_add_instance_private (ft_variable_item_type_id, sizeof (FtVariableItemPrivate));
	return ft_variable_item_type_id;
}

GType
ft_variable_item_get_type (void)
{
	static volatile gsize ft_variable_item_type_id__once = 0;
	if (g_once_init_enter (&ft_variable_item_type_id__once)) {
		GType ft_variable_item_type_id;
		ft_variable_item_type_id = ft_variable_item_get_type_once ();
		g_once_init_leave (&ft_variable_item_type_id__once, ft_variable_item_type_id);
	}
	return ft_variable_item_type_id__once;
}

static void
_vala_ft_variable_item_get_property (GObject * object,
                                     guint property_id,
                                     GValue * value,
                                     GParamSpec * pspec)
{
	FtVariableItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_VARIABLE_ITEM, FtVariableItem);
	switch (property_id) {
		case FT_VARIABLE_ITEM_DISPLAY_NAME_PROPERTY:
		g_value_set_string (value, ft_variable_item_get_display_name (self));
		break;
		case FT_VARIABLE_ITEM_NAME_PROPERTY:
		g_value_set_string (value, ft_variable_item_get_name (self));
		break;
		case FT_VARIABLE_ITEM_DESCRIPTION_PROPERTY:
		g_value_set_string (value, ft_variable_item_get_description (self));
		break;
		case FT_VARIABLE_ITEM_VALUE_TYPE_PROPERTY:
		g_value_set_gtype (value, ft_variable_item_get_value_type (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
ft_format_item_get_instance_private (FtFormatItem* self)
{
	return G_STRUCT_MEMBER_P (self, FtFormatItem_private_offset);
}

FtFormatItem*
ft_format_item_construct (GType object_type,
                          const gchar* variable_format)
{
	FtFormatItem * self = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	g_return_val_if_fail (variable_format != NULL, NULL);
	self = (FtFormatItem*) g_object_new (object_type, NULL);
	_tmp0_ = g_strdup (variable_format);
	_g_free0 (self->priv->_name);
	self->priv->_name = _tmp0_;
	_tmp1_ = ft_to_camel_case (variable_format);
	_g_free0 (self->priv->_display_name);
	self->priv->_display_name = _tmp1_;
	return self;
}

FtFormatItem*
ft_format_item_new (const gchar* variable_format)
{
	return ft_format_item_construct (FT_TYPE_FORMAT_ITEM, variable_format);
}

const gchar*
ft_format_item_get_display_name (FtFormatItem* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_display_name;
	result = _tmp0_;
	return result;
}

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

static void
ft_format_item_class_init (FtFormatItemClass * klass,
                           gpointer klass_data)
{
	ft_format_item_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FtFormatItem_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_ft_format_item_get_property;
	G_OBJECT_CLASS (klass)->finalize = ft_format_item_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_FORMAT_ITEM_DISPLAY_NAME_PROPERTY, ft_format_item_properties[FT_FORMAT_ITEM_DISPLAY_NAME_PROPERTY] = g_param_spec_string ("display-name", "display-name", "display-name", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_FORMAT_ITEM_NAME_PROPERTY, ft_format_item_properties[FT_FORMAT_ITEM_NAME_PROPERTY] = g_param_spec_string ("name", "name", "name", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
ft_format_item_instance_init (FtFormatItem * self,
                              gpointer klass)
{
	self->priv = ft_format_item_get_instance_private (self);
}

static void
ft_format_item_finalize (GObject * obj)
{
	FtFormatItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_FORMAT_ITEM, FtFormatItem);
	_g_free0 (self->priv->_display_name);
	_g_free0 (self->priv->_name);
	G_OBJECT_CLASS (ft_format_item_parent_class)->finalize (obj);
}

static GType
ft_format_item_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtFormatItemClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_format_item_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtFormatItem), 0, (GInstanceInitFunc) ft_format_item_instance_init, NULL };
	GType ft_format_item_type_id;
	ft_format_item_type_id = g_type_register_static (G_TYPE_OBJECT, "FtFormatItem", &g_define_type_info, 0);
	FtFormatItem_private_offset = g_type_add_instance_private (ft_format_item_type_id, sizeof (FtFormatItemPrivate));
	return ft_format_item_type_id;
}

GType
ft_format_item_get_type (void)
{
	static volatile gsize ft_format_item_type_id__once = 0;
	if (g_once_init_enter (&ft_format_item_type_id__once)) {
		GType ft_format_item_type_id;
		ft_format_item_type_id = ft_format_item_get_type_once ();
		g_once_init_leave (&ft_format_item_type_id__once, ft_format_item_type_id);
	}
	return ft_format_item_type_id__once;
}

static void
_vala_ft_format_item_get_property (GObject * object,
                                   guint property_id,
                                   GValue * value,
                                   GParamSpec * pspec)
{
	FtFormatItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_FORMAT_ITEM, FtFormatItem);
	switch (property_id) {
		case FT_FORMAT_ITEM_DISPLAY_NAME_PROPERTY:
		g_value_set_string (value, ft_format_item_get_display_name (self));
		break;
		case FT_FORMAT_ITEM_NAME_PROPERTY:
		g_value_set_string (value, ft_format_item_get_name (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
ft_variable_popover_get_instance_private (FtVariablePopover* self)
{
	return G_STRUCT_MEMBER_P (self, FtVariablePopover_private_offset);
}

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

static gchar*
ft_variable_popover_get_preferred_format (FtVariablePopover* self,
                                          GType value_type)
{
	gchar* format = NULL;
	GHashTable* _tmp0_;
	const gchar* _tmp7_;
	const gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	format = NULL;
	_tmp0_ = ft_variable_popover_last_used_formats;
	if (_tmp0_ == NULL) {
		GHashFunc _tmp1_;
		GEqualFunc _tmp2_;
		GHashTable* _tmp3_;
		_tmp1_ = g_direct_hash;
		_tmp2_ = g_direct_equal;
		_tmp3_ = g_hash_table_new_full (_tmp1_, _tmp2_, NULL, _g_free0_);
		_g_hash_table_unref0 (ft_variable_popover_last_used_formats);
		ft_variable_popover_last_used_formats = _tmp3_;
	} else {
		GHashTable* _tmp4_;
		gconstpointer _tmp5_;
		gchar* _tmp6_;
		_tmp4_ = ft_variable_popover_last_used_formats;
		_tmp5_ = g_hash_table_lookup (_tmp4_, (gpointer) ((gintptr) value_type));
		_tmp6_ = g_strdup ((const gchar*) _tmp5_);
		_g_free0 (format);
		format = _tmp6_;
	}
	_tmp7_ = format;
	if (_tmp7_ == NULL) {
		gchar* _tmp8_;
		_tmp8_ = ft_get_default_value_format (value_type);
		_g_free0 (format);
		format = _tmp8_;
	}
	_tmp9_ = format;
	_tmp10_ = ft_ensure_string (_tmp9_);
	result = _tmp10_;
	_g_free0 (format);
	return result;
}

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

static guint
ft_variable_popover_index_format (FtVariablePopover* self,
                                  const gchar* format_name)
{
	GListModel* model = NULL;
	GtkSingleSelection* _tmp0_;
	GListModel* _tmp1_;
	GListModel* _tmp2_;
	GListModel* _tmp3_;
	guint n_items = 0U;
	GListModel* _tmp4_;
	guint result;
	g_return_val_if_fail (self != NULL, 0U);
	g_return_val_if_fail (format_name != NULL, 0U);
	_tmp0_ = self->priv->formats_model;
	_tmp1_ = gtk_single_selection_get_model (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	model = _tmp3_;
	_tmp4_ = model;
	n_items = g_list_model_get_n_items (_tmp4_);
	{
		guint position = 0U;
		position = 0U;
		{
			gboolean _tmp5_ = FALSE;
			_tmp5_ = TRUE;
			while (TRUE) {
				FtFormatItem* item = NULL;
				GListModel* _tmp7_;
				GObject* _tmp8_;
				FtFormatItem* _tmp9_;
				const gchar* _tmp10_;
				const gchar* _tmp11_;
				if (!_tmp5_) {
					guint _tmp6_;
					_tmp6_ = position;
					position = _tmp6_ + 1;
				}
				_tmp5_ = FALSE;
				if (!(position < n_items)) {
					break;
				}
				_tmp7_ = model;
				_tmp8_ = g_list_model_get_item (_tmp7_, position);
				item = G_TYPE_CHECK_INSTANCE_CAST (_tmp8_, FT_TYPE_FORMAT_ITEM, FtFormatItem);
				_tmp9_ = item;
				_tmp10_ = ft_format_item_get_name (_tmp9_);
				_tmp11_ = _tmp10_;
				if (g_strcmp0 (_tmp11_, format_name) == 0) {
					result = position;
					_g_object_unref0 (item);
					_g_object_unref0 (model);
					return result;
				}
				_g_object_unref0 (item);
			}
		}
	}
	result = 0U;
	_g_object_unref0 (model);
	return result;
}

static GListModel*
ft_variable_popover_create_variables_model (FtVariablePopover* self)
{
	GListStore* model = NULL;
	GListStore* _tmp0_;
	gint _tmp1_ = 0;
	FtVariableSpec** _tmp2_;
	GListModel* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_list_store_new (FT_TYPE_VARIABLE_ITEM);
	model = _tmp0_;
	_tmp2_ = ft_list_variables (&_tmp1_);
	{
		FtVariableSpec** variable_collection = NULL;
		gint variable_collection_length1 = 0;
		gint _variable_collection_size_ = 0;
		gint variable_it = 0;
		variable_collection = _tmp2_;
		variable_collection_length1 = _tmp1_;
		for (variable_it = 0; variable_it < variable_collection_length1; variable_it = variable_it + 1) {
			FtVariableSpec* variable = NULL;
			variable = variable_collection[variable_it];
			{
				GListStore* _tmp3_;
				FtVariableSpec* _tmp4_;
				FtVariableItem* _tmp5_;
				FtVariableItem* _tmp6_;
				_tmp3_ = model;
				_tmp4_ = variable;
				_tmp5_ = ft_variable_item_new (_tmp4_);
				_tmp6_ = _tmp5_;
				g_list_store_append (_tmp3_, (GObject*) _tmp6_);
				_g_object_unref0 (_tmp6_);
			}
		}
		variable_collection = (g_free (variable_collection), NULL);
	}
	result = (GListModel*) model;
	return result;
}

static GListModel*
ft_variable_popover_create_formats_model (FtVariablePopover* self,
                                          GType value_type)
{
	GListStore* model = NULL;
	GListStore* _tmp0_;
	gint _tmp1_ = 0;
	gchar** _tmp2_;
	GListModel* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_list_store_new (FT_TYPE_FORMAT_ITEM);
	model = _tmp0_;
	_tmp2_ = ft_list_value_formats (value_type, &_tmp1_);
	{
		gchar** variable_format_collection = NULL;
		gint variable_format_collection_length1 = 0;
		gint _variable_format_collection_size_ = 0;
		gint variable_format_it = 0;
		variable_format_collection = _tmp2_;
		variable_format_collection_length1 = _tmp1_;
		for (variable_format_it = 0; variable_format_it < variable_format_collection_length1; variable_format_it = variable_format_it + 1) {
			const gchar* variable_format = NULL;
			variable_format = variable_format_collection[variable_format_it];
			{
				GListStore* _tmp3_;
				const gchar* _tmp4_;
				FtFormatItem* _tmp5_;
				FtFormatItem* _tmp6_;
				_tmp3_ = model;
				_tmp4_ = variable_format;
				_tmp5_ = ft_format_item_new (_tmp4_);
				_tmp6_ = _tmp5_;
				g_list_store_append (_tmp3_, (GObject*) _tmp6_);
				_g_object_unref0 (_tmp6_);
			}
		}
		variable_format_collection = (_vala_array_free (variable_format_collection, variable_format_collection_length1, (GDestroyNotify) g_free), NULL);
	}
	result = (GListModel*) model;
	return result;
}

void
ft_variable_popover_reset (FtVariablePopover* self)
{
	GtkSingleSelection* _tmp0_;
	GtkSingleSelection* _tmp1_;
	guint _tmp2_;
	guint _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->variables_model;
	_tmp1_ = self->priv->variables_model;
	_tmp2_ = gtk_single_selection_get_selected (_tmp1_);
	_tmp3_ = _tmp2_;
	gtk_selection_model_unselect_item ((GtkSelectionModel*) _tmp0_, _tmp3_);
}

static gchar*
ft_variable_popover_get_variable_display_name (GtkListItem* item)
{
	FtVariableItem* variable_item = NULL;
	GObject* _tmp0_;
	GObject* _tmp1_;
	FtVariableItem* _tmp2_ = NULL;
	FtVariableItem* _tmp3_;
	const gchar* _tmp4_ = NULL;
	gchar* _tmp7_;
	gchar* result;
	_tmp0_ = gtk_list_item_get_item (item);
	_tmp1_ = _tmp0_;
	variable_item = G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, FT_TYPE_VARIABLE_ITEM, FtVariableItem);
	_tmp3_ = variable_item;
	_tmp2_ = _tmp3_;
	_tmp4_ = NULL;
	if (_tmp2_ != NULL) {
		const gchar* _tmp5_;
		const gchar* _tmp6_;
		_tmp5_ = ft_variable_item_get_display_name (_tmp2_);
		_tmp6_ = _tmp5_;
		_tmp4_ = _tmp6_;
	}
	_tmp7_ = g_strdup (_tmp4_);
	result = _tmp7_;
	return result;
}

static void
ft_variable_popover_setup_format_item (FtVariablePopover* self,
                                       GObject* object)
{
	GtkCheckButton* check_button = NULL;
	GtkCheckButton* _tmp0_;
	GtkListItem* list_item = NULL;
	GtkListItem* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (object != NULL);
	_tmp0_ = (GtkCheckButton*) gtk_check_button_new ();
	g_object_ref_sink (_tmp0_);
	check_button = _tmp0_;
	gtk_widget_add_css_class ((GtkWidget*) check_button, "monospace");
	_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (object, gtk_list_item_get_type (), GtkListItem));
	list_item = _tmp1_;
	gtk_list_item_set_child (list_item, (GtkWidget*) check_button);
	_g_object_unref0 (list_item);
	_g_object_unref0 (check_button);
}

static void
_ft_variable_popover_setup_format_item_gtk_signal_list_item_factory_setup (GtkSignalListItemFactory* _sender,
                                                                           GObject* object,
                                                                           gpointer self)
{
	ft_variable_popover_setup_format_item ((FtVariablePopover*) self, object);
}

static Block27Data*
block27_data_ref (Block27Data* _data27_)
{
	g_atomic_int_inc (&_data27_->_ref_count_);
	return _data27_;
}

static void
block27_data_unref (void * _userdata_)
{
	Block27Data* _data27_;
	_data27_ = (Block27Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data27_->_ref_count_)) {
		FtVariablePopover* self;
		self = _data27_->self;
		_g_object_unref0 (_data27_->check_button);
		_g_object_unref0 (_data27_->list_item);
		_g_object_unref0 (self);
		g_slice_free (Block27Data, _data27_);
	}
}

static void
__lambda77_ (Block27Data* _data27_)
{
	FtVariablePopover* self;
	gboolean _tmp0_;
	gboolean _tmp1_;
	self = _data27_->self;
	_tmp0_ = gtk_check_button_get_active (_data27_->check_button);
	_tmp1_ = _tmp0_;
	if (_tmp1_) {
		GtkSingleSelection* _tmp2_;
		guint _tmp3_;
		guint _tmp4_;
		_tmp2_ = self->priv->formats_model;
		_tmp3_ = gtk_list_item_get_position (_data27_->list_item);
		_tmp4_ = _tmp3_;
		gtk_selection_model_select_item ((GtkSelectionModel*) _tmp2_, _tmp4_, TRUE);
	} else {
		gtk_check_button_set_active (_data27_->check_button, TRUE);
	}
}

static void
___lambda77__gtk_check_button_toggled (GtkCheckButton* _sender,
                                       gpointer self)
{
	__lambda77_ (self);
}

static void
__lambda78_ (Block27Data* _data27_,
             GObject* obj,
             GParamSpec* pspec)
{
	FtVariablePopover* self;
	gboolean _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	self = _data27_->self;
	g_return_if_fail (obj != NULL);
	g_return_if_fail (pspec != NULL);
	_tmp0_ = gtk_check_button_get_active (_data27_->check_button);
	_tmp1_ = _tmp0_;
	_tmp2_ = gtk_list_item_get_selected (_data27_->list_item);
	_tmp3_ = _tmp2_;
	if (_tmp1_ != _tmp3_) {
		gboolean _tmp4_;
		gboolean _tmp5_;
		g_signal_handler_block (_data27_->check_button, _data27_->toggled_id);
		_tmp4_ = gtk_list_item_get_selected (_data27_->list_item);
		_tmp5_ = _tmp4_;
		gtk_check_button_set_active (_data27_->check_button, _tmp5_);
		g_signal_handler_unblock (_data27_->check_button, _data27_->toggled_id);
	}
}

static void
___lambda78__g_object_notify (GObject* _sender,
                              GParamSpec* pspec,
                              gpointer self)
{
	__lambda78_ (self, _sender, pspec);
}

static void
ft_variable_popover_bind_format_item (FtVariablePopover* self,
                                      GObject* object)
{
	Block27Data* _data27_;
	GtkListItem* _tmp0_;
	GtkWidget* _tmp1_;
	GtkWidget* _tmp2_;
	GtkCheckButton* _tmp3_;
	gboolean _tmp4_;
	gboolean _tmp5_;
	FtFormatItem* format_item = NULL;
	GObject* _tmp6_;
	GObject* _tmp7_;
	FtFormatItem* _tmp8_;
	gulong _tmp9_;
	gulong notify_selected_id = 0UL;
	gulong _tmp10_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (object != NULL);
	_data27_ = g_slice_new0 (Block27Data);
	_data27_->_ref_count_ = 1;
	_data27_->self = g_object_ref (self);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (object, gtk_list_item_get_type (), GtkListItem));
	_data27_->list_item = _tmp0_;
	_tmp1_ = gtk_list_item_get_child (_data27_->list_item);
	_tmp2_ = _tmp1_;
	_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, gtk_check_button_get_type (), GtkCheckButton));
	_data27_->check_button = _tmp3_;
	_tmp4_ = gtk_list_item_get_selected (_data27_->list_item);
	_tmp5_ = _tmp4_;
	gtk_check_button_set_active (_data27_->check_button, _tmp5_);
	_tmp6_ = gtk_list_item_get_item (_data27_->list_item);
	_tmp7_ = _tmp6_;
	_tmp8_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, FT_TYPE_FORMAT_ITEM, FtFormatItem));
	format_item = _tmp8_;
	g_object_bind_property_with_closures ((GObject*) format_item, "display-name", (GObject*) _data27_->check_button, "label", G_BINDING_SYNC_CREATE, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	_tmp9_ = g_signal_connect_data (_data27_->check_button, "toggled", (GCallback) ___lambda77__gtk_check_button_toggled, block27_data_ref (_data27_), (GClosureNotify) block27_data_unref, 0);
	_data27_->toggled_id = _tmp9_;
	_tmp10_ = g_signal_connect_data ((GObject*) _data27_->list_item, "notify::selected", (GCallback) ___lambda78__g_object_notify, block27_data_ref (_data27_), (GClosureNotify) block27_data_unref, 0);
	notify_selected_id = _tmp10_;
	g_object_set_data_full ((GObject*) _data27_->list_item, "toggled-id", (gpointer) ((guintptr) _data27_->toggled_id), NULL);
	g_object_set_data_full ((GObject*) _data27_->list_item, "notify-selected-id", (gpointer) ((guintptr) notify_selected_id), NULL);
	_g_object_unref0 (format_item);
	block27_data_unref (_data27_);
	_data27_ = NULL;
}

static void
_ft_variable_popover_bind_format_item_gtk_signal_list_item_factory_bind (GtkSignalListItemFactory* _sender,
                                                                         GObject* object,
                                                                         gpointer self)
{
	ft_variable_popover_bind_format_item ((FtVariablePopover*) self, object);
}

static void
ft_variable_popover_unbind_format_item (FtVariablePopover* self,
                                        GObject* object)
{
	GtkListItem* list_item = NULL;
	GtkListItem* _tmp0_;
	gulong toggled_id = 0UL;
	gconstpointer _tmp1_;
	gulong notify_selected_id = 0UL;
	gconstpointer _tmp2_;
	GtkWidget* _tmp3_;
	GtkWidget* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (object != NULL);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (object, gtk_list_item_get_type (), GtkListItem));
	list_item = _tmp0_;
	_tmp1_ = g_object_get_data ((GObject*) list_item, "toggled-id");
	toggled_id = (gulong) ((guintptr) _tmp1_);
	_tmp2_ = g_object_get_data ((GObject*) list_item, "notify-selected-id");
	notify_selected_id = (gulong) ((guintptr) _tmp2_);
	_tmp3_ = gtk_list_item_get_child (list_item);
	_tmp4_ = _tmp3_;
	g_signal_handler_disconnect ((GObject*) _tmp4_, toggled_id);
	g_signal_handler_disconnect ((GObject*) list_item, notify_selected_id);
	_g_object_unref0 (list_item);
}

static void
_ft_variable_popover_unbind_format_item_gtk_signal_list_item_factory_unbind (GtkSignalListItemFactory* _sender,
                                                                             GObject* object,
                                                                             gpointer self)
{
	ft_variable_popover_unbind_format_item ((FtVariablePopover*) self, object);
}

static void
ft_variable_popover_on_back_button_clicked (FtVariablePopover* self)
{
	g_return_if_fail (self != NULL);
	ft_variable_popover_reset (self);
}

static void
_ft_variable_popover_on_back_button_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                gpointer self)
{
	ft_variable_popover_on_back_button_clicked ((FtVariablePopover*) self);
}

static void
ft_variable_popover_on_insert_variable_button_clicked (FtVariablePopover* self)
{
	FtVariableItem* variable_item = NULL;
	GtkSingleSelection* _tmp0_;
	GObject* _tmp1_;
	GObject* _tmp2_;
	FtVariableItem* _tmp3_;
	FtFormatItem* format_item = NULL;
	GtkSingleSelection* _tmp4_;
	GObject* _tmp5_;
	GObject* _tmp6_;
	FtFormatItem* _tmp7_;
	FtVariableItem* _tmp8_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->variables_model;
	_tmp1_ = gtk_single_selection_get_selected_item (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, FT_TYPE_VARIABLE_ITEM, FtVariableItem));
	variable_item = _tmp3_;
	_tmp4_ = self->priv->formats_model;
	_tmp5_ = gtk_single_selection_get_selected_item (_tmp4_);
	_tmp6_ = _tmp5_;
	_tmp7_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp6_, FT_TYPE_FORMAT_ITEM, FtFormatItem));
	format_item = _tmp7_;
	_tmp8_ = variable_item;
	if (_tmp8_ != NULL) {
		gchar* variable_name = NULL;
		FtVariableItem* _tmp9_;
		const gchar* _tmp10_;
		const gchar* _tmp11_;
		gchar* _tmp12_;
		const gchar* _tmp13_ = NULL;
		FtFormatItem* _tmp14_;
		gchar* format_name = NULL;
		gchar* _tmp18_;
		const gchar* _tmp19_;
		FtVariableItem* _tmp20_;
		GType _tmp21_;
		GType _tmp22_;
		gchar* _tmp23_;
		gchar* _tmp24_;
		gboolean _tmp25_;
		const gchar* _tmp27_;
		const gchar* _tmp28_;
		_tmp9_ = variable_item;
		_tmp10_ = ft_variable_item_get_name (_tmp9_);
		_tmp11_ = _tmp10_;
		_tmp12_ = g_strdup (_tmp11_);
		variable_name = _tmp12_;
		_tmp14_ = format_item;
		if (_tmp14_ != NULL) {
			FtFormatItem* _tmp15_;
			const gchar* _tmp16_;
			const gchar* _tmp17_;
			_tmp15_ = format_item;
			_tmp16_ = ft_format_item_get_name (_tmp15_);
			_tmp17_ = _tmp16_;
			_tmp13_ = _tmp17_;
		} else {
			_tmp13_ = "";
		}
		_tmp18_ = g_strdup (_tmp13_);
		format_name = _tmp18_;
		_tmp19_ = format_name;
		_tmp20_ = variable_item;
		_tmp21_ = ft_variable_item_get_value_type (_tmp20_);
		_tmp22_ = _tmp21_;
		_tmp23_ = ft_get_default_value_format (_tmp22_);
		_tmp24_ = _tmp23_;
		_tmp25_ = g_strcmp0 (_tmp19_, _tmp24_) == 0;
		_g_free0 (_tmp24_);
		if (_tmp25_) {
			gchar* _tmp26_;
			_tmp26_ = g_strdup ("");
			_g_free0 (format_name);
			format_name = _tmp26_;
		}
		_tmp27_ = variable_name;
		_tmp28_ = format_name;
		g_signal_emit (self, ft_variable_popover_signals[FT_VARIABLE_POPOVER_SELECTED_SIGNAL], 0, _tmp27_, _tmp28_);
		_g_free0 (format_name);
		_g_free0 (variable_name);
	}
	_g_object_unref0 (format_item);
	_g_object_unref0 (variable_item);
}

static void
_ft_variable_popover_on_insert_variable_button_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                           gpointer self)
{
	ft_variable_popover_on_insert_variable_button_clicked ((FtVariablePopover*) self);
}

static void
ft_variable_popover_on_formats_model_selection_changed (FtVariablePopover* self)
{
	GHashTable* _tmp0_;
	FtVariableItem* variable_item = NULL;
	GtkSingleSelection* _tmp1_;
	GObject* _tmp2_;
	GObject* _tmp3_;
	FtVariableItem* _tmp4_;
	FtFormatItem* format_item = NULL;
	GtkSingleSelection* _tmp5_;
	GObject* _tmp6_;
	GObject* _tmp7_;
	FtFormatItem* _tmp8_;
	gboolean _tmp9_ = FALSE;
	FtVariableItem* _tmp10_;
	g_return_if_fail (self != NULL);
	_tmp0_ = ft_variable_popover_last_used_formats;
	_vala_return_if_fail (_tmp0_ != NULL, "last_used_formats != null");
	_tmp1_ = self->priv->variables_model;
	_tmp2_ = gtk_single_selection_get_selected_item (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, FT_TYPE_VARIABLE_ITEM, FtVariableItem));
	variable_item = _tmp4_;
	_tmp5_ = self->priv->formats_model;
	_tmp6_ = gtk_single_selection_get_selected_item (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, FT_TYPE_FORMAT_ITEM, FtFormatItem));
	format_item = _tmp8_;
	_tmp10_ = variable_item;
	if (_tmp10_ != NULL) {
		FtFormatItem* _tmp11_;
		_tmp11_ = format_item;
		_tmp9_ = _tmp11_ != NULL;
	} else {
		_tmp9_ = FALSE;
	}
	if (_tmp9_) {
		GHashTable* _tmp12_;
		FtVariableItem* _tmp13_;
		GType _tmp14_;
		GType _tmp15_;
		FtFormatItem* _tmp16_;
		const gchar* _tmp17_;
		const gchar* _tmp18_;
		gchar* _tmp19_;
		_tmp12_ = ft_variable_popover_last_used_formats;
		_tmp13_ = variable_item;
		_tmp14_ = ft_variable_item_get_value_type (_tmp13_);
		_tmp15_ = _tmp14_;
		_tmp16_ = format_item;
		_tmp17_ = ft_format_item_get_name (_tmp16_);
		_tmp18_ = _tmp17_;
		_tmp19_ = g_strdup (_tmp18_);
		g_hash_table_insert (_tmp12_, (gpointer) ((gintptr) _tmp15_), _tmp19_);
	}
	_g_object_unref0 (format_item);
	_g_object_unref0 (variable_item);
}

static void
_ft_variable_popover_on_formats_model_selection_changed_gtk_selection_model_selection_changed (GtkSelectionModel* _sender,
                                                                                               guint position,
                                                                                               guint n_items,
                                                                                               gpointer self)
{
	ft_variable_popover_on_formats_model_selection_changed ((FtVariablePopover*) self);
}

static void
ft_variable_popover_on_variables_model_selection_changed (FtVariablePopover* self,
                                                          guint position,
                                                          guint n_items)
{
	FtVariableItem* variable_item = NULL;
	GtkSingleSelection* _tmp0_;
	GObject* _tmp1_;
	GObject* _tmp2_;
	FtVariableItem* _tmp3_;
	FtVariableItem* _tmp4_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->variables_model;
	_tmp1_ = gtk_single_selection_get_selected_item (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, FT_TYPE_VARIABLE_ITEM, FtVariableItem));
	variable_item = _tmp3_;
	_tmp4_ = variable_item;
	if (_tmp4_ != NULL) {
		GListModel* formats_model = NULL;
		FtVariableItem* _tmp5_;
		GType _tmp6_;
		GType _tmp7_;
		GListModel* _tmp8_;
		gchar* preferred_format = NULL;
		FtVariableItem* _tmp9_;
		GType _tmp10_;
		GType _tmp11_;
		gchar* _tmp12_;
		GListModel* _tmp13_;
		GListModel* _tmp14_;
		GtkSingleSelection* _tmp15_;
		GtkSingleSelection* _tmp16_;
		GtkSingleSelection* _tmp17_;
		GtkSingleSelection* _tmp18_;
		const gchar* _tmp19_;
		GtkSingleSelection* _tmp20_;
		GtkListView* _tmp21_;
		GtkSingleSelection* _tmp22_;
		GtkListView* _tmp23_;
		GtkSingleSelection* _tmp24_;
		guint _tmp25_;
		guint _tmp26_;
		GtkLabel* _tmp27_;
		FtVariableItem* _tmp28_;
		const gchar* _tmp29_;
		const gchar* _tmp30_;
		GtkLabel* _tmp31_;
		FtVariableItem* _tmp32_;
		const gchar* _tmp33_;
		const gchar* _tmp34_;
		GtkStack* _tmp35_;
		_tmp5_ = variable_item;
		_tmp6_ = ft_variable_item_get_value_type (_tmp5_);
		_tmp7_ = _tmp6_;
		_tmp8_ = ft_variable_popover_create_formats_model (self, _tmp7_);
		formats_model = _tmp8_;
		_tmp9_ = variable_item;
		_tmp10_ = ft_variable_item_get_value_type (_tmp9_);
		_tmp11_ = _tmp10_;
		_tmp12_ = ft_variable_popover_get_preferred_format (self, _tmp11_);
		preferred_format = _tmp12_;
		_tmp13_ = formats_model;
		_tmp14_ = _g_object_ref0 (_tmp13_);
		_tmp15_ = gtk_single_selection_new (_tmp14_);
		_g_object_unref0 (self->priv->formats_model);
		self->priv->formats_model = _tmp15_;
		_tmp16_ = self->priv->formats_model;
		gtk_single_selection_set_autoselect (_tmp16_, TRUE);
		_tmp17_ = self->priv->formats_model;
		gtk_single_selection_set_can_unselect (_tmp17_, FALSE);
		_tmp18_ = self->priv->formats_model;
		_tmp19_ = preferred_format;
		gtk_selection_model_select_item ((GtkSelectionModel*) _tmp18_, ft_variable_popover_index_format (self, _tmp19_), TRUE);
		_tmp20_ = self->priv->formats_model;
		g_signal_connect_object ((GtkSelectionModel*) _tmp20_, "selection-changed", (GCallback) _ft_variable_popover_on_formats_model_selection_changed_gtk_selection_model_selection_changed, self, 0);
		_tmp21_ = self->priv->formats_listview;
		_tmp22_ = self->priv->formats_model;
		gtk_list_view_set_model (_tmp21_, (GtkSelectionModel*) _tmp22_);
		_tmp23_ = self->priv->formats_listview;
		_tmp24_ = self->priv->formats_model;
		g_object_get (_tmp24_, "n-items", &_tmp25_, NULL);
		_tmp26_ = _tmp25_;
		gtk_widget_set_visible ((GtkWidget*) _tmp23_, _tmp26_ > ((guint) 1));
		_tmp27_ = self->priv->variable_name_label;
		_tmp28_ = variable_item;
		_tmp29_ = ft_variable_item_get_name (_tmp28_);
		_tmp30_ = _tmp29_;
		gtk_label_set_label (_tmp27_, _tmp30_);
		_tmp31_ = self->priv->variable_description_label;
		_tmp32_ = variable_item;
		_tmp33_ = ft_variable_item_get_description (_tmp32_);
		_tmp34_ = _tmp33_;
		gtk_label_set_label (_tmp31_, _tmp34_);
		_tmp35_ = self->priv->stack;
		gtk_stack_set_visible_child_name (_tmp35_, "details");
		_g_free0 (preferred_format);
		_g_object_unref0 (formats_model);
	} else {
		GtkStack* _tmp36_;
		_tmp36_ = self->priv->stack;
		gtk_stack_set_visible_child_name (_tmp36_, "list");
	}
	_g_object_unref0 (variable_item);
}

static void
ft_variable_popover_real_closed (GtkPopover* base)
{
	FtVariablePopover * self;
	self = (FtVariablePopover*) base;
	ft_variable_popover_reset (self);
}

static void
_ft_variable_popover_on_variables_model_selection_changed_gtk_selection_model_selection_changed (GtkSelectionModel* _sender,
                                                                                                 guint position,
                                                                                                 guint n_items,
                                                                                                 gpointer self)
{
	ft_variable_popover_on_variables_model_selection_changed ((FtVariablePopover*) self, position, n_items);
}

static void
ft_variable_popover_real_dispose (GObject* base)
{
	FtVariablePopover * self;
	GtkSingleSelection* _tmp0_;
	GtkSingleSelection* _tmp3_;
	self = (FtVariablePopover*) base;
	_tmp0_ = self->priv->variables_model;
	if (_tmp0_ != NULL) {
		GtkSingleSelection* _tmp1_;
		guint _tmp2_;
		_tmp1_ = self->priv->variables_model;
		g_signal_parse_name ("selection-changed", gtk_selection_model_get_type (), &_tmp2_, NULL, FALSE);
		g_signal_handlers_disconnect_matched ((GtkSelectionModel*) _tmp1_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp2_, 0, NULL, (GCallback) _ft_variable_popover_on_variables_model_selection_changed_gtk_selection_model_selection_changed, self);
		_g_object_unref0 (self->priv->variables_model);
		self->priv->variables_model = NULL;
	}
	_tmp3_ = self->priv->formats_model;
	if (_tmp3_ != NULL) {
		GtkSingleSelection* _tmp4_;
		guint _tmp5_;
		_tmp4_ = self->priv->formats_model;
		g_signal_parse_name ("selection-changed", gtk_selection_model_get_type (), &_tmp5_, NULL, FALSE);
		g_signal_handlers_disconnect_matched ((GtkSelectionModel*) _tmp4_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp5_, 0, NULL, (GCallback) _ft_variable_popover_on_formats_model_selection_changed_gtk_selection_model_selection_changed, self);
		_g_object_unref0 (self->priv->formats_model);
		self->priv->formats_model = NULL;
	}
	G_OBJECT_CLASS (ft_variable_popover_parent_class)->dispose ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_popover_get_type (), GtkPopover));
}

FtVariablePopover*
ft_variable_popover_construct (GType object_type)
{
	FtVariablePopover * self = NULL;
	self = (FtVariablePopover*) g_object_new (object_type, NULL);
	return self;
}

FtVariablePopover*
ft_variable_popover_new (void)
{
	return ft_variable_popover_construct (FT_TYPE_VARIABLE_POPOVER);
}

static void
ft_variable_popover_real_selected (FtVariablePopover* self,
                                   const gchar* variable_name,
                                   const gchar* variable_format_name)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (variable_name != NULL);
	g_return_if_fail (variable_format_name != NULL);
	gtk_widget_set_visible ((GtkWidget*) self, FALSE);
}

static void
g_cclosure_user_marshal_VOID__STRING_STRING (GClosure * closure,
                                             GValue * return_value,
                                             guint n_param_values,
                                             const GValue * param_values,
                                             gpointer invocation_hint,
                                             gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__STRING_STRING) (gpointer data1, const char* arg_1, const char* arg_2, gpointer data2);
	register GMarshalFunc_VOID__STRING_STRING callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 3);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__STRING_STRING) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_string (param_values + 1), g_value_get_string (param_values + 2), data2);
}

static GObject *
ft_variable_popover_constructor (GType type,
                                 guint n_construct_properties,
                                 GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	FtVariablePopover * self;
	GListModel* _tmp0_;
	GtkSingleSelection* _tmp1_;
	GtkSingleSelection* _tmp2_;
	GtkSingleSelection* _tmp3_;
	GtkSingleSelection* _tmp4_;
	GtkListView* _tmp5_;
	GtkSingleSelection* _tmp6_;
	parent_class = G_OBJECT_CLASS (ft_variable_popover_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_VARIABLE_POPOVER, FtVariablePopover);
	_tmp0_ = ft_variable_popover_create_variables_model (self);
	_tmp1_ = gtk_single_selection_new (_tmp0_);
	_g_object_unref0 (self->priv->variables_model);
	self->priv->variables_model = _tmp1_;
	_tmp2_ = self->priv->variables_model;
	gtk_single_selection_set_autoselect (_tmp2_, FALSE);
	_tmp3_ = self->priv->variables_model;
	gtk_single_selection_set_can_unselect (_tmp3_, TRUE);
	_tmp4_ = self->priv->variables_model;
	g_signal_connect_object ((GtkSelectionModel*) _tmp4_, "selection-changed", (GCallback) _ft_variable_popover_on_variables_model_selection_changed_gtk_selection_model_selection_changed, self, 0);
	_tmp5_ = self->priv->variables_listview;
	_tmp6_ = self->priv->variables_model;
	gtk_list_view_set_model (_tmp5_, (GtkSelectionModel*) _tmp6_);
	ft_variable_popover_reset (self);
	return obj;
}

static void
ft_variable_popover_class_init (FtVariablePopoverClass * klass,
                                gpointer klass_data)
{
	ft_variable_popover_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FtVariablePopover_private_offset);
	((GtkPopoverClass *) klass)->closed = (void (*) (GtkPopover*)) ft_variable_popover_real_closed;
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) ft_variable_popover_real_dispose;
	G_OBJECT_CLASS (klass)->constructor = ft_variable_popover_constructor;
	G_OBJECT_CLASS (klass)->finalize = ft_variable_popover_finalize;
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/io/github/focustimerhq/FocusTimer/ui/preferences/automation/action/variable-popover.ui");
	ft_variable_popover_signals[FT_VARIABLE_POPOVER_SELECTED_SIGNAL] = g_signal_new_class_handler ("selected", FT_TYPE_VARIABLE_POPOVER, G_SIGNAL_RUN_LAST, (GCallback) ft_variable_popover_real_selected, NULL, NULL, g_cclosure_user_marshal_VOID__STRING_STRING, G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING);
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "stack", FALSE, FtVariablePopover_private_offset + G_STRUCT_OFFSET (FtVariablePopoverPrivate, stack));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "variables_listview", FALSE, FtVariablePopover_private_offset + G_STRUCT_OFFSET (FtVariablePopoverPrivate, variables_listview));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "formats_listview", FALSE, FtVariablePopover_private_offset + G_STRUCT_OFFSET (FtVariablePopoverPrivate, formats_listview));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "variable_name_label", FALSE, FtVariablePopover_private_offset + G_STRUCT_OFFSET (FtVariablePopoverPrivate, variable_name_label));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "variable_description_label", FALSE, FtVariablePopover_private_offset + G_STRUCT_OFFSET (FtVariablePopoverPrivate, variable_description_label));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "get_variable_display_name", G_CALLBACK(ft_variable_popover_get_variable_display_name));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "setup_format_item", G_CALLBACK(_ft_variable_popover_setup_format_item_gtk_signal_list_item_factory_setup));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "bind_format_item", G_CALLBACK(_ft_variable_popover_bind_format_item_gtk_signal_list_item_factory_bind));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "unbind_format_item", G_CALLBACK(_ft_variable_popover_unbind_format_item_gtk_signal_list_item_factory_unbind));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_back_button_clicked", G_CALLBACK(_ft_variable_popover_on_back_button_clicked_gtk_button_clicked));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_insert_variable_button_clicked", G_CALLBACK(_ft_variable_popover_on_insert_variable_button_clicked_gtk_button_clicked));
}

static void
ft_variable_popover_instance_init (FtVariablePopover * self,
                                   gpointer klass)
{
	self->priv = ft_variable_popover_get_instance_private (self);
	self->priv->variables_model = NULL;
	self->priv->formats_model = NULL;
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
ft_variable_popover_finalize (GObject * obj)
{
	FtVariablePopover * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_VARIABLE_POPOVER, FtVariablePopover);
	_g_object_unref0 (self->priv->variables_model);
	_g_object_unref0 (self->priv->formats_model);
	G_OBJECT_CLASS (ft_variable_popover_parent_class)->finalize (obj);
}

static GType
ft_variable_popover_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtVariablePopoverClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_variable_popover_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtVariablePopover), 0, (GInstanceInitFunc) ft_variable_popover_instance_init, NULL };
	GType ft_variable_popover_type_id;
	ft_variable_popover_type_id = g_type_register_static (gtk_popover_get_type (), "FtVariablePopover", &g_define_type_info, 0);
	FtVariablePopover_private_offset = g_type_add_instance_private (ft_variable_popover_type_id, sizeof (FtVariablePopoverPrivate));
	return ft_variable_popover_type_id;
}

GType
ft_variable_popover_get_type (void)
{
	static volatile gsize ft_variable_popover_type_id__once = 0;
	if (g_once_init_enter (&ft_variable_popover_type_id__once)) {
		GType ft_variable_popover_type_id;
		ft_variable_popover_type_id = ft_variable_popover_get_type_once ();
		g_once_init_leave (&ft_variable_popover_type_id__once, ft_variable_popover_type_id);
	}
	return ft_variable_popover_type_id__once;
}

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 inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

