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

/*
 * Copyright © 2023 Alain M. (https://github.com/alainm23/planify)
 *
 * 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 3 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
 *
 * Authored by: Alain M. <alainmh23@gmail.com>
 */

#include "planify.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <glib-object.h>
#include <adwaita.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  {
	WIDGETS_LOADING_BUTTON_0_PROPERTY,
	WIDGETS_LOADING_BUTTON_TEXT_ICON_PROPERTY,
	WIDGETS_LOADING_BUTTON_LOADING_TYPE_PROPERTY,
	WIDGETS_LOADING_BUTTON_ICON_SIZE_PROPERTY,
	WIDGETS_LOADING_BUTTON_IS_LOADING_PROPERTY,
	WIDGETS_LOADING_BUTTON_NUM_PROPERTIES
};
static GParamSpec* widgets_loading_button_properties[WIDGETS_LOADING_BUTTON_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _WidgetsLoadingButtonPrivate {
	gchar* _text_icon;
	LoadingButtonType _loading_type;
	gint _icon_size;
	gboolean _is_loading;
	GtkStack* submit_stack;
	GtkImage* icon;
};

static gint WidgetsLoadingButton_private_offset;
static gpointer widgets_loading_button_parent_class = NULL;

static GObject * widgets_loading_button_constructor (GType type,
                                              guint n_construct_properties,
                                              GObjectConstructParam * construct_properties);
static void widgets_loading_button_finalize (GObject * obj);
static GType widgets_loading_button_get_type_once (void);
static void _vala_widgets_loading_button_get_property (GObject * object,
                                                guint property_id,
                                                GValue * value,
                                                GParamSpec * pspec);
static void _vala_widgets_loading_button_set_property (GObject * object,
                                                guint property_id,
                                                const GValue * value,
                                                GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
widgets_loading_button_get_instance_private (WidgetsLoadingButton* self)
{
	return G_STRUCT_MEMBER_P (self, WidgetsLoadingButton_private_offset);
}

WidgetsLoadingButton*
widgets_loading_button_construct (GType object_type,
                                  LoadingButtonType loading_type,
                                  const gchar* text_icon)
{
	WidgetsLoadingButton * self = NULL;
	g_return_val_if_fail (text_icon != NULL, NULL);
	self = (WidgetsLoadingButton*) g_object_new (object_type, "loading-type", loading_type, "text-icon", text_icon, NULL);
	return self;
}

WidgetsLoadingButton*
widgets_loading_button_new (LoadingButtonType loading_type,
                            const gchar* text_icon)
{
	return widgets_loading_button_construct (WIDGETS_TYPE_LOADING_BUTTON, loading_type, text_icon);
}

WidgetsLoadingButton*
widgets_loading_button_construct_with_label (GType object_type,
                                             const gchar* label)
{
	WidgetsLoadingButton * self = NULL;
	g_return_val_if_fail (label != NULL, NULL);
	self = (WidgetsLoadingButton*) g_object_new (object_type, "loading-type", LOADING_BUTTON_TYPE_LABEL, "text-icon", label, "icon-size", 16, NULL);
	return self;
}

WidgetsLoadingButton*
widgets_loading_button_new_with_label (const gchar* label)
{
	return widgets_loading_button_construct_with_label (WIDGETS_TYPE_LOADING_BUTTON, label);
}

WidgetsLoadingButton*
widgets_loading_button_construct_with_icon (GType object_type,
                                            const gchar* icon_name,
                                            gint icon_size)
{
	WidgetsLoadingButton * self = NULL;
	g_return_val_if_fail (icon_name != NULL, NULL);
	self = (WidgetsLoadingButton*) g_object_new (object_type, "loading-type", LOADING_BUTTON_TYPE_ICON, "text-icon", icon_name, "icon-size", icon_size, NULL);
	return self;
}

WidgetsLoadingButton*
widgets_loading_button_new_with_icon (const gchar* icon_name,
                                      gint icon_size)
{
	return widgets_loading_button_construct_with_icon (WIDGETS_TYPE_LOADING_BUTTON, icon_name, icon_size);
}

void
widgets_loading_button_update_icon (WidgetsLoadingButton* self,
                                    const gchar* icon_name)
{
	GtkImage* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (icon_name != NULL);
	_tmp0_ = self->priv->icon;
	if (_tmp0_ != NULL) {
		GtkImage* _tmp1_;
		_tmp1_ = self->priv->icon;
		g_object_set (_tmp1_, "icon-name", icon_name, NULL);
	}
}

const gchar*
widgets_loading_button_get_text_icon (WidgetsLoadingButton* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_text_icon;
	result = _tmp0_;
	return result;
}

static void
widgets_loading_button_set_text_icon (WidgetsLoadingButton* self,
                                      const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = widgets_loading_button_get_text_icon (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_text_icon);
		self->priv->_text_icon = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, widgets_loading_button_properties[WIDGETS_LOADING_BUTTON_TEXT_ICON_PROPERTY]);
	}
}

