/* ConversationListStore.c generated by valac 0.56.19, the Vala compiler
 * generated from ConversationListStore.vala, do not modify */

/* -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-*/
/*-
 * Copyright (c) 2017 elementary LLC. (https://elementary.io)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * Authored by: David Hewitt <davidmhewitt@gmail.com>
 */

#include <glib-object.h>
#include <gio/gio.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
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define TYPE_VIRTUALIZING_LIST_BOX_MODEL (virtualizing_list_box_model_get_type ())
#define VIRTUALIZING_LIST_BOX_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_VIRTUALIZING_LIST_BOX_MODEL, VirtualizingListBoxModel))
#define VIRTUALIZING_LIST_BOX_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_VIRTUALIZING_LIST_BOX_MODEL, VirtualizingListBoxModelClass))
#define IS_VIRTUALIZING_LIST_BOX_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_VIRTUALIZING_LIST_BOX_MODEL))
#define IS_VIRTUALIZING_LIST_BOX_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_VIRTUALIZING_LIST_BOX_MODEL))
#define VIRTUALIZING_LIST_BOX_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_VIRTUALIZING_LIST_BOX_MODEL, VirtualizingListBoxModelClass))

typedef struct _VirtualizingListBoxModel VirtualizingListBoxModel;
typedef struct _VirtualizingListBoxModelClass VirtualizingListBoxModelClass;
typedef struct _VirtualizingListBoxModelPrivate VirtualizingListBoxModelPrivate;

#define MAIL_TYPE_CONVERSATION_LIST_STORE (mail_conversation_list_store_get_type ())
#define MAIL_CONVERSATION_LIST_STORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MAIL_TYPE_CONVERSATION_LIST_STORE, MailConversationListStore))
#define MAIL_CONVERSATION_LIST_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MAIL_TYPE_CONVERSATION_LIST_STORE, MailConversationListStoreClass))
#define MAIL_IS_CONVERSATION_LIST_STORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MAIL_TYPE_CONVERSATION_LIST_STORE))
#define MAIL_IS_CONVERSATION_LIST_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MAIL_TYPE_CONVERSATION_LIST_STORE))
#define MAIL_CONVERSATION_LIST_STORE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MAIL_TYPE_CONVERSATION_LIST_STORE, MailConversationListStoreClass))

typedef struct _MailConversationListStore MailConversationListStore;
typedef struct _MailConversationListStoreClass MailConversationListStoreClass;
typedef struct _MailConversationListStorePrivate MailConversationListStorePrivate;

#define MAIL_TYPE_CONVERSATION_ITEM_MODEL (mail_conversation_item_model_get_type ())
#define MAIL_CONVERSATION_ITEM_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MAIL_TYPE_CONVERSATION_ITEM_MODEL, MailConversationItemModel))
#define MAIL_CONVERSATION_ITEM_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MAIL_TYPE_CONVERSATION_ITEM_MODEL, MailConversationItemModelClass))
#define MAIL_IS_CONVERSATION_ITEM_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MAIL_TYPE_CONVERSATION_ITEM_MODEL))
#define MAIL_IS_CONVERSATION_ITEM_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MAIL_TYPE_CONVERSATION_ITEM_MODEL))
#define MAIL_CONVERSATION_ITEM_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MAIL_TYPE_CONVERSATION_ITEM_MODEL, MailConversationItemModelClass))

typedef struct _MailConversationItemModel MailConversationItemModel;
typedef struct _MailConversationItemModelClass MailConversationItemModelClass;
typedef gboolean (*MailConversationListStoreRowVisibilityFunc) (GObject* row, gpointer user_data);
enum  {
	MAIL_CONVERSATION_LIST_STORE_0_PROPERTY,
	MAIL_CONVERSATION_LIST_STORE_NUM_PROPERTIES
};
static GParamSpec* mail_conversation_list_store_properties[MAIL_CONVERSATION_LIST_STORE_NUM_PROPERTIES];
#define _g_sequence_free0(var) ((var == NULL) ? NULL : (var = (g_sequence_free (var), NULL)))

