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

/*
 * Copyright 2019–2020 elementary, Inc. (https://elementary.io)
 * Copyright 2011–2013 Maxwell Barvian <maxwell@elementaryos.org>
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */

#include "granite.h"
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <glib-object.h>
#include <sys/prctl.h>
#include <sys/utsname.h>
#include <glib/gi18n-lib.h>
#include <gio/gio.h>

#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

enum  {
	GRANITE_APPLICATION_0_PROPERTY,
	GRANITE_APPLICATION_NUM_PROPERTIES
};
static GParamSpec* granite_application_properties[GRANITE_APPLICATION_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_option_group_unref0(var) ((var == NULL) ? NULL : (var = (g_option_group_unref (var), NULL)))

static gpointer granite_application_parent_class = NULL;
gboolean granite_application_DEBUG = FALSE;

static gint granite_application_on_handle_local_options (GraniteApplication* self,
                                                  GVariantDict* options);
static gint _granite_application_on_handle_local_options_g_application_handle_local_options (GApplication* _sender,
                                                                                      GVariantDict* options,
                                                                                      gpointer self);
static void granite_application_real_set_options (GraniteApplication* self);
static void granite_application_finalize (GObject * obj);
static GType granite_application_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);

const GOptionEntry GRANITE_APPLICATION_options[2] = {{"debug", 'd', (gint) 0, G_OPTION_ARG_NONE, &granite_application_DEBUG, "Enable debug logging", NULL}, {NULL}};

/**
         * This creates a new Application class
         */
static gint
_granite_application_on_handle_local_options_g_application_handle_local_options (GApplication* _sender,
                                                                                 GVariantDict* options,
                                                                                 gpointer self)
{
	gint result;
	result = granite_application_on_handle_local_options ((GraniteApplication*) self, options);
	return result;
}

GraniteApplication*
granite_application_construct (GType object_type)
{
	GraniteApplication * self = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	struct utsname un = {0};
	struct utsname _tmp4_;
	const gchar* _tmp5_;
	const gchar* _tmp6_;
	const gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	self = (GraniteApplication*) g_object_new (object_type, NULL);
	_tmp0_ = self->exec_name;
	prctl (15, _tmp0_, (gulong) 0, (gulong) 0, (gulong) 0);
	_tmp1_ = self->program_name;
	granite_services_logger_initialize (_tmp1_);
	granite_services_logger_set_DisplayLevel (GRANITE_SERVICES_LOG_LEVEL_INFO);
	_tmp2_ = self->program_name;
	_tmp3_ = self->build_version;
	g_message ("Application.vala:142: %s version: %s", _tmp2_, _tmp3_);
	uname (&un);
	_tmp4_ = un;
	_tmp5_ = _tmp4_.release;
	g_message ("Application.vala:145: Kernel version: %s", (const gchar*) _tmp5_);
	granite_services_logger_set_DisplayLevel (GRANITE_SERVICES_LOG_LEVEL_WARN);
	_tmp6_ = self->exec_name;
	_tmp7_ = self->build_data_dir;
	_tmp8_ = g_strconcat (_tmp7_, "/locale", NULL);
	_tmp9_ = _tmp8_;
	bindtextdomain (_tmp6_, _tmp9_);
	_g_free0 (_tmp9_);
	g_signal_connect_object ((GApplication*) self, "handle-local-options", (GCallback) _granite_application_on_handle_local_options_g_application_handle_local_options, self, 0);
	return self;
}

/**
         * This method runs the application
         *
         * @param args array of arguments
         */
gint
granite_application_run (GraniteApplication* self,
                         gchar** args,
                         gint args_length1)
{
	GOptionGroup* option_group = NULL;
	GOptionGroup* _tmp0_;
	GOptionGroup* _tmp1_;
	GOptionGroup* _tmp2_;
	gint result;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = g_option_group_new ("granite", "Granite Options", _ ("Show Granite Options"), NULL, NULL);
	option_group = _tmp0_;
	_tmp1_ = option_group;
	g_option_group_add_entries (_tmp1_, GRANITE_APPLICATION_options);
	_tmp2_ = option_group;
	option_group = NULL;
	g_application_add_option_group ((GApplication*) self, _tmp2_);
	result = g_application_run ((GApplication*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_application_get_type (), GtkApplication), (gint) args_length1, args);
	_g_option_group_unref0 (option_group);
	return result;
}

