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

#include <adwaita.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <json-glib/json-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 DC_TYPE_CONTACT_PICKER_DIALOG (dc_contact_picker_dialog_get_type ())
#define DC_CONTACT_PICKER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_CONTACT_PICKER_DIALOG, DcContactPickerDialog))
#define DC_CONTACT_PICKER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_CONTACT_PICKER_DIALOG, DcContactPickerDialogClass))
#define DC_IS_CONTACT_PICKER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_CONTACT_PICKER_DIALOG))
#define DC_IS_CONTACT_PICKER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_CONTACT_PICKER_DIALOG))
#define DC_CONTACT_PICKER_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_CONTACT_PICKER_DIALOG, DcContactPickerDialogClass))

typedef struct _DcContactPickerDialog DcContactPickerDialog;
typedef struct _DcContactPickerDialogClass DcContactPickerDialogClass;
typedef struct _DcContactPickerDialogPrivate DcContactPickerDialogPrivate;

#define DC_TYPE_RPC_CLIENT (dc_rpc_client_get_type ())
#define DC_RPC_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_RPC_CLIENT, DcRpcClient))
#define DC_RPC_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_RPC_CLIENT, DcRpcClientClass))
#define DC_IS_RPC_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_RPC_CLIENT))
#define DC_IS_RPC_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_RPC_CLIENT))
#define DC_RPC_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_RPC_CLIENT, DcRpcClientClass))

typedef struct _DcRpcClient DcRpcClient;
typedef struct _DcRpcClientClass DcRpcClientClass;

#define DC_TYPE_CONTACT (dc_contact_get_type ())
#define DC_CONTACT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_CONTACT, DcContact))
#define DC_CONTACT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_CONTACT, DcContactClass))
#define DC_IS_CONTACT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_CONTACT))
#define DC_IS_CONTACT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_CONTACT))
#define DC_CONTACT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_CONTACT, DcContactClass))

typedef struct _DcContact DcContact;
typedef struct _DcContactClass DcContactClass;
enum  {
	DC_CONTACT_PICKER_DIALOG_0_PROPERTY,
	DC_CONTACT_PICKER_DIALOG_NUM_PROPERTIES
};
static GParamSpec* dc_contact_picker_dialog_properties[DC_CONTACT_PICKER_DIALOG_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_ptr_array_unref0(var) ((var == NULL) ? NULL : (var = (g_ptr_array_unref (var), NULL)))
#define _json_array_unref0(var) ((var == NULL) ? NULL : (var = (json_array_unref (var), NULL)))
#define _json_object_unref0(var) ((var == NULL) ? NULL : (var = (json_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _DcContactPickerDialogLoadContactsData DcContactPickerDialogLoadContactsData;

#define DC_TYPE_CHAT_ENTRY (dc_chat_entry_get_type ())
#define DC_CHAT_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_CHAT_ENTRY, DcChatEntry))
#define DC_CHAT_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_CHAT_ENTRY, DcChatEntryClass))
#define DC_IS_CHAT_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_CHAT_ENTRY))
#define DC_IS_CHAT_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_CHAT_ENTRY))
#define DC_CHAT_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_CHAT_ENTRY, DcChatEntryClass))

typedef struct _DcChatEntry DcChatEntry;
typedef struct _DcChatEntryClass DcChatEntryClass;
enum  {
	DC_CONTACT_PICKER_DIALOG_CONTACT_PICKED_SIGNAL,
	DC_CONTACT_PICKER_DIALOG_CHAT_PICKED_SIGNAL,
	DC_CONTACT_PICKER_DIALOG_NUM_SIGNALS
};
static guint dc_contact_picker_dialog_signals[DC_CONTACT_PICKER_DIALOG_NUM_SIGNALS] = {0};

struct _DcContactPickerDialog {
	AdwDialog parent_instance;
	DcContactPickerDialogPrivate * priv;
};

struct _DcContactPickerDialogClass {
	AdwDialogClass parent_class;
};

struct _DcContactPickerDialogPrivate {
	DcRpcClient* rpc;
	GListStore* chat_store;
	GtkSearchEntry* search_entry;
	GtkListBox* chat_listbox;
	GtkListBox* contact_listbox;
	GtkLabel* chats_header;
	GtkLabel* contacts_header;
	GtkButton* use_email_btn;
	GPtrArray* all_contacts;
};

struct _DcContactPickerDialogLoadContactsData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcContactPickerDialog* self;
	JsonArray* ids;
	DcRpcClient* _tmp0_;
	DcRpcClient* _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	JsonArray* _tmp4_;
	JsonArray* _tmp5_;
	guint i;
	gboolean _tmp6_;
	guint _tmp7_;
	JsonArray* _tmp8_;
	gint cid;
	JsonArray* _tmp9_;
	JsonObject* obj;
	DcRpcClient* _tmp10_;
	DcRpcClient* _tmp11_;
	gint _tmp12_;
	gint _tmp13_;
	JsonObject* _tmp14_;
	JsonObject* _tmp15_;
	DcContact* ci;
	JsonObject* _tmp16_;
	DcContact* _tmp17_;
	DcContact* _tmp18_;
	const gchar* _tmp19_;
	const gchar* _tmp20_;
	gint _tmp21_;
	gint _tmp22_;
	GPtrArray* _tmp23_;
	DcContact* _tmp24_;
	DcContact* _tmp25_;
	GError* e;
	GtkLabel* lbl;
	GError* _tmp26_;
	const gchar* _tmp27_;
	gchar* _tmp28_;
	gchar* _tmp29_;
	GtkLabel* _tmp30_;
	GtkLabel* _tmp31_;
	GtkLabel* _tmp32_;
	GtkLabel* _tmp33_;
	GtkListBox* _tmp34_;
	GtkLabel* _tmp35_;
	GError* _inner_error0_;
};

static gint DcContactPickerDialog_private_offset;
static gpointer dc_contact_picker_dialog_parent_class = NULL;

VALA_EXTERN GType dc_contact_picker_dialog_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcContactPickerDialog, g_object_unref)
VALA_EXTERN GType dc_rpc_client_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcRpcClient, g_object_unref)
VALA_EXTERN GType dc_contact_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcContact, g_object_unref)
static void _g_object_unref0_ (gpointer var);
VALA_EXTERN DcContactPickerDialog* dc_contact_picker_dialog_new (DcRpcClient* rpc,
                                                     GListStore* chat_store,
                                                     const gchar* title);
VALA_EXTERN DcContactPickerDialog* dc_contact_picker_dialog_construct (GType object_type,
                                                           DcRpcClient* rpc,
                                                           GListStore* chat_store,
                                                           const gchar* title);
static void dc_contact_picker_dialog_on_search_changed (DcContactPickerDialog* self);
static void _dc_contact_picker_dialog_on_search_changed_gtk_search_entry_search_changed (GtkSearchEntry* _sender,
                                                                                  gpointer self);
static void dc_contact_picker_dialog_on_activate_search (DcContactPickerDialog* self);
static void _dc_contact_picker_dialog_on_activate_search_gtk_search_entry_activate (GtkSearchEntry* _sender,
                                                                             gpointer self);
static void dc_contact_picker_dialog_on_use_email (DcContactPickerDialog* self);
static void _dc_contact_picker_dialog_on_use_email_gtk_button_clicked (GtkButton* _sender,
                                                                gpointer self);
static void dc_contact_picker_dialog_on_chat_row_activated (DcContactPickerDialog* self,
                                                     GtkListBoxRow* row);
static void _dc_contact_picker_dialog_on_chat_row_activated_gtk_list_box_row_activated (GtkListBox* _sender,
                                                                                 GtkListBoxRow* row,
                                                                                 gpointer self);
