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

/*
 * Copyright © 2023 Alain M. (https://github.com/alainm23/planify)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA
 *
 * Authored by: Alain M. <alainmh23@gmail.com>
 */

#include "planify.h"
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gee.h>
#include <glib-object.h>
#include <glib/gi18n-lib.h>
#include <gio/gio.h>
#include <float.h>
#include <math.h>
#include <cairo-gobject.h>
#include <adwaita.h>
#include <gdk/gdk.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  {
	WIDGETS_LABEL_PICKER_LABEL_QUICK_PICKER_0_PROPERTY,
	WIDGETS_LABEL_PICKER_LABEL_QUICK_PICKER_SOURCE_PROPERTY,
	WIDGETS_LABEL_PICKER_LABEL_QUICK_PICKER_FILTER_TEXT_PROPERTY,
	WIDGETS_LABEL_PICKER_LABEL_QUICK_PICKER_NUM_PROPERTIES
};
static GParamSpec* widgets_label_picker_label_quick_picker_properties[WIDGETS_LABEL_PICKER_LABEL_QUICK_PICKER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _Block35Data Block35Data;
typedef struct _Block36Data Block36Data;
typedef struct _Block37Data Block37Data;
#define _http_response_unref0(var) ((var == NULL) ? NULL : (var = (http_response_unref (var), NULL)))
enum  {
	WIDGETS_LABEL_PICKER_LABEL_QUICK_PICKER_LABEL_SELECTED_SIGNAL,
	WIDGETS_LABEL_PICKER_LABEL_QUICK_PICKER_NUM_SIGNALS
};
static guint widgets_label_picker_label_quick_picker_signals[WIDGETS_LABEL_PICKER_LABEL_QUICK_PICKER_NUM_SIGNALS] = {0};

struct _WidgetsLabelPickerLabelQuickPickerPrivate {
	GtkListBox* listbox;
	GtkScrolledWindow* listbox_scrolled;
	GtkEventControllerKey* key_controller;
	WidgetsLabelPickerLabelRow* create_label_row;
	ObjectsSource* _source;
	gchar* _filter_text;
};

struct _Block35Data {
	int _ref_count_;
	WidgetsLabelPickerLabelQuickPicker* self;
	GtkWidget* parent_widget;
};

struct _Block36Data {
	int _ref_count_;
	WidgetsLabelPickerLabelQuickPicker* self;
	gint visible_count;
};

struct _Block37Data {
	int _ref_count_;
	WidgetsLabelPickerLabelQuickPicker* self;
	ObjectsLabel* label;
};

static gint WidgetsLabelPickerLabelQuickPicker_private_offset;
static gpointer widgets_label_picker_label_quick_picker_parent_class = NULL;

static void widgets_label_picker_label_quick_picker_setup_focus_monitoring (WidgetsLabelPickerLabelQuickPicker* self);
static Block35Data* block35_data_ref (Block35Data* _data35_);
static void block35_data_unref (void * _userdata_);
static void __lambda274_ (Block35Data* _data35_);
static gboolean __lambda275_ (Block35Data* _data35_);
static gboolean ___lambda275__gsource_func (gpointer self);
static void ___lambda274__gtk_event_controller_focus_leave (GtkEventControllerFocus* _sender,
                                                     gpointer self);
static void widgets_label_picker_label_quick_picker_add_labels (WidgetsLabelPickerLabelQuickPicker* self,
                                                         ObjectsSource* source);
static void _g_object_unref0_ (gpointer var);
static inline void _g_list_free__g_object_unref0_ (GList* self);
static void widgets_label_picker_label_quick_picker_add_label (WidgetsLabelPickerLabelQuickPicker* self,
                                                        ObjectsLabel* label);
static void widgets_label_picker_label_quick_picker_apply_filter (WidgetsLabelPickerLabelQuickPicker* self);
static Block36Data* block36_data_ref (Block36Data* _data36_);
static void block36_data_unref (void * _userdata_);
static gboolean __lambda276_ (Block36Data* _data36_,
                       GtkListBoxRow* row);
static gboolean ___lambda276__gtk_list_box_filter_func (GtkListBoxRow* row,
                                                 gpointer self);
static void widgets_label_picker_label_quick_picker_add_create_label_row (WidgetsLabelPickerLabelQuickPicker* self);
static void widgets_label_picker_label_quick_picker_create_new_label (WidgetsLabelPickerLabelQuickPicker* self,
                                                               const gchar* label_name);
static Block37Data* block37_data_ref (Block37Data* _data37_);
static void block37_data_unref (void * _userdata_);
static void ____lambda277_ (Block37Data* _data37_,
                     GObject* obj,
                     GAsyncResult* res);
static void _____lambda277__gasync_ready_callback (GObject* source_object,
                                            GAsyncResult* res,
                                            gpointer self);
static void widgets_label_picker_label_quick_picker_scroll_to_selected (WidgetsLabelPickerLabelQuickPicker* self);
static gint widgets_label_picker_label_quick_picker_count_visible_children (WidgetsLabelPickerLabelQuickPicker* self);
static GObject * widgets_label_picker_label_quick_picker_constructor (GType type,
                                                               guint n_construct_properties,
                                                               GObjectConstructParam * construct_properties);
static gint _widgets_label_picker_label_quick_picker___lambda278_ (WidgetsLabelPickerLabelQuickPicker* self,
                                                            GtkListBoxRow* row1,
                                                            GtkListBoxRow* row2);
static gint __widgets_label_picker_label_quick_picker___lambda278__gtk_list_box_sort_func (GtkListBoxRow* row1,
                                                                                    GtkListBoxRow* row2,
                                                                                    gpointer self);
static void _widgets_label_picker_label_quick_picker___lambda279_ (WidgetsLabelPickerLabelQuickPicker* self,
                                                            GtkListBoxRow* row);
static void __widgets_label_picker_label_quick_picker___lambda279__gtk_list_box_row_activated (GtkListBox* _sender,
                                                                                        GtkListBoxRow* row,
                                                                                        gpointer self);
static gboolean _widgets_label_picker_label_quick_picker___lambda280_ (WidgetsLabelPickerLabelQuickPicker* self,
                                                                guint keyval,
                                                                guint keycode,
                                                                GdkModifierType state);
static gboolean __widgets_label_picker_label_quick_picker___lambda280__gtk_event_controller_key_key_pressed (GtkEventControllerKey* _sender,
                                                                                                      guint keyval,
                                                                                                      guint keycode,
                                                                                                      GdkModifierType state,
                                                                                                      gpointer self);
static void _widgets_label_picker_label_quick_picker___lambda281_ (WidgetsLabelPickerLabelQuickPicker* self);
static void __widgets_label_picker_label_quick_picker___lambda281__g_object_notify (GObject* _sender,
                                                                             GParamSpec* pspec,
                                                                             gpointer self);
static void widgets_label_picker_label_quick_picker_finalize (GObject * obj);
static GType widgets_label_picker_label_quick_picker_get_type_once (void);
static void _vala_widgets_label_picker_label_quick_picker_get_property (GObject * object,
                                                                 guint property_id,
                                                                 GValue * value,
                                                                 GParamSpec * pspec);
static void _vala_widgets_label_picker_label_quick_picker_set_property (GObject * object,
                                                                 guint property_id,
                                                                 const GValue * value,
                                                                 GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
widgets_label_picker_label_quick_picker_get_instance_private (WidgetsLabelPickerLabelQuickPicker* self)
{
	return G_STRUCT_MEMBER_P (self, WidgetsLabelPickerLabelQuickPicker_private_offset);
}

WidgetsLabelPickerLabelQuickPicker*
widgets_label_picker_label_quick_picker_construct (GType object_type)
{
	WidgetsLabelPickerLabelQuickPicker * self = NULL;
	self = (WidgetsLabelPickerLabelQuickPicker*) g_object_new (object_type, "has-arrow", FALSE, "autohide", FALSE, "position", GTK_POS_BOTTOM, "width-request", 275, NULL);
	return self;
}

WidgetsLabelPickerLabelQuickPicker*
widgets_label_picker_label_quick_picker_new (void)
{
	return widgets_label_picker_label_quick_picker_construct (WIDGETS_LABEL_PICKER_TYPE_LABEL_QUICK_PICKER);
}

static Block35Data*
block35_data_ref (Block35Data* _data35_)
{
	g_atomic_int_inc (&_data35_->_ref_count_);
	return _data35_;
}

static void
block35_data_unref (void * _userdata_)
{
	Block35Data* _data35_;
	_data35_ = (Block35Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data35_->_ref_count_)) {
		WidgetsLabelPickerLabelQuickPicker* self;
		self = _data35_->self;
		_g_object_unref0 (_data35_->parent_widget);
		_g_object_unref0 (self);
		g_slice_free (Block35Data, _data35_);
	}
}

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

static gboolean
__lambda275_ (Block35Data* _data35_)
{
	WidgetsLabelPickerLabelQuickPicker* self;
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_;
	gboolean _tmp2_;
	gboolean result;
	self = _data35_->self;
	_tmp1_ = gtk_widget_get_visible ((GtkWidget*) self);
	_tmp2_ = _tmp1_;
	if (_tmp2_) {
		GtkWidget* _tmp3_;
		gboolean _tmp4_;
		gboolean _tmp5_;
		_tmp3_ = _data35_->parent_widget;
		g_object_get (_tmp3_, "has-focus", &_tmp4_, NULL);
		_tmp5_ = _tmp4_;
		_tmp0_ = !_tmp5_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		gtk_popover_popdown ((GtkPopover*) self);
	}
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
___lambda275__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda275_ (self);
	return result;
}

static void
__lambda274_ (Block35Data* _data35_)
{
	WidgetsLabelPickerLabelQuickPicker* self;
	self = _data35_->self;
	g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) 50, ___lambda275__gsource_func, block35_data_ref (_data35_), block35_data_unref);
}

