/* swell-foop.c generated by valac 0.56.0, the Vala compiler
 * generated from swell-foop.vala, do not modify */

/*
 * Copyright (C) 2010-2013 Robert Ancell
 *
 * This program 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 2 of the License, or (at your option) any later
 * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
 * license.
 */

#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 <clutter/clutter.h>
#include <stdio.h>
#include "config.h"
#include <locale.h>
#include <clutter-gtk/clutter-gtk.h>

#define SWELL_FOOP_PROGRAM_NAME _ ("Swell Foop")
#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_SWELL_FOOP (swell_foop_get_type ())
#define SWELL_FOOP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SWELL_FOOP, SwellFoop))
#define SWELL_FOOP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SWELL_FOOP, SwellFoopClass))
#define IS_SWELL_FOOP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SWELL_FOOP))
#define IS_SWELL_FOOP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SWELL_FOOP))
#define SWELL_FOOP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SWELL_FOOP, SwellFoopClass))

typedef struct _SwellFoop SwellFoop;
typedef struct _SwellFoopClass SwellFoopClass;
typedef struct _SwellFoopPrivate SwellFoopPrivate;

#define TYPE_SWELL_FOOP_WINDOW (swell_foop_window_get_type ())
#define SWELL_FOOP_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SWELL_FOOP_WINDOW, SwellFoopWindow))
#define SWELL_FOOP_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SWELL_FOOP_WINDOW, SwellFoopWindowClass))
#define IS_SWELL_FOOP_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SWELL_FOOP_WINDOW))
#define IS_SWELL_FOOP_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SWELL_FOOP_WINDOW))
#define SWELL_FOOP_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SWELL_FOOP_WINDOW, SwellFoopWindowClass))

typedef struct _SwellFoopWindow SwellFoopWindow;
typedef struct _SwellFoopWindowClass SwellFoopWindowClass;
enum  {
	SWELL_FOOP_0_PROPERTY,
	SWELL_FOOP_NUM_PROPERTIES
};
static GParamSpec* swell_foop_properties[SWELL_FOOP_NUM_PROPERTIES];
#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)))

struct _SwellFoop {
	GtkApplication parent_instance;
	SwellFoopPrivate * priv;
};

struct _SwellFoopClass {
	GtkApplicationClass parent_class;
};

struct _SwellFoopPrivate {
	SwellFoopWindow* window;
};

static gint SwellFoop_private_offset;
static gpointer swell_foop_parent_class = NULL;

VALA_EXTERN GType swell_foop_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SwellFoop, g_object_unref)
VALA_EXTERN GType swell_foop_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SwellFoopWindow, g_object_unref)
static inline void swell_foop_help_cb (SwellFoop* self);
static void _swell_foop_help_cb_gsimple_action_activate_callback (GSimpleAction* action,
                                                           GVariant* parameter,
                                                           gpointer self);
static inline void swell_foop_about_cb (SwellFoop* self);
static void _swell_foop_about_cb_gsimple_action_activate_callback (GSimpleAction* action,
                                                            GVariant* parameter,
                                                            gpointer self);
static inline void swell_foop_quit_cb (SwellFoop* self);
static void _swell_foop_quit_cb_gsimple_action_activate_callback (GSimpleAction* action,
                                                           GVariant* parameter,
                                                           gpointer self);
VALA_EXTERN SwellFoop* swell_foop_new (void);
VALA_EXTERN SwellFoop* swell_foop_construct (GType object_type);
static void swell_foop_real_startup (GApplication* base);
VALA_EXTERN SwellFoopWindow* swell_foop_window_new (GtkApplication* application);
VALA_EXTERN SwellFoopWindow* swell_foop_window_construct (GType object_type,
                                              GtkApplication* application);
static gint swell_foop_real_handle_local_options (GApplication* base,
                                           GVariantDict* options);
static void swell_foop_real_shutdown (GApplication* base);
static void swell_foop_real_activate (GApplication* base);
static gint swell_foop_main (gchar** args,
                      gint args_length1);
static void swell_foop_finalize (GObject * obj);
static GType swell_foop_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 inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static const GOptionEntry SWELL_FOOP_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 SWELL_FOOP_action_entries[3] = {{"help", _swell_foop_help_cb_gsimple_action_activate_callback}, {"about", _swell_foop_about_cb_gsimple_action_activate_callback}, {"quit", _swell_foop_quit_cb_gsimple_action_activate_callback}};

