/* contacts-shell-search-provider.c generated by valac 0.21.2.6-90bab, the Vala compiler
 * generated from contacts-shell-search-provider.vala, do not modify */


#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <gtk/gtk.h>
#include <gee.h>
#include <stdlib.h>
#include <string.h>
#include <contacts-esd-setup.h>
#include <folks/folks.h>
#include <stdio.h>


#define CONTACTS_TYPE_SEARCH_PROVIDER (contacts_search_provider_get_type ())
#define CONTACTS_SEARCH_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONTACTS_TYPE_SEARCH_PROVIDER, ContactsSearchProvider))
#define CONTACTS_SEARCH_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONTACTS_TYPE_SEARCH_PROVIDER, ContactsSearchProviderClass))
#define CONTACTS_IS_SEARCH_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONTACTS_TYPE_SEARCH_PROVIDER))
#define CONTACTS_IS_SEARCH_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONTACTS_TYPE_SEARCH_PROVIDER))
#define CONTACTS_SEARCH_PROVIDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONTACTS_TYPE_SEARCH_PROVIDER, ContactsSearchProviderClass))

typedef struct _ContactsSearchProvider ContactsSearchProvider;
typedef struct _ContactsSearchProviderClass ContactsSearchProviderClass;
typedef struct _ContactsSearchProviderPrivate ContactsSearchProviderPrivate;

#define CONTACTS_TYPE_SEARCH_PROVIDER_APP (contacts_search_provider_app_get_type ())
#define CONTACTS_SEARCH_PROVIDER_APP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONTACTS_TYPE_SEARCH_PROVIDER_APP, ContactsSearchProviderApp))
#define CONTACTS_SEARCH_PROVIDER_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONTACTS_TYPE_SEARCH_PROVIDER_APP, ContactsSearchProviderAppClass))
#define CONTACTS_IS_SEARCH_PROVIDER_APP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONTACTS_TYPE_SEARCH_PROVIDER_APP))
#define CONTACTS_IS_SEARCH_PROVIDER_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONTACTS_TYPE_SEARCH_PROVIDER_APP))
#define CONTACTS_SEARCH_PROVIDER_APP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONTACTS_TYPE_SEARCH_PROVIDER_APP, ContactsSearchProviderAppClass))

typedef struct _ContactsSearchProviderApp ContactsSearchProviderApp;
typedef struct _ContactsSearchProviderAppClass ContactsSearchProviderAppClass;

#define CONTACTS_TYPE_STORE (contacts_store_get_type ())
#define CONTACTS_STORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONTACTS_TYPE_STORE, ContactsStore))
#define CONTACTS_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONTACTS_TYPE_STORE, ContactsStoreClass))
#define CONTACTS_IS_STORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONTACTS_TYPE_STORE))
#define CONTACTS_IS_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONTACTS_TYPE_STORE))
#define CONTACTS_STORE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONTACTS_TYPE_STORE, ContactsStoreClass))

typedef struct _ContactsStore ContactsStore;
typedef struct _ContactsStoreClass ContactsStoreClass;

#define CONTACTS_TYPE_CONTACT (contacts_contact_get_type ())
#define CONTACTS_CONTACT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONTACTS_TYPE_CONTACT, ContactsContact))
#define CONTACTS_CONTACT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONTACTS_TYPE_CONTACT, ContactsContactClass))
#define CONTACTS_IS_CONTACT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONTACTS_TYPE_CONTACT))
#define CONTACTS_IS_CONTACT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONTACTS_TYPE_CONTACT))
#define CONTACTS_CONTACT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONTACTS_TYPE_CONTACT, ContactsContactClass))

typedef struct _ContactsContact ContactsContact;
typedef struct _ContactsContactClass ContactsContactClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _ContactsContactPrivate ContactsContactPrivate;
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _ContactsSearchProviderAppPrivate ContactsSearchProviderAppPrivate;

struct _ContactsSearchProvider {
	GObject parent_instance;
	ContactsSearchProviderPrivate * priv;
};

struct _ContactsSearchProviderClass {
	GObjectClass parent_class;
};

struct _ContactsSearchProviderPrivate {
	ContactsSearchProviderApp* app;
	ContactsStore* store;
	GeeHashMap* contacts_map;
	guint next_id;
};

struct _ContactsContact {
	GObject parent_instance;
	ContactsContactPrivate * priv;
	ContactsStore* store;
	gboolean is_main;
	FolksPresenceType presence_type;
	gchar* presence_message;
	gboolean is_phone;
	FolksIndividual* individual;
};

struct _ContactsContactClass {
	GObjectClass parent_class;
};

struct _ContactsSearchProviderApp {
	GtkApplication parent_instance;
	ContactsSearchProviderAppPrivate * priv;
};

struct _ContactsSearchProviderAppClass {
	GtkApplicationClass parent_class;
};


static gpointer contacts_search_provider_parent_class = NULL;
static gpointer contacts_search_provider_app_parent_class = NULL;

GType contacts_search_provider_get_type (void) G_GNUC_CONST;
guint contacts_search_provider_register_object (void* object, GDBusConnection* connection, const gchar* path, GError** error);
GType contacts_search_provider_app_get_type (void) G_GNUC_CONST;
GType contacts_store_get_type (void) G_GNUC_CONST;
GType contacts_contact_get_type (void) G_GNUC_CONST;
#define CONTACTS_SEARCH_PROVIDER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CONTACTS_TYPE_SEARCH_PROVIDER, ContactsSearchProviderPrivate))
enum  {
	CONTACTS_SEARCH_PROVIDER_DUMMY_PROPERTY
};
ContactsSearchProvider* contacts_search_provider_new (ContactsSearchProviderApp* app);
ContactsSearchProvider* contacts_search_provider_construct (GType object_type, ContactsSearchProviderApp* app);
ContactsStore* contacts_store_new (void);
ContactsStore* contacts_store_construct (GType object_type);
static void __lambda25_ (ContactsSearchProvider* self, ContactsContact* c);
static void ___lambda25__contacts_store_changed (ContactsStore* _sender, ContactsContact* c, gpointer self);
static void __lambda26_ (ContactsSearchProvider* self, ContactsContact* c);
static void ___lambda26__contacts_store_added (ContactsStore* _sender, ContactsContact* c, gpointer self);
static void __lambda27_ (ContactsSearchProvider* self, ContactsContact* c);
static void ___lambda27__contacts_store_removed (ContactsStore* _sender, ContactsContact* c, gpointer self);
static gint contacts_search_provider_compare_contacts (ContactsContact* a, ContactsContact* b);
gboolean contacts_is_set (const gchar* str);
const gchar* contacts_contact_get_display_name (ContactsContact* self);
static gchar** contacts_search_provider_do_search (ContactsSearchProvider* self, gchar** terms, int terms_length1, int* result_length1);
gchar* contacts_utils_canonicalize_for_search (const gchar* str);
GeeCollection* contacts_store_get_contacts (ContactsStore* self);
gboolean contacts_contact_get_is_hidden (ContactsContact* self);
gboolean contacts_contact_contains_strings (ContactsContact* self, gchar** strings, int strings_length1);
gchar** contacts_search_provider_GetInitialResultSet (ContactsSearchProvider* self, gchar** terms, int terms_length1, int* result_length1);
gchar** contacts_search_provider_GetSubsearchResultSet (ContactsSearchProvider* self, gchar** previous_results, int previous_results_length1, gchar** new_terms, int new_terms_length1, int* result_length1);
GHashTable** contacts_search_provider_GetResultMetas (ContactsSearchProvider* self, gchar** ids, int ids_length1, int* result_length1);
static void _g_free0_ (gpointer var);
static void _g_variant_unref0_ (gpointer var);
GIcon* contacts_contact_get_serializable_avatar_icon (ContactsContact* self);
GVariant* contacts_contact_get_avatar_icon_data (ContactsContact* self);
void contacts_search_provider_ActivateResult (ContactsSearchProvider* self, const gchar* search_id);
static void contacts_search_provider_finalize (GObject* obj);
static void _dbus_contacts_search_provider_GetInitialResultSet (ContactsSearchProvider* self, GVariant* parameters, GDBusMethodInvocation* invocation);
static void _dbus_contacts_search_provider_GetSubsearchResultSet (ContactsSearchProvider* self, GVariant* parameters, GDBusMethodInvocation* invocation);
static void _dbus_contacts_search_provider_GetResultMetas (ContactsSearchProvider* self, GVariant* parameters, GDBusMethodInvocation* invocation);
static void _dbus_contacts_search_provider_ActivateResult (ContactsSearchProvider* self, GVariant* parameters, GDBusMethodInvocation* invocation);
static void contacts_search_provider_dbus_interface_method_call (GDBusConnection* connection, const gchar* sender, const gchar* object_path, const gchar* interface_name, const gchar* method_name, GVariant* parameters, GDBusMethodInvocation* invocation, gpointer user_data);
static GVariant* contacts_search_provider_dbus_interface_get_property (GDBusConnection* connection, const gchar* sender, const gchar* object_path, const gchar* interface_name, const gchar* property_name, GError** error, gpointer user_data);
static gboolean contacts_search_provider_dbus_interface_set_property (GDBusConnection* connection, const gchar* sender, const gchar* object_path, const gchar* interface_name, const gchar* property_name, GVariant* value, GError** error, gpointer user_data);
static void _contacts_search_provider_unregister_object (gpointer user_data);
enum  {
	CONTACTS_SEARCH_PROVIDER_APP_DUMMY_PROPERTY
};
ContactsSearchProviderApp* contacts_search_provider_app_new (void);
ContactsSearchProviderApp* contacts_search_provider_app_construct (GType object_type);
static gboolean contacts_search_provider_app_real_dbus_register (GApplication* base, GDBusConnection* connection, const gchar* object_path, GError** error);
static void contacts_search_provider_app_real_startup (GApplication* base);
gint _vala_main (void);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);
static gint _vala_array_length (gpointer array);

