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

/*
 * Copyright 2017 elementary, Inc. (https://elementary.io)
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */

#include <gtk/gtk.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <glib.h>
#include <gee.h>
#include <stdlib.h>
#include <string.h>
#include "granite.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 TYPE_ASYNC_IMAGE_VIEW (async_image_view_get_type ())
#define ASYNC_IMAGE_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_ASYNC_IMAGE_VIEW, AsyncImageView))
#define ASYNC_IMAGE_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_ASYNC_IMAGE_VIEW, AsyncImageViewClass))
#define IS_ASYNC_IMAGE_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_ASYNC_IMAGE_VIEW))
#define IS_ASYNC_IMAGE_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_ASYNC_IMAGE_VIEW))
#define ASYNC_IMAGE_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_ASYNC_IMAGE_VIEW, AsyncImageViewClass))

typedef struct _AsyncImageView AsyncImageView;
typedef struct _AsyncImageViewClass AsyncImageViewClass;
typedef struct _AsyncImageViewPrivate AsyncImageViewPrivate;
enum  {
	ASYNC_IMAGE_VIEW_0_PROPERTY,
	ASYNC_IMAGE_VIEW_NUM_PROPERTIES
};
static GParamSpec* async_image_view_properties[ASYNC_IMAGE_VIEW_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block4Data Block4Data;
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _AsyncImageViewLoadIconsData AsyncImageViewLoadIconsData;

struct _AsyncImageView {
	GtkGrid parent_instance;
	AsyncImageViewPrivate * priv;
};

struct _AsyncImageViewClass {
	GtkGridClass parent_class;
};

struct _AsyncImageViewPrivate {
	GtkFlowBox* flow_box;
};

struct _Block4Data {
	int _ref_count_;
	AsyncImageView* self;
	GeeArrayList* icons;
	gpointer _async_data_;
};

struct _AsyncImageViewLoadIconsData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	AsyncImageView* self;
	Block4Data* _data4_;
	GtkFlowBox* _tmp0_;
	GList* _tmp1_;
	GList* _tmp2_;
	GeeArrayList* _tmp3_;
	GtkIconTheme* icon_theme;
	GtkIconTheme* _tmp4_;
	GtkIconTheme* _tmp5_;
	GtkIconTheme* _tmp6_;
	GList* _tmp7_;
	GList* _tmp8_;
	GeeArrayList* _name_list;
	GeeArrayList* _tmp9_;
	gint _name_size;
	GeeArrayList* _tmp10_;
	gint _tmp11_;
	gint _tmp12_;
	gint _name_index;
	gint _tmp13_;
	gint _tmp14_;
	gchar* name;
	GeeArrayList* _tmp15_;
	gpointer _tmp16_;
	GraniteAsyncImage* image;
	const gchar* _tmp17_;
	GraniteAsyncImage* _tmp18_;
	GtkFlowBox* _tmp19_;
	GraniteAsyncImage* _tmp20_;
	GtkFlowBox* _tmp21_;
};

static gint AsyncImageView_private_offset;
static gpointer async_image_view_parent_class = NULL;

VALA_EXTERN GType async_image_view_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (AsyncImageView, g_object_unref)
static void async_image_view_load_icons_data_free (gpointer _data);
static void async_image_view_load_icons (AsyncImageView* self,
                                  GAsyncReadyCallback _callback_,
                                  gpointer _user_data_);
static void async_image_view_load_icons_finish (AsyncImageView* self,
                                         GAsyncResult* _res_);
static gboolean async_image_view_load_icons_co (AsyncImageViewLoadIconsData* _data_);
static Block4Data* block4_data_ref (Block4Data* _data4_);
static void block4_data_unref (void * _userdata_);
static void __lambda32_ (AsyncImageView* self,
                  GtkWidget* child);
static void ___lambda32__gfunc (gconstpointer data,
                         gpointer self);
static void __lambda33_ (Block4Data* _data4_,
                  const gchar* name);
static void ___lambda33__gfunc (gconstpointer data,
                         gpointer self);
