/* SettingsToggle.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from SettingsToggle.vala, do not modify */

/*
 * SPDX-License-Identifier: GPL-3.0-or-later
 * SPDX-FileCopyrightText: 2023 elementary, Inc. (https://elementary.io)
 */

#include "network.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <glib-object.h>
#include <pango/pango.h>
#include <granite.h>
#include <gdk/gdk.h>
#include <gio/gio.h>
#include <float.h>
#include <math.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_SETTINGS_TOGGLE_0_PROPERTY,
	NETWORK_SETTINGS_TOGGLE_ACTION_NAME_PROPERTY,
	NETWORK_SETTINGS_TOGGLE_ICON_NAME_PROPERTY,
	NETWORK_SETTINGS_TOGGLE_TEXT_PROPERTY,
	NETWORK_SETTINGS_TOGGLE_SETTINGS_URI_PROPERTY,
	NETWORK_SETTINGS_TOGGLE_NUM_PROPERTIES
};
static GParamSpec* network_settings_toggle_properties[NETWORK_SETTINGS_TOGGLE_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)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _NetworkSettingsTogglePrivate {
	gchar* _action_name;
	gchar* _icon_name;
	gchar* _text;
	gchar* _settings_uri;
	GtkGestureMultiPress* middle_click_gesture;
};

static gint NetworkSettingsToggle_private_offset;
static gpointer network_settings_toggle_parent_class = NULL;

static GObject * network_settings_toggle_constructor (GType type,
                                               guint n_construct_properties,
                                               GObjectConstructParam * construct_properties);
static void _network_settings_toggle___lambda6_ (NetworkSettingsToggle* self);
static void __network_settings_toggle___lambda6__gtk_gesture_multi_press_pressed (GtkGestureMultiPress* _sender,
                                                                           gint n_press,
                                                                           gdouble x,
                                                                           gdouble y,
                                                                           gpointer self);
static void network_settings_toggle_finalize (GObject * obj);
static GType network_settings_toggle_get_type_once (void);
static void _vala_network_settings_toggle_get_property (GObject * object,
                                                 guint property_id,
                                                 GValue * value,
                                                 GParamSpec * pspec);
static void _vala_network_settings_toggle_set_property (GObject * object,
                                                 guint property_id,
                                                 const GValue * value,
                                                 GParamSpec * pspec);

static inline gpointer
network_settings_toggle_get_instance_private (NetworkSettingsToggle* self)
{
	return G_STRUCT_MEMBER_P (self, NetworkSettingsToggle_private_offset);
}

NetworkSettingsToggle*
network_settings_toggle_construct (GType object_type)
{
	NetworkSettingsToggle * self = NULL;
	self = (NetworkSettingsToggle*) g_object_new (object_type, NULL);
	return self;
}

NetworkSettingsToggle*
network_settings_toggle_new (void)
{
	return network_settings_toggle_construct (NETWORK_TYPE_SETTINGS_TOGGLE);
}

const gchar*
network_settings_toggle_get_action_name (NetworkSettingsToggle* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_action_name;
	result = _tmp0_;
	return result;
}

void
network_settings_toggle_set_action_name (NetworkSettingsToggle* self,
                                         const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = network_settings_toggle_get_action_name (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_action_name);
		self->priv->_action_name = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, network_settings_toggle_properties[NETWORK_SETTINGS_TOGGLE_ACTION_NAME_PROPERTY]);
	}
}

const gchar*
network_settings_toggle_get_icon_name (NetworkSettingsToggle* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_icon_name;
	result = _tmp0_;
	return result;
}

void
network_settings_toggle_set_icon_name (NetworkSettingsToggle* self,
                                       const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = network_settings_toggle_get_icon_name (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_icon_name);
		self->priv->_icon_name = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, network_settings_toggle_properties[NETWORK_SETTINGS_TOGGLE_ICON_NAME_PROPERTY]);
	}
}

const gchar*
network_settings_toggle_get_text (NetworkSettingsToggle* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_text;
	result = _tmp0_;
	return result;
}

