/* contacts-chunk-empty-filter.c generated by valac 0.56.3, the Vala compiler
 * generated from contacts-chunk-empty-filter.vala, do not modify */

/*
 * Copyright (C) 2022 Niels De Graef <nielsdegraef@gmail.com>
 *
 * 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, see <http://www.gnu.org/licenses/>.
 */

#include "contacts.h"
#include <glib.h>
#include <gtk/gtk.h>
#include <glib-object.h>
#include "contactscore.h"

enum  {
	CONTACTS_CHUNK_EMPTY_FILTER_0_PROPERTY,
	CONTACTS_CHUNK_EMPTY_FILTER_ALLOW_EMPTY_PROPERTY,
	CONTACTS_CHUNK_EMPTY_FILTER_NUM_PROPERTIES
};
static GParamSpec* contacts_chunk_empty_filter_properties[CONTACTS_CHUNK_EMPTY_FILTER_NUM_PROPERTIES];

struct _ContactsChunkEmptyFilterPrivate {
	gboolean _allow_empty;
};

static gint ContactsChunkEmptyFilter_private_offset;
static gpointer contacts_chunk_empty_filter_parent_class = NULL;

static gboolean contacts_chunk_empty_filter_real_match (GtkFilter* base,
                                                 GObject* item);
static gboolean contacts_chunk_empty_filter_match_empty (ContactsChunkEmptyFilter* self,
                                                  ContactsChunk* chunk);
static GtkFilterMatch contacts_chunk_empty_filter_real_get_strictness (GtkFilter* base);
static void contacts_chunk_empty_filter_finalize (GObject * obj);
static GType contacts_chunk_empty_filter_get_type_once (void);
static void _vala_contacts_chunk_empty_filter_get_property (GObject * object,
                                                     guint property_id,
                                                     GValue * value,
                                                     GParamSpec * pspec);
static void _vala_contacts_chunk_empty_filter_set_property (GObject * object,
                                                     guint property_id,
                                                     const GValue * value,
                                                     GParamSpec * pspec);

static inline gpointer
contacts_chunk_empty_filter_get_instance_private (ContactsChunkEmptyFilter* self)
{
	return G_STRUCT_MEMBER_P (self, ContactsChunkEmptyFilter_private_offset);
}

static gboolean
contacts_chunk_empty_filter_real_match (GtkFilter* base,
                                        GObject* item)
{
	ContactsChunkEmptyFilter * self;
	ContactsChunk* chunk = NULL;
	gboolean result;
	self = (ContactsChunkEmptyFilter*) base;
	chunk = G_TYPE_CHECK_INSTANCE_CAST (item, CONTACTS_TYPE_CHUNK, ContactsChunk);
	result = contacts_chunk_empty_filter_match_empty (self, chunk);
	return result;
}

static gboolean
contacts_chunk_empty_filter_match_empty (ContactsChunkEmptyFilter* self,
                                         ContactsChunk* chunk)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_;
	gboolean _tmp2_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (chunk != NULL, FALSE);
	_tmp1_ = contacts_chunk_empty_filter_get_allow_empty (self);
	_tmp2_ = _tmp1_;
	if (_tmp2_) {
		_tmp0_ = TRUE;
	} else {
		gboolean _tmp3_;
		gboolean _tmp4_;
		_tmp3_ = contacts_chunk_get_is_empty (chunk);
		_tmp4_ = _tmp3_;
		_tmp0_ = !_tmp4_;
	}
	result = _tmp0_;
	return result;
}

static GtkFilterMatch
contacts_chunk_empty_filter_real_get_strictness (GtkFilter* base)
{
	ContactsChunkEmptyFilter * self;
	GtkFilterMatch _tmp0_ = 0;
	gboolean _tmp1_;
	gboolean _tmp2_;
	GtkFilterMatch result;
	self = (ContactsChunkEmptyFilter*) base;
	_tmp1_ = contacts_chunk_empty_filter_get_allow_empty (self);
	_tmp2_ = _tmp1_;
	if (_tmp2_) {
		_tmp0_ = GTK_FILTER_MATCH_ALL;
	} else {
		_tmp0_ = GTK_FILTER_MATCH_SOME;
	}
	result = _tmp0_;
	return result;
}

ContactsChunkEmptyFilter*
contacts_chunk_empty_filter_construct (GType object_type)
{
	ContactsChunkEmptyFilter * self = NULL;
	self = (ContactsChunkEmptyFilter*) g_object_new (object_type, NULL);
	return self;
}

ContactsChunkEmptyFilter*
contacts_chunk_empty_filter_new (void)
{
	return contacts_chunk_empty_filter_construct (CONTACTS_TYPE_CHUNK_EMPTY_FILTER);
}

gboolean
contacts_chunk_empty_filter_get_allow_empty (ContactsChunkEmptyFilter* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_allow_empty;
	return result;
}

