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

#include <adwaita.h>
#include <glib-object.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <math.h>
#include <gio/gio.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_CLASSIC_EMAIL_DIALOG (dc_classic_email_dialog_get_type ())
#define DC_CLASSIC_EMAIL_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_CLASSIC_EMAIL_DIALOG, DcClassicEmailDialog))
#define DC_CLASSIC_EMAIL_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_CLASSIC_EMAIL_DIALOG, DcClassicEmailDialogClass))
#define DC_IS_CLASSIC_EMAIL_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_CLASSIC_EMAIL_DIALOG))
#define DC_IS_CLASSIC_EMAIL_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_CLASSIC_EMAIL_DIALOG))
#define DC_CLASSIC_EMAIL_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_CLASSIC_EMAIL_DIALOG, DcClassicEmailDialogClass))

typedef struct _DcClassicEmailDialog DcClassicEmailDialog;
typedef struct _DcClassicEmailDialogClass DcClassicEmailDialogClass;
typedef struct _DcClassicEmailDialogPrivate DcClassicEmailDialogPrivate;

#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_EVENT_HANDLER (dc_event_handler_get_type ())
#define DC_EVENT_HANDLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_EVENT_HANDLER, DcEventHandler))
#define DC_EVENT_HANDLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_EVENT_HANDLER, DcEventHandlerClass))
#define DC_IS_EVENT_HANDLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_EVENT_HANDLER))
#define DC_IS_EVENT_HANDLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_EVENT_HANDLER))
#define DC_EVENT_HANDLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_EVENT_HANDLER, DcEventHandlerClass))

typedef struct _DcEventHandler DcEventHandler;
typedef struct _DcEventHandlerClass DcEventHandlerClass;

#define DC_TYPE_ENTERED_LOGIN_PARAMS (dc_entered_login_params_get_type ())
#define DC_ENTERED_LOGIN_PARAMS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_ENTERED_LOGIN_PARAMS, DcEnteredLoginParams))
#define DC_ENTERED_LOGIN_PARAMS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_ENTERED_LOGIN_PARAMS, DcEnteredLoginParamsClass))
#define DC_IS_ENTERED_LOGIN_PARAMS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_ENTERED_LOGIN_PARAMS))
#define DC_IS_ENTERED_LOGIN_PARAMS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_ENTERED_LOGIN_PARAMS))
#define DC_ENTERED_LOGIN_PARAMS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_ENTERED_LOGIN_PARAMS, DcEnteredLoginParamsClass))

typedef struct _DcEnteredLoginParams DcEnteredLoginParams;
typedef struct _DcEnteredLoginParamsClass DcEnteredLoginParamsClass;

#define DC_TYPE_ACCOUNT_PROGRESS_PAGE (dc_account_progress_page_get_type ())
#define DC_ACCOUNT_PROGRESS_PAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_ACCOUNT_PROGRESS_PAGE, DcAccountProgressPage))
#define DC_ACCOUNT_PROGRESS_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_ACCOUNT_PROGRESS_PAGE, DcAccountProgressPageClass))
#define DC_IS_ACCOUNT_PROGRESS_PAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_ACCOUNT_PROGRESS_PAGE))
#define DC_IS_ACCOUNT_PROGRESS_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_ACCOUNT_PROGRESS_PAGE))
#define DC_ACCOUNT_PROGRESS_PAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_ACCOUNT_PROGRESS_PAGE, DcAccountProgressPageClass))

typedef struct _DcAccountProgressPage DcAccountProgressPage;
typedef struct _DcAccountProgressPageClass DcAccountProgressPageClass;
enum  {
	DC_CLASSIC_EMAIL_DIALOG_0_PROPERTY,
	DC_CLASSIC_EMAIL_DIALOG_NUM_PROPERTIES
};
static GParamSpec* dc_classic_email_dialog_properties[DC_CLASSIC_EMAIL_DIALOG_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _DcEnteredLoginParamsPrivate DcEnteredLoginParamsPrivate;
#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 _DcClassicEmailDialogDoConfigureData DcClassicEmailDialogDoConfigureData;
enum  {
	DC_CLASSIC_EMAIL_DIALOG_ACCOUNT_CREATED_SIGNAL,
	DC_CLASSIC_EMAIL_DIALOG_TRANSPORT_UPDATED_SIGNAL,
	DC_CLASSIC_EMAIL_DIALOG_NUM_SIGNALS
};
static guint dc_classic_email_dialog_signals[DC_CLASSIC_EMAIL_DIALOG_NUM_SIGNALS] = {0};

struct _DcClassicEmailDialog {
	AdwDialog parent_instance;
	DcClassicEmailDialogPrivate * priv;
};

struct _DcClassicEmailDialogClass {
	AdwDialogClass parent_class;
};

struct _DcClassicEmailDialogPrivate {
	DcRpcClient* rpc;
	DcEventHandler* events;
	gint edit_account_id;
	DcEnteredLoginParams* initial;
	GtkStack* stack;
	GtkEntry* email_entry;
	GtkPasswordEntry* pass_entry;
	GtkExpander* advanced_expander;
	GtkGrid* adv_grid;
	gint adv_row;
	GtkEntry* imap_user_entry;
	GtkEntry* imap_server_entry;
	GtkEntry* imap_port_entry;
	GtkDropDown* imap_security_dd;
	GtkEntry* smtp_user_entry;
	GtkPasswordEntry* smtp_pass_entry;
	GtkEntry* smtp_server_entry;
	GtkEntry* smtp_port_entry;
	GtkDropDown* smtp_security_dd;
	GtkDropDown* cert_checks_dd;
	GtkButton* submit_btn;
	DcAccountProgressPage* progress_page;
	gint new_account_id;
	gint target_account_id;
	gboolean configure_running;
	gboolean configure_finished;
	gboolean cancelled;
	gulong progress_handler_id;
};

struct _DcEnteredLoginParams {
	GObject parent_instance;
	DcEnteredLoginParamsPrivate * priv;
	gchar* addr;
	gchar* password;
	gchar* imap_user;
	gchar* imap_server;
	gint imap_port;
	gchar* imap_security;
	gchar* smtp_user;
	gchar* smtp_password;
	gchar* smtp_server;
	gint smtp_port;
	gchar* smtp_security;
	gchar* certificate_checks;
};

struct _DcEnteredLoginParamsClass {
	GObjectClass parent_class;
};

struct _DcClassicEmailDialogDoConfigureData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcClassicEmailDialog* self;
	DcEnteredLoginParams* params;
	DcEnteredLoginParams* _tmp0_;
	DcEnteredLoginParams* _tmp1_;
	GtkStack* _tmp2_;
	DcAccountProgressPage* _tmp3_;
	DcEnteredLoginParams* _tmp4_;
	const gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	DcEventHandler* _tmp8_;
	gulong _tmp9_;
	gint _tmp10_;
	DcRpcClient* _tmp11_;
	GError* e;
	GError* _tmp12_;
	const gchar* _tmp13_;
	gchar* _tmp14_;
	gchar* _tmp15_;
	GtkStack* _tmp16_;
	DcRpcClient* _tmp17_;
	DcEnteredLoginParams* _tmp18_;
	GError* _vala1_e;
	gint aid;
	DcRpcClient* _tmp19_;
	GError* _tmp20_;
	const gchar* _tmp21_;
	gchar* _tmp22_;
	gchar* _tmp23_;
	GtkStack* _tmp24_;
	gint created;
	GError* _inner_error0_;
};

static gint DcClassicEmailDialog_private_offset;
static gpointer dc_classic_email_dialog_parent_class = NULL;

VALA_EXTERN GType dc_classic_email_dialog_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcClassicEmailDialog, 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_event_handler_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcEventHandler, g_object_unref)
VALA_EXTERN GType dc_entered_login_params_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcEnteredLoginParams, g_object_unref)
VALA_EXTERN GType dc_account_progress_page_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcAccountProgressPage, g_object_unref)
VALA_EXTERN DcClassicEmailDialog* dc_classic_email_dialog_new (DcRpcClient* rpc,
                                                   DcEventHandler* events);
VALA_EXTERN DcClassicEmailDialog* dc_classic_email_dialog_construct (GType object_type,
                                                         DcRpcClient* rpc,
                                                         DcEventHandler* events);
static void dc_classic_email_dialog_setup (DcClassicEmailDialog* self,
                                    const gchar* title);
VALA_EXTERN DcClassicEmailDialog* dc_classic_email_dialog_new_for_edit (DcRpcClient* rpc,
                                                            DcEventHandler* events,
                                                            gint account_id,
                                                            DcEnteredLoginParams* current);
VALA_EXTERN DcClassicEmailDialog* dc_classic_email_dialog_construct_for_edit (GType object_type,
                                                                  DcRpcClient* rpc,
                                                                  DcEventHandler* events,
                                                                  gint account_id,
                                                                  DcEnteredLoginParams* current);
VALA_EXTERN GtkStack* dc_account_setup_dialog (AdwDialog* dialog,
                                   const gchar* title,
                                   GtkWidget* input_page,
                                   GtkWidget* progress_page);
static GtkWidget* dc_classic_email_dialog_build_input_page (DcClassicEmailDialog* self);
static GtkWidget* dc_classic_email_dialog_build_progress_page (DcClassicEmailDialog* self);
static void dc_classic_email_dialog_on_dialog_closed (DcClassicEmailDialog* self);
static void _dc_classic_email_dialog_on_dialog_closed_adw_dialog_closed (AdwDialog* _sender,
                                                                  gpointer self);
VALA_EXTERN GtkBox* dc_account_setup_content (void);
VALA_EXTERN GtkLabel* dc_account_setup_intro (const gchar* text);
VALA_EXTERN GtkEntry* dc_account_setup_entry (const gchar* placeholder,
                                  gboolean hexpand,
                                  GtkInputPurpose purpose);
