/* contacts-linked-personas-dialog.c generated by valac 0.56.0, 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_add_separator_gtk_list_box_update_header_func (GtkListBoxRow* row,
                                                              GtkListBoxRow* before,
                                                              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 _____lambda72_ (ContactsLinkedPersonasDialog* self);
static void ______lambda72__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_add_separator_gtk_list_box_update_header_func (GtkListBoxRow* row,
                                                         GtkListBoxRow* before,
                                                         gpointer self)
{
	contacts_add_separator (row, before);
}

static void
_____lambda72_ (ContactsLinkedPersonasDialog* self)
{
}

static void
______lambda72__gtk_button_clicked (GtkButton* _sender,
                                    gpointer self)
{
	_____lambda72_ ((ContactsLinkedPersonasDialog*) self);
}

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_;
	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_add_separator_gtk_list_box_update_header_func, NULL, NULL);
	_tmp4_ = contacts_utils_get_personas_for_display (individual);
	personas = _tmp4_;
	{
		gint i = 0;
		i = 1;
		{
			gboolean _tmp5_ = FALSE;
			_tmp5_ = TRUE;
			while (TRUE) {
				GListModel* _tmp7_;
				FolksPersona* p = NULL;
				GListModel* _tmp8_;
				GObject* _tmp9_;
				GtkGrid* row_grid = NULL;
				GtkGrid* _tmp10_;
				ContactsAvatar* image_frame = NULL;
				ContactsAvatar* _tmp11_;
				ContactsAvatar* _tmp12_;
				ContactsAvatar* _tmp13_;
				ContactsAvatar* _tmp14_;
				ContactsAvatar* _tmp15_;
				ContactsAvatar* _tmp16_;
				GtkGrid* _tmp17_;
				ContactsAvatar* _tmp18_;
				GtkLabel* display_name = NULL;
				GtkLabel* _tmp19_;
				GtkLabel* _tmp20_;
				GtkLabel* _tmp21_;
				GtkLabel* _tmp22_;
				GtkLabel* _tmp23_;
				FolksPersona* _tmp24_;
				const gchar* _tmp25_;
				const gchar* _tmp26_;
				gchar* _tmp27_;
				gchar* _tmp28_;
				GtkGrid* _tmp29_;
				GtkLabel* _tmp30_;
				GtkLabel* store_name = NULL;
				FolksPersona* _tmp31_;
				gchar* _tmp32_;
				gchar* _tmp33_;
				GtkLabel* _tmp34_;
				GtkLabel* _tmp35_;
				GtkLabel* _tmp36_;
				GtkLabel* _tmp37_;
				GtkLabel* _tmp38_;
				GtkLabel* _tmp39_;
				GtkStyleContext* _tmp40_;
				GtkGrid* _tmp41_;
				GtkLabel* _tmp42_;
				GtkButton* button = NULL;
				GtkButton* _tmp43_;
				GtkButton* _tmp44_;
				GtkButton* _tmp45_;
				GtkGrid* _tmp46_;
				GtkButton* _tmp47_;
				GtkButton* _tmp48_;
				GtkListBox* _tmp49_;
				GtkGrid* _tmp50_;
				if (!_tmp5_) {
					gint _tmp6_;
					_tmp6_ = i;
					i = _tmp6_ + 1;
				}
				_tmp5_ = FALSE;
				_tmp7_ = personas;
				if (!(((guint) i) < g_list_model_get_n_items (_tmp7_))) {
					break;
				}
				_tmp8_ = personas;
				_tmp9_ = g_list_model_get_item (_tmp8_, (guint) i);
				p = G_TYPE_CHECK_INSTANCE_CAST (_tmp9_, FOLKS_TYPE_PERSONA, FolksPersona);
				_tmp10_ = (GtkGrid*) gtk_grid_new ();
				g_object_ref_sink (_tmp10_);
				row_grid = _tmp10_;
				_tmp11_ = contacts_avatar_new (CONTACTS_LINKED_PERSONAS_DIALOG_AVATAR_SIZE, individual);
				g_object_ref_sink (_tmp11_);
				image_frame = _tmp11_;
				_tmp12_ = image_frame;
				gtk_widget_set_hexpand ((GtkWidget*) _tmp12_, FALSE);
				_tmp13_ = image_frame;
				gtk_widget_set_margin_top ((GtkWidget*) _tmp13_, 6);
				_tmp14_ = image_frame;
				gtk_widget_set_margin_bottom ((GtkWidget*) _tmp14_, 6);
				_tmp15_ = image_frame;
				gtk_widget_set_margin_start ((GtkWidget*) _tmp15_, 6);
				_tmp16_ = image_frame;
				gtk_widget_set_margin_end ((GtkWidget*) _tmp16_, 12);
				_tmp17_ = row_grid;
				_tmp18_ = image_frame;
				gtk_grid_attach (_tmp17_, (GtkWidget*) _tmp18_, 0, 0, 1, 2);
				_tmp19_ = (GtkLabel*) gtk_label_new ("");
				g_object_ref_sink (_tmp19_);
				display_name = _tmp19_;
				_tmp20_ = display_name;
				gtk_widget_set_halign ((GtkWidget*) _tmp20_, GTK_ALIGN_START);
				_tmp21_ = display_name;
				gtk_widget_set_valign ((GtkWidget*) _tmp21_, GTK_ALIGN_END);
				_tmp22_ = display_name;
				gtk_widget_set_hexpand ((GtkWidget*) _tmp22_, TRUE);
				_tmp23_ = display_name;
				_tmp24_ = p;
				_tmp25_ = folks_persona_get_display_id (_tmp24_);
				_tmp26_ = _tmp25_;
				_tmp27_ = g_markup_printf_escaped ("<span font='bold'>%s</span>", _tmp26_);
				_tmp28_ = _tmp27_;
				gtk_label_set_markup (_tmp23_, _tmp28_);
				_g_free0 (_tmp28_);
				_tmp29_ = row_grid;
				_tmp30_ = display_name;
				gtk_grid_attach (_tmp29_, (GtkWidget*) _tmp30_, 1, 0, 1, 1);
				_tmp31_ = p;
				_tmp32_ = contacts_utils_format_persona_store_name_for_contact (_tmp31_);
				_tmp33_ = _tmp32_;
				_tmp34_ = (GtkLabel*) gtk_label_new (_tmp33_);
				g_object_ref_sink (_tmp34_);
				_tmp35_ = _tmp34_;
				_g_free0 (_tmp33_);
				store_name = _tmp35_;
				_tmp36_ = store_name;
				gtk_widget_set_halign ((GtkWidget*) _tmp36_, GTK_ALIGN_START);
				_tmp37_ = store_name;
				gtk_widget_set_valign ((GtkWidget*) _tmp37_, GTK_ALIGN_START);
				_tmp38_ = store_name;
				gtk_widget_set_hexpand ((GtkWidget*) _tmp38_, TRUE);
				_tmp39_ = store_name;
				_tmp40_ = gtk_widget_get_style_context ((GtkWidget*) _tmp39_);
				gtk_style_context_add_class (_tmp40_, "dim-label");
				_tmp41_ = row_grid;
				_tmp42_ = store_name;
				gtk_grid_attach (_tmp41_, (GtkWidget*) _tmp42_, 1, 1, 1, 1);
				_tmp43_ = (GtkButton*) gtk_button_new_with_label (_ ("Unlink"));
				g_object_ref_sink (_tmp43_);
				button = _tmp43_;
				_tmp44_ = button;
				gtk_widget_set_margin_end ((GtkWidget*) _tmp44_, 6);
				_tmp45_ = button;
				gtk_widget_set_valign ((GtkWidget*) _tmp45_, GTK_ALIGN_CENTER);
				_tmp46_ = row_grid;
				_tmp47_ = button;
				gtk_grid_attach (_tmp46_, (GtkWidget*) _tmp47_, 2, 0, 1, 2);
				_tmp48_ = button;
				g_signal_connect_object (_tmp48_, "clicked", (GCallback) ______lambda72__gtk_button_clicked, self, 0);
				_tmp49_ = self->priv->linked_accounts_view;
				_tmp50_ = row_grid;
				gtk_list_box_append (_tmp49_, (GtkWidget*) _tmp50_);
				_g_object_unref0 (button);
				_g_object_unref0 (store_name);
				_g_object_unref0 (display_name);
				_g_object_unref0 (image_frame);
				_g_object_unref0 (row_grid);
				_g_object_unref0 (p);
			}
		}
	}
	_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
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;
}

