/* SearchBar.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from SearchBar.vala, do not modify */

/*
 * SPDX-License-Identifier: LGPL-3.0-or-later
 * SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io)
 */

#include <granite-7.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define MUSIC_TYPE_SEARCH_BAR (music_search_bar_get_type ())
#define MUSIC_SEARCH_BAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MUSIC_TYPE_SEARCH_BAR, MusicSearchBar))
#define MUSIC_SEARCH_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MUSIC_TYPE_SEARCH_BAR, MusicSearchBarClass))
#define MUSIC_IS_SEARCH_BAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MUSIC_TYPE_SEARCH_BAR))
#define MUSIC_IS_SEARCH_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MUSIC_TYPE_SEARCH_BAR))
#define MUSIC_SEARCH_BAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MUSIC_TYPE_SEARCH_BAR, MusicSearchBarClass))

typedef struct _MusicSearchBar MusicSearchBar;
typedef struct _MusicSearchBarClass MusicSearchBarClass;
typedef struct _MusicSearchBarPrivate MusicSearchBarPrivate;
enum  {
	MUSIC_SEARCH_BAR_0_PROPERTY,
	MUSIC_SEARCH_BAR_LIST_MODEL_PROPERTY,
	MUSIC_SEARCH_BAR_SEARCH_ENTRY_PROPERTY,
	MUSIC_SEARCH_BAR_FILTER_MODEL_PROPERTY,
	MUSIC_SEARCH_BAR_NUM_PROPERTIES
};
static GParamSpec* music_search_bar_properties[MUSIC_SEARCH_BAR_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define MUSIC_TYPE_AUDIO_OBJECT (music_audio_object_get_type ())
#define MUSIC_AUDIO_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MUSIC_TYPE_AUDIO_OBJECT, MusicAudioObject))
#define MUSIC_AUDIO_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MUSIC_TYPE_AUDIO_OBJECT, MusicAudioObjectClass))
#define MUSIC_IS_AUDIO_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MUSIC_TYPE_AUDIO_OBJECT))
#define MUSIC_IS_AUDIO_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MUSIC_TYPE_AUDIO_OBJECT))
#define MUSIC_AUDIO_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MUSIC_TYPE_AUDIO_OBJECT, MusicAudioObjectClass))

typedef struct _MusicAudioObject MusicAudioObject;
typedef struct _MusicAudioObjectClass MusicAudioObjectClass;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _gtk_expression_unref0(var) ((var == NULL) ? NULL : (var = (gtk_expression_unref (var), NULL)))
enum  {
	MUSIC_SEARCH_BAR_ACTIVATED_SIGNAL,
	MUSIC_SEARCH_BAR_NUM_SIGNALS
};
static guint music_search_bar_signals[MUSIC_SEARCH_BAR_NUM_SIGNALS] = {0};

struct _MusicSearchBar {
	GraniteBin parent_instance;
	MusicSearchBarPrivate * priv;
};

struct _MusicSearchBarClass {
	GraniteBinClass parent_class;
};

struct _MusicSearchBarPrivate {
	GListModel* _list_model;
	GtkSearchEntry* _search_entry;
	GtkFilterListModel* _filter_model;
	GtkStringFilter* filter;
};

static gint MusicSearchBar_private_offset;
static gpointer music_search_bar_parent_class = NULL;

VALA_EXTERN GType music_search_bar_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MusicSearchBar, g_object_unref)
VALA_EXTERN MusicSearchBar* music_search_bar_new (GListModel* list_model);
VALA_EXTERN MusicSearchBar* music_search_bar_construct (GType object_type,
                                            GListModel* list_model);
static void music_search_bar_on_search_changed (MusicSearchBar* self);
VALA_EXTERN GtkSearchEntry* music_search_bar_get_search_entry (MusicSearchBar* self);
VALA_EXTERN void music_search_bar_start_search (MusicSearchBar* self);
VALA_EXTERN GListModel* music_search_bar_get_list_model (MusicSearchBar* self);
static void music_search_bar_set_list_model (MusicSearchBar* self,
                                      GListModel* value);
static void music_search_bar_set_search_entry (MusicSearchBar* self,
                                        GtkSearchEntry* value);
VALA_EXTERN GtkFilterListModel* music_search_bar_get_filter_model (MusicSearchBar* self);
static void music_search_bar_set_filter_model (MusicSearchBar* self,
                                        GtkFilterListModel* value);
