/* PythonChecker.c generated by valac 0.30.0, the Vala compiler
 * generated from PythonChecker.vala, do not modify */

/* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 2 -*- */
/*
    This file is part of Déjà Dup.
    For copyright information, see AUTHORS.

    Déjà Dup is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Déjà Dup is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Déjà Dup.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>


#define DEJA_DUP_TYPE_CHECKER (deja_dup_checker_get_type ())
#define DEJA_DUP_CHECKER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DEJA_DUP_TYPE_CHECKER, DejaDupChecker))
#define DEJA_DUP_CHECKER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DEJA_DUP_TYPE_CHECKER, DejaDupCheckerClass))
#define DEJA_DUP_IS_CHECKER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DEJA_DUP_TYPE_CHECKER))
#define DEJA_DUP_IS_CHECKER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DEJA_DUP_TYPE_CHECKER))
#define DEJA_DUP_CHECKER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DEJA_DUP_TYPE_CHECKER, DejaDupCheckerClass))

typedef struct _DejaDupChecker DejaDupChecker;
typedef struct _DejaDupCheckerClass DejaDupCheckerClass;
typedef struct _DejaDupCheckerPrivate DejaDupCheckerPrivate;

#define DEJA_DUP_TYPE_PYTHON_CHECKER (deja_dup_python_checker_get_type ())
#define DEJA_DUP_PYTHON_CHECKER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DEJA_DUP_TYPE_PYTHON_CHECKER, DejaDupPythonChecker))
#define DEJA_DUP_PYTHON_CHECKER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DEJA_DUP_TYPE_PYTHON_CHECKER, DejaDupPythonCheckerClass))
#define DEJA_DUP_IS_PYTHON_CHECKER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DEJA_DUP_TYPE_PYTHON_CHECKER))
#define DEJA_DUP_IS_PYTHON_CHECKER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DEJA_DUP_TYPE_PYTHON_CHECKER))
#define DEJA_DUP_PYTHON_CHECKER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DEJA_DUP_TYPE_PYTHON_CHECKER, DejaDupPythonCheckerClass))

typedef struct _DejaDupPythonChecker DejaDupPythonChecker;
typedef struct _DejaDupPythonCheckerClass DejaDupPythonCheckerClass;
typedef struct _DejaDupPythonCheckerPrivate DejaDupPythonCheckerPrivate;

#define DEJA_DUP_TYPE_ASYNC_COMMAND (deja_dup_async_command_get_type ())
#define DEJA_DUP_ASYNC_COMMAND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DEJA_DUP_TYPE_ASYNC_COMMAND, DejaDupAsyncCommand))
#define DEJA_DUP_ASYNC_COMMAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DEJA_DUP_TYPE_ASYNC_COMMAND, DejaDupAsyncCommandClass))
#define DEJA_DUP_IS_ASYNC_COMMAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DEJA_DUP_TYPE_ASYNC_COMMAND))
#define DEJA_DUP_IS_ASYNC_COMMAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DEJA_DUP_TYPE_ASYNC_COMMAND))
#define DEJA_DUP_ASYNC_COMMAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DEJA_DUP_TYPE_ASYNC_COMMAND, DejaDupAsyncCommandClass))

typedef struct _DejaDupAsyncCommand DejaDupAsyncCommand;
typedef struct _DejaDupAsyncCommandClass DejaDupAsyncCommandClass;
#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_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))

struct _DejaDupChecker {
	GObject parent_instance;
	DejaDupCheckerPrivate * priv;
};

struct _DejaDupCheckerClass {
	GObjectClass parent_class;
};

struct _DejaDupPythonChecker {
	DejaDupChecker parent_instance;
	DejaDupPythonCheckerPrivate * priv;
};

struct _DejaDupPythonCheckerClass {
	DejaDupCheckerClass parent_class;
};

struct _DejaDupPythonCheckerPrivate {
	gchar* _module;
	DejaDupAsyncCommand* cmd;
};


static gpointer deja_dup_python_checker_parent_class = NULL;
static GHashTable* deja_dup_python_checker_modules;
static GHashTable* deja_dup_python_checker_modules = NULL;

GType deja_dup_checker_get_type (void) G_GNUC_CONST;
GType deja_dup_python_checker_get_type (void) G_GNUC_CONST;
GType deja_dup_async_command_get_type (void) G_GNUC_CONST;
#define DEJA_DUP_PYTHON_CHECKER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DEJA_DUP_TYPE_PYTHON_CHECKER, DejaDupPythonCheckerPrivate))
enum  {
	DEJA_DUP_PYTHON_CHECKER_DUMMY_PROPERTY,
	DEJA_DUP_PYTHON_CHECKER_MODULE
};
DejaDupPythonChecker* deja_dup_python_checker_get_checker (const gchar* module);
static void _g_free0_ (gpointer var);
static void _g_object_unref0_ (gpointer var);
DejaDupPythonChecker* deja_dup_python_checker_new (const gchar* module);
DejaDupPythonChecker* deja_dup_python_checker_construct (GType object_type, const gchar* module);
const gchar* deja_dup_python_checker_get_module (DejaDupPythonChecker* self);
static void deja_dup_python_checker_set_module (DejaDupPythonChecker* self, const gchar* value);
static GObject * deja_dup_python_checker_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
DejaDupAsyncCommand* deja_dup_async_command_new (gchar** argv, int argv_length1);
DejaDupAsyncCommand* deja_dup_async_command_construct (GType object_type, gchar** argv, int argv_length1);
static void _deja_dup_python_checker___lambda4_ (DejaDupPythonChecker* self, gboolean s);
void deja_dup_checker_set_available (DejaDupChecker* self, gboolean value);
void deja_dup_checker_set_complete (DejaDupChecker* self, gboolean value);
static void __deja_dup_python_checker___lambda4__deja_dup_async_command_done (DejaDupAsyncCommand* _sender, gboolean success, gpointer self);
void deja_dup_async_command_run (DejaDupAsyncCommand* self);
static void deja_dup_python_checker_finalize (GObject* obj);
static void _vala_deja_dup_python_checker_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_deja_dup_python_checker_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);
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 void _g_free0_ (gpointer var) {
	var = (g_free (var), NULL);
}


static void _g_object_unref0_ (gpointer var) {
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}


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


DejaDupPythonChecker* deja_dup_python_checker_get_checker (const gchar* module) {
	DejaDupPythonChecker* result = NULL;
	DejaDupPythonChecker* checker = NULL;
	GHashTable* _tmp0_ = NULL;
	DejaDupPythonChecker* _tmp8_ = NULL;
	g_return_val_if_fail (module != NULL, NULL);
	checker = NULL;
	_tmp0_ = deja_dup_python_checker_modules;
	if (_tmp0_ == NULL) {
		GHashFunc _tmp1_ = NULL;
		GEqualFunc _tmp2_ = NULL;
		GHashTable* _tmp3_ = NULL;
		_tmp1_ = g_str_hash;
		_tmp2_ = g_str_equal;
		_tmp3_ = g_hash_table_new_full (_tmp1_, _tmp2_, _g_free0_, _g_object_unref0_);
		_g_hash_table_unref0 (deja_dup_python_checker_modules);
		deja_dup_python_checker_modules = _tmp3_;
	} else {
		GHashTable* _tmp4_ = NULL;
		const gchar* _tmp5_ = NULL;
		gconstpointer _tmp6_ = NULL;
		DejaDupPythonChecker* _tmp7_ = NULL;
		_tmp4_ = deja_dup_python_checker_modules;
		_tmp5_ = module;
		_tmp6_ = g_hash_table_lookup (_tmp4_, _tmp5_);
		_tmp7_ = _g_object_ref0 ((DejaDupPythonChecker*) _tmp6_);
		_g_object_unref0 (checker);
		checker = _tmp7_;
	}
	_tmp8_ = checker;
	if (_tmp8_ == NULL) {
		const gchar* _tmp9_ = NULL;
		DejaDupPythonChecker* _tmp10_ = NULL;
		GHashTable* _tmp11_ = NULL;
		const gchar* _tmp12_ = NULL;
		gchar* _tmp13_ = NULL;
		DejaDupPythonChecker* _tmp14_ = NULL;
		DejaDupPythonChecker* _tmp15_ = NULL;
		_tmp9_ = module;
		_tmp10_ = deja_dup_python_checker_new (_tmp9_);
		_g_object_unref0 (checker);
		checker = _tmp10_;
		_tmp11_ = deja_dup_python_checker_modules;
		_tmp12_ = module;
		_tmp13_ = g_strdup (_tmp12_);
		_tmp14_ = checker;
		_tmp15_ = _g_object_ref0 (_tmp14_);
		g_hash_table_insert (_tmp11_, _tmp13_, _tmp15_);
	}
	result = checker;
	return result;
}


DejaDupPythonChecker* deja_dup_python_checker_construct (GType object_type, const gchar* module) {
	DejaDupPythonChecker * self = NULL;
	const gchar* _tmp0_ = NULL;
	g_return_val_if_fail (module != NULL, NULL);
	_tmp0_ = module;
	self = (DejaDupPythonChecker*) g_object_new (object_type, "module", _tmp0_, NULL);
	return self;
}


DejaDupPythonChecker* deja_dup_python_checker_new (const gchar* module) {
	return deja_dup_python_checker_construct (DEJA_DUP_TYPE_PYTHON_CHECKER, module);
}


const gchar* deja_dup_python_checker_get_module (DejaDupPythonChecker* self) {
	const gchar* result;
	const gchar* _tmp0_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_module;
	result = _tmp0_;
	return result;
}


static void deja_dup_python_checker_set_module (DejaDupPythonChecker* self, const gchar* value) {
	const gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	_tmp1_ = g_strdup (_tmp0_);
	_g_free0 (self->priv->_module);
	self->priv->_module = _tmp1_;
	g_object_notify ((GObject *) self, "module");
}


static void _deja_dup_python_checker___lambda4_ (DejaDupPythonChecker* self, gboolean s) {
	gboolean _tmp0_ = FALSE;
	_tmp0_ = s;
	deja_dup_checker_set_available ((DejaDupChecker*) self, _tmp0_);
	deja_dup_checker_set_complete ((DejaDupChecker*) self, TRUE);
}


static void __deja_dup_python_checker___lambda4__deja_dup_async_command_done (DejaDupAsyncCommand* _sender, gboolean success, gpointer self) {
	_deja_dup_python_checker___lambda4_ ((DejaDupPythonChecker*) self, success);
}


static GObject * deja_dup_python_checker_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	GObjectClass * parent_class;
	DejaDupPythonChecker * self;
	gchar* import = NULL;
	const gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	gchar** argv = NULL;
	gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	const gchar* _tmp4_ = NULL;
	gchar* _tmp5_ = NULL;
	gchar** _tmp6_ = NULL;
	gint argv_length1 = 0;
	gint _argv_size_ = 0;
	gchar** _tmp7_ = NULL;
	gint _tmp7__length1 = 0;
	DejaDupAsyncCommand* _tmp8_ = NULL;
	DejaDupAsyncCommand* _tmp9_ = NULL;
	DejaDupAsyncCommand* _tmp10_ = NULL;
	parent_class = G_OBJECT_CLASS (deja_dup_python_checker_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DEJA_DUP_TYPE_PYTHON_CHECKER, DejaDupPythonChecker);
	_tmp0_ = self->priv->_module;
	_tmp1_ = g_strdup_printf ("import %s", _tmp0_);
	import = _tmp1_;
	_tmp2_ = g_strdup ("python");
	_tmp3_ = g_strdup ("-c");
	_tmp4_ = import;
	_tmp5_ = g_strdup (_tmp4_);
	_tmp6_ = g_new0 (gchar*, 3 + 1);
	_tmp6_[0] = _tmp2_;
	_tmp6_[1] = _tmp3_;
	_tmp6_[2] = _tmp5_;
	argv = _tmp6_;
	argv_length1 = 3;
	_argv_size_ = argv_length1;
	_tmp7_ = argv;
	_tmp7__length1 = argv_length1;
	_tmp8_ = deja_dup_async_command_new (_tmp7_, _tmp7__length1);
	_g_object_unref0 (self->priv->cmd);
	self->priv->cmd = _tmp8_;
	_tmp9_ = self->priv->cmd;
	g_signal_connect_object (_tmp9_, "done", (GCallback) __deja_dup_python_checker___lambda4__deja_dup_async_command_done, self, 0);
	_tmp10_ = self->priv->cmd;
	deja_dup_async_command_run (_tmp10_);
	argv = (_vala_array_free (argv, argv_length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (import);
	return obj;
}


static void deja_dup_python_checker_class_init (DejaDupPythonCheckerClass * klass) {
	deja_dup_python_checker_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (DejaDupPythonCheckerPrivate));
	G_OBJECT_CLASS (klass)->get_property = _vala_deja_dup_python_checker_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_deja_dup_python_checker_set_property;
	G_OBJECT_CLASS (klass)->constructor = deja_dup_python_checker_constructor;
	G_OBJECT_CLASS (klass)->finalize = deja_dup_python_checker_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DEJA_DUP_PYTHON_CHECKER_MODULE, g_param_spec_string ("module", "module", "module", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
}


static void deja_dup_python_checker_instance_init (DejaDupPythonChecker * self) {
	self->priv = DEJA_DUP_PYTHON_CHECKER_GET_PRIVATE (self);
}


static void deja_dup_python_checker_finalize (GObject* obj) {
	DejaDupPythonChecker * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DEJA_DUP_TYPE_PYTHON_CHECKER, DejaDupPythonChecker);
	_g_free0 (self->priv->_module);
	_g_object_unref0 (self->priv->cmd);
	G_OBJECT_CLASS (deja_dup_python_checker_parent_class)->finalize (obj);
}


GType deja_dup_python_checker_get_type (void) {
	static volatile gsize deja_dup_python_checker_type_id__volatile = 0;
	if (g_once_init_enter (&deja_dup_python_checker_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (DejaDupPythonCheckerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) deja_dup_python_checker_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DejaDupPythonChecker), 0, (GInstanceInitFunc) deja_dup_python_checker_instance_init, NULL };
		GType deja_dup_python_checker_type_id;
		deja_dup_python_checker_type_id = g_type_register_static (DEJA_DUP_TYPE_CHECKER, "DejaDupPythonChecker", &g_define_type_info, 0);
		g_once_init_leave (&deja_dup_python_checker_type_id__volatile, deja_dup_python_checker_type_id);
	}
	return deja_dup_python_checker_type_id__volatile;
}


static void _vala_deja_dup_python_checker_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	DejaDupPythonChecker * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DEJA_DUP_TYPE_PYTHON_CHECKER, DejaDupPythonChecker);
	switch (property_id) {
		case DEJA_DUP_PYTHON_CHECKER_MODULE:
		g_value_set_string (value, deja_dup_python_checker_get_module (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_deja_dup_python_checker_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	DejaDupPythonChecker * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DEJA_DUP_TYPE_PYTHON_CHECKER, DejaDupPythonChecker);
	switch (property_id) {
		case DEJA_DUP_PYTHON_CHECKER_MODULE:
		deja_dup_python_checker_set_module (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


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



