/* lightsoff.c generated by valac 0.36.4, 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 <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>
#include <locale.h>
#include <clutter-gtk/clutter-gtk.h>
#include <clutter/clutter.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_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;
#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 _LightsOff {
	GtkApplication parent_instance;
	LightsOffPrivate * priv;
};

struct _LightsOffClass {
	GtkApplicationClass parent_class;
};

struct _LightsOffPrivate {
	LightsoffWindow* window;
};


static gpointer lights_off_parent_class = NULL;

GType lights_off_get_type (void) G_GNUC_CONST;
GType lightsoff_window_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 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_help_cb (LightsOff* self);
static void _lights_off_help_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 LightsOff* lights_off_new (void);
static LightsOff* lights_off_construct (GType object_type);
static void lights_off_real_startup (GApplication* base);
LightsoffWindow* lightsoff_window_new (void);
LightsoffWindow* lightsoff_window_construct (GType object_type);
static void lights_off_real_activate (GApplication* base);
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 const GActionEntry LIGHTS_OFF_action_entries[3] = {{"quit", _lights_off_quit_cb_gsimple_action_activate_callback}, {"help", _lights_off_help_cb_gsimple_action_activate_callback}, {"about", _lights_off_about_cb_gsimple_action_activate_callback}};

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_help_cb_gsimple_action_activate_callback (GSimpleAction* action, GVariant* parameter, gpointer self) {
	lights_off_help_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 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_FLAGS_NONE, NULL);
	return self;
}


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


static void lights_off_real_startup (GApplication* base) {
	LightsOff * self;
	GtkSettings* _tmp0_;
	LightsoffWindow* _tmp1_;
	LightsoffWindow* _tmp2_;
	self = (LightsOff*) base;
	G_APPLICATION_CLASS (lights_off_parent_class)->startup ((GApplication*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_application_get_type (), GtkApplication));
	gtk_window_set_default_icon_name ("lightsoff");
	_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, LIGHTS_OFF_action_entries, G_N_ELEMENTS (LIGHTS_OFF_action_entries), self);
	_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_);
}


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


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


static void lights_off_help_cb (LightsOff* self) {
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	{
		LightsoffWindow* _tmp0_;
		GdkScreen* _tmp1_;
		guint32 _tmp2_;
		_tmp0_ = self->priv->window;
		_tmp1_ = gtk_window_get_screen ((GtkWindow*) _tmp0_);
		_tmp2_ = gtk_get_current_event_time ();
		gtk_show_uri (_tmp1_, "help:lightsoff", _tmp2_, &_inner_error_);
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_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:60: Failed to show help: %s", _tmp4_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_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;
	}
}


static void lights_off_about_cb (LightsOff* 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_;
	gint artists_length1;
	gint _artists_size_;
	gchar** documenters = NULL;
	gchar* _tmp6_;
	gchar** _tmp7_;
	gint documenters_length1;
	gint _documenters_size_;
	LightsoffWindow* _tmp8_;
	g_return_if_fail (self != 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;
	gtk_show_about_dialog ((GtkWindow*) _tmp8_, "program-name", _ ("Lights Off"), "version", VERSION, "comments", _ ("Turn off all the lights"), "copyright", "Copyright © 2009 Tim Horton", "license-type", GTK_LICENSE_GPL_2_0, "authors", authors, "artists", artists, "documenters", documenters, "translator-credits", _ ("translator-credits"), "logo-icon-name", "lightsoff", "website", "https://wiki.gnome.org/Apps/Lightsoff", NULL, 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);
}


gint lights_off_main (gchar** args, int args_length1) {
	gint result = 0;
	ClutterInitError _tmp0_;
	LightsOff* app = NULL;
	LightsOff* _tmp1_;
	LightsOff* _tmp2_;
	gint _tmp3_;
	setlocale (LC_ALL, "");
	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
	g_set_application_name (_ ("Lights Off"));
	_tmp0_ = gtk_clutter_init (&args_length1, &args);
	if (_tmp0_ != CLUTTER_INIT_SUCCESS) {
		g_warning ("lightsoff.vala:113: Failed to initialise Clutter");
		result = EXIT_FAILURE;
		return result;
	}
	_tmp1_ = lights_off_new ();
	app = _tmp1_;
	_tmp2_ = app;
	_tmp3_ = g_application_run ((GApplication*) _tmp2_, 0, NULL);
	result = _tmp3_;
	_g_object_unref0 (app);
	return result;
}


int main (int argc, char ** argv) {
#if !GLIB_CHECK_VERSION (2,35,0)
	g_type_init ();
#endif
	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));
	((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;
}


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


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_application_get_type (), "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);
}



