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

/*///////////////////////////////////////////////////////////////////////*/
/* Copyright 2011-2021 Simon Schneegans*/
/**/
/* Permission is hereby granted, free of charge, to any person obtaining*/
/* a copy of this software and associated documentation files (the*/
/* "Software"), to deal in the Software without restriction, including*/
/* without limitation the rights to use, copy, modify, merge, publish,*/
/* distribute, sublicense, and/or sell copies of the Software, and to*/
/* permit persons to whom the Software is furnished to do so, subject to*/
/* the following conditions:*/
/* */
/* The above copyright notice and this permission notice shall be*/
/* included in all copies or substantial portions of the Software.*/
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,*/
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF*/
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY*/
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,*/
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE*/
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/
/*///////////////////////////////////////////////////////////////////////*/

#include <glib-object.h>
#include <gee.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <cairo-gobject.h>
#include <gtk/gtk.h>
#include <gio/gio.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 GNOME_PIE_TYPE_IMAGE (gnome_pie_image_get_type ())
#define GNOME_PIE_IMAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNOME_PIE_TYPE_IMAGE, GnomePieImage))
#define GNOME_PIE_IMAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNOME_PIE_TYPE_IMAGE, GnomePieImageClass))
#define GNOME_PIE_IS_IMAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNOME_PIE_TYPE_IMAGE))
#define GNOME_PIE_IS_IMAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNOME_PIE_TYPE_IMAGE))
#define GNOME_PIE_IMAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GNOME_PIE_TYPE_IMAGE, GnomePieImageClass))

typedef struct _GnomePieImage GnomePieImage;
typedef struct _GnomePieImageClass GnomePieImageClass;
typedef struct _GnomePieImagePrivate GnomePieImagePrivate;

#define GNOME_PIE_TYPE_ICON (gnome_pie_icon_get_type ())
#define GNOME_PIE_ICON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNOME_PIE_TYPE_ICON, GnomePieIcon))
#define GNOME_PIE_ICON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNOME_PIE_TYPE_ICON, GnomePieIconClass))
#define GNOME_PIE_IS_ICON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNOME_PIE_TYPE_ICON))
#define GNOME_PIE_IS_ICON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNOME_PIE_TYPE_ICON))
#define GNOME_PIE_ICON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GNOME_PIE_TYPE_ICON, GnomePieIconClass))

typedef struct _GnomePieIcon GnomePieIcon;
typedef struct _GnomePieIconClass GnomePieIconClass;
typedef struct _GnomePieIconPrivate GnomePieIconPrivate;
enum  {
	GNOME_PIE_ICON_0_PROPERTY,
	GNOME_PIE_ICON_NUM_PROPERTIES
};
static GParamSpec* gnome_pie_icon_properties[GNOME_PIE_ICON_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 _cairo_surface_destroy0(var) ((var == NULL) ? NULL : (var = (cairo_surface_destroy (var), NULL)))

struct _GnomePieImage {
	GObject parent_instance;
	GnomePieImagePrivate * priv;
};

struct _GnomePieImageClass {
	GObjectClass parent_class;
};

struct _GnomePieIcon {
	GnomePieImage parent_instance;
	GnomePieIconPrivate * priv;
};

struct _GnomePieIconClass {
	GnomePieImageClass parent_class;
};

static gpointer gnome_pie_icon_parent_class = NULL;
static GeeHashMap* gnome_pie_icon__cache;
static GeeHashMap* gnome_pie_icon__cache = NULL;

VALA_EXTERN GType gnome_pie_image_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GnomePieImage, g_object_unref)
VALA_EXTERN GType gnome_pie_icon_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GnomePieIcon, g_object_unref)
VALA_EXTERN void gnome_pie_icon_init (void);
VALA_EXTERN void gnome_pie_icon_clear_cache (void);
static void __lambda4_ (void);
static void ___lambda4__gtk_icon_theme_changed (GtkIconTheme* _sender,
                                         gpointer self);
static void gnome_pie_icon_set_cache (GeeHashMap* value);
VALA_EXTERN GnomePieIcon* gnome_pie_icon_new (const gchar* icon_name,
                                  gint size);
VALA_EXTERN GnomePieIcon* gnome_pie_icon_construct (GType object_type,
                                        const gchar* icon_name,
                                        gint size);
VALA_EXTERN GnomePieImage* gnome_pie_image_new (void);
VALA_EXTERN GnomePieImage* gnome_pie_image_construct (GType object_type);
static GeeHashMap* gnome_pie_icon_get_cache (void);
VALA_EXTERN void gnome_pie_image_load_file_at_size (GnomePieImage* self,
                                        const gchar* filename,
                                        gint width,
                                        gint height);
VALA_EXTERN gchar* gnome_pie_icon_get_icon_file (const gchar* icon_name,
                                     gint size);
