/* gameinfo-disc-id-disc-title.c generated by valac 0.36.12.13-3ae08, the Vala compiler
 * generated from gameinfo-disc-id-disc-title.vala, do not modify */

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

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


#define GAMES_TYPE_TITLE (games_title_get_type ())
#define GAMES_TITLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_TITLE, GamesTitle))
#define GAMES_IS_TITLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_TITLE))
#define GAMES_TITLE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GAMES_TYPE_TITLE, GamesTitleIface))

typedef struct _GamesTitle GamesTitle;
typedef struct _GamesTitleIface GamesTitleIface;

#define GAMES_TYPE_GAMEINFO_DISC_ID_DISC_TITLE (games_gameinfo_disc_id_disc_title_get_type ())
#define GAMES_GAMEINFO_DISC_ID_DISC_TITLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_GAMEINFO_DISC_ID_DISC_TITLE, GamesGameinfoDiscIdDiscTitle))
#define GAMES_GAMEINFO_DISC_ID_DISC_TITLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_GAMEINFO_DISC_ID_DISC_TITLE, GamesGameinfoDiscIdDiscTitleClass))
#define GAMES_IS_GAMEINFO_DISC_ID_DISC_TITLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_GAMEINFO_DISC_ID_DISC_TITLE))
#define GAMES_IS_GAMEINFO_DISC_ID_DISC_TITLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_GAMEINFO_DISC_ID_DISC_TITLE))
#define GAMES_GAMEINFO_DISC_ID_DISC_TITLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_GAMEINFO_DISC_ID_DISC_TITLE, GamesGameinfoDiscIdDiscTitleClass))

typedef struct _GamesGameinfoDiscIdDiscTitle GamesGameinfoDiscIdDiscTitle;
typedef struct _GamesGameinfoDiscIdDiscTitleClass GamesGameinfoDiscIdDiscTitleClass;
typedef struct _GamesGameinfoDiscIdDiscTitlePrivate GamesGameinfoDiscIdDiscTitlePrivate;

#define GAMES_TYPE_GAMEINFO_DOC (games_gameinfo_doc_get_type ())
#define GAMES_GAMEINFO_DOC(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_GAMEINFO_DOC, GamesGameinfoDoc))
#define GAMES_GAMEINFO_DOC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_GAMEINFO_DOC, GamesGameinfoDocClass))
#define GAMES_IS_GAMEINFO_DOC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_GAMEINFO_DOC))
#define GAMES_IS_GAMEINFO_DOC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_GAMEINFO_DOC))
#define GAMES_GAMEINFO_DOC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_GAMEINFO_DOC, GamesGameinfoDocClass))

typedef struct _GamesGameinfoDoc GamesGameinfoDoc;
typedef struct _GamesGameinfoDocClass GamesGameinfoDocClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _GamesTitleIface {
	GTypeInterface parent_iface;
	gchar* (*get_title) (GamesTitle* self, GError** error);
};

struct _GamesGameinfoDiscIdDiscTitle {
	GObject parent_instance;
	GamesGameinfoDiscIdDiscTitlePrivate * priv;
};

struct _GamesGameinfoDiscIdDiscTitleClass {
	GObjectClass parent_class;
};

struct _GamesGameinfoDiscIdDiscTitlePrivate {
	GamesGameinfoDoc* gameinfo;
	gchar* disc_id;
	gchar* domain;
	gchar* title;
};


static gpointer games_gameinfo_disc_id_disc_title_parent_class = NULL;
static GamesTitleIface * games_gameinfo_disc_id_disc_title_games_title_parent_iface = NULL;

