/* PlaceItem.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from PlaceItem.vala, do not modify */

/*
 * This file is part of budgie-desktop
 *
 * Copyright Budgie Desktop 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 2 of the License, or
 * (at your option) any later version.
 */

#include "placesindicator.h"
#include <glib-object.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <glib/gi18n-lib.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  {
	PLACE_ITEM_0_PROPERTY,
	PLACE_ITEM_NUM_PROPERTIES
};
static GParamSpec* place_item_properties[PLACE_ITEM_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block3Data Block3Data;
#define _g_free0(var) (var = (g_free (var), NULL))

struct _Block3Data {
	int _ref_count_;
	PlaceItem* self;
	GFile* file;
};

static gpointer place_item_parent_class = NULL;
static GType place_item_type_id = 0;

static Block3Data* block3_data_ref (Block3Data* _data3_);
static void block3_data_unref (void * _userdata_);
static void __lambda6_ (Block3Data* _data3_);
static void ___lambda6__gtk_tool_button_clicked (GtkToolButton* _sender,
                                          gpointer self);
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 gssize _vala_array_length (gpointer array);

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

static Block3Data*
block3_data_ref (Block3Data* _data3_)
{
	g_atomic_int_inc (&_data3_->_ref_count_);
	return _data3_;
}

static void
block3_data_unref (void * _userdata_)
{
	Block3Data* _data3_;
	_data3_ = (Block3Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data3_->_ref_count_)) {
		PlaceItem* self;
		self = _data3_->self;
		_g_object_unref0 (_data3_->file);
		_g_object_unref0 (self);
		g_slice_free (Block3Data, _data3_);
	}
}

static gchar*
string_slice (const gchar* self,
              glong start,
              glong end)
{
	glong string_length = 0L;
	gint _tmp0_;
	gint _tmp1_;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	gchar* _tmp4_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	string_length = (glong) _tmp1_;
	if (start < ((glong) 0)) {
		start = string_length + start;
	}
	if (end < ((glong) 0)) {
		end = string_length + end;
	}
	if (start >= ((glong) 0)) {
		_tmp2_ = start <= string_length;
	} else {
		_tmp2_ = FALSE;
	}
	g_return_val_if_fail (_tmp2_, NULL);
	if (end >= ((glong) 0)) {
		_tmp3_ = end <= string_length;
	} else {
		_tmp3_ = FALSE;
	}
	g_return_val_if_fail (_tmp3_, NULL);
	g_return_val_if_fail (start <= end, NULL);
	_tmp4_ = g_strndup (((gchar*) self) + start, (gsize) (end - start));
	result = _tmp4_;
	return result;
}

static gchar*
string_strip (const gchar* self)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	g_strstrip (_result_);
	result = _result_;
	return result;
}

static void
__lambda6_ (Block3Data* _data3_)
{
	PlaceItem* self;
	self = _data3_->self;
	list_item_open_directory ((ListItem*) self, _data3_->file);
}

static void
___lambda6__gtk_tool_button_clicked (GtkToolButton* _sender,
                                     gpointer self)
{
	__lambda6_ (self);
}

