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

/*
Copyright (C) 2014 Johan Mattsson

This library is free software; you can redistribute it and/or modify 
it under the terms of the GNU Lesser General Public License as 
published by the Free Software Foundation; either version 3 of the 
License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but 
WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
Lesser General Public License for more details.
*/

#include "birdfont.h"
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

enum  {
	BIRD_FONT_LOAD_CALLBACK_0_PROPERTY,
	BIRD_FONT_LOAD_CALLBACK_NUM_PROPERTIES
};
static GParamSpec* bird_font_load_callback_properties[BIRD_FONT_LOAD_CALLBACK_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))
enum  {
	BIRD_FONT_LOAD_CALLBACK_FILE_LOADED_SIGNAL,
	BIRD_FONT_LOAD_CALLBACK_NUM_SIGNALS
};
static guint bird_font_load_callback_signals[BIRD_FONT_LOAD_CALLBACK_NUM_SIGNALS] = {0};

struct _BirdFontLoadCallbackPrivate {
	BirdFontSaveDialogListener* dialog;
	BirdFontFont* font;
};

static gint BirdFontLoadCallback_private_offset;
static gpointer bird_font_load_callback_parent_class = NULL;

static void __lambda281_ (BirdFontLoadCallback* self);
static void ___lambda281__bird_font_load_callback_file_loaded (BirdFontLoadCallback* _sender,
                                                        gpointer self);
static void __lambda282_ (BirdFontLoadCallback* self);
static void bird_font_load_callback_load_new_font (BirdFontLoadCallback* self);
static void ___lambda282__bird_font_save_dialog_listener_signal_discard (BirdFontSaveDialogListener* _sender,
                                                                  gpointer self);
static void __lambda285_ (BirdFontLoadCallback* self);
static void _bird_font_load_callback_load_new_font_bird_font_save_callback_file_saved (BirdFontSaveCallback* _sender,
                                                                                gpointer self);
static void ___lambda285__bird_font_save_dialog_listener_signal_save (BirdFontSaveDialogListener* _sender,
                                                               gpointer self);
static void __lambda286_ (BirdFontLoadCallback* self);
static void ___lambda286__bird_font_save_dialog_listener_signal_cancel (BirdFontSaveDialogListener* _sender,
                                                                 gpointer self);
static void __lambda283_ (BirdFontLoadCallback* self,
                   const gchar* fn);
static void ___lambda284_ (BirdFontLoadCallback* self);
static void ____lambda284__bird_font_load_callback_file_loaded (BirdFontLoadCallback* _sender,
                                                         gpointer self);
static void ___lambda283__bird_font_file_chooser_file_selected (BirdFontFileChooser* _sender,
                                                         const gchar* path,
                                                         gpointer self);
static void bird_font_load_callback_finalize (GObject * obj);
static GType bird_font_load_callback_get_type_once (void);

static inline gpointer
bird_font_load_callback_get_instance_private (BirdFontLoadCallback* self)
{
	return G_STRUCT_MEMBER_P (self, BirdFontLoadCallback_private_offset);
}

