/* contacts-linked-personas-dialog.c generated by valac 0.56.3, the Vala compiler
 * generated from contacts-linked-personas-dialog.vala, do not modify */

/*
 * 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 <gtk/gtk.h>
#include <glib-object.h>
#include <glib.h>
#include <folks/folks.h>
#include "contacts.h"
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <adwaita.h>
#include <glib/gi18n-lib.h>

#define CONTACTS_LINKED_PERSONAS_DIALOG_AVATAR_SIZE 54
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define CONTACTS_TYPE_LINKED_PERSONAS_DIALOG (contacts_linked_personas_dialog_get_type ())
#define CONTACTS_LINKED_PERSONAS_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONTACTS_TYPE_LINKED_PERSONAS_DIALOG, ContactsLinkedPersonasDialog))
#define CONTACTS_LINKED_PERSONAS_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONTACTS_TYPE_LINKED_PERSONAS_DIALOG, ContactsLinkedPersonasDialogClass))
#define CONTACTS_IS_LINKED_PERSONAS_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONTACTS_TYPE_LINKED_PERSONAS_DIALOG))
#define CONTACTS_IS_LINKED_PERSONAS_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONTACTS_TYPE_LINKED_PERSONAS_DIALOG))
#define CONTACTS_LINKED_PERSONAS_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONTACTS_TYPE_LINKED_PERSONAS_DIALOG, ContactsLinkedPersonasDialogClass))

typedef struct _ContactsLinkedPersonasDialog ContactsLinkedPersonasDialog;
typedef struct _ContactsLinkedPersonasDialogClass ContactsLinkedPersonasDialogClass;
typedef struct _ContactsLinkedPersonasDialogPrivate ContactsLinkedPersonasDialogPrivate;
enum  {
	CONTACTS_LINKED_PERSONAS_DIALOG_0_PROPERTY,
	CONTACTS_LINKED_PERSONAS_DIALOG_NUM_PROPERTIES
};
static GParamSpec* contacts_linked_personas_dialog_properties[CONTACTS_LINKED_PERSONAS_DIALOG_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define CONTACTS_TYPE_AVATAR (contacts_avatar_get_type ())
#define CONTACTS_AVATAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONTACTS_TYPE_AVATAR, ContactsAvatar))
#define CONTACTS_AVATAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONTACTS_TYPE_AVATAR, ContactsAvatarClass))
#define CONTACTS_IS_AVATAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONTACTS_TYPE_AVATAR))
#define CONTACTS_IS_AVATAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONTACTS_TYPE_AVATAR))
#define CONTACTS_AVATAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONTACTS_TYPE_AVATAR, ContactsAvatarClass))

typedef struct _ContactsAvatar ContactsAvatar;
typedef struct _ContactsAvatarClass ContactsAvatarClass;
#define _g_free0(var) (var = (g_free (var), NULL))

struct _ContactsLinkedPersonasDialog {
	GtkDialog parent_instance;
	ContactsLinkedPersonasDialogPrivate * priv;
	gboolean any_unlinked;
};

struct _ContactsLinkedPersonasDialogClass {
	GtkDialogClass parent_class;
};

struct _ContactsLinkedPersonasDialogPrivate {
	GtkListBox* linked_accounts_view;
	FolksIndividual* individual;
};

static gint ContactsLinkedPersonasDialog_private_offset;
static gpointer contacts_linked_personas_dialog_parent_class = NULL;

VALA_EXTERN GType contacts_linked_personas_dialog_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ContactsLinkedPersonasDialog, g_object_unref)
VALA_EXTERN ContactsLinkedPersonasDialog* contacts_linked_personas_dialog_new (GtkWindow* main_win,
                                                                   ContactsStore* store,
                                                                   FolksIndividual* individual);
VALA_EXTERN ContactsLinkedPersonasDialog* contacts_linked_personas_dialog_construct (GType object_type,
                                                                         GtkWindow* main_win,
                                                                         ContactsStore* store,
                                                                         FolksIndividual* individual);
static void contacts_linked_personas_dialog_add_separator (ContactsLinkedPersonasDialog* self,
                                                    GtkListBoxRow* row,
                                                    GtkListBoxRow* before_row);
static void _contacts_linked_personas_dialog_add_separator_gtk_list_box_update_header_func (GtkListBoxRow* row,
                                                                                     GtkListBoxRow* before,
                                                                                     gpointer self);
static GtkWidget* contacts_linked_personas_dialog_create_row_for_persona (ContactsLinkedPersonasDialog* self,
                                                                   GObject* item);
static GtkWidget* _contacts_linked_personas_dialog_create_row_for_persona_gtk_list_box_create_widget_func (GObject* item,
                                                                                                    gpointer self);
VALA_EXTERN GType contacts_avatar_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ContactsAvatar, g_object_unref)
VALA_EXTERN ContactsAvatar* contacts_avatar_new (gint size,
                                     FolksIndividual* individual);
VALA_EXTERN ContactsAvatar* contacts_avatar_construct (GType object_type,
                                           gint size,
                                           FolksIndividual* individual);
static void __lambda55_ (ContactsLinkedPersonasDialog* self);
static void ___lambda55__gtk_button_clicked (GtkButton* _sender,
                                      gpointer self);
static void contacts_linked_personas_dialog_finalize (GObject * obj);
static GType contacts_linked_personas_dialog_get_type_once (void);

static inline gpointer
contacts_linked_personas_dialog_get_instance_private (ContactsLinkedPersonasDialog* self)
{
	return G_STRUCT_MEMBER_P (self, ContactsLinkedPersonasDialog_private_offset);
}

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

static void
_contacts_linked_personas_dialog_add_separator_gtk_list_box_update_header_func (GtkListBoxRow* row,
                                                                                GtkListBoxRow* before,
                                                                                gpointer self)
{
	contacts_linked_personas_dialog_add_separator ((ContactsLinkedPersonasDialog*) self, row, before);
}

static GtkWidget*
_contacts_linked_personas_dialog_create_row_for_persona_gtk_list_box_create_widget_func (GObject* item,
                                                                                         gpointer self)
{
	GtkWidget* result;
	result = contacts_linked_personas_dialog_create_row_for_persona ((ContactsLinkedPersonasDialog*) self, item);
	return result;
}

ContactsLinkedPersonasDialog*
contacts_linked_personas_dialog_construct (GType object_type,
                                           GtkWindow* main_win,
                                           ContactsStore* store,
                                           FolksIndividual* individual)
{
	ContactsLinkedPersonasDialog * self = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	FolksIndividual* _tmp2_;
	GtkListBox* _tmp3_;
	GListModel* personas = NULL;
	GListModel* _tmp4_;
	GtkFilterListModel* personas_filtered = NULL;
	GListModel* _tmp5_;
	ContactsPersonaFilter* _tmp6_;
	GtkFilterListModel* _tmp7_;
	GtkSortListModel* personas_sorted = NULL;
	GListModel* _tmp8_;
	ContactsPersonaSorter* _tmp9_;
	GtkSortListModel* _tmp10_;
	GtkListBox* _tmp11_;
	g_return_val_if_fail (main_win != NULL, NULL);
	g_return_val_if_fail (store != NULL, NULL);
	g_return_val_if_fail (individual != NULL, NULL);
	_tmp0_ = folks_individual_get_display_name (individual);
	_tmp1_ = _tmp0_;
	self = (ContactsLinkedPersonasDialog*) g_object_new (object_type, "use-header-bar", 1, "transient-for", main_win, "title", _tmp1_, NULL);
	_tmp2_ = _g_object_ref0 (individual);
	_g_object_unref0 (self->priv->individual);
	self->priv->individual = _tmp2_;
	_tmp3_ = self->priv->linked_accounts_view;
	gtk_list_box_set_header_func (_tmp3_, _contacts_linked_personas_dialog_add_separator_gtk_list_box_update_header_func, g_object_ref (self), g_object_unref);
	_tmp4_ = contacts_utils_personas_as_list_model (individual);
	personas = _tmp4_;
	_tmp5_ = _g_object_ref0 (personas);
	_tmp6_ = contacts_persona_filter_new ();
	_tmp7_ = gtk_filter_list_model_new (_tmp5_, (GtkFilter*) _tmp6_);
	personas_filtered = _tmp7_;
	_tmp8_ = _g_object_ref0 ((GListModel*) personas_filtered);
	_tmp9_ = contacts_persona_sorter_new ();
	_tmp10_ = gtk_sort_list_model_new (_tmp8_, (GtkSorter*) _tmp9_);
	personas_sorted = _tmp10_;
	_tmp11_ = self->priv->linked_accounts_view;
	gtk_list_box_bind_model (_tmp11_, (GListModel*) personas_sorted, _contacts_linked_personas_dialog_create_row_for_persona_gtk_list_box_create_widget_func, g_object_ref (self), g_object_unref);
	_g_object_unref0 (personas_sorted);
	_g_object_unref0 (personas_filtered);
	_g_object_unref0 (personas);
	return self;
}

ContactsLinkedPersonasDialog*
contacts_linked_personas_dialog_new (GtkWindow* main_win,
                                     ContactsStore* store,
                                     FolksIndividual* individual)
{
	return contacts_linked_personas_dialog_construct (CONTACTS_TYPE_LINKED_PERSONAS_DIALOG, main_win, store, individual);
}

static void
__lambda55_ (ContactsLinkedPersonasDialog* self)
{
}

static void
___lambda55__gtk_button_clicked (GtkButton* _sender,
                                 gpointer self)
{
	__lambda55_ ((ContactsLinkedPersonasDialog*) self);
}

static GtkWidget*
contacts_linked_personas_dialog_create_row_for_persona (ContactsLinkedPersonasDialog* self,
                                                        GObject* item)
{
	FolksPersona* persona = NULL;
	GtkGrid* row_grid = NULL;
	GtkGrid* _tmp0_;
	ContactsAvatar* image_frame = NULL;
	FolksIndividual* _tmp1_;
	ContactsAvatar* _tmp2_;
	GtkLabel* display_name = NULL;
	GtkLabel* _tmp3_;
	const gchar* _tmp4_;
	const gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	GtkLabel* store_name = NULL;
	gchar* _tmp8_;
	gchar* _tmp9_;
	GtkLabel* _tmp10_;
	GtkLabel* _tmp11_;
	GtkStyleContext* _tmp12_;
	GtkButton* button = NULL;
	GtkButton* _tmp13_;
	GtkWidget* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (item != NULL, NULL);
	persona = G_TYPE_CHECK_INSTANCE_CAST (item, FOLKS_TYPE_PERSONA, FolksPersona);
	_tmp0_ = (GtkGrid*) gtk_grid_new ();
	g_object_ref_sink (_tmp0_);
	row_grid = _tmp0_;
	_tmp1_ = self->priv->individual;
	_tmp2_ = contacts_avatar_new (CONTACTS_LINKED_PERSONAS_DIALOG_AVATAR_SIZE, _tmp1_);
	g_object_ref_sink (_tmp2_);
	image_frame = _tmp2_;
	gtk_widget_set_hexpand ((GtkWidget*) image_frame, FALSE);
	gtk_widget_set_margin_top ((GtkWidget*) image_frame, 6);
	gtk_widget_set_margin_bottom ((GtkWidget*) image_frame, 6);
	gtk_widget_set_margin_start ((GtkWidget*) image_frame, 6);
	gtk_widget_set_margin_end ((GtkWidget*) image_frame, 12);
	gtk_grid_attach (row_grid, (GtkWidget*) image_frame, 0, 0, 1, 2);
	_tmp3_ = (GtkLabel*) gtk_label_new ("");
	g_object_ref_sink (_tmp3_);
	display_name = _tmp3_;
	gtk_widget_set_halign ((GtkWidget*) display_name, GTK_ALIGN_START);
	gtk_widget_set_valign ((GtkWidget*) display_name, GTK_ALIGN_END);
	gtk_widget_set_hexpand ((GtkWidget*) display_name, TRUE);
	_tmp4_ = folks_persona_get_display_id (persona);
	_tmp5_ = _tmp4_;
	_tmp6_ = g_markup_printf_escaped ("<span font='bold'>%s</span>", _tmp5_);
	_tmp7_ = _tmp6_;
	gtk_label_set_markup (display_name, _tmp7_);
	_g_free0 (_tmp7_);
	gtk_grid_attach (row_grid, (GtkWidget*) display_name, 1, 0, 1, 1);
	_tmp8_ = contacts_utils_format_persona_store_name_for_contact (persona);
	_tmp9_ = _tmp8_;
	_tmp10_ = (GtkLabel*) gtk_label_new (_tmp9_);
	g_object_ref_sink (_tmp10_);
	_tmp11_ = _tmp10_;
	_g_free0 (_tmp9_);
	store_name = _tmp11_;
	gtk_widget_set_halign ((GtkWidget*) store_name, GTK_ALIGN_START);
	gtk_widget_set_valign ((GtkWidget*) store_name, GTK_ALIGN_START);
	gtk_widget_set_hexpand ((GtkWidget*) store_name, TRUE);
	_tmp12_ = gtk_widget_get_style_context ((GtkWidget*) store_name);
	gtk_style_context_add_class (_tmp12_, "dim-label");
	gtk_grid_attach (row_grid, (GtkWidget*) store_name, 1, 1, 1, 1);
	_tmp13_ = (GtkButton*) gtk_button_new_with_label (_ ("Unlink"));
	g_object_ref_sink (_tmp13_);
	button = _tmp13_;
	gtk_widget_set_margin_end ((GtkWidget*) button, 6);
	gtk_widget_set_valign ((GtkWidget*) button, GTK_ALIGN_CENTER);
	gtk_grid_attach (row_grid, (GtkWidget*) button, 2, 0, 1, 2);
	g_signal_connect_object (button, "clicked", (GCallback) ___lambda55__gtk_button_clicked, self, 0);
	result = (GtkWidget*) row_grid;
	_g_object_unref0 (button);
	_g_object_unref0 (store_name);
	_g_object_unref0 (display_name);
	_g_object_unref0 (image_frame);
	return result;
}

static void
contacts_linked_personas_dialog_add_separator (ContactsLinkedPersonasDialog* self,
                                               GtkListBoxRow* row,
                                               GtkListBoxRow* before_row)
{
	GtkSeparator* _tmp0_;
	GtkSeparator* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (row != NULL);
	_tmp0_ = (GtkSeparator*) gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
	g_object_ref_sink (_tmp0_);
	_tmp1_ = _tmp0_;
	gtk_list_box_row_set_header (row, (GtkWidget*) _tmp1_);
	_g_object_unref0 (_tmp1_);
}

static void
contacts_linked_personas_dialog_class_init (ContactsLinkedPersonasDialogClass * klass,
                                            gpointer klass_data)
{
	contacts_linked_personas_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ContactsLinkedPersonasDialog_private_offset);
	G_OBJECT_CLASS (klass)->finalize = contacts_linked_personas_dialog_finalize;
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/Contacts/ui/contacts-linked-personas-dialog.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "linked_accounts_view", FALSE, ContactsLinkedPersonasDialog_private_offset + G_STRUCT_OFFSET (ContactsLinkedPersonasDialogPrivate, linked_accounts_view));
}

static void
contacts_linked_personas_dialog_instance_init (ContactsLinkedPersonasDialog * self,
                                               gpointer klass)
{
	self->priv = contacts_linked_personas_dialog_get_instance_private (self);
	self->any_unlinked = FALSE;
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
contacts_linked_personas_dialog_finalize (GObject * obj)
{
	ContactsLinkedPersonasDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CONTACTS_TYPE_LINKED_PERSONAS_DIALOG, ContactsLinkedPersonasDialog);
	_g_object_unref0 (self->priv->individual);
	G_OBJECT_CLASS (contacts_linked_personas_dialog_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
contacts_linked_personas_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ContactsLinkedPersonasDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) contacts_linked_personas_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ContactsLinkedPersonasDialog), 0, (GInstanceInitFunc) contacts_linked_personas_dialog_instance_init, NULL };
	GType contacts_linked_personas_dialog_type_id;
	contacts_linked_personas_dialog_type_id = g_type_register_static (gtk_dialog_get_type (), "ContactsLinkedPersonasDialog", &g_define_type_info, 0);
	ContactsLinkedPersonasDialog_private_offset = g_type_add_instance_private (contacts_linked_personas_dialog_type_id, sizeof (ContactsLinkedPersonasDialogPrivate));
	return contacts_linked_personas_dialog_type_id;
}

GType
contacts_linked_personas_dialog_get_type (void)
{
	static volatile gsize contacts_linked_personas_dialog_type_id__once = 0;
	if (g_once_init_enter (&contacts_linked_personas_dialog_type_id__once)) {
		GType contacts_linked_personas_dialog_type_id;
		contacts_linked_personas_dialog_type_id = contacts_linked_personas_dialog_get_type_once ();
		g_once_init_leave (&contacts_linked_personas_dialog_type_id__once, contacts_linked_personas_dialog_type_id);
	}
	return contacts_linked_personas_dialog_type_id__once;
}

