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

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

#include <glib-object.h>
#include "gnome-games.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>
#include "games-love-plugin.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

#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;
enum  {
	GAMES_LOVE_TITLE_0_PROPERTY,
	GAMES_LOVE_TITLE_NUM_PROPERTIES
};
static GParamSpec* games_love_title_properties[GAMES_LOVE_TITLE_NUM_PROPERTIES];
#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)))
#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 gint GamesLoveTitle_private_offset;
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_register_type (GTypeModule * module);
VALA_EXTERN GType games_love_title_get_type (void) G_GNUC_CONST ;
GType games_love_package_register_type (GTypeModule * module);
VALA_EXTERN GType games_love_package_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GamesLoveTitle* games_love_title_new (GamesLovePackage* package);
VALA_EXTERN GamesLoveTitle* games_love_title_construct (GType object_type,
                                            GamesLovePackage* package);
static gchar* games_love_title_real_get_title (GamesTitle* base,
                                        GError** error);
VALA_EXTERN gchar* games_love_package_get_config (GamesLovePackage* self,
                                      const gchar* key);
VALA_EXTERN GamesUri* games_love_package_get_uri (GamesLovePackage* self);
static void games_love_title_finalize (GObject * obj);
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 gssize _vala_array_length (gpointer array);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
games_love_title_get_instance_private (GamesLoveTitle* self)
{
	return G_STRUCT_MEMBER_P (self, GamesLoveTitle_private_offset);
}

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_;
	g_return_val_if_fail (package != NULL, NULL);
	self = (GamesLoveTitle*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (package);
	_g_object_unref0 (self->priv->package);
	self->priv->package = _tmp0_;
	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* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	g_strstrip (_result_);
	result = _result_;
	return result;
}

static gchar*
games_love_title_real_get_title (GamesTitle* base,
                                 GError** error)
{
	GamesLoveTitle * self;
	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_;
	const gchar* _tmp26_;
	gchar** _tmp27_;
	gchar** _tmp28_;
	gchar** _tmp29_;
	gint _tmp29__length1;
	const gchar* _tmp30_;
	gchar* _tmp31_;
	const gchar* _tmp32_;
	gchar** _tmp33_;
	gchar** _tmp34_;
	gchar** _tmp35_;
	gint _tmp35__length1;
	const gchar* _tmp36_;
	gchar* _tmp37_;
	const gchar* _tmp38_;
	gchar* _tmp39_;
	const gchar* _tmp40_;
	gchar* _tmp41_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	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_;
	{
		GFileInfo* fileinfo = NULL;
		GFile* _tmp17_;
		GFileInfo* _tmp18_;
		GFileInfo* _tmp19_;
		const gchar* _tmp20_;
		gchar* _tmp21_;
		_tmp17_ = file;
		_tmp18_ = g_file_query_info (_tmp17_, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, G_FILE_QUERY_INFO_NONE, NULL, &_inner_error0_);
		fileinfo = _tmp18_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp19_ = fileinfo;
		_tmp20_ = g_file_info_get_display_name (_tmp19_);
		_tmp21_ = g_strdup (_tmp20_);
		_g_free0 (self->priv->title);
		self->priv->title = _tmp21_;
		_g_object_unref0 (fileinfo);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp22_;
		const gchar* _tmp23_;
		GFile* _tmp24_;
		gchar* _tmp25_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp22_ = e;
		_tmp23_ = _tmp22_->message;
		g_critical ("love-title.vala:32: Couldn't retrieve filename: %s", _tmp23_);
		_tmp24_ = file;
		_tmp25_ = g_file_get_basename (_tmp24_);
		_g_free0 (self->priv->title);
		self->priv->title = _tmp25_;
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (file);
		_games_uri_unref0 (uri);
		return NULL;
	}
	_tmp26_ = self->priv->title;
	_tmp28_ = _tmp27_ = g_strsplit (_tmp26_, ".", 0);
	_tmp29_ = _tmp28_;
	_tmp29__length1 = _vala_array_length (_tmp27_);
	_tmp30_ = _tmp29_[0];
	_tmp31_ = g_strdup (_tmp30_);
	_g_free0 (self->priv->title);
	self->priv->title = _tmp31_;
	_tmp29_ = (_vala_array_free (_tmp29_, _tmp29__length1, (GDestroyNotify) g_free), NULL);
	_tmp32_ = self->priv->title;
	_tmp34_ = _tmp33_ = g_strsplit (_tmp32_, "(", 0);
	_tmp35_ = _tmp34_;
	_tmp35__length1 = _vala_array_length (_tmp33_);
	_tmp36_ = _tmp35_[0];
	_tmp37_ = g_strdup (_tmp36_);
	_g_free0 (self->priv->title);
	self->priv->title = _tmp37_;
	_tmp35_ = (_vala_array_free (_tmp35_, _tmp35__length1, (GDestroyNotify) g_free), NULL);
	_tmp38_ = self->priv->title;
	_tmp39_ = string_strip (_tmp38_);
	_g_free0 (self->priv->title);
	self->priv->title = _tmp39_;
	_tmp40_ = self->priv->title;
	_tmp41_ = g_strdup (_tmp40_);
	result = _tmp41_;
	_g_object_unref0 (file);
	_games_uri_unref0 (uri);
	return result;
}

static void
games_love_title_class_init (GamesLoveTitleClass * klass,
                             gpointer klass_data)
{
	games_love_title_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GamesLoveTitle_private_offset);
	G_OBJECT_CLASS (klass)->finalize = games_love_title_finalize;
}

static void
games_love_title_games_title_interface_init (GamesTitleIface * iface,
                                             gpointer iface_data)
{
	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,
                                gpointer klass)
{
	self->priv = games_love_title_get_instance_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);
	GamesLoveTitle_private_offset = sizeof (GamesLoveTitlePrivate);
	return games_love_title_type_id;
}

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 gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

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

