/* import.c generated by valac 0.35.3.10-6b27, the Vala compiler
 * generated from import.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:
 *       Philip Withnall <philip.withnall@collabora.co.uk>
 */

#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>
#include <locale.h>
#include <config.h>
#include <stdio.h>
#include <folks/folks.h>
#include <gio/gio.h>
#include <gee.h>


#define FOLKS_TYPE_IMPORT_TOOL (folks_import_tool_get_type ())
#define FOLKS_IMPORT_TOOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FOLKS_TYPE_IMPORT_TOOL, FolksImportTool))
#define FOLKS_IMPORT_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FOLKS_TYPE_IMPORT_TOOL, FolksImportToolClass))
#define FOLKS_IS_IMPORT_TOOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FOLKS_TYPE_IMPORT_TOOL))
#define FOLKS_IS_IMPORT_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FOLKS_TYPE_IMPORT_TOOL))
#define FOLKS_IMPORT_TOOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FOLKS_TYPE_IMPORT_TOOL, FolksImportToolClass))

typedef struct _FolksImportTool FolksImportTool;
typedef struct _FolksImportToolClass FolksImportToolClass;
typedef struct _FolksImportToolPrivate FolksImportToolPrivate;
typedef struct _Block1Data Block1Data;
#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL)))
#define _g_option_context_free0(var) ((var == NULL) ? NULL : (var = (g_option_context_free (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define FOLKS_TYPE_IMPORTER (folks_importer_get_type ())
#define FOLKS_IMPORTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FOLKS_TYPE_IMPORTER, FolksImporter))
#define FOLKS_IMPORTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FOLKS_TYPE_IMPORTER, FolksImporterClass))
#define FOLKS_IS_IMPORTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FOLKS_TYPE_IMPORTER))
#define FOLKS_IS_IMPORTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FOLKS_TYPE_IMPORTER))
#define FOLKS_IMPORTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FOLKS_TYPE_IMPORTER, FolksImporterClass))

typedef struct _FolksImporter FolksImporter;
typedef struct _FolksImporterClass FolksImporterClass;

#define FOLKS_IMPORTERS_TYPE_PIDGIN (folks_importers_pidgin_get_type ())
#define FOLKS_IMPORTERS_PIDGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FOLKS_IMPORTERS_TYPE_PIDGIN, FolksImportersPidgin))
#define FOLKS_IMPORTERS_PIDGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FOLKS_IMPORTERS_TYPE_PIDGIN, FolksImportersPidginClass))
#define FOLKS_IMPORTERS_IS_PIDGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FOLKS_IMPORTERS_TYPE_PIDGIN))
#define FOLKS_IMPORTERS_IS_PIDGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FOLKS_IMPORTERS_TYPE_PIDGIN))
#define FOLKS_IMPORTERS_PIDGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FOLKS_IMPORTERS_TYPE_PIDGIN, FolksImportersPidginClass))

typedef struct _FolksImportersPidgin FolksImportersPidgin;
typedef struct _FolksImportersPidginClass FolksImportersPidginClass;
typedef struct _FolksImportToolImportData FolksImportToolImportData;
typedef struct _FolksImporterPrivate FolksImporterPrivate;

struct _FolksImportTool {
	GObject parent_instance;
	FolksImportToolPrivate * priv;
};

struct _FolksImportToolClass {
	GObjectClass parent_class;
};

struct _Block1Data {
	int _ref_count_;
	GMainLoop* main_loop;
	gboolean success;
};