static GtkWidget* dc_classic_email_dialog_build_advanced_grid (DcClassicEmailDialog* self);
static void __lambda148_ (DcClassicEmailDialog* self);
static void ___lambda148__g_object_notify (GObject* _sender,
                                    GParamSpec* pspec,
                                    gpointer self);
VALA_EXTERN GtkButton* dc_account_setup_action (GtkBox* content,
                                    const gchar* label,
                                    gboolean with_margin);
static void __lambda149_ (DcClassicEmailDialog* self);
static void dc_classic_email_dialog_do_configure (DcClassicEmailDialog* self,
                                           GAsyncReadyCallback _callback_,
                                           gpointer _user_data_);
static void dc_classic_email_dialog_do_configure_finish (DcClassicEmailDialog* self,
                                                  GAsyncResult* _res_);
static void ___lambda149__gtk_button_clicked (GtkButton* _sender,
                                       gpointer self);
static void dc_classic_email_dialog_apply_initial_values (DcClassicEmailDialog* self);
static void dc_classic_email_dialog_adv_heading (DcClassicEmailDialog* self,
                                          const gchar* text);
static GtkEntry* dc_classic_email_dialog_adv_entry (const gchar* placeholder);
static void dc_classic_email_dialog_adv_field (DcClassicEmailDialog* self,
                                        const gchar* label_text,
                                        GtkWidget* widget);
static GtkEntry* dc_classic_email_dialog_adv_port_entry (void);
static GtkDropDown* dc_classic_email_dialog_security_dropdown (void);
VALA_EXTERN GtkLabel* dc_account_setup_heading (const gchar* text);
static gchar* dc_classic_email_dialog_security_value (GtkDropDown* dd);
static guint dc_classic_email_dialog_security_index (const gchar* v);
static gboolean dc_classic_email_dialog_has_advanced_values (DcClassicEmailDialog* self);
static gchar* dc_classic_email_dialog_opt_text (GtkEntry* entry);
static gint dc_classic_email_dialog_port_value (GtkEntry* entry);
static DcEnteredLoginParams* dc_classic_email_dialog_collect_params (DcClassicEmailDialog* self);
VALA_EXTERN DcEnteredLoginParams* dc_entered_login_params_new (void);
VALA_EXTERN DcEnteredLoginParams* dc_entered_login_params_construct (GType object_type);
VALA_EXTERN void dc_show_error (GtkWidget* parent,
                    const gchar* message);
VALA_EXTERN DcAccountProgressPage* dc_account_progress_page_new (const gchar* initial_status,
                                                     gboolean wrap_status);
VALA_EXTERN DcAccountProgressPage* dc_account_progress_page_construct (GType object_type,
                                                           const gchar* initial_status,
                                                           gboolean wrap_status);
static void dc_classic_email_dialog_cancel_configure (DcClassicEmailDialog* self);
static void _dc_classic_email_dialog_cancel_configure_dc_account_progress_page_cancel_requested (DcAccountProgressPage* _sender,
                                                                                          gpointer self);
static void dc_classic_email_dialog_do_configure_data_free (gpointer _data);
static gboolean dc_classic_email_dialog_do_configure_co (DcClassicEmailDialogDoConfigureData* _data_);
VALA_EXTERN void dc_account_progress_page_set_status (DcAccountProgressPage* self,
                                          const gchar* status);
static void dc_classic_email_dialog_on_configure_progress (DcClassicEmailDialog* self,
                                                    gint ctx,
                                                    gint progress,
                                                    const gchar* comment);
static void _dc_classic_email_dialog_on_configure_progress_dc_event_handler_configure_progress (DcEventHandler* _sender,
                                                                                         gint context_id,
                                                                                         gint progress,
                                                                                         const gchar* comment,
                                                                                         gpointer self);
VALA_EXTERN void dc_rpc_client_add_account (DcRpcClient* self,
                                GAsyncReadyCallback _callback_,
                                gpointer _user_data_);
VALA_EXTERN gint dc_rpc_client_add_account_finish (DcRpcClient* self,
                                       GAsyncResult* _res_,
                                       GError** error);
static void dc_classic_email_dialog_do_configure_ready (GObject* source_object,
                                                 GAsyncResult* _res_,
                                                 gpointer _user_data_);
static void dc_classic_email_dialog_cleanup_signal (DcClassicEmailDialog* self);
VALA_EXTERN void dc_rpc_client_add_or_update_transport (DcRpcClient* self,
                                            gint acct_id,
                                            DcEnteredLoginParams* p,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_);
VALA_EXTERN void dc_rpc_client_add_or_update_transport_finish (DcRpcClient* self,
                                                   GAsyncResult* _res_,
                                                   GError** error);
VALA_EXTERN void dc_cleanup_pending_account (DcRpcClient* rpc,
                                 gint account_id,
                                 gboolean stop_first,
                                 GAsyncReadyCallback _callback_,
                                 gpointer _user_data_);
VALA_EXTERN void dc_cleanup_pending_account_finish (GAsyncResult* _res_);
VALA_EXTERN void dc_account_progress_page_set_permille (DcAccountProgressPage* self,
                                            gint progress,
                                            const gchar* comment,
                                            const gchar* active_status);
VALA_EXTERN void dc_disconnect_progress_handler (DcEventHandler* events,
                                     gulong* handler_id);
VALA_EXTERN gboolean dc_close_if_idle (AdwDialog* dialog,
                           gboolean running);
VALA_EXTERN void dc_stop_ongoing_account (DcRpcClient* rpc,
                              gint account_id);
VALA_EXTERN void dc_cleanup_unfinished_account (DcRpcClient* rpc,
                                    gint* account_id,
                                    gboolean finished);
static void dc_classic_email_dialog_finalize (GObject * obj);
static GType dc_classic_email_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 inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
dc_classic_email_dialog_get_instance_private (DcClassicEmailDialog* self)
{
	return G_STRUCT_MEMBER_P (self, DcClassicEmailDialog_private_offset);
}

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

DcClassicEmailDialog*
dc_classic_email_dialog_construct (GType object_type,
                                   DcRpcClient* rpc,
                                   DcEventHandler* events)
{
	DcClassicEmailDialog * self = NULL;
	DcRpcClient* _tmp0_;
	DcEventHandler* _tmp1_;
	g_return_val_if_fail (rpc != NULL, NULL);
	g_return_val_if_fail (events != NULL, NULL);
	self = (DcClassicEmailDialog*) 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 (events);
	_g_object_unref0 (self->priv->events);
	self->priv->events = _tmp1_;
	dc_classic_email_dialog_setup (self, "Use Classic Email Address");
	return self;
}

DcClassicEmailDialog*
dc_classic_email_dialog_new (DcRpcClient* rpc,
                             DcEventHandler* events)
{
	return dc_classic_email_dialog_construct (DC_TYPE_CLASSIC_EMAIL_DIALOG, rpc, events);
}

DcClassicEmailDialog*
dc_classic_email_dialog_construct_for_edit (GType object_type,
                                            DcRpcClient* rpc,
                                            DcEventHandler* events,
                                            gint account_id,
                                            DcEnteredLoginParams* current)
{
	DcClassicEmailDialog * self = NULL;
	DcRpcClient* _tmp0_;
	DcEventHandler* _tmp1_;
	DcEnteredLoginParams* _tmp2_;
	g_return_val_if_fail (rpc != NULL, NULL);
	g_return_val_if_fail (events != NULL, NULL);
	g_return_val_if_fail (current != NULL, NULL);
	self = (DcClassicEmailDialog*) 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 (events);
	_g_object_unref0 (self->priv->events);
	self->priv->events = _tmp1_;
	self->priv->edit_account_id = account_id;
	_tmp2_ = _g_object_ref0 (current);
	_g_object_unref0 (self->priv->initial);
	self->priv->initial = _tmp2_;
	dc_classic_email_dialog_setup (self, "Edit Transport");
	return self;
}

DcClassicEmailDialog*
dc_classic_email_dialog_new_for_edit (DcRpcClient* rpc,
                                      DcEventHandler* events,
                                      gint account_id,
                                      DcEnteredLoginParams* current)
{
	return dc_classic_email_dialog_construct_for_edit (DC_TYPE_CLASSIC_EMAIL_DIALOG, rpc, events, account_id, current);
}

static void
_dc_classic_email_dialog_on_dialog_closed_adw_dialog_closed (AdwDialog* _sender,
                                                             gpointer self)
{
	dc_classic_email_dialog_on_dialog_closed ((DcClassicEmailDialog*) self);
}

