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

/*
 * Copyright © 2023 Alain M. (https://github.com/alainm23/planify)
 *
 * 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 3 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
 *
 * Authored by: Alain M. <alainmh23@gmail.com>
 */

#include "planify.h"
#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <math.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  {
	SERVICES_SETTINGS_0_PROPERTY,
	SERVICES_SETTINGS_NUM_PROPERTIES
};
static GParamSpec* services_settings_properties[SERVICES_SETTINGS_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_settings_schema_unref0(var) ((var == NULL) ? NULL : (var = (g_settings_schema_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

static gpointer services_settings_parent_class = NULL;
static ServicesSettings* services_settings__instance;
static ServicesSettings* services_settings__instance = NULL;

static void services_settings_finalize (GObject * obj);
static GType services_settings_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 gssize _vala_array_length (gpointer array);

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

ServicesSettings*
services_settings_get_default (void)
{
	ServicesSettings* _tmp0_;
	ServicesSettings* _tmp2_;
	ServicesSettings* _tmp3_;
	ServicesSettings* result;
	_tmp0_ = services_settings__instance;
	if (_tmp0_ == NULL) {
		ServicesSettings* _tmp1_;
		_tmp1_ = services_settings_new ();
		_g_object_unref0 (services_settings__instance);
		services_settings__instance = _tmp1_;
	}
	_tmp2_ = services_settings__instance;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	result = _tmp3_;
	return result;
}

ServicesSettings*
services_settings_construct (GType object_type)
{
	ServicesSettings * self = NULL;
	GSettings* _tmp0_;
	GSettingsSchemaSource* _tmp1_;
	GSettingsSchema* _tmp2_;
	self = (ServicesSettings*) g_object_new (object_type, NULL);
	_tmp0_ = g_settings_new (SERVICES_SETTINGS_ID);
	_g_object_unref0 (self->settings);
	self->settings = _tmp0_;
	_tmp1_ = g_settings_schema_source_get_default ();
	_tmp2_ = g_settings_schema_source_lookup (_tmp1_, SERVICES_SETTINGS_ID, TRUE);
	_g_settings_schema_unref0 (self->settings_schema);
	self->settings_schema = _tmp2_;
	return self;
}

ServicesSettings*
services_settings_new (void)
{
	return services_settings_construct (SERVICES_TYPE_SETTINGS);
}

void
services_settings_reset_settings (ServicesSettings* self)
{
	GSettingsSchema* _tmp0_;
	gchar** _tmp1_;
	gchar** _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->settings_schema;
	_tmp2_ = _tmp1_ = g_settings_schema_list_keys (_tmp0_);
	{
		gchar** key_collection = NULL;
		gint key_collection_length1 = 0;
		gint _key_collection_size_ = 0;
		gint key_it = 0;
		key_collection = _tmp2_;
		key_collection_length1 = _vala_array_length (_tmp1_);
		for (key_it = 0; key_it < key_collection_length1; key_it = key_it + 1) {
			gchar* _tmp3_;
			gchar* key = NULL;
			_tmp3_ = g_strdup (key_collection[key_it]);
			key = _tmp3_;
			{
				ServicesSettings* _tmp4_;
				ServicesSettings* _tmp5_;
				GSettings* _tmp6_;
				const gchar* _tmp7_;
				_tmp4_ = services_settings_get_default ();
				_tmp5_ = _tmp4_;
				_tmp6_ = _tmp5_->settings;
				_tmp7_ = key;
				g_settings_reset (_tmp6_, _tmp7_);
				_g_object_unref0 (_tmp5_);
				_g_free0 (key);
			}
		}
		key_collection = (_vala_array_free (key_collection, key_collection_length1, (GDestroyNotify) g_free), NULL);
	}
}

gboolean
services_settings_has_key (ServicesSettings* self,
                           const gchar* key)
{
	GSettingsSchema* _tmp0_;
	gchar** _tmp1_;
	gchar** _tmp2_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (key != NULL, FALSE);
	_tmp0_ = self->settings_schema;
	_tmp2_ = _tmp1_ = g_settings_schema_list_keys (_tmp0_);
	{
		gchar** schema_key_collection = NULL;
		gint schema_key_collection_length1 = 0;
		gint _schema_key_collection_size_ = 0;
		gint schema_key_it = 0;
		schema_key_collection = _tmp2_;
		schema_key_collection_length1 = _vala_array_length (_tmp1_);
		for (schema_key_it = 0; schema_key_it < schema_key_collection_length1; schema_key_it = schema_key_it + 1) {
			gchar* _tmp3_;
			gchar* schema_key = NULL;
			_tmp3_ = g_strdup (schema_key_collection[schema_key_it]);
			schema_key = _tmp3_;
			{
				const gchar* _tmp4_;
				_tmp4_ = schema_key;
				if (g_strcmp0 (_tmp4_, key) == 0) {
					result = TRUE;
					_g_free0 (schema_key);
					schema_key_collection = (_vala_array_free (schema_key_collection, schema_key_collection_length1, (GDestroyNotify) g_free), NULL);
					return result;
				}
				_g_free0 (schema_key);
			}
		}
		schema_key_collection = (_vala_array_free (schema_key_collection, schema_key_collection_length1, (GDestroyNotify) g_free), NULL);
	}
	result = FALSE;
	return result;
}

NewTaskPosition
services_settings_get_new_task_position (ServicesSettings* self)
{
	gint value = 0;
	ServicesSettings* _tmp0_;
	ServicesSettings* _tmp1_;
	GSettings* _tmp2_;
	gint _tmp3_;
	NewTaskPosition _tmp4_ = 0;
	NewTaskPosition result;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = services_settings_get_default ();
	_tmp1_ = _tmp0_;
	_tmp2_ = _tmp1_->settings;
	_tmp3_ = g_settings_get_enum (_tmp2_, "new-tasks-position");
	_g_object_unref0 (_tmp1_);
	value = _tmp3_;
	if (value == 0) {
		_tmp4_ = NEW_TASK_POSITION_START;
	} else {
		_tmp4_ = NEW_TASK_POSITION_END;
	}
	result = _tmp4_;
	return result;
}

gboolean
services_settings_get_boolean (ServicesSettings* self,
                               const gchar* key)
{
	GSettings* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (key != NULL, FALSE);
	_tmp0_ = self->settings;
	result = g_settings_get_boolean (_tmp0_, key);
	return result;
}

gdouble
services_settings_get_double (ServicesSettings* self,
                              const gchar* key)
{
	GSettings* _tmp0_;
	gdouble result;
	g_return_val_if_fail (self != NULL, -1.0);
	g_return_val_if_fail (key != NULL, -1.0);
	_tmp0_ = self->settings;
	result = g_settings_get_double (_tmp0_, key);
	return result;
}

gchar*
services_settings_get_string (ServicesSettings* self,
                              const gchar* key)
{
	GSettings* _tmp0_;
	gchar* _tmp1_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (key != NULL, NULL);
	_tmp0_ = self->settings;
	_tmp1_ = g_settings_get_string (_tmp0_, key);
	result = _tmp1_;
	return result;
}

static void
services_settings_class_init (ServicesSettingsClass * klass,
                              gpointer klass_data)
{
	services_settings_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = services_settings_finalize;
}

static void
services_settings_instance_init (ServicesSettings * self,
                                 gpointer klass)
{
}

static void
services_settings_finalize (GObject * obj)
{
	ServicesSettings * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SERVICES_TYPE_SETTINGS, ServicesSettings);
	_g_object_unref0 (self->settings);
	_g_settings_schema_unref0 (self->settings_schema);
	G_OBJECT_CLASS (services_settings_parent_class)->finalize (obj);
}

static GType
services_settings_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ServicesSettingsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) services_settings_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ServicesSettings), 0, (GInstanceInitFunc) services_settings_instance_init, NULL };
	GType services_settings_type_id;
	services_settings_type_id = g_type_register_static (G_TYPE_OBJECT, "ServicesSettings", &g_define_type_info, 0);
	return services_settings_type_id;
}

GType
services_settings_get_type (void)
{
	static volatile gsize services_settings_type_id__once = 0;
	if (g_once_init_enter (&services_settings_type_id__once)) {
		GType services_settings_type_id;
		services_settings_type_id = services_settings_get_type_once ();
		g_once_init_leave (&services_settings_type_id__once, services_settings_type_id);
	}
	return services_settings_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);
}

static gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