static void
___lambda274__gtk_event_controller_focus_leave (GtkEventControllerFocus* _sender,
                                                gpointer self)
{
	__lambda274_ (self);
}

static void
widgets_label_picker_label_quick_picker_setup_focus_monitoring (WidgetsLabelPickerLabelQuickPicker* self)
{
	Block35Data* _data35_;
	GtkWidget* _tmp0_;
	GtkWidget* _tmp1_;
	GtkWidget* _tmp2_;
	GtkEventControllerFocus* focus_controller = NULL;
	GtkEventControllerFocus* _tmp3_;
	GtkEventControllerFocus* _tmp4_;
	GtkWidget* _tmp5_;
	GtkEventControllerFocus* _tmp6_;
	GtkEventController* _tmp7_;
	g_return_if_fail (self != NULL);
	_data35_ = g_slice_new0 (Block35Data);
	_data35_->_ref_count_ = 1;
	_data35_->self = g_object_ref (self);
	_tmp0_ = gtk_widget_get_parent ((GtkWidget*) self);
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_data35_->parent_widget = _tmp1_;
	_tmp2_ = _data35_->parent_widget;
	if (_tmp2_ == NULL) {
		block35_data_unref (_data35_);
		_data35_ = NULL;
		return;
	}
	_tmp3_ = (GtkEventControllerFocus*) gtk_event_controller_focus_new ();
	focus_controller = _tmp3_;
	_tmp4_ = focus_controller;
	g_signal_connect_data (_tmp4_, "leave", (GCallback) ___lambda274__gtk_event_controller_focus_leave, block35_data_ref (_data35_), (GClosureNotify) block35_data_unref, 0);
	_tmp5_ = _data35_->parent_widget;
	_tmp6_ = focus_controller;
	_tmp7_ = _g_object_ref0 ((GtkEventController*) _tmp6_);
	gtk_widget_add_controller (_tmp5_, _tmp7_);
	_g_object_unref0 (focus_controller);
	block35_data_unref (_data35_);
	_data35_ = NULL;
}

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_);
}

static void
widgets_label_picker_label_quick_picker_add_labels (WidgetsLabelPickerLabelQuickPicker* self,
                                                    ObjectsSource* source)
{
	GeeHashMap* _tmp0_;
	Util* _tmp1_;
	Util* _tmp2_;
	GtkListBox* _tmp3_;
	GList* _tmp4_;
	GList* _tmp5_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (source != NULL);
	_tmp0_ = self->labels_widgets_map;
	gee_abstract_map_clear ((GeeAbstractMap*) _tmp0_);
	_tmp1_ = util_get_default ();
	_tmp2_ = _tmp1_;
	_tmp3_ = self->priv->listbox;
	_tmp4_ = util_get_children (_tmp2_, _tmp3_);
	_tmp5_ = _tmp4_;
	_g_object_unref0 (_tmp2_);
	{
		GList* child_collection = NULL;
		GList* child_it = NULL;
		child_collection = _tmp5_;
		for (child_it = child_collection; child_it != NULL; child_it = child_it->next) {
			GtkWidget* child = NULL;
			child = (GtkWidget*) ((GtkListBoxRow*) child_it->data);
			{
				GtkListBox* _tmp6_;
				GtkWidget* _tmp7_;
				_tmp6_ = self->priv->listbox;
				_tmp7_ = child;
				gtk_list_box_remove (_tmp6_, _tmp7_);
			}
		}
		(child_collection == NULL) ? NULL : (child_collection = (_g_list_free__g_object_unref0_ (child_collection), NULL));
	}
	{
		GeeArrayList* _label_list = NULL;
		ServicesStore* _tmp8_;
		const gchar* _tmp9_;
		const gchar* _tmp10_;
		GeeArrayList* _tmp11_;
		gint _label_size = 0;
		GeeArrayList* _tmp12_;
		gint _tmp13_;
		gint _tmp14_;
		gint _label_index = 0;
		_tmp8_ = services_store_instance ();
		_tmp9_ = objects_base_object_get_id ((ObjectsBaseObject*) source);
		_tmp10_ = _tmp9_;
		_tmp11_ = services_store_get_labels_by_source (_tmp8_, _tmp10_);
		_label_list = _tmp11_;
		_tmp12_ = _label_list;
		_tmp13_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp12_);
		_tmp14_ = _tmp13_;
		_label_size = _tmp14_;
		_label_index = -1;
		while (TRUE) {
			gint _tmp15_;
			gint _tmp16_;
			ObjectsLabel* label = NULL;
			GeeArrayList* _tmp17_;
			gpointer _tmp18_;
			ObjectsLabel* _tmp19_;
			_label_index = _label_index + 1;
			_tmp15_ = _label_index;
			_tmp16_ = _label_size;
			if (!(_tmp15_ < _tmp16_)) {
				break;
			}
			_tmp17_ = _label_list;
			_tmp18_ = gee_abstract_list_get ((GeeAbstractList*) _tmp17_, _label_index);
			label = (ObjectsLabel*) _tmp18_;
			_tmp19_ = label;
			widgets_label_picker_label_quick_picker_add_label (self, _tmp19_);
			_g_object_unref0 (label);
		}
		_g_object_unref0 (_label_list);
	}
}

static void
widgets_label_picker_label_quick_picker_add_label (WidgetsLabelPickerLabelQuickPicker* self,
                                                   ObjectsLabel* label)
{
	GeeHashMap* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	WidgetsLabelPickerLabelRow* _tmp3_ = NULL;
	WidgetsLabelPickerLabelRow* _tmp4_;
	GtkListBox* _tmp5_;
	GeeHashMap* _tmp6_;
	const gchar* _tmp7_;
	const gchar* _tmp8_;
	gpointer _tmp9_;
	WidgetsLabelPickerLabelRow* _tmp10_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (label != NULL);
	_tmp0_ = self->labels_widgets_map;
	_tmp1_ = objects_base_object_get_id ((ObjectsBaseObject*) label);
	_tmp2_ = _tmp1_;
	_tmp3_ = widgets_label_picker_label_row_new (label);
	widgets_label_picker_label_row_set_hide_check_button (_tmp3_, TRUE);
	widgets_label_picker_label_row_set_margin (_tmp3_, 6);
	g_object_ref_sink (_tmp3_);
	_tmp4_ = _tmp3_;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp0_, _tmp2_, _tmp4_);
	_g_object_unref0 (_tmp4_);
	_tmp5_ = self->priv->listbox;
	_tmp6_ = self->labels_widgets_map;
	_tmp7_ = objects_base_object_get_id ((ObjectsBaseObject*) label);
	_tmp8_ = _tmp7_;
	_tmp9_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp6_, _tmp8_);
	_tmp10_ = (WidgetsLabelPickerLabelRow*) _tmp9_;
	gtk_list_box_append (_tmp5_, (GtkWidget*) _tmp10_);
	_g_object_unref0 (_tmp10_);
}

