/* preferences-page-import-export.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from preferences-page-import-export.vala, do not modify */

/* This file is part of GNOME Games. License: GPL-3.0+.*/

#include <gtk/gtk.h>
#include <glib-object.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <stdlib.h>
#include <string.h>
#include "gnome-games.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

#define GAMES_TYPE_PREFERENCES_PAGE (games_preferences_page_get_type ())
#define GAMES_PREFERENCES_PAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_PREFERENCES_PAGE, GamesPreferencesPage))
#define GAMES_PREFERENCES_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_PREFERENCES_PAGE, GamesPreferencesPageClass))
#define GAMES_IS_PREFERENCES_PAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_PREFERENCES_PAGE))
#define GAMES_IS_PREFERENCES_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_PREFERENCES_PAGE))
#define GAMES_PREFERENCES_PAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_PREFERENCES_PAGE, GamesPreferencesPageClass))

typedef struct _GamesPreferencesPage GamesPreferencesPage;
typedef struct _GamesPreferencesPageClass GamesPreferencesPageClass;
typedef struct _GamesPreferencesPagePrivate GamesPreferencesPagePrivate;

#define GAMES_TYPE_PREFERENCES_PAGE_IMPORT_EXPORT (games_preferences_page_import_export_get_type ())
#define GAMES_PREFERENCES_PAGE_IMPORT_EXPORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_PREFERENCES_PAGE_IMPORT_EXPORT, GamesPreferencesPageImportExport))
#define GAMES_PREFERENCES_PAGE_IMPORT_EXPORT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_PREFERENCES_PAGE_IMPORT_EXPORT, GamesPreferencesPageImportExportClass))
#define GAMES_IS_PREFERENCES_PAGE_IMPORT_EXPORT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_PREFERENCES_PAGE_IMPORT_EXPORT))
#define GAMES_IS_PREFERENCES_PAGE_IMPORT_EXPORT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_PREFERENCES_PAGE_IMPORT_EXPORT))
#define GAMES_PREFERENCES_PAGE_IMPORT_EXPORT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_PREFERENCES_PAGE_IMPORT_EXPORT, GamesPreferencesPageImportExportClass))

typedef struct _GamesPreferencesPageImportExport GamesPreferencesPageImportExport;
typedef struct _GamesPreferencesPageImportExportClass GamesPreferencesPageImportExportClass;
typedef struct _GamesPreferencesPageImportExportPrivate GamesPreferencesPageImportExportPrivate;
enum  {
	GAMES_PREFERENCES_PAGE_IMPORT_EXPORT_0_PROPERTY,
	GAMES_PREFERENCES_PAGE_IMPORT_EXPORT_NUM_PROPERTIES
};
static GParamSpec* games_preferences_page_import_export_properties[GAMES_PREFERENCES_PAGE_IMPORT_EXPORT_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))

struct _GamesPreferencesPage {
	GtkBin parent_instance;
	GamesPreferencesPagePrivate * priv;
};

struct _GamesPreferencesPageClass {
	GtkBinClass parent_class;
};

struct _GamesPreferencesPageImportExport {
	GamesPreferencesPage parent_instance;
	GamesPreferencesPageImportExportPrivate * priv;
};

struct _GamesPreferencesPageImportExportClass {
	GamesPreferencesPageClass parent_class;
};

static gpointer games_preferences_page_import_export_parent_class = NULL;

VALA_EXTERN GType games_preferences_page_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType games_preferences_page_import_export_get_type (void) G_GNUC_CONST ;
static void games_preferences_page_import_export_on_import_clicked (GamesPreferencesPageImportExport* self);
VALA_EXTERN void games_preferences_page_show_error_message (GamesPreferencesPage* self,
                                                const gchar* error_message);
static void _games_preferences_page_import_export_on_import_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                                 gpointer self);
static void games_preferences_page_import_export_on_export_clicked (GamesPreferencesPageImportExport* self);
static void _games_preferences_page_import_export_on_export_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                                 gpointer self);
VALA_EXTERN GamesPreferencesPageImportExport* games_preferences_page_import_export_new (void);
VALA_EXTERN GamesPreferencesPageImportExport* games_preferences_page_import_export_construct (GType object_type);
VALA_EXTERN GamesPreferencesPage* games_preferences_page_new (void);
VALA_EXTERN GamesPreferencesPage* games_preferences_page_construct (GType object_type);
static GType games_preferences_page_import_export_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

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