static void dc_contact_picker_dialog_on_contact_row_activated (DcContactPickerDialog* self,
                                                        GtkListBoxRow* row);
static void _dc_contact_picker_dialog_on_contact_row_activated_gtk_list_box_row_activated (GtkListBox* _sender,
                                                                                    GtkListBoxRow* row,
                                                                                    gpointer self);
VALA_EXTERN void dc_install_escape_close (AdwDialog* dialog);
static void dc_contact_picker_dialog_load_contacts (DcContactPickerDialog* self,
                                             GAsyncReadyCallback _callback_,
                                             gpointer _user_data_);
static void dc_contact_picker_dialog_load_contacts_finish (DcContactPickerDialog* self,
                                                    GAsyncResult* _res_);
static void dc_contact_picker_dialog_rebuild_chat_list (DcContactPickerDialog* self,
                                                 const gchar* query);
static void dc_contact_picker_dialog_load_contacts_data_free (gpointer _data);
static gboolean dc_contact_picker_dialog_load_contacts_co (DcContactPickerDialogLoadContactsData* _data_);
VALA_EXTERN void dc_rpc_client_get_contact_ids_for (DcRpcClient* self,
                                        gint acct_id,
                                        const gchar* query,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_);
VALA_EXTERN JsonArray* dc_rpc_client_get_contact_ids_for_finish (DcRpcClient* self,
                                                     GAsyncResult* _res_,
                                                     GError** error);
VALA_EXTERN gint dc_rpc_client_get_account_id (DcRpcClient* self);
static void dc_contact_picker_dialog_load_contacts_ready (GObject* source_object,
                                                   GAsyncResult* _res_,
                                                   gpointer _user_data_);
VALA_EXTERN void dc_rpc_client_get_contact_for (DcRpcClient* self,
                                    gint acct_id,
                                    gint contact_id,
                                    GAsyncReadyCallback _callback_,
                                    gpointer _user_data_);
VALA_EXTERN JsonObject* dc_rpc_client_get_contact_for_finish (DcRpcClient* self,
                                                  GAsyncResult* _res_,
                                                  GError** error);
VALA_EXTERN DcContact* dc_rpc_parsers_parse_contact (gint contact_id,
                                         JsonObject* obj);
VALA_EXTERN const gchar* dc_contact_get_address (DcContact* self);
static void dc_contact_picker_dialog_rebuild_contact_list (DcContactPickerDialog* self,
                                                    const gchar* query);
VALA_EXTERN void dc_clear_listbox (GtkListBox* lb);
VALA_EXTERN const gchar* dc_contact_get_display_name (DcContact* self);
static AdwActionRow* dc_contact_picker_dialog_build_contact_row (DcContactPickerDialog* self,
                                                          DcContact* ci);
VALA_EXTERN GType dc_chat_entry_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcChatEntry, g_object_unref)
VALA_EXTERN const gchar* dc_chat_entry_get_name (DcChatEntry* self);
VALA_EXTERN AdwActionRow* dc_chat_pick_row (DcChatEntry* chat);
VALA_EXTERN AdwActionRow* dc_contact_row (DcContact* c,
                              gboolean activatable,
                              gboolean show_presence);
VALA_EXTERN gint dc_contact_get_id (DcContact* self);
static void g_cclosure_user_marshal_VOID__INT_STRING (GClosure * closure,
                                               GValue * return_value,
                                               guint n_param_values,
                                               const GValue * param_values,
                                               gpointer invocation_hint,
                                               gpointer marshal_data);
static void dc_contact_picker_dialog_finalize (GObject * obj);
static GType dc_contact_picker_dialog_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 _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
dc_contact_picker_dialog_get_instance_private (DcContactPickerDialog* self)
{
	return G_STRUCT_MEMBER_P (self, DcContactPickerDialog_private_offset);
}

static void
_g_object_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}

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

static void
_dc_contact_picker_dialog_on_search_changed_gtk_search_entry_search_changed (GtkSearchEntry* _sender,
                                                                             gpointer self)
{
	dc_contact_picker_dialog_on_search_changed ((DcContactPickerDialog*) self);
}

static void
_dc_contact_picker_dialog_on_activate_search_gtk_search_entry_activate (GtkSearchEntry* _sender,
                                                                        gpointer self)
{
	dc_contact_picker_dialog_on_activate_search ((DcContactPickerDialog*) self);
}

static void
_dc_contact_picker_dialog_on_use_email_gtk_button_clicked (GtkButton* _sender,
                                                           gpointer self)
{
	dc_contact_picker_dialog_on_use_email ((DcContactPickerDialog*) self);
}

static void
_dc_contact_picker_dialog_on_chat_row_activated_gtk_list_box_row_activated (GtkListBox* _sender,
                                                                            GtkListBoxRow* row,
                                                                            gpointer self)
{
	dc_contact_picker_dialog_on_chat_row_activated ((DcContactPickerDialog*) self, row);
}

static void
_dc_contact_picker_dialog_on_contact_row_activated_gtk_list_box_row_activated (GtkListBox* _sender,
                                                                               GtkListBoxRow* row,
                                                                               gpointer self)
{
	dc_contact_picker_dialog_on_contact_row_activated ((DcContactPickerDialog*) self, row);
}

