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

/*
* Copyright (c) 2015-2016 elementary LLC (http://launchpad.net/wingpanel-indicator-network)
*
* 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 <gtk/gtk.h>
#include <glib.h>
#include <glib-object.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_DISPLAY_WIDGET_0_PROPERTY,
	NETWORK_WIDGETS_DISPLAY_WIDGET_NUM_PROPERTIES
};
static GParamSpec* network_widgets_display_widget_properties[NETWORK_WIDGETS_DISPLAY_WIDGET_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block2Data Block2Data;
#define _g_free0(var) (var = (g_free (var), NULL))

struct _NetworkWidgetsDisplayWidgetPrivate {
	NetworkWidgetsOverlayIcon* icon;
	GtkLabel* extra_info_label;
	GtkRevealer* extra_info_revealer;
	guint wifi_animation_timeout;
	gint wifi_animation_state;
	guint cellular_animation_timeout;
	gint cellular_animation_state;
};

struct _Block2Data {
	int _ref_count_;
	NetworkWidgetsDisplayWidget* self;
	gboolean secure;
};

static gint NetworkWidgetsDisplayWidget_private_offset;
static gpointer network_widgets_display_widget_parent_class = NULL;
static GType network_widgets_display_widget_type_id = 0;

static Block2Data* block2_data_ref (Block2Data* _data2_);
static void block2_data_unref (void * _userdata_);
static gboolean ___lambda39_ (Block2Data* _data2_);
static gboolean ____lambda39__gsource_func (gpointer self);
static gboolean ___lambda40_ (Block2Data* _data2_);
static gboolean ____lambda40__gsource_func (gpointer self);
static GObject * network_widgets_display_widget_constructor (GType type,
                                                      guint n_construct_properties,
                                                      GObjectConstructParam * construct_properties);
static void network_widgets_display_widget_finalize (GObject * obj);

static inline gpointer
network_widgets_display_widget_get_instance_private (NetworkWidgetsDisplayWidget* self)
{
	return G_STRUCT_MEMBER_P (self, NetworkWidgetsDisplayWidget_private_offset);
}

NetworkWidgetsDisplayWidget*
network_widgets_display_widget_construct (GType object_type)
{
	NetworkWidgetsDisplayWidget * self = NULL;
	self = (NetworkWidgetsDisplayWidget*) g_object_new (object_type, "orientation", GTK_ORIENTATION_HORIZONTAL, "halign", GTK_ALIGN_CENTER, "valign", GTK_ALIGN_CENTER, NULL);
	return self;
}

NetworkWidgetsDisplayWidget*
network_widgets_display_widget_new (void)
{
	return network_widgets_display_widget_construct (NETWORK_WIDGETS_TYPE_DISPLAY_WIDGET);
}

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_)) {
		NetworkWidgetsDisplayWidget* self;
		self = _data2_->self;
		_g_object_unref0 (self);
		g_slice_free (Block2Data, _data2_);
	}
}

static gboolean
___lambda39_ (Block2Data* _data2_)
{
	NetworkWidgetsDisplayWidget* self;
	gchar* strength = NULL;
	gchar* _tmp0_;
	const gchar* _tmp5_ = NULL;
	NetworkWidgetsOverlayIcon* _tmp6_;
	const gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	gboolean result;
	self = _data2_->self;
	self->priv->wifi_animation_state = (self->priv->wifi_animation_state + 1) % 4;
	_tmp0_ = g_strdup ("");
	strength = _tmp0_;
	switch (self->priv->wifi_animation_state) {
		case 0:
		{
			gchar* _tmp1_;
			_tmp1_ = g_strdup ("weak");
			_g_free0 (strength);
			strength = _tmp1_;
			break;
		}
		case 1:
		{
			gchar* _tmp2_;
			_tmp2_ = g_strdup ("ok");
			_g_free0 (strength);
			strength = _tmp2_;
			break;
		}
		case 2:
		{
			gchar* _tmp3_;
			_tmp3_ = g_strdup ("good");
			_g_free0 (strength);
			strength = _tmp3_;
			break;
		}
		case 3:
		{
			gchar* _tmp4_;
			_tmp4_ = g_strdup ("excellent");
			_g_free0 (strength);
			strength = _tmp4_;
			break;
		}
		default:
		break;
	}
	if (_data2_->secure) {
		_tmp5_ = "nm-vpn-lock";
	} else {
		_tmp5_ = "";
	}
	_tmp6_ = self->priv->icon;
	_tmp7_ = strength;
	_tmp8_ = g_strconcat ("network-wireless-signal-", _tmp7_, NULL);
	_tmp9_ = _tmp8_;
	_tmp10_ = g_strconcat (_tmp9_, "-symbolic", NULL);
	_tmp11_ = _tmp10_;
	network_widgets_overlay_icon_set_name (_tmp6_, _tmp11_, _tmp5_);
	_g_free0 (_tmp11_);
	_g_free0 (_tmp9_);
	result = TRUE;
	_g_free0 (strength);
	return result;
}

static gboolean
____lambda39__gsource_func (gpointer self)
{
	gboolean result;
	result = ___lambda39_ (self);
	return result;
}

static gboolean
___lambda40_ (Block2Data* _data2_)
{
	NetworkWidgetsDisplayWidget* self;
	gchar* strength = NULL;
	gchar* _tmp0_;
	const gchar* _tmp5_ = NULL;
	NetworkWidgetsOverlayIcon* _tmp6_;
	const gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	gboolean result;
	self = _data2_->self;
	self->priv->cellular_animation_state = (self->priv->cellular_animation_state + 1) % 4;
	_tmp0_ = g_strdup ("");
	strength = _tmp0_;
	switch (self->priv->cellular_animation_state) {
		case 0:
		{
			gchar* _tmp1_;
			_tmp1_ = g_strdup ("weak");
			_g_free0 (strength);
			strength = _tmp1_;
			break;
		}
		case 1:
		{
			gchar* _tmp2_;
			_tmp2_ = g_strdup ("ok");
			_g_free0 (strength);
			strength = _tmp2_;
			break;
		}
		case 2:
		{
			gchar* _tmp3_;
			_tmp3_ = g_strdup ("good");
			_g_free0 (strength);
			strength = _tmp3_;
			break;
		}
		case 3:
		{
			gchar* _tmp4_;
			_tmp4_ = g_strdup ("excellent");
			_g_free0 (strength);
			strength = _tmp4_;
			break;
		}
		default:
		break;
	}
	if (_data2_->secure) {
		_tmp5_ = "nm-vpn-lock";
	} else {
		_tmp5_ = "";
	}
	_tmp6_ = self->priv->icon;
	_tmp7_ = strength;
	_tmp8_ = g_strconcat ("network-cellular-signal-", _tmp7_, NULL);
	_tmp9_ = _tmp8_;
	_tmp10_ = g_strconcat (_tmp9_, "-symbolic", NULL);
	_tmp11_ = _tmp10_;
	network_widgets_overlay_icon_set_name (_tmp6_, _tmp11_, _tmp5_);
	_g_free0 (_tmp11_);
	_g_free0 (_tmp9_);
	result = TRUE;
	_g_free0 (strength);
	return result;
}

static gboolean
____lambda40__gsource_func (gpointer self)
{
	gboolean result;
	result = ___lambda40_ (self);
	return result;
}

void
network_widgets_display_widget_update_state (NetworkWidgetsDisplayWidget* self,
                                             NetworkState state,
                                             gboolean secure,
                                             const gchar* extra_info)
{
	Block2Data* _data2_;
	GtkRevealer* _tmp0_;
	GtkLabel* _tmp1_;
	g_return_if_fail (self != NULL);
	_data2_ = g_slice_new0 (Block2Data);
	_data2_->_ref_count_ = 1;
	_data2_->self = g_object_ref (self);
	_data2_->secure = secure;
	_tmp0_ = self->priv->extra_info_revealer;
	gtk_revealer_set_reveal_child (_tmp0_, extra_info != NULL);
	_tmp1_ = self->priv->extra_info_label;
	gtk_label_set_label (_tmp1_, extra_info);
	if (self->priv->wifi_animation_timeout > ((guint) 0)) {
		g_source_remove (self->priv->wifi_animation_timeout);
		self->priv->wifi_animation_timeout = (guint) 0;
	}
	if (self->priv->cellular_animation_timeout > ((guint) 0)) {
		g_source_remove (self->priv->cellular_animation_timeout);
		self->priv->cellular_animation_timeout = (guint) 0;
	}
	switch (state) {
		case NETWORK_STATE_DISCONNECTED_AIRPLANE_MODE:
		{
			NetworkWidgetsOverlayIcon* _tmp2_;
			_tmp2_ = self->priv->icon;
			network_widgets_overlay_icon_set_name (_tmp2_, "airplane-mode-symbolic", NULL);
			break;
		}
		case NETWORK_STATE_CONNECTING_WIRED:
		{
			NetworkWidgetsOverlayIcon* _tmp3_;
			_tmp3_ = self->priv->icon;
			network_widgets_overlay_icon_set_name (_tmp3_, "network-wired-acquiring-symbolic", NULL);
			break;
		}
		case NETWORK_STATE_CONNECTED_WIRED:
		{
			const gchar* _tmp4_ = NULL;
			NetworkWidgetsOverlayIcon* _tmp5_;
			if (_data2_->secure) {
				_tmp4_ = "nm-vpn-lock";
			} else {
				_tmp4_ = "";
			}
			_tmp5_ = self->priv->icon;
			network_widgets_overlay_icon_set_name (_tmp5_, "network-wired-symbolic", _tmp4_);
			break;
		}
		case NETWORK_STATE_CONNECTED_WIFI:
		{
			NetworkWidgetsOverlayIcon* _tmp6_;
			_tmp6_ = self->priv->icon;
			network_widgets_overlay_icon_set_name (_tmp6_, "network-wireless-connected-symbolic", NULL);
			break;
		}
		case NETWORK_STATE_CONNECTED_WIFI_WEAK:
		{
			const gchar* _tmp7_ = NULL;
			NetworkWidgetsOverlayIcon* _tmp8_;
			if (_data2_->secure) {
				_tmp7_ = "nm-vpn-lock";
			} else {
				_tmp7_ = "";
			}
			_tmp8_ = self->priv->icon;
			network_widgets_overlay_icon_set_name (_tmp8_, "network-wireless-signal-weak-symbolic", _tmp7_);
			break;
		}
		case NETWORK_STATE_CONNECTED_WIFI_OK:
		{
			const gchar* _tmp9_ = NULL;
			NetworkWidgetsOverlayIcon* _tmp10_;
			if (_data2_->secure) {
				_tmp9_ = "nm-vpn-lock";
			} else {
				_tmp9_ = "";
			}
			_tmp10_ = self->priv->icon;
			network_widgets_overlay_icon_set_name (_tmp10_, "network-wireless-signal-ok-symbolic", _tmp9_);
			break;
		}
		case NETWORK_STATE_CONNECTED_WIFI_GOOD:
		{
			const gchar* _tmp11_ = NULL;
			NetworkWidgetsOverlayIcon* _tmp12_;
			if (_data2_->secure) {
				_tmp11_ = "nm-vpn-lock";
			} else {
				_tmp11_ = "";
			}
			_tmp12_ = self->priv->icon;
			network_widgets_overlay_icon_set_name (_tmp12_, "network-wireless-signal-good-symbolic", _tmp11_);
			break;
		}
		case NETWORK_STATE_CONNECTED_WIFI_EXCELLENT:
		{
			const gchar* _tmp13_ = NULL;
			NetworkWidgetsOverlayIcon* _tmp14_;
			if (_data2_->secure) {
				_tmp13_ = "nm-vpn-lock";
			} else {
				_tmp13_ = "";
			}
			_tmp14_ = self->priv->icon;
			network_widgets_overlay_icon_set_name (_tmp14_, "network-wireless-signal-excellent-symbolic", _tmp13_);
			break;
		}
		case NETWORK_STATE_CONNECTING_WIFI:
		{
			self->priv->wifi_animation_timeout = g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) 300, ____lambda39__gsource_func, block2_data_ref (_data2_), block2_data_unref);
			break;
		}
		case NETWORK_STATE_CONNECTED_MOBILE_WEAK:
		{
			const gchar* _tmp15_ = NULL;
			NetworkWidgetsOverlayIcon* _tmp16_;
			if (_data2_->secure) {
				_tmp15_ = "nm-vpn-lock";
			} else {
				_tmp15_ = "";
			}
			_tmp16_ = self->priv->icon;
			network_widgets_overlay_icon_set_name (_tmp16_, "network-cellular-signal-weak-symbolic", _tmp15_);
			break;
		}
		case NETWORK_STATE_CONNECTED_MOBILE_OK:
		{
			const gchar* _tmp17_ = NULL;
			NetworkWidgetsOverlayIcon* _tmp18_;
			if (_data2_->secure) {
				_tmp17_ = "nm-vpn-lock";
			} else {
				_tmp17_ = "";
			}
			_tmp18_ = self->priv->icon;
			network_widgets_overlay_icon_set_name (_tmp18_, "network-cellular-signal-ok-symbolic", _tmp17_);
			break;
		}
		case NETWORK_STATE_CONNECTED_MOBILE_GOOD:
		{
			const gchar* _tmp19_ = NULL;
			NetworkWidgetsOverlayIcon* _tmp20_;
			if (_data2_->secure) {
				_tmp19_ = "nm-vpn-lock";
			} else {
				_tmp19_ = "";
			}
			_tmp20_ = self->priv->icon;
			network_widgets_overlay_icon_set_name (_tmp20_, "network-cellular-signal-good-symbolic", _tmp19_);
			break;
		}
		case NETWORK_STATE_CONNECTED_MOBILE_EXCELLENT:
		{
			const gchar* _tmp21_ = NULL;
			NetworkWidgetsOverlayIcon* _tmp22_;
			if (_data2_->secure) {
				_tmp21_ = "nm-vpn-lock";
			} else {
				_tmp21_ = "";
			}
			_tmp22_ = self->priv->icon;
			network_widgets_overlay_icon_set_name (_tmp22_, "network-cellular-signal-excellent-symbolic", _tmp21_);
			break;
		}
		case NETWORK_STATE_CONNECTING_MOBILE:
		{
			self->priv->cellular_animation_timeout = g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) 300, ____lambda40__gsource_func, block2_data_ref (_data2_), block2_data_unref);
			break;
		}
		case NETWORK_STATE_FAILED_MOBILE:
		{
			NetworkWidgetsOverlayIcon* _tmp23_;
			_tmp23_ = self->priv->icon;
			network_widgets_overlay_icon_set_name (_tmp23_, "network-cellular-offline-symbolic", NULL);
			break;
		}
		case NETWORK_STATE_FAILED_WIFI:
		case NETWORK_STATE_DISCONNECTED:
		{
			NetworkWidgetsOverlayIcon* _tmp24_;
			_tmp24_ = self->priv->icon;
			network_widgets_overlay_icon_set_name (_tmp24_, "network-wireless-offline-symbolic", NULL);
			break;
		}
		case NETWORK_STATE_WIRED_UNPLUGGED:
		{
			NetworkWidgetsOverlayIcon* _tmp25_;
			_tmp25_ = self->priv->icon;
			network_widgets_overlay_icon_set_name (_tmp25_, "network-wired-offline-symbolic", NULL);
			break;
		}
		default:
		{
			NetworkWidgetsOverlayIcon* _tmp26_;
			GEnumValue* _tmp27_;
			_tmp26_ = self->priv->icon;
			network_widgets_overlay_icon_set_name (_tmp26_, "network-offline-symbolic", NULL);
			_tmp27_ = g_enum_get_value (g_type_class_ref (NETWORK_TYPE_STATE), state);
			g_critical ("DisplayWidget.vala:159: Unknown network state, cannot show the good ic" \
"on: %s", (_tmp27_ != NULL) ? _tmp27_->value_name : NULL);
			break;
		}
	}
	block2_data_unref (_data2_);
	_data2_ = NULL;
}

static GObject *
network_widgets_display_widget_constructor (GType type,
                                            guint n_construct_properties,
                                            GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	NetworkWidgetsDisplayWidget * self;
	NetworkWidgetsOverlayIcon* _tmp0_;
	GtkLabel* _tmp1_;
	GtkLabel* _tmp2_;
	GtkLabel* _tmp3_;
	GtkLabel* _tmp4_;
	GtkRevealer* _tmp5_;
	GtkRevealer* _tmp6_;
	GtkRevealer* _tmp7_;
	GtkLabel* _tmp8_;
	NetworkWidgetsOverlayIcon* _tmp9_;
	GtkRevealer* _tmp10_;
	parent_class = G_OBJECT_CLASS (network_widgets_display_widget_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, NETWORK_WIDGETS_TYPE_DISPLAY_WIDGET, NetworkWidgetsDisplayWidget);
	_tmp0_ = network_widgets_overlay_icon_new ("network-wired-symbolic");
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->icon);
	self->priv->icon = _tmp0_;
	_tmp1_ = (GtkLabel*) gtk_label_new (NULL);
	g_object_ref_sink (_tmp1_);
	_g_object_unref0 (self->priv->extra_info_label);
	self->priv->extra_info_label = _tmp1_;
	_tmp2_ = self->priv->extra_info_label;
	gtk_widget_set_margin_start ((GtkWidget*) _tmp2_, 4);
	_tmp3_ = self->priv->extra_info_label;
	gtk_widget_set_valign ((GtkWidget*) _tmp3_, GTK_ALIGN_CENTER);
	_tmp4_ = self->priv->extra_info_label;
	gtk_widget_set_vexpand ((GtkWidget*) _tmp4_, FALSE);
	_tmp5_ = (GtkRevealer*) gtk_revealer_new ();
	g_object_ref_sink (_tmp5_);
	_g_object_unref0 (self->priv->extra_info_revealer);
	self->priv->extra_info_revealer = _tmp5_;
	_tmp6_ = self->priv->extra_info_revealer;
	gtk_revealer_set_transition_type (_tmp6_, GTK_REVEALER_TRANSITION_TYPE_SLIDE_LEFT);
	_tmp7_ = self->priv->extra_info_revealer;
	_tmp8_ = self->priv->extra_info_label;
	gtk_container_add ((GtkContainer*) _tmp7_, (GtkWidget*) _tmp8_);
	_tmp9_ = self->priv->icon;
	gtk_box_pack_start ((GtkBox*) self, (GtkWidget*) _tmp9_, TRUE, TRUE, (guint) 0);
	_tmp10_ = self->priv->extra_info_revealer;
	gtk_box_pack_start ((GtkBox*) self, (GtkWidget*) _tmp10_, TRUE, TRUE, (guint) 0);
	return obj;
}

static void
network_widgets_display_widget_class_init (NetworkWidgetsDisplayWidgetClass * klass,
                                           gpointer klass_data)
{
	network_widgets_display_widget_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &NetworkWidgetsDisplayWidget_private_offset);
	G_OBJECT_CLASS (klass)->constructor = network_widgets_display_widget_constructor;
	G_OBJECT_CLASS (klass)->finalize = network_widgets_display_widget_finalize;
}

static void
network_widgets_display_widget_instance_init (NetworkWidgetsDisplayWidget * self,
                                              gpointer klass)
{
	self->priv = network_widgets_display_widget_get_instance_private (self);
	self->priv->wifi_animation_state = 0;
	self->priv->cellular_animation_state = 0;
}

static void
network_widgets_display_widget_finalize (GObject * obj)
{
	NetworkWidgetsDisplayWidget * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, NETWORK_WIDGETS_TYPE_DISPLAY_WIDGET, NetworkWidgetsDisplayWidget);
	_g_object_unref0 (self->priv->icon);
	_g_object_unref0 (self->priv->extra_info_label);
	_g_object_unref0 (self->priv->extra_info_revealer);
	G_OBJECT_CLASS (network_widgets_display_widget_parent_class)->finalize (obj);
}

GType
network_widgets_display_widget_get_type (void)
{
	return network_widgets_display_widget_type_id;
}

GType
network_widgets_display_widget_register_type (GTypeModule * module)
{
	static const GTypeInfo g_define_type_info = { sizeof (NetworkWidgetsDisplayWidgetClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) network_widgets_display_widget_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (NetworkWidgetsDisplayWidget), 0, (GInstanceInitFunc) network_widgets_display_widget_instance_init, NULL };
	network_widgets_display_widget_type_id = g_type_module_register_type (module, gtk_box_get_type (), "NetworkWidgetsDisplayWidget", &g_define_type_info, 0);
	NetworkWidgetsDisplayWidget_private_offset = sizeof (NetworkWidgetsDisplayWidgetPrivate);
	return network_widgets_display_widget_type_id;
}

