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

/*-
 * Copyright (c) 2015-2021 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 "bluetooth.h"
#include <gtk/gtk.h>
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>
#include <granite.h>
#include <gdk/gdk.h>
#include <gio/gio.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  {
	BLUETOOTH_INDICATOR_WIDGETS_DISPLAY_WIDGET_0_PROPERTY,
	BLUETOOTH_INDICATOR_WIDGETS_DISPLAY_WIDGET_OBJECT_MANAGER_PROPERTY,
	BLUETOOTH_INDICATOR_WIDGETS_DISPLAY_WIDGET_NUM_PROPERTIES
};
static GParamSpec* bluetooth_indicator_widgets_display_widget_properties[BLUETOOTH_INDICATOR_WIDGETS_DISPLAY_WIDGET_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))

struct _BluetoothIndicatorWidgetsDisplayWidgetPrivate {
	BluetoothIndicatorServicesObjectManager* _object_manager;
	GtkStyleContext* style_context;
};

static gint BluetoothIndicatorWidgetsDisplayWidget_private_offset;
static gpointer bluetooth_indicator_widgets_display_widget_parent_class = NULL;

static void bluetooth_indicator_widgets_display_widget_set_icon (BluetoothIndicatorWidgetsDisplayWidget* self);
static void bluetooth_indicator_widgets_display_widget_update_icon (BluetoothIndicatorWidgetsDisplayWidget* self);
static void _bluetooth_indicator_widgets_display_widget_update_icon_gtk_widget_realize (GtkWidget* _sender,
                                                                                 gpointer self);
static GObject * bluetooth_indicator_widgets_display_widget_constructor (GType type,
                                                                  guint n_construct_properties,
                                                                  GObjectConstructParam * construct_properties);
static void _bluetooth_indicator_widgets_display_widget___lambda31_ (BluetoothIndicatorWidgetsDisplayWidget* self,
                                                              gboolean state,
                                                              gboolean connected);
static void __bluetooth_indicator_widgets_display_widget___lambda31__bluetooth_indicator_services_object_manager_global_state_changed (BluetoothIndicatorServicesObjectManager* _sender,
                                                                                                                                gboolean enabled,
                                                                                                                                gboolean connected,
                                                                                                                                gpointer self);
static void _bluetooth_indicator_widgets_display_widget_set_icon_g_object_notify (GObject* _sender,
                                                                           GParamSpec* pspec,
                                                                           gpointer self);
static gboolean _bluetooth_indicator_widgets_display_widget___lambda32_ (BluetoothIndicatorWidgetsDisplayWidget* self,
                                                                  GdkEventButton* e);
static gboolean __bluetooth_indicator_widgets_display_widget___lambda32__gtk_widget_button_press_event (GtkWidget* _sender,
                                                                                                 GdkEventButton* event,
                                                                                                 gpointer self);
static void bluetooth_indicator_widgets_display_widget_finalize (GObject * obj);
static GType bluetooth_indicator_widgets_display_widget_get_type_once (void);
static void _vala_bluetooth_indicator_widgets_display_widget_get_property (GObject * object,
                                                                    guint property_id,
                                                                    GValue * value,
                                                                    GParamSpec * pspec);
static void _vala_bluetooth_indicator_widgets_display_widget_set_property (GObject * object,
                                                                    guint property_id,
                                                                    const GValue * value,
                                                                    GParamSpec * pspec);

static inline gpointer
bluetooth_indicator_widgets_display_widget_get_instance_private (BluetoothIndicatorWidgetsDisplayWidget* self)
{
	return G_STRUCT_MEMBER_P (self, BluetoothIndicatorWidgetsDisplayWidget_private_offset);
}

BluetoothIndicatorWidgetsDisplayWidget*
bluetooth_indicator_widgets_display_widget_construct (GType object_type,
                                                      BluetoothIndicatorServicesObjectManager* object_manager)
{
	BluetoothIndicatorWidgetsDisplayWidget * self = NULL;
	g_return_val_if_fail (object_manager != NULL, NULL);
	self = (BluetoothIndicatorWidgetsDisplayWidget*) g_object_new (object_type, "object-manager", object_manager, NULL);
	return self;
}

BluetoothIndicatorWidgetsDisplayWidget*
bluetooth_indicator_widgets_display_widget_new (BluetoothIndicatorServicesObjectManager* object_manager)
{
	return bluetooth_indicator_widgets_display_widget_construct (BLUETOOTH_INDICATOR_WIDGETS_TYPE_DISPLAY_WIDGET, object_manager);
}

static void
_bluetooth_indicator_widgets_display_widget_update_icon_gtk_widget_realize (GtkWidget* _sender,
                                                                            gpointer self)
{
	bluetooth_indicator_widgets_display_widget_update_icon ((BluetoothIndicatorWidgetsDisplayWidget*) self);
}

static void
bluetooth_indicator_widgets_display_widget_set_icon (BluetoothIndicatorWidgetsDisplayWidget* self)
{
	g_return_if_fail (self != NULL);
	if (gtk_widget_get_realized ((GtkWidget*) self)) {
		bluetooth_indicator_widgets_display_widget_update_icon (self);
	} else {
		g_signal_connect_object ((GtkWidget*) self, "realize", (GCallback) _bluetooth_indicator_widgets_display_widget_update_icon_gtk_widget_realize, self, G_CONNECT_AFTER);
	}
}

static void
bluetooth_indicator_widgets_display_widget_update_icon (BluetoothIndicatorWidgetsDisplayWidget* self)
{
	gboolean state = FALSE;
	BluetoothIndicatorServicesObjectManager* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	gboolean connected = FALSE;
	BluetoothIndicatorServicesObjectManager* _tmp3_;
	gboolean _tmp4_;
	gboolean _tmp5_;
	gchar* description = NULL;
	gchar* context = NULL;
	const gchar* _tmp16_;
	const gchar* _tmp17_;
	gchar* _tmp18_;
	gchar* _tmp19_;
	gchar* _tmp20_;
	gchar* _tmp21_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_object_manager;
	_tmp1_ = bluetooth_indicator_services_object_manager_get_is_powered (_tmp0_);
	_tmp2_ = _tmp1_;
	state = _tmp2_;
	_tmp3_ = self->priv->_object_manager;
	_tmp4_ = bluetooth_indicator_services_object_manager_get_is_connected (_tmp3_);
	_tmp5_ = _tmp4_;
	connected = _tmp5_;
	if (state) {
		GtkStyleContext* _tmp6_;
		gchar* _tmp7_;
		_tmp6_ = self->priv->style_context;
		gtk_style_context_remove_class (_tmp6_, "disabled");
		_tmp7_ = g_strdup (_ ("Middle-click to turn Bluetooth off"));
		_g_free0 (context);
		context = _tmp7_;
		if (connected) {
			GtkStyleContext* _tmp8_;
			gchar* _tmp9_;
			_tmp8_ = self->priv->style_context;
			gtk_style_context_add_class (_tmp8_, "paired");
			_tmp9_ = g_strdup (_ ("Bluetooth connected"));
			_g_free0 (description);
			description = _tmp9_;
		} else {
			GtkStyleContext* _tmp10_;
			gchar* _tmp11_;
			_tmp10_ = self->priv->style_context;
			gtk_style_context_remove_class (_tmp10_, "paired");
			_tmp11_ = g_strdup (_ ("Bluetooth is on"));
			_g_free0 (description);
			description = _tmp11_;
		}
	} else {
		GtkStyleContext* _tmp12_;
		GtkStyleContext* _tmp13_;
		gchar* _tmp14_;
		gchar* _tmp15_;
		_tmp12_ = self->priv->style_context;
		gtk_style_context_remove_class (_tmp12_, "paired");
		_tmp13_ = self->priv->style_context;
		gtk_style_context_add_class (_tmp13_, "disabled");
		_tmp14_ = g_strdup (_ ("Bluetooth is off"));
		_g_free0 (description);
		description = _tmp14_;
		_tmp15_ = g_strdup (_ ("Middle-click to turn Bluetooth on"));
		_g_free0 (context);
		context = _tmp15_;
	}
	_tmp16_ = description;
	_tmp17_ = context;
	_tmp18_ = g_strdup_printf (GRANITE_TOOLTIP_SECONDARY_TEXT_MARKUP, _tmp17_);
	_tmp19_ = _tmp18_;
	_tmp20_ = g_strdup_printf ("%s\n%s", _tmp16_, _tmp19_);
	_tmp21_ = _tmp20_;
	gtk_widget_set_tooltip_markup ((GtkWidget*) self, _tmp21_);
	_g_free0 (_tmp21_);
	_g_free0 (_tmp19_);
	_g_free0 (context);
	_g_free0 (description);
}

BluetoothIndicatorServicesObjectManager*
bluetooth_indicator_widgets_display_widget_get_object_manager (BluetoothIndicatorWidgetsDisplayWidget* self)
{
	BluetoothIndicatorServicesObjectManager* result;
	BluetoothIndicatorServicesObjectManager* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_object_manager;
	result = _tmp0_;
	return result;
}

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

static void
bluetooth_indicator_widgets_display_widget_set_object_manager (BluetoothIndicatorWidgetsDisplayWidget* self,
                                                               BluetoothIndicatorServicesObjectManager* value)
{
	BluetoothIndicatorServicesObjectManager* old_value;
	g_return_if_fail (self != NULL);
	old_value = bluetooth_indicator_widgets_display_widget_get_object_manager (self);
	if (old_value != value) {
		BluetoothIndicatorServicesObjectManager* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_object_manager);
		self->priv->_object_manager = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, bluetooth_indicator_widgets_display_widget_properties[BLUETOOTH_INDICATOR_WIDGETS_DISPLAY_WIDGET_OBJECT_MANAGER_PROPERTY]);
	}
}

static void
_bluetooth_indicator_widgets_display_widget___lambda31_ (BluetoothIndicatorWidgetsDisplayWidget* self,
                                                         gboolean state,
                                                         gboolean connected)
{
	bluetooth_indicator_widgets_display_widget_set_icon (self);
}

static void
__bluetooth_indicator_widgets_display_widget___lambda31__bluetooth_indicator_services_object_manager_global_state_changed (BluetoothIndicatorServicesObjectManager* _sender,
                                                                                                                           gboolean enabled,
                                                                                                                           gboolean connected,
                                                                                                                           gpointer self)
{
	_bluetooth_indicator_widgets_display_widget___lambda31_ ((BluetoothIndicatorWidgetsDisplayWidget*) self, enabled, connected);
}

static void
_bluetooth_indicator_widgets_display_widget_set_icon_g_object_notify (GObject* _sender,
                                                                      GParamSpec* pspec,
                                                                      gpointer self)
{
	bluetooth_indicator_widgets_display_widget_set_icon ((BluetoothIndicatorWidgetsDisplayWidget*) self);
}

static gboolean
_bluetooth_indicator_widgets_display_widget___lambda32_ (BluetoothIndicatorWidgetsDisplayWidget* self,
                                                         GdkEventButton* e)
{
	gboolean result;
	g_return_val_if_fail (e != NULL, FALSE);
	if (e->button == ((guint) GDK_BUTTON_MIDDLE)) {
		BluetoothIndicatorServicesObjectManager* _tmp0_;
		GSettings* _tmp1_;
		GSettings* _tmp2_;
		BluetoothIndicatorServicesObjectManager* _tmp3_;
		GSettings* _tmp4_;
		GSettings* _tmp5_;
		_tmp0_ = self->priv->_object_manager;
		_tmp1_ = bluetooth_indicator_services_object_manager_get_settings (_tmp0_);
		_tmp2_ = _tmp1_;
		_tmp3_ = self->priv->_object_manager;
		_tmp4_ = bluetooth_indicator_services_object_manager_get_settings (_tmp3_);
		_tmp5_ = _tmp4_;
		g_settings_set_boolean (_tmp2_, "bluetooth-enabled", !g_settings_get_boolean (_tmp5_, "bluetooth-enabled"));
		result = GDK_EVENT_STOP;
		return result;
	}
	result = GDK_EVENT_PROPAGATE;
	return result;
}

static gboolean
__bluetooth_indicator_widgets_display_widget___lambda32__gtk_widget_button_press_event (GtkWidget* _sender,
                                                                                        GdkEventButton* event,
                                                                                        gpointer self)
{
	gboolean result;
	result = _bluetooth_indicator_widgets_display_widget___lambda32_ ((BluetoothIndicatorWidgetsDisplayWidget*) self, event);
	return result;
}

static GObject *
bluetooth_indicator_widgets_display_widget_constructor (GType type,
                                                        guint n_construct_properties,
                                                        GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	BluetoothIndicatorWidgetsDisplayWidget * self;
	GtkIconTheme* _tmp0_;
	GtkCssProvider* provider = NULL;
	GtkCssProvider* _tmp1_;
	GtkCssProvider* _tmp2_;
	GtkStyleContext* _tmp3_;
	GtkStyleContext* _tmp4_;
	GtkCssProvider* _tmp5_;
	GtkStyleContext* _tmp6_;
	GtkStyleContext* _tmp7_;
	BluetoothIndicatorServicesObjectManager* _tmp8_;
	gboolean _tmp9_ = FALSE;
	BluetoothIndicatorServicesObjectManager* _tmp10_;
	gboolean _tmp11_;
	gboolean _tmp12_;
	parent_class = G_OBJECT_CLASS (bluetooth_indicator_widgets_display_widget_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BLUETOOTH_INDICATOR_WIDGETS_TYPE_DISPLAY_WIDGET, BluetoothIndicatorWidgetsDisplayWidget);
	_tmp0_ = gtk_icon_theme_get_default ();
	gtk_icon_theme_add_resource_path (_tmp0_, "/org/elementary/wingpanel/icons");
	_tmp1_ = gtk_css_provider_new ();
	provider = _tmp1_;
	_tmp2_ = provider;
	gtk_css_provider_load_from_resource (_tmp2_, "io/elementary/wingpanel/bluetooth/indicator.css");
	_tmp3_ = gtk_widget_get_style_context ((GtkWidget*) self);
	self->priv->style_context = _tmp3_;
	_tmp4_ = self->priv->style_context;
	_tmp5_ = provider;
	gtk_style_context_add_provider (_tmp4_, (GtkStyleProvider*) _tmp5_, (guint) GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
	_tmp6_ = self->priv->style_context;
	gtk_style_context_add_class (_tmp6_, "bluetooth-icon");
	_tmp7_ = self->priv->style_context;
	gtk_style_context_add_class (_tmp7_, "disabled");
	_tmp8_ = self->priv->_object_manager;
	g_signal_connect_object (_tmp8_, "global-state-changed", (GCallback) __bluetooth_indicator_widgets_display_widget___lambda31__bluetooth_indicator_services_object_manager_global_state_changed, self, 0);
	_tmp10_ = self->priv->_object_manager;
	_tmp11_ = bluetooth_indicator_services_object_manager_get_has_object (_tmp10_);
	_tmp12_ = _tmp11_;
	if (_tmp12_) {
		BluetoothIndicatorServicesObjectManager* _tmp13_;
		gboolean _tmp14_;
		gboolean _tmp15_;
		_tmp13_ = self->priv->_object_manager;
		_tmp14_ = bluetooth_indicator_services_object_manager_get_retrieve_finished (_tmp13_);
		_tmp15_ = _tmp14_;
		_tmp9_ = _tmp15_;
	} else {
		_tmp9_ = FALSE;
	}
	if (_tmp9_) {
		bluetooth_indicator_widgets_display_widget_set_icon (self);
	} else {
		BluetoothIndicatorServicesObjectManager* _tmp16_;
		_tmp16_ = self->priv->_object_manager;
		g_signal_connect_object ((GObject*) _tmp16_, "notify::retrieve-finished", (GCallback) _bluetooth_indicator_widgets_display_widget_set_icon_g_object_notify, self, 0);
	}
	g_signal_connect_object ((GtkWidget*) self, "button-press-event", (GCallback) __bluetooth_indicator_widgets_display_widget___lambda32__gtk_widget_button_press_event, self, 0);
	_g_object_unref0 (provider);
	return obj;
}

static void
bluetooth_indicator_widgets_display_widget_class_init (BluetoothIndicatorWidgetsDisplayWidgetClass * klass,
                                                       gpointer klass_data)
{
	bluetooth_indicator_widgets_display_widget_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BluetoothIndicatorWidgetsDisplayWidget_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_bluetooth_indicator_widgets_display_widget_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_bluetooth_indicator_widgets_display_widget_set_property;
	G_OBJECT_CLASS (klass)->constructor = bluetooth_indicator_widgets_display_widget_constructor;
	G_OBJECT_CLASS (klass)->finalize = bluetooth_indicator_widgets_display_widget_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), BLUETOOTH_INDICATOR_WIDGETS_DISPLAY_WIDGET_OBJECT_MANAGER_PROPERTY, bluetooth_indicator_widgets_display_widget_properties[BLUETOOTH_INDICATOR_WIDGETS_DISPLAY_WIDGET_OBJECT_MANAGER_PROPERTY] = g_param_spec_object ("object-manager", "object-manager", "object-manager", BLUETOOTH_INDICATOR_SERVICES_TYPE_OBJECT_MANAGER, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
}

static void
bluetooth_indicator_widgets_display_widget_instance_init (BluetoothIndicatorWidgetsDisplayWidget * self,
                                                          gpointer klass)
{
	self->priv = bluetooth_indicator_widgets_display_widget_get_instance_private (self);
}

static void
bluetooth_indicator_widgets_display_widget_finalize (GObject * obj)
{
	BluetoothIndicatorWidgetsDisplayWidget * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BLUETOOTH_INDICATOR_WIDGETS_TYPE_DISPLAY_WIDGET, BluetoothIndicatorWidgetsDisplayWidget);
	_g_object_unref0 (self->priv->_object_manager);
	G_OBJECT_CLASS (bluetooth_indicator_widgets_display_widget_parent_class)->finalize (obj);
}

static GType
bluetooth_indicator_widgets_display_widget_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BluetoothIndicatorWidgetsDisplayWidgetClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bluetooth_indicator_widgets_display_widget_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BluetoothIndicatorWidgetsDisplayWidget), 0, (GInstanceInitFunc) bluetooth_indicator_widgets_display_widget_instance_init, NULL };
	GType bluetooth_indicator_widgets_display_widget_type_id;
	bluetooth_indicator_widgets_display_widget_type_id = g_type_register_static (gtk_spinner_get_type (), "BluetoothIndicatorWidgetsDisplayWidget", &g_define_type_info, 0);
	BluetoothIndicatorWidgetsDisplayWidget_private_offset = g_type_add_instance_private (bluetooth_indicator_widgets_display_widget_type_id, sizeof (BluetoothIndicatorWidgetsDisplayWidgetPrivate));
	return bluetooth_indicator_widgets_display_widget_type_id;
}

GType
bluetooth_indicator_widgets_display_widget_get_type (void)
{
	static volatile gsize bluetooth_indicator_widgets_display_widget_type_id__once = 0;
	if (g_once_init_enter (&bluetooth_indicator_widgets_display_widget_type_id__once)) {
		GType bluetooth_indicator_widgets_display_widget_type_id;
		bluetooth_indicator_widgets_display_widget_type_id = bluetooth_indicator_widgets_display_widget_get_type_once ();
		g_once_init_leave (&bluetooth_indicator_widgets_display_widget_type_id__once, bluetooth_indicator_widgets_display_widget_type_id);
	}
	return bluetooth_indicator_widgets_display_widget_type_id__once;
}

static void
_vala_bluetooth_indicator_widgets_display_widget_get_property (GObject * object,
                                                               guint property_id,
                                                               GValue * value,
                                                               GParamSpec * pspec)
{
	BluetoothIndicatorWidgetsDisplayWidget * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, BLUETOOTH_INDICATOR_WIDGETS_TYPE_DISPLAY_WIDGET, BluetoothIndicatorWidgetsDisplayWidget);
	switch (property_id) {
		case BLUETOOTH_INDICATOR_WIDGETS_DISPLAY_WIDGET_OBJECT_MANAGER_PROPERTY:
		g_value_set_object (value, bluetooth_indicator_widgets_display_widget_get_object_manager (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_bluetooth_indicator_widgets_display_widget_set_property (GObject * object,
                                                               guint property_id,
                                                               const GValue * value,
                                                               GParamSpec * pspec)
{
	BluetoothIndicatorWidgetsDisplayWidget * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, BLUETOOTH_INDICATOR_WIDGETS_TYPE_DISPLAY_WIDGET, BluetoothIndicatorWidgetsDisplayWidget);
	switch (property_id) {
		case BLUETOOTH_INDICATOR_WIDGETS_DISPLAY_WIDGET_OBJECT_MANAGER_PROPERTY:
		bluetooth_indicator_widgets_display_widget_set_object_manager (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

