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

/*
* Copyright (c) 2017 Robert San <robertsanseries@gmail.com>
*
* 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.
*
* 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, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
*/

#include <granite.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <gio/gio.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>

#define CIANO_CONFIGS_CONSTANTS_ID "com.github.robertsanseries.ciano"
#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 CIANO_TYPE_APPLICATION (ciano_application_get_type ())
#define CIANO_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CIANO_TYPE_APPLICATION, CianoApplication))
#define CIANO_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CIANO_TYPE_APPLICATION, CianoApplicationClass))
#define CIANO_IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CIANO_TYPE_APPLICATION))
#define CIANO_IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CIANO_TYPE_APPLICATION))
#define CIANO_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CIANO_TYPE_APPLICATION, CianoApplicationClass))

typedef struct _CianoApplication CianoApplication;
typedef struct _CianoApplicationClass CianoApplicationClass;
typedef struct _CianoApplicationPrivate CianoApplicationPrivate;

#define CIANO_TYPE_WINDOW (ciano_window_get_type ())
#define CIANO_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CIANO_TYPE_WINDOW, CianoWindow))
#define CIANO_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CIANO_TYPE_WINDOW, CianoWindowClass))
#define CIANO_IS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CIANO_TYPE_WINDOW))
#define CIANO_IS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CIANO_TYPE_WINDOW))
#define CIANO_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CIANO_TYPE_WINDOW, CianoWindowClass))

typedef struct _CianoWindow CianoWindow;
typedef struct _CianoWindowClass CianoWindowClass;
enum  {
	CIANO_APPLICATION_0_PROPERTY,
	CIANO_APPLICATION_NUM_PROPERTIES
};
static GParamSpec* ciano_application_properties[CIANO_APPLICATION_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _CianoApplication {
	GraniteApplication parent_instance;
	CianoApplicationPrivate * priv;
};

struct _CianoApplicationClass {
	GraniteApplicationClass parent_class;
};

struct _CianoApplicationPrivate {
	CianoWindow* _window;
};

static gint CianoApplication_private_offset;
static gpointer ciano_application_parent_class = NULL;

VALA_EXTERN GType ciano_application_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (CianoApplication, g_object_unref)
VALA_EXTERN GType ciano_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (CianoWindow, g_object_unref)
VALA_EXTERN CianoApplication* ciano_application_new (void);
VALA_EXTERN CianoApplication* ciano_application_construct (GType object_type);
static void ciano_application_real_activate (GApplication* base);
static CianoWindow* ciano_application_get_window (CianoApplication* self);
VALA_EXTERN CianoWindow* ciano_window_new (GtkApplication* app);
VALA_EXTERN CianoWindow* ciano_window_construct (GType object_type,
                                     GtkApplication* app);
static void ciano_application_set_window (CianoApplication* self,
                                   CianoWindow* value);
static void __lambda24_ (CianoApplication* self);
static void ___lambda24__g_simple_action_activate (GSimpleAction* _sender,
                                            GVariant* parameter,
                                            gpointer self);
static void ciano_application_finalize (GObject * obj);
static GType ciano_application_get_type_once (void);
static void _vala_ciano_application_get_property (GObject * object,
                                           guint property_id,
                                           GValue * value,
                                           GParamSpec * pspec);
static void _vala_ciano_application_set_property (GObject * object,
                                           guint property_id,
                                           const GValue * value,
                                           GParamSpec * pspec);
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 inline gpointer
ciano_application_get_instance_private (CianoApplication* self)
{
	return G_STRUCT_MEMBER_P (self, CianoApplication_private_offset);
}

/**
         * Constructs a new {@code Application} object and create default output folder if it does not exist.
         *
         * @see Ciano.Configs.Constants
         */
CianoApplication*
ciano_application_construct (GType object_type)
{
	CianoApplication * self = NULL;
	self = (CianoApplication*) g_object_new (object_type, "application-id", CIANO_CONFIGS_CONSTANTS_ID, "flags", G_APPLICATION_FLAGS_NONE, NULL);
	return self;
}

CianoApplication*
ciano_application_new (void)
{
	return ciano_application_construct (CIANO_TYPE_APPLICATION);
}

/**
         * Create the window of this application through the class {@code Window} and show it. If user clicks
         * <quit> or press <control + q> the window will be destroyed.
         *
         * @return {@code void}
         */
static void
__lambda24_ (CianoApplication* self)
{
	CianoWindow* _tmp0_;
	_tmp0_ = self->priv->_window;
	if (_tmp0_ != NULL) {
		CianoWindow* _tmp1_;
		_tmp1_ = self->priv->_window;
		gtk_widget_destroy ((GtkWidget*) _tmp1_);
	}
}

static void
___lambda24__g_simple_action_activate (GSimpleAction* _sender,
                                       GVariant* parameter,
                                       gpointer self)
{
	__lambda24_ ((CianoApplication*) self);
}

static void
ciano_application_real_activate (GApplication* base)
{
	CianoApplication * self;
	CianoWindow* _tmp0_;
	CianoWindow* _tmp2_;
	CianoWindow* _tmp3_;
	CianoWindow* _tmp4_;
	CianoWindow* _tmp5_;
	GSimpleAction* quit_action = NULL;
	GSimpleAction* _tmp6_;
	GSimpleAction* _tmp7_;
	GSimpleAction* _tmp8_;
	gchar* _tmp9_;
	gchar** _tmp10_;
	gchar** _tmp11_;
	gint _tmp11__length1;
	self = (CianoApplication*) base;
	_tmp0_ = self->priv->_window;
	if (_tmp0_ != NULL) {
		CianoWindow* _tmp1_;
		_tmp1_ = self->priv->_window;
		gtk_window_present ((GtkWindow*) _tmp1_);
		return;
	}
	_tmp2_ = ciano_window_new ((GtkApplication*) self);
	g_object_ref_sink (_tmp2_);
	_tmp3_ = _tmp2_;
	ciano_application_set_window (self, _tmp3_);
	_g_object_unref0 (_tmp3_);
	_tmp4_ = self->priv->_window;
	gtk_application_add_window ((GtkApplication*) self, (GtkWindow*) _tmp4_);
	_tmp5_ = self->priv->_window;
	gtk_widget_show_all ((GtkWidget*) _tmp5_);
	_tmp6_ = g_simple_action_new ("quit", NULL);
	quit_action = _tmp6_;
	_tmp7_ = quit_action;
	g_signal_connect_object (_tmp7_, "activate", (GCallback) ___lambda24__g_simple_action_activate, self, 0);
	_tmp8_ = quit_action;
	g_action_map_add_action ((GActionMap*) self, (GAction*) _tmp8_);
	_tmp9_ = g_strdup ("<Ctrl>q");
	_tmp10_ = g_new0 (gchar*, 1 + 1);
	_tmp10_[0] = _tmp9_;
	_tmp11_ = _tmp10_;
	_tmp11__length1 = 1;
	gtk_application_set_accels_for_action ((GtkApplication*) self, "app.quit", _tmp11_);
	_tmp11_ = (_vala_array_free (_tmp11_, _tmp11__length1, (GDestroyNotify) g_free), NULL);
	_g_object_unref0 (quit_action);
}

static CianoWindow*
ciano_application_get_window (CianoApplication* self)
{
	CianoWindow* result;
	CianoWindow* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_window;
	result = _tmp0_;
	return result;
}

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

static void
ciano_application_set_window (CianoApplication* self,
                              CianoWindow* value)
{
	CianoWindow* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _g_object_ref0 (value);
	_g_object_unref0 (self->priv->_window);
	self->priv->_window = _tmp0_;
}

static void
ciano_application_class_init (CianoApplicationClass * klass,
                              gpointer klass_data)
{
	ciano_application_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &CianoApplication_private_offset);
	((GApplicationClass *) klass)->activate = (void (*) (GApplication*)) ciano_application_real_activate;
	G_OBJECT_CLASS (klass)->get_property = _vala_ciano_application_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_ciano_application_set_property;
	G_OBJECT_CLASS (klass)->finalize = ciano_application_finalize;
}