static const GDBusArgInfo _contacts_search_provider_dbus_arg_info_GetInitialResultSet_terms = {-1, "terms", "as"};
static const GDBusArgInfo _contacts_search_provider_dbus_arg_info_GetInitialResultSet_result = {-1, "result", "as"};
static const GDBusArgInfo * const _contacts_search_provider_dbus_arg_info_GetInitialResultSet_in[] = {&_contacts_search_provider_dbus_arg_info_GetInitialResultSet_terms, NULL};
static const GDBusArgInfo * const _contacts_search_provider_dbus_arg_info_GetInitialResultSet_out[] = {&_contacts_search_provider_dbus_arg_info_GetInitialResultSet_result, NULL};
static const GDBusMethodInfo _contacts_search_provider_dbus_method_info_GetInitialResultSet = {-1, "GetInitialResultSet", (GDBusArgInfo **) (&_contacts_search_provider_dbus_arg_info_GetInitialResultSet_in), (GDBusArgInfo **) (&_contacts_search_provider_dbus_arg_info_GetInitialResultSet_out)};
static const GDBusArgInfo _contacts_search_provider_dbus_arg_info_GetSubsearchResultSet_previous_results = {-1, "previous_results", "as"};
static const GDBusArgInfo _contacts_search_provider_dbus_arg_info_GetSubsearchResultSet_new_terms = {-1, "new_terms", "as"};
static const GDBusArgInfo _contacts_search_provider_dbus_arg_info_GetSubsearchResultSet_result = {-1, "result", "as"};
static const GDBusArgInfo * const _contacts_search_provider_dbus_arg_info_GetSubsearchResultSet_in[] = {&_contacts_search_provider_dbus_arg_info_GetSubsearchResultSet_previous_results, &_contacts_search_provider_dbus_arg_info_GetSubsearchResultSet_new_terms, NULL};
static const GDBusArgInfo * const _contacts_search_provider_dbus_arg_info_GetSubsearchResultSet_out[] = {&_contacts_search_provider_dbus_arg_info_GetSubsearchResultSet_result, NULL};
static const GDBusMethodInfo _contacts_search_provider_dbus_method_info_GetSubsearchResultSet = {-1, "GetSubsearchResultSet", (GDBusArgInfo **) (&_contacts_search_provider_dbus_arg_info_GetSubsearchResultSet_in), (GDBusArgInfo **) (&_contacts_search_provider_dbus_arg_info_GetSubsearchResultSet_out)};
static const GDBusArgInfo _contacts_search_provider_dbus_arg_info_GetResultMetas_ids = {-1, "ids", "as"};
static const GDBusArgInfo _contacts_search_provider_dbus_arg_info_GetResultMetas_result = {-1, "result", "aa{sv}"};
static const GDBusArgInfo * const _contacts_search_provider_dbus_arg_info_GetResultMetas_in[] = {&_contacts_search_provider_dbus_arg_info_GetResultMetas_ids, NULL};
static const GDBusArgInfo * const _contacts_search_provider_dbus_arg_info_GetResultMetas_out[] = {&_contacts_search_provider_dbus_arg_info_GetResultMetas_result, NULL};
static const GDBusMethodInfo _contacts_search_provider_dbus_method_info_GetResultMetas = {-1, "GetResultMetas", (GDBusArgInfo **) (&_contacts_search_provider_dbus_arg_info_GetResultMetas_in), (GDBusArgInfo **) (&_contacts_search_provider_dbus_arg_info_GetResultMetas_out)};
static const GDBusArgInfo _contacts_search_provider_dbus_arg_info_ActivateResult_search_id = {-1, "search_id", "s"};
static const GDBusArgInfo * const _contacts_search_provider_dbus_arg_info_ActivateResult_in[] = {&_contacts_search_provider_dbus_arg_info_ActivateResult_search_id, NULL};
static const GDBusArgInfo * const _contacts_search_provider_dbus_arg_info_ActivateResult_out[] = {NULL};
static const GDBusMethodInfo _contacts_search_provider_dbus_method_info_ActivateResult = {-1, "ActivateResult", (GDBusArgInfo **) (&_contacts_search_provider_dbus_arg_info_ActivateResult_in), (GDBusArgInfo **) (&_contacts_search_provider_dbus_arg_info_ActivateResult_out)};
static const GDBusMethodInfo * const _contacts_search_provider_dbus_method_info[] = {&_contacts_search_provider_dbus_method_info_GetInitialResultSet, &_contacts_search_provider_dbus_method_info_GetSubsearchResultSet, &_contacts_search_provider_dbus_method_info_GetResultMetas, &_contacts_search_provider_dbus_method_info_ActivateResult, NULL};
static const GDBusSignalInfo * const _contacts_search_provider_dbus_signal_info[] = {NULL};
static const GDBusPropertyInfo * const _contacts_search_provider_dbus_property_info[] = {NULL};
static const GDBusInterfaceInfo _contacts_search_provider_dbus_interface_info = {-1, "org.gnome.Shell.SearchProvider", (GDBusMethodInfo **) (&_contacts_search_provider_dbus_method_info), (GDBusSignalInfo **) (&_contacts_search_provider_dbus_signal_info), (GDBusPropertyInfo **) (&_contacts_search_provider_dbus_property_info)};
static const GDBusInterfaceVTable _contacts_search_provider_dbus_interface_vtable = {contacts_search_provider_dbus_interface_method_call, contacts_search_provider_dbus_interface_get_property, contacts_search_provider_dbus_interface_set_property};

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


static void __lambda25_ (ContactsSearchProvider* self, ContactsContact* c) {
	GeeHashMap* _tmp0_ = NULL;
	ContactsContact* _tmp1_ = NULL;
	gconstpointer _tmp2_ = NULL;
	ContactsContact* _tmp3_ = NULL;
	g_return_if_fail (c != NULL);
	_tmp0_ = self->priv->contacts_map;
	_tmp1_ = c;
	_tmp2_ = g_object_get_data ((GObject*) _tmp1_, "search-id");
	_tmp3_ = c;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp0_, (const gchar*) _tmp2_, _tmp3_);
}


static void ___lambda25__contacts_store_changed (ContactsStore* _sender, ContactsContact* c, gpointer self) {
	__lambda25_ (self, c);
}


