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

#include <adwaita.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <string.h>
#include <stdlib.h>
#include <glib/gi18n-lib.h>
#include <gio/gio.h>
#include "config.h"

#define G4_CONTENT_WIDTH_MIN 340
#define G4_CONTENT_WIDTH_MAX 480
#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 G4_TYPE_DIALOG (g4_dialog_get_type ())
#define G4_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), G4_TYPE_DIALOG, G4Dialog))
#define G4_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), G4_TYPE_DIALOG, G4DialogClass))
#define G4_IS_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), G4_TYPE_DIALOG))
#define G4_IS_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), G4_TYPE_DIALOG))
#define G4_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), G4_TYPE_DIALOG, G4DialogClass))

typedef struct _G4Dialog G4Dialog;
typedef struct _G4DialogClass G4DialogClass;
typedef struct _G4DialogPrivate G4DialogPrivate;
enum  {
	G4_DIALOG_0_PROPERTY,
	G4_DIALOG_NUM_PROPERTIES
};
static GParamSpec* g4_dialog_properties[G4_DIALOG_NUM_PROPERTIES];
#define _g_free0(var) ((var == NULL) ? NULL : (var = (g_free (var), NULL)))

#define G4_TYPE_APPLICATION (g4_application_get_type ())
#define G4_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), G4_TYPE_APPLICATION, G4Application))
#define G4_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), G4_TYPE_APPLICATION, G4ApplicationClass))
#define G4_IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), G4_TYPE_APPLICATION))
#define G4_IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), G4_TYPE_APPLICATION))
#define G4_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), G4_TYPE_APPLICATION, G4ApplicationClass))

typedef struct _G4Application G4Application;
typedef struct _G4ApplicationClass G4ApplicationClass;

#define G4_TYPE_WINDOW (g4_window_get_type ())
#define G4_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), G4_TYPE_WINDOW, G4Window))
#define G4_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), G4_TYPE_WINDOW, G4WindowClass))
#define G4_IS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), G4_TYPE_WINDOW))
#define G4_IS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), G4_TYPE_WINDOW))
#define G4_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), G4_TYPE_WINDOW, G4WindowClass))

typedef struct _G4Window G4Window;
typedef struct _G4WindowClass G4WindowClass;
typedef struct _Block18Data Block18Data;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef void (*G4VoidFunc) (gpointer user_data);
typedef struct _Block19Data Block19Data;
typedef struct _G4ShowAlertDialogData G4ShowAlertDialogData;
typedef struct _G4ShowSaveFileDialogData G4ShowSaveFileDialogData;
typedef struct _G4ShowSelectFolderDialogData G4ShowSelectFolderDialogData;

struct _G4Dialog {
	AdwDialog parent_instance;
	G4DialogPrivate * priv;
};

struct _G4DialogClass {
	AdwDialogClass parent_class;
};

struct _Block18Data {
	int _ref_count_;
	G4Window* parent;
	AdwAboutDialog* win;
};

struct _Block19Data {
	int _ref_count_;
	gboolean _result_;
	gpointer _async_data_;
};

struct _G4ShowAlertDialogData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	gchar* text;
	GtkWindow* parent;
	gboolean result;
	Block19Data* _data19_;
	AdwAlertDialog* dialog;
	AdwAlertDialog* _tmp0_;
};

struct _G4ShowSaveFileDialogData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GtkWindow* parent;
	GFile* initial;
	GtkFileFilter** filters;
	gint filters_length1;
	GFile* result;
	GtkFileFilter* _tmp0_;
	gboolean _tmp1_;
	GtkFileFilter* _tmp2_;
	GtkFileFilter* default_filter;
	GtkFileFilter* _tmp3_;
	GListStore* filter_list;
	GListStore* _tmp4_;
	GtkFileFilter** filter_collection;
	gint filter_collection_length1;
	gint _filter_collection_size_;
	gint filter_it;
	GtkFileFilter* _tmp5_;
	GtkFileFilter* filter;
	GListStore* _tmp6_;
	GtkFileFilter* _tmp7_;
	GtkFileDialog* dialog;
	GtkFileDialog* _tmp8_;
	GListStore* _tmp9_;
	GtkFileFilter* _tmp10_;
	GFile* _tmp11_;
	GFile* _tmp12_;
	GFile* _tmp13_;
	GError* _inner_error0_;
};