static void _g_free0_ (gpointer var);
static inline void _g_list_free__g_free0_ (GList* self);
VALA_EXTERN AsyncImageView* async_image_view_new (void);
VALA_EXTERN AsyncImageView* async_image_view_construct (GType object_type);
static GObject * async_image_view_constructor (GType type,
                                        guint n_construct_properties,
                                        GObjectConstructParam * construct_properties);
static void _async_image_view___lambda34_ (AsyncImageView* self);
static void __async_image_view___lambda34__gtk_button_clicked (GtkButton* _sender,
                                                        gpointer self);
static void async_image_view_finalize (GObject * obj);
static GType async_image_view_get_type_once (void);

static inline gpointer
async_image_view_get_instance_private (AsyncImageView* self)
{
	return G_STRUCT_MEMBER_P (self, AsyncImageView_private_offset);
}

static void
async_image_view_load_icons_data_free (gpointer _data)
{
	AsyncImageViewLoadIconsData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (AsyncImageViewLoadIconsData, _data_);
}

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

static void
async_image_view_load_icons (AsyncImageView* self,
                             GAsyncReadyCallback _callback_,
                             gpointer _user_data_)
{
	AsyncImageViewLoadIconsData* _data_;
	AsyncImageView* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (AsyncImageViewLoadIconsData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, async_image_view_load_icons_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	async_image_view_load_icons_co (_data_);
}

static void
async_image_view_load_icons_finish (AsyncImageView* self,
                                    GAsyncResult* _res_)
{
	AsyncImageViewLoadIconsData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static Block4Data*
block4_data_ref (Block4Data* _data4_)
{
	g_atomic_int_inc (&_data4_->_ref_count_);
	return _data4_;
}

static void
block4_data_unref (void * _userdata_)
{
	Block4Data* _data4_;
	_data4_ = (Block4Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data4_->_ref_count_)) {
		AsyncImageView* self;
		self = _data4_->self;
		_g_object_unref0 (_data4_->icons);
		_g_object_unref0 (self);
		g_slice_free (Block4Data, _data4_);
	}
}

static void
__lambda32_ (AsyncImageView* self,
             GtkWidget* child)
{
	g_return_if_fail (child != NULL);
	gtk_widget_destroy (child);
}

static void
___lambda32__gfunc (gconstpointer data,
                    gpointer self)
{
	__lambda32_ ((AsyncImageView*) self, (GtkWidget*) data);
}

static void
__lambda33_ (Block4Data* _data4_,
             const gchar* name)
{
	AsyncImageView* self;
	GeeArrayList* _tmp0_;
	self = _data4_->self;
	g_return_if_fail (name != NULL);
	_tmp0_ = _data4_->icons;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp0_, name);
}

static void
___lambda33__gfunc (gconstpointer data,
                    gpointer self)
{
	__lambda33_ (self, (const gchar*) data);
}

static void
_g_free0_ (gpointer var)
{
	var = (g_free (var), NULL);
}

static inline void
_g_list_free__g_free0_ (GList* self)
{
	g_list_free_full (self, (GDestroyNotify) _g_free0_);
}

