/* GuestGrid.c generated by valac 0.56.19, the Vala compiler
 * generated from GuestGrid.vala, do not modify */

/*
 * Copyright 2011-2020 elementary, Inc. (https://elementary.io)
 *
 * 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 3 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/>.
 *
 * Authored by: Jaap Broekhuizen
 */

#include <gtk/gtk.h>
#include <glib-object.h>
#include <libical-glib/libical-glib.h>
#include <folks/folks.h>
#include <handy.h>
#include <glib.h>
#include <granite.h>
#include <glib/gi18n-lib.h>
#include <stdlib.h>
#include <string.h>
#include <pango/pango.h>
#include <float.h>
#include <math.h>
#include <gio/gio.h>
#include <gee.h>

#define MAYA_VIEW_EVENT_EDITION_GUEST_GRID_ICON_SIZE 32
#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 MAYA_VIEW_EVENT_EDITION_TYPE_GUEST_GRID (maya_view_event_edition_guest_grid_get_type ())
#define MAYA_VIEW_EVENT_EDITION_GUEST_GRID(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MAYA_VIEW_EVENT_EDITION_TYPE_GUEST_GRID, MayaViewEventEditionGuestGrid))
#define MAYA_VIEW_EVENT_EDITION_GUEST_GRID_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MAYA_VIEW_EVENT_EDITION_TYPE_GUEST_GRID, MayaViewEventEditionGuestGridClass))
#define MAYA_VIEW_EVENT_EDITION_IS_GUEST_GRID(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MAYA_VIEW_EVENT_EDITION_TYPE_GUEST_GRID))
#define MAYA_VIEW_EVENT_EDITION_IS_GUEST_GRID_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MAYA_VIEW_EVENT_EDITION_TYPE_GUEST_GRID))
#define MAYA_VIEW_EVENT_EDITION_GUEST_GRID_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MAYA_VIEW_EVENT_EDITION_TYPE_GUEST_GRID, MayaViewEventEditionGuestGridClass))

typedef struct _MayaViewEventEditionGuestGrid MayaViewEventEditionGuestGrid;
typedef struct _MayaViewEventEditionGuestGridClass MayaViewEventEditionGuestGridClass;
typedef struct _MayaViewEventEditionGuestGridPrivate MayaViewEventEditionGuestGridPrivate;
enum  {
	MAYA_VIEW_EVENT_EDITION_GUEST_GRID_0_PROPERTY,
	MAYA_VIEW_EVENT_EDITION_GUEST_GRID_NUM_PROPERTIES
};
static GParamSpec* maya_view_event_edition_guest_grid_properties[MAYA_VIEW_EVENT_EDITION_GUEST_GRID_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))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
typedef struct _Block12Data Block12Data;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _MayaViewEventEditionGuestGridGetContactByMailData MayaViewEventEditionGuestGridGetContactByMailData;
enum  {
	MAYA_VIEW_EVENT_EDITION_GUEST_GRID_REMOVED_SIGNAL,
	MAYA_VIEW_EVENT_EDITION_GUEST_GRID_NUM_SIGNALS
};
static guint maya_view_event_edition_guest_grid_signals[MAYA_VIEW_EVENT_EDITION_GUEST_GRID_NUM_SIGNALS] = {0};

struct _MayaViewEventEditionGuestGrid {
	GtkGrid parent_instance;
	MayaViewEventEditionGuestGridPrivate * priv;
	ICalProperty* attendee;
};

struct _MayaViewEventEditionGuestGridClass {
	GtkGridClass parent_class;
};

struct _MayaViewEventEditionGuestGridPrivate {
	FolksIndividual* individual;
	GtkLabel* name_label;
	GtkLabel* mail_label;
	HdyAvatar* avatar;
};

struct _Block12Data {
	int _ref_count_;
	MayaViewEventEditionGuestGrid* self;
	gchar* mail_address;
	gpointer _async_data_;
};

