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

/*-
 * Copyright (c) 2015-2020 elementary, Inc (https://elementary.io)
 *
 * 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 <gtk/gtk.h>
#include <granite-7.h>
#include <glib.h>
#include <glib-object.h>
#include <NetworkManager.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <switchboard.h>
#include <glib/gi18n-lib.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_ETHER_INTERFACE_0_PROPERTY,
	NETWORK_WIDGETS_ETHER_INTERFACE_NUM_PROPERTIES
};
static GParamSpec* network_widgets_ether_interface_properties[NETWORK_WIDGETS_ETHER_INTERFACE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _Block2Data Block2Data;

struct _NetworkWidgetsEtherInterfacePrivate {
	GtkStack* widgets_stack;
	GtkRevealer* top_revealer;
	GranitePlaceholder* no_cable;
};

struct _Block2Data {
	int _ref_count_;
	NetworkWidgetsEtherInterface* self;
	GtkButton* settings_button;
};

static gint NetworkWidgetsEtherInterface_private_offset;
static gpointer network_widgets_ether_interface_parent_class = NULL;

static void network_widgets_ether_interface_real_update_name (NetworkWidgetsPage* base,
                                                       gint count);
static void network_widgets_ether_interface_real_update (NetworkWidgetsPage* base);
static GObject * network_widgets_ether_interface_constructor (GType type,
                                                       guint n_construct_properties,
                                                       GObjectConstructParam * construct_properties);
static Block2Data* block2_data_ref (Block2Data* _data2_);
static void block2_data_unref (void * _userdata_);
static void _network_widgets_page_open_advanced_settings_gtk_button_clicked (GtkButton* _sender,
                                                                      gpointer self);
static void _network_widgets_ether_interface___lambda33_ (Block2Data* _data2_);
static void __network_widgets_ether_interface___lambda33__g_object_notify (GObject* _sender,
                                                                    GParamSpec* pspec,
                                                                    gpointer self);
static void network_widgets_ether_interface_finalize (GObject * obj);
static GType network_widgets_ether_interface_get_type_once (void);

static inline gpointer
network_widgets_ether_interface_get_instance_private (NetworkWidgetsEtherInterface* self)
{
	return G_STRUCT_MEMBER_P (self, NetworkWidgetsEtherInterface_private_offset);
}

NetworkWidgetsEtherInterface*
network_widgets_ether_interface_construct (GType object_type,
                                           NMDevice* device)
{
	NetworkWidgetsEtherInterface * self = NULL;
	GThemedIcon* _tmp0_;
	GThemedIcon* _tmp1_;
	g_return_val_if_fail (device != NULL, NULL);
	_tmp0_ = (GThemedIcon*) g_themed_icon_new ("network-wired");
	_tmp1_ = _tmp0_;
	self = (NetworkWidgetsEtherInterface*) g_object_new (object_type, "activatable", TRUE, "device", device, "icon", _tmp1_, NULL);
	_g_object_unref0 (_tmp1_);
	return self;
}

NetworkWidgetsEtherInterface*
network_widgets_ether_interface_new (NMDevice* device)
{
	return network_widgets_ether_interface_construct (NETWORK_WIDGETS_TYPE_ETHER_INTERFACE, device);
}

static void
network_widgets_ether_interface_real_update_name (NetworkWidgetsPage* base,
                                                  gint count)
{
	NetworkWidgetsEtherInterface * self;
	gchar* name = NULL;
	NMDevice* _tmp0_;
	NMDevice* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	const gchar* _tmp4_;
	self = (NetworkWidgetsEtherInterface*) base;
	_tmp0_ = network_widgets_page_get_device ((NetworkWidgetsPage*) self);
	_tmp1_ = _tmp0_;
	_tmp2_ = nm_device_get_description (_tmp1_);
	_tmp3_ = g_strdup (_tmp2_);
	name = _tmp3_;
	_tmp4_ = name;
	if (g_str_has_prefix (_tmp4_, "veth")) {
		const gchar* _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		_tmp5_ = name;
		_tmp6_ = g_strdup_printf (_ ("Virtual network: %s"), _tmp5_);
		_tmp7_ = _tmp6_;
		switchboard_settings_page_set_title ((SwitchboardSettingsPage*) self, _tmp7_);
		_g_free0 (_tmp7_);
	} else {
		if (count <= 1) {
			switchboard_settings_page_set_title ((SwitchboardSettingsPage*) self, _ ("Wired"));
		} else {
			const gchar* _tmp8_;
			_tmp8_ = name;
			switchboard_settings_page_set_title ((SwitchboardSettingsPage*) self, _tmp8_);
		}
	}
	_g_free0 (name);
}

static void
network_widgets_ether_interface_real_update (NetworkWidgetsPage* base)
{
	NetworkWidgetsEtherInterface * self;
	NMDevice* _tmp0_;
	NMDevice* _tmp1_;
	NMDeviceState _tmp2_;
	NMDeviceState _tmp3_;
	NMDeviceState _tmp4_;
	NMDeviceState _tmp5_;
	self = (NetworkWidgetsEtherInterface*) base;
	NETWORK_WIDGETS_PAGE_CLASS (network_widgets_ether_interface_parent_class)->update (G_TYPE_CHECK_INSTANCE_CAST (self, NETWORK_WIDGETS_TYPE_PAGE, NetworkWidgetsPage));
	_tmp0_ = network_widgets_page_get_device ((NetworkWidgetsPage*) self);
	_tmp1_ = _tmp0_;
	_tmp2_ = nm_device_get_state (_tmp1_);
	_tmp3_ = _tmp2_;
	network_widgets_page_set_state ((NetworkWidgetsPage*) self, _tmp3_);
	_tmp4_ = network_widgets_page_get_state ((NetworkWidgetsPage*) self);
	_tmp5_ = _tmp4_;
	if (_tmp5_ == NM_DEVICE_STATE_UNAVAILABLE) {
		GtkStack* _tmp6_;
		GranitePlaceholder* _tmp7_;
		_tmp6_ = self->priv->widgets_stack;
		_tmp7_ = self->priv->no_cable;
		gtk_stack_set_visible_child (_tmp6_, (GtkWidget*) _tmp7_);
	} else {
		GtkStack* _tmp8_;
		GtkRevealer* _tmp9_;
		_tmp8_ = self->priv->widgets_stack;
		_tmp9_ = self->priv->top_revealer;
		gtk_stack_set_visible_child (_tmp8_, (GtkWidget*) _tmp9_);
	}
}

static Block2Data*
block2_data_ref (Block2Data* _data2_)
{
	g_atomic_int_inc (&_data2_->_ref_count_);
	return _data2_;
}

static void
block2_data_unref (void * _userdata_)
{
	Block2Data* _data2_;
	_data2_ = (Block2Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data2_->_ref_count_)) {
		NetworkWidgetsEtherInterface* self;
		self = _data2_->self;
		_g_object_unref0 (_data2_->settings_button);
		_g_object_unref0 (self);
		g_slice_free (Block2Data, _data2_);
	}
}

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

static void
_network_widgets_page_open_advanced_settings_gtk_button_clicked (GtkButton* _sender,
                                                                 gpointer self)
{
	network_widgets_page_open_advanced_settings ((NetworkWidgetsPage*) self);
}

static void
_network_widgets_ether_interface___lambda33_ (Block2Data* _data2_)
{
	NetworkWidgetsEtherInterface* self;
	GtkButton* _tmp0_;
	const gchar* _tmp1_;
	self = _data2_->self;
	_tmp0_ = _data2_->settings_button;
	_tmp1_ = ((NetworkWidgetsPage*) self)->uuid;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp0_, g_strcmp0 (_tmp1_, "") != 0);
}

static void
__network_widgets_ether_interface___lambda33__g_object_notify (GObject* _sender,
                                                               GParamSpec* pspec,
                                                               gpointer self)
{
	_network_widgets_ether_interface___lambda33_ (self);
}

static GObject *
network_widgets_ether_interface_constructor (GType type,
                                             guint n_construct_properties,
                                             GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	NetworkWidgetsEtherInterface * self;
	Block2Data* _data2_;
	gchar* _tmp0_;
	GranitePlaceholder* _tmp1_ = NULL;
	NetworkWidgetsInfoBox* _tmp2_;
	GtkWidget* _tmp3_;
	GtkRevealer* _tmp4_ = NULL;
	GtkStack* _tmp5_;
	GtkStack* _tmp6_;
	GranitePlaceholder* _tmp7_;
	GtkStack* _tmp8_;
	GtkRevealer* _tmp9_;
	GtkStack* _tmp10_;
	GtkButton* _tmp11_;
	GtkButton* _tmp12_;
	GtkButton* _tmp13_;
	const gchar* _tmp14_;
	GtkSwitch* _tmp15_;
	GtkSwitch* _tmp16_;
	GtkRevealer* _tmp17_;
	parent_class = G_OBJECT_CLASS (network_widgets_ether_interface_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, NETWORK_WIDGETS_TYPE_ETHER_INTERFACE, NetworkWidgetsEtherInterface);
	_data2_ = g_slice_new0 (Block2Data);
	_data2_->_ref_count_ = 1;
	_data2_->self = g_object_ref (self);
	_tmp0_ = g_strdup (_ ("A network cable is not plugged in or may be broken"));
	_tmp1_ = granite_placeholder_new (_ ("This Wired Network is Unavailable"));
	granite_placeholder_set_description (_tmp1_, _tmp0_);
	_g_free0 (_tmp0_);
	g_object_ref_sink (_tmp1_);
	_g_object_unref0 (self->priv->no_cable);
	self->priv->no_cable = _tmp1_;
	_tmp2_ = ((NetworkWidgetsPage*) self)->info_box;
	_tmp3_ = _g_object_ref0 ((GtkWidget*) _tmp2_);
	_tmp4_ = (GtkRevealer*) gtk_revealer_new ();
	gtk_widget_set_valign ((GtkWidget*) _tmp4_, GTK_ALIGN_START);
	gtk_revealer_set_transition_type (_tmp4_, GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN);
	gtk_revealer_set_child (_tmp4_, _tmp3_);
	_g_object_unref0 (_tmp3_);
	g_object_ref_sink (_tmp4_);
	_g_object_unref0 (self->priv->top_revealer);
	self->priv->top_revealer = _tmp4_;
	_tmp5_ = (GtkStack*) gtk_stack_new ();
	g_object_ref_sink (_tmp5_);
	_g_object_unref0 (self->priv->widgets_stack);
	self->priv->widgets_stack = _tmp5_;
	_tmp6_ = self->priv->widgets_stack;
	_tmp7_ = self->priv->no_cable;
	gtk_stack_add_child (_tmp6_, (GtkWidget*) _tmp7_);
	_tmp8_ = self->priv->widgets_stack;
	_tmp9_ = self->priv->top_revealer;
	gtk_stack_add_child (_tmp8_, (GtkWidget*) _tmp9_);
	_tmp10_ = self->priv->widgets_stack;
	switchboard_settings_page_set_child ((SwitchboardSettingsPage*) self, (GtkWidget*) _tmp10_);
	_tmp11_ = switchboard_settings_page_add_button ((SwitchboardSettingsPage*) self, _ ("Advanced Settings…"));
	_data2_->settings_button = _tmp11_;
	_tmp12_ = _data2_->settings_button;
	g_signal_connect_object (_tmp12_, "clicked", (GCallback) _network_widgets_page_open_advanced_settings_gtk_button_clicked, (NetworkWidgetsPage*) self, 0);
	_tmp13_ = _data2_->settings_button;
	_tmp14_ = ((NetworkWidgetsPage*) self)->uuid;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp13_, g_strcmp0 (_tmp14_, "") != 0);
	g_signal_connect_data ((GObject*) self, "notify::uuid", (GCallback) __network_widgets_ether_interface___lambda33__g_object_notify, block2_data_ref (_data2_), (GClosureNotify) block2_data_unref, 0);
	_tmp15_ = switchboard_settings_page_get_status_switch ((SwitchboardSettingsPage*) self);
	_tmp16_ = _tmp15_;
	_tmp17_ = self->priv->top_revealer;
	g_object_bind_property_with_closures ((GObject*) _tmp16_, "active", (GObject*) _tmp17_, "reveal-child", 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)));
	block2_data_unref (_data2_);
	_data2_ = NULL;
	return obj;
}

static void
network_widgets_ether_interface_class_init (NetworkWidgetsEtherInterfaceClass * klass,
                                            gpointer klass_data)
{
	network_widgets_ether_interface_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &NetworkWidgetsEtherInterface_private_offset);
	((NetworkWidgetsPageClass *) klass)->update_name = (void (*) (NetworkWidgetsPage*, gint)) network_widgets_ether_interface_real_update_name;
	((NetworkWidgetsPageClass *) klass)->update = (void (*) (NetworkWidgetsPage*)) network_widgets_ether_interface_real_update;
	G_OBJECT_CLASS (klass)->constructor = network_widgets_ether_interface_constructor;
	G_OBJECT_CLASS (klass)->finalize = network_widgets_ether_interface_finalize;
}

static void
network_widgets_ether_interface_instance_init (NetworkWidgetsEtherInterface * self,
                                               gpointer klass)
{
	self->priv = network_widgets_ether_interface_get_instance_private (self);
}

static void
network_widgets_ether_interface_finalize (GObject * obj)
{
	NetworkWidgetsEtherInterface * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, NETWORK_WIDGETS_TYPE_ETHER_INTERFACE, NetworkWidgetsEtherInterface);
	_g_object_unref0 (self->priv->widgets_stack);
	_g_object_unref0 (self->priv->top_revealer);
	_g_object_unref0 (self->priv->no_cable);
	G_OBJECT_CLASS (network_widgets_ether_interface_parent_class)->finalize (obj);
}

static GType
network_widgets_ether_interface_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (NetworkWidgetsEtherInterfaceClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) network_widgets_ether_interface_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (NetworkWidgetsEtherInterface), 0, (GInstanceInitFunc) network_widgets_ether_interface_instance_init, NULL };
	GType network_widgets_ether_interface_type_id;
	network_widgets_ether_interface_type_id = g_type_register_static (NETWORK_WIDGETS_TYPE_PAGE, "NetworkWidgetsEtherInterface", &g_define_type_info, 0);
	NetworkWidgetsEtherInterface_private_offset = g_type_add_instance_private (network_widgets_ether_interface_type_id, sizeof (NetworkWidgetsEtherInterfacePrivate));
	return network_widgets_ether_interface_type_id;
}

GType
network_widgets_ether_interface_get_type (void)
{
	static volatile gsize network_widgets_ether_interface_type_id__once = 0;
	if (g_once_init_enter (&network_widgets_ether_interface_type_id__once)) {
		GType network_widgets_ether_interface_type_id;
		network_widgets_ether_interface_type_id = network_widgets_ether_interface_get_type_once ();
		g_once_init_leave (&network_widgets_ether_interface_type_id__once, network_widgets_ether_interface_type_id);
	}
	return network_widgets_ether_interface_type_id__once;
}

