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


#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <gio/gio.h>
#include <clutter/clutter.h>
#include "config.h"
#include <clutter-gtk/clutter-gtk.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>
#include <games-stock.h>
#include <locale.h>


#define TYPE_LIGHTS_OFF (lights_off_get_type ())
#define LIGHTS_OFF(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_LIGHTS_OFF, LightsOff))
#define LIGHTS_OFF_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_LIGHTS_OFF, LightsOffClass))
#define IS_LIGHTS_OFF(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_LIGHTS_OFF))
#define IS_LIGHTS_OFF_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_LIGHTS_OFF))
#define LIGHTS_OFF_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_LIGHTS_OFF, LightsOffClass))

typedef struct _LightsOff LightsOff;
typedef struct _LightsOffClass LightsOffClass;
typedef struct _LightsOffPrivate LightsOffPrivate;

#define TYPE_GAME_VIEW (game_view_get_type ())
#define GAME_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GAME_VIEW, GameView))
#define GAME_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_GAME_VIEW, GameViewClass))
#define IS_GAME_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_GAME_VIEW))
#define IS_GAME_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_GAME_VIEW))
#define GAME_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_GAME_VIEW, GameViewClass))

typedef struct _GameView GameView;
typedef struct _GameViewClass GameViewClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _LightsOff {
	GtkApplication parent_instance;
	LightsOffPrivate * priv;
};

struct _LightsOffClass {
	GtkApplicationClass parent_class;
};

struct _LightsOffPrivate {
	GSettings* settings;
	GtkBuilder* ui;
	GtkWindow* window;
	GameView* game_view;
};


static gpointer lights_off_parent_class = NULL;

GType lights_off_get_type (void) G_GNUC_CONST;
GType game_view_get_type (void) G_GNUC_CONST;
#define LIGHTS_OFF_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_LIGHTS_OFF, LightsOffPrivate))
enum  {
	LIGHTS_OFF_DUMMY_PROPERTY
};
static LightsOff* lights_off_new (GError** error);
static LightsOff* lights_off_construct (GType object_type, GError** error);
static gboolean lights_off_key_release_event_cb (LightsOff* self, ClutterActor* actor, ClutterKeyEvent* event);
static gboolean _lights_off_key_release_event_cb_clutter_actor_key_release_event (ClutterActor* _sender, ClutterKeyEvent* event, gpointer self);
GameView* game_view_new (gint level);
GameView* game_view_construct (GType object_type, gint level);
static void lights_off_level_changed_cb (LightsOff* self, gint level);
static void _lights_off_level_changed_cb_game_view_level_changed (GameView* _sender, gint level, gpointer self);
void game_view_hide_cursor (GameView* self);
void game_view_move_cursor (GameView* self, gint x_step, gint y_step);
void game_view_activate_cursor (GameView* self);
static void lights_off_real_activate (GApplication* base);
void G_MODULE_EXPORT new_game_cb (GtkWidget* widget, LightsOff* self);
void game_view_reset_game (GameView* self);
void G_MODULE_EXPORT quit_cb (GtkWidget* widget, LightsOff* self);
void G_MODULE_EXPORT help_cb (GtkWidget* widget, LightsOff* self);
void G_MODULE_EXPORT about_cb (GtkWidget* widget, LightsOff* self);
gint lights_off_main (gchar** args, int args_length1);
static void lights_off_finalize (GObject* obj);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);


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


static gboolean _lights_off_key_release_event_cb_clutter_actor_key_release_event (ClutterActor* _sender, ClutterKeyEvent* event, gpointer self) {
	gboolean result;
	result = lights_off_key_release_event_cb (self, _sender, event);
	return result;
}


static void _lights_off_level_changed_cb_game_view_level_changed (GameView* _sender, gint level, gpointer self) {
	lights_off_level_changed_cb (self, level);
}