static void
games_preferences_page_import_export_on_import_clicked (GamesPreferencesPageImportExport* self)
{
	GtkWindow* toplevel = NULL;
	GtkWidget* _tmp0_;
	GtkWindow* _tmp1_;
	GtkFileChooserNative* chooser = NULL;
	GtkWindow* _tmp2_;
	GtkFileChooserNative* _tmp3_;
	GtkFileChooserNative* _tmp4_;
	GtkFileChooserNative* _tmp12_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = gtk_widget_get_toplevel ((GtkWidget*) self);
	_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp0_, gtk_window_get_type ()) ? ((GtkWindow*) _tmp0_) : NULL);
	toplevel = _tmp1_;
	_tmp2_ = toplevel;
	_tmp3_ = gtk_file_chooser_native_new (_ ("Import save data"), _tmp2_, GTK_FILE_CHOOSER_ACTION_OPEN, _ ("_Import"), _ ("_Cancel"));
	chooser = _tmp3_;
	_tmp4_ = chooser;
	if (gtk_native_dialog_run ((GtkNativeDialog*) _tmp4_) == ((gint) GTK_RESPONSE_ACCEPT)) {
		gchar* archive_name = NULL;
		GtkFileChooserNative* _tmp5_;
		gchar* _tmp6_;
		_tmp5_ = chooser;
		_tmp6_ = gtk_file_chooser_get_filename ((GtkFileChooser*) _tmp5_);
		archive_name = _tmp6_;
		{
			const gchar* _tmp7_;
			_tmp7_ = archive_name;
			games_application_import_from (_tmp7_, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == GAMES_EXTRACTION_ERROR) {
					goto __catch0_games_extraction_error;
				}
				_g_free0 (archive_name);
				_g_object_unref0 (chooser);
				_g_object_unref0 (toplevel);
				g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
				g_clear_error (&_inner_error0_);
				return;
			}
		}
		goto __finally0;
		__catch0_games_extraction_error:
		{
			GError* e = NULL;
			gchar* msg = NULL;
			GError* _tmp8_;
			const gchar* _tmp9_;
			gchar* _tmp10_;
			const gchar* _tmp11_;
			e = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp8_ = e;
			_tmp9_ = _tmp8_->message;
			_tmp10_ = g_strdup_printf (_ ("Couldn’t import save data: %s"), _tmp9_);
			msg = _tmp10_;
			_tmp11_ = msg;
			games_preferences_page_show_error_message ((GamesPreferencesPage*) self, _tmp11_);
			_g_free0 (msg);
			_g_error_free0 (e);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_free0 (archive_name);
			_g_object_unref0 (chooser);
			_g_object_unref0 (toplevel);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
		_g_free0 (archive_name);
	}
	_tmp12_ = chooser;
	gtk_native_dialog_destroy ((GtkNativeDialog*) _tmp12_);
	_g_object_unref0 (chooser);
	_g_object_unref0 (toplevel);
}

static void
_games_preferences_page_import_export_on_import_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                            gpointer self)
{
	games_preferences_page_import_export_on_import_clicked ((GamesPreferencesPageImportExport*) self);
}

