/* media-set.c generated by valac 0.36.6.6-c7bee, the Vala compiler
 * generated from media-set.vala, do not modify */

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

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


#define GAMES_TYPE_MEDIA_SET (games_media_set_get_type ())
#define GAMES_MEDIA_SET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_MEDIA_SET, GamesMediaSet))
#define GAMES_MEDIA_SET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_MEDIA_SET, GamesMediaSetClass))
#define GAMES_IS_MEDIA_SET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_MEDIA_SET))
#define GAMES_IS_MEDIA_SET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_MEDIA_SET))
#define GAMES_MEDIA_SET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_MEDIA_SET, GamesMediaSetClass))

typedef struct _GamesMediaSet GamesMediaSet;
typedef struct _GamesMediaSetClass GamesMediaSetClass;
typedef struct _GamesMediaSetPrivate GamesMediaSetPrivate;

#define GAMES_TYPE_MEDIA (games_media_get_type ())
#define GAMES_MEDIA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_MEDIA, GamesMedia))
#define GAMES_MEDIA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_MEDIA, GamesMediaClass))
#define GAMES_IS_MEDIA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_MEDIA))
#define GAMES_IS_MEDIA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_MEDIA))
#define GAMES_MEDIA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_MEDIA, GamesMediaClass))

typedef struct _GamesMedia GamesMedia;
typedef struct _GamesMediaClass GamesMediaClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _GamesMediaSet {
	GObject parent_instance;
	GamesMediaSetPrivate * priv;
};

struct _GamesMediaSetClass {
	GObjectClass parent_class;
};

struct _GamesMediaSetPrivate {
	gint _selected_media_number;
	GIcon* _icon;
	GamesMedia** medias;
	gint medias_length1;
	gint _medias_size_;
};

typedef void (*GamesMediaSetMediaCallback) (GamesMedia* media, void* user_data);
typedef enum  {
	GAMES_MEDIA_SET_ERROR_NOT_A_MEDIA
} GamesMediaSetError;
#define GAMES_MEDIA_SET_ERROR games_media_set_error_quark ()

static gpointer games_media_set_parent_class = NULL;

GType games_media_set_get_type (void) G_GNUC_CONST;
GType games_media_get_type (void) G_GNUC_CONST;
#define GAMES_MEDIA_SET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GAMES_TYPE_MEDIA_SET, GamesMediaSetPrivate))
enum  {
	GAMES_MEDIA_SET_0_PROPERTY,
	GAMES_MEDIA_SET_SELECTED_MEDIA_NUMBER_PROPERTY,
	GAMES_MEDIA_SET_ICON_PROPERTY
};
void games_media_set_add_media (GamesMediaSet* self, GamesMedia* media);
static void _vala_array_add7 (GamesMedia** * array, int* length, int* size, GamesMedia* value);
gint games_media_set_get_size (GamesMediaSet* self);
GamesMedia* games_media_set_get_selected_media (GamesMediaSet* self, guint index, GError** error);
static GamesMedia* games_media_set_get_media (GamesMediaSet* self, guint index, GError** error);
gint games_media_set_get_selected_media_number (GamesMediaSet* self);
void games_media_set_foreach_media (GamesMediaSet* self, GamesMediaSetMediaCallback media_callback, void* media_callback_target);
GQuark games_media_set_error_quark (void);
GamesMediaSet* games_media_set_new (void);
GamesMediaSet* games_media_set_construct (GType object_type);
void games_media_set_set_selected_media_number (GamesMediaSet* self, gint value);
GIcon* games_media_set_get_icon (GamesMediaSet* self);
void games_media_set_set_icon (GamesMediaSet* self, GIcon* value);
static void games_media_set_finalize (GObject * obj);
static void _vala_games_media_set_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_games_media_set_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);
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 void _vala_array_add7 (GamesMedia** * array, int* length, int* size, GamesMedia* value) {
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (GamesMedia*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}


void games_media_set_add_media (GamesMediaSet* self, GamesMedia* media) {
	GamesMedia** _tmp0_;
	gint _tmp0__length1;
	GamesMedia* _tmp1_;
	GamesMedia* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (media != NULL);
	_tmp0_ = self->priv->medias;
	_tmp0__length1 = self->priv->medias_length1;
	_tmp1_ = media;
	_tmp2_ = _g_object_ref0 (_tmp1_);
	_vala_array_add7 (&self->priv->medias, &self->priv->medias_length1, &self->priv->_medias_size_, _tmp2_);
}


gint games_media_set_get_size (GamesMediaSet* self) {
	gint result = 0;
	GamesMedia** _tmp0_;
	gint _tmp0__length1;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = self->priv->medias;
	_tmp0__length1 = self->priv->medias_length1;
	result = _tmp0__length1;
	return result;
}


GamesMedia* games_media_set_get_selected_media (GamesMediaSet* self, guint index, GError** error) {
	GamesMedia* result = NULL;
	GamesMedia* _tmp0_ = NULL;
	gint _tmp1_;
	GamesMedia* _tmp2_;
	GamesMedia* _tmp3_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp1_ = self->priv->_selected_media_number;
	_tmp2_ = games_media_set_get_media (self, (guint) _tmp1_, &_inner_error_);
	_tmp0_ = _tmp2_;
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		return NULL;
	}
	_tmp3_ = _tmp0_;
	_tmp0_ = NULL;
	result = _tmp3_;
	_g_object_unref0 (_tmp0_);
	return result;
}