static gint
granite_application_on_handle_local_options (GraniteApplication* self,
                                             GVariantDict* options)
{
	gint result;
	g_return_val_if_fail (self != NULL, 0);
	g_return_val_if_fail (options != NULL, 0);
	granite_application_set_options (self);
	result = -1;
	return result;
}

static void
granite_application_real_set_options (GraniteApplication* self)
{
	if (granite_application_DEBUG) {
		granite_services_logger_set_DisplayLevel (GRANITE_SERVICES_LOG_LEVEL_DEBUG);
	}
}

void
granite_application_set_options (GraniteApplication* self)
{
	GraniteApplicationClass* _klass_;
	g_return_if_fail (self != NULL);
	_klass_ = GRANITE_APPLICATION_GET_CLASS (self);
	if (_klass_->set_options) {
		_klass_->set_options (self);
	}
}

static void
granite_application_class_init (GraniteApplicationClass * klass,
                                gpointer klass_data)
{
	granite_application_parent_class = g_type_class_peek_parent (klass);
	((GraniteApplicationClass *) klass)->set_options = (void (*) (GraniteApplication*)) granite_application_real_set_options;
	G_OBJECT_CLASS (klass)->finalize = granite_application_finalize;
}

static void
granite_application_instance_init (GraniteApplication * self,
                                   gpointer klass)
{
	gchar** _tmp0_;
	gchar** _tmp1_;
	gchar** _tmp2_;
	_tmp0_ = g_new0 (gchar*, 0 + 1);
	self->about_authors = _tmp0_;
	self->about_authors_length1 = 0;
	_tmp1_ = g_new0 (gchar*, 0 + 1);
	self->about_documenters = _tmp1_;
	self->about_documenters_length1 = 0;
	_tmp2_ = g_new0 (gchar*, 0 + 1);
	self->about_artists = _tmp2_;
	self->about_artists_length1 = 0;
}

static void
granite_application_finalize (GObject * obj)
{
	GraniteApplication * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GRANITE_TYPE_APPLICATION, GraniteApplication);
	_g_free0 (self->build_data_dir);
	_g_free0 (self->build_pkg_data_dir);
	_g_free0 (self->build_release_name);
	_g_free0 (self->build_version);
	_g_free0 (self->build_version_info);
	_g_free0 (self->program_name);
	_g_free0 (self->exec_name);
	_g_free0 (self->app_copyright);
	_g_free0 (self->app_years);
	_g_free0 (self->app_icon);
	_g_free0 (self->app_launcher);
	_g_free0 (self->main_url);
	_g_free0 (self->bug_url);
	_g_free0 (self->help_url);
	_g_free0 (self->translate_url);
	self->about_authors = (_vala_array_free (self->about_authors, self->about_authors_length1, (GDestroyNotify) g_free), NULL);
	self->about_documenters = (_vala_array_free (self->about_documenters, self->about_documenters_length1, (GDestroyNotify) g_free), NULL);
	self->about_artists = (_vala_array_free (self->about_artists, self->about_artists_length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (self->about_comments);
	_g_free0 (self->about_translators);
	_g_free0 (self->about_license);
	G_OBJECT_CLASS (granite_application_parent_class)->finalize (obj);
}

/**
     * This is the base class for all Granite-based apps. It has methods that help
     * to create a great deal of an app's functionality.
     */
static GType
granite_application_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GraniteApplicationClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) granite_application_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GraniteApplication), 0, (GInstanceInitFunc) granite_application_instance_init, NULL };
	GType granite_application_type_id;
	granite_application_type_id = g_type_register_static (gtk_application_get_type (), "GraniteApplication", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
	return granite_application_type_id;
}

GType
granite_application_get_type (void)
{
	static volatile gsize granite_application_type_id__once = 0;
	if (g_once_init_enter (&granite_application_type_id__once)) {
		GType granite_application_type_id;
		granite_application_type_id = granite_application_get_type_once ();
		g_once_init_leave (&granite_application_type_id__once, granite_application_type_id);
	}
	return granite_application_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);
}