static Block36Data*
block36_data_ref (Block36Data* _data36_)
{
	g_atomic_int_inc (&_data36_->_ref_count_);
	return _data36_;
}

static void
block36_data_unref (void * _userdata_)
{
	Block36Data* _data36_;
	_data36_ = (Block36Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data36_->_ref_count_)) {
		WidgetsLabelPickerLabelQuickPicker* self;
		self = _data36_->self;
		_g_object_unref0 (self);
		g_slice_free (Block36Data, _data36_);
	}
}

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 gboolean
__lambda276_ (Block36Data* _data36_,
              GtkListBoxRow* row)
{
	WidgetsLabelPickerLabelQuickPicker* self;
	WidgetsLabelPickerLabelRow* label_row = NULL;
	WidgetsLabelPickerLabelRow* _tmp0_;
	const gchar* _tmp1_;
	gboolean matches = FALSE;
	WidgetsLabelPickerLabelRow* _tmp2_;
	ObjectsLabel* _tmp3_;
	ObjectsLabel* _tmp4_;
	const gchar* _tmp5_;
	const gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	const gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	gboolean _tmp12_;
	gboolean result;
	self = _data36_->self;
	g_return_val_if_fail (row != NULL, FALSE);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (row, WIDGETS_LABEL_PICKER_TYPE_LABEL_ROW, WidgetsLabelPickerLabelRow));
	label_row = _tmp0_;
	_tmp1_ = self->priv->_filter_text;
	if (g_strcmp0 (_tmp1_, "") == 0) {
		result = TRUE;
		_g_object_unref0 (label_row);
		return result;
	}
	_tmp2_ = label_row;
	_tmp3_ = widgets_label_picker_label_row_get_label (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = objects_base_object_get_name ((ObjectsBaseObject*) _tmp4_);
	_tmp6_ = _tmp5_;
	_tmp7_ = g_utf8_strdown (_tmp6_, (gssize) -1);
	_tmp8_ = _tmp7_;
	_tmp9_ = self->priv->_filter_text;
	_tmp10_ = g_utf8_strdown (_tmp9_, (gssize) -1);
	_tmp11_ = _tmp10_;
	_tmp12_ = string_contains (_tmp8_, _tmp11_);
	_g_free0 (_tmp11_);
	_g_free0 (_tmp8_);
	matches = _tmp12_;
	if (matches) {
		gint _tmp13_;
		_tmp13_ = _data36_->visible_count;
		_data36_->visible_count = _tmp13_ + 1;
	}
	result = matches;
	_g_object_unref0 (label_row);
	return result;
}

static gboolean
___lambda276__gtk_list_box_filter_func (GtkListBoxRow* row,
                                        gpointer self)
{
	gboolean result;
	result = __lambda276_ (self, row);
	return result;
}

static void
widgets_label_picker_label_quick_picker_apply_filter (WidgetsLabelPickerLabelQuickPicker* self)
{
	Block36Data* _data36_;
	WidgetsLabelPickerLabelRow* _tmp0_;
	GtkListBox* _tmp3_;
	gboolean _tmp4_ = FALSE;
	g_return_if_fail (self != NULL);
	_data36_ = g_slice_new0 (Block36Data);
	_data36_->_ref_count_ = 1;
	_data36_->self = g_object_ref (self);
	_tmp0_ = self->priv->create_label_row;
	if (_tmp0_ != NULL) {
		GtkListBox* _tmp1_;
		WidgetsLabelPickerLabelRow* _tmp2_;
		_tmp1_ = self->priv->listbox;
		_tmp2_ = self->priv->create_label_row;
		gtk_list_box_remove (_tmp1_, (GtkWidget*) _tmp2_);
		_g_object_unref0 (self->priv->create_label_row);
		self->priv->create_label_row = NULL;
	}
	_data36_->visible_count = 0;
	_tmp3_ = self->priv->listbox;
	gtk_list_box_set_filter_func (_tmp3_, ___lambda276__gtk_list_box_filter_func, block36_data_ref (_data36_), block36_data_unref);
	if (_data36_->visible_count == 0) {
		const gchar* _tmp5_;
		gint _tmp6_;
		gint _tmp7_;
		_tmp5_ = self->priv->_filter_text;
		_tmp6_ = strlen (_tmp5_);
		_tmp7_ = _tmp6_;
		_tmp4_ = _tmp7_ > 0;
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		widgets_label_picker_label_quick_picker_add_create_label_row (self);
	} else {
		widgets_label_picker_label_quick_picker_select_first_item (self);
	}
	block36_data_unref (_data36_);
	_data36_ = NULL;
}

static void
widgets_label_picker_label_quick_picker_add_create_label_row (WidgetsLabelPickerLabelQuickPicker* self)
{
	ObjectsLabel* create_label = NULL;
	ObjectsLabel* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	WidgetsLabelPickerLabelRow* _tmp4_ = NULL;
	GtkListBox* _tmp5_;
	WidgetsLabelPickerLabelRow* _tmp6_;
	GtkListBox* _tmp7_;
	WidgetsLabelPickerLabelRow* _tmp8_;
	g_return_if_fail (self != NULL);
	_tmp0_ = objects_label_new ();
	create_label = _tmp0_;
	_tmp1_ = self->priv->_filter_text;
	_tmp2_ = g_strdup_printf (_ ("Label not found: Create '%s'"), _tmp1_);
	_tmp3_ = _tmp2_;
	objects_base_object_set_name ((ObjectsBaseObject*) create_label, _tmp3_);
	_g_free0 (_tmp3_);
	objects_base_object_set_color ((ObjectsBaseObject*) create_label, "#a0a0a0");
	objects_base_object_set_id ((ObjectsBaseObject*) create_label, "create_new_label");
	_tmp4_ = widgets_label_picker_label_row_new (create_label);
	widgets_label_picker_label_row_set_hide_check_button (_tmp4_, TRUE);
	widgets_label_picker_label_row_set_margin (_tmp4_, 6);
	g_object_ref_sink (_tmp4_);
	_g_object_unref0 (self->priv->create_label_row);
	self->priv->create_label_row = _tmp4_;
	_tmp5_ = self->priv->listbox;
	_tmp6_ = self->priv->create_label_row;
	gtk_list_box_append (_tmp5_, (GtkWidget*) _tmp6_);
	_tmp7_ = self->priv->listbox;
	_tmp8_ = self->priv->create_label_row;
	gtk_list_box_select_row (_tmp7_, (GtkListBoxRow*) _tmp8_);
	_g_object_unref0 (create_label);
}

static Block37Data*
block37_data_ref (Block37Data* _data37_)
{
	g_atomic_int_inc (&_data37_->_ref_count_);
	return _data37_;
}

static void
block37_data_unref (void * _userdata_)
{
	Block37Data* _data37_;
	_data37_ = (Block37Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data37_->_ref_count_)) {
		WidgetsLabelPickerLabelQuickPicker* self;
		self = _data37_->self;
		_g_object_unref0 (_data37_->label);
		_g_object_unref0 (self);
		g_slice_free (Block37Data, _data37_);
	}
}