void
contacts_chunk_empty_filter_set_allow_empty (ContactsChunkEmptyFilter* self,
                                             gboolean value)
{
	GtkFilterChange _tmp0_ = 0;
	g_return_if_fail (self != NULL);
	if (self->priv->_allow_empty == value) {
		return;
	}
	self->priv->_allow_empty = value;
	if (value) {
		_tmp0_ = GTK_FILTER_CHANGE_LESS_STRICT;
	} else {
		_tmp0_ = GTK_FILTER_CHANGE_MORE_STRICT;
	}
	gtk_filter_changed ((GtkFilter*) self, _tmp0_);
	g_object_notify_by_pspec ((GObject *) self, contacts_chunk_empty_filter_properties[CONTACTS_CHUNK_EMPTY_FILTER_ALLOW_EMPTY_PROPERTY]);
}

static void
contacts_chunk_empty_filter_class_init (ContactsChunkEmptyFilterClass * klass,
                                        gpointer klass_data)
{
	contacts_chunk_empty_filter_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ContactsChunkEmptyFilter_private_offset);
	((GtkFilterClass *) klass)->match = (gboolean (*) (GtkFilter*, GObject*)) contacts_chunk_empty_filter_real_match;
	((GtkFilterClass *) klass)->get_strictness = (GtkFilterMatch (*) (GtkFilter*)) contacts_chunk_empty_filter_real_get_strictness;
	G_OBJECT_CLASS (klass)->get_property = _vala_contacts_chunk_empty_filter_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_contacts_chunk_empty_filter_set_property;
	G_OBJECT_CLASS (klass)->finalize = contacts_chunk_empty_filter_finalize;
	/** Whether empty chunks match the filter */
	g_object_class_install_property (G_OBJECT_CLASS (klass), CONTACTS_CHUNK_EMPTY_FILTER_ALLOW_EMPTY_PROPERTY, contacts_chunk_empty_filter_properties[CONTACTS_CHUNK_EMPTY_FILTER_ALLOW_EMPTY_PROPERTY] = g_param_spec_boolean ("allow-empty", "allow-empty", "allow-empty", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
contacts_chunk_empty_filter_instance_init (ContactsChunkEmptyFilter * self,
                                           gpointer klass)
{
	self->priv = contacts_chunk_empty_filter_get_instance_private (self);
	self->priv->_allow_empty = FALSE;
}

static void
contacts_chunk_empty_filter_finalize (GObject * obj)
{
	ContactsChunkEmptyFilter * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CONTACTS_TYPE_CHUNK_EMPTY_FILTER, ContactsChunkEmptyFilter);
	G_OBJECT_CLASS (contacts_chunk_empty_filter_parent_class)->finalize (obj);
}

/**
 * A custom GtkFilter to filter {@link Chunk}s on them possibly being non-empty.
 */
 G_GNUC_NO_INLINE static GType
contacts_chunk_empty_filter_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ContactsChunkEmptyFilterClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) contacts_chunk_empty_filter_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ContactsChunkEmptyFilter), 0, (GInstanceInitFunc) contacts_chunk_empty_filter_instance_init, NULL };
	GType contacts_chunk_empty_filter_type_id;
	contacts_chunk_empty_filter_type_id = g_type_register_static (gtk_filter_get_type (), "ContactsChunkEmptyFilter", &g_define_type_info, 0);
	ContactsChunkEmptyFilter_private_offset = g_type_add_instance_private (contacts_chunk_empty_filter_type_id, sizeof (ContactsChunkEmptyFilterPrivate));
	return contacts_chunk_empty_filter_type_id;
}

GType
contacts_chunk_empty_filter_get_type (void)
{
	static volatile gsize contacts_chunk_empty_filter_type_id__once = 0;
	if (g_once_init_enter (&contacts_chunk_empty_filter_type_id__once)) {
		GType contacts_chunk_empty_filter_type_id;
		contacts_chunk_empty_filter_type_id = contacts_chunk_empty_filter_get_type_once ();
		g_once_init_leave (&contacts_chunk_empty_filter_type_id__once, contacts_chunk_empty_filter_type_id);
	}
	return contacts_chunk_empty_filter_type_id__once;
}

static void
_vala_contacts_chunk_empty_filter_get_property (GObject * object,
                                                guint property_id,
                                                GValue * value,
                                                GParamSpec * pspec)
{
	ContactsChunkEmptyFilter * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, CONTACTS_TYPE_CHUNK_EMPTY_FILTER, ContactsChunkEmptyFilter);
	switch (property_id) {
		case CONTACTS_CHUNK_EMPTY_FILTER_ALLOW_EMPTY_PROPERTY:
		g_value_set_boolean (value, contacts_chunk_empty_filter_get_allow_empty (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_contacts_chunk_empty_filter_set_property (GObject * object,
                                                guint property_id,
                                                const GValue * value,
                                                GParamSpec * pspec)
{
	ContactsChunkEmptyFilter * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, CONTACTS_TYPE_CHUNK_EMPTY_FILTER, ContactsChunkEmptyFilter);
	switch (property_id) {
		case CONTACTS_CHUNK_EMPTY_FILTER_ALLOW_EMPTY_PROPERTY:
		contacts_chunk_empty_filter_set_allow_empty (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

