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

#include "libdino.h"
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <glib-object.h>
#include <gobject/gvaluecollector.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

#define _g_free0(var) (var = (g_free (var), NULL))
#define __vala_GdkPixbufFormat_free0(var) ((var == NULL) ? NULL : (var = (_vala_GdkPixbufFormat_free (var), NULL)))
typedef struct _DinoParamSpecUtil DinoParamSpecUtil;

struct _DinoParamSpecUtil {
	GParamSpec parent_instance;
};

static gpointer dino_util_parent_class = NULL;

static GdkPixbufFormat* _vala_GdkPixbufFormat_copy (GdkPixbufFormat* self);
static void _vala_GdkPixbufFormat_free (GdkPixbufFormat* self);
static void dino_util_finalize (DinoUtil * obj);
static GType dino_util_get_type_once (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static gssize _vala_array_length (gpointer array);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

DinoEntitiesMessageType
dino_util_get_message_type_for_conversation (DinoEntitiesConversation* conversation)
{
	DinoEntitiesConversationType _tmp0_;
	DinoEntitiesConversationType _tmp1_;
	DinoEntitiesMessageType result;
	g_return_val_if_fail (conversation != NULL, 0);
	_tmp0_ = dino_entities_conversation_get_type_ (conversation);
	_tmp1_ = _tmp0_;
	switch (_tmp1_) {
		case DINO_ENTITIES_CONVERSATION_TYPE_CHAT:
		{
			result = DINO_ENTITIES_MESSAGE_TYPE_CHAT;
			return result;
		}
		case DINO_ENTITIES_CONVERSATION_TYPE_GROUPCHAT:
		{
			result = DINO_ENTITIES_MESSAGE_TYPE_GROUPCHAT;
			return result;
		}
		case DINO_ENTITIES_CONVERSATION_TYPE_GROUPCHAT_PM:
		{
			result = DINO_ENTITIES_MESSAGE_TYPE_GROUPCHAT_PM;
			return result;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
}

DinoEntitiesConversationType
dino_util_get_conversation_type_for_message (DinoEntitiesMessage* message)
{
	DinoEntitiesMessageType _tmp0_;
	DinoEntitiesMessageType _tmp1_;
	DinoEntitiesConversationType result;
	g_return_val_if_fail (message != NULL, 0);
	_tmp0_ = dino_entities_message_get_type_ (message);
	_tmp1_ = _tmp0_;
	switch (_tmp1_) {
		case DINO_ENTITIES_MESSAGE_TYPE_CHAT:
		{
			result = DINO_ENTITIES_CONVERSATION_TYPE_CHAT;
			return result;
		}
		case DINO_ENTITIES_MESSAGE_TYPE_GROUPCHAT:
		{
			result = DINO_ENTITIES_CONVERSATION_TYPE_GROUPCHAT;
			return result;
		}
		case DINO_ENTITIES_MESSAGE_TYPE_GROUPCHAT_PM:
		{
			result = DINO_ENTITIES_CONVERSATION_TYPE_GROUPCHAT_PM;
			return result;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
}

static GdkPixbufFormat*
_vala_GdkPixbufFormat_copy (GdkPixbufFormat* self)
{
	return g_boxed_copy (gdk_pixbuf_format_get_type (), self);
}

static gpointer
__vala_GdkPixbufFormat_copy0 (gpointer self)
{
	return self ? _vala_GdkPixbufFormat_copy (self) : NULL;
}

static void
_vala_GdkPixbufFormat_free (GdkPixbufFormat* self)
{
	g_boxed_free (gdk_pixbuf_format_get_type (), self);
}

gboolean
dino_util_is_pixbuf_supported_mime_type (const gchar* mime_type)
{
	GSList* _tmp0_;
	gboolean result;
	g_return_val_if_fail (mime_type != NULL, FALSE);
	if (mime_type == NULL) {
		result = FALSE;
		return result;
	}
	_tmp0_ = gdk_pixbuf_get_formats ();
	{
		GSList* pixbuf_format_collection = NULL;
		GSList* pixbuf_format_it = NULL;
		pixbuf_format_collection = _tmp0_;
		for (pixbuf_format_it = pixbuf_format_collection; pixbuf_format_it != NULL; pixbuf_format_it = pixbuf_format_it->next) {
			GdkPixbufFormat* _tmp1_;
			GdkPixbufFormat* pixbuf_format = NULL;
			_tmp1_ = __vala_GdkPixbufFormat_copy0 ((GdkPixbufFormat*) pixbuf_format_it->data);
			pixbuf_format = _tmp1_;
			{
				GdkPixbufFormat* _tmp2_;
				gchar** _tmp3_;
				gchar** _tmp4_;
				_tmp2_ = pixbuf_format;
				_tmp4_ = _tmp3_ = gdk_pixbuf_format_get_mime_types (_tmp2_);
				{
					gchar** pixbuf_mime_collection = NULL;
					gint pixbuf_mime_collection_length1 = 0;
					gint _pixbuf_mime_collection_size_ = 0;
					gint pixbuf_mime_it = 0;
					pixbuf_mime_collection = _tmp4_;
					pixbuf_mime_collection_length1 = _vala_array_length (_tmp3_);
					for (pixbuf_mime_it = 0; pixbuf_mime_it < pixbuf_mime_collection_length1; pixbuf_mime_it = pixbuf_mime_it + 1) {
						gchar* _tmp5_;
						gchar* pixbuf_mime = NULL;
						_tmp5_ = g_strdup (pixbuf_mime_collection[pixbuf_mime_it]);
						pixbuf_mime = _tmp5_;
						{
							const gchar* _tmp6_;
							_tmp6_ = pixbuf_mime;
							if (g_strcmp0 (_tmp6_, mime_type) == 0) {
								result = TRUE;
								_g_free0 (pixbuf_mime);
								pixbuf_mime_collection = (_vala_array_free (pixbuf_mime_collection, pixbuf_mime_collection_length1, (GDestroyNotify) g_free), NULL);
								__vala_GdkPixbufFormat_free0 (pixbuf_format);
								(pixbuf_format_collection == NULL) ? NULL : (pixbuf_format_collection = (g_slist_free (pixbuf_format_collection), NULL));
								return result;
							}
							_g_free0 (pixbuf_mime);
						}
					}
					pixbuf_mime_collection = (_vala_array_free (pixbuf_mime_collection, pixbuf_mime_collection_length1, (GDestroyNotify) g_free), NULL);
				}
				__vala_GdkPixbufFormat_free0 (pixbuf_format);
			}
		}
		(pixbuf_format_collection == NULL) ? NULL : (pixbuf_format_collection = (g_slist_free (pixbuf_format_collection), NULL));
	}
	result = FALSE;
	return result;
}

DinoUtil*
dino_util_construct (GType object_type)
{
	DinoUtil* self = NULL;
	self = (DinoUtil*) g_type_create_instance (object_type);
	return self;
}

DinoUtil*
dino_util_new (void)
{
	return dino_util_construct (DINO_TYPE_UTIL);
}

static void
dino_value_util_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
dino_value_util_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		dino_util_unref (value->data[0].v_pointer);
	}
}

static void
dino_value_util_copy_value (const GValue* src_value,
                            GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = dino_util_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
dino_value_util_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
dino_value_util_collect_value (GValue* value,
                               guint n_collect_values,
                               GTypeCValue* collect_values,
                               guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		DinoUtil * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = dino_util_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
dino_value_util_lcopy_value (const GValue* value,
                             guint n_collect_values,
                             GTypeCValue* collect_values,
                             guint collect_flags)
{
	DinoUtil ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = dino_util_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
dino_param_spec_util (const gchar* name,
                      const gchar* nick,
                      const gchar* blurb,
                      GType object_type,
                      GParamFlags flags)
{
	DinoParamSpecUtil* spec;
	g_return_val_if_fail (g_type_is_a (object_type, DINO_TYPE_UTIL), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
dino_value_get_util (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DINO_TYPE_UTIL), NULL);
	return value->data[0].v_pointer;
}

void
dino_value_set_util (GValue* value,
                     gpointer v_object)
{
	DinoUtil * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DINO_TYPE_UTIL));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, DINO_TYPE_UTIL));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		dino_util_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		dino_util_unref (old);
	}
}

void
dino_value_take_util (GValue* value,
                      gpointer v_object)
{
	DinoUtil * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DINO_TYPE_UTIL));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, DINO_TYPE_UTIL));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		dino_util_unref (old);
	}
}