static void
____lambda277_ (Block37Data* _data37_,
                GObject* obj,
                GAsyncResult* res)
{
	WidgetsLabelPickerLabelQuickPicker* self;
	HttpResponse* response = NULL;
	ServicesTodoist* _tmp0_;
	ServicesTodoist* _tmp1_;
	HttpResponse* _tmp2_;
	HttpResponse* _tmp3_;
	HttpResponse* _tmp4_;
	gboolean _tmp5_;
	gboolean _tmp6_;
	WidgetsLabelPickerLabelRow* _tmp14_;
	self = _data37_->self;
	g_return_if_fail (res != NULL);
	_tmp0_ = services_todoist_get_default ();
	_tmp1_ = _tmp0_;
	_tmp2_ = services_todoist_add_finish (_tmp1_, res);
	_tmp3_ = _tmp2_;
	_g_object_unref0 (_tmp1_);
	response = _tmp3_;
	_tmp4_ = response;
	_tmp5_ = http_response_get_status (_tmp4_);
	_tmp6_ = _tmp5_;
	if (_tmp6_) {
		ObjectsLabel* _tmp7_;
		HttpResponse* _tmp8_;
		const gchar* _tmp9_;
		const gchar* _tmp10_;
		ServicesStore* _tmp11_;
		ObjectsLabel* _tmp12_;
		ObjectsLabel* _tmp13_;
		_tmp7_ = _data37_->label;
		_tmp8_ = response;
		_tmp9_ = http_response_get_data (_tmp8_);
		_tmp10_ = _tmp9_;
		objects_base_object_set_id ((ObjectsBaseObject*) _tmp7_, _tmp10_);
		_tmp11_ = services_store_instance ();
		_tmp12_ = _data37_->label;
		services_store_insert_label (_tmp11_, _tmp12_);
		_tmp13_ = _data37_->label;
		g_signal_emit (self, widgets_label_picker_label_quick_picker_signals[WIDGETS_LABEL_PICKER_LABEL_QUICK_PICKER_LABEL_SELECTED_SIGNAL], 0, _tmp13_);
	}
	_tmp14_ = self->priv->create_label_row;
	if (_tmp14_ != NULL) {
		WidgetsLabelPickerLabelRow* _tmp15_;
		_tmp15_ = self->priv->create_label_row;
		widgets_label_picker_label_row_show_loading (_tmp15_, FALSE);
	}
	_http_response_unref0 (response);
}

static void
_____lambda277__gasync_ready_callback (GObject* source_object,
                                       GAsyncResult* res,
                                       gpointer self)
{
	____lambda277_ (self, source_object, res);
	block37_data_unref (self);
}

static void
widgets_label_picker_label_quick_picker_create_new_label (WidgetsLabelPickerLabelQuickPicker* self,
                                                          const gchar* label_name)
{
	Block37Data* _data37_;
	WidgetsLabelPickerLabelRow* _tmp0_;
	ObjectsLabel* _tmp2_;
	ObjectsLabel* _tmp3_;
	Util* _tmp4_;
	Util* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	ObjectsLabel* _tmp8_;
	ObjectsLabel* _tmp9_;
	ObjectsSource* _tmp10_;
	const gchar* _tmp11_;
	const gchar* _tmp12_;
	gboolean _tmp13_ = FALSE;
	ObjectsSource* _tmp14_;
	SourceType _tmp15_;
	SourceType _tmp16_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (label_name != NULL);
	_data37_ = g_slice_new0 (Block37Data);
	_data37_->_ref_count_ = 1;
	_data37_->self = g_object_ref (self);
	_tmp0_ = self->priv->create_label_row;
	if (_tmp0_ != NULL) {
		WidgetsLabelPickerLabelRow* _tmp1_;
		_tmp1_ = self->priv->create_label_row;
		widgets_label_picker_label_row_show_loading (_tmp1_, TRUE);
	}
	_tmp2_ = objects_label_new ();
	_data37_->label = _tmp2_;
	_tmp3_ = _data37_->label;
	_tmp4_ = util_get_default ();
	_tmp5_ = _tmp4_;
	_tmp6_ = util_get_random_color (_tmp5_);
	_tmp7_ = _tmp6_;
	objects_base_object_set_color ((ObjectsBaseObject*) _tmp3_, _tmp7_);
	_g_free0 (_tmp7_);
	_g_object_unref0 (_tmp5_);
	_tmp8_ = _data37_->label;
	objects_base_object_set_name ((ObjectsBaseObject*) _tmp8_, label_name);
	_tmp9_ = _data37_->label;
	_tmp10_ = self->priv->_source;
	_tmp11_ = objects_base_object_get_id ((ObjectsBaseObject*) _tmp10_);
	_tmp12_ = _tmp11_;
	objects_label_set_source_id (_tmp9_, _tmp12_);
	_tmp14_ = self->priv->_source;
	_tmp15_ = objects_source_get_source_type (_tmp14_);
	_tmp16_ = _tmp15_;
	if (_tmp16_ == SOURCE_TYPE_LOCAL) {
		_tmp13_ = TRUE;
	} else {
		ObjectsSource* _tmp17_;
		SourceType _tmp18_;
		SourceType _tmp19_;
		_tmp17_ = self->priv->_source;
		_tmp18_ = objects_source_get_source_type (_tmp17_);
		_tmp19_ = _tmp18_;
		_tmp13_ = _tmp19_ == SOURCE_TYPE_CALDAV;
	}
	if (_tmp13_) {
		ObjectsLabel* _tmp20_;
		Util* _tmp21_;
		Util* _tmp22_;
		ObjectsLabel* _tmp23_;
		gchar* _tmp24_;
		gchar* _tmp25_;
		ServicesStore* _tmp26_;
		ObjectsLabel* _tmp27_;
		ObjectsLabel* _tmp28_;
		_tmp20_ = _data37_->label;
		_tmp21_ = util_get_default ();
		_tmp22_ = _tmp21_;
		_tmp23_ = _data37_->label;
		_tmp24_ = util_generate_id (_tmp22_, (ObjectsBaseObject*) _tmp23_);
		_tmp25_ = _tmp24_;
		objects_base_object_set_id ((ObjectsBaseObject*) _tmp20_, _tmp25_);
		_g_free0 (_tmp25_);
		_g_object_unref0 (_tmp22_);
		_tmp26_ = services_store_instance ();
		_tmp27_ = _data37_->label;
		services_store_insert_label (_tmp26_, _tmp27_);
		_tmp28_ = _data37_->label;
		g_signal_emit (self, widgets_label_picker_label_quick_picker_signals[WIDGETS_LABEL_PICKER_LABEL_QUICK_PICKER_LABEL_SELECTED_SIGNAL], 0, _tmp28_);
	} else {
		ObjectsSource* _tmp29_;
		SourceType _tmp30_;
		SourceType _tmp31_;
		_tmp29_ = self->priv->_source;
		_tmp30_ = objects_source_get_source_type (_tmp29_);
		_tmp31_ = _tmp30_;
		if (_tmp31_ == SOURCE_TYPE_TODOIST) {
			ServicesTodoist* _tmp32_;
			ServicesTodoist* _tmp33_;
			ObjectsLabel* _tmp34_;
			_tmp32_ = services_todoist_get_default ();
			_tmp33_ = _tmp32_;
			_tmp34_ = _data37_->label;
			services_todoist_add (_tmp33_, (ObjectsBaseObject*) _tmp34_, _____lambda277__gasync_ready_callback, block37_data_ref (_data37_));
			_g_object_unref0 (_tmp33_);
		}
	}
	block37_data_unref (_data37_);
	_data37_ = NULL;
}

