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

#include <adwaita.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>
#include <glib/gstdio.h>
#include <gdk/gdk.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_PROFILE_DIALOG (dc_profile_dialog_get_type ())
#define DC_PROFILE_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_PROFILE_DIALOG, DcProfileDialog))
#define DC_PROFILE_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_PROFILE_DIALOG, DcProfileDialogClass))
#define DC_IS_PROFILE_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_PROFILE_DIALOG))
#define DC_IS_PROFILE_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_PROFILE_DIALOG))
#define DC_PROFILE_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_PROFILE_DIALOG, DcProfileDialogClass))

typedef struct _DcProfileDialog DcProfileDialog;
typedef struct _DcProfileDialogClass DcProfileDialogClass;
typedef struct _DcProfileDialogPrivate DcProfileDialogPrivate;

#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;
enum  {
	DC_PROFILE_DIALOG_0_PROPERTY,
	DC_PROFILE_DIALOG_NUM_PROPERTIES
};
static GParamSpec* dc_profile_dialog_properties[DC_PROFILE_DIALOG_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _DcProfileDialogLoadProfileData DcProfileDialogLoadProfileData;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _DcProfileDialogDoSaveData DcProfileDialogDoSaveData;
typedef struct _DcProfileDialogPickAvatarData DcProfileDialogPickAvatarData;
enum  {
	DC_PROFILE_DIALOG_PROFILE_UPDATED_SIGNAL,
	DC_PROFILE_DIALOG_NUM_SIGNALS
};
static guint dc_profile_dialog_signals[DC_PROFILE_DIALOG_NUM_SIGNALS] = {0};

struct _DcProfileDialog {
	AdwDialog parent_instance;
	DcProfileDialogPrivate * priv;
};

struct _DcProfileDialogClass {
	AdwDialogClass parent_class;
};

struct _DcProfileDialogPrivate {
	DcRpcClient* rpc;
	AdwAvatar* avatar_widget;
	GtkEntry* name_entry;
	GtkEntry* status_entry;
	GtkLabel* email_label;
	gchar* avatar_path;
	gboolean avatar_changed;
};

struct _DcProfileDialogLoadProfileData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcProfileDialog* self;
	gchar* name;
	DcRpcClient* _tmp0_;
	gchar* _tmp1_;
	gchar* status;
	DcRpcClient* _tmp2_;
	gchar* _tmp3_;
	gchar* email;
	DcRpcClient* _tmp4_;
	gchar* _tmp5_;
	gchar* avatar;
	DcRpcClient* _tmp6_;
	gchar* _tmp7_;
	const gchar* _tmp8_;
	GtkEntry* _tmp9_;
	const gchar* _tmp10_;
	AdwAvatar* _tmp11_;
	const gchar* _tmp12_;
	const gchar* _tmp13_;
	GtkEntry* _tmp14_;
	const gchar* _tmp15_;
	const gchar* _tmp16_;
	GtkLabel* _tmp17_;
	const gchar* _tmp18_;
	gboolean _tmp19_;
	gboolean _tmp20_;
	const gchar* _tmp21_;
	const gchar* _tmp22_;
	gint _tmp23_;
	gint _tmp24_;
	const gchar* _tmp25_;
	const gchar* _tmp26_;
	gchar* _tmp27_;
	AdwAvatar* _tmp28_;
	const gchar* _tmp29_;
	GdkTexture* _tmp30_;
	GdkTexture* _tmp31_;
	GError* _inner_error0_;
};

struct _DcProfileDialogDoSaveData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcProfileDialog* self;
	DcRpcClient* _tmp0_;
	GtkEntry* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	DcRpcClient* _tmp6_;
	GtkEntry* _tmp7_;
	const gchar* _tmp8_;
	const gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	gboolean _tmp12_;
	const gchar* _tmp13_;
	DcRpcClient* _tmp14_;
	const gchar* _tmp15_;
	GError* e;
	GError* _tmp16_;
	const gchar* _tmp17_;
	GError* _inner_error0_;
};

struct _DcProfileDialogPickAvatarData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcProfileDialog* self;
	gchar* path;
	GtkRoot* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	AdwAvatar* _tmp5_;
	const gchar* _tmp6_;
	GdkTexture* _tmp7_;
	GdkTexture* _tmp8_;
};