typedef enum  {
	FOLKS_IMPORT_ERROR_MALFORMED_INPUT
} FolksImportError;
#define FOLKS_IMPORT_ERROR folks_import_error_quark ()
struct _FolksImportToolImportData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	gboolean result;
	FolksBackendStore* backend_store;
	FolksBackendStore* _tmp0_;
	FolksBackendStore* _tmp1_;
	GError* e1;
	FILE* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	GError* _tmp5_;
	const gchar* _tmp6_;
	FolksBackend* kf_backend;
	FolksBackendStore* _tmp7_;
	FolksBackend* _tmp8_;
	FolksBackend* _tmp9_;
	FILE* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	FolksBackend* _tmp13_;
	GError* e2;
	FILE* _tmp14_;
	gchar* _tmp15_;
	gchar* _tmp16_;
	GError* _tmp17_;
	const gchar* _tmp18_;
	FolksPersonaStore* destination_store;
	GeeCollection* stores;
	FolksBackend* _tmp19_;
	GeeMap* _tmp20_;
	GeeMap* _tmp21_;
	GeeCollection* _tmp22_;
	GeeCollection* _tmp23_;
	GeeCollection* _tmp24_;
	gint _tmp25_;
	gint _tmp26_;
	FILE* _tmp27_;
	gchar* _tmp28_;
	gchar* _tmp29_;
	GeeIterator* _persona_store_it;
	GeeCollection* _tmp30_;
	GeeIterator* _tmp31_;
	GeeIterator* _tmp32_;
	gboolean _tmp33_;
	FolksPersonaStore* persona_store;
	GeeIterator* _tmp34_;
	gpointer _tmp35_;
	FolksPersonaStore* _tmp36_;
	FolksPersonaStore* _tmp37_;
	FolksPersonaStore* _tmp38_;
	GError* e3;
	FILE* _tmp39_;
	gchar* _tmp40_;
	gchar* _tmp41_;
	GError* _tmp42_;
	const gchar* _tmp43_;
	const gchar* _tmp44_;
	FolksImporter* importer;
	FolksImportersPidgin* _tmp45_;
	FolksImporter* _tmp46_;
	FolksPersonaStore* _tmp47_;
	const gchar* _tmp48_;
	GError* e;
	FILE* _tmp49_;
	gchar* _tmp50_;
	gchar* _tmp51_;
	GError* _tmp52_;
	const gchar* _tmp53_;
	FolksPersonaStore* _tmp54_;
	FILE* _tmp55_;
	gchar* _tmp56_;
	gchar* _tmp57_;
	const gchar* _tmp58_;
	GError * _inner_error_;
};

struct _FolksImporter {
	GObject parent_instance;
	FolksImporterPrivate * priv;
};

struct _FolksImporterClass {
	GObjectClass parent_class;
	void (*import) (FolksImporter* self, FolksPersonaStore* destination_store, const gchar* source_filename, GAsyncReadyCallback _callback_, gpointer _user_data_);
	guint (*import_finish) (FolksImporter* self, GAsyncResult* _res_, GError** error);
};


static gpointer folks_import_tool_parent_class = NULL;
static gchar* folks_import_tool_source;
static gchar* folks_import_tool_source = NULL;
static gchar* folks_import_tool_source_filename;
static gchar* folks_import_tool_source_filename = NULL;
static gpointer folks_importer_parent_class = NULL;

GType folks_import_tool_get_type (void) G_GNUC_CONST;
enum  {
	FOLKS_IMPORT_TOOL_DUMMY_PROPERTY
};
#define FOLKS_IMPORT_TOOL_DEFAULT_SOURCE "pidgin"
gint folks_import_tool_main (gchar** args, int args_length1);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static void folks_import_tool_import (GAsyncReadyCallback _callback_, gpointer _user_data_);
static gboolean folks_import_tool_import_finish (GAsyncResult* _res_);
static void __lambda4_ (Block1Data* _data1_, GObject* o, GAsyncResult* r);
static void ___lambda4__gasync_ready_callback (GObject* source_object, GAsyncResult* res, gpointer self);
static void folks_import_tool_import_data_free (gpointer _data);
static gboolean folks_import_tool_import_co (FolksImportToolImportData* _data_);
static void folks_import_tool_import_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
GType folks_importer_get_type (void) G_GNUC_CONST;
FolksImportersPidgin* folks_importers_pidgin_new (void);
FolksImportersPidgin* folks_importers_pidgin_construct (GType object_type);
GType folks_importers_pidgin_get_type (void) G_GNUC_CONST;
void folks_importer_import (FolksImporter* self, FolksPersonaStore* destination_store, const gchar* source_filename, GAsyncReadyCallback _callback_, gpointer _user_data_);
GQuark folks_import_error_quark (void);
guint folks_importer_import_finish (FolksImporter* self, GAsyncResult* _res_, GError** error);
FolksImportTool* folks_import_tool_new (void);
FolksImportTool* folks_import_tool_construct (GType object_type);
static void folks_import_tool_finalize (GObject * obj);
enum  {
	FOLKS_IMPORTER_DUMMY_PROPERTY
};
FolksImporter* folks_importer_construct (GType object_type);