LoadingButtonType
widgets_loading_button_get_loading_type (WidgetsLoadingButton* self)
{
	LoadingButtonType result;
	g_return_val_if_fail (self != NULL, 0);
	result = self->priv->_loading_type;
	return result;
}

static void
widgets_loading_button_set_loading_type (WidgetsLoadingButton* self,
                                         LoadingButtonType value)
{
	LoadingButtonType old_value;
	g_return_if_fail (self != NULL);
	old_value = widgets_loading_button_get_loading_type (self);
	if (old_value != value) {
		self->priv->_loading_type = value;
		g_object_notify_by_pspec ((GObject *) self, widgets_loading_button_properties[WIDGETS_LOADING_BUTTON_LOADING_TYPE_PROPERTY]);
	}
}

gint
widgets_loading_button_get_icon_size (WidgetsLoadingButton* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	result = self->priv->_icon_size;
	return result;
}

static void
widgets_loading_button_set_icon_size (WidgetsLoadingButton* self,
                                      gint value)
{
	gint old_value;
	g_return_if_fail (self != NULL);
	old_value = widgets_loading_button_get_icon_size (self);
	if (old_value != value) {
		self->priv->_icon_size = value;
		g_object_notify_by_pspec ((GObject *) self, widgets_loading_button_properties[WIDGETS_LOADING_BUTTON_ICON_SIZE_PROPERTY]);
	}
}

gboolean
widgets_loading_button_get_is_loading (WidgetsLoadingButton* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_is_loading;
	return result;
}

void
widgets_loading_button_set_is_loading (WidgetsLoadingButton* self,
                                       gboolean value)
{
	g_return_if_fail (self != NULL);
	if (value) {
		GtkStack* _tmp0_;
		_tmp0_ = self->priv->submit_stack;
		gtk_stack_set_visible_child_name (_tmp0_, "spinner");
	} else {
		GtkStack* _tmp1_;
		_tmp1_ = self->priv->submit_stack;
		gtk_stack_set_visible_child_name (_tmp1_, "button");
	}
	self->priv->_is_loading = value;
	g_object_notify_by_pspec ((GObject *) self, widgets_loading_button_properties[WIDGETS_LOADING_BUTTON_IS_LOADING_PROPERTY]);
}

