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

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

#include "contactscore.h"
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <folks/folks.h>
#include <gee.h>
#include <config.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

typedef enum  {
	CONTACTS_TYPEDESCRIPTOR_SOURCE_VCARD,
	CONTACTS_TYPEDESCRIPTOR_SOURCE_OTHER,
	CONTACTS_TYPEDESCRIPTOR_SOURCE_CUSTOM
} ContactsTypeDescriptorSource;

#define CONTACTS_TYPEDESCRIPTOR_TYPE_SOURCE (contacts_typedescriptor_source_get_type ())
enum  {
	CONTACTS_TYPEDESCRIPTOR_0_PROPERTY,
	CONTACTS_TYPEDESCRIPTOR_DISPLAY_NAME_PROPERTY,
	CONTACTS_TYPEDESCRIPTOR_NUM_PROPERTIES
};
static GParamSpec* contacts_typedescriptor_properties[CONTACTS_TYPEDESCRIPTOR_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))

struct _ContactsTypeDescriptorPrivate {
	ContactsTypeDescriptorSource source;
};

static gint ContactsTypeDescriptor_private_offset;
static gpointer contacts_typedescriptor_parent_class = NULL;

static GType contacts_typedescriptor_source_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static const gchar* contacts_typedescriptor_source_to_string (ContactsTypeDescriptorSource self);
static gchar** _vala_array_dup1 (gchar** self,
                          gssize length);
static void contacts_typedescriptor_finalize (GObject * obj);
static GType contacts_typedescriptor_get_type_once (void);
static void _vala_contacts_typedescriptor_get_property (GObject * object,
                                                 guint property_id,
                                                 GValue * value,
                                                 GParamSpec * pspec);
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 inline gpointer
contacts_typedescriptor_get_instance_private (ContactsTypeDescriptor* self)
{
	return G_STRUCT_MEMBER_P (self, ContactsTypeDescriptor_private_offset);
}

static const gchar*
contacts_typedescriptor_source_to_string (ContactsTypeDescriptorSource self)
{
	const gchar* result;
	switch (self) {
		case CONTACTS_TYPEDESCRIPTOR_SOURCE_VCARD:
		{
			result = "vcard";
			return result;
		}
		case CONTACTS_TYPEDESCRIPTOR_SOURCE_OTHER:
		{
			result = "other";
			return result;
		}
		case CONTACTS_TYPEDESCRIPTOR_SOURCE_CUSTOM:
		{
			result = "custom";
			return result;
		}
		default:
		break;
	}
	result = "INVALID";
	return result;
}

 G_GNUC_NO_INLINE static GType
contacts_typedescriptor_source_get_type_once (void)
{
	static const GEnumValue values[] = {{CONTACTS_TYPEDESCRIPTOR_SOURCE_VCARD, "CONTACTS_TYPEDESCRIPTOR_SOURCE_VCARD", "vcard"}, {CONTACTS_TYPEDESCRIPTOR_SOURCE_OTHER, "CONTACTS_TYPEDESCRIPTOR_SOURCE_OTHER", "other"}, {CONTACTS_TYPEDESCRIPTOR_SOURCE_CUSTOM, "CONTACTS_TYPEDESCRIPTOR_SOURCE_CUSTOM", "custom"}, {0, NULL, NULL}};
	GType contacts_typedescriptor_source_type_id;
	contacts_typedescriptor_source_type_id = g_enum_register_static ("ContactsTypeDescriptorSource", values);
	return contacts_typedescriptor_source_type_id;
}

static GType
contacts_typedescriptor_source_get_type (void)
{
	static volatile gsize contacts_typedescriptor_source_type_id__once = 0;
	if (g_once_init_enter (&contacts_typedescriptor_source_type_id__once)) {
		GType contacts_typedescriptor_source_type_id;
		contacts_typedescriptor_source_type_id = contacts_typedescriptor_source_get_type_once ();
		g_once_init_leave (&contacts_typedescriptor_source_type_id__once, contacts_typedescriptor_source_type_id);
	}
	return contacts_typedescriptor_source_type_id__once;
}