static gboolean
async_image_view_load_icons_co (AsyncImageViewLoadIconsData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data4_ = g_slice_new0 (Block4Data);
	_data_->_data4_->_ref_count_ = 1;
	_data_->_data4_->self = g_object_ref (_data_->self);
	_data_->_data4_->_async_data_ = _data_;
	_data_->_tmp0_ = _data_->self->priv->flow_box;
	_data_->_tmp1_ = gtk_container_get_children ((GtkContainer*) _data_->_tmp0_);
	_data_->_tmp2_ = _data_->_tmp1_;
	g_list_foreach (_data_->_tmp2_, ___lambda32__gfunc, _data_->self);
	(_data_->_tmp2_ == NULL) ? NULL : (_data_->_tmp2_ = (g_list_free (_data_->_tmp2_), NULL));
	_data_->_tmp3_ = gee_array_list_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL);
	_data_->_data4_->icons = _data_->_tmp3_;
	_data_->_tmp4_ = gtk_icon_theme_get_default ();
	_data_->_tmp5_ = _g_object_ref0 (_data_->_tmp4_);
	_data_->icon_theme = _data_->_tmp5_;
	_data_->_tmp6_ = _data_->icon_theme;
	_data_->_tmp7_ = gtk_icon_theme_list_icons (_data_->_tmp6_, "Applications");
	_data_->_tmp8_ = _data_->_tmp7_;
	g_list_foreach (_data_->_tmp8_, ___lambda33__gfunc, _data_->_data4_);
	(_data_->_tmp8_ == NULL) ? NULL : (_data_->_tmp8_ = (_g_list_free__g_free0_ (_data_->_tmp8_), NULL));
	{
		_data_->_tmp9_ = _data_->_data4_->icons;
		_data_->_name_list = _data_->_tmp9_;
		_data_->_tmp10_ = _data_->_name_list;
		_data_->_tmp11_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _data_->_tmp10_);
		_data_->_tmp12_ = _data_->_tmp11_;
		_data_->_name_size = _data_->_tmp12_;
		_data_->_name_index = -1;
		while (TRUE) {
			_data_->_name_index = _data_->_name_index + 1;
			_data_->_tmp13_ = _data_->_name_index;
			_data_->_tmp14_ = _data_->_name_size;
			if (!(_data_->_tmp13_ < _data_->_tmp14_)) {
				break;
			}
			_data_->_tmp15_ = _data_->_name_list;
			_data_->_tmp16_ = gee_abstract_list_get ((GeeAbstractList*) _data_->_tmp15_, _data_->_name_index);
			_data_->name = (gchar*) _data_->_tmp16_;
			_data_->_tmp17_ = _data_->name;
			_data_->_tmp18_ = granite_async_image_new_from_icon_name_async (_data_->_tmp17_, GTK_ICON_SIZE_DIALOG, TRUE, TRUE);
			g_object_ref_sink (_data_->_tmp18_);
			_data_->image = _data_->_tmp18_;
			_data_->_tmp19_ = _data_->self->priv->flow_box;
			_data_->_tmp20_ = _data_->image;
			gtk_container_add ((GtkContainer*) _data_->_tmp19_, (GtkWidget*) _data_->_tmp20_);
			_data_->_tmp21_ = _data_->self->priv->flow_box;
			gtk_widget_show_all ((GtkWidget*) _data_->_tmp21_);
			_g_object_unref0 (_data_->image);
			_g_free0 (_data_->name);
		}
	}
	_g_object_unref0 (_data_->icon_theme);
	block4_data_unref (_data_->_data4_);
	_data_->_data4_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

AsyncImageView*
async_image_view_construct (GType object_type)
{
	AsyncImageView * self = NULL;
	self = (AsyncImageView*) g_object_new (object_type, NULL);
	return self;
}

AsyncImageView*
async_image_view_new (void)
{
	return async_image_view_construct (TYPE_ASYNC_IMAGE_VIEW);
}

static void
_async_image_view___lambda34_ (AsyncImageView* self)
{
	async_image_view_load_icons (self, NULL, NULL);
}

static void
__async_image_view___lambda34__gtk_button_clicked (GtkButton* _sender,
                                                   gpointer self)
{
	_async_image_view___lambda34_ ((AsyncImageView*) self);
}