struct _G4ShowSelectFolderDialogData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GtkWindow* parent;
	GFile* initial;
	GFile* result;
	GtkFileDialog* dialog;
	GtkFileDialog* _tmp0_;
	GFile* _tmp1_;
	GFile* _tmp2_;
	GFile* _tmp3_;
	GError* _inner_error0_;
};

static gpointer g4_dialog_parent_class = NULL;

VALA_EXTERN GType g4_dialog_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (G4Dialog, g_object_unref)
VALA_EXTERN void g4_dialog_present (G4Dialog* self,
                        GtkWidget* parent);
VALA_EXTERN gint g4_compute_dialog_width (GtkWidget* parent);
VALA_EXTERN G4Dialog* g4_dialog_new (void);
VALA_EXTERN G4Dialog* g4_dialog_construct (GType object_type);
static GType g4_dialog_get_type_once (void);
static gint* _int_dup (gint* self);
VALA_EXTERN GType g4_application_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (G4Application, g_object_unref)
VALA_EXTERN void g4_show_about_dialog (G4Application* app);
VALA_EXTERN GType g4_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (G4Window, g_object_unref)
static Block18Data* block18_data_ref (Block18Data* _data18_);
static void block18_data_unref (void * _userdata_);
VALA_EXTERN G4Window* g4_window_get_default (void);
VALA_EXTERN guint g4_run_idle_once (G4VoidFunc func,
                        gpointer func_target,
                        GDestroyNotify func_target_destroy_notify,
                        gint priority);
static void __lambda146_ (Block18Data* _data18_);
static void ___lambda146__g4_void_func (gpointer self);
VALA_EXTERN const gchar* g4_application_get_name (G4Application* self);
static void g4_show_alert_dialog_data_free (gpointer _data);
VALA_EXTERN void g4_show_alert_dialog (const gchar* text,
                           GtkWindow* parent,
                           GAsyncReadyCallback _callback_,
                           gpointer _user_data_);
VALA_EXTERN gboolean g4_show_alert_dialog_finish (GAsyncResult* _res_);
static gboolean g4_show_alert_dialog_co (G4ShowAlertDialogData* _data_);
static Block19Data* block19_data_ref (Block19Data* _data19_);
static void block19_data_unref (void * _userdata_);
static void __lambda70_ (Block19Data* _data19_,
                  const gchar* id);
static gboolean _g4_show_alert_dialog_co_gsource_func (gpointer self);
static void ___lambda70__adw_alert_dialog_response (AdwAlertDialog* _sender,
                                             const gchar* response,
                                             gpointer self);
static void g4_show_save_file_dialog_data_free (gpointer _data);
VALA_EXTERN void g4_show_save_file_dialog (GtkWindow* parent,
                               GFile* initial,
                               GtkFileFilter** filters,
                               gint filters_length1,
                               GAsyncReadyCallback _callback_,
                               gpointer _user_data_);
VALA_EXTERN GFile* g4_show_save_file_dialog_finish (GAsyncResult* _res_);
static gboolean g4_show_save_file_dialog_co (G4ShowSaveFileDialogData* _data_);
static void g4_show_save_file_dialog_ready (GObject* source_object,
                                     GAsyncResult* _res_,
                                     gpointer _user_data_);
static void g4_show_select_folder_dialog_data_free (gpointer _data);
VALA_EXTERN void g4_show_select_folder_dialog (GtkWindow* parent,
                                   GFile* initial,
                                   GAsyncReadyCallback _callback_,
                                   gpointer _user_data_);