static gint DcProfileDialog_private_offset;
static gpointer dc_profile_dialog_parent_class = NULL;

VALA_EXTERN GType dc_profile_dialog_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcProfileDialog, 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 DcProfileDialog* dc_profile_dialog_new (DcRpcClient* rpc);
VALA_EXTERN DcProfileDialog* dc_profile_dialog_construct (GType object_type,
                                              DcRpcClient* rpc);
static void __lambda80_ (DcProfileDialog* self);
static void dc_profile_dialog_do_save (DcProfileDialog* self,
                                GAsyncReadyCallback _callback_,
                                gpointer _user_data_);
static void dc_profile_dialog_do_save_finish (DcProfileDialog* self,
                                       GAsyncResult* _res_);
static void ___lambda80__gtk_button_clicked (GtkButton* _sender,
                                      gpointer self);
static void __lambda81_ (DcProfileDialog* self);
static void dc_profile_dialog_pick_avatar (DcProfileDialog* self,
                                    GAsyncReadyCallback _callback_,
                                    gpointer _user_data_);
static void dc_profile_dialog_pick_avatar_finish (DcProfileDialog* self,
                                           GAsyncResult* _res_);
static void ___lambda81__gtk_button_clicked (GtkButton* _sender,
                                      gpointer self);
static void __lambda82_ (DcProfileDialog* self);
static void ___lambda82__gtk_editable_changed (GtkEditable* _sender,
                                        gpointer self);
static void dc_profile_dialog_load_profile (DcProfileDialog* self,
                                     GAsyncReadyCallback _callback_,
                                     gpointer _user_data_);
static void dc_profile_dialog_load_profile_finish (DcProfileDialog* self,
                                            GAsyncResult* _res_);
static void dc_profile_dialog_load_profile_data_free (gpointer _data);
static gboolean dc_profile_dialog_load_profile_co (DcProfileDialogLoadProfileData* _data_);
VALA_EXTERN void dc_rpc_client_get_config (DcRpcClient* self,
                               const gchar* key,
                               gint acct_id,
                               GAsyncReadyCallback _callback_,
                               gpointer _user_data_);
VALA_EXTERN gchar* dc_rpc_client_get_config_finish (DcRpcClient* self,
                                        GAsyncResult* _res_,
                                        GError** error);
static void dc_profile_dialog_load_profile_ready (GObject* source_object,
                                           GAsyncResult* _res_,
                                           gpointer _user_data_);
VALA_EXTERN GdkTexture* dc_load_avatar (const gchar* path);
static void dc_profile_dialog_do_save_data_free (gpointer _data);
static gboolean dc_profile_dialog_do_save_co (DcProfileDialogDoSaveData* _data_);
VALA_EXTERN void dc_rpc_client_batch_set_config (DcRpcClient* self,
                                     const gchar* key,
                                     const gchar* val,
                                     GAsyncReadyCallback _callback_,
                                     gpointer _user_data_);
VALA_EXTERN void dc_rpc_client_batch_set_config_finish (DcRpcClient* self,
                                            GAsyncResult* _res_,
                                            GError** error);
static void dc_profile_dialog_do_save_ready (GObject* source_object,
                                      GAsyncResult* _res_,
                                      gpointer _user_data_);
VALA_EXTERN void dc_show_error (GtkWidget* parent,
                    const gchar* message);
static void dc_profile_dialog_pick_avatar_data_free (gpointer _data);
static gboolean dc_profile_dialog_pick_avatar_co (DcProfileDialogPickAvatarData* _data_);
VALA_EXTERN void dc_pick_image_file (GtkWindow* parent,
                         const gchar* title,
                         GAsyncReadyCallback _callback_,
                         gpointer _user_data_);
VALA_EXTERN gchar* dc_pick_image_file_finish (GAsyncResult* _res_);
static void dc_profile_dialog_pick_avatar_ready (GObject* source_object,
                                          GAsyncResult* _res_,
                                          gpointer _user_data_);
static void dc_profile_dialog_finalize (GObject * obj);
static GType dc_profile_dialog_get_type_once (void);

static inline gpointer
dc_profile_dialog_get_instance_private (DcProfileDialog* self)
{
	return G_STRUCT_MEMBER_P (self, DcProfileDialog_private_offset);
}

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

