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

/* This file is part of GNOME Games. License: GPLv3*/

#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>


#define GAMES_TYPE_COVER (games_cover_get_type ())
#define GAMES_COVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_COVER, GamesCover))
#define GAMES_IS_COVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_COVER))
#define GAMES_COVER_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GAMES_TYPE_COVER, GamesCoverIface))

typedef struct _GamesCover GamesCover;
typedef struct _GamesCoverIface GamesCoverIface;

#define GAMES_TYPE_COMPOSITE_COVER (games_composite_cover_get_type ())
#define GAMES_COMPOSITE_COVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_COMPOSITE_COVER, GamesCompositeCover))
#define GAMES_COMPOSITE_COVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_COMPOSITE_COVER, GamesCompositeCoverClass))
#define GAMES_IS_COMPOSITE_COVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_COMPOSITE_COVER))
#define GAMES_IS_COMPOSITE_COVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_COMPOSITE_COVER))
#define GAMES_COMPOSITE_COVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_COMPOSITE_COVER, GamesCompositeCoverClass))

typedef struct _GamesCompositeCover GamesCompositeCover;
typedef struct _GamesCompositeCoverClass GamesCompositeCoverClass;
typedef struct _GamesCompositeCoverPrivate GamesCompositeCoverPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _GamesCoverIface {
	GTypeInterface parent_iface;
	GIcon* (*get_cover) (GamesCover* self);
};

struct _GamesCompositeCover {
	GObject parent_instance;
	GamesCompositeCoverPrivate * priv;
};

struct _GamesCompositeCoverClass {
	GObjectClass parent_class;
};

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


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

GType games_cover_get_type (void) G_GNUC_CONST;
GType games_composite_cover_get_type (void) G_GNUC_CONST;
#define GAMES_COMPOSITE_COVER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GAMES_TYPE_COMPOSITE_COVER, GamesCompositeCoverPrivate))
enum  {
	GAMES_COMPOSITE_COVER_DUMMY_PROPERTY
};
GamesCompositeCover* games_composite_cover_new (GamesCover** covers, int covers_length1);
GamesCompositeCover* games_composite_cover_construct (GType object_type, GamesCover** covers, int covers_length1);
static GamesCover** _vala_array_dup4 (GamesCover** self, int 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 GIcon* games_composite_cover_real_get_cover (GamesCover* base);
GIcon* games_cover_get_cover (GamesCover* self);
static void games_composite_cover_finalize (GObject * obj);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);


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


static GamesCover** _vala_array_dup4 (GamesCover** self, int length) {
	GamesCover** result;
	int 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;
}


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, int covers_length1) {
	GamesCompositeCover * self = NULL;
	GamesCover** _tmp0_;
	gint _tmp0__length1;
	GamesCover** _tmp1_;
	gint _tmp1__length1;
	GamesCover** _tmp2_;
	gint _tmp2__length1;
	self = (GamesCompositeCover*) g_object_new (object_type, NULL);
	_tmp0_ = covers;
	_tmp0__length1 = covers_length1;
	_tmp1_ = (_tmp0_ != NULL) ? _vala_array_dup4 (_tmp0_, _tmp0__length1) : ((gpointer) _tmp0_);
	_tmp1__length1 = _tmp0__length1;
	self->priv->covers = (_vala_array_free (self->priv->covers, self->priv->covers_length1, (GDestroyNotify) g_object_unref), NULL);
	self->priv->covers = _tmp1_;
	self->priv->covers_length1 = _tmp1__length1;
	self->priv->_covers_size_ = self->priv->covers_length1;
	_tmp2_ = covers;
	_tmp2__length1 = covers_length1;
	{
		GamesCover** cover_collection = NULL;
		gint cover_collection_length1 = 0;
		gint _cover_collection_size_ = 0;
		gint cover_it = 0;
		cover_collection = _tmp2_;
		cover_collection_length1 = _tmp2__length1;
		for (cover_it = 0; cover_it < _tmp2__length1; cover_it = cover_it + 1) {
			GamesCover* _tmp3_;
			GamesCover* cover = NULL;
			_tmp3_ = _g_object_ref0 (cover_collection[cover_it]);
			cover = _tmp3_;
			{
				GamesCover* _tmp4_;
				_tmp4_ = cover;
				g_signal_connect_object (_tmp4_, "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, int covers_length1) {
	return games_composite_cover_construct (GAMES_TYPE_COMPOSITE_COVER, covers, covers_length1);
}


static GIcon* games_composite_cover_real_get_cover (GamesCover* base) {
	GamesCompositeCover * self;
	GIcon* result = NULL;
	GamesCover** _tmp0_;
	gint _tmp0__length1;
	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 < _tmp0__length1; cover_it = cover_it + 1) {
			GamesCover* _tmp1_;
			GamesCover* cover = NULL;
			_tmp1_ = _g_object_ref0 (cover_collection[cover_it]);
			cover = _tmp1_;
			{
				GIcon* result_cover;
				GamesCover* _tmp2_;
				GIcon* _tmp3_;
				GIcon* _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) {
	games_composite_cover_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GamesCompositeCoverPrivate));
	G_OBJECT_CLASS (klass)->finalize = games_composite_cover_finalize;
}


static void games_composite_cover_games_cover_interface_init (GamesCoverIface * iface) {
	games_composite_cover_games_cover_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_cover = (GIcon* (*) (GamesCover *)) games_composite_cover_real_get_cover;
}


static void games_composite_cover_instance_init (GamesCompositeCover * self) {
	self->priv = GAMES_COMPOSITE_COVER_GET_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);
}


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


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int 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, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}



