/* ToggleGroup.c generated by valac, the Vala compiler
 * generated from ToggleGroup.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>


#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_TOGGLE_GROUP (deja_dup_toggle_group_get_type ())
#define DEJA_DUP_TOGGLE_GROUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DEJA_DUP_TYPE_TOGGLE_GROUP, DejaDupToggleGroup))
#define DEJA_DUP_TOGGLE_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DEJA_DUP_TYPE_TOGGLE_GROUP, DejaDupToggleGroupClass))
#define DEJA_DUP_IS_TOGGLE_GROUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DEJA_DUP_TYPE_TOGGLE_GROUP))
#define DEJA_DUP_IS_TOGGLE_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DEJA_DUP_TYPE_TOGGLE_GROUP))
#define DEJA_DUP_TOGGLE_GROUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DEJA_DUP_TYPE_TOGGLE_GROUP, DejaDupToggleGroupClass))

typedef struct _DejaDupToggleGroup DejaDupToggleGroup;
typedef struct _DejaDupToggleGroupClass DejaDupToggleGroupClass;
typedef struct _DejaDupToggleGroupPrivate DejaDupToggleGroupPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define __g_list_free_g_object_unref0(var) ((var == NULL) ? NULL : (var = (_g_list_free_g_object_unref (var), NULL)))

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

struct _DejaDupToggleGroup {
	GObject parent_instance;
	DejaDupToggleGroupPrivate * priv;
};

struct _DejaDupToggleGroupClass {
	GObjectClass parent_class;
};

struct _DejaDupToggleGroupPrivate {
	DejaDupTogglable* _toggle;
	GList* dependents;
};


static gpointer deja_dup_toggle_group_parent_class = NULL;

GType deja_dup_togglable_get_type (void);
gboolean deja_dup_togglable_get_active (DejaDupTogglable* self);
GType deja_dup_toggle_group_get_type (void);
#define DEJA_DUP_TOGGLE_GROUP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DEJA_DUP_TYPE_TOGGLE_GROUP, DejaDupToggleGroupPrivate))
enum  {
	DEJA_DUP_TOGGLE_GROUP_DUMMY_PROPERTY,
	DEJA_DUP_TOGGLE_GROUP_TOGGLE
};
static void _g_list_free_g_object_unref (GList* self);
DejaDupToggleGroup* deja_dup_toggle_group_new (DejaDupTogglable* toggle);
DejaDupToggleGroup* deja_dup_toggle_group_construct (GType object_type, DejaDupTogglable* toggle);
void deja_dup_toggle_group_add_dependent (DejaDupToggleGroup* self, GtkWidget* w);
DejaDupTogglable* deja_dup_toggle_group_get_toggle (DejaDupToggleGroup* self);
void deja_dup_toggle_group_check (DejaDupToggleGroup* self);
static void deja_dup_toggle_group_set_toggle (DejaDupToggleGroup* self, DejaDupTogglable* value);
static void _lambda5_ (DejaDupTogglable* t, DejaDupToggleGroup* self);
static void __lambda5__deja_dup_togglable_toggled (DejaDupTogglable* _sender, gpointer self);
static GObject * deja_dup_toggle_group_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
static void deja_dup_toggle_group_finalize (GObject* obj);
static void deja_dup_toggle_group_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void deja_dup_toggle_group_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);



gboolean deja_dup_togglable_get_active (DejaDupTogglable* self) {
	return DEJA_DUP_TOGGLABLE_GET_INTERFACE (self)->get_active (self);
}


static void deja_dup_togglable_base_init (DejaDupTogglableIface * iface) {
	static gboolean initialized = FALSE;
	if (!initialized) {
		initialized = TRUE;
		g_signal_new ("toggled", DEJA_DUP_TYPE_TOGGLABLE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	}
}


GType deja_dup_togglable_get_type (void) {
	static volatile gsize deja_dup_togglable_type_id__volatile = 0;
	if (g_once_init_enter (&deja_dup_togglable_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (DejaDupTogglableIface), (GBaseInitFunc) deja_dup_togglable_base_init, (GBaseFinalizeFunc) NULL, (GClassInitFunc) NULL, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
		GType deja_dup_togglable_type_id;
		deja_dup_togglable_type_id = g_type_register_static (G_TYPE_INTERFACE, "DejaDupTogglable", &g_define_type_info, 0);
		g_type_interface_add_prerequisite (deja_dup_togglable_type_id, G_TYPE_OBJECT);
		g_once_init_leave (&deja_dup_togglable_type_id__volatile, deja_dup_togglable_type_id);
	}
	return deja_dup_togglable_type_id__volatile;
}


static void _g_list_free_g_object_unref (GList* self) {
	g_list_foreach (self, (GFunc) g_object_unref, NULL);
	g_list_free (self);
}


DejaDupToggleGroup* deja_dup_toggle_group_construct (GType object_type, DejaDupTogglable* toggle) {
	DejaDupToggleGroup * self;
	g_return_val_if_fail (toggle != NULL, NULL);
	self = (DejaDupToggleGroup*) g_object_new (object_type, "toggle", toggle, NULL);
	return self;
}


DejaDupToggleGroup* deja_dup_toggle_group_new (DejaDupTogglable* toggle) {
	return deja_dup_toggle_group_construct (DEJA_DUP_TYPE_TOGGLE_GROUP, toggle);
}


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


void deja_dup_toggle_group_add_dependent (DejaDupToggleGroup* self, GtkWidget* w) {
	g_return_if_fail (self != NULL);
	g_return_if_fail (w != NULL);
	self->priv->dependents = g_list_append (self->priv->dependents, _g_object_ref0 (w));
}


void deja_dup_toggle_group_check (DejaDupToggleGroup* self) {
	gboolean on;
	g_return_if_fail (self != NULL);
	on = deja_dup_togglable_get_active (self->priv->_toggle);
	{
		GList* w_collection;
		GList* w_it;
		w_collection = self->priv->dependents;
		for (w_it = w_collection; w_it != NULL; w_it = w_it->next) {
			GtkWidget* w;
			w = _g_object_ref0 ((GtkWidget*) w_it->data);
			{
				gtk_widget_set_sensitive (w, on);
				_g_object_unref0 (w);
			}
		}
	}
}


DejaDupTogglable* deja_dup_toggle_group_get_toggle (DejaDupToggleGroup* self) {
	DejaDupTogglable* result;
	g_return_val_if_fail (self != NULL, NULL);
	result = self->priv->_toggle;
	return result;
}


static void deja_dup_toggle_group_set_toggle (DejaDupToggleGroup* self, DejaDupTogglable* value) {
	DejaDupTogglable* _tmp0_;
	g_return_if_fail (self != NULL);
	self->priv->_toggle = (_tmp0_ = _g_object_ref0 (value), _g_object_unref0 (self->priv->_toggle), _tmp0_);
	g_object_notify ((GObject *) self, "toggle");
}


static void _lambda5_ (DejaDupTogglable* t, DejaDupToggleGroup* self) {
	g_return_if_fail (t != NULL);
	deja_dup_toggle_group_check (self);
}


static void __lambda5__deja_dup_togglable_toggled (DejaDupTogglable* _sender, gpointer self) {
	_lambda5_ (_sender, self);
}


static GObject * deja_dup_toggle_group_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	GObjectClass * parent_class;
	DejaDupToggleGroup * self;
	parent_class = G_OBJECT_CLASS (deja_dup_toggle_group_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = DEJA_DUP_TOGGLE_GROUP (obj);
	{
		g_signal_connect_object (self->priv->_toggle, "toggled", (GCallback) __lambda5__deja_dup_togglable_toggled, self, 0);
	}
	return obj;
}


static void deja_dup_toggle_group_class_init (DejaDupToggleGroupClass * klass) {
	deja_dup_toggle_group_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (DejaDupToggleGroupPrivate));
	G_OBJECT_CLASS (klass)->get_property = deja_dup_toggle_group_get_property;
	G_OBJECT_CLASS (klass)->set_property = deja_dup_toggle_group_set_property;
	G_OBJECT_CLASS (klass)->constructor = deja_dup_toggle_group_constructor;
	G_OBJECT_CLASS (klass)->finalize = deja_dup_toggle_group_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DEJA_DUP_TOGGLE_GROUP_TOGGLE, g_param_spec_object ("toggle", "toggle", "toggle", DEJA_DUP_TYPE_TOGGLABLE, 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_toggle_group_instance_init (DejaDupToggleGroup * self) {
	self->priv = DEJA_DUP_TOGGLE_GROUP_GET_PRIVATE (self);
}


static void deja_dup_toggle_group_finalize (GObject* obj) {
	DejaDupToggleGroup * self;
	self = DEJA_DUP_TOGGLE_GROUP (obj);
	_g_object_unref0 (self->priv->_toggle);
	__g_list_free_g_object_unref0 (self->priv->dependents);
	G_OBJECT_CLASS (deja_dup_toggle_group_parent_class)->finalize (obj);
}


GType deja_dup_toggle_group_get_type (void) {
	static volatile gsize deja_dup_toggle_group_type_id__volatile = 0;
	if (g_once_init_enter (&deja_dup_toggle_group_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (DejaDupToggleGroupClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) deja_dup_toggle_group_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DejaDupToggleGroup), 0, (GInstanceInitFunc) deja_dup_toggle_group_instance_init, NULL };
		GType deja_dup_toggle_group_type_id;
		deja_dup_toggle_group_type_id = g_type_register_static (G_TYPE_OBJECT, "DejaDupToggleGroup", &g_define_type_info, 0);
		g_once_init_leave (&deja_dup_toggle_group_type_id__volatile, deja_dup_toggle_group_type_id);
	}
	return deja_dup_toggle_group_type_id__volatile;
}


static void deja_dup_toggle_group_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	DejaDupToggleGroup * self;
	self = DEJA_DUP_TOGGLE_GROUP (object);
	switch (property_id) {
		case DEJA_DUP_TOGGLE_GROUP_TOGGLE:
		g_value_set_object (value, deja_dup_toggle_group_get_toggle (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void deja_dup_toggle_group_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	DejaDupToggleGroup * self;
	self = DEJA_DUP_TOGGLE_GROUP (object);
	switch (property_id) {
		case DEJA_DUP_TOGGLE_GROUP_TOGGLE:
		deja_dup_toggle_group_set_toggle (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}




