/* Window.c generated by valac 0.56.19, the Vala compiler
 * generated from Window.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 <gtk/gtk.h>
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <granite.h>
#include <gdk/gdk.h>

#define CIANO_CONFIGS_CONSTANTS_APP_ICON "com.github.robertsanseries.ciano"
#define CIANO_CONFIGS_CONSTANTS_URL_CSS "com/github/robertsanseries/ciano/css/style.css"
#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_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;
typedef struct _CianoWindowPrivate CianoWindowPrivate;
enum  {
	CIANO_WINDOW_0_PROPERTY,
	CIANO_WINDOW_NUM_PROPERTIES
};
static GParamSpec* ciano_window_properties[CIANO_WINDOW_NUM_PROPERTIES];

#define CIANO_SERVICES_TYPE_SETTINGS (ciano_services_settings_get_type ())
#define CIANO_SERVICES_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CIANO_SERVICES_TYPE_SETTINGS, CianoServicesSettings))
#define CIANO_SERVICES_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CIANO_SERVICES_TYPE_SETTINGS, CianoServicesSettingsClass))
#define CIANO_SERVICES_IS_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CIANO_SERVICES_TYPE_SETTINGS))
#define CIANO_SERVICES_IS_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CIANO_SERVICES_TYPE_SETTINGS))
#define CIANO_SERVICES_SETTINGS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CIANO_SERVICES_TYPE_SETTINGS, CianoServicesSettingsClass))

typedef struct _CianoServicesSettings CianoServicesSettings;
typedef struct _CianoServicesSettingsClass CianoServicesSettingsClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define CIANO_VIEWS_TYPE_CONVERTER_VIEW (ciano_views_converter_view_get_type ())
#define CIANO_VIEWS_CONVERTER_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CIANO_VIEWS_TYPE_CONVERTER_VIEW, CianoViewsConverterView))
#define CIANO_VIEWS_CONVERTER_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CIANO_VIEWS_TYPE_CONVERTER_VIEW, CianoViewsConverterViewClass))
#define CIANO_VIEWS_IS_CONVERTER_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CIANO_VIEWS_TYPE_CONVERTER_VIEW))
#define CIANO_VIEWS_IS_CONVERTER_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CIANO_VIEWS_TYPE_CONVERTER_VIEW))
#define CIANO_VIEWS_CONVERTER_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CIANO_VIEWS_TYPE_CONVERTER_VIEW, CianoViewsConverterViewClass))

typedef struct _CianoViewsConverterView CianoViewsConverterView;
typedef struct _CianoViewsConverterViewClass CianoViewsConverterViewClass;

#define CIANO_CONTROLLERS_TYPE_CONVERTER_CONTROLLER (ciano_controllers_converter_controller_get_type ())
#define CIANO_CONTROLLERS_CONVERTER_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CIANO_CONTROLLERS_TYPE_CONVERTER_CONTROLLER, CianoControllersConverterController))
#define CIANO_CONTROLLERS_CONVERTER_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CIANO_CONTROLLERS_TYPE_CONVERTER_CONTROLLER, CianoControllersConverterControllerClass))
#define CIANO_CONTROLLERS_IS_CONVERTER_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CIANO_CONTROLLERS_TYPE_CONVERTER_CONTROLLER))
#define CIANO_CONTROLLERS_IS_CONVERTER_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CIANO_CONTROLLERS_TYPE_CONVERTER_CONTROLLER))
#define CIANO_CONTROLLERS_CONVERTER_CONTROLLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CIANO_CONTROLLERS_TYPE_CONVERTER_CONTROLLER, CianoControllersConverterControllerClass))

typedef struct _CianoControllersConverterController CianoControllersConverterController;
typedef struct _CianoControllersConverterControllerClass CianoControllersConverterControllerClass;
#define _ciano_controllers_converter_controller_unref0(var) ((var == NULL) ? NULL : (var = (ciano_controllers_converter_controller_unref (var), NULL)))

struct _CianoWindow {
	GtkApplicationWindow parent_instance;
	CianoWindowPrivate * priv;
};

struct _CianoWindowClass {
	GtkApplicationWindowClass parent_class;
};

static gpointer ciano_window_parent_class = NULL;

VALA_EXTERN GType ciano_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (CianoWindow, g_object_unref)
VALA_EXTERN CianoWindow* ciano_window_new (GtkApplication* app);
VALA_EXTERN CianoWindow* ciano_window_construct (GType object_type,
                                     GtkApplication* app);
VALA_EXTERN GType ciano_services_settings_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (CianoServicesSettings, g_object_unref)
VALA_EXTERN CianoServicesSettings* ciano_services_settings_get_instance (void);
VALA_EXTERN gint ciano_services_settings_get_window_x (CianoServicesSettings* self);
VALA_EXTERN gint ciano_services_settings_get_window_y (CianoServicesSettings* self);
static void ciano_window_style_provider (CianoWindow* self);
static void ciano_window_build (CianoWindow* self,
                         GtkApplication* app);
VALA_EXTERN GType ciano_views_converter_view_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (CianoViewsConverterView, g_object_unref)
VALA_EXTERN CianoViewsConverterView* ciano_views_converter_view_new (GtkApplicationWindow* app);
VALA_EXTERN CianoViewsConverterView* ciano_views_converter_view_construct (GType object_type,
                                                               GtkApplicationWindow* app);
VALA_EXTERN CianoControllersConverterController* ciano_controllers_converter_controller_new (GtkApplicationWindow* window,
                                                                                 GtkApplication* application,
                                                                                 CianoViewsConverterView* converter_view);
VALA_EXTERN CianoControllersConverterController* ciano_controllers_converter_controller_construct (GType object_type,
                                                                                       GtkApplicationWindow* window,
                                                                                       GtkApplication* application,
                                                                                       CianoViewsConverterView* converter_view);
VALA_EXTERN gpointer ciano_controllers_converter_controller_ref (gpointer instance);
VALA_EXTERN void ciano_controllers_converter_controller_unref (gpointer instance);
VALA_EXTERN GParamSpec* ciano_controllers_param_spec_converter_controller (const gchar* name,
                                                               const gchar* nick,
                                                               const gchar* blurb,
                                                               GType object_type,
                                                               GParamFlags flags);
VALA_EXTERN void ciano_controllers_value_set_converter_controller (GValue* value,
                                                       gpointer v_object);
VALA_EXTERN void ciano_controllers_value_take_converter_controller (GValue* value,
                                                        gpointer v_object);
VALA_EXTERN gpointer ciano_controllers_value_get_converter_controller (const GValue* value);
VALA_EXTERN GType ciano_controllers_converter_controller_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (CianoControllersConverterController, ciano_controllers_converter_controller_unref)
static GType ciano_window_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

/**
         * Constructs a new {@code Window} object.
         *
         * @see Ciano.Configs.Constants
         * @see style_provider
         * @see build
         */
