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

/* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 2 -*- */
/*
    This file is part of Déjà Dup.
    © 2008,2009 Michael Terry <mike@mterry.name>

    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 <gconf/gconf-client.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 DEJA_DUP_TYPE_TOGGLABLE (deja_dup_togglable_get_type ())
#define DEJA_DUP_TOGGLABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DEJA_DUP_TYPE_TOGGLABLE, DejaDupTogglable))
#define DEJA_DUP_IS_TOGGLABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DEJA_DUP_TYPE_TOGGLABLE))
#define DEJA_DUP_TOGGLABLE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), DEJA_DUP_TYPE_TOGGLABLE, DejaDupTogglableIface))

typedef struct _DejaDupTogglable DejaDupTogglable;
typedef struct _DejaDupTogglableIface DejaDupTogglableIface;

#define DEJA_DUP_TYPE_CONFIG_BOOL (deja_dup_config_bool_get_type ())
#define DEJA_DUP_CONFIG_BOOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DEJA_DUP_TYPE_CONFIG_BOOL, DejaDupConfigBool))
#define DEJA_DUP_CONFIG_BOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DEJA_DUP_TYPE_CONFIG_BOOL, DejaDupConfigBoolClass))
#define DEJA_DUP_IS_CONFIG_BOOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DEJA_DUP_TYPE_CONFIG_BOOL))
#define DEJA_DUP_IS_CONFIG_BOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DEJA_DUP_TYPE_CONFIG_BOOL))
#define DEJA_DUP_CONFIG_BOOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DEJA_DUP_TYPE_CONFIG_BOOL, DejaDupConfigBoolClass))

typedef struct _DejaDupConfigBool DejaDupConfigBool;
typedef struct _DejaDupConfigBoolClass DejaDupConfigBoolClass;
typedef struct _DejaDupConfigBoolPrivate DejaDupConfigBoolPrivate;
#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_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _DejaDupConfigWidget {
	GtkEventBox parent_instance;
	DejaDupConfigWidgetPrivate * priv;
	GConfClient* client;
};

struct _DejaDupConfigWidgetClass {
	GtkEventBoxClass parent_class;
	void (*set_from_config) (DejaDupConfigWidget* self);
};

struct _DejaDupTogglableIface {
	GTypeInterface parent_iface;
	gboolean (*get_active) (DejaDupTogglable* self);
};

struct _DejaDupConfigBool {
	DejaDupConfigWidget parent_instance;
	DejaDupConfigBoolPrivate * priv;
};

struct _DejaDupConfigBoolClass {
	DejaDupConfigWidgetClass parent_class;
};

struct _DejaDupConfigBoolPrivate {
	char* _label;
	GtkCheckButton* button;
};


static gpointer deja_dup_config_bool_parent_class = NULL;
static DejaDupTogglableIface* deja_dup_config_bool_deja_dup_togglable_parent_iface = NULL;

GType deja_dup_config_widget_get_type (void);
GType deja_dup_togglable_get_type (void);
GType deja_dup_config_bool_get_type (void);
#define DEJA_DUP_CONFIG_BOOL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DEJA_DUP_TYPE_CONFIG_BOOL, DejaDupConfigBoolPrivate))
enum  {
	DEJA_DUP_CONFIG_BOOL_DUMMY_PROPERTY,
	DEJA_DUP_CONFIG_BOOL_LABEL
};
DejaDupConfigBool* deja_dup_config_bool_new (const char* key, const char* label);
DejaDupConfigBool* deja_dup_config_bool_construct (GType object_type, const char* key, const char* label);
static gboolean deja_dup_config_bool_real_get_active (DejaDupTogglable* base);
const char* deja_dup_config_widget_get_key (DejaDupConfigWidget* self);
static void deja_dup_config_bool_real_set_from_config (DejaDupConfigWidget* base);
static void deja_dup_config_bool_handle_toggled (DejaDupConfigBool* self);
const char* deja_dup_config_bool_get_label (DejaDupConfigBool* self);
static void deja_dup_config_bool_set_label (DejaDupConfigBool* self, const char* value);
void deja_dup_config_widget_set_from_config (DejaDupConfigWidget* self);
static void _deja_dup_config_bool_handle_toggled_gtk_toggle_button_toggled (GtkToggleButton* _sender, gpointer self);
static GObject * deja_dup_config_bool_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
static void deja_dup_config_bool_finalize (GObject* obj);
static void deja_dup_config_bool_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void deja_dup_config_bool_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);



DejaDupConfigBool* deja_dup_config_bool_construct (GType object_type, const char* key, const char* label) {
	DejaDupConfigBool * self;
	g_return_val_if_fail (key != NULL, NULL);
	g_return_val_if_fail (label != NULL, NULL);
	self = (DejaDupConfigBool*) g_object_new (object_type, "key", key, "label", label, NULL);
	return self;
}


DejaDupConfigBool* deja_dup_config_bool_new (const char* key, const char* label) {
	return deja_dup_config_bool_construct (DEJA_DUP_TYPE_CONFIG_BOOL, key, label);
}


static gboolean deja_dup_config_bool_real_get_active (DejaDupTogglable* base) {
	DejaDupConfigBool * self;
	gboolean result = FALSE;
	self = (DejaDupConfigBool*) base;
	result = gtk_toggle_button_get_active ((GtkToggleButton*) self->priv->button);
	return result;
}


static void deja_dup_config_bool_real_set_from_config (DejaDupConfigWidget* base) {
	DejaDupConfigBool * self;
	GError * _inner_error_;
	self = (DejaDupConfigBool*) base;
	_inner_error_ = NULL;
	{
		gboolean val;
		val = gconf_client_get_bool (((DejaDupConfigWidget*) self)->client, deja_dup_config_widget_get_key ((DejaDupConfigWidget*) self), &_inner_error_);
		if (_inner_error_ != NULL) {
			goto __catch1_g_error;
		}
		gtk_toggle_button_set_active ((GtkToggleButton*) self->priv->button, val);
	}
	goto __finally1;
	__catch1_g_error:
	{
		GError * e;
		e = _inner_error_;
		_inner_error_ = NULL;
		{
			g_warning ("ConfigBool.vala:51: %s\n", e->message);
			_g_error_free0 (e);
		}
	}
	__finally1:
	if (_inner_error_ != NULL) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return;
	}
}


static void deja_dup_config_bool_handle_toggled (DejaDupConfigBool* self) {
	GError * _inner_error_;
	g_return_if_fail (self != NULL);
	_inner_error_ = NULL;
	{
		gconf_client_set_bool (((DejaDupConfigWidget*) self)->client, deja_dup_config_widget_get_key ((DejaDupConfigWidget*) self), gtk_toggle_button_get_active ((GtkToggleButton*) self->priv->button), &_inner_error_);
		if (_inner_error_ != NULL) {
			goto __catch2_g_error;
		}
	}
	goto __finally2;
	__catch2_g_error:
	{
		GError * e;
		e = _inner_error_;
		_inner_error_ = NULL;
		{
			g_warning ("ConfigBool.vala:61: %s\n", e->message);
			_g_error_free0 (e);
		}
	}
	__finally2:
	if (_inner_error_ != NULL) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return;
	}
	g_signal_emit_by_name ((DejaDupTogglable*) self, "toggled");
}


const char* deja_dup_config_bool_get_label (DejaDupConfigBool* self) {
	const char* result;
	g_return_val_if_fail (self != NULL, NULL);
	result = self->priv->_label;
	return result;
}


static void deja_dup_config_bool_set_label (DejaDupConfigBool* self, const char* value) {
	char* _tmp0_;
	g_return_if_fail (self != NULL);
	self->priv->_label = (_tmp0_ = g_strdup (value), _g_free0 (self->priv->_label), _tmp0_);
	g_object_notify ((GObject *) self, "label");
}


static void _deja_dup_config_bool_handle_toggled_gtk_toggle_button_toggled (GtkToggleButton* _sender, gpointer self) {
	deja_dup_config_bool_handle_toggled (self);
}


static GObject * deja_dup_config_bool_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	GObjectClass * parent_class;
	DejaDupConfigBool * self;
	parent_class = G_OBJECT_CLASS (deja_dup_config_bool_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = DEJA_DUP_CONFIG_BOOL (obj);
	{
		GtkCheckButton* _tmp0_;
		self->priv->button = (_tmp0_ = g_object_ref_sink ((GtkCheckButton*) gtk_check_button_new_with_mnemonic (self->priv->_label)), _g_object_unref0 (self->priv->button), _tmp0_);
		gtk_container_add ((GtkContainer*) self, (GtkWidget*) self->priv->button);
		deja_dup_config_widget_set_from_config ((DejaDupConfigWidget*) self);
		g_signal_connect_object ((GtkToggleButton*) self->priv->button, "toggled", (GCallback) _deja_dup_config_bool_handle_toggled_gtk_toggle_button_toggled, self, 0);
	}
	return obj;
}


static void deja_dup_config_bool_class_init (DejaDupConfigBoolClass * klass) {
	deja_dup_config_bool_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (DejaDupConfigBoolPrivate));
	DEJA_DUP_CONFIG_WIDGET_CLASS (klass)->set_from_config = deja_dup_config_bool_real_set_from_config;
	G_OBJECT_CLASS (klass)->get_property = deja_dup_config_bool_get_property;
	G_OBJECT_CLASS (klass)->set_property = deja_dup_config_bool_set_property;
	G_OBJECT_CLASS (klass)->constructor = deja_dup_config_bool_constructor;
	G_OBJECT_CLASS (klass)->finalize = deja_dup_config_bool_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DEJA_DUP_CONFIG_BOOL_LABEL, g_param_spec_string ("label", "label", "label", 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_config_bool_deja_dup_togglable_interface_init (DejaDupTogglableIface * iface) {
	deja_dup_config_bool_deja_dup_togglable_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_active = deja_dup_config_bool_real_get_active;
}


static void deja_dup_config_bool_instance_init (DejaDupConfigBool * self) {
	self->priv = DEJA_DUP_CONFIG_BOOL_GET_PRIVATE (self);
}


static void deja_dup_config_bool_finalize (GObject* obj) {
	DejaDupConfigBool * self;
	self = DEJA_DUP_CONFIG_BOOL (obj);
	_g_free0 (self->priv->_label);
	_g_object_unref0 (self->priv->button);
	G_OBJECT_CLASS (deja_dup_config_bool_parent_class)->finalize (obj);
}


GType deja_dup_config_bool_get_type (void) {
	static volatile gsize deja_dup_config_bool_type_id__volatile = 0;
	if (g_once_init_enter (&deja_dup_config_bool_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (DejaDupConfigBoolClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) deja_dup_config_bool_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DejaDupConfigBool), 0, (GInstanceInitFunc) deja_dup_config_bool_instance_init, NULL };
		static const GInterfaceInfo deja_dup_togglable_info = { (GInterfaceInitFunc) deja_dup_config_bool_deja_dup_togglable_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		GType deja_dup_config_bool_type_id;
		deja_dup_config_bool_type_id = g_type_register_static (DEJA_DUP_TYPE_CONFIG_WIDGET, "DejaDupConfigBool", &g_define_type_info, 0);
		g_type_add_interface_static (deja_dup_config_bool_type_id, DEJA_DUP_TYPE_TOGGLABLE, &deja_dup_togglable_info);
		g_once_init_leave (&deja_dup_config_bool_type_id__volatile, deja_dup_config_bool_type_id);
	}
	return deja_dup_config_bool_type_id__volatile;
}


static void deja_dup_config_bool_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	DejaDupConfigBool * self;
	self = DEJA_DUP_CONFIG_BOOL (object);
	switch (property_id) {
		case DEJA_DUP_CONFIG_BOOL_LABEL:
		g_value_set_string (value, deja_dup_config_bool_get_label (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void deja_dup_config_bool_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	DejaDupConfigBool * self;
	self = DEJA_DUP_CONFIG_BOOL (object);
	switch (property_id) {
		case DEJA_DUP_CONFIG_BOOL_LABEL:
		deja_dup_config_bool_set_label (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}