struct _VirtualizingListBoxModel {
	GObject parent_instance;
	VirtualizingListBoxModelPrivate * priv;
};

struct _VirtualizingListBoxModelClass {
	GObjectClass parent_class;
	guint (*get_n_items) (VirtualizingListBoxModel* self);
	GObject* (*get_item) (VirtualizingListBoxModel* self, guint index);
	GObject* (*get_item_unfiltered) (VirtualizingListBoxModel* self, guint index);
};

struct _MailConversationListStore {
	VirtualizingListBoxModel parent_instance;
	MailConversationListStorePrivate * priv;
};

struct _MailConversationListStoreClass {
	VirtualizingListBoxModelClass parent_class;
};

struct _MailConversationListStorePrivate {
	GSequence* data;
	guint last_position;
	GSequenceIter* last_iter;
	GCompareDataFunc compare_func;
	gpointer compare_func_target;
	MailConversationListStoreRowVisibilityFunc filter_func;
	gpointer filter_func_target;
};

static gint MailConversationListStore_private_offset;
static gpointer mail_conversation_list_store_parent_class = NULL;

VALA_EXTERN GType virtualizing_list_box_model_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (VirtualizingListBoxModel, g_object_unref)
VALA_EXTERN GType mail_conversation_list_store_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MailConversationListStore, g_object_unref)
VALA_EXTERN GType mail_conversation_item_model_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MailConversationItemModel, g_object_unref)
VALA_EXTERN guint virtualizing_list_box_model_get_n_items (VirtualizingListBoxModel* self);
VALA_EXTERN GObject* virtualizing_list_box_model_get_item (VirtualizingListBoxModel* self,
                                               guint index);
VALA_EXTERN GObject* virtualizing_list_box_model_get_item_unfiltered (VirtualizingListBoxModel* self,
                                                          guint index);
static void _g_object_unref0_ (gpointer var);
static guint mail_conversation_list_store_real_get_n_items (VirtualizingListBoxModel* base);
static GObject* mail_conversation_list_store_real_get_item (VirtualizingListBoxModel* base,
                                                     guint index);
static GObject* mail_conversation_list_store_get_item_internal (MailConversationListStore* self,
                                                         guint index,
                                                         gboolean unfiltered);
static GObject* mail_conversation_list_store_real_get_item_unfiltered (VirtualizingListBoxModel* base,
                                                                guint index);
VALA_EXTERN void mail_conversation_list_store_add (MailConversationListStore* self,
                                       MailConversationItemModel* data);
VALA_EXTERN void mail_conversation_list_store_remove (MailConversationListStore* self,
                                          MailConversationItemModel* data);
VALA_EXTERN gint virtualizing_list_box_model_get_index_of_unfiltered (VirtualizingListBoxModel* self,
                                                          GObject* item);
VALA_EXTERN void mail_conversation_list_store_remove_all (MailConversationListStore* self);
VALA_EXTERN void virtualizing_list_box_model_unselect_all (VirtualizingListBoxModel* self);
VALA_EXTERN void mail_conversation_list_store_set_sort_func (MailConversationListStore* self,
                                                 GCompareDataFunc function,
                                                 gpointer function_target);
VALA_EXTERN void mail_conversation_list_store_set_filter_func (MailConversationListStore* self,
                                                   MailConversationListStoreRowVisibilityFunc function,
                                                   gpointer function_target);
VALA_EXTERN MailConversationListStore* mail_conversation_list_store_new (void);
VALA_EXTERN MailConversationListStore* mail_conversation_list_store_construct (GType object_type);
VALA_EXTERN VirtualizingListBoxModel* virtualizing_list_box_model_construct (GType object_type);
static void mail_conversation_list_store_finalize (GObject * obj);
static GType mail_conversation_list_store_get_type_once (void);