static void
dc_classic_email_dialog_setup (DcClassicEmailDialog* self,
                               const gchar* title)
{
	GtkWidget* _tmp0_;
	GtkWidget* _tmp1_;
	GtkWidget* _tmp2_;
	GtkWidget* _tmp3_;
	GtkStack* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (title != NULL);
	_tmp0_ = dc_classic_email_dialog_build_input_page (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = dc_classic_email_dialog_build_progress_page (self);
	_tmp3_ = _tmp2_;
	_tmp4_ = dc_account_setup_dialog ((AdwDialog*) self, title, _tmp1_, _tmp3_);
	_g_object_unref0 (self->priv->stack);
	self->priv->stack = _tmp4_;
	_g_object_unref0 (_tmp3_);
	_g_object_unref0 (_tmp1_);
	g_signal_connect_object ((AdwDialog*) self, "closed", (GCallback) _dc_classic_email_dialog_on_dialog_closed_adw_dialog_closed, self, 0);
}

static void
__lambda148_ (DcClassicEmailDialog* self)
{
	gint _tmp0_ = 0;
	GtkExpander* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	_tmp1_ = self->priv->advanced_expander;
	_tmp2_ = gtk_expander_get_expanded (_tmp1_);
	_tmp3_ = _tmp2_;
	if (_tmp3_) {
		_tmp0_ = 680;
	} else {
		_tmp0_ = -1;
	}
	adw_dialog_set_content_height ((AdwDialog*) self, _tmp0_);
}

static void
___lambda148__g_object_notify (GObject* _sender,
                               GParamSpec* pspec,
                               gpointer self)
{
	__lambda148_ ((DcClassicEmailDialog*) self);
}

static void
__lambda149_ (DcClassicEmailDialog* self)
{
	dc_classic_email_dialog_do_configure (self, NULL, NULL);
}

static void
___lambda149__gtk_button_clicked (GtkButton* _sender,
                                  gpointer self)
{
	__lambda149_ ((DcClassicEmailDialog*) self);
}

static GtkWidget*
dc_classic_email_dialog_build_input_page (DcClassicEmailDialog* self)
{
	GtkBox* content = NULL;
	GtkBox* _tmp0_;
	const gchar* _tmp1_ = NULL;
	GtkBox* _tmp2_;
	GtkLabel* _tmp3_;
	GtkLabel* _tmp4_;
	GtkEntry* _tmp5_;
	GtkBox* _tmp6_;
	GtkEntry* _tmp7_;
	GtkPasswordEntry* _tmp8_;
	GtkPasswordEntry* _tmp9_;
	GtkPasswordEntry* _tmp10_;
	GtkPasswordEntry* _tmp11_;
	GtkBox* _tmp12_;
	GtkPasswordEntry* _tmp13_;
	GtkExpander* _tmp14_;
	GtkExpander* _tmp15_;
	GtkWidget* _tmp16_;
	GtkWidget* _tmp17_;
	GtkExpander* _tmp18_;
	GtkBox* _tmp19_;
	GtkExpander* _tmp20_;
	GtkLabel* hint = NULL;
	GtkLabel* _tmp21_;
	GtkLabel* _tmp22_;
	GtkLabel* _tmp23_;
	GtkLabel* _tmp24_;
	GtkLabel* _tmp25_;
	GtkBox* _tmp26_;
	GtkLabel* _tmp27_;
	const gchar* _tmp28_ = NULL;
	GtkBox* _tmp29_;
	GtkButton* _tmp30_;
	GtkButton* _tmp31_;
	GtkButton* _tmp32_;
	GtkScrolledWindow* scroll = NULL;
	GtkScrolledWindow* _tmp33_;
	GtkBox* _tmp34_;
	GtkWidget* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = dc_account_setup_content ();
	content = _tmp0_;
	if (self->priv->edit_account_id > 0) {
		_tmp1_ = "Change the login and server settings for this transport. " "Fields left on “Automatic” are configured automatically.";
	} else {
		_tmp1_ = "Sign in with an existing email account. For most providers " "the address and password are enough — servers are " "configured automatically. If your provider needs custom " "IMAP/SMTP servers, set them under Advanced Settings.";
	}
	_tmp2_ = content;
	_tmp3_ = dc_account_setup_intro (_tmp1_);
	_tmp4_ = _tmp3_;
	gtk_box_append (_tmp2_, (GtkWidget*) _tmp4_);
	_g_object_unref0 (_tmp4_);
	_tmp5_ = dc_account_setup_entry ("user@example.com", TRUE, GTK_INPUT_PURPOSE_EMAIL);
	_g_object_unref0 (self->priv->email_entry);
	self->priv->email_entry = _tmp5_;
	_tmp6_ = content;
	_tmp7_ = self->priv->email_entry;
	gtk_box_append (_tmp6_, (GtkWidget*) _tmp7_);
	_tmp8_ = (GtkPasswordEntry*) gtk_password_entry_new ();
	g_object_ref_sink (_tmp8_);
	_g_object_unref0 (self->priv->pass_entry);
	self->priv->pass_entry = _tmp8_;
	_tmp9_ = self->priv->pass_entry;
	g_object_set (_tmp9_, "placeholder-text", "Password", NULL);
	_tmp10_ = self->priv->pass_entry;
	gtk_password_entry_set_show_peek_icon (_tmp10_, TRUE);
	_tmp11_ = self->priv->pass_entry;
	g_object_set (_tmp11_, "activates-default", TRUE, NULL);
	_tmp12_ = content;
	_tmp13_ = self->priv->pass_entry;
	gtk_box_append (_tmp12_, (GtkWidget*) _tmp13_);
	_tmp14_ = (GtkExpander*) gtk_expander_new ("Advanced Settings");
	g_object_ref_sink (_tmp14_);
	_g_object_unref0 (self->priv->advanced_expander);
	self->priv->advanced_expander = _tmp14_;
	_tmp15_ = self->priv->advanced_expander;
	_tmp16_ = dc_classic_email_dialog_build_advanced_grid (self);
	_tmp17_ = _tmp16_;
	gtk_expander_set_child (_tmp15_, _tmp17_);
	_g_object_unref0 (_tmp17_);
	_tmp18_ = self->priv->advanced_expander;
	g_signal_connect_object ((GObject*) _tmp18_, "notify::expanded", (GCallback) ___lambda148__g_object_notify, self, 0);
	_tmp19_ = content;
	_tmp20_ = self->priv->advanced_expander;
	gtk_box_append (_tmp19_, (GtkWidget*) _tmp20_);
	_tmp21_ = (GtkLabel*) gtk_label_new ("Sometimes IMAP needs to be enabled in the web interface of " "your provider first.");
	g_object_ref_sink (_tmp21_);
	hint = _tmp21_;
	_tmp22_ = hint;
	gtk_label_set_wrap (_tmp22_, TRUE);
	_tmp23_ = hint;
	gtk_label_set_xalign (_tmp23_, (gfloat) 0);
	_tmp24_ = hint;
	gtk_widget_add_css_class ((GtkWidget*) _tmp24_, "dim-label");
	_tmp25_ = hint;
	gtk_widget_add_css_class ((GtkWidget*) _tmp25_, "caption");
	_tmp26_ = content;
	_tmp27_ = hint;
	gtk_box_append (_tmp26_, (GtkWidget*) _tmp27_);
	if (self->priv->edit_account_id > 0) {
		_tmp28_ = "Save & Reconnect";
	} else {
		_tmp28_ = "Sign In";
	}
	_tmp29_ = content;
	_tmp30_ = dc_account_setup_action (_tmp29_, _tmp28_, FALSE);
	_g_object_unref0 (self->priv->submit_btn);
	self->priv->submit_btn = _tmp30_;
	_tmp31_ = self->priv->submit_btn;
	g_signal_connect_object (_tmp31_, "clicked", (GCallback) ___lambda149__gtk_button_clicked, self, 0);
	_tmp32_ = self->priv->submit_btn;
	adw_dialog_set_default_widget ((AdwDialog*) self, (GtkWidget*) _tmp32_);
	dc_classic_email_dialog_apply_initial_values (self);
	_tmp33_ = (GtkScrolledWindow*) gtk_scrolled_window_new ();
	g_object_ref_sink (_tmp33_);
	scroll = _tmp33_;
	g_object_set (scroll, "hscrollbar-policy", GTK_POLICY_NEVER, NULL);
	gtk_scrolled_window_set_propagate_natural_height (scroll, TRUE);
	gtk_widget_set_vexpand ((GtkWidget*) scroll, TRUE);
	_tmp34_ = content;
	gtk_scrolled_window_set_child (scroll, (GtkWidget*) _tmp34_);
	result = (GtkWidget*) scroll;
	_g_object_unref0 (hint);
	_g_object_unref0 (content);
	return result;
}

static GtkWidget*
dc_classic_email_dialog_build_advanced_grid (DcClassicEmailDialog* self)
{
	GtkGrid* _tmp0_;
	GtkGrid* _tmp1_;
	GtkGrid* _tmp2_;
	GtkGrid* _tmp3_;
	GtkGrid* _tmp4_;
	GtkEntry* _tmp5_;
	GtkEntry* _tmp6_;
	GtkEntry* _tmp7_;
	GtkEntry* _tmp8_;
	GtkEntry* _tmp9_;
	GtkEntry* _tmp10_;
	GtkDropDown* _tmp11_;
	GtkDropDown* _tmp12_;
	GtkEntry* _tmp13_;
	GtkEntry* _tmp14_;
	GtkPasswordEntry* _tmp15_;
	GtkPasswordEntry* _tmp16_;
	GtkPasswordEntry* _tmp17_;
	GtkPasswordEntry* _tmp18_;
	GtkEntry* _tmp19_;
	GtkEntry* _tmp20_;
	GtkEntry* _tmp21_;
	GtkEntry* _tmp22_;
	GtkDropDown* _tmp23_;
	GtkDropDown* _tmp24_;
	gchar* _tmp25_;
	gchar* _tmp26_;
	gchar* _tmp27_;
	gchar** _tmp28_;
	gchar** _tmp29_;
	gint _tmp29__length1;
	GtkDropDown* _tmp30_;
	GtkDropDown* _tmp31_;
	GtkGrid* _tmp32_;
	GtkWidget* _tmp33_;
	GtkWidget* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = (GtkGrid*) gtk_grid_new ();
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->adv_grid);
	self->priv->adv_grid = _tmp0_;
	_tmp1_ = self->priv->adv_grid;
	gtk_grid_set_column_spacing (_tmp1_, 12);
	_tmp2_ = self->priv->adv_grid;
	gtk_grid_set_row_spacing (_tmp2_, 8);
	_tmp3_ = self->priv->adv_grid;
	gtk_widget_set_margin_top ((GtkWidget*) _tmp3_, 8);
	_tmp4_ = self->priv->adv_grid;
	gtk_widget_set_margin_start ((GtkWidget*) _tmp4_, 6);
	dc_classic_email_dialog_adv_heading (self, "Inbox (IMAP)");
	_tmp5_ = dc_classic_email_dialog_adv_entry ("Automatic");
	_g_object_unref0 (self->priv->imap_user_entry);
	self->priv->imap_user_entry = _tmp5_;
	_tmp6_ = self->priv->imap_user_entry;
	dc_classic_email_dialog_adv_field (self, "Login name", (GtkWidget*) _tmp6_);
	_tmp7_ = dc_classic_email_dialog_adv_entry ("Automatic");
	_g_object_unref0 (self->priv->imap_server_entry);
	self->priv->imap_server_entry = _tmp7_;
	_tmp8_ = self->priv->imap_server_entry;
	dc_classic_email_dialog_adv_field (self, "Server", (GtkWidget*) _tmp8_);
	_tmp9_ = dc_classic_email_dialog_adv_port_entry ();
	_g_object_unref0 (self->priv->imap_port_entry);
	self->priv->imap_port_entry = _tmp9_;
	_tmp10_ = self->priv->imap_port_entry;
	dc_classic_email_dialog_adv_field (self, "Port", (GtkWidget*) _tmp10_);
	_tmp11_ = dc_classic_email_dialog_security_dropdown ();
	_g_object_unref0 (self->priv->imap_security_dd);
	self->priv->imap_security_dd = _tmp11_;
	_tmp12_ = self->priv->imap_security_dd;
	dc_classic_email_dialog_adv_field (self, "Security", (GtkWidget*) _tmp12_);
	dc_classic_email_dialog_adv_heading (self, "Outbox (SMTP)");
	_tmp13_ = dc_classic_email_dialog_adv_entry ("Same as IMAP");
	_g_object_unref0 (self->priv->smtp_user_entry);
	self->priv->smtp_user_entry = _tmp13_;
	_tmp14_ = self->priv->smtp_user_entry;
	dc_classic_email_dialog_adv_field (self, "Login name", (GtkWidget*) _tmp14_);
	_tmp15_ = (GtkPasswordEntry*) gtk_password_entry_new ();
	g_object_ref_sink (_tmp15_);
	_g_object_unref0 (self->priv->smtp_pass_entry);
	self->priv->smtp_pass_entry = _tmp15_;
	_tmp16_ = self->priv->smtp_pass_entry;
	g_object_set (_tmp16_, "placeholder-text", "Same as IMAP", NULL);
	_tmp17_ = self->priv->smtp_pass_entry;
	gtk_password_entry_set_show_peek_icon (_tmp17_, TRUE);
	_tmp18_ = self->priv->smtp_pass_entry;
	dc_classic_email_dialog_adv_field (self, "Password", (GtkWidget*) _tmp18_);
	_tmp19_ = dc_classic_email_dialog_adv_entry ("Automatic");
	_g_object_unref0 (self->priv->smtp_server_entry);
	self->priv->smtp_server_entry = _tmp19_;
	_tmp20_ = self->priv->smtp_server_entry;
	dc_classic_email_dialog_adv_field (self, "Server", (GtkWidget*) _tmp20_);
	_tmp21_ = dc_classic_email_dialog_adv_port_entry ();
	_g_object_unref0 (self->priv->smtp_port_entry);
	self->priv->smtp_port_entry = _tmp21_;
	_tmp22_ = self->priv->smtp_port_entry;
	dc_classic_email_dialog_adv_field (self, "Port", (GtkWidget*) _tmp22_);
	_tmp23_ = dc_classic_email_dialog_security_dropdown ();
	_g_object_unref0 (self->priv->smtp_security_dd);
	self->priv->smtp_security_dd = _tmp23_;
	_tmp24_ = self->priv->smtp_security_dd;
	dc_classic_email_dialog_adv_field (self, "Security", (GtkWidget*) _tmp24_);
	dc_classic_email_dialog_adv_heading (self, "Certificates");
	_tmp25_ = g_strdup ("Automatic");
	_tmp26_ = g_strdup ("Strict");
	_tmp27_ = g_strdup ("Accept invalid certificates");
	_tmp28_ = g_new0 (gchar*, 3 + 1);
	_tmp28_[0] = _tmp25_;
	_tmp28_[1] = _tmp26_;
	_tmp28_[2] = _tmp27_;
	_tmp29_ = _tmp28_;
	_tmp29__length1 = 3;
	_tmp30_ = (GtkDropDown*) gtk_drop_down_new_from_strings (_tmp29_);
	g_object_ref_sink (_tmp30_);
	_g_object_unref0 (self->priv->cert_checks_dd);
	self->priv->cert_checks_dd = _tmp30_;
	_tmp29_ = (_vala_array_free (_tmp29_, _tmp29__length1, (GDestroyNotify) g_free), NULL);
	_tmp31_ = self->priv->cert_checks_dd;
	dc_classic_email_dialog_adv_field (self, "Validation", (GtkWidget*) _tmp31_);
	_tmp32_ = self->priv->adv_grid;
	_tmp33_ = _g_object_ref0 ((GtkWidget*) _tmp32_);
	result = _tmp33_;
	return result;
}