static GObject * music_search_bar_constructor (GType type,
                                        guint n_construct_properties,
                                        GObjectConstructParam * construct_properties);
VALA_EXTERN GType music_audio_object_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MusicAudioObject, g_object_unref)
static void _music_search_bar_on_search_changed_gtk_search_entry_search_changed (GtkSearchEntry* _sender,
                                                                          gpointer self);
static void _music_search_bar___lambda9_ (MusicSearchBar* self);
static void __music_search_bar___lambda9__gtk_search_entry_activate (GtkSearchEntry* _sender,
                                                              gpointer self);
static void music_search_bar_finalize (GObject * obj);
static GType music_search_bar_get_type_once (void);
static void _vala_music_search_bar_get_property (GObject * object,
                                          guint property_id,
                                          GValue * value,
                                          GParamSpec * pspec);
static void _vala_music_search_bar_set_property (GObject * object,
                                          guint property_id,
                                          const GValue * value,
                                          GParamSpec * pspec);

static inline gpointer
music_search_bar_get_instance_private (MusicSearchBar* self)
{
	return G_STRUCT_MEMBER_P (self, MusicSearchBar_private_offset);
}

MusicSearchBar*
music_search_bar_construct (GType object_type,
                            GListModel* list_model)
{
	MusicSearchBar * self = NULL;
	g_return_val_if_fail (list_model != NULL, NULL);
	self = (MusicSearchBar*) g_object_new (object_type, "list-model", list_model, NULL);
	return self;
}

MusicSearchBar*
music_search_bar_new (GListModel* list_model)
{
	return music_search_bar_construct (MUSIC_TYPE_SEARCH_BAR, list_model);
}

static void
music_search_bar_on_search_changed (MusicSearchBar* self)
{
	GtkStringFilter* _tmp0_;
	GtkSearchEntry* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->filter;
	_tmp1_ = self->priv->_search_entry;
	_tmp2_ = gtk_editable_get_text ((GtkEditable*) _tmp1_);
	_tmp3_ = _tmp2_;
	gtk_string_filter_set_search (_tmp0_, _tmp3_);
}

void
music_search_bar_start_search (MusicSearchBar* self)
{
	GtkSearchEntry* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_search_entry;
	gtk_widget_grab_focus ((GtkWidget*) _tmp0_);
}

GListModel*
music_search_bar_get_list_model (MusicSearchBar* self)
{
	GListModel* result;
	GListModel* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_list_model;
	result = _tmp0_;
	return result;
}

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

static void
music_search_bar_set_list_model (MusicSearchBar* self,
                                 GListModel* value)
{
	GListModel* old_value;
	g_return_if_fail (self != NULL);
	old_value = music_search_bar_get_list_model (self);
	if (old_value != value) {
		GListModel* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_list_model);
		self->priv->_list_model = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, music_search_bar_properties[MUSIC_SEARCH_BAR_LIST_MODEL_PROPERTY]);
	}
}

GtkSearchEntry*
music_search_bar_get_search_entry (MusicSearchBar* self)
{
	GtkSearchEntry* result;
	GtkSearchEntry* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_search_entry;
	result = _tmp0_;
	return result;
}

static void
music_search_bar_set_search_entry (MusicSearchBar* self,
                                   GtkSearchEntry* value)
{
	GtkSearchEntry* old_value;
	g_return_if_fail (self != NULL);
	old_value = music_search_bar_get_search_entry (self);
	if (old_value != value) {
		GtkSearchEntry* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_search_entry);
		self->priv->_search_entry = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, music_search_bar_properties[MUSIC_SEARCH_BAR_SEARCH_ENTRY_PROPERTY]);
	}
}

GtkFilterListModel*
music_search_bar_get_filter_model (MusicSearchBar* self)
{
	GtkFilterListModel* result;
	GtkFilterListModel* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_filter_model;
	result = _tmp0_;
	return result;
}

static void
music_search_bar_set_filter_model (MusicSearchBar* self,
                                   GtkFilterListModel* value)
{
	GtkFilterListModel* old_value;
	g_return_if_fail (self != NULL);
	old_value = music_search_bar_get_filter_model (self);
	if (old_value != value) {
		GtkFilterListModel* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_filter_model);
		self->priv->_filter_model = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, music_search_bar_properties[MUSIC_SEARCH_BAR_FILTER_MODEL_PROPERTY]);
	}
}

static gpointer
_gtk_expression_ref0 (gpointer self)
{
	return self ? gtk_expression_ref (self) : NULL;
}