struct _MayaViewEventEditionGuestGridGetContactByMailData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	MayaViewEventEditionGuestGrid* self;
	gchar* mail_address;
	Block12Data* _data12_;
	FolksIndividualAggregator* aggregator;
	FolksIndividualAggregator* _tmp0_;
	FolksIndividualAggregator* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	GeeMapIterator* map_iterator;
	FolksIndividualAggregator* _tmp4_;
	GeeMap* _tmp5_;
	GeeMap* _tmp6_;
	GeeMapIterator* _tmp7_;
	GeeMapIterator* _tmp8_;
	GeeIterator* _address_it;
	GeeMapIterator* _tmp9_;
	gpointer _tmp10_;
	FolksIndividual* _tmp11_;
	GeeSet* _tmp12_;
	GeeSet* _tmp13_;
	GeeIterator* _tmp14_;
	GeeIterator* _tmp15_;
	GeeIterator* _tmp16_;
	FolksEmailFieldDetails* address;
	GeeIterator* _tmp17_;
	gpointer _tmp18_;
	FolksEmailFieldDetails* _tmp19_;
	gconstpointer _tmp20_;
	gconstpointer _tmp21_;
	GeeMapIterator* _tmp22_;
	gpointer _tmp23_;
	FolksIndividual* _tmp24_;
	HdyAvatar* _tmp25_;
	FolksIndividual* _tmp26_;
	const gchar* _tmp27_;
	const gchar* _tmp28_;
	FolksIndividual* _tmp29_;
	GLoadableIcon* _tmp30_;
	GLoadableIcon* _tmp31_;
	HdyAvatar* _tmp32_;
	FolksIndividual* _tmp33_;
	GLoadableIcon* _tmp34_;
	GLoadableIcon* _tmp35_;
	gboolean _tmp36_;
	FolksIndividual* _tmp37_;
	const gchar* _tmp38_;
	const gchar* _tmp39_;
	FolksIndividual* _tmp40_;
	const gchar* _tmp41_;
	const gchar* _tmp42_;
	GtkLabel* _tmp43_;
	FolksIndividual* _tmp44_;
	const gchar* _tmp45_;
	const gchar* _tmp46_;
	gchar* _tmp47_;
	gchar* _tmp48_;
	GtkLabel* _tmp49_;
	ICalProperty* _tmp50_;
	const gchar* _tmp51_;
	gchar* _tmp52_;
	gchar* _tmp53_;
	FolksIndividualAggregator* _tmp54_;
	FolksIndividualAggregator* _tmp55_;
	GError* e;
	GError* _tmp56_;
	const gchar* _tmp57_;
	GError* _inner_error0_;
};

static gint MayaViewEventEditionGuestGrid_private_offset;
static gpointer maya_view_event_edition_guest_grid_parent_class = NULL;

VALA_EXTERN GType maya_view_event_edition_guest_grid_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MayaViewEventEditionGuestGrid, g_object_unref)
VALA_EXTERN MayaViewEventEditionGuestGrid* maya_view_event_edition_guest_grid_new (ICalProperty* attendee);
VALA_EXTERN MayaViewEventEditionGuestGrid* maya_view_event_edition_guest_grid_construct (GType object_type,
                                                                             ICalProperty* attendee);
static void maya_view_event_edition_guest_grid_get_contact_by_mail (MayaViewEventEditionGuestGrid* self,
                                                             const gchar* mail_address,
                                                             GAsyncReadyCallback _callback_,
                                                             gpointer _user_data_);
static void maya_view_event_edition_guest_grid_get_contact_by_mail_finish (MayaViewEventEditionGuestGrid* self,
                                                                    GAsyncResult* _res_);
static void __lambda17_ (MayaViewEventEditionGuestGrid* self);
static void ___lambda17__gtk_button_clicked (GtkButton* _sender,
                                      gpointer self);
static void maya_view_event_edition_guest_grid_get_contact_by_mail_data_free (gpointer _data);
static gboolean maya_view_event_edition_guest_grid_get_contact_by_mail_co (MayaViewEventEditionGuestGridGetContactByMailData* _data_);
static Block12Data* block12_data_ref (Block12Data* _data12_);
static void block12_data_unref (void * _userdata_);
static void ___lambda16_ (Block12Data* _data12_);
static void ____lambda16__g_object_notify (GObject* _sender,
                                    GParamSpec* pspec,
                                    gpointer self);
static void maya_view_event_edition_guest_grid_get_contact_by_mail_ready (GObject* source_object,
                                                                   GAsyncResult* _res_,
                                                                   gpointer _user_data_);
static void maya_view_event_edition_guest_grid_finalize (GObject * obj);
static GType maya_view_event_edition_guest_grid_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 gssize _vala_array_length (gpointer array);

