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

/*
 * Copyright (C) 2013-2017 elementary Developers
 *
 * 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, see <http://www.gnu.org/licenses/>.
 */

#include <glib-object.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gee.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
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define CONTRACTOR_TYPE_CONTRACT_FILE_ENUMERATOR (contractor_contract_file_enumerator_get_type ())
#define CONTRACTOR_CONTRACT_FILE_ENUMERATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONTRACTOR_TYPE_CONTRACT_FILE_ENUMERATOR, ContractorContractFileEnumerator))
#define CONTRACTOR_CONTRACT_FILE_ENUMERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONTRACTOR_TYPE_CONTRACT_FILE_ENUMERATOR, ContractorContractFileEnumeratorClass))
#define CONTRACTOR_IS_CONTRACT_FILE_ENUMERATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONTRACTOR_TYPE_CONTRACT_FILE_ENUMERATOR))
#define CONTRACTOR_IS_CONTRACT_FILE_ENUMERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONTRACTOR_TYPE_CONTRACT_FILE_ENUMERATOR))
#define CONTRACTOR_CONTRACT_FILE_ENUMERATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONTRACTOR_TYPE_CONTRACT_FILE_ENUMERATOR, ContractorContractFileEnumeratorClass))

typedef struct _ContractorContractFileEnumerator ContractorContractFileEnumerator;
typedef struct _ContractorContractFileEnumeratorClass ContractorContractFileEnumeratorClass;
typedef struct _ContractorContractFileEnumeratorPrivate ContractorContractFileEnumeratorPrivate;
enum  {
	CONTRACTOR_CONTRACT_FILE_ENUMERATOR_0_PROPERTY,
	CONTRACTOR_CONTRACT_FILE_ENUMERATOR_NUM_PROPERTIES
};
static GParamSpec* contractor_contract_file_enumerator_properties[CONTRACTOR_CONTRACT_FILE_ENUMERATOR_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))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _ContractorContractFileEnumerator {
	GObject parent_instance;
	ContractorContractFileEnumeratorPrivate * priv;
};

struct _ContractorContractFileEnumeratorClass {
	GObjectClass parent_class;
};

struct _ContractorContractFileEnumeratorPrivate {
	GFile* directory;
};

static gint ContractorContractFileEnumerator_private_offset;
static gpointer contractor_contract_file_enumerator_parent_class = NULL;
static gchar* contractor_contract_file_enumerator_attributes;
static gchar* contractor_contract_file_enumerator_attributes = NULL;

VALA_EXTERN GType contractor_contract_file_enumerator_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ContractorContractFileEnumerator, g_object_unref)
VALA_EXTERN ContractorContractFileEnumerator* contractor_contract_file_enumerator_new (GFile* directory);
VALA_EXTERN ContractorContractFileEnumerator* contractor_contract_file_enumerator_construct (GType object_type,
                                                                                 GFile* directory);
VALA_EXTERN GeeList* contractor_contract_file_enumerator_enumerate_files (ContractorContractFileEnumerator* self);
VALA_EXTERN gboolean contractor_contract_file_is_valid_filename (const gchar* filename);
static void contractor_contract_file_enumerator_finalize (GObject * obj);
static GType contractor_contract_file_enumerator_get_type_once (void);

static const gchar* CONTRACTOR_CONTRACT_FILE_ENUMERATOR_QUERY_ATTRIBUTES[2] = {G_FILE_ATTRIBUTE_STANDARD_NAME, G_FILE_ATTRIBUTE_STANDARD_TYPE};

static inline gpointer
contractor_contract_file_enumerator_get_instance_private (ContractorContractFileEnumerator* self)
{
	return G_STRUCT_MEMBER_P (self, ContractorContractFileEnumerator_private_offset);
}

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

