/* love-title.c generated by valac 0.36.9, the Vala compiler
 * generated from love-title.vala, do not modify */

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

#include <glib.h>
#include <glib-object.h>
#include <libgnome-games.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>


#define GAMES_TYPE_LOVE_TITLE (games_love_title_get_type ())
#define GAMES_LOVE_TITLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_LOVE_TITLE, GamesLoveTitle))
#define GAMES_LOVE_TITLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_LOVE_TITLE, GamesLoveTitleClass))
#define GAMES_IS_LOVE_TITLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_LOVE_TITLE))
#define GAMES_IS_LOVE_TITLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_LOVE_TITLE))
#define GAMES_LOVE_TITLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_LOVE_TITLE, GamesLoveTitleClass))

typedef struct _GamesLoveTitle GamesLoveTitle;
typedef struct _GamesLoveTitleClass GamesLoveTitleClass;
typedef struct _GamesLoveTitlePrivate GamesLoveTitlePrivate;

#define GAMES_TYPE_LOVE_PACKAGE (games_love_package_get_type ())
#define GAMES_LOVE_PACKAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_LOVE_PACKAGE, GamesLovePackage))
#define GAMES_LOVE_PACKAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_LOVE_PACKAGE, GamesLovePackageClass))
#define GAMES_IS_LOVE_PACKAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_LOVE_PACKAGE))
#define GAMES_IS_LOVE_PACKAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_LOVE_PACKAGE))
#define GAMES_LOVE_PACKAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_LOVE_PACKAGE, GamesLovePackageClass))

typedef struct _GamesLovePackage GamesLovePackage;
typedef struct _GamesLovePackageClass GamesLovePackageClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _games_uri_unref0(var) ((var == NULL) ? NULL : (var = (games_uri_unref (var), NULL)))

struct _GamesLoveTitle {
	GObject parent_instance;
	GamesLoveTitlePrivate * priv;
};

struct _GamesLoveTitleClass {
	GObjectClass parent_class;
};

struct _GamesLoveTitlePrivate {
	GamesLovePackage* package;
	gchar* title;
};


static gpointer games_love_title_parent_class = NULL;
static GamesTitleIface * games_love_title_games_title_parent_iface = NULL;
static GType games_love_title_type_id = 0;

GType games_love_title_get_type (void) G_GNUC_CONST;
GType games_love_package_get_type (void) G_GNUC_CONST;
#define GAMES_LOVE_TITLE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GAMES_TYPE_LOVE_TITLE, GamesLoveTitlePrivate))
enum  {
	GAMES_LOVE_TITLE_0_PROPERTY
};
GamesLoveTitle* games_love_title_new (GamesLovePackage* package);
GamesLoveTitle* games_love_title_construct (GType object_type, GamesLovePackage* package);
static gchar* games_love_title_real_get_title (GamesTitle* base, GError** error);
gchar* games_love_package_get_config (GamesLovePackage* self, const gchar* key);
GamesUri* games_love_package_get_uri (GamesLovePackage* self);
static void games_love_title_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 gint _vala_array_length (gpointer array);


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


GamesLoveTitle* games_love_title_construct (GType object_type, GamesLovePackage* package) {
	GamesLoveTitle * self = NULL;
	GamesLovePackage* _tmp0_;
	GamesLovePackage* _tmp1_;
	g_return_val_if_fail (package != NULL, NULL);
	self = (GamesLoveTitle*) g_object_new (object_type, NULL);
	_tmp0_ = package;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->package);
	self->priv->package = _tmp1_;
	return self;
}


GamesLoveTitle* games_love_title_new (GamesLovePackage* package) {
	return games_love_title_construct (GAMES_TYPE_LOVE_TITLE, package);
}


static gchar* string_strip (const gchar* self) {
	gchar* result = NULL;
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	_tmp1_ = _result_;
	g_strstrip (_tmp1_);
	result = _result_;
	return result;
}


