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

/* This file is part of GNOME Games. License: GPL-3.0+.*/

#include <gtk/gtk.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <handy.h>
#include <gdk/gdk.h>
#include "gnome-games.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

#define GAMES_TYPE_SEARCH_BAR (games_search_bar_get_type ())
#define GAMES_SEARCH_BAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_SEARCH_BAR, GamesSearchBar))
#define GAMES_SEARCH_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_SEARCH_BAR, GamesSearchBarClass))
#define GAMES_IS_SEARCH_BAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_SEARCH_BAR))
#define GAMES_IS_SEARCH_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_SEARCH_BAR))
#define GAMES_SEARCH_BAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_SEARCH_BAR, GamesSearchBarClass))

typedef struct _GamesSearchBar GamesSearchBar;
typedef struct _GamesSearchBarClass GamesSearchBarClass;
typedef struct _GamesSearchBarPrivate GamesSearchBarPrivate;
enum  {
	GAMES_SEARCH_BAR_0_PROPERTY,
	GAMES_SEARCH_BAR_TEXT_PROPERTY,
	GAMES_SEARCH_BAR_SEARCH_MODE_ENABLED_PROPERTY,
	GAMES_SEARCH_BAR_NUM_PROPERTIES
};
static GParamSpec* games_search_bar_properties[GAMES_SEARCH_BAR_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))

struct _GamesSearchBar {
	GtkBin parent_instance;
	GamesSearchBarPrivate * priv;
};

struct _GamesSearchBarClass {
	GtkBinClass parent_class;
};

struct _GamesSearchBarPrivate {
	gchar* _text;
	gboolean _search_mode_enabled;
	HdySearchBar* search_bar;
	GtkSearchEntry* entry;
};

static gint GamesSearchBar_private_offset;
static gpointer games_search_bar_parent_class = NULL;

VALA_EXTERN GType games_search_bar_get_type (void) G_GNUC_CONST ;
static void games_search_bar_on_search_changed (GamesSearchBar* self);
static void games_search_bar_set_text (GamesSearchBar* self,
                                const gchar* value);
static void _games_search_bar_on_search_changed_gtk_search_entry_search_changed (GtkSearchEntry* _sender,
                                                                          gpointer self);
static void games_search_bar_on_search_activated (GamesSearchBar* self);
static void _games_search_bar_on_search_activated_gtk_entry_activate (GtkEntry* _sender,
                                                               gpointer self);
VALA_EXTERN void games_search_bar_focus_entry (GamesSearchBar* self);
VALA_EXTERN void games_search_bar_run_search (GamesSearchBar* self,
                                  const gchar* query);
VALA_EXTERN gboolean games_search_bar_handle_event (GamesSearchBar* self,
                                        GdkEvent* event);
VALA_EXTERN GamesSearchBar* games_search_bar_new (void);
VALA_EXTERN GamesSearchBar* games_search_bar_construct (GType object_type);
VALA_EXTERN const gchar* games_search_bar_get_text (GamesSearchBar* self);
VALA_EXTERN gboolean games_search_bar_get_search_mode_enabled (GamesSearchBar* self);
VALA_EXTERN void games_search_bar_set_search_mode_enabled (GamesSearchBar* self,
                                               gboolean value);
static GObject * games_search_bar_constructor (GType type,
                                        guint n_construct_properties,
                                        GObjectConstructParam * construct_properties);
static void games_search_bar_finalize (GObject * obj);
static GType games_search_bar_get_type_once (void);
static void _vala_games_search_bar_get_property (GObject * object,
                                          guint property_id,
                                          GValue * value,
                                          GParamSpec * pspec);
static void _vala_games_search_bar_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
games_search_bar_get_instance_private (GamesSearchBar* self)
{
	return G_STRUCT_MEMBER_P (self, GamesSearchBar_private_offset);
}

