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

/*
 * Copyright (c) 2015-2018 elementary LLC (https://elementary.io)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Library 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 Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "networkapplet.h"
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <NetworkManager.h>
#include <glib/gi18n-lib.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_ABSTRACT_ETHER_INTERFACE_0_PROPERTY,
	NETWORK_ABSTRACT_ETHER_INTERFACE_NUM_PROPERTIES
};
static GParamSpec* network_abstract_ether_interface_properties[NETWORK_ABSTRACT_ETHER_INTERFACE_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))

static gpointer network_abstract_ether_interface_parent_class = NULL;
static GType network_abstract_ether_interface_type_id = 0;

static void network_abstract_ether_interface_real_update_name (NetworkWidgetNMInterface* base,
                                                        gint count);
static void network_abstract_ether_interface_real_update (NetworkWidgetNMInterface* base);

static void
network_abstract_ether_interface_real_update_name (NetworkWidgetNMInterface* base,
                                                   gint count)
{
	NetworkAbstractEtherInterface * self;
	gchar* name = NULL;
	NMDevice* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	const gchar* _tmp3_;
	self = (NetworkAbstractEtherInterface*) base;
	_tmp0_ = ((NetworkWidgetNMInterface*) self)->device;
	_tmp1_ = nm_device_get_description (_tmp0_);
	_tmp2_ = g_strdup (_tmp1_);
	name = _tmp2_;
	_tmp3_ = name;
	if (g_str_has_prefix (_tmp3_, "veth")) {
		const gchar* _tmp4_;
		gchar* _tmp5_;
		gchar* _tmp6_;
		_tmp4_ = name;
		_tmp5_ = g_strdup_printf (_ ("Virtual network: %s"), _tmp4_);
		_tmp6_ = _tmp5_;
		network_widget_nm_interface_set_display_title ((NetworkWidgetNMInterface*) self, _tmp6_);
		_g_free0 (_tmp6_);
	} else {
		if (count <= 1) {
			network_widget_nm_interface_set_display_title ((NetworkWidgetNMInterface*) self, _ ("Wired"));
		} else {
			const gchar* _tmp7_;
			_tmp7_ = name;
			network_widget_nm_interface_set_display_title ((NetworkWidgetNMInterface*) self, _tmp7_);
		}
	}
	_g_free0 (name);
}

static void
network_abstract_ether_interface_real_update (NetworkWidgetNMInterface* base)
{
	NetworkAbstractEtherInterface * self;
	NMDevice* _tmp0_;
	NMDeviceState _tmp1_;
	NMDeviceState _tmp2_;
	self = (NetworkAbstractEtherInterface*) base;
	NETWORK_WIDGET_NM_INTERFACE_CLASS (network_abstract_ether_interface_parent_class)->update (G_TYPE_CHECK_INSTANCE_CAST (self, NETWORK_TYPE_WIDGET_NM_INTERFACE, NetworkWidgetNMInterface));
	_tmp0_ = ((NetworkWidgetNMInterface*) self)->device;
	_tmp1_ = nm_device_get_state (_tmp0_);
	_tmp2_ = _tmp1_;
	switch (_tmp2_) {
		case NM_DEVICE_STATE_UNKNOWN:
		case NM_DEVICE_STATE_UNMANAGED:
		case NM_DEVICE_STATE_UNAVAILABLE:
		{
			network_widget_nm_interface_set_state ((NetworkWidgetNMInterface*) self, NETWORK_STATE_WIRED_UNPLUGGED);
			break;
		}
		case NM_DEVICE_STATE_DISCONNECTED:
		case NM_DEVICE_STATE_DEACTIVATING:
		case NM_DEVICE_STATE_FAILED:
		{
			network_widget_nm_interface_set_state ((NetworkWidgetNMInterface*) self, NETWORK_STATE_FAILED_WIRED);
			break;
		}
		case NM_DEVICE_STATE_PREPARE:
		case NM_DEVICE_STATE_CONFIG:
		case NM_DEVICE_STATE_NEED_AUTH:
		case NM_DEVICE_STATE_IP_CONFIG:
		case NM_DEVICE_STATE_IP_CHECK:
		case NM_DEVICE_STATE_SECONDARIES:
		{
			network_widget_nm_interface_set_state ((NetworkWidgetNMInterface*) self, NETWORK_STATE_CONNECTING_WIRED);
			break;
		}
		case NM_DEVICE_STATE_ACTIVATED:
		{
			network_widget_nm_interface_set_state ((NetworkWidgetNMInterface*) self, NETWORK_STATE_CONNECTED_WIRED);
			break;
		}
		default:
		break;
	}
}

NetworkAbstractEtherInterface*
network_abstract_ether_interface_construct (GType object_type)
{
	NetworkAbstractEtherInterface * self = NULL;
	self = (NetworkAbstractEtherInterface*) network_widget_nm_interface_construct (object_type);
	return self;
}

static void
network_abstract_ether_interface_class_init (NetworkAbstractEtherInterfaceClass * klass,
                                             gpointer klass_data)
{
	network_abstract_ether_interface_parent_class = g_type_class_peek_parent (klass);
	((NetworkWidgetNMInterfaceClass *) klass)->update_name = (void (*) (NetworkWidgetNMInterface*, gint)) network_abstract_ether_interface_real_update_name;
	((NetworkWidgetNMInterfaceClass *) klass)->update = (void (*) (NetworkWidgetNMInterface*)) network_abstract_ether_interface_real_update;
}

static void
network_abstract_ether_interface_instance_init (NetworkAbstractEtherInterface * self,
                                                gpointer klass)
{
}

GType
network_abstract_ether_interface_get_type (void)
{
	return network_abstract_ether_interface_type_id;
}

GType
network_abstract_ether_interface_register_type (GTypeModule * module)
{
	static const GTypeInfo g_define_type_info = { sizeof (NetworkAbstractEtherInterfaceClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) network_abstract_ether_interface_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (NetworkAbstractEtherInterface), 0, (GInstanceInitFunc) network_abstract_ether_interface_instance_init, NULL };
	network_abstract_ether_interface_type_id = g_type_module_register_type (module, NETWORK_TYPE_WIDGET_NM_INTERFACE, "NetworkAbstractEtherInterface", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
	return network_abstract_ether_interface_type_id;
}