static void __lambda26_ (ContactsSearchProvider* self, ContactsContact* c) {
	gchar* id = NULL;
	guint _tmp0_ = 0U;
	gchar* _tmp1_ = NULL;
	ContactsContact* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	GeeHashMap* _tmp4_ = NULL;
	ContactsContact* _tmp5_ = NULL;
	g_return_if_fail (c != NULL);
	_tmp0_ = self->priv->next_id;
	self->priv->next_id = _tmp0_ + 1;
	_tmp1_ = g_strdup_printf ("%u", _tmp0_);
	id = _tmp1_;
	_tmp2_ = c;
	_tmp3_ = g_strdup (id);
	g_object_set_data_full ((GObject*) _tmp2_, "search-id", _tmp3_, g_free);
	_tmp4_ = self->priv->contacts_map;
	_tmp5_ = c;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp4_, id, _tmp5_);
	_g_free0 (id);
}


static void ___lambda26__contacts_store_added (ContactsStore* _sender, ContactsContact* c, gpointer self) {
	__lambda26_ (self, c);
}


static void __lambda27_ (ContactsSearchProvider* self, ContactsContact* c) {
	GeeHashMap* _tmp0_ = NULL;
	ContactsContact* _tmp1_ = NULL;
	gconstpointer _tmp2_ = NULL;
	g_return_if_fail (c != NULL);
	_tmp0_ = self->priv->contacts_map;
	_tmp1_ = c;
	_tmp2_ = g_object_get_data ((GObject*) _tmp1_, "search-id");
	gee_abstract_map_unset ((GeeAbstractMap*) _tmp0_, (const gchar*) _tmp2_, NULL);
}


static void ___lambda27__contacts_store_removed (ContactsStore* _sender, ContactsContact* c, gpointer self) {
	__lambda27_ (self, c);
}


ContactsSearchProvider* contacts_search_provider_construct (GType object_type, ContactsSearchProviderApp* app) {
	ContactsSearchProvider * self = NULL;
	ContactsSearchProviderApp* _tmp0_ = NULL;
	ContactsSearchProviderApp* _tmp1_ = NULL;
	ContactsStore* _tmp2_ = NULL;
	GeeHashMap* _tmp3_ = NULL;
	ContactsStore* _tmp4_ = NULL;
	ContactsStore* _tmp5_ = NULL;
	ContactsStore* _tmp6_ = NULL;
	g_return_val_if_fail (app != NULL, NULL);
	self = (ContactsSearchProvider*) g_object_new (object_type, NULL);
	_tmp0_ = app;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->app);
	self->priv->app = _tmp1_;
	contacts_ensure_eds_accounts ();
	_tmp2_ = contacts_store_new ();
	_g_object_unref0 (self->priv->store);
	self->priv->store = _tmp2_;
	_tmp3_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, CONTACTS_TYPE_CONTACT, (GBoxedCopyFunc) g_object_ref, g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_g_object_unref0 (self->priv->contacts_map);
	self->priv->contacts_map = _tmp3_;
	self->priv->next_id = (guint) 0;
	_tmp4_ = self->priv->store;
	g_signal_connect_object (_tmp4_, "changed", (GCallback) ___lambda25__contacts_store_changed, self, 0);
	_tmp5_ = self->priv->store;
	g_signal_connect_object (_tmp5_, "added", (GCallback) ___lambda26__contacts_store_added, self, 0);
	_tmp6_ = self->priv->store;
	g_signal_connect_object (_tmp6_, "removed", (GCallback) ___lambda27__contacts_store_removed, self, 0);
	return self;
}


ContactsSearchProvider* contacts_search_provider_new (ContactsSearchProviderApp* app) {
	return contacts_search_provider_construct (CONTACTS_TYPE_SEARCH_PROVIDER, app);
}


static gint contacts_search_provider_compare_contacts (ContactsContact* a, ContactsContact* b) {
	gint result = 0;
	gint _tmp0_ = 0;
	ContactsContact* _tmp1_ = NULL;
	gboolean _tmp2_ = FALSE;
	gint a_prio = 0;
	gint _tmp3_ = 0;
	gint _tmp4_ = 0;
	ContactsContact* _tmp5_ = NULL;
	gboolean _tmp6_ = FALSE;
	gint b_prio = 0;
	gint _tmp7_ = 0;
	gint _tmp8_ = 0;
	gint _tmp9_ = 0;
	gint _tmp10_ = 0;
	gint _tmp11_ = 0;
	gboolean _tmp12_ = FALSE;
	ContactsContact* _tmp13_ = NULL;
	const gchar* _tmp14_ = NULL;
	const gchar* _tmp15_ = NULL;
	gboolean _tmp16_ = FALSE;
	gboolean _tmp21_ = FALSE;
	ContactsContact* _tmp29_ = NULL;
	const gchar* _tmp30_ = NULL;
	const gchar* _tmp31_ = NULL;
	gboolean _tmp32_ = FALSE;
	ContactsContact* _tmp33_ = NULL;
	const gchar* _tmp34_ = NULL;
	const gchar* _tmp35_ = NULL;
	gboolean _tmp36_ = FALSE;
	g_return_val_if_fail (a != NULL, 0);
	g_return_val_if_fail (b != NULL, 0);
	_tmp1_ = a;
	_tmp2_ = _tmp1_->is_main;
	if (_tmp2_) {
		_tmp0_ = 0;
	} else {
		_tmp0_ = -1;
	}
	_tmp3_ = _tmp0_;
	a_prio = _tmp3_;
	_tmp5_ = b;
	_tmp6_ = _tmp5_->is_main;
	if (_tmp6_) {
		_tmp4_ = 0;
	} else {
		_tmp4_ = -1;
	}
	_tmp7_ = _tmp4_;
	b_prio = _tmp7_;
	_tmp8_ = a_prio;
	_tmp9_ = b_prio;
	if (_tmp8_ > _tmp9_) {
		result = -1;
		return result;
	}
	_tmp10_ = a_prio;
	_tmp11_ = b_prio;
	if (_tmp10_ < _tmp11_) {
		result = 1;
		return result;
	}
	_tmp13_ = a;
	_tmp14_ = contacts_contact_get_display_name (_tmp13_);
	_tmp15_ = _tmp14_;
	_tmp16_ = contacts_is_set (_tmp15_);
	if (_tmp16_) {
		ContactsContact* _tmp17_ = NULL;
		const gchar* _tmp18_ = NULL;
		const gchar* _tmp19_ = NULL;
		gboolean _tmp20_ = FALSE;
		_tmp17_ = b;
		_tmp18_ = contacts_contact_get_display_name (_tmp17_);
		_tmp19_ = _tmp18_;
		_tmp20_ = contacts_is_set (_tmp19_);
		_tmp12_ = _tmp20_;
	} else {
		_tmp12_ = FALSE;
	}
	_tmp21_ = _tmp12_;
	if (_tmp21_) {
		ContactsContact* _tmp22_ = NULL;
		const gchar* _tmp23_ = NULL;
		const gchar* _tmp24_ = NULL;
		ContactsContact* _tmp25_ = NULL;
		const gchar* _tmp26_ = NULL;
		const gchar* _tmp27_ = NULL;
		gint _tmp28_ = 0;
		_tmp22_ = a;
		_tmp23_ = contacts_contact_get_display_name (_tmp22_);
		_tmp24_ = _tmp23_;
		_tmp25_ = b;
		_tmp26_ = contacts_contact_get_display_name (_tmp25_);
		_tmp27_ = _tmp26_;
		_tmp28_ = g_utf8_collate (_tmp24_, _tmp27_);
		result = _tmp28_;
		return result;
	}
	_tmp29_ = a;
	_tmp30_ = contacts_contact_get_display_name (_tmp29_);
	_tmp31_ = _tmp30_;
	_tmp32_ = contacts_is_set (_tmp31_);
	if (_tmp32_) {
		result = -1;
		return result;
	}
	_tmp33_ = b;
	_tmp34_ = contacts_contact_get_display_name (_tmp33_);
	_tmp35_ = _tmp34_;
	_tmp36_ = contacts_is_set (_tmp35_);
	if (_tmp36_) {
		result = 1;
		return result;
	}
	result = 0;
	return result;
}