static inline gpointer
swell_foop_get_instance_private (SwellFoop* self)
{
	return G_STRUCT_MEMBER_P (self, SwellFoop_private_offset);
}

static void
_swell_foop_help_cb_gsimple_action_activate_callback (GSimpleAction* action,
                                                      GVariant* parameter,
                                                      gpointer self)
{
	swell_foop_help_cb ((SwellFoop*) self);
}

static void
_swell_foop_about_cb_gsimple_action_activate_callback (GSimpleAction* action,
                                                       GVariant* parameter,
                                                       gpointer self)
{
	swell_foop_about_cb ((SwellFoop*) self);
}

static void
_swell_foop_quit_cb_gsimple_action_activate_callback (GSimpleAction* action,
                                                      GVariant* parameter,
                                                      gpointer self)
{
	swell_foop_quit_cb ((SwellFoop*) self);
}

SwellFoop*
swell_foop_construct (GType object_type)
{
	SwellFoop * self = NULL;
	GOptionGroup* _tmp0_;
	self = (SwellFoop*) g_object_new (object_type, "application-id", "org.gnome.SwellFoop", "flags", G_APPLICATION_FLAGS_NONE, NULL);
	_tmp0_ = clutter_get_option_group_without_init ();
	g_application_add_option_group ((GApplication*) self, _tmp0_);
	g_application_add_main_option_entries ((GApplication*) self, SWELL_FOOP_option_entries);
	return self;
}

SwellFoop*
swell_foop_new (void)
{
	return swell_foop_construct (TYPE_SWELL_FOOP);
}

static void
swell_foop_real_startup (GApplication* base)
{
	SwellFoop * self;
	GtkSettings* _tmp0_;
	gchar* _tmp1_;
	gchar** _tmp2_;
	gchar** _tmp3_;
	gint _tmp3__length1;
	gchar* _tmp4_;
	gchar** _tmp5_;
	gchar** _tmp6_;
	gint _tmp6__length1;
	gchar* _tmp7_;
	gchar** _tmp8_;
	gchar** _tmp9_;
	gint _tmp9__length1;
	gchar* _tmp10_;
	gchar** _tmp11_;
	gchar** _tmp12_;
	gint _tmp12__length1;
	gchar* _tmp13_;
	gchar** _tmp14_;
	gchar** _tmp15_;
	gint _tmp15__length1;
	gchar* _tmp16_;
	gchar** _tmp17_;
	gchar** _tmp18_;
	gint _tmp18__length1;
	SwellFoopWindow* _tmp19_;
	self = (SwellFoop*) base;
	G_APPLICATION_CLASS (swell_foop_parent_class)->startup ((GApplication*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_application_get_type (), GtkApplication));
	_tmp0_ = gtk_settings_get_default ();
	g_object_set ((GObject*) _tmp0_, "gtk-application-prefer-dark-theme", TRUE, NULL);
	g_action_map_add_action_entries ((GActionMap*) self, SWELL_FOOP_action_entries, (gint) G_N_ELEMENTS (SWELL_FOOP_action_entries), self);
	_tmp1_ = g_strdup ("F1");
	_tmp2_ = g_new0 (gchar*, 1 + 1);
	_tmp2_[0] = _tmp1_;
	_tmp3_ = _tmp2_;
	_tmp3__length1 = 1;
	gtk_application_set_accels_for_action ((GtkApplication*) self, "app.help", _tmp3_);
	_tmp3_ = (_vala_array_free (_tmp3_, _tmp3__length1, (GDestroyNotify) g_free), NULL);
	_tmp4_ = g_strdup ("F10");
	_tmp5_ = g_new0 (gchar*, 1 + 1);
	_tmp5_[0] = _tmp4_;
	_tmp6_ = _tmp5_;
	_tmp6__length1 = 1;
	gtk_application_set_accels_for_action ((GtkApplication*) self, "win.toggle-hamburger", _tmp6_);
	_tmp6_ = (_vala_array_free (_tmp6_, _tmp6__length1, (GDestroyNotify) g_free), NULL);
	_tmp7_ = g_strdup ("<Primary>n");
	_tmp8_ = g_new0 (gchar*, 1 + 1);
	_tmp8_[0] = _tmp7_;
	_tmp9_ = _tmp8_;
	_tmp9__length1 = 1;
	gtk_application_set_accels_for_action ((GtkApplication*) self, "win.new-game", _tmp9_);
	_tmp9_ = (_vala_array_free (_tmp9_, _tmp9__length1, (GDestroyNotify) g_free), NULL);
	_tmp10_ = g_strdup ("<Primary>q");
	_tmp11_ = g_new0 (gchar*, 1 + 1);
	_tmp11_[0] = _tmp10_;
	_tmp12_ = _tmp11_;
	_tmp12__length1 = 1;
	gtk_application_set_accels_for_action ((GtkApplication*) self, "app.quit", _tmp12_);
	_tmp12_ = (_vala_array_free (_tmp12_, _tmp12__length1, (GDestroyNotify) g_free), NULL);
	_tmp13_ = g_strdup ("<Primary>z");
	_tmp14_ = g_new0 (gchar*, 1 + 1);
	_tmp14_[0] = _tmp13_;
	_tmp15_ = _tmp14_;
	_tmp15__length1 = 1;
	gtk_application_set_accels_for_action ((GtkApplication*) self, "win.undo", _tmp15_);
	_tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) g_free), NULL);
	_tmp16_ = g_strdup ("<Shift><Primary>z");
	_tmp17_ = g_new0 (gchar*, 1 + 1);
	_tmp17_[0] = _tmp16_;
	_tmp18_ = _tmp17_;
	_tmp18__length1 = 1;
	gtk_application_set_accels_for_action ((GtkApplication*) self, "win.redo", _tmp18_);
	_tmp18_ = (_vala_array_free (_tmp18_, _tmp18__length1, (GDestroyNotify) g_free), NULL);
	_tmp19_ = swell_foop_window_new ((GtkApplication*) self);
	g_object_ref_sink (_tmp19_);
	_g_object_unref0 (self->priv->window);
	self->priv->window = _tmp19_;
}

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

