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

/*
 * Color lines for GNOME
 * Copyright © 1999 Free Software Foundation
 * Authors: Robert Szokovacs <szo@szo.hu>
 *          Szabolcs Ban <shooby@gnome.hu>
 *          Karuna Grewal <karunagrewal98@gmail.com>
 *          Ruxandra Simion <ruxandra.simion93@gmail.com>
 * Copyright © 2007 Christian Persch
 *
 * This game 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, or (at your option)
 * any later version.
 *
 * This program 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 this program; if not, see <https://www.gnu.org/licenses/>.
 */

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

#define FIVE_OR_MORE_APP_PROGRAM_NAME _ ("Five or More")
#define FIVE_OR_MORE_APP_KEY_SIZE "size"
#define FIVE_OR_MORE_APP_KEY_BACKGROUND_COLOR "background-color"
#define FIVE_OR_MORE_APP_KEY_THEME "ball-theme"
#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_FIVE_OR_MORE_APP (five_or_more_app_get_type ())
#define FIVE_OR_MORE_APP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FIVE_OR_MORE_APP, FiveOrMoreApp))
#define FIVE_OR_MORE_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FIVE_OR_MORE_APP, FiveOrMoreAppClass))
#define IS_FIVE_OR_MORE_APP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FIVE_OR_MORE_APP))
#define IS_FIVE_OR_MORE_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FIVE_OR_MORE_APP))
#define FIVE_OR_MORE_APP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FIVE_OR_MORE_APP, FiveOrMoreAppClass))

typedef struct _FiveOrMoreApp FiveOrMoreApp;
typedef struct _FiveOrMoreAppClass FiveOrMoreAppClass;
typedef struct _FiveOrMoreAppPrivate FiveOrMoreAppPrivate;

#define TYPE_GAME_WINDOW (game_window_get_type ())
#define GAME_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GAME_WINDOW, GameWindow))
#define GAME_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_GAME_WINDOW, GameWindowClass))
#define IS_GAME_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_GAME_WINDOW))
#define IS_GAME_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_GAME_WINDOW))
#define GAME_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_GAME_WINDOW, GameWindowClass))

typedef struct _GameWindow GameWindow;
typedef struct _GameWindowClass GameWindowClass;
enum  {
	FIVE_OR_MORE_APP_0_PROPERTY,
	FIVE_OR_MORE_APP_NUM_PROPERTIES
};
static GParamSpec* five_or_more_app_properties[FIVE_OR_MORE_APP_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)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _FiveOrMoreApp {
	GtkApplication parent_instance;
	FiveOrMoreAppPrivate * priv;
};

struct _FiveOrMoreAppClass {
	GtkApplicationClass parent_class;
};

struct _FiveOrMoreAppPrivate {
	GameWindow* window;
};

static gint FiveOrMoreApp_private_offset;
static gpointer five_or_more_app_parent_class = NULL;

VALA_EXTERN GType five_or_more_app_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (FiveOrMoreApp, g_object_unref)
VALA_EXTERN GType game_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GameWindow, g_object_unref)
static void five_or_more_app_help_cb (FiveOrMoreApp* self);
static void _five_or_more_app_help_cb_gsimple_action_activate_callback (GSimpleAction* action,
                                                                 GVariant* parameter,
                                                                 gpointer self);
static void five_or_more_app_about_cb (FiveOrMoreApp* self);
static void _five_or_more_app_about_cb_gsimple_action_activate_callback (GSimpleAction* action,
                                                                  GVariant* parameter,
                                                                  gpointer self);
static void _g_application_quit_gsimple_action_activate_callback (GSimpleAction* action,
                                                           GVariant* parameter,
                                                           gpointer self);
static gint five_or_more_app_main (gchar** args,
                            gint args_length1);
static FiveOrMoreApp* five_or_more_app_new (void);
static FiveOrMoreApp* five_or_more_app_construct (GType object_type);
static void five_or_more_app_real_startup (GApplication* base);
static void five_or_more_app_real_activate (GApplication* base);
VALA_EXTERN GameWindow* game_window_new (void);
VALA_EXTERN GameWindow* game_window_construct (GType object_type);
static void five_or_more_app_real_shutdown (GApplication* base);
VALA_EXTERN void game_window_on_shutdown (GameWindow* self);
static void five_or_more_app_finalize (GObject * obj);
static GType five_or_more_app_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 GActionEntry FIVE_OR_MORE_APP_action_entries[3] = {{"help", _five_or_more_app_help_cb_gsimple_action_activate_callback}, {"about", _five_or_more_app_about_cb_gsimple_action_activate_callback}, {"quit", _g_application_quit_gsimple_action_activate_callback}};

static inline gpointer
five_or_more_app_get_instance_private (FiveOrMoreApp* self)
{
	return G_STRUCT_MEMBER_P (self, FiveOrMoreApp_private_offset);
}

