/* System.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from System.vala, do not modify */

/*
 * Copyright 2011-2013 Robert Dyer
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */

#include "granite-7.h"
#include <gio/gio.h>
#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.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_SERVICES_SYSTEM_0_PROPERTY,
	GRANITE_SERVICES_SYSTEM_NUM_PROPERTIES
};
static GParamSpec* granite_services_system_properties[GRANITE_SERVICES_SYSTEM_NUM_PROPERTIES];

#define GRANITE_PORTAL_TYPE_SETTINGS (granite_portal_settings_get_type ())
#define GRANITE_PORTAL_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GRANITE_PORTAL_TYPE_SETTINGS, GranitePortalSettings))
#define GRANITE_PORTAL_IS_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GRANITE_PORTAL_TYPE_SETTINGS))
#define GRANITE_PORTAL_SETTINGS_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GRANITE_PORTAL_TYPE_SETTINGS, GranitePortalSettingsIface))

typedef struct _GranitePortalSettings GranitePortalSettings;
typedef struct _GranitePortalSettingsIface GranitePortalSettingsIface;

#define GRANITE_PORTAL_TYPE_SETTINGS_PROXY (granite_portal_settings_proxy_get_type ())
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_settings_schema_unref0(var) ((var == NULL) ? NULL : (var = (g_settings_schema_unref (var), NULL)))

struct _GranitePortalSettingsIface {
	GTypeInterface parent_iface;
	GHashTable* (*read_all) (GranitePortalSettings* self, gchar** namespaces, gint namespaces_length1, GError** error);
	GVariant* (*read) (GranitePortalSettings* self, const gchar* namespace, const gchar* key, GError** error);
};

static gpointer granite_services_system_parent_class = NULL;
static GSettingsSchema* granite_services_system_privacy_settings_schema;
static GSettingsSchema* granite_services_system_privacy_settings_schema = NULL;
static GSettings* granite_services_system_privacy_settings;
static GSettings* granite_services_system_privacy_settings = NULL;
static GranitePortalSettings* granite_services_system_portal;
static GranitePortalSettings* granite_services_system_portal = NULL;

VALA_EXTERN GType granite_portal_settings_proxy_get_type (void) G_GNUC_CONST ;
 G_GNUC_INTERNAL guint granite_portal_settings_register_object (void* object,
                                               GDBusConnection* connection,
                                               const gchar* path,
                                               GError** error);
 G_GNUC_INTERNAL GType granite_portal_settings_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
 G_GNUC_INTERNAL GranitePortalSettings* granite_portal_settings_get (GError** error);
 G_GNUC_INTERNAL GHashTable* granite_portal_settings_read_all (GranitePortalSettings* self,
                                              gchar** namespaces,
                                              gint namespaces_length1,
                                              GError** error);
static void granite_services_system_finalize (GObject * obj);
static GType granite_services_system_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);

/**
         * Returns whether history is enabled within the Security and Privacy system settings or not. A value of true
         * means that you should store information such as the last opened file or a history within the app.
         *
         * Checks the "remember_recent_files" key in "org.gnome.desktop.privacy", returning true if the schema does not exist.
         */