VALA_EXTERN GFile* g4_show_select_folder_dialog_finish (GAsyncResult* _res_);
static gboolean g4_show_select_folder_dialog_co (G4ShowSelectFolderDialogData* _data_);
static void g4_show_select_folder_dialog_ready (GObject* source_object,
                                         GAsyncResult* _res_,
                                         gpointer _user_data_);
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);

void
g4_dialog_present (G4Dialog* self,
                   GtkWidget* parent)
{
	g_return_if_fail (self != NULL);
	adw_dialog_set_content_width ((AdwDialog*) self, g4_compute_dialog_width (parent));
	adw_dialog_present (G_TYPE_CHECK_INSTANCE_CAST (self, adw_dialog_get_type (), AdwDialog), parent);
}

G4Dialog*
g4_dialog_construct (GType object_type)
{
	G4Dialog * self = NULL;
	self = (G4Dialog*) g_object_new (object_type, NULL);
	return self;
}

G4Dialog*
g4_dialog_new (void)
{
	return g4_dialog_construct (G4_TYPE_DIALOG);
}

static void
g4_dialog_class_init (G4DialogClass * klass,
                      gpointer klass_data)
{
	g4_dialog_parent_class = g_type_class_peek_parent (klass);
}

static void
g4_dialog_instance_init (G4Dialog * self,
                         gpointer klass)
{
}

static GType
g4_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (G4DialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) g4_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (G4Dialog), 0, (GInstanceInitFunc) g4_dialog_instance_init, NULL };
	GType g4_dialog_type_id;
	g4_dialog_type_id = g_type_register_static (adw_dialog_get_type (), "G4Dialog", &g_define_type_info, 0);
	return g4_dialog_type_id;
}

GType
g4_dialog_get_type (void)
{
	static volatile gsize g4_dialog_type_id__once = 0;
	if (g_once_init_enter (&g4_dialog_type_id__once)) {
		GType g4_dialog_type_id;
		g4_dialog_type_id = g4_dialog_get_type_once ();
		g_once_init_leave (&g4_dialog_type_id__once, g4_dialog_type_id);
	}
	return g4_dialog_type_id__once;
}

static gint*
_int_dup (gint* self)
{
	gint* dup;
	dup = g_new0 (gint, 1);
	memcpy (dup, self, sizeof (gint));
	return dup;
}

static gpointer
__int_dup0 (gpointer self)
{
	return self ? _int_dup (self) : NULL;
}

gint
g4_compute_dialog_width (GtkWidget* parent)
{
	GtkWidget* _tmp0_ = NULL;
	gint* _tmp1_ = NULL;
	gint* _tmp4_ = NULL;
	gint* _tmp5_;
	gint width = 0;
	gint* _tmp8_;
	gint _tmp9_;
	gint result;
	_tmp0_ = parent;
	_tmp1_ = NULL;
	if (_tmp0_ != NULL) {
		gint _tmp2_;
		gint* _tmp3_;
		_tmp2_ = gtk_widget_get_width (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, gtk_widget_get_type (), GtkWidget));
		_tmp3_ = __int_dup0 (&_tmp2_);
		_g_free0 (_tmp1_);
		_tmp1_ = _tmp3_;
	}
	_tmp5_ = _tmp1_;
	_tmp1_ = NULL;
	_tmp4_ = _tmp5_;
	if (_tmp4_ == NULL) {
		gint _tmp6_;
		gint* _tmp7_;
		_tmp6_ = G4_CONTENT_WIDTH_MIN;
		_tmp7_ = __int_dup0 (&_tmp6_);
		_g_free0 (_tmp4_);
		_tmp4_ = _tmp7_;
	}
	_tmp8_ = _tmp4_;
	_tmp4_ = NULL;
	_tmp9_ = (gint) (*_tmp8_);
	_g_free0 (_tmp8_);
	width = _tmp9_;
	if (width > 360) {
		width = CLAMP ((width * 3) / 8, 360, G4_CONTENT_WIDTH_MAX);
	}
	result = width;
	_g_free0 (_tmp4_);
	_g_free0 (_tmp1_);
	return result;
}