PlaceItem*
place_item_construct (GType object_type,
                      GFile* file,
                      const gchar* class,
                      const gchar* bookmark_name)
{
	PlaceItem * self = NULL;
	Block3Data* _data3_;
	GFile* _tmp0_;
	gchar* _tmp1_;
	gchar* name = NULL;
	gchar* _tmp2_;
	GtkToolButton* _tmp39_;
	const gchar* _tmp40_;
	gchar* _tmp41_;
	gchar* _tmp42_;
	gchar* _tmp43_;
	gchar* _tmp44_;
	GtkToolButton* _tmp45_;
	GError* _inner_error0_ = NULL;
	g_return_val_if_fail (file != NULL, NULL);
	g_return_val_if_fail (class != NULL, NULL);
	_data3_ = g_slice_new0 (Block3Data);
	_data3_->_ref_count_ = 1;
	_tmp0_ = _g_object_ref0 (file);
	_g_object_unref0 (_data3_->file);
	_data3_->file = _tmp0_;
	self = (PlaceItem*) list_item_construct (object_type);
	_data3_->self = g_object_ref (self);
	_tmp1_ = g_strdup (class);
	_g_free0 (((ListItem*) self)->item_class);
	((ListItem*) self)->item_class = _tmp1_;
	_tmp2_ = g_strdup ("");
	name = _tmp2_;
	if (bookmark_name != NULL) {
		gchar* _tmp3_;
		_tmp3_ = g_strdup (bookmark_name);
		_g_free0 (name);
		name = _tmp3_;
	} else {
		gboolean _tmp4_ = FALSE;
		gchar* _tmp5_;
		gchar* _tmp6_;
		gboolean _tmp7_;
		_tmp5_ = g_file_get_basename (_data3_->file);
		_tmp6_ = _tmp5_;
		_tmp7_ = g_strcmp0 (_tmp6_, "/") == 0;
		_g_free0 (_tmp6_);
		if (_tmp7_) {
			gchar* _tmp8_;
			gchar* _tmp9_;
			_tmp8_ = g_file_get_uri (_data3_->file);
			_tmp9_ = _tmp8_;
			_tmp4_ = g_strcmp0 (_tmp9_, "file:///") != 0;
			_g_free0 (_tmp9_);
		} else {
			_tmp4_ = FALSE;
		}
		if (_tmp4_) {
			gchar** uri_parts = NULL;
			gchar* _tmp10_;
			gchar* _tmp11_;
			gchar** _tmp12_;
			gchar** _tmp13_;
			gchar** _tmp14_;
			gint _tmp14__length1;
			gint uri_parts_length1;
			gint _uri_parts_size_;
			gchar** _tmp15_;
			gint _tmp15__length1;
			_tmp10_ = g_file_get_uri (_data3_->file);
			_tmp11_ = _tmp10_;
			_tmp13_ = _tmp12_ = g_strsplit (_tmp11_, "://", 0);
			_tmp14_ = _tmp13_;
			_tmp14__length1 = _vala_array_length (_tmp12_);
			_g_free0 (_tmp11_);
			uri_parts = _tmp14_;
			uri_parts_length1 = _tmp14__length1;
			_uri_parts_size_ = uri_parts_length1;
			_tmp15_ = uri_parts;
			_tmp15__length1 = uri_parts_length1;
			if (_tmp15__length1 >= 2) {
				gchar** _tmp16_;
				gint _tmp16__length1;
				const gchar* _tmp17_;
				gchar* _tmp18_;
				const gchar* _tmp19_;
				_tmp16_ = uri_parts;
				_tmp16__length1 = uri_parts_length1;
				_tmp17_ = _tmp16_[1];
				_tmp18_ = g_strdup (_tmp17_);
				_g_free0 (name);
				name = _tmp18_;
				_tmp19_ = name;
				if (g_str_has_suffix (_tmp19_, "/")) {
					const gchar* _tmp20_;
					const gchar* _tmp21_;
					gint _tmp22_;
					gint _tmp23_;
					gchar* _tmp24_;
					_tmp20_ = name;
					_tmp21_ = name;
					_tmp22_ = strlen (_tmp21_);
					_tmp23_ = _tmp22_;
					_tmp24_ = string_slice (_tmp20_, (glong) 0, (glong) (_tmp23_ - 1));
					_g_free0 (name);
					name = _tmp24_;
				}
			} else {
				gchar* _tmp25_;
				_tmp25_ = g_file_get_basename (_data3_->file);
				_g_free0 (name);
				name = _tmp25_;
			}
			uri_parts = (_vala_array_free (uri_parts, uri_parts_length1, (GDestroyNotify) g_free), NULL);
		} else {
			gchar* _tmp26_;
			_tmp26_ = g_file_get_basename (_data3_->file);
			_g_free0 (name);
			name = _tmp26_;
		}
	}
	{
		GFileInfo* info = NULL;
		GFileInfo* _tmp27_;
		const gchar* _tmp28_;
		gchar* _tmp29_;
		gchar* _tmp30_;
		GIcon* _tmp31_;
		GtkImage* _tmp32_;
		GtkImage* _tmp33_;
		_tmp27_ = g_file_query_info (_data3_->file, "standard::symbolic-icon", G_FILE_QUERY_INFO_NONE, NULL, &_inner_error0_);
		info = _tmp27_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp28_ = name;
		_tmp29_ = string_strip (_tmp28_);
		_tmp30_ = _tmp29_;
		_tmp31_ = g_file_info_get_symbolic_icon (info);
		_tmp32_ = list_item_get_icon ((ListItem*) self, _tmp31_);
		_tmp33_ = _tmp32_;
		list_item_set_button ((ListItem*) self, _tmp30_, _tmp33_, FALSE, FALSE);
		_g_object_unref0 (_tmp33_);
		_g_free0 (_tmp30_);
		_g_object_unref0 (info);
	}
	goto __finally0;
	__catch0_g_error:
	{
		const gchar* _tmp34_;
		gchar* _tmp35_;
		gchar* _tmp36_;
		GtkImage* _tmp37_;
		GtkImage* _tmp38_;
		g_clear_error (&_inner_error0_);
		_tmp34_ = name;
		_tmp35_ = string_strip (_tmp34_);
		_tmp36_ = _tmp35_;
		_tmp37_ = list_item_get_icon ((ListItem*) self, NULL);
		_tmp38_ = _tmp37_;
		list_item_set_button ((ListItem*) self, _tmp36_, _tmp38_, FALSE, FALSE);
		_g_object_unref0 (_tmp38_);
		_g_free0 (_tmp36_);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_free0 (name);
		block3_data_unref (_data3_);
		_data3_ = NULL;
		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;
	}
	_tmp39_ = ((ListItem*) self)->name_button;
	_tmp40_ = name;
	_tmp41_ = string_strip (_tmp40_);
	_tmp42_ = _tmp41_;
	_tmp43_ = g_strdup_printf ("Open \"%s\"", _tmp42_);
	_tmp44_ = _tmp43_;
	gtk_tool_item_set_tooltip_text ((GtkToolItem*) _tmp39_, _ (_tmp44_));
	_g_free0 (_tmp44_);
	_g_free0 (_tmp42_);
	_tmp45_ = ((ListItem*) self)->name_button;
	g_signal_connect_data (_tmp45_, "clicked", (GCallback) ___lambda6__gtk_tool_button_clicked, block3_data_ref (_data3_), (GClosureNotify) block3_data_unref, 0);
	_g_free0 (name);
	block3_data_unref (_data3_);
	_data3_ = NULL;
	return self;
}

PlaceItem*
place_item_new (GFile* file,
                const gchar* class,
                const gchar* bookmark_name)
{
	return place_item_construct (TYPE_PLACE_ITEM, file, class, bookmark_name);
}

static void
place_item_class_init (PlaceItemClass * klass,
                       gpointer klass_data)
{
	place_item_parent_class = g_type_class_peek_parent (klass);
}

static void
place_item_instance_init (PlaceItem * self,
                          gpointer klass)
{
}

GType
place_item_get_type (void)
{
	return place_item_type_id;
}

GType
place_item_register_type (GTypeModule * module)
{
	static const GTypeInfo g_define_type_info = { sizeof (PlaceItemClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) place_item_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PlaceItem), 0, (GInstanceInitFunc) place_item_instance_init, NULL };
	place_item_type_id = g_type_module_register_type (module, TYPE_LIST_ITEM, "PlaceItem", &g_define_type_info, 0);
	return place_item_type_id;
}

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);
}

static gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