void games_media_set_foreach_media (GamesMediaSet* self, GamesMediaSetMediaCallback media_callback, void* media_callback_target) {
	GamesMedia** _tmp0_;
	gint _tmp0__length1;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->medias;
	_tmp0__length1 = self->priv->medias_length1;
	{
		GamesMedia** media_collection = NULL;
		gint media_collection_length1 = 0;
		gint _media_collection_size_ = 0;
		gint media_it = 0;
		media_collection = _tmp0_;
		media_collection_length1 = _tmp0__length1;
		for (media_it = 0; media_it < _tmp0__length1; media_it = media_it + 1) {
			GamesMedia* _tmp1_;
			GamesMedia* media = NULL;
			_tmp1_ = _g_object_ref0 (media_collection[media_it]);
			media = _tmp1_;
			{
				GamesMediaSetMediaCallback _tmp2_;
				void* _tmp2__target;
				GamesMedia* _tmp3_;
				_tmp2_ = media_callback;
				_tmp2__target = media_callback_target;
				_tmp3_ = media;
				_tmp2_ (_tmp3_, _tmp2__target);
				_g_object_unref0 (media);
			}
		}
	}
}


static GamesMedia* games_media_set_get_media (GamesMediaSet* self, guint index, GError** error) {
	GamesMedia* result = NULL;
	guint _tmp0_;
	GamesMedia** _tmp1_;
	gint _tmp1__length1;
	GamesMedia** _tmp4_;
	gint _tmp4__length1;
	guint _tmp5_;
	GamesMedia* _tmp6_;
	GamesMedia* _tmp7_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = index;
	_tmp1_ = self->priv->medias;
	_tmp1__length1 = self->priv->medias_length1;
	if (_tmp0_ >= ((guint) _tmp1__length1)) {
		guint _tmp2_;
		GError* _tmp3_;
		_tmp2_ = index;
		_tmp3_ = g_error_new (GAMES_MEDIA_SET_ERROR, GAMES_MEDIA_SET_ERROR_NOT_A_MEDIA, _ ("Invalid media index %u."), _tmp2_);
		_inner_error_ = _tmp3_;
		g_propagate_error (error, _inner_error_);
		return NULL;
	}
	_tmp4_ = self->priv->medias;
	_tmp4__length1 = self->priv->medias_length1;
	_tmp5_ = index;
	_tmp6_ = _tmp4_[_tmp5_];
	_tmp7_ = _g_object_ref0 (_tmp6_);
	result = _tmp7_;
	return result;
}


GamesMediaSet* games_media_set_construct (GType object_type) {
	GamesMediaSet * self = NULL;
	self = (GamesMediaSet*) g_object_new (object_type, NULL);
	return self;
}


GamesMediaSet* games_media_set_new (void) {
	return games_media_set_construct (GAMES_TYPE_MEDIA_SET);
}