VALA_EXTERN cairo_surface_t* gnome_pie_image_get_surface (GnomePieImage* self);
VALA_EXTERN void gnome_pie_image_set_surface (GnomePieImage* self,
                                  cairo_surface_t* value);
VALA_EXTERN gint gnome_pie_icon_size (GnomePieIcon* self);
VALA_EXTERN gint gnome_pie_image_width (GnomePieImage* self);
static void gnome_pie_icon_finalize (GObject * obj);
static GType gnome_pie_icon_get_type_once (void);
static void _vala_gnome_pie_icon_get_property (GObject * object,
                                        guint property_id,
                                        GValue * value,
                                        GParamSpec * pspec);
static void _vala_gnome_pie_icon_set_property (GObject * object,
                                        guint property_id,
                                        const GValue * value,
                                        GParamSpec * pspec);
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 void
__lambda4_ (void)
{
	gnome_pie_icon_clear_cache ();
}

static void
___lambda4__gtk_icon_theme_changed (GtkIconTheme* _sender,
                                    gpointer self)
{
	__lambda4_ ();
}

void
gnome_pie_icon_init (void)
{
	GtkIconTheme* _tmp0_;
	gnome_pie_icon_clear_cache ();
	_tmp0_ = gtk_icon_theme_get_default ();
	g_signal_connect (_tmp0_, "changed", (GCallback) ___lambda4__gtk_icon_theme_changed, NULL);
}

void
gnome_pie_icon_clear_cache (void)
{
	GeeHashMap* _tmp0_;
	GeeHashMap* _tmp1_;
	_tmp0_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, cairo_gobject_surface_get_type (), (GBoxedCopyFunc) cairo_surface_reference, (GDestroyNotify) cairo_surface_destroy, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_tmp1_ = _tmp0_;
	gnome_pie_icon_set_cache (_tmp1_);
	_g_object_unref0 (_tmp1_);
}

GnomePieIcon*
gnome_pie_icon_construct (GType object_type,
                          const gchar* icon_name,
                          gint size)
{
	GnomePieIcon * self = NULL;
	cairo_surface_t* cached = NULL;
	GeeHashMap* _tmp0_;
	GeeHashMap* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gpointer _tmp4_;
	cairo_surface_t* _tmp5_;
	cairo_surface_t* _tmp6_;
	g_return_val_if_fail (icon_name != NULL, NULL);
	self = (GnomePieIcon*) gnome_pie_image_construct (object_type);
	_tmp0_ = gnome_pie_icon_get_cache ();
	_tmp1_ = _tmp0_;
	_tmp2_ = g_strdup_printf ("%s@%u", icon_name, (guint) size);
	_tmp3_ = _tmp2_;
	_tmp4_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp1_, _tmp3_);
	_tmp5_ = (cairo_surface_t*) _tmp4_;
	_g_free0 (_tmp3_);
	cached = _tmp5_;
	_tmp6_ = cached;
	if (_tmp6_ == NULL) {
		gchar* _tmp7_;
		gchar* _tmp8_;
		GeeHashMap* _tmp9_;
		GeeHashMap* _tmp10_;
		gchar* _tmp11_;
		gchar* _tmp12_;
		cairo_surface_t* _tmp13_;
		cairo_surface_t* _tmp14_;
		_tmp7_ = gnome_pie_icon_get_icon_file (icon_name, size);
		_tmp8_ = _tmp7_;
		gnome_pie_image_load_file_at_size ((GnomePieImage*) self, _tmp8_, size, size);
		_g_free0 (_tmp8_);
		_tmp9_ = gnome_pie_icon_get_cache ();
		_tmp10_ = _tmp9_;
		_tmp11_ = g_strdup_printf ("%s@%u", icon_name, (guint) size);
		_tmp12_ = _tmp11_;
		_tmp13_ = gnome_pie_image_get_surface ((GnomePieImage*) self);
		_tmp14_ = _tmp13_;
		gee_abstract_map_set ((GeeAbstractMap*) _tmp10_, _tmp12_, _tmp14_);
		_g_free0 (_tmp12_);
	} else {
		cairo_surface_t* _tmp15_;
		_tmp15_ = cached;
		gnome_pie_image_set_surface ((GnomePieImage*) self, _tmp15_);
	}
	_cairo_surface_destroy0 (cached);
	return self;
}

GnomePieIcon*
gnome_pie_icon_new (const gchar* icon_name,
                    gint size)
{
	return gnome_pie_icon_construct (GNOME_PIE_TYPE_ICON, icon_name, size);
}

gint
gnome_pie_icon_size (GnomePieIcon* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, 0);
	result = gnome_pie_image_width (G_TYPE_CHECK_INSTANCE_CAST (self, GNOME_PIE_TYPE_IMAGE, GnomePieImage));
	return result;
}