ContractorContractFileEnumerator*
contractor_contract_file_enumerator_construct (GType object_type,
                                               GFile* directory)
{
	ContractorContractFileEnumerator * self = NULL;
	GFile* _tmp0_;
	g_return_val_if_fail (directory != NULL, NULL);
	self = (ContractorContractFileEnumerator*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (directory);
	_g_object_unref0 (self->priv->directory);
	self->priv->directory = _tmp0_;
	return self;
}

ContractorContractFileEnumerator*
contractor_contract_file_enumerator_new (GFile* directory)
{
	return contractor_contract_file_enumerator_construct (CONTRACTOR_TYPE_CONTRACT_FILE_ENUMERATOR, directory);
}

GeeList*
contractor_contract_file_enumerator_enumerate_files (ContractorContractFileEnumerator* self)
{
	GeeLinkedList* files = NULL;
	GeeLinkedList* _tmp0_;
	GFile* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	GError* _inner_error0_ = NULL;
	GeeList* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = gee_linked_list_new (g_file_get_type (), (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	files = _tmp0_;
	_tmp1_ = self->priv->directory;
	_tmp2_ = g_file_get_path (_tmp1_);
	_tmp3_ = _tmp2_;
	g_message ("FileEnumerator.vala:39: Looking up contracts in: %s", _tmp3_);
	_g_free0 (_tmp3_);
	{
		GFileEnumerator* enumerator = NULL;
		GFile* _tmp4_;
		const gchar* _tmp5_;
		GFileEnumerator* _tmp6_;
		GFileInfo* f = NULL;
		_tmp4_ = self->priv->directory;
		_tmp5_ = contractor_contract_file_enumerator_attributes;
		_tmp6_ = g_file_enumerate_children (_tmp4_, _tmp5_, G_FILE_QUERY_INFO_NONE, NULL, &_inner_error0_);
		enumerator = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		while (TRUE) {
			GFileInfo* _tmp7_ = NULL;
			GFileEnumerator* _tmp8_;
			GFileInfo* _tmp9_;
			GFileInfo* _tmp10_;
			GFileInfo* _tmp11_;
			const gchar* name = NULL;
			GFileInfo* _tmp12_;
			const gchar* _tmp13_;
			GFileType file_type = 0;
			GFileInfo* _tmp14_;
			GFile* child = NULL;
			GFile* _tmp15_;
			const gchar* _tmp16_;
			GFile* _tmp17_;
			_tmp8_ = enumerator;
			_tmp9_ = g_file_enumerator_next_file (_tmp8_, NULL, &_inner_error0_);
			_tmp7_ = _tmp9_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				_g_object_unref0 (f);
				_g_object_unref0 (enumerator);
				goto __catch0_g_error;
			}
			_tmp10_ = _tmp7_;
			_tmp7_ = NULL;
			_g_object_unref0 (f);
			f = _tmp10_;
			_tmp11_ = f;
			if (!(_tmp11_ != NULL)) {
				_g_object_unref0 (_tmp7_);
				break;
			}
			_tmp12_ = f;
			_tmp13_ = g_file_info_get_name (_tmp12_);
			name = _tmp13_;
			_tmp14_ = f;
			file_type = g_file_info_get_file_type (_tmp14_);
			_tmp15_ = self->priv->directory;
			_tmp16_ = name;
			_tmp17_ = g_file_get_child (_tmp15_, _tmp16_);
			child = _tmp17_;
			if (file_type == G_FILE_TYPE_REGULAR) {
				const gchar* _tmp18_;
				_tmp18_ = name;
				if (contractor_contract_file_is_valid_filename (_tmp18_)) {
					GeeLinkedList* _tmp19_;
					GFile* _tmp20_;
					_tmp19_ = files;
					_tmp20_ = child;
					gee_abstract_collection_add ((GeeAbstractCollection*) _tmp19_, _tmp20_);
				}
			} else {
				GFile* _tmp21_;
				gchar* _tmp22_;
				gchar* _tmp23_;
				_tmp21_ = child;
				_tmp22_ = g_file_get_path (_tmp21_);
				_tmp23_ = _tmp22_;
				g_warning ("FileEnumerator.vala:56: '%s' is not a regular file. Skipping it...", _tmp23_);
				_g_free0 (_tmp23_);
			}
			_g_object_unref0 (child);
			_g_object_unref0 (_tmp7_);
		}
		_g_object_unref0 (f);
		_g_object_unref0 (enumerator);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* err = NULL;
		GFile* _tmp24_;
		gchar* _tmp25_;
		gchar* _tmp26_;
		GError* _tmp27_;
		const gchar* _tmp28_;
		err = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp24_ = self->priv->directory;
		_tmp25_ = g_file_get_path (_tmp24_);
		_tmp26_ = _tmp25_;
		_tmp27_ = err;
		_tmp28_ = _tmp27_->message;
		g_warning ("FileEnumerator.vala:60: Could not process directory '%s': %s", _tmp26_, _tmp28_);
		_g_free0 (_tmp26_);
		_g_error_free0 (err);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (files);
		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 NULL;
	}
	result = (GeeList*) files;
	return result;
}

static gchar*
_vala_g_strjoinv (const gchar* separator,
                  gchar** str_array,
                  gint str_array_length1)
{
	gboolean _tmp0_ = FALSE;
	gchar* result;
	if (separator == NULL) {
		separator = "";
	}
	if (str_array != NULL) {
		gboolean _tmp1_ = FALSE;
		if (str_array_length1 > 0) {
			_tmp1_ = TRUE;
		} else {
			gboolean _tmp2_ = FALSE;
			if (str_array_length1 == -1) {
				const gchar* _tmp3_;
				_tmp3_ = str_array[0];
				_tmp2_ = _tmp3_ != NULL;
			} else {
				_tmp2_ = FALSE;
			}
			_tmp1_ = _tmp2_;
		}
		_tmp0_ = _tmp1_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		gint i = 0;
		gsize len = 0UL;
		gint _tmp16_;
		gint _tmp17_;
		const gchar* res = NULL;
		void* _tmp18_;
		const gchar* _tmp19_ = NULL;
		const gchar* _tmp20_;
		void* ptr = NULL;
		const gchar* _tmp22_;
		void* _tmp23_;
		const gchar* _tmp33_;
		len = (gsize) 1;
		{
			gboolean _tmp4_ = FALSE;
			i = 0;
			_tmp4_ = TRUE;
			while (TRUE) {
				gboolean _tmp6_ = FALSE;
				gboolean _tmp7_ = FALSE;
				gint _tmp10_ = 0;
				const gchar* _tmp11_;
				if (!_tmp4_) {
					gint _tmp5_;
					_tmp5_ = i;
					i = _tmp5_ + 1;
				}
				_tmp4_ = FALSE;
				if (str_array_length1 != -1) {
					_tmp7_ = i < str_array_length1;
				} else {
					_tmp7_ = FALSE;
				}
				if (_tmp7_) {
					_tmp6_ = TRUE;
				} else {
					gboolean _tmp8_ = FALSE;
					if (str_array_length1 == -1) {
						const gchar* _tmp9_;
						_tmp9_ = str_array[i];
						_tmp8_ = _tmp9_ != NULL;
					} else {
						_tmp8_ = FALSE;
					}
					_tmp6_ = _tmp8_;
				}
				if (!_tmp6_) {
					break;
				}
				_tmp11_ = str_array[i];
				if (_tmp11_ != NULL) {
					const gchar* _tmp12_;
					gint _tmp13_;
					gint _tmp14_;
					_tmp12_ = str_array[i];
					_tmp13_ = strlen ((const gchar*) _tmp12_);
					_tmp14_ = _tmp13_;
					_tmp10_ = _tmp14_;
				} else {
					_tmp10_ = 0;
				}
				len += (gsize) _tmp10_;
			}
		}
		if (i == 0) {
			gchar* _tmp15_;
			_tmp15_ = g_strdup ("");
			result = _tmp15_;
			return result;
		}
		str_array_length1 = i;
		_tmp16_ = strlen ((const gchar*) separator);
		_tmp17_ = _tmp16_;
		len += (gsize) (_tmp17_ * (i - 1));
		_tmp18_ = g_malloc (len);
		res = _tmp18_;
		_tmp20_ = str_array[0];
		if (_tmp20_ != NULL) {
			const gchar* _tmp21_;
			_tmp21_ = str_array[0];
			_tmp19_ = (const gchar*) _tmp21_;
		} else {
			_tmp19_ = "";
		}
		_tmp22_ = res;
		_tmp23_ = g_stpcpy ((void*) _tmp22_, _tmp19_);
		ptr = _tmp23_;
		{
			gboolean _tmp24_ = FALSE;
			i = 1;
			_tmp24_ = TRUE;
			while (TRUE) {
				void* _tmp26_;
				void* _tmp27_;
				const gchar* _tmp28_ = NULL;
				const gchar* _tmp29_;
				void* _tmp31_;
				void* _tmp32_;
				if (!_tmp24_) {
					gint _tmp25_;
					_tmp25_ = i;
					i = _tmp25_ + 1;
				}
				_tmp24_ = FALSE;
				if (!(i < str_array_length1)) {
					break;
				}
				_tmp26_ = ptr;
				_tmp27_ = g_stpcpy (_tmp26_, (const gchar*) separator);
				ptr = _tmp27_;
				_tmp29_ = str_array[i];
				if (_tmp29_ != NULL) {
					const gchar* _tmp30_;
					_tmp30_ = str_array[i];
					_tmp28_ = (const gchar*) _tmp30_;
				} else {
					_tmp28_ = "";
				}
				_tmp31_ = ptr;
				_tmp32_ = g_stpcpy (_tmp31_, _tmp28_);
				ptr = _tmp32_;
			}
		}
		_tmp33_ = res;
		res = NULL;
		result = (gchar*) _tmp33_;
		return result;
	} else {
		gchar* _tmp34_;
		_tmp34_ = g_strdup ("");
		result = _tmp34_;
		return result;
	}
}

static void
contractor_contract_file_enumerator_class_init (ContractorContractFileEnumeratorClass * klass,
                                                gpointer klass_data)
{
	gchar* _tmp0_;
	contractor_contract_file_enumerator_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ContractorContractFileEnumerator_private_offset);
	G_OBJECT_CLASS (klass)->finalize = contractor_contract_file_enumerator_finalize;
	_tmp0_ = _vala_g_strjoinv (",", CONTRACTOR_CONTRACT_FILE_ENUMERATOR_QUERY_ATTRIBUTES, (gint) G_N_ELEMENTS (CONTRACTOR_CONTRACT_FILE_ENUMERATOR_QUERY_ATTRIBUTES));
	_g_free0 (contractor_contract_file_enumerator_attributes);
	contractor_contract_file_enumerator_attributes = _tmp0_;
}

static void
contractor_contract_file_enumerator_instance_init (ContractorContractFileEnumerator * self,
                                                   gpointer klass)
{
	self->priv = contractor_contract_file_enumerator_get_instance_private (self);
}

static void
contractor_contract_file_enumerator_finalize (GObject * obj)
{
	ContractorContractFileEnumerator * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CONTRACTOR_TYPE_CONTRACT_FILE_ENUMERATOR, ContractorContractFileEnumerator);
	_g_object_unref0 (self->priv->directory);
	G_OBJECT_CLASS (contractor_contract_file_enumerator_parent_class)->finalize (obj);
}