static void
_five_or_more_app_help_cb_gsimple_action_activate_callback (GSimpleAction* action,
                                                            GVariant* parameter,
                                                            gpointer self)
{
	five_or_more_app_help_cb ((FiveOrMoreApp*) self);
}

static void
_five_or_more_app_about_cb_gsimple_action_activate_callback (GSimpleAction* action,
                                                             GVariant* parameter,
                                                             gpointer self)
{
	five_or_more_app_about_cb ((FiveOrMoreApp*) self);
}

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

static gint
five_or_more_app_main (gchar** args,
                       gint args_length1)
{
	FiveOrMoreApp* app = NULL;
	FiveOrMoreApp* _tmp0_;
	gint result;
	setlocale (LC_ALL, "");
	bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIRECTORY);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
	g_set_application_name (FIVE_OR_MORE_APP_PROGRAM_NAME);
	g_set_prgname ("org.gnome.five-or-more");
	gtk_window_set_default_icon_name ("org.gnome.five-or-more");
	_tmp0_ = five_or_more_app_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 five_or_more_app_main (argv, argc);
}

static FiveOrMoreApp*
five_or_more_app_construct (GType object_type)
{
	FiveOrMoreApp * self = NULL;
	self = (FiveOrMoreApp*) g_object_new (object_type, "application-id", "org.gnome.five-or-more", "flags", G_APPLICATION_FLAGS_NONE, NULL);
	return self;
}

static FiveOrMoreApp*
five_or_more_app_new (void)
{
	return five_or_more_app_construct (TYPE_FIVE_OR_MORE_APP);
}

static void
five_or_more_app_real_startup (GApplication* base)
{
	FiveOrMoreApp * 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;
	self = (FiveOrMoreApp*) base;
	G_APPLICATION_CLASS (five_or_more_app_parent_class)->startup ((GApplication*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_application_get_type (), GtkApplication));
	g_action_map_add_action_entries ((GActionMap*) self, FIVE_OR_MORE_APP_action_entries, (gint) G_N_ELEMENTS (FIVE_OR_MORE_APP_action_entries), self);
	_tmp0_ = g_strdup ("<Primary>n");
	_tmp1_ = g_new0 (gchar*, 1 + 1);
	_tmp1_[0] = _tmp0_;
	_tmp2_ = _tmp1_;
	_tmp2__length1 = 1;
	gtk_application_set_accels_for_action ((GtkApplication*) self, "win.new-game", _tmp2_);
	_tmp2_ = (_vala_array_free (_tmp2_, _tmp2__length1, (GDestroyNotify) g_free), NULL);
	_tmp3_ = g_strdup ("<Primary>q");
	_tmp4_ = g_new0 (gchar*, 1 + 1);
	_tmp4_[0] = _tmp3_;
	_tmp5_ = _tmp4_;
	_tmp5__length1 = 1;
	gtk_application_set_accels_for_action ((GtkApplication*) self, "app.quit", _tmp5_);
	_tmp5_ = (_vala_array_free (_tmp5_, _tmp5__length1, (GDestroyNotify) g_free), NULL);
	_tmp6_ = g_strdup ("F1");
	_tmp7_ = g_new0 (gchar*, 1 + 1);
	_tmp7_[0] = _tmp6_;
	_tmp8_ = _tmp7_;
	_tmp8__length1 = 1;
	gtk_application_set_accels_for_action ((GtkApplication*) self, "app.help", _tmp8_);
	_tmp8_ = (_vala_array_free (_tmp8_, _tmp8__length1, (GDestroyNotify) g_free), NULL);
}

