/* ConfigNumber.c generated by valac 0.12.1, the Vala compiler
 * generated from ConfigNumber.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>
#include <float.h>
#include <math.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 DEJA_DUP_TYPE_CONFIG_NUMBER (deja_dup_config_number_get_type ())
#define DEJA_DUP_CONFIG_NUMBER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DEJA_DUP_TYPE_CONFIG_NUMBER, DejaDupConfigNumber))
#define DEJA_DUP_CONFIG_NUMBER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DEJA_DUP_TYPE_CONFIG_NUMBER, DejaDupConfigNumberClass))
#define DEJA_DUP_IS_CONFIG_NUMBER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DEJA_DUP_TYPE_CONFIG_NUMBER))
#define DEJA_DUP_IS_CONFIG_NUMBER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DEJA_DUP_TYPE_CONFIG_NUMBER))
#define DEJA_DUP_CONFIG_NUMBER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DEJA_DUP_TYPE_CONFIG_NUMBER, DejaDupConfigNumberClass))

typedef struct _DejaDupConfigNumber DejaDupConfigNumber;
typedef struct _DejaDupConfigNumberClass DejaDupConfigNumberClass;
typedef struct _DejaDupConfigNumberPrivate DejaDupConfigNumberPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _DejaDupConfigNumberSetFromConfigData DejaDupConfigNumberSetFromConfigData;

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 _DejaDupConfigNumber {
	DejaDupConfigWidget parent_instance;
	DejaDupConfigNumberPrivate * priv;
};

struct _DejaDupConfigNumberClass {
	DejaDupConfigWidgetClass parent_class;
};

struct _DejaDupConfigNumberPrivate {
	gint _lower_bound;
	gint _upper_bound;
	GtkSpinButton* spin;
};

struct _DejaDupConfigNumberSetFromConfigData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	DejaDupConfigNumber* self;
	const gchar* _tmp0_;
	gint _tmp1_;
};


static gpointer deja_dup_config_number_parent_class = NULL;

GType deja_dup_config_widget_get_type (void) G_GNUC_CONST;
GType deja_dup_config_number_get_type (void) G_GNUC_CONST;
#define DEJA_DUP_CONFIG_NUMBER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DEJA_DUP_TYPE_CONFIG_NUMBER, DejaDupConfigNumberPrivate))
enum  {
	DEJA_DUP_CONFIG_NUMBER_DUMMY_PROPERTY,
	DEJA_DUP_CONFIG_NUMBER_LOWER_BOUND,
	DEJA_DUP_CONFIG_NUMBER_UPPER_BOUND
};
DejaDupConfigNumber* deja_dup_config_number_new (const gchar* key, gint lower_bound, gint upper_bound, const gchar* ns);
DejaDupConfigNumber* deja_dup_config_number_construct (GType object_type, const gchar* key, gint lower_bound, gint upper_bound, const gchar* ns);
static void deja_dup_config_number_real_set_from_config_data_free (gpointer _data);
static void deja_dup_config_number_real_set_from_config (DejaDupConfigWidget* base, GAsyncReadyCallback _callback_, gpointer _user_data_);
static gboolean deja_dup_config_number_real_set_from_config_co (DejaDupConfigNumberSetFromConfigData* data);
const gchar* deja_dup_config_widget_get_key (DejaDupConfigWidget* self);
static void deja_dup_config_number_handle_value_changed (DejaDupConfigNumber* self);
gint deja_dup_config_number_get_lower_bound (DejaDupConfigNumber* self);
static void deja_dup_config_number_set_lower_bound (DejaDupConfigNumber* self, gint value);
gint deja_dup_config_number_get_upper_bound (DejaDupConfigNumber* self);
static void deja_dup_config_number_set_upper_bound (DejaDupConfigNumber* self, gint value);
static GObject * deja_dup_config_number_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
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_number_handle_value_changed_gtk_spin_button_value_changed (GtkSpinButton* _sender, gpointer self);
static void deja_dup_config_number_finalize (GObject* obj);
static void _vala_deja_dup_config_number_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_deja_dup_config_number_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);


DejaDupConfigNumber* deja_dup_config_number_construct (GType object_type, const gchar* key, gint lower_bound, gint upper_bound, const gchar* ns) {
	DejaDupConfigNumber * self = NULL;
	g_return_val_if_fail (key != NULL, NULL);
	g_return_val_if_fail (ns != NULL, NULL);
	self = (DejaDupConfigNumber*) g_object_new (object_type, "key", key, "lower-bound", lower_bound, "upper-bound", upper_bound, "ns", ns, NULL);
	return self;
}


DejaDupConfigNumber* deja_dup_config_number_new (const gchar* key, gint lower_bound, gint upper_bound, const gchar* ns) {
	return deja_dup_config_number_construct (DEJA_DUP_TYPE_CONFIG_NUMBER, key, lower_bound, upper_bound, ns);
}


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


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


static void deja_dup_config_number_real_set_from_config (DejaDupConfigWidget* base, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	DejaDupConfigNumber * self;
	DejaDupConfigNumberSetFromConfigData* _data_;
	self = (DejaDupConfigNumber*) base;
	_data_ = g_slice_new0 (DejaDupConfigNumberSetFromConfigData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, deja_dup_config_number_real_set_from_config);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, deja_dup_config_number_real_set_from_config_data_free);
	_data_->self = _g_object_ref0 (self);
	deja_dup_config_number_real_set_from_config_co (_data_);
}


static void deja_dup_config_number_real_set_from_config_finish (DejaDupConfigWidget* base, GAsyncResult* _res_) {
	DejaDupConfigNumberSetFromConfigData* _data_;
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
}


static gboolean deja_dup_config_number_real_set_from_config_co (DejaDupConfigNumberSetFromConfigData* data) {
	switch (data->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	data->_tmp0_ = NULL;
	data->_tmp0_ = deja_dup_config_widget_get_key ((DejaDupConfigWidget*) data->self);
	data->_tmp1_ = g_settings_get_int ((GSettings*) ((DejaDupConfigWidget*) data->self)->settings, data->_tmp0_);
	gtk_spin_button_set_value (data->self->priv->spin, (gdouble) data->_tmp1_);
	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;
}


static void deja_dup_config_number_handle_value_changed (DejaDupConfigNumber* self) {
	const gchar* _tmp0_ = NULL;
	gdouble _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = deja_dup_config_widget_get_key ((DejaDupConfigWidget*) self);
	_tmp1_ = gtk_spin_button_get_value (self->priv->spin);
	deja_dup_simple_settings_set_int (((DejaDupConfigWidget*) self)->settings, _tmp0_, (gint) _tmp1_);
}


gint deja_dup_config_number_get_lower_bound (DejaDupConfigNumber* self) {
	gint result;
	g_return_val_if_fail (self != NULL, 0);
	result = self->priv->_lower_bound;
	return result;
}


static void deja_dup_config_number_set_lower_bound (DejaDupConfigNumber* self, gint value) {
	g_return_if_fail (self != NULL);
	self->priv->_lower_bound = value;
	g_object_notify ((GObject *) self, "lower-bound");
}


gint deja_dup_config_number_get_upper_bound (DejaDupConfigNumber* self) {
	gint result;
	g_return_val_if_fail (self != NULL, 0);
	result = self->priv->_upper_bound;
	return result;
}


static void deja_dup_config_number_set_upper_bound (DejaDupConfigNumber* self, gint value) {
	g_return_if_fail (self != NULL);
	self->priv->_upper_bound = value;
	g_object_notify ((GObject *) self, "upper-bound");
}


static void _deja_dup_config_number_handle_value_changed_gtk_spin_button_value_changed (GtkSpinButton* _sender, gpointer self) {
	deja_dup_config_number_handle_value_changed (self);
}


static GObject * deja_dup_config_number_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	GObjectClass * parent_class;
	DejaDupConfigNumber * self;
	GtkSpinButton* _tmp0_ = NULL;
	parent_class = G_OBJECT_CLASS (deja_dup_config_number_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = DEJA_DUP_CONFIG_NUMBER (obj);
	_tmp0_ = (GtkSpinButton*) gtk_spin_button_new_with_range ((gdouble) self->priv->_lower_bound, (gdouble) self->priv->_upper_bound, (gdouble) 1);
	_g_object_unref0 (self->priv->spin);
	self->priv->spin = g_object_ref_sink (_tmp0_);
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) self->priv->spin);
	deja_dup_config_widget_set_from_config ((DejaDupConfigWidget*) self, NULL, NULL);
	g_signal_connect_object (self->priv->spin, "value-changed", (GCallback) _deja_dup_config_number_handle_value_changed_gtk_spin_button_value_changed, self, 0);
	return obj;
}


static void deja_dup_config_number_class_init (DejaDupConfigNumberClass * klass) {
	deja_dup_config_number_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (DejaDupConfigNumberPrivate));
	DEJA_DUP_CONFIG_WIDGET_CLASS (klass)->set_from_config = deja_dup_config_number_real_set_from_config;
	DEJA_DUP_CONFIG_WIDGET_CLASS (klass)->set_from_config_finish = deja_dup_config_number_real_set_from_config_finish;
	G_OBJECT_CLASS (klass)->get_property = _vala_deja_dup_config_number_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_deja_dup_config_number_set_property;
	G_OBJECT_CLASS (klass)->constructor = deja_dup_config_number_constructor;
	G_OBJECT_CLASS (klass)->finalize = deja_dup_config_number_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DEJA_DUP_CONFIG_NUMBER_LOWER_BOUND, g_param_spec_int ("lower-bound", "lower-bound", "lower-bound", G_MININT, G_MAXINT, 0, 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_NUMBER_UPPER_BOUND, g_param_spec_int ("upper-bound", "upper-bound", "upper-bound", G_MININT, G_MAXINT, 0, 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_config_number_instance_init (DejaDupConfigNumber * self) {
	self->priv = DEJA_DUP_CONFIG_NUMBER_GET_PRIVATE (self);
}


static void deja_dup_config_number_finalize (GObject* obj) {
	DejaDupConfigNumber * self;
	self = DEJA_DUP_CONFIG_NUMBER (obj);
	_g_object_unref0 (self->priv->spin);
	G_OBJECT_CLASS (deja_dup_config_number_parent_class)->finalize (obj);
}


GType deja_dup_config_number_get_type (void) {
	static volatile gsize deja_dup_config_number_type_id__volatile = 0;
	if (g_once_init_enter (&deja_dup_config_number_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (DejaDupConfigNumberClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) deja_dup_config_number_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DejaDupConfigNumber), 0, (GInstanceInitFunc) deja_dup_config_number_instance_init, NULL };
		GType deja_dup_config_number_type_id;
		deja_dup_config_number_type_id = g_type_register_static (DEJA_DUP_TYPE_CONFIG_WIDGET, "DejaDupConfigNumber", &g_define_type_info, 0);
		g_once_init_leave (&deja_dup_config_number_type_id__volatile, deja_dup_config_number_type_id);
	}
	return deja_dup_config_number_type_id__volatile;
}


static void _vala_deja_dup_config_number_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	DejaDupConfigNumber * self;
	self = DEJA_DUP_CONFIG_NUMBER (object);
	switch (property_id) {
		case DEJA_DUP_CONFIG_NUMBER_LOWER_BOUND:
		g_value_set_int (value, deja_dup_config_number_get_lower_bound (self));
		break;
		case DEJA_DUP_CONFIG_NUMBER_UPPER_BOUND:
		g_value_set_int (value, deja_dup_config_number_get_upper_bound (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_deja_dup_config_number_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	DejaDupConfigNumber * self;
	self = DEJA_DUP_CONFIG_NUMBER (object);
	switch (property_id) {
		case DEJA_DUP_CONFIG_NUMBER_LOWER_BOUND:
		deja_dup_config_number_set_lower_bound (self, g_value_get_int (value));
		break;
		case DEJA_DUP_CONFIG_NUMBER_UPPER_BOUND:
		deja_dup_config_number_set_upper_bound (self, g_value_get_int (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}