static void
dc_classic_email_dialog_adv_heading (DcClassicEmailDialog* self,
                                     const gchar* text)
{
	GtkLabel* label = NULL;
	GtkLabel* _tmp0_;
	GtkGrid* _tmp2_;
	GtkLabel* _tmp3_;
	gint _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (text != NULL);
	_tmp0_ = dc_account_setup_heading (text);
	label = _tmp0_;
	if (self->priv->adv_row > 0) {
		GtkLabel* _tmp1_;
		_tmp1_ = label;
		gtk_widget_set_margin_top ((GtkWidget*) _tmp1_, 8);
	}
	_tmp2_ = self->priv->adv_grid;
	_tmp3_ = label;
	_tmp4_ = self->priv->adv_row;
	self->priv->adv_row = _tmp4_ + 1;
	gtk_grid_attach (_tmp2_, (GtkWidget*) _tmp3_, 0, _tmp4_, 2, 1);
	_g_object_unref0 (label);
}

static void
dc_classic_email_dialog_adv_field (DcClassicEmailDialog* self,
                                   const gchar* label_text,
                                   GtkWidget* widget)
{
	GtkLabel* label = NULL;
	GtkLabel* _tmp0_;
	GtkGrid* _tmp1_;
	GtkGrid* _tmp2_;
	GtkWidget* _tmp3_;
	gint _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (label_text != NULL);
	g_return_if_fail (widget != NULL);
	_tmp0_ = (GtkLabel*) gtk_label_new (label_text);
	g_object_ref_sink (_tmp0_);
	label = _tmp0_;
	gtk_label_set_xalign (label, (gfloat) 0);
	gtk_widget_add_css_class ((GtkWidget*) label, "dim-label");
	_tmp1_ = self->priv->adv_grid;
	gtk_grid_attach (_tmp1_, (GtkWidget*) label, 0, self->priv->adv_row, 1, 1);
	gtk_widget_set_hexpand (widget, TRUE);
	_tmp2_ = self->priv->adv_grid;
	_tmp3_ = widget;
	_tmp4_ = self->priv->adv_row;
	self->priv->adv_row = _tmp4_ + 1;
	gtk_grid_attach (_tmp2_, _tmp3_, 1, _tmp4_, 1, 1);
	_g_object_unref0 (label);
}

static GtkEntry*
dc_classic_email_dialog_adv_entry (const gchar* placeholder)
{
	GtkEntry* _tmp0_;
	GtkEntry* result;
	g_return_val_if_fail (placeholder != NULL, NULL);
	_tmp0_ = dc_account_setup_entry (placeholder, TRUE, GTK_INPUT_PURPOSE_FREE_FORM);
	result = _tmp0_;
	return result;
}

static GtkEntry*
dc_classic_email_dialog_adv_port_entry (void)
{
	GtkEntry* entry = NULL;
	GtkEntry* _tmp0_;
	GtkEntry* result;
	_tmp0_ = dc_account_setup_entry ("Automatic", TRUE, GTK_INPUT_PURPOSE_DIGITS);
	entry = _tmp0_;
	gtk_entry_set_max_length (entry, 5);
	result = entry;
	return result;
}

static GtkDropDown*
dc_classic_email_dialog_security_dropdown (void)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar** _tmp4_;
	gchar** _tmp5_;
	gint _tmp5__length1;
	GtkDropDown* _tmp6_;
	GtkDropDown* _tmp7_;
	GtkDropDown* result;
	_tmp0_ = g_strdup ("Automatic");
	_tmp1_ = g_strdup ("SSL/TLS");
	_tmp2_ = g_strdup ("STARTTLS");
	_tmp3_ = g_strdup ("Plain (no encryption)");
	_tmp4_ = g_new0 (gchar*, 4 + 1);
	_tmp4_[0] = _tmp0_;
	_tmp4_[1] = _tmp1_;
	_tmp4_[2] = _tmp2_;
	_tmp4_[3] = _tmp3_;
	_tmp5_ = _tmp4_;
	_tmp5__length1 = 4;
	_tmp6_ = (GtkDropDown*) gtk_drop_down_new_from_strings (_tmp5_);
	g_object_ref_sink (_tmp6_);
	_tmp7_ = _tmp6_;
	_tmp5_ = (_vala_array_free (_tmp5_, _tmp5__length1, (GDestroyNotify) g_free), NULL);
	result = _tmp7_;
	return result;
}