DcContactPickerDialog*
dc_contact_picker_dialog_construct (GType object_type,
                                    DcRpcClient* rpc,
                                    GListStore* chat_store,
                                    const gchar* title)
{
	DcContactPickerDialog * self = NULL;
	DcRpcClient* _tmp0_;
	GListStore* _tmp1_;
	const gchar* _tmp2_ = NULL;
	GtkBox* box = NULL;
	GtkBox* _tmp4_;
	AdwHeaderBar* header = NULL;
	AdwHeaderBar* _tmp5_;
	AdwHeaderBar* _tmp6_;
	GtkBox* _tmp7_;
	AdwHeaderBar* _tmp8_;
	GtkBox* content = NULL;
	GtkBox* _tmp9_;
	GtkBox* _tmp10_;
	GtkBox* _tmp11_;
	GtkBox* _tmp12_;
	GtkBox* _tmp13_;
	GtkSearchEntry* _tmp14_;
	const gchar* _tmp15_ = NULL;
	GtkSearchEntry* _tmp16_;
	GtkSearchEntry* _tmp17_;
	GtkSearchEntry* _tmp18_;
	GtkSearchEntry* _tmp19_;
	GtkBox* _tmp20_;
	GtkSearchEntry* _tmp21_;
	GtkButton* _tmp22_;
	GtkButton* _tmp23_;
	GtkButton* _tmp24_;
	GtkButton* _tmp25_;
	GtkBox* _tmp26_;
	GtkButton* _tmp27_;
	GtkScrolledWindow* scroll = NULL;
	GtkScrolledWindow* _tmp28_;
	GtkScrolledWindow* _tmp29_;
	GtkScrolledWindow* _tmp30_;
	GtkBox* list_box = NULL;
	GtkBox* _tmp31_;
	GtkLabel* _tmp32_;
	GtkLabel* _tmp33_;
	GtkLabel* _tmp34_;
	GtkLabel* _tmp35_;
	GtkLabel* _tmp36_;
	GtkBox* _tmp37_;
	GtkLabel* _tmp38_;
	GtkListBox* _tmp39_;
	GtkListBox* _tmp40_;
	GtkListBox* _tmp41_;
	GtkListBox* _tmp42_;
	GtkListBox* _tmp43_;
	GtkBox* _tmp44_;
	GtkListBox* _tmp45_;
	GtkLabel* _tmp46_;
	GtkLabel* _tmp47_;
	GtkLabel* _tmp48_;
	GtkLabel* _tmp49_;
	GtkLabel* _tmp50_;
	GtkBox* _tmp51_;
	GtkLabel* _tmp52_;
	GtkListBox* _tmp53_;
	GtkListBox* _tmp54_;
	GtkListBox* _tmp55_;
	GtkListBox* _tmp56_;
	GtkBox* _tmp57_;
	GtkListBox* _tmp58_;
	GtkScrolledWindow* _tmp59_;
	GtkBox* _tmp60_;
	GtkBox* _tmp61_;
	GtkScrolledWindow* _tmp62_;
	GtkBox* _tmp63_;
	GtkBox* _tmp64_;
	GtkBox* _tmp65_;
	g_return_val_if_fail (rpc != NULL, NULL);
	self = (DcContactPickerDialog*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (rpc);
	_g_object_unref0 (self->priv->rpc);
	self->priv->rpc = _tmp0_;
	_tmp1_ = _g_object_ref0 (chat_store);
	_g_object_unref0 (self->priv->chat_store);
	self->priv->chat_store = _tmp1_;
	_tmp2_ = title;
	if (_tmp2_ == NULL) {
		const gchar* _tmp3_ = NULL;
		if (chat_store != NULL) {
			_tmp3_ = "Select Destination";
		} else {
			_tmp3_ = "Select Contact";
		}
		_tmp2_ = _tmp3_;
	}
	adw_dialog_set_title ((AdwDialog*) self, _tmp2_);
	adw_dialog_set_content_width ((AdwDialog*) self, 360);
	adw_dialog_set_content_height ((AdwDialog*) self, 500);
	_tmp4_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	g_object_ref_sink (_tmp4_);
	box = _tmp4_;
	_tmp5_ = (AdwHeaderBar*) adw_header_bar_new ();
	g_object_ref_sink (_tmp5_);
	header = _tmp5_;
	_tmp6_ = header;
	adw_header_bar_set_show_end_title_buttons (_tmp6_, TRUE);
	_tmp7_ = box;
	_tmp8_ = header;
	gtk_box_append (_tmp7_, (GtkWidget*) _tmp8_);
	_tmp9_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
	g_object_ref_sink (_tmp9_);
	content = _tmp9_;
	_tmp10_ = content;
	gtk_widget_set_margin_start ((GtkWidget*) _tmp10_, 12);
	_tmp11_ = content;
	gtk_widget_set_margin_end ((GtkWidget*) _tmp11_, 12);
	_tmp12_ = content;
	gtk_widget_set_margin_top ((GtkWidget*) _tmp12_, 8);
	_tmp13_ = content;
	gtk_widget_set_margin_bottom ((GtkWidget*) _tmp13_, 12);
	_tmp14_ = (GtkSearchEntry*) gtk_search_entry_new ();
	g_object_ref_sink (_tmp14_);
	_g_object_unref0 (self->priv->search_entry);
	self->priv->search_entry = _tmp14_;
	if (chat_store != NULL) {
		_tmp15_ = "Search chats, contacts or enter email\u2026";
	} else {
		_tmp15_ = "Search or enter email\u2026";
	}
	_tmp16_ = self->priv->search_entry;
	g_object_set (_tmp16_, "placeholder-text", _tmp15_, NULL);
	_tmp17_ = self->priv->search_entry;
	gtk_widget_set_hexpand ((GtkWidget*) _tmp17_, TRUE);
	_tmp18_ = self->priv->search_entry;
	g_signal_connect_object (_tmp18_, "search-changed", (GCallback) _dc_contact_picker_dialog_on_search_changed_gtk_search_entry_search_changed, self, 0);
	_tmp19_ = self->priv->search_entry;
	g_signal_connect_object (_tmp19_, "activate", (GCallback) _dc_contact_picker_dialog_on_activate_search_gtk_search_entry_activate, self, 0);
	_tmp20_ = content;
	_tmp21_ = self->priv->search_entry;
	gtk_box_append (_tmp20_, (GtkWidget*) _tmp21_);
	_tmp22_ = (GtkButton*) gtk_button_new ();
	g_object_ref_sink (_tmp22_);
	_g_object_unref0 (self->priv->use_email_btn);
	self->priv->use_email_btn = _tmp22_;
	_tmp23_ = self->priv->use_email_btn;
	gtk_widget_add_css_class ((GtkWidget*) _tmp23_, "suggested-action");
	_tmp24_ = self->priv->use_email_btn;
	gtk_widget_set_visible ((GtkWidget*) _tmp24_, FALSE);
	_tmp25_ = self->priv->use_email_btn;
	g_signal_connect_object (_tmp25_, "clicked", (GCallback) _dc_contact_picker_dialog_on_use_email_gtk_button_clicked, self, 0);
	_tmp26_ = content;
	_tmp27_ = self->priv->use_email_btn;
	gtk_box_append (_tmp26_, (GtkWidget*) _tmp27_);
	_tmp28_ = (GtkScrolledWindow*) gtk_scrolled_window_new ();
	g_object_ref_sink (_tmp28_);
	scroll = _tmp28_;
	_tmp29_ = scroll;
	gtk_widget_set_vexpand ((GtkWidget*) _tmp29_, TRUE);
	_tmp30_ = scroll;
	g_object_set (_tmp30_, "hscrollbar-policy", GTK_POLICY_NEVER, NULL);
	_tmp31_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
	g_object_ref_sink (_tmp31_);
	list_box = _tmp31_;
	_tmp32_ = (GtkLabel*) gtk_label_new ("Chats");
	g_object_ref_sink (_tmp32_);
	_g_object_unref0 (self->priv->chats_header);
	self->priv->chats_header = _tmp32_;
	_tmp33_ = self->priv->chats_header;
	gtk_widget_add_css_class ((GtkWidget*) _tmp33_, "heading");
	_tmp34_ = self->priv->chats_header;
	gtk_widget_add_css_class ((GtkWidget*) _tmp34_, "dim-label");
	_tmp35_ = self->priv->chats_header;
	gtk_widget_set_halign ((GtkWidget*) _tmp35_, GTK_ALIGN_START);
	_tmp36_ = self->priv->chats_header;
	gtk_widget_set_visible ((GtkWidget*) _tmp36_, FALSE);
	_tmp37_ = list_box;
	_tmp38_ = self->priv->chats_header;
	gtk_box_append (_tmp37_, (GtkWidget*) _tmp38_);
	_tmp39_ = (GtkListBox*) gtk_list_box_new ();
	g_object_ref_sink (_tmp39_);
	_g_object_unref0 (self->priv->chat_listbox);
	self->priv->chat_listbox = _tmp39_;
	_tmp40_ = self->priv->chat_listbox;
	gtk_list_box_set_selection_mode (_tmp40_, GTK_SELECTION_NONE);
	_tmp41_ = self->priv->chat_listbox;
	gtk_widget_add_css_class ((GtkWidget*) _tmp41_, "boxed-list");
	_tmp42_ = self->priv->chat_listbox;
	g_signal_connect_object (_tmp42_, "row-activated", (GCallback) _dc_contact_picker_dialog_on_chat_row_activated_gtk_list_box_row_activated, self, 0);
	_tmp43_ = self->priv->chat_listbox;
	gtk_widget_set_visible ((GtkWidget*) _tmp43_, FALSE);
	_tmp44_ = list_box;
	_tmp45_ = self->priv->chat_listbox;
	gtk_box_append (_tmp44_, (GtkWidget*) _tmp45_);
	_tmp46_ = (GtkLabel*) gtk_label_new ("Contacts");
	g_object_ref_sink (_tmp46_);
	_g_object_unref0 (self->priv->contacts_header);
	self->priv->contacts_header = _tmp46_;
	_tmp47_ = self->priv->contacts_header;
	gtk_widget_add_css_class ((GtkWidget*) _tmp47_, "heading");
	_tmp48_ = self->priv->contacts_header;
	gtk_widget_add_css_class ((GtkWidget*) _tmp48_, "dim-label");
	_tmp49_ = self->priv->contacts_header;
	gtk_widget_set_halign ((GtkWidget*) _tmp49_, GTK_ALIGN_START);
	_tmp50_ = self->priv->contacts_header;
	gtk_widget_set_visible ((GtkWidget*) _tmp50_, chat_store != NULL);
	_tmp51_ = list_box;
	_tmp52_ = self->priv->contacts_header;
	gtk_box_append (_tmp51_, (GtkWidget*) _tmp52_);
	_tmp53_ = (GtkListBox*) gtk_list_box_new ();
	g_object_ref_sink (_tmp53_);
	_g_object_unref0 (self->priv->contact_listbox);
	self->priv->contact_listbox = _tmp53_;
	_tmp54_ = self->priv->contact_listbox;
	gtk_list_box_set_selection_mode (_tmp54_, GTK_SELECTION_NONE);
	_tmp55_ = self->priv->contact_listbox;
	gtk_widget_add_css_class ((GtkWidget*) _tmp55_, "boxed-list");
	_tmp56_ = self->priv->contact_listbox;
	g_signal_connect_object (_tmp56_, "row-activated", (GCallback) _dc_contact_picker_dialog_on_contact_row_activated_gtk_list_box_row_activated, self, 0);
	_tmp57_ = list_box;
	_tmp58_ = self->priv->contact_listbox;
	gtk_box_append (_tmp57_, (GtkWidget*) _tmp58_);
	_tmp59_ = scroll;
	_tmp60_ = list_box;
	gtk_scrolled_window_set_child (_tmp59_, (GtkWidget*) _tmp60_);
	_tmp61_ = content;
	_tmp62_ = scroll;
	gtk_box_append (_tmp61_, (GtkWidget*) _tmp62_);
	_tmp63_ = box;
	_tmp64_ = content;
	gtk_box_append (_tmp63_, (GtkWidget*) _tmp64_);
	_tmp65_ = box;
	adw_dialog_set_child ((AdwDialog*) self, (GtkWidget*) _tmp65_);
	dc_install_escape_close ((AdwDialog*) self);
	dc_contact_picker_dialog_load_contacts (self, NULL, NULL);
	if (chat_store != NULL) {
		dc_contact_picker_dialog_rebuild_chat_list (self, "");
	}
	_g_object_unref0 (list_box);
	_g_object_unref0 (scroll);
	_g_object_unref0 (content);
	_g_object_unref0 (header);
	_g_object_unref0 (box);
	return self;
}

DcContactPickerDialog*
dc_contact_picker_dialog_new (DcRpcClient* rpc,
                              GListStore* chat_store,
                              const gchar* title)
{
	return dc_contact_picker_dialog_construct (DC_TYPE_CONTACT_PICKER_DIALOG, rpc, chat_store, title);
}

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

static void
dc_contact_picker_dialog_load_contacts (DcContactPickerDialog* self,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_)
{
	DcContactPickerDialogLoadContactsData* _data_;
	DcContactPickerDialog* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (DcContactPickerDialogLoadContactsData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_contact_picker_dialog_load_contacts_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	dc_contact_picker_dialog_load_contacts_co (_data_);
}

static void
dc_contact_picker_dialog_load_contacts_finish (DcContactPickerDialog* self,
                                               GAsyncResult* _res_)
{
	DcContactPickerDialogLoadContactsData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
dc_contact_picker_dialog_load_contacts_ready (GObject* source_object,
                                              GAsyncResult* _res_,
                                              gpointer _user_data_)
{
	DcContactPickerDialogLoadContactsData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_contact_picker_dialog_load_contacts_co (_data_);
}

static gboolean
dc_contact_picker_dialog_load_contacts_co (DcContactPickerDialogLoadContactsData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	{
		_data_->_tmp0_ = _data_->self->priv->rpc;
		_data_->_tmp1_ = _data_->self->priv->rpc;
		_data_->_tmp2_ = dc_rpc_client_get_account_id (_data_->_tmp1_);
		_data_->_tmp3_ = _data_->_tmp2_;
		_data_->_state_ = 1;
		dc_rpc_client_get_contact_ids_for (_data_->_tmp0_, _data_->_tmp3_, NULL, dc_contact_picker_dialog_load_contacts_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp4_ = dc_rpc_client_get_contact_ids_for_finish (_data_->_tmp0_, _data_->_res_, &_data_->_inner_error0_);
		_data_->ids = _data_->_tmp4_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp5_ = _data_->ids;
		if (_data_->_tmp5_ == NULL) {
			_json_array_unref0 (_data_->ids);
			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;
		}
		{
			_data_->i = (guint) 0;
			{
				_data_->_tmp6_ = TRUE;
				while (TRUE) {
					if (!_data_->_tmp6_) {
						_data_->_tmp7_ = _data_->i;
						_data_->i = _data_->_tmp7_ + 1;
					}
					_data_->_tmp6_ = FALSE;
					_data_->_tmp8_ = _data_->ids;
					if (!(_data_->i < json_array_get_length (_data_->_tmp8_))) {
						break;
					}
					_data_->_tmp9_ = _data_->ids;
					_data_->cid = (gint) json_array_get_int_element (_data_->_tmp9_, _data_->i);
					if (_data_->cid <= 1) {
						continue;
					}
					_data_->_tmp10_ = _data_->self->priv->rpc;
					_data_->_tmp11_ = _data_->self->priv->rpc;
					_data_->_tmp12_ = dc_rpc_client_get_account_id (_data_->_tmp11_);
					_data_->_tmp13_ = _data_->_tmp12_;
					_data_->_state_ = 2;
					dc_rpc_client_get_contact_for (_data_->_tmp10_, _data_->_tmp13_, _data_->cid, dc_contact_picker_dialog_load_contacts_ready, _data_);
					return FALSE;
					_state_2:
					_data_->_tmp14_ = dc_rpc_client_get_contact_for_finish (_data_->_tmp10_, _data_->_res_, &_data_->_inner_error0_);
					_data_->obj = _data_->_tmp14_;
					if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
						_json_array_unref0 (_data_->ids);
						goto __catch0_g_error;
					}
					_data_->_tmp15_ = _data_->obj;
					if (_data_->_tmp15_ == NULL) {
						_json_object_unref0 (_data_->obj);
						continue;
					}
					_data_->_tmp16_ = _data_->obj;
					_data_->_tmp17_ = dc_rpc_parsers_parse_contact (_data_->cid, _data_->_tmp16_);
					_data_->ci = _data_->_tmp17_;
					_data_->_tmp18_ = _data_->ci;
					_data_->_tmp19_ = dc_contact_get_address (_data_->_tmp18_);
					_data_->_tmp20_ = _data_->_tmp19_;
					_data_->_tmp21_ = strlen (_data_->_tmp20_);
					_data_->_tmp22_ = _data_->_tmp21_;
					if (_data_->_tmp22_ == 0) {
						_g_object_unref0 (_data_->ci);
						_json_object_unref0 (_data_->obj);
						continue;
					}
					_data_->_tmp23_ = _data_->self->priv->all_contacts;
					_data_->_tmp24_ = _data_->ci;
					_data_->_tmp25_ = _g_object_ref0 (_data_->_tmp24_);
					g_ptr_array_add (_data_->_tmp23_, _data_->_tmp25_);
					_g_object_unref0 (_data_->ci);
					_json_object_unref0 (_data_->obj);
				}
			}
		}
		dc_contact_picker_dialog_rebuild_contact_list (_data_->self, "");
		_json_array_unref0 (_data_->ids);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp26_ = _data_->e;
		_data_->_tmp27_ = _data_->_tmp26_->message;
		_data_->_tmp28_ = g_strconcat ("Failed to load contacts: ", _data_->_tmp27_, NULL);
		_data_->_tmp29_ = _data_->_tmp28_;
		_data_->_tmp30_ = (GtkLabel*) gtk_label_new (_data_->_tmp29_);
		g_object_ref_sink (_data_->_tmp30_);
		_data_->_tmp31_ = _data_->_tmp30_;
		_g_free0 (_data_->_tmp29_);
		_data_->lbl = _data_->_tmp31_;
		_data_->_tmp32_ = _data_->lbl;
		gtk_widget_add_css_class ((GtkWidget*) _data_->_tmp32_, "dim-label");
		_data_->_tmp33_ = _data_->lbl;
		gtk_label_set_wrap (_data_->_tmp33_, TRUE);
		_data_->_tmp34_ = _data_->self->priv->contact_listbox;
		_data_->_tmp35_ = _data_->lbl;
		gtk_list_box_append (_data_->_tmp34_, (GtkWidget*) _data_->_tmp35_);
		_g_object_unref0 (_data_->lbl);
		_g_error_free0 (_data_->e);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != 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_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 gchar*
string_strip (const gchar* self)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	g_strstrip (_result_);
	result = _result_;
	return result;
}

static gint
vala_g_ptr_array_get_length (GPtrArray* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	result = (gint) self->len;
	return result;
}

static gboolean
string_contains (const gchar* self,
                 const gchar* needle)
{
	gchar* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (needle != NULL, FALSE);
	_tmp0_ = strstr ((gchar*) self, (gchar*) needle);
	result = _tmp0_ != NULL;
	return result;
}

static void
dc_contact_picker_dialog_rebuild_contact_list (DcContactPickerDialog* self,
                                               const gchar* query)
{
	GtkListBox* _tmp0_;
	gchar* q = NULL;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (query != NULL);
	_tmp0_ = self->priv->contact_listbox;
	dc_clear_listbox (_tmp0_);
	_tmp1_ = string_strip (query);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_utf8_strdown (_tmp2_, (gssize) -1);
	_tmp4_ = _tmp3_;
	_g_free0 (_tmp2_);
	q = _tmp4_;
	{
		guint i = 0U;
		i = (guint) 0;
		{
			gboolean _tmp5_ = FALSE;
			_tmp5_ = TRUE;
			while (TRUE) {
				GPtrArray* _tmp7_;
				gint _tmp8_;
				gint _tmp9_;
				DcContact* ci = NULL;
				GPtrArray* _tmp10_;
				gconstpointer _tmp11_;
				DcContact* _tmp12_;
				const gchar* _tmp13_;
				gint _tmp14_;
				gint _tmp15_;
				AdwActionRow* r = NULL;
				DcContact* _tmp30_;
				AdwActionRow* _tmp31_;
				GtkListBox* _tmp32_;
				AdwActionRow* _tmp33_;
				if (!_tmp5_) {
					guint _tmp6_;
					_tmp6_ = i;
					i = _tmp6_ + 1;
				}
				_tmp5_ = FALSE;
				_tmp7_ = self->priv->all_contacts;
				_tmp8_ = vala_g_ptr_array_get_length (_tmp7_);
				_tmp9_ = _tmp8_;
				if (!(i < ((guint) _tmp9_))) {
					break;
				}
				_tmp10_ = self->priv->all_contacts;
				_tmp11_ = g_ptr_array_index (_tmp10_, i);
				_tmp12_ = _g_object_ref0 ((DcContact*) _tmp11_);
				ci = _tmp12_;
				_tmp13_ = q;
				_tmp14_ = strlen (_tmp13_);
				_tmp15_ = _tmp14_;
				if (_tmp15_ > 0) {
					gboolean _tmp16_ = FALSE;
					DcContact* _tmp17_;
					const gchar* _tmp18_;
					const gchar* _tmp19_;
					gchar* _tmp20_;
					gchar* _tmp21_;
					const gchar* _tmp22_;
					gboolean _tmp23_;
					gboolean matches = FALSE;
					_tmp17_ = ci;
					_tmp18_ = dc_contact_get_display_name (_tmp17_);
					_tmp19_ = _tmp18_;
					_tmp20_ = g_utf8_strdown (_tmp19_, (gssize) -1);
					_tmp21_ = _tmp20_;
					_tmp22_ = q;
					_tmp23_ = string_contains (_tmp21_, _tmp22_);
					_g_free0 (_tmp21_);
					if (_tmp23_) {
						_tmp16_ = TRUE;
					} else {
						DcContact* _tmp24_;
						const gchar* _tmp25_;
						const gchar* _tmp26_;
						gchar* _tmp27_;
						gchar* _tmp28_;
						const gchar* _tmp29_;
						_tmp24_ = ci;
						_tmp25_ = dc_contact_get_address (_tmp24_);
						_tmp26_ = _tmp25_;
						_tmp27_ = g_utf8_strdown (_tmp26_, (gssize) -1);
						_tmp28_ = _tmp27_;
						_tmp29_ = q;
						_tmp16_ = string_contains (_tmp28_, _tmp29_);
						_g_free0 (_tmp28_);
					}
					matches = _tmp16_;
					if (!matches) {
						_g_object_unref0 (ci);
						continue;
					}
				}
				_tmp30_ = ci;
				_tmp31_ = dc_contact_picker_dialog_build_contact_row (self, _tmp30_);
				r = _tmp31_;
				_tmp32_ = self->priv->contact_listbox;
				_tmp33_ = r;
				gtk_list_box_append (_tmp32_, (GtkWidget*) _tmp33_);
				_g_object_unref0 (r);
				_g_object_unref0 (ci);
			}
		}
	}
	_g_free0 (q);
}

static void
dc_contact_picker_dialog_rebuild_chat_list (DcContactPickerDialog* self,
                                            const gchar* query)
{
	GtkListBox* _tmp0_;
	GListStore* _tmp1_;
	gchar* q = NULL;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gboolean any = FALSE;
	GtkLabel* _tmp25_;
	GtkListBox* _tmp26_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (query != NULL);
	_tmp0_ = self->priv->chat_listbox;
	dc_clear_listbox (_tmp0_);
	_tmp1_ = self->priv->chat_store;
	if (_tmp1_ == NULL) {
		return;
	}
	_tmp2_ = string_strip (query);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_utf8_strdown (_tmp3_, (gssize) -1);
	_tmp5_ = _tmp4_;
	_g_free0 (_tmp3_);
	q = _tmp5_;
	any = FALSE;
	{
		guint i = 0U;
		i = (guint) 0;
		{
			gboolean _tmp6_ = FALSE;
			_tmp6_ = TRUE;
			while (TRUE) {
				GListStore* _tmp8_;
				DcChatEntry* chat = NULL;
				GListStore* _tmp9_;
				GObject* _tmp10_;
				gboolean _tmp11_ = FALSE;
				const gchar* _tmp12_;
				gint _tmp13_;
				gint _tmp14_;
				GtkListBox* _tmp21_;
				DcChatEntry* _tmp22_;
				AdwActionRow* _tmp23_;
				AdwActionRow* _tmp24_;
				if (!_tmp6_) {
					guint _tmp7_;
					_tmp7_ = i;
					i = _tmp7_ + 1;
				}
				_tmp6_ = FALSE;
				_tmp8_ = self->priv->chat_store;
				if (!(i < g_list_model_get_n_items ((GListModel*) _tmp8_))) {
					break;
				}
				_tmp9_ = self->priv->chat_store;
				_tmp10_ = g_list_model_get_item ((GListModel*) _tmp9_, i);
				chat = G_TYPE_CHECK_INSTANCE_CAST (_tmp10_, DC_TYPE_CHAT_ENTRY, DcChatEntry);
				_tmp12_ = q;
				_tmp13_ = strlen (_tmp12_);
				_tmp14_ = _tmp13_;
				if (_tmp14_ > 0) {
					DcChatEntry* _tmp15_;
					const gchar* _tmp16_;
					const gchar* _tmp17_;
					gchar* _tmp18_;
					gchar* _tmp19_;
					const gchar* _tmp20_;
					_tmp15_ = chat;
					_tmp16_ = dc_chat_entry_get_name (_tmp15_);
					_tmp17_ = _tmp16_;
					_tmp18_ = g_utf8_strdown (_tmp17_, (gssize) -1);
					_tmp19_ = _tmp18_;
					_tmp20_ = q;
					_tmp11_ = !string_contains (_tmp19_, _tmp20_);
					_g_free0 (_tmp19_);
				} else {
					_tmp11_ = FALSE;
				}
				if (_tmp11_) {
					_g_object_unref0 (chat);
					continue;
				}
				_tmp21_ = self->priv->chat_listbox;
				_tmp22_ = chat;
				_tmp23_ = dc_chat_pick_row (_tmp22_);
				_tmp24_ = _tmp23_;
				gtk_list_box_append (_tmp21_, (GtkWidget*) _tmp24_);
				_g_object_unref0 (_tmp24_);
				any = TRUE;
				_g_object_unref0 (chat);
			}
		}
	}
	_tmp25_ = self->priv->chats_header;
	gtk_widget_set_visible ((GtkWidget*) _tmp25_, any);
	_tmp26_ = self->priv->chat_listbox;
	gtk_widget_set_visible ((GtkWidget*) _tmp26_, any);
	_g_free0 (q);
}

static AdwActionRow*
dc_contact_picker_dialog_build_contact_row (DcContactPickerDialog* self,
                                            DcContact* ci)
{
	AdwActionRow* row = NULL;
	AdwActionRow* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	AdwActionRow* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (ci != NULL, NULL);
	_tmp0_ = dc_contact_row (ci, TRUE, TRUE);
	row = _tmp0_;
	_tmp1_ = dc_contact_get_id (ci);
	_tmp2_ = _tmp1_;
	_tmp3_ = dc_contact_get_address (ci);
	_tmp4_ = _tmp3_;
	_tmp5_ = g_strdup_printf ("%d\n%s", _tmp2_, _tmp4_);
	_tmp6_ = _tmp5_;
	gtk_widget_set_name ((GtkWidget*) row, _tmp6_);
	_g_free0 (_tmp6_);
	result = row;
	return result;
}

static void
dc_contact_picker_dialog_on_search_changed (DcContactPickerDialog* self)
{
	gchar* text = NULL;
	GtkSearchEntry* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	const gchar* _tmp4_;
	GListStore* _tmp5_;
	gboolean _tmp7_ = FALSE;
	const gchar* _tmp8_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->search_entry;
	_tmp1_ = gtk_editable_get_text ((GtkEditable*) _tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = string_strip (_tmp2_);
	text = _tmp3_;
	_tmp4_ = text;
	dc_contact_picker_dialog_rebuild_contact_list (self, _tmp4_);
	_tmp5_ = self->priv->chat_store;
	if (_tmp5_ != NULL) {
		const gchar* _tmp6_;
		_tmp6_ = text;
		dc_contact_picker_dialog_rebuild_chat_list (self, _tmp6_);
	}
	_tmp8_ = text;
	if (string_contains (_tmp8_, "@")) {
		const gchar* _tmp9_;
		gint _tmp10_;
		gint _tmp11_;
		_tmp9_ = text;
		_tmp10_ = strlen (_tmp9_);
		_tmp11_ = _tmp10_;
		_tmp7_ = _tmp11_ > 3;
	} else {
		_tmp7_ = FALSE;
	}
	if (_tmp7_) {
		gboolean already_listed = FALSE;
		GtkButton* _tmp29_;
		const gchar* _tmp30_;
		gchar* _tmp31_;
		gchar* _tmp32_;
		GtkButton* _tmp33_;
		already_listed = FALSE;
		{
			guint i = 0U;
			i = (guint) 0;
			{
				gboolean _tmp12_ = FALSE;
				_tmp12_ = TRUE;
				while (TRUE) {
					GPtrArray* _tmp14_;
					gint _tmp15_;
					gint _tmp16_;
					DcContact* ci = NULL;
					GPtrArray* _tmp17_;
					gconstpointer _tmp18_;
					DcContact* _tmp19_;
					DcContact* _tmp20_;
					const gchar* _tmp21_;
					const gchar* _tmp22_;
					gchar* _tmp23_;
					gchar* _tmp24_;
					const gchar* _tmp25_;
					gchar* _tmp26_;
					gchar* _tmp27_;
					gboolean _tmp28_;
					if (!_tmp12_) {
						guint _tmp13_;
						_tmp13_ = i;
						i = _tmp13_ + 1;
					}
					_tmp12_ = FALSE;
					_tmp14_ = self->priv->all_contacts;
					_tmp15_ = vala_g_ptr_array_get_length (_tmp14_);
					_tmp16_ = _tmp15_;
					if (!(i < ((guint) _tmp16_))) {
						break;
					}
					_tmp17_ = self->priv->all_contacts;
					_tmp18_ = g_ptr_array_index (_tmp17_, i);
					_tmp19_ = _g_object_ref0 ((DcContact*) _tmp18_);
					ci = _tmp19_;
					_tmp20_ = ci;
					_tmp21_ = dc_contact_get_address (_tmp20_);
					_tmp22_ = _tmp21_;
					_tmp23_ = g_utf8_strdown (_tmp22_, (gssize) -1);
					_tmp24_ = _tmp23_;
					_tmp25_ = text;
					_tmp26_ = g_utf8_strdown (_tmp25_, (gssize) -1);
					_tmp27_ = _tmp26_;
					_tmp28_ = g_strcmp0 (_tmp24_, _tmp27_) == 0;
					_g_free0 (_tmp27_);
					_g_free0 (_tmp24_);
					if (_tmp28_) {
						already_listed = TRUE;
						_g_object_unref0 (ci);
						break;
					}
					_g_object_unref0 (ci);
				}
			}
		}
		_tmp29_ = self->priv->use_email_btn;
		_tmp30_ = text;
		_tmp31_ = g_strdup_printf ("Start chat with %s", _tmp30_);
		_tmp32_ = _tmp31_;
		gtk_button_set_label (_tmp29_, _tmp32_);
		_g_free0 (_tmp32_);
		_tmp33_ = self->priv->use_email_btn;
		gtk_widget_set_visible ((GtkWidget*) _tmp33_, !already_listed);
	} else {
		GtkButton* _tmp34_;
		_tmp34_ = self->priv->use_email_btn;
		gtk_widget_set_visible ((GtkWidget*) _tmp34_, FALSE);
	}
	_g_free0 (text);
}

static void
dc_contact_picker_dialog_on_activate_search (DcContactPickerDialog* self)
{
	gchar* text = NULL;
	GtkSearchEntry* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	GListStore* _tmp4_;
	GtkListBoxRow* first = NULL;
	GtkListBox* _tmp20_;
	GtkListBoxRow* _tmp21_;
	GtkListBoxRow* _tmp22_;
	GtkListBoxRow* second = NULL;
	GtkListBox* _tmp23_;
	GtkListBoxRow* _tmp24_;
	GtkListBoxRow* _tmp25_;
	gboolean _tmp26_ = FALSE;
	GtkListBoxRow* _tmp27_;
	gboolean _tmp30_ = FALSE;
	const gchar* _tmp31_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->search_entry;
	_tmp1_ = gtk_editable_get_text ((GtkEditable*) _tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = string_strip (_tmp2_);
	text = _tmp3_;
	_tmp4_ = self->priv->chat_store;
	if (_tmp4_ != NULL) {
		GtkListBoxRow* first_chat = NULL;
		GtkListBox* _tmp5_;
		GtkListBoxRow* _tmp6_;
		GtkListBoxRow* _tmp7_;
		GtkListBoxRow* second_chat = NULL;
		GtkListBox* _tmp8_;
		GtkListBoxRow* _tmp9_;
		GtkListBoxRow* _tmp10_;
		GtkListBoxRow* first_contact = NULL;
		GtkListBox* _tmp11_;
		GtkListBoxRow* _tmp12_;
		GtkListBoxRow* _tmp13_;
		gboolean _tmp14_ = FALSE;
		gboolean _tmp15_ = FALSE;
		GtkListBoxRow* _tmp16_;
		_tmp5_ = self->priv->chat_listbox;
		_tmp6_ = gtk_list_box_get_row_at_index (_tmp5_, 0);
		_tmp7_ = _g_object_ref0 (_tmp6_);
		first_chat = _tmp7_;
		_tmp8_ = self->priv->chat_listbox;
		_tmp9_ = gtk_list_box_get_row_at_index (_tmp8_, 1);
		_tmp10_ = _g_object_ref0 (_tmp9_);
		second_chat = _tmp10_;
		_tmp11_ = self->priv->contact_listbox;
		_tmp12_ = gtk_list_box_get_row_at_index (_tmp11_, 0);
		_tmp13_ = _g_object_ref0 (_tmp12_);
		first_contact = _tmp13_;
		_tmp16_ = first_chat;
		if (_tmp16_ != NULL) {
			GtkListBoxRow* _tmp17_;
			_tmp17_ = second_chat;
			_tmp15_ = _tmp17_ == NULL;
		} else {
			_tmp15_ = FALSE;
		}
		if (_tmp15_) {
			GtkListBoxRow* _tmp18_;
			_tmp18_ = first_contact;
			_tmp14_ = _tmp18_ == NULL;
		} else {
			_tmp14_ = FALSE;
		}
		if (_tmp14_) {
			GtkListBoxRow* _tmp19_;
			_tmp19_ = first_chat;
			dc_contact_picker_dialog_on_chat_row_activated (self, _tmp19_);
			_g_object_unref0 (first_contact);
			_g_object_unref0 (second_chat);
			_g_object_unref0 (first_chat);
			_g_free0 (text);
			return;
		}
		_g_object_unref0 (first_contact);
		_g_object_unref0 (second_chat);
		_g_object_unref0 (first_chat);
	}
	_tmp20_ = self->priv->contact_listbox;
	_tmp21_ = gtk_list_box_get_row_at_index (_tmp20_, 0);
	_tmp22_ = _g_object_ref0 (_tmp21_);
	first = _tmp22_;
	_tmp23_ = self->priv->contact_listbox;
	_tmp24_ = gtk_list_box_get_row_at_index (_tmp23_, 1);
	_tmp25_ = _g_object_ref0 (_tmp24_);
	second = _tmp25_;
	_tmp27_ = first;
	if (_tmp27_ != NULL) {
		GtkListBoxRow* _tmp28_;
		_tmp28_ = second;
		_tmp26_ = _tmp28_ == NULL;
	} else {
		_tmp26_ = FALSE;
	}
	if (_tmp26_) {
		GtkListBoxRow* _tmp29_;
		_tmp29_ = first;
		dc_contact_picker_dialog_on_contact_row_activated (self, _tmp29_);
		_g_object_unref0 (second);
		_g_object_unref0 (first);
		_g_free0 (text);
		return;
	}
	_tmp31_ = text;
	if (string_contains (_tmp31_, "@")) {
		const gchar* _tmp32_;
		gint _tmp33_;
		gint _tmp34_;
		_tmp32_ = text;
		_tmp33_ = strlen (_tmp32_);
		_tmp34_ = _tmp33_;
		_tmp30_ = _tmp34_ > 3;
	} else {
		_tmp30_ = FALSE;
	}
	if (_tmp30_) {
		dc_contact_picker_dialog_on_use_email (self);
	}
	_g_object_unref0 (second);
	_g_object_unref0 (first);
	_g_free0 (text);
}

static void
dc_contact_picker_dialog_on_contact_row_activated (DcContactPickerDialog* self,
                                                   GtkListBoxRow* row)
{
	AdwActionRow* action_row = NULL;
	AdwActionRow* _tmp0_;
	AdwActionRow* _tmp1_;
	const gchar* _tmp8_ = NULL;
	AdwActionRow* _tmp9_;
	const gchar* _tmp10_;
	const gchar* _tmp11_;
	gchar* data = NULL;
	gchar* _tmp12_;
	gchar** parts = NULL;
	const gchar* _tmp13_;
	gchar** _tmp14_;
	gchar** _tmp15_;
	gint parts_length1;
	gint _parts_size_;
	gchar** _tmp16_;
	gint _tmp16__length1;
	gint contact_id = 0;
	gchar** _tmp17_;
	gint _tmp17__length1;
	const gchar* _tmp18_;
	gchar* email = NULL;
	gchar** _tmp19_;
	gint _tmp19__length1;
	const gchar* _tmp20_;
	gchar* _tmp21_;
	const gchar* _tmp22_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (row != NULL);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (row, adw_action_row_get_type ()) ? ((AdwActionRow*) row) : NULL);
	action_row = _tmp0_;
	_tmp1_ = action_row;
	if (_tmp1_ == NULL) {
		AdwActionRow* child = NULL;
		GtkWidget* _tmp2_;
		GtkWidget* _tmp3_;
		AdwActionRow* _tmp4_;
		AdwActionRow* _tmp5_;
		_tmp2_ = gtk_list_box_row_get_child (row);
		_tmp3_ = _tmp2_;
		_tmp4_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp3_, adw_action_row_get_type ()) ? ((AdwActionRow*) _tmp3_) : NULL);
		child = _tmp4_;
		_tmp5_ = child;
		if (_tmp5_ != NULL) {
			AdwActionRow* _tmp6_;
			AdwActionRow* _tmp7_;
			_tmp6_ = child;
			_tmp7_ = _g_object_ref0 (_tmp6_);
			_g_object_unref0 (action_row);
			action_row = _tmp7_;
		} else {
			_g_object_unref0 (child);
			_g_object_unref0 (action_row);
			return;
		}
		_g_object_unref0 (child);
	}
	_tmp9_ = action_row;
	_tmp10_ = gtk_widget_get_name ((GtkWidget*) _tmp9_);
	_tmp11_ = _tmp10_;
	_tmp8_ = _tmp11_;
	if (_tmp8_ == NULL) {
		_tmp8_ = "";
	}
	_tmp12_ = g_strdup (_tmp8_);
	data = _tmp12_;
	_tmp13_ = data;
	_tmp15_ = _tmp14_ = g_strsplit (_tmp13_, "\n", 2);
	parts = _tmp15_;
	parts_length1 = _vala_array_length (_tmp14_);
	_parts_size_ = parts_length1;
	_tmp16_ = parts;
	_tmp16__length1 = parts_length1;
	if (_tmp16__length1 < 2) {
		parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (data);
		_g_object_unref0 (action_row);
		return;
	}
	_tmp17_ = parts;
	_tmp17__length1 = parts_length1;
	_tmp18_ = _tmp17_[0];
	contact_id = atoi (_tmp18_);
	_tmp19_ = parts;
	_tmp19__length1 = parts_length1;
	_tmp20_ = _tmp19_[1];
	_tmp21_ = g_strdup (_tmp20_);
	email = _tmp21_;
	_tmp22_ = email;
	g_signal_emit (self, dc_contact_picker_dialog_signals[DC_CONTACT_PICKER_DIALOG_CONTACT_PICKED_SIGNAL], 0, contact_id, _tmp22_);
	adw_dialog_close ((AdwDialog*) self);
	_g_free0 (email);
	parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (data);
	_g_object_unref0 (action_row);
}

static void
dc_contact_picker_dialog_on_chat_row_activated (DcContactPickerDialog* self,
                                                GtkListBoxRow* row)
{
	AdwActionRow* action_row = NULL;
	AdwActionRow* _tmp0_;
	AdwActionRow* _tmp1_;
	const gchar* _tmp8_ = NULL;
	AdwActionRow* _tmp9_;
	const gchar* _tmp10_;
	const gchar* _tmp11_;
	gint chat_id = 0;
	g_return_if_fail (self != NULL);
	g_return_if_fail (row != NULL);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (row, adw_action_row_get_type ()) ? ((AdwActionRow*) row) : NULL);
	action_row = _tmp0_;
	_tmp1_ = action_row;
	if (_tmp1_ == NULL) {
		AdwActionRow* child = NULL;
		GtkWidget* _tmp2_;
		GtkWidget* _tmp3_;
		AdwActionRow* _tmp4_;
		AdwActionRow* _tmp5_;
		_tmp2_ = gtk_list_box_row_get_child (row);
		_tmp3_ = _tmp2_;
		_tmp4_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp3_, adw_action_row_get_type ()) ? ((AdwActionRow*) _tmp3_) : NULL);
		child = _tmp4_;
		_tmp5_ = child;
		if (_tmp5_ != NULL) {
			AdwActionRow* _tmp6_;
			AdwActionRow* _tmp7_;
			_tmp6_ = child;
			_tmp7_ = _g_object_ref0 (_tmp6_);
			_g_object_unref0 (action_row);
			action_row = _tmp7_;
		} else {
			_g_object_unref0 (child);
			_g_object_unref0 (action_row);
			return;
		}
		_g_object_unref0 (child);
	}
	_tmp9_ = action_row;
	_tmp10_ = gtk_widget_get_name ((GtkWidget*) _tmp9_);
	_tmp11_ = _tmp10_;
	_tmp8_ = _tmp11_;
	if (_tmp8_ == NULL) {
		_tmp8_ = "0";
	}
	chat_id = atoi (_tmp8_);
	if (chat_id <= 0) {
		_g_object_unref0 (action_row);
		return;
	}
	g_signal_emit (self, dc_contact_picker_dialog_signals[DC_CONTACT_PICKER_DIALOG_CHAT_PICKED_SIGNAL], 0, chat_id);
	adw_dialog_close ((AdwDialog*) self);
	_g_object_unref0 (action_row);
}

