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

/*
 * SPDX-License-Identifier: GPL-3.0-or-later
 * SPDX-FileCopyrightText: 2023 elementary, Inc. <https://elementary.io>
 *
 * Authored by: Marvin Ahlgrimm
 *              Colin Kiama <colinkiama@gmail.com>
 */

#include "fuzzy-search.h"
#include <glib-object.h>
#include <glib.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

enum  {
	FILE_ITEM_0_PROPERTY,
	FILE_ITEM_RESULT_PROPERTY,
	FILE_ITEM_FILEPATH_PROPERTY,
	FILE_ITEM_NUM_PROPERTIES
};
static GParamSpec* file_item_properties[FILE_ITEM_NUM_PROPERTIES];
#define _search_result_unref0(var) ((var == NULL) ? NULL : (var = (search_result_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _FileItemPrivate {
	SearchResult* _result;
};

static gint FileItem_private_offset;
static gpointer file_item_parent_class = NULL;
static GType file_item_type_id = 0;

static void file_item_set_result (FileItem* self,
                           SearchResult* value);
static void file_item_finalize (GObject * obj);
static void _vala_file_item_get_property (GObject * object,
                                   guint property_id,
                                   GValue * value,
                                   GParamSpec * pspec);
static void _vala_file_item_set_property (GObject * object,
                                   guint property_id,
                                   const GValue * value,
                                   GParamSpec * pspec);

static inline gpointer
file_item_get_instance_private (FileItem* self)
{
	return G_STRUCT_MEMBER_P (self, FileItem_private_offset);
}

static const gchar*
string_to_string (const gchar* self)
{
	const gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	result = self;
	return result;
}