static inline gpointer
maya_view_event_edition_guest_grid_get_instance_private (MayaViewEventEditionGuestGrid* self)
{
	return G_STRUCT_MEMBER_P (self, MayaViewEventEditionGuestGrid_private_offset);
}

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

static gchar*
string_replace (const gchar* self,
                const gchar* old,
                const gchar* replacement)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (old != NULL, NULL);
	g_return_val_if_fail (replacement != NULL, NULL);
	if ((*((gchar*) self)) == '\0') {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = (*((gchar*) old)) == '\0';
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = g_strcmp0 (old, replacement) == 0;
	}
	if (_tmp0_) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup (self);
		result = _tmp2_;
		return result;
	}
	{
		GRegex* regex = NULL;
		gchar* _tmp3_;
		gchar* _tmp4_;
		GRegex* _tmp5_;
		GRegex* _tmp6_;
		gchar* _tmp7_ = NULL;
		GRegex* _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		_tmp3_ = g_regex_escape_string (old, -1);
		_tmp4_ = _tmp3_;
		_tmp5_ = g_regex_new (_tmp4_, 0, 0, &_inner_error0_);
		_tmp6_ = _tmp5_;
		_g_free0 (_tmp4_);
		regex = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp8_ = regex;
		_tmp9_ = g_regex_replace_literal (_tmp8_, self, (gssize) -1, 0, replacement, 0, &_inner_error0_);
		_tmp7_ = _tmp9_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp10_ = _tmp7_;
		_tmp7_ = NULL;
		result = _tmp10_;
		_g_free0 (_tmp7_);
		_g_regex_unref0 (regex);
		return result;
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		g_clear_error (&_inner_error0_);
		g_assert_not_reached ();
	}
	__finally0:
	g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
	g_clear_error (&_inner_error0_);
	return NULL;
}

static void
__lambda17_ (MayaViewEventEditionGuestGrid* self)
{
	g_signal_emit (self, maya_view_event_edition_guest_grid_signals[MAYA_VIEW_EVENT_EDITION_GUEST_GRID_REMOVED_SIGNAL], 0);
	gtk_widget_hide ((GtkWidget*) self);
	gtk_widget_destroy ((GtkWidget*) self);
}

static void
___lambda17__gtk_button_clicked (GtkButton* _sender,
                                 gpointer self)
{
	__lambda17_ ((MayaViewEventEditionGuestGrid*) self);
}