static void
games_search_bar_on_search_changed (GamesSearchBar* self)
{
	GtkSearchEntry* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->entry;
	_tmp1_ = gtk_entry_get_text ((GtkEntry*) _tmp0_);
	_tmp2_ = _tmp1_;
	games_search_bar_set_text (self, _tmp2_);
}

static void
_games_search_bar_on_search_changed_gtk_search_entry_search_changed (GtkSearchEntry* _sender,
                                                                     gpointer self)
{
	games_search_bar_on_search_changed ((GamesSearchBar*) self);
}

static void
games_search_bar_on_search_activated (GamesSearchBar* self)
{
	GtkSearchEntry* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->entry;
	_tmp1_ = gtk_entry_get_text ((GtkEntry*) _tmp0_);
	_tmp2_ = _tmp1_;
	games_search_bar_set_text (self, _tmp2_);
}

static void
_games_search_bar_on_search_activated_gtk_entry_activate (GtkEntry* _sender,
                                                          gpointer self)
{
	games_search_bar_on_search_activated ((GamesSearchBar*) self);
}

void
games_search_bar_focus_entry (GamesSearchBar* self)
{
	GtkSearchEntry* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->entry;
	gtk_entry_grab_focus_without_selecting ((GtkEntry*) _tmp0_);
}

void
games_search_bar_run_search (GamesSearchBar* self,
                             const gchar* query)
{
	GtkSearchEntry* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (query != NULL);
	_tmp0_ = self->priv->entry;
	gtk_entry_set_text ((GtkEntry*) _tmp0_, query);
}

gboolean
games_search_bar_handle_event (GamesSearchBar* self,
                               GdkEvent* event)
{
	HdySearchBar* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (event != NULL, FALSE);
	_tmp0_ = self->priv->search_bar;
	result = hdy_search_bar_handle_event (_tmp0_, event);
	return result;
}

GamesSearchBar*
games_search_bar_construct (GType object_type)
{
	GamesSearchBar * self = NULL;
	self = (GamesSearchBar*) g_object_new (object_type, NULL);
	return self;
}

GamesSearchBar*
games_search_bar_new (void)
{
	return games_search_bar_construct (GAMES_TYPE_SEARCH_BAR);
}

const gchar*
games_search_bar_get_text (GamesSearchBar* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_text;
	result = _tmp0_;
	return result;
}

static void
games_search_bar_set_text (GamesSearchBar* self,
                           const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = games_search_bar_get_text (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_text);
		self->priv->_text = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, games_search_bar_properties[GAMES_SEARCH_BAR_TEXT_PROPERTY]);
	}
}

gboolean
games_search_bar_get_search_mode_enabled (GamesSearchBar* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_search_mode_enabled;
	return result;
}

void
games_search_bar_set_search_mode_enabled (GamesSearchBar* self,
                                          gboolean value)
{
	gboolean old_value;
	g_return_if_fail (self != NULL);
	old_value = games_search_bar_get_search_mode_enabled (self);
	if (old_value != value) {
		self->priv->_search_mode_enabled = value;
		g_object_notify_by_pspec ((GObject *) self, games_search_bar_properties[GAMES_SEARCH_BAR_SEARCH_MODE_ENABLED_PROPERTY]);
	}
}

static GObject *
games_search_bar_constructor (GType type,
                              guint n_construct_properties,
                              GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GamesSearchBar * self;
	HdySearchBar* _tmp0_;
	GtkSearchEntry* _tmp1_;
	parent_class = G_OBJECT_CLASS (games_search_bar_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_SEARCH_BAR, GamesSearchBar);
	_tmp0_ = self->priv->search_bar;
	_tmp1_ = self->priv->entry;
	hdy_search_bar_connect_entry (_tmp0_, (GtkEntry*) _tmp1_);
	return obj;
}