void
widgets_label_picker_label_quick_picker_navigate_listbox (WidgetsLabelPickerLabelQuickPicker* self,
                                                          gboolean down)
{
	GtkListBoxRow* selected_row = NULL;
	GtkListBox* _tmp0_;
	GtkListBoxRow* _tmp1_;
	GtkListBoxRow* _tmp2_;
	GtkListBoxRow* _tmp3_;
	gint current_index = 0;
	GtkListBoxRow* _tmp12_;
	gint _tmp13_ = 0;
	gint new_index = 0;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->listbox;
	_tmp1_ = gtk_list_box_get_selected_row (_tmp0_);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	selected_row = _tmp2_;
	_tmp3_ = selected_row;
	if (_tmp3_ == NULL) {
		gint index = 0;
		index = 0;
		while (TRUE) {
			GtkListBoxRow* row = NULL;
			GtkListBox* _tmp4_;
			GtkListBoxRow* _tmp5_;
			GtkListBoxRow* _tmp6_;
			GtkListBoxRow* _tmp7_;
			GtkListBoxRow* _tmp8_;
			gint _tmp11_;
			_tmp4_ = self->priv->listbox;
			_tmp5_ = gtk_list_box_get_row_at_index (_tmp4_, index);
			_tmp6_ = _g_object_ref0 (_tmp5_);
			row = _tmp6_;
			_tmp7_ = row;
			if (_tmp7_ == NULL) {
				_g_object_unref0 (row);
				break;
			}
			_tmp8_ = row;
			if (gtk_widget_get_child_visible ((GtkWidget*) _tmp8_)) {
				GtkListBox* _tmp9_;
				GtkListBoxRow* _tmp10_;
				_tmp9_ = self->priv->listbox;
				_tmp10_ = row;
				gtk_list_box_select_row (_tmp9_, _tmp10_);
				widgets_label_picker_label_quick_picker_scroll_to_selected (self);
				_g_object_unref0 (row);
				break;
			}
			_tmp11_ = index;
			index = _tmp11_ + 1;
			_g_object_unref0 (row);
		}
		_g_object_unref0 (selected_row);
		return;
	}
	_tmp12_ = selected_row;
	current_index = gtk_list_box_row_get_index (_tmp12_);
	if (down) {
		_tmp13_ = current_index + 1;
	} else {
		_tmp13_ = current_index - 1;
	}
	new_index = _tmp13_;
	while (TRUE) {
		GtkListBoxRow* new_row = NULL;
		GtkListBox* _tmp14_;
		GtkListBoxRow* _tmp15_;
		GtkListBoxRow* _tmp16_;
		GtkListBoxRow* _tmp17_;
		GtkListBoxRow* _tmp18_;
		gint _tmp21_ = 0;
		if (!(new_index >= 0)) {
			break;
		}
		_tmp14_ = self->priv->listbox;
		_tmp15_ = gtk_list_box_get_row_at_index (_tmp14_, new_index);
		_tmp16_ = _g_object_ref0 (_tmp15_);
		new_row = _tmp16_;
		_tmp17_ = new_row;
		if (_tmp17_ == NULL) {
			_g_object_unref0 (new_row);
			break;
		}
		_tmp18_ = new_row;
		if (gtk_widget_get_child_visible ((GtkWidget*) _tmp18_)) {
			GtkListBox* _tmp19_;
			GtkListBoxRow* _tmp20_;
			_tmp19_ = self->priv->listbox;
			_tmp20_ = new_row;
			gtk_list_box_select_row (_tmp19_, _tmp20_);
			widgets_label_picker_label_quick_picker_scroll_to_selected (self);
			_g_object_unref0 (new_row);
			break;
		}
		if (down) {
			_tmp21_ = new_index + 1;
		} else {
			_tmp21_ = new_index - 1;
		}
		new_index = _tmp21_;
		_g_object_unref0 (new_row);
	}
	_g_object_unref0 (selected_row);
}

void
widgets_label_picker_label_quick_picker_activate_selected (WidgetsLabelPickerLabelQuickPicker* self)
{
	GtkListBoxRow* selected_row = NULL;
	GtkListBox* _tmp0_;
	GtkListBoxRow* _tmp1_;
	GtkListBoxRow* _tmp2_;
	GtkListBoxRow* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->listbox;
	_tmp1_ = gtk_list_box_get_selected_row (_tmp0_);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	selected_row = _tmp2_;
	_tmp3_ = selected_row;
	if (_tmp3_ != NULL) {
		WidgetsLabelPickerLabelRow* label_row = NULL;
		GtkListBoxRow* _tmp4_;
		WidgetsLabelPickerLabelRow* _tmp5_;
		WidgetsLabelPickerLabelRow* _tmp6_;
		WidgetsLabelPickerLabelRow* _tmp7_;
		_tmp4_ = selected_row;
		_tmp5_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, WIDGETS_LABEL_PICKER_TYPE_LABEL_ROW, WidgetsLabelPickerLabelRow));
		label_row = _tmp5_;
		_tmp6_ = label_row;
		_tmp7_ = self->priv->create_label_row;
		if (_tmp6_ == _tmp7_) {
			const gchar* _tmp8_;
			_tmp8_ = self->priv->_filter_text;
			widgets_label_picker_label_quick_picker_create_new_label (self, _tmp8_);
		} else {
			WidgetsLabelPickerLabelRow* _tmp9_;
			ObjectsLabel* _tmp10_;
			ObjectsLabel* _tmp11_;
			_tmp9_ = label_row;
			_tmp10_ = widgets_label_picker_label_row_get_label (_tmp9_);
			_tmp11_ = _tmp10_;
			g_signal_emit (self, widgets_label_picker_label_quick_picker_signals[WIDGETS_LABEL_PICKER_LABEL_QUICK_PICKER_LABEL_SELECTED_SIGNAL], 0, _tmp11_);
		}
		_g_object_unref0 (label_row);
	}
	_g_object_unref0 (selected_row);
}

void
widgets_label_picker_label_quick_picker_select_first_item (WidgetsLabelPickerLabelQuickPicker* self)
{
	gint index = 0;
	g_return_if_fail (self != NULL);
	index = 0;
	while (TRUE) {
		GtkListBoxRow* row = NULL;
		GtkListBox* _tmp0_;
		GtkListBoxRow* _tmp1_;
		GtkListBoxRow* _tmp2_;
		GtkListBoxRow* _tmp3_;
		GtkListBoxRow* _tmp4_;
		gint _tmp7_;
		_tmp0_ = self->priv->listbox;
		_tmp1_ = gtk_list_box_get_row_at_index (_tmp0_, index);
		_tmp2_ = _g_object_ref0 (_tmp1_);
		row = _tmp2_;
		_tmp3_ = row;
		if (_tmp3_ == NULL) {
			_g_object_unref0 (row);
			break;
		}
		_tmp4_ = row;
		if (gtk_widget_get_child_visible ((GtkWidget*) _tmp4_)) {
			GtkListBox* _tmp5_;
			GtkListBoxRow* _tmp6_;
			_tmp5_ = self->priv->listbox;
			_tmp6_ = row;
			gtk_list_box_select_row (_tmp5_, _tmp6_);
			widgets_label_picker_label_quick_picker_scroll_to_selected (self);
			_g_object_unref0 (row);
			break;
		}
		_tmp7_ = index;
		index = _tmp7_ + 1;
		_g_object_unref0 (row);
	}
}

void
widgets_label_picker_label_quick_picker_reset_filter (WidgetsLabelPickerLabelQuickPicker* self)
{
	WidgetsLabelPickerLabelRow* _tmp0_;
	GtkListBox* _tmp3_;
	GtkListBox* _tmp4_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->create_label_row;
	if (_tmp0_ != NULL) {
		GtkListBox* _tmp1_;
		WidgetsLabelPickerLabelRow* _tmp2_;
		_tmp1_ = self->priv->listbox;
		_tmp2_ = self->priv->create_label_row;
		gtk_list_box_remove (_tmp1_, (GtkWidget*) _tmp2_);
		_g_object_unref0 (self->priv->create_label_row);
		self->priv->create_label_row = NULL;
	}
	_tmp3_ = self->priv->listbox;
	gtk_list_box_set_filter_func (_tmp3_, NULL, NULL, NULL);
	_tmp4_ = self->priv->listbox;
	gtk_list_box_unselect_all (_tmp4_);
}

