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

/*
* Copyright (c) 2018-2020 Daniel Pinto (https://github.com/danielpinto8zz6/budgie-network-applet)
* 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 <stdlib.h>
#include <string.h>
#include <glib.h>
#include <plugin.h>
#include <glib-object.h>
#include <locale.h>
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <libpeas.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_PLUGIN_0_PROPERTY,
	NETWORK_PLUGIN_NUM_PROPERTIES
};
static GParamSpec* network_plugin_properties[NETWORK_PLUGIN_NUM_PROPERTIES];
enum  {
	NETWORK_APPLET_0_PROPERTY,
	NETWORK_APPLET_NUM_PROPERTIES
};
static GParamSpec* network_applet_properties[NETWORK_APPLET_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _NetworkAppletPrivate {
	BudgiePopover* popover;
	BudgiePopoverManager* manager;
	NetworkWidgetsPopoverWidget* popover_widget;
	NetworkWidgetsDisplayWidget* display_widget;
};

static gpointer network_plugin_parent_class = NULL;
static BudgiePluginIface * network_plugin_budgie_plugin_parent_iface = NULL;
static GType network_plugin_type_id = 0;
static gint NetworkApplet_private_offset;
static gpointer network_applet_parent_class = NULL;
static GType network_applet_type_id = 0;

static BudgieApplet* network_plugin_real_get_panel_widget (BudgiePlugin* base,
                                                    const gchar* uuid);
static void network_applet_on_state_changed (NetworkApplet* self);
static void _network_applet_on_state_changed_g_object_notify (GObject* _sender,
                                                       GParamSpec* pspec,
                                                       gpointer self);
static void __lambda41_ (NetworkApplet* self);
static void ___lambda41__network_widgets_popover_widget_settings_shown (NetworkWidgetsPopoverWidget* _sender,
                                                                 gpointer self);
static gboolean __lambda42_ (NetworkApplet* self,
                      GdkEventButton* e);
static gboolean ___lambda42__gtk_widget_button_press_event (GtkWidget* _sender,
                                                     GdkEventButton* event,
                                                     gpointer self);
static void network_applet_real_update_popovers (BudgieApplet* base,
                                          BudgiePopoverManager* manager);
static void network_applet_finalize (GObject * obj);
GType network_widgets_nm_visualizer_register_type (GTypeModule * module);
GType network_widgets_display_widget_register_type (GTypeModule * module);
GType network_widgets_popover_widget_register_type (GTypeModule * module);
GType network_widgets_separator_register_type (GTypeModule * module);
GType network_widgets_switch_register_type (GTypeModule * module);
GType network_widgets_overlay_icon_register_type (GTypeModule * module);
GType network_widget_nm_interface_register_type (GTypeModule * module);
GType network_abstract_ether_interface_register_type (GTypeModule * module);
GType network_abstract_modem_interface_register_type (GTypeModule * module);
GType network_abstract_vpn_interface_register_type (GTypeModule * module);
GType network_abstract_wifi_interface_register_type (GTypeModule * module);
GType network_abstract_bluetooth_interface_register_type (GTypeModule * module);
GType network_vpn_menu_item_register_type (GTypeModule * module);
GType network_wifi_menu_item_register_type (GTypeModule * module);
GType network_ether_interface_register_type (GTypeModule * module);
GType network_modem_interface_register_type (GTypeModule * module);
GType network_vpn_interface_register_type (GTypeModule * module);
GType network_wifi_interface_register_type (GTypeModule * module);
GType network_bluetooth_interface_register_type (GTypeModule * module);
GType rf_kill_device_register_type (GTypeModule * module);
GType rf_kill_manager_register_type (GTypeModule * module);

static BudgieApplet*
network_plugin_real_get_panel_widget (BudgiePlugin* base,
                                      const gchar* uuid)
{
	NetworkPlugin * self;
	NetworkApplet* _tmp0_;
	BudgieApplet* result;
	self = (NetworkPlugin*) base;
	g_return_val_if_fail (uuid != NULL, NULL);
	_tmp0_ = network_applet_new ();
	g_object_ref_sink (_tmp0_);
	result = (BudgieApplet*) _tmp0_;
	return result;
}

NetworkPlugin*
network_plugin_construct (GType object_type)
{
	NetworkPlugin * self = NULL;
	self = (NetworkPlugin*) g_object_new (object_type, NULL);
	return self;
}

NetworkPlugin*
network_plugin_new (void)
{
	return network_plugin_construct (NETWORK_TYPE_PLUGIN);
}

static void
network_plugin_class_init (NetworkPluginClass * klass,
                           gpointer klass_data)
{
	network_plugin_parent_class = g_type_class_peek_parent (klass);
}

static void
network_plugin_budgie_plugin_interface_init (BudgiePluginIface * iface,
                                             gpointer iface_data)
{
	network_plugin_budgie_plugin_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_panel_widget = (BudgieApplet* (*) (BudgiePlugin*, const gchar*)) network_plugin_real_get_panel_widget;
}

static void
network_plugin_instance_init (NetworkPlugin * self,
                              gpointer klass)
{
}

GType
network_plugin_get_type (void)
{
	return network_plugin_type_id;
}

GType
network_plugin_register_type (GTypeModule * module)
{
	static const GTypeInfo g_define_type_info = { sizeof (NetworkPluginClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) network_plugin_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (NetworkPlugin), 0, (GInstanceInitFunc) network_plugin_instance_init, NULL };
	static const GInterfaceInfo budgie_plugin_info = { (GInterfaceInitFunc) network_plugin_budgie_plugin_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	network_plugin_type_id = g_type_module_register_type (module, peas_extension_base_get_type (), "NetworkPlugin", &g_define_type_info, 0);
	g_type_module_add_interface (module, network_plugin_type_id, budgie_plugin_get_type (), &budgie_plugin_info);
	return network_plugin_type_id;
}

static inline gpointer
network_applet_get_instance_private (NetworkApplet* self)
{
	return G_STRUCT_MEMBER_P (self, NetworkApplet_private_offset);
}

static void
_network_applet_on_state_changed_g_object_notify (GObject* _sender,
                                                  GParamSpec* pspec,
                                                  gpointer self)
{
	network_applet_on_state_changed ((NetworkApplet*) self);
}

static void
__lambda41_ (NetworkApplet* self)
{
	BudgiePopover* _tmp0_;
	_tmp0_ = self->priv->popover;
	gtk_widget_hide ((GtkWidget*) _tmp0_);
}

static void
___lambda41__network_widgets_popover_widget_settings_shown (NetworkWidgetsPopoverWidget* _sender,
                                                            gpointer self)
{
	__lambda41_ ((NetworkApplet*) self);
}

static gboolean
__lambda42_ (NetworkApplet* self,
             GdkEventButton* e)
{
	BudgiePopover* _tmp0_;
	gboolean result;
	g_return_val_if_fail (e != NULL, FALSE);
	if (e->button != ((guint) 1)) {
		result = GDK_EVENT_PROPAGATE;
		return result;
	}
	_tmp0_ = self->priv->popover;
	if (gtk_widget_get_visible ((GtkWidget*) _tmp0_)) {
		BudgiePopover* _tmp1_;
		_tmp1_ = self->priv->popover;
		gtk_widget_hide ((GtkWidget*) _tmp1_);
	} else {
		BudgiePopoverManager* _tmp2_;
		GtkEventBox* _tmp3_;
		_tmp2_ = self->priv->manager;
		_tmp3_ = self->widget;
		budgie_popover_manager_show_popover (_tmp2_, (GtkWidget*) _tmp3_);
	}
	result = GDK_EVENT_STOP;
	return result;
}

static gboolean
___lambda42__gtk_widget_button_press_event (GtkWidget* _sender,
                                            GdkEventButton* event,
                                            gpointer self)
{
	gboolean result;
	result = __lambda42_ ((NetworkApplet*) self, event);
	return result;
}

NetworkApplet*
network_applet_construct (GType object_type)
{
	NetworkApplet * self = NULL;
	GtkEventBox* _tmp0_;
	GtkEventBox* _tmp1_;
	GtkStyleContext* _tmp2_;
	GtkEventBox* _tmp3_;
	BudgiePopover* _tmp4_;
	NetworkWidgetsDisplayWidget* _tmp5_;
	GtkEventBox* _tmp6_;
	NetworkWidgetsDisplayWidget* _tmp7_;
	NetworkWidgetsPopoverWidget* _tmp8_;
	NetworkWidgetsPopoverWidget* _tmp9_;
	NetworkWidgetsPopoverWidget* _tmp10_;
	BudgiePopover* _tmp11_;
	NetworkWidgetsPopoverWidget* _tmp12_;
	NetworkWidgetsPopoverWidget* _tmp13_;
	NetworkWidgetsPopoverWidget* _tmp14_;
	NetworkWidgetsPopoverWidget* _tmp15_;
	NetworkWidgetsPopoverWidget* _tmp16_;
	GtkEventBox* _tmp17_;
	BudgiePopover* _tmp18_;
	GtkWidget* _tmp19_;
	self = (NetworkApplet*) g_object_new (object_type, NULL);
	setlocale (LC_ALL, "");
	bindtextdomain (CONFIG_GETTEXT_PACKAGE, CONFIG_LOCALE_DIR);
	bind_textdomain_codeset (CONFIG_GETTEXT_PACKAGE, "UTF-8");
	textdomain (CONFIG_GETTEXT_PACKAGE);
	_tmp0_ = (GtkEventBox*) gtk_event_box_new ();
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->widget);
	self->widget = _tmp0_;
	_tmp1_ = self->widget;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp1_);
	_tmp2_ = gtk_widget_get_style_context ((GtkWidget*) self);
	gtk_style_context_add_class (_tmp2_, "budgie-network-applet");
	_tmp3_ = self->widget;
	_tmp4_ = (BudgiePopover*) budgie_popover_new ((GtkWidget*) _tmp3_);
	g_object_ref_sink (_tmp4_);
	_g_object_unref0 (self->priv->popover);
	self->priv->popover = _tmp4_;
	_tmp5_ = network_widgets_display_widget_new ();
	g_object_ref_sink (_tmp5_);
	_g_object_unref0 (self->priv->display_widget);
	self->priv->display_widget = _tmp5_;
	_tmp6_ = self->widget;
	_tmp7_ = self->priv->display_widget;
	gtk_container_add ((GtkContainer*) _tmp6_, (GtkWidget*) _tmp7_);
	_tmp8_ = network_widgets_popover_widget_new ();
	g_object_ref_sink (_tmp8_);
	_g_object_unref0 (self->priv->popover_widget);
	self->priv->popover_widget = _tmp8_;
	_tmp9_ = self->priv->popover_widget;
	g_object_set ((GtkWidget*) _tmp9_, "width-request", 250, NULL);
	_tmp10_ = self->priv->popover_widget;
	gtk_container_set_border_width ((GtkContainer*) _tmp10_, (guint) 6);
	_tmp11_ = self->priv->popover;
	_tmp12_ = self->priv->popover_widget;
	gtk_container_add ((GtkContainer*) _tmp11_, (GtkWidget*) _tmp12_);
	_tmp13_ = self->priv->popover_widget;
	g_signal_connect_object ((GObject*) _tmp13_, "notify::state", (GCallback) _network_applet_on_state_changed_g_object_notify, self, 0);
	_tmp14_ = self->priv->popover_widget;
	g_signal_connect_object ((GObject*) _tmp14_, "notify::secure", (GCallback) _network_applet_on_state_changed_g_object_notify, self, 0);
	_tmp15_ = self->priv->popover_widget;
	g_signal_connect_object ((GObject*) _tmp15_, "notify::extra-info", (GCallback) _network_applet_on_state_changed_g_object_notify, self, 0);
	_tmp16_ = self->priv->popover_widget;
	g_signal_connect_object (_tmp16_, "settings-shown", (GCallback) ___lambda41__network_widgets_popover_widget_settings_shown, self, 0);
	_tmp17_ = self->widget;
	g_signal_connect_object ((GtkWidget*) _tmp17_, "button-press-event", (GCallback) ___lambda42__gtk_widget_button_press_event, self, 0);
	_tmp18_ = self->priv->popover;
	_tmp19_ = gtk_bin_get_child ((GtkBin*) _tmp18_);
	gtk_widget_show_all (_tmp19_);
	gtk_widget_show_all ((GtkWidget*) self);
	network_applet_on_state_changed (self);
	return self;
}

NetworkApplet*
network_applet_new (void)
{
	return network_applet_construct (NETWORK_TYPE_APPLET);
}

static void
network_applet_real_update_popovers (BudgieApplet* base,
                                     BudgiePopoverManager* manager)
{
	NetworkApplet * self;
	GtkEventBox* _tmp0_;
	BudgiePopover* _tmp1_;
	self = (NetworkApplet*) base;
	self->priv->manager = manager;
	_tmp0_ = self->widget;
	_tmp1_ = self->priv->popover;
	budgie_popover_manager_register_popover (manager, (GtkWidget*) _tmp0_, (GtkPopover*) _tmp1_);
}

static void
network_applet_on_state_changed (NetworkApplet* self)
{
	NetworkWidgetsPopoverWidget* _tmp0_;
	NetworkWidgetsDisplayWidget* _tmp1_;
	NetworkWidgetsDisplayWidget* _tmp2_;
	NetworkWidgetsPopoverWidget* _tmp3_;
	NetworkState _tmp4_;
	NetworkState _tmp5_;
	NetworkWidgetsPopoverWidget* _tmp6_;
	gboolean _tmp7_;
	gboolean _tmp8_;
	NetworkWidgetsPopoverWidget* _tmp9_;
	const gchar* _tmp10_;
	const gchar* _tmp11_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->popover_widget;
	_vala_assert (_tmp0_ != NULL, "popover_widget != null");
	_tmp1_ = self->priv->display_widget;
	_vala_assert (_tmp1_ != NULL, "display_widget != null");
	_tmp2_ = self->priv->display_widget;
	_tmp3_ = self->priv->popover_widget;
	_tmp4_ = network_widgets_nm_visualizer_get_state ((NetworkWidgetsNMVisualizer*) _tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = self->priv->popover_widget;
	_tmp7_ = network_widgets_nm_visualizer_get_secure ((NetworkWidgetsNMVisualizer*) _tmp6_);
	_tmp8_ = _tmp7_;
	_tmp9_ = self->priv->popover_widget;
	_tmp10_ = network_widgets_nm_visualizer_get_extra_info ((NetworkWidgetsNMVisualizer*) _tmp9_);
	_tmp11_ = _tmp10_;
	network_widgets_display_widget_update_state (_tmp2_, _tmp5_, _tmp8_, _tmp11_);
}

static void
network_applet_class_init (NetworkAppletClass * klass,
                           gpointer klass_data)
{
	network_applet_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &NetworkApplet_private_offset);
	((BudgieAppletClass *) klass)->update_popovers = (void (*) (BudgieApplet*, BudgiePopoverManager*)) network_applet_real_update_popovers;
	G_OBJECT_CLASS (klass)->finalize = network_applet_finalize;
}

static void
network_applet_instance_init (NetworkApplet * self,
                              gpointer klass)
{
	self->priv = network_applet_get_instance_private (self);
	self->priv->popover = NULL;
	self->priv->manager = NULL;
	self->priv->popover_widget = NULL;
	self->priv->display_widget = NULL;
}

static void
network_applet_finalize (GObject * obj)
{
	NetworkApplet * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, NETWORK_TYPE_APPLET, NetworkApplet);
	_g_object_unref0 (self->widget);
	_g_object_unref0 (self->priv->popover);
	_g_object_unref0 (self->priv->popover_widget);
	_g_object_unref0 (self->priv->display_widget);
	G_OBJECT_CLASS (network_applet_parent_class)->finalize (obj);
}

GType
network_applet_get_type (void)
{
	return network_applet_type_id;
}

GType
network_applet_register_type (GTypeModule * module)
{
	static const GTypeInfo g_define_type_info = { sizeof (NetworkAppletClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) network_applet_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (NetworkApplet), 0, (GInstanceInitFunc) network_applet_instance_init, NULL };
	network_applet_type_id = g_type_module_register_type (module, budgie_applet_get_type (), "NetworkApplet", &g_define_type_info, 0);
	NetworkApplet_private_offset = sizeof (NetworkAppletPrivate);
	return network_applet_type_id;
}

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

void
peas_register_types (GTypeModule* module)
{
	PeasObjectModule* objmodule = NULL;
	PeasObjectModule* _tmp0_;
	g_return_if_fail (module != NULL);
	network_widgets_nm_visualizer_register_type (module);
	network_widgets_display_widget_register_type (module);
	network_widgets_popover_widget_register_type (module);
	network_widgets_separator_register_type (module);
	network_widgets_switch_register_type (module);
	network_widgets_overlay_icon_register_type (module);
	network_plugin_register_type (module);
	network_applet_register_type (module);
	network_widget_nm_interface_register_type (module);
	network_abstract_ether_interface_register_type (module);
	network_abstract_modem_interface_register_type (module);
	network_abstract_vpn_interface_register_type (module);
	network_abstract_wifi_interface_register_type (module);
	network_abstract_bluetooth_interface_register_type (module);
	network_vpn_menu_item_register_type (module);
	network_wifi_menu_item_register_type (module);
	network_ether_interface_register_type (module);
	network_modem_interface_register_type (module);
	network_vpn_interface_register_type (module);
	network_wifi_interface_register_type (module);
	network_bluetooth_interface_register_type (module);
	rf_kill_device_register_type (module);
	rf_kill_manager_register_type (module);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (module, peas_object_module_get_type ()) ? ((PeasObjectModule*) module) : NULL);
	objmodule = _tmp0_;
	peas_object_module_register_extension_type (objmodule, budgie_plugin_get_type (), NETWORK_TYPE_PLUGIN);
	_g_object_unref0 (objmodule);
}