GType games_title_get_type (void) G_GNUC_CONST;
GType games_gameinfo_disc_id_disc_title_get_type (void) G_GNUC_CONST;
GType games_gameinfo_doc_get_type (void) G_GNUC_CONST;
#define GAMES_GAMEINFO_DISC_ID_DISC_TITLE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GAMES_TYPE_GAMEINFO_DISC_ID_DISC_TITLE, GamesGameinfoDiscIdDiscTitlePrivate))
enum  {
	GAMES_GAMEINFO_DISC_ID_DISC_TITLE_0_PROPERTY
};
GamesGameinfoDiscIdDiscTitle* games_gameinfo_disc_id_disc_title_new (GamesGameinfoDoc* gameinfo, const gchar* disc_id, const gchar* domain);
GamesGameinfoDiscIdDiscTitle* games_gameinfo_disc_id_disc_title_construct (GType object_type, GamesGameinfoDoc* gameinfo, const gchar* disc_id, const gchar* domain);
static gchar* games_gameinfo_disc_id_disc_title_real_get_title (GamesTitle* base, GError** error);
gchar* games_gameinfo_doc_get_disc_title_for_disc_id (GamesGameinfoDoc* self, const gchar* disc_id, GError** error);
gint games_gameinfo_doc_get_disc_set_index_for_disc_id (GamesGameinfoDoc* self, const gchar* disc_id, GError** error);
static void games_gameinfo_disc_id_disc_title_finalize (GObject * obj);


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


GamesGameinfoDiscIdDiscTitle* games_gameinfo_disc_id_disc_title_construct (GType object_type, GamesGameinfoDoc* gameinfo, const gchar* disc_id, const gchar* domain) {
	GamesGameinfoDiscIdDiscTitle * self = NULL;
	GamesGameinfoDoc* _tmp0_;
	GamesGameinfoDoc* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	const gchar* _tmp4_;
	gchar* _tmp5_;
	g_return_val_if_fail (gameinfo != NULL, NULL);
	g_return_val_if_fail (disc_id != NULL, NULL);
	self = (GamesGameinfoDiscIdDiscTitle*) g_object_new (object_type, NULL);
	_tmp0_ = gameinfo;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->gameinfo);
	self->priv->gameinfo = _tmp1_;
	_tmp2_ = disc_id;
	_tmp3_ = g_strdup (_tmp2_);
	_g_free0 (self->priv->disc_id);
	self->priv->disc_id = _tmp3_;
	_tmp4_ = domain;
	_tmp5_ = g_strdup (_tmp4_);
	_g_free0 (self->priv->domain);
	self->priv->domain = _tmp5_;
	return self;
}


GamesGameinfoDiscIdDiscTitle* games_gameinfo_disc_id_disc_title_new (GamesGameinfoDoc* gameinfo, const gchar* disc_id, const gchar* domain) {
	return games_gameinfo_disc_id_disc_title_construct (GAMES_TYPE_GAMEINFO_DISC_ID_DISC_TITLE, gameinfo, disc_id, domain);
}


static gchar* games_gameinfo_disc_id_disc_title_real_get_title (GamesTitle* base, GError** error) {
	GamesGameinfoDiscIdDiscTitle * self;
	gchar* result = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp14_;
	const gchar* _tmp15_;
	gchar* _tmp16_;
	GError * _inner_error_ = NULL;
	self = (GamesGameinfoDiscIdDiscTitle*) base;
	_tmp0_ = self->priv->title;
	if (_tmp0_ != NULL) {
		const gchar* _tmp1_;
		const gchar* _tmp2_;
		gchar* _tmp3_;
		_tmp1_ = self->priv->domain;
		_tmp2_ = self->priv->title;
		_tmp3_ = g_strdup (g_dgettext (_tmp1_, _tmp2_));
		result = _tmp3_;
		return result;
	}
	{
		gchar* _tmp4_ = NULL;
		GamesGameinfoDoc* _tmp5_;
		const gchar* _tmp6_;
		gchar* _tmp7_;
		gchar* _tmp8_;
		_tmp5_ = self->priv->gameinfo;
		_tmp6_ = self->priv->disc_id;
		_tmp7_ = games_gameinfo_doc_get_disc_title_for_disc_id (_tmp5_, _tmp6_, &_inner_error_);
		_tmp4_ = _tmp7_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			goto __catch6_g_error;
		}
		_tmp8_ = _tmp4_;
		_tmp4_ = NULL;
		_g_free0 (self->priv->title);
		self->priv->title = _tmp8_;
		_g_free0 (_tmp4_);
	}
	goto __finally6;
	__catch6_g_error:
	{
		GError* e = NULL;
		gint index = 0;
		GamesGameinfoDoc* _tmp9_;
		const gchar* _tmp10_;
		gint _tmp11_;
		gint _tmp12_;
		gchar* _tmp13_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp9_ = self->priv->gameinfo;
		_tmp10_ = self->priv->disc_id;
		_tmp11_ = games_gameinfo_doc_get_disc_set_index_for_disc_id (_tmp9_, _tmp10_, &_inner_error_);
		index = _tmp11_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			_g_error_free0 (e);
			goto __finally6;
		}
		_tmp12_ = index;
		_tmp13_ = g_strdup_printf (_ ("Disc %d"), _tmp12_ + 1);
		_g_free0 (self->priv->title);
		self->priv->title = _tmp13_;
		_g_error_free0 (e);
	}
	__finally6:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		return NULL;
	}
	_tmp14_ = self->priv->domain;
	_tmp15_ = self->priv->title;
	_tmp16_ = g_strdup (g_dgettext (_tmp14_, _tmp15_));
	result = _tmp16_;
	return result;
}