static gint
widgets_label_picker_label_quick_picker_count_visible_children (WidgetsLabelPickerLabelQuickPicker* self)
{
	gint count = 0;
	gint index = 0;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	count = 0;
	index = 0;
	while (TRUE) {
		GtkListBoxRow* row = NULL;
		GtkListBox* _tmp0_;
		GtkListBoxRow* _tmp1_;
		GtkListBoxRow* _tmp2_;
		GtkListBoxRow* _tmp3_;
		GtkListBoxRow* _tmp4_;
		gint _tmp6_;
		_tmp0_ = self->priv->listbox;
		_tmp1_ = gtk_list_box_get_row_at_index (_tmp0_, index);
		_tmp2_ = _g_object_ref0 (_tmp1_);
		row = _tmp2_;
		_tmp3_ = row;
		if (_tmp3_ == NULL) {
			_g_object_unref0 (row);
			break;
		}
		_tmp4_ = row;
		if (gtk_widget_get_child_visible ((GtkWidget*) _tmp4_)) {
			gint _tmp5_;
			_tmp5_ = count;
			count = _tmp5_ + 1;
		}
		_tmp6_ = index;
		index = _tmp6_ + 1;
		_g_object_unref0 (row);
	}
	result = count;
	return result;
}

static void
widgets_label_picker_label_quick_picker_scroll_to_selected (WidgetsLabelPickerLabelQuickPicker* self)
{
	GtkListBoxRow* selected_row = NULL;
	GtkListBox* _tmp0_;
	GtkListBoxRow* _tmp1_;
	GtkListBoxRow* _tmp2_;
	GtkListBoxRow* _tmp3_;
	GtkAllocation allocation = {0};
	GtkListBoxRow* _tmp4_;
	GtkAllocation _tmp5_ = {0};
	GtkAdjustment* adjustment = NULL;
	GtkScrolledWindow* _tmp6_;
	GtkAdjustment* _tmp7_;
	GtkAdjustment* _tmp8_;
	GtkAdjustment* _tmp9_;
	gdouble row_start = 0.0;
	GtkAllocation _tmp10_;
	gdouble row_end = 0.0;
	GtkAllocation _tmp11_;
	GtkAllocation _tmp12_;
	gdouble visible_start = 0.0;
	GtkAdjustment* _tmp13_;
	gdouble _tmp14_;
	gdouble _tmp15_;
	gdouble visible_end = 0.0;
	GtkAdjustment* _tmp16_;
	gdouble _tmp17_;
	gdouble _tmp18_;
	GtkAdjustment* _tmp19_;
	gdouble _tmp20_;
	gdouble _tmp21_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->listbox;
	_tmp1_ = gtk_list_box_get_selected_row (_tmp0_);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	selected_row = _tmp2_;
	_tmp3_ = selected_row;
	if (_tmp3_ == NULL) {
		_g_object_unref0 (selected_row);
		return;
	}
	_tmp4_ = selected_row;
	gtk_widget_get_allocation ((GtkWidget*) _tmp4_, &_tmp5_);
	allocation = _tmp5_;
	_tmp6_ = self->priv->listbox_scrolled;
	_tmp7_ = gtk_scrolled_window_get_vadjustment (_tmp6_);
	_tmp8_ = _tmp7_;
	_tmp9_ = _g_object_ref0 (_tmp8_);
	adjustment = _tmp9_;
	_tmp10_ = allocation;
	row_start = (gdouble) _tmp10_.y;
	_tmp11_ = allocation;
	_tmp12_ = allocation;
	row_end = (gdouble) (_tmp11_.y + _tmp12_.height);
	_tmp13_ = adjustment;
	_tmp14_ = gtk_adjustment_get_value (_tmp13_);
	_tmp15_ = _tmp14_;
	visible_start = _tmp15_;
	_tmp16_ = adjustment;
	_tmp17_ = gtk_adjustment_get_value (_tmp16_);
	_tmp18_ = _tmp17_;
	_tmp19_ = adjustment;
	_tmp20_ = gtk_adjustment_get_page_size (_tmp19_);
	_tmp21_ = _tmp20_;
	visible_end = _tmp18_ + _tmp21_;
	if (row_start < visible_start) {
		GtkAdjustment* _tmp22_;
		_tmp22_ = adjustment;
		gtk_adjustment_set_value (_tmp22_, row_start - 10);
	} else {
		if (row_end > visible_end) {
			GtkAdjustment* _tmp23_;
			GtkAdjustment* _tmp24_;
			gdouble _tmp25_;
			gdouble _tmp26_;
			_tmp23_ = adjustment;
			_tmp24_ = adjustment;
			_tmp25_ = gtk_adjustment_get_page_size (_tmp24_);
			_tmp26_ = _tmp25_;
			gtk_adjustment_set_value (_tmp23_, (row_end - _tmp26_) + 10);
		}
	}
	_g_object_unref0 (adjustment);
	_g_object_unref0 (selected_row);
}

ObjectsSource*
widgets_label_picker_label_quick_picker_get_source (WidgetsLabelPickerLabelQuickPicker* self)
{
	ObjectsSource* result;
	ObjectsSource* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_source;
	result = _tmp0_;
	return result;
}

void
widgets_label_picker_label_quick_picker_set_source (WidgetsLabelPickerLabelQuickPicker* self,
                                                    ObjectsSource* value)
{
	ObjectsSource* _tmp0_;
	ObjectsSource* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _g_object_ref0 (value);
	_g_object_unref0 (self->priv->_source);
	self->priv->_source = _tmp0_;
	_tmp1_ = self->priv->_source;
	widgets_label_picker_label_quick_picker_add_labels (self, _tmp1_);
	g_object_notify_by_pspec ((GObject *) self, widgets_label_picker_label_quick_picker_properties[WIDGETS_LABEL_PICKER_LABEL_QUICK_PICKER_SOURCE_PROPERTY]);
}

const gchar*
widgets_label_picker_label_quick_picker_get_filter_text (WidgetsLabelPickerLabelQuickPicker* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_filter_text;
	result = _tmp0_;
	return result;
}

void
widgets_label_picker_label_quick_picker_set_filter_text (WidgetsLabelPickerLabelQuickPicker* self,
                                                         const gchar* value)
{
	gchar* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_strdup (value);
	_g_free0 (self->priv->_filter_text);
	self->priv->_filter_text = _tmp0_;
	widgets_label_picker_label_quick_picker_apply_filter (self);
	g_object_notify_by_pspec ((GObject *) self, widgets_label_picker_label_quick_picker_properties[WIDGETS_LABEL_PICKER_LABEL_QUICK_PICKER_FILTER_TEXT_PROPERTY]);
}

static gint
_widgets_label_picker_label_quick_picker___lambda278_ (WidgetsLabelPickerLabelQuickPicker* self,
                                                       GtkListBoxRow* row1,
                                                       GtkListBoxRow* row2)
{
	ObjectsLabel* item1 = NULL;
	ObjectsLabel* _tmp0_;
	ObjectsLabel* _tmp1_;
	ObjectsLabel* _tmp2_;
	ObjectsLabel* item2 = NULL;
	ObjectsLabel* _tmp3_;
	ObjectsLabel* _tmp4_;
	ObjectsLabel* _tmp5_;
	ObjectsLabel* _tmp6_;
	gint _tmp7_;
	gint _tmp8_;
	ObjectsLabel* _tmp9_;
	gint _tmp10_;
	gint _tmp11_;
	gint result;
	g_return_val_if_fail (row1 != NULL, -1);
	g_return_val_if_fail (row2 != NULL, -1);
	_tmp0_ = widgets_label_picker_label_row_get_label (G_TYPE_CHECK_INSTANCE_CAST (row1, WIDGETS_LABEL_PICKER_TYPE_LABEL_ROW, WidgetsLabelPickerLabelRow));
	_tmp1_ = _tmp0_;
	_tmp2_ = _g_object_ref0 (_tmp1_);
	item1 = _tmp2_;
	_tmp3_ = widgets_label_picker_label_row_get_label (G_TYPE_CHECK_INSTANCE_CAST (row2, WIDGETS_LABEL_PICKER_TYPE_LABEL_ROW, WidgetsLabelPickerLabelRow));
	_tmp4_ = _tmp3_;
	_tmp5_ = _g_object_ref0 (_tmp4_);
	item2 = _tmp5_;
	_tmp6_ = item1;
	_tmp7_ = objects_label_get_item_order (_tmp6_);
	_tmp8_ = _tmp7_;
	_tmp9_ = item2;
	_tmp10_ = objects_label_get_item_order (_tmp9_);
	_tmp11_ = _tmp10_;
	result = _tmp8_ - _tmp11_;
	_g_object_unref0 (item2);
	_g_object_unref0 (item1);
	return result;
}