static void
__lambda80_ (DcProfileDialog* self)
{
	dc_profile_dialog_do_save (self, NULL, NULL);
}

static void
___lambda80__gtk_button_clicked (GtkButton* _sender,
                                 gpointer self)
{
	__lambda80_ ((DcProfileDialog*) self);
}

static void
__lambda81_ (DcProfileDialog* self)
{
	dc_profile_dialog_pick_avatar (self, NULL, NULL);
}

static void
___lambda81__gtk_button_clicked (GtkButton* _sender,
                                 gpointer self)
{
	__lambda81_ ((DcProfileDialog*) self);
}

static void
__lambda82_ (DcProfileDialog* self)
{
	const gchar* _tmp0_ = NULL;
	GtkEntry* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	AdwAvatar* _tmp9_;
	_tmp1_ = self->priv->name_entry;
	_tmp2_ = gtk_editable_get_text ((GtkEditable*) _tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = strlen (_tmp3_);
	_tmp5_ = _tmp4_;
	if (_tmp5_ > 0) {
		GtkEntry* _tmp6_;
		const gchar* _tmp7_;
		const gchar* _tmp8_;
		_tmp6_ = self->priv->name_entry;
		_tmp7_ = gtk_editable_get_text ((GtkEditable*) _tmp6_);
		_tmp8_ = _tmp7_;
		_tmp0_ = _tmp8_;
	} else {
		_tmp0_ = "";
	}
	_tmp9_ = self->priv->avatar_widget;
	adw_avatar_set_text (_tmp9_, _tmp0_);
}

static void
___lambda82__gtk_editable_changed (GtkEditable* _sender,
                                   gpointer self)
{
	__lambda82_ ((DcProfileDialog*) self);
}

DcProfileDialog*
dc_profile_dialog_construct (GType object_type,
                             DcRpcClient* rpc)
{
	DcProfileDialog * self = NULL;
	DcRpcClient* _tmp0_;
	GtkBox* box = NULL;
	GtkBox* _tmp1_;
	AdwHeaderBar* header = NULL;
	AdwHeaderBar* _tmp2_;
	GtkButton* save_btn = NULL;
	GtkButton* _tmp3_;
	GtkBox* content = NULL;
	GtkBox* _tmp4_;
	AdwAvatar* _tmp5_;
	AdwAvatar* _tmp6_;
	AdwAvatar* _tmp7_;
	GtkButton* avatar_btn = NULL;
	GtkButton* _tmp8_;
	GtkSeparator* _tmp9_;
	GtkSeparator* _tmp10_;
	GtkLabel* name_lbl = NULL;
	GtkLabel* _tmp11_;
	GtkEntry* _tmp12_;
	GtkEntry* _tmp13_;
	GtkEntry* _tmp14_;
	GtkEntry* _tmp15_;
	GtkLabel* status_lbl = NULL;
	GtkLabel* _tmp16_;
	GtkEntry* _tmp17_;
	GtkEntry* _tmp18_;
	GtkEntry* _tmp19_;
	GtkLabel* email_lbl = NULL;
	GtkLabel* _tmp20_;
	GtkLabel* _tmp21_;
	GtkLabel* _tmp22_;
	GtkLabel* _tmp23_;
	GtkLabel* _tmp24_;
	GtkLabel* _tmp25_;
	GtkScrolledWindow* scroll = NULL;
	GtkScrolledWindow* _tmp26_;
	g_return_val_if_fail (rpc != NULL, NULL);
	self = (DcProfileDialog*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (rpc);
	_g_object_unref0 (self->priv->rpc);
	self->priv->rpc = _tmp0_;
	adw_dialog_set_title ((AdwDialog*) self, "My Profile");
	adw_dialog_set_content_width ((AdwDialog*) self, 360);
	adw_dialog_set_content_height ((AdwDialog*) self, 420);
	_tmp1_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	g_object_ref_sink (_tmp1_);
	box = _tmp1_;
	_tmp2_ = (AdwHeaderBar*) adw_header_bar_new ();
	g_object_ref_sink (_tmp2_);
	header = _tmp2_;
	_tmp3_ = (GtkButton*) gtk_button_new_with_label ("Save");
	g_object_ref_sink (_tmp3_);
	save_btn = _tmp3_;
	gtk_widget_add_css_class ((GtkWidget*) save_btn, "suggested-action");
	g_signal_connect_object (save_btn, "clicked", (GCallback) ___lambda80__gtk_button_clicked, self, 0);
	adw_header_bar_pack_end (header, (GtkWidget*) save_btn);
	gtk_box_append (box, (GtkWidget*) header);
	_tmp4_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
	g_object_ref_sink (_tmp4_);
	content = _tmp4_;
	gtk_widget_set_margin_start ((GtkWidget*) content, 16);
	gtk_widget_set_margin_end ((GtkWidget*) content, 16);
	gtk_widget_set_margin_top ((GtkWidget*) content, 12);
	gtk_widget_set_margin_bottom ((GtkWidget*) content, 16);
	_tmp5_ = (AdwAvatar*) adw_avatar_new (96, "", TRUE);
	g_object_ref_sink (_tmp5_);
	_g_object_unref0 (self->priv->avatar_widget);
	self->priv->avatar_widget = _tmp5_;
	_tmp6_ = self->priv->avatar_widget;
	gtk_widget_set_halign ((GtkWidget*) _tmp6_, GTK_ALIGN_CENTER);
	_tmp7_ = self->priv->avatar_widget;
	gtk_box_append (content, (GtkWidget*) _tmp7_);
	_tmp8_ = (GtkButton*) gtk_button_new_with_label ("Change Avatar");
	g_object_ref_sink (_tmp8_);
	avatar_btn = _tmp8_;
	gtk_widget_set_halign ((GtkWidget*) avatar_btn, GTK_ALIGN_CENTER);
	gtk_widget_add_css_class ((GtkWidget*) avatar_btn, "flat");
	g_signal_connect_object (avatar_btn, "clicked", (GCallback) ___lambda81__gtk_button_clicked, self, 0);
	gtk_box_append (content, (GtkWidget*) avatar_btn);
	_tmp9_ = (GtkSeparator*) gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
	g_object_ref_sink (_tmp9_);
	_tmp10_ = _tmp9_;
	gtk_box_append (content, (GtkWidget*) _tmp10_);
	_g_object_unref0 (_tmp10_);
	_tmp11_ = (GtkLabel*) gtk_label_new ("Display Name");
	g_object_ref_sink (_tmp11_);
	name_lbl = _tmp11_;
	gtk_widget_add_css_class ((GtkWidget*) name_lbl, "heading");
	gtk_widget_set_halign ((GtkWidget*) name_lbl, GTK_ALIGN_START);
	gtk_box_append (content, (GtkWidget*) name_lbl);
	_tmp12_ = (GtkEntry*) gtk_entry_new ();
	g_object_ref_sink (_tmp12_);
	_g_object_unref0 (self->priv->name_entry);
	self->priv->name_entry = _tmp12_;
	_tmp13_ = self->priv->name_entry;
	gtk_entry_set_placeholder_text (_tmp13_, "Your name");
	_tmp14_ = self->priv->name_entry;
	g_signal_connect_object ((GtkEditable*) _tmp14_, "changed", (GCallback) ___lambda82__gtk_editable_changed, self, 0);
	_tmp15_ = self->priv->name_entry;
	gtk_box_append (content, (GtkWidget*) _tmp15_);
	_tmp16_ = (GtkLabel*) gtk_label_new ("Status");
	g_object_ref_sink (_tmp16_);
	status_lbl = _tmp16_;
	gtk_widget_add_css_class ((GtkWidget*) status_lbl, "heading");
	gtk_widget_set_halign ((GtkWidget*) status_lbl, GTK_ALIGN_START);
	gtk_box_append (content, (GtkWidget*) status_lbl);
	_tmp17_ = (GtkEntry*) gtk_entry_new ();
	g_object_ref_sink (_tmp17_);
	_g_object_unref0 (self->priv->status_entry);
	self->priv->status_entry = _tmp17_;
	_tmp18_ = self->priv->status_entry;
	gtk_entry_set_placeholder_text (_tmp18_, "Your status message");
	_tmp19_ = self->priv->status_entry;
	gtk_box_append (content, (GtkWidget*) _tmp19_);
	_tmp20_ = (GtkLabel*) gtk_label_new ("Email");
	g_object_ref_sink (_tmp20_);
	email_lbl = _tmp20_;
	gtk_widget_add_css_class ((GtkWidget*) email_lbl, "heading");
	gtk_widget_set_halign ((GtkWidget*) email_lbl, GTK_ALIGN_START);
	gtk_box_append (content, (GtkWidget*) email_lbl);
	_tmp21_ = (GtkLabel*) gtk_label_new ("");
	g_object_ref_sink (_tmp21_);
	_g_object_unref0 (self->priv->email_label);
	self->priv->email_label = _tmp21_;
	_tmp22_ = self->priv->email_label;
	gtk_widget_set_halign ((GtkWidget*) _tmp22_, GTK_ALIGN_START);
	_tmp23_ = self->priv->email_label;
	gtk_widget_add_css_class ((GtkWidget*) _tmp23_, "dim-label");
	_tmp24_ = self->priv->email_label;
	gtk_label_set_selectable (_tmp24_, TRUE);
	_tmp25_ = self->priv->email_label;
	gtk_box_append (content, (GtkWidget*) _tmp25_);
	_tmp26_ = (GtkScrolledWindow*) gtk_scrolled_window_new ();
	g_object_ref_sink (_tmp26_);
	scroll = _tmp26_;
	gtk_widget_set_vexpand ((GtkWidget*) scroll, TRUE);
	g_object_set (scroll, "hscrollbar-policy", GTK_POLICY_NEVER, NULL);
	gtk_scrolled_window_set_child (scroll, (GtkWidget*) content);
	gtk_box_append (box, (GtkWidget*) scroll);
	adw_dialog_set_child ((AdwDialog*) self, (GtkWidget*) box);
	dc_profile_dialog_load_profile (self, NULL, NULL);
	_g_object_unref0 (scroll);
	_g_object_unref0 (email_lbl);
	_g_object_unref0 (status_lbl);
	_g_object_unref0 (name_lbl);
	_g_object_unref0 (avatar_btn);
	_g_object_unref0 (content);
	_g_object_unref0 (save_btn);
	_g_object_unref0 (header);
	_g_object_unref0 (box);
	return self;
}

DcProfileDialog*
dc_profile_dialog_new (DcRpcClient* rpc)
{
	return dc_profile_dialog_construct (DC_TYPE_PROFILE_DIALOG, rpc);
}

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

static void
dc_profile_dialog_load_profile (DcProfileDialog* self,
                                GAsyncReadyCallback _callback_,
                                gpointer _user_data_)
{
	DcProfileDialogLoadProfileData* _data_;
	DcProfileDialog* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (DcProfileDialogLoadProfileData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_profile_dialog_load_profile_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	dc_profile_dialog_load_profile_co (_data_);
}

static void
dc_profile_dialog_load_profile_finish (DcProfileDialog* self,
                                       GAsyncResult* _res_)
{
	DcProfileDialogLoadProfileData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
dc_profile_dialog_load_profile_ready (GObject* source_object,
                                      GAsyncResult* _res_,
                                      gpointer _user_data_)
{
	DcProfileDialogLoadProfileData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_profile_dialog_load_profile_co (_data_);
}

static gboolean
dc_profile_dialog_load_profile_co (DcProfileDialogLoadProfileData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		case 4:
		goto _state_4;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	{
		_data_->_tmp0_ = _data_->self->priv->rpc;
		_data_->_state_ = 1;
		dc_rpc_client_get_config (_data_->_tmp0_, "displayname", 0, dc_profile_dialog_load_profile_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp1_ = dc_rpc_client_get_config_finish (_data_->_tmp0_, _data_->_res_, &_data_->_inner_error0_);
		_data_->name = _data_->_tmp1_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp2_ = _data_->self->priv->rpc;
		_data_->_state_ = 2;
		dc_rpc_client_get_config (_data_->_tmp2_, "selfstatus", 0, dc_profile_dialog_load_profile_ready, _data_);
		return FALSE;
		_state_2:
		_data_->_tmp3_ = dc_rpc_client_get_config_finish (_data_->_tmp2_, _data_->_res_, &_data_->_inner_error0_);
		_data_->status = _data_->_tmp3_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_free0 (_data_->name);
			goto __catch0_g_error;
		}
		_data_->_tmp4_ = _data_->self->priv->rpc;
		_data_->_state_ = 3;
		dc_rpc_client_get_config (_data_->_tmp4_, "addr", 0, dc_profile_dialog_load_profile_ready, _data_);
		return FALSE;
		_state_3:
		_data_->_tmp5_ = dc_rpc_client_get_config_finish (_data_->_tmp4_, _data_->_res_, &_data_->_inner_error0_);
		_data_->email = _data_->_tmp5_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_free0 (_data_->status);
			_g_free0 (_data_->name);
			goto __catch0_g_error;
		}
		_data_->_tmp6_ = _data_->self->priv->rpc;
		_data_->_state_ = 4;
		dc_rpc_client_get_config (_data_->_tmp6_, "selfavatar", 0, dc_profile_dialog_load_profile_ready, _data_);
		return FALSE;
		_state_4:
		_data_->_tmp7_ = dc_rpc_client_get_config_finish (_data_->_tmp6_, _data_->_res_, &_data_->_inner_error0_);
		_data_->avatar = _data_->_tmp7_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_free0 (_data_->email);
			_g_free0 (_data_->status);
			_g_free0 (_data_->name);
			goto __catch0_g_error;
		}
		_data_->_tmp8_ = _data_->name;
		if (_data_->_tmp8_ != NULL) {
			_data_->_tmp9_ = _data_->self->priv->name_entry;
			_data_->_tmp10_ = _data_->name;
			gtk_editable_set_text ((GtkEditable*) _data_->_tmp9_, _data_->_tmp10_);
			_data_->_tmp11_ = _data_->self->priv->avatar_widget;
			_data_->_tmp12_ = _data_->name;
			adw_avatar_set_text (_data_->_tmp11_, _data_->_tmp12_);
		}
		_data_->_tmp13_ = _data_->status;
		if (_data_->_tmp13_ != NULL) {
			_data_->_tmp14_ = _data_->self->priv->status_entry;
			_data_->_tmp15_ = _data_->status;
			gtk_editable_set_text ((GtkEditable*) _data_->_tmp14_, _data_->_tmp15_);
		}
		_data_->_tmp16_ = _data_->email;
		if (_data_->_tmp16_ != NULL) {
			_data_->_tmp17_ = _data_->self->priv->email_label;
			_data_->_tmp18_ = _data_->email;
			gtk_label_set_label (_data_->_tmp17_, _data_->_tmp18_);
		}
		_data_->_tmp21_ = _data_->avatar;
		if (_data_->_tmp21_ != NULL) {
			_data_->_tmp22_ = _data_->avatar;
			_data_->_tmp23_ = strlen (_data_->_tmp22_);
			_data_->_tmp24_ = _data_->_tmp23_;
			_data_->_tmp20_ = _data_->_tmp24_ > 0;
		} else {
			_data_->_tmp20_ = FALSE;
		}
		if (_data_->_tmp20_) {
			_data_->_tmp25_ = _data_->avatar;
			_data_->_tmp19_ = g_file_test (_data_->_tmp25_, G_FILE_TEST_EXISTS);
		} else {
			_data_->_tmp19_ = FALSE;
		}
		if (_data_->_tmp19_) {
			_data_->_tmp26_ = _data_->avatar;
			_data_->_tmp27_ = g_strdup (_data_->_tmp26_);
			_g_free0 (_data_->self->priv->avatar_path);
			_data_->self->priv->avatar_path = _data_->_tmp27_;
		}
		_data_->_tmp28_ = _data_->self->priv->avatar_widget;
		_data_->_tmp29_ = _data_->avatar;
		_data_->_tmp30_ = dc_load_avatar (_data_->_tmp29_);
		_data_->_tmp31_ = _data_->_tmp30_;
		adw_avatar_set_custom_image (_data_->_tmp28_, (GdkPaintable*) _data_->_tmp31_);
		_g_object_unref0 (_data_->_tmp31_);
		_g_free0 (_data_->avatar);
		_g_free0 (_data_->email);
		_g_free0 (_data_->status);
		_g_free0 (_data_->name);
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_data_->_inner_error0_);
	}
	__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 void
dc_profile_dialog_do_save_data_free (gpointer _data)
{
	DcProfileDialogDoSaveData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (DcProfileDialogDoSaveData, _data_);
}

static void
dc_profile_dialog_do_save (DcProfileDialog* self,
                           GAsyncReadyCallback _callback_,
                           gpointer _user_data_)
{
	DcProfileDialogDoSaveData* _data_;
	DcProfileDialog* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (DcProfileDialogDoSaveData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_profile_dialog_do_save_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	dc_profile_dialog_do_save_co (_data_);
}

static void
dc_profile_dialog_do_save_finish (DcProfileDialog* self,
                                  GAsyncResult* _res_)
{
	DcProfileDialogDoSaveData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

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 void
dc_profile_dialog_do_save_ready (GObject* source_object,
                                 GAsyncResult* _res_,
                                 gpointer _user_data_)
{
	DcProfileDialogDoSaveData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_profile_dialog_do_save_co (_data_);
}

static gboolean
dc_profile_dialog_do_save_co (DcProfileDialogDoSaveData* _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:
	{
		_data_->_tmp0_ = _data_->self->priv->rpc;
		_data_->_tmp1_ = _data_->self->priv->name_entry;
		_data_->_tmp2_ = gtk_editable_get_text ((GtkEditable*) _data_->_tmp1_);
		_data_->_tmp3_ = _data_->_tmp2_;
		_data_->_tmp4_ = string_strip (_data_->_tmp3_);
		_data_->_tmp5_ = _data_->_tmp4_;
		_data_->_state_ = 1;
		dc_rpc_client_batch_set_config (_data_->_tmp0_, "displayname", _data_->_tmp5_, dc_profile_dialog_do_save_ready, _data_);
		return FALSE;
		_state_1:
		dc_rpc_client_batch_set_config_finish (_data_->_tmp0_, _data_->_res_, &_data_->_inner_error0_);
		_g_free0 (_data_->_tmp5_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp6_ = _data_->self->priv->rpc;
		_data_->_tmp7_ = _data_->self->priv->status_entry;
		_data_->_tmp8_ = gtk_editable_get_text ((GtkEditable*) _data_->_tmp7_);
		_data_->_tmp9_ = _data_->_tmp8_;
		_data_->_tmp10_ = string_strip (_data_->_tmp9_);
		_data_->_tmp11_ = _data_->_tmp10_;
		_data_->_state_ = 2;
		dc_rpc_client_batch_set_config (_data_->_tmp6_, "selfstatus", _data_->_tmp11_, dc_profile_dialog_do_save_ready, _data_);
		return FALSE;
		_state_2:
		dc_rpc_client_batch_set_config_finish (_data_->_tmp6_, _data_->_res_, &_data_->_inner_error0_);
		_g_free0 (_data_->_tmp11_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		if (_data_->self->priv->avatar_changed) {
			_data_->_tmp13_ = _data_->self->priv->avatar_path;
			_data_->_tmp12_ = _data_->_tmp13_ != NULL;
		} else {
			_data_->_tmp12_ = FALSE;
		}
		if (_data_->_tmp12_) {
			_data_->_tmp14_ = _data_->self->priv->rpc;
			_data_->_tmp15_ = _data_->self->priv->avatar_path;
			_data_->_state_ = 3;
			dc_rpc_client_batch_set_config (_data_->_tmp14_, "selfavatar", _data_->_tmp15_, dc_profile_dialog_do_save_ready, _data_);
			return FALSE;
			_state_3:
			dc_rpc_client_batch_set_config_finish (_data_->_tmp14_, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
		}
		g_signal_emit (_data_->self, dc_profile_dialog_signals[DC_PROFILE_DIALOG_PROFILE_UPDATED_SIGNAL], 0);
		adw_dialog_close ((AdwDialog*) _data_->self);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp16_ = _data_->e;
		_data_->_tmp17_ = _data_->_tmp16_->message;
		dc_show_error ((GtkWidget*) _data_->self, _data_->_tmp17_);
		_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 void
dc_profile_dialog_pick_avatar_data_free (gpointer _data)
{
	DcProfileDialogPickAvatarData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (DcProfileDialogPickAvatarData, _data_);
}

static void
dc_profile_dialog_pick_avatar (DcProfileDialog* self,
                               GAsyncReadyCallback _callback_,
                               gpointer _user_data_)
{
	DcProfileDialogPickAvatarData* _data_;
	DcProfileDialog* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (DcProfileDialogPickAvatarData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_profile_dialog_pick_avatar_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	dc_profile_dialog_pick_avatar_co (_data_);
}

static void
dc_profile_dialog_pick_avatar_finish (DcProfileDialog* self,
                                      GAsyncResult* _res_)
{
	DcProfileDialogPickAvatarData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
dc_profile_dialog_pick_avatar_ready (GObject* source_object,
                                     GAsyncResult* _res_,
                                     gpointer _user_data_)
{
	DcProfileDialogPickAvatarData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_profile_dialog_pick_avatar_co (_data_);
}

static gboolean
dc_profile_dialog_pick_avatar_co (DcProfileDialogPickAvatarData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = gtk_widget_get_root ((GtkWidget*) _data_->self);
	_data_->_state_ = 1;
	dc_pick_image_file (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, gtk_window_get_type (), GtkWindow), "Select Avatar", dc_profile_dialog_pick_avatar_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp1_ = dc_pick_image_file_finish (_data_->_res_);
	_data_->path = _data_->_tmp1_;
	_data_->_tmp2_ = _data_->path;
	if (_data_->_tmp2_ != NULL) {
		_data_->_tmp3_ = _data_->path;
		_data_->_tmp4_ = g_strdup (_data_->_tmp3_);
		_g_free0 (_data_->self->priv->avatar_path);
		_data_->self->priv->avatar_path = _data_->_tmp4_;
		_data_->self->priv->avatar_changed = TRUE;
		_data_->_tmp5_ = _data_->self->priv->avatar_widget;
		_data_->_tmp6_ = _data_->path;
		_data_->_tmp7_ = dc_load_avatar (_data_->_tmp6_);
		_data_->_tmp8_ = _data_->_tmp7_;
		adw_avatar_set_custom_image (_data_->_tmp5_, (GdkPaintable*) _data_->_tmp8_);
		_g_object_unref0 (_data_->_tmp8_);
	}
	_g_free0 (_data_->path);
	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_profile_dialog_class_init (DcProfileDialogClass * klass,
                              gpointer klass_data)
{
	dc_profile_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DcProfileDialog_private_offset);
	G_OBJECT_CLASS (klass)->finalize = dc_profile_dialog_finalize;
	dc_profile_dialog_signals[DC_PROFILE_DIALOG_PROFILE_UPDATED_SIGNAL] = g_signal_new ("profile-updated", DC_TYPE_PROFILE_DIALOG, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
dc_profile_dialog_instance_init (DcProfileDialog * self,
                                 gpointer klass)
{
	self->priv = dc_profile_dialog_get_instance_private (self);
	self->priv->avatar_path = NULL;
	self->priv->avatar_changed = FALSE;
}

static void
dc_profile_dialog_finalize (GObject * obj)
{
	DcProfileDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DC_TYPE_PROFILE_DIALOG, DcProfileDialog);
	_g_object_unref0 (self->priv->rpc);
	_g_object_unref0 (self->priv->avatar_widget);
	_g_object_unref0 (self->priv->name_entry);
	_g_object_unref0 (self->priv->status_entry);
	_g_object_unref0 (self->priv->email_label);
	_g_free0 (self->priv->avatar_path);
	G_OBJECT_CLASS (dc_profile_dialog_parent_class)->finalize (obj);
}

static GType
dc_profile_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DcProfileDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dc_profile_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DcProfileDialog), 0, (GInstanceInitFunc) dc_profile_dialog_instance_init, NULL };
	GType dc_profile_dialog_type_id;
	dc_profile_dialog_type_id = g_type_register_static (adw_dialog_get_type (), "DcProfileDialog", &g_define_type_info, 0);
	DcProfileDialog_private_offset = g_type_add_instance_private (dc_profile_dialog_type_id, sizeof (DcProfileDialogPrivate));
	return dc_profile_dialog_type_id;
}

GType
dc_profile_dialog_get_type (void)
{
	static volatile gsize dc_profile_dialog_type_id__once = 0;
	if (g_once_init_enter (&dc_profile_dialog_type_id__once)) {
		GType dc_profile_dialog_type_id;
		dc_profile_dialog_type_id = dc_profile_dialog_get_type_once ();
		g_once_init_leave (&dc_profile_dialog_type_id__once, dc_profile_dialog_type_id);
	}
	return dc_profile_dialog_type_id__once;
}