static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

CianoWindow*
ciano_window_construct (GType object_type,
                        GtkApplication* app)
{
	CianoWindow * self = NULL;
	CianoServicesSettings* settings = NULL;
	CianoServicesSettings* _tmp0_;
	CianoServicesSettings* _tmp1_;
	gint x = 0;
	CianoServicesSettings* _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	gint y = 0;
	CianoServicesSettings* _tmp5_;
	gint _tmp6_;
	gint _tmp7_;
	gboolean _tmp8_ = FALSE;
	g_return_val_if_fail (app != NULL, NULL);
	self = (CianoWindow*) g_object_new (object_type, "application", app, "icon-name", CIANO_CONFIGS_CONSTANTS_APP_ICON, "deletable", TRUE, "resizable", TRUE, NULL);
	_tmp0_ = ciano_services_settings_get_instance ();
	_tmp1_ = _g_object_ref0 (_tmp0_);
	settings = _tmp1_;
	_tmp2_ = settings;
	_tmp3_ = ciano_services_settings_get_window_x (_tmp2_);
	_tmp4_ = _tmp3_;
	x = _tmp4_;
	_tmp5_ = settings;
	_tmp6_ = ciano_services_settings_get_window_y (_tmp5_);
	_tmp7_ = _tmp6_;
	y = _tmp7_;
	if (x != -1) {
		_tmp8_ = y != -1;
	} else {
		_tmp8_ = FALSE;
	}
	if (_tmp8_) {
		gtk_window_move ((GtkWindow*) self, x, y);
	}
	ciano_window_style_provider (self);
	ciano_window_build (self, app);
	_g_object_unref0 (settings);
	return self;
}