static gchar*
dc_classic_email_dialog_security_value (GtkDropDown* dd)
{
	guint _tmp0_;
	guint _tmp1_;
	gchar* result;
	g_return_val_if_fail (dd != NULL, NULL);
	_tmp0_ = gtk_drop_down_get_selected (dd);
	_tmp1_ = _tmp0_;
	switch (_tmp1_) {
		case 1:
		{
			gchar* _tmp2_;
			_tmp2_ = g_strdup ("ssl");
			result = _tmp2_;
			return result;
		}
		case 2:
		{
			gchar* _tmp3_;
			_tmp3_ = g_strdup ("starttls");
			result = _tmp3_;
			return result;
		}
		case 3:
		{
			gchar* _tmp4_;
			_tmp4_ = g_strdup ("plain");
			result = _tmp4_;
			return result;
		}
		default:
		{
			result = NULL;
			return result;
		}
	}
}

static guint
dc_classic_email_dialog_security_index (const gchar* v)
{
	const gchar* _tmp0_;
	GQuark _tmp2_ = 0U;
	static GQuark _tmp1_label0 = 0;
	static GQuark _tmp1_label1 = 0;
	static GQuark _tmp1_label2 = 0;
	guint result;
	_tmp0_ = v;
	_tmp2_ = (NULL == _tmp0_) ? 0 : g_quark_from_string (_tmp0_);
	if (_tmp2_ == ((0 != _tmp1_label0) ? _tmp1_label0 : (_tmp1_label0 = g_quark_from_static_string ("ssl")))) {
		switch (0) {
			default:
			{
				result = (guint) 1;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label1) ? _tmp1_label1 : (_tmp1_label1 = g_quark_from_static_string ("starttls")))) {
		switch (0) {
			default:
			{
				result = (guint) 2;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label2) ? _tmp1_label2 : (_tmp1_label2 = g_quark_from_static_string ("plain")))) {
		switch (0) {
			default:
			{
				result = (guint) 3;
				return result;
			}
		}
	} else {
		switch (0) {
			default:
			{
				result = (guint) 0;
				return result;
			}
		}
	}
}

static void
dc_classic_email_dialog_apply_initial_values (DcClassicEmailDialog* self)
{
	DcEnteredLoginParams* _tmp0_;
	GtkEntry* _tmp1_;
	DcEnteredLoginParams* _tmp2_;
	const gchar* _tmp3_;
	GtkEntry* _tmp4_;
	GtkEntry* _tmp5_;
	GtkPasswordEntry* _tmp6_;
	DcEnteredLoginParams* _tmp7_;
	const gchar* _tmp8_;
	const gchar* _tmp9_ = NULL;
	DcEnteredLoginParams* _tmp10_;
	const gchar* _tmp11_;
	GtkEntry* _tmp12_;
	const gchar* _tmp13_ = NULL;
	DcEnteredLoginParams* _tmp14_;
	const gchar* _tmp15_;
	GtkEntry* _tmp16_;
	DcEnteredLoginParams* _tmp17_;
	GtkDropDown* _tmp22_;
	DcEnteredLoginParams* _tmp23_;
	const gchar* _tmp24_;
	const gchar* _tmp25_ = NULL;
	DcEnteredLoginParams* _tmp26_;
	const gchar* _tmp27_;
	GtkEntry* _tmp28_;
	const gchar* _tmp29_ = NULL;
	DcEnteredLoginParams* _tmp30_;
	const gchar* _tmp31_;
	GtkPasswordEntry* _tmp32_;
	const gchar* _tmp33_ = NULL;
	DcEnteredLoginParams* _tmp34_;
	const gchar* _tmp35_;
	GtkEntry* _tmp36_;
	DcEnteredLoginParams* _tmp37_;
	GtkDropDown* _tmp42_;
	DcEnteredLoginParams* _tmp43_;
	const gchar* _tmp44_;
	gint _tmp45_ = 0;
	DcEnteredLoginParams* _tmp46_;
	const gchar* _tmp47_;
	GtkDropDown* _tmp51_;
	GtkExpander* _tmp52_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->initial;
	if (_tmp0_ == NULL) {
		return;
	}
	_tmp1_ = self->priv->email_entry;
	_tmp2_ = self->priv->initial;
	_tmp3_ = _tmp2_->addr;
	gtk_editable_set_text ((GtkEditable*) _tmp1_, _tmp3_);
	_tmp4_ = self->priv->email_entry;
	gtk_editable_set_editable ((GtkEditable*) _tmp4_, FALSE);
	_tmp5_ = self->priv->email_entry;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp5_, FALSE);
	_tmp6_ = self->priv->pass_entry;
	_tmp7_ = self->priv->initial;
	_tmp8_ = _tmp7_->password;
	gtk_editable_set_text ((GtkEditable*) _tmp6_, _tmp8_);
	_tmp10_ = self->priv->initial;
	_tmp11_ = _tmp10_->imap_user;
	_tmp9_ = _tmp11_;
	if (_tmp9_ == NULL) {
		_tmp9_ = "";
	}
	_tmp12_ = self->priv->imap_user_entry;
	gtk_editable_set_text ((GtkEditable*) _tmp12_, _tmp9_);
	_tmp14_ = self->priv->initial;
	_tmp15_ = _tmp14_->imap_server;
	_tmp13_ = _tmp15_;
	if (_tmp13_ == NULL) {
		_tmp13_ = "";
	}
	_tmp16_ = self->priv->imap_server_entry;
	gtk_editable_set_text ((GtkEditable*) _tmp16_, _tmp13_);
	_tmp17_ = self->priv->initial;
	if (_tmp17_->imap_port > 0) {
		GtkEntry* _tmp18_;
		DcEnteredLoginParams* _tmp19_;
		gchar* _tmp20_;
		gchar* _tmp21_;
		_tmp18_ = self->priv->imap_port_entry;
		_tmp19_ = self->priv->initial;
		_tmp20_ = g_strdup_printf ("%i", _tmp19_->imap_port);
		_tmp21_ = _tmp20_;
		gtk_editable_set_text ((GtkEditable*) _tmp18_, _tmp21_);
		_g_free0 (_tmp21_);
	}
	_tmp22_ = self->priv->imap_security_dd;
	_tmp23_ = self->priv->initial;
	_tmp24_ = _tmp23_->imap_security;
	gtk_drop_down_set_selected (_tmp22_, dc_classic_email_dialog_security_index (_tmp24_));
	_tmp26_ = self->priv->initial;
	_tmp27_ = _tmp26_->smtp_user;
	_tmp25_ = _tmp27_;
	if (_tmp25_ == NULL) {
		_tmp25_ = "";
	}
	_tmp28_ = self->priv->smtp_user_entry;
	gtk_editable_set_text ((GtkEditable*) _tmp28_, _tmp25_);
	_tmp30_ = self->priv->initial;
	_tmp31_ = _tmp30_->smtp_password;
	_tmp29_ = _tmp31_;
	if (_tmp29_ == NULL) {
		_tmp29_ = "";
	}
	_tmp32_ = self->priv->smtp_pass_entry;
	gtk_editable_set_text ((GtkEditable*) _tmp32_, _tmp29_);
	_tmp34_ = self->priv->initial;
	_tmp35_ = _tmp34_->smtp_server;
	_tmp33_ = _tmp35_;
	if (_tmp33_ == NULL) {
		_tmp33_ = "";
	}
	_tmp36_ = self->priv->smtp_server_entry;
	gtk_editable_set_text ((GtkEditable*) _tmp36_, _tmp33_);
	_tmp37_ = self->priv->initial;
	if (_tmp37_->smtp_port > 0) {
		GtkEntry* _tmp38_;
		DcEnteredLoginParams* _tmp39_;
		gchar* _tmp40_;
		gchar* _tmp41_;
		_tmp38_ = self->priv->smtp_port_entry;
		_tmp39_ = self->priv->initial;
		_tmp40_ = g_strdup_printf ("%i", _tmp39_->smtp_port);
		_tmp41_ = _tmp40_;
		gtk_editable_set_text ((GtkEditable*) _tmp38_, _tmp41_);
		_g_free0 (_tmp41_);
	}
	_tmp42_ = self->priv->smtp_security_dd;
	_tmp43_ = self->priv->initial;
	_tmp44_ = _tmp43_->smtp_security;
	gtk_drop_down_set_selected (_tmp42_, dc_classic_email_dialog_security_index (_tmp44_));
	_tmp46_ = self->priv->initial;
	_tmp47_ = _tmp46_->certificate_checks;
	if (g_strcmp0 (_tmp47_, "strict") == 0) {
		_tmp45_ = 1;
	} else {
		gint _tmp48_ = 0;
		DcEnteredLoginParams* _tmp49_;
		const gchar* _tmp50_;
		_tmp49_ = self->priv->initial;
		_tmp50_ = _tmp49_->certificate_checks;
		if (g_strcmp0 (_tmp50_, "acceptInvalidCertificates") == 0) {
			_tmp48_ = 2;
		} else {
			_tmp48_ = 0;
		}
		_tmp45_ = _tmp48_;
	}
	_tmp51_ = self->priv->cert_checks_dd;
	gtk_drop_down_set_selected (_tmp51_, (guint) _tmp45_);
	_tmp52_ = self->priv->advanced_expander;
	gtk_expander_set_expanded (_tmp52_, dc_classic_email_dialog_has_advanced_values (self));
}

