/* PythonChecker.c generated by valac 0.12.1, 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 _lambda0_ (gboolean s, DejaDupPythonChecker* self);
void deja_dup_checker_set_available (DejaDupChecker* self, gboolean value);
void deja_dup_checker_set_complete (DejaDupChecker* self, gboolean value);
static void __lambda0__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;
	g_return_val_if_fail (module != NULL, NULL);
	checker = NULL;
	if (deja_dup_python_checker_modules == NULL) {
		GHashTable* _tmp0_ = NULL;
		_tmp0_ = g_hash_table_new_full (g_str_hash, g_str_equal, _g_free0_, _g_object_unref0_);
		_g_hash_table_unref0 (deja_dup_python_checker_modules);
		deja_dup_python_checker_modules = _tmp0_;
	} else {
		gconstpointer _tmp1_ = NULL;
		DejaDupPythonChecker* _tmp2_;
		_tmp1_ = g_hash_table_lookup (deja_dup_python_checker_modules, module);
		_tmp2_ = _g_object_ref0 ((DejaDupPythonChecker*) _tmp1_);
		_g_object_unref0 (checker);
		checker = _tmp2_;
	}
	if (checker == NULL) {
		DejaDupPythonChecker* _tmp3_ = NULL;
		gchar* _tmp4_;
		DejaDupPythonChecker* _tmp5_;
		_tmp3_ = deja_dup_python_checker_new (module);
		_g_object_unref0 (checker);
		checker = _tmp3_;
		_tmp4_ = g_strdup (module);
		_tmp5_ = _g_object_ref0 (checker);
		g_hash_table_insert (deja_dup_python_checker_modules, _tmp4_, _tmp5_);
	}
	result = checker;
	return result;
}


DejaDupPythonChecker* deja_dup_python_checker_construct (GType object_type, const gchar* module) {
	DejaDupPythonChecker * self = NULL;
	g_return_val_if_fail (module != NULL, NULL);
	self = (DejaDupPythonChecker*) g_object_new (object_type, "module", module, 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;
	g_return_val_if_fail (self != NULL, NULL);
	result = self->priv->_module;
	return result;
}


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


static void _lambda0_ (gboolean s, DejaDupPythonChecker* self) {
	deja_dup_checker_set_available ((DejaDupChecker*) self, s);
	deja_dup_checker_set_complete ((DejaDupChecker*) self, TRUE);
}


static void __lambda0__deja_dup_async_command_done (DejaDupAsyncCommand* _sender, gboolean success, gpointer self) {
	_lambda0_ (success, self);
}


static GObject * deja_dup_python_checker_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	GObjectClass * parent_class;
	DejaDupPythonChecker * self;
	gchar* _tmp0_ = NULL;
	gchar* import;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar** _tmp4_ = NULL;
	gchar** argv;
	gint argv_length1;
	gint _argv_size_;
	DejaDupAsyncCommand* _tmp5_ = NULL;
	parent_class = G_OBJECT_CLASS (deja_dup_python_checker_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = DEJA_DUP_PYTHON_CHECKER (obj);
	_tmp0_ = g_strdup_printf ("import %s", self->priv->_module);
	import = _tmp0_;
	_tmp1_ = g_strdup ("python");
	_tmp2_ = g_strdup ("-c");
	_tmp3_ = g_strdup (import);
	_tmp4_ = g_new0 (gchar*, 3 + 1);
	_tmp4_[0] = _tmp1_;
	_tmp4_[1] = _tmp2_;
	_tmp4_[2] = _tmp3_;
	argv = _tmp4_;
	argv_length1 = 3;
	_argv_size_ = 3;
	_tmp5_ = deja_dup_async_command_new (argv, argv_length1);
	_g_object_unref0 (self->priv->cmd);
	self->priv->cmd = _tmp5_;
	g_signal_connect_object (self->priv->cmd, "done", (GCallback) __lambda0__deja_dup_async_command_done, self, 0);
	deja_dup_async_command_run (self->priv->cmd);
	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 = DEJA_DUP_PYTHON_CHECKER (obj);
	_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 = DEJA_DUP_PYTHON_CHECKER (object);
	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 = DEJA_DUP_PYTHON_CHECKER (object);
	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);
}



