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

/*
 * Copyright (c) 2011-2018 elementary, Inc. (https://elementary.io)
 *
 * 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 "wingpanel.h"
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
#include <glib-object.h>
#include <gdk/gdk.h>

enum  {
	WINGPANEL_WIDGETS_SWITCH_0_PROPERTY,
	WINGPANEL_WIDGETS_SWITCH_ACTIVE_PROPERTY,
	WINGPANEL_WIDGETS_SWITCH_CAPTION_PROPERTY,
	WINGPANEL_WIDGETS_SWITCH_NUM_PROPERTIES
};
static GParamSpec* wingpanel_widgets_switch_properties[WINGPANEL_WIDGETS_SWITCH_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _WingpanelWidgetsSwitchPrivate {
	gboolean _active;
	gchar* _caption;
	GtkLabel* button_label;
	GtkSwitch* button_switch;
};

static gint WingpanelWidgetsSwitch_private_offset;
static gpointer wingpanel_widgets_switch_parent_class = NULL;

static GObject * wingpanel_widgets_switch_constructor (GType type,
                                                guint n_construct_properties,
                                                GObjectConstructParam * construct_properties);
static gboolean _wingpanel_widgets_switch___lambda10_ (WingpanelWidgetsSwitch* self);
static gboolean __wingpanel_widgets_switch___lambda10__gtk_widget_button_release_event (GtkWidget* _sender,
                                                                                 GdkEventButton* event,
                                                                                 gpointer self);
static void wingpanel_widgets_switch_finalize (GObject * obj);
static GType wingpanel_widgets_switch_get_type_once (void);
static void _vala_wingpanel_widgets_switch_get_property (GObject * object,
                                                  guint property_id,
                                                  GValue * value,
                                                  GParamSpec * pspec);
static void _vala_wingpanel_widgets_switch_set_property (GObject * object,
                                                  guint property_id,
                                                  const GValue * value,
                                                  GParamSpec * pspec);

static inline gpointer
wingpanel_widgets_switch_get_instance_private (WingpanelWidgetsSwitch* self)
{
	return G_STRUCT_MEMBER_P (self, WingpanelWidgetsSwitch_private_offset);
}

WingpanelWidgetsSwitch*
wingpanel_widgets_switch_construct (GType object_type,
                                    const gchar* caption,
                                    gboolean active)
{
	WingpanelWidgetsSwitch * self = NULL;
	g_return_val_if_fail (caption != NULL, NULL);
	self = (WingpanelWidgetsSwitch*) g_object_new (object_type, "caption", caption, "active", active, NULL);
	return self;
}

WingpanelWidgetsSwitch*
wingpanel_widgets_switch_new (const gchar* caption,
                              gboolean active)
{
	return wingpanel_widgets_switch_construct (WINGPANEL_WIDGETS_TYPE_SWITCH, caption, active);
}

WingpanelWidgetsSwitch*
wingpanel_widgets_switch_construct_with_mnemonic (GType object_type,
                                                  const gchar* caption,
                                                  gboolean active)
{
	WingpanelWidgetsSwitch * self = NULL;
	GtkLabel* _tmp0_;
	GtkLabel* _tmp1_;
	g_return_val_if_fail (caption != NULL, NULL);
	self = (WingpanelWidgetsSwitch*) g_object_new (object_type, "caption", caption, "active", active, NULL);
	_tmp0_ = self->priv->button_label;
	gtk_label_set_text_with_mnemonic (_tmp0_, caption);
	_tmp1_ = self->priv->button_label;
	gtk_label_set_mnemonic_widget (_tmp1_, (GtkWidget*) self);
	return self;
}

WingpanelWidgetsSwitch*
wingpanel_widgets_switch_new_with_mnemonic (const gchar* caption,
                                            gboolean active)
{
	return wingpanel_widgets_switch_construct_with_mnemonic (WINGPANEL_WIDGETS_TYPE_SWITCH, caption, active);
}

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

GtkLabel*
wingpanel_widgets_switch_get_label (WingpanelWidgetsSwitch* self)
{
	GtkLabel* _tmp0_;
	GtkLabel* _tmp1_;
	GtkLabel* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->button_label;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	result = _tmp1_;
	return result;
}

GtkSwitch*
wingpanel_widgets_switch_get_switch (WingpanelWidgetsSwitch* self)
{
	GtkSwitch* _tmp0_;
	GtkSwitch* _tmp1_;
	GtkSwitch* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->button_switch;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	result = _tmp1_;
	return result;
}

void
wingpanel_widgets_switch_toggle_switch (WingpanelWidgetsSwitch* self)
{
	GtkSwitch* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->button_switch;
	g_signal_emit_by_name (_tmp0_, "activate");
}

gboolean
wingpanel_widgets_switch_get_active (WingpanelWidgetsSwitch* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_active;
	return result;
}

void
wingpanel_widgets_switch_set_active (WingpanelWidgetsSwitch* self,
                                     gboolean value)
{
	gboolean old_value;
	g_return_if_fail (self != NULL);
	old_value = wingpanel_widgets_switch_get_active (self);
	if (old_value != value) {
		self->priv->_active = value;
		g_object_notify_by_pspec ((GObject *) self, wingpanel_widgets_switch_properties[WINGPANEL_WIDGETS_SWITCH_ACTIVE_PROPERTY]);
	}
}

gchar*
wingpanel_widgets_switch_get_caption (WingpanelWidgetsSwitch* self)
{
	gchar* result;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_caption;
	_tmp1_ = g_strdup (_tmp0_);
	result = _tmp1_;
	return result;
}

void
wingpanel_widgets_switch_set_caption (WingpanelWidgetsSwitch* self,
                                      const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = wingpanel_widgets_switch_get_caption (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_caption);
		self->priv->_caption = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, wingpanel_widgets_switch_properties[WINGPANEL_WIDGETS_SWITCH_CAPTION_PROPERTY]);
	}
	_g_free0 (old_value);
}

static gboolean
_wingpanel_widgets_switch___lambda10_ (WingpanelWidgetsSwitch* self)
{
	gboolean result;
	wingpanel_widgets_switch_toggle_switch (self);
	result = GDK_EVENT_STOP;
	return result;
}

static gboolean
__wingpanel_widgets_switch___lambda10__gtk_widget_button_release_event (GtkWidget* _sender,
                                                                        GdkEventButton* event,
                                                                        gpointer self)
{
	gboolean result;
	result = _wingpanel_widgets_switch___lambda10_ ((WingpanelWidgetsSwitch*) self);
	return result;
}

static GObject *
wingpanel_widgets_switch_constructor (GType type,
                                      guint n_construct_properties,
                                      GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	WingpanelWidgetsSwitch * self;
	GtkSwitch* _tmp0_;
	GtkSwitch* _tmp1_;
	gboolean _tmp2_;
	GtkSwitch* _tmp3_;
	GtkSwitch* _tmp4_;
	GtkSwitch* _tmp5_;
	GtkLabel* _tmp6_;
	GtkLabel* _tmp7_;
	GtkGrid* grid = NULL;
	GtkGrid* _tmp8_;
	GtkGrid* _tmp9_;
	GtkGrid* _tmp10_;
	GtkLabel* _tmp11_;
	GtkGrid* _tmp12_;
	GtkSwitch* _tmp13_;
	GtkModelButton* modelbutton = NULL;
	GtkModelButton* _tmp14_;
	GtkModelButton* _tmp15_;
	GtkWidget* _tmp16_;
	GtkModelButton* _tmp17_;
	GtkGrid* _tmp18_;
	GtkModelButton* _tmp19_;
	GtkModelButton* _tmp20_;
	GtkSwitch* _tmp21_;
	GtkLabel* _tmp22_;
	parent_class = G_OBJECT_CLASS (wingpanel_widgets_switch_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WINGPANEL_WIDGETS_TYPE_SWITCH, WingpanelWidgetsSwitch);
	_tmp0_ = (GtkSwitch*) gtk_switch_new ();
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->button_switch);
	self->priv->button_switch = _tmp0_;
	_tmp1_ = self->priv->button_switch;
	_tmp2_ = self->priv->_active;
	gtk_switch_set_active (_tmp1_, _tmp2_);
	_tmp3_ = self->priv->button_switch;
	gtk_widget_set_halign ((GtkWidget*) _tmp3_, GTK_ALIGN_END);
	_tmp4_ = self->priv->button_switch;
	gtk_widget_set_hexpand ((GtkWidget*) _tmp4_, TRUE);
	_tmp5_ = self->priv->button_switch;
	gtk_widget_set_valign ((GtkWidget*) _tmp5_, GTK_ALIGN_CENTER);
	_tmp6_ = (GtkLabel*) gtk_label_new (NULL);
	g_object_ref_sink (_tmp6_);
	_g_object_unref0 (self->priv->button_label);
	self->priv->button_label = _tmp6_;
	_tmp7_ = self->priv->button_label;
	gtk_widget_set_halign ((GtkWidget*) _tmp7_, GTK_ALIGN_START);
	_tmp8_ = (GtkGrid*) gtk_grid_new ();
	g_object_ref_sink (_tmp8_);
	grid = _tmp8_;
	_tmp9_ = grid;
	gtk_grid_set_column_spacing (_tmp9_, 12);
	_tmp10_ = grid;
	_tmp11_ = self->priv->button_label;
	gtk_grid_attach (_tmp10_, (GtkWidget*) _tmp11_, 0, 0, 1, 1);
	_tmp12_ = grid;
	_tmp13_ = self->priv->button_switch;
	gtk_grid_attach (_tmp12_, (GtkWidget*) _tmp13_, 1, 0, 1, 1);
	_tmp14_ = (GtkModelButton*) gtk_model_button_new ();
	g_object_ref_sink (_tmp14_);
	modelbutton = _tmp14_;
	_tmp15_ = modelbutton;
	_tmp16_ = gtk_bin_get_child ((GtkBin*) _tmp15_);
	gtk_widget_destroy (_tmp16_);
	_tmp17_ = modelbutton;
	_tmp18_ = grid;
	gtk_container_add ((GtkContainer*) _tmp17_, (GtkWidget*) _tmp18_);
	_tmp19_ = modelbutton;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp19_);
	_tmp20_ = modelbutton;
	g_signal_connect_object ((GtkWidget*) _tmp20_, "button-release-event", (GCallback) __wingpanel_widgets_switch___lambda10__gtk_widget_button_release_event, self, 0);
	_tmp21_ = self->priv->button_switch;
	g_object_bind_property_with_closures ((GObject*) self, "active", (GObject*) _tmp21_, "active", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	_tmp22_ = self->priv->button_label;
	g_object_bind_property_with_closures ((GObject*) self, "caption", (GObject*) _tmp22_, "label", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	_g_object_unref0 (modelbutton);
	_g_object_unref0 (grid);
	return obj;
}

static void
wingpanel_widgets_switch_class_init (WingpanelWidgetsSwitchClass * klass,
                                     gpointer klass_data)
{
	wingpanel_widgets_switch_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &WingpanelWidgetsSwitch_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_wingpanel_widgets_switch_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_wingpanel_widgets_switch_set_property;
	G_OBJECT_CLASS (klass)->constructor = wingpanel_widgets_switch_constructor;
	G_OBJECT_CLASS (klass)->finalize = wingpanel_widgets_switch_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), WINGPANEL_WIDGETS_SWITCH_ACTIVE_PROPERTY, wingpanel_widgets_switch_properties[WINGPANEL_WIDGETS_SWITCH_ACTIVE_PROPERTY] = g_param_spec_boolean ("active", "active", "active", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), WINGPANEL_WIDGETS_SWITCH_CAPTION_PROPERTY, wingpanel_widgets_switch_properties[WINGPANEL_WIDGETS_SWITCH_CAPTION_PROPERTY] = g_param_spec_string ("caption", "caption", "caption", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
wingpanel_widgets_switch_instance_init (WingpanelWidgetsSwitch * self,
                                        gpointer klass)
{
	self->priv = wingpanel_widgets_switch_get_instance_private (self);
}

static void
wingpanel_widgets_switch_finalize (GObject * obj)
{
	WingpanelWidgetsSwitch * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WINGPANEL_WIDGETS_TYPE_SWITCH, WingpanelWidgetsSwitch);
	_g_free0 (self->priv->_caption);
	_g_object_unref0 (self->priv->button_label);
	_g_object_unref0 (self->priv->button_switch);
	G_OBJECT_CLASS (wingpanel_widgets_switch_parent_class)->finalize (obj);
}

static GType
wingpanel_widgets_switch_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (WingpanelWidgetsSwitchClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) wingpanel_widgets_switch_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (WingpanelWidgetsSwitch), 0, (GInstanceInitFunc) wingpanel_widgets_switch_instance_init, NULL };
	GType wingpanel_widgets_switch_type_id;
	wingpanel_widgets_switch_type_id = g_type_register_static (gtk_bin_get_type (), "WingpanelWidgetsSwitch", &g_define_type_info, 0);
	WingpanelWidgetsSwitch_private_offset = g_type_add_instance_private (wingpanel_widgets_switch_type_id, sizeof (WingpanelWidgetsSwitchPrivate));
	return wingpanel_widgets_switch_type_id;
}

GType
wingpanel_widgets_switch_get_type (void)
{
	static volatile gsize wingpanel_widgets_switch_type_id__once = 0;
	if (g_once_init_enter (&wingpanel_widgets_switch_type_id__once)) {
		GType wingpanel_widgets_switch_type_id;
		wingpanel_widgets_switch_type_id = wingpanel_widgets_switch_get_type_once ();
		g_once_init_leave (&wingpanel_widgets_switch_type_id__once, wingpanel_widgets_switch_type_id);
	}
	return wingpanel_widgets_switch_type_id__once;
}

static void
_vala_wingpanel_widgets_switch_get_property (GObject * object,
                                             guint property_id,
                                             GValue * value,
                                             GParamSpec * pspec)
{
	WingpanelWidgetsSwitch * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, WINGPANEL_WIDGETS_TYPE_SWITCH, WingpanelWidgetsSwitch);
	switch (property_id) {
		case WINGPANEL_WIDGETS_SWITCH_ACTIVE_PROPERTY:
		g_value_set_boolean (value, wingpanel_widgets_switch_get_active (self));
		break;
		case WINGPANEL_WIDGETS_SWITCH_CAPTION_PROPERTY:
		g_value_take_string (value, wingpanel_widgets_switch_get_caption (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_wingpanel_widgets_switch_set_property (GObject * object,
                                             guint property_id,
                                             const GValue * value,
                                             GParamSpec * pspec)
{
	WingpanelWidgetsSwitch * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, WINGPANEL_WIDGETS_TYPE_SWITCH, WingpanelWidgetsSwitch);
	switch (property_id) {
		case WINGPANEL_WIDGETS_SWITCH_ACTIVE_PROPERTY:
		wingpanel_widgets_switch_set_active (self, g_value_get_boolean (value));
		break;
		case WINGPANEL_WIDGETS_SWITCH_CAPTION_PROPERTY:
		wingpanel_widgets_switch_set_caption (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