static void
__lambda281_ (BirdFontLoadCallback* self)
{
	BirdFontFont* f = NULL;
	BirdFontFont* _tmp0_;
	BirdFontFont* _tmp1_;
	BirdFontFont* _tmp24_;
	_tmp0_ = bird_font_bird_font_get_current_font ();
	f = _tmp0_;
	_tmp1_ = f;
	if (!bird_font_font_has_compatible_format (_tmp1_)) {
		BirdFontFont* _tmp2_;
		BirdFontFont* _tmp13_;
		_tmp2_ = f;
		if (bird_font_font_newer_format (_tmp2_)) {
			gchar* _tmp3_;
			gchar* _tmp4_;
			gchar* _tmp5_;
			gchar* _tmp6_;
			gchar* _tmp7_;
			gchar* _tmp8_;
			gchar* _tmp9_;
			gchar* _tmp10_;
			BirdFontMessageDialog* _tmp11_;
			BirdFontMessageDialog* _tmp12_;
			_tmp3_ = bird_font_t_ ("This font was made with a newer version of Birdfont.");
			_tmp4_ = _tmp3_;
			_tmp5_ = g_strconcat (_tmp4_, " ", NULL);
			_tmp6_ = _tmp5_;
			_tmp7_ = bird_font_t_ ("You need to upgrade your version of Birdfont.");
			_tmp8_ = _tmp7_;
			_tmp9_ = g_strconcat (_tmp6_, _tmp8_, NULL);
			_tmp10_ = _tmp9_;
			_tmp11_ = bird_font_main_window_show_message (_tmp10_);
			_tmp12_ = _tmp11_;
			_g_object_unref0 (_tmp12_);
			_g_free0 (_tmp10_);
			_g_free0 (_tmp8_);
			_g_free0 (_tmp6_);
			_g_free0 (_tmp4_);
		}
		_tmp13_ = f;
		if (bird_font_font_older_format (_tmp13_)) {
			gchar* _tmp14_;
			gchar* _tmp15_;
			gchar* _tmp16_;
			gchar* _tmp17_;
			gchar* _tmp18_;
			gchar* _tmp19_;
			gchar* _tmp20_;
			gchar* _tmp21_;
			BirdFontMessageDialog* _tmp22_;
			BirdFontMessageDialog* _tmp23_;
			_tmp14_ = bird_font_t_ ("This font was made with an old version of Birdfont.");
			_tmp15_ = _tmp14_;
			_tmp16_ = g_strconcat (_tmp15_, " ", NULL);
			_tmp17_ = _tmp16_;
			_tmp18_ = bird_font_t_ ("You need an older version of Birdfont to open it.");
			_tmp19_ = _tmp18_;
			_tmp20_ = g_strconcat (_tmp17_, _tmp19_, NULL);
			_tmp21_ = _tmp20_;
			_tmp22_ = bird_font_main_window_show_message (_tmp21_);
			_tmp23_ = _tmp22_;
			_g_object_unref0 (_tmp23_);
			_g_free0 (_tmp21_);
			_g_free0 (_tmp19_);
			_g_free0 (_tmp17_);
			_g_free0 (_tmp15_);
		}
	}
	_tmp24_ = f;
	if (_tmp24_->has_svg) {
		gchar* _tmp25_;
		gchar* _tmp26_;
		gchar* _tmp27_;
		gchar* _tmp28_;
		gchar* _tmp29_;
		gchar* _tmp30_;
		gchar* _tmp31_;
		gchar* _tmp32_;
		BirdFontMessageDialog* _tmp33_;
		BirdFontMessageDialog* _tmp34_;
		_tmp25_ = bird_font_t_ ("This font has color glyphs but your version of BirdFont does not have " \
"color support.");
		_tmp26_ = _tmp25_;
		_tmp27_ = g_strconcat (_tmp26_, " ", NULL);
		_tmp28_ = _tmp27_;
		_tmp29_ = bird_font_t_ ("Check birdfont.org for other versions.");
		_tmp30_ = _tmp29_;
		_tmp31_ = g_strconcat (_tmp28_, _tmp30_, NULL);
		_tmp32_ = _tmp31_;
		_tmp33_ = bird_font_main_window_show_message (_tmp32_);
		_tmp34_ = _tmp33_;
		_g_object_unref0 (_tmp34_);
		_g_free0 (_tmp32_);
		_g_free0 (_tmp30_);
		_g_free0 (_tmp28_);
		_g_free0 (_tmp26_);
	}
	_g_object_unref0 (f);
}

static void
___lambda281__bird_font_load_callback_file_loaded (BirdFontLoadCallback* _sender,
                                                   gpointer self)
{
	__lambda281_ ((BirdFontLoadCallback*) self);
}

BirdFontLoadCallback*
bird_font_load_callback_construct (GType object_type)
{
	BirdFontLoadCallback * self = NULL;
	self = (BirdFontLoadCallback*) g_object_new (object_type, NULL);
	g_signal_connect_object (self, "file-loaded", (GCallback) ___lambda281__bird_font_load_callback_file_loaded, self, 0);
	return self;
}

BirdFontLoadCallback*
bird_font_load_callback_new (void)
{
	return bird_font_load_callback_construct (BIRD_FONT_TYPE_LOAD_CALLBACK);
}

static void
__lambda282_ (BirdFontLoadCallback* self)
{
	bird_font_main_window_close_all_tabs ();
	bird_font_load_callback_load_new_font (self);
}

static void
___lambda282__bird_font_save_dialog_listener_signal_discard (BirdFontSaveDialogListener* _sender,
                                                             gpointer self)
{
	__lambda282_ ((BirdFontLoadCallback*) self);
}

static void
_bird_font_load_callback_load_new_font_bird_font_save_callback_file_saved (BirdFontSaveCallback* _sender,
                                                                           gpointer self)
{
	bird_font_load_callback_load_new_font ((BirdFontLoadCallback*) self);
}

