/* contacts-link-suggestion-grid.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from contacts-link-suggestion-grid.vala, do not modify */

/*
 * Copyright (C) 2011 Alexander Larsson <alexl@redhat.com>
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include <gtk/gtk.h>
#include <glib-object.h>
#include <adwaita.h>
#include <glib.h>
#include <folks/folks.h>
#include <stdlib.h>
#include <string.h>
#include "contacts.h"
#include <glib/gi18n-lib.h>
#include <gee.h>

#define CONTACTS_LINK_SUGGESTION_GRID_AVATAR_SIZE 54
#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#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_LINK_SUGGESTION_GRID (contacts_link_suggestion_grid_get_type ())
#define CONTACTS_LINK_SUGGESTION_GRID(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONTACTS_TYPE_LINK_SUGGESTION_GRID, ContactsLinkSuggestionGrid))
#define CONTACTS_LINK_SUGGESTION_GRID_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONTACTS_TYPE_LINK_SUGGESTION_GRID, ContactsLinkSuggestionGridClass))
#define CONTACTS_IS_LINK_SUGGESTION_GRID(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONTACTS_TYPE_LINK_SUGGESTION_GRID))
#define CONTACTS_IS_LINK_SUGGESTION_GRID_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONTACTS_TYPE_LINK_SUGGESTION_GRID))
#define CONTACTS_LINK_SUGGESTION_GRID_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONTACTS_TYPE_LINK_SUGGESTION_GRID, ContactsLinkSuggestionGridClass))

typedef struct _ContactsLinkSuggestionGrid ContactsLinkSuggestionGrid;
typedef struct _ContactsLinkSuggestionGridClass ContactsLinkSuggestionGridClass;
typedef struct _ContactsLinkSuggestionGridPrivate ContactsLinkSuggestionGridPrivate;
enum  {
	CONTACTS_LINK_SUGGESTION_GRID_0_PROPERTY,
	CONTACTS_LINK_SUGGESTION_GRID_NUM_PROPERTIES
};
static GParamSpec* contacts_link_suggestion_grid_properties[CONTACTS_LINK_SUGGESTION_GRID_NUM_PROPERTIES];

#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))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
enum  {
	CONTACTS_LINK_SUGGESTION_GRID_SUGGESTION_ACCEPTED_SIGNAL,
	CONTACTS_LINK_SUGGESTION_GRID_SUGGESTION_REJECTED_SIGNAL,
	CONTACTS_LINK_SUGGESTION_GRID_NUM_SIGNALS
};
static guint contacts_link_suggestion_grid_signals[CONTACTS_LINK_SUGGESTION_GRID_NUM_SIGNALS] = {0};

struct _ContactsLinkSuggestionGrid {
	GtkBox parent_instance;
	ContactsLinkSuggestionGridPrivate * priv;
};

struct _ContactsLinkSuggestionGridClass {
	GtkBoxClass parent_class;
};

struct _ContactsLinkSuggestionGridPrivate {
	GtkLabel* description_label;
	GtkLabel* extra_info_label;
	GtkButton* accept_button;
	GtkButton* reject_button;
	AdwBin* avatar_bin;
};

static gint ContactsLinkSuggestionGrid_private_offset;
static gpointer contacts_link_suggestion_grid_parent_class = NULL;

VALA_EXTERN GType contacts_link_suggestion_grid_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ContactsLinkSuggestionGrid, g_object_unref)
VALA_EXTERN ContactsLinkSuggestionGrid* contacts_link_suggestion_grid_new (FolksIndividual* individual);
VALA_EXTERN ContactsLinkSuggestionGrid* contacts_link_suggestion_grid_construct (GType object_type,
                                                                     FolksIndividual* individual);
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 gchar* contacts_link_suggestion_grid_find_extra_description (ContactsLinkSuggestionGrid* self,
                                                             FolksIndividual* individual);
static void __lambda33_ (ContactsLinkSuggestionGrid* self);
static void ___lambda33__gtk_button_clicked (GtkButton* _sender,
                                      gpointer self);
static void __lambda34_ (ContactsLinkSuggestionGrid* self);
static void ___lambda34__gtk_button_clicked (GtkButton* _sender,
                                      gpointer self);
static void contacts_link_suggestion_grid_finalize (GObject * obj);
static GType contacts_link_suggestion_grid_get_type_once (void);

static inline gpointer
contacts_link_suggestion_grid_get_instance_private (ContactsLinkSuggestionGrid* self)
{
	return G_STRUCT_MEMBER_P (self, ContactsLinkSuggestionGrid_private_offset);
}

static void
__lambda33_ (ContactsLinkSuggestionGrid* self)
{
	g_signal_emit (self, contacts_link_suggestion_grid_signals[CONTACTS_LINK_SUGGESTION_GRID_SUGGESTION_REJECTED_SIGNAL], 0);
}

static void
___lambda33__gtk_button_clicked (GtkButton* _sender,
                                 gpointer self)
{
	__lambda33_ ((ContactsLinkSuggestionGrid*) self);
}

static void
__lambda34_ (ContactsLinkSuggestionGrid* self)
{
	g_signal_emit (self, contacts_link_suggestion_grid_signals[CONTACTS_LINK_SUGGESTION_GRID_SUGGESTION_ACCEPTED_SIGNAL], 0);
}

static void
___lambda34__gtk_button_clicked (GtkButton* _sender,
                                 gpointer self)
{
	__lambda34_ ((ContactsLinkSuggestionGrid*) self);
}

ContactsLinkSuggestionGrid*
contacts_link_suggestion_grid_construct (GType object_type,
                                         FolksIndividual* individual)
{
	ContactsLinkSuggestionGrid * self = NULL;
	ContactsAvatar* image_frame = NULL;
	ContactsAvatar* _tmp0_;
	AdwBin* _tmp1_;
	ContactsAvatar* _tmp2_;
	gchar* _tmp3_ = NULL;
	GtkLabel* _tmp12_;
	gchar* extra_info = NULL;
	gchar* _tmp13_;
	const gchar* _tmp14_;
	GtkButton* _tmp17_;
	GtkButton* _tmp18_;
	g_return_val_if_fail (individual != NULL, NULL);
	self = (ContactsLinkSuggestionGrid*) g_object_new (object_type, NULL);
	_tmp0_ = contacts_avatar_new (CONTACTS_LINK_SUGGESTION_GRID_AVATAR_SIZE, individual);
	g_object_ref_sink (_tmp0_);
	image_frame = _tmp0_;
	_tmp1_ = self->priv->avatar_bin;
	_tmp2_ = image_frame;
	adw_bin_set_child (_tmp1_, (GtkWidget*) _tmp2_);
	if (contacts_utils_has_main_persona (individual)) {
		const gchar* _tmp4_;
		const gchar* _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		gchar* _tmp8_;
		_tmp4_ = folks_individual_get_display_name (individual);
		_tmp5_ = _tmp4_;
		_tmp6_ = contacts_utils_format_persona_stores (individual);
		_tmp7_ = _tmp6_;
		_tmp8_ = g_strdup_printf (_ ("Is this the same person as %s from %s?"), _tmp5_, _tmp7_);
		_g_free0 (_tmp3_);
		_tmp3_ = _tmp8_;
		_g_free0 (_tmp7_);
	} else {
		const gchar* _tmp9_;
		const gchar* _tmp10_;
		gchar* _tmp11_;
		_tmp9_ = folks_individual_get_display_name (individual);
		_tmp10_ = _tmp9_;
		_tmp11_ = g_strdup_printf (_ ("Is this the same person as %s?"), _tmp10_);
		_g_free0 (_tmp3_);
		_tmp3_ = _tmp11_;
	}
	_tmp12_ = self->priv->description_label;
	gtk_label_set_label (_tmp12_, _tmp3_);
	_tmp13_ = contacts_link_suggestion_grid_find_extra_description (self, individual);
	extra_info = _tmp13_;
	_tmp14_ = extra_info;
	if (_tmp14_ != NULL) {
		GtkLabel* _tmp15_;
		const gchar* _tmp16_;
		_tmp15_ = self->priv->extra_info_label;
		_tmp16_ = extra_info;
		gtk_label_set_label (_tmp15_, _tmp16_);
	}
	_tmp17_ = self->priv->reject_button;
	g_signal_connect_object (_tmp17_, "clicked", (GCallback) ___lambda33__gtk_button_clicked, self, 0);
	_tmp18_ = self->priv->accept_button;
	g_signal_connect_object (_tmp18_, "clicked", (GCallback) ___lambda34__gtk_button_clicked, self, 0);
	_g_free0 (extra_info);
	_g_free0 (_tmp3_);
	_g_object_unref0 (image_frame);
	return self;
}

ContactsLinkSuggestionGrid*
contacts_link_suggestion_grid_new (FolksIndividual* individual)
{
	return contacts_link_suggestion_grid_construct (CONTACTS_TYPE_LINK_SUGGESTION_GRID, individual);
}

static gchar*
contacts_link_suggestion_grid_find_extra_description (ContactsLinkSuggestionGrid* self,
                                                      FolksIndividual* individual)
{
	GeeSet* emails = NULL;
	GeeSet* _tmp0_;
	GeeSet* _tmp1_;
	GeeSet* _tmp2_;
	gboolean _tmp3_;
	gboolean _tmp4_;
	GeeSet* urls = NULL;
	GeeSet* _tmp12_;
	GeeSet* _tmp13_;
	GeeSet* _tmp14_;
	gboolean _tmp15_;
	gboolean _tmp16_;
	GeeSet* phones = NULL;
	GeeSet* _tmp24_;
	GeeSet* _tmp25_;
	GeeSet* _tmp26_;
	gboolean _tmp27_;
	gboolean _tmp28_;
	GeeSet* addresses = NULL;
	GeeSet* _tmp36_;
	GeeSet* _tmp37_;
	GeeSet* _tmp38_;
	gboolean _tmp39_;
	gboolean _tmp40_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (individual != NULL, NULL);
	_tmp0_ = folks_email_details_get_email_addresses ((FolksEmailDetails*) individual);
	_tmp1_ = _tmp0_;
	emails = _tmp1_;
	_tmp2_ = emails;
	_tmp3_ = gee_collection_get_is_empty ((GeeCollection*) _tmp2_);
	_tmp4_ = _tmp3_;
	if (!_tmp4_) {
		GeeSet* _tmp5_;
		gpointer _tmp6_;
		FolksEmailFieldDetails* _tmp7_;
		gconstpointer _tmp8_;
		gconstpointer _tmp9_;
		gchar* _tmp10_;
		gchar* _tmp11_;
		_tmp5_ = emails;
		_tmp6_ = contacts_utils_get_first (FOLKS_TYPE_EMAIL_FIELD_DETAILS, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, (GeeCollection*) _tmp5_);
		_tmp7_ = (FolksEmailFieldDetails*) _tmp6_;
		_tmp8_ = folks_abstract_field_details_get_value ((FolksAbstractFieldDetails*) _tmp7_);
		_tmp9_ = _tmp8_;
		_tmp10_ = g_strdup ((const gchar*) _tmp9_);
		_tmp11_ = _tmp10_;
		_g_object_unref0 (_tmp7_);
		result = _tmp11_;
		return result;
	}
	_tmp12_ = folks_url_details_get_urls ((FolksUrlDetails*) individual);
	_tmp13_ = _tmp12_;
	urls = _tmp13_;
	_tmp14_ = urls;
	_tmp15_ = gee_collection_get_is_empty ((GeeCollection*) _tmp14_);
	_tmp16_ = _tmp15_;
	if (!_tmp16_) {
		GeeSet* _tmp17_;
		gpointer _tmp18_;
		FolksUrlFieldDetails* _tmp19_;
		gconstpointer _tmp20_;
		gconstpointer _tmp21_;
		gchar* _tmp22_;
		gchar* _tmp23_;
		_tmp17_ = urls;
		_tmp18_ = contacts_utils_get_first (FOLKS_TYPE_URL_FIELD_DETAILS, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, (GeeCollection*) _tmp17_);
		_tmp19_ = (FolksUrlFieldDetails*) _tmp18_;
		_tmp20_ = folks_abstract_field_details_get_value ((FolksAbstractFieldDetails*) _tmp19_);
		_tmp21_ = _tmp20_;
		_tmp22_ = g_strdup ((const gchar*) _tmp21_);
		_tmp23_ = _tmp22_;
		_g_object_unref0 (_tmp19_);
		result = _tmp23_;
		return result;
	}
	_tmp24_ = folks_phone_details_get_phone_numbers ((FolksPhoneDetails*) individual);
	_tmp25_ = _tmp24_;
	phones = _tmp25_;
	_tmp26_ = phones;
	_tmp27_ = gee_collection_get_is_empty ((GeeCollection*) _tmp26_);
	_tmp28_ = _tmp27_;
	if (!_tmp28_) {
		GeeSet* _tmp29_;
		gpointer _tmp30_;
		FolksPhoneFieldDetails* _tmp31_;
		gconstpointer _tmp32_;
		gconstpointer _tmp33_;
		gchar* _tmp34_;
		gchar* _tmp35_;
		_tmp29_ = phones;
		_tmp30_ = contacts_utils_get_first (FOLKS_TYPE_PHONE_FIELD_DETAILS, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, (GeeCollection*) _tmp29_);
		_tmp31_ = (FolksPhoneFieldDetails*) _tmp30_;
		_tmp32_ = folks_abstract_field_details_get_value ((FolksAbstractFieldDetails*) _tmp31_);
		_tmp33_ = _tmp32_;
		_tmp34_ = g_strdup ((const gchar*) _tmp33_);
		_tmp35_ = _tmp34_;
		_g_object_unref0 (_tmp31_);
		result = _tmp35_;
		return result;
	}
	_tmp36_ = folks_postal_address_details_get_postal_addresses ((FolksPostalAddressDetails*) individual);
	_tmp37_ = _tmp36_;
	addresses = _tmp37_;
	_tmp38_ = addresses;
	_tmp39_ = gee_collection_get_is_empty ((GeeCollection*) _tmp38_);
	_tmp40_ = _tmp39_;
	if (!_tmp40_) {
		GeeSet* _tmp41_;
		gpointer _tmp42_;
		FolksPostalAddressFieldDetails* _tmp43_;
		gconstpointer _tmp44_;
		gconstpointer _tmp45_;
		gchar* _tmp46_;
		gchar* _tmp47_;
		_tmp41_ = addresses;
		_tmp42_ = contacts_utils_get_first (FOLKS_TYPE_POSTAL_ADDRESS_FIELD_DETAILS, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, (GeeCollection*) _tmp41_);
		_tmp43_ = (FolksPostalAddressFieldDetails*) _tmp42_;
		_tmp44_ = folks_abstract_field_details_get_value ((FolksAbstractFieldDetails*) _tmp43_);
		_tmp45_ = _tmp44_;
		_tmp46_ = folks_postal_address_to_string ((FolksPostalAddress*) _tmp45_);
		_tmp47_ = _tmp46_;
		_g_object_unref0 (_tmp43_);
		result = _tmp47_;
		return result;
	}
	result = NULL;
	return result;
}

static void
contacts_link_suggestion_grid_class_init (ContactsLinkSuggestionGridClass * klass,
                                          gpointer klass_data)
{
	contacts_link_suggestion_grid_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ContactsLinkSuggestionGrid_private_offset);
	G_OBJECT_CLASS (klass)->finalize = contacts_link_suggestion_grid_finalize;
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/Contacts/ui/contacts-link-suggestion-grid.ui");
	contacts_link_suggestion_grid_signals[CONTACTS_LINK_SUGGESTION_GRID_SUGGESTION_ACCEPTED_SIGNAL] = g_signal_new ("suggestion-accepted", CONTACTS_TYPE_LINK_SUGGESTION_GRID, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	contacts_link_suggestion_grid_signals[CONTACTS_LINK_SUGGESTION_GRID_SUGGESTION_REJECTED_SIGNAL] = g_signal_new ("suggestion-rejected", CONTACTS_TYPE_LINK_SUGGESTION_GRID, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "description_label", FALSE, ContactsLinkSuggestionGrid_private_offset + G_STRUCT_OFFSET (ContactsLinkSuggestionGridPrivate, description_label));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "extra_info_label", FALSE, ContactsLinkSuggestionGrid_private_offset + G_STRUCT_OFFSET (ContactsLinkSuggestionGridPrivate, extra_info_label));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "accept_button", FALSE, ContactsLinkSuggestionGrid_private_offset + G_STRUCT_OFFSET (ContactsLinkSuggestionGridPrivate, accept_button));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "reject_button", FALSE, ContactsLinkSuggestionGrid_private_offset + G_STRUCT_OFFSET (ContactsLinkSuggestionGridPrivate, reject_button));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "avatar_bin", FALSE, ContactsLinkSuggestionGrid_private_offset + G_STRUCT_OFFSET (ContactsLinkSuggestionGridPrivate, avatar_bin));
}

static void
contacts_link_suggestion_grid_instance_init (ContactsLinkSuggestionGrid * self,
                                             gpointer klass)
{
	self->priv = contacts_link_suggestion_grid_get_instance_private (self);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
contacts_link_suggestion_grid_finalize (GObject * obj)
{
	ContactsLinkSuggestionGrid * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CONTACTS_TYPE_LINK_SUGGESTION_GRID, ContactsLinkSuggestionGrid);
	G_OBJECT_CLASS (contacts_link_suggestion_grid_parent_class)->finalize (obj);
}

/**
 * The LinkSuggestionGrid is show at the bottom of the ContactPane.
 * It offers the user the sugugestion of linking the currently shown contact
 * and another (hopefully) similar contact.
 */
 G_GNUC_NO_INLINE static GType
