/* gnome-klotski.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from gnome-klotski.vala, do not modify */

/*
   This file is part of GNOME Klotski.

   Copyright (C) 2010-2013 Robert Ancell

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

   GNOME Klotski 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 General Public License for more details.

   You should have received a copy of the GNU General Public License along
   with GNOME Klotski.  If not, see <https://www.gnu.org/licenses/>.
*/

#include <gtk/gtk.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>
#include <locale.h>
#include <stdio.h>

#define KLOTSKI_PROGRAM_NAME _ ("Klotski")
#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 TYPE_KLOTSKI (klotski_get_type ())
#define KLOTSKI(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_KLOTSKI, Klotski))
#define KLOTSKI_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_KLOTSKI, KlotskiClass))
#define IS_KLOTSKI(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_KLOTSKI))
#define IS_KLOTSKI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_KLOTSKI))
#define KLOTSKI_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_KLOTSKI, KlotskiClass))

typedef struct _Klotski Klotski;
typedef struct _KlotskiClass KlotskiClass;
typedef struct _KlotskiPrivate KlotskiPrivate;

#define TYPE_KLOTSKI_WINDOW (klotski_window_get_type ())
#define KLOTSKI_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_KLOTSKI_WINDOW, KlotskiWindow))
#define KLOTSKI_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_KLOTSKI_WINDOW, KlotskiWindowClass))
#define IS_KLOTSKI_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_KLOTSKI_WINDOW))
#define IS_KLOTSKI_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_KLOTSKI_WINDOW))
#define KLOTSKI_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_KLOTSKI_WINDOW, KlotskiWindowClass))

typedef struct _KlotskiWindow KlotskiWindow;
typedef struct _KlotskiWindowClass KlotskiWindowClass;
enum  {
	KLOTSKI_0_PROPERTY,
	KLOTSKI_NUM_PROPERTIES
};
static GParamSpec* klotski_properties[KLOTSKI_NUM_PROPERTIES];
typedef void (*GSimpleActionActivateCallback) (GSimpleAction* action, GVariant* parameter, gpointer user_data);
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _Klotski {
	GtkApplication parent_instance;
	KlotskiPrivate * priv;
};

struct _KlotskiClass {
	GtkApplicationClass parent_class;
};

struct _KlotskiPrivate {
	KlotskiWindow* window;
};

static gint Klotski_private_offset;
static gpointer klotski_parent_class = NULL;

VALA_EXTERN GType klotski_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Klotski, g_object_unref)
VALA_EXTERN GType klotski_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (KlotskiWindow, g_object_unref)
static void _g_application_quit_gsimple_action_activate_callback (GSimpleAction* action,
                                                           GVariant* parameter,
                                                           gpointer self);
static gint klotski_main (gchar** args,
                   gint args_length1);
static Klotski* klotski_new (void);
static Klotski* klotski_construct (GType object_type);
static gint klotski_real_handle_local_options (GApplication* base,
                                        GVariantDict* options);
static void klotski_real_startup (GApplication* base);
static void klotski_real_activate (GApplication* base);
VALA_EXTERN KlotskiWindow* klotski_window_new (void);
VALA_EXTERN KlotskiWindow* klotski_window_construct (GType object_type);
static void klotski_real_shutdown (GApplication* base);
static void klotski_finalize (GObject * obj);
static GType klotski_get_type_once (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);

static const GOptionEntry KLOTSKI_option_entries[2] = {{"version", 'v', (gint) G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, N_ ("Print release version and exit"), NULL}, {0}};
static const GActionEntry KLOTSKI_action_entries[1] = {{"quit", _g_application_quit_gsimple_action_activate_callback}};

static inline gpointer
klotski_get_instance_private (Klotski* self)
{
	return G_STRUCT_MEMBER_P (self, Klotski_private_offset);
}

static void
_g_application_quit_gsimple_action_activate_callback (GSimpleAction* action,
                                                      GVariant* parameter,
                                                      gpointer self)
{
	g_application_quit ((GApplication*) self);
}

static gint
klotski_main (gchar** args,
              gint args_length1)
{
	Klotski* app = NULL;
	Klotski* _tmp0_;
	gint result;
	setlocale (LC_ALL, "");
	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
	g_set_application_name (KLOTSKI_PROGRAM_NAME);
	g_set_prgname ("org.gnome.Klotski");
	gtk_window_set_default_icon_name ("org.gnome.Klotski");
	_tmp0_ = klotski_new ();
	app = _tmp0_;
	result = g_application_run ((GApplication*) app, (gint) args_length1, args);
	_g_object_unref0 (app);
	return result;
}

int
main (int argc,
      char ** argv)
{
	return klotski_main (argv, argc);
}