static gchar** contacts_search_provider_do_search (ContactsSearchProvider* self, gchar** terms, int terms_length1, int* result_length1) {
	gchar** result = NULL;
	ContactsSearchProviderApp* _tmp0_ = NULL;
	gchar** normalized_terms = NULL;
	gchar** _tmp1_ = NULL;
	gint _tmp1__length1 = 0;
	gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	gchar* _tmp4_ = NULL;
	gchar* _tmp5_ = NULL;
	gchar** _tmp6_ = NULL;
	gchar** _tmp7_ = NULL;
	gchar** _tmp8_ = NULL;
	gint _tmp8__length1 = 0;
	gint normalized_terms_length1 = 0;
	gint _normalized_terms_size_ = 0;
	GeeArrayList* matches = NULL;
	GeeArrayList* _tmp9_ = NULL;
	GeeArrayList* _tmp27_ = NULL;
	gchar** results = NULL;
	GeeArrayList* _tmp28_ = NULL;
	gint _tmp29_ = 0;
	gint _tmp30_ = 0;
	gchar** _tmp31_ = NULL;
	gint results_length1 = 0;
	gint _results_size_ = 0;
	ContactsSearchProviderApp* _tmp48_ = NULL;
	gchar** _tmp49_ = NULL;
	gint _tmp49__length1 = 0;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->app;
	g_application_hold ((GApplication*) _tmp0_);
	_tmp1_ = terms;
	_tmp1__length1 = terms_length1;
	_tmp2_ = g_strjoinv (" ", _tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = contacts_utils_canonicalize_for_search (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp7_ = _tmp6_ = g_strsplit (_tmp5_, " ", 0);
	_tmp8_ = _tmp7_;
	_tmp8__length1 = _vala_array_length (_tmp6_);
	_g_free0 (_tmp5_);
	_g_free0 (_tmp3_);
	normalized_terms = _tmp8_;
	normalized_terms_length1 = _tmp8__length1;
	_normalized_terms_size_ = normalized_terms_length1;
	_tmp9_ = gee_array_list_new (CONTACTS_TYPE_CONTACT, (GBoxedCopyFunc) g_object_ref, g_object_unref, NULL, NULL, NULL);
	matches = _tmp9_;
	{
		GeeIterator* _c_it = NULL;
		ContactsStore* _tmp10_ = NULL;
		GeeCollection* _tmp11_ = NULL;
		GeeCollection* _tmp12_ = NULL;
		GeeIterator* _tmp13_ = NULL;
		GeeIterator* _tmp14_ = NULL;
		_tmp10_ = self->priv->store;
		_tmp11_ = contacts_store_get_contacts (_tmp10_);
		_tmp12_ = _tmp11_;
		_tmp13_ = gee_iterable_iterator ((GeeIterable*) _tmp12_);
		_tmp14_ = _tmp13_;
		_g_object_unref0 (_tmp12_);
		_c_it = _tmp14_;
		while (TRUE) {
			GeeIterator* _tmp15_ = NULL;
			gboolean _tmp16_ = FALSE;
			ContactsContact* c = NULL;
			GeeIterator* _tmp17_ = NULL;
			gpointer _tmp18_ = NULL;
			ContactsContact* _tmp19_ = NULL;
			gboolean _tmp20_ = FALSE;
			gboolean _tmp21_ = FALSE;
			ContactsContact* _tmp22_ = NULL;
			gchar** _tmp23_ = NULL;
			gint _tmp23__length1 = 0;
			gboolean _tmp24_ = FALSE;
			_tmp15_ = _c_it;
			_tmp16_ = gee_iterator_next (_tmp15_);
			if (!_tmp16_) {
				break;
			}
			_tmp17_ = _c_it;
			_tmp18_ = gee_iterator_get (_tmp17_);
			c = (ContactsContact*) _tmp18_;
			_tmp19_ = c;
			_tmp20_ = contacts_contact_get_is_hidden (_tmp19_);
			_tmp21_ = _tmp20_;
			if (_tmp21_) {
				_g_object_unref0 (c);
				continue;
			}
			_tmp22_ = c;
			_tmp23_ = normalized_terms;
			_tmp23__length1 = normalized_terms_length1;
			_tmp24_ = contacts_contact_contains_strings (_tmp22_, _tmp23_, _tmp23__length1);
			if (_tmp24_) {
				GeeArrayList* _tmp25_ = NULL;
				ContactsContact* _tmp26_ = NULL;
				_tmp25_ = matches;
				_tmp26_ = c;
				gee_abstract_collection_add ((GeeAbstractCollection*) _tmp25_, _tmp26_);
			}
			_g_object_unref0 (c);
		}
		_g_object_unref0 (_c_it);
	}
	_tmp27_ = matches;
	gee_list_sort ((GeeList*) _tmp27_, (GCompareDataFunc) contacts_search_provider_compare_contacts, NULL, NULL);
	_tmp28_ = matches;
	_tmp29_ = gee_abstract_collection_get_size ((GeeCollection*) _tmp28_);
	_tmp30_ = _tmp29_;
	_tmp31_ = g_new0 (gchar*, _tmp30_ + 1);
	results = _tmp31_;
	results_length1 = _tmp30_;
	_results_size_ = results_length1;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp32_ = FALSE;
			_tmp32_ = TRUE;
			while (TRUE) {
				gboolean _tmp33_ = FALSE;
				gint _tmp35_ = 0;
				GeeArrayList* _tmp36_ = NULL;
				gint _tmp37_ = 0;
				gint _tmp38_ = 0;
				gchar** _tmp39_ = NULL;
				gint _tmp39__length1 = 0;
				gint _tmp40_ = 0;
				GeeArrayList* _tmp41_ = NULL;
				gint _tmp42_ = 0;
				gpointer _tmp43_ = NULL;
				ContactsContact* _tmp44_ = NULL;
				gconstpointer _tmp45_ = NULL;
				gchar* _tmp46_ = NULL;
				gchar* _tmp47_ = NULL;
				_tmp33_ = _tmp32_;
				if (!_tmp33_) {
					gint _tmp34_ = 0;
					_tmp34_ = i;
					i = _tmp34_ + 1;
				}
				_tmp32_ = FALSE;
				_tmp35_ = i;
				_tmp36_ = matches;
				_tmp37_ = gee_abstract_collection_get_size ((GeeCollection*) _tmp36_);
				_tmp38_ = _tmp37_;
				if (!(_tmp35_ < _tmp38_)) {
					break;
				}
				_tmp39_ = results;
				_tmp39__length1 = results_length1;
				_tmp40_ = i;
				_tmp41_ = matches;
				_tmp42_ = i;
				_tmp43_ = gee_abstract_list_get ((GeeAbstractList*) _tmp41_, _tmp42_);
				_tmp44_ = (ContactsContact*) _tmp43_;
				_tmp45_ = g_object_get_data ((GObject*) _tmp44_, "search-id");
				_tmp46_ = g_strdup ((const gchar*) _tmp45_);
				_g_free0 (_tmp39_[_tmp40_]);
				_tmp39_[_tmp40_] = _tmp46_;
				_tmp47_ = _tmp39_[_tmp40_];
				_g_object_unref0 (_tmp44_);
			}
		}
	}
	_tmp48_ = self->priv->app;
	g_application_release ((GApplication*) _tmp48_);
	_tmp49_ = results;
	_tmp49__length1 = results_length1;
	if (result_length1) {
		*result_length1 = _tmp49__length1;
	}
	result = _tmp49_;
	_g_object_unref0 (matches);
	normalized_terms = (_vala_array_free (normalized_terms, normalized_terms_length1, (GDestroyNotify) g_free), NULL);
	return result;
}


