/* contacts-setup-window.c generated by valac 0.20.1.71-45f6, 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.h>
#include <folks/folks-eds.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 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;
#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;
typedef struct _Block44Data Block44Data;
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;
	ContactsAccountsList* accounts_list;
	GtkButton* done_button;
};

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

struct _ContactsAppClass {
	GtkApplicationClass parent_class;
};

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

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

struct _ContactsAccountsListClass {
	GtkFrameClass 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;
GType contacts_accounts_list_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);
static Block44Data* block44_data_ref (Block44Data* _data44_);
static void block44_data_unref (void * _userdata_);
static void __lambda126_ (ContactsSetupWindow* self, GtkButton* button);
static void ___lambda126__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 __lambda127_ (Block44Data* _data44_);
static void ___lambda127__e_source_registry_source_changed (ESourceRegistry* _sender, ESource* source, gpointer self);
static void __lambda128_ (ContactsSetupWindow* self);
static void ___lambda128__contacts_accounts_list_account_selected (ContactsAccountsList* _sender, gpointer self);
static void __lambda129_ (Block44Data* _data44_, GtkButton* button);
static void ___lambda129__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 Block44Data* block44_data_ref (Block44Data* _data44_) {
	g_atomic_int_inc (&_data44_->_ref_count_);
	return _data44_;
}


static void block44_data_unref (void * _userdata_) {
	Block44Data* _data44_;
	_data44_ = (Block44Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data44_->_ref_count_)) {
		ContactsSetupWindow * self;
		self = _data44_->self;
		_g_object_unref0 (_data44_->accounts_list);
		_g_object_unref0 (self);
		g_slice_free (Block44Data, _data44_);
	}
}


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


static void ___lambda126__gtk_button_clicked (GtkButton* _sender, gpointer self) {
	__lambda126_ (self, _sender);
}


static void __lambda127_ (Block44Data* _data44_) {
	ContactsSetupWindow * self;
	self = _data44_->self;
	contacts_accounts_list_update_contents (_data44_->accounts_list, FALSE);
}


static void ___lambda127__e_source_registry_source_changed (ESourceRegistry* _sender, ESource* source, gpointer self) {
	__lambda127_ (self);
}


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


static void ___lambda128__contacts_accounts_list_account_selected (ContactsAccountsList* _sender, gpointer self) {
	__lambda128_ (self);
}


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


static void __lambda129_ (Block44Data* _data44_, GtkButton* button) {
	ContactsSetupWindow * self;
	FolksPersonaStore* selected_store = NULL;
	EdsfPersonaStore* e_store = NULL;
	FolksPersonaStore* _tmp0_ = NULL;
	EdsfPersonaStore* _tmp1_ = NULL;
	ESource* _tmp2_ = NULL;
	ESource* _tmp3_ = NULL;
	self = _data44_->self;
	g_return_if_fail (button != NULL);
	_tmp0_ = _data44_->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);
	_g_object_unref0 (selected_store);
}


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


ContactsSetupWindow* contacts_setup_window_construct (GType object_type) {
	ContactsSetupWindow * self = NULL;
	Block44Data* _data44_;
	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;
	ESourceRegistry* _tmp21_ = NULL;
	gulong _tmp22_ = 0UL;
	GtkButton* _tmp23_ = NULL;
	_data44_ = g_slice_new0 (Block44Data);
	_data44_->_ref_count_ = 1;
	self = (ContactsSetupWindow*) g_object_new (object_type, NULL);
	_data44_->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) ___lambda126__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_);
	_data44_->accounts_list = _tmp20_;
	gtk_widget_set_halign ((GtkWidget*) _data44_->accounts_list, GTK_ALIGN_CENTER);
	contacts_accounts_list_update_contents (_data44_->accounts_list, FALSE);
	gtk_container_add ((GtkContainer*) grid, (GtkWidget*) _data44_->accounts_list);
	_tmp21_ = eds_source_registry;
	_tmp22_ = g_signal_connect_data (_tmp21_, "source-changed", (GCallback) ___lambda127__e_source_registry_source_changed, block44_data_ref (_data44_), (GClosureNotify) block44_data_unref, 0);
	self->priv->source_list_changed_id = _tmp22_;
	g_signal_connect_object (_data44_->accounts_list, "account-selected", (GCallback) ___lambda128__contacts_accounts_list_account_selected, self, 0);
	_tmp23_ = self->priv->done_button;
	g_signal_connect_data (_tmp23_, "clicked", (GCallback) ___lambda129__gtk_button_clicked, block44_data_ref (_data44_), (GClosureNotify) block44_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);
	block44_data_unref (_data44_);
	_data44_ = 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)) {
		ESourceRegistry* _tmp1_ = NULL;
		gulong _tmp2_ = 0UL;
		_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 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->accounts_list);
	_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;
}



