/* gmpc-paned-size-group.c generated by valac 0.12.0, the Vala compiler
 * generated from gmpc-paned-size-group.vala, do not modify */

/* Gnome Music Player Client (GMPC)
 * Copyright (C) 2004-2011 Qball Cow <qball@gmpclient.org>
 * Project homepage: http://gmpclient.org/
 
 * This program 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 2 of the License, or
 * (at your option) any later version.

 * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include <glib.h>
#include <glib-object.h>
#include "gmpc-extras.h"
#include <gtk/gtk.h>
#include <plugin.h>
#include <config1.h>
#include <gdk/gdk.h>

#define _g_list_free0(var) ((var == NULL) ? NULL : (var = (g_list_free (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _GmpcPanedSizeGroupPrivate {
	GList* list;
	gint position;
	gboolean block_changed_callback;
};


static gpointer gmpc_paned_size_group_parent_class = NULL;

#define GMPC_PANED_SIZE_GROUP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GMPC_TYPE_PANED_SIZE_GROUP, GmpcPanedSizeGroupPrivate))
enum  {
	GMPC_PANED_SIZE_GROUP_DUMMY_PROPERTY
};
static gboolean gmpc_paned_size_group_child_destroy_event (GmpcPanedSizeGroup* self, GtkWidget* paned, GdkEvent* event);
static void gmpc_paned_size_group_child_position_changed (GmpcPanedSizeGroup* self, GObject* paned, GParamSpec* spec);
static void _gmpc_paned_size_group_child_position_changed_g_object_notify (GObject* _sender, GParamSpec* pspec, gpointer self);
static gboolean _gmpc_paned_size_group_child_destroy_event_gtk_widget_destroy_event (GtkWidget* _sender, GdkEvent* event, gpointer self);
static void gmpc_paned_size_group_finalize (GObject* obj);


GmpcPanedSizeGroup* gmpc_paned_size_group_construct (GType object_type) {
	GmpcPanedSizeGroup * self = NULL;
	self = (GmpcPanedSizeGroup*) g_object_new (object_type, NULL);
	return self;
}


GmpcPanedSizeGroup* gmpc_paned_size_group_new (void) {
	return gmpc_paned_size_group_construct (GMPC_TYPE_PANED_SIZE_GROUP);
}


static gboolean gmpc_paned_size_group_child_destroy_event (GmpcPanedSizeGroup* self, GtkWidget* paned, GdkEvent* event) {
	gboolean result = FALSE;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (paned != NULL, FALSE);
	g_return_val_if_fail (event != NULL, FALSE);
	self->priv->list = g_list_remove (self->priv->list, GTK_PANED (paned));
	result = FALSE;
	return result;
}


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


static void gmpc_paned_size_group_child_position_changed (GmpcPanedSizeGroup* self, GObject* paned, GParamSpec* spec) {
	GtkPaned* _tmp0_;
	GtkPaned* pane;
	gint _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (paned != NULL);
	g_return_if_fail (spec != NULL);
	if (self->priv->block_changed_callback) {
		return;
	}
	self->priv->block_changed_callback = TRUE;
	_tmp0_ = _g_object_ref0 (GTK_PANED (paned));
	pane = _tmp0_;
	_tmp1_ = gtk_paned_get_position (pane);
	self->priv->position = _tmp1_;
	{
		GList* p_collection;
		GList* p_it;
		p_collection = self->priv->list;
		for (p_it = p_collection; p_it != NULL; p_it = p_it->next) {
			GtkPaned* p;
			p = (GtkPaned*) p_it->data;
			{
				if (G_OBJECT (p) != paned) {
					gtk_paned_set_position (p, self->priv->position);
				}
			}
		}
	}
	self->priv->block_changed_callback = FALSE;
	_g_object_unref0 (pane);
}


static void _gmpc_paned_size_group_child_position_changed_g_object_notify (GObject* _sender, GParamSpec* pspec, gpointer self) {
	gmpc_paned_size_group_child_position_changed (self, _sender, pspec);
}


static gboolean _gmpc_paned_size_group_child_destroy_event_gtk_widget_destroy_event (GtkWidget* _sender, GdkEvent* event, gpointer self) {
	gboolean result;
	result = gmpc_paned_size_group_child_destroy_event (self, _sender, event);
	return result;
}


void gmpc_paned_size_group_add_paned (GmpcPanedSizeGroup* self, GtkPaned* paned) {
	g_return_if_fail (self != NULL);
	g_return_if_fail (paned != NULL);
	g_signal_connect_object ((GObject*) paned, "notify::position", (GCallback) _gmpc_paned_size_group_child_position_changed_g_object_notify, self, 0);
	g_signal_connect_object ((GtkWidget*) paned, "destroy-event", (GCallback) _gmpc_paned_size_group_child_destroy_event_gtk_widget_destroy_event, self, 0);
	self->priv->block_changed_callback = TRUE;
	gtk_paned_set_position (paned, self->priv->position);
	self->priv->block_changed_callback = FALSE;
	self->priv->list = g_list_append (self->priv->list, paned);
}


static void gmpc_paned_size_group_class_init (GmpcPanedSizeGroupClass * klass) {
	gmpc_paned_size_group_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GmpcPanedSizeGroupPrivate));
	G_OBJECT_CLASS (klass)->finalize = gmpc_paned_size_group_finalize;
}


static void gmpc_paned_size_group_instance_init (GmpcPanedSizeGroup * self) {
	gint _tmp0_;
	self->priv = GMPC_PANED_SIZE_GROUP_GET_PRIVATE (self);
	self->priv->list = NULL;
	_tmp0_ = cfg_get_single_value_as_int_with_default (config, "paned-size-group", "position", 150);
	self->priv->position = _tmp0_;
	self->priv->block_changed_callback = FALSE;
}


static void gmpc_paned_size_group_finalize (GObject* obj) {
	GmpcPanedSizeGroup * self;
	self = GMPC_PANED_SIZE_GROUP (obj);
	cfg_set_single_value_as_int (config, "paned-size-group", "position", self->priv->position);
	_g_list_free0 (self->priv->list);
	G_OBJECT_CLASS (gmpc_paned_size_group_parent_class)->finalize (obj);
}


GType gmpc_paned_size_group_get_type (void) {
	static volatile gsize gmpc_paned_size_group_type_id__volatile = 0;
	if (g_once_init_enter (&gmpc_paned_size_group_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (GmpcPanedSizeGroupClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gmpc_paned_size_group_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GmpcPanedSizeGroup), 0, (GInstanceInitFunc) gmpc_paned_size_group_instance_init, NULL };
		GType gmpc_paned_size_group_type_id;
		gmpc_paned_size_group_type_id = g_type_register_static (G_TYPE_OBJECT, "GmpcPanedSizeGroup", &g_define_type_info, 0);
		g_once_init_leave (&gmpc_paned_size_group_type_id__volatile, gmpc_paned_size_group_type_id);
	}
	return gmpc_paned_size_group_type_id__volatile;
}