static LightsOff* lights_off_construct (GType object_type, GError** error) {
	LightsOff * self = NULL;
	GSettings* _tmp0_;
	GtkBuilder* _tmp1_;
	GtkBuilder* _tmp7_;
	GtkBuilder* _tmp8_;
	GObject* _tmp9_ = NULL;
	GtkWindow* _tmp10_;
	GtkWindow* _tmp11_;
	GtkBuilder* _tmp12_;
	GObject* _tmp13_ = NULL;
	GtkBox* _tmp14_;
	GtkBox* box;
	GtkClutterEmbed* _tmp15_;
	GtkClutterEmbed* _tmp16_;
	GtkClutterEmbed* clutter_embed;
	ClutterActor* _tmp17_ = NULL;
	ClutterStage* _tmp18_;
	ClutterStage* stage;
	ClutterColor _tmp19_ = {0};
	GSettings* _tmp20_;
	gint _tmp21_ = 0;
	GameView* _tmp22_;
	GameView* _tmp23_;
	GameView* _tmp24_;
	GameView* _tmp25_;
	GameView* _tmp26_;
	GameView* _tmp27_;
	gfloat _tmp28_;
	gfloat _tmp29_;
	GameView* _tmp30_;
	gfloat _tmp31_;
	gfloat _tmp32_;
	gfloat _tmp33_;
	gfloat _tmp34_;
	gfloat _tmp35_;
	gfloat _tmp36_;
	GError * _inner_error_ = NULL;
	self = (LightsOff*) g_object_new (object_type, "application-id", "org.gnome.lightsoff", "flags", G_APPLICATION_FLAGS_NONE, NULL);
	_tmp0_ = g_settings_new ("org.gnome.lightsoff");
	_g_object_unref0 (self->priv->settings);
	self->priv->settings = _tmp0_;
	_tmp1_ = gtk_builder_new ();
	_g_object_unref0 (self->priv->ui);
	self->priv->ui = _tmp1_;
	{
		GtkBuilder* _tmp2_;
		gchar* _tmp3_ = NULL;
		gchar* _tmp4_;
		_tmp2_ = self->priv->ui;
		_tmp3_ = g_build_filename (DATADIR, "lightsoff.ui", NULL);
		_tmp4_ = _tmp3_;
		gtk_builder_add_from_file (_tmp2_, _tmp4_, &_inner_error_);
		_g_free0 (_tmp4_);
		if (_inner_error_ != NULL) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp5_;
		const gchar* _tmp6_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp5_ = e;
		_tmp6_ = _tmp5_->message;
		g_warning ("lightsoff.vala:21: Could not load UI: %s", _tmp6_);
		_g_error_free0 (e);
	}
	__finally0:
	if (_inner_error_ != NULL) {
		g_propagate_error (error, _inner_error_);
		_g_object_unref0 (self);
		return NULL;
	}
	_tmp7_ = self->priv->ui;
	gtk_builder_connect_signals (_tmp7_, self);
	_tmp8_ = self->priv->ui;
	_tmp9_ = gtk_builder_get_object (_tmp8_, "game_window");
	_tmp10_ = _g_object_ref0 (GTK_WINDOW (_tmp9_));
	_g_object_unref0 (self->priv->window);
	self->priv->window = _tmp10_;
	_tmp11_ = self->priv->window;
	gtk_application_add_window ((GtkApplication*) self, _tmp11_);
	_tmp12_ = self->priv->ui;
	_tmp13_ = gtk_builder_get_object (_tmp12_, "game_vbox");
	_tmp14_ = _g_object_ref0 (GTK_BOX (_tmp13_));
	box = _tmp14_;
	_tmp15_ = (GtkClutterEmbed*) gtk_clutter_embed_new ();
	_tmp16_ = g_object_ref_sink (_tmp15_);
	clutter_embed = _tmp16_;
	gtk_widget_show ((GtkWidget*) clutter_embed);
	gtk_box_pack_start (box, (GtkWidget*) clutter_embed, TRUE, TRUE, (guint) 0);
	_tmp17_ = gtk_clutter_embed_get_stage (clutter_embed);
	_tmp18_ = _g_object_ref0 (CLUTTER_STAGE (_tmp17_));
	stage = _tmp18_;
	g_signal_connect_object ((ClutterActor*) stage, "key-release-event", (GCallback) _lights_off_key_release_event_cb_clutter_actor_key_release_event, self, 0);
	clutter_color_from_string (&_tmp19_, "#000000");
	clutter_stage_set_color (stage, &_tmp19_);
	clutter_stage_set_use_fog (stage, FALSE);
	_tmp20_ = self->priv->settings;
	_tmp21_ = g_settings_get_int (_tmp20_, "level");
	_tmp22_ = game_view_new (_tmp21_);
	_tmp23_ = g_object_ref_sink (_tmp22_);
	_g_object_unref0 (self->priv->game_view);
	self->priv->game_view = _tmp23_;
	_tmp24_ = self->priv->game_view;
	g_signal_connect_object (_tmp24_, "level-changed", (GCallback) _lights_off_level_changed_cb_game_view_level_changed, self, 0);
	_tmp25_ = self->priv->game_view;
	clutter_actor_show ((ClutterActor*) _tmp25_);
	_tmp26_ = self->priv->game_view;
	clutter_container_add_actor ((ClutterContainer*) stage, (ClutterActor*) _tmp26_);
	_tmp27_ = self->priv->game_view;
	_tmp28_ = clutter_actor_get_width ((ClutterActor*) _tmp27_);
	_tmp29_ = _tmp28_;
	_tmp30_ = self->priv->game_view;
	_tmp31_ = clutter_actor_get_height ((ClutterActor*) _tmp30_);
	_tmp32_ = _tmp31_;
	clutter_actor_set_size ((ClutterActor*) stage, _tmp29_, _tmp32_);
	_tmp33_ = clutter_actor_get_width ((ClutterActor*) stage);
	_tmp34_ = _tmp33_;
	_tmp35_ = clutter_actor_get_height ((ClutterActor*) stage);
	_tmp36_ = _tmp35_;
	gtk_widget_set_size_request ((GtkWidget*) clutter_embed, (gint) _tmp34_, (gint) _tmp36_);
	_g_object_unref0 (stage);
	_g_object_unref0 (clutter_embed);
	_g_object_unref0 (box);
	return self;
}


