/* import.c generated by valac 0.17.2.19-5f50d, 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 <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* _tmp0_;
	FolksBackendStore* backend_store;
	FolksBackendStore* _tmp1_;
	GError* e1;
	FILE* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	GError* _tmp6_;
	const gchar* _tmp7_;
	FolksBackendStore* _tmp8_;
	FolksBackend* _tmp9_;
	FolksBackend* kf_backend;
	FolksBackend* _tmp10_;
	FILE* _tmp11_;
	const gchar* _tmp12_;
	gchar* _tmp13_;
	gchar* _tmp14_;
	FolksBackend* _tmp15_;
	GError* e2;
	FILE* _tmp16_;
	const gchar* _tmp17_;
	gchar* _tmp18_;
	gchar* _tmp19_;
	GError* _tmp20_;
	const gchar* _tmp21_;
	FolksPersonaStore* destination_store;
	FolksBackend* _tmp22_;
	GeeMap* _tmp23_;
	GeeMap* _tmp24_;
	GeeCollection* _tmp25_;
	GeeCollection* _tmp26_;
	GeeCollection* stores;
	GeeCollection* _tmp27_;
	gint _tmp28_;
	gint _tmp29_;
	FILE* _tmp30_;
	const gchar* _tmp31_;
	gchar* _tmp32_;
	gchar* _tmp33_;
	GeeCollection* _tmp34_;
	GeeIterator* _tmp35_;
	GeeIterator* _persona_store_it;
	GeeIterator* _tmp36_;
	gboolean _tmp37_;
	GeeIterator* _tmp38_;
	gpointer _tmp39_;
	FolksPersonaStore* persona_store;
	FolksPersonaStore* _tmp40_;
	FolksPersonaStore* _tmp41_;
	FolksPersonaStore* _tmp42_;
	GError* e3;
	FILE* _tmp43_;
	const gchar* _tmp44_;
	gchar* _tmp45_;
	gchar* _tmp46_;
	GError* _tmp47_;
	const gchar* _tmp48_;
	const gchar* _tmp49_;
	FolksImportersPidgin* _tmp50_;
	FolksImporter* importer;
	FolksImporter* _tmp51_;
	FolksPersonaStore* _tmp52_;
	const gchar* _tmp53_;
	GError* e;
	FILE* _tmp54_;
	const gchar* _tmp55_;
	gchar* _tmp56_;
	gchar* _tmp57_;
	GError* _tmp58_;
	const gchar* _tmp59_;
	FolksPersonaStore* _tmp60_;
	FILE* _tmp61_;
	const gchar* _tmp62_;
	gchar* _tmp63_;
	gchar* _tmp64_;
	const gchar* _tmp65_;
	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 __lambda2_ (Block1Data* _data1_, GObject* o, GAsyncResult* r);
static void ___lambda2__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_);
FolksImportersPidgin* folks_importers_pidgin_new (void);
FolksImportersPidgin* folks_importers_pidgin_construct (GType object_type);
GType folks_importer_get_type (void) G_GNUC_CONST;
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, "Source backend name (default: 'pidgin')", "name"}, {"source-filename", (gchar) 0, 0, G_OPTION_ARG_FILENAME, &folks_import_tool_source_filename, "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* _tmp0_ = NULL;
	gchar* _result_;
	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 __lambda2_ (Block1Data* _data1_, GObject* o, GAsyncResult* r) {
	GAsyncResult* _tmp0_;
	gboolean _tmp1_ = FALSE;
	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 ___lambda2__gasync_ready_callback (GObject* source_object, GAsyncResult* res, gpointer self) {
	__lambda2_ (self, source_object, res);
	block1_data_unref (self);
}


gint folks_import_tool_main (gchar** args, int args_length1) {
	gint result = 0;
	Block1Data* _data1_;
	const gchar* _tmp0_ = NULL;
	GOptionContext* _tmp1_;
	GOptionContext* context;
	GOptionContext* _tmp2_;
	gboolean _tmp10_ = FALSE;
	const gchar* _tmp11_;
	gboolean _tmp15_;
	FolksIndividualAggregator* _tmp17_;
	FolksIndividualAggregator* aggregator;
	GMainLoop* _tmp18_;
	GMainLoop* _tmp19_;
	gint _tmp20_ = 0;
	gboolean _tmp21_;
	gint _tmp22_;
	GError * _inner_error_ = NULL;
	_data1_ = g_slice_new0 (Block1Data);
	_data1_->_ref_count_ = 1;
	bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR);
	textdomain (GETTEXT_PACKAGE);
	_tmp0_ = _ ("— import meta-contact information to libfolks");
	_tmp1_ = g_option_context_new (_tmp0_);
	context = _tmp1_;
	_tmp2_ = context;
	g_option_context_add_main_entries (_tmp2_, FOLKS_IMPORT_TOOL_options, "folks");
	{
		GOptionContext* _tmp3_;
		_tmp3_ = context;
		g_option_context_parse (_tmp3_, &args_length1, &args, &_inner_error_);
		if (_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* _tmp4_;
		const gchar* _tmp5_ = NULL;
		gchar* _tmp6_;
		gchar* _tmp7_;
		GError* _tmp8_;
		const gchar* _tmp9_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp4_ = stderr;
		_tmp5_ = _ ("Couldn't parse command line options: %s");
		_tmp6_ = g_strconcat (_tmp5_, "\n", NULL);
		_tmp7_ = _tmp6_;
		_tmp8_ = e;
		_tmp9_ = _tmp8_->message;
		fprintf (_tmp4_, _tmp7_, _tmp9_);
		_g_free0 (_tmp7_);
		result = 1;
		_g_error_free0 (e);
		_g_option_context_free0 (context);
		block1_data_unref (_data1_);
		_data1_ = NULL;
		return result;
	}
	__finally0:
	if (_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;
	}
	_tmp11_ = folks_import_tool_source;
	if (_tmp11_ == NULL) {
		_tmp10_ = TRUE;
	} else {
		const gchar* _tmp12_;
		gchar* _tmp13_ = NULL;
		gchar* _tmp14_;
		_tmp12_ = folks_import_tool_source;
		_tmp13_ = string_strip (_tmp12_);
		_tmp14_ = _tmp13_;
		_tmp10_ = g_strcmp0 (_tmp14_, "") == 0;
		_g_free0 (_tmp14_);
	}
	_tmp15_ = _tmp10_;
	if (_tmp15_) {
		gchar* _tmp16_;
		_tmp16_ = g_strdup (FOLKS_IMPORT_TOOL_DEFAULT_SOURCE);
		_g_free0 (folks_import_tool_source);
		folks_import_tool_source = _tmp16_;
	}
	_tmp17_ = folks_individual_aggregator_new ();
	aggregator = _tmp17_;
	_g_object_unref0 (aggregator);
	aggregator = NULL;
	_tmp18_ = g_main_loop_new (NULL, FALSE);
	_data1_->main_loop = _tmp18_;
	_data1_->success = FALSE;
	folks_import_tool_import (___lambda2__gasync_ready_callback, block1_data_ref (_data1_));
	_tmp19_ = _data1_->main_loop;
	g_main_loop_run (_tmp19_);
	_tmp21_ = _data1_->success;
	if (_tmp21_) {
		_tmp20_ = 0;
	} else {
		_tmp20_ = 1;
	}
	_tmp22_ = _tmp20_;
	result = _tmp22_;
	_g_object_unref0 (aggregator);
	_g_option_context_free0 (context);
	block1_data_unref (_data1_);
	_data1_ = NULL;
	return result;
}


int main (int argc, char ** argv) {
	g_type_init ();
	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 (g_object_newv (G_TYPE_OBJECT, 0, 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_ = NULL;
	_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 (_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_ = NULL;
		_data_->_tmp3_ = _ ("Couldn't load the backends: %s");
		_data_->_tmp4_ = g_strconcat (_data_->_tmp3_, "\n", NULL);
		_data_->_tmp5_ = _data_->_tmp4_;
		_data_->_tmp6_ = _data_->e1;
		_data_->_tmp7_ = _data_->_tmp6_->message;
		fprintf (_data_->_tmp2_, _data_->_tmp5_, _data_->_tmp7_);
		_g_free0 (_data_->_tmp5_);
		_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 (_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_->_tmp8_ = _data_->backend_store;
	_data_->_tmp9_ = NULL;
	_data_->_tmp9_ = folks_backend_store_dup_backend_by_name (_data_->_tmp8_, "key-file");
	_data_->kf_backend = _data_->_tmp9_;
	_data_->_tmp10_ = _data_->kf_backend;
	if (_data_->_tmp10_ == NULL) {
		_data_->_tmp11_ = stderr;
		_data_->_tmp12_ = NULL;
		_data_->_tmp12_ = _ ("Couldn't load the ‘%s’ backend.");
		_data_->_tmp13_ = g_strconcat (_data_->_tmp12_, "\n", NULL);
		_data_->_tmp14_ = _data_->_tmp13_;
		fprintf (_data_->_tmp11_, _data_->_tmp14_, "key-file");
		_g_free0 (_data_->_tmp14_);
		_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_->_tmp15_ = _data_->kf_backend;
		_data_->_state_ = 2;
		folks_backend_prepare (_data_->_tmp15_, folks_import_tool_import_ready, _data_);
		return FALSE;
		_state_2:
		folks_backend_prepare_finish (_data_->_tmp15_, _data_->_res_, &_data_->_inner_error_);
		if (_data_->_inner_error_ != NULL) {
			goto __catch2_g_error;
		}
	}
	goto __finally2;
	__catch2_g_error:
	{
		_data_->e2 = _data_->_inner_error_;
		_data_->_inner_error_ = NULL;
		_data_->_tmp16_ = stderr;
		_data_->_tmp17_ = NULL;
		_data_->_tmp17_ = _ ("Couldn't prepare the ‘%s’ backend: %s");
		_data_->_tmp18_ = g_strconcat (_data_->_tmp17_, "\n", NULL);
		_data_->_tmp19_ = _data_->_tmp18_;
		_data_->_tmp20_ = _data_->e2;
		_data_->_tmp21_ = _data_->_tmp20_->message;
		fprintf (_data_->_tmp16_, _data_->_tmp19_, "key-file", _data_->_tmp21_);
		_g_free0 (_data_->_tmp19_);
		_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 (_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_->_tmp22_ = _data_->kf_backend;
	_data_->_tmp23_ = folks_backend_get_persona_stores (_data_->_tmp22_);
	_data_->_tmp24_ = _data_->_tmp23_;
	_data_->_tmp25_ = gee_map_get_values (_data_->_tmp24_);
	_data_->_tmp26_ = _data_->_tmp25_;
	_data_->stores = _data_->_tmp26_;
	_data_->_tmp27_ = _data_->stores;
	_data_->_tmp28_ = gee_collection_get_size (_data_->_tmp27_);
	_data_->_tmp29_ = _data_->_tmp28_;
	if (_data_->_tmp29_ == 0) {
		_data_->_tmp30_ = stderr;
		_data_->_tmp31_ = NULL;
		_data_->_tmp31_ = _ ("Couldn't load the ‘%s’ backend's persona store.");
		_data_->_tmp32_ = g_strconcat (_data_->_tmp31_, "\n", NULL);
		_data_->_tmp33_ = _data_->_tmp32_;
		fprintf (_data_->_tmp30_, _data_->_tmp33_, "key-file");
		_g_free0 (_data_->_tmp33_);
		_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_->_tmp34_ = _data_->stores;
			_data_->_tmp35_ = NULL;
			_data_->_tmp35_ = gee_iterable_iterator ((GeeIterable*) _data_->_tmp34_);
			_data_->_persona_store_it = _data_->_tmp35_;
			while (TRUE) {
				_data_->_tmp36_ = _data_->_persona_store_it;
				_data_->_tmp37_ = FALSE;
				_data_->_tmp37_ = gee_iterator_next (_data_->_tmp36_);
				if (!_data_->_tmp37_) {
					break;
				}
				_data_->_tmp38_ = _data_->_persona_store_it;
				_data_->_tmp39_ = NULL;
				_data_->_tmp39_ = gee_iterator_get (_data_->_tmp38_);
				_data_->persona_store = (FolksPersonaStore*) _data_->_tmp39_;
				_data_->_tmp40_ = _data_->persona_store;
				_data_->_tmp41_ = _g_object_ref0 (_data_->_tmp40_);
				_g_object_unref0 (_data_->destination_store);
				_data_->destination_store = _data_->_tmp41_;
				_g_object_unref0 (_data_->persona_store);
				break;
			}
			_g_object_unref0 (_data_->_persona_store_it);
		}
		_data_->_tmp42_ = _data_->destination_store;
		_data_->_state_ = 3;
		folks_persona_store_prepare (_data_->_tmp42_, folks_import_tool_import_ready, _data_);
		return FALSE;
		_state_3:
		folks_persona_store_prepare_finish (_data_->_tmp42_, _data_->_res_, &_data_->_inner_error_);
		if (_data_->_inner_error_ != NULL) {
			goto __catch3_g_error;
		}
	}
	goto __finally3;
	__catch3_g_error:
	{
		_data_->e3 = _data_->_inner_error_;
		_data_->_inner_error_ = NULL;
		_data_->_tmp43_ = stderr;
		_data_->_tmp44_ = NULL;
		_data_->_tmp44_ = _ ("Couldn't prepare the ‘%s’ backend's persona store: %s");
		_data_->_tmp45_ = g_strconcat (_data_->_tmp44_, "\n", NULL);
		_data_->_tmp46_ = _data_->_tmp45_;
		_data_->_tmp47_ = _data_->e3;
		_data_->_tmp48_ = _data_->_tmp47_->message;
		fprintf (_data_->_tmp43_, _data_->_tmp46_, _data_->_tmp48_);
		_g_free0 (_data_->_tmp46_);
		_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 (_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_->_tmp49_ = folks_import_tool_source;
	if (g_strcmp0 (_data_->_tmp49_, "pidgin") == 0) {
		_data_->_tmp50_ = folks_importers_pidgin_new ();
		_data_->importer = (FolksImporter*) _data_->_tmp50_;
		{
			_data_->_tmp51_ = _data_->importer;
			_data_->_tmp52_ = _data_->destination_store;
			_data_->_tmp53_ = folks_import_tool_source_filename;
			_data_->_state_ = 4;
			folks_importer_import (_data_->_tmp51_, _data_->_tmp52_, _data_->_tmp53_, folks_import_tool_import_ready, _data_);
			return FALSE;
			_state_4:
			folks_importer_import_finish (_data_->_tmp51_, _data_->_res_, &_data_->_inner_error_);
			if (_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_->_tmp54_ = stderr;
			_data_->_tmp55_ = NULL;
			_data_->_tmp55_ = _ ("Error importing contacts: %s");
			_data_->_tmp56_ = g_strconcat (_data_->_tmp55_, "\n", NULL);
			_data_->_tmp57_ = _data_->_tmp56_;
			_data_->_tmp58_ = _data_->e;
			_data_->_tmp59_ = _data_->_tmp58_->message;
			fprintf (_data_->_tmp54_, _data_->_tmp57_, _data_->_tmp59_);
			_g_free0 (_data_->_tmp57_);
			_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 (_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_->_tmp60_ = _data_->destination_store;
		_data_->_state_ = 5;
		folks_persona_store_flush (_data_->_tmp60_, folks_import_tool_import_ready, _data_);
		return FALSE;
		_state_5:
		folks_persona_store_flush_finish (_data_->_tmp60_, _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_->_tmp61_ = stderr;
		_data_->_tmp62_ = NULL;
		_data_->_tmp62_ = _ ("Unrecognized source backend name ‘%s’. ‘%s’ is currently the only supp" \
"orted source backend.");
		_data_->_tmp63_ = g_strconcat (_data_->_tmp62_, "\n", NULL);
		_data_->_tmp64_ = _data_->_tmp63_;
		_data_->_tmp65_ = folks_import_tool_source;
		fprintf (_data_->_tmp61_, _data_->_tmp64_, _data_->_tmp65_, "pidgin");
		_g_free0 (_data_->_tmp64_);
		_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;
}