static void
swell_foop_real_shutdown (GApplication* base)
{
	SwellFoop * self;
	SwellFoopWindow* _tmp0_;
	self = (SwellFoop*) base;
	_tmp0_ = self->priv->window;
	gtk_widget_destroy ((GtkWidget*) _tmp0_);
	G_APPLICATION_CLASS (swell_foop_parent_class)->shutdown ((GApplication*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_application_get_type (), GtkApplication));
}

static void
swell_foop_real_activate (GApplication* base)
{
	SwellFoop * self;
	SwellFoopWindow* _tmp0_;
	self = (SwellFoop*) base;
	_tmp0_ = self->priv->window;
	gtk_window_present ((GtkWindow*) _tmp0_);
}

static inline void
swell_foop_quit_cb (SwellFoop* self)
{
	SwellFoopWindow* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->window;
	gtk_widget_destroy ((GtkWidget*) _tmp0_);
}

static inline void
swell_foop_help_cb (SwellFoop* self)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	{
		SwellFoopWindow* _tmp0_;
		_tmp0_ = self->priv->window;
		gtk_show_uri_on_window ((GtkWindow*) _tmp0_, "help:swell-foop", gtk_get_current_event_time (), &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp1_;
		const gchar* _tmp2_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp1_ = e;
		_tmp2_ = _tmp1_->message;
		g_warning ("swell-foop.vala:98: Failed to show help: %s", _tmp2_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		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;
	}
}

static inline void
swell_foop_about_cb (SwellFoop* self)
{
	gchar** authors = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar** _tmp2_;
	gint authors_length1;
	gint _authors_size_;
	gchar** artists = NULL;
	gchar* _tmp3_;
	gchar** _tmp4_;
	gint artists_length1;
	gint _artists_size_;
	gchar** documenters = NULL;
	gchar** _tmp5_;
	gint documenters_length1;
	gint _documenters_size_;
	SwellFoopWindow* _tmp6_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_strdup (_ ("Tim Horton"));
	_tmp1_ = g_strdup (_ ("Sophia Yu"));
	_tmp2_ = g_new0 (gchar*, 2 + 1);
	_tmp2_[0] = _tmp0_;
	_tmp2_[1] = _tmp1_;
	authors = _tmp2_;
	authors_length1 = 2;
	_authors_size_ = authors_length1;
	_tmp3_ = g_strdup (_ ("Tim Horton"));
	_tmp4_ = g_new0 (gchar*, 1 + 1);
	_tmp4_[0] = _tmp3_;
	artists = _tmp4_;
	artists_length1 = 1;
	_artists_size_ = artists_length1;
	_tmp5_ = g_new0 (gchar*, 0 + 1);
	documenters = _tmp5_;
	documenters_length1 = 0;
	_documenters_size_ = documenters_length1;
	_tmp6_ = self->priv->window;
	gtk_show_about_dialog ((GtkWindow*) _tmp6_, "program-name", SWELL_FOOP_PROGRAM_NAME, "version", VERSION, "comments", _ ("I want to play that game!\n" \
"You know, they all light-up and you click on them and they vanish!"), "license-type", GTK_LICENSE_GPL_2_0, "authors", authors, "copyright", _ ("Copyright \xc2\xa9 2009 Tim Horton"), "artists", artists, "documenters", documenters, "translator-credits", _ ("translator-credits"), "logo-icon-name", "org.gnome.SwellFoop", "website", PACKAGE_URL, NULL);
	documenters = (_vala_array_free (documenters, documenters_length1, (GDestroyNotify) g_free), NULL);
	artists = (_vala_array_free (artists, artists_length1, (GDestroyNotify) g_free), NULL);
	authors = (_vala_array_free (authors, authors_length1, (GDestroyNotify) g_free), NULL);
}

static gint
swell_foop_main (gchar** args,
                 gint args_length1)
{
	ClutterInitError _tmp0_;
	SwellFoop* app = NULL;
	SwellFoop* _tmp1_;
	SwellFoop* _tmp2_;
	gint result;
	setlocale (LC_ALL, "");
	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
	_tmp0_ = gtk_clutter_init ((gint*) (&args_length1), &args);
	if (_tmp0_ != CLUTTER_INIT_SUCCESS) {
		g_warning ("swell-foop.vala:145: Failed to initialise Clutter");
		result = EXIT_FAILURE;
		return result;
	}
	g_set_application_name (SWELL_FOOP_PROGRAM_NAME);
	gtk_window_set_default_icon_name ("org.gnome.SwellFoop");
	_tmp1_ = swell_foop_new ();
	app = _tmp1_;
	_tmp2_ = app;
	result = g_application_run ((GApplication*) _tmp2_, (gint) args_length1, args);
	_g_object_unref0 (app);
	return result;
}

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

static void
swell_foop_class_init (SwellFoopClass * klass,
                       gpointer klass_data)
{
	swell_foop_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &SwellFoop_private_offset);
	((GApplicationClass *) klass)->startup = (void (*) (GApplication*)) swell_foop_real_startup;
	((GApplicationClass *) klass)->handle_local_options = (gint (*) (GApplication*, GVariantDict*)) swell_foop_real_handle_local_options;
	((GApplicationClass *) klass)->shutdown = (void (*) (GApplication*)) swell_foop_real_shutdown;
	((GApplicationClass *) klass)->activate = (void (*) (GApplication*)) swell_foop_real_activate;
	G_OBJECT_CLASS (klass)->finalize = swell_foop_finalize;
}