static LightsOff* lights_off_new (GError** error) {
	return lights_off_construct (TYPE_LIGHTS_OFF, error);
}


static void lights_off_level_changed_cb (LightsOff* self, gint level) {
	GSettings* _tmp0_;
	gint _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->settings;
	_tmp1_ = level;
	g_settings_set_int (_tmp0_, "level", _tmp1_);
}


static gboolean lights_off_key_release_event_cb (LightsOff* self, ClutterActor* actor, ClutterKeyEvent* event) {
	gboolean result = FALSE;
	ClutterKeyEvent _tmp0_;
	guint _tmp1_;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (actor != NULL, FALSE);
	g_return_val_if_fail (event != NULL, FALSE);
	_tmp0_ = *event;
	_tmp1_ = _tmp0_.keyval;
	switch (_tmp1_) {
		case CLUTTER_KEY_Escape:
		{
			GameView* _tmp2_;
			_tmp2_ = self->priv->game_view;
			game_view_hide_cursor (_tmp2_);
			result = TRUE;
			return result;
		}
		case CLUTTER_KEY_Down:
		{
			GameView* _tmp3_;
			_tmp3_ = self->priv->game_view;
			game_view_move_cursor (_tmp3_, 0, 1);
			result = TRUE;
			return result;
		}
		case CLUTTER_KEY_Up:
		{
			GameView* _tmp4_;
			_tmp4_ = self->priv->game_view;
			game_view_move_cursor (_tmp4_, 0, -1);
			result = TRUE;
			return result;
		}
		case CLUTTER_KEY_Left:
		{
			GameView* _tmp5_;
			_tmp5_ = self->priv->game_view;
			game_view_move_cursor (_tmp5_, -1, 0);
			result = TRUE;
			return result;
		}
		case CLUTTER_KEY_Right:
		{
			GameView* _tmp6_;
			_tmp6_ = self->priv->game_view;
			game_view_move_cursor (_tmp6_, 1, 0);
			result = TRUE;
			return result;
		}
		case CLUTTER_KEY_Return:
		{
			GameView* _tmp7_;
			_tmp7_ = self->priv->game_view;
			game_view_activate_cursor (_tmp7_);
			result = TRUE;
			return result;
		}
		default:
		{
			result = FALSE;
			return result;
		}
	}
}


