/* preferences-page-platforms-retro-row.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from preferences-page-platforms-retro-row.vala, do not modify */

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

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

#define GAMES_TYPE_PREFERENCES_PAGE_PLATFORMS_RETRO_ROW (games_preferences_page_platforms_retro_row_get_type ())
#define GAMES_PREFERENCES_PAGE_PLATFORMS_RETRO_ROW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_PREFERENCES_PAGE_PLATFORMS_RETRO_ROW, GamesPreferencesPagePlatformsRetroRow))
#define GAMES_PREFERENCES_PAGE_PLATFORMS_RETRO_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_PREFERENCES_PAGE_PLATFORMS_RETRO_ROW, GamesPreferencesPagePlatformsRetroRowClass))
#define GAMES_IS_PREFERENCES_PAGE_PLATFORMS_RETRO_ROW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_PREFERENCES_PAGE_PLATFORMS_RETRO_ROW))
#define GAMES_IS_PREFERENCES_PAGE_PLATFORMS_RETRO_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_PREFERENCES_PAGE_PLATFORMS_RETRO_ROW))
#define GAMES_PREFERENCES_PAGE_PLATFORMS_RETRO_ROW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_PREFERENCES_PAGE_PLATFORMS_RETRO_ROW, GamesPreferencesPagePlatformsRetroRowClass))