static const GOptionEntry FOLKS_IMPORT_TOOL_options[3] = {{"source", 's', 0, G_OPTION_ARG_STRING, &folks_import_tool_source, N_ ("Source backend name (default: ‘pidgin’)"), "name"}, {"source-filename", (gchar) 0, 0, G_OPTION_ARG_FILENAME, &folks_import_tool_source_filename, N_ ("Source filename (default: specific to source backend)"), NULL}, {NULL}};

static Block1Data* block1_data_ref (Block1Data* _data1_) {
	g_atomic_int_inc (&_data1_->_ref_count_);
	return _data1_;
}


static void block1_data_unref (void * _userdata_) {
	Block1Data* _data1_;
	_data1_ = (Block1Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) {
		_g_main_loop_unref0 (_data1_->main_loop);
		g_slice_free (Block1Data, _data1_);
	}
}


static gchar* string_strip (const gchar* self) {
	gchar* result = NULL;
	gchar* _result_;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	_tmp1_ = _result_;
	g_strstrip (_tmp1_);
	result = _result_;
	return result;
}


static void __lambda4_ (Block1Data* _data1_, GObject* o, GAsyncResult* r) {
	GAsyncResult* _tmp0_;
	gboolean _tmp1_;
	GMainLoop* _tmp2_;
	g_return_if_fail (r != NULL);
	_tmp0_ = r;
	_tmp1_ = folks_import_tool_import_finish (_tmp0_);
	_data1_->success = _tmp1_;
	_tmp2_ = _data1_->main_loop;
	g_main_loop_quit (_tmp2_);
}


static void ___lambda4__gasync_ready_callback (GObject* source_object, GAsyncResult* res, gpointer self) {
	__lambda4_ (self, source_object, res);
	block1_data_unref (self);
}