MayaViewEventEditionGuestGrid*
maya_view_event_edition_guest_grid_construct (GType object_type,
                                              ICalProperty* attendee)
{
	MayaViewEventEditionGuestGrid * self = NULL;
	ICalProperty* _tmp0_;
	GtkLabel* status_label = NULL;
	GtkLabel* _tmp1_;
	GtkLabel* _tmp2_;
	GtkStyleContext* status_label_context = NULL;
	GtkLabel* _tmp3_;
	GtkStyleContext* _tmp4_;
	GtkStyleContext* _tmp5_;
	GtkStyleContext* _tmp6_;
	ICalParameter* parameter = NULL;
	ICalParameter* _tmp7_;
	ICalParameter* _tmp8_;
	gchar* mail = NULL;
	const gchar* _tmp16_;
	gchar* _tmp17_;
	gchar** _tmp18_;
	gchar** _tmp19_;
	gchar** _tmp20_;
	gint _tmp20__length1;
	const gchar* _tmp21_;
	gchar* _tmp22_;
	gchar* _tmp23_;
	GtkLabel* _tmp24_;
	GtkLabel* _tmp25_;
	GtkLabel* _tmp26_;
	gchar* _tmp27_;
	gchar* _tmp28_;
	GtkLabel* _tmp29_;
	GtkLabel* _tmp30_;
	GtkLabel* _tmp31_;
	GtkLabel* _tmp32_;
	GtkButton* remove_button = NULL;
	GtkButton* _tmp33_;
	const gchar* _tmp34_;
	gchar* _tmp35_;
	gchar* _tmp36_;
	GtkLabel* _tmp37_;
	const gchar* _tmp38_;
	const gchar* _tmp39_;
	HdyAvatar* _tmp40_;
	HdyAvatar* _tmp41_;
	GtkLabel* _tmp42_;
	GtkLabel* _tmp43_;
	GtkLabel* _tmp44_;
	g_return_val_if_fail (attendee != NULL, NULL);
	self = (MayaViewEventEditionGuestGrid*) g_object_new (object_type, NULL);
	_tmp0_ = i_cal_property_clone (attendee);
	_g_object_unref0 (self->attendee);
	self->attendee = _tmp0_;
	_g_object_unref0 (self->priv->individual);
	self->priv->individual = NULL;
	_tmp1_ = (GtkLabel*) gtk_label_new ("");
	g_object_ref_sink (_tmp1_);
	status_label = _tmp1_;
	_tmp2_ = status_label;
	gtk_label_set_justify (_tmp2_, GTK_JUSTIFY_RIGHT);
	_tmp3_ = status_label;
	_tmp4_ = gtk_widget_get_style_context ((GtkWidget*) _tmp3_);
	_tmp5_ = _g_object_ref0 (_tmp4_);
	status_label_context = _tmp5_;
	_tmp6_ = status_label_context;
	gtk_style_context_add_class (_tmp6_, GRANITE_STYLE_CLASS_H4_LABEL);
	_tmp7_ = i_cal_property_get_first_parameter (attendee, I_CAL_PARTSTAT_PARAMETER);
	_g_object_unref0 (parameter);
	parameter = _tmp7_;
	_tmp8_ = parameter;
	if (_tmp8_ != NULL) {
		ICalParameter* _tmp9_;
		_tmp9_ = parameter;
		switch (i_cal_parameter_get_partstat (_tmp9_)) {
			case I_CAL_PARTSTAT_ACCEPTED:
			{
				GtkLabel* _tmp10_;
				GtkStyleContext* _tmp11_;
				_tmp10_ = status_label;
				gtk_label_set_label (_tmp10_, _ ("Accepted"));
				_tmp11_ = status_label_context;
				gtk_style_context_add_class (_tmp11_, "success");
				break;
			}
			case I_CAL_PARTSTAT_DECLINED:
			{
				GtkLabel* _tmp12_;
				GtkStyleContext* _tmp13_;
				_tmp12_ = status_label;
				gtk_label_set_label (_tmp12_, _ ("Declined"));
				_tmp13_ = status_label_context;
				gtk_style_context_add_class (_tmp13_, GTK_STYLE_CLASS_ERROR);
				break;
			}
			case I_CAL_PARTSTAT_TENTATIVE:
			{
				GtkLabel* _tmp14_;
				GtkStyleContext* _tmp15_;
				_tmp14_ = status_label;
				gtk_label_set_label (_tmp14_, _ ("Maybe"));
				_tmp15_ = status_label_context;
				gtk_style_context_add_class (_tmp15_, GTK_STYLE_CLASS_ERROR);
				break;
			}
			default:
			{
				break;
			}
		}
	}
	_tmp16_ = i_cal_property_get_attendee (attendee);
	_tmp17_ = string_replace (_tmp16_, "mailto:", "");
	mail = _tmp17_;
	_tmp19_ = _tmp18_ = g_strsplit (mail, "@", 2);
	_tmp20_ = _tmp19_;
	_tmp20__length1 = _vala_array_length (_tmp18_);
	_tmp21_ = _tmp20_[0];
	_tmp22_ = g_markup_escape_text (_tmp21_, (gssize) -1);
	_tmp23_ = _tmp22_;
	_tmp24_ = (GtkLabel*) gtk_label_new (_tmp23_);
	g_object_ref_sink (_tmp24_);
	_g_object_unref0 (self->priv->name_label);
	self->priv->name_label = _tmp24_;
	_g_free0 (_tmp23_);
	_tmp20_ = (_vala_array_free (_tmp20_, _tmp20__length1, (GDestroyNotify) g_free), NULL);
	_tmp25_ = self->priv->name_label;
	gtk_label_set_ellipsize (_tmp25_, PANGO_ELLIPSIZE_MIDDLE);
	_tmp26_ = self->priv->name_label;
	gtk_label_set_xalign (_tmp26_, (gfloat) 0);
	_tmp27_ = g_markup_escape_text (mail, (gssize) -1);
	_tmp28_ = _tmp27_;
	_tmp29_ = (GtkLabel*) gtk_label_new (_tmp28_);
	g_object_ref_sink (_tmp29_);
	_g_object_unref0 (self->priv->mail_label);
	self->priv->mail_label = _tmp29_;
	_g_free0 (_tmp28_);
	_tmp30_ = self->priv->mail_label;
	gtk_label_set_ellipsize (_tmp30_, PANGO_ELLIPSIZE_MIDDLE);
	_tmp31_ = self->priv->mail_label;
	gtk_widget_set_hexpand ((GtkWidget*) _tmp31_, TRUE);
	_tmp32_ = self->priv->mail_label;
	gtk_label_set_xalign (_tmp32_, (gfloat) 0);
	_tmp33_ = (GtkButton*) gtk_button_new_from_icon_name ("edit-delete-symbolic", (GtkIconSize) GTK_ICON_SIZE_BUTTON);
	g_object_ref_sink (_tmp33_);
	remove_button = _tmp33_;
	gtk_button_set_relief (remove_button, GTK_RELIEF_NONE);
	gtk_widget_set_valign ((GtkWidget*) remove_button, GTK_ALIGN_CENTER);
	_tmp34_ = i_cal_property_get_attendee (attendee);
	_tmp35_ = string_replace (_tmp34_, "mailto:", "");
	_tmp36_ = _tmp35_;
	maya_view_event_edition_guest_grid_get_contact_by_mail (self, _tmp36_, NULL, NULL);
	_g_free0 (_tmp36_);
	_tmp37_ = self->priv->name_label;
	_tmp38_ = gtk_label_get_label (_tmp37_);
	_tmp39_ = _tmp38_;
	_tmp40_ = (HdyAvatar*) hdy_avatar_new (MAYA_VIEW_EVENT_EDITION_GUEST_GRID_ICON_SIZE, _tmp39_, TRUE);
	g_object_ref_sink (_tmp40_);
	_g_object_unref0 (self->priv->avatar);
	self->priv->avatar = _tmp40_;
	gtk_grid_set_column_spacing ((GtkGrid*) self, 12);
	g_object_set ((GtkWidget*) self, "margin", 6, NULL);
	_tmp41_ = self->priv->avatar;
	gtk_grid_attach ((GtkGrid*) self, (GtkWidget*) _tmp41_, 0, 0, 1, 4);
	_tmp42_ = self->priv->name_label;
	gtk_grid_attach ((GtkGrid*) self, (GtkWidget*) _tmp42_, 1, 1, 1, 1);
	_tmp43_ = self->priv->mail_label;
	gtk_grid_attach ((GtkGrid*) self, (GtkWidget*) _tmp43_, 1, 2, 1, 1);
	_tmp44_ = status_label;
	gtk_grid_attach ((GtkGrid*) self, (GtkWidget*) _tmp44_, 2, 1, 1, 2);
	gtk_grid_attach ((GtkGrid*) self, (GtkWidget*) remove_button, 3, 1, 1, 2);
	g_signal_connect_object (remove_button, "clicked", (GCallback) ___lambda17__gtk_button_clicked, self, 0);
	_g_object_unref0 (remove_button);
	_g_free0 (mail);
	_g_object_unref0 (parameter);
	_g_object_unref0 (status_label_context);
	_g_object_unref0 (status_label);
	return self;
}