static inline gpointer
mail_conversation_list_store_get_instance_private (MailConversationListStore* self)
{
	return G_STRUCT_MEMBER_P (self, MailConversationListStore_private_offset);
}

static void
_g_object_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}

static guint
mail_conversation_list_store_real_get_n_items (VirtualizingListBoxModel* base)
{
	MailConversationListStore * self;
	GSequence* _tmp0_;
	guint result;
	self = (MailConversationListStore*) base;
	_tmp0_ = self->priv->data;
	result = (guint) g_sequence_get_length (_tmp0_);
	return result;
}

static GObject*
mail_conversation_list_store_real_get_item (VirtualizingListBoxModel* base,
                                            guint index)
{
	MailConversationListStore * self;
	GObject* _tmp0_;
	GObject* result;
	self = (MailConversationListStore*) base;
	_tmp0_ = mail_conversation_list_store_get_item_internal (self, index, FALSE);
	result = _tmp0_;
	return result;
}

static GObject*
mail_conversation_list_store_real_get_item_unfiltered (VirtualizingListBoxModel* base,
                                                       guint index)
{
	MailConversationListStore * self;
	GObject* _tmp0_;
	GObject* result;
	self = (MailConversationListStore*) base;
	_tmp0_ = mail_conversation_list_store_get_item_internal (self, index, TRUE);
	result = _tmp0_;
	return result;
}

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

static GObject*
mail_conversation_list_store_get_item_internal (MailConversationListStore* self,
                                                guint index,
                                                gboolean unfiltered)
{
	GSequenceIter* iter = NULL;
	GSequenceIter* _tmp5_;
	GSequenceIter* _tmp8_;
	GSequenceIter* _tmp9_;
	MailConversationListStoreRowVisibilityFunc _tmp10_;
	gpointer _tmp10__target;
	GObject* result;
	g_return_val_if_fail (self != NULL, NULL);
	iter = NULL;
	if (self->priv->last_position != G_MAXUINT) {
		if (self->priv->last_position == (index + 1)) {
			GSequenceIter* _tmp0_;
			GSequenceIter* _tmp1_;
			_tmp0_ = self->priv->last_iter;
			_tmp1_ = g_sequence_iter_prev (_tmp0_);
			iter = _tmp1_;
		} else {
			if (self->priv->last_position == (index - 1)) {
				GSequenceIter* _tmp2_;
				GSequenceIter* _tmp3_;
				_tmp2_ = self->priv->last_iter;
				_tmp3_ = g_sequence_iter_next (_tmp2_);
				iter = _tmp3_;
			} else {
				if (self->priv->last_position == index) {
					GSequenceIter* _tmp4_;
					_tmp4_ = self->priv->last_iter;
					iter = _tmp4_;
				}
			}
		}
	}
	_tmp5_ = iter;
	if (_tmp5_ == NULL) {
		GSequence* _tmp6_;
		GSequenceIter* _tmp7_;
		_tmp6_ = self->priv->data;
		_tmp7_ = g_sequence_get_iter_at_pos (_tmp6_, (gint) index);
		iter = _tmp7_;
	}
	_tmp8_ = iter;
	self->priv->last_iter = _tmp8_;
	self->priv->last_position = index;
	_tmp9_ = iter;
	if (g_sequence_iter_is_end (_tmp9_)) {
		result = NULL;
		return result;
	}
	_tmp10_ = self->priv->filter_func;
	_tmp10__target = self->priv->filter_func_target;
	if (_tmp10_ == NULL) {
		GSequenceIter* _tmp11_;
		gconstpointer _tmp12_;
		GObject* _tmp13_;
		_tmp11_ = iter;
		_tmp12_ = g_sequence_get (_tmp11_);
		_tmp13_ = _g_object_ref0 ((GObject*) ((MailConversationItemModel*) _tmp12_));
		result = _tmp13_;
		return result;
	} else {
		MailConversationListStoreRowVisibilityFunc _tmp14_;
		gpointer _tmp14__target;
		GSequenceIter* _tmp15_;
		gconstpointer _tmp16_;
		_tmp14_ = self->priv->filter_func;
		_tmp14__target = self->priv->filter_func_target;
		_tmp15_ = iter;
		_tmp16_ = g_sequence_get (_tmp15_);
		if (_tmp14_ ((GObject*) ((MailConversationItemModel*) _tmp16_), _tmp14__target)) {
			GSequenceIter* _tmp17_;
			gconstpointer _tmp18_;
			GObject* _tmp19_;
			_tmp17_ = iter;
			_tmp18_ = g_sequence_get (_tmp17_);
			_tmp19_ = _g_object_ref0 ((GObject*) ((MailConversationItemModel*) _tmp18_));
			result = _tmp19_;
			return result;
		} else {
			if (unfiltered) {
				GSequenceIter* _tmp20_;
				gconstpointer _tmp21_;
				GObject* _tmp22_;
				_tmp20_ = iter;
				_tmp21_ = g_sequence_get (_tmp20_);
				_tmp22_ = _g_object_ref0 ((GObject*) ((MailConversationItemModel*) _tmp21_));
				result = _tmp22_;
				return result;
			} else {
				result = NULL;
				return result;
			}
		}
	}
}