static void
__lambda285_ (BirdFontLoadCallback* self)
{
	BirdFontSaveCallback* _tmp0_;
	BirdFontSaveCallback* _tmp1_;
	BirdFontSaveCallback* _tmp2_;
	BirdFontSaveCallback* _tmp3_;
	bird_font_main_window_close_all_tabs ();
	_tmp0_ = bird_font_save_callback_new ();
	_tmp1_ = _tmp0_;
	bird_font_menu_tab_set_save_callback (_tmp1_);
	_g_object_unref0 (_tmp1_);
	_tmp2_ = bird_font_menu_tab_save_callback;
	g_signal_connect_object (_tmp2_, "file-saved", (GCallback) _bird_font_load_callback_load_new_font_bird_font_save_callback_file_saved, self, 0);
	_tmp3_ = bird_font_menu_tab_save_callback;
	bird_font_save_callback_save (_tmp3_);
}

static void
___lambda285__bird_font_save_dialog_listener_signal_save (BirdFontSaveDialogListener* _sender,
                                                          gpointer self)
{
	__lambda285_ ((BirdFontLoadCallback*) self);
}

static void
__lambda286_ (BirdFontLoadCallback* self)
{
	bird_font_main_window_hide_dialog ();
}

static void
___lambda286__bird_font_save_dialog_listener_signal_cancel (BirdFontSaveDialogListener* _sender,
                                                            gpointer self)
{
	__lambda286_ ((BirdFontLoadCallback*) self);
}

void
bird_font_load_callback_load (BirdFontLoadCallback* self)
{
	BirdFontSaveDialogListener* _tmp0_;
	BirdFontFont* _tmp1_;
	BirdFontSaveDialogListener* _tmp2_;
	BirdFontSaveDialogListener* _tmp3_;
	BirdFontSaveDialogListener* _tmp4_;
	BirdFontFont* _tmp5_;
	g_return_if_fail (self != NULL);
	if (bird_font_menu_tab_has_suppress_event ()) {
		bird_font_warn_if_test ("Event suppressed");
		return;
	}
	_tmp0_ = bird_font_save_dialog_listener_new ();
	_g_object_unref0 (self->priv->dialog);
	self->priv->dialog = _tmp0_;
	_tmp1_ = bird_font_bird_font_get_current_font ();
	_g_object_unref0 (self->priv->font);
	self->priv->font = _tmp1_;
	_tmp2_ = self->priv->dialog;
	g_signal_connect_object (_tmp2_, "signal-discard", (GCallback) ___lambda282__bird_font_save_dialog_listener_signal_discard, self, 0);
	_tmp3_ = self->priv->dialog;
	g_signal_connect_object (_tmp3_, "signal-save", (GCallback) ___lambda285__bird_font_save_dialog_listener_signal_save, self, 0);
	_tmp4_ = self->priv->dialog;
	g_signal_connect_object (_tmp4_, "signal-cancel", (GCallback) ___lambda286__bird_font_save_dialog_listener_signal_cancel, self, 0);
	_tmp5_ = self->priv->font;
	if (!bird_font_font_is_modified (_tmp5_)) {
		BirdFontSaveDialogListener* _tmp6_;
		_tmp6_ = self->priv->dialog;
		g_signal_emit_by_name (_tmp6_, "signal-discard");
	} else {
		BirdFontSaveDialogListener* _tmp7_;
		BirdFontSaveDialog* _tmp8_;
		BirdFontSaveDialog* _tmp9_;
		_tmp7_ = self->priv->dialog;
		_tmp8_ = bird_font_save_dialog_new (_tmp7_);
		_tmp9_ = _tmp8_;
		bird_font_main_window_show_dialog ((BirdFontDialog*) _tmp9_);
		_g_object_unref0 (_tmp9_);
	}
}

static void
___lambda284_ (BirdFontLoadCallback* self)
{
	bird_font_kerning_tools_update_kerning_classes ();
	bird_font_menu_tab_show_all_available_characters ();
}

static void
____lambda284__bird_font_load_callback_file_loaded (BirdFontLoadCallback* _sender,
                                                    gpointer self)
{
	___lambda284_ ((BirdFontLoadCallback*) self);
}

