/* contacts-setup-window.c generated by valac 0.21.2.6-90bab, 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 <libedataserver/libedataserver.h>
#include <contacts-esd-setup.h>
#include <gio/gio.h>
#include <glib/gi18n-lib.h>
#include <folks/folks-eds.h>
#include <folks/folks.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 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 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 _Block43Data Block43Data;
typedef struct _ContactsAccountsListPrivate ContactsAccountsListPrivate;

struct _ContactsSetupWindow {
	GtkWindow parent_instance;
	ContactsSetupWindowPrivate * priv;
	gboolean succeeded;
};

struct _ContactsSetupWindowClass {
	GtkWindowClass parent_class;
};

struct _ContactsSetupWindowPrivate {
	gulong source_list_changed_id;
	GtkButton* done_button;
};

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

struct _ContactsAppClass {
	GtkApplicationClass parent_class;
};

struct _Block43Data {
	int _ref_count_;
	ContactsSetupWindow * self;
	ContactsAccountsList* accounts_list;
};

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

struct _ContactsAccountsListClass {
	GtkGridClass 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
};
static void contacts_setup_window_select_source (ContactsSetupWindow* self, ESource* source);
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;
ContactsSetupWindow* contacts_setup_window_new (void);
ContactsSetupWindow* contacts_setup_window_construct (GType object_type);
GType contacts_accounts_list_get_type (void) G_GNUC_CONST;
static Block43Data* block43_data_ref (Block43Data* _data43_);
static void block43_data_unref (void * _userdata_);
static void __lambda129_ (ContactsSetupWindow* self, GtkButton* button);
static void ___lambda129__gtk_button_clicked (GtkButton* _sender, gpointer self);
ContactsAccountsList* contacts_accounts_list_new (void);
ContactsAccountsList* contacts_accounts_list_construct (GType object_type);
void contacts_accounts_list_update_contents (ContactsAccountsList* self, gboolean select_active);
static void __lambda130_ (Block43Data* _data43_);
static void ___lambda130__contacts_store_eds_persona_store_changed (ContactsStore* _sender, gpointer self);
static void __lambda131_ (ContactsSetupWindow* self);
static void ___lambda131__contacts_accounts_list_account_selected (ContactsAccountsList* _sender, gpointer self);
static void __lambda132_ (Block43Data* _data43_, GtkButton* button);
static void ___lambda132__gtk_button_clicked (GtkButton* _sender, gpointer self);
static void contacts_setup_window_real_destroy (GtkWidget* base);
static void contacts_setup_window_finalize (GObject* obj);


static void contacts_setup_window_select_source (ContactsSetupWindow* self, ESource* source) {
	ESourceRegistry* _tmp0_ = NULL;
	ESource* _tmp1_ = NULL;
	ContactsApp* _tmp2_ = NULL;
	GSettings* _tmp3_ = NULL;
	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 Block43Data* block43_data_ref (Block43Data* _data43_) {
	g_atomic_int_inc (&_data43_->_ref_count_);
	return _data43_;
}


static void block43_data_unref (void * _userdata_) {
	Block43Data* _data43_;
	_data43_ = (Block43Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data43_->_ref_count_)) {
		ContactsSetupWindow * self;
		self = _data43_->self;
		_g_object_unref0 (_data43_->accounts_list);
		_g_object_unref0 (self);
		g_slice_free (Block43Data, _data43_);
	}
}


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


static void ___lambda129__gtk_button_clicked (GtkButton* _sender, gpointer self) {
	__lambda129_ (self, _sender);
}


static void __lambda130_ (Block43Data* _data43_) {
	ContactsSetupWindow * self;
	self = _data43_->self;
	contacts_accounts_list_update_contents (_data43_->accounts_list, FALSE);
}


static void ___lambda130__contacts_store_eds_persona_store_changed (ContactsStore* _sender, gpointer self) {
	__lambda130_ (self);
}


static void __lambda131_ (ContactsSetupWindow* self) {
	GtkButton* _tmp0_ = NULL;
	_tmp0_ = self->priv->done_button;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp0_, TRUE);
}


static void ___lambda131__contacts_accounts_list_account_selected (ContactsAccountsList* _sender, gpointer self) {
	__lambda131_ (self);
}


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


static void __lambda132_ (Block43Data* _data43_, GtkButton* button) {
	ContactsSetupWindow * self;
	EdsfPersonaStore* e_store = NULL;
	FolksPersonaStore* _tmp0_ = NULL;
	EdsfPersonaStore* _tmp1_ = NULL;
	ESource* _tmp2_ = NULL;
	ESource* _tmp3_ = NULL;
	self = _data43_->self;
	g_return_if_fail (button != NULL);
	_tmp0_ = _data43_->accounts_list->selected_store;
	_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp0_, EDSF_TYPE_PERSONA_STORE) ? ((EdsfPersonaStore*) _tmp0_) : NULL);
	e_store = _tmp1_;
	_tmp2_ = edsf_persona_store_get_source (e_store);
	_tmp3_ = _tmp2_;
	contacts_setup_window_select_source (self, _tmp3_);
	_g_object_unref0 (e_store);
}


static void ___lambda132__gtk_button_clicked (GtkButton* _sender, gpointer self) {
	__lambda132_ (self, _sender);
}


ContactsSetupWindow* contacts_setup_window_construct (GType object_type) {
	ContactsSetupWindow * self = NULL;
	Block43Data* _data43_;
	GtkHeaderBar* titlebar = NULL;
	GtkHeaderBar* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	GtkButton* cancel_button = NULL;
	const gchar* _tmp2_ = NULL;
	GtkButton* _tmp3_ = NULL;
	GtkWidget* _tmp4_ = NULL;
	GtkWidget* _tmp5_ = NULL;
	GtkWidget* _tmp6_ = NULL;
	const gchar* _tmp7_ = NULL;
	GtkButton* _tmp8_ = NULL;
	GtkButton* _tmp9_ = NULL;
	GtkWidget* _tmp10_ = NULL;
	GtkButton* _tmp11_ = NULL;
	GtkWidget* _tmp12_ = NULL;
	GtkButton* _tmp13_ = NULL;
	GtkWidget* _tmp14_ = NULL;
	GtkButton* _tmp15_ = NULL;
	GtkButton* _tmp16_ = NULL;
	GtkGrid* grid = NULL;
	GtkGrid* _tmp17_ = NULL;
	GtkLabel* l = NULL;
	const gchar* _tmp18_ = NULL;
	GtkLabel* _tmp19_ = NULL;
	ContactsAccountsList* _tmp20_ = NULL;
	ContactsApp* _tmp21_ = NULL;
	ContactsStore* _tmp22_ = NULL;
	gulong _tmp23_ = 0UL;
	GtkButton* _tmp24_ = NULL;
	_data43_ = g_slice_new0 (Block43Data);
	_data43_->_ref_count_ = 1;
	self = (ContactsSetupWindow*) g_object_new (object_type, NULL);
	_data43_->self = g_object_ref (self);
	gtk_window_set_default_size ((GtkWindow*) self, 640, 480);
	_tmp0_ = (GtkHeaderBar*) gtk_header_bar_new ();
	g_object_ref_sink (_tmp0_);
	titlebar = _tmp0_;
	_tmp1_ = _ ("Contacts Setup");
	gtk_header_bar_set_title (titlebar, _tmp1_);
	gtk_window_set_titlebar ((GtkWindow*) self, (GtkWidget*) titlebar);
	_tmp2_ = _ ("Cancel");
	_tmp3_ = (GtkButton*) gtk_button_new_with_label (_tmp2_);
	g_object_ref_sink (_tmp3_);
	cancel_button = _tmp3_;
	_tmp4_ = gtk_bin_get_child ((GtkBin*) cancel_button);
	g_object_set (_tmp4_, "margin", 3, NULL);
	_tmp5_ = gtk_bin_get_child ((GtkBin*) cancel_button);
	gtk_widget_set_margin_left (_tmp5_, 6);
	_tmp6_ = gtk_bin_get_child ((GtkBin*) cancel_button);
	gtk_widget_set_margin_right (_tmp6_, 6);
	gtk_header_bar_pack_start (titlebar, (GtkWidget*) cancel_button);
	g_signal_connect_object (cancel_button, "clicked", (GCallback) ___lambda129__gtk_button_clicked, self, 0);
	gtk_widget_grab_focus ((GtkWidget*) cancel_button);
	_tmp7_ = _ ("Done");
	_tmp8_ = (GtkButton*) gtk_button_new_with_label (_tmp7_);
	g_object_ref_sink (_tmp8_);
	_g_object_unref0 (self->priv->done_button);
	self->priv->done_button = _tmp8_;
	_tmp9_ = self->priv->done_button;
	_tmp10_ = gtk_bin_get_child ((GtkBin*) _tmp9_);
	g_object_set (_tmp10_, "margin", 3, NULL);
	_tmp11_ = self->priv->done_button;
	_tmp12_ = gtk_bin_get_child ((GtkBin*) _tmp11_);
	gtk_widget_set_margin_left (_tmp12_, 6);
	_tmp13_ = self->priv->done_button;
	_tmp14_ = gtk_bin_get_child ((GtkBin*) _tmp13_);
	gtk_widget_set_margin_right (_tmp14_, 6);
	_tmp15_ = self->priv->done_button;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp15_, FALSE);
	_tmp16_ = self->priv->done_button;
	gtk_header_bar_pack_end (titlebar, (GtkWidget*) _tmp16_);
	gtk_widget_show_all ((GtkWidget*) titlebar);
	_tmp17_ = (GtkGrid*) gtk_grid_new ();
	g_object_ref_sink (_tmp17_);
	grid = _tmp17_;
	gtk_orientable_set_orientation ((GtkOrientable*) grid, GTK_ORIENTATION_VERTICAL);
	gtk_container_set_border_width ((GtkContainer*) grid, (guint) 24);
	gtk_grid_set_row_spacing (grid, (guint) 24);
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) grid);
	_tmp18_ = _ ("Please select your primary contacts account");
	_tmp19_ = (GtkLabel*) gtk_label_new (_tmp18_);
	g_object_ref_sink (_tmp19_);
	l = _tmp19_;
	gtk_widget_set_halign ((GtkWidget*) l, GTK_ALIGN_CENTER);
	gtk_container_add ((GtkContainer*) grid, (GtkWidget*) l);
	_tmp20_ = contacts_accounts_list_new ();
	g_object_ref_sink (_tmp20_);
	_data43_->accounts_list = _tmp20_;
	gtk_widget_set_hexpand ((GtkWidget*) _data43_->accounts_list, TRUE);
	gtk_widget_set_halign ((GtkWidget*) _data43_->accounts_list, GTK_ALIGN_CENTER);
	contacts_accounts_list_update_contents (_data43_->accounts_list, FALSE);
	gtk_container_add ((GtkContainer*) grid, (GtkWidget*) _data43_->accounts_list);
	_tmp21_ = contacts_app_app;
	_tmp22_ = _tmp21_->contacts_store;
	_tmp23_ = g_signal_connect_data (_tmp22_, "eds-persona-store-changed", (GCallback) ___lambda130__contacts_store_eds_persona_store_changed, block43_data_ref (_data43_), (GClosureNotify) block43_data_unref, 0);
	self->priv->source_list_changed_id = _tmp23_;
	g_signal_connect_object (_data43_->accounts_list, "account-selected", (GCallback) ___lambda131__contacts_accounts_list_account_selected, self, 0);
	_tmp24_ = self->priv->done_button;
	g_signal_connect_data (_tmp24_, "clicked", (GCallback) ___lambda132__gtk_button_clicked, block43_data_ref (_data43_), (GClosureNotify) block43_data_unref, 0);
	gtk_widget_show_all ((GtkWidget*) grid);
	_g_object_unref0 (l);
	_g_object_unref0 (grid);
	_g_object_unref0 (cancel_button);
	_g_object_unref0 (titlebar);
	block43_data_unref (_data43_);
	_data43_ = NULL;
	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_ = 0UL;
	self = (ContactsSetupWindow*) base;
	_tmp0_ = self->priv->source_list_changed_id;
	if (_tmp0_ != ((gulong) 0)) {
		ContactsApp* _tmp1_ = NULL;
		ContactsStore* _tmp2_ = NULL;
		gulong _tmp3_ = 0UL;
		_tmp1_ = contacts_app_app;
		_tmp2_ = _tmp1_->contacts_store;
		_tmp3_ = self->priv->source_list_changed_id;
		g_signal_handler_disconnect ((GObject*) _tmp2_, _tmp3_);
		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 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;
	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->priv->done_button);
	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;
}