static GObject *
widgets_loading_button_constructor (GType type,
                                    guint n_construct_properties,
                                    GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	WidgetsLoadingButton * self;
	AdwSpinner* submit_spinner = NULL;
	AdwSpinner* _tmp0_ = NULL;
	GtkStack* _tmp1_ = NULL;
	LoadingButtonType _tmp2_;
	GtkStack* _tmp14_;
	AdwSpinner* _tmp15_;
	GtkStack* _tmp16_;
	parent_class = G_OBJECT_CLASS (widgets_loading_button_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_TYPE_LOADING_BUTTON, WidgetsLoadingButton);
	_tmp0_ = (AdwSpinner*) adw_spinner_new ();
	gtk_widget_set_valign ((GtkWidget*) _tmp0_, GTK_ALIGN_CENTER);
	gtk_widget_set_halign ((GtkWidget*) _tmp0_, GTK_ALIGN_CENTER);
	g_object_ref_sink (_tmp0_);
	submit_spinner = _tmp0_;
	_tmp1_ = (GtkStack*) gtk_stack_new ();
	gtk_stack_set_transition_type (_tmp1_, GTK_STACK_TRANSITION_TYPE_CROSSFADE);
	gtk_widget_set_valign ((GtkWidget*) _tmp1_, GTK_ALIGN_CENTER);
	g_object_ref_sink (_tmp1_);
	_g_object_unref0 (self->priv->submit_stack);
	self->priv->submit_stack = _tmp1_;
	_tmp2_ = self->priv->_loading_type;
	if (_tmp2_ == LOADING_BUTTON_TYPE_LABEL) {
		GtkStack* _tmp3_;
		const gchar* _tmp4_;
		GtkLabel* _tmp5_;
		GtkLabel* _tmp6_;
		_tmp3_ = self->priv->submit_stack;
		_tmp4_ = self->priv->_text_icon;
		_tmp5_ = (GtkLabel*) gtk_label_new (_tmp4_);
		g_object_ref_sink (_tmp5_);
		_tmp6_ = _tmp5_;
		gtk_stack_add_named (_tmp3_, (GtkWidget*) _tmp6_, "button");
		_g_object_unref0 (_tmp6_);
	} else {
		GtkImage* _tmp7_;
		GtkImage* _tmp8_;
		gint _tmp9_;
		GtkImage* _tmp10_;
		const gchar* _tmp11_;
		GtkStack* _tmp12_;
		GtkImage* _tmp13_;
		_tmp7_ = (GtkImage*) gtk_image_new ();
		g_object_ref_sink (_tmp7_);
		_g_object_unref0 (self->priv->icon);
		self->priv->icon = _tmp7_;
		_tmp8_ = self->priv->icon;
		_tmp9_ = self->priv->_icon_size;
		gtk_image_set_pixel_size (_tmp8_, _tmp9_);
		_tmp10_ = self->priv->icon;
		_tmp11_ = self->priv->_text_icon;
		g_object_set (_tmp10_, "icon-name", _tmp11_, NULL);
		_tmp12_ = self->priv->submit_stack;
		_tmp13_ = self->priv->icon;
		gtk_stack_add_named (_tmp12_, (GtkWidget*) _tmp13_, "button");
	}
	_tmp14_ = self->priv->submit_stack;
	_tmp15_ = submit_spinner;
	gtk_stack_add_named (_tmp14_, (GtkWidget*) _tmp15_, "spinner");
	_tmp16_ = self->priv->submit_stack;
	gtk_button_set_child ((GtkButton*) self, (GtkWidget*) _tmp16_);
	_g_object_unref0 (submit_spinner);
	return obj;
}

static void
widgets_loading_button_class_init (WidgetsLoadingButtonClass * klass,
                                   gpointer klass_data)
{
	widgets_loading_button_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &WidgetsLoadingButton_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_widgets_loading_button_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_widgets_loading_button_set_property;
	G_OBJECT_CLASS (klass)->constructor = widgets_loading_button_constructor;
	G_OBJECT_CLASS (klass)->finalize = widgets_loading_button_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), WIDGETS_LOADING_BUTTON_TEXT_ICON_PROPERTY, widgets_loading_button_properties[WIDGETS_LOADING_BUTTON_TEXT_ICON_PROPERTY] = g_param_spec_string ("text-icon", "text-icon", "text-icon", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), WIDGETS_LOADING_BUTTON_LOADING_TYPE_PROPERTY, widgets_loading_button_properties[WIDGETS_LOADING_BUTTON_LOADING_TYPE_PROPERTY] = g_param_spec_enum ("loading-type", "loading-type", "loading-type", TYPE_LOADING_BUTTON_TYPE, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), WIDGETS_LOADING_BUTTON_ICON_SIZE_PROPERTY, widgets_loading_button_properties[WIDGETS_LOADING_BUTTON_ICON_SIZE_PROPERTY] = g_param_spec_int ("icon-size", "icon-size", "icon-size", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), WIDGETS_LOADING_BUTTON_IS_LOADING_PROPERTY, widgets_loading_button_properties[WIDGETS_LOADING_BUTTON_IS_LOADING_PROPERTY] = g_param_spec_boolean ("is-loading", "Show loading", "Show loading", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
widgets_loading_button_instance_init (WidgetsLoadingButton * self,
                                      gpointer klass)
{
	self->priv = widgets_loading_button_get_instance_private (self);
}

static void
widgets_loading_button_finalize (GObject * obj)
{
	WidgetsLoadingButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_TYPE_LOADING_BUTTON, WidgetsLoadingButton);
	g_debug ("LoadingButton.vala:72: Destroying - Widgets.LoadingButton\n");
	_g_free0 (self->priv->_text_icon);
	_g_object_unref0 (self->priv->submit_stack);
	_g_object_unref0 (self->priv->icon);
	G_OBJECT_CLASS (widgets_loading_button_parent_class)->finalize (obj);
}

