/* contacts-accounts-list.c generated by valac 0.22.1, the Vala compiler
 * generated from contacts-accounts-list.vala, do not modify */

/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 8 -*- */
/*
 * Copyright (C) 2011 Erick Pérez Castellanos <erick.red@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <folks/folks.h>
#include <glib/gi18n-lib.h>
#include <libedataserver/libedataserver.h>
#include <folks/folks-eds.h>
#include <contacts-esd-setup.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>


#define CONTACTS_TYPE_ACCOUNTS_LIST (contacts_accounts_list_get_type ())
#define CONTACTS_ACCOUNTS_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONTACTS_TYPE_ACCOUNTS_LIST, ContactsAccountsList))
#define CONTACTS_ACCOUNTS_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONTACTS_TYPE_ACCOUNTS_LIST, ContactsAccountsListClass))
#define CONTACTS_IS_ACCOUNTS_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONTACTS_TYPE_ACCOUNTS_LIST))
#define CONTACTS_IS_ACCOUNTS_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONTACTS_TYPE_ACCOUNTS_LIST))
#define CONTACTS_ACCOUNTS_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONTACTS_TYPE_ACCOUNTS_LIST, ContactsAccountsListClass))

typedef struct _ContactsAccountsList ContactsAccountsList;
typedef struct _ContactsAccountsListClass ContactsAccountsListClass;
typedef struct _ContactsAccountsListPrivate ContactsAccountsListPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_list_free0(var) ((var == NULL) ? NULL : (var = (g_list_free (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

#define CONTACTS_TYPE_APP (contacts_app_get_type ())
#define CONTACTS_APP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONTACTS_TYPE_APP, ContactsApp))
#define CONTACTS_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONTACTS_TYPE_APP, ContactsAppClass))
#define CONTACTS_IS_APP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONTACTS_TYPE_APP))
#define CONTACTS_IS_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONTACTS_TYPE_APP))
#define CONTACTS_APP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONTACTS_TYPE_APP, ContactsAppClass))

typedef struct _ContactsApp ContactsApp;
typedef struct _ContactsAppClass ContactsAppClass;
typedef struct _ContactsAppPrivate ContactsAppPrivate;

#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_WINDOW (contacts_window_get_type ())
#define CONTACTS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONTACTS_TYPE_WINDOW, ContactsWindow))
#define CONTACTS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONTACTS_TYPE_WINDOW, ContactsWindowClass))
#define CONTACTS_IS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONTACTS_TYPE_WINDOW))
#define CONTACTS_IS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONTACTS_TYPE_WINDOW))
#define CONTACTS_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONTACTS_TYPE_WINDOW, ContactsWindowClass))

typedef struct _ContactsWindow ContactsWindow;
typedef struct _ContactsWindowClass ContactsWindowClass;

struct _ContactsAccountsList {
	GtkGrid parent_instance;
	ContactsAccountsListPrivate * priv;
	FolksPersonaStore* selected_store;
};

struct _ContactsAccountsListClass {
	GtkGridClass parent_class;
};

struct _ContactsAccountsListPrivate {
	GtkListBox* accounts_view;
	GtkListBoxRow* last_selected_row;
	GtkButton* add_account_button;
};

struct _ContactsApp {
	GtkApplication parent_instance;
	ContactsAppPrivate * priv;
	GSettings* settings;
	ContactsStore* contacts_store;
	ContactsWindow* window;
};

struct _ContactsAppClass {
	GtkApplicationClass parent_class;
};


static gpointer contacts_accounts_list_parent_class = NULL;
extern ContactsApp* contacts_app_app;

GType contacts_accounts_list_get_type (void) G_GNUC_CONST;
#define CONTACTS_ACCOUNTS_LIST_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CONTACTS_TYPE_ACCOUNTS_LIST, ContactsAccountsListPrivate))
enum  {
	CONTACTS_ACCOUNTS_LIST_DUMMY_PROPERTY
};
ContactsAccountsList* contacts_accounts_list_new (void);
ContactsAccountsList* contacts_accounts_list_construct (GType object_type);
static void contacts_accounts_list_update_header_func (ContactsAccountsList* self, GtkListBoxRow* row, GtkListBoxRow* before);
static void _contacts_accounts_list_update_header_func_gtk_list_box_update_header_func (GtkListBoxRow* row, GtkListBoxRow* before, gpointer self);
static void __lambda100_ (ContactsAccountsList* self);
static void ___lambda100__gtk_button_clicked (GtkButton* _sender, gpointer self);
static void contacts_accounts_list_row_activated (ContactsAccountsList* self, GtkListBoxRow* row);
static void _contacts_accounts_list_row_activated_gtk_list_box_row_activated (GtkListBox* _sender, GtkListBoxRow* row, gpointer self);
void contacts_accounts_list_update_contents (ContactsAccountsList* self, gboolean select_active);
FolksPersonaStore** contacts_app_get_eds_address_books (int* result_length1);
gchar* contacts_contact_format_persona_store_name (FolksPersonaStore* store);
GType contacts_app_get_type (void) G_GNUC_CONST;
GType contacts_store_get_type (void) G_GNUC_CONST;
GType contacts_window_get_type (void) G_GNUC_CONST;
FolksIndividualAggregator* contacts_store_get_aggregator (ContactsStore* self);
static void contacts_accounts_list_finalize (GObject* obj);
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 void _contacts_accounts_list_update_header_func_gtk_list_box_update_header_func (GtkListBoxRow* row, GtkListBoxRow* before, gpointer self) {
	contacts_accounts_list_update_header_func (self, row, before);
}


static void __lambda100_ (ContactsAccountsList* self) {
	GError * _inner_error_ = NULL;
	{
		g_spawn_command_line_async ("gnome-control-center online-accounts", &_inner_error_);
		if (_inner_error_ != NULL) {
			goto __catch35_g_error;
		}
	}
	goto __finally35;
	__catch35_g_error:
	{
		GError* e = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		_g_error_free0 (e);
	}
	__finally35:
	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;
	}
}


static void ___lambda100__gtk_button_clicked (GtkButton* _sender, gpointer self) {
	__lambda100_ (self);
}


static void _contacts_accounts_list_row_activated_gtk_list_box_row_activated (GtkListBox* _sender, GtkListBoxRow* row, gpointer self) {
	contacts_accounts_list_row_activated (self, row);
}


ContactsAccountsList* contacts_accounts_list_construct (GType object_type) {
	ContactsAccountsList * self = NULL;
	GtkListBox* _tmp0_ = NULL;
	GtkListBox* _tmp1_ = NULL;
	GtkListBox* _tmp2_ = NULL;
	GtkListBox* _tmp3_ = NULL;
	GtkScrolledWindow* scrolled = NULL;
	GtkScrolledWindow* _tmp4_ = NULL;
	GtkListBox* _tmp5_ = NULL;
	const gchar* _tmp6_ = NULL;
	GtkButton* _tmp7_ = NULL;
	GtkButton* _tmp8_ = NULL;
	GtkStyleContext* _tmp9_ = NULL;
	GtkButton* _tmp10_ = NULL;
	GtkWidget* _tmp11_ = NULL;
	GtkButton* _tmp12_ = NULL;
	GtkWidget* _tmp13_ = NULL;
	GtkButton* _tmp14_ = NULL;
	GtkWidget* _tmp15_ = NULL;
	GtkButton* _tmp16_ = NULL;
	GtkWidget* _tmp17_ = NULL;
	GtkButton* _tmp18_ = NULL;
	GtkButton* _tmp19_ = NULL;
	GtkListBox* _tmp20_ = NULL;
	self = (ContactsAccountsList*) g_object_new (object_type, NULL);
	gtk_orientable_set_orientation ((GtkOrientable*) self, GTK_ORIENTATION_VERTICAL);
	gtk_grid_set_row_spacing ((GtkGrid*) self, (guint) 22);
	_g_object_unref0 (self->selected_store);
	self->selected_store = NULL;
	_tmp0_ = (GtkListBox*) gtk_list_box_new ();
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->accounts_view);
	self->priv->accounts_view = _tmp0_;
	_tmp1_ = self->priv->accounts_view;
	gtk_list_box_set_selection_mode (_tmp1_, GTK_SELECTION_NONE);
	_tmp2_ = self->priv->accounts_view;
	gtk_widget_set_size_request ((GtkWidget*) _tmp2_, 400, -1);
	_tmp3_ = self->priv->accounts_view;
	gtk_list_box_set_header_func (_tmp3_, _contacts_accounts_list_update_header_func_gtk_list_box_update_header_func, g_object_ref (self), g_object_unref);
	_tmp4_ = (GtkScrolledWindow*) gtk_scrolled_window_new (NULL, NULL);
	g_object_ref_sink (_tmp4_);
	scrolled = _tmp4_;
	gtk_scrolled_window_set_min_content_height (scrolled, 260);
	gtk_scrolled_window_set_policy (scrolled, GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
	gtk_scrolled_window_set_shadow_type (scrolled, GTK_SHADOW_IN);
	_tmp5_ = self->priv->accounts_view;
	gtk_container_add ((GtkContainer*) scrolled, (GtkWidget*) _tmp5_);
	_tmp6_ = _ ("Online Accounts");
	_tmp7_ = (GtkButton*) gtk_button_new_with_label (_tmp6_);
	g_object_ref_sink (_tmp7_);
	_g_object_unref0 (self->priv->add_account_button);
	self->priv->add_account_button = _tmp7_;
	_tmp8_ = self->priv->add_account_button;
	_tmp9_ = gtk_widget_get_style_context ((GtkWidget*) _tmp8_);
	gtk_style_context_add_class (_tmp9_, GTK_STYLE_CLASS_RAISED);
	_tmp10_ = self->priv->add_account_button;
	_tmp11_ = gtk_bin_get_child ((GtkBin*) _tmp10_);
	gtk_widget_set_margin_left (_tmp11_, 6);
	_tmp12_ = self->priv->add_account_button;
	_tmp13_ = gtk_bin_get_child ((GtkBin*) _tmp12_);
	gtk_widget_set_margin_right (_tmp13_, 6);
	_tmp14_ = self->priv->add_account_button;
	_tmp15_ = gtk_bin_get_child ((GtkBin*) _tmp14_);
	gtk_widget_set_margin_top (_tmp15_, 3);
	_tmp16_ = self->priv->add_account_button;
	_tmp17_ = gtk_bin_get_child ((GtkBin*) _tmp16_);
	gtk_widget_set_margin_bottom (_tmp17_, 3);
	_tmp18_ = self->priv->add_account_button;
	g_signal_connect_object (_tmp18_, "clicked", (GCallback) ___lambda100__gtk_button_clicked, self, 0);
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) scrolled);
	_tmp19_ = self->priv->add_account_button;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp19_);
	gtk_widget_show_all ((GtkWidget*) self);
	_tmp20_ = self->priv->accounts_view;
	g_signal_connect_object (_tmp20_, "row-activated", (GCallback) _contacts_accounts_list_row_activated_gtk_list_box_row_activated, self, 0);
	_g_object_unref0 (scrolled);
	return self;
}


ContactsAccountsList* contacts_accounts_list_new (void) {
	return contacts_accounts_list_construct (CONTACTS_TYPE_ACCOUNTS_LIST);
}


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


static void contacts_accounts_list_row_activated (ContactsAccountsList* self, GtkListBoxRow* row) {
	GtkListBoxRow* _tmp0_ = NULL;
	GtkGrid* row_data = NULL;
	GtkListBoxRow* _tmp1_ = NULL;
	GtkWidget* _tmp2_ = NULL;
	GtkGrid* _tmp3_ = NULL;
	GtkImage* checkmark = NULL;
	GtkImage* _tmp4_ = NULL;
	GtkImage* _tmp5_ = NULL;
	GtkTextDirection _tmp6_ = 0;
	GtkImage* _tmp9_ = NULL;
	GtkImage* _tmp10_ = NULL;
	GtkImage* _tmp11_ = NULL;
	GtkImage* _tmp12_ = NULL;
	GtkImage* _tmp13_ = NULL;
	GtkGrid* _tmp14_ = NULL;
	GtkImage* _tmp15_ = NULL;
	GtkListBoxRow* _tmp16_ = NULL;
	GtkListBoxRow* _tmp22_ = NULL;
	GtkListBoxRow* _tmp23_ = NULL;
	GtkGrid* _tmp24_ = NULL;
	gconstpointer _tmp25_ = NULL;
	FolksPersonaStore* _tmp26_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = row;
	if (_tmp0_ == NULL) {
		return;
	}
	_tmp1_ = row;
	_tmp2_ = gtk_bin_get_child (G_TYPE_CHECK_INSTANCE_TYPE (_tmp1_, GTK_TYPE_BIN) ? ((GtkBin*) _tmp1_) : NULL);
	_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp2_, GTK_TYPE_GRID) ? ((GtkGrid*) _tmp2_) : NULL);
	row_data = _tmp3_;
	_tmp4_ = (GtkImage*) gtk_image_new_from_icon_name ("object-select-symbolic", GTK_ICON_SIZE_MENU);
	g_object_ref_sink (_tmp4_);
	checkmark = _tmp4_;
	_tmp5_ = checkmark;
	_tmp6_ = gtk_widget_get_direction ((GtkWidget*) _tmp5_);
	if (_tmp6_ == GTK_TEXT_DIR_LTR) {
		GtkImage* _tmp7_ = NULL;
		_tmp7_ = checkmark;
		gtk_widget_set_margin_right ((GtkWidget*) _tmp7_, 12);
	} else {
		GtkImage* _tmp8_ = NULL;
		_tmp8_ = checkmark;
		gtk_widget_set_margin_left ((GtkWidget*) _tmp8_, 12);
	}
	_tmp9_ = checkmark;
	gtk_widget_set_valign ((GtkWidget*) _tmp9_, GTK_ALIGN_CENTER);
	_tmp10_ = checkmark;
	gtk_widget_set_halign ((GtkWidget*) _tmp10_, GTK_ALIGN_END);
	_tmp11_ = checkmark;
	gtk_widget_set_vexpand ((GtkWidget*) _tmp11_, TRUE);
	_tmp12_ = checkmark;
	gtk_widget_set_hexpand ((GtkWidget*) _tmp12_, TRUE);
	_tmp13_ = checkmark;
	gtk_widget_show ((GtkWidget*) _tmp13_);
	_tmp14_ = row_data;
	_tmp15_ = checkmark;
	gtk_grid_attach (_tmp14_, (GtkWidget*) _tmp15_, 2, 0, 1, 2);
	_tmp16_ = self->priv->last_selected_row;
	if (_tmp16_ != NULL) {
		GtkGrid* last_row_data = NULL;
		GtkListBoxRow* _tmp17_ = NULL;
		GtkWidget* _tmp18_ = NULL;
		GtkGrid* _tmp19_ = NULL;
		GtkGrid* _tmp20_ = NULL;
		GtkWidget* _tmp21_ = NULL;
		_tmp17_ = self->priv->last_selected_row;
		_tmp18_ = gtk_bin_get_child (G_TYPE_CHECK_INSTANCE_TYPE (_tmp17_, GTK_TYPE_BIN) ? ((GtkBin*) _tmp17_) : NULL);
		_tmp19_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp18_, GTK_TYPE_GRID) ? ((GtkGrid*) _tmp18_) : NULL);
		last_row_data = _tmp19_;
		_tmp20_ = last_row_data;
		_tmp21_ = gtk_grid_get_child_at (_tmp20_, 2, 0);
		gtk_widget_destroy (_tmp21_);
		_g_object_unref0 (last_row_data);
	}
	_tmp22_ = row;
	_tmp23_ = _g_object_ref0 (_tmp22_);
	_g_object_unref0 (self->priv->last_selected_row);
	self->priv->last_selected_row = _tmp23_;
	_tmp24_ = row_data;
	_tmp25_ = g_object_get_data ((GObject*) _tmp24_, "store");
	_tmp26_ = _g_object_ref0 ((FolksPersonaStore*) _tmp25_);
	_g_object_unref0 (self->selected_store);
	self->selected_store = _tmp26_;
	g_signal_emit_by_name (self, "account-selected");
	_g_object_unref0 (checkmark);
	_g_object_unref0 (row_data);
}


static void contacts_accounts_list_update_header_func (ContactsAccountsList* self, GtkListBoxRow* row, GtkListBoxRow* before) {
	GtkListBoxRow* _tmp0_ = NULL;
	GtkWidget* _tmp1_ = NULL;
	GtkListBoxRow* _tmp5_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (row != NULL);
	_tmp0_ = row;
	_tmp1_ = gtk_list_box_row_get_header (_tmp0_);
	if (_tmp1_ == NULL) {
		GtkListBoxRow* _tmp2_ = NULL;
		GtkSeparator* _tmp3_ = NULL;
		GtkSeparator* _tmp4_ = NULL;
		_tmp2_ = row;
		_tmp3_ = (GtkSeparator*) gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
		g_object_ref_sink (_tmp3_);
		_tmp4_ = _tmp3_;
		gtk_list_box_row_set_header (_tmp2_, (GtkWidget*) _tmp4_);
		_g_object_unref0 (_tmp4_);
		return;
	}
	_tmp5_ = row;
	gtk_list_box_row_set_header (_tmp5_, NULL);
}


void contacts_accounts_list_update_contents (ContactsAccountsList* self, gboolean select_active) {
	GtkListBox* _tmp0_ = NULL;
	GList* _tmp1_ = NULL;
	FolksPersonaStore* local_store = NULL;
	gint _tmp3_ = 0;
	FolksPersonaStore** _tmp4_ = NULL;
	GtkGrid* local_data = NULL;
	GtkGrid* _tmp88_ = NULL;
	GtkGrid* _tmp89_ = NULL;
	GtkGrid* _tmp90_ = NULL;
	GtkTextDirection _tmp91_ = 0;
	GtkGrid* _tmp94_ = NULL;
	GtkGrid* _tmp95_ = NULL;
	FolksPersonaStore* _tmp96_ = NULL;
	FolksPersonaStore* _tmp97_ = NULL;
	GtkImage* provider_image = NULL;
	GtkImage* _tmp98_ = NULL;
	GtkGrid* _tmp99_ = NULL;
	GtkImage* _tmp100_ = NULL;
	GtkLabel* local_label = NULL;
	const gchar* _tmp101_ = NULL;
	GtkLabel* _tmp102_ = NULL;
	GtkGrid* _tmp103_ = NULL;
	GtkLabel* _tmp104_ = NULL;
	GtkListBox* _tmp105_ = NULL;
	GtkGrid* _tmp106_ = NULL;
	gboolean _tmp107_ = FALSE;
	gboolean _tmp108_ = FALSE;
	gboolean _tmp116_ = FALSE;
	GtkListBox* _tmp121_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->accounts_view;
	_tmp1_ = gtk_container_get_children ((GtkContainer*) _tmp0_);
	{
		GList* child_collection = NULL;
		GList* child_it = NULL;
		child_collection = _tmp1_;
		for (child_it = child_collection; child_it != NULL; child_it = child_it->next) {
			GtkWidget* child = NULL;
			child = (GtkWidget*) child_it->data;
			{
				GtkWidget* _tmp2_ = NULL;
				_tmp2_ = child;
				gtk_widget_destroy (_tmp2_);
			}
		}
		_g_list_free0 (child_collection);
	}
	local_store = NULL;
	_tmp4_ = contacts_app_get_eds_address_books (&_tmp3_);
	{
		FolksPersonaStore** persona_store_collection = NULL;
		gint persona_store_collection_length1 = 0;
		gint _persona_store_collection_size_ = 0;
		gint persona_store_it = 0;
		persona_store_collection = _tmp4_;
		persona_store_collection_length1 = _tmp3_;
		for (persona_store_it = 0; persona_store_it < _tmp3_; persona_store_it = persona_store_it + 1) {
			FolksPersonaStore* _tmp5_ = NULL;
			FolksPersonaStore* persona_store = NULL;
			_tmp5_ = _g_object_ref0 (persona_store_collection[persona_store_it]);
			persona_store = _tmp5_;
			{
				FolksPersonaStore* _tmp6_ = NULL;
				const gchar* _tmp7_ = NULL;
				const gchar* _tmp8_ = NULL;
				ESource* source = NULL;
				FolksPersonaStore* _tmp11_ = NULL;
				ESource* _tmp12_ = NULL;
				ESource* _tmp13_ = NULL;
				ESource* _tmp14_ = NULL;
				ESource* parent_source = NULL;
				ESourceRegistry* _tmp15_ = NULL;
				ESource* _tmp16_ = NULL;
				const gchar* _tmp17_ = NULL;
				const gchar* _tmp18_ = NULL;
				ESource* _tmp19_ = NULL;
				gchar* provider_name = NULL;
				FolksPersonaStore* _tmp20_ = NULL;
				gchar* _tmp21_ = NULL;
				gchar* source_account_id = NULL;
				gchar* _tmp22_ = NULL;
				ESource* _tmp23_ = NULL;
				gboolean _tmp24_ = FALSE;
				GtkGrid* row_data = NULL;
				GtkGrid* _tmp32_ = NULL;
				GtkGrid* _tmp33_ = NULL;
				FolksPersonaStore* _tmp34_ = NULL;
				FolksPersonaStore* _tmp35_ = NULL;
				GtkGrid* _tmp36_ = NULL;
				GtkGrid* _tmp37_ = NULL;
				GtkTextDirection _tmp38_ = 0;
				GtkGrid* _tmp41_ = NULL;
				GtkGrid* _tmp42_ = NULL;
				const gchar* _tmp43_ = NULL;
				GtkLabel* provider_label = NULL;
				const gchar* _tmp52_ = NULL;
				GtkLabel* _tmp53_ = NULL;
				GtkLabel* _tmp54_ = NULL;
				GtkLabel* _tmp55_ = NULL;
				GtkLabel* _tmp56_ = NULL;
				GtkGrid* _tmp57_ = NULL;
				GtkLabel* _tmp58_ = NULL;
				gchar* account_name = NULL;
				ESource* _tmp59_ = NULL;
				const gchar* _tmp60_ = NULL;
				const gchar* _tmp61_ = NULL;
				gchar* _tmp62_ = NULL;
				GtkLabel* account_label = NULL;
				const gchar* _tmp63_ = NULL;
				GtkLabel* _tmp64_ = NULL;
				GtkLabel* _tmp65_ = NULL;
				GtkLabel* _tmp66_ = NULL;
				GtkLabel* _tmp67_ = NULL;
				GtkLabel* _tmp68_ = NULL;
				GtkStyleContext* _tmp69_ = NULL;
				GtkGrid* _tmp70_ = NULL;
				GtkLabel* _tmp71_ = NULL;
				GtkListBox* _tmp72_ = NULL;
				GtkGrid* _tmp73_ = NULL;
				gboolean _tmp74_ = FALSE;
				gboolean _tmp75_ = FALSE;
				gboolean _tmp83_ = FALSE;
				_tmp6_ = persona_store;
				_tmp7_ = folks_persona_store_get_id (_tmp6_);
				_tmp8_ = _tmp7_;
				if (g_strcmp0 (_tmp8_, "system-address-book") == 0) {
					FolksPersonaStore* _tmp9_ = NULL;
					FolksPersonaStore* _tmp10_ = NULL;
					_tmp9_ = persona_store;
					_tmp10_ = _g_object_ref0 (_tmp9_);
					_g_object_unref0 (local_store);
					local_store = _tmp10_;
					_g_object_unref0 (persona_store);
					continue;
				}
				_tmp11_ = persona_store;
				_tmp12_ = edsf_persona_store_get_source (G_TYPE_CHECK_INSTANCE_TYPE (_tmp11_, EDSF_TYPE_PERSONA_STORE) ? ((EdsfPersonaStore*) _tmp11_) : NULL);
				_tmp13_ = _tmp12_;
				_tmp14_ = _g_object_ref0 (_tmp13_);
				source = _tmp14_;
				_tmp15_ = eds_source_registry;
				_tmp16_ = source;
				_tmp17_ = e_source_get_parent (_tmp16_);
				_tmp18_ = _tmp17_;
				_tmp19_ = e_source_registry_ref_source (_tmp15_, _tmp18_);
				parent_source = _tmp19_;
				_tmp20_ = persona_store;
				_tmp21_ = contacts_contact_format_persona_store_name (_tmp20_);
				provider_name = _tmp21_;
				_tmp22_ = g_strdup ("");
				source_account_id = _tmp22_;
				_tmp23_ = parent_source;
				_tmp24_ = e_source_has_extension (_tmp23_, E_SOURCE_EXTENSION_GOA);
				if (_tmp24_) {
					ESourceGoa* goa_source_ext = NULL;
					ESource* _tmp25_ = NULL;
					ESourceExtension* _tmp26_ = NULL;
					ESourceGoa* _tmp27_ = NULL;
					ESourceGoa* _tmp28_ = NULL;
					const gchar* _tmp29_ = NULL;
					const gchar* _tmp30_ = NULL;
					gchar* _tmp31_ = NULL;
					_tmp25_ = parent_source;
					_tmp26_ = e_source_get_extension (_tmp25_, E_SOURCE_EXTENSION_GOA);
					_tmp27_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp26_, e_source_goa_get_type ()) ? ((ESourceGoa*) _tmp26_) : NULL);
					goa_source_ext = _tmp27_;
					_tmp28_ = goa_source_ext;
					_tmp29_ = e_source_goa_get_account_id (_tmp28_);
					_tmp30_ = _tmp29_;
					_tmp31_ = g_strdup (_tmp30_);
					_g_free0 (source_account_id);
					source_account_id = _tmp31_;
					_g_object_unref0 (goa_source_ext);
				}
				_tmp32_ = (GtkGrid*) gtk_grid_new ();
				g_object_ref_sink (_tmp32_);
				row_data = _tmp32_;
				_tmp33_ = row_data;
				_tmp34_ = persona_store;
				_tmp35_ = _g_object_ref0 (_tmp34_);
				g_object_set_data_full ((GObject*) _tmp33_, "store", _tmp35_, g_object_unref);
				_tmp36_ = row_data;
				g_object_set ((GtkWidget*) _tmp36_, "margin", 6, NULL);
				_tmp37_ = row_data;
				_tmp38_ = gtk_widget_get_direction ((GtkWidget*) _tmp37_);
				if (_tmp38_ == GTK_TEXT_DIR_LTR) {
					GtkGrid* _tmp39_ = NULL;
					_tmp39_ = row_data;
					gtk_widget_set_margin_left ((GtkWidget*) _tmp39_, 5);
				} else {
					GtkGrid* _tmp40_ = NULL;
					_tmp40_ = row_data;
					gtk_widget_set_margin_right ((GtkWidget*) _tmp40_, 5);
				}
				_tmp41_ = row_data;
				gtk_grid_set_row_spacing (_tmp41_, (guint) 2);
				_tmp42_ = row_data;
				gtk_grid_set_column_spacing (_tmp42_, (guint) 10);
				_tmp43_ = source_account_id;
				if (g_strcmp0 (_tmp43_, "") != 0) {
					GtkWidget* provider_image = NULL;
					const gchar* _tmp44_ = NULL;
					GtkWidget* _tmp45_ = NULL;
					GtkWidget* _tmp46_ = NULL;
					GtkGrid* _tmp47_ = NULL;
					GtkWidget* _tmp48_ = NULL;
					_tmp44_ = source_account_id;
					_tmp45_ = contacts_get_icon_for_goa_account (_tmp44_);
					_tmp46_ = _g_object_ref0 (_tmp45_);
					provider_image = _tmp46_;
					_tmp47_ = row_data;
					_tmp48_ = provider_image;
					gtk_grid_attach (_tmp47_, _tmp48_, 0, 0, 1, 2);
					_g_object_unref0 (provider_image);
				} else {
					GtkImage* provider_image = NULL;
					GtkImage* _tmp49_ = NULL;
					GtkGrid* _tmp50_ = NULL;
					GtkImage* _tmp51_ = NULL;
					_tmp49_ = (GtkImage*) gtk_image_new_from_icon_name ("drive-harddisk-system-symbolic", GTK_ICON_SIZE_DIALOG);
					g_object_ref_sink (_tmp49_);
					provider_image = _tmp49_;
					_tmp50_ = row_data;
					_tmp51_ = provider_image;
					gtk_grid_attach (_tmp50_, (GtkWidget*) _tmp51_, 0, 0, 1, 2);
					_g_object_unref0 (provider_image);
				}
				_tmp52_ = provider_name;
				_tmp53_ = (GtkLabel*) gtk_label_new (_tmp52_);
				g_object_ref_sink (_tmp53_);
				provider_label = _tmp53_;
				_tmp54_ = provider_label;
				gtk_widget_set_halign ((GtkWidget*) _tmp54_, GTK_ALIGN_START);
				_tmp55_ = provider_label;
				gtk_widget_set_hexpand ((GtkWidget*) _tmp55_, TRUE);
				_tmp56_ = provider_label;
				gtk_widget_set_valign ((GtkWidget*) _tmp56_, GTK_ALIGN_END);
				_tmp57_ = row_data;
				_tmp58_ = provider_label;
				gtk_grid_attach (_tmp57_, (GtkWidget*) _tmp58_, 1, 0, 1, 1);
				_tmp59_ = parent_source;
				_tmp60_ = e_source_get_display_name (_tmp59_);
				_tmp61_ = _tmp60_;
				_tmp62_ = g_strdup (_tmp61_);
				account_name = _tmp62_;
				_tmp63_ = account_name;
				_tmp64_ = (GtkLabel*) gtk_label_new (_tmp63_);
				g_object_ref_sink (_tmp64_);
				account_label = _tmp64_;
				_tmp65_ = account_label;
				gtk_widget_set_halign ((GtkWidget*) _tmp65_, GTK_ALIGN_START);
				_tmp66_ = account_label;
				gtk_widget_set_hexpand ((GtkWidget*) _tmp66_, TRUE);
				_tmp67_ = account_label;
				gtk_widget_set_valign ((GtkWidget*) _tmp67_, GTK_ALIGN_START);
				_tmp68_ = account_label;
				_tmp69_ = gtk_widget_get_style_context ((GtkWidget*) _tmp68_);
				gtk_style_context_add_class (_tmp69_, "dim-label");
				_tmp70_ = row_data;
				_tmp71_ = account_label;
				gtk_grid_attach (_tmp70_, (GtkWidget*) _tmp71_, 1, 1, 1, 1);
				_tmp72_ = self->priv->accounts_view;
				_tmp73_ = row_data;
				gtk_container_add ((GtkContainer*) _tmp72_, (GtkWidget*) _tmp73_);
				_tmp75_ = select_active;
				if (_tmp75_) {
					FolksPersonaStore* _tmp76_ = NULL;
					ContactsApp* _tmp77_ = NULL;
					ContactsStore* _tmp78_ = NULL;
					FolksIndividualAggregator* _tmp79_ = NULL;
					FolksIndividualAggregator* _tmp80_ = NULL;
					FolksPersonaStore* _tmp81_ = NULL;
					FolksPersonaStore* _tmp82_ = NULL;
					_tmp76_ = persona_store;
					_tmp77_ = contacts_app_app;
					_tmp78_ = _tmp77_->contacts_store;
					_tmp79_ = contacts_store_get_aggregator (_tmp78_);
					_tmp80_ = _tmp79_;
					_tmp81_ = folks_individual_aggregator_get_primary_store (_tmp80_);
					_tmp82_ = _tmp81_;
					_tmp74_ = _tmp76_ == _tmp82_;
				} else {
					_tmp74_ = FALSE;
				}
				_tmp83_ = _tmp74_;
				if (_tmp83_) {
					GtkListBoxRow* row = NULL;
					GtkGrid* _tmp84_ = NULL;
					GtkWidget* _tmp85_ = NULL;
					GtkListBoxRow* _tmp86_ = NULL;
					GtkListBoxRow* _tmp87_ = NULL;
					_tmp84_ = row_data;
					_tmp85_ = gtk_widget_get_parent ((GtkWidget*) _tmp84_);
					_tmp86_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp85_, GTK_TYPE_LIST_BOX_ROW) ? ((GtkListBoxRow*) _tmp85_) : NULL);
					row = _tmp86_;
					_tmp87_ = row;
					contacts_accounts_list_row_activated (self, _tmp87_);
					_g_object_unref0 (row);
				}
				_g_object_unref0 (account_label);
				_g_free0 (account_name);
				_g_object_unref0 (provider_label);
				_g_object_unref0 (row_data);
				_g_free0 (source_account_id);
				_g_free0 (provider_name);
				_g_object_unref0 (parent_source);
				_g_object_unref0 (source);
				_g_object_unref0 (persona_store);
			}
		}
		persona_store_collection = (_vala_array_free (persona_store_collection, persona_store_collection_length1, (GDestroyNotify) g_object_unref), NULL);
	}
	_tmp88_ = (GtkGrid*) gtk_grid_new ();
	g_object_ref_sink (_tmp88_);
	local_data = _tmp88_;
	_tmp89_ = local_data;
	g_object_set ((GtkWidget*) _tmp89_, "margin", 6, NULL);
	_tmp90_ = local_data;
	_tmp91_ = gtk_widget_get_direction ((GtkWidget*) _tmp90_);
	if (_tmp91_ == GTK_TEXT_DIR_LTR) {
		GtkGrid* _tmp92_ = NULL;
		_tmp92_ = local_data;
		gtk_widget_set_margin_left ((GtkWidget*) _tmp92_, 5);
	} else {
		GtkGrid* _tmp93_ = NULL;
		_tmp93_ = local_data;
		gtk_widget_set_margin_right ((GtkWidget*) _tmp93_, 5);
	}
	_tmp94_ = local_data;
	gtk_grid_set_column_spacing (_tmp94_, (guint) 10);
	_tmp95_ = local_data;
	_tmp96_ = local_store;
	_tmp97_ = _g_object_ref0 (_tmp96_);
	g_object_set_data_full ((GObject*) _tmp95_, "store", _tmp97_, g_object_unref);
	_tmp98_ = (GtkImage*) gtk_image_new_from_icon_name ("drive-harddisk-system-symbolic", GTK_ICON_SIZE_DIALOG);
	g_object_ref_sink (_tmp98_);
	provider_image = _tmp98_;
	_tmp99_ = local_data;
	_tmp100_ = provider_image;
	gtk_container_add ((GtkContainer*) _tmp99_, (GtkWidget*) _tmp100_);
	_tmp101_ = _ ("Local Address Book");
	_tmp102_ = (GtkLabel*) gtk_label_new (_tmp101_);
	g_object_ref_sink (_tmp102_);
	local_label = _tmp102_;
	_tmp103_ = local_data;
	_tmp104_ = local_label;
	gtk_container_add ((GtkContainer*) _tmp103_, (GtkWidget*) _tmp104_);
	_tmp105_ = self->priv->accounts_view;
	_tmp106_ = local_data;
	gtk_container_add ((GtkContainer*) _tmp105_, (GtkWidget*) _tmp106_);
	_tmp108_ = select_active;
	if (_tmp108_) {
		FolksPersonaStore* _tmp109_ = NULL;
		ContactsApp* _tmp110_ = NULL;
		ContactsStore* _tmp111_ = NULL;
		FolksIndividualAggregator* _tmp112_ = NULL;
		FolksIndividualAggregator* _tmp113_ = NULL;
		FolksPersonaStore* _tmp114_ = NULL;
		FolksPersonaStore* _tmp115_ = NULL;
		_tmp109_ = local_store;
		_tmp110_ = contacts_app_app;
		_tmp111_ = _tmp110_->contacts_store;
		_tmp112_ = contacts_store_get_aggregator (_tmp111_);
		_tmp113_ = _tmp112_;
		_tmp114_ = folks_individual_aggregator_get_primary_store (_tmp113_);
		_tmp115_ = _tmp114_;
		_tmp107_ = _tmp109_ == _tmp115_;
	} else {
		_tmp107_ = FALSE;
	}
	_tmp116_ = _tmp107_;
	if (_tmp116_) {
		GtkListBoxRow* row = NULL;
		GtkGrid* _tmp117_ = NULL;
		GtkWidget* _tmp118_ = NULL;
		GtkListBoxRow* _tmp119_ = NULL;
		GtkListBoxRow* _tmp120_ = NULL;
		_tmp117_ = local_data;
		_tmp118_ = gtk_widget_get_parent ((GtkWidget*) _tmp117_);
		_tmp119_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp118_, GTK_TYPE_LIST_BOX_ROW) ? ((GtkListBoxRow*) _tmp118_) : NULL);
		row = _tmp119_;
		_tmp120_ = row;
		contacts_accounts_list_row_activated (self, _tmp120_);
		_g_object_unref0 (row);
	}
	_tmp121_ = self->priv->accounts_view;
	gtk_widget_show_all ((GtkWidget*) _tmp121_);
	_g_object_unref0 (local_label);
	_g_object_unref0 (provider_image);
	_g_object_unref0 (local_data);
	_g_object_unref0 (local_store);
}


static void contacts_accounts_list_class_init (ContactsAccountsListClass * klass) {
	contacts_accounts_list_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (ContactsAccountsListPrivate));
	G_OBJECT_CLASS (klass)->finalize = contacts_accounts_list_finalize;
	g_signal_new ("account_selected", CONTACTS_TYPE_ACCOUNTS_LIST, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}


static void contacts_accounts_list_instance_init (ContactsAccountsList * self) {
	self->priv = CONTACTS_ACCOUNTS_LIST_GET_PRIVATE (self);
}


static void contacts_accounts_list_finalize (GObject* obj) {
	ContactsAccountsList * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CONTACTS_TYPE_ACCOUNTS_LIST, ContactsAccountsList);
	_g_object_unref0 (self->priv->accounts_view);
	_g_object_unref0 (self->priv->last_selected_row);
	_g_object_unref0 (self->priv->add_account_button);
	_g_object_unref0 (self->selected_store);
	G_OBJECT_CLASS (contacts_accounts_list_parent_class)->finalize (obj);
}


GType contacts_accounts_list_get_type (void) {
	static volatile gsize contacts_accounts_list_type_id__volatile = 0;
	if (g_once_init_enter (&contacts_accounts_list_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ContactsAccountsListClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) contacts_accounts_list_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ContactsAccountsList), 0, (GInstanceInitFunc) contacts_accounts_list_instance_init, NULL };
		GType contacts_accounts_list_type_id;
		contacts_accounts_list_type_id = g_type_register_static (GTK_TYPE_GRID, "ContactsAccountsList", &g_define_type_info, 0);
		g_once_init_leave (&contacts_accounts_list_type_id__volatile, contacts_accounts_list_type_id);
	}
	return contacts_accounts_list_type_id__volatile;
}


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



