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

/*
 * Copyright (C) 2023 Niels De Graef <nielsdegraef@gmail.com>
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "contacts.h"
#include <glib.h>
#include <folks/folks.h>
#include <gtk/gtk.h>
#include <glib-object.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  {
	CONTACTS_MANUAL_FILTER_0_PROPERTY,
	CONTACTS_MANUAL_FILTER_NUM_PROPERTIES
};
static GParamSpec* contacts_manual_filter_properties[CONTACTS_MANUAL_FILTER_NUM_PROPERTIES];
#define _g_ptr_array_unref0(var) ((var == NULL) ? NULL : (var = (g_ptr_array_unref (var), NULL)))
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _ContactsManualFilterPrivate {
	GPtrArray* hidden;
};

static gint ContactsManualFilter_private_offset;
static gpointer contacts_manual_filter_parent_class = NULL;

static gboolean contacts_manual_filter_real_match (GtkFilter* base,
                                            GObject* item);
static GtkFilterMatch contacts_manual_filter_real_get_strictness (GtkFilter* base);
static void contacts_manual_filter_finalize (GObject * obj);
static GType contacts_manual_filter_get_type_once (void);

static inline gpointer
contacts_manual_filter_get_instance_private (ContactsManualFilter* self)
{
	return G_STRUCT_MEMBER_P (self, ContactsManualFilter_private_offset);
}

/**
   * Marks that the given individual should to be hidden
   */
void
contacts_manual_filter_add_individual (ContactsManualFilter* self,
                                       FolksIndividual* individual)
{
	GPtrArray* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (individual != NULL);
	_tmp0_ = self->priv->hidden;
	g_ptr_array_add (_tmp0_, individual);
	gtk_filter_changed ((GtkFilter*) self, GTK_FILTER_CHANGE_MORE_STRICT);
}

/**
   * Marks that the given individual should no longer to be hidden
   */
void
contacts_manual_filter_remove_individual (ContactsManualFilter* self,
                                          FolksIndividual* individual)
{
	GPtrArray* _tmp0_;
	GPtrArray* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (individual != NULL);
	_tmp0_ = self->priv->hidden;
	_vala_return_if_fail (g_ptr_array_find (_tmp0_, individual, NULL), "this.hidden.find (individual)");
	_tmp1_ = self->priv->hidden;
	g_ptr_array_remove (_tmp1_, individual);
	gtk_filter_changed ((GtkFilter*) self, GTK_FILTER_CHANGE_LESS_STRICT);
}

static gboolean
contacts_manual_filter_real_match (GtkFilter* base,
                                   GObject* item)
{
	ContactsManualFilter * self;
	GPtrArray* _tmp0_;
	gboolean result;
	self = (ContactsManualFilter*) base;
	_vala_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (item, FOLKS_TYPE_INDIVIDUAL), "item is Individual", FALSE);
	_tmp0_ = self->priv->hidden;
	result = !g_ptr_array_find (_tmp0_, G_TYPE_CHECK_INSTANCE_CAST (item, FOLKS_TYPE_INDIVIDUAL, FolksIndividual), NULL);
	return result;
}

static gint
vala_g_ptr_array_get_length (GPtrArray* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, 0);
	result = (gint) self->len;
	return result;
}

static GtkFilterMatch
contacts_manual_filter_real_get_strictness (GtkFilter* base)
{
	ContactsManualFilter * self;
	GPtrArray* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	GtkFilterMatch result;
	self = (ContactsManualFilter*) base;
	_tmp0_ = self->priv->hidden;
	_tmp1_ = vala_g_ptr_array_get_length (_tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_ == 0) {
		result = GTK_FILTER_MATCH_ALL;
		return result;
	}
	result = GTK_FILTER_MATCH_SOME;
	return result;
}

ContactsManualFilter*
contacts_manual_filter_construct (GType object_type)
{
	ContactsManualFilter * self = NULL;
	self = (ContactsManualFilter*) g_object_new (object_type, NULL);
	return self;
}

ContactsManualFilter*
contacts_manual_filter_new (void)
{
	return contacts_manual_filter_construct (CONTACTS_TYPE_MANUAL_FILTER);
}

static void
contacts_manual_filter_class_init (ContactsManualFilterClass * klass,
                                   gpointer klass_data)
{
	contacts_manual_filter_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ContactsManualFilter_private_offset);
	((GtkFilterClass *) klass)->match = (gboolean (*) (GtkFilter*, GObject*)) contacts_manual_filter_real_match;
	((GtkFilterClass *) klass)->get_strictness = (GtkFilterMatch (*) (GtkFilter*)) contacts_manual_filter_real_get_strictness;
	G_OBJECT_CLASS (klass)->finalize = contacts_manual_filter_finalize;
}

static void
contacts_manual_filter_instance_init (ContactsManualFilter * self,
                                      gpointer klass)
{
	GPtrArray* _tmp0_;
	self->priv = contacts_manual_filter_get_instance_private (self);
	_tmp0_ = g_ptr_array_new_full ((guint) 0, NULL);
	self->priv->hidden = _tmp0_;
}

static void
contacts_manual_filter_finalize (GObject * obj)
{
	ContactsManualFilter * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CONTACTS_TYPE_MANUAL_FILTER, ContactsManualFilter);
	_g_ptr_array_unref0 (self->priv->hidden);
	G_OBJECT_CLASS (contacts_manual_filter_parent_class)->finalize (obj);
}

/**
 * A subclass of {@link Gtk.Filter} which hides a programmatically chosen set
 * of individuals. The main use case here is to temporarily hide individuals
 * that are going to be deleted soon.
 */
 G_GNUC_NO_INLINE static GType
contacts_manual_filter_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ContactsManualFilterClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) contacts_manual_filter_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ContactsManualFilter), 0, (GInstanceInitFunc) contacts_manual_filter_instance_init, NULL };
	GType contacts_manual_filter_type_id;
	contacts_manual_filter_type_id = g_type_register_static (gtk_filter_get_type (), "ContactsManualFilter", &g_define_type_info, 0);
	ContactsManualFilter_private_offset = g_type_add_instance_private (contacts_manual_filter_type_id, sizeof (ContactsManualFilterPrivate));
	return contacts_manual_filter_type_id;
}

GType
contacts_manual_filter_get_type (void)
{
	static volatile gsize contacts_manual_filter_type_id__once = 0;
	if (g_once_init_enter (&contacts_manual_filter_type_id__once)) {
		GType contacts_manual_filter_type_id;
		contacts_manual_filter_type_id = contacts_manual_filter_get_type_once ();
		g_once_init_leave (&contacts_manual_filter_type_id__once, contacts_manual_filter_type_id);
	}
	return contacts_manual_filter_type_id__once;
}