static gboolean
string_contains (const gchar* self,
                 const gchar* needle)
{
	gchar* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (needle != NULL, FALSE);
	_tmp0_ = strstr ((gchar*) self, (gchar*) needle);
	result = _tmp0_ != NULL;
	return result;
}

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

gchar*
gnome_pie_icon_get_icon_file (const gchar* icon_name,
                              gint size)
{
	GtkIconTheme* icon_theme = NULL;
	GtkIconTheme* _tmp3_;
	GtkIconTheme* _tmp4_;
	GtkIconInfo* file = NULL;
	GtkIconTheme* _tmp5_;
	GtkIconInfo* _tmp6_;
	GtkIconInfo* _tmp7_;
	gchar* _tmp19_;
	gchar* _tmp20_;
	gchar* _tmp21_;
	gchar* _tmp22_;
	gchar** default_icons = NULL;
	gchar* _tmp23_;
	gchar* _tmp24_;
	gchar** _tmp25_;
	gint default_icons_length1;
	gint _default_icons_size_;
	gchar** _tmp26_;
	gint _tmp26__length1;
	gchar* _tmp35_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (icon_name != NULL, NULL);
	if (string_contains (icon_name, "/")) {
		GFile* file = NULL;
		GFile* _tmp0_;
		GFile* _tmp1_;
		_tmp0_ = g_file_new_for_path (icon_name);
		file = _tmp0_;
		_tmp1_ = file;
		if (g_file_query_exists (_tmp1_, NULL)) {
			gchar* _tmp2_;
			_tmp2_ = g_strdup (icon_name);
			result = _tmp2_;
			_g_object_unref0 (file);
			return result;
		}
		_g_object_unref0 (file);
	}
	_tmp3_ = gtk_icon_theme_get_default ();
	_tmp4_ = _g_object_ref0 (_tmp3_);
	icon_theme = _tmp4_;
	_tmp5_ = icon_theme;
	_tmp6_ = gtk_icon_theme_lookup_icon (_tmp5_, icon_name, size, 0);
	file = _tmp6_;
	_tmp7_ = file;
	if (_tmp7_ != NULL) {
		GtkIconInfo* _tmp8_;
		const gchar* _tmp9_;
		gchar* _tmp10_;
		_tmp8_ = file;
		_tmp9_ = gtk_icon_info_get_filename (_tmp8_);
		_tmp10_ = g_strdup (_tmp9_);
		result = _tmp10_;
		_g_object_unref0 (file);
		_g_object_unref0 (icon_theme);
		return result;
	}
	{
		GIcon* _tmp11_ = NULL;
		GIcon* _tmp12_;
		GtkIconTheme* _tmp13_;
		GtkIconInfo* _tmp14_;
		GtkIconInfo* _tmp15_;
		_tmp12_ = g_icon_new_for_string (icon_name, &_inner_error0_);
		_tmp11_ = _tmp12_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp13_ = icon_theme;
		_tmp14_ = gtk_icon_theme_lookup_by_gicon (_tmp13_, _tmp11_, size, 0);
		_g_object_unref0 (file);
		file = _tmp14_;
		_tmp15_ = file;
		if (_tmp15_ != NULL) {
			GtkIconInfo* _tmp16_;
			const gchar* _tmp17_;
			gchar* _tmp18_;
			_tmp16_ = file;
			_tmp17_ = gtk_icon_info_get_filename (_tmp16_);
			_tmp18_ = g_strdup (_tmp17_);
			result = _tmp18_;
			_g_object_unref0 (_tmp11_);
			_g_object_unref0 (file);
			_g_object_unref0 (icon_theme);
			return result;
		}
		_g_object_unref0 (_tmp11_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_inner_error0_);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (file);
		_g_object_unref0 (icon_theme);
		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;
	}
	_tmp19_ = g_strconcat ("Icon \"", icon_name, NULL);
	_tmp20_ = _tmp19_;
	_tmp21_ = g_strconcat (_tmp20_, "\" not found! Using default icon...", NULL);
	_tmp22_ = _tmp21_;
	g_warning ("icon.vala:108: %s", _tmp22_);
	_g_free0 (_tmp22_);
	_g_free0 (_tmp20_);
	_tmp23_ = g_strdup ("image-missing");
	_tmp24_ = g_strdup ("application-default-icon");
	_tmp25_ = g_new0 (gchar*, 2 + 1);
	_tmp25_[0] = _tmp23_;
	_tmp25_[1] = _tmp24_;
	default_icons = _tmp25_;
	default_icons_length1 = 2;
	_default_icons_size_ = default_icons_length1;
	_tmp26_ = default_icons;
	_tmp26__length1 = default_icons_length1;
	{
		gchar** icon_collection = NULL;
		gint icon_collection_length1 = 0;
		gint _icon_collection_size_ = 0;
		gint icon_it = 0;
		icon_collection = _tmp26_;
		icon_collection_length1 = _tmp26__length1;
		for (icon_it = 0; icon_it < icon_collection_length1; icon_it = icon_it + 1) {
			gchar* _tmp27_;
			gchar* icon = NULL;
			_tmp27_ = g_strdup (icon_collection[icon_it]);
			icon = _tmp27_;
			{
				GtkIconTheme* _tmp28_;
				const gchar* _tmp29_;
				GtkIconInfo* _tmp30_;
				GtkIconInfo* _tmp31_;
				_tmp28_ = icon_theme;
				_tmp29_ = icon;
				_tmp30_ = gtk_icon_theme_lookup_icon (_tmp28_, _tmp29_, size, 0);
				_g_object_unref0 (file);
				file = _tmp30_;
				_tmp31_ = file;
				if (_tmp31_ != NULL) {
					GtkIconInfo* _tmp32_;
					const gchar* _tmp33_;
					gchar* _tmp34_;
					_tmp32_ = file;
					_tmp33_ = gtk_icon_info_get_filename (_tmp32_);
					_tmp34_ = g_strdup (_tmp33_);
					result = _tmp34_;
					_g_free0 (icon);
					default_icons = (_vala_array_free (default_icons, default_icons_length1, (GDestroyNotify) g_free), NULL);
					_g_object_unref0 (file);
					_g_object_unref0 (icon_theme);
					return result;
				}
				_g_free0 (icon);
			}
		}
	}
	g_warning ("icon.vala:118: No default icon found! Will be ugly...");
	_tmp35_ = g_strdup ("");
	result = _tmp35_;
	default_icons = (_vala_array_free (default_icons, default_icons_length1, (GDestroyNotify) g_free), NULL);
	_g_object_unref0 (file);
	_g_object_unref0 (icon_theme);
	return result;
}