static Block18Data*
block18_data_ref (Block18Data* _data18_)
{
	g_atomic_int_inc (&_data18_->_ref_count_);
	return _data18_;
}

static void
block18_data_unref (void * _userdata_)
{
	Block18Data* _data18_;
	_data18_ = (Block18Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data18_->_ref_count_)) {
		_g_object_unref0 (_data18_->win);
		_g_object_unref0 (_data18_->parent);
		g_slice_free (Block18Data, _data18_);
	}
}

static void
__lambda146_ (Block18Data* _data18_)
{
	gboolean _tmp0_ = FALSE;
	if (_data18_->parent != NULL) {
		gint _tmp1_;
		gint _tmp2_;
		g_object_get ((GtkWidget*) _data18_->win, "width-request", &_tmp1_, NULL);
		_tmp2_ = _tmp1_;
		_tmp0_ = gtk_widget_get_width ((GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (_data18_->parent, G4_TYPE_WINDOW, G4Window)) < _tmp2_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		gint _tmp3_;
		gint _tmp4_;
		g_object_get ((GtkWidget*) _data18_->win, "width-request", &_tmp3_, NULL);
		_tmp4_ = _tmp3_;
		g_object_set ((GtkWindow*) G_TYPE_CHECK_INSTANCE_CAST (_data18_->parent, G4_TYPE_WINDOW, G4Window), "default-width", _tmp4_, NULL);
	}
}

static void
___lambda146__g4_void_func (gpointer self)
{
	__lambda146_ (self);
}

void
g4_show_about_dialog (G4Application* app)
{
	Block18Data* _data18_;
	gchar** authors = NULL;
	gchar* _tmp0_;
	gchar** _tmp1_;
	gint authors_length1;
	gint _authors_size_;
	gchar* translator_credits = NULL;
	gchar* _tmp2_;
	gchar* website = NULL;
	gchar* _tmp3_;
	G4Window* _tmp4_;
	AdwAboutDialog* _tmp5_;
	const gchar* _tmp6_;
	const gchar* _tmp7_;
	const gchar* _tmp8_;
	const gchar* _tmp9_;
	g_return_if_fail (app != NULL);
	_data18_ = g_slice_new0 (Block18Data);
	_data18_->_ref_count_ = 1;
	_tmp0_ = g_strdup ("Nanling");
	_tmp1_ = g_new0 (gchar*, 1 + 1);
	_tmp1_[0] = _tmp0_;
	authors = _tmp1_;
	authors_length1 = 1;
	_authors_size_ = authors_length1;
	_tmp2_ = g_strdup (_ ("translator-credits"));
	translator_credits = _tmp2_;
	_tmp3_ = g_strdup ("https://gitlab.gnome.org/neithern/g4music");
	website = _tmp3_;
	_tmp4_ = g4_window_get_default ();
	_data18_->parent = _tmp4_;
	_tmp5_ = (AdwAboutDialog*) adw_about_dialog_new ();
	g_object_ref_sink (_tmp5_);
	_data18_->win = _tmp5_;
	g4_run_idle_once (___lambda146__g4_void_func, block18_data_ref (_data18_), block18_data_unref, G_PRIORITY_DEFAULT_IDLE);
	_tmp6_ = g_application_get_application_id ((GApplication*) app);
	_tmp7_ = _tmp6_;
	adw_about_dialog_set_application_icon (_data18_->win, _tmp7_);
	_tmp8_ = g4_application_get_name (app);
	_tmp9_ = _tmp8_;
	adw_about_dialog_set_application_name (_data18_->win, _tmp9_);
	adw_about_dialog_set_version (_data18_->win, VERSION);
	adw_about_dialog_set_license_type (_data18_->win, GTK_LICENSE_GPL_3_0);
	adw_about_dialog_set_developers (_data18_->win, authors);
	adw_about_dialog_set_website (_data18_->win, website);
	adw_about_dialog_set_issue_url (_data18_->win, "https://gitlab.gnome.org/neithern/g4music/issues");
	adw_about_dialog_set_translator_credits (_data18_->win, translator_credits);
	adw_dialog_present ((AdwDialog*) _data18_->win, (GtkWidget*) _data18_->parent);
	_g_free0 (website);
	_g_free0 (translator_credits);
	authors = (_vala_array_free (authors, authors_length1, (GDestroyNotify) g_free), NULL);
	block18_data_unref (_data18_);
	_data18_ = NULL;
}

static void
g4_show_alert_dialog_data_free (gpointer _data)
{
	G4ShowAlertDialogData* _data_;
	_data_ = _data;
	_g_free0 (_data_->text);
	_g_object_unref0 (_data_->parent);
	g_slice_free (G4ShowAlertDialogData, _data_);
}

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

void
g4_show_alert_dialog (const gchar* text,
                      GtkWindow* parent,
                      GAsyncReadyCallback _callback_,
                      gpointer _user_data_)
{
	G4ShowAlertDialogData* _data_;
	gchar* _tmp0_;
	GtkWindow* _tmp1_;
	g_return_if_fail (text != NULL);
	_data_ = g_slice_new0 (G4ShowAlertDialogData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, g4_show_alert_dialog_data_free);
	_tmp0_ = g_strdup (text);
	_g_free0 (_data_->text);
	_data_->text = _tmp0_;
	_tmp1_ = _g_object_ref0 (parent);
	_g_object_unref0 (_data_->parent);
	_data_->parent = _tmp1_;
	g4_show_alert_dialog_co (_data_);
}

gboolean
g4_show_alert_dialog_finish (GAsyncResult* _res_)
{
	gboolean result;
	G4ShowAlertDialogData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	return result;
}

static Block19Data*
block19_data_ref (Block19Data* _data19_)
{
	g_atomic_int_inc (&_data19_->_ref_count_);
	return _data19_;
}

static void
block19_data_unref (void * _userdata_)
{
	Block19Data* _data19_;
	_data19_ = (Block19Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data19_->_ref_count_)) {
		g_slice_free (Block19Data, _data19_);
	}
}