static gchar* games_love_title_real_get_title (GamesTitle* base, GError** error) {
	GamesLoveTitle * self;
	gchar* result = NULL;
	const gchar* _tmp0_;
	GamesLovePackage* _tmp3_;
	gchar* _tmp4_;
	const gchar* _tmp5_;
	GamesLovePackage* _tmp8_;
	gchar* _tmp9_;
	const gchar* _tmp10_;
	GamesUri* uri = NULL;
	GamesLovePackage* _tmp13_;
	GamesUri* _tmp14_;
	GFile* file = NULL;
	GamesUri* _tmp15_;
	GFile* _tmp16_;
	GFile* _tmp17_;
	gchar* _tmp18_;
	const gchar* _tmp19_;
	gchar** _tmp20_;
	gchar** _tmp21_;
	gchar** _tmp22_;
	gint _tmp22__length1;
	const gchar* _tmp23_;
	gchar* _tmp24_;
	const gchar* _tmp25_;
	gchar** _tmp26_;
	gchar** _tmp27_;
	gchar** _tmp28_;
	gint _tmp28__length1;
	const gchar* _tmp29_;
	gchar* _tmp30_;
	const gchar* _tmp31_;
	gchar* _tmp32_;
	const gchar* _tmp33_;
	gchar* _tmp34_;
	self = (GamesLoveTitle*) base;
	_tmp0_ = self->priv->title;
	if (_tmp0_ != NULL) {
		const gchar* _tmp1_;
		gchar* _tmp2_;
		_tmp1_ = self->priv->title;
		_tmp2_ = g_strdup (_tmp1_);
		result = _tmp2_;
		return result;
	}
	_tmp3_ = self->priv->package;
	_tmp4_ = games_love_package_get_config (_tmp3_, "title");
	_g_free0 (self->priv->title);
	self->priv->title = _tmp4_;
	_tmp5_ = self->priv->title;
	if (_tmp5_ != NULL) {
		const gchar* _tmp6_;
		gchar* _tmp7_;
		_tmp6_ = self->priv->title;
		_tmp7_ = g_strdup (_tmp6_);
		result = _tmp7_;
		return result;
	}
	_tmp8_ = self->priv->package;
	_tmp9_ = games_love_package_get_config (_tmp8_, "identity");
	_g_free0 (self->priv->title);
	self->priv->title = _tmp9_;
	_tmp10_ = self->priv->title;
	if (_tmp10_ != NULL) {
		const gchar* _tmp11_;
		gchar* _tmp12_;
		_tmp11_ = self->priv->title;
		_tmp12_ = g_strdup (_tmp11_);
		result = _tmp12_;
		return result;
	}
	_tmp13_ = self->priv->package;
	_tmp14_ = games_love_package_get_uri (_tmp13_);
	uri = _tmp14_;
	_tmp15_ = uri;
	_tmp16_ = games_uri_to_file (_tmp15_);
	file = _tmp16_;
	_tmp17_ = file;
	_tmp18_ = g_file_get_basename (_tmp17_);
	_g_free0 (self->priv->title);
	self->priv->title = _tmp18_;
	_tmp19_ = self->priv->title;
	_tmp21_ = _tmp20_ = g_strsplit (_tmp19_, ".", 0);
	_tmp22_ = _tmp21_;
	_tmp22__length1 = _vala_array_length (_tmp20_);
	_tmp23_ = _tmp22_[0];
	_tmp24_ = g_strdup (_tmp23_);
	_g_free0 (self->priv->title);
	self->priv->title = _tmp24_;
	_tmp22_ = (_vala_array_free (_tmp22_, _tmp22__length1, (GDestroyNotify) g_free), NULL);
	_tmp25_ = self->priv->title;
	_tmp27_ = _tmp26_ = g_strsplit (_tmp25_, "(", 0);
	_tmp28_ = _tmp27_;
	_tmp28__length1 = _vala_array_length (_tmp26_);
	_tmp29_ = _tmp28_[0];
	_tmp30_ = g_strdup (_tmp29_);
	_g_free0 (self->priv->title);
	self->priv->title = _tmp30_;
	_tmp28_ = (_vala_array_free (_tmp28_, _tmp28__length1, (GDestroyNotify) g_free), NULL);
	_tmp31_ = self->priv->title;
	_tmp32_ = string_strip (_tmp31_);
	_g_free0 (self->priv->title);
	self->priv->title = _tmp32_;
	_tmp33_ = self->priv->title;
	_tmp34_ = g_strdup (_tmp33_);
	result = _tmp34_;
	_g_object_unref0 (file);
	_games_uri_unref0 (uri);
	return result;
}


static void games_love_title_class_init (GamesLoveTitleClass * klass) {
	games_love_title_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GamesLoveTitlePrivate));
	G_OBJECT_CLASS (klass)->finalize = games_love_title_finalize;
}


static void games_love_title_games_title_interface_init (GamesTitleIface * iface) {
	games_love_title_games_title_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_title = (gchar* (*) (GamesTitle *, GError**)) games_love_title_real_get_title;
}


static void games_love_title_instance_init (GamesLoveTitle * self) {
	self->priv = GAMES_LOVE_TITLE_GET_PRIVATE (self);
}


static void games_love_title_finalize (GObject * obj) {
	GamesLoveTitle * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_LOVE_TITLE, GamesLoveTitle);
	_g_object_unref0 (self->priv->package);
	_g_free0 (self->priv->title);
	G_OBJECT_CLASS (games_love_title_parent_class)->finalize (obj);
}


GType games_love_title_get_type (void) {
	return games_love_title_type_id;
}


GType games_love_title_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (GamesLoveTitleClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_love_title_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesLoveTitle), 0, (GInstanceInitFunc) games_love_title_instance_init, NULL };
	static const GInterfaceInfo games_title_info = { (GInterfaceInitFunc) games_love_title_games_title_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	games_love_title_type_id = g_type_module_register_type (module, G_TYPE_OBJECT, "GamesLoveTitle", &g_define_type_info, 0);
	g_type_module_add_interface (module, games_love_title_type_id, GAMES_TYPE_TITLE, &games_title_info);
	return games_love_title_type_id;
}


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


static gint _vala_array_length (gpointer array) {
	int length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}



