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

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

#include "gnome-games.h"
#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <string.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  {
	GAMES_COMPOSITE_COVER_0_PROPERTY,
	GAMES_COMPOSITE_COVER_NUM_PROPERTIES
};
static GParamSpec* games_composite_cover_properties[GAMES_COMPOSITE_COVER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _GamesCompositeCoverPrivate {
	GamesCover** covers;
	gint covers_length1;
	gint _covers_size_;
};

static gint GamesCompositeCover_private_offset;
static gpointer games_composite_cover_parent_class = NULL;
static GamesCoverIface * games_composite_cover_games_cover_parent_iface = NULL;

static GamesCover** _vala_array_dup30 (GamesCover** self,
                                gssize length);
static void games_composite_cover_on_cover_changed (GamesCompositeCover* self);
static void _games_composite_cover_on_cover_changed_games_cover_changed (GamesCover* _sender,
                                                                  gpointer self);
static GFile* games_composite_cover_real_get_cover (GamesCover* base);
static void games_composite_cover_finalize (GObject * obj);
static GType games_composite_cover_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
games_composite_cover_get_instance_private (GamesCompositeCover* self)
{
	return G_STRUCT_MEMBER_P (self, GamesCompositeCover_private_offset);
}

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

static GamesCover**
_vala_array_dup30 (GamesCover** self,
                   gssize length)
{
	if (length >= 0) {
		GamesCover** result;
		gssize i;
		result = g_new0 (GamesCover*, length + 1);
		for (i = 0; i < length; i++) {
			GamesCover* _tmp0_;
			_tmp0_ = _g_object_ref0 (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

static void
_games_composite_cover_on_cover_changed_games_cover_changed (GamesCover* _sender,
                                                             gpointer self)
{
	games_composite_cover_on_cover_changed ((GamesCompositeCover*) self);
}

GamesCompositeCover*
games_composite_cover_construct (GType object_type,
                                 GamesCover** covers,
                                 gint covers_length1)
{
	GamesCompositeCover * self = NULL;
	GamesCover** _tmp0_;
	gint _tmp0__length1;
	self = (GamesCompositeCover*) g_object_new (object_type, NULL);
	_tmp0_ = (covers != NULL) ? _vala_array_dup30 (covers, covers_length1) : covers;
	_tmp0__length1 = covers_length1;
	self->priv->covers = (_vala_array_free (self->priv->covers, self->priv->covers_length1, (GDestroyNotify) g_object_unref), NULL);
	self->priv->covers = _tmp0_;
	self->priv->covers_length1 = _tmp0__length1;
	self->priv->_covers_size_ = self->priv->covers_length1;
	{
		GamesCover** cover_collection = NULL;
		gint cover_collection_length1 = 0;
		gint _cover_collection_size_ = 0;
		gint cover_it = 0;
		cover_collection = covers;
		cover_collection_length1 = covers_length1;
		for (cover_it = 0; cover_it < cover_collection_length1; cover_it = cover_it + 1) {
			GamesCover* _tmp1_;
			GamesCover* cover = NULL;
			_tmp1_ = _g_object_ref0 (cover_collection[cover_it]);
			cover = _tmp1_;
			{
				GamesCover* _tmp2_;
				_tmp2_ = cover;
				g_signal_connect_object (_tmp2_, "changed", (GCallback) _games_composite_cover_on_cover_changed_games_cover_changed, self, 0);
				_g_object_unref0 (cover);
			}
		}
	}
	return self;
}

GamesCompositeCover*
games_composite_cover_new (GamesCover** covers,
                           gint covers_length1)
{
	return games_composite_cover_construct (GAMES_TYPE_COMPOSITE_COVER, covers, covers_length1);
}

static GFile*
games_composite_cover_real_get_cover (GamesCover* base)
{
	GamesCompositeCover * self;
	GamesCover** _tmp0_;
	gint _tmp0__length1;
	GFile* result;
	self = (GamesCompositeCover*) base;
	_tmp0_ = self->priv->covers;
	_tmp0__length1 = self->priv->covers_length1;
	{
		GamesCover** cover_collection = NULL;
		gint cover_collection_length1 = 0;
		gint _cover_collection_size_ = 0;
		gint cover_it = 0;
		cover_collection = _tmp0_;
		cover_collection_length1 = _tmp0__length1;
		for (cover_it = 0; cover_it < cover_collection_length1; cover_it = cover_it + 1) {
			GamesCover* _tmp1_;
			GamesCover* cover = NULL;
			_tmp1_ = _g_object_ref0 (cover_collection[cover_it]);
			cover = _tmp1_;
			{
				GFile* result_cover = NULL;
				GamesCover* _tmp2_;
				GFile* _tmp3_;
				GFile* _tmp4_;
				_tmp2_ = cover;
				_tmp3_ = games_cover_get_cover (_tmp2_);
				result_cover = _tmp3_;
				_tmp4_ = result_cover;
				if (_tmp4_ != NULL) {
					result = result_cover;
					_g_object_unref0 (cover);
					return result;
				}
				_g_object_unref0 (result_cover);
				_g_object_unref0 (cover);
			}
		}
	}
	result = NULL;
	return result;
}

static void
games_composite_cover_on_cover_changed (GamesCompositeCover* self)
{
	g_return_if_fail (self != NULL);
	g_signal_emit_by_name ((GamesCover*) self, "changed");
}

static void
games_composite_cover_class_init (GamesCompositeCoverClass * klass,
                                  gpointer klass_data)
{
	games_composite_cover_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GamesCompositeCover_private_offset);
	G_OBJECT_CLASS (klass)->finalize = games_composite_cover_finalize;
}

static void
games_composite_cover_games_cover_interface_init (GamesCoverIface * iface,
                                                  gpointer iface_data)
{
	games_composite_cover_games_cover_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_cover = (GFile* (*) (GamesCover*)) games_composite_cover_real_get_cover;
}

static void
games_composite_cover_instance_init (GamesCompositeCover * self,
                                     gpointer klass)
{
	self->priv = games_composite_cover_get_instance_private (self);
}

static void
games_composite_cover_finalize (GObject * obj)
{
	GamesCompositeCover * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_COMPOSITE_COVER, GamesCompositeCover);
	self->priv->covers = (_vala_array_free (self->priv->covers, self->priv->covers_length1, (GDestroyNotify) g_object_unref), NULL);
	G_OBJECT_CLASS (games_composite_cover_parent_class)->finalize (obj);
}

static GType
games_composite_cover_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GamesCompositeCoverClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_composite_cover_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesCompositeCover), 0, (GInstanceInitFunc) games_composite_cover_instance_init, NULL };
	static const GInterfaceInfo games_cover_info = { (GInterfaceInitFunc) games_composite_cover_games_cover_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType games_composite_cover_type_id;
	games_composite_cover_type_id = g_type_register_static (G_TYPE_OBJECT, "GamesCompositeCover", &g_define_type_info, 0);
	g_type_add_interface_static (games_composite_cover_type_id, GAMES_TYPE_COVER, &games_cover_info);
	GamesCompositeCover_private_offset = g_type_add_instance_private (games_composite_cover_type_id, sizeof (GamesCompositeCoverPrivate));
	return games_composite_cover_type_id;
}

GType
games_composite_cover_get_type (void)
{
	static volatile gsize games_composite_cover_type_id__once = 0;
	if (g_once_init_enter (&games_composite_cover_type_id__once)) {
		GType games_composite_cover_type_id;
		games_composite_cover_type_id = games_composite_cover_get_type_once ();
		g_once_init_leave (&games_composite_cover_type_id__once, games_composite_cover_type_id);
	}
	return games_composite_cover_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;
}