static gboolean
_g4_show_alert_dialog_co_gsource_func (gpointer self)
{
	gboolean result;
	result = g4_show_alert_dialog_co (self);
	return result;
}

static void
__lambda70_ (Block19Data* _data19_,
             const gchar* id)
{
	g_return_if_fail (id != NULL);
	_data19_->_result_ = g_strcmp0 (id, "yes") == 0;
	g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, _g4_show_alert_dialog_co_gsource_func, _data19_->_async_data_, NULL);
}

static void
___lambda70__adw_alert_dialog_response (AdwAlertDialog* _sender,
                                        const gchar* response,
                                        gpointer self)
{
	__lambda70_ (self, response);
}

static gboolean
g4_show_alert_dialog_co (G4ShowAlertDialogData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data19_ = g_slice_new0 (Block19Data);
	_data_->_data19_->_ref_count_ = 1;
	_data_->_data19_->_async_data_ = _data_;
	_data_->_data19_->_result_ = FALSE;
	_data_->_tmp0_ = (AdwAlertDialog*) adw_alert_dialog_new (NULL, _data_->text);
	g_object_ref_sink (_data_->_tmp0_);
	_data_->dialog = _data_->_tmp0_;
	adw_alert_dialog_add_response (_data_->dialog, "no", _ ("No"));
	adw_alert_dialog_add_response (_data_->dialog, "yes", _ ("Yes"));
	adw_alert_dialog_set_default_response (_data_->dialog, "yes");
	g_signal_connect_data (_data_->dialog, "response", (GCallback) ___lambda70__adw_alert_dialog_response, block19_data_ref (_data_->_data19_), (GClosureNotify) block19_data_unref, 0);
	adw_dialog_present ((AdwDialog*) _data_->dialog, (GtkWidget*) _data_->parent);
	_data_->_state_ = 1;
	return FALSE;
	_state_1:
	;
	_data_->result = _data_->_data19_->_result_;
	_g_object_unref0 (_data_->dialog);
	block19_data_unref (_data_->_data19_);
	_data_->_data19_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
g4_show_save_file_dialog_data_free (gpointer _data)
{
	G4ShowSaveFileDialogData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->parent);
	_g_object_unref0 (_data_->initial);
	_g_object_unref0 (_data_->result);
	g_slice_free (G4ShowSaveFileDialogData, _data_);
}