gchar** contacts_search_provider_GetInitialResultSet (ContactsSearchProvider* self, gchar** terms, int terms_length1, int* result_length1) {
	gchar** result = NULL;
	gchar** _tmp0_ = NULL;
	gint _tmp0__length1 = 0;
	gint _tmp1_ = 0;
	gchar** _tmp2_ = NULL;
	gchar** _tmp3_ = NULL;
	gint _tmp3__length1 = 0;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = terms;
	_tmp0__length1 = terms_length1;
	_tmp2_ = contacts_search_provider_do_search (self, _tmp0_, _tmp0__length1, &_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp3__length1 = _tmp1_;
	if (result_length1) {
		*result_length1 = _tmp3__length1;
	}
	result = _tmp3_;
	return result;
}


gchar** contacts_search_provider_GetSubsearchResultSet (ContactsSearchProvider* self, gchar** previous_results, int previous_results_length1, gchar** new_terms, int new_terms_length1, int* result_length1) {
	gchar** result = NULL;
	gchar** _tmp0_ = NULL;
	gint _tmp0__length1 = 0;
	gint _tmp1_ = 0;
	gchar** _tmp2_ = NULL;
	gchar** _tmp3_ = NULL;
	gint _tmp3__length1 = 0;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = new_terms;
	_tmp0__length1 = new_terms_length1;
	_tmp2_ = contacts_search_provider_do_search (self, _tmp0_, _tmp0__length1, &_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp3__length1 = _tmp1_;
	if (result_length1) {
		*result_length1 = _tmp3__length1;
	}
	result = _tmp3_;
	return result;
}


static void _g_free0_ (gpointer var) {
	var = (g_free (var), NULL);
}


static void _g_variant_unref0_ (gpointer var) {
	(var == NULL) ? NULL : (var = (g_variant_unref (var), NULL));
}


static gpointer _g_variant_ref0 (gpointer self) {
	return self ? g_variant_ref (self) : NULL;
}


GHashTable** contacts_search_provider_GetResultMetas (ContactsSearchProvider* self, gchar** ids, int ids_length1, int* result_length1) {
	GHashTable** result = NULL;
	ContactsSearchProviderApp* _tmp0_ = NULL;
	GeeArrayList* results = NULL;
	GeeArrayList* _tmp1_ = NULL;
	gchar** _tmp2_ = NULL;
	gint _tmp2__length1 = 0;
	ContactsSearchProviderApp* _tmp50_ = NULL;
	GeeArrayList* _tmp51_ = NULL;
	gint _tmp52_ = 0;
	gpointer* _tmp53_ = NULL;
	GHashTable** _tmp54_ = NULL;
	gint _tmp54__length1 = 0;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->app;
	g_application_hold ((GApplication*) _tmp0_);
	_tmp1_ = gee_array_list_new (G_TYPE_HASH_TABLE, (GBoxedCopyFunc) g_hash_table_ref, g_hash_table_unref, NULL, NULL, NULL);
	results = _tmp1_;
	_tmp2_ = ids;
	_tmp2__length1 = ids_length1;
	{
		gchar** id_collection = NULL;
		gint id_collection_length1 = 0;
		gint _id_collection_size_ = 0;
		gint id_it = 0;
		id_collection = _tmp2_;
		id_collection_length1 = _tmp2__length1;
		for (id_it = 0; id_it < _tmp2__length1; id_it = id_it + 1) {
			gchar* _tmp3_ = NULL;
			gchar* id = NULL;
			_tmp3_ = g_strdup (id_collection[id_it]);
			id = _tmp3_;
			{
				ContactsContact* contact = NULL;
				GeeHashMap* _tmp4_ = NULL;
				const gchar* _tmp5_ = NULL;
				gpointer _tmp6_ = NULL;
				ContactsContact* _tmp7_ = NULL;
				GHashTable* meta = NULL;
				GHashFunc _tmp8_ = NULL;
				GEqualFunc _tmp9_ = NULL;
				GHashTable* _tmp10_ = NULL;
				GHashTable* _tmp11_ = NULL;
				gchar* _tmp12_ = NULL;
				const gchar* _tmp13_ = NULL;
				GVariant* _tmp14_ = NULL;
				GHashTable* _tmp15_ = NULL;
				gchar* _tmp16_ = NULL;
				ContactsContact* _tmp17_ = NULL;
				const gchar* _tmp18_ = NULL;
				const gchar* _tmp19_ = NULL;
				GVariant* _tmp20_ = NULL;
				ContactsContact* _tmp21_ = NULL;
				GIcon* _tmp22_ = NULL;
				GIcon* _tmp23_ = NULL;
				GeeArrayList* _tmp48_ = NULL;
				GHashTable* _tmp49_ = NULL;
				_tmp4_ = self->priv->contacts_map;
				_tmp5_ = id;
				_tmp6_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp4_, _tmp5_);
				contact = (ContactsContact*) _tmp6_;
				_tmp7_ = contact;
				if (_tmp7_ == NULL) {
					_g_object_unref0 (contact);
					_g_free0 (id);
					continue;
				}
				_tmp8_ = g_str_hash;
				_tmp9_ = g_str_equal;
				_tmp10_ = g_hash_table_new_full (_tmp8_, _tmp9_, _g_free0_, _g_variant_unref0_);
				meta = _tmp10_;
				_tmp11_ = meta;
				_tmp12_ = g_strdup ("id");
				_tmp13_ = id;
				_tmp14_ = g_variant_new_string (_tmp13_);
				g_variant_ref_sink (_tmp14_);
				g_hash_table_insert (_tmp11_, _tmp12_, _tmp14_);
				_tmp15_ = meta;
				_tmp16_ = g_strdup ("name");
				_tmp17_ = contact;
				_tmp18_ = contacts_contact_get_display_name (_tmp17_);
				_tmp19_ = _tmp18_;
				_tmp20_ = g_variant_new_string (_tmp19_);
				g_variant_ref_sink (_tmp20_);
				g_hash_table_insert (_tmp15_, _tmp16_, _tmp20_);
				_tmp21_ = contact;
				_tmp22_ = contacts_contact_get_serializable_avatar_icon (_tmp21_);
				_tmp23_ = _tmp22_;
				if (_tmp23_ != NULL) {
					GHashTable* _tmp24_ = NULL;
					gchar* _tmp25_ = NULL;
					ContactsContact* _tmp26_ = NULL;
					GIcon* _tmp27_ = NULL;
					GIcon* _tmp28_ = NULL;
					gchar* _tmp29_ = NULL;
					gchar* _tmp30_ = NULL;
					GVariant* _tmp31_ = NULL;
					_tmp24_ = meta;
					_tmp25_ = g_strdup ("gicon");
					_tmp26_ = contact;
					_tmp27_ = contacts_contact_get_serializable_avatar_icon (_tmp26_);
					_tmp28_ = _tmp27_;
					_tmp29_ = g_icon_to_string (_tmp28_);
					_tmp30_ = _tmp29_;
					_tmp31_ = g_variant_new_string (_tmp30_);
					g_variant_ref_sink (_tmp31_);
					g_hash_table_insert (_tmp24_, _tmp25_, _tmp31_);
					_g_free0 (_tmp30_);
				} else {
					ContactsContact* _tmp32_ = NULL;
					GVariant* _tmp33_ = NULL;
					GVariant* _tmp34_ = NULL;
					_tmp32_ = contact;
					_tmp33_ = contacts_contact_get_avatar_icon_data (_tmp32_);
					_tmp34_ = _tmp33_;
					if (_tmp34_ != NULL) {
						GHashTable* _tmp35_ = NULL;
						gchar* _tmp36_ = NULL;
						ContactsContact* _tmp37_ = NULL;
						GVariant* _tmp38_ = NULL;
						GVariant* _tmp39_ = NULL;
						GVariant* _tmp40_ = NULL;
						_tmp35_ = meta;
						_tmp36_ = g_strdup ("icon-data");
						_tmp37_ = contact;
						_tmp38_ = contacts_contact_get_avatar_icon_data (_tmp37_);
						_tmp39_ = _tmp38_;
						_tmp40_ = _g_variant_ref0 (_tmp39_);
						g_hash_table_insert (_tmp35_, _tmp36_, _tmp40_);
					} else {
						GHashTable* _tmp41_ = NULL;
						gchar* _tmp42_ = NULL;
						GThemedIcon* _tmp43_ = NULL;
						GThemedIcon* _tmp44_ = NULL;
						gchar* _tmp45_ = NULL;
						gchar* _tmp46_ = NULL;
						GVariant* _tmp47_ = NULL;
						_tmp41_ = meta;
						_tmp42_ = g_strdup ("gicon");
						_tmp43_ = (GThemedIcon*) g_themed_icon_new ("avatar-default");
						_tmp44_ = _tmp43_;
						_tmp45_ = g_icon_to_string ((GIcon*) _tmp44_);
						_tmp46_ = _tmp45_;
						_tmp47_ = g_variant_new_string (_tmp46_);
						g_variant_ref_sink (_tmp47_);
						g_hash_table_insert (_tmp41_, _tmp42_, _tmp47_);
						_g_free0 (_tmp46_);
						_g_object_unref0 (_tmp44_);
					}
				}
				_tmp48_ = results;
				_tmp49_ = meta;
				gee_abstract_collection_add ((GeeAbstractCollection*) _tmp48_, _tmp49_);
				_g_hash_table_unref0 (meta);
				_g_object_unref0 (contact);
				_g_free0 (id);
			}
		}
	}
	_tmp50_ = self->priv->app;
	g_application_release ((GApplication*) _tmp50_);
	_tmp51_ = results;
	_tmp53_ = gee_collection_to_array ((GeeCollection*) _tmp51_, &_tmp52_);
	_tmp54_ = _tmp53_;
	_tmp54__length1 = _tmp52_;
	if (result_length1) {
		*result_length1 = _tmp54__length1;
	}
	result = _tmp54_;
	_g_object_unref0 (results);
	return result;
}


void contacts_search_provider_ActivateResult (ContactsSearchProvider* self, const gchar* search_id) {
	ContactsSearchProviderApp* _tmp0_ = NULL;
	ContactsContact* contact = NULL;
	GeeHashMap* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gpointer _tmp3_ = NULL;
	ContactsContact* _tmp4_ = NULL;
	gchar* id = NULL;
	ContactsContact* _tmp6_ = NULL;
	FolksIndividual* _tmp7_ = NULL;
	const gchar* _tmp8_ = NULL;
	const gchar* _tmp9_ = NULL;
	gchar* _tmp10_ = NULL;
	ContactsSearchProviderApp* _tmp21_ = NULL;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (search_id != NULL);
	_tmp0_ = self->priv->app;
	g_application_hold ((GApplication*) _tmp0_);
	_tmp1_ = self->priv->contacts_map;
	_tmp2_ = search_id;
	_tmp3_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp1_, _tmp2_);
	contact = (ContactsContact*) _tmp3_;
	_tmp4_ = contact;
	if (_tmp4_ == NULL) {
		ContactsSearchProviderApp* _tmp5_ = NULL;
		_tmp5_ = self->priv->app;
		g_application_release ((GApplication*) _tmp5_);
		_g_object_unref0 (contact);
		return;
	}
	_tmp6_ = contact;
	_tmp7_ = _tmp6_->individual;
	_tmp8_ = folks_individual_get_id (_tmp7_);
	_tmp9_ = _tmp8_;
	_tmp10_ = g_strdup (_tmp9_);
	id = _tmp10_;
	{
		gboolean _tmp11_ = FALSE;
		const gchar* _tmp12_ = NULL;
		gchar* _tmp13_ = NULL;
		gchar* _tmp14_ = NULL;
		gboolean _tmp15_ = FALSE;
		gboolean _tmp16_ = FALSE;
		_tmp12_ = id;
		_tmp13_ = g_strconcat ("gnome-contacts -i ", _tmp12_, NULL);
		_tmp14_ = _tmp13_;
		_tmp15_ = g_spawn_command_line_async (_tmp14_, &_inner_error_);
		_tmp16_ = _tmp15_;
		_g_free0 (_tmp14_);
		_tmp11_ = _tmp16_;
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == G_SPAWN_ERROR) {
				goto __catch2_g_spawn_error;
			}
			_g_free0 (id);
			_g_object_unref0 (contact);
			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;
		}
		if (!_tmp11_) {
			FILE* _tmp17_ = NULL;
			const gchar* _tmp18_ = NULL;
			_tmp17_ = stderr;
			_tmp18_ = id;
			fprintf (_tmp17_, "Failed to launch contact with id '%s'\n", _tmp18_);
		}
	}
	goto __finally2;
	__catch2_g_spawn_error:
	{
		GError* e = NULL;
		FILE* _tmp19_ = NULL;
		const gchar* _tmp20_ = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp19_ = stderr;
		_tmp20_ = id;
		fprintf (_tmp19_, "Failed to launch contact with id '%s'\n", _tmp20_);
		_g_error_free0 (e);
	}
	__finally2:
	if (_inner_error_ != NULL) {
		_g_free0 (id);
		_g_object_unref0 (contact);
		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;
	}
	_tmp21_ = self->priv->app;
	g_application_release ((GApplication*) _tmp21_);
	_g_free0 (id);
	_g_object_unref0 (contact);
}


