/* SectionPicker.c generated by valac 0.56.19, the Vala compiler
 * generated from SectionPicker.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 <glib-object.h>
#include <glib.h>
#include <gee.h>
#include <glib/gi18n-lib.h>
#include <stdlib.h>
#include <string.h>
#include <gdk/gdk.h>
#include <adwaita.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_SECTION_PICKER_SECTION_PICKER_0_PROPERTY,
	WIDGETS_SECTION_PICKER_SECTION_PICKER_NUM_PROPERTIES
};
static GParamSpec* widgets_section_picker_section_picker_properties[WIDGETS_SECTION_PICKER_SECTION_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))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
enum  {
	WIDGETS_SECTION_PICKER_SECTION_PICKER_SELECTED_SIGNAL,
	WIDGETS_SECTION_PICKER_SECTION_PICKER_NUM_SIGNALS
};
static guint widgets_section_picker_section_picker_signals[WIDGETS_SECTION_PICKER_SECTION_PICKER_NUM_SIGNALS] = {0};

struct _WidgetsSectionPickerSectionPickerPrivate {
	GtkSearchEntry* search_entry;
	GtkListBox* listbox;
};

static gint WidgetsSectionPickerSectionPicker_private_offset;
static gpointer widgets_section_picker_section_picker_parent_class = NULL;

static void _g_object_unref0_ (gpointer var);
static inline void _g_list_free__g_object_unref0_ (GList* self);
static void widgets_section_picker_section_picker_row_activated (WidgetsSectionPickerSectionPicker* self,
                                                          GtkListBoxRow* row);
static gboolean widgets_section_picker_section_picker_key_pressed (WidgetsSectionPickerSectionPicker* self,
                                                            guint keyval,
                                                            guint keycode,
                                                            GdkModifierType state);
static GObject * widgets_section_picker_section_picker_constructor (GType type,
                                                             guint n_construct_properties,
                                                             GObjectConstructParam * construct_properties);
static gboolean _widgets_section_picker_section_picker___lambda368_ (WidgetsSectionPickerSectionPicker* self,
                                                              GtkListBoxRow* row);
static gboolean __widgets_section_picker_section_picker___lambda368__gtk_list_box_filter_func (GtkListBoxRow* row,
                                                                                        gpointer self);
static void _widgets_section_picker_section_picker_row_activated_gtk_list_box_row_activated (GtkListBox* _sender,
                                                                                      GtkListBoxRow* row,
                                                                                      gpointer self);
static gboolean _widgets_section_picker_section_picker_key_pressed_gtk_event_controller_key_key_pressed (GtkEventControllerKey* _sender,
                                                                                                  guint keyval,
                                                                                                  guint keycode,
                                                                                                  GdkModifierType state,
                                                                                                  gpointer self);
static void _widgets_section_picker_section_picker___lambda369_ (WidgetsSectionPickerSectionPicker* self);
static void __widgets_section_picker_section_picker___lambda369__gtk_search_entry_search_changed (GtkSearchEntry* _sender,
                                                                                           gpointer self);
static void widgets_section_picker_section_picker_finalize (GObject * obj);
static GType widgets_section_picker_section_picker_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
widgets_section_picker_section_picker_get_instance_private (WidgetsSectionPickerSectionPicker* self)
{
	return G_STRUCT_MEMBER_P (self, WidgetsSectionPickerSectionPicker_private_offset);
}

WidgetsSectionPickerSectionPicker*
widgets_section_picker_section_picker_construct (GType object_type)
{
	WidgetsSectionPickerSectionPicker * self = NULL;
	self = (WidgetsSectionPickerSectionPicker*) g_object_new (object_type, "has-arrow", FALSE, "position", GTK_POS_BOTTOM, "width-request", 275, "height-request", 300, NULL);
	return self;
}

WidgetsSectionPickerSectionPicker*
widgets_section_picker_section_picker_new (void)
{
	return widgets_section_picker_section_picker_construct (WIDGETS_SECTION_PICKER_TYPE_SECTION_PICKER);
}

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

void
widgets_section_picker_section_picker_set_sections (WidgetsSectionPickerSectionPicker* self,
                                                    GeeArrayList* sections)
{
	Util* _tmp0_;
	Util* _tmp1_;
	GtkListBox* _tmp2_;
	GList* _tmp3_;
	GList* _tmp4_;
	ObjectsSection* _section = NULL;
	ObjectsSection* _tmp7_;
	ObjectsSection* _tmp8_;
	GtkListBox* _tmp9_;
	ObjectsSection* _tmp10_;
	WidgetsSectionPickerSectionPickerRow* _tmp11_;
	WidgetsSectionPickerSectionPickerRow* _tmp12_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (sections != NULL);
	_tmp0_ = util_get_default ();
	_tmp1_ = _tmp0_;
	_tmp2_ = self->priv->listbox;
	_tmp3_ = util_get_children (_tmp1_, _tmp2_);
	_tmp4_ = _tmp3_;
	_g_object_unref0 (_tmp1_);
	{
		GList* child_collection = NULL;
		GList* child_it = NULL;
		child_collection = _tmp4_;
		for (child_it = child_collection; child_it != NULL; child_it = child_it->next) {
			GtkWidget* child = NULL;
			child = (GtkWidget*) ((GtkListBoxRow*) child_it->data);
			{
				GtkListBox* _tmp5_;
				GtkWidget* _tmp6_;
				_tmp5_ = self->priv->listbox;
				_tmp6_ = child;
				gtk_list_box_remove (_tmp5_, _tmp6_);
			}
		}
		(child_collection == NULL) ? NULL : (child_collection = (_g_list_free__g_object_unref0_ (child_collection), NULL));
	}
	_tmp7_ = objects_section_new ();
	_section = _tmp7_;
	_tmp8_ = _section;
	objects_base_object_set_name ((ObjectsBaseObject*) _tmp8_, _ ("No Section"));
	_tmp9_ = self->priv->listbox;
	_tmp10_ = _section;
	_tmp11_ = widgets_section_picker_section_picker_row_new (_tmp10_);
	g_object_ref_sink (_tmp11_);
	_tmp12_ = _tmp11_;
	gtk_list_box_append (_tmp9_, (GtkWidget*) _tmp12_);
	_g_object_unref0 (_tmp12_);
	{
		GeeArrayList* _section_list = NULL;
		gint _section_size = 0;
		GeeArrayList* _tmp13_;
		gint _tmp14_;
		gint _tmp15_;
		gint _section_index = 0;
		_section_list = sections;
		_tmp13_ = _section_list;
		_tmp14_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp13_);
		_tmp15_ = _tmp14_;
		_section_size = _tmp15_;
		_section_index = -1;
		while (TRUE) {
			gint _tmp16_;
			gint _tmp17_;
			ObjectsSection* section = NULL;
			GeeArrayList* _tmp18_;
			gpointer _tmp19_;
			GtkListBox* _tmp20_;
			ObjectsSection* _tmp21_;
			WidgetsSectionPickerSectionPickerRow* _tmp22_;
			WidgetsSectionPickerSectionPickerRow* _tmp23_;
			_section_index = _section_index + 1;
			_tmp16_ = _section_index;
			_tmp17_ = _section_size;
			if (!(_tmp16_ < _tmp17_)) {
				break;
			}
			_tmp18_ = _section_list;
			_tmp19_ = gee_abstract_list_get ((GeeAbstractList*) _tmp18_, _section_index);
			section = (ObjectsSection*) _tmp19_;
			_tmp20_ = self->priv->listbox;
			_tmp21_ = section;
			_tmp22_ = widgets_section_picker_section_picker_row_new (_tmp21_);
			g_object_ref_sink (_tmp22_);
			_tmp23_ = _tmp22_;
			gtk_list_box_append (_tmp20_, (GtkWidget*) _tmp23_);
			_g_object_unref0 (_tmp23_);
			_g_object_unref0 (section);
		}
	}
	_g_object_unref0 (_section);
}

void
widgets_section_picker_section_picker_set_section (WidgetsSectionPickerSectionPicker* self,
                                                   const gchar* section_id)
{
	ServicesEventBus* _tmp0_;
	ServicesEventBus* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (section_id != NULL);
	_tmp0_ = services_event_bus_get_default ();
	_tmp1_ = _tmp0_;
	g_signal_emit_by_name (_tmp1_, "section-picker-changed", section_id);
	_g_object_unref0 (_tmp1_);
}

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

static void
widgets_section_picker_section_picker_row_activated (WidgetsSectionPickerSectionPicker* self,
                                                     GtkListBoxRow* row)
{
	ObjectsSection* section = NULL;
	ObjectsSection* _tmp0_;
	ObjectsSection* _tmp1_;
	ObjectsSection* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (row != NULL);
	_tmp0_ = widgets_section_picker_section_picker_row_get_section (G_TYPE_CHECK_INSTANCE_CAST (row, WIDGETS_SECTION_PICKER_TYPE_SECTION_PICKER_ROW, WidgetsSectionPickerSectionPickerRow));
	_tmp1_ = _tmp0_;
	_tmp2_ = _g_object_ref0 (_tmp1_);
	section = _tmp2_;
	g_signal_emit (self, widgets_section_picker_section_picker_signals[WIDGETS_SECTION_PICKER_SECTION_PICKER_SELECTED_SIGNAL], 0, section);
	gtk_popover_popdown ((GtkPopover*) self);
	_g_object_unref0 (section);
}

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

static gboolean
widgets_section_picker_section_picker_key_pressed (WidgetsSectionPickerSectionPicker* self,
                                                   guint keyval,
                                                   guint keycode,
                                                   GdkModifierType state)
{
	gchar* key = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gboolean _tmp2_ = FALSE;
	const gchar* _tmp3_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = gdk_keyval_name (keyval);
	_tmp1_ = string_replace (_tmp0_, "KP_", "");
	key = _tmp1_;
	_tmp3_ = key;
	if (g_strcmp0 (_tmp3_, "Up") == 0) {
		_tmp2_ = TRUE;
	} else {
		const gchar* _tmp4_;
		_tmp4_ = key;
		_tmp2_ = g_strcmp0 (_tmp4_, "Down") == 0;
	}
	if (_tmp2_) {
	} else {
		gboolean _tmp5_ = FALSE;
		gboolean _tmp6_ = FALSE;
		const gchar* _tmp7_;
		_tmp7_ = key;
		if (g_strcmp0 (_tmp7_, "Enter") == 0) {
			_tmp6_ = TRUE;
		} else {
			const gchar* _tmp8_;
			_tmp8_ = key;
			_tmp6_ = g_strcmp0 (_tmp8_, "Return") == 0;
		}
		if (_tmp6_) {
			_tmp5_ = TRUE;
		} else {
			const gchar* _tmp9_;
			_tmp9_ = key;
			_tmp5_ = g_strcmp0 (_tmp9_, "KP_Enter") == 0;
		}
		if (_tmp5_) {
			GtkListBox* _tmp10_;
			GtkListBoxRow* _tmp11_;
			_tmp10_ = self->priv->listbox;
			_tmp11_ = gtk_list_box_get_selected_row (_tmp10_);
			widgets_section_picker_section_picker_row_activated (self, _tmp11_);
		} else {
			GtkSearchEntry* _tmp12_;
			gboolean _tmp13_;
			gboolean _tmp14_;
			_tmp12_ = self->priv->search_entry;
			g_object_get ((GtkWidget*) _tmp12_, "has-focus", &_tmp13_, NULL);
			_tmp14_ = _tmp13_;
			if (!_tmp14_) {
				GtkSearchEntry* _tmp15_;
				GtkSearchEntry* _tmp16_;
				gint _tmp17_;
				gint _tmp18_;
				GtkSearchEntry* _tmp19_;
				const gchar* _tmp20_;
				const gchar* _tmp21_;
				gint _tmp22_;
				gint _tmp23_;
				_tmp15_ = self->priv->search_entry;
				gtk_widget_grab_focus ((GtkWidget*) _tmp15_);
				_tmp16_ = self->priv->search_entry;
				g_object_get ((GtkEditable*) _tmp16_, "cursor-position", &_tmp17_, NULL);
				_tmp18_ = _tmp17_;
				_tmp19_ = self->priv->search_entry;
				_tmp20_ = gtk_editable_get_text ((GtkEditable*) _tmp19_);
				_tmp21_ = _tmp20_;
				_tmp22_ = strlen (_tmp21_);
				_tmp23_ = _tmp22_;
				if (_tmp18_ < _tmp23_) {
					GtkSearchEntry* _tmp24_;
					GtkSearchEntry* _tmp25_;
					const gchar* _tmp26_;
					const gchar* _tmp27_;
					gint _tmp28_;
					gint _tmp29_;
					_tmp24_ = self->priv->search_entry;
					_tmp25_ = self->priv->search_entry;
					_tmp26_ = gtk_editable_get_text ((GtkEditable*) _tmp25_);
					_tmp27_ = _tmp26_;
					_tmp28_ = strlen (_tmp27_);
					_tmp29_ = _tmp28_;
					gtk_editable_set_position ((GtkEditable*) _tmp24_, _tmp29_);
				}
			}
		}
	}
	result = FALSE;
	_g_free0 (key);
	return result;
}

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

static gboolean
_widgets_section_picker_section_picker___lambda368_ (WidgetsSectionPickerSectionPicker* self,
                                                     GtkListBoxRow* row)
{
	ObjectsSection* _tmp0_;
	ObjectsSection* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	GtkSearchEntry* _tmp6_;
	const gchar* _tmp7_;
	const gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gboolean _tmp11_;
	gboolean result;
	g_return_val_if_fail (row != NULL, FALSE);
	_tmp0_ = widgets_section_picker_section_picker_row_get_section (G_TYPE_CHECK_INSTANCE_CAST (row, WIDGETS_SECTION_PICKER_TYPE_SECTION_PICKER_ROW, WidgetsSectionPickerSectionPickerRow));
	_tmp1_ = _tmp0_;
	_tmp2_ = objects_base_object_get_name ((ObjectsBaseObject*) _tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_utf8_strdown (_tmp3_, (gssize) -1);
	_tmp5_ = _tmp4_;
	_tmp6_ = self->priv->search_entry;
	_tmp7_ = gtk_editable_get_text ((GtkEditable*) _tmp6_);
	_tmp8_ = _tmp7_;
	_tmp9_ = g_utf8_strdown (_tmp8_, (gssize) -1);
	_tmp10_ = _tmp9_;
	_tmp11_ = string_contains (_tmp5_, _tmp10_);
	_g_free0 (_tmp10_);
	_g_free0 (_tmp5_);
	result = _tmp11_;
	return result;
}

static gboolean
__widgets_section_picker_section_picker___lambda368__gtk_list_box_filter_func (GtkListBoxRow* row,
                                                                               gpointer self)
{
	gboolean result;
	result = _widgets_section_picker_section_picker___lambda368_ ((WidgetsSectionPickerSectionPicker*) self, row);
	return result;
}

static void
_widgets_section_picker_section_picker_row_activated_gtk_list_box_row_activated (GtkListBox* _sender,
                                                                                 GtkListBoxRow* row,
                                                                                 gpointer self)
{
	widgets_section_picker_section_picker_row_activated ((WidgetsSectionPickerSectionPicker*) self, row);
}

static gboolean
_widgets_section_picker_section_picker_key_pressed_gtk_event_controller_key_key_pressed (GtkEventControllerKey* _sender,
                                                                                         guint keyval,
                                                                                         guint keycode,
                                                                                         GdkModifierType state,
                                                                                         gpointer self)
{
	gboolean result;
	result = widgets_section_picker_section_picker_key_pressed ((WidgetsSectionPickerSectionPicker*) self, keyval, keycode, state);
	return result;
}

static void
_widgets_section_picker_section_picker___lambda369_ (WidgetsSectionPickerSectionPicker* self)
{
	GtkListBox* _tmp0_;
	_tmp0_ = self->priv->listbox;
	gtk_list_box_invalidate_filter (_tmp0_);
}

static void
__widgets_section_picker_section_picker___lambda369__gtk_search_entry_search_changed (GtkSearchEntry* _sender,
                                                                                      gpointer self)
{
	_widgets_section_picker_section_picker___lambda369_ ((WidgetsSectionPickerSectionPicker*) self);
}

static GObject *
widgets_section_picker_section_picker_constructor (GType type,
                                                   guint n_construct_properties,
                                                   GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	WidgetsSectionPickerSectionPicker * self;
	gchar* _tmp0_;
	GtkSearchEntry* _tmp1_ = NULL;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar** _tmp4_;
	GtkListBox* _tmp5_ = NULL;
	GtkListBox* _tmp6_;
	AdwBin* listbox_content = NULL;
	GtkListBox* _tmp7_;
	GtkWidget* _tmp8_;
	AdwBin* _tmp9_ = NULL;
	GtkScrolledWindow* listbox_scrolled = NULL;
	AdwBin* _tmp10_;
	GtkWidget* _tmp11_;
	GtkScrolledWindow* _tmp12_ = NULL;
	AdwToolbarView* toolbar_view = NULL;
	AdwToolbarView* _tmp13_;
	AdwToolbarView* _tmp14_;
	GtkSearchEntry* _tmp15_;
	AdwToolbarView* _tmp16_;
	GtkScrolledWindow* _tmp17_;
	AdwToolbarView* _tmp18_;
	GtkListBox* _tmp19_;
	GtkEventControllerKey* listbox_controller_key = NULL;
	GtkEventControllerKey* _tmp20_;
	GtkListBox* _tmp21_;
	GtkEventControllerKey* _tmp22_;
	GtkEventController* _tmp23_;
	GtkEventControllerKey* _tmp24_;
	GtkSearchEntry* _tmp25_;
	parent_class = G_OBJECT_CLASS (widgets_section_picker_section_picker_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_SECTION_PICKER_TYPE_SECTION_PICKER, WidgetsSectionPickerSectionPicker);
	_tmp0_ = g_strdup (_ ("Search"));
	_tmp1_ = (GtkSearchEntry*) gtk_search_entry_new ();
	g_object_set (_tmp1_, "placeholder-text", _tmp0_, NULL);
	_g_free0 (_tmp0_);
	gtk_widget_set_valign ((GtkWidget*) _tmp1_, GTK_ALIGN_CENTER);
	gtk_widget_set_hexpand ((GtkWidget*) _tmp1_, TRUE);
	gtk_widget_set_margin_top ((GtkWidget*) _tmp1_, 9);
	gtk_widget_set_margin_start ((GtkWidget*) _tmp1_, 9);
	gtk_widget_set_margin_end ((GtkWidget*) _tmp1_, 9);
	gtk_widget_set_margin_bottom ((GtkWidget*) _tmp1_, 9);
	g_object_ref_sink (_tmp1_);
	_g_object_unref0 (self->priv->search_entry);
	self->priv->search_entry = _tmp1_;
	_tmp2_ = g_strdup ("listbox-separator-3");
	_tmp3_ = g_strdup ("listbox-background");
	_tmp4_ = g_new0 (gchar*, 2 + 1);
	_tmp4_[0] = _tmp2_;
	_tmp4_[1] = _tmp3_;
	_tmp5_ = (GtkListBox*) gtk_list_box_new ();
	gtk_widget_set_hexpand ((GtkWidget*) _tmp5_, TRUE);
	gtk_widget_set_valign ((GtkWidget*) _tmp5_, GTK_ALIGN_START);
	gtk_widget_set_css_classes ((GtkWidget*) _tmp5_, _tmp4_);
	_tmp4_ = (_vala_array_free (_tmp4_, 2, (GDestroyNotify) g_free), NULL);
	g_object_ref_sink (_tmp5_);
	_g_object_unref0 (self->priv->listbox);
	self->priv->listbox = _tmp5_;
	_tmp6_ = self->priv->listbox;
	gtk_list_box_set_filter_func (_tmp6_, __widgets_section_picker_section_picker___lambda368__gtk_list_box_filter_func, g_object_ref (self), g_object_unref);
	_tmp7_ = self->priv->listbox;
	_tmp8_ = _g_object_ref0 ((GtkWidget*) _tmp7_);
	_tmp9_ = (AdwBin*) adw_bin_new ();
	gtk_widget_set_margin_start ((GtkWidget*) _tmp9_, 6);
	gtk_widget_set_margin_end ((GtkWidget*) _tmp9_, 6);
	gtk_widget_set_margin_bottom ((GtkWidget*) _tmp9_, 6);
	adw_bin_set_child (_tmp9_, _tmp8_);
	_g_object_unref0 (_tmp8_);
	gtk_widget_set_valign ((GtkWidget*) _tmp9_, GTK_ALIGN_START);
	g_object_ref_sink (_tmp9_);
	listbox_content = _tmp9_;
	_tmp10_ = listbox_content;
	_tmp11_ = _g_object_ref0 ((GtkWidget*) _tmp10_);
	_tmp12_ = (GtkScrolledWindow*) gtk_scrolled_window_new ();
	g_object_set (_tmp12_, "hscrollbar-policy", GTK_POLICY_NEVER, NULL);
	gtk_widget_set_hexpand ((GtkWidget*) _tmp12_, TRUE);
	gtk_widget_set_vexpand ((GtkWidget*) _tmp12_, TRUE);
	gtk_scrolled_window_set_child (_tmp12_, _tmp11_);
	_g_object_unref0 (_tmp11_);
	g_object_ref_sink (_tmp12_);
	listbox_scrolled = _tmp12_;
	_tmp13_ = (AdwToolbarView*) adw_toolbar_view_new ();
	g_object_ref_sink (_tmp13_);
	toolbar_view = _tmp13_;
	_tmp14_ = toolbar_view;
	_tmp15_ = self->priv->search_entry;
	adw_toolbar_view_add_top_bar (_tmp14_, (GtkWidget*) _tmp15_);
	_tmp16_ = toolbar_view;
	_tmp17_ = listbox_scrolled;
	adw_toolbar_view_set_content (_tmp16_, (GtkWidget*) _tmp17_);
	_tmp18_ = toolbar_view;
	gtk_popover_set_child ((GtkPopover*) self, (GtkWidget*) _tmp18_);
	_tmp19_ = self->priv->listbox;
	g_signal_connect_object (_tmp19_, "row-activated", (GCallback) _widgets_section_picker_section_picker_row_activated_gtk_list_box_row_activated, self, 0);
	_tmp20_ = (GtkEventControllerKey*) gtk_event_controller_key_new ();
	listbox_controller_key = _tmp20_;
	_tmp21_ = self->priv->listbox;
	_tmp22_ = listbox_controller_key;
	_tmp23_ = _g_object_ref0 ((GtkEventController*) _tmp22_);
	gtk_widget_add_controller ((GtkWidget*) _tmp21_, _tmp23_);
	_tmp24_ = listbox_controller_key;
	g_signal_connect_object (_tmp24_, "key-pressed", (GCallback) _widgets_section_picker_section_picker_key_pressed_gtk_event_controller_key_key_pressed, self, 0);
	_tmp25_ = self->priv->search_entry;
	g_signal_connect_object (_tmp25_, "search-changed", (GCallback) __widgets_section_picker_section_picker___lambda369__gtk_search_entry_search_changed, self, 0);
	_g_object_unref0 (listbox_controller_key);
	_g_object_unref0 (toolbar_view);
	_g_object_unref0 (listbox_scrolled);
	_g_object_unref0 (listbox_content);
	return obj;
}

static void
widgets_section_picker_section_picker_class_init (WidgetsSectionPickerSectionPickerClass * klass,
                                                  gpointer klass_data)
{
	widgets_section_picker_section_picker_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &WidgetsSectionPickerSectionPicker_private_offset);
	G_OBJECT_CLASS (klass)->constructor = widgets_section_picker_section_picker_constructor;
	G_OBJECT_CLASS (klass)->finalize = widgets_section_picker_section_picker_finalize;
	widgets_section_picker_section_picker_signals[WIDGETS_SECTION_PICKER_SECTION_PICKER_SELECTED_SIGNAL] = g_signal_new ("selected", WIDGETS_SECTION_PICKER_TYPE_SECTION_PICKER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, OBJECTS_TYPE_SECTION);
}

static void
widgets_section_picker_section_picker_instance_init (WidgetsSectionPickerSectionPicker * self,
                                                     gpointer klass)
{
	self->priv = widgets_section_picker_section_picker_get_instance_private (self);
}

static void
widgets_section_picker_section_picker_finalize (GObject * obj)
{
	WidgetsSectionPickerSectionPicker * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_SECTION_PICKER_TYPE_SECTION_PICKER, WidgetsSectionPickerSectionPicker);
	_g_object_unref0 (self->priv->search_entry);
	_g_object_unref0 (self->priv->listbox);
	G_OBJECT_CLASS (widgets_section_picker_section_picker_parent_class)->finalize (obj);
}

static GType
widgets_section_picker_section_picker_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (WidgetsSectionPickerSectionPickerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) widgets_section_picker_section_picker_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (WidgetsSectionPickerSectionPicker), 0, (GInstanceInitFunc) widgets_section_picker_section_picker_instance_init, NULL };
	GType widgets_section_picker_section_picker_type_id;
	widgets_section_picker_section_picker_type_id = g_type_register_static (gtk_popover_get_type (), "WidgetsSectionPickerSectionPicker", &g_define_type_info, 0);
	WidgetsSectionPickerSectionPicker_private_offset = g_type_add_instance_private (widgets_section_picker_section_picker_type_id, sizeof (WidgetsSectionPickerSectionPickerPrivate));
	return widgets_section_picker_section_picker_type_id;
}

GType
widgets_section_picker_section_picker_get_type (void)
{
	static volatile gsize widgets_section_picker_section_picker_type_id__once = 0;
	if (g_once_init_enter (&widgets_section_picker_section_picker_type_id__once)) {
		GType widgets_section_picker_section_picker_type_id;
		widgets_section_picker_section_picker_type_id = widgets_section_picker_section_picker_get_type_once ();
		g_once_init_leave (&widgets_section_picker_section_picker_type_id__once, widgets_section_picker_section_picker_type_id);
	}
	return widgets_section_picker_section_picker_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;
}

