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

/*
 * Copyright (C) 2010-2013 Robert Ancell
 * Copyright (C) 2014 Michael Catanzaro
 * Copyright (C) 2016 Arnaud Bonatti
 *
 * 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 <adwaita.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 "config.h"
#include <stdio.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>

#define LIGHTS_OFF_PROGRAM_NAME _ ("Lights Off")
#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_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_MANAGED_WINDOW (managed_window_get_type ())
#define MANAGED_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MANAGED_WINDOW, ManagedWindow))
#define MANAGED_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MANAGED_WINDOW, ManagedWindowClass))
#define IS_MANAGED_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MANAGED_WINDOW))
#define IS_MANAGED_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MANAGED_WINDOW))
#define MANAGED_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MANAGED_WINDOW, ManagedWindowClass))

typedef struct _ManagedWindow ManagedWindow;
typedef struct _ManagedWindowClass ManagedWindowClass;

#define TYPE_LIGHTSOFF_WINDOW (lightsoff_window_get_type ())
#define LIGHTSOFF_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_LIGHTSOFF_WINDOW, LightsoffWindow))
#define LIGHTSOFF_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_LIGHTSOFF_WINDOW, LightsoffWindowClass))
#define IS_LIGHTSOFF_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_LIGHTSOFF_WINDOW))
#define IS_LIGHTSOFF_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_LIGHTSOFF_WINDOW))
#define LIGHTSOFF_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_LIGHTSOFF_WINDOW, LightsoffWindowClass))

typedef struct _LightsoffWindow LightsoffWindow;
typedef struct _LightsoffWindowClass LightsoffWindowClass;
enum  {
	LIGHTS_OFF_0_PROPERTY,
	LIGHTS_OFF_NUM_PROPERTIES
};
static GParamSpec* lights_off_properties[LIGHTS_OFF_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_free0(var) (var = (g_free (var), NULL))

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

struct _LightsOffClass {
	AdwApplicationClass parent_class;
};

struct _LightsOffPrivate {
	LightsoffWindow* window;
};

static gint LightsOff_private_offset;
static gpointer lights_off_parent_class = NULL;
static gchar** lights_off_remaining;
static gint lights_off_remaining_length1;
static gchar** lights_off_remaining = NULL;
static gint lights_off_remaining_length1 = 0;
static gint _lights_off_remaining_size_ = 0;

VALA_EXTERN GType lights_off_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (LightsOff, g_object_unref)
VALA_EXTERN GType managed_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ManagedWindow, g_object_unref)
VALA_EXTERN GType lightsoff_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (LightsoffWindow, g_object_unref)
static inline void lights_off_help_cb (LightsOff* self);
static void _lights_off_help_cb_gsimple_action_activate_callback (GSimpleAction* action,
                                                           GVariant* parameter,
                                                           gpointer self);
static void lights_off_quit_cb (LightsOff* self);
static void _lights_off_quit_cb_gsimple_action_activate_callback (GSimpleAction* action,
                                                           GVariant* parameter,
                                                           gpointer self);
static void lights_off_about_cb (LightsOff* self);
static void _lights_off_about_cb_gsimple_action_activate_callback (GSimpleAction* action,
                                                            GVariant* parameter,
                                                            gpointer self);
static gint lights_off_main (gchar** args,
                      gint args_length1);
static LightsOff* lights_off_new (void);
static LightsOff* lights_off_construct (GType object_type);
static gint lights_off_real_handle_local_options (GApplication* base,
                                           GVariantDict* options);
static void lights_off_real_startup (GApplication* base);
static void lights_off_real_activate (GApplication* base);
VALA_EXTERN LightsoffWindow* lightsoff_window_new (void);
VALA_EXTERN LightsoffWindow* lightsoff_window_construct (GType object_type);
static void lights_off_finalize (GObject * obj);
static GType lights_off_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 LIGHTS_OFF_option_entries[3] = {{"version", 'v', (gint) G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, N_ ("Display version number"), NULL}, {G_OPTION_REMAINING, (gchar) 0, (gint) G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING_ARRAY, &lights_off_remaining, "args", NULL}, {0}};
static const GActionEntry LIGHTS_OFF_action_entries[3] = {{"help", _lights_off_help_cb_gsimple_action_activate_callback}, {"quit", _lights_off_quit_cb_gsimple_action_activate_callback}, {"about", _lights_off_about_cb_gsimple_action_activate_callback}};

static inline gpointer
lights_off_get_instance_private (LightsOff* self)
{
	return G_STRUCT_MEMBER_P (self, LightsOff_private_offset);
}

static void
_lights_off_help_cb_gsimple_action_activate_callback (GSimpleAction* action,
                                                      GVariant* parameter,
                                                      gpointer self)
{
	lights_off_help_cb ((LightsOff*) self);
}

static void
_lights_off_quit_cb_gsimple_action_activate_callback (GSimpleAction* action,
                                                      GVariant* parameter,
                                                      gpointer self)
{
	lights_off_quit_cb ((LightsOff*) self);
}

static void
_lights_off_about_cb_gsimple_action_activate_callback (GSimpleAction* action,
                                                       GVariant* parameter,
                                                       gpointer self)
{
	lights_off_about_cb ((LightsOff*) self);
}

static gint
lights_off_main (gchar** args,
                 gint args_length1)
{
	LightsOff* app = NULL;
	LightsOff* _tmp0_;
	gint result;
	setlocale (LC_ALL, "");
	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
	g_set_application_name (LIGHTS_OFF_PROGRAM_NAME);
	_tmp0_ = lights_off_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 lights_off_main (argv, argc);
}

static LightsOff*
lights_off_construct (GType object_type)
{
	LightsOff * self = NULL;
	self = (LightsOff*) g_object_new (object_type, "application-id", "org.gnome.LightsOff", "flags", G_APPLICATION_DEFAULT_FLAGS, NULL);
	g_application_add_main_option_entries ((GApplication*) self, LIGHTS_OFF_option_entries);
	return self;
}

static LightsOff*
lights_off_new (void)
{
	return lights_off_construct (TYPE_LIGHTS_OFF);
}

static gint
lights_off_real_handle_local_options (GApplication* base,
                                      GVariantDict* options)
{
	LightsOff * self;
	gboolean _tmp0_ = FALSE;
	gchar** _tmp6_;
	gint _tmp6__length1;
	const gchar* _tmp7_;
	gint result;
	self = (LightsOff*) base;
	g_return_val_if_fail (options != NULL, 0);
	if (g_variant_dict_contains (options, "version")) {
		_tmp0_ = TRUE;
	} else {
		gboolean _tmp1_ = FALSE;
		gchar** _tmp2_;
		gint _tmp2__length1;
		const gchar* _tmp3_;
		_tmp2_ = lights_off_remaining;
		_tmp2__length1 = lights_off_remaining_length1;
		_tmp3_ = _tmp2_[0];
		if (_tmp3_ != NULL) {
			gchar** _tmp4_;
			gint _tmp4__length1;
			const gchar* _tmp5_;
			_tmp4_ = lights_off_remaining;
			_tmp4__length1 = lights_off_remaining_length1;
			_tmp5_ = _tmp4_[0];
			_tmp1_ = g_strcmp0 ((const gchar*) _tmp5_, "version") == 0;
		} else {
			_tmp1_ = FALSE;
		}
		_tmp0_ = _tmp1_;
	}
	if (_tmp0_) {
		g_print ("%s %s\n", LIGHTS_OFF_PROGRAM_NAME, VERSION);
		result = EXIT_SUCCESS;
		return result;
	}
	_tmp6_ = lights_off_remaining;
	_tmp6__length1 = lights_off_remaining_length1;
	_tmp7_ = _tmp6_[0];
	if (_tmp7_ != NULL) {
		FILE* _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		_tmp8_ = stderr;
		_tmp9_ = g_strconcat (_ ("Failed to parse command-line arguments."), "\n", NULL);
		_tmp10_ = _tmp9_;
		fprintf (_tmp8_, "%s", _tmp10_);
		_g_free0 (_tmp10_);
		result = EXIT_FAILURE;
		return result;
	}
	result = -1;
	return result;
}

static void
lights_off_real_startup (GApplication* base)
{
	LightsOff * 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_;
	gint _tmp14__length1;
	gchar* _tmp15_;
	gchar** _tmp16_;
	gchar** _tmp17_;
	gint _tmp17__length1;
	self = (LightsOff*) base;
	G_APPLICATION_CLASS (lights_off_parent_class)->startup ((GApplication*) G_TYPE_CHECK_INSTANCE_CAST (self, adw_application_get_type (), AdwApplication));
	g_action_map_add_action_entries ((GActionMap*) self, LIGHTS_OFF_action_entries, (gint) G_N_ELEMENTS (LIGHTS_OFF_action_entries), self);
	_tmp0_ = g_strdup ("<Primary>q");
	_tmp1_ = g_new0 (gchar*, 1 + 1);
	_tmp1_[0] = _tmp0_;
	_tmp2_ = _tmp1_;
	_tmp2__length1 = 1;
	gtk_application_set_accels_for_action ((GtkApplication*) self, "app.quit", _tmp2_);
	_tmp2_ = (_vala_array_free (_tmp2_, _tmp2__length1, (GDestroyNotify) g_free), NULL);
	_tmp3_ = g_strdup ("F1");
	_tmp4_ = g_new0 (gchar*, 1 + 1);
	_tmp4_[0] = _tmp3_;
	_tmp5_ = _tmp4_;
	_tmp5__length1 = 1;
	gtk_application_set_accels_for_action ((GtkApplication*) self, "app.help", _tmp5_);
	_tmp5_ = (_vala_array_free (_tmp5_, _tmp5__length1, (GDestroyNotify) g_free), NULL);
	_tmp6_ = g_strdup ("<Primary>n");
	_tmp7_ = g_new0 (gchar*, 1 + 1);
	_tmp7_[0] = _tmp6_;
	_tmp8_ = _tmp7_;
	_tmp8__length1 = 1;
	gtk_application_set_accels_for_action ((GtkApplication*) self, "win.new-game", _tmp8_);
	_tmp8_ = (_vala_array_free (_tmp8_, _tmp8__length1, (GDestroyNotify) g_free), NULL);
	_tmp9_ = g_strdup ("<Primary>Page_Up");
	_tmp10_ = g_new0 (gchar*, 1 + 1);
	_tmp10_[0] = _tmp9_;
	_tmp11_ = _tmp10_;
	_tmp11__length1 = 1;
	gtk_application_set_accels_for_action ((GtkApplication*) self, "win.previous-level", _tmp11_);
	_tmp11_ = (_vala_array_free (_tmp11_, _tmp11__length1, (GDestroyNotify) g_free), NULL);
	_tmp12_ = g_strdup ("<Primary>Page_Down");
	_tmp13_ = g_new0 (gchar*, 1 + 1);
	_tmp13_[0] = _tmp12_;
	_tmp14_ = _tmp13_;
	_tmp14__length1 = 1;
	gtk_application_set_accels_for_action ((GtkApplication*) self, "win.next-level", _tmp14_);
	_tmp14_ = (_vala_array_free (_tmp14_, _tmp14__length1, (GDestroyNotify) g_free), NULL);
	_tmp15_ = g_strdup ("<Primary>r");
	_tmp16_ = g_new0 (gchar*, 1 + 1);
	_tmp16_[0] = _tmp15_;
	_tmp17_ = _tmp16_;
	_tmp17__length1 = 1;
	gtk_application_set_accels_for_action ((GtkApplication*) self, "win.restart", _tmp17_);
	_tmp17_ = (_vala_array_free (_tmp17_, _tmp17__length1, (GDestroyNotify) g_free), NULL);
}

static void
lights_off_real_activate (GApplication* base)
{
	LightsOff * self;
	LightsoffWindow* _tmp0_;
	LightsoffWindow* _tmp3_;
	self = (LightsOff*) base;
	_tmp0_ = self->priv->window;
	if (_tmp0_ == NULL) {
		LightsoffWindow* _tmp1_;
		LightsoffWindow* _tmp2_;
		_tmp1_ = lightsoff_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 inline void
lights_off_help_cb (LightsOff* self)
{
	LightsoffWindow* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->window;
	gtk_show_uri ((GtkWindow*) _tmp0_, "help:lightsoff", (guint32) GDK_CURRENT_TIME);
}

static void
lights_off_quit_cb (LightsOff* self)
{
	LightsoffWindow* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->window;
	gtk_window_destroy ((GtkWindow*) _tmp0_);
}

static void
lights_off_about_cb (LightsOff* self)
{
	gchar** authors = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar** _tmp3_;
	gint authors_length1;
	gint _authors_size_;
	gchar** artists = NULL;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar** _tmp6_;
	gint artists_length1;
	gint _artists_size_;
	gchar** documenters = NULL;
	gchar* _tmp7_;
	gchar** _tmp8_;
	gint documenters_length1;
	gint _documenters_size_;
	gchar* comments = NULL;
	gchar* _tmp9_;
	LightsoffWindow* _tmp10_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_strdup ("Tim Horton");
	_tmp1_ = g_strdup ("Robert Ancell");
	_tmp2_ = g_strdup ("Robert Roth");
	_tmp3_ = g_new0 (gchar*, 3 + 1);
	_tmp3_[0] = _tmp0_;
	_tmp3_[1] = _tmp1_;
	_tmp3_[2] = _tmp2_;
	authors = _tmp3_;
	authors_length1 = 3;
	_authors_size_ = authors_length1;
	_tmp4_ = g_strdup ("Tim Horton");
	_tmp5_ = g_strdup ("Ulisse Perusin");
	_tmp6_ = g_new0 (gchar*, 2 + 1);
	_tmp6_[0] = _tmp4_;
	_tmp6_[1] = _tmp5_;
	artists = _tmp6_;
	artists_length1 = 2;
	_artists_size_ = artists_length1;
	_tmp7_ = g_strdup ("Eric Baudais");
	_tmp8_ = g_new0 (gchar*, 1 + 1);
	_tmp8_[0] = _tmp7_;
	documenters = _tmp8_;
	documenters_length1 = 1;
	_documenters_size_ = documenters_length1;
	_tmp9_ = g_strdup (_ ("Turn off all the lights"));
	comments = _tmp9_;
	_tmp10_ = self->priv->window;
	adw_show_about_dialog ((GtkWidget*) _tmp10_, "application-name", LIGHTS_OFF_PROGRAM_NAME, "version", VERSION, "developer_name", _ ("The GNOME Project"), "comments", comments, "copyright", "Copyright © 2009 Tim Horton", "license-type", GTK_LICENSE_GPL_2_0, "developers", authors, "artists", artists, "documenters", documenters, "translator-credits", _ ("translator-credits"), "application-icon", "org.gnome.LightsOff", "website", "https://wiki.gnome.org/Apps/Lightsoff", NULL);
	_g_free0 (comments);
	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
lights_off_class_init (LightsOffClass * klass,
                       gpointer klass_data)
{
	gchar** _tmp0_;
	lights_off_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &LightsOff_private_offset);
	((GApplicationClass *) klass)->handle_local_options = (gint (*) (GApplication*, GVariantDict*)) lights_off_real_handle_local_options;
	((GApplicationClass *) klass)->startup = (void (*) (GApplication*)) lights_off_real_startup;
	((GApplicationClass *) klass)->activate = (void (*) (GApplication*)) lights_off_real_activate;
	G_OBJECT_CLASS (klass)->finalize = lights_off_finalize;
	_tmp0_ = g_new0 (gchar*, 1 + 1);
	lights_off_remaining = _tmp0_;
	lights_off_remaining_length1 = 1;
	_lights_off_remaining_size_ = lights_off_remaining_length1;
}

static void
lights_off_instance_init (LightsOff * self,
                          gpointer klass)
{
	self->priv = lights_off_get_instance_private (self);
}

static void
lights_off_finalize (GObject * obj)
{
	LightsOff * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_LIGHTS_OFF, LightsOff);
	_g_object_unref0 (self->priv->window);
	G_OBJECT_CLASS (lights_off_parent_class)->finalize (obj);
}

static GType
lights_off_get_type_once (void)
{
	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 (adw_application_get_type (), "LightsOff", &g_define_type_info, 0);
	LightsOff_private_offset = g_type_add_instance_private (lights_off_type_id, sizeof (LightsOffPrivate));
	return lights_off_type_id;
}

GType
lights_off_get_type (void)
{
	static volatile gsize lights_off_type_id__once = 0;
	if (g_once_init_enter (&lights_off_type_id__once)) {
		GType lights_off_type_id;
		lights_off_type_id = lights_off_get_type_once ();
		g_once_init_leave (&lights_off_type_id__once, lights_off_type_id);
	}
	return lights_off_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);
}