void
network_settings_toggle_set_text (NetworkSettingsToggle* self,
                                  const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = network_settings_toggle_get_text (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_text);
		self->priv->_text = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, network_settings_toggle_properties[NETWORK_SETTINGS_TOGGLE_TEXT_PROPERTY]);
	}
}

const gchar*
network_settings_toggle_get_settings_uri (NetworkSettingsToggle* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_settings_uri;
	result = _tmp0_;
	return result;
}

void
network_settings_toggle_set_settings_uri (NetworkSettingsToggle* self,
                                          const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = network_settings_toggle_get_settings_uri (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_settings_uri);
		self->priv->_settings_uri = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, network_settings_toggle_properties[NETWORK_SETTINGS_TOGGLE_SETTINGS_URI_PROPERTY]);
	}
}

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

static void
_network_settings_toggle___lambda6_ (NetworkSettingsToggle* self)
{
	GError* _inner_error0_ = NULL;
	{
		const gchar* _tmp0_;
		GtkPopover* popover = NULL;
		GtkWidget* _tmp1_;
		GtkPopover* _tmp2_;
		GtkPopover* _tmp3_;
		_tmp0_ = self->priv->_settings_uri;
		g_app_info_launch_default_for_uri (_tmp0_, NULL, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp1_ = gtk_widget_get_ancestor ((GtkWidget*) self, gtk_popover_get_type ());
		_tmp2_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, gtk_popover_get_type (), GtkPopover));
		popover = _tmp2_;
		_tmp3_ = popover;
		gtk_popover_popdown (_tmp3_);
		_g_object_unref0 (popover);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp4_;
		const gchar* _tmp5_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp4_ = e;
		_tmp5_ = _tmp4_->message;
		g_critical ("SettingsToggle.vala:55: Failed to open system settings: %s", _tmp5_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
}

static void
__network_settings_toggle___lambda6__gtk_gesture_multi_press_pressed (GtkGestureMultiPress* _sender,
                                                                      gint n_press,
                                                                      gdouble x,
                                                                      gdouble y,
                                                                      gpointer self)
{
	_network_settings_toggle___lambda6_ ((NetworkSettingsToggle*) self);
}

static GObject *
network_settings_toggle_constructor (GType type,
                                     guint n_construct_properties,
                                     GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	NetworkSettingsToggle * self;
	GtkImage* image = NULL;
	GtkImage* _tmp0_;
	GtkToggleButton* button = NULL;
	GtkImage* _tmp1_;
	GtkWidget* _tmp2_;
	GtkToggleButton* _tmp3_ = NULL;
	GtkLabel* label = NULL;
	GtkToggleButton* _tmp4_;
	GtkWidget* _tmp5_;
	GtkLabel* _tmp6_ = NULL;
	GtkLabel* _tmp7_;
	GtkStyleContext* _tmp8_;
	GtkToggleButton* _tmp9_;
	GtkLabel* _tmp10_;
	GtkToggleButton* _tmp11_;
	GtkImage* _tmp12_;
	GtkLabel* _tmp13_;
	GtkGestureMultiPress* _tmp14_ = NULL;
	GtkGestureMultiPress* _tmp15_;
	parent_class = G_OBJECT_CLASS (network_settings_toggle_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, NETWORK_TYPE_SETTINGS_TOGGLE, NetworkSettingsToggle);
	_tmp0_ = (GtkImage*) gtk_image_new ();
	g_object_ref_sink (_tmp0_);
	image = _tmp0_;
	_tmp1_ = image;
	_tmp2_ = _g_object_ref0 ((GtkWidget*) _tmp1_);
	_tmp3_ = (GtkToggleButton*) gtk_toggle_button_new ();
	gtk_widget_set_halign ((GtkWidget*) _tmp3_, GTK_ALIGN_CENTER);
	gtk_button_set_image ((GtkButton*) _tmp3_, _tmp2_);
	_g_object_unref0 (_tmp2_);
	g_object_ref_sink (_tmp3_);
	button = _tmp3_;
	_tmp4_ = button;
	_tmp5_ = _g_object_ref0 ((GtkWidget*) _tmp4_);
	_tmp6_ = (GtkLabel*) gtk_label_new (NULL);
	gtk_label_set_ellipsize (_tmp6_, PANGO_ELLIPSIZE_MIDDLE);
	gtk_label_set_justify (_tmp6_, GTK_JUSTIFY_CENTER);
	gtk_label_set_lines (_tmp6_, 2);
	gtk_label_set_max_width_chars (_tmp6_, 13);
	gtk_label_set_mnemonic_widget (_tmp6_, _tmp5_);
	_g_object_unref0 (_tmp5_);
	g_object_ref_sink (_tmp6_);
	label = _tmp6_;
	_tmp7_ = label;
	_tmp8_ = gtk_widget_get_style_context ((GtkWidget*) _tmp7_);
	gtk_style_context_add_class (_tmp8_, GRANITE_STYLE_CLASS_SMALL_LABEL);
	gtk_widget_set_halign ((GtkWidget*) self, GTK_ALIGN_CENTER);
	gtk_orientable_set_orientation ((GtkOrientable*) self, GTK_ORIENTATION_VERTICAL);
	gtk_box_set_spacing ((GtkBox*) self, 3);
	_tmp9_ = button;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp9_);
	_tmp10_ = label;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp10_);
	_tmp11_ = button;
	g_object_bind_property_with_closures ((GObject*) self, "action-name", (GObject*) _tmp11_, "action-name", G_BINDING_DEFAULT, (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_ = image;
	g_object_bind_property_with_closures ((GObject*) self, "icon-name", (GObject*) _tmp12_, "icon-name", G_BINDING_DEFAULT, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	_tmp13_ = label;
	g_object_bind_property_with_closures ((GObject*) self, "text", (GObject*) _tmp13_, "label", G_BINDING_DEFAULT, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	_tmp14_ = (GtkGestureMultiPress*) gtk_gesture_multi_press_new ((GtkWidget*) self);
	gtk_gesture_single_set_button ((GtkGestureSingle*) _tmp14_, (guint) GDK_BUTTON_MIDDLE);
	_g_object_unref0 (self->priv->middle_click_gesture);
	self->priv->middle_click_gesture = _tmp14_;
	_tmp15_ = self->priv->middle_click_gesture;
	g_signal_connect_object (_tmp15_, "pressed", (GCallback) __network_settings_toggle___lambda6__gtk_gesture_multi_press_pressed, self, 0);
	_g_object_unref0 (label);
	_g_object_unref0 (button);
	_g_object_unref0 (image);
	return obj;
}

static void
network_settings_toggle_base_init (NetworkSettingsToggleClass * klass)
{
	gtk_widget_class_set_css_name (GTK_WIDGET_CLASS (klass), "settings-toggle");
}

static void
network_settings_toggle_class_init (NetworkSettingsToggleClass * klass,
                                    gpointer klass_data)
{
	network_settings_toggle_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &NetworkSettingsToggle_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_network_settings_toggle_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_network_settings_toggle_set_property;
	G_OBJECT_CLASS (klass)->constructor = network_settings_toggle_constructor;
	G_OBJECT_CLASS (klass)->finalize = network_settings_toggle_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), NETWORK_SETTINGS_TOGGLE_ACTION_NAME_PROPERTY, network_settings_toggle_properties[NETWORK_SETTINGS_TOGGLE_ACTION_NAME_PROPERTY] = g_param_spec_string ("action-name", "action-name", "action-name", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), NETWORK_SETTINGS_TOGGLE_ICON_NAME_PROPERTY, network_settings_toggle_properties[NETWORK_SETTINGS_TOGGLE_ICON_NAME_PROPERTY] = g_param_spec_string ("icon-name", "icon-name", "icon-name", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), NETWORK_SETTINGS_TOGGLE_TEXT_PROPERTY, network_settings_toggle_properties[NETWORK_SETTINGS_TOGGLE_TEXT_PROPERTY] = g_param_spec_string ("text", "text", "text", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), NETWORK_SETTINGS_TOGGLE_SETTINGS_URI_PROPERTY, network_settings_toggle_properties[NETWORK_SETTINGS_TOGGLE_SETTINGS_URI_PROPERTY] = g_param_spec_string ("settings-uri", "settings-uri", "settings-uri", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
network_settings_toggle_instance_init (NetworkSettingsToggle * self,
                                       gpointer klass)
{
	gchar* _tmp0_;
	self->priv = network_settings_toggle_get_instance_private (self);
	_tmp0_ = g_strdup ("settings://");
	self->priv->_settings_uri = _tmp0_;
}

static void
network_settings_toggle_finalize (GObject * obj)
{
	NetworkSettingsToggle * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, NETWORK_TYPE_SETTINGS_TOGGLE, NetworkSettingsToggle);
	_g_free0 (self->priv->_action_name);
	_g_free0 (self->priv->_icon_name);
	_g_free0 (self->priv->_text);
	_g_free0 (self->priv->_settings_uri);
	_g_object_unref0 (self->priv->middle_click_gesture);
	G_OBJECT_CLASS (network_settings_toggle_parent_class)->finalize (obj);
}

static GType
network_settings_toggle_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (NetworkSettingsToggleClass), (GBaseInitFunc) network_settings_toggle_base_init, (GBaseFinalizeFunc) NULL, (GClassInitFunc) network_settings_toggle_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (NetworkSettingsToggle), 0, (GInstanceInitFunc) network_settings_toggle_instance_init, NULL };
	GType network_settings_toggle_type_id;
	network_settings_toggle_type_id = g_type_register_static (gtk_box_get_type (), "NetworkSettingsToggle", &g_define_type_info, 0);
	NetworkSettingsToggle_private_offset = g_type_add_instance_private (network_settings_toggle_type_id, sizeof (NetworkSettingsTogglePrivate));
	return network_settings_toggle_type_id;
}

GType
network_settings_toggle_get_type (void)
{
	static volatile gsize network_settings_toggle_type_id__once = 0;
	if (g_once_init_enter (&network_settings_toggle_type_id__once)) {
		GType network_settings_toggle_type_id;
		network_settings_toggle_type_id = network_settings_toggle_get_type_once ();
		g_once_init_leave (&network_settings_toggle_type_id__once, network_settings_toggle_type_id);
	}
	return network_settings_toggle_type_id__once;
}

static void
_vala_network_settings_toggle_get_property (GObject * object,
                                            guint property_id,
                                            GValue * value,
                                            GParamSpec * pspec)
{
	NetworkSettingsToggle * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, NETWORK_TYPE_SETTINGS_TOGGLE, NetworkSettingsToggle);
	switch (property_id) {
		case NETWORK_SETTINGS_TOGGLE_ACTION_NAME_PROPERTY:
		g_value_set_string (value, network_settings_toggle_get_action_name (self));
		break;
		case NETWORK_SETTINGS_TOGGLE_ICON_NAME_PROPERTY:
		g_value_set_string (value, network_settings_toggle_get_icon_name (self));
		break;
		case NETWORK_SETTINGS_TOGGLE_TEXT_PROPERTY:
		g_value_set_string (value, network_settings_toggle_get_text (self));
		break;
		case NETWORK_SETTINGS_TOGGLE_SETTINGS_URI_PROPERTY:
		g_value_set_string (value, network_settings_toggle_get_settings_uri (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_network_settings_toggle_set_property (GObject * object,
                                            guint property_id,
                                            const GValue * value,
                                            GParamSpec * pspec)
{
	NetworkSettingsToggle * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, NETWORK_TYPE_SETTINGS_TOGGLE, NetworkSettingsToggle);
	switch (property_id) {
		case NETWORK_SETTINGS_TOGGLE_ACTION_NAME_PROPERTY:
		network_settings_toggle_set_action_name (self, g_value_get_string (value));
		break;
		case NETWORK_SETTINGS_TOGGLE_ICON_NAME_PROPERTY:
		network_settings_toggle_set_icon_name (self, g_value_get_string (value));
		break;
		case NETWORK_SETTINGS_TOGGLE_TEXT_PROPERTY:
		network_settings_toggle_set_text (self, g_value_get_string (value));
		break;
		case NETWORK_SETTINGS_TOGGLE_SETTINGS_URI_PROPERTY:
		network_settings_toggle_set_settings_uri (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

