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

/* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 2 -*-
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 * SPDX-FileCopyrightText: Michael Terry
 */

#include "deja.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>
#include <glib-object.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  {
	DEJA_DUP_INSTALL_ENV_0_PROPERTY,
	DEJA_DUP_INSTALL_ENV_NUM_PROPERTIES
};
static GParamSpec* deja_dup_install_env_properties[DEJA_DUP_INSTALL_ENV_NUM_PROPERTIES];

#define DEJA_DUP_TYPE_INSTALL_ENV_FLATPAK (deja_dup_install_env_flatpak_get_type ())
#define DEJA_DUP_INSTALL_ENV_FLATPAK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DEJA_DUP_TYPE_INSTALL_ENV_FLATPAK, DejaDupInstallEnvFlatpak))
#define DEJA_DUP_INSTALL_ENV_FLATPAK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DEJA_DUP_TYPE_INSTALL_ENV_FLATPAK, DejaDupInstallEnvFlatpakClass))
#define DEJA_DUP_IS_INSTALL_ENV_FLATPAK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DEJA_DUP_TYPE_INSTALL_ENV_FLATPAK))
#define DEJA_DUP_IS_INSTALL_ENV_FLATPAK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DEJA_DUP_TYPE_INSTALL_ENV_FLATPAK))
#define DEJA_DUP_INSTALL_ENV_FLATPAK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DEJA_DUP_TYPE_INSTALL_ENV_FLATPAK, DejaDupInstallEnvFlatpakClass))

typedef struct _DejaDupInstallEnvFlatpak DejaDupInstallEnvFlatpak;
typedef struct _DejaDupInstallEnvFlatpakClass DejaDupInstallEnvFlatpakClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define DEJA_DUP_TYPE_INSTALL_ENV_SNAP (deja_dup_install_env_snap_get_type ())
#define DEJA_DUP_INSTALL_ENV_SNAP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DEJA_DUP_TYPE_INSTALL_ENV_SNAP, DejaDupInstallEnvSnap))
#define DEJA_DUP_INSTALL_ENV_SNAP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DEJA_DUP_TYPE_INSTALL_ENV_SNAP, DejaDupInstallEnvSnapClass))
#define DEJA_DUP_IS_INSTALL_ENV_SNAP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DEJA_DUP_TYPE_INSTALL_ENV_SNAP))
#define DEJA_DUP_IS_INSTALL_ENV_SNAP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DEJA_DUP_TYPE_INSTALL_ENV_SNAP))
#define DEJA_DUP_INSTALL_ENV_SNAP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DEJA_DUP_TYPE_INSTALL_ENV_SNAP, DejaDupInstallEnvSnapClass))

typedef struct _DejaDupInstallEnvSnap DejaDupInstallEnvSnap;
typedef struct _DejaDupInstallEnvSnapClass DejaDupInstallEnvSnapClass;
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _DejaDupInstallEnvRequestAutostartData DejaDupInstallEnvRequestAutostartData;

struct _DejaDupInstallEnvRequestAutostartData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DejaDupInstallEnv* self;
	gchar* handle;
	gchar* mitigation;
	gboolean result;
};

static gpointer deja_dup_install_env_parent_class = NULL;
static DejaDupInstallEnv* deja_dup_install_env__instance;
static DejaDupInstallEnv* deja_dup_install_env__instance = NULL;

VALA_EXTERN DejaDupInstallEnvFlatpak* deja_dup_install_env_flatpak_new (void);
VALA_EXTERN DejaDupInstallEnvFlatpak* deja_dup_install_env_flatpak_construct (GType object_type);
VALA_EXTERN GType deja_dup_install_env_flatpak_get_type (void) G_GNUC_CONST ;
VALA_EXTERN DejaDupInstallEnvSnap* deja_dup_install_env_snap_new (void);
VALA_EXTERN DejaDupInstallEnvSnap* deja_dup_install_env_snap_construct (GType object_type);
VALA_EXTERN GType deja_dup_install_env_snap_get_type (void) G_GNUC_CONST ;
static gchar* deja_dup_install_env_real_get_name (DejaDupInstallEnv* self);
static void deja_dup_install_env_real_request_autostart_data_free (gpointer _data);
static void deja_dup_install_env_real_request_autostart (DejaDupInstallEnv* self,
                                                  const gchar* handle,
                                                  GAsyncReadyCallback _callback_,
                                                  gpointer _user_data_);