typedef struct _GamesPreferencesPagePlatformsRetroRow GamesPreferencesPagePlatformsRetroRow;
typedef struct _GamesPreferencesPagePlatformsRetroRowClass GamesPreferencesPagePlatformsRetroRowClass;
typedef struct _GamesPreferencesPagePlatformsRetroRowPrivate GamesPreferencesPagePlatformsRetroRowPrivate;
enum  {
	GAMES_PREFERENCES_PAGE_PLATFORMS_RETRO_ROW_0_PROPERTY,
	GAMES_PREFERENCES_PAGE_PLATFORMS_RETRO_ROW_PLATFORM_PROPERTY,
	GAMES_PREFERENCES_PAGE_PLATFORMS_RETRO_ROW_NUM_PROPERTIES
};
static GParamSpec* games_preferences_page_platforms_retro_row_properties[GAMES_PREFERENCES_PAGE_PLATFORMS_RETRO_ROW_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 _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _GamesPreferencesPagePlatformsRetroRow {
	HdyComboRow parent_instance;
	GamesPreferencesPagePlatformsRetroRowPrivate * priv;
};

struct _GamesPreferencesPagePlatformsRetroRowClass {
	HdyComboRowClass parent_class;
};

struct _GamesPreferencesPagePlatformsRetroRowPrivate {
	GamesRetroPlatform* _platform;
	GListStore* model;
};

static gint GamesPreferencesPagePlatformsRetroRow_private_offset;
static gpointer games_preferences_page_platforms_retro_row_parent_class = NULL;

VALA_EXTERN GType games_preferences_page_platforms_retro_row_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GamesPreferencesPagePlatformsRetroRow* games_preferences_page_platforms_retro_row_new (GamesRetroPlatform* platform);
VALA_EXTERN GamesPreferencesPagePlatformsRetroRow* games_preferences_page_platforms_retro_row_construct (GType object_type,
                                                                                             GamesRetroPlatform* platform);
static gchar* games_preferences_page_platforms_retro_row_get_core_name (GamesPreferencesPagePlatformsRetroRow* self,
                                                                 GObject* object);
static void games_preferences_page_platforms_retro_row_notify_selected_index_cb (GamesPreferencesPagePlatformsRetroRow* self);
VALA_EXTERN GamesRetroPlatform* games_preferences_page_platforms_retro_row_get_platform (GamesPreferencesPagePlatformsRetroRow* self);
static void games_preferences_page_platforms_retro_row_set_platform (GamesPreferencesPagePlatformsRetroRow* self,
                                                              GamesRetroPlatform* value);
static GObject * games_preferences_page_platforms_retro_row_constructor (GType type,
                                                                  guint n_construct_properties,
                                                                  GObjectConstructParam * construct_properties);
static void _games_preferences_page_platforms_retro_row_notify_selected_index_cb_g_object_notify (GObject* _sender,
                                                                                           GParamSpec* pspec,
                                                                                           gpointer self);
static gchar* _games_preferences_page_platforms_retro_row_get_core_name_hdy_combo_row_get_name_func (GObject* item,
                                                                                              gpointer self);
static void games_preferences_page_platforms_retro_row_finalize (GObject * obj);
static GType games_preferences_page_platforms_retro_row_get_type_once (void);
static void _vala_games_preferences_page_platforms_retro_row_get_property (GObject * object,
                                                                    guint property_id,
                                                                    GValue * value,
                                                                    GParamSpec * pspec);
static void _vala_games_preferences_page_platforms_retro_row_set_property (GObject * object,
                                                                    guint property_id,
                                                                    const GValue * value,
                                                                    GParamSpec * pspec);
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
games_preferences_page_platforms_retro_row_get_instance_private (GamesPreferencesPagePlatformsRetroRow* self)
{
	return G_STRUCT_MEMBER_P (self, GamesPreferencesPagePlatformsRetroRow_private_offset);
}

GamesPreferencesPagePlatformsRetroRow*
games_preferences_page_platforms_retro_row_construct (GType object_type,
                                                      GamesRetroPlatform* platform)
{
	GamesPreferencesPagePlatformsRetroRow * self = NULL;
	g_return_val_if_fail (platform != NULL, NULL);
	self = (GamesPreferencesPagePlatformsRetroRow*) g_object_new (object_type, "platform", platform, NULL);
	return self;
}

GamesPreferencesPagePlatformsRetroRow*
games_preferences_page_platforms_retro_row_new (GamesRetroPlatform* platform)
{
	return games_preferences_page_platforms_retro_row_construct (GAMES_TYPE_PREFERENCES_PAGE_PLATFORMS_RETRO_ROW, platform);
}

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

static gchar*
games_preferences_page_platforms_retro_row_get_core_name (GamesPreferencesPagePlatformsRetroRow* self,
                                                          GObject* object)
{
	RetroCoreDescriptor* core = NULL;
	RetroCoreDescriptor* _tmp0_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (object != NULL, NULL);
	_vala_assert (G_TYPE_CHECK_INSTANCE_TYPE (object, retro_core_descriptor_get_type ()), "object is Retro.CoreDescriptor");
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (object, retro_core_descriptor_get_type ()) ? ((RetroCoreDescriptor*) object) : NULL);
	core = _tmp0_;
	{
		gchar* _tmp1_ = NULL;
		gchar* _tmp2_;
		gchar* _tmp3_;
		_tmp2_ = retro_core_descriptor_get_name (core, &_inner_error0_);
		_tmp1_ = _tmp2_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp3_ = _tmp1_;
		_tmp1_ = NULL;
		result = _tmp3_;
		_g_free0 (_tmp1_);
		_g_object_unref0 (core);
		return result;
	}
	goto __finally0;
	__catch0_g_error:
	{
		gchar* _tmp4_;
		g_clear_error (&_inner_error0_);
		_tmp4_ = retro_core_descriptor_get_id (core);
		result = _tmp4_;
		_g_object_unref0 (core);
		return result;
	}
	__finally0:
	_g_object_unref0 (core);
	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 void
games_preferences_page_platforms_retro_row_notify_selected_index_cb (GamesPreferencesPagePlatformsRetroRow* self)
{
	RetroCoreDescriptor* core = NULL;
	GListStore* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	GObject* _tmp3_;
	RetroCoreDescriptor* _tmp4_;
	RetroCoreDescriptor* _tmp5_;
	GamesRetroCoreManager* core_manager = NULL;
	GamesRetroCoreManager* _tmp6_;
	GamesRetroCoreManager* _tmp7_;
	GamesRetroPlatform* _tmp8_;
	RetroCoreDescriptor* _tmp9_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->model;
	_tmp1_ = hdy_combo_row_get_selected_index ((HdyComboRow*) self);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_list_model_get_item ((GListModel*) _tmp0_, (guint) _tmp2_);
	_tmp4_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp3_, retro_core_descriptor_get_type ()) ? ((RetroCoreDescriptor*) _tmp3_) : NULL;
	if (_tmp4_ == NULL) {
		_g_object_unref0 (_tmp3_);
	}
	core = _tmp4_;
	_tmp5_ = core;
	if (_tmp5_ == NULL) {
		_g_object_unref0 (core);
		return;
	}
	_tmp6_ = games_retro_core_manager_get_instance ();
	core_manager = _tmp6_;
	_tmp7_ = core_manager;
	_tmp8_ = self->priv->_platform;
	_tmp9_ = core;
	games_retro_core_manager_set_preferred_core (_tmp7_, _tmp8_, _tmp9_);
	_g_object_unref0 (core_manager);
	_g_object_unref0 (core);
}

GamesRetroPlatform*
games_preferences_page_platforms_retro_row_get_platform (GamesPreferencesPagePlatformsRetroRow* self)
{
	GamesRetroPlatform* result;
	GamesRetroPlatform* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_platform;
	result = _tmp0_;
	return result;
}