gboolean
granite_services_system_history_is_enabled (void)
{
	GSettingsSchema* _tmp22_;
	gboolean _tmp25_ = FALSE;
	GSettingsSchema* _tmp26_;
	GError* _inner_error0_ = NULL;
	gboolean result;
	{
		GranitePortalSettings* _tmp0_;
		GHashTable* schemes = NULL;
		GranitePortalSettings* _tmp4_;
		gchar* _tmp5_;
		gchar** _tmp6_;
		gchar** _tmp7_;
		gint _tmp7__length1;
		GHashTable* _tmp8_;
		GHashTable* _tmp9_;
		gboolean _tmp10_ = FALSE;
		GHashTable* _tmp11_;
		guint _tmp12_;
		guint _tmp13_;
		_tmp0_ = granite_services_system_portal;
		if (_tmp0_ == NULL) {
			GranitePortalSettings* _tmp1_ = NULL;
			GranitePortalSettings* _tmp2_;
			GranitePortalSettings* _tmp3_;
			_tmp2_ = granite_portal_settings_get (&_inner_error0_);
			_tmp1_ = _tmp2_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			_tmp3_ = _tmp1_;
			_tmp1_ = NULL;
			_g_object_unref0 (granite_services_system_portal);
			granite_services_system_portal = _tmp3_;
			_g_object_unref0 (_tmp1_);
		}
		_tmp4_ = granite_services_system_portal;
		_tmp5_ = g_strdup ("org.gnome.desktop.privacy");
		_tmp6_ = g_new0 (gchar*, 1 + 1);
		_tmp6_[0] = _tmp5_;
		_tmp7_ = _tmp6_;
		_tmp7__length1 = 1;
		_tmp8_ = granite_portal_settings_read_all (_tmp4_, _tmp7_, (gint) 1, &_inner_error0_);
		_tmp9_ = _tmp8_;
		_tmp7_ = (_vala_array_free (_tmp7_, _tmp7__length1, (GDestroyNotify) g_free), NULL);
		schemes = _tmp9_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp11_ = schemes;
		_tmp12_ = g_hash_table_size (_tmp11_);
		_tmp13_ = _tmp12_;
		if (_tmp13_ > ((guint) 0)) {
			GHashTable* _tmp14_;
			gconstpointer _tmp15_;
			_tmp14_ = schemes;
			_tmp15_ = g_hash_table_lookup (_tmp14_, "org.gnome.desktop.privacy");
			_tmp10_ = g_hash_table_contains ((GHashTable*) _tmp15_, "remember-recent-files");
		} else {
			_tmp10_ = FALSE;
		}
		if (_tmp10_) {
			GHashTable* _tmp16_;
			gconstpointer _tmp17_;
			gconstpointer _tmp18_;
			_tmp16_ = schemes;
			_tmp17_ = g_hash_table_lookup (_tmp16_, "org.gnome.desktop.privacy");
			_tmp18_ = g_hash_table_lookup ((GHashTable*) _tmp17_, "remember-recent-files");
			result = g_variant_get_boolean ((GVariant*) _tmp18_);
			_g_hash_table_unref0 (schemes);
			return result;
		}
		_g_hash_table_unref0 (schemes);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp19_;
		const gchar* _tmp20_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp19_ = e;
		_tmp20_ = _tmp19_->message;
		g_debug ("System.vala:33: cannot use portal, using GSettings: %s", _tmp20_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp21_ = FALSE;
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return _tmp21_;
	}
	_tmp22_ = granite_services_system_privacy_settings_schema;
	if (_tmp22_ == NULL) {
		GSettingsSchemaSource* _tmp23_;
		GSettingsSchema* _tmp24_;
		_tmp23_ = g_settings_schema_source_get_default ();
		_tmp24_ = g_settings_schema_source_lookup (_tmp23_, "org.gnome.desktop.privacy", TRUE);
		_g_settings_schema_unref0 (granite_services_system_privacy_settings_schema);
		granite_services_system_privacy_settings_schema = _tmp24_;
	}
	_tmp26_ = granite_services_system_privacy_settings_schema;
	if (_tmp26_ != NULL) {
		GSettingsSchema* _tmp27_;
		_tmp27_ = granite_services_system_privacy_settings_schema;
		_tmp25_ = g_settings_schema_has_key (_tmp27_, "remember-recent-files");
	} else {
		_tmp25_ = FALSE;
	}
	if (_tmp25_) {
		GSettings* _tmp28_;
		GSettings* _tmp30_;
		_tmp28_ = granite_services_system_privacy_settings;
		if (_tmp28_ == NULL) {
			GSettings* _tmp29_;
			_tmp29_ = g_settings_new ("org.gnome.desktop.privacy");
			_g_object_unref0 (granite_services_system_privacy_settings);
			granite_services_system_privacy_settings = _tmp29_;
		}
		_tmp30_ = granite_services_system_privacy_settings;
		result = g_settings_get_boolean (_tmp30_, "remember-recent-files");
		return result;
	}
	result = TRUE;
	return result;
}

GraniteServicesSystem*
granite_services_system_construct (GType object_type)
{
	GraniteServicesSystem * self = NULL;
	self = (GraniteServicesSystem*) g_object_new (object_type, NULL);
	return self;
}

GraniteServicesSystem*
granite_services_system_new (void)
{
	return granite_services_system_construct (GRANITE_SERVICES_TYPE_SYSTEM);
}

static void
granite_services_system_class_init (GraniteServicesSystemClass * klass,
                                    gpointer klass_data)
{
	granite_services_system_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = granite_services_system_finalize;
}

static void
granite_services_system_instance_init (GraniteServicesSystem * self,
                                       gpointer klass)
{
}

static void
granite_services_system_finalize (GObject * obj)
{
	GraniteServicesSystem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GRANITE_SERVICES_TYPE_SYSTEM, GraniteServicesSystem);
	G_OBJECT_CLASS (granite_services_system_parent_class)->finalize (obj);
}

/**
     * Utility class for frequently-used system-related functions, such as opening files, launching
     * applications, or executing terminal commands.
     */
static GType
granite_services_system_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GraniteServicesSystemClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) granite_services_system_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GraniteServicesSystem), 0, (GInstanceInitFunc) granite_services_system_instance_init, NULL };
	GType granite_services_system_type_id;
	granite_services_system_type_id = g_type_register_static (G_TYPE_OBJECT, "GraniteServicesSystem", &g_define_type_info, 0);
	return granite_services_system_type_id;
}

GType
granite_services_system_get_type (void)
{
	static volatile gsize granite_services_system_type_id__once = 0;
	if (g_once_init_enter (&granite_services_system_type_id__once)) {
		GType granite_services_system_type_id;
		granite_services_system_type_id = granite_services_system_get_type_once ();
		g_once_init_leave (&granite_services_system_type_id__once, granite_services_system_type_id);
	}
	return granite_services_system_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);
}