static gboolean deja_dup_install_env_real_request_autostart_co (DejaDupInstallEnvRequestAutostartData* _data_);
static gboolean deja_dup_install_env_real_has_custom_config_home (DejaDupInstallEnv* self);
static gchar** deja_dup_install_env_real_get_system_tempdirs (DejaDupInstallEnv* self,
                                                       gint* result_length1);
static gchar* deja_dup_install_env_real_get_trash_dir (DejaDupInstallEnv* self);
static gchar* deja_dup_install_env_real_get_read_root (DejaDupInstallEnv* self);
static void deja_dup_install_env_real_register_monitor_restart (DejaDupInstallEnv* self,
                                                         GMainLoop* loop);
static gboolean deja_dup_install_env_real_is_file_available (DejaDupInstallEnv* self,
                                                      GFile* file);
static gchar* deja_dup_install_env_real_get_debug_info (DejaDupInstallEnv* self);
static void deja_dup_install_env_finalize (GObject * obj);
static GType deja_dup_install_env_get_type_once (void);

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

DejaDupInstallEnv*
deja_dup_install_env_instance (void)
{
	DejaDupInstallEnv* _tmp0_;
	DejaDupInstallEnv* _tmp6_;
	DejaDupInstallEnv* _tmp7_;
	DejaDupInstallEnv* result;
	_tmp0_ = deja_dup_install_env__instance;
	if (_tmp0_ == NULL) {
		const gchar* _tmp1_;
		_tmp1_ = g_getenv ("FLATPAK_ID");
		if (_tmp1_ != NULL) {
			DejaDupInstallEnvFlatpak* _tmp2_;
			_tmp2_ = deja_dup_install_env_flatpak_new ();
			_g_object_unref0 (deja_dup_install_env__instance);
			deja_dup_install_env__instance = (DejaDupInstallEnv*) _tmp2_;
		} else {
			const gchar* _tmp3_;
			_tmp3_ = g_getenv ("SNAP_NAME");
			if (_tmp3_ != NULL) {
				DejaDupInstallEnvSnap* _tmp4_;
				_tmp4_ = deja_dup_install_env_snap_new ();
				_g_object_unref0 (deja_dup_install_env__instance);
				deja_dup_install_env__instance = (DejaDupInstallEnv*) _tmp4_;
			} else {
				DejaDupInstallEnv* _tmp5_;
				_tmp5_ = deja_dup_install_env_new ();
				_g_object_unref0 (deja_dup_install_env__instance);
				deja_dup_install_env__instance = _tmp5_;
			}
		}
	}
	_tmp6_ = deja_dup_install_env__instance;
	_tmp7_ = _g_object_ref0 (_tmp6_);
	result = _tmp7_;
	return result;
}

static gchar*
deja_dup_install_env_real_get_name (DejaDupInstallEnv* self)
{
	gchar* result;
	result = NULL;
	return result;
}

gchar*
deja_dup_install_env_get_name (DejaDupInstallEnv* self)
{
	DejaDupInstallEnvClass* _klass_;
	g_return_val_if_fail (self != NULL, NULL);
	_klass_ = DEJA_DUP_INSTALL_ENV_GET_CLASS (self);
	if (_klass_->get_name) {
		return _klass_->get_name (self);
	}
	return NULL;
}

