/* IconColorProject.c generated by valac 0.56.19, the Vala compiler
 * generated from IconColorProject.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 <glib.h>
#include <gtk/gtk.h>
#include <gee.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <math.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_ICON_COLOR_PROJECT_0_PROPERTY,
	WIDGETS_ICON_COLOR_PROJECT_PROJECT_PROPERTY,
	WIDGETS_ICON_COLOR_PROJECT_PIXEL_SIZE_PROPERTY,
	WIDGETS_ICON_COLOR_PROJECT_NUM_PROPERTIES
};
static GParamSpec* widgets_icon_color_project_properties[WIDGETS_ICON_COLOR_PROJECT_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _WidgetsIconColorProjectPrivate {
	ObjectsProject* _project;
	gint _pixel_size;
	WidgetsCircularProgressBar* circular_progress_bar;
	GtkLabel* emoji_label;
	GtkStack* stack;
	GeeHashMap* signal_map;
};

static gint WidgetsIconColorProject_private_offset;
static gpointer widgets_icon_color_project_parent_class = NULL;

static GObject * widgets_icon_color_project_constructor (GType type,
                                                  guint n_construct_properties,
                                                  GObjectConstructParam * construct_properties);
static void _widgets_icon_color_project___lambda107_ (WidgetsIconColorProject* self);
static void __widgets_icon_color_project___lambda107__g_object_notify (GObject* _sender,
                                                                GParamSpec* pspec,
                                                                gpointer self);
static void widgets_icon_color_project_finalize (GObject * obj);
static GType widgets_icon_color_project_get_type_once (void);
static void _vala_widgets_icon_color_project_get_property (GObject * object,
                                                    guint property_id,
                                                    GValue * value,
                                                    GParamSpec * pspec);
static void _vala_widgets_icon_color_project_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_icon_color_project_get_instance_private (WidgetsIconColorProject* self)
{
	return G_STRUCT_MEMBER_P (self, WidgetsIconColorProject_private_offset);
}

WidgetsIconColorProject*
widgets_icon_color_project_construct (GType object_type,
                                      gint pixel_size)
{
	WidgetsIconColorProject * self = NULL;
	self = (WidgetsIconColorProject*) g_object_new (object_type, "pixel-size", pixel_size, NULL);
	return self;
}

WidgetsIconColorProject*
widgets_icon_color_project_new (gint pixel_size)
{
	return widgets_icon_color_project_construct (WIDGETS_TYPE_ICON_COLOR_PROJECT, pixel_size);
}

void
widgets_icon_color_project_update_request (WidgetsIconColorProject* self)
{
	WidgetsCircularProgressBar* _tmp0_;
	ObjectsProject* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	WidgetsCircularProgressBar* _tmp4_;
	ObjectsProject* _tmp5_;
	gdouble _tmp6_;
	gdouble _tmp7_;
	GtkLabel* _tmp8_;
	ObjectsProject* _tmp9_;
	const gchar* _tmp10_;
	const gchar* _tmp11_;
	ObjectsProject* _tmp12_;
	gboolean _tmp13_;
	gboolean _tmp14_;
	const gchar* _tmp16_ = NULL;
	ObjectsProject* _tmp17_;
	ProjectIconStyle _tmp18_;
	ProjectIconStyle _tmp19_;
	GtkStack* _tmp20_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->circular_progress_bar;
	_tmp1_ = self->priv->_project;
	_tmp2_ = objects_base_object_get_color ((ObjectsBaseObject*) _tmp1_);
	_tmp3_ = _tmp2_;
	widgets_circular_progress_bar_set_color (_tmp0_, _tmp3_);
	_tmp4_ = self->priv->circular_progress_bar;
	_tmp5_ = self->priv->_project;
	_tmp6_ = objects_base_object_get_percentage ((ObjectsBaseObject*) _tmp5_);
	_tmp7_ = _tmp6_;
	widgets_circular_progress_bar_set_percentage (_tmp4_, _tmp7_);
	_tmp8_ = self->priv->emoji_label;
	_tmp9_ = self->priv->_project;
	_tmp10_ = objects_project_get_emoji (_tmp9_);
	_tmp11_ = _tmp10_;
	gtk_label_set_label (_tmp8_, _tmp11_);
	_tmp12_ = self->priv->_project;
	_tmp13_ = objects_project_get_is_inbox_project (_tmp12_);
	_tmp14_ = _tmp13_;
	if (_tmp14_) {
		GtkStack* _tmp15_;
		_tmp15_ = self->priv->stack;
		gtk_stack_set_visible_child_name (_tmp15_, "inbox");
		return;
	}
	_tmp17_ = self->priv->_project;
	_tmp18_ = objects_project_get_icon_style (_tmp17_);
	_tmp19_ = _tmp18_;
	if (_tmp19_ == PROJECT_ICON_STYLE_PROGRESS) {
		_tmp16_ = "color";
	} else {
		_tmp16_ = "emoji";
	}
	_tmp20_ = self->priv->stack;
	gtk_stack_set_visible_child_name (_tmp20_, _tmp16_);
}

void
widgets_icon_color_project_clean_up (WidgetsIconColorProject* self)
{
	GeeHashMap* _tmp15_;
	g_return_if_fail (self != NULL);
	{
		GeeIterator* _entry_it = NULL;
		GeeHashMap* _tmp0_;
		GeeSet* _tmp1_;
		GeeSet* _tmp2_;
		GeeSet* _tmp3_;
		GeeIterator* _tmp4_;
		GeeIterator* _tmp5_;
		_tmp0_ = self->priv->signal_map;
		_tmp1_ = gee_abstract_map_get_entries ((GeeAbstractMap*) _tmp0_);
		_tmp2_ = _tmp1_;
		_tmp3_ = _tmp2_;
		_tmp4_ = gee_iterable_iterator ((GeeIterable*) _tmp3_);
		_tmp5_ = _tmp4_;
		_g_object_unref0 (_tmp3_);
		_entry_it = _tmp5_;
		while (TRUE) {
			GeeIterator* _tmp6_;
			GeeMapEntry* entry = NULL;
			GeeIterator* _tmp7_;
			gpointer _tmp8_;
			GeeMapEntry* _tmp9_;
			gconstpointer _tmp10_;
			gconstpointer _tmp11_;
			GeeMapEntry* _tmp12_;
			gconstpointer _tmp13_;
			gconstpointer _tmp14_;
			_tmp6_ = _entry_it;
			if (!gee_iterator_next (_tmp6_)) {
				break;
			}
			_tmp7_ = _entry_it;
			_tmp8_ = gee_iterator_get (_tmp7_);
			entry = (GeeMapEntry*) _tmp8_;
			_tmp9_ = entry;
			_tmp10_ = gee_map_entry_get_value (_tmp9_);
			_tmp11_ = _tmp10_;
			_tmp12_ = entry;
			_tmp13_ = gee_map_entry_get_key (_tmp12_);
			_tmp14_ = _tmp13_;
			g_signal_handler_disconnect ((GObject*) _tmp11_, (gulong) ((guintptr) _tmp14_));
			_g_object_unref0 (entry);
		}
		_g_object_unref0 (_entry_it);
	}
	_tmp15_ = self->priv->signal_map;
	gee_abstract_map_clear ((GeeAbstractMap*) _tmp15_);
}

ObjectsProject*
widgets_icon_color_project_get_project (WidgetsIconColorProject* self)
{
	ObjectsProject* result;
	ObjectsProject* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_project;
	result = _tmp0_;
	return result;
}

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

void
widgets_icon_color_project_set_project (WidgetsIconColorProject* self,
                                        ObjectsProject* value)
{
	ObjectsProject* old_value;
	g_return_if_fail (self != NULL);
	old_value = widgets_icon_color_project_get_project (self);
	if (old_value != value) {
		ObjectsProject* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_project);
		self->priv->_project = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, widgets_icon_color_project_properties[WIDGETS_ICON_COLOR_PROJECT_PROJECT_PROPERTY]);
	}
}

gint
widgets_icon_color_project_get_pixel_size (WidgetsIconColorProject* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	result = self->priv->_pixel_size;
	return result;
}

static void
widgets_icon_color_project_set_pixel_size (WidgetsIconColorProject* self,
                                           gint value)
{
	gint old_value;
	g_return_if_fail (self != NULL);
	old_value = widgets_icon_color_project_get_pixel_size (self);
	if (old_value != value) {
		self->priv->_pixel_size = value;
		g_object_notify_by_pspec ((GObject *) self, widgets_icon_color_project_properties[WIDGETS_ICON_COLOR_PROJECT_PIXEL_SIZE_PROPERTY]);
	}
}

static void
_widgets_icon_color_project___lambda107_ (WidgetsIconColorProject* self)
{
	widgets_icon_color_project_update_request (self);
}

static void
__widgets_icon_color_project___lambda107__g_object_notify (GObject* _sender,
                                                           GParamSpec* pspec,
                                                           gpointer self)
{
	_widgets_icon_color_project___lambda107_ ((WidgetsIconColorProject*) self);
}

static GObject *
widgets_icon_color_project_constructor (GType type,
                                        guint n_construct_properties,
                                        GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	WidgetsIconColorProject * self;
	gint _tmp0_;
	WidgetsCircularProgressBar* _tmp1_;
	GtkLabel* _tmp2_ = NULL;
	GtkImage* _tmp3_ = NULL;
	GtkStack* _tmp4_ = NULL;
	GtkStack* _tmp5_;
	WidgetsCircularProgressBar* _tmp6_;
	GtkStack* _tmp7_;
	GtkLabel* _tmp8_;
	GtkStack* _tmp9_;
	GtkImage* _tmp10_;
	GtkStack* _tmp11_;
	GeeHashMap* _tmp12_;
	gulong _tmp13_;
	parent_class = G_OBJECT_CLASS (widgets_icon_color_project_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_TYPE_ICON_COLOR_PROJECT, WidgetsIconColorProject);
	_tmp0_ = self->priv->_pixel_size;
	_tmp1_ = widgets_circular_progress_bar_new (_tmp0_);
	g_object_ref_sink (_tmp1_);
	_g_object_unref0 (self->priv->circular_progress_bar);
	self->priv->circular_progress_bar = _tmp1_;
	_tmp2_ = (GtkLabel*) gtk_label_new (NULL);
	gtk_widget_set_halign ((GtkWidget*) _tmp2_, GTK_ALIGN_CENTER);
	g_object_ref_sink (_tmp2_);
	_g_object_unref0 (self->priv->emoji_label);
	self->priv->emoji_label = _tmp2_;
	_tmp3_ = (GtkImage*) gtk_image_new_from_icon_name ("mailbox-symbolic");
	gtk_image_set_pixel_size (_tmp3_, 16);
	gtk_widget_set_valign ((GtkWidget*) _tmp3_, GTK_ALIGN_CENTER);
	gtk_widget_set_halign ((GtkWidget*) _tmp3_, GTK_ALIGN_CENTER);
	g_object_ref_sink (_tmp3_);
	_g_object_unref0 (self->inbox_icon);
	self->inbox_icon = _tmp3_;
	_tmp4_ = (GtkStack*) gtk_stack_new ();
	gtk_stack_set_transition_type (_tmp4_, GTK_STACK_TRANSITION_TYPE_CROSSFADE);
	g_object_ref_sink (_tmp4_);
	_g_object_unref0 (self->priv->stack);
	self->priv->stack = _tmp4_;
	_tmp5_ = self->priv->stack;
	_tmp6_ = self->priv->circular_progress_bar;
	gtk_stack_add_named (_tmp5_, (GtkWidget*) _tmp6_, "color");
	_tmp7_ = self->priv->stack;
	_tmp8_ = self->priv->emoji_label;
	gtk_stack_add_named (_tmp7_, (GtkWidget*) _tmp8_, "emoji");
	_tmp9_ = self->priv->stack;
	_tmp10_ = self->inbox_icon;
	gtk_stack_add_named (_tmp9_, (GtkWidget*) _tmp10_, "inbox");
	_tmp11_ = self->priv->stack;
	adw_bin_set_child ((AdwBin*) self, (GtkWidget*) _tmp11_);
	_tmp12_ = self->priv->signal_map;
	_tmp13_ = g_signal_connect_object ((GObject*) self, "notify::project", (GCallback) __widgets_icon_color_project___lambda107__g_object_notify, self, 0);
	gee_abstract_map_set ((GeeAbstractMap*) _tmp12_, (gpointer) ((guintptr) _tmp13_), (GObject*) self);
	return obj;
}

static void
widgets_icon_color_project_class_init (WidgetsIconColorProjectClass * klass,
                                       gpointer klass_data)
{
	widgets_icon_color_project_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &WidgetsIconColorProject_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_widgets_icon_color_project_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_widgets_icon_color_project_set_property;
	G_OBJECT_CLASS (klass)->constructor = widgets_icon_color_project_constructor;
	G_OBJECT_CLASS (klass)->finalize = widgets_icon_color_project_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), WIDGETS_ICON_COLOR_PROJECT_PROJECT_PROPERTY, widgets_icon_color_project_properties[WIDGETS_ICON_COLOR_PROJECT_PROJECT_PROPERTY] = g_param_spec_object ("project", "project", "project", OBJECTS_TYPE_PROJECT, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), WIDGETS_ICON_COLOR_PROJECT_PIXEL_SIZE_PROPERTY, widgets_icon_color_project_properties[WIDGETS_ICON_COLOR_PROJECT_PIXEL_SIZE_PROPERTY] = g_param_spec_int ("pixel-size", "pixel-size", "pixel-size", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
}

static void
widgets_icon_color_project_instance_init (WidgetsIconColorProject * self,
                                          gpointer klass)
{
	GeeHashMap* _tmp0_;
	self->priv = widgets_icon_color_project_get_instance_private (self);
	_tmp0_ = gee_hash_map_new (G_TYPE_ULONG, NULL, NULL, G_TYPE_OBJECT, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->signal_map = _tmp0_;
}

static void
widgets_icon_color_project_finalize (GObject * obj)
{
	WidgetsIconColorProject * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_TYPE_ICON_COLOR_PROJECT, WidgetsIconColorProject);
	g_debug ("IconColorProject.vala:40: Destroying - Widgets.IconColorProject\n");
	_g_object_unref0 (self->priv->_project);
	_g_object_unref0 (self->priv->circular_progress_bar);
	_g_object_unref0 (self->inbox_icon);
	_g_object_unref0 (self->priv->emoji_label);
	_g_object_unref0 (self->priv->stack);
	_g_object_unref0 (self->priv->signal_map);
	G_OBJECT_CLASS (widgets_icon_color_project_parent_class)->finalize (obj);
}

static GType
widgets_icon_color_project_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (WidgetsIconColorProjectClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) widgets_icon_color_project_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (WidgetsIconColorProject), 0, (GInstanceInitFunc) widgets_icon_color_project_instance_init, NULL };
	GType widgets_icon_color_project_type_id;
	widgets_icon_color_project_type_id = g_type_register_static (adw_bin_get_type (), "WidgetsIconColorProject", &g_define_type_info, 0);
	WidgetsIconColorProject_private_offset = g_type_add_instance_private (widgets_icon_color_project_type_id, sizeof (WidgetsIconColorProjectPrivate));
	return widgets_icon_color_project_type_id;
}

GType
widgets_icon_color_project_get_type (void)
{
	static volatile gsize widgets_icon_color_project_type_id__once = 0;
	if (g_once_init_enter (&widgets_icon_color_project_type_id__once)) {
		GType widgets_icon_color_project_type_id;
		widgets_icon_color_project_type_id = widgets_icon_color_project_get_type_once ();
		g_once_init_leave (&widgets_icon_color_project_type_id__once, widgets_icon_color_project_type_id);
	}
	return widgets_icon_color_project_type_id__once;
}

static void
_vala_widgets_icon_color_project_get_property (GObject * object,
                                               guint property_id,
                                               GValue * value,
                                               GParamSpec * pspec)
{
	WidgetsIconColorProject * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, WIDGETS_TYPE_ICON_COLOR_PROJECT, WidgetsIconColorProject);
	switch (property_id) {
		case WIDGETS_ICON_COLOR_PROJECT_PROJECT_PROPERTY:
		g_value_set_object (value, widgets_icon_color_project_get_project (self));
		break;
		case WIDGETS_ICON_COLOR_PROJECT_PIXEL_SIZE_PROPERTY:
		g_value_set_int (value, widgets_icon_color_project_get_pixel_size (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_widgets_icon_color_project_set_property (GObject * object,
                                               guint property_id,
                                               const GValue * value,
                                               GParamSpec * pspec)
{
	WidgetsIconColorProject * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, WIDGETS_TYPE_ICON_COLOR_PROJECT, WidgetsIconColorProject);
	switch (property_id) {
		case WIDGETS_ICON_COLOR_PROJECT_PROJECT_PROPERTY:
		widgets_icon_color_project_set_project (self, g_value_get_object (value));
		break;
		case WIDGETS_ICON_COLOR_PROJECT_PIXEL_SIZE_PROPERTY:
		widgets_icon_color_project_set_pixel_size (self, g_value_get_int (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;
}

