/* folder-popover-row.c generated by valac 0.56.19, the Vala compiler
 * generated from folder-popover-row.vala, do not modify */

/* Copyright 2022 Cédric Bellegarde <cedric.bellegarde@adishatz.org>
 *
 * This software is licensed under the GNU Lesser General Public License
 * (version 2.1 or later).  See the COPYING file in this distribution.
 */

#include "geary-client-46.0.h"
#include <gtk/gtk.h>
#include <glib-object.h>
#include <gee.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "geary-engine.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  {
	FOLDER_POPOVER_ROW_0_PROPERTY,
	FOLDER_POPOVER_ROW_NUM_PROPERTIES
};
static GParamSpec* folder_popover_row_properties[FOLDER_POPOVER_ROW_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))

struct _FolderPopoverRowPrivate {
	GtkImage* image;
	GtkLabel* label;
};

static gint FolderPopoverRow_private_offset;
static gpointer folder_popover_row_parent_class = NULL;

static gboolean _util_gtk_query_tooltip_label_gtk_widget_query_tooltip (GtkWidget* _sender,
                                                                 gint x,
                                                                 gint y,
                                                                 gboolean keyboard_tooltip,
                                                                 GtkTooltip* tooltip,
                                                                 gpointer self);
static void folder_popover_row_finalize (GObject * obj);
static GType folder_popover_row_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
folder_popover_row_get_instance_private (FolderPopoverRow* self)
{
	return G_STRUCT_MEMBER_P (self, FolderPopoverRow_private_offset);
}

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

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 gboolean
_util_gtk_query_tooltip_label_gtk_widget_query_tooltip (GtkWidget* _sender,
                                                        gint x,
                                                        gint y,
                                                        gboolean keyboard_tooltip,
                                                        GtkTooltip* tooltip,
                                                        gpointer self)
{
	gboolean result;
	result = util_gtk_query_tooltip_label (_sender, x, y, keyboard_tooltip, tooltip);
	return result;
}

FolderPopoverRow*
folder_popover_row_construct (GType object_type,
                              ApplicationFolderContext* context,
                              GeeHashMap* map)
{
	FolderPopoverRow * self = NULL;
	gchar** as_array = NULL;
	GearyFolder* _tmp0_;
	GearyFolder* _tmp1_;
	GearyFolderPath* _tmp2_;
	GearyFolderPath* _tmp3_;
	gint _tmp4_ = 0;
	gchar** _tmp5_;
	gint as_array_length1;
	gint _as_array_size_;
	gchar** _tmp6_;
	gint _tmp6__length1;
	const gchar* _tmp7_;
	gint i = 0;
	gchar** _tmp12_;
	gint _tmp12__length1;
	GearyFolder* _tmp17_;
	GearyFolder* _tmp18_;
	GearyFolder* _tmp19_;
	GtkImage* _tmp20_;
	const gchar* _tmp21_;
	const gchar* _tmp22_;
	GtkLabel* _tmp23_;
	gchar** _tmp24_;
	gint _tmp24__length1;
	gchar* _tmp25_;
	gchar* _tmp26_;
	GtkLabel* _tmp27_;
	g_return_val_if_fail (APPLICATION_IS_FOLDER_CONTEXT (context), NULL);
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (map, GEE_TYPE_HASH_MAP), NULL);
	self = (FolderPopoverRow*) g_object_new (object_type, NULL);
	_tmp0_ = application_folder_context_get_folder (context);
	_tmp1_ = _tmp0_;
	_tmp2_ = geary_folder_get_path (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp5_ = geary_folder_path_as_array (_tmp3_, &_tmp4_);
	as_array = _tmp5_;
	as_array_length1 = _tmp4_;
	_as_array_size_ = as_array_length1;
	_tmp6_ = as_array;
	_tmp6__length1 = as_array_length1;
	_tmp7_ = _tmp6_[0];
	if (gee_abstract_map_has_key (G_TYPE_CHECK_INSTANCE_CAST (map, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap), _tmp7_)) {
		gchar** _tmp8_;
		gint _tmp8__length1;
		gchar** _tmp9_;
		gint _tmp9__length1;
		const gchar* _tmp10_;
		gpointer _tmp11_;
		_tmp8_ = as_array;
		_tmp8__length1 = as_array_length1;
		_tmp9_ = as_array;
		_tmp9__length1 = as_array_length1;
		_tmp10_ = _tmp9_[0];
		_tmp11_ = gee_abstract_map_get (G_TYPE_CHECK_INSTANCE_CAST (map, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap), _tmp10_);
		_g_free0 (_tmp8_[0]);
		_tmp8_[0] = (gchar*) _tmp11_;
	}
	i = 0;
	_tmp12_ = as_array;
	_tmp12__length1 = as_array_length1;
	{
		gchar** name_collection = NULL;
		gint name_collection_length1 = 0;
		gint _name_collection_size_ = 0;
		gint name_it = 0;
		name_collection = _tmp12_;
		name_collection_length1 = _tmp12__length1;
		for (name_it = 0; name_it < name_collection_length1; name_it = name_it + 1) {
			gchar* _tmp13_;
			gchar* name = NULL;
			_tmp13_ = g_strdup (name_collection[name_it]);
			name = _tmp13_;
			{
				gchar** _tmp14_;
				gint _tmp14__length1;
				const gchar* _tmp15_;
				gchar* _tmp16_;
				_tmp14_ = as_array;
				_tmp14__length1 = as_array_length1;
				_tmp15_ = name;
				_tmp16_ = g_markup_escape_text (_tmp15_, (gssize) -1);
				_g_free0 (_tmp14_[i]);
				_tmp14_[i] = _tmp16_;
				i += 1;
				_g_free0 (name);
			}
		}
	}
	_tmp17_ = application_folder_context_get_folder (context);
	_tmp18_ = _tmp17_;
	_tmp19_ = _g_object_ref0 (_tmp18_);
	g_object_set_data_full (G_TYPE_CHECK_INSTANCE_CAST (self, G_TYPE_OBJECT, GObject), "folder", _tmp19_, g_object_unref);
	_tmp20_ = self->priv->image;
	_tmp21_ = application_folder_context_get_icon_name (context);
	_tmp22_ = _tmp21_;
	g_object_set (_tmp20_, "icon-name", _tmp22_, NULL);
	_tmp23_ = self->priv->label;
	_tmp24_ = as_array;
	_tmp24__length1 = as_array_length1;
	_tmp25_ = _vala_g_strjoinv ("<span alpha='30%'> / </span>", _tmp24_, (gint) _tmp24__length1);
	_tmp26_ = _tmp25_;
	gtk_label_set_markup (_tmp23_, _tmp26_);
	_g_free0 (_tmp26_);
	_tmp27_ = self->priv->label;
	g_signal_connect (G_TYPE_CHECK_INSTANCE_CAST (_tmp27_, gtk_widget_get_type (), GtkWidget), "query-tooltip", (GCallback) _util_gtk_query_tooltip_label_gtk_widget_query_tooltip, NULL);
	as_array = (_vala_array_free (as_array, as_array_length1, (GDestroyNotify) g_free), NULL);
	return self;
}