CianoWindow*
ciano_window_new (GtkApplication* app)
{
	return ciano_window_construct (CIANO_TYPE_WINDOW, app);
}

/**
         * Load the application's CSS.
         *
         * @see Ciano.Configs.Constants
         * @return {@code void}
         */
static void
ciano_window_style_provider (CianoWindow* self)
{
	GtkCssProvider* css_provider = NULL;
	GtkCssProvider* _tmp0_;
	GdkScreen* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = gtk_css_provider_new ();
	css_provider = _tmp0_;
	gtk_css_provider_load_from_resource (css_provider, CIANO_CONFIGS_CONSTANTS_URL_CSS);
	_tmp1_ = gdk_screen_get_default ();
	gtk_style_context_add_provider_for_screen (_tmp1_, (GtkStyleProvider*) css_provider, (guint) GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
	_g_object_unref0 (css_provider);
}

/**
         * Load classes for application building.
         *
         * @see Ciano.Controllers.ConverterController
         * @see Ciano.Views.ConverterView
         * @return {@code void}
         */
static void
ciano_window_build (CianoWindow* self,
                    GtkApplication* app)
{
	CianoViewsConverterView* converter_view = NULL;
	CianoViewsConverterView* _tmp0_;
	CianoControllersConverterController* _tmp1_;
	CianoControllersConverterController* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (app != NULL);
	_tmp0_ = ciano_views_converter_view_new ((GtkApplicationWindow*) self);
	g_object_ref_sink (_tmp0_);
	converter_view = _tmp0_;
	_tmp1_ = ciano_controllers_converter_controller_new ((GtkApplicationWindow*) self, app, converter_view);
	_tmp2_ = _tmp1_;
	_ciano_controllers_converter_controller_unref0 (_tmp2_);
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) converter_view);
	gtk_widget_show_all ((GtkWidget*) self);
	_g_object_unref0 (converter_view);
}

static void
ciano_window_class_init (CianoWindowClass * klass,
                         gpointer klass_data)
{
	ciano_window_parent_class = g_type_class_peek_parent (klass);
}

static void
ciano_window_instance_init (CianoWindow * self,
                            gpointer klass)
{
}

/**
     * Class responsible for creating the u window and will contain contain other widgets. 
     * allowing the user to manipulate the window (resize it, move it, close it, ...).
     *
     * @see Gtk.ApplicationWindow
     * @since 0.1.0
     */
static GType
ciano_window_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (CianoWindowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ciano_window_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (CianoWindow), 0, (GInstanceInitFunc) ciano_window_instance_init, NULL };
	GType ciano_window_type_id;
	ciano_window_type_id = g_type_register_static (gtk_application_window_get_type (), "CianoWindow", &g_define_type_info, 0);
	return ciano_window_type_id;
}

GType
ciano_window_get_type (void)
{
	static volatile gsize ciano_window_type_id__once = 0;
	if (g_once_init_enter (&ciano_window_type_id__once)) {
		GType ciano_window_type_id;
		ciano_window_type_id = ciano_window_get_type_once ();
		g_once_init_leave (&ciano_window_type_id__once, ciano_window_type_id);
	}
	return ciano_window_type_id__once;
}

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