static void
games_search_bar_class_init (GamesSearchBarClass * klass,
                             gpointer klass_data)
{
	games_search_bar_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GamesSearchBar_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_games_search_bar_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_games_search_bar_set_property;
	G_OBJECT_CLASS (klass)->constructor = games_search_bar_constructor;
	G_OBJECT_CLASS (klass)->finalize = games_search_bar_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GAMES_SEARCH_BAR_TEXT_PROPERTY, games_search_bar_properties[GAMES_SEARCH_BAR_TEXT_PROPERTY] = g_param_spec_string ("text", "text", "text", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GAMES_SEARCH_BAR_SEARCH_MODE_ENABLED_PROPERTY, games_search_bar_properties[GAMES_SEARCH_BAR_SEARCH_MODE_ENABLED_PROPERTY] = g_param_spec_boolean ("search-mode-enabled", "search-mode-enabled", "search-mode-enabled", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/Games/ui/search-bar.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "search_bar", FALSE, GamesSearchBar_private_offset + G_STRUCT_OFFSET (GamesSearchBarPrivate, search_bar));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "entry", FALSE, GamesSearchBar_private_offset + G_STRUCT_OFFSET (GamesSearchBarPrivate, entry));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_search_changed", G_CALLBACK(_games_search_bar_on_search_changed_gtk_search_entry_search_changed));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_search_activated", G_CALLBACK(_games_search_bar_on_search_activated_gtk_entry_activate));
}

static void
games_search_bar_instance_init (GamesSearchBar * self,
                                gpointer klass)
{
	self->priv = games_search_bar_get_instance_private (self);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
games_search_bar_finalize (GObject * obj)
{
	GamesSearchBar * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_SEARCH_BAR, GamesSearchBar);
	_g_free0 (self->priv->_text);
	G_OBJECT_CLASS (games_search_bar_parent_class)->finalize (obj);
}

static GType
games_search_bar_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GamesSearchBarClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_search_bar_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesSearchBar), 0, (GInstanceInitFunc) games_search_bar_instance_init, NULL };
	GType games_search_bar_type_id;
	games_search_bar_type_id = g_type_register_static (gtk_bin_get_type (), "GamesSearchBar", &g_define_type_info, 0);
	GamesSearchBar_private_offset = g_type_add_instance_private (games_search_bar_type_id, sizeof (GamesSearchBarPrivate));
	return games_search_bar_type_id;
}

GType
games_search_bar_get_type (void)
{
	static volatile gsize games_search_bar_type_id__once = 0;
	if (g_once_init_enter (&games_search_bar_type_id__once)) {
		GType games_search_bar_type_id;
		games_search_bar_type_id = games_search_bar_get_type_once ();
		g_once_init_leave (&games_search_bar_type_id__once, games_search_bar_type_id);
	}
	return games_search_bar_type_id__once;
}

static void
_vala_games_search_bar_get_property (GObject * object,
                                     guint property_id,
                                     GValue * value,
                                     GParamSpec * pspec)
{
	GamesSearchBar * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GAMES_TYPE_SEARCH_BAR, GamesSearchBar);
	switch (property_id) {
		case GAMES_SEARCH_BAR_TEXT_PROPERTY:
		g_value_set_string (value, games_search_bar_get_text (self));
		break;
		case GAMES_SEARCH_BAR_SEARCH_MODE_ENABLED_PROPERTY:
		g_value_set_boolean (value, games_search_bar_get_search_mode_enabled (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_games_search_bar_set_property (GObject * object,
                                     guint property_id,
                                     const GValue * value,
                                     GParamSpec * pspec)
{
	GamesSearchBar * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GAMES_TYPE_SEARCH_BAR, GamesSearchBar);
	switch (property_id) {
		case GAMES_SEARCH_BAR_TEXT_PROPERTY:
		games_search_bar_set_text (self, g_value_get_string (value));
		break;
		case GAMES_SEARCH_BAR_SEARCH_MODE_ENABLED_PROPERTY:
		games_search_bar_set_search_mode_enabled (self, g_value_get_boolean (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;
}