contacts_link_suggestion_grid_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ContactsLinkSuggestionGridClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) contacts_link_suggestion_grid_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ContactsLinkSuggestionGrid), 0, (GInstanceInitFunc) contacts_link_suggestion_grid_instance_init, NULL };
	GType contacts_link_suggestion_grid_type_id;
	contacts_link_suggestion_grid_type_id = g_type_register_static (gtk_box_get_type (), "ContactsLinkSuggestionGrid", &g_define_type_info, 0);
	ContactsLinkSuggestionGrid_private_offset = g_type_add_instance_private (contacts_link_suggestion_grid_type_id, sizeof (ContactsLinkSuggestionGridPrivate));
	return contacts_link_suggestion_grid_type_id;
}

GType
contacts_link_suggestion_grid_get_type (void)
{
	static volatile gsize contacts_link_suggestion_grid_type_id__once = 0;
	if (g_once_init_enter (&contacts_link_suggestion_grid_type_id__once)) {
		GType contacts_link_suggestion_grid_type_id;
		contacts_link_suggestion_grid_type_id = contacts_link_suggestion_grid_get_type_once ();
		g_once_init_leave (&contacts_link_suggestion_grid_type_id__once, contacts_link_suggestion_grid_type_id);
	}
	return contacts_link_suggestion_grid_type_id__once;
}