static void
dino_util_class_init (DinoUtilClass * klass,
                      gpointer klass_data)
{
	dino_util_parent_class = g_type_class_peek_parent (klass);
	((DinoUtilClass *) klass)->finalize = dino_util_finalize;
}

static void
dino_util_instance_init (DinoUtil * self,
                         gpointer klass)
{
	self->ref_count = 1;
}

static void
dino_util_finalize (DinoUtil * obj)
{
	DinoUtil * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_TYPE_UTIL, DinoUtil);
	g_signal_handlers_destroy (self);
}

static GType
dino_util_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { dino_value_util_init, dino_value_util_free_value, dino_value_util_copy_value, dino_value_util_peek_pointer, "p", dino_value_util_collect_value, "p", dino_value_util_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (DinoUtilClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_util_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoUtil), 0, (GInstanceInitFunc) dino_util_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType dino_util_type_id;
	dino_util_type_id = g_type_register_fundamental (g_type_fundamental_next (), "DinoUtil", &g_define_type_info, &g_define_type_fundamental_info, 0);
	return dino_util_type_id;
}

GType
dino_util_get_type (void)
{
	static volatile gsize dino_util_type_id__once = 0;
	if (g_once_init_enter (&dino_util_type_id__once)) {
		GType dino_util_type_id;
		dino_util_type_id = dino_util_get_type_once ();
		g_once_init_leave (&dino_util_type_id__once, dino_util_type_id);
	}
	return dino_util_type_id__once;
}

gpointer
dino_util_ref (gpointer instance)
{
	DinoUtil * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
dino_util_unref (gpointer instance)
{
	DinoUtil * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		DINO_UTIL_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

static gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

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