static Klotski*
klotski_construct (GType object_type)
{
	Klotski * self = NULL;
	self = (Klotski*) g_object_new (object_type, "application-id", "org.gnome.Klotski", "flags", G_APPLICATION_FLAGS_NONE, NULL);
	g_application_add_main_option_entries ((GApplication*) self, KLOTSKI_option_entries);
	return self;
}

static Klotski*
klotski_new (void)
{
	return klotski_construct (TYPE_KLOTSKI);
}

static gint
klotski_real_handle_local_options (GApplication* base,
                                   GVariantDict* options)
{
	Klotski * self;
	gint result;
	self = (Klotski*) base;
	g_return_val_if_fail (options != NULL, 0);
	if (g_variant_dict_contains (options, "version")) {
		FILE* _tmp0_;
		_tmp0_ = stdout;
		fprintf (_tmp0_, "%1$s %2$s\n", "gnome-klotski", VERSION);
		result = EXIT_SUCCESS;
		return result;
	}
	result = -1;
	return result;
}

static void
klotski_real_startup (GApplication* base)
{
	Klotski * self;
	gchar* _tmp0_;
	gchar** _tmp1_;
	gchar** _tmp2_;
	gint _tmp2__length1;
	gchar* _tmp3_;
	gchar** _tmp4_;
	gchar** _tmp5_;
	gint _tmp5__length1;
	gchar* _tmp6_;
	gchar** _tmp7_;
	gchar** _tmp8_;
	gint _tmp8__length1;
	gchar* _tmp9_;
	gchar** _tmp10_;
	gchar** _tmp11_;
	gint _tmp11__length1;
	gchar* _tmp12_;
	gchar* _tmp13_;
	gchar** _tmp14_;
	gchar** _tmp15_;
	gint _tmp15__length1;
	gchar* _tmp16_;
	gchar* _tmp17_;
	gchar** _tmp18_;
	gchar** _tmp19_;
	gint _tmp19__length1;
	gchar* _tmp20_;
	gchar* _tmp21_;
	gchar** _tmp22_;
	gchar** _tmp23_;
	gint _tmp23__length1;
	self = (Klotski*) base;
	G_APPLICATION_CLASS (klotski_parent_class)->startup ((GApplication*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_application_get_type (), GtkApplication));
	g_action_map_add_action_entries ((GActionMap*) self, KLOTSKI_action_entries, (gint) G_N_ELEMENTS (KLOTSKI_action_entries), self);
	_tmp0_ = g_strdup ("Up");
	_tmp1_ = g_new0 (gchar*, 1 + 1);
	_tmp1_[0] = _tmp0_;
	_tmp2_ = _tmp1_;
	_tmp2__length1 = 1;
	gtk_application_set_accels_for_action ((GtkApplication*) self, "win.prev-puzzle", _tmp2_);
	_tmp2_ = (_vala_array_free (_tmp2_, _tmp2__length1, (GDestroyNotify) g_free), NULL);
	_tmp3_ = g_strdup ("Down");
	_tmp4_ = g_new0 (gchar*, 1 + 1);
	_tmp4_[0] = _tmp3_;
	_tmp5_ = _tmp4_;
	_tmp5__length1 = 1;
	gtk_application_set_accels_for_action ((GtkApplication*) self, "win.next-puzzle", _tmp5_);
	_tmp5_ = (_vala_array_free (_tmp5_, _tmp5__length1, (GDestroyNotify) g_free), NULL);
	_tmp6_ = g_strdup ("Page_Up");
	_tmp7_ = g_new0 (gchar*, 1 + 1);
	_tmp7_[0] = _tmp6_;
	_tmp8_ = _tmp7_;
	_tmp8__length1 = 1;
	gtk_application_set_accels_for_action ((GtkApplication*) self, "win.prev-pack", _tmp8_);
	_tmp8_ = (_vala_array_free (_tmp8_, _tmp8__length1, (GDestroyNotify) g_free), NULL);
	_tmp9_ = g_strdup ("Page_Down");
	_tmp10_ = g_new0 (gchar*, 1 + 1);
	_tmp10_[0] = _tmp9_;
	_tmp11_ = _tmp10_;
	_tmp11__length1 = 1;
	gtk_application_set_accels_for_action ((GtkApplication*) self, "win.next-pack", _tmp11_);
	_tmp11_ = (_vala_array_free (_tmp11_, _tmp11__length1, (GDestroyNotify) g_free), NULL);
	_tmp12_ = g_strdup ("<Shift><Primary>n");
	_tmp13_ = g_strdup ("<Shift><Primary>r");
	_tmp14_ = g_new0 (gchar*, 2 + 1);
	_tmp14_[0] = _tmp12_;
	_tmp14_[1] = _tmp13_;
	_tmp15_ = _tmp14_;
	_tmp15__length1 = 2;
	gtk_application_set_accels_for_action ((GtkApplication*) self, "win.start-game", _tmp15_);
	_tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) g_free), NULL);
	_tmp16_ = g_strdup ("<Primary>s");
	_tmp17_ = g_strdup ("<Shift><Primary>s");
	_tmp18_ = g_new0 (gchar*, 2 + 1);
	_tmp18_[0] = _tmp16_;
	_tmp18_[1] = _tmp17_;
	_tmp19_ = _tmp18_;
	_tmp19__length1 = 2;
	gtk_application_set_accels_for_action ((GtkApplication*) self, "win.show-scores", _tmp19_);
	_tmp19_ = (_vala_array_free (_tmp19_, _tmp19__length1, (GDestroyNotify) g_free), NULL);
	_tmp20_ = g_strdup ("<Primary>q");
	_tmp21_ = g_strdup ("<Shift><Primary>q");
	_tmp22_ = g_new0 (gchar*, 2 + 1);
	_tmp22_[0] = _tmp20_;
	_tmp22_[1] = _tmp21_;
	_tmp23_ = _tmp22_;
	_tmp23__length1 = 2;
	gtk_application_set_accels_for_action ((GtkApplication*) self, "app.quit", _tmp23_);
	_tmp23_ = (_vala_array_free (_tmp23_, _tmp23__length1, (GDestroyNotify) g_free), NULL);
}