static gint
__widgets_label_picker_label_quick_picker___lambda278__gtk_list_box_sort_func (GtkListBoxRow* row1,
                                                                               GtkListBoxRow* row2,
                                                                               gpointer self)
{
	gint result;
	result = _widgets_label_picker_label_quick_picker___lambda278_ ((WidgetsLabelPickerLabelQuickPicker*) self, row1, row2);
	return result;
}

static void
_widgets_label_picker_label_quick_picker___lambda279_ (WidgetsLabelPickerLabelQuickPicker* self,
                                                       GtkListBoxRow* row)
{
	WidgetsLabelPickerLabelRow* label_row = NULL;
	WidgetsLabelPickerLabelRow* _tmp0_;
	WidgetsLabelPickerLabelRow* _tmp1_;
	WidgetsLabelPickerLabelRow* _tmp2_;
	g_return_if_fail (row != NULL);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (row, WIDGETS_LABEL_PICKER_TYPE_LABEL_ROW, WidgetsLabelPickerLabelRow));
	label_row = _tmp0_;
	_tmp1_ = label_row;
	_tmp2_ = self->priv->create_label_row;
	if (_tmp1_ == _tmp2_) {
		const gchar* _tmp3_;
		_tmp3_ = self->priv->_filter_text;
		widgets_label_picker_label_quick_picker_create_new_label (self, _tmp3_);
	} else {
		WidgetsLabelPickerLabelRow* _tmp4_;
		ObjectsLabel* _tmp5_;
		ObjectsLabel* _tmp6_;
		_tmp4_ = label_row;
		_tmp5_ = widgets_label_picker_label_row_get_label (_tmp4_);
		_tmp6_ = _tmp5_;
		g_signal_emit (self, widgets_label_picker_label_quick_picker_signals[WIDGETS_LABEL_PICKER_LABEL_QUICK_PICKER_LABEL_SELECTED_SIGNAL], 0, _tmp6_);
	}
	_g_object_unref0 (label_row);
}

static void
__widgets_label_picker_label_quick_picker___lambda279__gtk_list_box_row_activated (GtkListBox* _sender,
                                                                                   GtkListBoxRow* row,
                                                                                   gpointer self)
{
	_widgets_label_picker_label_quick_picker___lambda279_ ((WidgetsLabelPickerLabelQuickPicker*) self, row);
}

static gboolean
_widgets_label_picker_label_quick_picker___lambda280_ (WidgetsLabelPickerLabelQuickPicker* self,
                                                       guint keyval,
                                                       guint keycode,
                                                       GdkModifierType state)
{
	gboolean _tmp0_ = FALSE;
	gboolean result;
	if (keyval == GDK_KEY_Tab) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = keyval == GDK_KEY_ISO_Left_Tab;
	}
	if (_tmp0_) {
		gtk_popover_popdown ((GtkPopover*) self);
		result = TRUE;
		return result;
	}
	result = FALSE;
	return result;
}

static gboolean
__widgets_label_picker_label_quick_picker___lambda280__gtk_event_controller_key_key_pressed (GtkEventControllerKey* _sender,
                                                                                             guint keyval,
                                                                                             guint keycode,
                                                                                             GdkModifierType state,
                                                                                             gpointer self)
{
	gboolean result;
	result = _widgets_label_picker_label_quick_picker___lambda280_ ((WidgetsLabelPickerLabelQuickPicker*) self, keyval, keycode, state);
	return result;
}

static void
_widgets_label_picker_label_quick_picker___lambda281_ (WidgetsLabelPickerLabelQuickPicker* self)
{
	gboolean _tmp0_;
	gboolean _tmp1_;
	_tmp0_ = gtk_widget_get_visible ((GtkWidget*) self);
	_tmp1_ = _tmp0_;
	if (_tmp1_) {
		widgets_label_picker_label_quick_picker_setup_focus_monitoring (self);
		widgets_label_picker_label_quick_picker_reset_filter (self);
	}
}

static void
__widgets_label_picker_label_quick_picker___lambda281__g_object_notify (GObject* _sender,
                                                                        GParamSpec* pspec,
                                                                        gpointer self)
{
	_widgets_label_picker_label_quick_picker___lambda281_ ((WidgetsLabelPickerLabelQuickPicker*) self);
}

static GObject *
widgets_label_picker_label_quick_picker_constructor (GType type,
                                                     guint n_construct_properties,
                                                     GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	WidgetsLabelPickerLabelQuickPicker * self;
	GtkListBox* _tmp0_ = NULL;
	GtkListBox* _tmp1_;
	GtkListBox* _tmp2_;
	GtkListBox* _tmp3_;
	AdwBin* listbox_content = NULL;
	GtkListBox* _tmp4_;
	GtkWidget* _tmp5_;
	AdwBin* _tmp6_ = NULL;
	AdwBin* _tmp7_;
	GtkWidget* _tmp8_;
	GtkScrolledWindow* _tmp9_ = NULL;
	GtkScrolledWindow* _tmp10_;
	GtkEventControllerKey* _tmp11_;
	GtkEventControllerKey* _tmp12_;
	GtkEventControllerKey* _tmp13_;
	GtkEventController* _tmp14_;
	parent_class = G_OBJECT_CLASS (widgets_label_picker_label_quick_picker_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_LABEL_PICKER_TYPE_LABEL_QUICK_PICKER, WidgetsLabelPickerLabelQuickPicker);
	_tmp0_ = (GtkListBox*) gtk_list_box_new ();
	gtk_widget_set_hexpand ((GtkWidget*) _tmp0_, TRUE);
	gtk_widget_set_valign ((GtkWidget*) _tmp0_, GTK_ALIGN_START);
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->listbox);
	self->priv->listbox = _tmp0_;
	_tmp1_ = self->priv->listbox;
	gtk_widget_add_css_class ((GtkWidget*) _tmp1_, "listbox-background");
	_tmp2_ = self->priv->listbox;
	gtk_list_box_set_sort_func (_tmp2_, __widgets_label_picker_label_quick_picker___lambda278__gtk_list_box_sort_func, g_object_ref (self), g_object_unref);
	_tmp3_ = self->priv->listbox;
	g_signal_connect_object (_tmp3_, "row-activated", (GCallback) __widgets_label_picker_label_quick_picker___lambda279__gtk_list_box_row_activated, self, 0);
	_tmp4_ = self->priv->listbox;
	_tmp5_ = _g_object_ref0 ((GtkWidget*) _tmp4_);
	_tmp6_ = (AdwBin*) adw_bin_new ();
	adw_bin_set_child (_tmp6_, _tmp5_);
	_g_object_unref0 (_tmp5_);
	gtk_widget_set_margin_start ((GtkWidget*) _tmp6_, 12);
	gtk_widget_set_margin_end ((GtkWidget*) _tmp6_, 12);
	gtk_widget_set_margin_top ((GtkWidget*) _tmp6_, 12);
	gtk_widget_set_margin_bottom ((GtkWidget*) _tmp6_, 12);
	g_object_ref_sink (_tmp6_);
	listbox_content = _tmp6_;
	_tmp7_ = listbox_content;
	_tmp8_ = _g_object_ref0 ((GtkWidget*) _tmp7_);
	_tmp9_ = (GtkScrolledWindow*) gtk_scrolled_window_new ();
	g_object_set (_tmp9_, "hscrollbar-policy", GTK_POLICY_NEVER, NULL);
	gtk_widget_set_hexpand ((GtkWidget*) _tmp9_, TRUE);
	gtk_widget_set_vexpand ((GtkWidget*) _tmp9_, TRUE);
	gtk_scrolled_window_set_child (_tmp9_, _tmp8_);
	_g_object_unref0 (_tmp8_);
	g_object_set ((GtkWidget*) _tmp9_, "height-request", 175, NULL);
	g_object_ref_sink (_tmp9_);
	_g_object_unref0 (self->priv->listbox_scrolled);
	self->priv->listbox_scrolled = _tmp9_;
	_tmp10_ = self->priv->listbox_scrolled;
	gtk_popover_set_child ((GtkPopover*) self, (GtkWidget*) _tmp10_);
	gtk_widget_add_css_class ((GtkWidget*) self, "popover-contents");
	_tmp11_ = (GtkEventControllerKey*) gtk_event_controller_key_new ();
	_g_object_unref0 (self->priv->key_controller);
	self->priv->key_controller = _tmp11_;
	_tmp12_ = self->priv->key_controller;
	g_signal_connect_object (_tmp12_, "key-pressed", (GCallback) __widgets_label_picker_label_quick_picker___lambda280__gtk_event_controller_key_key_pressed, self, 0);
	_tmp13_ = self->priv->key_controller;
	_tmp14_ = _g_object_ref0 ((GtkEventController*) _tmp13_);
	gtk_widget_add_controller (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget), _tmp14_);
	g_signal_connect_object ((GObject*) self, "notify::visible", (GCallback) __widgets_label_picker_label_quick_picker___lambda281__g_object_notify, self, 0);
	_g_object_unref0 (listbox_content);
	return obj;
}