static gboolean
dc_classic_email_dialog_has_advanced_values (DcClassicEmailDialog* self)
{
	gboolean _tmp0_ = FALSE;
	DcEnteredLoginParams* _tmp1_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp1_ = self->priv->initial;
	if (_tmp1_ != NULL) {
		gboolean _tmp2_ = FALSE;
		gboolean _tmp3_ = FALSE;
		gboolean _tmp4_ = FALSE;
		gboolean _tmp5_ = FALSE;
		gboolean _tmp6_ = FALSE;
		gboolean _tmp7_ = FALSE;
		gboolean _tmp8_ = FALSE;
		gboolean _tmp9_ = FALSE;
		gboolean _tmp10_ = FALSE;
		DcEnteredLoginParams* _tmp11_;
		const gchar* _tmp12_;
		_tmp11_ = self->priv->initial;
		_tmp12_ = _tmp11_->imap_user;
		if (_tmp12_ != NULL) {
			_tmp10_ = TRUE;
		} else {
			DcEnteredLoginParams* _tmp13_;
			const gchar* _tmp14_;
			_tmp13_ = self->priv->initial;
			_tmp14_ = _tmp13_->imap_server;
			_tmp10_ = _tmp14_ != NULL;
		}
		if (_tmp10_) {
			_tmp9_ = TRUE;
		} else {
			DcEnteredLoginParams* _tmp15_;
			_tmp15_ = self->priv->initial;
			_tmp9_ = _tmp15_->imap_port > 0;
		}
		if (_tmp9_) {
			_tmp8_ = TRUE;
		} else {
			DcEnteredLoginParams* _tmp16_;
			const gchar* _tmp17_;
			_tmp16_ = self->priv->initial;
			_tmp17_ = _tmp16_->imap_security;
			_tmp8_ = _tmp17_ != NULL;
		}
		if (_tmp8_) {
			_tmp7_ = TRUE;
		} else {
			DcEnteredLoginParams* _tmp18_;
			const gchar* _tmp19_;
			_tmp18_ = self->priv->initial;
			_tmp19_ = _tmp18_->smtp_user;
			_tmp7_ = _tmp19_ != NULL;
		}
		if (_tmp7_) {
			_tmp6_ = TRUE;
		} else {
			DcEnteredLoginParams* _tmp20_;
			const gchar* _tmp21_;
			_tmp20_ = self->priv->initial;
			_tmp21_ = _tmp20_->smtp_password;
			_tmp6_ = _tmp21_ != NULL;
		}
		if (_tmp6_) {
			_tmp5_ = TRUE;
		} else {
			DcEnteredLoginParams* _tmp22_;
			const gchar* _tmp23_;
			_tmp22_ = self->priv->initial;
			_tmp23_ = _tmp22_->smtp_server;
			_tmp5_ = _tmp23_ != NULL;
		}
		if (_tmp5_) {
			_tmp4_ = TRUE;
		} else {
			DcEnteredLoginParams* _tmp24_;
			_tmp24_ = self->priv->initial;
			_tmp4_ = _tmp24_->smtp_port > 0;
		}
		if (_tmp4_) {
			_tmp3_ = TRUE;
		} else {
			DcEnteredLoginParams* _tmp25_;
			const gchar* _tmp26_;
			_tmp25_ = self->priv->initial;
			_tmp26_ = _tmp25_->smtp_security;
			_tmp3_ = _tmp26_ != NULL;
		}
		if (_tmp3_) {
			_tmp2_ = TRUE;
		} else {
			DcEnteredLoginParams* _tmp27_;
			const gchar* _tmp28_;
			_tmp27_ = self->priv->initial;
			_tmp28_ = _tmp27_->certificate_checks;
			_tmp2_ = _tmp28_ != NULL;
		}
		_tmp0_ = _tmp2_;
	} else {
		_tmp0_ = FALSE;
	}
	result = _tmp0_;
	return result;
}

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 gchar*
dc_classic_email_dialog_opt_text (GtkEntry* entry)
{
	gchar* t = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	const gchar* _tmp3_ = NULL;
	const gchar* _tmp4_;
	gint _tmp5_;
	gint _tmp6_;
	gchar* _tmp8_;
	gchar* result;
	g_return_val_if_fail (entry != NULL, NULL);
	_tmp0_ = gtk_editable_get_text ((GtkEditable*) entry);
	_tmp1_ = _tmp0_;
	_tmp2_ = string_strip (_tmp1_);
	t = _tmp2_;
	_tmp4_ = t;
	_tmp5_ = strlen (_tmp4_);
	_tmp6_ = _tmp5_;
	if (_tmp6_ > 0) {
		const gchar* _tmp7_;
		_tmp7_ = t;
		_tmp3_ = _tmp7_;
	} else {
		_tmp3_ = NULL;
	}
	_tmp8_ = g_strdup (_tmp3_);
	result = _tmp8_;
	_g_free0 (t);
	return result;
}