static void
deja_dup_install_env_real_request_autostart_data_free (gpointer _data)
{
	DejaDupInstallEnvRequestAutostartData* _data_;
	_data_ = _data;
	_g_free0 (_data_->handle);
	_g_object_unref0 (_data_->self);
	g_slice_free (DejaDupInstallEnvRequestAutostartData, _data_);
}

static void
deja_dup_install_env_real_request_autostart (DejaDupInstallEnv* self,
                                             const gchar* handle,
                                             GAsyncReadyCallback _callback_,
                                             gpointer _user_data_)
{
	DejaDupInstallEnvRequestAutostartData* _data_;
	DejaDupInstallEnv* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (handle != NULL);
	_data_ = g_slice_new0 (DejaDupInstallEnvRequestAutostartData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, deja_dup_install_env_real_request_autostart_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = g_strdup (handle);
	_g_free0 (_data_->handle);
	_data_->handle = _tmp1_;
	deja_dup_install_env_real_request_autostart_co (_data_);
}

static gboolean
deja_dup_install_env_real_request_autostart_finish (DejaDupInstallEnv* self,
                                                    GAsyncResult* _res_,
                                                    gchar** mitigation)
{
	gboolean result;
	DejaDupInstallEnvRequestAutostartData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	if (mitigation) {
		*mitigation = _data_->mitigation;
	} else {
		_g_free0 (_data_->mitigation);
	}
	_data_->mitigation = NULL;
	result = _data_->result;
	return result;
}

static gboolean
deja_dup_install_env_real_request_autostart_co (DejaDupInstallEnvRequestAutostartData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_g_free0 (_data_->mitigation);
	_data_->mitigation = NULL;
	_data_->result = TRUE;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

void
deja_dup_install_env_request_autostart (DejaDupInstallEnv* self,
                                        const gchar* handle,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_)
{
	DejaDupInstallEnvClass* _klass_;
	_klass_ = DEJA_DUP_INSTALL_ENV_GET_CLASS (self);
	if (_klass_->request_autostart) {
		_klass_->request_autostart (self, handle, _callback_, _user_data_);
	}
}

gboolean
deja_dup_install_env_request_autostart_finish (DejaDupInstallEnv* self,
                                               GAsyncResult* _res_,
                                               gchar** mitigation)
{
	DejaDupInstallEnvClass* _klass_;
	_klass_ = DEJA_DUP_INSTALL_ENV_GET_CLASS (self);
	if (_klass_->request_autostart_finish) {
		return _klass_->request_autostart_finish (self, _res_, mitigation);
	}
	return FALSE;
}

static gboolean
deja_dup_install_env_real_has_custom_config_home (DejaDupInstallEnv* self)
{
	gboolean result;
	result = FALSE;
	return result;
}

gboolean
deja_dup_install_env_has_custom_config_home (DejaDupInstallEnv* self)
{
	DejaDupInstallEnvClass* _klass_;
	g_return_val_if_fail (self != NULL, FALSE);
	_klass_ = DEJA_DUP_INSTALL_ENV_GET_CLASS (self);
	if (_klass_->has_custom_config_home) {
		return _klass_->has_custom_config_home (self);
	}
	return FALSE;
}

static gchar**
deja_dup_install_env_real_get_system_tempdirs (DejaDupInstallEnv* self,
                                               gint* result_length1)
{
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar** _tmp3_;
	gchar** _tmp4_;
	gint _tmp4__length1;
	gchar** result;
	_tmp0_ = g_get_tmp_dir ();
	_tmp1_ = g_strdup (_tmp0_);
	_tmp2_ = g_strdup ("/var/tmp");
	_tmp3_ = g_new0 (gchar*, 2 + 1);
	_tmp3_[0] = _tmp1_;
	_tmp3_[1] = _tmp2_;
	_tmp4_ = _tmp3_;
	_tmp4__length1 = 2;
	if (result_length1) {
		*result_length1 = _tmp4__length1;
	}
	result = _tmp4_;
	return result;
}

gchar**
deja_dup_install_env_get_system_tempdirs (DejaDupInstallEnv* self,
                                          gint* result_length1)
{
	DejaDupInstallEnvClass* _klass_;
	g_return_val_if_fail (self != NULL, NULL);
	_klass_ = DEJA_DUP_INSTALL_ENV_GET_CLASS (self);
	if (_klass_->get_system_tempdirs) {
		return _klass_->get_system_tempdirs (self, result_length1);
	}
	return NULL;
}

static gchar*
deja_dup_install_env_real_get_trash_dir (DejaDupInstallEnv* self)
{
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* result;
	_tmp0_ = g_get_user_data_dir ();
	_tmp1_ = g_build_filename (_tmp0_, "Trash", NULL);
	result = _tmp1_;
	return result;
}

gchar*
deja_dup_install_env_get_trash_dir (DejaDupInstallEnv* self)
{
	DejaDupInstallEnvClass* _klass_;
	g_return_val_if_fail (self != NULL, NULL);
	_klass_ = DEJA_DUP_INSTALL_ENV_GET_CLASS (self);
	if (_klass_->get_trash_dir) {
		return _klass_->get_trash_dir (self);
	}
	return NULL;
}

static gchar*
deja_dup_install_env_real_get_read_root (DejaDupInstallEnv* self)
{
	gchar* _tmp0_;
	gchar* result;
	_tmp0_ = g_strdup ("/");
	result = _tmp0_;
	return result;
}

gchar*
deja_dup_install_env_get_read_root (DejaDupInstallEnv* self)
{
	DejaDupInstallEnvClass* _klass_;
	g_return_val_if_fail (self != NULL, NULL);
	_klass_ = DEJA_DUP_INSTALL_ENV_GET_CLASS (self);
	if (_klass_->get_read_root) {
		return _klass_->get_read_root (self);
	}
	return NULL;
}

static void
deja_dup_install_env_real_register_monitor_restart (DejaDupInstallEnv* self,
                                                    GMainLoop* loop)
{
	g_return_if_fail (loop != NULL);
}

void
deja_dup_install_env_register_monitor_restart (DejaDupInstallEnv* self,
                                               GMainLoop* loop)
{
	DejaDupInstallEnvClass* _klass_;
	g_return_if_fail (self != NULL);
	_klass_ = DEJA_DUP_INSTALL_ENV_GET_CLASS (self);
	if (_klass_->register_monitor_restart) {
		_klass_->register_monitor_restart (self, loop);
	}
}

static gboolean
deja_dup_install_env_real_is_file_available (DejaDupInstallEnv* self,
                                             GFile* file)
{
	gboolean result;
	g_return_val_if_fail (file != NULL, FALSE);
	result = TRUE;
	return result;
}

gboolean
deja_dup_install_env_is_file_available (DejaDupInstallEnv* self,
                                        GFile* file)
{
	DejaDupInstallEnvClass* _klass_;
	g_return_val_if_fail (self != NULL, FALSE);
	_klass_ = DEJA_DUP_INSTALL_ENV_GET_CLASS (self);
	if (_klass_->is_file_available) {
		return _klass_->is_file_available (self, file);
	}
	return FALSE;
}

static gchar*
deja_dup_install_env_real_get_debug_info (DejaDupInstallEnv* self)
{
	gchar* _tmp0_;
	gchar* result;
	_tmp0_ = g_strdup ("");
	result = _tmp0_;
	return result;
}

gchar*
deja_dup_install_env_get_debug_info (DejaDupInstallEnv* self)
{
	DejaDupInstallEnvClass* _klass_;
	g_return_val_if_fail (self != NULL, NULL);
	_klass_ = DEJA_DUP_INSTALL_ENV_GET_CLASS (self);
	if (_klass_->get_debug_info) {
		return _klass_->get_debug_info (self);
	}
	return NULL;
}

DejaDupInstallEnv*
deja_dup_install_env_construct (GType object_type)
{
	DejaDupInstallEnv * self = NULL;
	self = (DejaDupInstallEnv*) g_object_new (object_type, NULL);
	return self;
}

DejaDupInstallEnv*
deja_dup_install_env_new (void)
{
	return deja_dup_install_env_construct (DEJA_DUP_TYPE_INSTALL_ENV);
}

static void
deja_dup_install_env_class_init (DejaDupInstallEnvClass * klass,
                                 gpointer klass_data)
{
	deja_dup_install_env_parent_class = g_type_class_peek_parent (klass);
	((DejaDupInstallEnvClass *) klass)->get_name = (gchar* (*) (DejaDupInstallEnv*)) deja_dup_install_env_real_get_name;
	((DejaDupInstallEnvClass *) klass)->request_autostart = (void (*) (DejaDupInstallEnv*, const gchar*, GAsyncReadyCallback, gpointer)) deja_dup_install_env_real_request_autostart;
	((DejaDupInstallEnvClass *) klass)->request_autostart_finish = (gboolean (*) (DejaDupInstallEnv*, GAsyncResult*, gchar**)) deja_dup_install_env_real_request_autostart_finish;
	((DejaDupInstallEnvClass *) klass)->has_custom_config_home = (gboolean (*) (DejaDupInstallEnv*)) deja_dup_install_env_real_has_custom_config_home;
	((DejaDupInstallEnvClass *) klass)->get_system_tempdirs = (gchar** (*) (DejaDupInstallEnv*, gint*)) deja_dup_install_env_real_get_system_tempdirs;
	((DejaDupInstallEnvClass *) klass)->get_trash_dir = (gchar* (*) (DejaDupInstallEnv*)) deja_dup_install_env_real_get_trash_dir;
	((DejaDupInstallEnvClass *) klass)->get_read_root = (gchar* (*) (DejaDupInstallEnv*)) deja_dup_install_env_real_get_read_root;
	((DejaDupInstallEnvClass *) klass)->register_monitor_restart = (void (*) (DejaDupInstallEnv*, GMainLoop*)) deja_dup_install_env_real_register_monitor_restart;
	((DejaDupInstallEnvClass *) klass)->is_file_available = (gboolean (*) (DejaDupInstallEnv*, GFile*)) deja_dup_install_env_real_is_file_available;
	((DejaDupInstallEnvClass *) klass)->get_debug_info = (gchar* (*) (DejaDupInstallEnv*)) deja_dup_install_env_real_get_debug_info;
	G_OBJECT_CLASS (klass)->finalize = deja_dup_install_env_finalize;
}

static void
deja_dup_install_env_instance_init (DejaDupInstallEnv * self,
                                    gpointer klass)
{
}

static void
deja_dup_install_env_finalize (GObject * obj)
{
	DejaDupInstallEnv * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DEJA_DUP_TYPE_INSTALL_ENV, DejaDupInstallEnv);
	G_OBJECT_CLASS (deja_dup_install_env_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
deja_dup_install_env_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DejaDupInstallEnvClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) deja_dup_install_env_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DejaDupInstallEnv), 0, (GInstanceInitFunc) deja_dup_install_env_instance_init, NULL };
	GType deja_dup_install_env_type_id;
	deja_dup_install_env_type_id = g_type_register_static (G_TYPE_OBJECT, "DejaDupInstallEnv", &g_define_type_info, 0);
	return deja_dup_install_env_type_id;
}

GType
deja_dup_install_env_get_type (void)
{
	static gsize deja_dup_install_env_type_id__once = 0;
	if (g_once_init_enter (&deja_dup_install_env_type_id__once)) {
		GType deja_dup_install_env_type_id;
		deja_dup_install_env_type_id = deja_dup_install_env_get_type_once ();
		g_once_init_leave (&deja_dup_install_env_type_id__once, deja_dup_install_env_type_id);
	}
	return deja_dup_install_env_type_id__once;
}

