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

/*
* Copyright 2020 elementary, Inc. (https://elementary.io)
*
* 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: Marius Meisenzahl <mariusmeisenzahl@gmail.com>
*/

#include "applications.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib-object.h>
#include <flatpak.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  {
	PERMISSIONS_BACKEND_FLATPAK_MANAGER_0_PROPERTY,
	PERMISSIONS_BACKEND_FLATPAK_MANAGER_USER_INSTALLATION_PATH_PROPERTY,
	PERMISSIONS_BACKEND_FLATPAK_MANAGER_NUM_PROPERTIES
};
static GParamSpec* permissions_backend_flatpak_manager_properties[PERMISSIONS_BACKEND_FLATPAK_MANAGER_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _PermissionsBackendFlatpakManagerPrivate {
	gchar* _user_installation_path;
};

static gint PermissionsBackendFlatpakManager_private_offset;
static gpointer permissions_backend_flatpak_manager_parent_class = NULL;
static PermissionsBackendFlatpakManager* permissions_backend_flatpak_manager_instance;
static PermissionsBackendFlatpakManager* permissions_backend_flatpak_manager_instance = NULL;

static void permissions_backend_flatpak_manager_set_user_installation_path (PermissionsBackendFlatpakManager* self,
                                                                     const gchar* value);
static GObject * permissions_backend_flatpak_manager_constructor (GType type,
                                                           guint n_construct_properties,
                                                           GObjectConstructParam * construct_properties);
static void permissions_backend_flatpak_manager_finalize (GObject * obj);
static GType permissions_backend_flatpak_manager_get_type_once (void);
static void _vala_permissions_backend_flatpak_manager_get_property (GObject * object,
                                                             guint property_id,
                                                             GValue * value,
                                                             GParamSpec * pspec);
static void _vala_permissions_backend_flatpak_manager_set_property (GObject * object,
                                                             guint property_id,
                                                             const GValue * value,
                                                             GParamSpec * pspec);

static inline gpointer
permissions_backend_flatpak_manager_get_instance_private (PermissionsBackendFlatpakManager* self)
{
	return G_STRUCT_MEMBER_P (self, PermissionsBackendFlatpakManager_private_offset);
}

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

PermissionsBackendFlatpakManager*
permissions_backend_flatpak_manager_get_default (void)
{
	PermissionsBackendFlatpakManager* _tmp0_;
	PermissionsBackendFlatpakManager* _tmp2_;
	PermissionsBackendFlatpakManager* _tmp3_;
	PermissionsBackendFlatpakManager* result;
	_tmp0_ = permissions_backend_flatpak_manager_instance;
	if (_tmp0_ == NULL) {
		PermissionsBackendFlatpakManager* _tmp1_;
		_tmp1_ = permissions_backend_flatpak_manager_new ();
		_g_object_unref0 (permissions_backend_flatpak_manager_instance);
		permissions_backend_flatpak_manager_instance = _tmp1_;
	}
	_tmp2_ = permissions_backend_flatpak_manager_instance;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	result = _tmp3_;
	return result;
}

PermissionsBackendFlatpakManager*
permissions_backend_flatpak_manager_construct (GType object_type)
{
	PermissionsBackendFlatpakManager * self = NULL;
	self = (PermissionsBackendFlatpakManager*) g_object_new (object_type, NULL);
	return self;
}

PermissionsBackendFlatpakManager*
permissions_backend_flatpak_manager_new (void)
{
	return permissions_backend_flatpak_manager_construct (PERMISSIONS_BACKEND_TYPE_FLATPAK_MANAGER);
}

const gchar*
permissions_backend_flatpak_manager_get_user_installation_path (PermissionsBackendFlatpakManager* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_user_installation_path;
	result = _tmp0_;
	return result;
}

static void
permissions_backend_flatpak_manager_set_user_installation_path (PermissionsBackendFlatpakManager* self,
                                                                const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = permissions_backend_flatpak_manager_get_user_installation_path (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_user_installation_path);
		self->priv->_user_installation_path = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, permissions_backend_flatpak_manager_properties[PERMISSIONS_BACKEND_FLATPAK_MANAGER_USER_INSTALLATION_PATH_PROPERTY]);
	}
}