gint games_media_set_get_selected_media_number (GamesMediaSet* self) {
	gint result;
	gint _tmp0_;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = self->priv->_selected_media_number;
	result = _tmp0_;
	return result;
}


void games_media_set_set_selected_media_number (GamesMediaSet* self, gint value) {
	g_return_if_fail (self != NULL);
	if (games_media_set_get_selected_media_number (self) != value) {
		gint _tmp0_;
		_tmp0_ = value;
		self->priv->_selected_media_number = _tmp0_;
		g_object_notify ((GObject *) self, "selected-media-number");
	}
}


GIcon* games_media_set_get_icon (GamesMediaSet* self) {
	GIcon* result;
	GIcon* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_icon;
	result = _tmp0_;
	return result;
}


void games_media_set_set_icon (GamesMediaSet* self, GIcon* value) {
	g_return_if_fail (self != NULL);
	if (games_media_set_get_icon (self) != value) {
		GIcon* _tmp0_;
		GIcon* _tmp1_;
		_tmp0_ = value;
		_tmp1_ = _g_object_ref0 (_tmp0_);
		_g_object_unref0 (self->priv->_icon);
		self->priv->_icon = _tmp1_;
		g_object_notify ((GObject *) self, "icon");
	}
}


static void games_media_set_class_init (GamesMediaSetClass * klass) {
	games_media_set_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GamesMediaSetPrivate));
	G_OBJECT_CLASS (klass)->get_property = _vala_games_media_set_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_games_media_set_set_property;
	G_OBJECT_CLASS (klass)->finalize = games_media_set_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GAMES_MEDIA_SET_SELECTED_MEDIA_NUMBER_PROPERTY, g_param_spec_int ("selected-media-number", "selected-media-number", "selected-media-number", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GAMES_MEDIA_SET_ICON_PROPERTY, g_param_spec_object ("icon", "icon", "icon", g_icon_get_type (), G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
}


static void games_media_set_instance_init (GamesMediaSet * self) {
	self->priv = GAMES_MEDIA_SET_GET_PRIVATE (self);
	self->priv->_selected_media_number = 0;
}


static void games_media_set_finalize (GObject * obj) {
	GamesMediaSet * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_MEDIA_SET, GamesMediaSet);
	_g_object_unref0 (self->priv->_icon);
	self->priv->medias = (_vala_array_free (self->priv->medias, self->priv->medias_length1, (GDestroyNotify) g_object_unref), NULL);
	G_OBJECT_CLASS (games_media_set_parent_class)->finalize (obj);
}


GType games_media_set_get_type (void) {
	static volatile gsize games_media_set_type_id__volatile = 0;
	if (g_once_init_enter (&games_media_set_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (GamesMediaSetClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_media_set_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesMediaSet), 0, (GInstanceInitFunc) games_media_set_instance_init, NULL };
		GType games_media_set_type_id;
		games_media_set_type_id = g_type_register_static (G_TYPE_OBJECT, "GamesMediaSet", &g_define_type_info, 0);
		g_once_init_leave (&games_media_set_type_id__volatile, games_media_set_type_id);
	}
	return games_media_set_type_id__volatile;
}


static void _vala_games_media_set_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	GamesMediaSet * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GAMES_TYPE_MEDIA_SET, GamesMediaSet);
	switch (property_id) {
		case GAMES_MEDIA_SET_SELECTED_MEDIA_NUMBER_PROPERTY:
		g_value_set_int (value, games_media_set_get_selected_media_number (self));
		break;
		case GAMES_MEDIA_SET_ICON_PROPERTY:
		g_value_set_object (value, games_media_set_get_icon (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_games_media_set_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	GamesMediaSet * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GAMES_TYPE_MEDIA_SET, GamesMediaSet);
	switch (property_id) {
		case GAMES_MEDIA_SET_SELECTED_MEDIA_NUMBER_PROPERTY:
		games_media_set_set_selected_media_number (self, g_value_get_int (value));
		break;
		case GAMES_MEDIA_SET_ICON_PROPERTY:
		games_media_set_set_icon (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, 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);
}



