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

/* This file is part of GNOME Games. License: GPLv3*/

#include <glib.h>
#include <glib-object.h>
#include <libgnome-games.h>
#include <stdlib.h>
#include <string.h>
#include <libtracker-sparql/tracker-sparql.h>


#define GAMES_TYPE_LOVE_PLUGIN (games_love_plugin_get_type ())
#define GAMES_LOVE_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_LOVE_PLUGIN, GamesLovePlugin))
#define GAMES_LOVE_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_LOVE_PLUGIN, GamesLovePluginClass))
#define GAMES_IS_LOVE_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_LOVE_PLUGIN))
#define GAMES_IS_LOVE_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_LOVE_PLUGIN))
#define GAMES_LOVE_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_LOVE_PLUGIN, GamesLovePluginClass))

typedef struct _GamesLovePlugin GamesLovePlugin;
typedef struct _GamesLovePluginClass GamesLovePluginClass;
typedef struct _GamesLovePluginPrivate GamesLovePluginPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

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

#define GAMES_TYPE_LOVE_ICON (games_love_icon_get_type ())
#define GAMES_LOVE_ICON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_LOVE_ICON, GamesLoveIcon))
#define GAMES_LOVE_ICON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_LOVE_ICON, GamesLoveIconClass))
#define GAMES_IS_LOVE_ICON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_LOVE_ICON))
#define GAMES_IS_LOVE_ICON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_LOVE_ICON))
#define GAMES_LOVE_ICON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_LOVE_ICON, GamesLoveIconClass))

typedef struct _GamesLoveIcon GamesLoveIcon;
typedef struct _GamesLoveIconClass GamesLoveIconClass;

struct _GamesLovePlugin {
	GObject parent_instance;
	GamesLovePluginPrivate * priv;
};

struct _GamesLovePluginClass {
	GObjectClass parent_class;
};


static gpointer games_love_plugin_parent_class = NULL;
static GamesPluginIface * games_love_plugin_games_plugin_parent_iface = NULL;
static GType games_love_plugin_type_id = 0;

GType games_love_plugin_get_type (void) G_GNUC_CONST;
enum  {
	GAMES_LOVE_PLUGIN_DUMMY_PROPERTY
};
#define GAMES_LOVE_PLUGIN_MIME_TYPE "application/x-love-game"
static GamesGameSource* games_love_plugin_real_get_game_source (GamesPlugin* base, GError** error);
static GamesGame* games_love_plugin_game_for_uri (const gchar* uri, GError** error);
static GamesGame* _games_love_plugin_game_for_uri_games_generic_sync_game_uri_adapter_game_for_uri (const gchar* uri, gpointer self, GError** error);
GType games_love_package_get_type (void) G_GNUC_CONST;
GamesLovePackage* games_love_package_new (const gchar* uri, GError** error);
GamesLovePackage* games_love_package_construct (GType object_type, const gchar* uri, GError** error);
GType games_love_title_get_type (void) G_GNUC_CONST;
GamesLoveTitle* games_love_title_new (GamesLovePackage* package);
GamesLoveTitle* games_love_title_construct (GType object_type, GamesLovePackage* package);
GType games_love_icon_get_type (void) G_GNUC_CONST;
GamesLoveIcon* games_love_icon_new (GamesLovePackage* package);
GamesLoveIcon* games_love_icon_construct (GType object_type, GamesLovePackage* package);
GamesLovePlugin* games_love_plugin_new (void);
GamesLovePlugin* games_love_plugin_construct (GType object_type);
GType register_games_plugin (GTypeModule* module);
GType games_love_icon_register_type (GTypeModule * module);
GType games_love_package_register_type (GTypeModule * module);
GType games_love_plugin_register_type (GTypeModule * module);
GType games_love_title_register_type (GTypeModule * module);
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 GamesGame* _games_love_plugin_game_for_uri_games_generic_sync_game_uri_adapter_game_for_uri (const gchar* uri, gpointer self, GError** error) {
	GamesGame* result;
	result = games_love_plugin_game_for_uri (uri, error);
	return result;
}


static GamesGameSource* games_love_plugin_real_get_game_source (GamesPlugin* base, GError** error) {
	GamesLovePlugin * self;
	GamesGameSource* result = NULL;
	GamesGenericSyncGameUriAdapter* game_uri_adapter;
	GamesGenericSyncGameUriAdapter* _tmp0_;
	GamesGenericUriGameFactory* factory;
	GamesGenericUriGameFactory* _tmp1_;
	GamesMimeTypeTrackerQuery* query;
	GamesMimeTypeTrackerQuery* _tmp2_;
	TrackerSparqlConnection* connection;
	TrackerSparqlConnection* _tmp3_;
	GamesTrackerGameSource* source;
	GamesTrackerGameSource* _tmp4_;
	GamesTrackerGameSource* _tmp5_;
	GError * _inner_error_ = NULL;
	self = (GamesLovePlugin*) base;
	_tmp0_ = games_generic_sync_game_uri_adapter_new (_games_love_plugin_game_for_uri_games_generic_sync_game_uri_adapter_game_for_uri, NULL, NULL);
	game_uri_adapter = _tmp0_;
	_tmp1_ = games_generic_uri_game_factory_new ((GamesGameUriAdapter*) game_uri_adapter, NULL, NULL, NULL);
	factory = _tmp1_;
	_tmp2_ = games_mime_type_tracker_query_new (GAMES_LOVE_PLUGIN_MIME_TYPE, (GamesUriGameFactory*) factory);
	query = _tmp2_;
	_tmp3_ = tracker_sparql_connection_get (NULL, &_inner_error_);
	connection = _tmp3_;
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_g_object_unref0 (query);
		_g_object_unref0 (factory);
		_g_object_unref0 (game_uri_adapter);
		return NULL;
	}
	_tmp4_ = games_tracker_game_source_new (connection);
	source = _tmp4_;
	_tmp5_ = source;
	games_tracker_game_source_add_query (_tmp5_, (GamesTrackerQuery*) query);
	result = (GamesGameSource*) source;
	_g_object_unref0 (connection);
	_g_object_unref0 (query);
	_g_object_unref0 (factory);
	_g_object_unref0 (game_uri_adapter);
	return result;
}