static void lights_off_real_activate (GApplication* base) {
	LightsOff * self;
	GtkWindow* _tmp0_;
	self = (LightsOff*) base;
	_tmp0_ = self->priv->window;
	gtk_widget_show ((GtkWidget*) _tmp0_);
}


void G_MODULE_EXPORT new_game_cb (GtkWidget* widget, LightsOff* self) {
	GameView* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (widget != NULL);
	_tmp0_ = self->priv->game_view;
	game_view_reset_game (_tmp0_);
}


void G_MODULE_EXPORT quit_cb (GtkWidget* widget, LightsOff* self) {
	GtkWindow* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (widget != NULL);
	_tmp0_ = self->priv->window;
	gtk_widget_destroy ((GtkWidget*) _tmp0_);
}


void G_MODULE_EXPORT help_cb (GtkWidget* widget, LightsOff* self) {
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (widget != NULL);
	{
		GtkWindow* _tmp0_;
		GdkScreen* _tmp1_ = NULL;
		guint32 _tmp2_ = 0U;
		_tmp0_ = self->priv->window;
		_tmp1_ = gtk_window_get_screen (_tmp0_);
		_tmp2_ = gtk_get_current_event_time ();
		gtk_show_uri (_tmp1_, "help:lightsoff", _tmp2_, &_inner_error_);
		if (_inner_error_ != NULL) {
			goto __catch1_g_error;
		}
	}
	goto __finally1;
	__catch1_g_error:
	{
		GError* e = NULL;
		GError* _tmp3_;
		const gchar* _tmp4_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp3_ = e;
		_tmp4_ = _tmp3_->message;
		g_warning ("lightsoff.vala:106: Failed to show help: %s", _tmp4_);
		_g_error_free0 (e);
	}
	__finally1:
	if (_inner_error_ != NULL) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return;
	}
}


void G_MODULE_EXPORT about_cb (GtkWidget* widget, LightsOff* self) {
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar** _tmp2_ = NULL;
	gchar** authors;
	gint authors_length1;
	gint _authors_size_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar** _tmp5_ = NULL;
	gchar** artists;
	gint artists_length1;
	gint _artists_size_;
	gchar* _tmp6_;
	gchar** _tmp7_ = NULL;
	gchar** documenters;
	gint documenters_length1;
	gint _documenters_size_;
	GtkWindow* _tmp8_;
	const gchar* _tmp9_ = NULL;
	const gchar* _tmp10_ = NULL;
	const gchar* _tmp11_ = NULL;
	gchar* _tmp12_ = NULL;
	gchar* _tmp13_;
	const gchar* _tmp14_ = NULL;
	const gchar* _tmp15_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (widget != NULL);
	_tmp0_ = g_strdup ("Tim Horton");
	_tmp1_ = g_strdup ("Robert Ancell");
	_tmp2_ = g_new0 (gchar*, 3 + 1);
	_tmp2_[0] = _tmp0_;
	_tmp2_[1] = _tmp1_;
	_tmp2_[2] = NULL;
	authors = _tmp2_;
	authors_length1 = 3;
	_authors_size_ = authors_length1;
	_tmp3_ = g_strdup ("Tim Horton");
	_tmp4_ = g_strdup ("Ulisse Perusin");
	_tmp5_ = g_new0 (gchar*, 3 + 1);
	_tmp5_[0] = _tmp3_;
	_tmp5_[1] = _tmp4_;
	_tmp5_[2] = NULL;
	artists = _tmp5_;
	artists_length1 = 3;
	_artists_size_ = artists_length1;
	_tmp6_ = g_strdup ("Eric Baudais");
	_tmp7_ = g_new0 (gchar*, 2 + 1);
	_tmp7_[0] = _tmp6_;
	_tmp7_[1] = NULL;
	documenters = _tmp7_;
	documenters_length1 = 2;
	_documenters_size_ = documenters_length1;
	_tmp8_ = self->priv->window;
	_tmp9_ = _ ("Lights Off");
	_tmp10_ = _ ("Turn off all the lights\n\nLights Off is a part of GNOME Games.");
	_tmp11_ = _ ("Lights Off");
	_tmp12_ = games_get_license (_tmp11_);
	_tmp13_ = _tmp12_;
	_tmp14_ = _ ("translator-credits");
	_tmp15_ = _ ("GNOME Games web site");
	gtk_show_about_dialog (_tmp8_, "program-name", _tmp9_, "version", VERSION, "comments", _tmp10_, "copyright", "Copyright © 2009 Tim Horton", "license", _tmp13_, "wrap-license", TRUE, "authors", authors, "artists", artists, "documenters", documenters, "translator-credits", _tmp14_, "logo-icon-name", "lightsoff", "website", "http://www.gnome.org/projects/gnome-games", "website-label", _tmp15_, NULL, NULL);
	_g_free0 (_tmp13_);
	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);
}


