/* Labels.c generated by valac 0.56.19, the Vala compiler
 * generated from Labels.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 <stdlib.h>
#include <string.h>
#include <gee.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <glib/gi18n-lib.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  {
	OBJECTS_FILTERS_LABELS_0_PROPERTY,
	OBJECTS_FILTERS_LABELS_NUM_PROPERTIES
};
static GParamSpec* objects_filters_labels_properties[OBJECTS_FILTERS_LABELS_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) ((var == NULL) ? NULL : (var = (g_free (var), NULL)))

static gpointer objects_filters_labels_parent_class = NULL;
static ObjectsFiltersLabels* objects_filters_labels__instance;
static ObjectsFiltersLabels* objects_filters_labels__instance = NULL;

static gint objects_filters_labels_real_update_count (ObjectsBaseObject* base);
static void objects_filters_labels_real_count_update (ObjectsBaseObject* base);
static gint* _int_dup (gint* self);
static gchar* objects_filters_labels_real_theme_color (ObjectsBaseObject* base);
static GObject * objects_filters_labels_constructor (GType type,
                                              guint n_construct_properties,
                                              GObjectConstructParam * construct_properties);
static void _objects_filters_labels___lambda401_ (ObjectsFiltersLabels* self);
static void __objects_filters_labels___lambda401__services_store_label_added (ServicesStore* _sender,
                                                                       ObjectsLabel* label,
                                                                       gpointer self);
static void _objects_filters_labels___lambda402_ (ObjectsFiltersLabels* self);
static void __objects_filters_labels___lambda402__services_store_label_deleted (ServicesStore* _sender,
                                                                         ObjectsLabel* label,
                                                                         gpointer self);
static void _objects_filters_labels___lambda403_ (ObjectsFiltersLabels* self);
static void __objects_filters_labels___lambda403__services_store_label_updated (ServicesStore* _sender,
                                                                         ObjectsLabel* label,
                                                                         gpointer self);
static void _objects_filters_labels___lambda404_ (ObjectsFiltersLabels* self);
static void __objects_filters_labels___lambda404__services_store_item_added (ServicesStore* _sender,
                                                                      ObjectsItem* item,
                                                                      gboolean insert,
                                                                      gpointer self);
static void _objects_filters_labels___lambda405_ (ObjectsFiltersLabels* self);
static void __objects_filters_labels___lambda405__services_store_item_deleted (ServicesStore* _sender,
                                                                        ObjectsItem* item,
                                                                        gpointer self);
static void _objects_filters_labels___lambda406_ (ObjectsFiltersLabels* self);
static void __objects_filters_labels___lambda406__services_store_item_archived (ServicesStore* _sender,
                                                                         ObjectsItem* item,
                                                                         gpointer self);
static void _objects_filters_labels___lambda407_ (ObjectsFiltersLabels* self,
                                           ObjectsItem* item);
static void __objects_filters_labels___lambda407__services_store_item_unarchived (ServicesStore* _sender,
                                                                           ObjectsItem* item,
                                                                           gpointer self);
static void _objects_filters_labels___lambda408_ (ObjectsFiltersLabels* self);
static void __objects_filters_labels___lambda408__services_store_item_updated (ServicesStore* _sender,
                                                                        ObjectsItem* item,
                                                                        const gchar* update_id,
                                                                        gpointer self);
static void objects_filters_labels_finalize (GObject * obj);
static GType objects_filters_labels_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

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

ObjectsFiltersLabels*
objects_filters_labels_get_default (void)
{
	ObjectsFiltersLabels* _tmp0_;
	ObjectsFiltersLabels* _tmp2_;
	ObjectsFiltersLabels* _tmp3_;
	ObjectsFiltersLabels* result;
	_tmp0_ = objects_filters_labels__instance;
	if (_tmp0_ == NULL) {
		ObjectsFiltersLabels* _tmp1_;
		_tmp1_ = objects_filters_labels_new ();
		_g_object_unref0 (objects_filters_labels__instance);
		objects_filters_labels__instance = _tmp1_;
	}
	_tmp2_ = objects_filters_labels__instance;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	result = _tmp3_;
	return result;
}

static gint
objects_filters_labels_real_update_count (ObjectsBaseObject* base)
{
	ObjectsFiltersLabels * self;
	ServicesStore* _tmp0_;
	GeeArrayList* _tmp1_;
	GeeArrayList* _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	gint result;
	self = (ObjectsFiltersLabels*) base;
	_tmp0_ = services_store_instance ();
	_tmp1_ = services_store_get_items_has_labels (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = _tmp4_;
	_g_object_unref0 (_tmp2_);
	result = _tmp5_;
	return result;
}

static gint*
_int_dup (gint* self)
{
	gint* dup;
	dup = g_new0 (gint, 1);
	memcpy (dup, self, sizeof (gint));
	return dup;
}

static gpointer
__int_dup0 (gpointer self)
{
	return self ? _int_dup (self) : NULL;
}

static void
objects_filters_labels_real_count_update (ObjectsBaseObject* base)
{
	ObjectsFiltersLabels * self;
	gint _tmp0_;
	gint* _tmp1_;
	self = (ObjectsFiltersLabels*) base;
	_tmp0_ = objects_base_object_update_count ((ObjectsBaseObject*) self);
	_tmp1_ = __int_dup0 (&_tmp0_);
	_g_free0 (((ObjectsBaseObject*) self)->_item_count);
	((ObjectsBaseObject*) self)->_item_count = _tmp1_;
	g_signal_emit_by_name ((ObjectsBaseObject*) self, "count-updated");
}

static gchar*
objects_filters_labels_real_theme_color (ObjectsBaseObject* base)
{
	ObjectsFiltersLabels * self;
	const gchar* _tmp0_ = NULL;
	ServicesSettings* _tmp1_;
	ServicesSettings* _tmp2_;
	GSettings* _tmp3_;
	gboolean _tmp4_;
	gchar* _tmp5_;
	gchar* result;
	self = (ObjectsFiltersLabels*) base;
	_tmp1_ = services_settings_get_default ();
	_tmp2_ = _tmp1_;
	_tmp3_ = _tmp2_->settings;
	_tmp4_ = g_settings_get_boolean (_tmp3_, "dark-mode");
	_g_object_unref0 (_tmp2_);
	if (_tmp4_) {
		_tmp0_ = "#cdab8f";
	} else {
		_tmp0_ = "#986a44";
	}
	_tmp5_ = g_strdup (_tmp0_);
	result = _tmp5_;
	return result;
}

ObjectsFiltersLabels*
objects_filters_labels_construct (GType object_type)
{
	ObjectsFiltersLabels * self = NULL;
	self = (ObjectsFiltersLabels*) objects_base_object_construct (object_type);
	return self;
}

ObjectsFiltersLabels*
objects_filters_labels_new (void)
{
	return objects_filters_labels_construct (OBJECTS_FILTERS_TYPE_LABELS);
}

static void
_objects_filters_labels___lambda401_ (ObjectsFiltersLabels* self)
{
	objects_base_object_count_update ((ObjectsBaseObject*) self);
}

static void
__objects_filters_labels___lambda401__services_store_label_added (ServicesStore* _sender,
                                                                  ObjectsLabel* label,
                                                                  gpointer self)
{
	_objects_filters_labels___lambda401_ ((ObjectsFiltersLabels*) self);
}

static void
_objects_filters_labels___lambda402_ (ObjectsFiltersLabels* self)
{
	objects_base_object_count_update ((ObjectsBaseObject*) self);
}

static void
__objects_filters_labels___lambda402__services_store_label_deleted (ServicesStore* _sender,
                                                                    ObjectsLabel* label,
                                                                    gpointer self)
{
	_objects_filters_labels___lambda402_ ((ObjectsFiltersLabels*) self);
}

static void
_objects_filters_labels___lambda403_ (ObjectsFiltersLabels* self)
{
	objects_base_object_count_update ((ObjectsBaseObject*) self);
}

static void
__objects_filters_labels___lambda403__services_store_label_updated (ServicesStore* _sender,
                                                                    ObjectsLabel* label,
                                                                    gpointer self)
{
	_objects_filters_labels___lambda403_ ((ObjectsFiltersLabels*) self);
}

static void
_objects_filters_labels___lambda404_ (ObjectsFiltersLabels* self)
{
	objects_base_object_count_update ((ObjectsBaseObject*) self);
}

static void
__objects_filters_labels___lambda404__services_store_item_added (ServicesStore* _sender,
                                                                 ObjectsItem* item,
                                                                 gboolean insert,
                                                                 gpointer self)
{
	_objects_filters_labels___lambda404_ ((ObjectsFiltersLabels*) self);
}

static void
_objects_filters_labels___lambda405_ (ObjectsFiltersLabels* self)
{
	objects_base_object_count_update ((ObjectsBaseObject*) self);
}

static void
__objects_filters_labels___lambda405__services_store_item_deleted (ServicesStore* _sender,
                                                                   ObjectsItem* item,
                                                                   gpointer self)
{
	_objects_filters_labels___lambda405_ ((ObjectsFiltersLabels*) self);
}

static void
_objects_filters_labels___lambda406_ (ObjectsFiltersLabels* self)
{
	objects_base_object_count_update ((ObjectsBaseObject*) self);
}

static void
__objects_filters_labels___lambda406__services_store_item_archived (ServicesStore* _sender,
                                                                    ObjectsItem* item,
                                                                    gpointer self)
{
	_objects_filters_labels___lambda406_ ((ObjectsFiltersLabels*) self);
}

static void
_objects_filters_labels___lambda407_ (ObjectsFiltersLabels* self,
                                      ObjectsItem* item)
{
	g_return_if_fail (item != NULL);
	objects_base_object_count_update ((ObjectsBaseObject*) self);
}

static void
__objects_filters_labels___lambda407__services_store_item_unarchived (ServicesStore* _sender,
                                                                      ObjectsItem* item,
                                                                      gpointer self)
{
	_objects_filters_labels___lambda407_ ((ObjectsFiltersLabels*) self, item);
}

static void
_objects_filters_labels___lambda408_ (ObjectsFiltersLabels* self)
{
	objects_base_object_count_update ((ObjectsBaseObject*) self);
}

static void
__objects_filters_labels___lambda408__services_store_item_updated (ServicesStore* _sender,
                                                                   ObjectsItem* item,
                                                                   const gchar* update_id,
                                                                   gpointer self)
{
	_objects_filters_labels___lambda408_ ((ObjectsFiltersLabels*) self);
}

static GObject *
objects_filters_labels_constructor (GType type,
                                    guint n_construct_properties,
                                    GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	ObjectsFiltersLabels * self;
	gchar* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_ = NULL;
	ServicesSettings* _tmp3_;
	ServicesSettings* _tmp4_;
	GSettings* _tmp5_;
	gboolean _tmp6_;
	ServicesStore* _tmp7_;
	ServicesStore* _tmp8_;
	ServicesStore* _tmp9_;
	ServicesStore* _tmp10_;
	ServicesStore* _tmp11_;
	ServicesStore* _tmp12_;
	ServicesStore* _tmp13_;
	ServicesStore* _tmp14_;
	parent_class = G_OBJECT_CLASS (objects_filters_labels_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, OBJECTS_FILTERS_TYPE_LABELS, ObjectsFiltersLabels);
	objects_base_object_set_name ((ObjectsBaseObject*) self, _ ("Labels"));
	_tmp0_ = g_strdup_printf ("%s;%s", _ ("labels"), _ ("filters"));
	_tmp1_ = _tmp0_;
	objects_base_object_set_keywords ((ObjectsBaseObject*) self, _tmp1_);
	_g_free0 (_tmp1_);
	objects_base_object_set_icon_name ((ObjectsBaseObject*) self, "tag-outline-symbolic");
	objects_base_object_set_view_id ((ObjectsBaseObject*) self, "labels");
	_tmp3_ = services_settings_get_default ();
	_tmp4_ = _tmp3_;
	_tmp5_ = _tmp4_->settings;
	_tmp6_ = g_settings_get_boolean (_tmp5_, "dark-mode");
	_g_object_unref0 (_tmp4_);
	if (_tmp6_) {
		_tmp2_ = "#cdab8f";
	} else {
		_tmp2_ = "#986a44";
	}
	objects_base_object_set_color ((ObjectsBaseObject*) self, _tmp2_);
	_tmp7_ = services_store_instance ();
	g_signal_connect_object (_tmp7_, "label-added", (GCallback) __objects_filters_labels___lambda401__services_store_label_added, self, 0);
	_tmp8_ = services_store_instance ();
	g_signal_connect_object (_tmp8_, "label-deleted", (GCallback) __objects_filters_labels___lambda402__services_store_label_deleted, self, 0);
	_tmp9_ = services_store_instance ();
	g_signal_connect_object (_tmp9_, "label-updated", (GCallback) __objects_filters_labels___lambda403__services_store_label_updated, self, 0);
	_tmp10_ = services_store_instance ();
	g_signal_connect_object (_tmp10_, "item-added", (GCallback) __objects_filters_labels___lambda404__services_store_item_added, self, 0);
	_tmp11_ = services_store_instance ();
	g_signal_connect_object (_tmp11_, "item-deleted", (GCallback) __objects_filters_labels___lambda405__services_store_item_deleted, self, 0);
	_tmp12_ = services_store_instance ();
	g_signal_connect_object (_tmp12_, "item-archived", (GCallback) __objects_filters_labels___lambda406__services_store_item_archived, self, 0);
	_tmp13_ = services_store_instance ();
	g_signal_connect_object (_tmp13_, "item-unarchived", (GCallback) __objects_filters_labels___lambda407__services_store_item_unarchived, self, 0);
	_tmp14_ = services_store_instance ();
	g_signal_connect_object (_tmp14_, "item-updated", (GCallback) __objects_filters_labels___lambda408__services_store_item_updated, self, 0);
	return obj;
}

static void
objects_filters_labels_class_init (ObjectsFiltersLabelsClass * klass,
                                   gpointer klass_data)
{
	objects_filters_labels_parent_class = g_type_class_peek_parent (klass);
	((ObjectsBaseObjectClass *) klass)->update_count = (gint (*) (ObjectsBaseObject*)) objects_filters_labels_real_update_count;
	((ObjectsBaseObjectClass *) klass)->count_update = (void (*) (ObjectsBaseObject*)) objects_filters_labels_real_count_update;
	((ObjectsBaseObjectClass *) klass)->theme_color = (gchar* (*) (ObjectsBaseObject*)) objects_filters_labels_real_theme_color;
	G_OBJECT_CLASS (klass)->constructor = objects_filters_labels_constructor;
	G_OBJECT_CLASS (klass)->finalize = objects_filters_labels_finalize;
}

static void
objects_filters_labels_instance_init (ObjectsFiltersLabels * self,
                                      gpointer klass)
{
}

static void
objects_filters_labels_finalize (GObject * obj)
{
	ObjectsFiltersLabels * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, OBJECTS_FILTERS_TYPE_LABELS, ObjectsFiltersLabels);
	G_OBJECT_CLASS (objects_filters_labels_parent_class)->finalize (obj);
}

static GType
objects_filters_labels_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ObjectsFiltersLabelsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) objects_filters_labels_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ObjectsFiltersLabels), 0, (GInstanceInitFunc) objects_filters_labels_instance_init, NULL };
	GType objects_filters_labels_type_id;
	objects_filters_labels_type_id = g_type_register_static (OBJECTS_TYPE_BASE_OBJECT, "ObjectsFiltersLabels", &g_define_type_info, 0);
	return objects_filters_labels_type_id;
}

GType
objects_filters_labels_get_type (void)
{
	static volatile gsize objects_filters_labels_type_id__once = 0;
	if (g_once_init_enter (&objects_filters_labels_type_id__once)) {
		GType objects_filters_labels_type_id;
		objects_filters_labels_type_id = objects_filters_labels_get_type_once ();
		g_once_init_leave (&objects_filters_labels_type_id__once, objects_filters_labels_type_id);
	}
	return objects_filters_labels_type_id__once;
}

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;
}

