/* BackendWatcher.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from BackendWatcher.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 <glib.h>
#include <gio/gio.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  {
	DEJA_DUP_BACKEND_WATCHER_0_PROPERTY,
	DEJA_DUP_BACKEND_WATCHER_NUM_PROPERTIES
};
static GParamSpec* deja_dup_backend_watcher_properties[DEJA_DUP_BACKEND_WATCHER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
enum  {
	DEJA_DUP_BACKEND_WATCHER_CHANGED_SIGNAL,
	DEJA_DUP_BACKEND_WATCHER_NEW_BACKUP_SIGNAL,
	DEJA_DUP_BACKEND_WATCHER_NUM_SIGNALS
};
static guint deja_dup_backend_watcher_signals[DEJA_DUP_BACKEND_WATCHER_NUM_SIGNALS] = {0};

struct _DejaDupBackendWatcherPrivate {
	GList* all_settings;
};

static gint DejaDupBackendWatcher_private_offset;
static gpointer deja_dup_backend_watcher_parent_class = NULL;
static DejaDupBackendWatcher* deja_dup_backend_watcher_instance;
static DejaDupBackendWatcher* deja_dup_backend_watcher_instance = NULL;

static void _g_object_unref0_ (gpointer var);
static inline void _g_list_free__g_object_unref0_ (GList* self);
static DejaDupBackendWatcher* deja_dup_backend_watcher_new (void);
static DejaDupBackendWatcher* deja_dup_backend_watcher_construct (GType object_type);
static void deja_dup_backend_watcher_handle_change (DejaDupBackendWatcher* self);
static gboolean deja_dup_backend_watcher_handle_change_event (DejaDupBackendWatcher* self);
static GObject * deja_dup_backend_watcher_constructor (GType type,
                                                guint n_construct_properties,
                                                GObjectConstructParam * construct_properties);
static void _deja_dup_backend_watcher_handle_change_g_settings_changed (GSettings* _sender,
                                                                 const gchar* key,
                                                                 gpointer self);
static void _deja_dup_backend_watcher___lambda6_ (DejaDupBackendWatcher* self);
static void __deja_dup_backend_watcher___lambda6__g_settings_changed (GSettings* _sender,
                                                               const gchar* key,
                                                               gpointer self);
static gboolean _deja_dup_backend_watcher_handle_change_event_g_settings_change_event (GSettings* _sender,
                                                                                GQuark* keys,
                                                                                gint n_keys,
                                                                                gpointer self);
static void deja_dup_backend_watcher_finalize (GObject * obj);
static GType deja_dup_backend_watcher_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 inline gpointer
deja_dup_backend_watcher_get_instance_private (DejaDupBackendWatcher* self)
{
	return G_STRUCT_MEMBER_P (self, DejaDupBackendWatcher_private_offset);
}

static void
_g_object_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}

static inline void
_g_list_free__g_object_unref0_ (GList* self)
{
	g_list_free_full (self, (GDestroyNotify) _g_object_unref0_);
}

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

DejaDupBackendWatcher*
deja_dup_backend_watcher_get_instance (void)
{
	DejaDupBackendWatcher* _tmp0_;
	DejaDupBackendWatcher* _tmp2_;
	DejaDupBackendWatcher* _tmp3_;
	DejaDupBackendWatcher* result;
	_tmp0_ = deja_dup_backend_watcher_instance;
	if (_tmp0_ == NULL) {
		DejaDupBackendWatcher* _tmp1_;
		_tmp1_ = deja_dup_backend_watcher_new ();
		_g_object_unref0 (deja_dup_backend_watcher_instance);
		deja_dup_backend_watcher_instance = _tmp1_;
	}
	_tmp2_ = deja_dup_backend_watcher_instance;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	result = _tmp3_;
	return result;
}

static DejaDupBackendWatcher*
deja_dup_backend_watcher_construct (GType object_type)
{
	DejaDupBackendWatcher * self = NULL;
	self = (DejaDupBackendWatcher*) g_object_new (object_type, NULL);
	return self;
}

static DejaDupBackendWatcher*
deja_dup_backend_watcher_new (void)
{
	return deja_dup_backend_watcher_construct (DEJA_DUP_TYPE_BACKEND_WATCHER);
}

static void
deja_dup_backend_watcher_handle_change (DejaDupBackendWatcher* self)
{
	g_return_if_fail (self != NULL);
	g_signal_emit (self, deja_dup_backend_watcher_signals[DEJA_DUP_BACKEND_WATCHER_CHANGED_SIGNAL], 0);
}

static gboolean
deja_dup_backend_watcher_handle_change_event (DejaDupBackendWatcher* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_signal_emit (self, deja_dup_backend_watcher_signals[DEJA_DUP_BACKEND_WATCHER_CHANGED_SIGNAL], 0);
	result = FALSE;
	return result;
}

static void
_deja_dup_backend_watcher_handle_change_g_settings_changed (GSettings* _sender,
                                                            const gchar* key,
                                                            gpointer self)
{
	deja_dup_backend_watcher_handle_change ((DejaDupBackendWatcher*) self);
}

static void
_deja_dup_backend_watcher___lambda6_ (DejaDupBackendWatcher* self)
{
	g_signal_emit (self, deja_dup_backend_watcher_signals[DEJA_DUP_BACKEND_WATCHER_NEW_BACKUP_SIGNAL], 0);
}

static void
__deja_dup_backend_watcher___lambda6__g_settings_changed (GSettings* _sender,
                                                          const gchar* key,
                                                          gpointer self)
{
	_deja_dup_backend_watcher___lambda6_ ((DejaDupBackendWatcher*) self);
}

static gboolean
_deja_dup_backend_watcher_handle_change_event_g_settings_change_event (GSettings* _sender,
                                                                       GQuark* keys,
                                                                       gint n_keys,
                                                                       gpointer self)
{
	gboolean result;
	result = deja_dup_backend_watcher_handle_change_event ((DejaDupBackendWatcher*) self);
	return result;
}

static GObject *
deja_dup_backend_watcher_constructor (GType type,
                                      guint n_construct_properties,
                                      GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	DejaDupBackendWatcher * self;
	DejaDupFilteredSettings* settings = NULL;
	DejaDupFilteredSettings* _tmp0_;
	DejaDupFilteredSettings* _tmp1_;
	gchar* _tmp2_;
	DejaDupFilteredSettings* _tmp3_;
	gchar* _tmp4_;
	DejaDupFilteredSettings* _tmp5_;
	GSettings* _tmp6_;
	gchar** roots = NULL;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	gchar** _tmp12_;
	gint roots_length1;
	gint _roots_size_;
	gchar** _tmp13_;
	gint _tmp13__length1;
	DejaDupFilteredSettings* _tmp20_;
	DejaDupFilteredSettings* _tmp21_;
	gchar* _tmp22_;
	DejaDupFilteredSettings* _tmp23_;
	gchar* _tmp24_;
	DejaDupFilteredSettings* _tmp25_;
	GSettings* _tmp26_;
	parent_class = G_OBJECT_CLASS (deja_dup_backend_watcher_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DEJA_DUP_TYPE_BACKEND_WATCHER, DejaDupBackendWatcher);
	_tmp0_ = deja_dup_get_settings (NULL);
	settings = _tmp0_;
	_tmp1_ = settings;
	_tmp2_ = g_strconcat ("changed::", DEJA_DUP_BACKEND_KEY, NULL);
	g_signal_connect_object ((GSettings*) _tmp1_, _tmp2_, (GCallback) _deja_dup_backend_watcher_handle_change_g_settings_changed, self, 0);
	_g_free0 (_tmp2_);
	_tmp3_ = settings;
	_tmp4_ = g_strconcat ("changed::", DEJA_DUP_LAST_BACKUP_KEY, NULL);
	g_signal_connect_object ((GSettings*) _tmp3_, _tmp4_, (GCallback) __deja_dup_backend_watcher___lambda6__g_settings_changed, self, 0);
	_g_free0 (_tmp4_);
	_tmp5_ = settings;
	_tmp6_ = _g_object_ref0 ((GSettings*) _tmp5_);
	self->priv->all_settings = g_list_prepend (self->priv->all_settings, _tmp6_);
	_tmp7_ = g_strdup (DEJA_DUP_GOOGLE_ROOT);
	_tmp8_ = g_strdup (DEJA_DUP_LOCAL_ROOT);
	_tmp9_ = g_strdup (DEJA_DUP_MICROSOFT_ROOT);
	_tmp10_ = g_strdup (DEJA_DUP_REMOTE_ROOT);
	_tmp11_ = g_strdup (DEJA_DUP_RCLONE_ROOT);
	_tmp12_ = g_new0 (gchar*, 5 + 1);
	_tmp12_[0] = _tmp7_;
	_tmp12_[1] = _tmp8_;
	_tmp12_[2] = _tmp9_;
	_tmp12_[3] = _tmp10_;
	_tmp12_[4] = _tmp11_;
	roots = _tmp12_;
	roots_length1 = 5;
	_roots_size_ = roots_length1;
	_tmp13_ = roots;
	_tmp13__length1 = roots_length1;
	{
		gchar** root_collection = NULL;
		gint root_collection_length1 = 0;
		gint _root_collection_size_ = 0;
		gint root_it = 0;
		root_collection = _tmp13_;
		root_collection_length1 = _tmp13__length1;
		for (root_it = 0; root_it < root_collection_length1; root_it = root_it + 1) {
			gchar* _tmp14_;
			gchar* root = NULL;
			_tmp14_ = g_strdup (root_collection[root_it]);
			root = _tmp14_;
			{
				const gchar* _tmp15_;
				DejaDupFilteredSettings* _tmp16_;
				DejaDupFilteredSettings* _tmp17_;
				DejaDupFilteredSettings* _tmp18_;
				GSettings* _tmp19_;
				_tmp15_ = root;
				_tmp16_ = deja_dup_get_settings (_tmp15_);
				_g_object_unref0 (settings);
				settings = _tmp16_;
				_tmp17_ = settings;
				g_signal_connect_object ((GSettings*) _tmp17_, "change-event", (GCallback) _deja_dup_backend_watcher_handle_change_event_g_settings_change_event, self, 0);
				_tmp18_ = settings;
				_tmp19_ = _g_object_ref0 ((GSettings*) _tmp18_);
				self->priv->all_settings = g_list_prepend (self->priv->all_settings, _tmp19_);
				_g_free0 (root);
			}
		}
	}
	_tmp20_ = deja_dup_get_settings (DEJA_DUP_DRIVE_ROOT);
	_g_object_unref0 (settings);
	settings = _tmp20_;
	_tmp21_ = settings;
	_tmp22_ = g_strconcat ("changed::", DEJA_DUP_DRIVE_UUID_KEY, NULL);
	g_signal_connect_object ((GSettings*) _tmp21_, _tmp22_, (GCallback) _deja_dup_backend_watcher_handle_change_g_settings_changed, self, 0);
	_g_free0 (_tmp22_);
	_tmp23_ = settings;
	_tmp24_ = g_strconcat ("changed::", DEJA_DUP_DRIVE_FOLDER_KEY, NULL);
	g_signal_connect_object ((GSettings*) _tmp23_, _tmp24_, (GCallback) _deja_dup_backend_watcher_handle_change_g_settings_changed, self, 0);
	_g_free0 (_tmp24_);
	_tmp25_ = settings;
	_tmp26_ = _g_object_ref0 ((GSettings*) _tmp25_);
	self->priv->all_settings = g_list_prepend (self->priv->all_settings, _tmp26_);
	roots = (_vala_array_free (roots, roots_length1, (GDestroyNotify) g_free), NULL);
	_g_object_unref0 (settings);
	return obj;
}

static void
deja_dup_backend_watcher_class_init (DejaDupBackendWatcherClass * klass,
                                     gpointer klass_data)
{
	deja_dup_backend_watcher_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DejaDupBackendWatcher_private_offset);
	G_OBJECT_CLASS (klass)->constructor = deja_dup_backend_watcher_constructor;
	G_OBJECT_CLASS (klass)->finalize = deja_dup_backend_watcher_finalize;
	deja_dup_backend_watcher_signals[DEJA_DUP_BACKEND_WATCHER_CHANGED_SIGNAL] = g_signal_new ("changed", DEJA_DUP_TYPE_BACKEND_WATCHER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	deja_dup_backend_watcher_signals[DEJA_DUP_BACKEND_WATCHER_NEW_BACKUP_SIGNAL] = g_signal_new ("new-backup", DEJA_DUP_TYPE_BACKEND_WATCHER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
deja_dup_backend_watcher_instance_init (DejaDupBackendWatcher * self,
                                        gpointer klass)
{
	self->priv = deja_dup_backend_watcher_get_instance_private (self);
}

static void
deja_dup_backend_watcher_finalize (GObject * obj)
{
	DejaDupBackendWatcher * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DEJA_DUP_TYPE_BACKEND_WATCHER, DejaDupBackendWatcher);
	(self->priv->all_settings == NULL) ? NULL : (self->priv->all_settings = (_g_list_free__g_object_unref0_ (self->priv->all_settings), NULL));
	G_OBJECT_CLASS (deja_dup_backend_watcher_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
deja_dup_backend_watcher_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DejaDupBackendWatcherClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) deja_dup_backend_watcher_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DejaDupBackendWatcher), 0, (GInstanceInitFunc) deja_dup_backend_watcher_instance_init, NULL };
	GType deja_dup_backend_watcher_type_id;
	deja_dup_backend_watcher_type_id = g_type_register_static (G_TYPE_OBJECT, "DejaDupBackendWatcher", &g_define_type_info, 0);
	DejaDupBackendWatcher_private_offset = g_type_add_instance_private (deja_dup_backend_watcher_type_id, sizeof (DejaDupBackendWatcherPrivate));
	return deja_dup_backend_watcher_type_id;
}

GType
deja_dup_backend_watcher_get_type (void)
{
	static gsize deja_dup_backend_watcher_type_id__once = 0;
	if (g_once_init_enter (&deja_dup_backend_watcher_type_id__once)) {
		GType deja_dup_backend_watcher_type_id;
		deja_dup_backend_watcher_type_id = deja_dup_backend_watcher_get_type_once ();
		g_once_init_leave (&deja_dup_backend_watcher_type_id__once, deja_dup_backend_watcher_type_id);
	}
	return deja_dup_backend_watcher_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);
}