static void
games_preferences_page_platforms_retro_row_set_platform (GamesPreferencesPagePlatformsRetroRow* self,
                                                         GamesRetroPlatform* value)
{
	GamesRetroPlatform* old_value;
	g_return_if_fail (self != NULL);
	old_value = games_preferences_page_platforms_retro_row_get_platform (self);
	if (old_value != value) {
		GamesRetroPlatform* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_platform);
		self->priv->_platform = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, games_preferences_page_platforms_retro_row_properties[GAMES_PREFERENCES_PAGE_PLATFORMS_RETRO_ROW_PLATFORM_PROPERTY]);
	}
}

static void
_games_preferences_page_platforms_retro_row_notify_selected_index_cb_g_object_notify (GObject* _sender,
                                                                                      GParamSpec* pspec,
                                                                                      gpointer self)
{
	games_preferences_page_platforms_retro_row_notify_selected_index_cb ((GamesPreferencesPagePlatformsRetroRow*) self);
}

static gchar*
_games_preferences_page_platforms_retro_row_get_core_name_hdy_combo_row_get_name_func (GObject* item,
                                                                                       gpointer self)
{
	gchar* result;
	result = games_preferences_page_platforms_retro_row_get_core_name ((GamesPreferencesPagePlatformsRetroRow*) self, item);
	return result;
}

static GObject *
games_preferences_page_platforms_retro_row_constructor (GType type,
                                                        guint n_construct_properties,
                                                        GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GamesPreferencesPagePlatformsRetroRow * self;
	GamesRetroPlatform* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	GListStore* _tmp3_;
	GamesRetroCoreManager* core_manager = NULL;
	GamesRetroCoreManager* _tmp4_;
	RetroCoreDescriptor** cores = NULL;
	GamesRetroCoreManager* _tmp5_;
	GamesRetroPlatform* _tmp6_;
	gint _tmp7_ = 0;
	RetroCoreDescriptor** _tmp8_;
	gint cores_length1;
	gint _cores_size_;
	RetroCoreDescriptor** _tmp9_;
	gint _tmp9__length1;
	GListStore* _tmp13_;
	parent_class = G_OBJECT_CLASS (games_preferences_page_platforms_retro_row_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_PREFERENCES_PAGE_PLATFORMS_RETRO_ROW, GamesPreferencesPagePlatformsRetroRow);
	_tmp0_ = self->priv->_platform;
	_tmp1_ = games_platform_get_name ((GamesPlatform*) _tmp0_);
	_tmp2_ = _tmp1_;
	hdy_preferences_row_set_title ((HdyPreferencesRow*) self, _tmp2_);
	_g_free0 (_tmp2_);
	hdy_action_row_set_subtitle ((HdyActionRow*) self, _ ("None"));
	hdy_combo_row_set_use_subtitle ((HdyComboRow*) self, TRUE);
	_tmp3_ = g_list_store_new (retro_core_descriptor_get_type ());
	_g_object_unref0 (self->priv->model);
	self->priv->model = _tmp3_;
	_tmp4_ = games_retro_core_manager_get_instance ();
	core_manager = _tmp4_;
	_tmp5_ = core_manager;
	_tmp6_ = self->priv->_platform;
	_tmp8_ = games_retro_core_manager_get_cores_for_platform (_tmp5_, _tmp6_, &_tmp7_);
	cores = _tmp8_;
	cores_length1 = _tmp7_;
	_cores_size_ = cores_length1;
	_tmp9_ = cores;
	_tmp9__length1 = cores_length1;
	{
		RetroCoreDescriptor** core_collection = NULL;
		gint core_collection_length1 = 0;
		gint _core_collection_size_ = 0;
		gint core_it = 0;
		core_collection = _tmp9_;
		core_collection_length1 = _tmp9__length1;
		for (core_it = 0; core_it < core_collection_length1; core_it = core_it + 1) {
			RetroCoreDescriptor* _tmp10_;
			RetroCoreDescriptor* core = NULL;
			_tmp10_ = _g_object_ref0 (core_collection[core_it]);
			core = _tmp10_;
			{
				GListStore* _tmp11_;
				RetroCoreDescriptor* _tmp12_;
				_tmp11_ = self->priv->model;
				_tmp12_ = core;
				g_list_store_append (_tmp11_, (GObject*) _tmp12_);
				_g_object_unref0 (core);
			}
		}
	}
	g_signal_connect_object ((GObject*) self, "notify::selected-index", (GCallback) _games_preferences_page_platforms_retro_row_notify_selected_index_cb_g_object_notify, self, 0);
	_tmp13_ = self->priv->model;
	hdy_combo_row_bind_name_model ((HdyComboRow*) self, (GListModel*) _tmp13_, _games_preferences_page_platforms_retro_row_get_core_name_hdy_combo_row_get_name_func, g_object_ref (self), g_object_unref);
	cores = (_vala_array_free (cores, cores_length1, (GDestroyNotify) g_object_unref), NULL);
	_g_object_unref0 (core_manager);
	return obj;
}