static void
widgets_label_picker_label_quick_picker_class_init (WidgetsLabelPickerLabelQuickPickerClass * klass,
                                                    gpointer klass_data)
{
	widgets_label_picker_label_quick_picker_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &WidgetsLabelPickerLabelQuickPicker_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_widgets_label_picker_label_quick_picker_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_widgets_label_picker_label_quick_picker_set_property;
	G_OBJECT_CLASS (klass)->constructor = widgets_label_picker_label_quick_picker_constructor;
	G_OBJECT_CLASS (klass)->finalize = widgets_label_picker_label_quick_picker_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), WIDGETS_LABEL_PICKER_LABEL_QUICK_PICKER_SOURCE_PROPERTY, widgets_label_picker_label_quick_picker_properties[WIDGETS_LABEL_PICKER_LABEL_QUICK_PICKER_SOURCE_PROPERTY] = g_param_spec_object ("source", "source", "source", OBJECTS_TYPE_SOURCE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), WIDGETS_LABEL_PICKER_LABEL_QUICK_PICKER_FILTER_TEXT_PROPERTY, widgets_label_picker_label_quick_picker_properties[WIDGETS_LABEL_PICKER_LABEL_QUICK_PICKER_FILTER_TEXT_PROPERTY] = g_param_spec_string ("filter-text", "filter-text", "filter-text", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	widgets_label_picker_label_quick_picker_signals[WIDGETS_LABEL_PICKER_LABEL_QUICK_PICKER_LABEL_SELECTED_SIGNAL] = g_signal_new ("label-selected", WIDGETS_LABEL_PICKER_TYPE_LABEL_QUICK_PICKER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, OBJECTS_TYPE_LABEL);
}

static void
widgets_label_picker_label_quick_picker_instance_init (WidgetsLabelPickerLabelQuickPicker * self,
                                                       gpointer klass)
{
	gchar* _tmp0_;
	GeeHashMap* _tmp1_;
	self->priv = widgets_label_picker_label_quick_picker_get_instance_private (self);
	_tmp0_ = g_strdup ("");
	self->priv->_filter_text = _tmp0_;
	_tmp1_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, WIDGETS_LABEL_PICKER_TYPE_LABEL_ROW, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->labels_widgets_map = _tmp1_;
}

static void
widgets_label_picker_label_quick_picker_finalize (GObject * obj)
{
	WidgetsLabelPickerLabelQuickPicker * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_LABEL_PICKER_TYPE_LABEL_QUICK_PICKER, WidgetsLabelPickerLabelQuickPicker);
	g_debug ("LabelQuickPicker.vala:63: Destroying - Widgets.LabelPicker.LabelQuickP" \
"icker\n");
	_g_object_unref0 (self->priv->listbox);
	_g_object_unref0 (self->priv->listbox_scrolled);
	_g_object_unref0 (self->priv->key_controller);
	_g_object_unref0 (self->priv->create_label_row);
	_g_object_unref0 (self->priv->_source);
	_g_free0 (self->priv->_filter_text);
	_g_object_unref0 (self->labels_widgets_map);
	G_OBJECT_CLASS (widgets_label_picker_label_quick_picker_parent_class)->finalize (obj);
}

static GType
widgets_label_picker_label_quick_picker_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (WidgetsLabelPickerLabelQuickPickerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) widgets_label_picker_label_quick_picker_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (WidgetsLabelPickerLabelQuickPicker), 0, (GInstanceInitFunc) widgets_label_picker_label_quick_picker_instance_init, NULL };
	GType widgets_label_picker_label_quick_picker_type_id;
	widgets_label_picker_label_quick_picker_type_id = g_type_register_static (gtk_popover_get_type (), "WidgetsLabelPickerLabelQuickPicker", &g_define_type_info, 0);
	WidgetsLabelPickerLabelQuickPicker_private_offset = g_type_add_instance_private (widgets_label_picker_label_quick_picker_type_id, sizeof (WidgetsLabelPickerLabelQuickPickerPrivate));
	return widgets_label_picker_label_quick_picker_type_id;
}

GType
widgets_label_picker_label_quick_picker_get_type (void)
{
	static volatile gsize widgets_label_picker_label_quick_picker_type_id__once = 0;
	if (g_once_init_enter (&widgets_label_picker_label_quick_picker_type_id__once)) {
		GType widgets_label_picker_label_quick_picker_type_id;
		widgets_label_picker_label_quick_picker_type_id = widgets_label_picker_label_quick_picker_get_type_once ();
		g_once_init_leave (&widgets_label_picker_label_quick_picker_type_id__once, widgets_label_picker_label_quick_picker_type_id);
	}
	return widgets_label_picker_label_quick_picker_type_id__once;
}

static void
_vala_widgets_label_picker_label_quick_picker_get_property (GObject * object,
                                                            guint property_id,
                                                            GValue * value,
                                                            GParamSpec * pspec)
{
	WidgetsLabelPickerLabelQuickPicker * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, WIDGETS_LABEL_PICKER_TYPE_LABEL_QUICK_PICKER, WidgetsLabelPickerLabelQuickPicker);
	switch (property_id) {
		case WIDGETS_LABEL_PICKER_LABEL_QUICK_PICKER_SOURCE_PROPERTY:
		g_value_set_object (value, widgets_label_picker_label_quick_picker_get_source (self));
		break;
		case WIDGETS_LABEL_PICKER_LABEL_QUICK_PICKER_FILTER_TEXT_PROPERTY:
		g_value_set_string (value, widgets_label_picker_label_quick_picker_get_filter_text (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_widgets_label_picker_label_quick_picker_set_property (GObject * object,
                                                            guint property_id,
                                                            const GValue * value,
                                                            GParamSpec * pspec)
{
	WidgetsLabelPickerLabelQuickPicker * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, WIDGETS_LABEL_PICKER_TYPE_LABEL_QUICK_PICKER, WidgetsLabelPickerLabelQuickPicker);
	switch (property_id) {
		case WIDGETS_LABEL_PICKER_LABEL_QUICK_PICKER_SOURCE_PROPERTY:
		widgets_label_picker_label_quick_picker_set_source (self, g_value_get_object (value));
		break;
		case WIDGETS_LABEL_PICKER_LABEL_QUICK_PICKER_FILTER_TEXT_PROPERTY:
		widgets_label_picker_label_quick_picker_set_filter_text (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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

