/* filename-title.c generated by valac 0.36.6.6-c7bee, the Vala compiler
 * generated from filename-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 <gio/gio.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_FILENAME_TITLE (games_filename_title_get_type ())
#define GAMES_FILENAME_TITLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_FILENAME_TITLE, GamesFilenameTitle))
#define GAMES_FILENAME_TITLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_FILENAME_TITLE, GamesFilenameTitleClass))
#define GAMES_IS_FILENAME_TITLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_FILENAME_TITLE))
#define GAMES_IS_FILENAME_TITLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_FILENAME_TITLE))
#define GAMES_FILENAME_TITLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_FILENAME_TITLE, GamesFilenameTitleClass))

typedef struct _GamesFilenameTitle GamesFilenameTitle;
typedef struct _GamesFilenameTitleClass GamesFilenameTitleClass;
typedef struct _GamesFilenameTitlePrivate GamesFilenameTitlePrivate;

#define GAMES_TYPE_URI (games_uri_get_type ())
#define GAMES_URI(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_URI, GamesUri))
#define GAMES_URI_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_URI, GamesUriClass))
#define GAMES_IS_URI(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_URI))
#define GAMES_IS_URI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_URI))
#define GAMES_URI_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_URI, GamesUriClass))

typedef struct _GamesUri GamesUri;
typedef struct _GamesUriClass GamesUriClass;
#define _games_uri_unref0(var) ((var == NULL) ? NULL : (var = (games_uri_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))

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

struct _GamesFilenameTitle {
	GObject parent_instance;
	GamesFilenameTitlePrivate * priv;
};

struct _GamesFilenameTitleClass {
	GObjectClass parent_class;
};

struct _GamesFilenameTitlePrivate {
	GamesUri* uri;
};


static gpointer games_filename_title_parent_class = NULL;
static GRegex* games_filename_title_filename_ext_regex;
static GRegex* games_filename_title_filename_ext_regex = NULL;
static GamesTitleIface * games_filename_title_games_title_parent_iface = NULL;

GType games_title_get_type (void) G_GNUC_CONST;
GType games_filename_title_get_type (void) G_GNUC_CONST;
gpointer games_uri_ref (gpointer instance);
void games_uri_unref (gpointer instance);
GParamSpec* games_param_spec_uri (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void games_value_set_uri (GValue* value, gpointer v_object);
void games_value_take_uri (GValue* value, gpointer v_object);
gpointer games_value_get_uri (const GValue* value);
GType games_uri_get_type (void) G_GNUC_CONST;
#define GAMES_FILENAME_TITLE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GAMES_TYPE_FILENAME_TITLE, GamesFilenameTitlePrivate))
enum  {
	GAMES_FILENAME_TITLE_0_PROPERTY
};
GamesFilenameTitle* games_filename_title_new (GamesUri* uri);
GamesFilenameTitle* games_filename_title_construct (GType object_type, GamesUri* uri);
static gchar* games_filename_title_real_get_title (GamesTitle* base, GError** error);
GFile* games_uri_to_file (GamesUri* self);
static void games_filename_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 GRegex* _tmp_regex_0 = NULL;

static gpointer _games_uri_ref0 (gpointer self) {
	return self ? games_uri_ref (self) : NULL;
}


GamesFilenameTitle* games_filename_title_construct (GType object_type, GamesUri* uri) {
	GamesFilenameTitle * self = NULL;
	GamesUri* _tmp0_;
	GamesUri* _tmp1_;
	g_return_val_if_fail (uri != NULL, NULL);
	self = (GamesFilenameTitle*) g_object_new (object_type, NULL);
	_tmp0_ = uri;
	_tmp1_ = _games_uri_ref0 (_tmp0_);
	_games_uri_unref0 (self->priv->uri);
	self->priv->uri = _tmp1_;
	return self;
}


GamesFilenameTitle* games_filename_title_new (GamesUri* uri) {
	return games_filename_title_construct (GAMES_TYPE_FILENAME_TITLE, uri);
}


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_filename_title_real_get_title (GamesTitle* base, GError** error) {
	GamesFilenameTitle * self;
	gchar* result = NULL;
	GFile* file = NULL;
	GamesUri* _tmp0_;
	GFile* _tmp1_;
	gchar* name = NULL;
	gchar* _tmp2_;
	gchar* _tmp3_ = NULL;
	GRegex* _tmp4_;
	const gchar* _tmp5_;
	const gchar* _tmp6_;
	gint _tmp7_;
	gint _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	const gchar* _tmp11_;
	gchar** _tmp12_;
	gchar** _tmp13_;
	gchar** _tmp14_;
	gint _tmp14__length1;
	const gchar* _tmp15_;
	gchar* _tmp16_;
	const gchar* _tmp17_;
	gchar* _tmp18_;
	GError * _inner_error_ = NULL;
	self = (GamesFilenameTitle*) base;
	_tmp0_ = self->priv->uri;
	_tmp1_ = games_uri_to_file (_tmp0_);
	file = _tmp1_;
	_tmp2_ = g_file_get_basename (file);
	name = _tmp2_;
	_tmp4_ = games_filename_title_filename_ext_regex;
	_tmp5_ = name;
	_tmp6_ = name;
	_tmp7_ = strlen (_tmp6_);
	_tmp8_ = _tmp7_;
	_tmp9_ = g_regex_replace (_tmp4_, _tmp5_, (gssize) _tmp8_, 0, "", 0, &_inner_error_);
	_tmp3_ = _tmp9_;
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_g_free0 (name);
		_g_object_unref0 (file);
		return NULL;
	}
	_tmp10_ = _tmp3_;
	_tmp3_ = NULL;
	_g_free0 (name);
	name = _tmp10_;
	_tmp11_ = name;
	_tmp13_ = _tmp12_ = g_strsplit (_tmp11_, "(", 0);
	_tmp14_ = _tmp13_;
	_tmp14__length1 = _vala_array_length (_tmp12_);
	_tmp15_ = _tmp14_[0];
	_tmp16_ = g_strdup (_tmp15_);
	_g_free0 (name);
	name = _tmp16_;
	_tmp14_ = (_vala_array_free (_tmp14_, _tmp14__length1, (GDestroyNotify) g_free), NULL);
	_tmp17_ = name;
	_tmp18_ = string_strip (_tmp17_);
	_g_free0 (name);
	name = _tmp18_;
	result = name;
	_g_free0 (_tmp3_);
	_g_object_unref0 (file);
	return result;
}


static inline GRegex* _thread_safe_regex_init (GRegex** re, const gchar * pattern, GRegexMatchFlags match_options) {
	if (g_once_init_enter ((volatile gsize*) re)) {
		GRegex* val = g_regex_new (pattern, match_options, 0, NULL);
		g_once_init_leave ((volatile gsize*) re, (gsize) val);
	}
	return *re;
}


static gpointer _g_regex_ref0 (gpointer self) {
	return self ? g_regex_ref (self) : NULL;
}


static void games_filename_title_class_init (GamesFilenameTitleClass * klass) {
	GRegex* _tmp0_;
	games_filename_title_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GamesFilenameTitlePrivate));
	G_OBJECT_CLASS (klass)->finalize = games_filename_title_finalize;
	_tmp0_ = _g_regex_ref0 (_thread_safe_regex_init (&_tmp_regex_0, "\\.\\w+$", 0));
	_g_regex_unref0 (games_filename_title_filename_ext_regex);
	games_filename_title_filename_ext_regex = _tmp0_;
}


static void games_filename_title_games_title_interface_init (GamesTitleIface * iface) {
	games_filename_title_games_title_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_title = (gchar* (*) (GamesTitle *, GError**)) games_filename_title_real_get_title;
}


static void games_filename_title_instance_init (GamesFilenameTitle * self) {
	self->priv = GAMES_FILENAME_TITLE_GET_PRIVATE (self);
}


static void games_filename_title_finalize (GObject * obj) {
	GamesFilenameTitle * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_FILENAME_TITLE, GamesFilenameTitle);
	_games_uri_unref0 (self->priv->uri);
	G_OBJECT_CLASS (games_filename_title_parent_class)->finalize (obj);
}


GType games_filename_title_get_type (void) {
	static volatile gsize games_filename_title_type_id__volatile = 0;
	if (g_once_init_enter (&games_filename_title_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (GamesFilenameTitleClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_filename_title_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesFilenameTitle), 0, (GInstanceInitFunc) games_filename_title_instance_init, NULL };
		static const GInterfaceInfo games_title_info = { (GInterfaceInitFunc) games_filename_title_games_title_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		GType games_filename_title_type_id;
		games_filename_title_type_id = g_type_register_static (G_TYPE_OBJECT, "GamesFilenameTitle", &g_define_type_info, 0);
		g_type_add_interface_static (games_filename_title_type_id, GAMES_TYPE_TITLE, &games_title_info);
		g_once_init_leave (&games_filename_title_type_id__volatile, games_filename_title_type_id);
	}
	return games_filename_title_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);
}


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



