/* contacts-individual-section-sorter.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from contacts-individual-section-sorter.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 <gtk/gtk.h>
#include <glib-object.h>
#include <folks/folks.h>
#include <glib.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_INDIVIDUAL_SECTION_SORTER_0_PROPERTY,
	CONTACTS_INDIVIDUAL_SECTION_SORTER_NUM_PROPERTIES
};
static GParamSpec* contacts_individual_section_sorter_properties[CONTACTS_INDIVIDUAL_SECTION_SORTER_NUM_PROPERTIES];

static gpointer contacts_individual_section_sorter_parent_class = NULL;

static GtkOrdering contacts_individual_section_sorter_real_compare (GtkSorter* base,
                                                             GObject* item1,
                                                             GObject* item2);
static GtkSorterOrder contacts_individual_section_sorter_real_get_order (GtkSorter* base);
static GType contacts_individual_section_sorter_get_type_once (void);

ContactsIndividualSectionSorter*
contacts_individual_section_sorter_construct (GType object_type)
{
	ContactsIndividualSectionSorter * self = NULL;
	self = (ContactsIndividualSectionSorter*) g_object_new (object_type, NULL);
	return self;
}

ContactsIndividualSectionSorter*
contacts_individual_section_sorter_new (void)
{
	return contacts_individual_section_sorter_construct (CONTACTS_TYPE_INDIVIDUAL_SECTION_SORTER);
}

static GtkOrdering
contacts_individual_section_sorter_real_compare (GtkSorter* base,
                                                 GObject* item1,
                                                 GObject* item2)
{
	ContactsIndividualSectionSorter * self;
	FolksIndividual* a = NULL;
	FolksIndividual* _tmp0_;
	FolksIndividual* b = NULL;
	FolksIndividual* _tmp1_;
	FolksIndividual* _tmp2_;
	gboolean _tmp3_;
	gboolean _tmp4_;
	FolksIndividual* _tmp5_;
	gboolean _tmp6_;
	gboolean _tmp7_;
	GtkOrdering result;
	self = (ContactsIndividualSectionSorter*) base;
	a = G_TYPE_CHECK_INSTANCE_TYPE (item1, FOLKS_TYPE_INDIVIDUAL) ? ((FolksIndividual*) item1) : NULL;
	_tmp0_ = a;
	if (_tmp0_ == NULL) {
		result = GTK_ORDERING_SMALLER;
		return result;
	}
	b = G_TYPE_CHECK_INSTANCE_TYPE (item2, FOLKS_TYPE_INDIVIDUAL) ? ((FolksIndividual*) item2) : NULL;
	_tmp1_ = b;
	if (_tmp1_ == NULL) {
		result = GTK_ORDERING_LARGER;
		return result;
	}
	_tmp2_ = a;
	_tmp3_ = folks_favourite_details_get_is_favourite ((FolksFavouriteDetails*) _tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = b;
	_tmp6_ = folks_favourite_details_get_is_favourite ((FolksFavouriteDetails*) _tmp5_);
	_tmp7_ = _tmp6_;
	if (_tmp4_ != _tmp7_) {
		GtkOrdering _tmp8_ = 0;
		FolksIndividual* _tmp9_;
		gboolean _tmp10_;
		gboolean _tmp11_;
		_tmp9_ = a;
		_tmp10_ = folks_favourite_details_get_is_favourite ((FolksFavouriteDetails*) _tmp9_);
		_tmp11_ = _tmp10_;
		if (_tmp11_) {
			_tmp8_ = GTK_ORDERING_SMALLER;
		} else {
			_tmp8_ = GTK_ORDERING_LARGER;
		}
		result = _tmp8_;
		return result;
	}
	result = GTK_ORDERING_EQUAL;
	return result;
}

static GtkSorterOrder
contacts_individual_section_sorter_real_get_order (GtkSorter* base)
{
	ContactsIndividualSectionSorter * self;
	GtkSorterOrder result;
	self = (ContactsIndividualSectionSorter*) base;
	result = GTK_SORTER_ORDER_PARTIAL;
	return result;
}

static void
contacts_individual_section_sorter_class_init (ContactsIndividualSectionSorterClass * klass,
                                               gpointer klass_data)
{
	contacts_individual_section_sorter_parent_class = g_type_class_peek_parent (klass);
	((GtkSorterClass *) klass)->compare = (GtkOrdering (*) (GtkSorter*, GObject*, GObject*)) contacts_individual_section_sorter_real_compare;
	((GtkSorterClass *) klass)->get_order = (GtkSorterOrder (*) (GtkSorter*)) contacts_individual_section_sorter_real_get_order;
}

static void
contacts_individual_section_sorter_instance_init (ContactsIndividualSectionSorter * self,
                                                  gpointer klass)
{
}

/**
 * A subclass of {@link Gtk.Sorter} which sorts {@link Folks.Individual}s into
 * sections (for example "Favorites").
 */
 G_GNUC_NO_INLINE static GType
contacts_individual_section_sorter_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ContactsIndividualSectionSorterClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) contacts_individual_section_sorter_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ContactsIndividualSectionSorter), 0, (GInstanceInitFunc) contacts_individual_section_sorter_instance_init, NULL };
	GType contacts_individual_section_sorter_type_id;
	contacts_individual_section_sorter_type_id = g_type_register_static (gtk_sorter_get_type (), "ContactsIndividualSectionSorter", &g_define_type_info, 0);
	return contacts_individual_section_sorter_type_id;
}

GType
contacts_individual_section_sorter_get_type (void)
{
	static volatile gsize contacts_individual_section_sorter_type_id__once = 0;
	if (g_once_init_enter (&contacts_individual_section_sorter_type_id__once)) {
		GType contacts_individual_section_sorter_type_id;
		contacts_individual_section_sorter_type_id = contacts_individual_section_sorter_get_type_once ();
		g_once_init_leave (&contacts_individual_section_sorter_type_id__once, contacts_individual_section_sorter_type_id);
	}
	return contacts_individual_section_sorter_type_id__once;
}