static void contacts_search_provider_class_init (ContactsSearchProviderClass * klass) {
	contacts_search_provider_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (ContactsSearchProviderPrivate));
	G_OBJECT_CLASS (klass)->finalize = contacts_search_provider_finalize;
}


static void contacts_search_provider_instance_init (ContactsSearchProvider * self) {
	self->priv = CONTACTS_SEARCH_PROVIDER_GET_PRIVATE (self);
}


static void contacts_search_provider_finalize (GObject* obj) {
	ContactsSearchProvider * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CONTACTS_TYPE_SEARCH_PROVIDER, ContactsSearchProvider);
	_g_object_unref0 (self->priv->app);
	_g_object_unref0 (self->priv->store);
	_g_object_unref0 (self->priv->contacts_map);
	G_OBJECT_CLASS (contacts_search_provider_parent_class)->finalize (obj);
}


GType contacts_search_provider_get_type (void) {
	static volatile gsize contacts_search_provider_type_id__volatile = 0;
	if (g_once_init_enter (&contacts_search_provider_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ContactsSearchProviderClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) contacts_search_provider_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ContactsSearchProvider), 0, (GInstanceInitFunc) contacts_search_provider_instance_init, NULL };
		GType contacts_search_provider_type_id;
		contacts_search_provider_type_id = g_type_register_static (G_TYPE_OBJECT, "ContactsSearchProvider", &g_define_type_info, 0);
		g_type_set_qdata (contacts_search_provider_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) contacts_search_provider_register_object);
		g_once_init_leave (&contacts_search_provider_type_id__volatile, contacts_search_provider_type_id);
	}
	return contacts_search_provider_type_id__volatile;
}


static void _dbus_contacts_search_provider_GetInitialResultSet (ContactsSearchProvider* self, GVariant* parameters, GDBusMethodInvocation* invocation) {
	GError* error = NULL;
	GVariantIter _arguments_iter;
	gchar** terms = NULL;
	int terms_length1 = 0;
	GVariant* _tmp0_;
	gchar** _tmp1_;
	int _tmp1__length;
	int _tmp1__size;
	int _tmp1__length1;
	GVariantIter _tmp2_;
	GVariant* _tmp3_;
	GDBusMessage* _reply_message;
	GVariant* _reply;
	GVariantBuilder _reply_builder;
	gchar** result;
	int result_length1 = 0;
	gchar** _tmp4_;
	GVariantBuilder _tmp5_;
	int _tmp6_;
	g_variant_iter_init (&_arguments_iter, parameters);
	_tmp0_ = g_variant_iter_next_value (&_arguments_iter);
	_tmp1_ = g_new (gchar*, 5);
	_tmp1__length = 0;
	_tmp1__size = 4;
	_tmp1__length1 = 0;
	g_variant_iter_init (&_tmp2_, _tmp0_);
	for (; (_tmp3_ = g_variant_iter_next_value (&_tmp2_)) != NULL; _tmp1__length1++) {
		if (_tmp1__size == _tmp1__length) {
			_tmp1__size = 2 * _tmp1__size;
			_tmp1_ = g_renew (gchar*, _tmp1_, _tmp1__size + 1);
		}
		_tmp1_[_tmp1__length++] = g_variant_dup_string (_tmp3_, NULL);
		g_variant_unref (_tmp3_);
	}
	terms_length1 = _tmp1__length1;
	_tmp1_[_tmp1__length] = NULL;
	terms = _tmp1_;
	g_variant_unref (_tmp0_);
	result = contacts_search_provider_GetInitialResultSet (self, terms, terms_length1, &result_length1);
	_reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation));
	g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE);
	_tmp4_ = result;
	g_variant_builder_init (&_tmp5_, G_VARIANT_TYPE ("as"));
	for (_tmp6_ = 0; _tmp6_ < result_length1; _tmp6_++) {
		g_variant_builder_add_value (&_tmp5_, g_variant_new_string (*_tmp4_));
		_tmp4_++;
	}
	g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp5_));
	result = (_vala_array_free (result, result_length1, (GDestroyNotify) g_free), NULL);
	_reply = g_variant_builder_end (&_reply_builder);
	g_dbus_message_set_body (_reply_message, _reply);
	terms = (_vala_array_free (terms, terms_length1, (GDestroyNotify) g_free), NULL);
	g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
	g_object_unref (invocation);
	g_object_unref (_reply_message);
}


