/* kf-persona-store.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from kf-persona-store.vala, do not modify */

/*
 * Copyright (C) 2010 Collabora Ltd.
 *
 * 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 2.1 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, see <http://www.gnu.org/licenses/>.
 *
 * Authors:
 *       Travis Reitter <travis.reitter@collabora.co.uk>
 *       Philip Withnall <philip.withnall@collabora.co.uk>
 */

#include "key-file.h"
#include <gee.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>
#include "folks/folks.h"
#include "folks-internal.h"
#include <glib/gi18n-lib.h>
#include "folks/small-set.h"

#define FOLKS_BACKENDS_KF_PERSONA_STORE_anti_links_key_name "__anti-links"
#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  {
	FOLKS_BACKENDS_KF_PERSONA_STORE_0_PROPERTY,
	FOLKS_BACKENDS_KF_PERSONA_STORE_TYPE_ID_PROPERTY,
	FOLKS_BACKENDS_KF_PERSONA_STORE_CAN_ADD_PERSONAS_PROPERTY,
	FOLKS_BACKENDS_KF_PERSONA_STORE_CAN_ALIAS_PERSONAS_PROPERTY,
	FOLKS_BACKENDS_KF_PERSONA_STORE_CAN_GROUP_PERSONAS_PROPERTY,
	FOLKS_BACKENDS_KF_PERSONA_STORE_CAN_REMOVE_PERSONAS_PROPERTY,
	FOLKS_BACKENDS_KF_PERSONA_STORE_IS_PREPARED_PROPERTY,
	FOLKS_BACKENDS_KF_PERSONA_STORE_IS_QUIESCENT_PROPERTY,
	FOLKS_BACKENDS_KF_PERSONA_STORE_ALWAYS_WRITEABLE_PROPERTIES_PROPERTY,
	FOLKS_BACKENDS_KF_PERSONA_STORE_PERSONAS_PROPERTY,
	FOLKS_BACKENDS_KF_PERSONA_STORE_FILE_PROPERTY,
	FOLKS_BACKENDS_KF_PERSONA_STORE_NUM_PROPERTIES
};
static GParamSpec* folks_backends_kf_persona_store_properties[FOLKS_BACKENDS_KF_PERSONA_STORE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_key_file_unref0(var) ((var == NULL) ? NULL : (var = (g_key_file_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _folks_internal_profile_block_free0(var) ((var == NULL) ? NULL : (var = (folks_internal_profile_block_free (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _FolksBackendsKfPersonaStorePrepareData FolksBackendsKfPersonaStorePrepareData;
#define _g_main_context_unref0(var) ((var == NULL) ? NULL : (var = (g_main_context_unref (var), NULL)))
typedef struct _FolksBackendsKfPersonaStoreFlushData FolksBackendsKfPersonaStoreFlushData;
typedef struct _FolksBackendsKfPersonaStoreRemovePersonaData FolksBackendsKfPersonaStoreRemovePersonaData;
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
typedef struct _FolksBackendsKfPersonaStoreAddPersonaFromDetailsData FolksBackendsKfPersonaStoreAddPersonaFromDetailsData;
typedef struct _FolksBackendsKfPersonaStoreSaveKeyFileData FolksBackendsKfPersonaStoreSaveKeyFileData;

struct _FolksBackendsKfPersonaStorePrivate {
	GeeHashMap* _personas;
	GeeMap* _personas_ro;
	GKeyFile* _key_file;
	GCancellable* _save_key_file_cancellable;
	gboolean _is_prepared;
	gboolean _prepare_pending;
	gboolean _is_quiescent;
	GFile* _file;
};

struct _FolksBackendsKfPersonaStorePrepareData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	FolksBackendsKfPersonaStore* self;
	FolksInternalProfileBlock* profiling;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	FolksInternalProfileBlock* _tmp2_;
	gboolean _tmp3_;
	gchar* filename;
	GFile* _tmp4_;
	gchar* _tmp5_;
	GKeyFile* _tmp6_;
	guint8* contents;
	gint contents_length1;
	gint _contents_size_;
	GFile* _tmp7_;
	guint8* _tmp8_;
	gsize _tmp9_;
	const gchar* contents_s;
	guint8* _tmp10_;
	gint _tmp10__length1;
	const gchar* _tmp11_;
	const gchar* _tmp12_;
	const gchar* _tmp13_;
	gint _tmp14_;
	gint _tmp15_;
	GKeyFile* _tmp16_;
	const gchar* _tmp17_;
	const gchar* _tmp18_;
	gint _tmp19_;
	gint _tmp20_;
	const gchar* _tmp21_;
	const gchar* _tmp22_;
	GError* e1;
	GError* _tmp23_;
	const gchar* _tmp24_;
	GError* _tmp25_;
	const gchar* _tmp26_;
	GFile* parent_dir;
	GFile* _tmp27_;
	GFile* _tmp28_;
	GFile* _tmp29_;
	GError* e3;
	GError* _tmp30_;
	GFile* _tmp31_;
	gchar* _tmp32_;
	gchar* _tmp33_;
	GError* _tmp34_;
	const gchar* _tmp35_;
	GFileOutputStream* stream;
	GFile* _tmp36_;
	GFileOutputStream* _tmp37_;
	GFileOutputStream* _tmp38_;
	GError* e2;
	GError* _tmp39_;
	const gchar* _tmp40_;
	GError* _tmp41_;
	const gchar* _tmp42_;
	gchar** groups;
	GKeyFile* _tmp43_;
	gsize _tmp44_;
	gchar** _tmp45_;
	gint groups_length1;
	gint _groups_size_;
	GeeHashSet* added_personas;
	GeeHashSet* _tmp46_;
	gchar** _tmp47_;
	gint _tmp47__length1;
	gchar** persona_id_collection;
	gint persona_id_collection_length1;
	gint _persona_id_collection_size_;
	gint persona_id_it;
	gchar* _tmp48_;
	gchar* persona_id;
	FolksBackendsKfPersona* persona;
	const gchar* _tmp49_;
	FolksBackendsKfPersona* _tmp50_;
	GeeHashMap* _tmp51_;
	FolksBackendsKfPersona* _tmp52_;
	const gchar* _tmp53_;
	const gchar* _tmp54_;
	FolksBackendsKfPersona* _tmp55_;
	GeeHashSet* _tmp56_;
	FolksBackendsKfPersona* _tmp57_;
	GeeHashMap* _tmp58_;
	gint _tmp59_;
	gint _tmp60_;
	GeeHashSet* _tmp61_;
	FolksInternalProfileBlock* _tmp62_;
	GError* _inner_error0_;
};

struct _FolksBackendsKfPersonaStoreFlushData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	FolksBackendsKfPersonaStore* self;
	GMainContext* context;
	GMainContext* _tmp0_;
	GMainContext* _tmp1_;
	GCancellable* _tmp2_;
	GMainContext* _tmp3_;
};

struct _FolksBackendsKfPersonaStoreRemovePersonaData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	FolksBackendsKfPersonaStore* self;
	FolksPersona* persona;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_;
	const gchar* _tmp5_;
	GKeyFile* _tmp6_;
	const gchar* _tmp7_;
	const gchar* _tmp8_;
	FolksSmallSet* personas;
	FolksSmallSet* _tmp9_;
	FolksSmallSet* _tmp10_;
	FolksSmallSet* _tmp11_;
	GError* _inner_error0_;
};

struct _FolksBackendsKfPersonaStoreAddPersonaFromDetailsData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	FolksBackendsKfPersonaStore* self;
	GHashTable* details;
	FolksPersona* result;
	GValue* val;
	const gchar* _tmp0_;
	gconstpointer _tmp1_;
	GeeMultiMap* _tmp2_;
	GValue* _tmp3_;
	GValue* _tmp4_;
	GObject* _tmp5_;
	GeeMultiMap* im_addresses;
	GeeMultiMap* _tmp6_;
	GValue* val2;
	const gchar* _tmp7_;
	gconstpointer _tmp8_;
	GeeMultiMap* _tmp9_;
	GValue* _tmp10_;
	GValue* _tmp11_;
	GObject* _tmp12_;
	GeeMultiMap* web_service_addresses;
	GeeMultiMap* _tmp13_;
	GValue* val3;
	const gchar* _tmp14_;
	gconstpointer _tmp15_;
	GeeSet* _tmp16_;
	GValue* _tmp17_;
	GValue* _tmp18_;
	GObject* _tmp19_;
	GeeSet* local_ids;
	GeeSet* _tmp20_;
	gchar* persona_id;
	gboolean _tmp21_;
	GKeyFile* _tmp22_;
	const gchar* _tmp23_;
	gchar* _tmp24_;
	FolksBackendsKfPersona* persona;
	const gchar* _tmp25_;
	FolksBackendsKfPersona* _tmp26_;
	GeeHashMap* _tmp27_;
	FolksBackendsKfPersona* _tmp28_;
	const gchar* _tmp29_;
	const gchar* _tmp30_;
	FolksBackendsKfPersona* _tmp31_;
	GeeSet* _tmp32_;
	FolksBackendsKfPersona* _tmp33_;
	GeeSet* _tmp34_;
	GeeMultiMap* _tmp35_;
	FolksBackendsKfPersona* _tmp36_;
	GeeMultiMap* _tmp37_;
	GeeMultiMap* _tmp38_;
	FolksBackendsKfPersona* _tmp39_;
	GeeMultiMap* _tmp40_;
	GError* e;
	GError* _tmp41_;
	const gchar* _tmp42_;
	GError* _tmp43_;
	FolksSmallSet* personas;
	FolksSmallSet* _tmp44_;
	FolksBackendsKfPersona* _tmp45_;
	GError* _inner_error0_;
};

struct _FolksBackendsKfPersonaStoreSaveKeyFileData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	FolksBackendsKfPersonaStore* self;
	gchar* key_file_data;
	GKeyFile* _tmp0_;
	gchar* _tmp1_;
	GCancellable* cancellable;
	GCancellable* _tmp2_;
	GFile* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	GCancellable* _tmp6_;
	GCancellable* _tmp7_;
	GCancellable* _tmp8_;
	GFile* _tmp9_;
	const gchar* _tmp10_;
	guint8* _tmp11_;
	gint _tmp11__length1;
	gint _tmp12_;
	guint8* _tmp13_;
	gint _tmp13__length1;
	GCancellable* _tmp14_;
	GError* e;
	GError* _tmp15_;
	GFile* _tmp16_;
	gchar* _tmp17_;
	gchar* _tmp18_;
	GError* _tmp19_;
	const gchar* _tmp20_;
	GCancellable* _tmp21_;
	GCancellable* _tmp22_;
	GError* _inner_error0_;
};

static gint FolksBackendsKfPersonaStore_private_offset;
static gpointer folks_backends_kf_persona_store_parent_class = NULL;

static void folks_backends_kf_persona_store_real_prepare_data_free (gpointer _data);
static void folks_backends_kf_persona_store_real_prepare (FolksPersonaStore* base,
                                                   GAsyncReadyCallback _callback_,
                                                   gpointer _user_data_);
static gboolean folks_backends_kf_persona_store_real_prepare_co (FolksBackendsKfPersonaStorePrepareData* _data_);
static void folks_backends_kf_persona_store_prepare_ready (GObject* source_object,
                                                    GAsyncResult* _res_,
                                                    gpointer _user_data_);
static void folks_backends_kf_persona_store_real_flush_data_free (gpointer _data);
static void folks_backends_kf_persona_store_real_flush (FolksPersonaStore* base,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_);
static gboolean folks_backends_kf_persona_store_real_flush_co (FolksBackendsKfPersonaStoreFlushData* _data_);
static void folks_backends_kf_persona_store_real_remove_persona_data_free (gpointer _data);
static void folks_backends_kf_persona_store_real_remove_persona (FolksPersonaStore* base,
                                                          FolksPersona* persona,
                                                          GAsyncReadyCallback _callback_,
                                                          gpointer _user_data_);
static gboolean folks_backends_kf_persona_store_real_remove_persona_co (FolksBackendsKfPersonaStoreRemovePersonaData* _data_);
VALA_EXTERN void folks_backends_kf_persona_store_save_key_file (FolksBackendsKfPersonaStore* self,
                                                    GAsyncReadyCallback _callback_,
                                                    gpointer _user_data_);
VALA_EXTERN void folks_backends_kf_persona_store_save_key_file_finish (FolksBackendsKfPersonaStore* self,
                                                           GAsyncResult* _res_);
static void folks_backends_kf_persona_store_remove_persona_ready (GObject* source_object,
                                                           GAsyncResult* _res_,
                                                           gpointer _user_data_);
static void folks_backends_kf_persona_store_real_add_persona_from_details_data_free (gpointer _data);
static void folks_backends_kf_persona_store_real_add_persona_from_details (FolksPersonaStore* base,
                                                                    GHashTable* details,
                                                                    GAsyncReadyCallback _callback_,
                                                                    gpointer _user_data_);
static gboolean folks_backends_kf_persona_store_real_add_persona_from_details_co (FolksBackendsKfPersonaStoreAddPersonaFromDetailsData* _data_);
static void folks_backends_kf_persona_store_add_persona_from_details_ready (GObject* source_object,
                                                                     GAsyncResult* _res_,
                                                                     gpointer _user_data_);
VALA_EXTERN GKeyFile* folks_backends_kf_persona_store_get_key_file (FolksBackendsKfPersonaStore* self);
static void folks_backends_kf_persona_store_save_key_file_data_free (gpointer _data);
static gboolean folks_backends_kf_persona_store_save_key_file_co (FolksBackendsKfPersonaStoreSaveKeyFileData* _data_);
static void folks_backends_kf_persona_store_save_key_file_ready (GObject* source_object,
                                                          GAsyncResult* _res_,
                                                          gpointer _user_data_);
static GObject * folks_backends_kf_persona_store_constructor (GType type,
                                                       guint n_construct_properties,
                                                       GObjectConstructParam * construct_properties);
static void folks_backends_kf_persona_store_finalize (GObject * obj);
static GType folks_backends_kf_persona_store_get_type_once (void);
static void _vala_folks_backends_kf_persona_store_get_property (GObject * object,
                                                         guint property_id,
                                                         GValue * value,
                                                         GParamSpec * pspec);
static void _vala_folks_backends_kf_persona_store_set_property (GObject * object,
                                                         guint property_id,
                                                         const 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 const gchar* FOLKS_BACKENDS_KF_PERSONA_STORE__always_writeable_properties[6] = {"alias", "im-addresses", "web-service-addresses", "local-ids", "anti-links", NULL};

static inline gpointer
folks_backends_kf_persona_store_get_instance_private (FolksBackendsKfPersonaStore* self)
{
	return G_STRUCT_MEMBER_P (self, FolksBackendsKfPersonaStore_private_offset);
}

/**
   * Create a new PersonaStore.
   *
   * Create a new persona store to expose the {@link Persona}s provided by the
   * different groups in the key file given by ``key_file``.
   */
FolksBackendsKfPersonaStore*
folks_backends_kf_persona_store_construct (GType object_type,
                                           GFile* key_file)
{
	FolksBackendsKfPersonaStore * self = NULL;
	gchar* id = NULL;
	gchar* _tmp0_;
	g_return_val_if_fail (key_file != NULL, NULL);
	_tmp0_ = g_file_get_basename (key_file);
	id = _tmp0_;
	self = (FolksBackendsKfPersonaStore*) g_object_new (object_type, "id", id, "display-name", id, "file", key_file, NULL);
	_g_free0 (id);
	return self;
}

FolksBackendsKfPersonaStore*
folks_backends_kf_persona_store_new (GFile* key_file)
{
	return folks_backends_kf_persona_store_construct (FOLKS_BACKENDS_KF_TYPE_PERSONA_STORE, key_file);
}

static void
folks_backends_kf_persona_store_real_prepare_data_free (gpointer _data)
{
	FolksBackendsKfPersonaStorePrepareData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (FolksBackendsKfPersonaStorePrepareData, _data_);
}

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

static void
folks_backends_kf_persona_store_real_prepare (FolksPersonaStore* base,
                                              GAsyncReadyCallback _callback_,
                                              gpointer _user_data_)
{
	FolksBackendsKfPersonaStore * self;
	FolksBackendsKfPersonaStorePrepareData* _data_;
	FolksBackendsKfPersonaStore* _tmp0_;
	self = (FolksBackendsKfPersonaStore*) base;
	_data_ = g_slice_new0 (FolksBackendsKfPersonaStorePrepareData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, folks_backends_kf_persona_store_real_prepare_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	folks_backends_kf_persona_store_real_prepare_co (_data_);
}

static void
folks_backends_kf_persona_store_prepare_finish (FolksPersonaStore* base,
                                                GAsyncResult* _res_,
                                                GError** error)
{
	FolksBackendsKfPersonaStorePrepareData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

/**
   * {@inheritDoc}
   */
static void
folks_backends_kf_persona_store_prepare_ready (GObject* source_object,
                                               GAsyncResult* _res_,
                                               gpointer _user_data_)
{
	FolksBackendsKfPersonaStorePrepareData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	folks_backends_kf_persona_store_real_prepare_co (_data_);
}

static gboolean
folks_backends_kf_persona_store_real_prepare_co (FolksBackendsKfPersonaStorePrepareData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = folks_persona_store_get_id ((FolksPersonaStore*) _data_->self);
	_data_->_tmp1_ = _data_->_tmp0_;
	_data_->_tmp2_ = folks_internal_profiling_start ("preparing Kf.PersonaStore (ID: %s)", _data_->_tmp1_, NULL);
	_data_->profiling = _data_->_tmp2_;
	if (_data_->self->priv->_is_prepared) {
		_data_->_tmp3_ = TRUE;
	} else {
		_data_->_tmp3_ = _data_->self->priv->_prepare_pending;
	}
	if (_data_->_tmp3_) {
		_folks_internal_profile_block_free0 (_data_->profiling);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	{
		_data_->self->priv->_prepare_pending = TRUE;
		_data_->_tmp4_ = _data_->self->priv->_file;
		_data_->_tmp5_ = g_file_get_path (_data_->_tmp4_);
		_data_->filename = _data_->_tmp5_;
		_data_->_tmp6_ = g_key_file_new ();
		_g_key_file_unref0 (_data_->self->priv->_key_file);
		_data_->self->priv->_key_file = _data_->_tmp6_;
		while (TRUE) {
			{
				_data_->contents_length1 = 0;
				_data_->_contents_size_ = 0;
				_data_->_tmp7_ = _data_->self->priv->_file;
				_data_->_tmp8_ = NULL;
				_data_->_tmp9_ = 0;
				_data_->_state_ = 1;
				g_file_load_contents_async (_data_->_tmp7_, NULL, folks_backends_kf_persona_store_prepare_ready, _data_);
				return FALSE;
				_state_1:
				g_file_load_contents_finish (_data_->_tmp7_, _data_->_res_, &_data_->_tmp8_, &_data_->_tmp9_, NULL, &_data_->_inner_error0_);
				_data_->contents = (g_free (_data_->contents), NULL);
				_data_->contents = _data_->_tmp8_;
				_data_->contents_length1 = _data_->_tmp9_;
				_data_->_contents_size_ = _data_->contents_length1;
				if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
					_data_->contents = (g_free (_data_->contents), NULL);
					goto __catch1_g_error;
				}
				_data_->_tmp10_ = _data_->contents;
				_data_->_tmp10__length1 = _data_->contents_length1;
				_data_->contents_s = (const gchar*) _data_->_tmp10_;
				_data_->_tmp11_ = folks_persona_store_get_id ((FolksPersonaStore*) _data_->self);
				_data_->_tmp12_ = _data_->_tmp11_;
				folks_internal_profiling_point ("loaded file in " "Kf.PersonaStore (ID: %s)", _data_->_tmp12_);
				_data_->_tmp13_ = _data_->contents_s;
				_data_->_tmp14_ = strlen (_data_->_tmp13_);
				_data_->_tmp15_ = _data_->_tmp14_;
				if (_data_->_tmp15_ > 0) {
					_data_->_tmp16_ = _data_->self->priv->_key_file;
					_data_->_tmp17_ = _data_->contents_s;
					_data_->_tmp18_ = _data_->contents_s;
					_data_->_tmp19_ = strlen (_data_->_tmp18_);
					_data_->_tmp20_ = _data_->_tmp19_;
					g_key_file_load_from_data (_data_->_tmp16_, _data_->_tmp17_, (gsize) _data_->_tmp20_, G_KEY_FILE_KEEP_COMMENTS, &_data_->_inner_error0_);
					if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
						_data_->contents = (g_free (_data_->contents), NULL);
						goto __catch1_g_error;
					}
					_data_->_tmp21_ = folks_persona_store_get_id ((FolksPersonaStore*) _data_->self);
					_data_->_tmp22_ = _data_->_tmp21_;
					folks_internal_profiling_point ("parsed data in " "Kf.PersonaStore (ID: %s)", _data_->_tmp22_);
				}
				_data_->contents = (g_free (_data_->contents), NULL);
				break;
			}
			goto __finally1;
			__catch1_g_error:
			{
				_data_->e1 = _data_->_inner_error0_;
				_data_->_inner_error0_ = NULL;
				_data_->_tmp23_ = _data_->e1;
				if (!g_error_matches (_data_->_tmp23_, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) {
					_data_->_tmp24_ = _data_->filename;
					_data_->_tmp25_ = _data_->e1;
					_data_->_tmp26_ = _data_->_tmp25_->message;
					g_warning (_ ("The relationship key file ‘%s’ could not be loaded: %s"), _data_->_tmp24_, _data_->_tmp26_);
					g_signal_emit_by_name ((FolksPersonaStore*) _data_->self, "removed");
					_g_error_free0 (_data_->e1);
					_g_free0 (_data_->filename);
					{
						_data_->self->priv->_prepare_pending = FALSE;
					}
					_folks_internal_profile_block_free0 (_data_->profiling);
					g_task_return_pointer (_data_->_async_result, _data_, NULL);
					if (_data_->_state_ != 0) {
						while (!g_task_get_completed (_data_->_async_result)) {
							g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
						}
					}
					g_object_unref (_data_->_async_result);
					return FALSE;
				}
				_g_error_free0 (_data_->e1);
			}
			__finally1:
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_free0 (_data_->filename);
				_folks_internal_profile_block_free0 (_data_->profiling);
				g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
				g_clear_error (&_data_->_inner_error0_);
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
			_data_->_tmp27_ = _data_->self->priv->_file;
			_data_->_tmp28_ = g_file_get_parent (_data_->_tmp27_);
			_data_->parent_dir = _data_->_tmp28_;
			{
				_data_->_tmp29_ = _data_->parent_dir;
				g_file_make_directory_with_parents (_data_->_tmp29_, NULL, &_data_->_inner_error0_);
				if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
					goto __catch2_g_error;
				}
			}
			goto __finally2;
			__catch2_g_error:
			{
				_data_->e3 = _data_->_inner_error0_;
				_data_->_inner_error0_ = NULL;
				_data_->_tmp30_ = _data_->e3;
				if (!g_error_matches (_data_->_tmp30_, G_IO_ERROR, G_IO_ERROR_EXISTS)) {
					_data_->_tmp31_ = _data_->parent_dir;
					_data_->_tmp32_ = g_file_get_path (_data_->_tmp31_);
					_data_->_tmp33_ = _data_->_tmp32_;
					_data_->_tmp34_ = _data_->e3;
					_data_->_tmp35_ = _data_->_tmp34_->message;
					g_warning (_ ("The relationship key file directory ‘%s’ could not be created: %s"), _data_->_tmp33_, _data_->_tmp35_);
					_g_free0 (_data_->_tmp33_);
					g_signal_emit_by_name ((FolksPersonaStore*) _data_->self, "removed");
					_g_error_free0 (_data_->e3);
					_g_object_unref0 (_data_->parent_dir);
					_g_free0 (_data_->filename);
					{
						_data_->self->priv->_prepare_pending = FALSE;
					}
					_folks_internal_profile_block_free0 (_data_->profiling);
					g_task_return_pointer (_data_->_async_result, _data_, NULL);
					if (_data_->_state_ != 0) {
						while (!g_task_get_completed (_data_->_async_result)) {
							g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
						}
					}
					g_object_unref (_data_->_async_result);
					return FALSE;
				}
				_g_error_free0 (_data_->e3);
			}
			__finally2:
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_object_unref0 (_data_->parent_dir);
				_g_free0 (_data_->filename);
				_folks_internal_profile_block_free0 (_data_->profiling);
				g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
				g_clear_error (&_data_->_inner_error0_);
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
			{
				_data_->_tmp36_ = _data_->self->priv->_file;
				_data_->_state_ = 2;
				g_file_create_async (_data_->_tmp36_, G_FILE_CREATE_PRIVATE, G_PRIORITY_DEFAULT, NULL, folks_backends_kf_persona_store_prepare_ready, _data_);
				return FALSE;
				_state_2:
				_data_->_tmp37_ = g_file_create_finish (_data_->_tmp36_, _data_->_res_, &_data_->_inner_error0_);
				_data_->stream = _data_->_tmp37_;
				if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
					goto __catch3_g_error;
				}
				_data_->_tmp38_ = _data_->stream;
				_data_->_state_ = 3;
				g_output_stream_close_async ((GOutputStream*) _data_->_tmp38_, G_PRIORITY_DEFAULT, NULL, folks_backends_kf_persona_store_prepare_ready, _data_);
				return FALSE;
				_state_3:
				g_output_stream_close_finish ((GOutputStream*) _data_->_tmp38_, _data_->_res_, &_data_->_inner_error0_);
				if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
					_g_object_unref0 (_data_->stream);
					goto __catch3_g_error;
				}
				_g_object_unref0 (_data_->stream);
			}
			goto __finally3;
			__catch3_g_error:
			{
				_data_->e2 = _data_->_inner_error0_;
				_data_->_inner_error0_ = NULL;
				_data_->_tmp39_ = _data_->e2;
				if (!g_error_matches (_data_->_tmp39_, G_IO_ERROR, G_IO_ERROR_EXISTS)) {
					_data_->_tmp40_ = _data_->filename;
					_data_->_tmp41_ = _data_->e2;
					_data_->_tmp42_ = _data_->_tmp41_->message;
					g_warning (_ ("The relationship key file ‘%s’ could not be created: %s"), _data_->_tmp40_, _data_->_tmp42_);
					g_signal_emit_by_name ((FolksPersonaStore*) _data_->self, "removed");
					_g_error_free0 (_data_->e2);
					_g_object_unref0 (_data_->parent_dir);
					_g_free0 (_data_->filename);
					{
						_data_->self->priv->_prepare_pending = FALSE;
					}
					_folks_internal_profile_block_free0 (_data_->profiling);
					g_task_return_pointer (_data_->_async_result, _data_, NULL);
					if (_data_->_state_ != 0) {
						while (!g_task_get_completed (_data_->_async_result)) {
							g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
						}
					}
					g_object_unref (_data_->_async_result);
					return FALSE;
				}
				_g_error_free0 (_data_->e2);
			}
			__finally3:
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_object_unref0 (_data_->parent_dir);
				_g_free0 (_data_->filename);
				_folks_internal_profile_block_free0 (_data_->profiling);
				g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
				g_clear_error (&_data_->_inner_error0_);
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
			_g_object_unref0 (_data_->parent_dir);
		}
		_data_->_tmp43_ = _data_->self->priv->_key_file;
		_data_->_tmp44_ = 0;
		_data_->_tmp45_ = g_key_file_get_groups (_data_->_tmp43_, &_data_->_tmp44_);
		_data_->groups = _data_->_tmp45_;
		_data_->groups_length1 = _data_->_tmp44_;
		_data_->_groups_size_ = _data_->groups_length1;
		_data_->_tmp46_ = gee_hash_set_new (FOLKS_BACKENDS_KF_TYPE_PERSONA, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL);
		_data_->added_personas = _data_->_tmp46_;
		_data_->_tmp47_ = _data_->groups;
		_data_->_tmp47__length1 = _data_->groups_length1;
		{
			_data_->persona_id_collection_length1 = 0;
			_data_->_persona_id_collection_size_ = 0;
			_data_->persona_id_collection = _data_->_tmp47_;
			_data_->persona_id_collection_length1 = _data_->_tmp47__length1;
			for (_data_->persona_id_it = 0; _data_->persona_id_it < _data_->persona_id_collection_length1; _data_->persona_id_it = _data_->persona_id_it + 1) {
				_data_->_tmp48_ = g_strdup (_data_->persona_id_collection[_data_->persona_id_it]);
				_data_->persona_id = _data_->_tmp48_;
				{
					_data_->_tmp49_ = _data_->persona_id;
					_data_->_tmp50_ = folks_backends_kf_persona_new (_data_->_tmp49_, (FolksPersonaStore*) _data_->self);
					_data_->persona = _data_->_tmp50_;
					_data_->_tmp51_ = _data_->self->priv->_personas;
					_data_->_tmp52_ = _data_->persona;
					_data_->_tmp53_ = folks_persona_get_iid ((FolksPersona*) _data_->_tmp52_);
					_data_->_tmp54_ = _data_->_tmp53_;
					_data_->_tmp55_ = _data_->persona;
					gee_abstract_map_set ((GeeAbstractMap*) _data_->_tmp51_, _data_->_tmp54_, _data_->_tmp55_);
					_data_->_tmp56_ = _data_->added_personas;
					_data_->_tmp57_ = _data_->persona;
					gee_abstract_collection_add ((GeeAbstractCollection*) _data_->_tmp56_, _data_->_tmp57_);
					_g_object_unref0 (_data_->persona);
					_g_free0 (_data_->persona_id);
				}
			}
		}
		_data_->_tmp58_ = _data_->self->priv->_personas;
		_data_->_tmp59_ = gee_abstract_map_get_size ((GeeAbstractMap*) _data_->_tmp58_);
		_data_->_tmp60_ = _data_->_tmp59_;
		if (_data_->_tmp60_ > 0) {
			_data_->_tmp61_ = _data_->added_personas;
			_folks_persona_store_emit_personas_changed ((FolksPersonaStore*) _data_->self, (GeeSet*) _data_->_tmp61_, NULL, NULL, NULL, FOLKS_GROUP_DETAILS_CHANGE_REASON_NONE);
		}
		_data_->self->priv->_is_prepared = TRUE;
		g_object_notify ((GObject*) _data_->self, "is-prepared");
		_data_->self->priv->_is_quiescent = TRUE;
		g_object_notify ((GObject*) _data_->self, "is-quiescent");
		_g_object_unref0 (_data_->added_personas);
		_data_->groups = (_vala_array_free (_data_->groups, _data_->groups_length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (_data_->filename);
	}
	__finally0:
	{
		_data_->self->priv->_prepare_pending = FALSE;
	}
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_folks_internal_profile_block_free0 (_data_->profiling);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp62_ = _data_->profiling;
	_data_->profiling = NULL;
	folks_internal_profiling_end (_data_->_tmp62_);
	_folks_internal_profile_block_free0 (_data_->profiling);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
folks_backends_kf_persona_store_real_flush_data_free (gpointer _data)
{
	FolksBackendsKfPersonaStoreFlushData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (FolksBackendsKfPersonaStoreFlushData, _data_);
}

static void
folks_backends_kf_persona_store_real_flush (FolksPersonaStore* base,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_)
{
	FolksBackendsKfPersonaStore * self;
	FolksBackendsKfPersonaStoreFlushData* _data_;
	FolksBackendsKfPersonaStore* _tmp0_;
	self = (FolksBackendsKfPersonaStore*) base;
	_data_ = g_slice_new0 (FolksBackendsKfPersonaStoreFlushData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, folks_backends_kf_persona_store_real_flush_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	folks_backends_kf_persona_store_real_flush_co (_data_);
}

static void
folks_backends_kf_persona_store_flush_finish (FolksPersonaStore* base,
                                              GAsyncResult* _res_)
{
	FolksBackendsKfPersonaStoreFlushData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

/**
   * {@inheritDoc}
   */
static gpointer
_g_main_context_ref0 (gpointer self)
{
	return self ? g_main_context_ref (self) : NULL;
}

static gboolean
folks_backends_kf_persona_store_real_flush_co (FolksBackendsKfPersonaStoreFlushData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = g_main_context_default ();
	_data_->_tmp1_ = _g_main_context_ref0 (_data_->_tmp0_);
	_data_->context = _data_->_tmp1_;
	while (TRUE) {
		_data_->_tmp2_ = _data_->self->priv->_save_key_file_cancellable;
		if (!(_data_->_tmp2_ != NULL)) {
			break;
		}
		_data_->_tmp3_ = _data_->context;
		g_main_context_iteration (_data_->_tmp3_, TRUE);
	}
	_g_main_context_unref0 (_data_->context);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
folks_backends_kf_persona_store_real_remove_persona_data_free (gpointer _data)
{
	FolksBackendsKfPersonaStoreRemovePersonaData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->persona);
	_g_object_unref0 (_data_->self);
	g_slice_free (FolksBackendsKfPersonaStoreRemovePersonaData, _data_);
}

static void
folks_backends_kf_persona_store_real_remove_persona (FolksPersonaStore* base,
                                                     FolksPersona* persona,
                                                     GAsyncReadyCallback _callback_,
                                                     gpointer _user_data_)
{
	FolksBackendsKfPersonaStore * self;
	FolksBackendsKfPersonaStoreRemovePersonaData* _data_;
	FolksBackendsKfPersonaStore* _tmp0_;
	FolksPersona* _tmp1_;
	g_return_if_fail (persona != NULL);
	self = (FolksBackendsKfPersonaStore*) base;
	_data_ = g_slice_new0 (FolksBackendsKfPersonaStoreRemovePersonaData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, folks_backends_kf_persona_store_real_remove_persona_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (persona);
	_g_object_unref0 (_data_->persona);
	_data_->persona = _tmp1_;
	folks_backends_kf_persona_store_real_remove_persona_co (_data_);
}

static void
folks_backends_kf_persona_store_remove_persona_finish (FolksPersonaStore* base,
                                                       GAsyncResult* _res_,
                                                       GError** error)
{
	FolksBackendsKfPersonaStoreRemovePersonaData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

/**
   * {@inheritDoc}
   */
static void
folks_backends_kf_persona_store_remove_persona_ready (GObject* source_object,
                                                      GAsyncResult* _res_,
                                                      gpointer _user_data_)
{
	FolksBackendsKfPersonaStoreRemovePersonaData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	folks_backends_kf_persona_store_real_remove_persona_co (_data_);
}

static gboolean
folks_backends_kf_persona_store_real_remove_persona_co (FolksBackendsKfPersonaStoreRemovePersonaData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = folks_persona_get_uid (_data_->persona);
	_data_->_tmp1_ = _data_->_tmp0_;
	_data_->_tmp2_ = folks_persona_get_iid (_data_->persona);
	_data_->_tmp3_ = _data_->_tmp2_;
	_data_->_tmp4_ = folks_persona_get_display_id (_data_->persona);
	_data_->_tmp5_ = _data_->_tmp4_;
	g_debug ("kf-persona-store.vala:342: Removing Persona '%s' (IID '%s', group '%s'" \
")", _data_->_tmp1_, _data_->_tmp3_, _data_->_tmp5_);
	{
		_data_->_tmp6_ = _data_->self->priv->_key_file;
		_data_->_tmp7_ = folks_persona_get_display_id (_data_->persona);
		_data_->_tmp8_ = _data_->_tmp7_;
		g_key_file_remove_group (_data_->_tmp6_, _data_->_tmp8_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			if (_data_->_inner_error0_->domain == G_KEY_FILE_ERROR) {
				goto __catch0_g_key_file_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
			g_clear_error (&_data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_state_ = 1;
		folks_backends_kf_persona_store_save_key_file (_data_->self, folks_backends_kf_persona_store_remove_persona_ready, _data_);
		return FALSE;
		_state_1:
		folks_backends_kf_persona_store_save_key_file_finish (_data_->self, _data_->_res_);
		_data_->_tmp9_ = folks_small_set_new (FOLKS_TYPE_PERSONA, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL);
		_data_->personas = _data_->_tmp9_;
		_data_->_tmp10_ = _data_->personas;
		gee_abstract_collection_add ((GeeAbstractCollection*) _data_->_tmp10_, _data_->persona);
		_data_->_tmp11_ = _data_->personas;
		_folks_persona_store_emit_personas_changed ((FolksPersonaStore*) _data_->self, NULL, (GeeSet*) _data_->_tmp11_, NULL, NULL, FOLKS_GROUP_DETAILS_CHANGE_REASON_NONE);
		_g_object_unref0 (_data_->personas);
	}
	goto __finally0;
	__catch0_g_key_file_error:
	{
		g_clear_error (&_data_->_inner_error0_);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
folks_backends_kf_persona_store_real_add_persona_from_details_data_free (gpointer _data)
{
	FolksBackendsKfPersonaStoreAddPersonaFromDetailsData* _data_;
	_data_ = _data;
	_g_hash_table_unref0 (_data_->details);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (FolksBackendsKfPersonaStoreAddPersonaFromDetailsData, _data_);
}

static gpointer
_g_hash_table_ref0 (gpointer self)
{
	return self ? g_hash_table_ref (self) : NULL;
}

static void
folks_backends_kf_persona_store_real_add_persona_from_details (FolksPersonaStore* base,
                                                               GHashTable* details,
                                                               GAsyncReadyCallback _callback_,
                                                               gpointer _user_data_)
{
	FolksBackendsKfPersonaStore * self;
	FolksBackendsKfPersonaStoreAddPersonaFromDetailsData* _data_;
	FolksBackendsKfPersonaStore* _tmp0_;
	GHashTable* _tmp1_;
	g_return_if_fail (details != NULL);
	self = (FolksBackendsKfPersonaStore*) base;
	_data_ = g_slice_new0 (FolksBackendsKfPersonaStoreAddPersonaFromDetailsData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, folks_backends_kf_persona_store_real_add_persona_from_details_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_hash_table_ref0 (details);
	_g_hash_table_unref0 (_data_->details);
	_data_->details = _tmp1_;
	folks_backends_kf_persona_store_real_add_persona_from_details_co (_data_);
}

static FolksPersona*
folks_backends_kf_persona_store_add_persona_from_details_finish (FolksPersonaStore* base,
                                                                 GAsyncResult* _res_,
                                                                 GError** error)
{
	FolksPersona* result;
	FolksBackendsKfPersonaStoreAddPersonaFromDetailsData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

/**
   * Add a new {@link Persona} to the PersonaStore.
   *
   * Accepted keys for ``details`` are:
   * - PersonaStore.detail_key (PersonaDetail.IM_ADDRESSES)
   * - PersonaStore.detail_key (PersonaDetail.WEB_SERVICE_ADDRESSES)
   *
   * See {@link Folks.PersonaStore.add_persona_from_details}.
   *
   * @throws Folks.PersonaStoreError.CREATE_FAILED if setting the persona’s
   * properties failed
   */
static void
folks_backends_kf_persona_store_add_persona_from_details_ready (GObject* source_object,
                                                                GAsyncResult* _res_,
                                                                gpointer _user_data_)
{
	FolksBackendsKfPersonaStoreAddPersonaFromDetailsData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	folks_backends_kf_persona_store_real_add_persona_from_details_co (_data_);
}

static gboolean
folks_backends_kf_persona_store_real_add_persona_from_details_co (FolksBackendsKfPersonaStoreAddPersonaFromDetailsData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = folks_persona_store_detail_key (FOLKS_PERSONA_DETAIL_IM_ADDRESSES);
	_data_->_tmp1_ = g_hash_table_lookup (_data_->details, _data_->_tmp0_);
	_data_->val = (GValue*) _data_->_tmp1_;
	_data_->_tmp3_ = _data_->val;
	if (((gpointer) _data_->_tmp3_) != NULL) {
		_data_->_tmp4_ = _data_->val;
		_data_->_tmp5_ = g_value_get_object (_data_->_tmp4_);
		_data_->_tmp2_ = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp5_, GEE_TYPE_MULTI_MAP, GeeMultiMap);
	} else {
		_data_->_tmp2_ = NULL;
	}
	_data_->_tmp6_ = _g_object_ref0 (_data_->_tmp2_);
	_data_->im_addresses = _data_->_tmp6_;
	_data_->_tmp7_ = folks_persona_store_detail_key (FOLKS_PERSONA_DETAIL_WEB_SERVICE_ADDRESSES);
	_data_->_tmp8_ = g_hash_table_lookup (_data_->details, _data_->_tmp7_);
	_data_->val2 = (GValue*) _data_->_tmp8_;
	_data_->_tmp10_ = _data_->val2;
	if (((gpointer) _data_->_tmp10_) != NULL) {
		_data_->_tmp11_ = _data_->val2;
		_data_->_tmp12_ = g_value_get_object (_data_->_tmp11_);
		_data_->_tmp9_ = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp12_, GEE_TYPE_MULTI_MAP, GeeMultiMap);
	} else {
		_data_->_tmp9_ = NULL;
	}
	_data_->_tmp13_ = _g_object_ref0 (_data_->_tmp9_);
	_data_->web_service_addresses = _data_->_tmp13_;
	_data_->_tmp14_ = folks_persona_store_detail_key (FOLKS_PERSONA_DETAIL_LOCAL_IDS);
	_data_->_tmp15_ = g_hash_table_lookup (_data_->details, _data_->_tmp14_);
	_data_->val3 = (GValue*) _data_->_tmp15_;
	_data_->_tmp17_ = _data_->val3;
	if (((gpointer) _data_->_tmp17_) != NULL) {
		_data_->_tmp18_ = _data_->val3;
		_data_->_tmp19_ = g_value_get_object (_data_->_tmp18_);
		_data_->_tmp16_ = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp19_, GEE_TYPE_SET, GeeSet);
	} else {
		_data_->_tmp16_ = NULL;
	}
	_data_->_tmp20_ = _g_object_ref0 (_data_->_tmp16_);
	_data_->local_ids = _data_->_tmp20_;
	g_debug ("kf-persona-store.vala:397: Adding Persona from details.");
	_data_->persona_id = NULL;
	{
		_data_->_tmp21_ = TRUE;
		while (TRUE) {
			if (!_data_->_tmp21_) {
				_data_->_tmp22_ = _data_->self->priv->_key_file;
				_data_->_tmp23_ = _data_->persona_id;
				if (!(g_key_file_has_group (_data_->_tmp22_, _data_->_tmp23_) == TRUE)) {
					break;
				}
			}
			_data_->_tmp21_ = FALSE;
			_data_->_tmp24_ = g_strdup_printf ("%u", g_random_int ());
			_g_free0 (_data_->persona_id);
			_data_->persona_id = _data_->_tmp24_;
		}
	}
	_data_->_tmp25_ = _data_->persona_id;
	_data_->_tmp26_ = folks_backends_kf_persona_new (_data_->_tmp25_, (FolksPersonaStore*) _data_->self);
	_data_->persona = _data_->_tmp26_;
	_data_->_tmp27_ = _data_->self->priv->_personas;
	_data_->_tmp28_ = _data_->persona;
	_data_->_tmp29_ = folks_persona_get_iid ((FolksPersona*) _data_->_tmp28_);
	_data_->_tmp30_ = _data_->_tmp29_;
	_data_->_tmp31_ = _data_->persona;
	gee_abstract_map_set ((GeeAbstractMap*) _data_->_tmp27_, _data_->_tmp30_, _data_->_tmp31_);
	{
		_data_->_tmp32_ = _data_->local_ids;
		if (_data_->_tmp32_ != NULL) {
			_data_->_tmp33_ = _data_->persona;
			_data_->_tmp34_ = _data_->local_ids;
			_data_->_state_ = 1;
			folks_local_id_details_change_local_ids ((FolksLocalIdDetails*) _data_->_tmp33_, _data_->_tmp34_, folks_backends_kf_persona_store_add_persona_from_details_ready, _data_);
			return FALSE;
			_state_1:
			folks_local_id_details_change_local_ids_finish ((FolksLocalIdDetails*) _data_->_tmp33_, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				if (_data_->_inner_error0_->domain == FOLKS_PROPERTY_ERROR) {
					goto __catch0_folks_property_error;
				}
				_g_object_unref0 (_data_->persona);
				_g_free0 (_data_->persona_id);
				_g_object_unref0 (_data_->local_ids);
				_g_object_unref0 (_data_->web_service_addresses);
				_g_object_unref0 (_data_->im_addresses);
				g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
				g_clear_error (&_data_->_inner_error0_);
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
		}
		_data_->_tmp35_ = _data_->im_addresses;
		if (_data_->_tmp35_ != NULL) {
			_data_->_tmp36_ = _data_->persona;
			_data_->_tmp37_ = _data_->im_addresses;
			_data_->_state_ = 2;
			folks_im_details_change_im_addresses ((FolksImDetails*) _data_->_tmp36_, _data_->_tmp37_, folks_backends_kf_persona_store_add_persona_from_details_ready, _data_);
			return FALSE;
			_state_2:
			folks_im_details_change_im_addresses_finish ((FolksImDetails*) _data_->_tmp36_, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				if (_data_->_inner_error0_->domain == FOLKS_PROPERTY_ERROR) {
					goto __catch0_folks_property_error;
				}
				_g_object_unref0 (_data_->persona);
				_g_free0 (_data_->persona_id);
				_g_object_unref0 (_data_->local_ids);
				_g_object_unref0 (_data_->web_service_addresses);
				_g_object_unref0 (_data_->im_addresses);
				g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
				g_clear_error (&_data_->_inner_error0_);
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
		}
		_data_->_tmp38_ = _data_->web_service_addresses;
		if (_data_->_tmp38_ != NULL) {
			_data_->_tmp39_ = _data_->persona;
			_data_->_tmp40_ = _data_->web_service_addresses;
			_data_->_state_ = 3;
			folks_web_service_details_change_web_service_addresses ((FolksWebServiceDetails*) _data_->_tmp39_, _data_->_tmp40_, folks_backends_kf_persona_store_add_persona_from_details_ready, _data_);
			return FALSE;
			_state_3:
			folks_web_service_details_change_web_service_addresses_finish ((FolksWebServiceDetails*) _data_->_tmp39_, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				if (_data_->_inner_error0_->domain == FOLKS_PROPERTY_ERROR) {
					goto __catch0_folks_property_error;
				}
				_g_object_unref0 (_data_->persona);
				_g_free0 (_data_->persona_id);
				_g_object_unref0 (_data_->local_ids);
				_g_object_unref0 (_data_->web_service_addresses);
				_g_object_unref0 (_data_->im_addresses);
				g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
				g_clear_error (&_data_->_inner_error0_);
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
		}
	}
	goto __finally0;
	__catch0_folks_property_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp41_ = _data_->e;
		_data_->_tmp42_ = _data_->_tmp41_->message;
		_data_->_tmp43_ = g_error_new_literal (FOLKS_PERSONA_STORE_ERROR, FOLKS_PERSONA_STORE_ERROR_CREATE_FAILED, _data_->_tmp42_);
		_data_->_inner_error0_ = _data_->_tmp43_;
		_g_error_free0 (_data_->e);
		goto __finally0;
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		if (_data_->_inner_error0_->domain == FOLKS_PERSONA_STORE_ERROR) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_object_unref0 (_data_->persona);
			_g_free0 (_data_->persona_id);
			_g_object_unref0 (_data_->local_ids);
			_g_object_unref0 (_data_->web_service_addresses);
			_g_object_unref0 (_data_->im_addresses);
			g_object_unref (_data_->_async_result);
			return FALSE;
		} else {
			_g_object_unref0 (_data_->persona);
			_g_free0 (_data_->persona_id);
			_g_object_unref0 (_data_->local_ids);
			_g_object_unref0 (_data_->web_service_addresses);
			_g_object_unref0 (_data_->im_addresses);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
			g_clear_error (&_data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	_data_->_tmp44_ = folks_small_set_new (FOLKS_BACKENDS_KF_TYPE_PERSONA, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL);
	_data_->personas = _data_->_tmp44_;
	_data_->_tmp45_ = _data_->persona;
	gee_abstract_collection_add ((GeeAbstractCollection*) _data_->personas, _data_->_tmp45_);
	_folks_persona_store_emit_personas_changed ((FolksPersonaStore*) _data_->self, (GeeSet*) _data_->personas, NULL, NULL, NULL, FOLKS_GROUP_DETAILS_CHANGE_REASON_NONE);
	_data_->result = (FolksPersona*) _data_->persona;
	_g_object_unref0 (_data_->personas);
	_g_free0 (_data_->persona_id);
	_g_object_unref0 (_data_->local_ids);
	_g_object_unref0 (_data_->web_service_addresses);
	_g_object_unref0 (_data_->im_addresses);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

GKeyFile*
folks_backends_kf_persona_store_get_key_file (FolksBackendsKfPersonaStore* self)
{
	GKeyFile* _tmp0_;
	GKeyFile* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_key_file;
	result = _tmp0_;
	return result;
}

static void
folks_backends_kf_persona_store_save_key_file_data_free (gpointer _data)
{
	FolksBackendsKfPersonaStoreSaveKeyFileData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (FolksBackendsKfPersonaStoreSaveKeyFileData, _data_);
}

void
folks_backends_kf_persona_store_save_key_file (FolksBackendsKfPersonaStore* self,
                                               GAsyncReadyCallback _callback_,
                                               gpointer _user_data_)
{
	FolksBackendsKfPersonaStoreSaveKeyFileData* _data_;
	FolksBackendsKfPersonaStore* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (FolksBackendsKfPersonaStoreSaveKeyFileData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, folks_backends_kf_persona_store_save_key_file_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	folks_backends_kf_persona_store_save_key_file_co (_data_);
}

void
folks_backends_kf_persona_store_save_key_file_finish (FolksBackendsKfPersonaStore* self,
                                                      GAsyncResult* _res_)
{
	FolksBackendsKfPersonaStoreSaveKeyFileData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static guint8*
string_get_data (const gchar* self,
                 gint* result_length1)
{
	guint8* result;
	guint8* res = NULL;
	gint res_length1;
	gint _res_size_;
	gint _tmp0_;
	gint _tmp1_;
	guint8* _tmp2_;
	gint _tmp2__length1;
	g_return_val_if_fail (self != NULL, NULL);
	res = (guint8*) self;
	res_length1 = -1;
	_res_size_ = res_length1;
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	res_length1 = (gint) _tmp1_;
	_tmp2_ = res;
	_tmp2__length1 = res_length1;
	if (result_length1) {
		*result_length1 = _tmp2__length1;
	}
	result = _tmp2_;
	return result;
}

static void
folks_backends_kf_persona_store_save_key_file_ready (GObject* source_object,
                                                     GAsyncResult* _res_,
                                                     gpointer _user_data_)
{
	FolksBackendsKfPersonaStoreSaveKeyFileData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	folks_backends_kf_persona_store_save_key_file_co (_data_);
}

static gboolean
folks_backends_kf_persona_store_save_key_file_co (FolksBackendsKfPersonaStoreSaveKeyFileData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->priv->_key_file;
	_data_->_tmp1_ = g_key_file_to_data (_data_->_tmp0_, NULL, NULL);
	_data_->key_file_data = _data_->_tmp1_;
	_data_->_tmp2_ = g_cancellable_new ();
	_data_->cancellable = _data_->_tmp2_;
	_data_->_tmp3_ = _data_->self->priv->_file;
	_data_->_tmp4_ = g_file_get_path (_data_->_tmp3_);
	_data_->_tmp5_ = _data_->_tmp4_;
	g_debug ("kf-persona-store.vala:459: Saving key file '%s'.", _data_->_tmp5_);
	_g_free0 (_data_->_tmp5_);
	_data_->_tmp6_ = _data_->self->priv->_save_key_file_cancellable;
	if (_data_->_tmp6_ != NULL) {
		_data_->_tmp7_ = _data_->self->priv->_save_key_file_cancellable;
		g_cancellable_cancel (_data_->_tmp7_);
	}
	_data_->_tmp8_ = _data_->cancellable;
	_data_->self->priv->_save_key_file_cancellable = _data_->_tmp8_;
	{
		_data_->_tmp9_ = _data_->self->priv->_file;
		_data_->_tmp10_ = _data_->key_file_data;
		_data_->_tmp12_ = 0;
		_data_->_tmp11_ = string_get_data (_data_->_tmp10_, &_data_->_tmp12_);
		_data_->_tmp11__length1 = _data_->_tmp12_;
		_data_->_tmp13_ = _data_->_tmp11_;
		_data_->_tmp13__length1 = _data_->_tmp11__length1;
		_data_->_tmp14_ = _data_->cancellable;
		_data_->_state_ = 1;
		g_file_replace_contents_async (_data_->_tmp9_, (const char*) _data_->_tmp13_, (gsize) _data_->_tmp13__length1, NULL, FALSE, G_FILE_CREATE_PRIVATE, _data_->_tmp14_, folks_backends_kf_persona_store_save_key_file_ready, _data_);
		return FALSE;
		_state_1:
		g_file_replace_contents_finish (_data_->_tmp9_, _data_->_res_, NULL, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp15_ = _data_->e;
		if (!g_error_matches (_data_->_tmp15_, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
			_data_->_tmp16_ = _data_->self->priv->_file;
			_data_->_tmp17_ = g_file_get_path (_data_->_tmp16_);
			_data_->_tmp18_ = _data_->_tmp17_;
			_data_->_tmp19_ = _data_->e;
			_data_->_tmp20_ = _data_->_tmp19_->message;
			g_warning (_ ("Could not write updated key file ‘%s’: %s"), _data_->_tmp18_, _data_->_tmp20_);
			_g_free0 (_data_->_tmp18_);
		}
		_g_error_free0 (_data_->e);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_object_unref0 (_data_->cancellable);
		_g_free0 (_data_->key_file_data);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp21_ = _data_->self->priv->_save_key_file_cancellable;
	_data_->_tmp22_ = _data_->cancellable;
	if (_data_->_tmp21_ == _data_->_tmp22_) {
		_data_->self->priv->_save_key_file_cancellable = NULL;
	}
	_g_object_unref0 (_data_->cancellable);
	_g_free0 (_data_->key_file_data);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static const gchar*
folks_backends_kf_persona_store_real_get_type_id (FolksPersonaStore* base)
{
	const gchar* result;
	FolksBackendsKfPersonaStore* self;
	self = (FolksBackendsKfPersonaStore*) base;
	result = BACKEND_NAME;
	return result;
}

static FolksMaybeBool
folks_backends_kf_persona_store_real_get_can_add_personas (FolksPersonaStore* base)
{
	FolksMaybeBool result;
	FolksBackendsKfPersonaStore* self;
	self = (FolksBackendsKfPersonaStore*) base;
	result = FOLKS_MAYBE_BOOL_TRUE;
	return result;
}

static FolksMaybeBool
folks_backends_kf_persona_store_real_get_can_alias_personas (FolksPersonaStore* base)
{
	FolksMaybeBool result;
	FolksBackendsKfPersonaStore* self;
	self = (FolksBackendsKfPersonaStore*) base;
	result = FOLKS_MAYBE_BOOL_TRUE;
	return result;
}

static FolksMaybeBool
folks_backends_kf_persona_store_real_get_can_group_personas (FolksPersonaStore* base)
{
	FolksMaybeBool result;
	FolksBackendsKfPersonaStore* self;
	self = (FolksBackendsKfPersonaStore*) base;
	result = FOLKS_MAYBE_BOOL_FALSE;
	return result;
}

static FolksMaybeBool
folks_backends_kf_persona_store_real_get_can_remove_personas (FolksPersonaStore* base)
{
	FolksMaybeBool result;
	FolksBackendsKfPersonaStore* self;
	self = (FolksBackendsKfPersonaStore*) base;
	result = FOLKS_MAYBE_BOOL_TRUE;
	return result;
}

static gboolean
folks_backends_kf_persona_store_real_get_is_prepared (FolksPersonaStore* base)
{
	gboolean result;
	FolksBackendsKfPersonaStore* self;
	self = (FolksBackendsKfPersonaStore*) base;
	result = self->priv->_is_prepared;
	return result;
}

static gboolean
folks_backends_kf_persona_store_real_get_is_quiescent (FolksPersonaStore* base)
{
	gboolean result;
	FolksBackendsKfPersonaStore* self;
	self = (FolksBackendsKfPersonaStore*) base;
	result = self->priv->_is_quiescent;
	return result;
}

static gchar**
folks_backends_kf_persona_store_real_get_always_writeable_properties (FolksPersonaStore* base,
                                                                      gint* result_length1)
{
	gchar** result;
	FolksBackendsKfPersonaStore* self;
	gchar** _tmp0_;
	gint _tmp0__length1;
	self = (FolksBackendsKfPersonaStore*) base;
	_tmp0_ = FOLKS_BACKENDS_KF_PERSONA_STORE__always_writeable_properties;
	_tmp0__length1 = G_N_ELEMENTS (FOLKS_BACKENDS_KF_PERSONA_STORE__always_writeable_properties);
	if (result_length1) {
		*result_length1 = _tmp0__length1;
	}
	result = _tmp0_;
	return result;
}

static GeeMap*
folks_backends_kf_persona_store_real_get_personas (FolksPersonaStore* base)
{
	GeeMap* result;
	FolksBackendsKfPersonaStore* self;
	GeeMap* _tmp0_;
	self = (FolksBackendsKfPersonaStore*) base;
	_tmp0_ = self->priv->_personas_ro;
	result = _tmp0_;
	return result;
}

GFile*
folks_backends_kf_persona_store_get_file (FolksBackendsKfPersonaStore* self)
{
	GFile* result;
	GFile* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_file;
	result = _tmp0_;
	return result;
}

static void
folks_backends_kf_persona_store_set_file (FolksBackendsKfPersonaStore* self,
                                          GFile* value)
{
	GFile* old_value;
	g_return_if_fail (self != NULL);
	old_value = folks_backends_kf_persona_store_get_file (self);
	if (old_value != value) {
		GFile* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_file);
		self->priv->_file = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, folks_backends_kf_persona_store_properties[FOLKS_BACKENDS_KF_PERSONA_STORE_FILE_PROPERTY]);
	}
}

static GObject *
folks_backends_kf_persona_store_constructor (GType type,
                                             guint n_construct_properties,
                                             GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	FolksBackendsKfPersonaStore * self;
	GeeHashMap* _tmp0_;
	GeeHashMap* _tmp1_;
	GeeMap* _tmp2_;
	GeeMap* _tmp3_;
	parent_class = G_OBJECT_CLASS (folks_backends_kf_persona_store_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FOLKS_BACKENDS_KF_TYPE_PERSONA_STORE, FolksBackendsKfPersonaStore);
	folks_persona_store_set_trust_level ((FolksPersonaStore*) self, FOLKS_PERSONA_STORE_TRUST_FULL);
	_tmp0_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, FOLKS_BACKENDS_KF_TYPE_PERSONA, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_g_object_unref0 (self->priv->_personas);
	self->priv->_personas = _tmp0_;
	_tmp1_ = self->priv->_personas;
	_tmp2_ = gee_abstract_map_get_read_only_view ((GeeAbstractMap*) _tmp1_);
	_tmp3_ = _tmp2_;
	_g_object_unref0 (self->priv->_personas_ro);
	self->priv->_personas_ro = _tmp3_;
	return obj;
}

static void
folks_backends_kf_persona_store_class_init (FolksBackendsKfPersonaStoreClass * klass,
                                            gpointer klass_data)
{
	folks_backends_kf_persona_store_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FolksBackendsKfPersonaStore_private_offset);
	((FolksPersonaStoreClass *) klass)->prepare = (void (*) (FolksPersonaStore*, GAsyncReadyCallback, gpointer)) folks_backends_kf_persona_store_real_prepare;
	((FolksPersonaStoreClass *) klass)->prepare_finish = (void (*) (FolksPersonaStore*, GAsyncResult*, GError**)) folks_backends_kf_persona_store_prepare_finish;
	((FolksPersonaStoreClass *) klass)->flush = (void (*) (FolksPersonaStore*, GAsyncReadyCallback, gpointer)) folks_backends_kf_persona_store_real_flush;
	((FolksPersonaStoreClass *) klass)->flush_finish = (void (*) (FolksPersonaStore*, GAsyncResult*)) folks_backends_kf_persona_store_flush_finish;
	((FolksPersonaStoreClass *) klass)->remove_persona = (void (*) (FolksPersonaStore*, FolksPersona*, GAsyncReadyCallback, gpointer)) folks_backends_kf_persona_store_real_remove_persona;
	((FolksPersonaStoreClass *) klass)->remove_persona_finish = (void (*) (FolksPersonaStore*, GAsyncResult*, GError**)) folks_backends_kf_persona_store_remove_persona_finish;
	((FolksPersonaStoreClass *) klass)->add_persona_from_details = (void (*) (FolksPersonaStore*, GHashTable*, GAsyncReadyCallback, gpointer)) folks_backends_kf_persona_store_real_add_persona_from_details;
	((FolksPersonaStoreClass *) klass)->add_persona_from_details_finish = (FolksPersona* (*) (FolksPersonaStore*, GAsyncResult*, GError**)) folks_backends_kf_persona_store_add_persona_from_details_finish;
	FOLKS_PERSONA_STORE_CLASS (klass)->get_type_id = (const gchar* (*) (FolksPersonaStore*)) folks_backends_kf_persona_store_real_get_type_id;
	FOLKS_PERSONA_STORE_CLASS (klass)->get_can_add_personas = (FolksMaybeBool (*) (FolksPersonaStore*)) folks_backends_kf_persona_store_real_get_can_add_personas;
	FOLKS_PERSONA_STORE_CLASS (klass)->get_can_alias_personas = (FolksMaybeBool (*) (FolksPersonaStore*)) folks_backends_kf_persona_store_real_get_can_alias_personas;
	FOLKS_PERSONA_STORE_CLASS (klass)->get_can_group_personas = (FolksMaybeBool (*) (FolksPersonaStore*)) folks_backends_kf_persona_store_real_get_can_group_personas;
	FOLKS_PERSONA_STORE_CLASS (klass)->get_can_remove_personas = (FolksMaybeBool (*) (FolksPersonaStore*)) folks_backends_kf_persona_store_real_get_can_remove_personas;
	FOLKS_PERSONA_STORE_CLASS (klass)->get_is_prepared = (gboolean (*) (FolksPersonaStore*)) folks_backends_kf_persona_store_real_get_is_prepared;
	FOLKS_PERSONA_STORE_CLASS (klass)->get_is_quiescent = (gboolean (*) (FolksPersonaStore*)) folks_backends_kf_persona_store_real_get_is_quiescent;
	FOLKS_PERSONA_STORE_CLASS (klass)->get_always_writeable_properties = (gchar** (*) (FolksPersonaStore*, gint*)) folks_backends_kf_persona_store_real_get_always_writeable_properties;
	FOLKS_PERSONA_STORE_CLASS (klass)->get_personas = (GeeMap* (*) (FolksPersonaStore*)) folks_backends_kf_persona_store_real_get_personas;
	G_OBJECT_CLASS (klass)->get_property = _vala_folks_backends_kf_persona_store_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_folks_backends_kf_persona_store_set_property;
	G_OBJECT_CLASS (klass)->constructor = folks_backends_kf_persona_store_constructor;
	G_OBJECT_CLASS (klass)->finalize = folks_backends_kf_persona_store_finalize;
	/**
	   * {@inheritDoc}
	   */
	g_object_class_install_property (G_OBJECT_CLASS (klass), FOLKS_BACKENDS_KF_PERSONA_STORE_TYPE_ID_PROPERTY, folks_backends_kf_persona_store_properties[FOLKS_BACKENDS_KF_PERSONA_STORE_TYPE_ID_PROPERTY] = g_param_spec_string ("type-id", "type-id", "type-id", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/**
	   * Whether this PersonaStore can add {@link Folks.Persona}s.
	   *
	   * See {@link Folks.PersonaStore.can_add_personas}.
	   *
	   * @since 0.3.1
	   */
	g_object_class_install_property (G_OBJECT_CLASS (klass), FOLKS_BACKENDS_KF_PERSONA_STORE_CAN_ADD_PERSONAS_PROPERTY, folks_backends_kf_persona_store_properties[FOLKS_BACKENDS_KF_PERSONA_STORE_CAN_ADD_PERSONAS_PROPERTY] = g_param_spec_enum ("can-add-personas", "can-add-personas", "can-add-personas", FOLKS_TYPE_MAYBE_BOOL, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/**
	   * Whether this PersonaStore can set the alias of {@link Folks.Persona}s.
	   *
	   * See {@link Folks.PersonaStore.can_alias_personas}.
	   *
	   * @since 0.3.1
	   */
	g_object_class_install_property (G_OBJECT_CLASS (klass), FOLKS_BACKENDS_KF_PERSONA_STORE_CAN_ALIAS_PERSONAS_PROPERTY, folks_backends_kf_persona_store_properties[FOLKS_BACKENDS_KF_PERSONA_STORE_CAN_ALIAS_PERSONAS_PROPERTY] = g_param_spec_enum ("can-alias-personas", "can-alias-personas", "can-alias-personas", FOLKS_TYPE_MAYBE_BOOL, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/**
	   * Whether this PersonaStore can set the groups of {@link Folks.Persona}s.
	   *
	   * See {@link Folks.PersonaStore.can_group_personas}.
	   *
	   * @since 0.3.1
	   */
	g_object_class_install_property (G_OBJECT_CLASS (klass), FOLKS_BACKENDS_KF_PERSONA_STORE_CAN_GROUP_PERSONAS_PROPERTY, folks_backends_kf_persona_store_properties[FOLKS_BACKENDS_KF_PERSONA_STORE_CAN_GROUP_PERSONAS_PROPERTY] = g_param_spec_enum ("can-group-personas", "can-group-personas", "can-group-personas", FOLKS_TYPE_MAYBE_BOOL, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/**
	   * Whether this PersonaStore can remove {@link Folks.Persona}s.
	   *
	   * See {@link Folks.PersonaStore.can_remove_personas}.
	   *
	   * @since 0.3.1
	   */
	g_object_class_install_property (G_OBJECT_CLASS (klass), FOLKS_BACKENDS_KF_PERSONA_STORE_CAN_REMOVE_PERSONAS_PROPERTY, folks_backends_kf_persona_store_properties[FOLKS_BACKENDS_KF_PERSONA_STORE_CAN_REMOVE_PERSONAS_PROPERTY] = g_param_spec_enum ("can-remove-personas", "can-remove-personas", "can-remove-personas", FOLKS_TYPE_MAYBE_BOOL, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/**
	   * Whether this PersonaStore has been prepared.
	   *
	   * See {@link Folks.PersonaStore.is_prepared}.
	   *
	   * @since 0.3.0
	   */
	g_object_class_install_property (G_OBJECT_CLASS (klass), FOLKS_BACKENDS_KF_PERSONA_STORE_IS_PREPARED_PROPERTY, folks_backends_kf_persona_store_properties[FOLKS_BACKENDS_KF_PERSONA_STORE_IS_PREPARED_PROPERTY] = g_param_spec_boolean ("is-prepared", "is-prepared", "is-prepared", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/**
	   * Whether this PersonaStore has reached a quiescent state.
	   *
	   * See {@link Folks.PersonaStore.is_quiescent}.
	   *
	   * @since 0.6.2
	   */
	g_object_class_install_property (G_OBJECT_CLASS (klass), FOLKS_BACKENDS_KF_PERSONA_STORE_IS_QUIESCENT_PROPERTY, folks_backends_kf_persona_store_properties[FOLKS_BACKENDS_KF_PERSONA_STORE_IS_QUIESCENT_PROPERTY] = g_param_spec_boolean ("is-quiescent", "is-quiescent", "is-quiescent", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/**
	   * {@inheritDoc}
	   *
	   * @since 0.6.2
	   */
	g_object_class_install_property (G_OBJECT_CLASS (klass), FOLKS_BACKENDS_KF_PERSONA_STORE_ALWAYS_WRITEABLE_PROPERTIES_PROPERTY, folks_backends_kf_persona_store_properties[FOLKS_BACKENDS_KF_PERSONA_STORE_ALWAYS_WRITEABLE_PROPERTIES_PROPERTY] = g_param_spec_boxed ("always-writeable-properties", "always-writeable-properties", "always-writeable-properties", G_TYPE_STRV, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/**
	   * {@inheritDoc}
	   */
	g_object_class_install_property (G_OBJECT_CLASS (klass), FOLKS_BACKENDS_KF_PERSONA_STORE_PERSONAS_PROPERTY, folks_backends_kf_persona_store_properties[FOLKS_BACKENDS_KF_PERSONA_STORE_PERSONAS_PROPERTY] = g_param_spec_object ("personas", "personas", "personas", GEE_TYPE_MAP, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/**
	   * File containing the persona store data.
	   *
	   * This must be in GLib key file format.
	   *
	   * @since 0.6.6
	   */
	g_object_class_install_property (G_OBJECT_CLASS (klass), FOLKS_BACKENDS_KF_PERSONA_STORE_FILE_PROPERTY, folks_backends_kf_persona_store_properties[FOLKS_BACKENDS_KF_PERSONA_STORE_FILE_PROPERTY] = g_param_spec_object ("file", "file", "file", g_file_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
}

static void
folks_backends_kf_persona_store_instance_init (FolksBackendsKfPersonaStore * self,
                                               gpointer klass)
{
	self->priv = folks_backends_kf_persona_store_get_instance_private (self);
	self->priv->_save_key_file_cancellable = NULL;
	self->priv->_is_prepared = FALSE;
	self->priv->_prepare_pending = FALSE;
	self->priv->_is_quiescent = FALSE;
}

static void
folks_backends_kf_persona_store_finalize (GObject * obj)
{
	FolksBackendsKfPersonaStore * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FOLKS_BACKENDS_KF_TYPE_PERSONA_STORE, FolksBackendsKfPersonaStore);
	_g_object_unref0 (self->priv->_personas);
	_g_object_unref0 (self->priv->_personas_ro);
	_g_key_file_unref0 (self->priv->_key_file);
	_g_object_unref0 (self->priv->_file);
	G_OBJECT_CLASS (folks_backends_kf_persona_store_parent_class)->finalize (obj);
}

/**
 * A persona store which is associated with a single simple key file. It will
 * create a {@link Persona} for each of the groups in the key file.
 *
 * @since 0.1.13
 */
static GType
folks_backends_kf_persona_store_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FolksBackendsKfPersonaStoreClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) folks_backends_kf_persona_store_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FolksBackendsKfPersonaStore), 0, (GInstanceInitFunc) folks_backends_kf_persona_store_instance_init, NULL };
	GType folks_backends_kf_persona_store_type_id;
	folks_backends_kf_persona_store_type_id = g_type_register_static (FOLKS_TYPE_PERSONA_STORE, "FolksBackendsKfPersonaStore", &g_define_type_info, 0);
	FolksBackendsKfPersonaStore_private_offset = g_type_add_instance_private (folks_backends_kf_persona_store_type_id, sizeof (FolksBackendsKfPersonaStorePrivate));
	return folks_backends_kf_persona_store_type_id;
}

GType
folks_backends_kf_persona_store_get_type (void)
{
	static volatile gsize folks_backends_kf_persona_store_type_id__once = 0;
	if (g_once_init_enter (&folks_backends_kf_persona_store_type_id__once)) {
		GType folks_backends_kf_persona_store_type_id;
		folks_backends_kf_persona_store_type_id = folks_backends_kf_persona_store_get_type_once ();
		g_once_init_leave (&folks_backends_kf_persona_store_type_id__once, folks_backends_kf_persona_store_type_id);
	}
	return folks_backends_kf_persona_store_type_id__once;
}

static void
_vala_folks_backends_kf_persona_store_get_property (GObject * object,
                                                    guint property_id,
                                                    GValue * value,
                                                    GParamSpec * pspec)
{
	FolksBackendsKfPersonaStore * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FOLKS_BACKENDS_KF_TYPE_PERSONA_STORE, FolksBackendsKfPersonaStore);
	switch (property_id) {
		case FOLKS_BACKENDS_KF_PERSONA_STORE_TYPE_ID_PROPERTY:
		g_value_set_string (value, folks_persona_store_get_type_id ((FolksPersonaStore*) self));
		break;
		case FOLKS_BACKENDS_KF_PERSONA_STORE_CAN_ADD_PERSONAS_PROPERTY:
		g_value_set_enum (value, folks_persona_store_get_can_add_personas ((FolksPersonaStore*) self));
		break;
		case FOLKS_BACKENDS_KF_PERSONA_STORE_CAN_ALIAS_PERSONAS_PROPERTY:
		g_value_set_enum (value, folks_persona_store_get_can_alias_personas ((FolksPersonaStore*) self));
		break;
		case FOLKS_BACKENDS_KF_PERSONA_STORE_CAN_GROUP_PERSONAS_PROPERTY:
		g_value_set_enum (value, folks_persona_store_get_can_group_personas ((FolksPersonaStore*) self));
		break;
		case FOLKS_BACKENDS_KF_PERSONA_STORE_CAN_REMOVE_PERSONAS_PROPERTY:
		g_value_set_enum (value, folks_persona_store_get_can_remove_personas ((FolksPersonaStore*) self));
		break;
		case FOLKS_BACKENDS_KF_PERSONA_STORE_IS_PREPARED_PROPERTY:
		g_value_set_boolean (value, folks_persona_store_get_is_prepared ((FolksPersonaStore*) self));
		break;
		case FOLKS_BACKENDS_KF_PERSONA_STORE_IS_QUIESCENT_PROPERTY:
		g_value_set_boolean (value, folks_persona_store_get_is_quiescent ((FolksPersonaStore*) self));
		break;
		case FOLKS_BACKENDS_KF_PERSONA_STORE_ALWAYS_WRITEABLE_PROPERTIES_PROPERTY:
		{
			int length;
			g_value_set_boxed (value, folks_persona_store_get_always_writeable_properties ((FolksPersonaStore*) self, &length));
		}
		break;
		case FOLKS_BACKENDS_KF_PERSONA_STORE_PERSONAS_PROPERTY:
		g_value_set_object (value, folks_persona_store_get_personas ((FolksPersonaStore*) self));
		break;
		case FOLKS_BACKENDS_KF_PERSONA_STORE_FILE_PROPERTY:
		g_value_set_object (value, folks_backends_kf_persona_store_get_file (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_folks_backends_kf_persona_store_set_property (GObject * object,
                                                    guint property_id,
                                                    const GValue * value,
                                                    GParamSpec * pspec)
{
	FolksBackendsKfPersonaStore * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FOLKS_BACKENDS_KF_TYPE_PERSONA_STORE, FolksBackendsKfPersonaStore);
	switch (property_id) {
		case FOLKS_BACKENDS_KF_PERSONA_STORE_FILE_PROPERTY:
		folks_backends_kf_persona_store_set_file (self, g_value_get_object (value));
		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);
}