MayaViewEventEditionGuestGrid*
maya_view_event_edition_guest_grid_new (ICalProperty* attendee)
{
	return maya_view_event_edition_guest_grid_construct (MAYA_VIEW_EVENT_EDITION_TYPE_GUEST_GRID, attendee);
}

static void
maya_view_event_edition_guest_grid_get_contact_by_mail_data_free (gpointer _data)
{
	MayaViewEventEditionGuestGridGetContactByMailData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (MayaViewEventEditionGuestGridGetContactByMailData, _data_);
}

static void
maya_view_event_edition_guest_grid_get_contact_by_mail (MayaViewEventEditionGuestGrid* self,
                                                        const gchar* mail_address,
                                                        GAsyncReadyCallback _callback_,
                                                        gpointer _user_data_)
{
	MayaViewEventEditionGuestGridGetContactByMailData* _data_;
	MayaViewEventEditionGuestGrid* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (mail_address != NULL);
	_data_ = g_slice_new0 (MayaViewEventEditionGuestGridGetContactByMailData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, maya_view_event_edition_guest_grid_get_contact_by_mail_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = g_strdup (mail_address);
	_g_free0 (_data_->mail_address);
	_data_->mail_address = _tmp1_;
	maya_view_event_edition_guest_grid_get_contact_by_mail_co (_data_);
}

static void
maya_view_event_edition_guest_grid_get_contact_by_mail_finish (MayaViewEventEditionGuestGrid* self,
                                                               GAsyncResult* _res_)
{
	MayaViewEventEditionGuestGridGetContactByMailData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static Block12Data*
block12_data_ref (Block12Data* _data12_)
{
	g_atomic_int_inc (&_data12_->_ref_count_);
	return _data12_;
}

static void
block12_data_unref (void * _userdata_)
{
	Block12Data* _data12_;
	_data12_ = (Block12Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data12_->_ref_count_)) {
		MayaViewEventEditionGuestGrid* self;
		self = _data12_->self;
		_g_free0 (_data12_->mail_address);
		_g_object_unref0 (self);
		g_slice_free (Block12Data, _data12_);
	}
}

static void
___lambda16_ (Block12Data* _data12_)
{
	MayaViewEventEditionGuestGrid* self;
	self = _data12_->self;
	maya_view_event_edition_guest_grid_get_contact_by_mail (self, _data12_->mail_address, NULL, NULL);
}

static void
____lambda16__g_object_notify (GObject* _sender,
                               GParamSpec* pspec,
                               gpointer self)
{
	___lambda16_ (self);
}

static void
maya_view_event_edition_guest_grid_get_contact_by_mail_ready (GObject* source_object,
                                                              GAsyncResult* _res_,
                                                              gpointer _user_data_)
{
	MayaViewEventEditionGuestGridGetContactByMailData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	maya_view_event_edition_guest_grid_get_contact_by_mail_co (_data_);
}

static gboolean
maya_view_event_edition_guest_grid_get_contact_by_mail_co (MayaViewEventEditionGuestGridGetContactByMailData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data12_ = g_slice_new0 (Block12Data);
	_data_->_data12_->_ref_count_ = 1;
	_data_->_data12_->self = g_object_ref (_data_->self);
	_g_free0 (_data_->_data12_->mail_address);
	_data_->_data12_->mail_address = _data_->mail_address;
	_data_->_data12_->_async_data_ = _data_;
	_data_->_tmp0_ = folks_individual_aggregator_dup ();
	_data_->aggregator = _data_->_tmp0_;
	_data_->_tmp1_ = _data_->aggregator;
	_data_->_tmp2_ = folks_individual_aggregator_get_is_prepared (_data_->_tmp1_);
	_data_->_tmp3_ = _data_->_tmp2_;
	if (_data_->_tmp3_) {
		_data_->_tmp4_ = _data_->aggregator;
		_data_->_tmp5_ = folks_individual_aggregator_get_individuals (_data_->_tmp4_);
		_data_->_tmp6_ = _data_->_tmp5_;
		_data_->_tmp7_ = gee_map_map_iterator (_data_->_tmp6_);
		_g_object_unref0 (_data_->map_iterator);
		_data_->map_iterator = _data_->_tmp7_;
		while (TRUE) {
			_data_->_tmp8_ = _data_->map_iterator;
			if (!gee_map_iterator_next (_data_->_tmp8_)) {
				break;
			}
			{
				_data_->_tmp9_ = _data_->map_iterator;
				_data_->_tmp10_ = gee_map_iterator_get_value (_data_->_tmp9_);
				_data_->_tmp11_ = (FolksIndividual*) _data_->_tmp10_;
				_data_->_tmp12_ = folks_email_details_get_email_addresses ((FolksEmailDetails*) _data_->_tmp11_);
				_data_->_tmp13_ = _data_->_tmp12_;
				_data_->_tmp14_ = gee_iterable_iterator ((GeeIterable*) _data_->_tmp13_);
				_data_->_tmp15_ = _data_->_tmp14_;
				_g_object_unref0 (_data_->_tmp11_);
				_data_->_address_it = _data_->_tmp15_;
				while (TRUE) {
					_data_->_tmp16_ = _data_->_address_it;
					if (!gee_iterator_next (_data_->_tmp16_)) {
						break;
					}
					_data_->_tmp17_ = _data_->_address_it;
					_data_->_tmp18_ = gee_iterator_get (_data_->_tmp17_);
					_data_->address = (FolksEmailFieldDetails*) _data_->_tmp18_;
					_data_->_tmp19_ = _data_->address;
					_data_->_tmp20_ = folks_abstract_field_details_get_value ((FolksAbstractFieldDetails*) _data_->_tmp19_);
					_data_->_tmp21_ = _data_->_tmp20_;
					if (g_strcmp0 ((const gchar*) _data_->_tmp21_, _data_->_data12_->mail_address) == 0) {
						_data_->_tmp22_ = _data_->map_iterator;
						_data_->_tmp23_ = gee_map_iterator_get_value (_data_->_tmp22_);
						_g_object_unref0 (_data_->self->priv->individual);
						_data_->self->priv->individual = (FolksIndividual*) _data_->_tmp23_;
						_data_->_tmp24_ = _data_->self->priv->individual;
						if (_data_->_tmp24_ != NULL) {
							_data_->_tmp25_ = _data_->self->priv->avatar;
							_data_->_tmp26_ = _data_->self->priv->individual;
							_data_->_tmp27_ = folks_individual_get_display_name (_data_->_tmp26_);
							_data_->_tmp28_ = _data_->_tmp27_;
							hdy_avatar_set_text (_data_->_tmp25_, _data_->_tmp28_);
							_data_->_tmp29_ = _data_->self->priv->individual;
							_data_->_tmp30_ = folks_avatar_details_get_avatar ((FolksAvatarDetails*) _data_->_tmp29_);
							_data_->_tmp31_ = _data_->_tmp30_;
							if (_data_->_tmp31_ != NULL) {
								_data_->_tmp32_ = _data_->self->priv->avatar;
								_data_->_tmp33_ = _data_->self->priv->individual;
								_data_->_tmp34_ = folks_avatar_details_get_avatar ((FolksAvatarDetails*) _data_->_tmp33_);
								_data_->_tmp35_ = _data_->_tmp34_;
								hdy_avatar_set_loadable_icon (_data_->_tmp32_, _data_->_tmp35_);
							}
							_data_->_tmp37_ = _data_->self->priv->individual;
							_data_->_tmp38_ = folks_name_details_get_full_name ((FolksNameDetails*) _data_->_tmp37_);
							_data_->_tmp39_ = _data_->_tmp38_;
							if (_data_->_tmp39_ != NULL) {
								_data_->_tmp40_ = _data_->self->priv->individual;
								_data_->_tmp41_ = folks_name_details_get_full_name ((FolksNameDetails*) _data_->_tmp40_);
								_data_->_tmp42_ = _data_->_tmp41_;
								_data_->_tmp36_ = g_strcmp0 (_data_->_tmp42_, "") != 0;
							} else {
								_data_->_tmp36_ = FALSE;
							}
							if (_data_->_tmp36_) {
								_data_->_tmp43_ = _data_->self->priv->name_label;
								_data_->_tmp44_ = _data_->self->priv->individual;
								_data_->_tmp45_ = folks_name_details_get_full_name ((FolksNameDetails*) _data_->_tmp44_);
								_data_->_tmp46_ = _data_->_tmp45_;
								_data_->_tmp47_ = g_markup_escape_text (_data_->_tmp46_, (gssize) -1);
								_data_->_tmp48_ = _data_->_tmp47_;
								gtk_label_set_label (_data_->_tmp43_, _data_->_tmp48_);
								_g_free0 (_data_->_tmp48_);
								_data_->_tmp49_ = _data_->self->priv->mail_label;
								_data_->_tmp50_ = _data_->self->attendee;
								_data_->_tmp51_ = i_cal_property_get_attendee (_data_->_tmp50_);
								_data_->_tmp52_ = g_markup_escape_text (_data_->_tmp51_, (gssize) -1);
								_data_->_tmp53_ = _data_->_tmp52_;
								gtk_label_set_label (_data_->_tmp49_, _data_->_tmp53_);
								_g_free0 (_data_->_tmp53_);
							}
						}
					}
					_g_object_unref0 (_data_->address);
				}
				_g_object_unref0 (_data_->_address_it);
			}
		}
		_g_object_unref0 (_data_->map_iterator);
	} else {
		_data_->_tmp54_ = _data_->aggregator;
		g_signal_connect_data ((GObject*) _data_->_tmp54_, "notify::is-quiescent", (GCallback) ____lambda16__g_object_notify, block12_data_ref (_data_->_data12_), (GClosureNotify) block12_data_unref, 0);
		{
			_data_->_tmp55_ = _data_->aggregator;
			_data_->_state_ = 1;
			folks_individual_aggregator_prepare (_data_->_tmp55_, maya_view_event_edition_guest_grid_get_contact_by_mail_ready, _data_);
			return FALSE;
			_state_1:
			folks_individual_aggregator_prepare_finish (_data_->_tmp55_, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
		}
		goto __finally0;
		__catch0_g_error:
		{
			_data_->e = _data_->_inner_error0_;
			_data_->_inner_error0_ = NULL;
			_data_->_tmp56_ = _data_->e;
			_data_->_tmp57_ = _data_->_tmp56_->message;
			g_critical ("GuestGrid.vala:128: %s", _data_->_tmp57_);
			_g_error_free0 (_data_->e);
		}
		__finally0:
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->aggregator);
			block12_data_unref (_data_->_data12_);
			_data_->_data12_ = NULL;
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
			g_clear_error (&_data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	_g_object_unref0 (_data_->aggregator);
	block12_data_unref (_data_->_data12_);
	_data_->_data12_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
maya_view_event_edition_guest_grid_class_init (MayaViewEventEditionGuestGridClass * klass,
                                               gpointer klass_data)
{
	maya_view_event_edition_guest_grid_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &MayaViewEventEditionGuestGrid_private_offset);
	G_OBJECT_CLASS (klass)->finalize = maya_view_event_edition_guest_grid_finalize;
	maya_view_event_edition_guest_grid_signals[MAYA_VIEW_EVENT_EDITION_GUEST_GRID_REMOVED_SIGNAL] = g_signal_new ("removed", MAYA_VIEW_EVENT_EDITION_TYPE_GUEST_GRID, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
maya_view_event_edition_guest_grid_instance_init (MayaViewEventEditionGuestGrid * self,
                                                  gpointer klass)
{
	self->priv = maya_view_event_edition_guest_grid_get_instance_private (self);
}

static void
maya_view_event_edition_guest_grid_finalize (GObject * obj)
{
	MayaViewEventEditionGuestGrid * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, MAYA_VIEW_EVENT_EDITION_TYPE_GUEST_GRID, MayaViewEventEditionGuestGrid);
	_g_object_unref0 (self->attendee);
	_g_object_unref0 (self->priv->individual);
	_g_object_unref0 (self->priv->name_label);
	_g_object_unref0 (self->priv->mail_label);
	_g_object_unref0 (self->priv->avatar);
	G_OBJECT_CLASS (maya_view_event_edition_guest_grid_parent_class)->finalize (obj);
}

static GType
maya_view_event_edition_guest_grid_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (MayaViewEventEditionGuestGridClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) maya_view_event_edition_guest_grid_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MayaViewEventEditionGuestGrid), 0, (GInstanceInitFunc) maya_view_event_edition_guest_grid_instance_init, NULL };
	GType maya_view_event_edition_guest_grid_type_id;
	maya_view_event_edition_guest_grid_type_id = g_type_register_static (gtk_grid_get_type (), "MayaViewEventEditionGuestGrid", &g_define_type_info, 0);
	MayaViewEventEditionGuestGrid_private_offset = g_type_add_instance_private (maya_view_event_edition_guest_grid_type_id, sizeof (MayaViewEventEditionGuestGridPrivate));
	return maya_view_event_edition_guest_grid_type_id;
}

GType
maya_view_event_edition_guest_grid_get_type (void)
{
	static volatile gsize maya_view_event_edition_guest_grid_type_id__once = 0;
	if (g_once_init_enter (&maya_view_event_edition_guest_grid_type_id__once)) {
		GType maya_view_event_edition_guest_grid_type_id;
		maya_view_event_edition_guest_grid_type_id = maya_view_event_edition_guest_grid_get_type_once ();
		g_once_init_leave (&maya_view_event_edition_guest_grid_type_id__once, maya_view_event_edition_guest_grid_type_id);
	}
	return maya_view_event_edition_guest_grid_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);
}

static gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