static void
swell_foop_instance_init (SwellFoop * self,
                          gpointer klass)
{
	self->priv = swell_foop_get_instance_private (self);
}

static void
swell_foop_finalize (GObject * obj)
{
	SwellFoop * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_SWELL_FOOP, SwellFoop);
	_g_object_unref0 (self->priv->window);
	G_OBJECT_CLASS (swell_foop_parent_class)->finalize (obj);
}

static GType
swell_foop_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SwellFoopClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) swell_foop_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SwellFoop), 0, (GInstanceInitFunc) swell_foop_instance_init, NULL };
	GType swell_foop_type_id;
	swell_foop_type_id = g_type_register_static (gtk_application_get_type (), "SwellFoop", &g_define_type_info, 0);
	SwellFoop_private_offset = g_type_add_instance_private (swell_foop_type_id, sizeof (SwellFoopPrivate));
	return swell_foop_type_id;
}

GType
swell_foop_get_type (void)
{
	static volatile gsize swell_foop_type_id__once = 0;
	if (g_once_init_enter (&swell_foop_type_id__once)) {
		GType swell_foop_type_id;
		swell_foop_type_id = swell_foop_get_type_once ();
		g_once_init_leave (&swell_foop_type_id__once, swell_foop_type_id);
	}
	return swell_foop_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);
}

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

