/* CreateJob.c generated by valac 0.56.19, the Vala compiler
 * generated from CreateJob.vala, do not modify */

/* Copyright 2022 elementary LLC (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, Inc.,; either version 2 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.
 */

#include "pantheon-files-core.h"
#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <gio/gio.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

#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _files_undo_action_data_unref0(var) ((var == NULL) ? NULL : (var = (files_undo_action_data_unref (var), NULL)))

static gpointer marlin_file_operations_create_job_parent_class = NULL;

static guint8* _vala_array_dup4 (guint8* self,
                          gssize length);
static void marlin_file_operations_create_job_finalize (FilesFileOperationsCommonJob * obj);
static GType marlin_file_operations_create_job_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

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

FilesFileOperationsCreateJob*
marlin_file_operations_create_job_construct_folder (GType object_type,
                                                    GtkWindow* parent_window,
                                                    GFile* dest_dir)
{
	FilesFileOperationsCreateJob* self = NULL;
	GFile* _tmp0_;
	FilesUndoActionData* _tmp1_;
	g_return_val_if_fail (dest_dir != NULL, NULL);
	self = (FilesFileOperationsCreateJob*) marlin_file_operations_common_job_construct (object_type, parent_window);
	_tmp0_ = _g_object_ref0 (dest_dir);
	_g_object_unref0 (self->dest_dir);
	self->dest_dir = _tmp0_;
	self->make_dir = TRUE;
	_tmp1_ = files_undo_action_data_new (MARLIN_UNDO_CREATEFOLDER, 1);
	_files_undo_action_data_unref0 (((FilesFileOperationsCommonJob*) self)->undo_redo_data);
	((FilesFileOperationsCommonJob*) self)->undo_redo_data = _tmp1_;
	return self;
}

FilesFileOperationsCreateJob*
marlin_file_operations_create_job_new_folder (GtkWindow* parent_window,
                                              GFile* dest_dir)
{
	return marlin_file_operations_create_job_construct_folder (MARLIN_FILE_OPERATIONS_TYPE_CREATE_JOB, parent_window, dest_dir);
}

FilesFileOperationsCreateJob*
marlin_file_operations_create_job_construct_file_from_template (GType object_type,
                                                                GtkWindow* parent_window,
                                                                GFile* dest_dir,
                                                                const gchar* target_filename,
                                                                GFile* src)
{
	FilesFileOperationsCreateJob* self = NULL;
	GFile* _tmp0_;
	gchar* _tmp1_;
	GFile* _tmp2_;
	FilesUndoActionData* _tmp3_;
	g_return_val_if_fail (dest_dir != NULL, NULL);
	g_return_val_if_fail (target_filename != NULL, NULL);
	self = (FilesFileOperationsCreateJob*) marlin_file_operations_common_job_construct (object_type, parent_window);
	_tmp0_ = _g_object_ref0 (dest_dir);
	_g_object_unref0 (self->dest_dir);
	self->dest_dir = _tmp0_;
	_tmp1_ = g_strdup (target_filename);
	_g_free0 (self->filename);
	self->filename = _tmp1_;
	_tmp2_ = _g_object_ref0 (src);
	_g_object_unref0 (self->src);
	self->src = _tmp2_;
	_tmp3_ = files_undo_action_data_new (MARLIN_UNDO_CREATEFILEFROMTEMPLATE, 1);
	_files_undo_action_data_unref0 (((FilesFileOperationsCommonJob*) self)->undo_redo_data);
	((FilesFileOperationsCommonJob*) self)->undo_redo_data = _tmp3_;
	return self;
}

FilesFileOperationsCreateJob*
marlin_file_operations_create_job_new_file_from_template (GtkWindow* parent_window,
                                                          GFile* dest_dir,
                                                          const gchar* target_filename,
                                                          GFile* src)
{
	return marlin_file_operations_create_job_construct_file_from_template (MARLIN_FILE_OPERATIONS_TYPE_CREATE_JOB, parent_window, dest_dir, target_filename, src);
}

static guint8*
_vala_array_dup4 (guint8* self,
                  gssize length)
{
	if (length > 0) {
		return _vala_memdup2 (self, length * sizeof (guint8));
	}
	return NULL;
}