static GType
contractor_contract_file_enumerator_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ContractorContractFileEnumeratorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) contractor_contract_file_enumerator_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ContractorContractFileEnumerator), 0, (GInstanceInitFunc) contractor_contract_file_enumerator_instance_init, NULL };
	GType contractor_contract_file_enumerator_type_id;
	contractor_contract_file_enumerator_type_id = g_type_register_static (G_TYPE_OBJECT, "ContractorContractFileEnumerator", &g_define_type_info, 0);
	ContractorContractFileEnumerator_private_offset = g_type_add_instance_private (contractor_contract_file_enumerator_type_id, sizeof (ContractorContractFileEnumeratorPrivate));
	return contractor_contract_file_enumerator_type_id;
}

GType
contractor_contract_file_enumerator_get_type (void)
{
	static volatile gsize contractor_contract_file_enumerator_type_id__once = 0;
	if (g_once_init_enter (&contractor_contract_file_enumerator_type_id__once)) {
		GType contractor_contract_file_enumerator_type_id;
		contractor_contract_file_enumerator_type_id = contractor_contract_file_enumerator_get_type_once ();
		g_once_init_leave (&contractor_contract_file_enumerator_type_id__once, contractor_contract_file_enumerator_type_id);
	}
	return contractor_contract_file_enumerator_type_id__once;
}