static GamesGame* games_love_plugin_game_for_uri (const gchar* uri, GError** error) {
	GamesGame* result = NULL;
	GamesLovePackage* package;
	const gchar* _tmp0_;
	GamesLovePackage* _tmp1_;
	GamesLoveTitle* title;
	GamesLoveTitle* _tmp2_;
	GamesLoveIcon* icon;
	GamesLoveIcon* _tmp3_;
	GamesLocalCover* cover;
	const gchar* _tmp4_;
	GamesLocalCover* _tmp5_;
	gchar** args;
	gchar* _tmp6_;
	const gchar* _tmp7_;
	gchar* _tmp8_;
	gchar** _tmp9_;
	gint args_length1;
	gint _args_size_;
	GamesCommandRunner* runner;
	gchar** _tmp10_;
	gint _tmp10__length1;
	GamesCommandRunner* _tmp11_;
	GamesLoveTitle* _tmp12_;
	GamesLoveIcon* _tmp13_;
	GamesLocalCover* _tmp14_;
	GamesCommandRunner* _tmp15_;
	GamesGenericGame* _tmp16_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (uri != NULL, NULL);
	_tmp0_ = uri;
	_tmp1_ = games_love_package_new (_tmp0_, &_inner_error_);
	package = _tmp1_;
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		return NULL;
	}
	_tmp2_ = games_love_title_new (package);
	title = _tmp2_;
	_tmp3_ = games_love_icon_new (package);
	icon = _tmp3_;
	_tmp4_ = uri;
	_tmp5_ = games_local_cover_new (_tmp4_);
	cover = _tmp5_;
	_tmp6_ = g_strdup ("love");
	_tmp7_ = uri;
	_tmp8_ = g_strdup (_tmp7_);
	_tmp9_ = g_new0 (gchar*, 2 + 1);
	_tmp9_[0] = _tmp6_;
	_tmp9_[1] = _tmp8_;
	args = _tmp9_;
	args_length1 = 2;
	_args_size_ = args_length1;
	_tmp10_ = args;
	_tmp10__length1 = args_length1;
	_tmp11_ = games_command_runner_new (_tmp10_, _tmp10__length1, TRUE);
	runner = _tmp11_;
	_tmp12_ = title;
	_tmp13_ = icon;
	_tmp14_ = cover;
	_tmp15_ = runner;
	_tmp16_ = games_generic_game_new ((GamesTitle*) _tmp12_, (GamesIcon*) _tmp13_, (GamesCover*) _tmp14_, (GamesRunner*) _tmp15_);
	result = (GamesGame*) _tmp16_;
	_g_object_unref0 (runner);
	args = (_vala_array_free (args, args_length1, (GDestroyNotify) g_free), NULL);
	_g_object_unref0 (cover);
	_g_object_unref0 (icon);
	_g_object_unref0 (title);
	_g_object_unref0 (package);
	return result;
}


GamesLovePlugin* games_love_plugin_construct (GType object_type) {
	GamesLovePlugin * self = NULL;
	self = (GamesLovePlugin*) g_object_new (object_type, NULL);
	return self;
}


GamesLovePlugin* games_love_plugin_new (void) {
	return games_love_plugin_construct (GAMES_TYPE_LOVE_PLUGIN);
}


static void games_love_plugin_class_init (GamesLovePluginClass * klass) {
	games_love_plugin_parent_class = g_type_class_peek_parent (klass);
}


static void games_love_plugin_games_plugin_interface_init (GamesPluginIface * iface) {
	games_love_plugin_games_plugin_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_game_source = (GamesGameSource* (*) (GamesPlugin *, GError**)) games_love_plugin_real_get_game_source;
}


static void games_love_plugin_instance_init (GamesLovePlugin * self) {
}


GType games_love_plugin_get_type (void) {
	return games_love_plugin_type_id;
}


GType games_love_plugin_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (GamesLovePluginClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_love_plugin_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesLovePlugin), 0, (GInstanceInitFunc) games_love_plugin_instance_init, NULL };
	static const GInterfaceInfo games_plugin_info = { (GInterfaceInitFunc) games_love_plugin_games_plugin_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	games_love_plugin_type_id = g_type_module_register_type (module, G_TYPE_OBJECT, "GamesLovePlugin", &g_define_type_info, 0);
	g_type_module_add_interface (module, games_love_plugin_type_id, GAMES_TYPE_PLUGIN, &games_plugin_info);
	return games_love_plugin_type_id;
}


GType register_games_plugin (GTypeModule* module) {
	GType result = 0UL;
	g_return_val_if_fail (module != NULL, 0UL);
	games_love_icon_register_type (module);
	games_love_package_register_type (module);
	games_love_plugin_register_type (module);
	games_love_title_register_type (module);
	result = GAMES_TYPE_LOVE_PLUGIN;
	return result;
}


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



