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

/*
 * Copyright (c) 2018-2020 Daniel Pinto (https://github.com/danielpinto8zz6/budgie-network-applet)
 * 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 "networkapplet.h"
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
#include <glib-object.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

enum  {
	NETWORK_WIDGETS_SWITCH_0_PROPERTY,
	NETWORK_WIDGETS_SWITCH_ACTIVE_PROPERTY,
	NETWORK_WIDGETS_SWITCH_CAPTION_PROPERTY,
	NETWORK_WIDGETS_SWITCH_NUM_PROPERTIES
};
static GParamSpec* network_widgets_switch_properties[NETWORK_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 _NetworkWidgetsSwitchPrivate {
	gboolean _active;
	gchar* _caption;
	GtkLabel* button_label;
	GtkSwitch* button_switch;
};

static gint NetworkWidgetsSwitch_private_offset;
static gpointer network_widgets_switch_parent_class = NULL;
static GType network_widgets_switch_type_id = 0;

static void network_widgets_switch_finalize (GObject * obj);
static void _vala_network_widgets_switch_get_property (GObject * object,
                                                guint property_id,
                                                GValue * value,
                                                GParamSpec * pspec);
static void _vala_network_widgets_switch_set_property (GObject * object,
                                                guint property_id,
                                                const GValue * value,
                                                GParamSpec * pspec);

static inline gpointer
network_widgets_switch_get_instance_private (NetworkWidgetsSwitch* self)
{
	return G_STRUCT_MEMBER_P (self, NetworkWidgetsSwitch_private_offset);
}

NetworkWidgetsSwitch*
network_widgets_switch_construct (GType object_type,
                                  const gchar* caption)
{
	NetworkWidgetsSwitch * self = NULL;
	GtkLabel* _tmp0_;
	GtkLabel* _tmp1_;
	GtkLabel* _tmp2_;
	GtkLabel* _tmp3_;
	GtkSwitch* _tmp4_;
	GtkSwitch* _tmp5_;
	gboolean _tmp6_;
	GtkSwitch* _tmp7_;
	GtkSwitch* _tmp8_;
	GtkLabel* _tmp9_;
	GtkSwitch* _tmp10_;
	GtkSwitch* _tmp11_;
	GtkLabel* _tmp12_;
	g_return_val_if_fail (caption != NULL, NULL);
	self = (NetworkWidgetsSwitch*) g_object_new (object_type, "caption", caption, "orientation", GTK_ORIENTATION_HORIZONTAL, "hexpand", TRUE, NULL);
	_tmp0_ = (GtkLabel*) gtk_label_new (NULL);
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->button_label);
	self->priv->button_label = _tmp0_;
	_tmp1_ = self->priv->button_label;
	gtk_widget_set_halign ((GtkWidget*) _tmp1_, GTK_ALIGN_START);
	_tmp2_ = self->priv->button_label;
	gtk_widget_set_margin_start ((GtkWidget*) _tmp2_, 6);
	_tmp3_ = self->priv->button_label;
	gtk_widget_set_margin_end ((GtkWidget*) _tmp3_, 10);
	_tmp4_ = (GtkSwitch*) gtk_switch_new ();
	g_object_ref_sink (_tmp4_);
	_g_object_unref0 (self->priv->button_switch);
	self->priv->button_switch = _tmp4_;
	_tmp5_ = self->priv->button_switch;
	_tmp6_ = self->priv->_active;
	gtk_switch_set_active (_tmp5_, _tmp6_);
	_tmp7_ = self->priv->button_switch;
	gtk_widget_set_halign ((GtkWidget*) _tmp7_, GTK_ALIGN_END);
	_tmp8_ = self->priv->button_switch;
	gtk_widget_set_hexpand ((GtkWidget*) _tmp8_, TRUE);
	_tmp9_ = self->priv->button_label;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp9_);
	_tmp10_ = self->priv->button_switch;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp10_);
	_tmp11_ = self->priv->button_switch;
	g_object_bind_property_with_closures ((GObject*) self, "active", (GObject*) _tmp11_, "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)));
	_tmp12_ = self->priv->button_label;
	g_object_bind_property_with_closures ((GObject*) self, "caption", (GObject*) _tmp12_, "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)));
	return self;
}

NetworkWidgetsSwitch*
network_widgets_switch_new (const gchar* caption)
{
	return network_widgets_switch_construct (NETWORK_WIDGETS_TYPE_SWITCH, caption);
}

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

void
network_widgets_switch_set_active (NetworkWidgetsSwitch* self,
                                   gboolean value)
{
	gboolean old_value;
	g_return_if_fail (self != NULL);
	old_value = network_widgets_switch_get_active (self);
	if (old_value != value) {
		self->priv->_active = value;
		g_object_notify_by_pspec ((GObject *) self, network_widgets_switch_properties[NETWORK_WIDGETS_SWITCH_ACTIVE_PROPERTY]);
	}
}

gchar*
network_widgets_switch_get_caption (NetworkWidgetsSwitch* 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
network_widgets_switch_set_caption (NetworkWidgetsSwitch* self,
                                    const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = network_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, network_widgets_switch_properties[NETWORK_WIDGETS_SWITCH_CAPTION_PROPERTY]);
	}
	_g_free0 (old_value);
}

static void
network_widgets_switch_class_init (NetworkWidgetsSwitchClass * klass,
                                   gpointer klass_data)
{
	network_widgets_switch_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &NetworkWidgetsSwitch_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_network_widgets_switch_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_network_widgets_switch_set_property;
	G_OBJECT_CLASS (klass)->finalize = network_widgets_switch_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), NETWORK_WIDGETS_SWITCH_ACTIVE_PROPERTY, network_widgets_switch_properties[NETWORK_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), NETWORK_WIDGETS_SWITCH_CAPTION_PROPERTY, network_widgets_switch_properties[NETWORK_WIDGETS_SWITCH_CAPTION_PROPERTY] = g_param_spec_string ("caption", "caption", "caption", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
network_widgets_switch_instance_init (NetworkWidgetsSwitch * self,
                                      gpointer klass)
{
	self->priv = network_widgets_switch_get_instance_private (self);
}

static void
network_widgets_switch_finalize (GObject * obj)
{
	NetworkWidgetsSwitch * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, NETWORK_WIDGETS_TYPE_SWITCH, NetworkWidgetsSwitch);
	_g_free0 (self->priv->_caption);
	_g_object_unref0 (self->priv->button_label);
	_g_object_unref0 (self->priv->button_switch);
	G_OBJECT_CLASS (network_widgets_switch_parent_class)->finalize (obj);
}

GType
network_widgets_switch_get_type (void)
{
	return network_widgets_switch_type_id;
}

GType
network_widgets_switch_register_type (GTypeModule * module)
{
	static const GTypeInfo g_define_type_info = { sizeof (NetworkWidgetsSwitchClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) network_widgets_switch_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (NetworkWidgetsSwitch), 0, (GInstanceInitFunc) network_widgets_switch_instance_init, NULL };
	network_widgets_switch_type_id = g_type_module_register_type (module, gtk_box_get_type (), "NetworkWidgetsSwitch", &g_define_type_info, 0);
	NetworkWidgetsSwitch_private_offset = sizeof (NetworkWidgetsSwitchPrivate);
	return network_widgets_switch_type_id;
}

static void
_vala_network_widgets_switch_get_property (GObject * object,
                                           guint property_id,
                                           GValue * value,
                                           GParamSpec * pspec)
{
	NetworkWidgetsSwitch * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, NETWORK_WIDGETS_TYPE_SWITCH, NetworkWidgetsSwitch);
	switch (property_id) {
		case NETWORK_WIDGETS_SWITCH_ACTIVE_PROPERTY:
		g_value_set_boolean (value, network_widgets_switch_get_active (self));
		break;
		case NETWORK_WIDGETS_SWITCH_CAPTION_PROPERTY:
		g_value_take_string (value, network_widgets_switch_get_caption (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_network_widgets_switch_set_property (GObject * object,
                                           guint property_id,
                                           const GValue * value,
                                           GParamSpec * pspec)
{
	NetworkWidgetsSwitch * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, NETWORK_WIDGETS_TYPE_SWITCH, NetworkWidgetsSwitch);
	switch (property_id) {
		case NETWORK_WIDGETS_SWITCH_ACTIVE_PROPERTY:
		network_widgets_switch_set_active (self, g_value_get_boolean (value));
		break;
		case NETWORK_WIDGETS_SWITCH_CAPTION_PROPERTY:
		network_widgets_switch_set_caption (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