static void
five_or_more_app_real_activate (GApplication* base)
{
	FiveOrMoreApp * self;
	GameWindow* _tmp0_;
	GameWindow* _tmp3_;
	self = (FiveOrMoreApp*) base;
	_tmp0_ = self->priv->window;
	if (_tmp0_ == NULL) {
		GameWindow* _tmp1_;
		GameWindow* _tmp2_;
		_tmp1_ = game_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
five_or_more_app_help_cb (FiveOrMoreApp* self)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	{
		GameWindow* _tmp0_;
		_tmp0_ = self->priv->window;
		gtk_show_uri_on_window ((GtkWindow*) _tmp0_, "help:five-or-more", 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 ("main.vala:91: Unable to open 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 void
five_or_more_app_about_cb (FiveOrMoreApp* self)
{
	gchar** authors = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar** _tmp2_;
	gint authors_length1;
	gint _authors_size_;
	gchar** artists = NULL;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar** _tmp6_;
	gint artists_length1;
	gint _artists_size_;
	gchar** documenters = NULL;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar** _tmp9_;
	gint documenters_length1;
	gint _documenters_size_;
	gchar* copyright = NULL;
	gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	GameWindow* _tmp14_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_strdup (_ ("Robert Szokovacs <szo@szo.hu>"));
	_tmp1_ = g_strdup (_ ("Szabolcs B\xc3\xa1n <shooby@gnome.hu>"));
	_tmp2_ = g_new0 (gchar*, 2 + 1);
	_tmp2_[0] = _tmp0_;
	_tmp2_[1] = _tmp1_;
	authors = _tmp2_;
	authors_length1 = 2;
	_authors_size_ = authors_length1;
	_tmp3_ = g_strdup (_ ("Callum McKenzie"));
	_tmp4_ = g_strdup (_ ("kenney.nl"));
	_tmp5_ = g_strdup (_ ("Robert Roth"));
	_tmp6_ = g_new0 (gchar*, 3 + 1);
	_tmp6_[0] = _tmp3_;
	_tmp6_[1] = _tmp4_;
	_tmp6_[2] = _tmp5_;
	artists = _tmp6_;
	artists_length1 = 3;
	_artists_size_ = artists_length1;
	_tmp7_ = g_strdup (_ ("Tiffany Antopolski"));
	_tmp8_ = g_strdup (_ ("Lanka Rathnayaka"));
	_tmp9_ = g_new0 (gchar*, 2 + 1);
	_tmp9_[0] = _tmp7_;
	_tmp9_[1] = _tmp8_;
	documenters = _tmp9_;
	documenters_length1 = 2;
	_documenters_size_ = documenters_length1;
	_tmp10_ = g_strconcat (_ ("Copyright © 1997–2008 Free Software Foundation, Inc."), "\n", NULL);
	_tmp11_ = _tmp10_;
	_tmp12_ = g_strconcat (_tmp11_, _ ("Copyright © 2013–2014 Michael Catanzaro"), NULL);
	_tmp13_ = _tmp12_;
	_g_free0 (_tmp11_);
	copyright = _tmp13_;
	_tmp14_ = self->priv->window;
	gtk_show_about_dialog ((GtkWindow*) _tmp14_, "program-name", FIVE_OR_MORE_APP_PROGRAM_NAME, "logo-icon-name", "org.gnome.five-or-more", "version", VERSION, "comments", _ ("GNOME port of the once-popular Color Lines game"), "copyright", copyright, "license-type", GTK_LICENSE_GPL_2_0, "authors", authors, "artists", artists, "documenters", documenters, "translator-credits", _ ("translator-credits"), "website", "https://wiki.gnome.org/Apps/Five%20or%20more", NULL);
	_g_free0 (copyright);
	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 void
five_or_more_app_real_shutdown (GApplication* base)
{
	FiveOrMoreApp * self;
	GameWindow* _tmp0_;
	self = (FiveOrMoreApp*) base;
	_tmp0_ = self->priv->window;
	if (_tmp0_ != NULL) {
		GameWindow* _tmp1_;
		_tmp1_ = self->priv->window;
		game_window_on_shutdown (_tmp1_);
	}
	G_APPLICATION_CLASS (five_or_more_app_parent_class)->shutdown ((GApplication*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_application_get_type (), GtkApplication));
}

static void
five_or_more_app_class_init (FiveOrMoreAppClass * klass,
                             gpointer klass_data)
{
	five_or_more_app_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FiveOrMoreApp_private_offset);
	((GApplicationClass *) klass)->startup = (void (*) (GApplication*)) five_or_more_app_real_startup;
	((GApplicationClass *) klass)->activate = (void (*) (GApplication*)) five_or_more_app_real_activate;
	((GApplicationClass *) klass)->shutdown = (void (*) (GApplication*)) five_or_more_app_real_shutdown;
	G_OBJECT_CLASS (klass)->finalize = five_or_more_app_finalize;
}

static void
five_or_more_app_instance_init (FiveOrMoreApp * self,
                                gpointer klass)
{
	self->priv = five_or_more_app_get_instance_private (self);
}

static void
five_or_more_app_finalize (GObject * obj)
{
	FiveOrMoreApp * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_FIVE_OR_MORE_APP, FiveOrMoreApp);
	_g_object_unref0 (self->priv->window);
	G_OBJECT_CLASS (five_or_more_app_parent_class)->finalize (obj);
}

static GType
five_or_more_app_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FiveOrMoreAppClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) five_or_more_app_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FiveOrMoreApp), 0, (GInstanceInitFunc) five_or_more_app_instance_init, NULL };
	GType five_or_more_app_type_id;
	five_or_more_app_type_id = g_type_register_static (gtk_application_get_type (), "FiveOrMoreApp", &g_define_type_info, 0);
	FiveOrMoreApp_private_offset = g_type_add_instance_private (five_or_more_app_type_id, sizeof (FiveOrMoreAppPrivate));
	return five_or_more_app_type_id;
}

GType
five_or_more_app_get_type (void)
{
	static volatile gsize five_or_more_app_type_id__once = 0;
	if (g_once_init_enter (&five_or_more_app_type_id__once)) {
		GType five_or_more_app_type_id;
		five_or_more_app_type_id = five_or_more_app_get_type_once ();
		g_once_init_leave (&five_or_more_app_type_id__once, five_or_more_app_type_id);
	}
	return five_or_more_app_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);
}

