/* contacts-contact-sheet-row.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from contacts-contact-sheet-row.vala, do not modify */

/*
 * Copyright (C) 2024 Niels De Graef <nielsdegraef@gmail.com>
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include <adwaita.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include "contactscore.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>

#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_CONTACT_SHEET_ROW (contacts_contact_sheet_row_get_type ())
#define CONTACTS_CONTACT_SHEET_ROW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONTACTS_TYPE_CONTACT_SHEET_ROW, ContactsContactSheetRow))
#define CONTACTS_CONTACT_SHEET_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONTACTS_TYPE_CONTACT_SHEET_ROW, ContactsContactSheetRowClass))
#define CONTACTS_IS_CONTACT_SHEET_ROW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONTACTS_TYPE_CONTACT_SHEET_ROW))
#define CONTACTS_IS_CONTACT_SHEET_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONTACTS_TYPE_CONTACT_SHEET_ROW))
#define CONTACTS_CONTACT_SHEET_ROW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONTACTS_TYPE_CONTACT_SHEET_ROW, ContactsContactSheetRowClass))

typedef struct _ContactsContactSheetRow ContactsContactSheetRow;
typedef struct _ContactsContactSheetRowClass ContactsContactSheetRowClass;
typedef struct _ContactsContactSheetRowPrivate ContactsContactSheetRowPrivate;
enum  {
	CONTACTS_CONTACT_SHEET_ROW_0_PROPERTY,
	CONTACTS_CONTACT_SHEET_ROW_NUM_PROPERTIES
};
static GParamSpec* contacts_contact_sheet_row_properties[CONTACTS_CONTACT_SHEET_ROW_NUM_PROPERTIES];

struct _ContactsContactSheetRow {
	AdwPreferencesRow parent_instance;
	ContactsContactSheetRowPrivate * priv;
};

struct _ContactsContactSheetRowClass {
	AdwPreferencesRowClass parent_class;
};

struct _ContactsContactSheetRowPrivate {
	GtkImage* image;
	GtkLabel* title;
	GtkLabel* subtitle;
	GtkBox* suffixes;
};

static gint ContactsContactSheetRow_private_offset;
static gpointer contacts_contact_sheet_row_parent_class = NULL;

VALA_EXTERN GType contacts_contact_sheet_row_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ContactsContactSheetRow, g_object_unref)
VALA_EXTERN ContactsContactSheetRow* contacts_contact_sheet_row_new (ContactsChunk* chunk,
                                                         const gchar* title,
                                                         const gchar* subtitle);
VALA_EXTERN ContactsContactSheetRow* contacts_contact_sheet_row_construct (GType object_type,
                                                               ContactsChunk* chunk,
                                                               const gchar* title,
                                                               const gchar* subtitle);
VALA_EXTERN void contacts_contact_sheet_row_set_title_direction (ContactsContactSheetRow* self,
                                                     GtkTextDirection direction);
VALA_EXTERN GtkButton* contacts_contact_sheet_row_add_button (ContactsContactSheetRow* self,
                                                  const gchar* icon);
static void contacts_contact_sheet_row_finalize (GObject * obj);
static GType contacts_contact_sheet_row_get_type_once (void);

static inline gpointer
contacts_contact_sheet_row_get_instance_private (ContactsContactSheetRow* self)
{
	return G_STRUCT_MEMBER_P (self, ContactsContactSheetRow_private_offset);
}

ContactsContactSheetRow*
contacts_contact_sheet_row_construct (GType object_type,
                                      ContactsChunk* chunk,
                                      const gchar* title,
                                      const gchar* subtitle)
{
	ContactsContactSheetRow * self = NULL;
	const gchar* icon_name = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	GtkLabel* _tmp8_;
	g_return_val_if_fail (chunk != NULL, NULL);
	g_return_val_if_fail (title != NULL, NULL);
	self = (ContactsContactSheetRow*) g_object_new (object_type, NULL);
	_tmp0_ = contacts_chunk_get_icon_name (chunk);
	_tmp1_ = _tmp0_;
	icon_name = _tmp1_;
	_tmp2_ = icon_name;
	if (_tmp2_ != NULL) {
		GtkImage* _tmp3_;
		const gchar* _tmp4_;
		GtkImage* _tmp5_;
		const gchar* _tmp6_;
		const gchar* _tmp7_;
		_tmp3_ = self->priv->image;
		_tmp4_ = icon_name;
		g_object_set (_tmp3_, "icon-name", _tmp4_, NULL);
		_tmp5_ = self->priv->image;
		_tmp6_ = contacts_chunk_get_display_name (chunk);
		_tmp7_ = _tmp6_;
		gtk_widget_set_tooltip_text ((GtkWidget*) _tmp5_, _tmp7_);
	}
	_tmp8_ = self->priv->title;
	gtk_label_set_label (_tmp8_, title);
	if (subtitle != NULL) {
		GtkLabel* _tmp9_;
		_tmp9_ = self->priv->subtitle;
		gtk_label_set_label (_tmp9_, subtitle);
	}
	return self;
}

ContactsContactSheetRow*
contacts_contact_sheet_row_new (ContactsChunk* chunk,
                                const gchar* title,
                                const gchar* subtitle)
{
	return contacts_contact_sheet_row_construct (CONTACTS_TYPE_CONTACT_SHEET_ROW, chunk, title, subtitle);
}

void
contacts_contact_sheet_row_set_title_direction (ContactsContactSheetRow* self,
                                                GtkTextDirection direction)
{
	GtkLabel* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->title;
	gtk_widget_set_direction ((GtkWidget*) _tmp0_, direction);
	if (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL) {
		GtkLabel* _tmp1_;
		_tmp1_ = self->priv->title;
		gtk_label_set_xalign (_tmp1_, 1.0f);
	}
}

GtkButton*
contacts_contact_sheet_row_add_button (ContactsContactSheetRow* self,
                                       const gchar* icon)
{
	GtkButton* button = NULL;
	GtkButton* _tmp0_;
	GtkBox* _tmp1_;
	GtkBox* _tmp2_;
	GtkButton* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (icon != NULL, NULL);
	_tmp0_ = (GtkButton*) gtk_button_new_from_icon_name (icon);
	g_object_ref_sink (_tmp0_);
	button = _tmp0_;
	gtk_widget_set_valign ((GtkWidget*) button, GTK_ALIGN_CENTER);
	gtk_widget_add_css_class ((GtkWidget*) button, "flat");
	_tmp1_ = self->priv->suffixes;
	gtk_box_append (_tmp1_, (GtkWidget*) button);
	_tmp2_ = self->priv->suffixes;
	gtk_widget_set_visible ((GtkWidget*) _tmp2_, TRUE);
	result = button;
	return result;
}

static void
contacts_contact_sheet_row_class_init (ContactsContactSheetRowClass * klass,
                                       gpointer klass_data)
{
	contacts_contact_sheet_row_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ContactsContactSheetRow_private_offset);
	G_OBJECT_CLASS (klass)->finalize = contacts_contact_sheet_row_finalize;
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/Contacts/ui/contacts-contact-sheet-row.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "image", FALSE, ContactsContactSheetRow_private_offset + G_STRUCT_OFFSET (ContactsContactSheetRowPrivate, image));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "title", FALSE, ContactsContactSheetRow_private_offset + G_STRUCT_OFFSET (ContactsContactSheetRowPrivate, title));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "subtitle", FALSE, ContactsContactSheetRow_private_offset + G_STRUCT_OFFSET (ContactsContactSheetRowPrivate, subtitle));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "suffixes", FALSE, ContactsContactSheetRow_private_offset + G_STRUCT_OFFSET (ContactsContactSheetRowPrivate, suffixes));
}

static void
contacts_contact_sheet_row_instance_init (ContactsContactSheetRow * self,
                                          gpointer klass)
{
	self->priv = contacts_contact_sheet_row_get_instance_private (self);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
contacts_contact_sheet_row_finalize (GObject * obj)
{
	ContactsContactSheetRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CONTACTS_TYPE_CONTACT_SHEET_ROW, ContactsContactSheetRow);
	G_OBJECT_CLASS (contacts_contact_sheet_row_parent_class)->finalize (obj);
}

/**
 * ContactSheetRow is a custom Gtk.ListBoxRow for displaying a field in the
 * ContactSheet widget, similar to when one would use an Adw.ActionRow (or
 * generally a Adw.PreferencesRow).
 */
 G_GNUC_NO_INLINE static GType
contacts_contact_sheet_row_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ContactsContactSheetRowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) contacts_contact_sheet_row_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ContactsContactSheetRow), 0, (GInstanceInitFunc) contacts_contact_sheet_row_instance_init, NULL };
	GType contacts_contact_sheet_row_type_id;
	contacts_contact_sheet_row_type_id = g_type_register_static (adw_preferences_row_get_type (), "ContactsContactSheetRow", &g_define_type_info, 0);
	ContactsContactSheetRow_private_offset = g_type_add_instance_private (contacts_contact_sheet_row_type_id, sizeof (ContactsContactSheetRowPrivate));
	return contacts_contact_sheet_row_type_id;
}

GType
contacts_contact_sheet_row_get_type (void)
{
	static volatile gsize contacts_contact_sheet_row_type_id__once = 0;
	if (g_once_init_enter (&contacts_contact_sheet_row_type_id__once)) {
		GType contacts_contact_sheet_row_type_id;
		contacts_contact_sheet_row_type_id = contacts_contact_sheet_row_get_type_once ();
		g_once_init_leave (&contacts_contact_sheet_row_type_id__once, contacts_contact_sheet_row_type_id);
	}
	return contacts_contact_sheet_row_type_id__once;
}