FolderPopoverRow*
folder_popover_row_new (ApplicationFolderContext* context,
                        GeeHashMap* map)
{
	return folder_popover_row_construct (TYPE_FOLDER_POPOVER_ROW, context, map);
}

static void
folder_popover_row_class_init (FolderPopoverRowClass * klass,
                               gpointer klass_data)
{
	folder_popover_row_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FolderPopoverRow_private_offset);
	G_OBJECT_CLASS (klass)->finalize = folder_popover_row_finalize;
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/Geary/folder-popover-row.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "image", FALSE, FolderPopoverRow_private_offset + G_STRUCT_OFFSET (FolderPopoverRowPrivate, image));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "label", FALSE, FolderPopoverRow_private_offset + G_STRUCT_OFFSET (FolderPopoverRowPrivate, label));
}

static void
folder_popover_row_instance_init (FolderPopoverRow * self,
                                  gpointer klass)
{
	self->priv = folder_popover_row_get_instance_private (self);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
folder_popover_row_finalize (GObject * obj)
{
	FolderPopoverRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_FOLDER_POPOVER_ROW, FolderPopoverRow);
	G_OBJECT_CLASS (folder_popover_row_parent_class)->finalize (obj);
}

static GType
folder_popover_row_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FolderPopoverRowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) folder_popover_row_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FolderPopoverRow), 0, (GInstanceInitFunc) folder_popover_row_instance_init, NULL };
	GType folder_popover_row_type_id;
	folder_popover_row_type_id = g_type_register_static (gtk_list_box_row_get_type (), "FolderPopoverRow", &g_define_type_info, 0);
	FolderPopoverRow_private_offset = g_type_add_instance_private (folder_popover_row_type_id, sizeof (FolderPopoverRowPrivate));
	return folder_popover_row_type_id;
}

GType
folder_popover_row_get_type (void)
{
	static volatile gsize folder_popover_row_type_id__once = 0;
	if (g_once_init_enter (&folder_popover_row_type_id__once)) {
		GType folder_popover_row_type_id;
		folder_popover_row_type_id = folder_popover_row_get_type_once ();
		g_once_init_leave (&folder_popover_row_type_id__once, folder_popover_row_type_id);
	}
	return folder_popover_row_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);
}