void
mail_conversation_list_store_add (MailConversationListStore* self,
                                  MailConversationItemModel* data)
{
	GCompareDataFunc _tmp0_;
	gpointer _tmp0__target;
	g_return_if_fail (self != NULL);
	g_return_if_fail (data != NULL);
	_tmp0_ = self->priv->compare_func;
	_tmp0__target = self->priv->compare_func_target;
	if (_tmp0_ != NULL) {
		GSequence* _tmp1_;
		MailConversationItemModel* _tmp2_;
		GCompareDataFunc _tmp3_;
		gpointer _tmp3__target;
		GSequenceIter* _tmp4_;
		_tmp1_ = self->priv->data;
		_tmp2_ = _g_object_ref0 (data);
		_tmp3_ = self->priv->compare_func;
		_tmp3__target = self->priv->compare_func_target;
		_tmp4_ = g_sequence_insert_sorted (_tmp1_, _tmp2_, _tmp3_, _tmp3__target);
	} else {
		GSequence* _tmp5_;
		MailConversationItemModel* _tmp6_;
		GSequenceIter* _tmp7_;
		_tmp5_ = self->priv->data;
		_tmp6_ = _g_object_ref0 (data);
		_tmp7_ = g_sequence_append (_tmp5_, _tmp6_);
	}
	self->priv->last_iter = NULL;
	self->priv->last_position = G_MAXUINT;
}

void
mail_conversation_list_store_remove (MailConversationListStore* self,
                                     MailConversationItemModel* data)
{
	GSequenceIter* iter = NULL;
	GSequence* _tmp0_;
	GSequenceIter* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (data != NULL);
	_tmp0_ = self->priv->data;
	_tmp1_ = g_sequence_get_iter_at_pos (_tmp0_, virtualizing_list_box_model_get_index_of_unfiltered ((VirtualizingListBoxModel*) self, (GObject*) data));
	iter = _tmp1_;
	g_sequence_remove (iter);
	self->priv->last_iter = NULL;
	self->priv->last_position = G_MAXUINT;
}

void
mail_conversation_list_store_remove_all (MailConversationListStore* self)
{
	GSequence* _tmp0_;
	GSequenceIter* _tmp1_;
	GSequence* _tmp2_;
	GSequenceIter* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->data;
	_tmp1_ = g_sequence_get_begin_iter (_tmp0_);
	_tmp2_ = self->priv->data;
	_tmp3_ = g_sequence_get_end_iter (_tmp2_);
	g_sequence_remove_range (_tmp1_, _tmp3_);
	virtualizing_list_box_model_unselect_all ((VirtualizingListBoxModel*) self);
	self->priv->last_iter = NULL;
	self->priv->last_position = G_MAXUINT;
}