static void
_music_search_bar_on_search_changed_gtk_search_entry_search_changed (GtkSearchEntry* _sender,
                                                                     gpointer self)
{
	music_search_bar_on_search_changed ((MusicSearchBar*) self);
}

static void
_music_search_bar___lambda9_ (MusicSearchBar* self)
{
	g_signal_emit (self, music_search_bar_signals[MUSIC_SEARCH_BAR_ACTIVATED_SIGNAL], 0);
}

static void
__music_search_bar___lambda9__gtk_search_entry_activate (GtkSearchEntry* _sender,
                                                         gpointer self)
{
	_music_search_bar___lambda9_ ((MusicSearchBar*) self);
}

static GObject *
music_search_bar_constructor (GType type,
                              guint n_construct_properties,
                              GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	MusicSearchBar * self;
	GtkPropertyExpression* expression = NULL;
	GtkPropertyExpression* _tmp0_;
	GtkPropertyExpression* _tmp1_;
	GtkExpression* _tmp2_;
	GtkStringFilter* _tmp3_ = NULL;
	GListModel* _tmp4_;
	GListModel* _tmp5_;
	GtkStringFilter* _tmp6_;
	GtkFilter* _tmp7_;
	GtkFilterListModel* _tmp8_;
	GtkFilterListModel* _tmp9_;
	gchar* _tmp10_;
	GtkSearchEntry* _tmp11_ = NULL;
	GtkSearchEntry* _tmp12_;
	GtkSearchEntry* _tmp13_;
	GtkSearchEntry* _tmp14_;
	GtkSearchEntry* _tmp15_;
	parent_class = G_OBJECT_CLASS (music_search_bar_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, MUSIC_TYPE_SEARCH_BAR, MusicSearchBar);
	_tmp0_ = (GtkPropertyExpression*) gtk_property_expression_new (MUSIC_TYPE_AUDIO_OBJECT, NULL, "title");
	expression = _tmp0_;
	_tmp1_ = expression;
	_tmp2_ = _gtk_expression_ref0 ((GtkExpression*) _tmp1_);
	_tmp3_ = gtk_string_filter_new (_tmp2_);
	gtk_string_filter_set_ignore_case (_tmp3_, TRUE);
	gtk_string_filter_set_match_mode (_tmp3_, GTK_STRING_FILTER_MATCH_MODE_SUBSTRING);
	_g_object_unref0 (self->priv->filter);
	self->priv->filter = _tmp3_;
	_tmp4_ = self->priv->_list_model;
	_tmp5_ = _g_object_ref0 (_tmp4_);
	_tmp6_ = self->priv->filter;
	_tmp7_ = _g_object_ref0 ((GtkFilter*) _tmp6_);
	_tmp8_ = gtk_filter_list_model_new (_tmp5_, _tmp7_);
	_tmp9_ = _tmp8_;
	music_search_bar_set_filter_model (self, _tmp9_);
	_g_object_unref0 (_tmp9_);
	_tmp10_ = g_strdup (_ ("Search titles in playlist"));
	_tmp11_ = (GtkSearchEntry*) gtk_search_entry_new ();
	g_object_set (_tmp11_, "placeholder-text", _tmp10_, NULL);
	_g_free0 (_tmp10_);
	g_object_ref_sink (_tmp11_);
	_tmp12_ = _tmp11_;
	music_search_bar_set_search_entry (self, _tmp12_);
	_g_object_unref0 (_tmp12_);
	_tmp13_ = self->priv->_search_entry;
	granite_bin_set_child ((GraniteBin*) self, (GtkWidget*) _tmp13_);
	_tmp14_ = self->priv->_search_entry;
	g_signal_connect_object (_tmp14_, "search-changed", (GCallback) _music_search_bar_on_search_changed_gtk_search_entry_search_changed, self, 0);
	_tmp15_ = self->priv->_search_entry;
	g_signal_connect_object (_tmp15_, "activate", (GCallback) __music_search_bar___lambda9__gtk_search_entry_activate, self, 0);
	_gtk_expression_unref0 (expression);
	return obj;
}