static void _dbus_contacts_search_provider_GetSubsearchResultSet (ContactsSearchProvider* self, GVariant* parameters, GDBusMethodInvocation* invocation) {
	GError* error = NULL;
	GVariantIter _arguments_iter;
	gchar** previous_results = NULL;
	int previous_results_length1 = 0;
	GVariant* _tmp7_;
	gchar** _tmp8_;
	int _tmp8__length;
	int _tmp8__size;
	int _tmp8__length1;
	GVariantIter _tmp9_;
	GVariant* _tmp10_;
	gchar** new_terms = NULL;
	int new_terms_length1 = 0;
	GVariant* _tmp11_;
	gchar** _tmp12_;
	int _tmp12__length;
	int _tmp12__size;
	int _tmp12__length1;
	GVariantIter _tmp13_;
	GVariant* _tmp14_;
	GDBusMessage* _reply_message;
	GVariant* _reply;
	GVariantBuilder _reply_builder;
	gchar** result;
	int result_length1 = 0;
	gchar** _tmp15_;
	GVariantBuilder _tmp16_;
	int _tmp17_;
	g_variant_iter_init (&_arguments_iter, parameters);
	_tmp7_ = g_variant_iter_next_value (&_arguments_iter);
	_tmp8_ = g_new (gchar*, 5);
	_tmp8__length = 0;
	_tmp8__size = 4;
	_tmp8__length1 = 0;
	g_variant_iter_init (&_tmp9_, _tmp7_);
	for (; (_tmp10_ = g_variant_iter_next_value (&_tmp9_)) != NULL; _tmp8__length1++) {
		if (_tmp8__size == _tmp8__length) {
			_tmp8__size = 2 * _tmp8__size;
			_tmp8_ = g_renew (gchar*, _tmp8_, _tmp8__size + 1);
		}
		_tmp8_[_tmp8__length++] = g_variant_dup_string (_tmp10_, NULL);
		g_variant_unref (_tmp10_);
	}
	previous_results_length1 = _tmp8__length1;
	_tmp8_[_tmp8__length] = NULL;
	previous_results = _tmp8_;
	g_variant_unref (_tmp7_);
	_tmp11_ = g_variant_iter_next_value (&_arguments_iter);
	_tmp12_ = g_new (gchar*, 5);
	_tmp12__length = 0;
	_tmp12__size = 4;
	_tmp12__length1 = 0;
	g_variant_iter_init (&_tmp13_, _tmp11_);
	for (; (_tmp14_ = g_variant_iter_next_value (&_tmp13_)) != NULL; _tmp12__length1++) {
		if (_tmp12__size == _tmp12__length) {
			_tmp12__size = 2 * _tmp12__size;
			_tmp12_ = g_renew (gchar*, _tmp12_, _tmp12__size + 1);
		}
		_tmp12_[_tmp12__length++] = g_variant_dup_string (_tmp14_, NULL);
		g_variant_unref (_tmp14_);
	}
	new_terms_length1 = _tmp12__length1;
	_tmp12_[_tmp12__length] = NULL;
	new_terms = _tmp12_;
	g_variant_unref (_tmp11_);
	result = contacts_search_provider_GetSubsearchResultSet (self, previous_results, previous_results_length1, new_terms, new_terms_length1, &result_length1);
	_reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation));
	g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE);
	_tmp15_ = result;
	g_variant_builder_init (&_tmp16_, G_VARIANT_TYPE ("as"));
	for (_tmp17_ = 0; _tmp17_ < result_length1; _tmp17_++) {
		g_variant_builder_add_value (&_tmp16_, g_variant_new_string (*_tmp15_));
		_tmp15_++;
	}
	g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp16_));
	result = (_vala_array_free (result, result_length1, (GDestroyNotify) g_free), NULL);
	_reply = g_variant_builder_end (&_reply_builder);
	g_dbus_message_set_body (_reply_message, _reply);
	previous_results = (_vala_array_free (previous_results, previous_results_length1, (GDestroyNotify) g_free), NULL);
	new_terms = (_vala_array_free (new_terms, new_terms_length1, (GDestroyNotify) g_free), NULL);
	g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
	g_object_unref (invocation);
	g_object_unref (_reply_message);
}


static void _dbus_contacts_search_provider_GetResultMetas (ContactsSearchProvider* self, GVariant* parameters, GDBusMethodInvocation* invocation) {
	GError* error = NULL;
	GVariantIter _arguments_iter;
	gchar** ids = NULL;
	int ids_length1 = 0;
	GVariant* _tmp18_;
	gchar** _tmp19_;
	int _tmp19__length;
	int _tmp19__size;
	int _tmp19__length1;
	GVariantIter _tmp20_;
	GVariant* _tmp21_;
	GDBusMessage* _reply_message;
	GVariant* _reply;
	GVariantBuilder _reply_builder;
	GHashTable** result;
	int result_length1 = 0;
	GHashTable** _tmp22_;
	GVariantBuilder _tmp23_;
	int _tmp24_;
	g_variant_iter_init (&_arguments_iter, parameters);
	_tmp18_ = g_variant_iter_next_value (&_arguments_iter);
	_tmp19_ = g_new (gchar*, 5);
	_tmp19__length = 0;
	_tmp19__size = 4;
	_tmp19__length1 = 0;
	g_variant_iter_init (&_tmp20_, _tmp18_);
	for (; (_tmp21_ = g_variant_iter_next_value (&_tmp20_)) != NULL; _tmp19__length1++) {
		if (_tmp19__size == _tmp19__length) {
			_tmp19__size = 2 * _tmp19__size;
			_tmp19_ = g_renew (gchar*, _tmp19_, _tmp19__size + 1);
		}
		_tmp19_[_tmp19__length++] = g_variant_dup_string (_tmp21_, NULL);
		g_variant_unref (_tmp21_);
	}
	ids_length1 = _tmp19__length1;
	_tmp19_[_tmp19__length] = NULL;
	ids = _tmp19_;
	g_variant_unref (_tmp18_);
	result = contacts_search_provider_GetResultMetas (self, ids, ids_length1, &result_length1);
	_reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation));
	g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE);
	_tmp22_ = result;
	g_variant_builder_init (&_tmp23_, G_VARIANT_TYPE ("aa{sv}"));
	for (_tmp24_ = 0; _tmp24_ < result_length1; _tmp24_++) {
		GVariantBuilder _tmp25_;
		GHashTableIter _tmp26_;
		gpointer _tmp27_;
		gpointer _tmp28_;
		g_hash_table_iter_init (&_tmp26_, *_tmp22_);
		g_variant_builder_init (&_tmp25_, G_VARIANT_TYPE ("a{sv}"));
		while (g_hash_table_iter_next (&_tmp26_, &_tmp27_, &_tmp28_)) {
			gchar* _key;
			GVariant* _value;
			_key = (gchar*) _tmp27_;
			_value = (GVariant*) _tmp28_;
			g_variant_builder_add (&_tmp25_, "{?*}", g_variant_new_string (_key), g_variant_new_variant (_value));
		}
		g_variant_builder_add_value (&_tmp23_, g_variant_builder_end (&_tmp25_));
		_tmp22_++;
	}
	g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp23_));
	result = (_vala_array_free (result, result_length1, (GDestroyNotify) g_hash_table_unref), NULL);
	_reply = g_variant_builder_end (&_reply_builder);
	g_dbus_message_set_body (_reply_message, _reply);
	ids = (_vala_array_free (ids, ids_length1, (GDestroyNotify) g_free), NULL);
	g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
	g_object_unref (invocation);
	g_object_unref (_reply_message);
}