void
mail_conversation_list_store_set_sort_func (MailConversationListStore* self,
                                            GCompareDataFunc function,
                                            gpointer function_target)
{
	g_return_if_fail (self != NULL);
	self->priv->compare_func = function;
	self->priv->compare_func_target = function_target;
}

void
mail_conversation_list_store_set_filter_func (MailConversationListStore* self,
                                              MailConversationListStoreRowVisibilityFunc function,
                                              gpointer function_target)
{
	g_return_if_fail (self != NULL);
	self->priv->filter_func = function;
	self->priv->filter_func_target = function_target;
}

MailConversationListStore*
mail_conversation_list_store_construct (GType object_type)
{
	MailConversationListStore * self = NULL;
	self = (MailConversationListStore*) virtualizing_list_box_model_construct (object_type);
	return self;
}

MailConversationListStore*
mail_conversation_list_store_new (void)
{
	return mail_conversation_list_store_construct (MAIL_TYPE_CONVERSATION_LIST_STORE);
}

static void
mail_conversation_list_store_class_init (MailConversationListStoreClass * klass,
                                         gpointer klass_data)
{
	mail_conversation_list_store_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &MailConversationListStore_private_offset);
	((VirtualizingListBoxModelClass *) klass)->get_n_items = (guint (*) (VirtualizingListBoxModel*)) mail_conversation_list_store_real_get_n_items;
	((VirtualizingListBoxModelClass *) klass)->get_item = (GObject* (*) (VirtualizingListBoxModel*, guint)) mail_conversation_list_store_real_get_item;
	((VirtualizingListBoxModelClass *) klass)->get_item_unfiltered = (GObject* (*) (VirtualizingListBoxModel*, guint)) mail_conversation_list_store_real_get_item_unfiltered;
	G_OBJECT_CLASS (klass)->finalize = mail_conversation_list_store_finalize;
}

static void
mail_conversation_list_store_instance_init (MailConversationListStore * self,
                                            gpointer klass)
{
	GSequence* _tmp0_;
	self->priv = mail_conversation_list_store_get_instance_private (self);
	_tmp0_ = g_sequence_new (_g_object_unref0_);
	self->priv->data = _tmp0_;
	self->priv->last_position = G_MAXUINT;
}

static void
mail_conversation_list_store_finalize (GObject * obj)
{
	MailConversationListStore * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, MAIL_TYPE_CONVERSATION_LIST_STORE, MailConversationListStore);
	_g_sequence_free0 (self->priv->data);
	G_OBJECT_CLASS (mail_conversation_list_store_parent_class)->finalize (obj);
}

static GType
mail_conversation_list_store_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (MailConversationListStoreClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) mail_conversation_list_store_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MailConversationListStore), 0, (GInstanceInitFunc) mail_conversation_list_store_instance_init, NULL };
	GType mail_conversation_list_store_type_id;
	mail_conversation_list_store_type_id = g_type_register_static (TYPE_VIRTUALIZING_LIST_BOX_MODEL, "MailConversationListStore", &g_define_type_info, 0);
	MailConversationListStore_private_offset = g_type_add_instance_private (mail_conversation_list_store_type_id, sizeof (MailConversationListStorePrivate));
	return mail_conversation_list_store_type_id;
}

GType
mail_conversation_list_store_get_type (void)
{
	static volatile gsize mail_conversation_list_store_type_id__once = 0;
	if (g_once_init_enter (&mail_conversation_list_store_type_id__once)) {
		GType mail_conversation_list_store_type_id;
		mail_conversation_list_store_type_id = mail_conversation_list_store_get_type_once ();
		g_once_init_leave (&mail_conversation_list_store_type_id__once, mail_conversation_list_store_type_id);
	}
	return mail_conversation_list_store_type_id__once;
}