static void
klotski_real_activate (GApplication* base)
{
	Klotski * self;
	GtkWindow* _tmp0_;
	KlotskiWindow* _tmp3_;
	self = (Klotski*) base;
	_tmp0_ = gtk_application_get_active_window ((GtkApplication*) self);
	if (_tmp0_ == NULL) {
		KlotskiWindow* _tmp1_;
		KlotskiWindow* _tmp2_;
		_tmp1_ = klotski_window_new ();
		g_object_ref_sink (_tmp1_);
		_g_object_unref0 (self->priv->window);
		self->priv->window = _tmp1_;
		_tmp2_ = self->priv->window;
		gtk_application_add_window ((GtkApplication*) self, (GtkWindow*) _tmp2_);
	}
	_tmp3_ = self->priv->window;
	gtk_window_present ((GtkWindow*) _tmp3_);
}

static void
klotski_real_shutdown (GApplication* base)
{
	Klotski * self;
	GtkWindow* _tmp0_;
	self = (Klotski*) base;
	_tmp0_ = gtk_application_get_active_window ((GtkApplication*) self);
	if (_tmp0_ != NULL) {
		KlotskiWindow* _tmp1_;
		_tmp1_ = self->priv->window;
		gtk_widget_destroy ((GtkWidget*) _tmp1_);
	}
	G_APPLICATION_CLASS (klotski_parent_class)->shutdown ((GApplication*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_application_get_type (), GtkApplication));
}

static void
klotski_class_init (KlotskiClass * klass,
                    gpointer klass_data)
{
	klotski_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &Klotski_private_offset);
	((GApplicationClass *) klass)->handle_local_options = (gint (*) (GApplication*, GVariantDict*)) klotski_real_handle_local_options;
	((GApplicationClass *) klass)->startup = (void (*) (GApplication*)) klotski_real_startup;
	((GApplicationClass *) klass)->activate = (void (*) (GApplication*)) klotski_real_activate;
	((GApplicationClass *) klass)->shutdown = (void (*) (GApplication*)) klotski_real_shutdown;
	G_OBJECT_CLASS (klass)->finalize = klotski_finalize;
}

static void
klotski_instance_init (Klotski * self,
                       gpointer klass)
{
	self->priv = klotski_get_instance_private (self);
}

static void
klotski_finalize (GObject * obj)
{
	Klotski * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_KLOTSKI, Klotski);
	_g_object_unref0 (self->priv->window);
	G_OBJECT_CLASS (klotski_parent_class)->finalize (obj);
}

static GType
klotski_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (KlotskiClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) klotski_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Klotski), 0, (GInstanceInitFunc) klotski_instance_init, NULL };
	GType klotski_type_id;
	klotski_type_id = g_type_register_static (gtk_application_get_type (), "Klotski", &g_define_type_info, 0);
	Klotski_private_offset = g_type_add_instance_private (klotski_type_id, sizeof (KlotskiPrivate));
	return klotski_type_id;
}

GType
klotski_get_type (void)
{
	static volatile gsize klotski_type_id__once = 0;
	if (g_once_init_enter (&klotski_type_id__once)) {
		GType klotski_type_id;
		klotski_type_id = klotski_get_type_once ();
		g_once_init_leave (&klotski_type_id__once, klotski_type_id);
	}
	return klotski_type_id__once;
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