static void _dbus_contacts_search_provider_ActivateResult (ContactsSearchProvider* self, GVariant* parameters, GDBusMethodInvocation* invocation) {
	GError* error = NULL;
	GVariantIter _arguments_iter;
	gchar* search_id = NULL;
	GVariant* _tmp29_;
	GDBusMessage* _reply_message;
	GVariant* _reply;
	GVariantBuilder _reply_builder;
	g_variant_iter_init (&_arguments_iter, parameters);
	_tmp29_ = g_variant_iter_next_value (&_arguments_iter);
	search_id = g_variant_dup_string (_tmp29_, NULL);
	g_variant_unref (_tmp29_);
	contacts_search_provider_ActivateResult (self, search_id);
	_reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation));
	g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE);
	_reply = g_variant_builder_end (&_reply_builder);
	g_dbus_message_set_body (_reply_message, _reply);
	_g_free0 (search_id);
	g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
	g_object_unref (invocation);
	g_object_unref (_reply_message);
}


static void contacts_search_provider_dbus_interface_method_call (GDBusConnection* connection, const gchar* sender, const gchar* object_path, const gchar* interface_name, const gchar* method_name, GVariant* parameters, GDBusMethodInvocation* invocation, gpointer user_data) {
	gpointer* data;
	gpointer object;
	data = user_data;
	object = data[0];
	if (strcmp (method_name, "GetInitialResultSet") == 0) {
		_dbus_contacts_search_provider_GetInitialResultSet (object, parameters, invocation);
	} else if (strcmp (method_name, "GetSubsearchResultSet") == 0) {
		_dbus_contacts_search_provider_GetSubsearchResultSet (object, parameters, invocation);
	} else if (strcmp (method_name, "GetResultMetas") == 0) {
		_dbus_contacts_search_provider_GetResultMetas (object, parameters, invocation);
	} else if (strcmp (method_name, "ActivateResult") == 0) {
		_dbus_contacts_search_provider_ActivateResult (object, parameters, invocation);
	} else {
		g_object_unref (invocation);
	}
}


static GVariant* contacts_search_provider_dbus_interface_get_property (GDBusConnection* connection, const gchar* sender, const gchar* object_path, const gchar* interface_name, const gchar* property_name, GError** error, gpointer user_data) {
	gpointer* data;
	gpointer object;
	data = user_data;
	object = data[0];
	return NULL;
}


static gboolean contacts_search_provider_dbus_interface_set_property (GDBusConnection* connection, const gchar* sender, const gchar* object_path, const gchar* interface_name, const gchar* property_name, GVariant* value, GError** error, gpointer user_data) {
	gpointer* data;
	gpointer object;
	data = user_data;
	object = data[0];
	return FALSE;
}


guint contacts_search_provider_register_object (gpointer object, GDBusConnection* connection, const gchar* path, GError** error) {
	guint result;
	gpointer *data;
	data = g_new (gpointer, 3);
	data[0] = g_object_ref (object);
	data[1] = g_object_ref (connection);
	data[2] = g_strdup (path);
	result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_contacts_search_provider_dbus_interface_info), &_contacts_search_provider_dbus_interface_vtable, data, _contacts_search_provider_unregister_object, error);
	if (!result) {
		return 0;
	}
	return result;
}


static void _contacts_search_provider_unregister_object (gpointer user_data) {
	gpointer* data;
	data = user_data;
	g_object_unref (data[0]);
	g_object_unref (data[1]);
	g_free (data[2]);
	g_free (data);
}


ContactsSearchProviderApp* contacts_search_provider_app_construct (GType object_type) {
	ContactsSearchProviderApp * self = NULL;
	self = (ContactsSearchProviderApp*) g_object_new (object_type, "application-id", "org.gnome.Contacts.SearchProvider", "flags", G_APPLICATION_IS_SERVICE, "inactivity-timeout", 10000, NULL);
	return self;
}


ContactsSearchProviderApp* contacts_search_provider_app_new (void) {
	return contacts_search_provider_app_construct (CONTACTS_TYPE_SEARCH_PROVIDER_APP);
}


static gboolean contacts_search_provider_app_real_dbus_register (GApplication* base, GDBusConnection* connection, const gchar* object_path, GError** error) {
	ContactsSearchProviderApp * self;
	gboolean result = FALSE;
	GError * _inner_error_ = NULL;
	self = (ContactsSearchProviderApp*) base;
	g_return_val_if_fail (connection != NULL, FALSE);
	g_return_val_if_fail (object_path != NULL, FALSE);
	{
		GDBusConnection* _tmp0_ = NULL;
		const gchar* _tmp1_ = NULL;
		ContactsSearchProvider* _tmp2_ = NULL;
		ContactsSearchProvider* _tmp3_ = NULL;
		_tmp0_ = connection;
		_tmp1_ = object_path;
		_tmp2_ = contacts_search_provider_new (self);
		_tmp3_ = _tmp2_;
		contacts_search_provider_register_object (_tmp3_, _tmp0_, _tmp1_, &_inner_error_);
		_g_object_unref0 (_tmp3_);
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == G_IO_ERROR) {
				goto __catch3_g_io_error;
			}
			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 FALSE;
		}
	}
	goto __finally3;
	__catch3_g_io_error:
	{
		GError* _error_ = NULL;
		FILE* _tmp4_ = NULL;
		GError* _tmp5_ = NULL;
		const gchar* _tmp6_ = NULL;
		_error_ = _inner_error_;
		_inner_error_ = NULL;
		_tmp4_ = stderr;
		_tmp5_ = _error_;
		_tmp6_ = _tmp5_->message;
		fprintf (_tmp4_, "Could not register service: %s", _tmp6_);
		g_application_quit ((GApplication*) self);
		_g_error_free0 (_error_);
	}
	__finally3:
	if (_inner_error_ != 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 FALSE;
	}
	result = TRUE;
	return result;
}


static void contacts_search_provider_app_real_startup (GApplication* base) {
	ContactsSearchProviderApp * self;
	const gchar* _tmp0_ = NULL;
	self = (ContactsSearchProviderApp*) base;
	_tmp0_ = g_getenv ("CONTACTS_SEARCH_PROVIDER_PERSIST");
	if (_tmp0_ != NULL) {
		g_application_hold ((GApplication*) self);
	}
	G_APPLICATION_CLASS (contacts_search_provider_app_parent_class)->startup ((GApplication*) G_TYPE_CHECK_INSTANCE_CAST (self, GTK_TYPE_APPLICATION, GtkApplication));
}


static void contacts_search_provider_app_class_init (ContactsSearchProviderAppClass * klass) {
	contacts_search_provider_app_parent_class = g_type_class_peek_parent (klass);
	G_APPLICATION_CLASS (klass)->dbus_register = contacts_search_provider_app_real_dbus_register;
	G_APPLICATION_CLASS (klass)->startup = contacts_search_provider_app_real_startup;
}


static void contacts_search_provider_app_instance_init (ContactsSearchProviderApp * self) {
}


GType contacts_search_provider_app_get_type (void) {
	static volatile gsize contacts_search_provider_app_type_id__volatile = 0;
	if (g_once_init_enter (&contacts_search_provider_app_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ContactsSearchProviderAppClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) contacts_search_provider_app_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ContactsSearchProviderApp), 0, (GInstanceInitFunc) contacts_search_provider_app_instance_init, NULL };
		GType contacts_search_provider_app_type_id;
		contacts_search_provider_app_type_id = g_type_register_static (GTK_TYPE_APPLICATION, "ContactsSearchProviderApp", &g_define_type_info, 0);
		g_once_init_leave (&contacts_search_provider_app_type_id__volatile, contacts_search_provider_app_type_id);
	}
	return contacts_search_provider_app_type_id__volatile;
}


gint _vala_main (void) {
	gint result = 0;
	ContactsSearchProviderApp* _tmp0_ = NULL;
	ContactsSearchProviderApp* _tmp1_ = NULL;
	gint _tmp2_ = 0;
	gint _tmp3_ = 0;
	_tmp0_ = contacts_search_provider_app_new ();
	_tmp1_ = _tmp0_;
	_tmp2_ = g_application_run ((GApplication*) _tmp1_, 0, NULL);
	_tmp3_ = _tmp2_;
	_g_object_unref0 (_tmp1_);
	result = _tmp3_;
	return result;
}


int main (int argc, char ** argv) {
	return _vala_main ();
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int 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, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}


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