static GType
widgets_loading_button_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (WidgetsLoadingButtonClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) widgets_loading_button_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (WidgetsLoadingButton), 0, (GInstanceInitFunc) widgets_loading_button_instance_init, NULL };
	GType widgets_loading_button_type_id;
	widgets_loading_button_type_id = g_type_register_static (gtk_button_get_type (), "WidgetsLoadingButton", &g_define_type_info, 0);
	WidgetsLoadingButton_private_offset = g_type_add_instance_private (widgets_loading_button_type_id, sizeof (WidgetsLoadingButtonPrivate));
	return widgets_loading_button_type_id;
}

GType
widgets_loading_button_get_type (void)
{
	static volatile gsize widgets_loading_button_type_id__once = 0;
	if (g_once_init_enter (&widgets_loading_button_type_id__once)) {
		GType widgets_loading_button_type_id;
		widgets_loading_button_type_id = widgets_loading_button_get_type_once ();
		g_once_init_leave (&widgets_loading_button_type_id__once, widgets_loading_button_type_id);
	}
	return widgets_loading_button_type_id__once;
}

static void
_vala_widgets_loading_button_get_property (GObject * object,
                                           guint property_id,
                                           GValue * value,
                                           GParamSpec * pspec)
{
	WidgetsLoadingButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, WIDGETS_TYPE_LOADING_BUTTON, WidgetsLoadingButton);
	switch (property_id) {
		case WIDGETS_LOADING_BUTTON_TEXT_ICON_PROPERTY:
		g_value_set_string (value, widgets_loading_button_get_text_icon (self));
		break;
		case WIDGETS_LOADING_BUTTON_LOADING_TYPE_PROPERTY:
		g_value_set_enum (value, widgets_loading_button_get_loading_type (self));
		break;
		case WIDGETS_LOADING_BUTTON_ICON_SIZE_PROPERTY:
		g_value_set_int (value, widgets_loading_button_get_icon_size (self));
		break;
		case WIDGETS_LOADING_BUTTON_IS_LOADING_PROPERTY:
		g_value_set_boolean (value, widgets_loading_button_get_is_loading (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_widgets_loading_button_set_property (GObject * object,
                                           guint property_id,
                                           const GValue * value,
                                           GParamSpec * pspec)
{
	WidgetsLoadingButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, WIDGETS_TYPE_LOADING_BUTTON, WidgetsLoadingButton);
	switch (property_id) {
		case WIDGETS_LOADING_BUTTON_TEXT_ICON_PROPERTY:
		widgets_loading_button_set_text_icon (self, g_value_get_string (value));
		break;
		case WIDGETS_LOADING_BUTTON_LOADING_TYPE_PROPERTY:
		widgets_loading_button_set_loading_type (self, g_value_get_enum (value));
		break;
		case WIDGETS_LOADING_BUTTON_ICON_SIZE_PROPERTY:
		widgets_loading_button_set_icon_size (self, g_value_get_int (value));
		break;
		case WIDGETS_LOADING_BUTTON_IS_LOADING_PROPERTY:
		widgets_loading_button_set_is_loading (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