static void games_gameinfo_disc_id_disc_title_class_init (GamesGameinfoDiscIdDiscTitleClass * klass) {
	games_gameinfo_disc_id_disc_title_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GamesGameinfoDiscIdDiscTitlePrivate));
	G_OBJECT_CLASS (klass)->finalize = games_gameinfo_disc_id_disc_title_finalize;
}


static void games_gameinfo_disc_id_disc_title_games_title_interface_init (GamesTitleIface * iface) {
	games_gameinfo_disc_id_disc_title_games_title_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_title = (gchar* (*) (GamesTitle *, GError**)) games_gameinfo_disc_id_disc_title_real_get_title;
}


static void games_gameinfo_disc_id_disc_title_instance_init (GamesGameinfoDiscIdDiscTitle * self) {
	self->priv = GAMES_GAMEINFO_DISC_ID_DISC_TITLE_GET_PRIVATE (self);
}


static void games_gameinfo_disc_id_disc_title_finalize (GObject * obj) {
	GamesGameinfoDiscIdDiscTitle * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_GAMEINFO_DISC_ID_DISC_TITLE, GamesGameinfoDiscIdDiscTitle);
	_g_object_unref0 (self->priv->gameinfo);
	_g_free0 (self->priv->disc_id);
	_g_free0 (self->priv->domain);
	_g_free0 (self->priv->title);
	G_OBJECT_CLASS (games_gameinfo_disc_id_disc_title_parent_class)->finalize (obj);
}


GType games_gameinfo_disc_id_disc_title_get_type (void) {
	static volatile gsize games_gameinfo_disc_id_disc_title_type_id__volatile = 0;
	if (g_once_init_enter (&games_gameinfo_disc_id_disc_title_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (GamesGameinfoDiscIdDiscTitleClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_gameinfo_disc_id_disc_title_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesGameinfoDiscIdDiscTitle), 0, (GInstanceInitFunc) games_gameinfo_disc_id_disc_title_instance_init, NULL };
		static const GInterfaceInfo games_title_info = { (GInterfaceInitFunc) games_gameinfo_disc_id_disc_title_games_title_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		GType games_gameinfo_disc_id_disc_title_type_id;
		games_gameinfo_disc_id_disc_title_type_id = g_type_register_static (G_TYPE_OBJECT, "GamesGameinfoDiscIdDiscTitle", &g_define_type_info, 0);
		g_type_add_interface_static (games_gameinfo_disc_id_disc_title_type_id, GAMES_TYPE_TITLE, &games_title_info);
		g_once_init_leave (&games_gameinfo_disc_id_disc_title_type_id__volatile, games_gameinfo_disc_id_disc_title_type_id);
	}
	return games_gameinfo_disc_id_disc_title_type_id__volatile;
}