FilesFileOperationsCreateJob*
marlin_file_operations_create_job_construct_file (GType object_type,
                                                  GtkWindow* parent_window,
                                                  GFile* dest_dir,
                                                  const gchar* target_filename,
                                                  guint8* src_data,
                                                  gint length)
{
	FilesFileOperationsCreateJob* self = NULL;
	GFile* _tmp0_;
	gchar* _tmp1_;
	guint8* _tmp2_;
	gint _tmp2__length1;
	FilesUndoActionData* _tmp3_;
	g_return_val_if_fail (dest_dir != NULL, NULL);
	self = (FilesFileOperationsCreateJob*) marlin_file_operations_common_job_construct (object_type, parent_window);
	_tmp0_ = _g_object_ref0 (dest_dir);
	_g_object_unref0 (self->dest_dir);
	self->dest_dir = _tmp0_;
	_tmp1_ = g_strdup (target_filename);
	_g_free0 (self->filename);
	self->filename = _tmp1_;
	_tmp2_ = (src_data != NULL) ? _vala_array_dup4 (src_data, length) : src_data;
	_tmp2__length1 = length;
	self->src_data = (g_free (self->src_data), NULL);
	self->src_data = _tmp2_;
	self->length = _tmp2__length1;
	_tmp3_ = files_undo_action_data_new (MARLIN_UNDO_CREATEEMPTYFILE, 1);
	_files_undo_action_data_unref0 (((FilesFileOperationsCommonJob*) self)->undo_redo_data);
	((FilesFileOperationsCommonJob*) self)->undo_redo_data = _tmp3_;
	return self;
}

FilesFileOperationsCreateJob*
marlin_file_operations_create_job_new_file (GtkWindow* parent_window,
                                            GFile* dest_dir,
                                            const gchar* target_filename,
                                            guint8* src_data,
                                            gint length)
{
	return marlin_file_operations_create_job_construct_file (MARLIN_FILE_OPERATIONS_TYPE_CREATE_JOB, parent_window, dest_dir, target_filename, src_data, length);
}

FilesFileOperationsCreateJob*
marlin_file_operations_create_job_construct (GType object_type)
{
	FilesFileOperationsCreateJob* self = NULL;
	self = (FilesFileOperationsCreateJob*) marlin_file_operations_common_job_construct (object_type, NULL);
	return self;
}

FilesFileOperationsCreateJob*
marlin_file_operations_create_job_new (void)
{
	return marlin_file_operations_create_job_construct (MARLIN_FILE_OPERATIONS_TYPE_CREATE_JOB);
}

static void
marlin_file_operations_create_job_class_init (FilesFileOperationsCreateJobClass * klass,
                                              gpointer klass_data)
{
	marlin_file_operations_create_job_parent_class = g_type_class_peek_parent (klass);
	((FilesFileOperationsCommonJobClass *) klass)->finalize = marlin_file_operations_create_job_finalize;
}

static void
marlin_file_operations_create_job_instance_init (FilesFileOperationsCreateJob * self,
                                                 gpointer klass)
{
}

static void
marlin_file_operations_create_job_finalize (FilesFileOperationsCommonJob * obj)
{
	FilesFileOperationsCreateJob * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, MARLIN_FILE_OPERATIONS_TYPE_CREATE_JOB, FilesFileOperationsCreateJob);
	files_file_changes_consume_changes (TRUE);
	_g_object_unref0 (self->dest_dir);
	_g_free0 (self->filename);
	_g_object_unref0 (self->src);
	self->src_data = (g_free (self->src_data), NULL);
	_g_object_unref0 (self->created_file);
	MARLIN_FILE_OPERATIONS_COMMON_JOB_CLASS (marlin_file_operations_create_job_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
marlin_file_operations_create_job_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FilesFileOperationsCreateJobClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) marlin_file_operations_create_job_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FilesFileOperationsCreateJob), 0, (GInstanceInitFunc) marlin_file_operations_create_job_instance_init, NULL };
	GType marlin_file_operations_create_job_type_id;
	marlin_file_operations_create_job_type_id = g_type_register_static (MARLIN_FILE_OPERATIONS_TYPE_COMMON_JOB, "FilesFileOperationsCreateJob", &g_define_type_info, 0);
	return marlin_file_operations_create_job_type_id;
}

GType
marlin_file_operations_create_job_get_type (void)
{
	static volatile gsize marlin_file_operations_create_job_type_id__once = 0;
	if (g_once_init_enter (&marlin_file_operations_create_job_type_id__once)) {
		GType marlin_file_operations_create_job_type_id;
		marlin_file_operations_create_job_type_id = marlin_file_operations_create_job_get_type_once ();
		g_once_init_leave (&marlin_file_operations_create_job_type_id__once, marlin_file_operations_create_job_type_id);
	}
	return marlin_file_operations_create_job_type_id__once;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