FileItem*
file_item_construct (GType object_type,
                     SearchResult* res,
                     gboolean should_distinguish_project)
{
	FileItem * self = NULL;
	GtkStyleContext* _tmp0_;
	GtkStyleContext* _tmp1_;
	GIcon* icon = NULL;
	GtkBox* path_box = NULL;
	GtkBox* _tmp2_;
	GtkBox* _tmp3_;
	gchar* _tmp4_ = NULL;
	GtkLabel* path_label = NULL;
	const gchar* _tmp9_;
	SearchResult* _tmp10_;
	const gchar* _tmp11_;
	const gchar* _tmp12_;
	gchar* _tmp13_;
	gchar* _tmp14_;
	GtkLabel* _tmp15_;
	GtkLabel* _tmp16_;
	GtkLabel* filename_label = NULL;
	SearchResult* _tmp17_;
	const gchar* _tmp18_;
	gchar* _tmp19_;
	gchar* _tmp20_;
	GtkLabel* _tmp21_;
	GtkLabel* _tmp22_;
	GtkImage* image = NULL;
	GIcon* _tmp30_;
	GtkImage* _tmp31_;
	GtkStyleContext* _tmp32_;
	GtkBox* _tmp33_;
	GtkBox* _tmp34_;
	GtkBox* container_box = NULL;
	GtkBox* _tmp35_ = NULL;
	GtkBox* _tmp36_;
	GError* _inner_error0_ = NULL;
	g_return_val_if_fail (res != NULL, NULL);
	self = (FileItem*) g_object_new (object_type, NULL);
	_tmp0_ = gtk_widget_get_style_context ((GtkWidget*) self);
	gtk_style_context_add_class (_tmp0_, "fuzzy-item");
	_tmp1_ = gtk_widget_get_style_context ((GtkWidget*) self);
	gtk_style_context_add_class (_tmp1_, "flat");
	file_item_set_result (self, res);
	_tmp2_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 1);
	g_object_ref_sink (_tmp2_);
	path_box = _tmp2_;
	_tmp3_ = path_box;
	gtk_widget_set_valign ((GtkWidget*) _tmp3_, GTK_ALIGN_CENTER);
	if (should_distinguish_project) {
		SearchResult* _tmp5_;
		const gchar* _tmp6_;
		gchar* _tmp7_;
		_tmp5_ = self->priv->_result;
		_tmp6_ = _tmp5_->project;
		_tmp7_ = g_strconcat (_tmp6_, " • ", NULL);
		_g_free0 (_tmp4_);
		_tmp4_ = _tmp7_;
	} else {
		gchar* _tmp8_;
		_tmp8_ = g_strdup ("");
		_g_free0 (_tmp4_);
		_tmp4_ = _tmp8_;
	}
	_tmp9_ = string_to_string (_tmp4_);
	_tmp10_ = self->priv->_result;
	_tmp11_ = _tmp10_->relative_path;
	_tmp12_ = string_to_string (_tmp11_);
	_tmp13_ = g_strconcat (_tmp9_, _tmp12_, NULL);
	_tmp14_ = _tmp13_;
	_tmp15_ = (GtkLabel*) gtk_label_new (_tmp14_);
	g_object_ref_sink (_tmp15_);
	_tmp16_ = _tmp15_;
	_g_free0 (_tmp14_);
	path_label = _tmp16_;
	gtk_widget_set_halign ((GtkWidget*) path_label, GTK_ALIGN_START);
	_tmp17_ = self->priv->_result;
	_tmp18_ = _tmp17_->relative_path;
	_tmp19_ = g_path_get_basename (_tmp18_);
	_tmp20_ = _tmp19_;
	_tmp21_ = (GtkLabel*) gtk_label_new (_tmp20_);
	g_object_ref_sink (_tmp21_);
	_tmp22_ = _tmp21_;
	_g_free0 (_tmp20_);
	filename_label = _tmp22_;
	gtk_widget_set_halign ((GtkWidget*) filename_label, GTK_ALIGN_START);
	{
		GFile* fi = NULL;
		SearchResult* _tmp23_;
		const gchar* _tmp24_;
		GFile* _tmp25_;
		GFileInfo* info = NULL;
		GFileInfo* _tmp26_;
		const gchar* _tmp27_;
		GIcon* _tmp28_;
		_tmp23_ = self->priv->_result;
		_tmp24_ = _tmp23_->full_path;
		_tmp25_ = g_file_new_for_path (_tmp24_);
		fi = _tmp25_;
		_tmp26_ = g_file_query_info (fi, "standard::*", 0, NULL, &_inner_error0_);
		info = _tmp26_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (fi);
			goto __catch0_g_error;
		}
		_tmp27_ = g_file_info_get_content_type (info);
		_tmp28_ = g_content_type_get_icon (_tmp27_);
		_g_object_unref0 (icon);
		icon = _tmp28_;
		_g_object_unref0 (info);
		_g_object_unref0 (fi);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GIcon* _tmp29_;
		g_clear_error (&_inner_error0_);
		_tmp29_ = g_content_type_get_icon ("text/plain");
		_g_object_unref0 (icon);
		icon = _tmp29_;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (filename_label);
		_g_object_unref0 (path_label);
		_g_free0 (_tmp4_);
		_g_object_unref0 (path_box);
		_g_object_unref0 (icon);
		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;
	}
	_tmp30_ = icon;
	_tmp31_ = (GtkImage*) gtk_image_new_from_gicon (_tmp30_, (GtkIconSize) GTK_ICON_SIZE_DND);
	g_object_ref_sink (_tmp31_);
	image = _tmp31_;
	_tmp32_ = gtk_widget_get_style_context ((GtkWidget*) image);
	gtk_style_context_add_class (_tmp32_, "fuzzy-file-icon");
	_tmp33_ = path_box;
	gtk_container_add ((GtkContainer*) _tmp33_, (GtkWidget*) filename_label);
	_tmp34_ = path_box;
	gtk_container_add ((GtkContainer*) _tmp34_, (GtkWidget*) path_label);
	_tmp35_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 1);
	gtk_widget_set_valign ((GtkWidget*) _tmp35_, GTK_ALIGN_CENTER);
	g_object_ref_sink (_tmp35_);
	container_box = _tmp35_;
	gtk_container_add ((GtkContainer*) container_box, (GtkWidget*) image);
	_tmp36_ = path_box;
	gtk_container_add ((GtkContainer*) container_box, (GtkWidget*) _tmp36_);
	g_object_set ((GtkContainer*) self, "child", (GtkWidget*) container_box, NULL);
	_g_object_unref0 (container_box);
	_g_object_unref0 (image);
	_g_object_unref0 (filename_label);
	_g_object_unref0 (path_label);
	_g_free0 (_tmp4_);
	_g_object_unref0 (path_box);
	_g_object_unref0 (icon);
	return self;
}