void
g4_show_save_file_dialog (GtkWindow* parent,
                          GFile* initial,
                          GtkFileFilter** filters,
                          gint filters_length1,
                          GAsyncReadyCallback _callback_,
                          gpointer _user_data_)
{
	G4ShowSaveFileDialogData* _data_;
	GtkWindow* _tmp0_;
	GFile* _tmp1_;
	_data_ = g_slice_new0 (G4ShowSaveFileDialogData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, g4_show_save_file_dialog_data_free);
	_tmp0_ = _g_object_ref0 (parent);
	_g_object_unref0 (_data_->parent);
	_data_->parent = _tmp0_;
	_tmp1_ = _g_object_ref0 (initial);
	_g_object_unref0 (_data_->initial);
	_data_->initial = _tmp1_;
	_data_->filters = filters;
	_data_->filters_length1 = filters_length1;
	g4_show_save_file_dialog_co (_data_);
}

GFile*
g4_show_save_file_dialog_finish (GAsyncResult* _res_)
{
	GFile* result;
	G4ShowSaveFileDialogData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
g4_show_save_file_dialog_ready (GObject* source_object,
                                GAsyncResult* _res_,
                                gpointer _user_data_)
{
	G4ShowSaveFileDialogData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	g4_show_save_file_dialog_co (_data_);
}

static gboolean
g4_show_save_file_dialog_co (G4ShowSaveFileDialogData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	if (_data_->filters != NULL) {
		_data_->_tmp1_ = ((_data_->filters_length1 * sizeof (GtkFileFilter*)) / sizeof (GtkFileFilter*)) > 0;
	} else {
		_data_->_tmp1_ = FALSE;
	}
	if (_data_->_tmp1_) {
		_data_->_tmp2_ = ((GtkFileFilter**) _data_->filters)[0];
		_data_->_tmp0_ = _data_->_tmp2_;
	} else {
		_data_->_tmp0_ = G_TYPE_CHECK_INSTANCE_CAST (NULL, gtk_file_filter_get_type (), GtkFileFilter);
	}
	_data_->_tmp3_ = _g_object_ref0 (_data_->_tmp0_);
	_data_->default_filter = _data_->_tmp3_;
	_data_->_tmp4_ = g_list_store_new (gtk_file_filter_get_type ());
	_data_->filter_list = _data_->_tmp4_;
	if (_data_->filters != NULL) {
		{
			_data_->filter_collection_length1 = 0;
			_data_->_filter_collection_size_ = 0;
			_data_->filter_collection = (GtkFileFilter**) _data_->filters;
			_data_->filter_collection_length1 = (_data_->filters_length1 * sizeof (GtkFileFilter*)) / sizeof (GtkFileFilter*);
			for (_data_->filter_it = 0; _data_->filter_it < _data_->filter_collection_length1; _data_->filter_it = _data_->filter_it + 1) {
				_data_->_tmp5_ = _g_object_ref0 (_data_->filter_collection[_data_->filter_it]);
				_data_->filter = _data_->_tmp5_;
				{
					_data_->_tmp6_ = _data_->filter_list;
					_data_->_tmp7_ = _data_->filter;
					g_list_store_append (_data_->_tmp6_, (GObject*) _data_->_tmp7_);
					_g_object_unref0 (_data_->filter);
				}
			}
		}
	}
	_data_->_tmp8_ = gtk_file_dialog_new ();
	_data_->dialog = _data_->_tmp8_;
	_data_->_tmp9_ = _data_->filter_list;
	gtk_file_dialog_set_filters (_data_->dialog, (GListModel*) _data_->_tmp9_);
	gtk_file_dialog_set_modal (_data_->dialog, TRUE);
	_data_->_tmp10_ = _data_->default_filter;
	gtk_file_dialog_set_default_filter (_data_->dialog, _data_->_tmp10_);
	gtk_file_dialog_set_initial_file (_data_->dialog, _data_->initial);
	{
		_data_->_state_ = 1;
		gtk_file_dialog_save (_data_->dialog, _data_->parent, NULL, g4_show_save_file_dialog_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp12_ = gtk_file_dialog_save_finish (_data_->dialog, _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp11_ = _data_->_tmp12_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp13_ = _data_->_tmp11_;
		_data_->_tmp11_ = NULL;
		_data_->result = _data_->_tmp13_;
		_g_object_unref0 (_data_->_tmp11_);
		_g_object_unref0 (_data_->dialog);
		_g_object_unref0 (_data_->filter_list);
		_g_object_unref0 (_data_->default_filter);
		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;
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_data_->_inner_error0_);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_object_unref0 (_data_->dialog);
		_g_object_unref0 (_data_->filter_list);
		_g_object_unref0 (_data_->default_filter);
		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_->result = NULL;
	_g_object_unref0 (_data_->dialog);
	_g_object_unref0 (_data_->filter_list);
	_g_object_unref0 (_data_->default_filter);
	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
g4_show_select_folder_dialog_data_free (gpointer _data)
{
	G4ShowSelectFolderDialogData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->parent);
	_g_object_unref0 (_data_->initial);
	_g_object_unref0 (_data_->result);
	g_slice_free (G4ShowSelectFolderDialogData, _data_);
}

void
g4_show_select_folder_dialog (GtkWindow* parent,
                              GFile* initial,
                              GAsyncReadyCallback _callback_,
                              gpointer _user_data_)
{
	G4ShowSelectFolderDialogData* _data_;
	GtkWindow* _tmp0_;
	GFile* _tmp1_;
	_data_ = g_slice_new0 (G4ShowSelectFolderDialogData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, g4_show_select_folder_dialog_data_free);
	_tmp0_ = _g_object_ref0 (parent);
	_g_object_unref0 (_data_->parent);
	_data_->parent = _tmp0_;
	_tmp1_ = _g_object_ref0 (initial);
	_g_object_unref0 (_data_->initial);
	_data_->initial = _tmp1_;
	g4_show_select_folder_dialog_co (_data_);
}

GFile*
g4_show_select_folder_dialog_finish (GAsyncResult* _res_)
{
	GFile* result;
	G4ShowSelectFolderDialogData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
g4_show_select_folder_dialog_ready (GObject* source_object,
                                    GAsyncResult* _res_,
                                    gpointer _user_data_)
{
	G4ShowSelectFolderDialogData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	g4_show_select_folder_dialog_co (_data_);
}

static gboolean
g4_show_select_folder_dialog_co (G4ShowSelectFolderDialogData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = gtk_file_dialog_new ();
	_data_->dialog = _data_->_tmp0_;
	gtk_file_dialog_set_initial_folder (_data_->dialog, _data_->initial);
	gtk_file_dialog_set_modal (_data_->dialog, TRUE);
	{
		_data_->_state_ = 1;
		gtk_file_dialog_select_folder (_data_->dialog, _data_->parent, NULL, g4_show_select_folder_dialog_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp2_ = gtk_file_dialog_select_folder_finish (_data_->dialog, _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp1_ = _data_->_tmp2_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp3_ = _data_->_tmp1_;
		_data_->_tmp1_ = NULL;
		_data_->result = _data_->_tmp3_;
		_g_object_unref0 (_data_->_tmp1_);
		_g_object_unref0 (_data_->dialog);
		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;
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_data_->_inner_error0_);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_object_unref0 (_data_->dialog);
		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_->result = NULL;
	_g_object_unref0 (_data_->dialog);
	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
_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;
}