static void
games_preferences_page_import_export_on_export_clicked (GamesPreferencesPageImportExport* self)
{
	GtkWindow* toplevel = NULL;
	GtkWidget* _tmp0_;
	GtkWindow* _tmp1_;
	GtkFileChooserNative* chooser = NULL;
	GtkWindow* _tmp2_;
	GtkFileChooserNative* _tmp3_;
	GtkFileChooserNative* _tmp4_;
	GDateTime* current_time = NULL;
	GDateTime* _tmp5_;
	gchar* creation_time = NULL;
	GDateTime* _tmp6_;
	gchar* _tmp7_;
	gchar* archive_filename = NULL;
	const gchar* _tmp8_;
	gchar* _tmp9_;
	GtkFileChooserNative* _tmp10_;
	const gchar* _tmp11_;
	GtkFileChooserNative* _tmp12_;
	GtkFileChooserNative* _tmp20_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = gtk_widget_get_toplevel ((GtkWidget*) self);
	_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp0_, gtk_window_get_type ()) ? ((GtkWindow*) _tmp0_) : NULL);
	toplevel = _tmp1_;
	_tmp2_ = toplevel;
	_tmp3_ = gtk_file_chooser_native_new (_ ("Export save data"), _tmp2_, GTK_FILE_CHOOSER_ACTION_SAVE, _ ("_Export"), _ ("_Cancel"));
	chooser = _tmp3_;
	_tmp4_ = chooser;
	gtk_file_chooser_set_do_overwrite_confirmation ((GtkFileChooser*) _tmp4_, TRUE);
	_tmp5_ = g_date_time_new_now_local ();
	current_time = _tmp5_;
	_tmp6_ = current_time;
	_tmp7_ = g_date_time_format (_tmp6_, "%c");
	creation_time = _tmp7_;
	_tmp8_ = creation_time;
	_tmp9_ = g_strdup_printf ("gnome-games-save-data-%s.tar.gz", _tmp8_);
	archive_filename = _tmp9_;
	_tmp10_ = chooser;
	_tmp11_ = archive_filename;
	gtk_file_chooser_set_current_name ((GtkFileChooser*) _tmp10_, _tmp11_);
	_tmp12_ = chooser;
	if (gtk_native_dialog_run ((GtkNativeDialog*) _tmp12_) == ((gint) GTK_RESPONSE_ACCEPT)) {
		gchar* filename = NULL;
		GtkFileChooserNative* _tmp13_;
		gchar* _tmp14_;
		_tmp13_ = chooser;
		_tmp14_ = gtk_file_chooser_get_filename ((GtkFileChooser*) _tmp13_);
		filename = _tmp14_;
		{
			const gchar* _tmp15_;
			_tmp15_ = filename;
			games_application_export_to (_tmp15_, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == GAMES_COMPRESSION_ERROR) {
					goto __catch0_games_compression_error;
				}
				_g_free0 (filename);
				_g_free0 (archive_filename);
				_g_free0 (creation_time);
				_g_date_time_unref0 (current_time);
				_g_object_unref0 (chooser);
				_g_object_unref0 (toplevel);
				g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
				g_clear_error (&_inner_error0_);
				return;
			}
		}
		goto __finally0;
		__catch0_games_compression_error:
		{
			GError* e = NULL;
			gchar* msg = NULL;
			GError* _tmp16_;
			const gchar* _tmp17_;
			gchar* _tmp18_;
			const gchar* _tmp19_;
			e = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp16_ = e;
			_tmp17_ = _tmp16_->message;
			_tmp18_ = g_strdup_printf (_ ("Couldn’t export save data: %s"), _tmp17_);
			msg = _tmp18_;
			_tmp19_ = msg;
			games_preferences_page_show_error_message ((GamesPreferencesPage*) self, _tmp19_);
			_g_free0 (msg);
			_g_error_free0 (e);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_free0 (filename);
			_g_free0 (archive_filename);
			_g_free0 (creation_time);
			_g_date_time_unref0 (current_time);
			_g_object_unref0 (chooser);
			_g_object_unref0 (toplevel);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
		_g_free0 (filename);
	}
	_tmp20_ = chooser;
	gtk_native_dialog_destroy ((GtkNativeDialog*) _tmp20_);
	_g_free0 (archive_filename);
	_g_free0 (creation_time);
	_g_date_time_unref0 (current_time);
	_g_object_unref0 (chooser);
	_g_object_unref0 (toplevel);
}

static void
_games_preferences_page_import_export_on_export_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                            gpointer self)
{
	games_preferences_page_import_export_on_export_clicked ((GamesPreferencesPageImportExport*) self);
}

GamesPreferencesPageImportExport*
games_preferences_page_import_export_construct (GType object_type)
{
	GamesPreferencesPageImportExport * self = NULL;
	self = (GamesPreferencesPageImportExport*) games_preferences_page_construct (object_type);
	return self;
}

GamesPreferencesPageImportExport*
games_preferences_page_import_export_new (void)
{
	return games_preferences_page_import_export_construct (GAMES_TYPE_PREFERENCES_PAGE_IMPORT_EXPORT);
}

static void
games_preferences_page_import_export_class_init (GamesPreferencesPageImportExportClass * klass,
                                                 gpointer klass_data)
{
	games_preferences_page_import_export_parent_class = g_type_class_peek_parent (klass);
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/Games/preferences/preferences-page-import-export.ui");
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_import_clicked", G_CALLBACK(_games_preferences_page_import_export_on_import_clicked_gtk_button_clicked));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_export_clicked", G_CALLBACK(_games_preferences_page_import_export_on_export_clicked_gtk_button_clicked));
}

static void
games_preferences_page_import_export_instance_init (GamesPreferencesPageImportExport * self,
                                                    gpointer klass)
{
	gtk_widget_init_template (GTK_WIDGET (self));
}

static GType
games_preferences_page_import_export_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GamesPreferencesPageImportExportClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_preferences_page_import_export_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesPreferencesPageImportExport), 0, (GInstanceInitFunc) games_preferences_page_import_export_instance_init, NULL };
	GType games_preferences_page_import_export_type_id;
	games_preferences_page_import_export_type_id = g_type_register_static (GAMES_TYPE_PREFERENCES_PAGE, "GamesPreferencesPageImportExport", &g_define_type_info, 0);
	return games_preferences_page_import_export_type_id;
}

GType
games_preferences_page_import_export_get_type (void)
{
	static volatile gsize games_preferences_page_import_export_type_id__once = 0;
	if (g_once_init_enter (&games_preferences_page_import_export_type_id__once)) {
		GType games_preferences_page_import_export_type_id;
		games_preferences_page_import_export_type_id = games_preferences_page_import_export_get_type_once ();
		g_once_init_leave (&games_preferences_page_import_export_type_id__once, games_preferences_page_import_export_type_id);
	}
	return games_preferences_page_import_export_type_id__once;
}

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;
}