gint folks_import_tool_main (gchar** args, int args_length1) {
	gint result = 0;
	Block1Data* _data1_;
	GOptionContext* context;
	GOptionContext* _tmp0_;
	GOptionContext* _tmp1_;
	gboolean _tmp8_ = FALSE;
	const gchar* _tmp9_;
	FolksIndividualAggregator* aggregator;
	FolksIndividualAggregator* _tmp14_;
	GMainLoop* _tmp15_;
	GMainLoop* _tmp16_;
	gint _tmp17_ = 0;
	gboolean _tmp18_;
	GError * _inner_error_ = NULL;
	_data1_ = g_slice_new0 (Block1Data);
	_data1_->_ref_count_ = 1;
	setlocale (LC_ALL, "");
	bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR);
	textdomain (GETTEXT_PACKAGE);
	_tmp0_ = g_option_context_new (_ ("— import meta-contact information to libfolks"));
	context = _tmp0_;
	_tmp1_ = context;
	g_option_context_add_main_entries (_tmp1_, FOLKS_IMPORT_TOOL_options, "folks");
	{
		GOptionContext* _tmp2_;
		_tmp2_ = context;
		g_option_context_parse (_tmp2_, &args_length1, &args, &_inner_error_);
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			if (_inner_error_->domain == G_OPTION_ERROR) {
				goto __catch0_g_option_error;
			}
			_g_option_context_free0 (context);
			block1_data_unref (_data1_);
			_data1_ = NULL;
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
	}
	goto __finally0;
	__catch0_g_option_error:
	{
		GError* e = NULL;
		FILE* _tmp3_;
		gchar* _tmp4_;
		gchar* _tmp5_;
		GError* _tmp6_;
		const gchar* _tmp7_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp3_ = stderr;
		_tmp4_ = g_strconcat (_ ("Couldn’t parse command line options: %s"), "\n", NULL);
		_tmp5_ = _tmp4_;
		_tmp6_ = e;
		_tmp7_ = _tmp6_->message;
		fprintf (_tmp3_, _tmp5_, _tmp7_);
		_g_free0 (_tmp5_);
		result = 1;
		_g_error_free0 (e);
		_g_option_context_free0 (context);
		block1_data_unref (_data1_);
		_data1_ = NULL;
		return result;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		_g_option_context_free0 (context);
		block1_data_unref (_data1_);
		_data1_ = NULL;
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return 0;
	}
	_tmp9_ = folks_import_tool_source;
	if (_tmp9_ == NULL) {
		_tmp8_ = TRUE;
	} else {
		const gchar* _tmp10_;
		gchar* _tmp11_;
		gchar* _tmp12_;
		_tmp10_ = folks_import_tool_source;
		_tmp11_ = string_strip (_tmp10_);
		_tmp12_ = _tmp11_;
		_tmp8_ = g_strcmp0 (_tmp12_, "") == 0;
		_g_free0 (_tmp12_);
	}
	if (_tmp8_) {
		gchar* _tmp13_;
		_tmp13_ = g_strdup (FOLKS_IMPORT_TOOL_DEFAULT_SOURCE);
		_g_free0 (folks_import_tool_source);
		folks_import_tool_source = _tmp13_;
	}
	_tmp14_ = folks_individual_aggregator_dup ();
	aggregator = _tmp14_;
	_g_object_unref0 (aggregator);
	aggregator = NULL;
	_tmp15_ = g_main_loop_new (NULL, FALSE);
	_data1_->main_loop = _tmp15_;
	_data1_->success = FALSE;
	folks_import_tool_import (___lambda4__gasync_ready_callback, block1_data_ref (_data1_));
	_tmp16_ = _data1_->main_loop;
	g_main_loop_run (_tmp16_);
	_tmp18_ = _data1_->success;
	if (_tmp18_) {
		_tmp17_ = 0;
	} else {
		_tmp17_ = 1;
	}
	result = _tmp17_;
	_g_object_unref0 (aggregator);
	_g_option_context_free0 (context);
	block1_data_unref (_data1_);
	_data1_ = NULL;
	return result;
}


int main (int argc, char ** argv) {
#if !GLIB_CHECK_VERSION (2,35,0)
	g_type_init ();
#endif
	return folks_import_tool_main (argv, argc);
}


static void folks_import_tool_import_data_free (gpointer _data) {
	FolksImportToolImportData* _data_;
	_data_ = _data;
	g_slice_free (FolksImportToolImportData, _data_);
}


static void folks_import_tool_import (GAsyncReadyCallback _callback_, gpointer _user_data_) {
	FolksImportToolImportData* _data_;
	_data_ = g_slice_new0 (FolksImportToolImportData);
	_data_->_async_result = g_simple_async_result_new (NULL, _callback_, _user_data_, folks_import_tool_import);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, folks_import_tool_import_data_free);
	folks_import_tool_import_co (_data_);
}


static gboolean folks_import_tool_import_finish (GAsyncResult* _res_) {
	gboolean result;
	FolksImportToolImportData* _data_;
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
	result = _data_->result;
	return result;
}


static void folks_import_tool_import_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	FolksImportToolImportData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	folks_import_tool_import_co (_data_);
}


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