static void
__lambda283_ (BirdFontLoadCallback* self,
              const gchar* fn)
{
	BirdFontFont* f = NULL;
	BirdFontFont* _tmp0_;
	_tmp0_ = bird_font_bird_font_get_current_font ();
	f = _tmp0_;
	if (fn != NULL) {
		BirdFontFont* _tmp1_;
		BirdFontFont* _tmp2_;
		BirdFontNativeWindow* _tmp3_;
		_tmp1_ = bird_font_bird_font_new_font ();
		_g_object_unref0 (f);
		f = _tmp1_;
		_tmp2_ = f;
		bird_font_font_set_file (_tmp2_, (const gchar*) fn);
		bird_font_preferences_add_recent_files ((const gchar*) fn);
		_tmp3_ = bird_font_main_window_native_window;
		bird_font_native_window_load (_tmp3_);
		g_signal_connect_object (self, "file-loaded", (GCallback) ____lambda284__bird_font_load_callback_file_loaded, self, 0);
	}
	_g_object_unref0 (f);
}

static void
___lambda283__bird_font_file_chooser_file_selected (BirdFontFileChooser* _sender,
                                                    const gchar* path,
                                                    gpointer self)
{
	__lambda283_ ((BirdFontLoadCallback*) self, path);
}

static void
bird_font_load_callback_load_new_font (BirdFontLoadCallback* self)
{
	BirdFontFileChooser* fc = NULL;
	BirdFontFileChooser* _tmp0_;
	BirdFontFileChooser* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	BirdFontFileChooser* _tmp4_;
	g_return_if_fail (self != NULL);
	_tmp0_ = bird_font_file_chooser_new ();
	fc = _tmp0_;
	if (bird_font_menu_tab_has_suppress_event ()) {
		bird_font_warn_if_test ("Event suppressed");
		_g_object_unref0 (fc);
		return;
	}
	_tmp1_ = fc;
	g_signal_connect_object (_tmp1_, "file-selected", (GCallback) ___lambda283__bird_font_file_chooser_file_selected, self, 0);
	_tmp2_ = bird_font_t_ ("Open");
	_tmp3_ = _tmp2_;
	_tmp4_ = fc;
	bird_font_main_window_file_chooser (_tmp3_, _tmp4_, BIRD_FONT_FILE_CHOOSER_LOAD);
	_g_free0 (_tmp3_);
	_g_object_unref0 (fc);
}

static void
bird_font_load_callback_class_init (BirdFontLoadCallbackClass * klass,
                                    gpointer klass_data)
{
	bird_font_load_callback_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BirdFontLoadCallback_private_offset);
	G_OBJECT_CLASS (klass)->finalize = bird_font_load_callback_finalize;
	bird_font_load_callback_signals[BIRD_FONT_LOAD_CALLBACK_FILE_LOADED_SIGNAL] = g_signal_new ("file-loaded", BIRD_FONT_TYPE_LOAD_CALLBACK, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
bird_font_load_callback_instance_init (BirdFontLoadCallback * self,
                                       gpointer klass)
{
	self->priv = bird_font_load_callback_get_instance_private (self);
}

static void
bird_font_load_callback_finalize (GObject * obj)
{
	BirdFontLoadCallback * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_LOAD_CALLBACK, BirdFontLoadCallback);
	_g_object_unref0 (self->priv->dialog);
	_g_object_unref0 (self->priv->font);
	G_OBJECT_CLASS (bird_font_load_callback_parent_class)->finalize (obj);
}

static GType
bird_font_load_callback_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontLoadCallbackClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_load_callback_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontLoadCallback), 0, (GInstanceInitFunc) bird_font_load_callback_instance_init, NULL };
	GType bird_font_load_callback_type_id;
	bird_font_load_callback_type_id = g_type_register_static (G_TYPE_OBJECT, "BirdFontLoadCallback", &g_define_type_info, 0);
	BirdFontLoadCallback_private_offset = g_type_add_instance_private (bird_font_load_callback_type_id, sizeof (BirdFontLoadCallbackPrivate));
	return bird_font_load_callback_type_id;
}

GType
bird_font_load_callback_get_type (void)
{
	static volatile gsize bird_font_load_callback_type_id__once = 0;
	if (g_once_init_enter (&bird_font_load_callback_type_id__once)) {
		GType bird_font_load_callback_type_id;
		bird_font_load_callback_type_id = bird_font_load_callback_get_type_once ();
		g_once_init_leave (&bird_font_load_callback_type_id__once, bird_font_load_callback_type_id);
	}
	return bird_font_load_callback_type_id__once;
}