static void
games_preferences_page_platforms_retro_row_class_init (GamesPreferencesPagePlatformsRetroRowClass * klass,
                                                       gpointer klass_data)
{
	games_preferences_page_platforms_retro_row_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GamesPreferencesPagePlatformsRetroRow_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_games_preferences_page_platforms_retro_row_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_games_preferences_page_platforms_retro_row_set_property;
	G_OBJECT_CLASS (klass)->constructor = games_preferences_page_platforms_retro_row_constructor;
	G_OBJECT_CLASS (klass)->finalize = games_preferences_page_platforms_retro_row_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GAMES_PREFERENCES_PAGE_PLATFORMS_RETRO_ROW_PLATFORM_PROPERTY, games_preferences_page_platforms_retro_row_properties[GAMES_PREFERENCES_PAGE_PLATFORMS_RETRO_ROW_PLATFORM_PROPERTY] = g_param_spec_object ("platform", "platform", "platform", GAMES_TYPE_RETRO_PLATFORM, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
}

static void
games_preferences_page_platforms_retro_row_instance_init (GamesPreferencesPagePlatformsRetroRow * self,
                                                          gpointer klass)
{
	self->priv = games_preferences_page_platforms_retro_row_get_instance_private (self);
}

static void
games_preferences_page_platforms_retro_row_finalize (GObject * obj)
{
	GamesPreferencesPagePlatformsRetroRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_PREFERENCES_PAGE_PLATFORMS_RETRO_ROW, GamesPreferencesPagePlatformsRetroRow);
	_g_object_unref0 (self->priv->_platform);
	_g_object_unref0 (self->priv->model);
	G_OBJECT_CLASS (games_preferences_page_platforms_retro_row_parent_class)->finalize (obj);
}

static GType
games_preferences_page_platforms_retro_row_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GamesPreferencesPagePlatformsRetroRowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_preferences_page_platforms_retro_row_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesPreferencesPagePlatformsRetroRow), 0, (GInstanceInitFunc) games_preferences_page_platforms_retro_row_instance_init, NULL };
	GType games_preferences_page_platforms_retro_row_type_id;
	games_preferences_page_platforms_retro_row_type_id = g_type_register_static (hdy_combo_row_get_type (), "GamesPreferencesPagePlatformsRetroRow", &g_define_type_info, 0);
	GamesPreferencesPagePlatformsRetroRow_private_offset = g_type_add_instance_private (games_preferences_page_platforms_retro_row_type_id, sizeof (GamesPreferencesPagePlatformsRetroRowPrivate));
	return games_preferences_page_platforms_retro_row_type_id;
}

GType
games_preferences_page_platforms_retro_row_get_type (void)
{
	static volatile gsize games_preferences_page_platforms_retro_row_type_id__once = 0;
	if (g_once_init_enter (&games_preferences_page_platforms_retro_row_type_id__once)) {
		GType games_preferences_page_platforms_retro_row_type_id;
		games_preferences_page_platforms_retro_row_type_id = games_preferences_page_platforms_retro_row_get_type_once ();
		g_once_init_leave (&games_preferences_page_platforms_retro_row_type_id__once, games_preferences_page_platforms_retro_row_type_id);
	}
	return games_preferences_page_platforms_retro_row_type_id__once;
}

static void
_vala_games_preferences_page_platforms_retro_row_get_property (GObject * object,
                                                               guint property_id,
                                                               GValue * value,
                                                               GParamSpec * pspec)
{
	GamesPreferencesPagePlatformsRetroRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GAMES_TYPE_PREFERENCES_PAGE_PLATFORMS_RETRO_ROW, GamesPreferencesPagePlatformsRetroRow);
	switch (property_id) {
		case GAMES_PREFERENCES_PAGE_PLATFORMS_RETRO_ROW_PLATFORM_PROPERTY:
		g_value_set_object (value, games_preferences_page_platforms_retro_row_get_platform (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_games_preferences_page_platforms_retro_row_set_property (GObject * object,
                                                               guint property_id,
                                                               const GValue * value,
                                                               GParamSpec * pspec)
{
	GamesPreferencesPagePlatformsRetroRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GAMES_TYPE_PREFERENCES_PAGE_PLATFORMS_RETRO_ROW, GamesPreferencesPagePlatformsRetroRow);
	switch (property_id) {
		case GAMES_PREFERENCES_PAGE_PLATFORMS_RETRO_ROW_PLATFORM_PROPERTY:
		games_preferences_page_platforms_retro_row_set_platform (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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