static void
dc_contact_picker_dialog_on_use_email (DcContactPickerDialog* self)
{
	gchar* email = NULL;
	GtkSearchEntry* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gboolean _tmp4_ = FALSE;
	const gchar* _tmp5_;
	gint _tmp6_;
	gint _tmp7_;
	const gchar* _tmp9_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->search_entry;
	_tmp1_ = gtk_editable_get_text ((GtkEditable*) _tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = string_strip (_tmp2_);
	email = _tmp3_;
	_tmp5_ = email;
	_tmp6_ = strlen (_tmp5_);
	_tmp7_ = _tmp6_;
	if (_tmp7_ == 0) {
		_tmp4_ = TRUE;
	} else {
		const gchar* _tmp8_;
		_tmp8_ = email;
		_tmp4_ = !string_contains (_tmp8_, "@");
	}
	if (_tmp4_) {
		_g_free0 (email);
		return;
	}
	_tmp9_ = email;
	g_signal_emit (self, dc_contact_picker_dialog_signals[DC_CONTACT_PICKER_DIALOG_CONTACT_PICKED_SIGNAL], 0, 0, _tmp9_);
	adw_dialog_close ((AdwDialog*) self);
	_g_free0 (email);
}

static void
g_cclosure_user_marshal_VOID__INT_STRING (GClosure * closure,
                                          GValue * return_value,
                                          guint n_param_values,
                                          const GValue * param_values,
                                          gpointer invocation_hint,
                                          gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__INT_STRING) (gpointer data1, gint arg_1, const char* arg_2, gpointer data2);
	register GMarshalFunc_VOID__INT_STRING callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 3);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__INT_STRING) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_int (param_values + 1), g_value_get_string (param_values + 2), data2);
}

