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

/*
 * Copyright (C) 2019 Purism SPC
 *
 * Author: Julian Sparber
 *
 * 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 <adwaita.h>
#include <glib-object.h>
#include <folks/folks.h>
#include <glib.h>
#include <gtk/gtk.h>
#include "contacts.h"
#include <stdlib.h>
#include <string.h>
#include <libedataserver/libedataserver.h>
#include <folks/folks-eds.h>
#include <config.h>
#include <glib/gi18n-lib.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_ADDRESSBOOK_LIST (contacts_addressbook_list_get_type ())
#define CONTACTS_ADDRESSBOOK_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONTACTS_TYPE_ADDRESSBOOK_LIST, ContactsAddressbookList))
#define CONTACTS_ADDRESSBOOK_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONTACTS_TYPE_ADDRESSBOOK_LIST, ContactsAddressbookListClass))
#define CONTACTS_IS_ADDRESSBOOK_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONTACTS_TYPE_ADDRESSBOOK_LIST))
#define CONTACTS_IS_ADDRESSBOOK_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONTACTS_TYPE_ADDRESSBOOK_LIST))
#define CONTACTS_ADDRESSBOOK_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONTACTS_TYPE_ADDRESSBOOK_LIST, ContactsAddressbookListClass))

typedef struct _ContactsAddressbookList ContactsAddressbookList;
typedef struct _ContactsAddressbookListClass ContactsAddressbookListClass;
typedef struct _ContactsAddressbookListPrivate ContactsAddressbookListPrivate;

#define CONTACTS_TYPE_ADDRESSBOOK_ROW (contacts_addressbook_row_get_type ())
#define CONTACTS_ADDRESSBOOK_ROW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONTACTS_TYPE_ADDRESSBOOK_ROW, ContactsAddressbookRow))
#define CONTACTS_ADDRESSBOOK_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONTACTS_TYPE_ADDRESSBOOK_ROW, ContactsAddressbookRowClass))
#define CONTACTS_IS_ADDRESSBOOK_ROW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONTACTS_TYPE_ADDRESSBOOK_ROW))
#define CONTACTS_IS_ADDRESSBOOK_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONTACTS_TYPE_ADDRESSBOOK_ROW))
#define CONTACTS_ADDRESSBOOK_ROW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONTACTS_TYPE_ADDRESSBOOK_ROW, ContactsAddressbookRowClass))

typedef struct _ContactsAddressbookRow ContactsAddressbookRow;
typedef struct _ContactsAddressbookRowClass ContactsAddressbookRowClass;
enum  {
	CONTACTS_ADDRESSBOOK_LIST_0_PROPERTY,
	CONTACTS_ADDRESSBOOK_LIST_NUM_PROPERTIES
};
static GParamSpec* contacts_addressbook_list_properties[CONTACTS_ADDRESSBOOK_LIST_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
enum  {
	CONTACTS_ADDRESSBOOK_LIST_ADDRESSBOOK_SELECTED_SIGNAL,
	CONTACTS_ADDRESSBOOK_LIST_NUM_SIGNALS
};
static guint contacts_addressbook_list_signals[CONTACTS_ADDRESSBOOK_LIST_NUM_SIGNALS] = {0};
typedef struct _ContactsAddressbookRowPrivate ContactsAddressbookRowPrivate;
enum  {
	CONTACTS_ADDRESSBOOK_ROW_0_PROPERTY,
	CONTACTS_ADDRESSBOOK_ROW_NUM_PROPERTIES
};
static GParamSpec* contacts_addressbook_row_properties[CONTACTS_ADDRESSBOOK_ROW_NUM_PROPERTIES];

struct _ContactsAddressbookList {
	AdwBin parent_instance;
	ContactsAddressbookListPrivate * priv;
};

struct _ContactsAddressbookListClass {
	AdwBinClass parent_class;
};

struct _ContactsAddressbookListPrivate {
	FolksBackendStore* store;
	gboolean show_icon;
	GtkListBox* listbox;
	ContactsAddressbookRow* marked_row;
};

struct _ContactsAddressbookRow {
	AdwActionRow parent_instance;
	ContactsAddressbookRowPrivate * priv;
};

struct _ContactsAddressbookRowClass {
	AdwActionRowClass parent_class;
};

struct _ContactsAddressbookRowPrivate {
	GtkWidget* checkmark;
};

static gint ContactsAddressbookList_private_offset;
static gpointer contacts_addressbook_list_parent_class = NULL;
static gint ContactsAddressbookRow_private_offset;
static gpointer contacts_addressbook_row_parent_class = NULL;

VALA_EXTERN GType contacts_addressbook_list_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ContactsAddressbookList, g_object_unref)
VALA_EXTERN GType contacts_addressbook_row_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ContactsAddressbookRow, g_object_unref)
VALA_EXTERN ContactsAddressbookList* contacts_addressbook_list_new (FolksBackendStore* store,
                                                        gboolean icon);
VALA_EXTERN ContactsAddressbookList* contacts_addressbook_list_construct (GType object_type,
                                                              FolksBackendStore* store,
                                                              gboolean icon);
VALA_EXTERN void contacts_addressbook_list_update (ContactsAddressbookList* self);
static void contacts_addressbook_list_list_box_update_header_func (ContactsAddressbookList* self,
                                                            GtkListBoxRow* row,
                                                            GtkListBoxRow* before);
static void contacts_addressbook_list_on_row_activated (ContactsAddressbookList* self,
                                                 GtkListBox* listbox,
                                                 GtkListBoxRow* row);
VALA_EXTERN void contacts_addressbook_row_unselect (ContactsAddressbookRow* self);
VALA_EXTERN void contacts_addressbook_row_select (ContactsAddressbookRow* self);
VALA_EXTERN ContactsAddressbookRow* contacts_addressbook_row_new (const gchar* title,
                                                      const gchar* subtitle,
                                                      GtkWidget* image);
VALA_EXTERN ContactsAddressbookRow* contacts_addressbook_row_construct (GType object_type,
                                                            const gchar* title,
                                                            const gchar* subtitle,
                                                            GtkWidget* image);
static GObject * contacts_addressbook_list_constructor (GType type,
                                                 guint n_construct_properties,
                                                 GObjectConstructParam * construct_properties);
static void _contacts_addressbook_list_on_row_activated_gtk_list_box_row_activated (GtkListBox* _sender,
                                                                             GtkListBoxRow* row,
                                                                             gpointer self);
static void _contacts_addressbook_list_list_box_update_header_func_gtk_list_box_update_header_func (GtkListBoxRow* row,
                                                                                             GtkListBoxRow* before,
                                                                                             gpointer self);
static void contacts_addressbook_list_finalize (GObject * obj);
static GType contacts_addressbook_list_get_type_once (void);
static void contacts_addressbook_row_finalize (GObject * obj);
static GType contacts_addressbook_row_get_type_once (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);

static inline gpointer
contacts_addressbook_list_get_instance_private (ContactsAddressbookList* self)
{
	return G_STRUCT_MEMBER_P (self, ContactsAddressbookList_private_offset);
}

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

ContactsAddressbookList*
contacts_addressbook_list_construct (GType object_type,
                                     FolksBackendStore* store,
                                     gboolean icon)
{
	ContactsAddressbookList * self = NULL;
	FolksBackendStore* _tmp0_;
	g_return_val_if_fail (store != NULL, NULL);
	self = (ContactsAddressbookList*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (store);
	_g_object_unref0 (self->priv->store);
	self->priv->store = _tmp0_;
	self->priv->show_icon = icon;
	contacts_addressbook_list_update (self);
	return self;
}

ContactsAddressbookList*
contacts_addressbook_list_new (FolksBackendStore* store,
                               gboolean icon)
{
	return contacts_addressbook_list_construct (CONTACTS_TYPE_ADDRESSBOOK_LIST, store, icon);
}

static void
contacts_addressbook_list_list_box_update_header_func (ContactsAddressbookList* self,
                                                       GtkListBoxRow* row,
                                                       GtkListBoxRow* before)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (row != NULL);
	if (before == NULL) {
		gtk_list_box_row_set_header (row, NULL);
	} else {
		GtkWidget* _tmp0_;
		_tmp0_ = gtk_list_box_row_get_header (row);
		if (_tmp0_ == NULL) {
			GtkSeparator* header = NULL;
			GtkSeparator* _tmp1_;
			GtkSeparator* _tmp2_;
			GtkSeparator* _tmp3_;
			_tmp1_ = (GtkSeparator*) gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
			g_object_ref_sink (_tmp1_);
			header = _tmp1_;
			_tmp2_ = header;
			gtk_widget_show ((GtkWidget*) _tmp2_);
			_tmp3_ = header;
			gtk_list_box_row_set_header (row, (GtkWidget*) _tmp3_);
			_g_object_unref0 (header);
		}
	}
}

static void
contacts_addressbook_list_on_row_activated (ContactsAddressbookList* self,
                                            GtkListBox* listbox,
                                            GtkListBoxRow* row)
{
	ContactsAddressbookRow* addressbook = NULL;
	ContactsAddressbookRow* _tmp0_;
	ContactsAddressbookRow* _tmp1_;
	gboolean _tmp2_ = FALSE;
	ContactsAddressbookRow* _tmp3_;
	ContactsAddressbookRow* _tmp6_;
	ContactsAddressbookRow* _tmp8_;
	ContactsAddressbookRow* _tmp9_;
	ContactsAddressbookRow* _tmp10_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (listbox != NULL);
	g_return_if_fail (row != NULL);
	_tmp0_ = _g_object_ref0 (CONTACTS_IS_ADDRESSBOOK_ROW (row) ? ((ContactsAddressbookRow*) row) : NULL);
	addressbook = _tmp0_;
	_tmp1_ = addressbook;
	if (_tmp1_ == NULL) {
		_g_object_unref0 (addressbook);
		return;
	}
	_tmp3_ = self->priv->marked_row;
	if (_tmp3_ != NULL) {
		ContactsAddressbookRow* _tmp4_;
		ContactsAddressbookRow* _tmp5_;
		_tmp4_ = self->priv->marked_row;
		_tmp5_ = addressbook;
		_tmp2_ = _tmp4_ == _tmp5_;
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		_g_object_unref0 (addressbook);
		return;
	}
	_tmp6_ = self->priv->marked_row;
	if (_tmp6_ != NULL) {
		ContactsAddressbookRow* _tmp7_;
		_tmp7_ = self->priv->marked_row;
		contacts_addressbook_row_unselect (_tmp7_);
	}
	_tmp8_ = addressbook;
	contacts_addressbook_row_select (_tmp8_);
	_tmp9_ = addressbook;
	_tmp10_ = _g_object_ref0 (_tmp9_);
	_g_object_unref0 (self->priv->marked_row);
	self->priv->marked_row = _tmp10_;
	g_signal_emit (self, contacts_addressbook_list_signals[CONTACTS_ADDRESSBOOK_LIST_ADDRESSBOOK_SELECTED_SIGNAL], 0);
	_g_object_unref0 (addressbook);
}

void
contacts_addressbook_list_update (ContactsAddressbookList* self)
{
	GtkWidget* child = NULL;
	GtkListBox* _tmp0_;
	GtkWidget* _tmp1_;
	FolksPersonaStore** eds_stores = NULL;
	FolksBackendStore* _tmp8_;
	gint _tmp9_ = 0;
	FolksPersonaStore** _tmp10_;
	gint eds_stores_length1;
	gint _eds_stores_size_;
	FolksPersonaStore** _tmp11_;
	gint _tmp11__length1;
	FolksPersonaStore* local_store = NULL;
	FolksPersonaStore** _tmp12_;
	gint _tmp12__length1;
	FolksPersonaStore* _tmp52_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->listbox;
	_tmp1_ = gtk_widget_get_first_child ((GtkWidget*) _tmp0_);
	child = _tmp1_;
	while (TRUE) {
		GtkWidget* _tmp2_;
		GtkWidget* next = NULL;
		GtkWidget* _tmp3_;
		GtkWidget* _tmp4_;
		GtkListBox* _tmp5_;
		GtkWidget* _tmp6_;
		GtkWidget* _tmp7_;
		_tmp2_ = child;
		if (!(_tmp2_ != NULL)) {
			break;
		}
		_tmp3_ = child;
		_tmp4_ = gtk_widget_get_next_sibling (_tmp3_);
		next = _tmp4_;
		_tmp5_ = self->priv->listbox;
		_tmp6_ = child;
		gtk_list_box_remove (_tmp5_, _tmp6_);
		_tmp7_ = next;
		child = _tmp7_;
	}
	_tmp8_ = self->priv->store;
	_tmp10_ = contacts_utils_get_eds_address_books_from_backend (_tmp8_, &_tmp9_);
	eds_stores = _tmp10_;
	eds_stores_length1 = _tmp9_;
	_eds_stores_size_ = eds_stores_length1;
	_tmp11_ = eds_stores;
	_tmp11__length1 = eds_stores_length1;
	g_debug ("contacts-addressbook-list.vala:85: Found %d EDS stores", _tmp11__length1);
	local_store = NULL;
	_tmp12_ = eds_stores;
	_tmp12__length1 = eds_stores_length1;
	{
		FolksPersonaStore** persona_store_collection = NULL;
		gint persona_store_collection_length1 = 0;
		gint _persona_store_collection_size_ = 0;
		gint persona_store_it = 0;
		persona_store_collection = _tmp12_;
		persona_store_collection_length1 = _tmp12__length1;
		for (persona_store_it = 0; persona_store_it < persona_store_collection_length1; persona_store_it = persona_store_it + 1) {
			FolksPersonaStore* _tmp13_;
			FolksPersonaStore* persona_store = NULL;
			_tmp13_ = _g_object_ref0 (persona_store_collection[persona_store_it]);
			persona_store = _tmp13_;
			{
				FolksPersonaStore* _tmp14_;
				const gchar* _tmp15_;
				const gchar* _tmp16_;
				ESource* source = NULL;
				FolksPersonaStore* _tmp19_;
				ESource* _tmp20_;
				ESource* _tmp21_;
				ESource* _tmp22_;
				ESource* parent_source = NULL;
				ESourceRegistry* _tmp23_;
				ESource* _tmp24_;
				const gchar* _tmp25_;
				const gchar* _tmp26_;
				ESource* _tmp27_;
				gchar* provider_name = NULL;
				FolksPersonaStore* _tmp28_;
				gchar* _tmp29_;
				const gchar* _tmp30_;
				gchar* source_account_id = NULL;
				gchar* _tmp31_;
				ESource* _tmp32_;
				GtkImage* provider_image = NULL;
				ContactsAddressbookRow* row = NULL;
				const gchar* _tmp44_;
				ESource* _tmp45_;
				const gchar* _tmp46_;
				const gchar* _tmp47_;
				GtkImage* _tmp48_;
				ContactsAddressbookRow* _tmp49_;
				GtkListBox* _tmp50_;
				ContactsAddressbookRow* _tmp51_;
				_tmp14_ = persona_store;
				_tmp15_ = folks_persona_store_get_id (_tmp14_);
				_tmp16_ = _tmp15_;
				if (g_strcmp0 (_tmp16_, "system-address-book") == 0) {
					FolksPersonaStore* _tmp17_;
					FolksPersonaStore* _tmp18_;
					_tmp17_ = persona_store;
					_tmp18_ = _g_object_ref0 (_tmp17_);
					_g_object_unref0 (local_store);
					local_store = _tmp18_;
					_g_object_unref0 (persona_store);
					continue;
				}
				_tmp19_ = persona_store;
				_tmp20_ = edsf_persona_store_get_source (G_TYPE_CHECK_INSTANCE_CAST (_tmp19_, EDSF_TYPE_PERSONA_STORE, EdsfPersonaStore));
				_tmp21_ = _tmp20_;
				_tmp22_ = _g_object_ref0 (_tmp21_);
				source = _tmp22_;
				_tmp23_ = contacts_eds_source_registry;
				_tmp24_ = source;
				_tmp25_ = e_source_get_parent (_tmp24_);
				_tmp26_ = _tmp25_;
				_tmp27_ = e_source_registry_ref_source (_tmp23_, _tmp26_);
				parent_source = _tmp27_;
				_tmp28_ = persona_store;
				_tmp29_ = contacts_utils_format_persona_store_name (_tmp28_);
				provider_name = _tmp29_;
				_tmp30_ = provider_name;
				g_debug ("contacts-addressbook-list.vala:97: Contact store \"%s\"", _tmp30_);
				_tmp31_ = g_strdup ("");
				source_account_id = _tmp31_;
				_tmp32_ = parent_source;
				if (e_source_has_extension (_tmp32_, E_SOURCE_EXTENSION_GOA)) {
					ESourceGoa* goa_source_ext = NULL;
					ESource* _tmp33_;
					ESourceExtension* _tmp34_;
					ESourceGoa* _tmp35_;
					ESourceGoa* _tmp36_;
					const gchar* _tmp37_;
					const gchar* _tmp38_;
					gchar* _tmp39_;
					_tmp33_ = parent_source;
					_tmp34_ = e_source_get_extension (_tmp33_, E_SOURCE_EXTENSION_GOA);
					_tmp35_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp34_, e_source_goa_get_type ()) ? ((ESourceGoa*) _tmp34_) : NULL);
					goa_source_ext = _tmp35_;
					_tmp36_ = goa_source_ext;
					_tmp37_ = e_source_goa_get_account_id (_tmp36_);
					_tmp38_ = _tmp37_;
					_tmp39_ = g_strdup (_tmp38_);
					_g_free0 (source_account_id);
					source_account_id = _tmp39_;
					_g_object_unref0 (goa_source_ext);
				}
				provider_image = NULL;
				if (self->priv->show_icon) {
					const gchar* _tmp40_;
					_tmp40_ = source_account_id;
					if (g_strcmp0 (_tmp40_, "") != 0) {
						const gchar* _tmp41_;
						GtkImage* _tmp42_;
						_tmp41_ = source_account_id;
						_tmp42_ = contacts_get_icon_for_goa_account (_tmp41_);
						_g_object_unref0 (provider_image);
						provider_image = _tmp42_;
					} else {
						GtkImage* _tmp43_;
						_tmp43_ = (GtkImage*) gtk_image_new_from_icon_name (APP_ID);
						g_object_ref_sink (_tmp43_);
						_g_object_unref0 (provider_image);
						provider_image = _tmp43_;
					}
				}
				_tmp44_ = provider_name;
				_tmp45_ = parent_source;
				_tmp46_ = e_source_get_display_name (_tmp45_);
				_tmp47_ = _tmp46_;
				_tmp48_ = provider_image;
				_tmp49_ = contacts_addressbook_row_new (_tmp44_, _tmp47_, (GtkWidget*) _tmp48_);
				g_object_ref_sink (_tmp49_);
				row = _tmp49_;
				_tmp50_ = self->priv->listbox;
				_tmp51_ = row;
				gtk_list_box_append (_tmp50_, (GtkWidget*) _tmp51_);
				_g_object_unref0 (row);
				_g_object_unref0 (provider_image);
				_g_free0 (source_account_id);
				_g_free0 (provider_name);
				_g_object_unref0 (parent_source);
				_g_object_unref0 (source);
				_g_object_unref0 (persona_store);
			}
		}
	}
	_tmp52_ = local_store;
	if (_tmp52_ != NULL) {
		GtkImage* _tmp53_ = NULL;
		GtkImage* provider_image = NULL;
		GtkImage* _tmp55_;
		ContactsAddressbookRow* local_row = NULL;
		GtkImage* _tmp56_;
		ContactsAddressbookRow* _tmp57_;
		GtkListBox* _tmp58_;
		ContactsAddressbookRow* _tmp59_;
		if (self->priv->show_icon) {
			GtkImage* _tmp54_;
			_tmp54_ = (GtkImage*) gtk_image_new_from_icon_name (APP_ID);
			g_object_ref_sink (_tmp54_);
			_g_object_unref0 (_tmp53_);
			_tmp53_ = _tmp54_;
		} else {
			_g_object_unref0 (_tmp53_);
			_tmp53_ = NULL;
		}
		_tmp55_ = _g_object_ref0 (_tmp53_);
		provider_image = _tmp55_;
		_tmp56_ = provider_image;
		_tmp57_ = contacts_addressbook_row_new (_ ("Local Address Book"), NULL, (GtkWidget*) _tmp56_);
		g_object_ref_sink (_tmp57_);
		local_row = _tmp57_;
		_tmp58_ = self->priv->listbox;
		_tmp59_ = local_row;
		gtk_list_box_append (_tmp58_, (GtkWidget*) _tmp59_);
		_g_object_unref0 (local_row);
		_g_object_unref0 (provider_image);
		_g_object_unref0 (_tmp53_);
	}
	_g_object_unref0 (local_store);
	eds_stores = (_vala_array_free (eds_stores, eds_stores_length1, (GDestroyNotify) g_object_unref), NULL);
}

static void
_contacts_addressbook_list_on_row_activated_gtk_list_box_row_activated (GtkListBox* _sender,
                                                                        GtkListBoxRow* row,
                                                                        gpointer self)
{
	contacts_addressbook_list_on_row_activated ((ContactsAddressbookList*) self, _sender, row);
}

static void
_contacts_addressbook_list_list_box_update_header_func_gtk_list_box_update_header_func (GtkListBoxRow* row,
                                                                                        GtkListBoxRow* before,
                                                                                        gpointer self)
{
	contacts_addressbook_list_list_box_update_header_func ((ContactsAddressbookList*) self, row, before);
}

static GObject *
contacts_addressbook_list_constructor (GType type,
                                       guint n_construct_properties,
                                       GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	ContactsAddressbookList * self;
	GtkListBox* list_box = NULL;
	GtkListBox* _tmp0_;
	GtkListBox* _tmp1_;
	GtkListBox* _tmp2_;
	GtkListBox* _tmp3_;
	GtkListBox* _tmp4_;
	parent_class = G_OBJECT_CLASS (contacts_addressbook_list_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CONTACTS_TYPE_ADDRESSBOOK_LIST, ContactsAddressbookList);
	_tmp0_ = (GtkListBox*) gtk_list_box_new ();
	g_object_ref_sink (_tmp0_);
	list_box = _tmp0_;
	_tmp1_ = list_box;
	g_signal_connect_object (_tmp1_, "row-activated", (GCallback) _contacts_addressbook_list_on_row_activated_gtk_list_box_row_activated, self, 0);
	_tmp2_ = list_box;
	gtk_list_box_set_header_func (_tmp2_, _contacts_addressbook_list_list_box_update_header_func_gtk_list_box_update_header_func, g_object_ref (self), g_object_unref);
	_tmp3_ = list_box;
	self->priv->listbox = _tmp3_;
	_tmp4_ = self->priv->listbox;
	adw_bin_set_child ((AdwBin*) self, (GtkWidget*) _tmp4_);
	_g_object_unref0 (list_box);
	return obj;
}

static void
contacts_addressbook_list_class_init (ContactsAddressbookListClass * klass,
                                      gpointer klass_data)
{
	contacts_addressbook_list_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ContactsAddressbookList_private_offset);
	G_OBJECT_CLASS (klass)->constructor = contacts_addressbook_list_constructor;
	G_OBJECT_CLASS (klass)->finalize = contacts_addressbook_list_finalize;
	contacts_addressbook_list_signals[CONTACTS_ADDRESSBOOK_LIST_ADDRESSBOOK_SELECTED_SIGNAL] = g_signal_new ("addressbook-selected", CONTACTS_TYPE_ADDRESSBOOK_LIST, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
contacts_addressbook_list_instance_init (ContactsAddressbookList * self,
                                         gpointer klass)
{
	self->priv = contacts_addressbook_list_get_instance_private (self);
	self->priv->marked_row = NULL;
}

static void
contacts_addressbook_list_finalize (GObject * obj)
{
	ContactsAddressbookList * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CONTACTS_TYPE_ADDRESSBOOK_LIST, ContactsAddressbookList);
	_g_object_unref0 (self->priv->store);
	_g_object_unref0 (self->priv->marked_row);
	G_OBJECT_CLASS (contacts_addressbook_list_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
contacts_addressbook_list_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ContactsAddressbookListClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) contacts_addressbook_list_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ContactsAddressbookList), 0, (GInstanceInitFunc) contacts_addressbook_list_instance_init, NULL };
	GType contacts_addressbook_list_type_id;
	contacts_addressbook_list_type_id = g_type_register_static (adw_bin_get_type (), "ContactsAddressbookList", &g_define_type_info, 0);
	ContactsAddressbookList_private_offset = g_type_add_instance_private (contacts_addressbook_list_type_id, sizeof (ContactsAddressbookListPrivate));
	return contacts_addressbook_list_type_id;
}

GType
contacts_addressbook_list_get_type (void)
{
	static volatile gsize contacts_addressbook_list_type_id__once = 0;
	if (g_once_init_enter (&contacts_addressbook_list_type_id__once)) {
		GType contacts_addressbook_list_type_id;
		contacts_addressbook_list_type_id = contacts_addressbook_list_get_type_once ();
		g_once_init_leave (&contacts_addressbook_list_type_id__once, contacts_addressbook_list_type_id);
	}
	return contacts_addressbook_list_type_id__once;
}

static inline gpointer
contacts_addressbook_row_get_instance_private (ContactsAddressbookRow* self)
{
	return G_STRUCT_MEMBER_P (self, ContactsAddressbookRow_private_offset);
}

ContactsAddressbookRow*
contacts_addressbook_row_construct (GType object_type,
                                    const gchar* title,
                                    const gchar* subtitle,
                                    GtkWidget* image)
{
	ContactsAddressbookRow * self = NULL;
	GtkImage* _tmp0_;
	GtkWidget* _tmp1_;
	GtkWidget* _tmp2_;
	g_return_val_if_fail (title != NULL, NULL);
	self = (ContactsAddressbookRow*) g_object_new (object_type, NULL);
	gtk_list_box_row_set_selectable ((GtkListBoxRow*) self, FALSE);
	if (image != NULL) {
		adw_action_row_add_prefix ((AdwActionRow*) self, image);
	}
	adw_preferences_row_set_title ((AdwPreferencesRow*) self, title);
	if (subtitle != NULL) {
		adw_action_row_set_subtitle ((AdwActionRow*) self, subtitle);
	}
	_tmp0_ = (GtkImage*) gtk_image_new_from_icon_name ("object-select-symbolic");
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->checkmark);
	self->priv->checkmark = (GtkWidget*) _tmp0_;
	_tmp1_ = self->priv->checkmark;
	g_object_set ((GObject*) _tmp1_, "margin-end", 6, "valign", GTK_ALIGN_CENTER, "halign", GTK_ALIGN_END, "vexpand", TRUE, "hexpand", TRUE, NULL);
	_tmp2_ = self->priv->checkmark;
	gtk_list_box_row_set_child ((GtkListBoxRow*) self, _tmp2_);
	return self;
}

ContactsAddressbookRow*
contacts_addressbook_row_new (const gchar* title,
                              const gchar* subtitle,
                              GtkWidget* image)
{
	return contacts_addressbook_row_construct (CONTACTS_TYPE_ADDRESSBOOK_ROW, title, subtitle, image);
}

void
contacts_addressbook_row_unselect (ContactsAddressbookRow* self)
{
	GtkWidget* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->checkmark;
	gtk_widget_hide (_tmp0_);
}

void
contacts_addressbook_row_select (ContactsAddressbookRow* self)
{
	GtkWidget* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->checkmark;
	gtk_widget_show (_tmp0_);
}

static void
contacts_addressbook_row_class_init (ContactsAddressbookRowClass * klass,
                                     gpointer klass_data)
{
	contacts_addressbook_row_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ContactsAddressbookRow_private_offset);
	G_OBJECT_CLASS (klass)->finalize = contacts_addressbook_row_finalize;
}

static void
contacts_addressbook_row_instance_init (ContactsAddressbookRow * self,
                                        gpointer klass)
{
	self->priv = contacts_addressbook_row_get_instance_private (self);
}

static void
contacts_addressbook_row_finalize (GObject * obj)
{
	ContactsAddressbookRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CONTACTS_TYPE_ADDRESSBOOK_ROW, ContactsAddressbookRow);
	_g_object_unref0 (self->priv->checkmark);
	G_OBJECT_CLASS (contacts_addressbook_row_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
contacts_addressbook_row_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ContactsAddressbookRowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) contacts_addressbook_row_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ContactsAddressbookRow), 0, (GInstanceInitFunc) contacts_addressbook_row_instance_init, NULL };
	GType contacts_addressbook_row_type_id;
	contacts_addressbook_row_type_id = g_type_register_static (adw_action_row_get_type (), "ContactsAddressbookRow", &g_define_type_info, 0);
	ContactsAddressbookRow_private_offset = g_type_add_instance_private (contacts_addressbook_row_type_id, sizeof (ContactsAddressbookRowPrivate));
	return contacts_addressbook_row_type_id;
}

GType
contacts_addressbook_row_get_type (void)
{
	static volatile gsize contacts_addressbook_row_type_id__once = 0;
	if (g_once_init_enter (&contacts_addressbook_row_type_id__once)) {
		GType contacts_addressbook_row_type_id;
		contacts_addressbook_row_type_id = contacts_addressbook_row_get_type_once ();
		g_once_init_leave (&contacts_addressbook_row_type_id__once, contacts_addressbook_row_type_id);
	}
	return contacts_addressbook_row_type_id__once;
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