/**
   * Creates a TypeDescriptor which is mappable to the given VCard Type strings.
   */
static gchar**
_vala_array_dup1 (gchar** self,
                  gssize length)
{
	if (length >= 0) {
		gchar** result;
		gssize i;
		result = g_new0 (gchar*, length + 1);
		for (i = 0; i < length; i++) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

ContactsTypeDescriptor*
contacts_typedescriptor_construct_vcard (GType object_type,
                                         const gchar* untranslated_name,
                                         gchar** types,
                                         gint types_length1)
{
	ContactsTypeDescriptor * self = NULL;
	gchar* _tmp0_;
	gchar** _tmp1_;
	gint _tmp1__length1;
	g_return_val_if_fail (untranslated_name != NULL, NULL);
	self = (ContactsTypeDescriptor*) g_object_new (object_type, NULL);
	self->priv->source = CONTACTS_TYPEDESCRIPTOR_SOURCE_VCARD;
	_tmp0_ = g_strdup (untranslated_name);
	_g_free0 (self->name);
	self->name = _tmp0_;
	_tmp1_ = (types != NULL) ? _vala_array_dup1 (types, types_length1) : types;
	_tmp1__length1 = types_length1;
	self->vcard_types = (_vala_array_free (self->vcard_types, self->vcard_types_length1, (GDestroyNotify) g_free), NULL);
	self->vcard_types = _tmp1_;
	self->vcard_types_length1 = _tmp1__length1;
	return self;
}

ContactsTypeDescriptor*
contacts_typedescriptor_new_vcard (const gchar* untranslated_name,
                                   gchar** types,
                                   gint types_length1)
{
	return contacts_typedescriptor_construct_vcard (CONTACTS_TYPE_TYPEDESCRIPTOR, untranslated_name, types, types_length1);
}

/**
   * Creates a TypeDescriptor with a custom label
   */
ContactsTypeDescriptor*
contacts_typedescriptor_construct_custom (GType object_type,
                                          const gchar* name)
{
	ContactsTypeDescriptor * self = NULL;
	gchar* _tmp0_;
	g_return_val_if_fail (name != NULL, NULL);
	self = (ContactsTypeDescriptor*) g_object_new (object_type, NULL);
	self->priv->source = CONTACTS_TYPEDESCRIPTOR_SOURCE_CUSTOM;
	_tmp0_ = g_strdup (name);
	_g_free0 (self->name);
	self->name = _tmp0_;
	return self;
}

ContactsTypeDescriptor*
contacts_typedescriptor_new_custom (const gchar* name)
{
	return contacts_typedescriptor_construct_custom (CONTACTS_TYPE_TYPEDESCRIPTOR, name);
}

/**
   * Creates a TypeDescriptor which represents all non-representable types.
   */
ContactsTypeDescriptor*
contacts_typedescriptor_construct_other (GType object_type)
{
	ContactsTypeDescriptor * self = NULL;
	gchar* _tmp0_;
	self = (ContactsTypeDescriptor*) g_object_new (object_type, NULL);
	self->priv->source = CONTACTS_TYPEDESCRIPTOR_SOURCE_OTHER;
	_tmp0_ = g_strdup (N_ ("Other"));
	_g_free0 (self->name);
	self->name = _tmp0_;
	return self;
}

ContactsTypeDescriptor*
contacts_typedescriptor_new_other (void)
{
	return contacts_typedescriptor_construct_other (CONTACTS_TYPE_TYPEDESCRIPTOR);
}

gboolean
contacts_typedescriptor_is_custom (ContactsTypeDescriptor* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->source == CONTACTS_TYPEDESCRIPTOR_SOURCE_CUSTOM;
	return result;
}

void
contacts_typedescriptor_save_to_field_details (ContactsTypeDescriptor* self,
                                               FolksAbstractFieldDetails* details)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	GeeMultiMap* _tmp2_;
	GeeMultiMap* _tmp3_;
	GeeMultiMap* _tmp4_;
	GeeMultiMap* _tmp5_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (details != NULL);
	_tmp0_ = contacts_typedescriptor_to_string (self);
	_tmp1_ = _tmp0_;
	g_debug ("contacts-type-descriptor.vala:79: Saving type %s to AbsractFieldDetail" \
"s", _tmp1_);
	_g_free0 (_tmp1_);
	_tmp2_ = folks_abstract_field_details_get_parameters (details);
	_tmp3_ = _tmp2_;
	_tmp4_ = contacts_typedescriptor_adapt_parameters (self, _tmp3_);
	_tmp5_ = _tmp4_;
	folks_abstract_field_details_set_parameters (details, _tmp5_);
	_g_object_unref0 (_tmp5_);
}

GeeMultiMap*
contacts_typedescriptor_adapt_parameters (ContactsTypeDescriptor* self,
                                          GeeMultiMap* parameters)
{
	GeeHashMultiMap* _result_ = NULL;
	GeeHashMultiMap* _tmp0_;
	gboolean has_pref = FALSE;
	GeeMultiMap* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (parameters != NULL, NULL);
	_tmp0_ = gee_hash_multi_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_result_ = _tmp0_;
	has_pref = FALSE;
	{
		GeeIterator* _val_it = NULL;
		GeeCollection* _tmp1_;
		GeeCollection* _tmp2_;
		GeeIterator* _tmp3_;
		GeeIterator* _tmp4_;
		_tmp1_ = gee_multi_map_get (parameters, "type");
		_tmp2_ = _tmp1_;
		_tmp3_ = gee_iterable_iterator ((GeeIterable*) _tmp2_);
		_tmp4_ = _tmp3_;
		_g_object_unref0 (_tmp2_);
		_val_it = _tmp4_;
		while (TRUE) {
			GeeIterator* _tmp5_;
			gchar* val = NULL;
			GeeIterator* _tmp6_;
			gpointer _tmp7_;
			const gchar* _tmp8_;
			_tmp5_ = _val_it;
			if (!gee_iterator_next (_tmp5_)) {
				break;
			}
			_tmp6_ = _val_it;
			_tmp7_ = gee_iterator_get (_tmp6_);
			val = (gchar*) _tmp7_;
			_tmp8_ = val;
			if (g_ascii_strcasecmp (_tmp8_, "PREF") == 0) {
				has_pref = TRUE;
				_g_free0 (val);
				break;
			}
			_g_free0 (val);
		}
		_g_object_unref0 (_val_it);
	}
	{
		GeeIterator* _param_it = NULL;
		GeeSet* _tmp9_;
		GeeSet* _tmp10_;
		GeeIterator* _tmp11_;
		GeeIterator* _tmp12_;
		_tmp9_ = gee_multi_map_get_keys (parameters);
		_tmp10_ = _tmp9_;
		_tmp11_ = gee_iterable_iterator ((GeeIterable*) _tmp10_);
		_tmp12_ = _tmp11_;
		_g_object_unref0 (_tmp10_);
		_param_it = _tmp12_;
		while (TRUE) {
			GeeIterator* _tmp13_;
			gchar* param = NULL;
			GeeIterator* _tmp14_;
			gpointer _tmp15_;
			gboolean _tmp16_ = FALSE;
			const gchar* _tmp17_;
			_tmp13_ = _param_it;
			if (!gee_iterator_next (_tmp13_)) {
				break;
			}
			_tmp14_ = _param_it;
			_tmp15_ = gee_iterator_get (_tmp14_);
			param = (gchar*) _tmp15_;
			_tmp17_ = param;
			if (g_strcmp0 (_tmp17_, "type") != 0) {
				const gchar* _tmp18_;
				_tmp18_ = param;
				_tmp16_ = g_strcmp0 (_tmp18_, CONTACTS_TYPEDESCRIPTOR_X_GOOGLE_LABEL) != 0;
			} else {
				_tmp16_ = FALSE;
			}
			if (_tmp16_) {
				{
					GeeIterator* _val_it = NULL;
					const gchar* _tmp19_;
					GeeCollection* _tmp20_;
					GeeCollection* _tmp21_;
					GeeIterator* _tmp22_;
					GeeIterator* _tmp23_;
					_tmp19_ = param;
					_tmp20_ = gee_multi_map_get (parameters, _tmp19_);
					_tmp21_ = _tmp20_;
					_tmp22_ = gee_iterable_iterator ((GeeIterable*) _tmp21_);
					_tmp23_ = _tmp22_;
					_g_object_unref0 (_tmp21_);
					_val_it = _tmp23_;
					while (TRUE) {
						GeeIterator* _tmp24_;
						gchar* val = NULL;
						GeeIterator* _tmp25_;
						gpointer _tmp26_;
						GeeHashMultiMap* _tmp27_;
						const gchar* _tmp28_;
						const gchar* _tmp29_;
						_tmp24_ = _val_it;
						if (!gee_iterator_next (_tmp24_)) {
							break;
						}
						_tmp25_ = _val_it;
						_tmp26_ = gee_iterator_get (_tmp25_);
						val = (gchar*) _tmp26_;
						_tmp27_ = _result_;
						_tmp28_ = param;
						_tmp29_ = val;
						gee_multi_map_set ((GeeMultiMap*) _tmp27_, _tmp28_, _tmp29_);
						_g_free0 (val);
					}
					_g_object_unref0 (_val_it);
				}
			}
			_g_free0 (param);
		}
		_g_object_unref0 (_param_it);
	}
	switch (self->priv->source) {
		case CONTACTS_TYPEDESCRIPTOR_SOURCE_VCARD:
		{
			gchar** _tmp30_;
			gint _tmp30__length1;
			_tmp30_ = self->vcard_types;
			_tmp30__length1 = self->vcard_types_length1;
			{
				gchar** type_collection = NULL;
				gint type_collection_length1 = 0;
				gint _type_collection_size_ = 0;
				gint type_it = 0;
				type_collection = _tmp30_;
				type_collection_length1 = _tmp30__length1;
				for (type_it = 0; type_it < type_collection_length1; type_it = type_it + 1) {
					gchar* _tmp31_;
					gchar* type = NULL;
					_tmp31_ = g_strdup (type_collection[type_it]);
					type = _tmp31_;
					{
						const gchar* _tmp32_;
						_tmp32_ = type;
						if (_tmp32_ != NULL) {
							GeeHashMultiMap* _tmp33_;
							const gchar* _tmp34_;
							_tmp33_ = _result_;
							_tmp34_ = type;
							gee_multi_map_set ((GeeMultiMap*) _tmp33_, "type", _tmp34_);
						}
						_g_free0 (type);
					}
				}
			}
			break;
		}
		case CONTACTS_TYPEDESCRIPTOR_SOURCE_OTHER:
		{
			GeeHashMultiMap* _tmp35_;
			_tmp35_ = _result_;
			gee_multi_map_set ((GeeMultiMap*) _tmp35_, "type", "OTHER");
			break;
		}
		case CONTACTS_TYPEDESCRIPTOR_SOURCE_CUSTOM:
		{
			GeeHashMultiMap* _tmp36_;
			GeeHashMultiMap* _tmp37_;
			const gchar* _tmp38_;
			_tmp36_ = _result_;
			gee_multi_map_set ((GeeMultiMap*) _tmp36_, "type", "OTHER");
			_tmp37_ = _result_;
			_tmp38_ = self->name;
			gee_multi_map_set ((GeeMultiMap*) _tmp37_, CONTACTS_TYPEDESCRIPTOR_X_GOOGLE_LABEL, _tmp38_);
			break;
		}
		default:
		break;
	}
	if (has_pref) {
		GeeHashMultiMap* _tmp39_;
		_tmp39_ = _result_;
		gee_multi_map_set ((GeeMultiMap*) _tmp39_, "type", "PREF");
	}
	result = (GeeMultiMap*) _result_;
	return result;
}

/**
   * Converts the TypeDescriptor to a string. Should only be used for debugging.
   */
static gchar*
_vala_g_strjoinv (const gchar* separator,
                  gchar** str_array,
                  gint str_array_length1)
{
	gboolean _tmp0_ = FALSE;
	gchar* result;
	if (separator == NULL) {
		separator = "";
	}
	if (str_array != NULL) {
		gboolean _tmp1_ = FALSE;
		if (str_array_length1 > 0) {
			_tmp1_ = TRUE;
		} else {
			gboolean _tmp2_ = FALSE;
			if (str_array_length1 == -1) {
				const gchar* _tmp3_;
				_tmp3_ = str_array[0];
				_tmp2_ = _tmp3_ != NULL;
			} else {
				_tmp2_ = FALSE;
			}
			_tmp1_ = _tmp2_;
		}
		_tmp0_ = _tmp1_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		gint i = 0;
		gsize len = 0UL;
		gint _tmp16_;
		gint _tmp17_;
		const gchar* res = NULL;
		void* _tmp18_;
		const gchar* _tmp19_ = NULL;
		const gchar* _tmp20_;
		void* ptr = NULL;
		const gchar* _tmp22_;
		void* _tmp23_;
		const gchar* _tmp33_;
		len = (gsize) 1;
		{
			gboolean _tmp4_ = FALSE;
			i = 0;
			_tmp4_ = TRUE;
			while (TRUE) {
				gboolean _tmp6_ = FALSE;
				gboolean _tmp7_ = FALSE;
				gint _tmp10_ = 0;
				const gchar* _tmp11_;
				if (!_tmp4_) {
					gint _tmp5_;
					_tmp5_ = i;
					i = _tmp5_ + 1;
				}
				_tmp4_ = FALSE;
				if (str_array_length1 != -1) {
					_tmp7_ = i < str_array_length1;
				} else {
					_tmp7_ = FALSE;
				}
				if (_tmp7_) {
					_tmp6_ = TRUE;
				} else {
					gboolean _tmp8_ = FALSE;
					if (str_array_length1 == -1) {
						const gchar* _tmp9_;
						_tmp9_ = str_array[i];
						_tmp8_ = _tmp9_ != NULL;
					} else {
						_tmp8_ = FALSE;
					}
					_tmp6_ = _tmp8_;
				}
				if (!_tmp6_) {
					break;
				}
				_tmp11_ = str_array[i];
				if (_tmp11_ != NULL) {
					const gchar* _tmp12_;
					gint _tmp13_;
					gint _tmp14_;
					_tmp12_ = str_array[i];
					_tmp13_ = strlen ((const gchar*) _tmp12_);
					_tmp14_ = _tmp13_;
					_tmp10_ = _tmp14_;
				} else {
					_tmp10_ = 0;
				}
				len += (gsize) _tmp10_;
			}
		}
		if (i == 0) {
			gchar* _tmp15_;
			_tmp15_ = g_strdup ("");
			result = _tmp15_;
			return result;
		}
		str_array_length1 = i;
		_tmp16_ = strlen ((const gchar*) separator);
		_tmp17_ = _tmp16_;
		len += (gsize) (_tmp17_ * (i - 1));
		_tmp18_ = g_malloc (len);
		res = _tmp18_;
		_tmp20_ = str_array[0];
		if (_tmp20_ != NULL) {
			const gchar* _tmp21_;
			_tmp21_ = str_array[0];
			_tmp19_ = (const gchar*) _tmp21_;
		} else {
			_tmp19_ = "";
		}
		_tmp22_ = res;
		_tmp23_ = g_stpcpy ((void*) _tmp22_, _tmp19_);
		ptr = _tmp23_;
		{
			gboolean _tmp24_ = FALSE;
			i = 1;
			_tmp24_ = TRUE;
			while (TRUE) {
				void* _tmp26_;
				void* _tmp27_;
				const gchar* _tmp28_ = NULL;
				const gchar* _tmp29_;
				void* _tmp31_;
				void* _tmp32_;
				if (!_tmp24_) {
					gint _tmp25_;
					_tmp25_ = i;
					i = _tmp25_ + 1;
				}
				_tmp24_ = FALSE;
				if (!(i < str_array_length1)) {
					break;
				}
				_tmp26_ = ptr;
				_tmp27_ = g_stpcpy (_tmp26_, (const gchar*) separator);
				ptr = _tmp27_;
				_tmp29_ = str_array[i];
				if (_tmp29_ != NULL) {
					const gchar* _tmp30_;
					_tmp30_ = str_array[i];
					_tmp28_ = (const gchar*) _tmp30_;
				} else {
					_tmp28_ = "";
				}
				_tmp31_ = ptr;
				_tmp32_ = g_stpcpy (_tmp31_, _tmp28_);
				ptr = _tmp32_;
			}
		}
		_tmp33_ = res;
		res = NULL;
		result = (gchar*) _tmp33_;
		return result;
	} else {
		gchar* _tmp34_;
		_tmp34_ = g_strdup ("");
		result = _tmp34_;
		return result;
	}
}

gchar*
contacts_typedescriptor_to_string (ContactsTypeDescriptor* self)
{
	GString* str = NULL;
	GString* _tmp0_;
	GString* _tmp1_;
	const gchar* _tmp2_;
	GString* _tmp3_;
	const gchar* _tmp4_;
	GString* _tmp5_;
	const gchar* _tmp6_;
	const gchar* _tmp7_;
	gchar** _tmp8_;
	gint _tmp8__length1;
	GString* _tmp14_;
	const gchar* _tmp15_;
	gchar* _tmp16_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_string_new ("{ ");
	str = _tmp0_;
	_tmp1_ = str;
	_tmp2_ = contacts_typedescriptor_source_to_string (self->priv->source);
	g_string_append_printf (_tmp1_, ".source = %s, ", _tmp2_);
	_tmp3_ = str;
	_tmp4_ = self->name;
	g_string_append_printf (_tmp3_, ".name = \"%s\", ", _tmp4_);
	_tmp5_ = str;
	_tmp6_ = contacts_typedescriptor_get_display_name (self);
	_tmp7_ = _tmp6_;
	g_string_append_printf (_tmp5_, ".display_name = \"%s\", ", _tmp7_);
	_tmp8_ = self->vcard_types;
	_tmp8__length1 = self->vcard_types_length1;
	if (_tmp8_ == NULL) {
		GString* _tmp9_;
		_tmp9_ = str;
		g_string_append_printf (_tmp9_, ".vcard_types = NULL }");
	} else {
		GString* _tmp10_;
		gchar** _tmp11_;
		gint _tmp11__length1;
		gchar* _tmp12_;
		gchar* _tmp13_;
		_tmp10_ = str;
		_tmp11_ = self->vcard_types;
		_tmp11__length1 = self->vcard_types_length1;
		_tmp12_ = _vala_g_strjoinv (", ", _tmp11_, (gint) _tmp11__length1);
		_tmp13_ = _tmp12_;
		g_string_append_printf (_tmp10_, ".vcard_types = [ %s }", _tmp13_);
		_g_free0 (_tmp13_);
	}
	_tmp14_ = str;
	_tmp15_ = _tmp14_->str;
	_tmp16_ = g_strdup (_tmp15_);
	result = _tmp16_;
	_g_string_free0 (str);
	return result;
}

ContactsTypeDescriptor*
contacts_typedescriptor_construct (GType object_type)
{
	ContactsTypeDescriptor * self = NULL;
	self = (ContactsTypeDescriptor*) g_object_new (object_type, NULL);
	return self;
}

ContactsTypeDescriptor*
contacts_typedescriptor_new (void)
{
	return contacts_typedescriptor_construct (CONTACTS_TYPE_TYPEDESCRIPTOR);
}

const gchar*
contacts_typedescriptor_get_display_name (ContactsTypeDescriptor* self)
{
	const gchar* result;
	const gchar* _tmp1_;
	g_return_val_if_fail (self != NULL, NULL);
	if (contacts_typedescriptor_is_custom (self)) {
		const gchar* _tmp0_;
		_tmp0_ = self->name;
		result = _tmp0_;
		return result;
	}
	_tmp1_ = self->name;
	result = g_dgettext (GETTEXT_PACKAGE, _tmp1_);
	return result;
}

static void
contacts_typedescriptor_class_init (ContactsTypeDescriptorClass * klass,
                                    gpointer klass_data)
{
	contacts_typedescriptor_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ContactsTypeDescriptor_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_contacts_typedescriptor_get_property;
	G_OBJECT_CLASS (klass)->finalize = contacts_typedescriptor_finalize;
	/**
	   * Returns the translated name for this property.
	   */
	g_object_class_install_property (G_OBJECT_CLASS (klass), CONTACTS_TYPEDESCRIPTOR_DISPLAY_NAME_PROPERTY, contacts_typedescriptor_properties[CONTACTS_TYPEDESCRIPTOR_DISPLAY_NAME_PROPERTY] = g_param_spec_string ("display-name", "display-name", "display-name", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
contacts_typedescriptor_instance_init (ContactsTypeDescriptor * self,
                                       gpointer klass)
{
	self->priv = contacts_typedescriptor_get_instance_private (self);
	self->name = NULL;
	self->vcard_types = NULL;
	self->vcard_types_length1 = 0;
}

static void
contacts_typedescriptor_finalize (GObject * obj)
{
	ContactsTypeDescriptor * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CONTACTS_TYPE_TYPEDESCRIPTOR, ContactsTypeDescriptor);
	_g_free0 (self->name);
	self->vcard_types = (_vala_array_free (self->vcard_types, self->vcard_types_length1, (GDestroyNotify) g_free), NULL);
	G_OBJECT_CLASS (contacts_typedescriptor_parent_class)->finalize (obj);
}

/**
 * The TypeDescriptor is the internal representation of a property's type.
 */
 G_GNUC_NO_INLINE static GType
contacts_typedescriptor_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ContactsTypeDescriptorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) contacts_typedescriptor_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ContactsTypeDescriptor), 0, (GInstanceInitFunc) contacts_typedescriptor_instance_init, NULL };
	GType contacts_typedescriptor_type_id;
	contacts_typedescriptor_type_id = g_type_register_static (G_TYPE_OBJECT, "ContactsTypeDescriptor", &g_define_type_info, 0);
	ContactsTypeDescriptor_private_offset = g_type_add_instance_private (contacts_typedescriptor_type_id, sizeof (ContactsTypeDescriptorPrivate));
	return contacts_typedescriptor_type_id;
}

GType
contacts_typedescriptor_get_type (void)
{
	static volatile gsize contacts_typedescriptor_type_id__once = 0;
	if (g_once_init_enter (&contacts_typedescriptor_type_id__once)) {
		GType contacts_typedescriptor_type_id;
		contacts_typedescriptor_type_id = contacts_typedescriptor_get_type_once ();
		g_once_init_leave (&contacts_typedescriptor_type_id__once, contacts_typedescriptor_type_id);
	}
	return contacts_typedescriptor_type_id__once;
}

static void
_vala_contacts_typedescriptor_get_property (GObject * object,
                                            guint property_id,
                                            GValue * value,
                                            GParamSpec * pspec)
{
	ContactsTypeDescriptor * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, CONTACTS_TYPE_TYPEDESCRIPTOR, ContactsTypeDescriptor);
	switch (property_id) {
		case CONTACTS_TYPEDESCRIPTOR_DISPLAY_NAME_PROPERTY:
		g_value_set_string (value, contacts_typedescriptor_get_display_name (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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