static gboolean folks_import_tool_import_co (FolksImportToolImportData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		case 4:
		goto _state_4;
		case 5:
		goto _state_5;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = folks_backend_store_dup ();
	_data_->backend_store = _data_->_tmp0_;
	{
		_data_->_tmp1_ = _data_->backend_store;
		_data_->_state_ = 1;
		folks_backend_store_load_backends (_data_->_tmp1_, folks_import_tool_import_ready, _data_);
		return FALSE;
		_state_1:
		folks_backend_store_load_backends_finish (_data_->_tmp1_, _data_->_res_, &_data_->_inner_error_);
		if (G_UNLIKELY (_data_->_inner_error_ != NULL)) {
			goto __catch1_g_error;
		}
	}
	goto __finally1;
	__catch1_g_error:
	{
		_data_->e1 = _data_->_inner_error_;
		_data_->_inner_error_ = NULL;
		_data_->_tmp2_ = stderr;
		_data_->_tmp3_ = g_strconcat (_ ("Couldn’t load the backends: %s"), "\n", NULL);
		_data_->_tmp4_ = _data_->_tmp3_;
		_data_->_tmp5_ = _data_->e1;
		_data_->_tmp6_ = _data_->_tmp5_->message;
		fprintf (_data_->_tmp2_, _data_->_tmp4_, _data_->_tmp6_);
		_g_free0 (_data_->_tmp4_);
		_data_->result = FALSE;
		_g_error_free0 (_data_->e1);
		_g_object_unref0 (_data_->backend_store);
		if (_data_->_state_ == 0) {
			g_simple_async_result_complete_in_idle (_data_->_async_result);
		} else {
			g_simple_async_result_complete (_data_->_async_result);
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	__finally1:
	if (G_UNLIKELY (_data_->_inner_error_ != NULL)) {
		_g_object_unref0 (_data_->backend_store);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
		g_clear_error (&_data_->_inner_error_);
		return FALSE;
	}
	_data_->_tmp7_ = _data_->backend_store;
	_data_->_tmp8_ = folks_backend_store_dup_backend_by_name (_data_->_tmp7_, "key-file");
	_data_->kf_backend = _data_->_tmp8_;
	_data_->_tmp9_ = _data_->kf_backend;
	if (_data_->_tmp9_ == NULL) {
		_data_->_tmp10_ = stderr;
		_data_->_tmp11_ = g_strconcat (_ ("Couldn’t load the ‘%s’ backend."), "\n", NULL);
		_data_->_tmp12_ = _data_->_tmp11_;
		fprintf (_data_->_tmp10_, _data_->_tmp12_, "key-file");
		_g_free0 (_data_->_tmp12_);
		_data_->result = FALSE;
		_g_object_unref0 (_data_->kf_backend);
		_g_object_unref0 (_data_->backend_store);
		if (_data_->_state_ == 0) {
			g_simple_async_result_complete_in_idle (_data_->_async_result);
		} else {
			g_simple_async_result_complete (_data_->_async_result);
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	{
		_data_->_tmp13_ = _data_->kf_backend;
		_data_->_state_ = 2;
		folks_backend_prepare (_data_->_tmp13_, folks_import_tool_import_ready, _data_);
		return FALSE;
		_state_2:
		folks_backend_prepare_finish (_data_->_tmp13_, _data_->_res_, &_data_->_inner_error_);
		if (G_UNLIKELY (_data_->_inner_error_ != NULL)) {
			goto __catch2_g_error;
		}
	}
	goto __finally2;
	__catch2_g_error:
	{
		_data_->e2 = _data_->_inner_error_;
		_data_->_inner_error_ = NULL;
		_data_->_tmp14_ = stderr;
		_data_->_tmp15_ = g_strconcat (_ ("Couldn’t prepare the ‘%s’ backend: %s"), "\n", NULL);
		_data_->_tmp16_ = _data_->_tmp15_;
		_data_->_tmp17_ = _data_->e2;
		_data_->_tmp18_ = _data_->_tmp17_->message;
		fprintf (_data_->_tmp14_, _data_->_tmp16_, "key-file", _data_->_tmp18_);
		_g_free0 (_data_->_tmp16_);
		_data_->result = FALSE;
		_g_error_free0 (_data_->e2);
		_g_object_unref0 (_data_->kf_backend);
		_g_object_unref0 (_data_->backend_store);
		if (_data_->_state_ == 0) {
			g_simple_async_result_complete_in_idle (_data_->_async_result);
		} else {
			g_simple_async_result_complete (_data_->_async_result);
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	__finally2:
	if (G_UNLIKELY (_data_->_inner_error_ != NULL)) {
		_g_object_unref0 (_data_->kf_backend);
		_g_object_unref0 (_data_->backend_store);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
		g_clear_error (&_data_->_inner_error_);
		return FALSE;
	}
	_data_->destination_store = NULL;
	_data_->_tmp19_ = _data_->kf_backend;
	_data_->_tmp20_ = folks_backend_get_persona_stores (_data_->_tmp19_);
	_data_->_tmp21_ = _data_->_tmp20_;
	_data_->_tmp22_ = gee_map_get_values (_data_->_tmp21_);
	_data_->_tmp23_ = _data_->_tmp22_;
	_data_->stores = _data_->_tmp23_;
	_data_->_tmp24_ = _data_->stores;
	_data_->_tmp25_ = gee_collection_get_size (_data_->_tmp24_);
	_data_->_tmp26_ = _data_->_tmp25_;
	if (_data_->_tmp26_ == 0) {
		_data_->_tmp27_ = stderr;
		_data_->_tmp28_ = g_strconcat (_ ("Couldn’t load the ‘%s’ backend’s persona store."), "\n", NULL);
		_data_->_tmp29_ = _data_->_tmp28_;
		fprintf (_data_->_tmp27_, _data_->_tmp29_, "key-file");
		_g_free0 (_data_->_tmp29_);
		_data_->result = FALSE;
		_g_object_unref0 (_data_->stores);
		_g_object_unref0 (_data_->destination_store);
		_g_object_unref0 (_data_->kf_backend);
		_g_object_unref0 (_data_->backend_store);
		if (_data_->_state_ == 0) {
			g_simple_async_result_complete_in_idle (_data_->_async_result);
		} else {
			g_simple_async_result_complete (_data_->_async_result);
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	{
		{
			_data_->_tmp30_ = _data_->stores;
			_data_->_tmp31_ = gee_iterable_iterator ((GeeIterable*) _data_->_tmp30_);
			_data_->_persona_store_it = _data_->_tmp31_;
			while (TRUE) {
				_data_->_tmp32_ = _data_->_persona_store_it;
				_data_->_tmp33_ = gee_iterator_next (_data_->_tmp32_);
				if (!_data_->_tmp33_) {
					break;
				}
				_data_->_tmp34_ = _data_->_persona_store_it;
				_data_->_tmp35_ = gee_iterator_get (_data_->_tmp34_);
				_data_->persona_store = (FolksPersonaStore*) _data_->_tmp35_;
				_data_->_tmp36_ = _data_->persona_store;
				_data_->_tmp37_ = _g_object_ref0 (_data_->_tmp36_);
				_g_object_unref0 (_data_->destination_store);
				_data_->destination_store = _data_->_tmp37_;
				_g_object_unref0 (_data_->persona_store);
				break;
			}
			_g_object_unref0 (_data_->_persona_store_it);
		}
		_data_->_tmp38_ = _data_->destination_store;
		_data_->_state_ = 3;
		folks_persona_store_prepare (_data_->_tmp38_, folks_import_tool_import_ready, _data_);
		return FALSE;
		_state_3:
		folks_persona_store_prepare_finish (_data_->_tmp38_, _data_->_res_, &_data_->_inner_error_);
		if (G_UNLIKELY (_data_->_inner_error_ != NULL)) {
			goto __catch3_g_error;
		}
	}
	goto __finally3;
	__catch3_g_error:
	{
		_data_->e3 = _data_->_inner_error_;
		_data_->_inner_error_ = NULL;
		_data_->_tmp39_ = stderr;
		_data_->_tmp40_ = g_strconcat (_ ("Couldn’t prepare the ‘%s’ backend’s persona store: %s"), "\n", NULL);
		_data_->_tmp41_ = _data_->_tmp40_;
		_data_->_tmp42_ = _data_->e3;
		_data_->_tmp43_ = _data_->_tmp42_->message;
		fprintf (_data_->_tmp39_, _data_->_tmp41_, _data_->_tmp43_);
		_g_free0 (_data_->_tmp41_);
		_data_->result = FALSE;
		_g_error_free0 (_data_->e3);
		_g_object_unref0 (_data_->stores);
		_g_object_unref0 (_data_->destination_store);
		_g_object_unref0 (_data_->kf_backend);
		_g_object_unref0 (_data_->backend_store);
		if (_data_->_state_ == 0) {
			g_simple_async_result_complete_in_idle (_data_->_async_result);
		} else {
			g_simple_async_result_complete (_data_->_async_result);
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	__finally3:
	if (G_UNLIKELY (_data_->_inner_error_ != NULL)) {
		_g_object_unref0 (_data_->stores);
		_g_object_unref0 (_data_->destination_store);
		_g_object_unref0 (_data_->kf_backend);
		_g_object_unref0 (_data_->backend_store);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
		g_clear_error (&_data_->_inner_error_);
		return FALSE;
	}
	_data_->_tmp44_ = folks_import_tool_source;
	if (g_strcmp0 (_data_->_tmp44_, "pidgin") == 0) {
		_data_->_tmp45_ = folks_importers_pidgin_new ();
		_data_->importer = (FolksImporter*) _data_->_tmp45_;
		{
			_data_->_tmp46_ = _data_->importer;
			_data_->_tmp47_ = _data_->destination_store;
			_data_->_tmp48_ = folks_import_tool_source_filename;
			_data_->_state_ = 4;
			folks_importer_import (_data_->_tmp46_, _data_->_tmp47_, _data_->_tmp48_, folks_import_tool_import_ready, _data_);
			return FALSE;
			_state_4:
			folks_importer_import_finish (_data_->_tmp46_, _data_->_res_, &_data_->_inner_error_);
			if (G_UNLIKELY (_data_->_inner_error_ != NULL)) {
				if (_data_->_inner_error_->domain == FOLKS_IMPORT_ERROR) {
					goto __catch4_folks_import_error;
				}
				_g_object_unref0 (_data_->importer);
				_g_object_unref0 (_data_->stores);
				_g_object_unref0 (_data_->destination_store);
				_g_object_unref0 (_data_->kf_backend);
				_g_object_unref0 (_data_->backend_store);
				g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
				g_clear_error (&_data_->_inner_error_);
				return FALSE;
			}
		}
		goto __finally4;
		__catch4_folks_import_error:
		{
			_data_->e = _data_->_inner_error_;
			_data_->_inner_error_ = NULL;
			_data_->_tmp49_ = stderr;
			_data_->_tmp50_ = g_strconcat (_ ("Error importing contacts: %s"), "\n", NULL);
			_data_->_tmp51_ = _data_->_tmp50_;
			_data_->_tmp52_ = _data_->e;
			_data_->_tmp53_ = _data_->_tmp52_->message;
			fprintf (_data_->_tmp49_, _data_->_tmp51_, _data_->_tmp53_);
			_g_free0 (_data_->_tmp51_);
			_data_->result = FALSE;
			_g_error_free0 (_data_->e);
			_g_object_unref0 (_data_->importer);
			_g_object_unref0 (_data_->stores);
			_g_object_unref0 (_data_->destination_store);
			_g_object_unref0 (_data_->kf_backend);
			_g_object_unref0 (_data_->backend_store);
			if (_data_->_state_ == 0) {
				g_simple_async_result_complete_in_idle (_data_->_async_result);
			} else {
				g_simple_async_result_complete (_data_->_async_result);
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		__finally4:
		if (G_UNLIKELY (_data_->_inner_error_ != NULL)) {
			_g_object_unref0 (_data_->importer);
			_g_object_unref0 (_data_->stores);
			_g_object_unref0 (_data_->destination_store);
			_g_object_unref0 (_data_->kf_backend);
			_g_object_unref0 (_data_->backend_store);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
			g_clear_error (&_data_->_inner_error_);
			return FALSE;
		}
		_data_->_tmp54_ = _data_->destination_store;
		_data_->_state_ = 5;
		folks_persona_store_flush (_data_->_tmp54_, folks_import_tool_import_ready, _data_);
		return FALSE;
		_state_5:
		folks_persona_store_flush_finish (_data_->_tmp54_, _data_->_res_);
		_data_->result = TRUE;
		_g_object_unref0 (_data_->importer);
		_g_object_unref0 (_data_->stores);
		_g_object_unref0 (_data_->destination_store);
		_g_object_unref0 (_data_->kf_backend);
		_g_object_unref0 (_data_->backend_store);
		if (_data_->_state_ == 0) {
			g_simple_async_result_complete_in_idle (_data_->_async_result);
		} else {
			g_simple_async_result_complete (_data_->_async_result);
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	} else {
		_data_->_tmp55_ = stderr;
		_data_->_tmp56_ = g_strconcat (_ ("Unrecognized source backend name ‘%s’. ‘%s’ is currently the only supp" \
"orted source backend."), "\n", NULL);
		_data_->_tmp57_ = _data_->_tmp56_;
		_data_->_tmp58_ = folks_import_tool_source;
		fprintf (_data_->_tmp55_, _data_->_tmp57_, _data_->_tmp58_, "pidgin");
		_g_free0 (_data_->_tmp57_);
		_data_->result = FALSE;
		_g_object_unref0 (_data_->stores);
		_g_object_unref0 (_data_->destination_store);
		_g_object_unref0 (_data_->kf_backend);
		_g_object_unref0 (_data_->backend_store);
		if (_data_->_state_ == 0) {
			g_simple_async_result_complete_in_idle (_data_->_async_result);
		} else {
			g_simple_async_result_complete (_data_->_async_result);
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_g_object_unref0 (_data_->stores);
	_g_object_unref0 (_data_->destination_store);
	_g_object_unref0 (_data_->kf_backend);
	_g_object_unref0 (_data_->backend_store);
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


FolksImportTool* folks_import_tool_construct (GType object_type) {
	FolksImportTool * self = NULL;
	self = (FolksImportTool*) g_object_new (object_type, NULL);
	return self;
}


FolksImportTool* folks_import_tool_new (void) {
	return folks_import_tool_construct (FOLKS_TYPE_IMPORT_TOOL);
}


static void folks_import_tool_class_init (FolksImportToolClass * klass) {
	folks_import_tool_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = folks_import_tool_finalize;
}


static void folks_import_tool_instance_init (FolksImportTool * self) {
}


static void folks_import_tool_finalize (GObject * obj) {
	FolksImportTool * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FOLKS_TYPE_IMPORT_TOOL, FolksImportTool);
	G_OBJECT_CLASS (folks_import_tool_parent_class)->finalize (obj);
}


GType folks_import_tool_get_type (void) {
	static volatile gsize folks_import_tool_type_id__volatile = 0;
	if (g_once_init_enter (&folks_import_tool_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (FolksImportToolClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) folks_import_tool_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FolksImportTool), 0, (GInstanceInitFunc) folks_import_tool_instance_init, NULL };
		GType folks_import_tool_type_id;
		folks_import_tool_type_id = g_type_register_static (G_TYPE_OBJECT, "FolksImportTool", &g_define_type_info, 0);
		g_once_init_leave (&folks_import_tool_type_id__volatile, folks_import_tool_type_id);
	}
	return folks_import_tool_type_id__volatile;
}


GQuark folks_import_error_quark (void) {
	return g_quark_from_static_string ("folks_import_error-quark");
}


void folks_importer_import (FolksImporter* self, FolksPersonaStore* destination_store, const gchar* source_filename, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	FOLKS_IMPORTER_GET_CLASS (self)->import (self, destination_store, source_filename, _callback_, _user_data_);
}


guint folks_importer_import_finish (FolksImporter* self, GAsyncResult* _res_, GError** error) {
	return FOLKS_IMPORTER_GET_CLASS (self)->import_finish (self, _res_, error);
}


FolksImporter* folks_importer_construct (GType object_type) {
	FolksImporter * self = NULL;
	self = (FolksImporter*) g_object_new (object_type, NULL);
	return self;
}


static void folks_importer_class_init (FolksImporterClass * klass) {
	folks_importer_parent_class = g_type_class_peek_parent (klass);
}


static void folks_importer_instance_init (FolksImporter * self) {
}


GType folks_importer_get_type (void) {
	static volatile gsize folks_importer_type_id__volatile = 0;
	if (g_once_init_enter (&folks_importer_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (FolksImporterClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) folks_importer_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FolksImporter), 0, (GInstanceInitFunc) folks_importer_instance_init, NULL };
		GType folks_importer_type_id;
		folks_importer_type_id = g_type_register_static (G_TYPE_OBJECT, "FolksImporter", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
		g_once_init_leave (&folks_importer_type_id__volatile, folks_importer_type_id);
	}
	return folks_importer_type_id__volatile;
}



