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

/*-
 * Copyright (c) 2015-2016 elementary LLC.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 2.1 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * Authored by: Adam Bieńkowski <donadigos159@gmail.com>
 */

#include "network.h"
#include <glib-object.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <gio/gio.h>
#include <switchboard.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.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_PROXY_PAGE_0_PROPERTY,
	NETWORK_WIDGETS_PROXY_PAGE_NUM_PROPERTIES
};
static GParamSpec* network_widgets_proxy_page_properties[NETWORK_WIDGETS_PROXY_PAGE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
enum  {
	NETWORK_WIDGETS_PROXY_PAGE_UPDATE_STATUS_LABEL_SIGNAL,
	NETWORK_WIDGETS_PROXY_PAGE_NUM_SIGNALS
};
static guint network_widgets_proxy_page_signals[NETWORK_WIDGETS_PROXY_PAGE_NUM_SIGNALS] = {0};

static gpointer network_widgets_proxy_page_parent_class = NULL;

static void network_widgets_proxy_page_real_control_switch_activated (NetworkWidgetsPage* base);
static void network_widgets_proxy_page_real_update_switch (NetworkWidgetsPage* base);
static void network_widgets_proxy_page_update_mode (NetworkWidgetsProxyPage* self);
static GObject * network_widgets_proxy_page_constructor (GType type,
                                                  guint n_construct_properties,
                                                  GObjectConstructParam * construct_properties);
static void _network_widgets_proxy_page_update_mode_g_settings_changed (GSettings* _sender,
                                                                 const gchar* key,
                                                                 gpointer self);
static void network_widgets_proxy_page_finalize (GObject * obj);
static GType network_widgets_proxy_page_get_type_once (void);

NetworkWidgetsProxyPage*
network_widgets_proxy_page_construct (GType object_type)
{
	NetworkWidgetsProxyPage * self = NULL;
	GThemedIcon* _tmp0_;
	GThemedIcon* _tmp1_;
	_tmp0_ = (GThemedIcon*) g_themed_icon_new ("preferences-system-network");
	_tmp1_ = _tmp0_;
	self = (NetworkWidgetsProxyPage*) g_object_new (object_type, "activatable", TRUE, "title", _ ("Proxy"), "icon", _tmp1_, NULL);
	_g_object_unref0 (_tmp1_);
	return self;
}

NetworkWidgetsProxyPage*
network_widgets_proxy_page_new (void)
{
	return network_widgets_proxy_page_construct (NETWORK_WIDGETS_TYPE_PROXY_PAGE);
}

static void
network_widgets_proxy_page_real_control_switch_activated (NetworkWidgetsPage* base)
{
	NetworkWidgetsProxyPage * self;
	GtkSwitch* _tmp0_;
	GtkSwitch* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	self = (NetworkWidgetsProxyPage*) base;
	_tmp0_ = switchboard_settings_page_get_status_switch ((SwitchboardSettingsPage*) self);
	_tmp1_ = _tmp0_;
	_tmp2_ = gtk_switch_get_active (_tmp1_);
	_tmp3_ = _tmp2_;
	if (_tmp3_) {
		GSettings* _tmp4_;
		_tmp4_ = network_plug_proxy_settings;
		g_settings_set_string (_tmp4_, "mode", "auto");
	} else {
		GSettings* _tmp5_;
		_tmp5_ = network_plug_proxy_settings;
		g_settings_set_string (_tmp5_, "mode", "none");
	}
}

static void
network_widgets_proxy_page_real_update_switch (NetworkWidgetsPage* base)
{
	NetworkWidgetsProxyPage * self;
	self = (NetworkWidgetsProxyPage*) base;
}

static void
network_widgets_proxy_page_update_mode (NetworkWidgetsProxyPage* self)
{
	GSettings* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	GQuark _tmp4_ = 0U;
	static GQuark _tmp3_label0 = 0;
	static GQuark _tmp3_label1 = 0;
	static GQuark _tmp3_label2 = 0;
	g_return_if_fail (self != NULL);
	_tmp0_ = network_plug_proxy_settings;
	_tmp1_ = g_settings_get_string (_tmp0_, "mode");
	_tmp2_ = _tmp1_;
	_tmp4_ = (NULL == _tmp2_) ? 0 : g_quark_from_string (_tmp2_);
	g_free (_tmp2_);
	if (_tmp4_ == ((0 != _tmp3_label0) ? _tmp3_label0 : (_tmp3_label0 = g_quark_from_static_string ("none")))) {
		switch (0) {
			default:
			{
				GtkSwitch* _tmp5_;
				GtkSwitch* _tmp6_;
				switchboard_settings_page_set_status ((SwitchboardSettingsPage*) self, _ ("Disabled"));
				_tmp5_ = switchboard_settings_page_get_status_switch ((SwitchboardSettingsPage*) self);
				_tmp6_ = _tmp5_;
				gtk_switch_set_active (_tmp6_, FALSE);
				switchboard_settings_page_set_status_type ((SwitchboardSettingsPage*) self, SWITCHBOARD_SETTINGS_PAGE_STATUS_TYPE_OFFLINE);
				break;
			}
		}
	} else if (_tmp4_ == ((0 != _tmp3_label1) ? _tmp3_label1 : (_tmp3_label1 = g_quark_from_static_string ("manual")))) {
		switch (0) {
			default:
			{
				GtkSwitch* _tmp7_;
				GtkSwitch* _tmp8_;
				switchboard_settings_page_set_status ((SwitchboardSettingsPage*) self, _ ("Enabled (manual mode)"));
				_tmp7_ = switchboard_settings_page_get_status_switch ((SwitchboardSettingsPage*) self);
				_tmp8_ = _tmp7_;
				gtk_switch_set_active (_tmp8_, TRUE);
				switchboard_settings_page_set_status_type ((SwitchboardSettingsPage*) self, SWITCHBOARD_SETTINGS_PAGE_STATUS_TYPE_SUCCESS);
				break;
			}
		}
	} else if (_tmp4_ == ((0 != _tmp3_label2) ? _tmp3_label2 : (_tmp3_label2 = g_quark_from_static_string ("auto")))) {
		switch (0) {
			default:
			{
				GtkSwitch* _tmp9_;
				GtkSwitch* _tmp10_;
				switchboard_settings_page_set_status ((SwitchboardSettingsPage*) self, _ ("Enabled (auto mode)"));
				_tmp9_ = switchboard_settings_page_get_status_switch ((SwitchboardSettingsPage*) self);
				_tmp10_ = _tmp9_;
				gtk_switch_set_active (_tmp10_, TRUE);
				switchboard_settings_page_set_status_type ((SwitchboardSettingsPage*) self, SWITCHBOARD_SETTINGS_PAGE_STATUS_TYPE_SUCCESS);
				break;
			}
		}
	}
}

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

static void
_network_widgets_proxy_page_update_mode_g_settings_changed (GSettings* _sender,
                                                            const gchar* key,
                                                            gpointer self)
{
	network_widgets_proxy_page_update_mode ((NetworkWidgetsProxyPage*) self);
}

static GObject *
network_widgets_proxy_page_constructor (GType type,
                                        guint n_construct_properties,
                                        GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	NetworkWidgetsProxyPage * self;
	NetworkWidgetsConfigurationPage* configuration_page = NULL;
	NetworkWidgetsConfigurationPage* _tmp0_;
	NetworkWidgetsExecepionsPage* exceptions_page = NULL;
	NetworkWidgetsExecepionsPage* _tmp1_;
	GtkSwitch* _tmp2_;
	GtkSwitch* _tmp3_;
	NetworkWidgetsConfigurationPage* _tmp4_;
	GtkSwitch* _tmp5_;
	GtkSwitch* _tmp6_;
	NetworkWidgetsExecepionsPage* _tmp7_;
	GtkStack* _tmp8_;
	GtkStack* _tmp9_;
	NetworkWidgetsConfigurationPage* _tmp10_;
	GtkStack* _tmp11_;
	NetworkWidgetsExecepionsPage* _tmp12_;
	GtkStackSwitcher* stackswitcher = NULL;
	GtkStack* _tmp13_;
	GtkStack* _tmp14_;
	GtkStackSwitcher* _tmp15_ = NULL;
	GtkSizeGroup* sizegroup = NULL;
	GtkSizeGroup* _tmp16_;
	GtkWidget* switcher_child = NULL;
	GtkStackSwitcher* _tmp17_;
	GtkWidget* _tmp18_;
	GSettings* _tmp24_;
	GtkBox* box = NULL;
	GtkBox* _tmp25_;
	GtkBox* _tmp26_;
	GtkStackSwitcher* _tmp27_;
	GtkBox* _tmp28_;
	GtkStack* _tmp29_;
	GtkBox* _tmp30_;
	GtkStack* _tmp31_;
	NetworkWidgetsConfigurationPage* _tmp32_;
	parent_class = G_OBJECT_CLASS (network_widgets_proxy_page_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, NETWORK_WIDGETS_TYPE_PROXY_PAGE, NetworkWidgetsProxyPage);
	_tmp0_ = network_widgets_configuration_page_new ();
	g_object_ref_sink (_tmp0_);
	configuration_page = _tmp0_;
	_tmp1_ = network_widgets_execepions_page_new ();
	g_object_ref_sink (_tmp1_);
	exceptions_page = _tmp1_;
	_tmp2_ = switchboard_settings_page_get_status_switch ((SwitchboardSettingsPage*) self);
	_tmp3_ = _tmp2_;
	_tmp4_ = configuration_page;
	g_object_bind_property_with_closures ((GObject*) _tmp3_, "active", (GObject*) _tmp4_, "sensitive", G_BINDING_SYNC_CREATE, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	_tmp5_ = switchboard_settings_page_get_status_switch ((SwitchboardSettingsPage*) self);
	_tmp6_ = _tmp5_;
	_tmp7_ = exceptions_page;
	g_object_bind_property_with_closures ((GObject*) _tmp6_, "active", (GObject*) _tmp7_, "sensitive", G_BINDING_SYNC_CREATE, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	_tmp8_ = (GtkStack*) gtk_stack_new ();
	g_object_ref_sink (_tmp8_);
	_g_object_unref0 (self->stack);
	self->stack = _tmp8_;
	_tmp9_ = self->stack;
	_tmp10_ = configuration_page;
	gtk_stack_add_titled (_tmp9_, (GtkWidget*) _tmp10_, "configuration", _ ("Configuration"));
	_tmp11_ = self->stack;
	_tmp12_ = exceptions_page;
	gtk_stack_add_titled (_tmp11_, (GtkWidget*) _tmp12_, "exceptions", _ ("Exceptions"));
	_tmp13_ = self->stack;
	_tmp14_ = _g_object_ref0 (_tmp13_);
	_tmp15_ = (GtkStackSwitcher*) gtk_stack_switcher_new ();
	gtk_widget_set_halign ((GtkWidget*) _tmp15_, GTK_ALIGN_CENTER);
	gtk_stack_switcher_set_stack (_tmp15_, _tmp14_);
	_g_object_unref0 (_tmp14_);
	g_object_ref_sink (_tmp15_);
	stackswitcher = _tmp15_;
	_tmp16_ = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
	sizegroup = _tmp16_;
	_tmp17_ = stackswitcher;
	_tmp18_ = gtk_widget_get_first_child ((GtkWidget*) _tmp17_);
	switcher_child = _tmp18_;
	while (TRUE) {
		GtkWidget* _tmp19_;
		GtkSizeGroup* _tmp20_;
		GtkWidget* _tmp21_;
		GtkWidget* _tmp22_;
		GtkWidget* _tmp23_;
		_tmp19_ = switcher_child;
		if (!(_tmp19_ != NULL)) {
			break;
		}
		_tmp20_ = sizegroup;
		_tmp21_ = switcher_child;
		gtk_size_group_add_widget (_tmp20_, _tmp21_);
		_tmp22_ = switcher_child;
		_tmp23_ = gtk_widget_get_next_sibling (_tmp22_);
		switcher_child = _tmp23_;
	}
	_tmp24_ = network_plug_proxy_settings;
	g_signal_connect_object (_tmp24_, "changed", (GCallback) _network_widgets_proxy_page_update_mode_g_settings_changed, self, 0);
	network_widgets_proxy_page_update_mode (self);
	_tmp25_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
	g_object_ref_sink (_tmp25_);
	box = _tmp25_;
	_tmp26_ = box;
	_tmp27_ = stackswitcher;
	gtk_box_append (_tmp26_, (GtkWidget*) _tmp27_);
	_tmp28_ = box;
	_tmp29_ = self->stack;
	gtk_box_append (_tmp28_, (GtkWidget*) _tmp29_);
	_tmp30_ = box;
	switchboard_settings_page_set_child ((SwitchboardSettingsPage*) self, (GtkWidget*) _tmp30_);
	_tmp31_ = self->stack;
	_tmp32_ = configuration_page;
	gtk_stack_set_visible_child (_tmp31_, (GtkWidget*) _tmp32_);
	_g_object_unref0 (box);
	_g_object_unref0 (sizegroup);
	_g_object_unref0 (stackswitcher);
	_g_object_unref0 (exceptions_page);
	_g_object_unref0 (configuration_page);
	return obj;
}

static void
network_widgets_proxy_page_class_init (NetworkWidgetsProxyPageClass * klass,
                                       gpointer klass_data)
{
	network_widgets_proxy_page_parent_class = g_type_class_peek_parent (klass);
	((NetworkWidgetsPageClass *) klass)->control_switch_activated = (void (*) (NetworkWidgetsPage*)) network_widgets_proxy_page_real_control_switch_activated;
	((NetworkWidgetsPageClass *) klass)->update_switch = (void (*) (NetworkWidgetsPage*)) network_widgets_proxy_page_real_update_switch;
	G_OBJECT_CLASS (klass)->constructor = network_widgets_proxy_page_constructor;
	G_OBJECT_CLASS (klass)->finalize = network_widgets_proxy_page_finalize;
	network_widgets_proxy_page_signals[NETWORK_WIDGETS_PROXY_PAGE_UPDATE_STATUS_LABEL_SIGNAL] = g_signal_new ("update-status-label", NETWORK_WIDGETS_TYPE_PROXY_PAGE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING);
}

static void
network_widgets_proxy_page_instance_init (NetworkWidgetsProxyPage * self,
                                          gpointer klass)
{
}

static void
network_widgets_proxy_page_finalize (GObject * obj)
{
	NetworkWidgetsProxyPage * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, NETWORK_WIDGETS_TYPE_PROXY_PAGE, NetworkWidgetsProxyPage);
	_g_object_unref0 (self->stack);
	G_OBJECT_CLASS (network_widgets_proxy_page_parent_class)->finalize (obj);
}

static GType
network_widgets_proxy_page_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (NetworkWidgetsProxyPageClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) network_widgets_proxy_page_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (NetworkWidgetsProxyPage), 0, (GInstanceInitFunc) network_widgets_proxy_page_instance_init, NULL };
	GType network_widgets_proxy_page_type_id;
	network_widgets_proxy_page_type_id = g_type_register_static (NETWORK_WIDGETS_TYPE_PAGE, "NetworkWidgetsProxyPage", &g_define_type_info, 0);
	return network_widgets_proxy_page_type_id;
}

GType
network_widgets_proxy_page_get_type (void)
{
	static volatile gsize network_widgets_proxy_page_type_id__once = 0;
	if (g_once_init_enter (&network_widgets_proxy_page_type_id__once)) {
		GType network_widgets_proxy_page_type_id;
		network_widgets_proxy_page_type_id = network_widgets_proxy_page_get_type_once ();
		g_once_init_leave (&network_widgets_proxy_page_type_id__once, network_widgets_proxy_page_type_id);
	}
	return network_widgets_proxy_page_type_id__once;
}