static GObject *
permissions_backend_flatpak_manager_constructor (GType type,
                                                 guint n_construct_properties,
                                                 GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	PermissionsBackendFlatpakManager * self;
	GError* _inner_error0_ = NULL;
	parent_class = G_OBJECT_CLASS (permissions_backend_flatpak_manager_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PERMISSIONS_BACKEND_TYPE_FLATPAK_MANAGER, PermissionsBackendFlatpakManager);
	{
		FlatpakInstallation* installation = NULL;
		FlatpakInstallation* _tmp0_;
		FlatpakInstallation* _tmp1_;
		GFile* _tmp2_;
		GFile* _tmp3_;
		gchar* _tmp4_;
		gchar* _tmp5_;
		_tmp0_ = flatpak_installation_new_user (NULL, &_inner_error0_);
		installation = _tmp0_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp1_ = installation;
		_tmp2_ = flatpak_installation_get_path (_tmp1_);
		_tmp3_ = _tmp2_;
		_tmp4_ = g_file_get_path (_tmp3_);
		_tmp5_ = _tmp4_;
		permissions_backend_flatpak_manager_set_user_installation_path (self, _tmp5_);
		_g_free0 (_tmp5_);
		_g_object_unref0 (_tmp3_);
		_g_object_unref0 (installation);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp6_;
		const gchar* _tmp7_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp6_ = e;
		_tmp7_ = _tmp6_->message;
		g_critical ("FlatpakManager.vala:39: Unable to get flatpak user installation : %s", _tmp7_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		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 obj;
}

static void
permissions_backend_flatpak_manager_class_init (PermissionsBackendFlatpakManagerClass * klass,
                                                gpointer klass_data)
{
	permissions_backend_flatpak_manager_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &PermissionsBackendFlatpakManager_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_permissions_backend_flatpak_manager_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_permissions_backend_flatpak_manager_set_property;
	G_OBJECT_CLASS (klass)->constructor = permissions_backend_flatpak_manager_constructor;
	G_OBJECT_CLASS (klass)->finalize = permissions_backend_flatpak_manager_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), PERMISSIONS_BACKEND_FLATPAK_MANAGER_USER_INSTALLATION_PATH_PROPERTY, permissions_backend_flatpak_manager_properties[PERMISSIONS_BACKEND_FLATPAK_MANAGER_USER_INSTALLATION_PATH_PROPERTY] = g_param_spec_string ("user-installation-path", "user-installation-path", "user-installation-path", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
permissions_backend_flatpak_manager_instance_init (PermissionsBackendFlatpakManager * self,
                                                   gpointer klass)
{
	self->priv = permissions_backend_flatpak_manager_get_instance_private (self);
}

static void
permissions_backend_flatpak_manager_finalize (GObject * obj)
{
	PermissionsBackendFlatpakManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PERMISSIONS_BACKEND_TYPE_FLATPAK_MANAGER, PermissionsBackendFlatpakManager);
	_g_free0 (self->priv->_user_installation_path);
	G_OBJECT_CLASS (permissions_backend_flatpak_manager_parent_class)->finalize (obj);
}

static GType
permissions_backend_flatpak_manager_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (PermissionsBackendFlatpakManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) permissions_backend_flatpak_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PermissionsBackendFlatpakManager), 0, (GInstanceInitFunc) permissions_backend_flatpak_manager_instance_init, NULL };
	GType permissions_backend_flatpak_manager_type_id;
	permissions_backend_flatpak_manager_type_id = g_type_register_static (G_TYPE_OBJECT, "PermissionsBackendFlatpakManager", &g_define_type_info, 0);
	PermissionsBackendFlatpakManager_private_offset = g_type_add_instance_private (permissions_backend_flatpak_manager_type_id, sizeof (PermissionsBackendFlatpakManagerPrivate));
	return permissions_backend_flatpak_manager_type_id;
}

GType
permissions_backend_flatpak_manager_get_type (void)
{
	static volatile gsize permissions_backend_flatpak_manager_type_id__once = 0;
	if (g_once_init_enter (&permissions_backend_flatpak_manager_type_id__once)) {
		GType permissions_backend_flatpak_manager_type_id;
		permissions_backend_flatpak_manager_type_id = permissions_backend_flatpak_manager_get_type_once ();
		g_once_init_leave (&permissions_backend_flatpak_manager_type_id__once, permissions_backend_flatpak_manager_type_id);
	}
	return permissions_backend_flatpak_manager_type_id__once;
}

static void
_vala_permissions_backend_flatpak_manager_get_property (GObject * object,
                                                        guint property_id,
                                                        GValue * value,
                                                        GParamSpec * pspec)
{
	PermissionsBackendFlatpakManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, PERMISSIONS_BACKEND_TYPE_FLATPAK_MANAGER, PermissionsBackendFlatpakManager);
	switch (property_id) {
		case PERMISSIONS_BACKEND_FLATPAK_MANAGER_USER_INSTALLATION_PATH_PROPERTY:
		g_value_set_string (value, permissions_backend_flatpak_manager_get_user_installation_path (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_permissions_backend_flatpak_manager_set_property (GObject * object,
                                                        guint property_id,
                                                        const GValue * value,
                                                        GParamSpec * pspec)
{
	PermissionsBackendFlatpakManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, PERMISSIONS_BACKEND_TYPE_FLATPAK_MANAGER, PermissionsBackendFlatpakManager);
	switch (property_id) {
		case PERMISSIONS_BACKEND_FLATPAK_MANAGER_USER_INSTALLATION_PATH_PROPERTY:
		permissions_backend_flatpak_manager_set_user_installation_path (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

