/* OperationFiles.c generated by valac 0.56.19, the Vala compiler
 * generated from OperationFiles.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 <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.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_OPERATION_FILES_0_PROPERTY,
	DEJA_DUP_OPERATION_FILES_SOURCE_PROPERTY,
	DEJA_DUP_OPERATION_FILES_TAG_PROPERTY,
	DEJA_DUP_OPERATION_FILES_NUM_PROPERTIES
};
static GParamSpec* deja_dup_operation_files_properties[DEJA_DUP_OPERATION_FILES_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))
typedef struct _DejaDupOperationFilesOperationFinishedData DejaDupOperationFilesOperationFinishedData;
enum  {
	DEJA_DUP_OPERATION_FILES_LISTED_CURRENT_FILES_SIGNAL,
	DEJA_DUP_OPERATION_FILES_NUM_SIGNALS
};
static guint deja_dup_operation_files_signals[DEJA_DUP_OPERATION_FILES_NUM_SIGNALS] = {0};

struct _DejaDupOperationFilesPrivate {
	GFile* _source;
	gchar* _tag;
	DejaDupFileTree* tree;
};

struct _DejaDupOperationFilesOperationFinishedData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DejaDupOperationFiles* self;
	gboolean success;
	gboolean cancelled;
	gboolean _tmp0_;
	DejaDupFileTree* _tmp1_;
	DejaDupFileTree* _tmp2_;
};

static gint DejaDupOperationFiles_private_offset;
static gpointer deja_dup_operation_files_parent_class = NULL;

VALA_EXTERN void deja_dup_operation_operation_finished (DejaDupOperation* self,
                                            gboolean success,
                                            gboolean cancelled,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_);
VALA_EXTERN void deja_dup_operation_operation_finished_finish (DejaDupOperation* self,
                                                   GAsyncResult* _res_);
static void deja_dup_operation_files_real_connect_to_job (DejaDupOperation* base,
                                                   gboolean actions);
static void deja_dup_operation_files_handle_list_file (DejaDupOperationFiles* self,
                                                DejaDupToolJob* job,
                                                const gchar* file,
                                                GFileType type);
static void _deja_dup_operation_files_handle_list_file_deja_dup_tool_job_listed_current_files (DejaDupToolJob* _sender,
                                                                                        const gchar* file,
                                                                                        GFileType type,
                                                                                        gpointer self);
static void deja_dup_operation_files_real_operation_finished_data_free (gpointer _data);
static void deja_dup_operation_files_real_operation_finished (DejaDupOperation* base,
                                                       gboolean success,
                                                       gboolean cancelled,
                                                       GAsyncReadyCallback _callback_,
                                                       gpointer _user_data_);
static gboolean deja_dup_operation_files_real_operation_finished_co (DejaDupOperationFilesOperationFinishedData* _data_);
static void deja_dup_operation_files_operation_finished_ready (GObject* source_object,
                                                        GAsyncResult* _res_,
                                                        gpointer _user_data_);
static GList* deja_dup_operation_files_real_make_argv (DejaDupOperation* base);
static GObject * deja_dup_operation_files_constructor (GType type,
                                                guint n_construct_properties,
                                                GObjectConstructParam * construct_properties);
static void deja_dup_operation_files_finalize (GObject * obj);
static GType deja_dup_operation_files_get_type_once (void);
static void _vala_deja_dup_operation_files_get_property (GObject * object,
                                                  guint property_id,
                                                  GValue * value,
                                                  GParamSpec * pspec);
static void _vala_deja_dup_operation_files_set_property (GObject * object,
                                                  guint property_id,
                                                  const GValue * value,
                                                  GParamSpec * pspec);

static inline gpointer
deja_dup_operation_files_get_instance_private (DejaDupOperationFiles* self)
{
	return G_STRUCT_MEMBER_P (self, DejaDupOperationFiles_private_offset);
}

DejaDupOperationFiles*
deja_dup_operation_files_construct (GType object_type,
                                    DejaDupBackend* backend,
                                    const gchar* tag,
                                    GFile* source)
{
	DejaDupOperationFiles * self = NULL;
	g_return_val_if_fail (backend != NULL, NULL);
	g_return_val_if_fail (tag != NULL, NULL);
	self = (DejaDupOperationFiles*) g_object_new (object_type, "mode", DEJA_DUP_TOOL_JOB_MODE_LIST_FILES, "source", source, "backend", backend, "tag", tag, NULL);
	return self;
}

DejaDupOperationFiles*
deja_dup_operation_files_new (DejaDupBackend* backend,
                              const gchar* tag,
                              GFile* source)
{
	return deja_dup_operation_files_construct (DEJA_DUP_TYPE_OPERATION_FILES, backend, tag, source);
}

static void
_deja_dup_operation_files_handle_list_file_deja_dup_tool_job_listed_current_files (DejaDupToolJob* _sender,
                                                                                   const gchar* file,
                                                                                   GFileType type,
                                                                                   gpointer self)
{
	deja_dup_operation_files_handle_list_file ((DejaDupOperationFiles*) self, _sender, file, type);
}

static void
deja_dup_operation_files_real_connect_to_job (DejaDupOperation* base,
                                              gboolean actions)
{
	DejaDupOperationFiles * self;
	DejaDupToolJob* _tmp0_;
	self = (DejaDupOperationFiles*) base;
	_tmp0_ = ((DejaDupOperation*) self)->job;
	g_signal_connect_object (_tmp0_, "listed-current-files", (GCallback) _deja_dup_operation_files_handle_list_file_deja_dup_tool_job_listed_current_files, self, 0);
	DEJA_DUP_OPERATION_CLASS (deja_dup_operation_files_parent_class)->connect_to_job (G_TYPE_CHECK_INSTANCE_CAST (self, DEJA_DUP_TYPE_OPERATION, DejaDupOperation), actions);
}

static void
deja_dup_operation_files_handle_list_file (DejaDupOperationFiles* self,
                                           DejaDupToolJob* job,
                                           const gchar* file,
                                           GFileType type)
{
	DejaDupFileTree* _tmp0_;
	DejaDupFileTreeNode* _tmp1_;
	DejaDupFileTreeNode* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (job != NULL);
	g_return_if_fail (file != NULL);
	_tmp0_ = self->priv->tree;
	_tmp1_ = deja_dup_file_tree_add (_tmp0_, file, type, NULL);
	_tmp2_ = _tmp1_;
	_g_object_unref0 (_tmp2_);
}

static void
deja_dup_operation_files_real_operation_finished_data_free (gpointer _data)
{
	DejaDupOperationFilesOperationFinishedData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (DejaDupOperationFilesOperationFinishedData, _data_);
}

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

static void
deja_dup_operation_files_real_operation_finished (DejaDupOperation* base,
                                                  gboolean success,
                                                  gboolean cancelled,
                                                  GAsyncReadyCallback _callback_,
                                                  gpointer _user_data_)
{
	DejaDupOperationFiles * self;
	DejaDupOperationFilesOperationFinishedData* _data_;
	DejaDupOperationFiles* _tmp0_;
	self = (DejaDupOperationFiles*) base;
	_data_ = g_slice_new0 (DejaDupOperationFilesOperationFinishedData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, deja_dup_operation_files_real_operation_finished_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->success = success;
	_data_->cancelled = cancelled;
	deja_dup_operation_files_real_operation_finished_co (_data_);
}

static void
deja_dup_operation_files_operation_finished_finish (DejaDupOperation* base,
                                                    GAsyncResult* _res_)
{
	DejaDupOperationFilesOperationFinishedData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
deja_dup_operation_files_operation_finished_ready (GObject* source_object,
                                                   GAsyncResult* _res_,
                                                   gpointer _user_data_)
{
	DejaDupOperationFilesOperationFinishedData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	deja_dup_operation_files_real_operation_finished_co (_data_);
}

static gboolean
deja_dup_operation_files_real_operation_finished_co (DejaDupOperationFilesOperationFinishedData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	if (_data_->success) {
		_data_->_tmp0_ = !_data_->cancelled;
	} else {
		_data_->_tmp0_ = FALSE;
	}
	if (_data_->_tmp0_) {
		_data_->_tmp1_ = _data_->self->priv->tree;
		deja_dup_file_tree_finish (_data_->_tmp1_);
		_data_->_tmp2_ = _data_->self->priv->tree;
		g_signal_emit (_data_->self, deja_dup_operation_files_signals[DEJA_DUP_OPERATION_FILES_LISTED_CURRENT_FILES_SIGNAL], 0, _data_->_tmp2_);
	}
	_data_->_state_ = 1;
	DEJA_DUP_OPERATION_CLASS (deja_dup_operation_files_parent_class)->operation_finished (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, DEJA_DUP_TYPE_OPERATION, DejaDupOperation), _data_->success, _data_->cancelled, deja_dup_operation_files_operation_finished_ready, _data_);
	return FALSE;
	_state_1:
	DEJA_DUP_OPERATION_CLASS (deja_dup_operation_files_parent_class)->operation_finished_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, DEJA_DUP_TYPE_OPERATION, DejaDupOperation), _data_->_res_);
	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;
}

static GList*
deja_dup_operation_files_real_make_argv (DejaDupOperation* base)
{
	DejaDupOperationFiles * self;
	DejaDupToolJob* _tmp0_;
	const gchar* _tmp1_;
	DejaDupToolJob* _tmp2_;
	GFile* _tmp3_;
	GList* result;
	self = (DejaDupOperationFiles*) base;
	_tmp0_ = ((DejaDupOperation*) self)->job;
	_tmp1_ = self->priv->_tag;
	deja_dup_tool_job_set_tag (_tmp0_, _tmp1_);
	_tmp2_ = ((DejaDupOperation*) self)->job;
	_tmp3_ = self->priv->_source;
	deja_dup_tool_job_set_local (_tmp2_, _tmp3_);
	result = NULL;
	return result;
}

GFile*
deja_dup_operation_files_get_source (DejaDupOperationFiles* self)
{
	GFile* result;
	GFile* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_source;
	result = _tmp0_;
	return result;
}

static void
deja_dup_operation_files_set_source (DejaDupOperationFiles* self,
                                     GFile* value)
{
	GFile* old_value;
	g_return_if_fail (self != NULL);
	old_value = deja_dup_operation_files_get_source (self);
	if (old_value != value) {
		GFile* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_source);
		self->priv->_source = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, deja_dup_operation_files_properties[DEJA_DUP_OPERATION_FILES_SOURCE_PROPERTY]);
	}
}

const gchar*
deja_dup_operation_files_get_tag (DejaDupOperationFiles* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_tag;
	result = _tmp0_;
	return result;
}

static void
deja_dup_operation_files_set_tag (DejaDupOperationFiles* self,
                                  const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = deja_dup_operation_files_get_tag (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_tag);
		self->priv->_tag = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, deja_dup_operation_files_properties[DEJA_DUP_OPERATION_FILES_TAG_PROPERTY]);
	}
}

static GObject *
deja_dup_operation_files_constructor (GType type,
                                      guint n_construct_properties,
                                      GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	DejaDupOperationFiles * self;
	DejaDupFileTree* _tmp0_;
	parent_class = G_OBJECT_CLASS (deja_dup_operation_files_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DEJA_DUP_TYPE_OPERATION_FILES, DejaDupOperationFiles);
	_tmp0_ = deja_dup_file_tree_new ();
	_g_object_unref0 (self->priv->tree);
	self->priv->tree = _tmp0_;
	return obj;
}

static void
deja_dup_operation_files_class_init (DejaDupOperationFilesClass * klass,
                                     gpointer klass_data)
{
	deja_dup_operation_files_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DejaDupOperationFiles_private_offset);
	((DejaDupOperationClass *) klass)->connect_to_job = (void (*) (DejaDupOperation*, gboolean)) deja_dup_operation_files_real_connect_to_job;
	((DejaDupOperationClass *) klass)->operation_finished = (void (*) (DejaDupOperation*, gboolean, gboolean, GAsyncReadyCallback, gpointer)) deja_dup_operation_files_real_operation_finished;
	((DejaDupOperationClass *) klass)->operation_finished_finish = (void (*) (DejaDupOperation*, GAsyncResult*)) deja_dup_operation_files_operation_finished_finish;
	((DejaDupOperationClass *) klass)->make_argv = (GList* (*) (DejaDupOperation*)) deja_dup_operation_files_real_make_argv;
	G_OBJECT_CLASS (klass)->get_property = _vala_deja_dup_operation_files_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_deja_dup_operation_files_set_property;
	G_OBJECT_CLASS (klass)->constructor = deja_dup_operation_files_constructor;
	G_OBJECT_CLASS (klass)->finalize = deja_dup_operation_files_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DEJA_DUP_OPERATION_FILES_SOURCE_PROPERTY, deja_dup_operation_files_properties[DEJA_DUP_OPERATION_FILES_SOURCE_PROPERTY] = g_param_spec_object ("source", "source", "source", g_file_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), DEJA_DUP_OPERATION_FILES_TAG_PROPERTY, deja_dup_operation_files_properties[DEJA_DUP_OPERATION_FILES_TAG_PROPERTY] = g_param_spec_string ("tag", "tag", "tag", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	deja_dup_operation_files_signals[DEJA_DUP_OPERATION_FILES_LISTED_CURRENT_FILES_SIGNAL] = g_signal_new ("listed-current-files", DEJA_DUP_TYPE_OPERATION_FILES, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, DEJA_DUP_TYPE_FILE_TREE);
}

static void
deja_dup_operation_files_instance_init (DejaDupOperationFiles * self,
                                        gpointer klass)
{
	self->priv = deja_dup_operation_files_get_instance_private (self);
	self->priv->tree = NULL;
}

static void
deja_dup_operation_files_finalize (GObject * obj)
{
	DejaDupOperationFiles * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DEJA_DUP_TYPE_OPERATION_FILES, DejaDupOperationFiles);
	_g_object_unref0 (self->priv->_source);
	_g_free0 (self->priv->_tag);
	_g_object_unref0 (self->priv->tree);
	G_OBJECT_CLASS (deja_dup_operation_files_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
deja_dup_operation_files_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DejaDupOperationFilesClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) deja_dup_operation_files_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DejaDupOperationFiles), 0, (GInstanceInitFunc) deja_dup_operation_files_instance_init, NULL };
	GType deja_dup_operation_files_type_id;
	deja_dup_operation_files_type_id = g_type_register_static (DEJA_DUP_TYPE_OPERATION, "DejaDupOperationFiles", &g_define_type_info, G_TYPE_FLAG_NONE);
	DejaDupOperationFiles_private_offset = g_type_add_instance_private (deja_dup_operation_files_type_id, sizeof (DejaDupOperationFilesPrivate));
	return deja_dup_operation_files_type_id;
}

GType
deja_dup_operation_files_get_type (void)
{
	static GType deja_dup_operation_files_type_id__once = 0;
	if (g_once_init_enter_pointer (&deja_dup_operation_files_type_id__once)) {
		GType deja_dup_operation_files_type_id;
		deja_dup_operation_files_type_id = deja_dup_operation_files_get_type_once ();
		g_once_init_leave_pointer (&deja_dup_operation_files_type_id__once, deja_dup_operation_files_type_id);
	}
	return deja_dup_operation_files_type_id__once;
}

static void
_vala_deja_dup_operation_files_get_property (GObject * object,
                                             guint property_id,
                                             GValue * value,
                                             GParamSpec * pspec)
{
	DejaDupOperationFiles * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DEJA_DUP_TYPE_OPERATION_FILES, DejaDupOperationFiles);
	switch (property_id) {
		case DEJA_DUP_OPERATION_FILES_SOURCE_PROPERTY:
		g_value_set_object (value, deja_dup_operation_files_get_source (self));
		break;
		case DEJA_DUP_OPERATION_FILES_TAG_PROPERTY:
		g_value_set_string (value, deja_dup_operation_files_get_tag (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_deja_dup_operation_files_set_property (GObject * object,
                                             guint property_id,
                                             const GValue * value,
                                             GParamSpec * pspec)
{
	DejaDupOperationFiles * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DEJA_DUP_TYPE_OPERATION_FILES, DejaDupOperationFiles);
	switch (property_id) {
		case DEJA_DUP_OPERATION_FILES_SOURCE_PROPERTY:
		deja_dup_operation_files_set_source (self, g_value_get_object (value));
		break;
		case DEJA_DUP_OPERATION_FILES_TAG_PROPERTY:
		deja_dup_operation_files_set_tag (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

