/* ConfigWidget.c generated by valac 0.12.1, the Vala compiler
 * generated from ConfigWidget.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 <gtk/gtk.h>
#include <gio/gio.h>
#include <common.h>
#include <stdlib.h>
#include <string.h>


#define DEJA_DUP_TYPE_CONFIG_WIDGET (deja_dup_config_widget_get_type ())
#define DEJA_DUP_CONFIG_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DEJA_DUP_TYPE_CONFIG_WIDGET, DejaDupConfigWidget))
#define DEJA_DUP_CONFIG_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DEJA_DUP_TYPE_CONFIG_WIDGET, DejaDupConfigWidgetClass))
#define DEJA_DUP_IS_CONFIG_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DEJA_DUP_TYPE_CONFIG_WIDGET))
#define DEJA_DUP_IS_CONFIG_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DEJA_DUP_TYPE_CONFIG_WIDGET))
#define DEJA_DUP_CONFIG_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DEJA_DUP_TYPE_CONFIG_WIDGET, DejaDupConfigWidgetClass))

typedef struct _DejaDupConfigWidget DejaDupConfigWidget;
typedef struct _DejaDupConfigWidgetClass DejaDupConfigWidgetClass;
typedef struct _DejaDupConfigWidgetPrivate DejaDupConfigWidgetPrivate;
#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_list_free__g_object_unref0_0(var) ((var == NULL) ? NULL : (var = (_g_list_free__g_object_unref0_ (var), NULL)))
typedef struct _DejaDupConfigWidgetKeyChangedData DejaDupConfigWidgetKeyChangedData;

struct _DejaDupConfigWidget {
	GtkEventBox parent_instance;
	DejaDupConfigWidgetPrivate * priv;
	gboolean syncing;
	DejaDupSimpleSettings* settings;
	GList* all_settings;
};

struct _DejaDupConfigWidgetClass {
	GtkEventBoxClass parent_class;
	void (*set_from_config) (DejaDupConfigWidget* self, GAsyncReadyCallback _callback_, gpointer _user_data_);
	void (*set_from_config_finish) (DejaDupConfigWidget* self, GAsyncResult* _res_);
};

struct _DejaDupConfigWidgetPrivate {
	GtkWidget* _mnemonic_widget;
	gchar* _key;
	gchar* _ns;
};

struct _DejaDupConfigWidgetKeyChangedData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	DejaDupConfigWidget* self;
};


static gpointer deja_dup_config_widget_parent_class = NULL;

GType deja_dup_config_widget_get_type (void) G_GNUC_CONST;
#define DEJA_DUP_CONFIG_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DEJA_DUP_TYPE_CONFIG_WIDGET, DejaDupConfigWidgetPrivate))
enum  {
	DEJA_DUP_CONFIG_WIDGET_DUMMY_PROPERTY,
	DEJA_DUP_CONFIG_WIDGET_MNEMONIC_WIDGET,
	DEJA_DUP_CONFIG_WIDGET_KEY,
	DEJA_DUP_CONFIG_WIDGET_NS
};
static gboolean deja_dup_config_widget_key_changed_wrapper (DejaDupConfigWidget* w);
static void _g_object_unref0_ (gpointer var);
static void _g_list_free__g_object_unref0_ (GList* self);
void deja_dup_config_widget_watch_key (DejaDupConfigWidget* self, const gchar* key, DejaDupSimpleSettings* s);
static void deja_dup_config_widget_key_changed (DejaDupConfigWidget* self, GAsyncReadyCallback _callback_, gpointer _user_data_);
static void deja_dup_config_widget_key_changed_finish (DejaDupConfigWidget* self, GAsyncResult* _res_);
static void deja_dup_config_widget_key_changed_data_free (gpointer _data);
static gboolean deja_dup_config_widget_key_changed_co (DejaDupConfigWidgetKeyChangedData* data);
void deja_dup_config_widget_set_from_config (DejaDupConfigWidget* self, GAsyncReadyCallback _callback_, gpointer _user_data_);
void deja_dup_config_widget_set_from_config_finish (DejaDupConfigWidget* self, GAsyncResult* _res_);
static void deja_dup_config_widget_key_changed_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
static gboolean deja_dup_config_widget_on_mnemonic_activate (DejaDupConfigWidget* self, GtkWidget* w, gboolean g);
GtkWidget* deja_dup_config_widget_get_mnemonic_widget (DejaDupConfigWidget* self);
DejaDupConfigWidget* deja_dup_config_widget_construct (GType object_type);
void deja_dup_config_widget_set_mnemonic_widget (DejaDupConfigWidget* self, GtkWidget* value);
const gchar* deja_dup_config_widget_get_key (DejaDupConfigWidget* self);
static void deja_dup_config_widget_set_key (DejaDupConfigWidget* self, const gchar* value);
const gchar* deja_dup_config_widget_get_ns (DejaDupConfigWidget* self);
static void deja_dup_config_widget_set_ns (DejaDupConfigWidget* self, const gchar* value);
static GObject * deja_dup_config_widget_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
static gboolean _deja_dup_config_widget_on_mnemonic_activate_gtk_widget_mnemonic_activate (GtkWidget* _sender, gboolean group_cycling, gpointer self);
static void deja_dup_config_widget_finalize (GObject* obj);
static void _vala_deja_dup_config_widget_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_deja_dup_config_widget_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);


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


static void _g_list_free__g_object_unref0_ (GList* self) {
	g_list_foreach (self, (GFunc) _g_object_unref0_, NULL);
	g_list_free (self);
}


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


void deja_dup_config_widget_watch_key (DejaDupConfigWidget* self, const gchar* key, DejaDupSimpleSettings* s) {
	gchar* _tmp1_ = NULL;
	gchar* _tmp4_;
	gchar* signal_name;
	g_return_if_fail (self != NULL);
	if (s == NULL) {
		s = self->settings;
	} else {
		DejaDupSimpleSettings* _tmp0_;
		g_object_ref ((GObject*) s);
		_tmp0_ = _g_object_ref0 (s);
		self->all_settings = g_list_prepend (self->all_settings, _tmp0_);
	}
	if (key == NULL) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup ("change-event");
		_g_free0 (_tmp1_);
		_tmp1_ = _tmp2_;
	} else {
		gchar* _tmp3_ = NULL;
		_tmp3_ = g_strdup_printf ("changed::%s", key);
		_g_free0 (_tmp1_);
		_tmp1_ = _tmp3_;
	}
	_tmp4_ = g_strdup (_tmp1_);
	signal_name = _tmp4_;
	g_signal_connect_swapped (s, signal_name, (GCallback) deja_dup_config_widget_key_changed_wrapper, self);
	_g_free0 (signal_name);
	_g_free0 (_tmp1_);
}


static gboolean deja_dup_config_widget_key_changed_wrapper (DejaDupConfigWidget* w) {
	gboolean result = FALSE;
	g_return_val_if_fail (w != NULL, FALSE);
	deja_dup_config_widget_key_changed (w, NULL, NULL);
	result = FALSE;
	return result;
}


static void deja_dup_config_widget_key_changed_data_free (gpointer _data) {
	DejaDupConfigWidgetKeyChangedData* data;
	data = _data;
	_g_object_unref0 (data->self);
	g_slice_free (DejaDupConfigWidgetKeyChangedData, data);
}


static void deja_dup_config_widget_key_changed (DejaDupConfigWidget* self, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	DejaDupConfigWidgetKeyChangedData* _data_;
	_data_ = g_slice_new0 (DejaDupConfigWidgetKeyChangedData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, deja_dup_config_widget_key_changed);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, deja_dup_config_widget_key_changed_data_free);
	_data_->self = _g_object_ref0 (self);
	deja_dup_config_widget_key_changed_co (_data_);
}


static void deja_dup_config_widget_key_changed_finish (DejaDupConfigWidget* self, GAsyncResult* _res_) {
	DejaDupConfigWidgetKeyChangedData* _data_;
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
}


static void deja_dup_config_widget_key_changed_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	DejaDupConfigWidgetKeyChangedData* data;
	data = _user_data_;
	data->_source_object_ = source_object;
	data->_res_ = _res_;
	deja_dup_config_widget_key_changed_co (data);
}


static gboolean deja_dup_config_widget_key_changed_co (DejaDupConfigWidgetKeyChangedData* data) {
	switch (data->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	if (data->self->syncing) {
		if (data->_state_ == 0) {
			g_simple_async_result_complete_in_idle (data->_async_result);
		} else {
			g_simple_async_result_complete (data->_async_result);
		}
		g_object_unref (data->_async_result);
		return FALSE;
	}
	data->self->syncing = TRUE;
	data->_state_ = 1;
	deja_dup_config_widget_set_from_config (data->self, deja_dup_config_widget_key_changed_ready, data);
	return FALSE;
	_state_1:
	deja_dup_config_widget_set_from_config_finish (data->self, data->_res_);
	g_signal_emit_by_name (data->self, "changed");
	data->self->syncing = FALSE;
	if (data->_state_ == 0) {
		g_simple_async_result_complete_in_idle (data->_async_result);
	} else {
		g_simple_async_result_complete (data->_async_result);
	}
	g_object_unref (data->_async_result);
	return FALSE;
}


void deja_dup_config_widget_set_from_config (DejaDupConfigWidget* self, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	DEJA_DUP_CONFIG_WIDGET_GET_CLASS (self)->set_from_config (self, _callback_, _user_data_);
}


void deja_dup_config_widget_set_from_config_finish (DejaDupConfigWidget* self, GAsyncResult* _res_) {
	DEJA_DUP_CONFIG_WIDGET_GET_CLASS (self)->set_from_config_finish (self, _res_);
}


static gboolean deja_dup_config_widget_on_mnemonic_activate (DejaDupConfigWidget* self, GtkWidget* w, gboolean g) {
	gboolean result = FALSE;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (w != NULL, FALSE);
	if (self->priv->_mnemonic_widget != NULL) {
		gboolean _tmp0_;
		_tmp0_ = gtk_widget_mnemonic_activate (self->priv->_mnemonic_widget, g);
		result = _tmp0_;
		return result;
	} else {
		result = FALSE;
		return result;
	}
}


DejaDupConfigWidget* deja_dup_config_widget_construct (GType object_type) {
	DejaDupConfigWidget * self = NULL;
	self = (DejaDupConfigWidget*) g_object_new (object_type, NULL);
	return self;
}


GtkWidget* deja_dup_config_widget_get_mnemonic_widget (DejaDupConfigWidget* self) {
	GtkWidget* result;
	g_return_val_if_fail (self != NULL, NULL);
	result = self->priv->_mnemonic_widget;
	return result;
}


void deja_dup_config_widget_set_mnemonic_widget (DejaDupConfigWidget* self, GtkWidget* value) {
	GtkWidget* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _g_object_ref0 (value);
	_g_object_unref0 (self->priv->_mnemonic_widget);
	self->priv->_mnemonic_widget = _tmp0_;
	g_object_notify ((GObject *) self, "mnemonic-widget");
}


const gchar* deja_dup_config_widget_get_key (DejaDupConfigWidget* self) {
	const gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	result = self->priv->_key;
	return result;
}


static void deja_dup_config_widget_set_key (DejaDupConfigWidget* self, const gchar* value) {
	gchar* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_strdup (value);
	_g_free0 (self->priv->_key);
	self->priv->_key = _tmp0_;
	g_object_notify ((GObject *) self, "key");
}


const gchar* deja_dup_config_widget_get_ns (DejaDupConfigWidget* self) {
	const gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	result = self->priv->_ns;
	return result;
}


static void deja_dup_config_widget_set_ns (DejaDupConfigWidget* self, const gchar* value) {
	gchar* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_strdup (value);
	_g_free0 (self->priv->_ns);
	self->priv->_ns = _tmp0_;
	g_object_notify ((GObject *) self, "ns");
}


static gboolean _deja_dup_config_widget_on_mnemonic_activate_gtk_widget_mnemonic_activate (GtkWidget* _sender, gboolean group_cycling, gpointer self) {
	gboolean result;
	result = deja_dup_config_widget_on_mnemonic_activate (self, _sender, group_cycling);
	return result;
}


static GObject * deja_dup_config_widget_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	GObjectClass * parent_class;
	DejaDupConfigWidget * self;
	DejaDupSimpleSettings* _tmp0_ = NULL;
	parent_class = G_OBJECT_CLASS (deja_dup_config_widget_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = DEJA_DUP_CONFIG_WIDGET (obj);
	_tmp0_ = deja_dup_get_settings (self->priv->_ns);
	_g_object_unref0 (self->settings);
	self->settings = _tmp0_;
	if (self->priv->_key != NULL) {
		deja_dup_config_widget_watch_key (self, self->priv->_key, NULL);
	}
	g_signal_connect_object ((GtkWidget*) self, "mnemonic-activate", (GCallback) _deja_dup_config_widget_on_mnemonic_activate_gtk_widget_mnemonic_activate, self, 0);
	return obj;
}


static void deja_dup_config_widget_class_init (DejaDupConfigWidgetClass * klass) {
	deja_dup_config_widget_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (DejaDupConfigWidgetPrivate));
	G_OBJECT_CLASS (klass)->get_property = _vala_deja_dup_config_widget_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_deja_dup_config_widget_set_property;
	G_OBJECT_CLASS (klass)->constructor = deja_dup_config_widget_constructor;
	G_OBJECT_CLASS (klass)->finalize = deja_dup_config_widget_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DEJA_DUP_CONFIG_WIDGET_MNEMONIC_WIDGET, g_param_spec_object ("mnemonic-widget", "mnemonic-widget", "mnemonic-widget", GTK_TYPE_WIDGET, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), DEJA_DUP_CONFIG_WIDGET_KEY, g_param_spec_string ("key", "key", "key", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), DEJA_DUP_CONFIG_WIDGET_NS, g_param_spec_string ("ns", "ns", "ns", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_signal_new ("changed", DEJA_DUP_TYPE_CONFIG_WIDGET, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}


static void deja_dup_config_widget_instance_init (DejaDupConfigWidget * self) {
	gchar* _tmp0_;
	self->priv = DEJA_DUP_CONFIG_WIDGET_GET_PRIVATE (self);
	_tmp0_ = g_strdup ("");
	self->priv->_ns = _tmp0_;
}


static void deja_dup_config_widget_finalize (GObject* obj) {
	DejaDupConfigWidget * self;
	self = DEJA_DUP_CONFIG_WIDGET (obj);
	g_signal_handlers_disconnect_by_func (self->settings, (void*) deja_dup_config_widget_key_changed_wrapper, self);
	{
		GList* s_collection;
		GList* s_it;
		s_collection = self->all_settings;
		for (s_it = s_collection; s_it != NULL; s_it = s_it->next) {
			DejaDupSimpleSettings* s;
			s = (DejaDupSimpleSettings*) s_it->data;
			{
				g_signal_handlers_disconnect_by_func (s, (void*) deja_dup_config_widget_key_changed_wrapper, self);
				g_object_unref ((GObject*) s);
			}
		}
	}
	_g_object_unref0 (self->priv->_mnemonic_widget);
	_g_free0 (self->priv->_key);
	_g_free0 (self->priv->_ns);
	_g_object_unref0 (self->settings);
	__g_list_free__g_object_unref0_0 (self->all_settings);
	G_OBJECT_CLASS (deja_dup_config_widget_parent_class)->finalize (obj);
}


GType deja_dup_config_widget_get_type (void) {
	static volatile gsize deja_dup_config_widget_type_id__volatile = 0;
	if (g_once_init_enter (&deja_dup_config_widget_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (DejaDupConfigWidgetClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) deja_dup_config_widget_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DejaDupConfigWidget), 0, (GInstanceInitFunc) deja_dup_config_widget_instance_init, NULL };
		GType deja_dup_config_widget_type_id;
		deja_dup_config_widget_type_id = g_type_register_static (GTK_TYPE_EVENT_BOX, "DejaDupConfigWidget", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
		g_once_init_leave (&deja_dup_config_widget_type_id__volatile, deja_dup_config_widget_type_id);
	}
	return deja_dup_config_widget_type_id__volatile;
}


static void _vala_deja_dup_config_widget_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	DejaDupConfigWidget * self;
	self = DEJA_DUP_CONFIG_WIDGET (object);
	switch (property_id) {
		case DEJA_DUP_CONFIG_WIDGET_MNEMONIC_WIDGET:
		g_value_set_object (value, deja_dup_config_widget_get_mnemonic_widget (self));
		break;
		case DEJA_DUP_CONFIG_WIDGET_KEY:
		g_value_set_string (value, deja_dup_config_widget_get_key (self));
		break;
		case DEJA_DUP_CONFIG_WIDGET_NS:
		g_value_set_string (value, deja_dup_config_widget_get_ns (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_deja_dup_config_widget_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	DejaDupConfigWidget * self;
	self = DEJA_DUP_CONFIG_WIDGET (object);
	switch (property_id) {
		case DEJA_DUP_CONFIG_WIDGET_MNEMONIC_WIDGET:
		deja_dup_config_widget_set_mnemonic_widget (self, g_value_get_object (value));
		break;
		case DEJA_DUP_CONFIG_WIDGET_KEY:
		deja_dup_config_widget_set_key (self, g_value_get_string (value));
		break;
		case DEJA_DUP_CONFIG_WIDGET_NS:
		deja_dup_config_widget_set_ns (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}