static GeeHashMap*
gnome_pie_icon_get_cache (void)
{
	GeeHashMap* result;
	GeeHashMap* _tmp0_;
	_tmp0_ = gnome_pie_icon__cache;
	result = _tmp0_;
	return result;
}

static void
gnome_pie_icon_set_cache (GeeHashMap* value)
{
	GeeHashMap* _tmp0_;
	_tmp0_ = _g_object_ref0 (value);
	_g_object_unref0 (gnome_pie_icon__cache);
	gnome_pie_icon__cache = _tmp0_;
}

static void
gnome_pie_icon_class_init (GnomePieIconClass * klass,
                           gpointer klass_data)
{
	gnome_pie_icon_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->get_property = _vala_gnome_pie_icon_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gnome_pie_icon_set_property;
	G_OBJECT_CLASS (klass)->finalize = gnome_pie_icon_finalize;
}

static void
gnome_pie_icon_instance_init (GnomePieIcon * self,
                              gpointer klass)
{
}

static void
gnome_pie_icon_finalize (GObject * obj)
{
	GnomePieIcon * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GNOME_PIE_TYPE_ICON, GnomePieIcon);
	G_OBJECT_CLASS (gnome_pie_icon_parent_class)->finalize (obj);
}

static GType
gnome_pie_icon_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GnomePieIconClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gnome_pie_icon_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GnomePieIcon), 0, (GInstanceInitFunc) gnome_pie_icon_instance_init, NULL };
	GType gnome_pie_icon_type_id;
	gnome_pie_icon_type_id = g_type_register_static (GNOME_PIE_TYPE_IMAGE, "GnomePieIcon", &g_define_type_info, 0);
	return gnome_pie_icon_type_id;
}

GType
gnome_pie_icon_get_type (void)
{
	static volatile gsize gnome_pie_icon_type_id__once = 0;
	if (g_once_init_enter (&gnome_pie_icon_type_id__once)) {
		GType gnome_pie_icon_type_id;
		gnome_pie_icon_type_id = gnome_pie_icon_get_type_once ();
		g_once_init_leave (&gnome_pie_icon_type_id__once, gnome_pie_icon_type_id);
	}
	return gnome_pie_icon_type_id__once;
}

static void
_vala_gnome_pie_icon_get_property (GObject * object,
                                   guint property_id,
                                   GValue * value,
                                   GParamSpec * pspec)
{
	GnomePieIcon * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GNOME_PIE_TYPE_ICON, GnomePieIcon);
	switch (property_id) {
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_gnome_pie_icon_set_property (GObject * object,
                                   guint property_id,
                                   const GValue * value,
                                   GParamSpec * pspec)
{
	GnomePieIcon * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GNOME_PIE_TYPE_ICON, GnomePieIcon);
	switch (property_id) {
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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