static void
ciano_application_instance_init (CianoApplication * self,
                                 gpointer klass)
{
	self->priv = ciano_application_get_instance_private (self);
	self->priv->_window = NULL;
}

static void
ciano_application_finalize (GObject * obj)
{
	CianoApplication * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CIANO_TYPE_APPLICATION, CianoApplication);
	_g_object_unref0 (self->priv->_window);
	G_OBJECT_CLASS (ciano_application_parent_class)->finalize (obj);
}

/**
     * The {@code Application} class is a foundation for all granite-based applications.
     *
     * @see Granite.Application
     * @since 0.1.0
     */
static GType
ciano_application_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (CianoApplicationClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ciano_application_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (CianoApplication), 0, (GInstanceInitFunc) ciano_application_instance_init, NULL };
	GType ciano_application_type_id;
	ciano_application_type_id = g_type_register_static (GRANITE_TYPE_APPLICATION, "CianoApplication", &g_define_type_info, 0);
	CianoApplication_private_offset = g_type_add_instance_private (ciano_application_type_id, sizeof (CianoApplicationPrivate));
	return ciano_application_type_id;
}

GType
ciano_application_get_type (void)
{
	static volatile gsize ciano_application_type_id__once = 0;
	if (g_once_init_enter (&ciano_application_type_id__once)) {
		GType ciano_application_type_id;
		ciano_application_type_id = ciano_application_get_type_once ();
		g_once_init_leave (&ciano_application_type_id__once, ciano_application_type_id);
	}
	return ciano_application_type_id__once;
}

static void
_vala_ciano_application_get_property (GObject * object,
                                      guint property_id,
                                      GValue * value,
                                      GParamSpec * pspec)
{
	CianoApplication * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, CIANO_TYPE_APPLICATION, CianoApplication);
	switch (property_id) {
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_ciano_application_set_property (GObject * object,
                                      guint property_id,
                                      const GValue * value,
                                      GParamSpec * pspec)
{
	CianoApplication * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, CIANO_TYPE_APPLICATION, CianoApplication);
	switch (property_id) {
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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

