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

/*
 * Copyright 2011-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 General Public
 * License as published by the Free Software Foundation; either
 * version 2 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
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include "power.h"
#include <gtk/gtk.h>
#include <glib.h>
#include <glib-object.h>
#include <glib/gi18n-lib.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <gdk/gdk.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  {
	POWER_WIDGETS_DISPLAY_WIDGET_0_PROPERTY,
	POWER_WIDGETS_DISPLAY_WIDGET_ICON_NAME_PROPERTY,
	POWER_WIDGETS_DISPLAY_WIDGET_ALLOW_PERCENT_PROPERTY,
	POWER_WIDGETS_DISPLAY_WIDGET_PERCENTAGE_PROPERTY,
	POWER_WIDGETS_DISPLAY_WIDGET_NUM_PROPERTIES
};
static GParamSpec* power_widgets_display_widget_properties[POWER_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))
typedef struct _Block2Data Block2Data;

struct _PowerWidgetsDisplayWidgetPrivate {
	GtkRevealer* percent_revealer;
	gboolean _allow_percent;
	GtkLabel* percent_label;
	GtkImage* image;
};

struct _Block2Data {
	int _ref_count_;
	PowerWidgetsDisplayWidget* self;
	GSettings* settings;
};

static gint PowerWidgetsDisplayWidget_private_offset;
static gpointer power_widgets_display_widget_parent_class = NULL;

static GObject * power_widgets_display_widget_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 gboolean _power_widgets_display_widget___lambda4_ (Block2Data* _data2_,
                                                   GdkEventButton* e);
static gboolean __power_widgets_display_widget___lambda4__gtk_widget_button_press_event (GtkWidget* _sender,
                                                                                  GdkEventButton* event,
                                                                                  gpointer self);
static void power_widgets_display_widget_finalize (GObject * obj);
static GType power_widgets_display_widget_get_type_once (void);
static void _vala_power_widgets_display_widget_get_property (GObject * object,
                                                      guint property_id,
                                                      GValue * value,
                                                      GParamSpec * pspec);
static void _vala_power_widgets_display_widget_set_property (GObject * object,
                                                      guint property_id,
                                                      const GValue * value,
                                                      GParamSpec * pspec);

static inline gpointer
power_widgets_display_widget_get_instance_private (PowerWidgetsDisplayWidget* self)
{
	return G_STRUCT_MEMBER_P (self, PowerWidgetsDisplayWidget_private_offset);
}

void
power_widgets_display_widget_show_percentage (PowerWidgetsDisplayWidget* self,
                                              gboolean show)
{
	GtkRevealer* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->percent_revealer;
	gtk_revealer_set_reveal_child (_tmp0_, show);
}

PowerWidgetsDisplayWidget*
power_widgets_display_widget_construct (GType object_type)
{
	PowerWidgetsDisplayWidget * self = NULL;
	self = (PowerWidgetsDisplayWidget*) g_object_new (object_type, NULL);
	return self;
}

PowerWidgetsDisplayWidget*
power_widgets_display_widget_new (void)
{
	return power_widgets_display_widget_construct (POWER_WIDGETS_TYPE_DISPLAY_WIDGET);
}

void
power_widgets_display_widget_set_icon_name (PowerWidgetsDisplayWidget* self,
                                            const gchar* value)
{
	GtkImage* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->image;
	g_object_set (_tmp0_, "icon-name", value, NULL);
	g_object_notify_by_pspec ((GObject *) self, power_widgets_display_widget_properties[POWER_WIDGETS_DISPLAY_WIDGET_ICON_NAME_PROPERTY]);
}

gboolean
power_widgets_display_widget_get_allow_percent (PowerWidgetsDisplayWidget* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_allow_percent;
	return result;
}

void
power_widgets_display_widget_set_allow_percent (PowerWidgetsDisplayWidget* self,
                                                gboolean value)
{
	gboolean old_value;
	g_return_if_fail (self != NULL);
	old_value = power_widgets_display_widget_get_allow_percent (self);
	if (old_value != value) {
		self->priv->_allow_percent = value;
		g_object_notify_by_pspec ((GObject *) self, power_widgets_display_widget_properties[POWER_WIDGETS_DISPLAY_WIDGET_ALLOW_PERCENT_PROPERTY]);
	}
}

void
power_widgets_display_widget_set_percentage (PowerWidgetsDisplayWidget* self,
                                             gint value)
{
	GtkLabel* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->percent_label;
	_tmp1_ = g_strdup_printf (_ ("%i%%"), value);
	_tmp2_ = _tmp1_;
	gtk_label_set_label (_tmp0_, _tmp2_);
	_g_free0 (_tmp2_);
	g_object_notify_by_pspec ((GObject *) self, power_widgets_display_widget_properties[POWER_WIDGETS_DISPLAY_WIDGET_PERCENTAGE_PROPERTY]);
}

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

static gboolean
_power_widgets_display_widget___lambda4_ (Block2Data* _data2_,
                                          GdkEventButton* e)
{
	PowerWidgetsDisplayWidget* self;
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_;
	gboolean result;
	self = _data2_->self;
	g_return_val_if_fail (e != NULL, FALSE);
	_tmp1_ = self->priv->_allow_percent;
	if (_tmp1_) {
		_tmp0_ = e->button == ((guint) GDK_BUTTON_MIDDLE);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		GSettings* _tmp2_;
		GSettings* _tmp3_;
		_tmp2_ = _data2_->settings;
		_tmp3_ = _data2_->settings;
		g_settings_set_boolean (_tmp2_, "show-percentage", !g_settings_get_boolean (_tmp3_, "show-percentage"));
		result = TRUE;
		return result;
	}
	result = FALSE;
	return result;
}

static gboolean
__power_widgets_display_widget___lambda4__gtk_widget_button_press_event (GtkWidget* _sender,
                                                                         GdkEventButton* event,
                                                                         gpointer self)
{
	gboolean result;
	result = _power_widgets_display_widget___lambda4_ (self, event);
	return result;
}

static GObject *
power_widgets_display_widget_constructor (GType type,
                                          guint n_construct_properties,
                                          GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	PowerWidgetsDisplayWidget * self;
	Block2Data* _data2_;
	gchar* _tmp0_;
	GtkImage* _tmp1_ = NULL;
	GtkLabel* _tmp2_;
	GtkRevealer* _tmp3_ = NULL;
	GtkRevealer* _tmp4_;
	GtkLabel* _tmp5_;
	GtkImage* _tmp6_;
	GtkRevealer* _tmp7_;
	GSettings* _tmp8_;
	GSettings* _tmp9_;
	GtkRevealer* _tmp10_;
	GtkRevealer* _tmp11_;
	parent_class = G_OBJECT_CLASS (power_widgets_display_widget_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, POWER_WIDGETS_TYPE_DISPLAY_WIDGET, PowerWidgetsDisplayWidget);
	_data2_ = g_slice_new0 (Block2Data);
	_data2_->_ref_count_ = 1;
	_data2_->self = g_object_ref (self);
	gtk_widget_set_valign ((GtkWidget*) self, GTK_ALIGN_CENTER);
	_tmp0_ = g_strdup ("content-loading-symbolic");
	_tmp1_ = (GtkImage*) gtk_image_new ();
	g_object_set (_tmp1_, "icon-name", _tmp0_, NULL);
	_g_free0 (_tmp0_);
	gtk_image_set_pixel_size (_tmp1_, 24);
	g_object_ref_sink (_tmp1_);
	_g_object_unref0 (self->priv->image);
	self->priv->image = _tmp1_;
	_tmp2_ = (GtkLabel*) gtk_label_new (NULL);
	g_object_ref_sink (_tmp2_);
	_g_object_unref0 (self->priv->percent_label);
	self->priv->percent_label = _tmp2_;
	_tmp3_ = (GtkRevealer*) gtk_revealer_new ();
	gtk_revealer_set_transition_type (_tmp3_, GTK_REVEALER_TRANSITION_TYPE_SLIDE_RIGHT);
	g_object_ref_sink (_tmp3_);
	_g_object_unref0 (self->priv->percent_revealer);
	self->priv->percent_revealer = _tmp3_;
	_tmp4_ = self->priv->percent_revealer;
	_tmp5_ = self->priv->percent_label;
	gtk_container_add ((GtkContainer*) _tmp4_, (GtkWidget*) _tmp5_);
	_tmp6_ = self->priv->image;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp6_);
	_tmp7_ = self->priv->percent_revealer;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp7_);
	_tmp8_ = g_settings_new ("io.elementary.desktop.wingpanel.power");
	_data2_->settings = _tmp8_;
	_tmp9_ = _data2_->settings;
	_tmp10_ = self->priv->percent_revealer;
	g_settings_bind (_tmp9_, "show-percentage", (GObject*) _tmp10_, "reveal-child", G_SETTINGS_BIND_GET);
	_tmp11_ = self->priv->percent_revealer;
	g_object_bind_property_with_closures ((GObject*) self, "allow-percent", (GObject*) _tmp11_, "visible", 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)));
	g_signal_connect_data ((GtkWidget*) self, "button-press-event", (GCallback) __power_widgets_display_widget___lambda4__gtk_widget_button_press_event, block2_data_ref (_data2_), (GClosureNotify) block2_data_unref, 0);
	block2_data_unref (_data2_);
	_data2_ = NULL;
	return obj;
}

static void
power_widgets_display_widget_class_init (PowerWidgetsDisplayWidgetClass * klass,
                                         gpointer klass_data)
{
	power_widgets_display_widget_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &PowerWidgetsDisplayWidget_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_power_widgets_display_widget_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_power_widgets_display_widget_set_property;
	G_OBJECT_CLASS (klass)->constructor = power_widgets_display_widget_constructor;
	G_OBJECT_CLASS (klass)->finalize = power_widgets_display_widget_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), POWER_WIDGETS_DISPLAY_WIDGET_ICON_NAME_PROPERTY, power_widgets_display_widget_properties[POWER_WIDGETS_DISPLAY_WIDGET_ICON_NAME_PROPERTY] = g_param_spec_string ("icon-name", "icon-name", "icon-name", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), POWER_WIDGETS_DISPLAY_WIDGET_ALLOW_PERCENT_PROPERTY, power_widgets_display_widget_properties[POWER_WIDGETS_DISPLAY_WIDGET_ALLOW_PERCENT_PROPERTY] = g_param_spec_boolean ("allow-percent", "allow-percent", "allow-percent", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), POWER_WIDGETS_DISPLAY_WIDGET_PERCENTAGE_PROPERTY, power_widgets_display_widget_properties[POWER_WIDGETS_DISPLAY_WIDGET_PERCENTAGE_PROPERTY] = g_param_spec_int ("percentage", "percentage", "percentage", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE));
}

static void
power_widgets_display_widget_instance_init (PowerWidgetsDisplayWidget * self,
                                            gpointer klass)
{
	self->priv = power_widgets_display_widget_get_instance_private (self);
	self->priv->_allow_percent = FALSE;
}

static void
power_widgets_display_widget_finalize (GObject * obj)
{
	PowerWidgetsDisplayWidget * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, POWER_WIDGETS_TYPE_DISPLAY_WIDGET, PowerWidgetsDisplayWidget);
	_g_object_unref0 (self->priv->percent_revealer);
	_g_object_unref0 (self->priv->percent_label);
	_g_object_unref0 (self->priv->image);
	G_OBJECT_CLASS (power_widgets_display_widget_parent_class)->finalize (obj);
}

static GType
power_widgets_display_widget_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (PowerWidgetsDisplayWidgetClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) power_widgets_display_widget_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PowerWidgetsDisplayWidget), 0, (GInstanceInitFunc) power_widgets_display_widget_instance_init, NULL };
	GType power_widgets_display_widget_type_id;
	power_widgets_display_widget_type_id = g_type_register_static (gtk_box_get_type (), "PowerWidgetsDisplayWidget", &g_define_type_info, 0);
	PowerWidgetsDisplayWidget_private_offset = g_type_add_instance_private (power_widgets_display_widget_type_id, sizeof (PowerWidgetsDisplayWidgetPrivate));
	return power_widgets_display_widget_type_id;
}

GType
power_widgets_display_widget_get_type (void)
{
	static volatile gsize power_widgets_display_widget_type_id__once = 0;
	if (g_once_init_enter (&power_widgets_display_widget_type_id__once)) {
		GType power_widgets_display_widget_type_id;
		power_widgets_display_widget_type_id = power_widgets_display_widget_get_type_once ();
		g_once_init_leave (&power_widgets_display_widget_type_id__once, power_widgets_display_widget_type_id);
	}
	return power_widgets_display_widget_type_id__once;
}

static void
_vala_power_widgets_display_widget_get_property (GObject * object,
                                                 guint property_id,
                                                 GValue * value,
                                                 GParamSpec * pspec)
{
	PowerWidgetsDisplayWidget * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, POWER_WIDGETS_TYPE_DISPLAY_WIDGET, PowerWidgetsDisplayWidget);
	switch (property_id) {
		case POWER_WIDGETS_DISPLAY_WIDGET_ALLOW_PERCENT_PROPERTY:
		g_value_set_boolean (value, power_widgets_display_widget_get_allow_percent (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_power_widgets_display_widget_set_property (GObject * object,
                                                 guint property_id,
                                                 const GValue * value,
                                                 GParamSpec * pspec)
{
	PowerWidgetsDisplayWidget * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, POWER_WIDGETS_TYPE_DISPLAY_WIDGET, PowerWidgetsDisplayWidget);
	switch (property_id) {
		case POWER_WIDGETS_DISPLAY_WIDGET_ICON_NAME_PROPERTY:
		power_widgets_display_widget_set_icon_name (self, g_value_get_string (value));
		break;
		case POWER_WIDGETS_DISPLAY_WIDGET_ALLOW_PERCENT_PROPERTY:
		power_widgets_display_widget_set_allow_percent (self, g_value_get_boolean (value));
		break;
		case POWER_WIDGETS_DISPLAY_WIDGET_PERCENTAGE_PROPERTY:
		power_widgets_display_widget_set_percentage (self, g_value_get_int (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