static GObject *
async_image_view_constructor (GType type,
                              guint n_construct_properties,
                              GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	AsyncImageView * self;
	GtkFlowBox* _tmp0_;
	GtkScrolledWindow* scrolled = NULL;
	GtkScrolledWindow* _tmp1_;
	GtkScrolledWindow* _tmp2_;
	GtkScrolledWindow* _tmp3_;
	GtkStyleContext* _tmp4_;
	GtkScrolledWindow* _tmp5_;
	GtkFlowBox* _tmp6_;
	GtkButton* load_button = NULL;
	GtkButton* _tmp7_;
	GtkButton* _tmp8_;
	GtkButton* _tmp9_;
	GtkButton* _tmp10_;
	GtkScrolledWindow* _tmp11_;
	GtkSeparator* _tmp12_;
	GtkSeparator* _tmp13_;
	GtkButton* _tmp14_;
	parent_class = G_OBJECT_CLASS (async_image_view_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_ASYNC_IMAGE_VIEW, AsyncImageView);
	_tmp0_ = (GtkFlowBox*) gtk_flow_box_new ();
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->flow_box);
	self->priv->flow_box = _tmp0_;
	_tmp1_ = (GtkScrolledWindow*) gtk_scrolled_window_new (NULL, NULL);
	g_object_ref_sink (_tmp1_);
	scrolled = _tmp1_;
	_tmp2_ = scrolled;
	g_object_set ((GtkWidget*) _tmp2_, "expand", TRUE, NULL);
	_tmp3_ = scrolled;
	_tmp4_ = gtk_widget_get_style_context ((GtkWidget*) _tmp3_);
	gtk_style_context_add_class (_tmp4_, GTK_STYLE_CLASS_VIEW);
	_tmp5_ = scrolled;
	_tmp6_ = self->priv->flow_box;
	gtk_container_add ((GtkContainer*) _tmp5_, (GtkWidget*) _tmp6_);
	_tmp7_ = (GtkButton*) gtk_button_new_with_label ("Load Applications Icons");
	g_object_ref_sink (_tmp7_);
	load_button = _tmp7_;
	_tmp8_ = load_button;
	g_signal_connect_object (_tmp8_, "clicked", (GCallback) __async_image_view___lambda34__gtk_button_clicked, self, 0);
	_tmp9_ = load_button;
	g_object_set ((GtkWidget*) _tmp9_, "margin", 6, NULL);
	_tmp10_ = load_button;
	gtk_widget_set_halign ((GtkWidget*) _tmp10_, GTK_ALIGN_END);
	_tmp11_ = scrolled;
	gtk_grid_attach ((GtkGrid*) self, (GtkWidget*) _tmp11_, 0, 0, 1, 1);
	_tmp12_ = (GtkSeparator*) gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
	g_object_ref_sink (_tmp12_);
	_tmp13_ = _tmp12_;
	gtk_grid_attach ((GtkGrid*) self, (GtkWidget*) _tmp13_, 0, 1, 1, 1);
	_g_object_unref0 (_tmp13_);
	_tmp14_ = load_button;
	gtk_grid_attach ((GtkGrid*) self, (GtkWidget*) _tmp14_, 0, 2, 1, 1);
	_g_object_unref0 (load_button);
	_g_object_unref0 (scrolled);
	return obj;
}

static void
async_image_view_class_init (AsyncImageViewClass * klass,
                             gpointer klass_data)
{
	async_image_view_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &AsyncImageView_private_offset);
	G_OBJECT_CLASS (klass)->constructor = async_image_view_constructor;
	G_OBJECT_CLASS (klass)->finalize = async_image_view_finalize;
}

static void
async_image_view_instance_init (AsyncImageView * self,
                                gpointer klass)
{
	self->priv = async_image_view_get_instance_private (self);
}

static void
async_image_view_finalize (GObject * obj)
{
	AsyncImageView * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_ASYNC_IMAGE_VIEW, AsyncImageView);
	_g_object_unref0 (self->priv->flow_box);
	G_OBJECT_CLASS (async_image_view_parent_class)->finalize (obj);
}

static GType
async_image_view_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (AsyncImageViewClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) async_image_view_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (AsyncImageView), 0, (GInstanceInitFunc) async_image_view_instance_init, NULL };
	GType async_image_view_type_id;
	async_image_view_type_id = g_type_register_static (gtk_grid_get_type (), "AsyncImageView", &g_define_type_info, 0);
	AsyncImageView_private_offset = g_type_add_instance_private (async_image_view_type_id, sizeof (AsyncImageViewPrivate));
	return async_image_view_type_id;
}

GType
async_image_view_get_type (void)
{
	static volatile gsize async_image_view_type_id__once = 0;
	if (g_once_init_enter (&async_image_view_type_id__once)) {
		GType async_image_view_type_id;
		async_image_view_type_id = async_image_view_get_type_once ();
		g_once_init_leave (&async_image_view_type_id__once, async_image_view_type_id);
	}
	return async_image_view_type_id__once;
}

