/* contacts-editor-persona.c generated by valac 0.56.0, the Vala compiler
 * generated from contacts-editor-persona.vala, do not modify */

/*
 * Copyright (C) 2019 Purism SPC
 * Author: Julian Sparber <julian.sparber@puri.sm>
 * Copyright (C) 2021 Niels De Graef <nielsdegraef@gmail.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 <folks/folks.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>
#include <adwaita.h>
#include <glib/gi18n-lib.h>
#include "contacts.h"

#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_EDITOR_PERSONA (contacts_editor_persona_get_type ())
#define CONTACTS_EDITOR_PERSONA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONTACTS_TYPE_EDITOR_PERSONA, ContactsEditorPersona))
#define CONTACTS_EDITOR_PERSONA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONTACTS_TYPE_EDITOR_PERSONA, ContactsEditorPersonaClass))
#define CONTACTS_IS_EDITOR_PERSONA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONTACTS_TYPE_EDITOR_PERSONA))
#define CONTACTS_IS_EDITOR_PERSONA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONTACTS_TYPE_EDITOR_PERSONA))
#define CONTACTS_EDITOR_PERSONA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONTACTS_TYPE_EDITOR_PERSONA, ContactsEditorPersonaClass))

typedef struct _ContactsEditorPersona ContactsEditorPersona;
typedef struct _ContactsEditorPersonaClass ContactsEditorPersonaClass;
typedef struct _ContactsEditorPersonaPrivate ContactsEditorPersonaPrivate;
enum  {
	CONTACTS_EDITOR_PERSONA_0_PROPERTY,
	CONTACTS_EDITOR_PERSONA_NUM_PROPERTIES
};
static GParamSpec* contacts_editor_persona_properties[CONTACTS_EDITOR_PERSONA_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block21Data Block21Data;

#define CONTACTS_TYPE_EDITOR_PROPERTY (contacts_editor_property_get_type ())
#define CONTACTS_EDITOR_PROPERTY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONTACTS_TYPE_EDITOR_PROPERTY, ContactsEditorProperty))
#define CONTACTS_EDITOR_PROPERTY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONTACTS_TYPE_EDITOR_PROPERTY, ContactsEditorPropertyClass))
#define CONTACTS_IS_EDITOR_PROPERTY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONTACTS_TYPE_EDITOR_PROPERTY))
#define CONTACTS_IS_EDITOR_PROPERTY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONTACTS_TYPE_EDITOR_PROPERTY))
#define CONTACTS_EDITOR_PROPERTY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONTACTS_TYPE_EDITOR_PROPERTY, ContactsEditorPropertyClass))

typedef struct _ContactsEditorProperty ContactsEditorProperty;
typedef struct _ContactsEditorPropertyClass ContactsEditorPropertyClass;

#define CONTACTS_TYPE_EDITOR_PROPERTY_ROW (contacts_editor_property_row_get_type ())
#define CONTACTS_EDITOR_PROPERTY_ROW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONTACTS_TYPE_EDITOR_PROPERTY_ROW, ContactsEditorPropertyRow))
#define CONTACTS_EDITOR_PROPERTY_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONTACTS_TYPE_EDITOR_PROPERTY_ROW, ContactsEditorPropertyRowClass))
#define CONTACTS_IS_EDITOR_PROPERTY_ROW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONTACTS_TYPE_EDITOR_PROPERTY_ROW))
#define CONTACTS_IS_EDITOR_PROPERTY_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONTACTS_TYPE_EDITOR_PROPERTY_ROW))
#define CONTACTS_EDITOR_PROPERTY_ROW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONTACTS_TYPE_EDITOR_PROPERTY_ROW, ContactsEditorPropertyRowClass))

typedef struct _ContactsEditorPropertyRow ContactsEditorPropertyRow;
typedef struct _ContactsEditorPropertyRowClass ContactsEditorPropertyRowClass;
typedef struct _Block22Data Block22Data;
#define _g_free0(var) (var = (g_free (var), NULL))

struct _ContactsEditorPersona {
	GtkBox parent_instance;
	ContactsEditorPersonaPrivate * priv;
};

struct _ContactsEditorPersonaClass {
	GtkBoxClass parent_class;
};

struct _ContactsEditorPersonaPrivate {
	FolksPersona* persona;
	GtkBox* header;
	GtkBox* content;
	FolksIndividualAggregator* aggregator;
};

struct _Block21Data {
	int _ref_count_;
	ContactsEditorPersona* self;
	GtkButton* show_more_button;
	FolksPersona* persona;
};

struct _Block22Data {
	int _ref_count_;
	ContactsEditorPersona* self;
	ContactsEditorPropertyRow* row;
};

static gint ContactsEditorPersona_private_offset;
static gpointer contacts_editor_persona_parent_class = NULL;

VALA_EXTERN GType contacts_editor_persona_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ContactsEditorPersona, g_object_unref)
VALA_EXTERN ContactsEditorPersona* contacts_editor_persona_new (FolksPersona* persona,
                                                    FolksIndividualAggregator* aggregator);
VALA_EXTERN ContactsEditorPersona* contacts_editor_persona_construct (GType object_type,
                                                          FolksPersona* persona,
                                                          FolksIndividualAggregator* aggregator);
static Block21Data* block21_data_ref (Block21Data* _data21_);
static void block21_data_unref (void * _userdata_);
static void contacts_editor_persona_create_label (ContactsEditorPersona* self);
VALA_EXTERN GType contacts_editor_property_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ContactsEditorProperty, g_object_unref)
VALA_EXTERN ContactsEditorProperty* contacts_editor_property_new (FolksPersona* persona,
                                                      const gchar* property_name,
                                                      gboolean only_new);
VALA_EXTERN ContactsEditorProperty* contacts_editor_property_construct (GType object_type,
                                                            FolksPersona* persona,
                                                            const gchar* property_name,
                                                            gboolean only_new);
VALA_EXTERN GType contacts_editor_property_row_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ContactsEditorPropertyRow, g_object_unref)
VALA_EXTERN void contacts_editor_property_row_show_with_animation (ContactsEditorPropertyRow* self,
                                                       gboolean animate);
static void contacts_editor_persona_connect_row (ContactsEditorPersona* self,
                                          ContactsEditorPropertyRow* row);
static void __lambda44_ (Block21Data* _data21_,
                  GtkButton* current_row);
static void ___lambda44__gtk_button_clicked (GtkButton* _sender,
                                      gpointer self);
static Block22Data* block22_data_ref (Block22Data* _data22_);
static void block22_data_unref (void * _userdata_);
static void __lambda43_ (Block22Data* _data22_);
static guint contacts_editor_persona_count_empty_rows (ContactsEditorPersona* self,
                                                const gchar* type);
VALA_EXTERN const gchar* contacts_editor_property_row_get_ptype (ContactsEditorPropertyRow* self);
VALA_EXTERN gboolean contacts_editor_property_row_get_is_empty (ContactsEditorPropertyRow* self);
static void contacts_editor_persona_destroy_empty_rows (ContactsEditorPersona* self,
                                                 GtkWidget* current_row,
                                                 const gchar* type);
static void ___lambda43__g_object_notify (GObject* _sender,
                                   GParamSpec* pspec,
                                   gpointer self);
VALA_EXTERN gboolean contacts_editor_property_row_get_is_removed (ContactsEditorPropertyRow* self);
VALA_EXTERN void contacts_editor_property_row_remove (ContactsEditorPropertyRow* self);
static GObject * contacts_editor_persona_constructor (GType type,
                                               guint n_construct_properties,
                                               GObjectConstructParam * construct_properties);
static void contacts_editor_persona_finalize (GObject * obj);
static GType contacts_editor_persona_get_type_once (void);

static const gchar* CONTACTS_EDITOR_PERSONA_PROPERTIES[2] = {"email-addresses", "phone-numbers"};
static const gchar* CONTACTS_EDITOR_PERSONA_OTHER_PROPERTIES[7] = {"im-addresses", "roles", "urls", "nickname", "birthday", "postal-addresses", "notes"};

static inline gpointer
contacts_editor_persona_get_instance_private (ContactsEditorPersona* self)
{
	return G_STRUCT_MEMBER_P (self, ContactsEditorPersona_private_offset);
}

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

static Block21Data*
block21_data_ref (Block21Data* _data21_)
{
	g_atomic_int_inc (&_data21_->_ref_count_);
	return _data21_;
}

static void
block21_data_unref (void * _userdata_)
{
	Block21Data* _data21_;
	_data21_ = (Block21Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data21_->_ref_count_)) {
		ContactsEditorPersona* self;
		self = _data21_->self;
		_g_object_unref0 (_data21_->show_more_button);
		_g_object_unref0 (_data21_->persona);
		_g_object_unref0 (self);
		g_slice_free (Block21Data, _data21_);
	}
}

static void
__lambda44_ (Block21Data* _data21_,
             GtkButton* current_row)
{
	ContactsEditorPersona* self;
	GtkBox* _tmp12_;
	self = _data21_->self;
	g_return_if_fail (current_row != NULL);
	{
		const gchar** property_collection = NULL;
		gint property_collection_length1 = 0;
		gint _property_collection_size_ = 0;
		gint property_it = 0;
		property_collection = CONTACTS_EDITOR_PERSONA_OTHER_PROPERTIES;
		property_collection_length1 = G_N_ELEMENTS (CONTACTS_EDITOR_PERSONA_OTHER_PROPERTIES);
		for (property_it = 0; property_it < property_collection_length1; property_it = property_it + 1) {
			const gchar* property = NULL;
			property = property_collection[property_it];
			{
				const gchar* _tmp0_;
				ContactsEditorProperty* prop_editor = NULL;
				const gchar* _tmp1_;
				ContactsEditorProperty* _tmp2_;
				_tmp0_ = property;
				g_debug ("contacts-editor-persona.vala:89: Create property entry for %s", _tmp0_);
				_tmp1_ = property;
				_tmp2_ = contacts_editor_property_new (_data21_->persona, _tmp1_, FALSE);
				prop_editor = _tmp2_;
				{
					gint i = 0;
					i = 0;
					{
						gboolean _tmp3_ = FALSE;
						_tmp3_ = TRUE;
						while (TRUE) {
							ContactsEditorProperty* _tmp5_;
							ContactsEditorPropertyRow* row = NULL;
							ContactsEditorProperty* _tmp6_;
							GObject* _tmp7_;
							ContactsEditorPropertyRow* _tmp8_;
							GtkBox* _tmp9_;
							ContactsEditorPropertyRow* _tmp10_;
							ContactsEditorPropertyRow* _tmp11_;
							if (!_tmp3_) {
								gint _tmp4_;
								_tmp4_ = i;
								i = _tmp4_ + 1;
							}
							_tmp3_ = FALSE;
							_tmp5_ = prop_editor;
							if (!(((guint) i) < g_list_model_get_n_items ((GListModel*) _tmp5_))) {
								break;
							}
							_tmp6_ = prop_editor;
							_tmp7_ = g_list_model_get_item ((GListModel*) _tmp6_, (guint) i);
							row = G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, CONTACTS_TYPE_EDITOR_PROPERTY_ROW, ContactsEditorPropertyRow);
							_tmp8_ = row;
							contacts_editor_persona_connect_row (self, _tmp8_);
							_tmp9_ = self->priv->content;
							_tmp10_ = row;
							gtk_box_append (_tmp9_, (GtkWidget*) _tmp10_);
							_tmp11_ = row;
							contacts_editor_property_row_show_with_animation (_tmp11_, TRUE);
							_g_object_unref0 (row);
						}
					}
				}
				_g_object_unref0 (prop_editor);
			}
		}
	}
	_tmp12_ = self->priv->content;
	gtk_box_remove (_tmp12_, (GtkWidget*) _data21_->show_more_button);
}

static void
___lambda44__gtk_button_clicked (GtkButton* _sender,
                                 gpointer self)
{
	__lambda44_ (self, _sender);
}

ContactsEditorPersona*
contacts_editor_persona_construct (GType object_type,
                                   FolksPersona* persona,
                                   FolksIndividualAggregator* aggregator)
{
	ContactsEditorPersona * self = NULL;
	Block21Data* _data21_;
	FolksPersona* _tmp0_;
	GtkButton* _tmp13_;
	AdwButtonContent* show_more_content = NULL;
	AdwButtonContent* _tmp14_;
	GtkBox* _tmp15_;
	g_return_val_if_fail (persona != NULL, NULL);
	g_return_val_if_fail (aggregator != NULL, NULL);
	_data21_ = g_slice_new0 (Block21Data);
	_data21_->_ref_count_ = 1;
	_tmp0_ = _g_object_ref0 (persona);
	_g_object_unref0 (_data21_->persona);
	_data21_->persona = _tmp0_;
	self = (ContactsEditorPersona*) g_object_new (object_type, "orientation", GTK_ORIENTATION_VERTICAL, "spacing", 6, NULL);
	_data21_->self = g_object_ref (self);
	self->priv->persona = _data21_->persona;
	self->priv->aggregator = aggregator;
	contacts_editor_persona_create_label (self);
	{
		const gchar** property_collection = NULL;
		gint property_collection_length1 = 0;
		gint _property_collection_size_ = 0;
		gint property_it = 0;
		property_collection = CONTACTS_EDITOR_PERSONA_PROPERTIES;
		property_collection_length1 = G_N_ELEMENTS (CONTACTS_EDITOR_PERSONA_PROPERTIES);
		for (property_it = 0; property_it < property_collection_length1; property_it = property_it + 1) {
			const gchar* property = NULL;
			property = property_collection[property_it];
			{
				const gchar* _tmp1_;
				ContactsEditorProperty* prop_editor = NULL;
				const gchar* _tmp2_;
				ContactsEditorProperty* _tmp3_;
				_tmp1_ = property;
				g_debug ("contacts-editor-persona.vala:68: Create property entry for %s", _tmp1_);
				_tmp2_ = property;
				_tmp3_ = contacts_editor_property_new (_data21_->persona, _tmp2_, FALSE);
				prop_editor = _tmp3_;
				{
					gint i = 0;
					i = 0;
					{
						gboolean _tmp4_ = FALSE;
						_tmp4_ = TRUE;
						while (TRUE) {
							ContactsEditorProperty* _tmp6_;
							ContactsEditorPropertyRow* row = NULL;
							ContactsEditorProperty* _tmp7_;
							GObject* _tmp8_;
							ContactsEditorPropertyRow* _tmp9_;
							ContactsEditorPropertyRow* _tmp10_;
							GtkBox* _tmp11_;
							ContactsEditorPropertyRow* _tmp12_;
							if (!_tmp4_) {
								gint _tmp5_;
								_tmp5_ = i;
								i = _tmp5_ + 1;
							}
							_tmp4_ = FALSE;
							_tmp6_ = prop_editor;
							if (!(((guint) i) < g_list_model_get_n_items ((GListModel*) _tmp6_))) {
								break;
							}
							_tmp7_ = prop_editor;
							_tmp8_ = g_list_model_get_item ((GListModel*) _tmp7_, (guint) i);
							row = G_TYPE_CHECK_INSTANCE_CAST (_tmp8_, CONTACTS_TYPE_EDITOR_PROPERTY_ROW, ContactsEditorPropertyRow);
							_tmp9_ = row;
							contacts_editor_property_row_show_with_animation (_tmp9_, FALSE);
							_tmp10_ = row;
							contacts_editor_persona_connect_row (self, _tmp10_);
							_tmp11_ = self->priv->content;
							_tmp12_ = row;
							gtk_box_append (_tmp11_, (GtkWidget*) _tmp12_);
							_g_object_unref0 (row);
						}
					}
				}
				_g_object_unref0 (prop_editor);
			}
		}
	}
	_tmp13_ = (GtkButton*) gtk_button_new ();
	g_object_ref_sink (_tmp13_);
	_data21_->show_more_button = _tmp13_;
	_tmp14_ = (AdwButtonContent*) adw_button_content_new ();
	g_object_ref_sink (_tmp14_);
	show_more_content = _tmp14_;
	adw_button_content_set_icon_name (show_more_content, "view-more-symbolic");
	adw_button_content_set_label (show_more_content, _ ("Show More"));
	gtk_button_set_child (_data21_->show_more_button, (GtkWidget*) show_more_content);
	gtk_widget_set_halign ((GtkWidget*) _data21_->show_more_button, GTK_ALIGN_CENTER);
	gtk_widget_add_css_class ((GtkWidget*) _data21_->show_more_button, "flat");
	g_signal_connect_data (_data21_->show_more_button, "clicked", (GCallback) ___lambda44__gtk_button_clicked, block21_data_ref (_data21_), (GClosureNotify) block21_data_unref, 0);
	_tmp15_ = self->priv->content;
	gtk_box_append (_tmp15_, (GtkWidget*) _data21_->show_more_button);
	_g_object_unref0 (show_more_content);
	block21_data_unref (_data21_);
	_data21_ = NULL;
	return self;
}

ContactsEditorPersona*
contacts_editor_persona_new (FolksPersona* persona,
                             FolksIndividualAggregator* aggregator)
{
	return contacts_editor_persona_construct (CONTACTS_TYPE_EDITOR_PERSONA, persona, aggregator);
}

static Block22Data*
block22_data_ref (Block22Data* _data22_)
{
	g_atomic_int_inc (&_data22_->_ref_count_);
	return _data22_;
}

static void
block22_data_unref (void * _userdata_)
{
	Block22Data* _data22_;
	_data22_ = (Block22Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data22_->_ref_count_)) {
		ContactsEditorPersona* self;
		self = _data22_->self;
		_g_object_unref0 (_data22_->row);
		_g_object_unref0 (self);
		g_slice_free (Block22Data, _data22_);
	}
}

static void
__lambda43_ (Block22Data* _data22_)
{
	ContactsEditorPersona* self;
	guint empty_rows_count = 0U;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	gboolean _tmp6_ = FALSE;
	gboolean _tmp7_;
	gboolean _tmp8_;
	self = _data22_->self;
	_tmp0_ = contacts_editor_property_row_get_ptype (_data22_->row);
	_tmp1_ = _tmp0_;
	empty_rows_count = contacts_editor_persona_count_empty_rows (self, _tmp1_);
	_tmp2_ = contacts_editor_property_row_get_is_empty (_data22_->row);
	_tmp3_ = _tmp2_;
	if (_tmp3_) {
		const gchar* _tmp4_;
		const gchar* _tmp5_;
		_tmp4_ = contacts_editor_property_row_get_ptype (_data22_->row);
		_tmp5_ = _tmp4_;
		contacts_editor_persona_destroy_empty_rows (self, (GtkWidget*) _data22_->row, _tmp5_);
	}
	_tmp7_ = contacts_editor_property_row_get_is_empty (_data22_->row);
	_tmp8_ = _tmp7_;
	if (!_tmp8_) {
		_tmp6_ = empty_rows_count == ((guint) 0);
	} else {
		_tmp6_ = FALSE;
	}
	if (_tmp6_) {
		ContactsEditorProperty* new_rows = NULL;
		FolksPersona* _tmp9_;
		const gchar* _tmp10_;
		const gchar* _tmp11_;
		ContactsEditorProperty* _tmp12_;
		ContactsEditorProperty* _tmp13_;
		_tmp9_ = self->priv->persona;
		_tmp10_ = contacts_editor_property_row_get_ptype (_data22_->row);
		_tmp11_ = _tmp10_;
		_tmp12_ = contacts_editor_property_new (_tmp9_, _tmp11_, TRUE);
		new_rows = _tmp12_;
		_tmp13_ = new_rows;
		if (g_list_model_get_n_items ((GListModel*) _tmp13_) > ((guint) 0)) {
			ContactsEditorPropertyRow* first_row = NULL;
			ContactsEditorProperty* _tmp14_;
			GObject* _tmp15_;
			GtkBox* _tmp16_;
			ContactsEditorPropertyRow* _tmp17_;
			ContactsEditorPropertyRow* _tmp18_;
			_tmp14_ = new_rows;
			_tmp15_ = g_list_model_get_item ((GListModel*) _tmp14_, (guint) 0);
			first_row = G_TYPE_CHECK_INSTANCE_CAST (_tmp15_, CONTACTS_TYPE_EDITOR_PROPERTY_ROW, ContactsEditorPropertyRow);
			_tmp16_ = self->priv->content;
			_tmp17_ = first_row;
			gtk_box_insert_child_after (_tmp16_, (GtkWidget*) _tmp17_, (GtkWidget*) _data22_->row);
			_tmp18_ = first_row;
			contacts_editor_persona_connect_row (self, _tmp18_);
			_g_object_unref0 (first_row);
		} else {
			const gchar* _tmp19_;
			const gchar* _tmp20_;
			_tmp19_ = contacts_editor_property_row_get_ptype (_data22_->row);
			_tmp20_ = _tmp19_;
			g_debug ("contacts-editor-persona.vala:119: Couldn't add new row with type %s", _tmp20_);
		}
		_g_object_unref0 (new_rows);
	}
}

static void
___lambda43__g_object_notify (GObject* _sender,
                              GParamSpec* pspec,
                              gpointer self)
{
	__lambda43_ (self);
}

static void
contacts_editor_persona_connect_row (ContactsEditorPersona* self,
                                     ContactsEditorPropertyRow* row)
{
	Block22Data* _data22_;
	ContactsEditorPropertyRow* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (row != NULL);
	_data22_ = g_slice_new0 (Block22Data);
	_data22_->_ref_count_ = 1;
	_data22_->self = g_object_ref (self);
	_tmp0_ = _g_object_ref0 (row);
	_g_object_unref0 (_data22_->row);
	_data22_->row = _tmp0_;
	g_signal_connect_data ((GObject*) _data22_->row, "notify::is-empty", (GCallback) ___lambda43__g_object_notify, block22_data_ref (_data22_), (GClosureNotify) block22_data_unref, 0);
	block22_data_unref (_data22_);
	_data22_ = NULL;
}

static guint
contacts_editor_persona_count_empty_rows (ContactsEditorPersona* self,
                                          const gchar* type)
{
	guint count = 0U;
	guint result;
	g_return_val_if_fail (self != NULL, 0U);
	g_return_val_if_fail (type != NULL, 0U);
	count = (guint) 0;
	{
		GtkWidget* child = NULL;
		GtkBox* _tmp0_;
		GtkWidget* _tmp1_;
		_tmp0_ = self->priv->content;
		_tmp1_ = gtk_widget_get_first_child ((GtkWidget*) _tmp0_);
		child = _tmp1_;
		{
			gboolean _tmp2_ = FALSE;
			_tmp2_ = TRUE;
			while (TRUE) {
				GtkWidget* _tmp5_;
				ContactsEditorPropertyRow* prop = NULL;
				GtkWidget* _tmp6_;
				gboolean _tmp7_ = FALSE;
				gboolean _tmp8_ = FALSE;
				gboolean _tmp9_ = FALSE;
				ContactsEditorPropertyRow* _tmp10_;
				if (!_tmp2_) {
					GtkWidget* _tmp3_;
					GtkWidget* _tmp4_;
					_tmp3_ = child;
					_tmp4_ = gtk_widget_get_next_sibling (_tmp3_);
					child = _tmp4_;
				}
				_tmp2_ = FALSE;
				_tmp5_ = child;
				if (!(_tmp5_ != NULL)) {
					break;
				}
				_tmp6_ = child;
				prop = CONTACTS_IS_EDITOR_PROPERTY_ROW (_tmp6_) ? ((ContactsEditorPropertyRow*) _tmp6_) : NULL;
				_tmp10_ = prop;
				if (_tmp10_ != NULL) {
					ContactsEditorPropertyRow* _tmp11_;
					gboolean _tmp12_;
					gboolean _tmp13_;
					_tmp11_ = prop;
					_tmp12_ = contacts_editor_property_row_get_is_removed (_tmp11_);
					_tmp13_ = _tmp12_;
					_tmp9_ = !_tmp13_;
				} else {
					_tmp9_ = FALSE;
				}
				if (_tmp9_) {
					ContactsEditorPropertyRow* _tmp14_;
					gboolean _tmp15_;
					gboolean _tmp16_;
					_tmp14_ = prop;
					_tmp15_ = contacts_editor_property_row_get_is_empty (_tmp14_);
					_tmp16_ = _tmp15_;
					_tmp8_ = _tmp16_;
				} else {
					_tmp8_ = FALSE;
				}
				if (_tmp8_) {
					ContactsEditorPropertyRow* _tmp17_;
					const gchar* _tmp18_;
					const gchar* _tmp19_;
					_tmp17_ = prop;
					_tmp18_ = contacts_editor_property_row_get_ptype (_tmp17_);
					_tmp19_ = _tmp18_;
					_tmp7_ = g_strcmp0 (_tmp19_, type) == 0;
				} else {
					_tmp7_ = FALSE;
				}
				if (_tmp7_) {
					guint _tmp20_;
					_tmp20_ = count;
					count = _tmp20_ + 1;
				}
			}
		}
	}
	result = count;
	return result;
}

static void
contacts_editor_persona_destroy_empty_rows (ContactsEditorPersona* self,
                                            GtkWidget* current_row,
                                            const gchar* type)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (current_row != NULL);
	g_return_if_fail (type != NULL);
	{
		GtkWidget* child = NULL;
		GtkBox* _tmp0_;
		GtkWidget* _tmp1_;
		_tmp0_ = self->priv->content;
		_tmp1_ = gtk_widget_get_first_child ((GtkWidget*) _tmp0_);
		child = _tmp1_;
		{
			gboolean _tmp2_ = FALSE;
			_tmp2_ = TRUE;
			while (TRUE) {
				GtkWidget* _tmp5_;
				GtkWidget* _tmp6_;
				ContactsEditorPropertyRow* prop = NULL;
				GtkWidget* _tmp7_;
				gboolean _tmp8_ = FALSE;
				gboolean _tmp9_ = FALSE;
				gboolean _tmp10_ = FALSE;
				ContactsEditorPropertyRow* _tmp11_;
				if (!_tmp2_) {
					GtkWidget* _tmp3_;
					GtkWidget* _tmp4_;
					_tmp3_ = child;
					_tmp4_ = gtk_widget_get_next_sibling (_tmp3_);
					child = _tmp4_;
				}
				_tmp2_ = FALSE;
				_tmp5_ = child;
				if (!(_tmp5_ != NULL)) {
					break;
				}
				_tmp6_ = child;
				if (current_row == _tmp6_) {
					continue;
				}
				_tmp7_ = child;
				prop = CONTACTS_IS_EDITOR_PROPERTY_ROW (_tmp7_) ? ((ContactsEditorPropertyRow*) _tmp7_) : NULL;
				_tmp11_ = prop;
				if (_tmp11_ != NULL) {
					ContactsEditorPropertyRow* _tmp12_;
					gboolean _tmp13_;
					gboolean _tmp14_;
					_tmp12_ = prop;
					_tmp13_ = contacts_editor_property_row_get_is_removed (_tmp12_);
					_tmp14_ = _tmp13_;
					_tmp10_ = !_tmp14_;
				} else {
					_tmp10_ = FALSE;
				}
				if (_tmp10_) {
					ContactsEditorPropertyRow* _tmp15_;
					gboolean _tmp16_;
					gboolean _tmp17_;
					_tmp15_ = prop;
					_tmp16_ = contacts_editor_property_row_get_is_empty (_tmp15_);
					_tmp17_ = _tmp16_;
					_tmp9_ = _tmp17_;
				} else {
					_tmp9_ = FALSE;
				}
				if (_tmp9_) {
					ContactsEditorPropertyRow* _tmp18_;
					const gchar* _tmp19_;
					const gchar* _tmp20_;
					_tmp18_ = prop;
					_tmp19_ = contacts_editor_property_row_get_ptype (_tmp18_);
					_tmp20_ = _tmp19_;
					_tmp8_ = g_strcmp0 (_tmp20_, type) == 0;
				} else {
					_tmp8_ = FALSE;
				}
				if (_tmp8_) {
					ContactsEditorPropertyRow* _tmp21_;
					_tmp21_ = prop;
					contacts_editor_property_row_remove (_tmp21_);
				}
			}
		}
	}
}

static void
contacts_editor_persona_create_label (ContactsEditorPersona* self)
{
	gchar* title = NULL;
	gchar* _tmp0_;
	ContactsFakePersona* fake_persona = NULL;
	FolksPersona* _tmp1_;
	gboolean _tmp2_ = FALSE;
	ContactsFakePersona* _tmp3_;
	GtkLabel* addressbook = NULL;
	const gchar* _tmp21_;
	GtkLabel* _tmp22_;
	GtkBox* _tmp23_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_strdup ("");
	title = _tmp0_;
	_tmp1_ = self->priv->persona;
	fake_persona = G_TYPE_CHECK_INSTANCE_TYPE (_tmp1_, CONTACTS_TYPE_FAKE_PERSONA) ? ((ContactsFakePersona*) _tmp1_) : NULL;
	_tmp3_ = fake_persona;
	if (_tmp3_ != NULL) {
		ContactsFakePersona* _tmp4_;
		FolksPersona* _tmp5_;
		FolksPersona* _tmp6_;
		_tmp4_ = fake_persona;
		_tmp5_ = contacts_fake_persona_get_real_persona (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp2_ = _tmp6_ != NULL;
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		ContactsFakePersona* _tmp7_;
		FolksPersona* _tmp8_;
		FolksPersona* _tmp9_;
		FolksPersonaStore* _tmp10_;
		FolksPersonaStore* _tmp11_;
		const gchar* _tmp12_;
		const gchar* _tmp13_;
		gchar* _tmp14_;
		_tmp7_ = fake_persona;
		_tmp8_ = contacts_fake_persona_get_real_persona (_tmp7_);
		_tmp9_ = _tmp8_;
		_tmp10_ = folks_persona_get_store (_tmp9_);
		_tmp11_ = _tmp10_;
		_tmp12_ = folks_persona_store_get_display_name (_tmp11_);
		_tmp13_ = _tmp12_;
		_tmp14_ = g_strdup (_tmp13_);
		_g_free0 (title);
		title = _tmp14_;
	} else {
		FolksIndividualAggregator* _tmp15_;
		FolksPersonaStore* _tmp16_;
		FolksPersonaStore* _tmp17_;
		const gchar* _tmp18_;
		const gchar* _tmp19_;
		gchar* _tmp20_;
		_tmp15_ = self->priv->aggregator;
		_tmp16_ = folks_individual_aggregator_get_primary_store (_tmp15_);
		_tmp17_ = _tmp16_;
		_tmp18_ = folks_persona_store_get_display_name (_tmp17_);
		_tmp19_ = _tmp18_;
		_tmp20_ = g_strdup (_tmp19_);
		_g_free0 (title);
		title = _tmp20_;
	}
	_tmp21_ = title;
	_tmp22_ = (GtkLabel*) gtk_label_new (_tmp21_);
	g_object_ref_sink (_tmp22_);
	addressbook = _tmp22_;
	gtk_widget_add_css_class ((GtkWidget*) addressbook, "heading");
	_tmp23_ = self->priv->header;
	gtk_box_append (_tmp23_, (GtkWidget*) addressbook);
	_g_object_unref0 (addressbook);
	_g_free0 (title);
}

static GObject *
contacts_editor_persona_constructor (GType type,
                                     guint n_construct_properties,
                                     GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	ContactsEditorPersona * self;
	GtkBox* _header = NULL;
	GtkBox* _tmp0_;
	GtkBox* _tmp1_;
	GtkBox* _tmp2_;
	GtkBox* listbox = NULL;
	GtkBox* _tmp3_;
	GtkBox* _tmp4_;
	GtkBox* _tmp5_;
	GtkBox* _tmp6_;
	parent_class = G_OBJECT_CLASS (contacts_editor_persona_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CONTACTS_TYPE_EDITOR_PERSONA, ContactsEditorPersona);
	_tmp0_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
	g_object_ref_sink (_tmp0_);
	_header = _tmp0_;
	_tmp1_ = _header;
	gtk_box_append ((GtkBox*) self, (GtkWidget*) _tmp1_);
	_tmp2_ = _header;
	self->priv->header = _tmp2_;
	_tmp3_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	g_object_ref_sink (_tmp3_);
	listbox = _tmp3_;
	_tmp4_ = listbox;
	self->priv->content = _tmp4_;
	_tmp5_ = self->priv->content;
	gtk_widget_add_css_class ((GtkWidget*) _tmp5_, "boxed-list");
	_tmp6_ = self->priv->content;
	gtk_box_append ((GtkBox*) self, (GtkWidget*) _tmp6_);
	_g_object_unref0 (listbox);
	_g_object_unref0 (_header);
	return obj;
}

static void
contacts_editor_persona_class_init (ContactsEditorPersonaClass * klass,
                                    gpointer klass_data)
{
	contacts_editor_persona_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ContactsEditorPersona_private_offset);
	G_OBJECT_CLASS (klass)->constructor = contacts_editor_persona_constructor;
	G_OBJECT_CLASS (klass)->finalize = contacts_editor_persona_finalize;
}

static void
contacts_editor_persona_instance_init (ContactsEditorPersona * self,
                                       gpointer klass)
{
	self->priv = contacts_editor_persona_get_instance_private (self);
}

static void
contacts_editor_persona_finalize (GObject * obj)
{
	ContactsEditorPersona * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CONTACTS_TYPE_EDITOR_PERSONA, ContactsEditorPersona);
	G_OBJECT_CLASS (contacts_editor_persona_parent_class)->finalize (obj);
}

/**
 * A widget representing a persona in the {@link ContactEditor}.
 */
 G_GNUC_NO_INLINE static GType
contacts_editor_persona_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ContactsEditorPersonaClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) contacts_editor_persona_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ContactsEditorPersona), 0, (GInstanceInitFunc) contacts_editor_persona_instance_init, NULL };
	GType contacts_editor_persona_type_id;
	contacts_editor_persona_type_id = g_type_register_static (gtk_box_get_type (), "ContactsEditorPersona", &g_define_type_info, 0);
	ContactsEditorPersona_private_offset = g_type_add_instance_private (contacts_editor_persona_type_id, sizeof (ContactsEditorPersonaPrivate));
	return contacts_editor_persona_type_id;
}

GType
contacts_editor_persona_get_type (void)
{
	static volatile gsize contacts_editor_persona_type_id__once = 0;
	if (g_once_init_enter (&contacts_editor_persona_type_id__once)) {
		GType contacts_editor_persona_type_id;
		contacts_editor_persona_type_id = contacts_editor_persona_get_type_once ();
		g_once_init_leave (&contacts_editor_persona_type_id__once, contacts_editor_persona_type_id);
	}
	return contacts_editor_persona_type_id__once;
}