static void
music_search_bar_class_init (MusicSearchBarClass * klass,
                             gpointer klass_data)
{
	music_search_bar_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &MusicSearchBar_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_music_search_bar_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_music_search_bar_set_property;
	G_OBJECT_CLASS (klass)->constructor = music_search_bar_constructor;
	G_OBJECT_CLASS (klass)->finalize = music_search_bar_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), MUSIC_SEARCH_BAR_LIST_MODEL_PROPERTY, music_search_bar_properties[MUSIC_SEARCH_BAR_LIST_MODEL_PROPERTY] = g_param_spec_object ("list-model", "list-model", "list-model", g_list_model_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), MUSIC_SEARCH_BAR_SEARCH_ENTRY_PROPERTY, music_search_bar_properties[MUSIC_SEARCH_BAR_SEARCH_ENTRY_PROPERTY] = g_param_spec_object ("search-entry", "search-entry", "search-entry", gtk_search_entry_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/**
	     * The new model with the search applied. Make sure to use this one in further UI
	     * instead of the old given model.
	     */
	g_object_class_install_property (G_OBJECT_CLASS (klass), MUSIC_SEARCH_BAR_FILTER_MODEL_PROPERTY, music_search_bar_properties[MUSIC_SEARCH_BAR_FILTER_MODEL_PROPERTY] = g_param_spec_object ("filter-model", "filter-model", "filter-model", gtk_filter_list_model_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	music_search_bar_signals[MUSIC_SEARCH_BAR_ACTIVATED_SIGNAL] = g_signal_new ("activated", MUSIC_TYPE_SEARCH_BAR, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
music_search_bar_instance_init (MusicSearchBar * self,
                                gpointer klass)
{
	self->priv = music_search_bar_get_instance_private (self);
}

static void
music_search_bar_finalize (GObject * obj)
{
	MusicSearchBar * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, MUSIC_TYPE_SEARCH_BAR, MusicSearchBar);
	_g_object_unref0 (self->priv->_list_model);
	_g_object_unref0 (self->priv->_search_entry);
	_g_object_unref0 (self->priv->_filter_model);
	_g_object_unref0 (self->priv->filter);
	G_OBJECT_CLASS (music_search_bar_parent_class)->finalize (obj);
}

static GType
music_search_bar_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (MusicSearchBarClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) music_search_bar_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MusicSearchBar), 0, (GInstanceInitFunc) music_search_bar_instance_init, NULL };
	GType music_search_bar_type_id;
	music_search_bar_type_id = g_type_register_static (GRANITE_TYPE_BIN, "MusicSearchBar", &g_define_type_info, 0);
	MusicSearchBar_private_offset = g_type_add_instance_private (music_search_bar_type_id, sizeof (MusicSearchBarPrivate));
	return music_search_bar_type_id;
}

GType
music_search_bar_get_type (void)
{
	static volatile gsize music_search_bar_type_id__once = 0;
	if (g_once_init_enter (&music_search_bar_type_id__once)) {
		GType music_search_bar_type_id;
		music_search_bar_type_id = music_search_bar_get_type_once ();
		g_once_init_leave (&music_search_bar_type_id__once, music_search_bar_type_id);
	}
	return music_search_bar_type_id__once;
}

static void
_vala_music_search_bar_get_property (GObject * object,
                                     guint property_id,
                                     GValue * value,
                                     GParamSpec * pspec)
{
	MusicSearchBar * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, MUSIC_TYPE_SEARCH_BAR, MusicSearchBar);
	switch (property_id) {
		case MUSIC_SEARCH_BAR_LIST_MODEL_PROPERTY:
		g_value_set_object (value, music_search_bar_get_list_model (self));
		break;
		case MUSIC_SEARCH_BAR_SEARCH_ENTRY_PROPERTY:
		g_value_set_object (value, music_search_bar_get_search_entry (self));
		break;
		case MUSIC_SEARCH_BAR_FILTER_MODEL_PROPERTY:
		g_value_set_object (value, music_search_bar_get_filter_model (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_music_search_bar_set_property (GObject * object,
                                     guint property_id,
                                     const GValue * value,
                                     GParamSpec * pspec)
{
	MusicSearchBar * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, MUSIC_TYPE_SEARCH_BAR, MusicSearchBar);
	switch (property_id) {
		case MUSIC_SEARCH_BAR_LIST_MODEL_PROPERTY:
		music_search_bar_set_list_model (self, g_value_get_object (value));
		break;
		case MUSIC_SEARCH_BAR_SEARCH_ENTRY_PROPERTY:
		music_search_bar_set_search_entry (self, g_value_get_object (value));
		break;
		case MUSIC_SEARCH_BAR_FILTER_MODEL_PROPERTY:
		music_search_bar_set_filter_model (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