FileItem*
file_item_new (SearchResult* res,
               gboolean should_distinguish_project)
{
	return file_item_construct (TYPE_FILE_ITEM, res, should_distinguish_project);
}

SearchResult*
file_item_get_result (FileItem* self)
{
	SearchResult* result;
	SearchResult* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_result;
	result = _tmp0_;
	return result;
}

static gpointer
_search_result_ref0 (gpointer self)
{
	return self ? search_result_ref (self) : NULL;
}

static void
file_item_set_result (FileItem* self,
                      SearchResult* value)
{
	SearchResult* old_value;
	g_return_if_fail (self != NULL);
	old_value = file_item_get_result (self);
	if (old_value != value) {
		SearchResult* _tmp0_;
		_tmp0_ = _search_result_ref0 (value);
		_search_result_unref0 (self->priv->_result);
		self->priv->_result = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, file_item_properties[FILE_ITEM_RESULT_PROPERTY]);
	}
}

const gchar*
file_item_get_filepath (FileItem* self)
{
	const gchar* result;
	SearchResult* _tmp0_;
	const gchar* _tmp1_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_result;
	_tmp1_ = _tmp0_->full_path;
	result = _tmp1_;
	return result;
}

static void
file_item_class_init (FileItemClass * klass,
                      gpointer klass_data)
{
	file_item_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FileItem_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_file_item_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_file_item_set_property;
	G_OBJECT_CLASS (klass)->finalize = file_item_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), FILE_ITEM_RESULT_PROPERTY, file_item_properties[FILE_ITEM_RESULT_PROPERTY] = param_spec_search_result ("result", "result", "result", TYPE_SEARCH_RESULT, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FILE_ITEM_FILEPATH_PROPERTY, file_item_properties[FILE_ITEM_FILEPATH_PROPERTY] = g_param_spec_string ("filepath", "filepath", "filepath", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
file_item_instance_init (FileItem * self,
                         gpointer klass)
{
	self->priv = file_item_get_instance_private (self);
}

static void
file_item_finalize (GObject * obj)
{
	FileItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_FILE_ITEM, FileItem);
	_search_result_unref0 (self->priv->_result);
	G_OBJECT_CLASS (file_item_parent_class)->finalize (obj);
}

GType
file_item_get_type (void)
{
	return file_item_type_id;
}

GType
file_item_register_type (GTypeModule * module)
{
	static const GTypeInfo g_define_type_info = { sizeof (FileItemClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) file_item_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FileItem), 0, (GInstanceInitFunc) file_item_instance_init, NULL };
	file_item_type_id = g_type_module_register_type (module, gtk_list_box_row_get_type (), "FileItem", &g_define_type_info, G_TYPE_FLAG_NONE);
	FileItem_private_offset = sizeof (FileItemPrivate);
	return file_item_type_id;
}

static void
_vala_file_item_get_property (GObject * object,
                              guint property_id,
                              GValue * value,
                              GParamSpec * pspec)
{
	FileItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_FILE_ITEM, FileItem);
	switch (property_id) {
		case FILE_ITEM_RESULT_PROPERTY:
		value_set_search_result (value, file_item_get_result (self));
		break;
		case FILE_ITEM_FILEPATH_PROPERTY:
		g_value_set_string (value, file_item_get_filepath (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_file_item_set_property (GObject * object,
                              guint property_id,
                              const GValue * value,
                              GParamSpec * pspec)
{
	FileItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_FILE_ITEM, FileItem);
	switch (property_id) {
		case FILE_ITEM_RESULT_PROPERTY:
		file_item_set_result (self, value_get_search_result (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

