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

/*
 * 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 <libedataserver/libedataserver.h>
#include <folks/folks-eds.h>
#include <contacts-esd-setup.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.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 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;
enum  {
	CONTACTS_ACCOUNTS_LIST_0_PROPERTY,
	CONTACTS_ACCOUNTS_LIST_NUM_PROPERTIES
};
static GParamSpec* contacts_accounts_list_properties[CONTACTS_ACCOUNTS_LIST_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (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 _g_variant_type_free0(var) ((var == NULL) ? NULL : (var = (g_variant_type_free (var), NULL)))
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))
#define _g_variant_builder_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_builder_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
enum  {
	CONTACTS_ACCOUNTS_LIST_ACCOUNT_SELECTED_SIGNAL,
	CONTACTS_ACCOUNTS_LIST_NUM_SIGNALS
};
static guint contacts_accounts_list_signals[CONTACTS_ACCOUNTS_LIST_NUM_SIGNALS] = {0};

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

struct _ContactsAccountsListClass {
	GtkBoxClass parent_class;
};

struct _ContactsAccountsListPrivate {
	GtkListBox* accounts_view;
	GtkListBoxRow* last_selected_row;
	ContactsStore* contacts_store;
};


static gpointer contacts_accounts_list_parent_class = NULL;

GType contacts_accounts_list_get_type (void) G_GNUC_CONST;
GType contacts_store_get_type (void) G_GNUC_CONST;
#define CONTACTS_ACCOUNTS_LIST_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CONTACTS_TYPE_ACCOUNTS_LIST, ContactsAccountsListPrivate))
ContactsAccountsList* contacts_accounts_list_new (ContactsStore* contacts_store);
ContactsAccountsList* contacts_accounts_list_construct (GType object_type, ContactsStore* contacts_store);
void contacts_add_separator (GtkListBoxRow* row, GtkListBoxRow* before_row);
static void _contacts_add_separator_gtk_list_box_update_header_func (GtkListBoxRow* row, GtkListBoxRow* before, 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_utils_get_eds_address_books (ContactsStore* contacts_store, int* result_length1);
gchar* contacts_contact_format_persona_store_name (FolksPersonaStore* store);
FolksIndividualAggregator* contacts_store_get_aggregator (ContactsStore* self);
static void contacts_accounts_list_on_goa_button_clicked (ContactsAccountsList* self);
static void _contacts_accounts_list_on_goa_button_clicked_gtk_button_clicked (GtkButton* _sender, gpointer 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 gpointer _g_object_ref0 (gpointer self) {
	return self ? g_object_ref (self) : NULL;
}


static void _contacts_add_separator_gtk_list_box_update_header_func (GtkListBoxRow* row, GtkListBoxRow* before, gpointer self) {
	contacts_add_separator (row, before);
}


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


ContactsAccountsList* contacts_accounts_list_construct (GType object_type, ContactsStore* contacts_store) {
	ContactsAccountsList * self = NULL;
	ContactsStore* _tmp0_;
	ContactsStore* _tmp1_;
	GtkListBox* _tmp2_;
	GtkListBox* _tmp3_;
	g_return_val_if_fail (contacts_store != NULL, NULL);
	self = (ContactsAccountsList*) g_object_new (object_type, NULL);
	_tmp0_ = contacts_store;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->contacts_store);
	self->priv->contacts_store = _tmp1_;
	_g_object_unref0 (self->selected_store);
	self->selected_store = NULL;
	_tmp2_ = self->priv->accounts_view;
	gtk_list_box_set_header_func (_tmp2_, _contacts_add_separator_gtk_list_box_update_header_func, NULL, NULL);
	_tmp3_ = self->priv->accounts_view;
	g_signal_connect_object (_tmp3_, "row-activated", (GCallback) _contacts_accounts_list_row_activated_gtk_list_box_row_activated, self, 0);
	return self;
}


ContactsAccountsList* contacts_accounts_list_new (ContactsStore* contacts_store) {
	return contacts_accounts_list_construct (CONTACTS_TYPE_ACCOUNTS_LIST, contacts_store);
}


static void contacts_accounts_list_row_activated (ContactsAccountsList* self, GtkListBoxRow* row) {
	GtkListBoxRow* _tmp0_;
	gboolean _tmp1_ = FALSE;
	GtkListBoxRow* _tmp2_;
	GtkGrid* row_data = NULL;
	GtkListBoxRow* _tmp5_;
	GtkWidget* _tmp6_;
	GtkGrid* _tmp7_;
	GtkImage* checkmark = NULL;
	GtkImage* _tmp8_;
	GtkImage* _tmp9_;
	GtkImage* _tmp10_;
	GtkGrid* _tmp11_;
	GtkImage* _tmp12_;
	GtkListBoxRow* _tmp13_;
	GtkListBoxRow* _tmp20_;
	GtkListBoxRow* _tmp21_;
	GtkGrid* _tmp22_;
	gconstpointer _tmp23_;
	FolksPersonaStore* _tmp24_;
	g_return_if_fail (self != NULL);
	_tmp0_ = row;
	if (_tmp0_ == NULL) {
		return;
	}
	_tmp2_ = self->priv->last_selected_row;
	if (_tmp2_ != NULL) {
		GtkListBoxRow* _tmp3_;
		GtkListBoxRow* _tmp4_;
		_tmp3_ = self->priv->last_selected_row;
		_tmp4_ = row;
		_tmp1_ = _tmp3_ == _tmp4_;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		return;
	}
	_tmp5_ = row;
	_tmp6_ = gtk_bin_get_child (G_TYPE_CHECK_INSTANCE_TYPE (_tmp5_, gtk_bin_get_type ()) ? ((GtkBin*) _tmp5_) : NULL);
	_tmp7_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp6_, gtk_grid_get_type ()) ? ((GtkGrid*) _tmp6_) : NULL);
	row_data = _tmp7_;
	_tmp8_ = (GtkImage*) gtk_image_new_from_icon_name ("object-select-symbolic", GTK_ICON_SIZE_MENU);
	g_object_ref_sink (_tmp8_);
	checkmark = _tmp8_;
	_tmp9_ = checkmark;
	g_object_set ((GObject*) _tmp9_, "margin-end", 12, "valign", GTK_ALIGN_CENTER, "halign", GTK_ALIGN_END, "vexpand", TRUE, "hexpand", TRUE, NULL);
	_tmp10_ = checkmark;
	gtk_widget_show ((GtkWidget*) _tmp10_);
	_tmp11_ = row_data;
	_tmp12_ = checkmark;
	gtk_grid_attach (_tmp11_, (GtkWidget*) _tmp12_, 2, 0, 1, 2);
	_tmp13_ = self->priv->last_selected_row;
	if (_tmp13_ != NULL) {
		GtkGrid* last_row_data = NULL;
		GtkListBoxRow* _tmp14_;
		GtkWidget* _tmp15_;
		GtkGrid* _tmp16_;
		GtkGrid* _tmp17_;
		_tmp14_ = self->priv->last_selected_row;
		_tmp15_ = gtk_bin_get_child (G_TYPE_CHECK_INSTANCE_TYPE (_tmp14_, gtk_bin_get_type ()) ? ((GtkBin*) _tmp14_) : NULL);
		_tmp16_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp15_, gtk_grid_get_type ()) ? ((GtkGrid*) _tmp15_) : NULL);
		last_row_data = _tmp16_;
		_tmp17_ = last_row_data;
		if (_tmp17_ != NULL) {
			GtkGrid* _tmp18_;
			GtkWidget* _tmp19_;
			_tmp18_ = last_row_data;
			_tmp19_ = gtk_grid_get_child_at (_tmp18_, 2, 0);
			gtk_widget_destroy (_tmp19_);
		}
		_g_object_unref0 (last_row_data);
	}
	_tmp20_ = row;
	_tmp21_ = _g_object_ref0 (_tmp20_);
	_g_object_unref0 (self->priv->last_selected_row);
	self->priv->last_selected_row = _tmp21_;
	_tmp22_ = row_data;
	_tmp23_ = g_object_get_data ((GObject*) _tmp22_, "store");
	_tmp24_ = _g_object_ref0 ((FolksPersonaStore*) _tmp23_);
	_g_object_unref0 (self->selected_store);
	self->selected_store = _tmp24_;
	g_signal_emit (self, contacts_accounts_list_signals[CONTACTS_ACCOUNTS_LIST_ACCOUNT_SELECTED_SIGNAL], 0);
	_g_object_unref0 (checkmark);
	_g_object_unref0 (row_data);
}


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


static void contacts_accounts_list_on_goa_button_clicked (ContactsAccountsList* self) {
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	{
		GDBusProxy* proxy = NULL;
		GDBusProxy* _tmp0_;
		GVariantBuilder* builder = NULL;
		GVariantType* _tmp1_;
		GVariantType* _tmp2_;
		GVariantBuilder* _tmp3_;
		GVariantBuilder* _tmp4_;
		GVariantBuilder* _tmp5_;
		GVariant* _tmp6_;
		GVariant* _tmp7_;
		GVariant* param = NULL;
		GVariant* _tmp8_;
		GVariantType* _tmp9_;
		GVariantType* _tmp10_;
		GVariantBuilder* _tmp11_;
		GVariant* _tmp12_;
		GVariant* _tmp13_;
		GVariant* _tmp14_;
		GVariant** _tmp15_;
		GVariant** _tmp16_;
		gint _tmp16__length1;
		GVariant* _tmp17_;
		GVariantType* _tmp18_;
		GVariantType* _tmp19_;
		GVariant** _tmp20_;
		GVariant** _tmp21_;
		gint _tmp21__length1;
		GVariant* _tmp22_;
		GVariant** _tmp23_;
		GVariant** _tmp24_;
		gint _tmp24__length1;
		GVariant* _tmp25_;
		GVariant* _tmp26_;
		GDBusProxy* _tmp27_;
		GVariant* _tmp28_;
		GVariant* _tmp29_;
		GVariant* _tmp30_;
		_tmp0_ = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, NULL, "org.gnome.ControlCenter", "/org/gnome/ControlCenter", "org.gtk.Actions", NULL, &_inner_error_);
		proxy = _tmp0_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			goto __catch38_g_error;
		}
		_tmp1_ = g_variant_type_new ("av");
		_tmp2_ = _tmp1_;
		_tmp3_ = g_variant_builder_new (_tmp2_);
		_tmp4_ = _tmp3_;
		_g_variant_type_free0 (_tmp2_);
		builder = _tmp4_;
		_tmp5_ = builder;
		_tmp6_ = g_variant_new_string ("");
		g_variant_ref_sink (_tmp6_);
		_tmp7_ = _tmp6_;
		g_variant_builder_add (_tmp5_, "v", _tmp7_, NULL);
		_g_variant_unref0 (_tmp7_);
		_tmp8_ = g_variant_new_string ("launch-panel");
		g_variant_ref_sink (_tmp8_);
		_tmp9_ = g_variant_type_new ("v");
		_tmp10_ = _tmp9_;
		_tmp11_ = builder;
		_tmp12_ = g_variant_new ("(sav)", "online-accounts", _tmp11_, NULL);
		g_variant_ref_sink (_tmp12_);
		_tmp13_ = _tmp12_;
		_tmp14_ = g_variant_new ("v", _tmp13_, NULL);
		g_variant_ref_sink (_tmp14_);
		_tmp15_ = g_new0 (GVariant*, 1 + 1);
		_tmp15_[0] = _tmp14_;
		_tmp16_ = _tmp15_;
		_tmp16__length1 = 1;
		_tmp17_ = g_variant_new_array (_tmp10_, _tmp16_, 1);
		g_variant_ref_sink (_tmp17_);
		_tmp18_ = g_variant_type_new ("{sv}");
		_tmp19_ = _tmp18_;
		_tmp20_ = g_new0 (GVariant*, 0 + 1);
		_tmp21_ = _tmp20_;
		_tmp21__length1 = 0;
		_tmp22_ = g_variant_new_array (_tmp19_, _tmp21_, 0);
		g_variant_ref_sink (_tmp22_);
		_tmp23_ = g_new0 (GVariant*, 3 + 1);
		_tmp23_[0] = _tmp8_;
		_tmp23_[1] = _tmp17_;
		_tmp23_[2] = _tmp22_;
		_tmp24_ = _tmp23_;
		_tmp24__length1 = 3;
		_tmp25_ = g_variant_new_tuple (_tmp24_, 3);
		g_variant_ref_sink (_tmp25_);
		_tmp26_ = _tmp25_;
		_tmp24_ = (_vala_array_free (_tmp24_, _tmp24__length1, (GDestroyNotify) g_variant_unref), NULL);
		_tmp21_ = (_vala_array_free (_tmp21_, _tmp21__length1, (GDestroyNotify) g_variant_unref), NULL);
		_g_variant_type_free0 (_tmp19_);
		_tmp16_ = (_vala_array_free (_tmp16_, _tmp16__length1, (GDestroyNotify) g_variant_unref), NULL);
		_g_variant_unref0 (_tmp13_);
		_g_variant_type_free0 (_tmp10_);
		param = _tmp26_;
		_tmp27_ = proxy;
		_tmp28_ = param;
		_tmp29_ = g_dbus_proxy_call_sync (_tmp27_, "Activate", _tmp28_, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &_inner_error_);
		_tmp30_ = _tmp29_;
		_g_variant_unref0 (_tmp30_);
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			_g_variant_unref0 (param);
			_g_variant_builder_unref0 (builder);
			_g_object_unref0 (proxy);
			goto __catch38_g_error;
		}
		_g_variant_unref0 (param);
		_g_variant_builder_unref0 (builder);
		_g_object_unref0 (proxy);
	}
	goto __finally38;
	__catch38_g_error:
	{
		GError* e = NULL;
		GError* _tmp31_;
		const gchar* _tmp32_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp31_ = e;
		_tmp32_ = _tmp31_->message;
		g_warning ("contacts-accounts-list.vala:180: Couldn't open online-accounts: %s", _tmp32_);
		_g_error_free0 (e);
	}
	__finally38:
	if (G_UNLIKELY (_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 _contacts_accounts_list_on_goa_button_clicked_gtk_button_clicked (GtkButton* _sender, gpointer self) {
	contacts_accounts_list_on_goa_button_clicked ((ContactsAccountsList*) self);
}


static void contacts_accounts_list_class_init (ContactsAccountsListClass * klass) {
	gint ContactsAccountsList_private_offset;
	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;
	ContactsAccountsList_private_offset = g_type_class_get_instance_private_offset (klass);
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/contacts/ui/contacts-accounts-list.ui");
	contacts_accounts_list_signals[CONTACTS_ACCOUNTS_LIST_ACCOUNT_SELECTED_SIGNAL] = 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);
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "accounts_view", FALSE, ContactsAccountsList_private_offset + G_STRUCT_OFFSET (ContactsAccountsListPrivate, accounts_view));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_goa_button_clicked", G_CALLBACK(_contacts_accounts_list_on_goa_button_clicked_gtk_button_clicked));
}


static void contacts_accounts_list_instance_init (ContactsAccountsList * self) {
	self->priv = CONTACTS_ACCOUNTS_LIST_GET_PRIVATE (self);
	gtk_widget_init_template (GTK_WIDGET (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->contacts_store);
	_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_box_get_type (), "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);
}