static gint
dc_classic_email_dialog_port_value (GtkEntry* entry)
{
	gchar* t = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	const gchar* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	gint v = 0;
	const gchar* _tmp6_;
	gint _tmp7_ = 0;
	gboolean _tmp8_ = FALSE;
	gint result;
	g_return_val_if_fail (entry != NULL, -1);
	_tmp0_ = gtk_editable_get_text ((GtkEditable*) entry);
	_tmp1_ = _tmp0_;
	_tmp2_ = string_strip (_tmp1_);
	t = _tmp2_;
	_tmp3_ = t;
	_tmp4_ = strlen (_tmp3_);
	_tmp5_ = _tmp4_;
	if (_tmp5_ == 0) {
		result = 0;
		_g_free0 (t);
		return result;
	}
	_tmp6_ = t;
	v = atoi (_tmp6_);
	if (v > 0) {
		_tmp8_ = v <= 65535;
	} else {
		_tmp8_ = FALSE;
	}
	if (_tmp8_) {
		_tmp7_ = v;
	} else {
		_tmp7_ = -1;
	}
	result = _tmp7_;
	_g_free0 (t);
	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 DcEnteredLoginParams*
dc_classic_email_dialog_collect_params (DcClassicEmailDialog* self)
{
	DcEnteredLoginParams* p = NULL;
	DcEnteredLoginParams* _tmp0_;
	DcEnteredLoginParams* _tmp1_;
	GtkEntry* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_;
	gchar* _tmp5_;
	DcEnteredLoginParams* _tmp6_;
	GtkPasswordEntry* _tmp7_;
	const gchar* _tmp8_;
	const gchar* _tmp9_;
	gchar* _tmp10_;
	gboolean _tmp11_ = FALSE;
	DcEnteredLoginParams* _tmp12_;
	const gchar* _tmp13_;
	gint _tmp14_;
	gint _tmp15_;
	DcEnteredLoginParams* _tmp18_;
	const gchar* _tmp19_;
	gint _tmp20_;
	gint _tmp21_;
	DcEnteredLoginParams* _tmp22_;
	GtkEntry* _tmp23_;
	gchar* _tmp24_;
	DcEnteredLoginParams* _tmp25_;
	GtkEntry* _tmp26_;
	gchar* _tmp27_;
	DcEnteredLoginParams* _tmp28_;
	GtkEntry* _tmp29_;
	DcEnteredLoginParams* _tmp30_;
	GtkDropDown* _tmp31_;
	gchar* _tmp32_;
	DcEnteredLoginParams* _tmp33_;
	GtkEntry* _tmp34_;
	gchar* _tmp35_;
	const gchar* _tmp36_ = NULL;
	GtkPasswordEntry* _tmp37_;
	const gchar* _tmp38_;
	const gchar* _tmp39_;
	gint _tmp40_;
	gint _tmp41_;
	DcEnteredLoginParams* _tmp45_;
	gchar* _tmp46_;
	DcEnteredLoginParams* _tmp47_;
	GtkEntry* _tmp48_;
	gchar* _tmp49_;
	DcEnteredLoginParams* _tmp50_;
	GtkEntry* _tmp51_;
	DcEnteredLoginParams* _tmp52_;
	GtkDropDown* _tmp53_;
	gchar* _tmp54_;
	gboolean _tmp55_ = FALSE;
	DcEnteredLoginParams* _tmp56_;
	GtkDropDown* _tmp58_;
	guint _tmp59_;
	guint _tmp60_;
	DcEnteredLoginParams* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = dc_entered_login_params_new ();
	p = _tmp0_;
	_tmp1_ = p;
	_tmp2_ = self->priv->email_entry;
	_tmp3_ = gtk_editable_get_text ((GtkEditable*) _tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = string_strip (_tmp4_);
	_g_free0 (_tmp1_->addr);
	_tmp1_->addr = _tmp5_;
	_tmp6_ = p;
	_tmp7_ = self->priv->pass_entry;
	_tmp8_ = gtk_editable_get_text ((GtkEditable*) _tmp7_);
	_tmp9_ = _tmp8_;
	_tmp10_ = g_strdup (_tmp9_);
	_g_free0 (_tmp6_->password);
	_tmp6_->password = _tmp10_;
	_tmp12_ = p;
	_tmp13_ = _tmp12_->addr;
	_tmp14_ = strlen (_tmp13_);
	_tmp15_ = _tmp14_;
	if (_tmp15_ == 0) {
		_tmp11_ = TRUE;
	} else {
		DcEnteredLoginParams* _tmp16_;
		const gchar* _tmp17_;
		_tmp16_ = p;
		_tmp17_ = _tmp16_->addr;
		_tmp11_ = !string_contains (_tmp17_, "@");
	}
	if (_tmp11_) {
		dc_show_error ((GtkWidget*) self, "Please enter a valid email address.");
		result = NULL;
		_g_object_unref0 (p);
		return result;
	}
	_tmp18_ = p;
	_tmp19_ = _tmp18_->password;
	_tmp20_ = strlen (_tmp19_);
	_tmp21_ = _tmp20_;
	if (_tmp21_ == 0) {
		dc_show_error ((GtkWidget*) self, "Please enter your password.");
		result = NULL;
		_g_object_unref0 (p);
		return result;
	}
	_tmp22_ = p;
	_tmp23_ = self->priv->imap_user_entry;
	_tmp24_ = dc_classic_email_dialog_opt_text (_tmp23_);
	_g_free0 (_tmp22_->imap_user);
	_tmp22_->imap_user = _tmp24_;
	_tmp25_ = p;
	_tmp26_ = self->priv->imap_server_entry;
	_tmp27_ = dc_classic_email_dialog_opt_text (_tmp26_);
	_g_free0 (_tmp25_->imap_server);
	_tmp25_->imap_server = _tmp27_;
	_tmp28_ = p;
	_tmp29_ = self->priv->imap_port_entry;
	_tmp28_->imap_port = dc_classic_email_dialog_port_value (_tmp29_);
	_tmp30_ = p;
	_tmp31_ = self->priv->imap_security_dd;
	_tmp32_ = dc_classic_email_dialog_security_value (_tmp31_);
	_g_free0 (_tmp30_->imap_security);
	_tmp30_->imap_security = _tmp32_;
	_tmp33_ = p;
	_tmp34_ = self->priv->smtp_user_entry;
	_tmp35_ = dc_classic_email_dialog_opt_text (_tmp34_);
	_g_free0 (_tmp33_->smtp_user);
	_tmp33_->smtp_user = _tmp35_;
	_tmp37_ = self->priv->smtp_pass_entry;
	_tmp38_ = gtk_editable_get_text ((GtkEditable*) _tmp37_);
	_tmp39_ = _tmp38_;
	_tmp40_ = strlen (_tmp39_);
	_tmp41_ = _tmp40_;
	if (_tmp41_ > 0) {
		GtkPasswordEntry* _tmp42_;
		const gchar* _tmp43_;
		const gchar* _tmp44_;
		_tmp42_ = self->priv->smtp_pass_entry;
		_tmp43_ = gtk_editable_get_text ((GtkEditable*) _tmp42_);
		_tmp44_ = _tmp43_;
		_tmp36_ = _tmp44_;
	} else {
		_tmp36_ = NULL;
	}
	_tmp45_ = p;
	_tmp46_ = g_strdup (_tmp36_);
	_g_free0 (_tmp45_->smtp_password);
	_tmp45_->smtp_password = _tmp46_;
	_tmp47_ = p;
	_tmp48_ = self->priv->smtp_server_entry;
	_tmp49_ = dc_classic_email_dialog_opt_text (_tmp48_);
	_g_free0 (_tmp47_->smtp_server);
	_tmp47_->smtp_server = _tmp49_;
	_tmp50_ = p;
	_tmp51_ = self->priv->smtp_port_entry;
	_tmp50_->smtp_port = dc_classic_email_dialog_port_value (_tmp51_);
	_tmp52_ = p;
	_tmp53_ = self->priv->smtp_security_dd;
	_tmp54_ = dc_classic_email_dialog_security_value (_tmp53_);
	_g_free0 (_tmp52_->smtp_security);
	_tmp52_->smtp_security = _tmp54_;
	_tmp56_ = p;
	if (_tmp56_->imap_port < 0) {
		_tmp55_ = TRUE;
	} else {
		DcEnteredLoginParams* _tmp57_;
		_tmp57_ = p;
		_tmp55_ = _tmp57_->smtp_port < 0;
	}
	if (_tmp55_) {
		dc_show_error ((GtkWidget*) self, "Ports must be numbers between 1 and 65535.");
		result = NULL;
		_g_object_unref0 (p);
		return result;
	}
	_tmp58_ = self->priv->cert_checks_dd;
	_tmp59_ = gtk_drop_down_get_selected (_tmp58_);
	_tmp60_ = _tmp59_;
	switch (_tmp60_) {
		case 1:
		{
			DcEnteredLoginParams* _tmp61_;
			gchar* _tmp62_;
			_tmp61_ = p;
			_tmp62_ = g_strdup ("strict");
			_g_free0 (_tmp61_->certificate_checks);
			_tmp61_->certificate_checks = _tmp62_;
			break;
		}
		case 2:
		{
			DcEnteredLoginParams* _tmp63_;
			gchar* _tmp64_;
			_tmp63_ = p;
			_tmp64_ = g_strdup ("acceptInvalidCertificates");
			_g_free0 (_tmp63_->certificate_checks);
			_tmp63_->certificate_checks = _tmp64_;
			break;
		}
		default:
		{
			DcEnteredLoginParams* _tmp65_;
			_tmp65_ = p;
			_g_free0 (_tmp65_->certificate_checks);
			_tmp65_->certificate_checks = NULL;
			break;
		}
	}
	result = p;
	return result;
}

static void
_dc_classic_email_dialog_cancel_configure_dc_account_progress_page_cancel_requested (DcAccountProgressPage* _sender,
                                                                                     gpointer self)
{
	dc_classic_email_dialog_cancel_configure ((DcClassicEmailDialog*) self);
}

static GtkWidget*
dc_classic_email_dialog_build_progress_page (DcClassicEmailDialog* self)
{
	DcAccountProgressPage* _tmp0_;
	DcAccountProgressPage* _tmp1_;
	DcAccountProgressPage* _tmp2_;
	GtkWidget* _tmp3_;
	GtkWidget* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = dc_account_progress_page_new ("Connecting…", TRUE);
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->progress_page);
	self->priv->progress_page = _tmp0_;
	_tmp1_ = self->priv->progress_page;
	g_signal_connect_object (_tmp1_, "cancel-requested", (GCallback) _dc_classic_email_dialog_cancel_configure_dc_account_progress_page_cancel_requested, self, 0);
	_tmp2_ = self->priv->progress_page;
	_tmp3_ = _g_object_ref0 ((GtkWidget*) _tmp2_);
	result = _tmp3_;
	return result;
}

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

static void
dc_classic_email_dialog_do_configure (DcClassicEmailDialog* self,
                                      GAsyncReadyCallback _callback_,
                                      gpointer _user_data_)
{
	DcClassicEmailDialogDoConfigureData* _data_;
	DcClassicEmailDialog* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (DcClassicEmailDialogDoConfigureData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_classic_email_dialog_do_configure_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	dc_classic_email_dialog_do_configure_co (_data_);
}

static void
dc_classic_email_dialog_do_configure_finish (DcClassicEmailDialog* self,
                                             GAsyncResult* _res_)
{
	DcClassicEmailDialogDoConfigureData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
_dc_classic_email_dialog_on_configure_progress_dc_event_handler_configure_progress (DcEventHandler* _sender,
                                                                                    gint context_id,
                                                                                    gint progress,
                                                                                    const gchar* comment,
                                                                                    gpointer self)
{
	dc_classic_email_dialog_on_configure_progress ((DcClassicEmailDialog*) self, context_id, progress, comment);
}

static void
dc_classic_email_dialog_do_configure_ready (GObject* source_object,
                                            GAsyncResult* _res_,
                                            gpointer _user_data_)
{
	DcClassicEmailDialogDoConfigureData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_classic_email_dialog_do_configure_co (_data_);
}

static gboolean
dc_classic_email_dialog_do_configure_co (DcClassicEmailDialogDoConfigureData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	if (_data_->self->priv->configure_running) {
		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_->_tmp0_ = dc_classic_email_dialog_collect_params (_data_->self);
	_data_->params = _data_->_tmp0_;
	_data_->_tmp1_ = _data_->params;
	if (_data_->_tmp1_ == NULL) {
		_g_object_unref0 (_data_->params);
		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_->self->priv->configure_running = TRUE;
	_data_->_tmp2_ = _data_->self->priv->stack;
	gtk_stack_set_visible_child_name (_data_->_tmp2_, "progress");
	_data_->_tmp3_ = _data_->self->priv->progress_page;
	_data_->_tmp4_ = _data_->params;
	_data_->_tmp5_ = _data_->_tmp4_->addr;
	_data_->_tmp6_ = g_strdup_printf ("Configuring %s…", _data_->_tmp5_);
	_data_->_tmp7_ = _data_->_tmp6_;
	dc_account_progress_page_set_status (_data_->_tmp3_, _data_->_tmp7_);
	_g_free0 (_data_->_tmp7_);
	_data_->_tmp8_ = _data_->self->priv->events;
	_data_->_tmp9_ = g_signal_connect_object (_data_->_tmp8_, "configure-progress", (GCallback) _dc_classic_email_dialog_on_configure_progress_dc_event_handler_configure_progress, _data_->self, 0);
	_data_->self->priv->progress_handler_id = _data_->_tmp9_;
	if (_data_->self->priv->edit_account_id > 0) {
		_data_->self->priv->target_account_id = _data_->self->priv->edit_account_id;
	} else {
		{
			_data_->_tmp11_ = _data_->self->priv->rpc;
			_data_->_state_ = 1;
			dc_rpc_client_add_account (_data_->_tmp11_, dc_classic_email_dialog_do_configure_ready, _data_);
			return FALSE;
			_state_1:
			_data_->_tmp10_ = dc_rpc_client_add_account_finish (_data_->_tmp11_, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			_data_->self->priv->new_account_id = _data_->_tmp10_;
		}
		goto __finally0;
		__catch0_g_error:
		{
			_data_->e = _data_->_inner_error0_;
			_data_->_inner_error0_ = NULL;
			dc_classic_email_dialog_cleanup_signal (_data_->self);
			_data_->self->priv->configure_running = FALSE;
			if (!_data_->self->priv->cancelled) {
				_data_->_tmp12_ = _data_->e;
				_data_->_tmp13_ = _data_->_tmp12_->message;
				_data_->_tmp14_ = g_strconcat ("Failed to create account: ", _data_->_tmp13_, NULL);
				_data_->_tmp15_ = _data_->_tmp14_;
				dc_show_error ((GtkWidget*) _data_->self, _data_->_tmp15_);
				_g_free0 (_data_->_tmp15_);
				_data_->_tmp16_ = _data_->self->priv->stack;
				gtk_stack_set_visible_child_name (_data_->_tmp16_, "input");
			}
			_g_error_free0 (_data_->e);
			_g_object_unref0 (_data_->params);
			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;
		}
		__finally0:
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->params);
			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;
		}
		_data_->self->priv->target_account_id = _data_->self->priv->new_account_id;
	}
	if (_data_->self->priv->cancelled) {
		dc_classic_email_dialog_cleanup_signal (_data_->self);
		_data_->self->priv->configure_running = FALSE;
		_g_object_unref0 (_data_->params);
		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_->_tmp17_ = _data_->self->priv->rpc;
		_data_->_tmp18_ = _data_->params;
		_data_->_state_ = 2;
		dc_rpc_client_add_or_update_transport (_data_->_tmp17_, _data_->self->priv->target_account_id, _data_->_tmp18_, dc_classic_email_dialog_do_configure_ready, _data_);
		return FALSE;
		_state_2:
		dc_rpc_client_add_or_update_transport_finish (_data_->_tmp17_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch1_g_error;
		}
	}
	goto __finally1;
	__catch1_g_error:
	{
		_data_->_vala1_e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		dc_classic_email_dialog_cleanup_signal (_data_->self);
		_data_->self->priv->configure_running = FALSE;
		if (_data_->self->priv->cancelled) {
			_g_error_free0 (_data_->_vala1_e);
			_g_object_unref0 (_data_->params);
			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;
		}
		if (_data_->self->priv->new_account_id > 0) {
			_data_->aid = _data_->self->priv->new_account_id;
			_data_->self->priv->new_account_id = 0;
			_data_->_tmp19_ = _data_->self->priv->rpc;
			_data_->_state_ = 3;
			dc_cleanup_pending_account (_data_->_tmp19_, _data_->aid, FALSE, dc_classic_email_dialog_do_configure_ready, _data_);
			return FALSE;
			_state_3:
			dc_cleanup_pending_account_finish (_data_->_res_);
		}
		_data_->_tmp20_ = _data_->_vala1_e;
		_data_->_tmp21_ = _data_->_tmp20_->message;
		_data_->_tmp22_ = g_strconcat ("Configuration failed: ", _data_->_tmp21_, NULL);
		_data_->_tmp23_ = _data_->_tmp22_;
		dc_show_error ((GtkWidget*) _data_->self, _data_->_tmp23_);
		_g_free0 (_data_->_tmp23_);
		_data_->_tmp24_ = _data_->self->priv->stack;
		gtk_stack_set_visible_child_name (_data_->_tmp24_, "input");
		_g_error_free0 (_data_->_vala1_e);
		_g_object_unref0 (_data_->params);
		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;
	}
	__finally1:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_object_unref0 (_data_->params);
		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;
	}
	dc_classic_email_dialog_cleanup_signal (_data_->self);
	_data_->self->priv->configure_running = FALSE;
	if (_data_->self->priv->cancelled) {
		_g_object_unref0 (_data_->params);
		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_->self->priv->configure_finished = TRUE;
	if (_data_->self->priv->edit_account_id > 0) {
		g_signal_emit (_data_->self, dc_classic_email_dialog_signals[DC_CLASSIC_EMAIL_DIALOG_TRANSPORT_UPDATED_SIGNAL], 0);
	} else {
		_data_->created = _data_->self->priv->new_account_id;
		_data_->self->priv->new_account_id = 0;
		g_signal_emit (_data_->self, dc_classic_email_dialog_signals[DC_CLASSIC_EMAIL_DIALOG_ACCOUNT_CREATED_SIGNAL], 0, _data_->created);
	}
	adw_dialog_close ((AdwDialog*) _data_->self);
	_g_object_unref0 (_data_->params);
	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
dc_classic_email_dialog_on_configure_progress (DcClassicEmailDialog* self,
                                               gint ctx,
                                               gint progress,
                                               const gchar* comment)
{
	DcAccountProgressPage* _tmp0_;
	g_return_if_fail (self != NULL);
	if (ctx != self->priv->target_account_id) {
		return;
	}
	_tmp0_ = self->priv->progress_page;
	dc_account_progress_page_set_permille (_tmp0_, progress, comment, "Configuring…");
}

static void
dc_classic_email_dialog_cleanup_signal (DcClassicEmailDialog* self)
{
	DcEventHandler* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->events;
	dc_disconnect_progress_handler (_tmp0_, &self->priv->progress_handler_id);
}

static void
dc_classic_email_dialog_cancel_configure (DcClassicEmailDialog* self)
{
	DcRpcClient* _tmp0_;
	g_return_if_fail (self != NULL);
	if (dc_close_if_idle ((AdwDialog*) self, self->priv->configure_running)) {
		return;
	}
	self->priv->cancelled = TRUE;
	_tmp0_ = self->priv->rpc;
	dc_stop_ongoing_account (_tmp0_, self->priv->target_account_id);
	adw_dialog_close ((AdwDialog*) self);
}

static void
dc_classic_email_dialog_on_dialog_closed (DcClassicEmailDialog* self)
{
	DcRpcClient* _tmp0_;
	g_return_if_fail (self != NULL);
	dc_classic_email_dialog_cleanup_signal (self);
	_tmp0_ = self->priv->rpc;
	dc_cleanup_unfinished_account (_tmp0_, &self->priv->new_account_id, self->priv->configure_finished);
}

static void
dc_classic_email_dialog_class_init (DcClassicEmailDialogClass * klass,
                                    gpointer klass_data)
{
	dc_classic_email_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DcClassicEmailDialog_private_offset);
	G_OBJECT_CLASS (klass)->finalize = dc_classic_email_dialog_finalize;
	dc_classic_email_dialog_signals[DC_CLASSIC_EMAIL_DIALOG_ACCOUNT_CREATED_SIGNAL] = g_signal_new ("account-created", DC_TYPE_CLASSIC_EMAIL_DIALOG, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
	dc_classic_email_dialog_signals[DC_CLASSIC_EMAIL_DIALOG_TRANSPORT_UPDATED_SIGNAL] = g_signal_new ("transport-updated", DC_TYPE_CLASSIC_EMAIL_DIALOG, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
dc_classic_email_dialog_instance_init (DcClassicEmailDialog * self,
                                       gpointer klass)
{
	self->priv = dc_classic_email_dialog_get_instance_private (self);
	self->priv->edit_account_id = 0;
	self->priv->initial = NULL;
	self->priv->adv_row = 0;
	self->priv->new_account_id = 0;
	self->priv->target_account_id = 0;
	self->priv->configure_running = FALSE;
	self->priv->configure_finished = FALSE;
	self->priv->cancelled = FALSE;
	self->priv->progress_handler_id = (gulong) 0;
}

static void
dc_classic_email_dialog_finalize (GObject * obj)
{
	DcClassicEmailDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DC_TYPE_CLASSIC_EMAIL_DIALOG, DcClassicEmailDialog);
	_g_object_unref0 (self->priv->rpc);
	_g_object_unref0 (self->priv->events);
	_g_object_unref0 (self->priv->initial);
	_g_object_unref0 (self->priv->stack);
	_g_object_unref0 (self->priv->email_entry);
	_g_object_unref0 (self->priv->pass_entry);
	_g_object_unref0 (self->priv->advanced_expander);
	_g_object_unref0 (self->priv->adv_grid);
	_g_object_unref0 (self->priv->imap_user_entry);
	_g_object_unref0 (self->priv->imap_server_entry);
	_g_object_unref0 (self->priv->imap_port_entry);
	_g_object_unref0 (self->priv->imap_security_dd);
	_g_object_unref0 (self->priv->smtp_user_entry);
	_g_object_unref0 (self->priv->smtp_pass_entry);
	_g_object_unref0 (self->priv->smtp_server_entry);
	_g_object_unref0 (self->priv->smtp_port_entry);
	_g_object_unref0 (self->priv->smtp_security_dd);
	_g_object_unref0 (self->priv->cert_checks_dd);
	_g_object_unref0 (self->priv->submit_btn);
	_g_object_unref0 (self->priv->progress_page);
	G_OBJECT_CLASS (dc_classic_email_dialog_parent_class)->finalize (obj);
}

/**
     * Sign in with a classic email account, or edit the transport settings
     * of an existing one. Mirrors the official client's login form: address
     * and password up front, plus an "Advanced Settings" section for manual
     * IMAP/SMTP server configuration when autoconfiguration is not enough.
     */
static GType
dc_classic_email_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DcClassicEmailDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dc_classic_email_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DcClassicEmailDialog), 0, (GInstanceInitFunc) dc_classic_email_dialog_instance_init, NULL };
	GType dc_classic_email_dialog_type_id;
	dc_classic_email_dialog_type_id = g_type_register_static (adw_dialog_get_type (), "DcClassicEmailDialog", &g_define_type_info, 0);
	DcClassicEmailDialog_private_offset = g_type_add_instance_private (dc_classic_email_dialog_type_id, sizeof (DcClassicEmailDialogPrivate));
	return dc_classic_email_dialog_type_id;
}

GType
dc_classic_email_dialog_get_type (void)
{
	static volatile gsize dc_classic_email_dialog_type_id__once = 0;
	if (g_once_init_enter (&dc_classic_email_dialog_type_id__once)) {
		GType dc_classic_email_dialog_type_id;
		dc_classic_email_dialog_type_id = dc_classic_email_dialog_get_type_once ();
		g_once_init_leave (&dc_classic_email_dialog_type_id__once, dc_classic_email_dialog_type_id);
	}
	return dc_classic_email_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 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;
}

