/* contacts-setup-window.c generated by valac 0.20.1, the Vala compiler
 * generated from contacts-setup-window.vala, do not modify */

/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 8 -*- */
/*
 * Copyright (C) 2011 Alexander Larsson <alexl@redhat.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 <glib/gi18n-lib.h>
#include <contacts-esd-setup.h>
#include <stdlib.h>
#include <string.h>
#include <folks/folks.h>
#include <gio/gio.h>
#include <libedataserver/libedataserver.h>
#include <folks/folks-eds.h>
#include <gdk/gdk.h>


#define CONTACTS_TYPE_SETUP_WINDOW (contacts_setup_window_get_type ())
#define CONTACTS_SETUP_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONTACTS_TYPE_SETUP_WINDOW, ContactsSetupWindow))
#define CONTACTS_SETUP_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONTACTS_TYPE_SETUP_WINDOW, ContactsSetupWindowClass))
#define CONTACTS_IS_SETUP_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONTACTS_TYPE_SETUP_WINDOW))
#define CONTACTS_IS_SETUP_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONTACTS_TYPE_SETUP_WINDOW))
#define CONTACTS_SETUP_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONTACTS_TYPE_SETUP_WINDOW, ContactsSetupWindowClass))

typedef struct _ContactsSetupWindow ContactsSetupWindow;
typedef struct _ContactsSetupWindowClass ContactsSetupWindowClass;
typedef struct _ContactsSetupWindowPrivate ContactsSetupWindowPrivate;
#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 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;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _ContactsSetupWindow {
	GtkWindow parent_instance;
	ContactsSetupWindowPrivate * priv;
	gboolean succeeded;
	GtkLabel* title_label;
	GtkGrid* content_grid;
};

struct _ContactsSetupWindowClass {
	GtkWindowClass parent_class;
};

struct _ContactsSetupWindowPrivate {
	gulong source_list_changed_id;
	GtkToolButton* select_button;
	GtkListStore* list_store;
	GtkTreeView* tree_view;
};

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

struct _ContactsAppClass {
	GtkApplicationClass parent_class;
};


static gpointer contacts_setup_window_parent_class = NULL;
extern ContactsApp* contacts_app_app;

GType contacts_setup_window_get_type (void) G_GNUC_CONST;
#define CONTACTS_SETUP_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CONTACTS_TYPE_SETUP_WINDOW, ContactsSetupWindowPrivate))
enum  {
	CONTACTS_SETUP_WINDOW_DUMMY_PROPERTY
};
void contacts_setup_window_update_content (ContactsSetupWindow* self);
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 ___lambda124_ (ContactsSetupWindow* self);
static void contacts_setup_window_select_source (ContactsSetupWindow* self, ESource* source);
static void ____lambda124__gtk_button_clicked (GtkButton* _sender, gpointer self);
static void __lambda125_ (ContactsSetupWindow* self, GtkButton* button);
static void ___lambda125__gtk_button_clicked (GtkButton* _sender, gpointer self);
ContactsSetupWindow* contacts_setup_window_new (void);
ContactsSetupWindow* contacts_setup_window_construct (GType object_type);
static void __lambda126_ (ContactsSetupWindow* self, GtkToolButton* button);
static void ___lambda126__gtk_tool_button_clicked (GtkToolButton* _sender, gpointer self);
static void __lambda127_ (ContactsSetupWindow* self, GtkToolButton* button);
static void ___lambda127__gtk_tool_button_clicked (GtkToolButton* _sender, gpointer self);
static void __lambda128_ (ContactsSetupWindow* self);
static void ___lambda128__e_source_registry_source_changed (ESourceRegistry* _sender, ESource* source, gpointer self);
static void contacts_setup_window_real_destroy (GtkWidget* base);
static gboolean contacts_setup_window_real_window_state_event (GtkWidget* base, GdkEventWindowState* e);
static void contacts_setup_window_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 ___lambda124_ (ContactsSetupWindow* self) {
	ESourceRegistry* _tmp0_;
	ESource* _tmp1_ = NULL;
	ESource* source;
	_tmp0_ = eds_source_registry;
	_tmp1_ = e_source_registry_ref_builtin_address_book (_tmp0_);
	source = _tmp1_;
	contacts_setup_window_select_source (self, source);
	_g_object_unref0 (source);
}


static void ____lambda124__gtk_button_clicked (GtkButton* _sender, gpointer self) {
	___lambda124_ (self);
}


static void __lambda125_ (ContactsSetupWindow* self, GtkButton* button) {
	GError * _inner_error_ = NULL;
	g_return_if_fail (button != NULL);
	{
		contacts_setup_window_update_content (self);
		g_spawn_command_line_async ("gnome-control-center online-accounts", &_inner_error_);
		if (_inner_error_ != NULL) {
			goto __catch31_g_error;
		}
	}
	goto __finally31;
	__catch31_g_error:
	{
		GError* e = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		_g_error_free0 (e);
	}
	__finally31:
	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 ___lambda125__gtk_button_clicked (GtkButton* _sender, gpointer self) {
	__lambda125_ (self, _sender);
}


void contacts_setup_window_update_content (ContactsSetupWindow* self) {
	GtkGrid* _tmp0_;
	GList* _tmp1_ = NULL;
	const gchar* _tmp3_ = NULL;
	GtkLabel* _tmp4_;
	GtkLabel* l;
	GtkLabel* _tmp5_;
	GtkLabel* _tmp6_;
	GtkLabel* _tmp7_;
	GtkLabel* _tmp8_;
	GtkGrid* _tmp9_;
	GtkLabel* _tmp10_;
	GtkButton* goa_button = NULL;
	gboolean _tmp11_ = FALSE;
	GtkButton* _tmp78_;
	GtkGrid* _tmp79_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->content_grid;
	_tmp1_ = gtk_container_get_children ((GtkContainer*) _tmp0_);
	{
		GList* w_collection = NULL;
		GList* w_it = NULL;
		w_collection = _tmp1_;
		for (w_it = w_collection; w_it != NULL; w_it = w_it->next) {
			GtkWidget* w = NULL;
			w = (GtkWidget*) w_it->data;
			{
				GtkWidget* _tmp2_;
				_tmp2_ = w;
				gtk_widget_destroy (_tmp2_);
			}
		}
		_g_list_free0 (w_collection);
	}
	_tmp3_ = _ ("Welcome to Contacts! Please select where you want to keep your address" \
" book:");
	_tmp4_ = (GtkLabel*) gtk_label_new (_tmp3_);
	g_object_ref_sink (_tmp4_);
	l = _tmp4_;
	_tmp5_ = l;
	gtk_label_set_line_wrap (_tmp5_, TRUE);
	_tmp6_ = l;
	gtk_label_set_max_width_chars (_tmp6_, 5);
	_tmp7_ = l;
	gtk_widget_set_halign ((GtkWidget*) _tmp7_, GTK_ALIGN_FILL);
	_tmp8_ = l;
	gtk_misc_set_alignment ((GtkMisc*) _tmp8_, 0.0f, 0.5f);
	_tmp9_ = self->content_grid;
	_tmp10_ = l;
	gtk_container_add ((GtkContainer*) _tmp9_, (GtkWidget*) _tmp10_);
	_tmp11_ = contacts_has_goa_account ();
	if (_tmp11_) {
		GtkToolButton* _tmp12_;
		GtkTreeView* _tmp13_;
		GtkListStore* _tmp14_;
		GtkListStore* store;
		GtkListStore* _tmp15_;
		GtkListStore* _tmp16_;
		GtkTreeView* _tmp17_;
		GtkListStore* _tmp18_;
		GtkTreeView* _tmp19_;
		GtkTreeView* _tmp20_;
		GtkTreeSelection* _tmp21_ = NULL;
		GtkTreeViewColumn* _tmp22_;
		GtkTreeViewColumn* column;
		GtkTreeView* _tmp23_;
		GtkTreeViewColumn* _tmp24_;
		GtkCellRendererText* _tmp25_;
		GtkCellRendererText* renderer;
		GtkTreeViewColumn* _tmp26_;
		GtkCellRendererText* _tmp27_;
		GtkTreeViewColumn* _tmp28_;
		GtkCellRendererText* _tmp29_;
		GtkScrolledWindow* _tmp30_;
		GtkScrolledWindow* scrolled;
		GtkScrolledWindow* _tmp31_;
		GtkScrolledWindow* _tmp32_;
		GtkScrolledWindow* _tmp33_;
		GtkScrolledWindow* _tmp34_;
		GtkScrolledWindow* _tmp35_;
		GtkTreeView* _tmp36_;
		GtkGrid* _tmp37_;
		GtkScrolledWindow* _tmp38_;
		GtkTreeIter iter = {0};
		gint _tmp39_ = 0;
		FolksPersonaStore** _tmp40_ = NULL;
		const gchar* _tmp60_ = NULL;
		GtkButton* _tmp61_;
		GtkGrid* _tmp62_;
		GtkButton* _tmp63_;
		_tmp12_ = self->priv->select_button;
		gtk_widget_show ((GtkWidget*) _tmp12_);
		_tmp13_ = (GtkTreeView*) gtk_tree_view_new ();
		g_object_ref_sink (_tmp13_);
		_g_object_unref0 (self->priv->tree_view);
		self->priv->tree_view = _tmp13_;
		_tmp14_ = gtk_list_store_new (2, G_TYPE_STRING, FOLKS_TYPE_PERSONA_STORE);
		store = _tmp14_;
		_tmp15_ = store;
		_tmp16_ = _g_object_ref0 (_tmp15_);
		_g_object_unref0 (self->priv->list_store);
		self->priv->list_store = _tmp16_;
		_tmp17_ = self->priv->tree_view;
		_tmp18_ = store;
		gtk_tree_view_set_model (_tmp17_, (GtkTreeModel*) _tmp18_);
		_tmp19_ = self->priv->tree_view;
		gtk_tree_view_set_headers_visible (_tmp19_, FALSE);
		_tmp20_ = self->priv->tree_view;
		_tmp21_ = gtk_tree_view_get_selection (_tmp20_);
		gtk_tree_selection_set_mode (_tmp21_, GTK_SELECTION_BROWSE);
		_tmp22_ = gtk_tree_view_column_new ();
		g_object_ref_sink (_tmp22_);
		column = _tmp22_;
		_tmp23_ = self->priv->tree_view;
		_tmp24_ = column;
		gtk_tree_view_append_column (_tmp23_, _tmp24_);
		_tmp25_ = (GtkCellRendererText*) gtk_cell_renderer_text_new ();
		g_object_ref_sink (_tmp25_);
		renderer = _tmp25_;
		_tmp26_ = column;
		_tmp27_ = renderer;
		gtk_cell_layout_pack_start ((GtkCellLayout*) _tmp26_, (GtkCellRenderer*) _tmp27_, FALSE);
		_tmp28_ = column;
		_tmp29_ = renderer;
		gtk_cell_layout_add_attribute ((GtkCellLayout*) _tmp28_, (GtkCellRenderer*) _tmp29_, "text", 0);
		_tmp30_ = (GtkScrolledWindow*) gtk_scrolled_window_new (NULL, NULL);
		g_object_ref_sink (_tmp30_);
		scrolled = _tmp30_;
		_tmp31_ = scrolled;
		gtk_widget_set_size_request ((GtkWidget*) _tmp31_, 340, 220);
		_tmp32_ = scrolled;
		gtk_scrolled_window_set_policy (_tmp32_, GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
		_tmp33_ = scrolled;
		gtk_widget_set_vexpand ((GtkWidget*) _tmp33_, FALSE);
		_tmp34_ = scrolled;
		gtk_scrolled_window_set_shadow_type (_tmp34_, GTK_SHADOW_IN);
		_tmp35_ = scrolled;
		_tmp36_ = self->priv->tree_view;
		gtk_container_add ((GtkContainer*) _tmp35_, (GtkWidget*) _tmp36_);
		_tmp37_ = self->content_grid;
		_tmp38_ = scrolled;
		gtk_container_add ((GtkContainer*) _tmp37_, (GtkWidget*) _tmp38_);
		_tmp40_ = contacts_app_get_eds_address_books (&_tmp39_);
		{
			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 = _tmp40_;
			persona_store_collection_length1 = _tmp39_;
			for (persona_store_it = 0; persona_store_it < _tmp39_; persona_store_it = persona_store_it + 1) {
				FolksPersonaStore* _tmp41_;
				FolksPersonaStore* persona_store = NULL;
				_tmp41_ = _g_object_ref0 (persona_store_collection[persona_store_it]);
				persona_store = _tmp41_;
				{
					FolksPersonaStore* _tmp42_;
					gchar* _tmp43_ = NULL;
					gchar* name;
					GtkListStore* _tmp44_;
					GtkTreeIter _tmp45_ = {0};
					GtkListStore* _tmp46_;
					GtkTreeIter _tmp47_;
					const gchar* _tmp48_;
					FolksPersonaStore* _tmp49_;
					FolksPersonaStore* _tmp50_;
					ContactsApp* _tmp51_;
					ContactsStore* _tmp52_;
					FolksIndividualAggregator* _tmp53_;
					FolksIndividualAggregator* _tmp54_;
					FolksPersonaStore* _tmp55_;
					FolksPersonaStore* _tmp56_;
					_tmp42_ = persona_store;
					_tmp43_ = contacts_contact_format_persona_store_name (_tmp42_);
					name = _tmp43_;
					_tmp44_ = store;
					gtk_list_store_append (_tmp44_, &_tmp45_);
					iter = _tmp45_;
					_tmp46_ = store;
					_tmp47_ = iter;
					_tmp48_ = name;
					_tmp49_ = persona_store;
					gtk_list_store_set (_tmp46_, &_tmp47_, 0, _tmp48_, 1, _tmp49_, -1);
					_tmp50_ = persona_store;
					_tmp51_ = contacts_app_app;
					_tmp52_ = _tmp51_->contacts_store;
					_tmp53_ = contacts_store_get_aggregator (_tmp52_);
					_tmp54_ = _tmp53_;
					_tmp55_ = folks_individual_aggregator_get_primary_store (_tmp54_);
					_tmp56_ = _tmp55_;
					if (_tmp50_ == _tmp56_) {
						GtkTreeView* _tmp57_;
						GtkTreeSelection* _tmp58_ = NULL;
						GtkTreeIter _tmp59_;
						_tmp57_ = self->priv->tree_view;
						_tmp58_ = gtk_tree_view_get_selection (_tmp57_);
						_tmp59_ = iter;
						gtk_tree_selection_select_iter (_tmp58_, &_tmp59_);
					}
					_g_free0 (name);
					_g_object_unref0 (persona_store);
				}
			}
			persona_store_collection = (_vala_array_free (persona_store_collection, persona_store_collection_length1, (GDestroyNotify) g_object_unref), NULL);
		}
		_tmp60_ = _ ("Online Account Settings");
		_tmp61_ = (GtkButton*) gtk_button_new_with_label (_tmp60_);
		g_object_ref_sink (_tmp61_);
		_g_object_unref0 (goa_button);
		goa_button = _tmp61_;
		_tmp62_ = self->content_grid;
		_tmp63_ = goa_button;
		gtk_container_add ((GtkContainer*) _tmp62_, (GtkWidget*) _tmp63_);
		_g_object_unref0 (scrolled);
		_g_object_unref0 (renderer);
		_g_object_unref0 (column);
		_g_object_unref0 (store);
	} else {
		GtkToolButton* _tmp64_;
		const gchar* _tmp65_ = NULL;
		GtkLabel* _tmp66_;
		GtkGrid* _tmp67_;
		GtkLabel* _tmp68_;
		const gchar* _tmp69_ = NULL;
		GtkButton* _tmp70_;
		GtkGrid* _tmp71_;
		GtkButton* _tmp72_;
		const gchar* _tmp73_ = NULL;
		GtkButton* _tmp74_;
		GtkButton* b;
		GtkGrid* _tmp75_;
		GtkButton* _tmp76_;
		GtkButton* _tmp77_;
		_tmp64_ = self->priv->select_button;
		gtk_widget_hide ((GtkWidget*) _tmp64_);
		_tmp65_ = _ ("Setup an online account or use a local address book");
		_tmp66_ = (GtkLabel*) gtk_label_new (_tmp65_);
		g_object_ref_sink (_tmp66_);
		_g_object_unref0 (l);
		l = _tmp66_;
		_tmp67_ = self->content_grid;
		_tmp68_ = l;
		gtk_container_add ((GtkContainer*) _tmp67_, (GtkWidget*) _tmp68_);
		_tmp69_ = _ ("Online Accounts");
		_tmp70_ = (GtkButton*) gtk_button_new_with_label (_tmp69_);
		g_object_ref_sink (_tmp70_);
		_g_object_unref0 (goa_button);
		goa_button = _tmp70_;
		_tmp71_ = self->content_grid;
		_tmp72_ = goa_button;
		gtk_container_add ((GtkContainer*) _tmp71_, (GtkWidget*) _tmp72_);
		_tmp73_ = _ ("Use Local Address Book");
		_tmp74_ = (GtkButton*) gtk_button_new_with_label (_tmp73_);
		g_object_ref_sink (_tmp74_);
		b = _tmp74_;
		_tmp75_ = self->content_grid;
		_tmp76_ = b;
		gtk_container_add ((GtkContainer*) _tmp75_, (GtkWidget*) _tmp76_);
		_tmp77_ = b;
		g_signal_connect_object (_tmp77_, "clicked", (GCallback) ____lambda124__gtk_button_clicked, self, 0);
		_g_object_unref0 (b);
	}
	_tmp78_ = goa_button;
	g_signal_connect_object (_tmp78_, "clicked", (GCallback) ___lambda125__gtk_button_clicked, self, 0);
	_tmp79_ = self->content_grid;
	gtk_widget_show_all ((GtkWidget*) _tmp79_);
	_g_object_unref0 (goa_button);
	_g_object_unref0 (l);
}


static void contacts_setup_window_select_source (ContactsSetupWindow* self, ESource* source) {
	ESourceRegistry* _tmp0_;
	ESource* _tmp1_;
	ContactsApp* _tmp2_;
	GSettings* _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (source != NULL);
	_tmp0_ = eds_source_registry;
	_tmp1_ = source;
	e_source_registry_set_default_address_book (_tmp0_, _tmp1_);
	self->succeeded = TRUE;
	_tmp2_ = contacts_app_app;
	_tmp3_ = _tmp2_->settings;
	g_settings_set_boolean (_tmp3_, "did-initial-setup", TRUE);
	gtk_widget_destroy ((GtkWidget*) self);
}


static void __lambda126_ (ContactsSetupWindow* self, GtkToolButton* button) {
	g_return_if_fail (button != NULL);
	gtk_widget_destroy ((GtkWidget*) self);
}


static void ___lambda126__gtk_tool_button_clicked (GtkToolButton* _sender, gpointer self) {
	__lambda126_ (self, _sender);
}


static void __lambda127_ (ContactsSetupWindow* self, GtkToolButton* button) {
	FolksPersonaStore* selected_store = NULL;
	GtkTreeIter iter = {0};
	GtkTreeView* _tmp0_;
	GtkTreeSelection* _tmp1_ = NULL;
	GtkTreeIter _tmp2_ = {0};
	gboolean _tmp3_ = FALSE;
	g_return_if_fail (button != NULL);
	_tmp0_ = self->priv->tree_view;
	_tmp1_ = gtk_tree_view_get_selection (_tmp0_);
	_tmp3_ = gtk_tree_selection_get_selected (_tmp1_, NULL, &_tmp2_);
	iter = _tmp2_;
	if (_tmp3_) {
		GtkListStore* _tmp4_;
		GtkTreeIter _tmp5_;
		FolksPersonaStore* _tmp6_;
		EdsfPersonaStore* _tmp7_;
		EdsfPersonaStore* e_store;
		EdsfPersonaStore* _tmp8_;
		ESource* _tmp9_;
		ESource* _tmp10_;
		_tmp4_ = self->priv->list_store;
		_tmp5_ = iter;
		gtk_tree_model_get ((GtkTreeModel*) _tmp4_, &_tmp5_, 1, &selected_store, -1);
		_tmp6_ = selected_store;
		_tmp7_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp6_, EDSF_TYPE_PERSONA_STORE) ? ((EdsfPersonaStore*) _tmp6_) : NULL);
		e_store = _tmp7_;
		_tmp8_ = e_store;
		_tmp9_ = edsf_persona_store_get_source (_tmp8_);
		_tmp10_ = _tmp9_;
		contacts_setup_window_select_source (self, _tmp10_);
		_g_object_unref0 (e_store);
	}
	_g_object_unref0 (selected_store);
}


static void ___lambda127__gtk_tool_button_clicked (GtkToolButton* _sender, gpointer self) {
	__lambda127_ (self, _sender);
}


static void __lambda128_ (ContactsSetupWindow* self) {
	contacts_setup_window_update_content (self);
}


static void ___lambda128__e_source_registry_source_changed (ESourceRegistry* _sender, ESource* source, gpointer self) {
	__lambda128_ (self);
}


ContactsSetupWindow* contacts_setup_window_construct (GType object_type) {
	ContactsSetupWindow * self = NULL;
	GtkGrid* _tmp0_;
	GtkGrid* grid;
	const gchar* _tmp1_ = NULL;
	GtkToolbar* _tmp2_;
	GtkToolbar* toolbar;
	GtkStyleContext* _tmp3_ = NULL;
	const gchar* _tmp4_ = NULL;
	GtkToolButton* _tmp5_;
	GtkToolButton* cancel_button;
	GtkToolItem* _tmp6_;
	GtkToolItem* item;
	GtkLabel* _tmp7_;
	GtkLabel* _tmp8_;
	const gchar* _tmp9_ = NULL;
	gchar* _tmp10_ = NULL;
	gchar* _tmp11_;
	GtkLabel* _tmp12_;
	GtkLabel* _tmp13_;
	const gchar* _tmp14_ = NULL;
	GtkToolButton* _tmp15_;
	GtkToolButton* _tmp16_;
	GtkToolButton* _tmp17_;
	GtkToolButton* _tmp18_;
	GtkToolButton* _tmp19_;
	GtkFrame* _tmp20_;
	GtkFrame* frame;
	GtkStyleContext* _tmp21_ = NULL;
	GtkEventBox* _tmp22_;
	GtkEventBox* box;
	GtkStyleContext* _tmp23_ = NULL;
	GtkStyleContext* _tmp24_ = NULL;
	GtkGrid* _tmp25_;
	GtkGrid* _tmp26_;
	GtkGrid* _tmp27_;
	GtkGrid* _tmp28_;
	GtkGrid* _tmp29_;
	GtkGrid* _tmp30_;
	ESourceRegistry* _tmp31_;
	gulong _tmp32_ = 0UL;
	self = (ContactsSetupWindow*) g_object_new (object_type, NULL);
	_tmp0_ = (GtkGrid*) gtk_grid_new ();
	g_object_ref_sink (_tmp0_);
	grid = _tmp0_;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) grid);
	_tmp1_ = _ ("Contacts Setup");
	gtk_window_set_title ((GtkWindow*) self, _tmp1_);
	gtk_window_set_default_size ((GtkWindow*) self, 640, 480);
	gtk_window_set_hide_titlebar_when_maximized ((GtkWindow*) self, TRUE);
	_tmp2_ = (GtkToolbar*) gtk_toolbar_new ();
	g_object_ref_sink (_tmp2_);
	toolbar = _tmp2_;
	gtk_toolbar_set_icon_size (toolbar, GTK_ICON_SIZE_MENU);
	_tmp3_ = gtk_widget_get_style_context ((GtkWidget*) toolbar);
	gtk_style_context_add_class (_tmp3_, GTK_STYLE_CLASS_MENUBAR);
	gtk_widget_set_vexpand ((GtkWidget*) toolbar, FALSE);
	gtk_widget_set_hexpand ((GtkWidget*) toolbar, TRUE);
	gtk_grid_attach (grid, (GtkWidget*) toolbar, 0, 0, 1, 1);
	_tmp4_ = _ ("Cancel");
	_tmp5_ = (GtkToolButton*) gtk_tool_button_new (NULL, _tmp4_);
	g_object_ref_sink (_tmp5_);
	cancel_button = _tmp5_;
	gtk_tool_item_set_is_important ((GtkToolItem*) cancel_button, TRUE);
	gtk_container_add ((GtkContainer*) toolbar, (GtkWidget*) cancel_button);
	g_signal_connect_object (cancel_button, "clicked", (GCallback) ___lambda126__gtk_tool_button_clicked, self, 0);
	_tmp6_ = gtk_tool_item_new ();
	g_object_ref_sink (_tmp6_);
	item = _tmp6_;
	_tmp7_ = (GtkLabel*) gtk_label_new ("");
	g_object_ref_sink (_tmp7_);
	_g_object_unref0 (self->title_label);
	self->title_label = _tmp7_;
	_tmp8_ = self->title_label;
	_tmp9_ = _ ("Contacts Setup");
	_tmp10_ = g_markup_printf_escaped ("<b>%s</b>", _tmp9_);
	_tmp11_ = _tmp10_;
	gtk_label_set_markup (_tmp8_, _tmp11_);
	_g_free0 (_tmp11_);
	_tmp12_ = self->title_label;
	gtk_widget_set_no_show_all ((GtkWidget*) _tmp12_, TRUE);
	_tmp13_ = self->title_label;
	gtk_container_add ((GtkContainer*) item, (GtkWidget*) _tmp13_);
	gtk_tool_item_set_expand (item, TRUE);
	gtk_container_add ((GtkContainer*) toolbar, (GtkWidget*) item);
	_tmp14_ = _ ("Select");
	_tmp15_ = (GtkToolButton*) gtk_tool_button_new (NULL, _tmp14_);
	g_object_ref_sink (_tmp15_);
	_g_object_unref0 (self->priv->select_button);
	self->priv->select_button = _tmp15_;
	_tmp16_ = self->priv->select_button;
	gtk_tool_item_set_is_important ((GtkToolItem*) _tmp16_, TRUE);
	_tmp17_ = self->priv->select_button;
	gtk_widget_set_no_show_all ((GtkWidget*) _tmp17_, TRUE);
	_tmp18_ = self->priv->select_button;
	gtk_container_add ((GtkContainer*) toolbar, (GtkWidget*) _tmp18_);
	_tmp19_ = self->priv->select_button;
	g_signal_connect_object (_tmp19_, "clicked", (GCallback) ___lambda127__gtk_tool_button_clicked, self, 0);
	_tmp20_ = (GtkFrame*) gtk_frame_new (NULL);
	g_object_ref_sink (_tmp20_);
	frame = _tmp20_;
	_tmp21_ = gtk_widget_get_style_context ((GtkWidget*) frame);
	gtk_style_context_add_class (_tmp21_, "contacts-content");
	_tmp22_ = (GtkEventBox*) gtk_event_box_new ();
	g_object_ref_sink (_tmp22_);
	box = _tmp22_;
	gtk_widget_set_hexpand ((GtkWidget*) box, TRUE);
	gtk_widget_set_vexpand ((GtkWidget*) box, TRUE);
	_tmp23_ = gtk_widget_get_style_context ((GtkWidget*) box);
	gtk_style_context_add_class (_tmp23_, "contacts-main-view");
	_tmp24_ = gtk_widget_get_style_context ((GtkWidget*) box);
	gtk_style_context_add_class (_tmp24_, "view");
	gtk_container_add ((GtkContainer*) frame, (GtkWidget*) box);
	gtk_grid_attach (grid, (GtkWidget*) frame, 0, 1, 1, 1);
	_tmp25_ = (GtkGrid*) gtk_grid_new ();
	g_object_ref_sink (_tmp25_);
	_g_object_unref0 (self->content_grid);
	self->content_grid = _tmp25_;
	_tmp26_ = self->content_grid;
	gtk_container_set_border_width ((GtkContainer*) _tmp26_, (guint) 12);
	_tmp27_ = self->content_grid;
	gtk_orientable_set_orientation ((GtkOrientable*) _tmp27_, GTK_ORIENTATION_VERTICAL);
	_tmp28_ = self->content_grid;
	gtk_widget_set_halign ((GtkWidget*) _tmp28_, GTK_ALIGN_CENTER);
	_tmp29_ = self->content_grid;
	gtk_grid_set_row_spacing (_tmp29_, (guint) 8);
	_tmp30_ = self->content_grid;
	gtk_container_add ((GtkContainer*) box, (GtkWidget*) _tmp30_);
	contacts_setup_window_update_content (self);
	_tmp31_ = eds_source_registry;
	_tmp32_ = g_signal_connect_object (_tmp31_, "source-changed", (GCallback) ___lambda128__e_source_registry_source_changed, self, 0);
	self->priv->source_list_changed_id = _tmp32_;
	gtk_widget_show_all ((GtkWidget*) grid);
	_g_object_unref0 (box);
	_g_object_unref0 (frame);
	_g_object_unref0 (item);
	_g_object_unref0 (cancel_button);
	_g_object_unref0 (toolbar);
	_g_object_unref0 (grid);
	return self;
}


ContactsSetupWindow* contacts_setup_window_new (void) {
	return contacts_setup_window_construct (CONTACTS_TYPE_SETUP_WINDOW);
}


static void contacts_setup_window_real_destroy (GtkWidget* base) {
	ContactsSetupWindow * self;
	gulong _tmp0_;
	self = (ContactsSetupWindow*) base;
	_tmp0_ = self->priv->source_list_changed_id;
	if (_tmp0_ != ((gulong) 0)) {
		ESourceRegistry* _tmp1_;
		gulong _tmp2_;
		_tmp1_ = eds_source_registry;
		_tmp2_ = self->priv->source_list_changed_id;
		g_signal_handler_disconnect ((GObject*) _tmp1_, _tmp2_);
		self->priv->source_list_changed_id = (gulong) 0;
	}
	GTK_WIDGET_CLASS (contacts_setup_window_parent_class)->destroy ((GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (self, GTK_TYPE_WINDOW, GtkWindow));
}


static gboolean contacts_setup_window_real_window_state_event (GtkWidget* base, GdkEventWindowState* e) {
	ContactsSetupWindow * self;
	gboolean result = FALSE;
	GdkEventWindowState _tmp0_;
	GdkEventWindowState _tmp1_;
	GdkWindowState _tmp2_;
	self = (ContactsSetupWindow*) base;
	g_return_val_if_fail (e != NULL, FALSE);
	_tmp0_ = *e;
	GTK_WIDGET_CLASS (contacts_setup_window_parent_class)->window_state_event ((GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (self, GTK_TYPE_WINDOW, GtkWindow), &_tmp0_);
	_tmp1_ = *e;
	_tmp2_ = _tmp1_.new_window_state;
	if ((_tmp2_ & GDK_WINDOW_STATE_MAXIMIZED) != 0) {
		GtkLabel* _tmp3_;
		_tmp3_ = self->title_label;
		gtk_widget_show ((GtkWidget*) _tmp3_);
	} else {
		GtkLabel* _tmp4_;
		_tmp4_ = self->title_label;
		gtk_widget_hide ((GtkWidget*) _tmp4_);
	}
	result = FALSE;
	return result;
}


static void contacts_setup_window_class_init (ContactsSetupWindowClass * klass) {
	contacts_setup_window_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (ContactsSetupWindowPrivate));
	GTK_WIDGET_CLASS (klass)->destroy = contacts_setup_window_real_destroy;
	GTK_WIDGET_CLASS (klass)->window_state_event = contacts_setup_window_real_window_state_event;
	G_OBJECT_CLASS (klass)->finalize = contacts_setup_window_finalize;
}


static void contacts_setup_window_instance_init (ContactsSetupWindow * self) {
	self->priv = CONTACTS_SETUP_WINDOW_GET_PRIVATE (self);
}


static void contacts_setup_window_finalize (GObject* obj) {
	ContactsSetupWindow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CONTACTS_TYPE_SETUP_WINDOW, ContactsSetupWindow);
	_g_object_unref0 (self->title_label);
	_g_object_unref0 (self->content_grid);
	_g_object_unref0 (self->priv->select_button);
	_g_object_unref0 (self->priv->list_store);
	_g_object_unref0 (self->priv->tree_view);
	G_OBJECT_CLASS (contacts_setup_window_parent_class)->finalize (obj);
}


GType contacts_setup_window_get_type (void) {
	static volatile gsize contacts_setup_window_type_id__volatile = 0;
	if (g_once_init_enter (&contacts_setup_window_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ContactsSetupWindowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) contacts_setup_window_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ContactsSetupWindow), 0, (GInstanceInitFunc) contacts_setup_window_instance_init, NULL };
		GType contacts_setup_window_type_id;
		contacts_setup_window_type_id = g_type_register_static (GTK_TYPE_WINDOW, "ContactsSetupWindow", &g_define_type_info, 0);
		g_once_init_leave (&contacts_setup_window_type_id__volatile, contacts_setup_window_type_id);
	}
	return contacts_setup_window_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);
}