static void
dc_contact_picker_dialog_class_init (DcContactPickerDialogClass * klass,
                                     gpointer klass_data)
{
	dc_contact_picker_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DcContactPickerDialog_private_offset);
	G_OBJECT_CLASS (klass)->finalize = dc_contact_picker_dialog_finalize;
	dc_contact_picker_dialog_signals[DC_CONTACT_PICKER_DIALOG_CONTACT_PICKED_SIGNAL] = g_signal_new ("contact-picked", DC_TYPE_CONTACT_PICKER_DIALOG, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__INT_STRING, G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_STRING);
	dc_contact_picker_dialog_signals[DC_CONTACT_PICKER_DIALOG_CHAT_PICKED_SIGNAL] = g_signal_new ("chat-picked", DC_TYPE_CONTACT_PICKER_DIALOG, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
}

static void
dc_contact_picker_dialog_instance_init (DcContactPickerDialog * self,
                                        gpointer klass)
{
	GPtrArray* _tmp0_;
	self->priv = dc_contact_picker_dialog_get_instance_private (self);
	_tmp0_ = g_ptr_array_new_full ((guint) 0, _g_object_unref0_);
	self->priv->all_contacts = _tmp0_;
}

static void
dc_contact_picker_dialog_finalize (GObject * obj)
{
	DcContactPickerDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DC_TYPE_CONTACT_PICKER_DIALOG, DcContactPickerDialog);
	_g_object_unref0 (self->priv->rpc);
	_g_object_unref0 (self->priv->chat_store);
	_g_object_unref0 (self->priv->search_entry);
	_g_object_unref0 (self->priv->chat_listbox);
	_g_object_unref0 (self->priv->contact_listbox);
	_g_object_unref0 (self->priv->chats_header);
	_g_object_unref0 (self->priv->contacts_header);
	_g_object_unref0 (self->priv->use_email_btn);
	_g_ptr_array_unref0 (self->priv->all_contacts);
	G_OBJECT_CLASS (dc_contact_picker_dialog_parent_class)->finalize (obj);
}

static GType
dc_contact_picker_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DcContactPickerDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dc_contact_picker_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DcContactPickerDialog), 0, (GInstanceInitFunc) dc_contact_picker_dialog_instance_init, NULL };
	GType dc_contact_picker_dialog_type_id;
	dc_contact_picker_dialog_type_id = g_type_register_static (adw_dialog_get_type (), "DcContactPickerDialog", &g_define_type_info, 0);
	DcContactPickerDialog_private_offset = g_type_add_instance_private (dc_contact_picker_dialog_type_id, sizeof (DcContactPickerDialogPrivate));
	return dc_contact_picker_dialog_type_id;
}

GType
dc_contact_picker_dialog_get_type (void)
{
	static volatile gsize dc_contact_picker_dialog_type_id__once = 0;
	if (g_once_init_enter (&dc_contact_picker_dialog_type_id__once)) {
		GType dc_contact_picker_dialog_type_id;
		dc_contact_picker_dialog_type_id = dc_contact_picker_dialog_get_type_once ();
		g_once_init_leave (&dc_contact_picker_dialog_type_id__once, dc_contact_picker_dialog_type_id);
	}
	return dc_contact_picker_dialog_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;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