gint lights_off_main (gchar** args, int args_length1) {
	gint result = 0;
	ClutterInitError _tmp0_ = 0;
	LightsOff* app = NULL;
	GError * _inner_error_ = NULL;
	setlocale (LC_ALL, "");
	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
	g_set_prgname ("lightsoff");
	_tmp0_ = gtk_clutter_init (&args_length1, &args);
	if (_tmp0_ != CLUTTER_INIT_SUCCESS) {
		g_warning ("lightsoff.vala:162: Failed to initialise Clutter");
		result = EXIT_FAILURE;
		return result;
	}
	games_stock_init ();
	{
		LightsOff* _tmp1_;
		LightsOff* _tmp2_;
		LightsOff* _tmp3_;
		gint _tmp4_ = 0;
		_tmp1_ = lights_off_new (&_inner_error_);
		_tmp2_ = _tmp1_;
		if (_inner_error_ != NULL) {
			goto __catch2_g_error;
		}
		_g_object_unref0 (app);
		app = _tmp2_;
		_tmp3_ = app;
		_tmp4_ = g_application_run ((GApplication*) _tmp3_, 0, NULL);
		result = _tmp4_;
		_g_object_unref0 (app);
		return result;
	}
	goto __finally2;
	__catch2_g_error:
	{
		GError* e = NULL;
		GError* _tmp5_;
		const gchar* _tmp6_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp5_ = e;
		_tmp6_ = _tmp5_->message;
		g_warning ("lightsoff.vala:176: Failed to create application: %s", _tmp6_);
		result = EXIT_FAILURE;
		_g_error_free0 (e);
		_g_object_unref0 (app);
		return result;
	}
	__finally2:
	_g_object_unref0 (app);
	g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
	g_clear_error (&_inner_error_);
	return 0;
}


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


static void lights_off_class_init (LightsOffClass * klass) {
	lights_off_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (LightsOffPrivate));
	G_APPLICATION_CLASS (klass)->activate = lights_off_real_activate;
	G_OBJECT_CLASS (klass)->finalize = lights_off_finalize;
}


static void lights_off_instance_init (LightsOff * self) {
	self->priv = LIGHTS_OFF_GET_PRIVATE (self);
}


static void lights_off_finalize (GObject* obj) {
	LightsOff * self;
	self = LIGHTS_OFF (obj);
	_g_object_unref0 (self->priv->settings);
	_g_object_unref0 (self->priv->ui);
	_g_object_unref0 (self->priv->window);
	_g_object_unref0 (self->priv->game_view);
	G_OBJECT_CLASS (lights_off_parent_class)->finalize (obj);
}


GType lights_off_get_type (void) {
	static volatile gsize lights_off_type_id__volatile = 0;
	if (g_once_init_enter (&lights_off_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (LightsOffClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) lights_off_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (LightsOff), 0, (GInstanceInitFunc) lights_off_instance_init, NULL };
		GType lights_off_type_id;
		lights_off_type_id = g_type_register_static (GTK_TYPE_APPLICATION, "LightsOff", &g_define_type_info, 0);
		g_once_init_leave (&lights_off_type_id__volatile, lights_off_type_id);
	}
	return lights_off_type_id__volatile;
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int 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, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}



