/* collection-icon-view.c generated by valac 0.36.12.13-3ae08, the Vala compiler
 * generated from collection-icon-view.vala, do not modify */

/* This file is part of GNOME Games. License: GPL-3.0+.*/

#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>


#define GAMES_TYPE_COLLECTION_ICON_VIEW (games_collection_icon_view_get_type ())
#define GAMES_COLLECTION_ICON_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_COLLECTION_ICON_VIEW, GamesCollectionIconView))
#define GAMES_COLLECTION_ICON_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_COLLECTION_ICON_VIEW, GamesCollectionIconViewClass))
#define GAMES_IS_COLLECTION_ICON_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_COLLECTION_ICON_VIEW))
#define GAMES_IS_COLLECTION_ICON_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_COLLECTION_ICON_VIEW))
#define GAMES_COLLECTION_ICON_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_COLLECTION_ICON_VIEW, GamesCollectionIconViewClass))

typedef struct _GamesCollectionIconView GamesCollectionIconView;
typedef struct _GamesCollectionIconViewClass GamesCollectionIconViewClass;
typedef struct _GamesCollectionIconViewPrivate GamesCollectionIconViewPrivate;

#define GAMES_TYPE_EMPTY_COLLECTION (games_empty_collection_get_type ())
#define GAMES_EMPTY_COLLECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_EMPTY_COLLECTION, GamesEmptyCollection))
#define GAMES_EMPTY_COLLECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_EMPTY_COLLECTION, GamesEmptyCollectionClass))
#define GAMES_IS_EMPTY_COLLECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_EMPTY_COLLECTION))
#define GAMES_IS_EMPTY_COLLECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_EMPTY_COLLECTION))
#define GAMES_EMPTY_COLLECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_EMPTY_COLLECTION, GamesEmptyCollectionClass))

typedef struct _GamesEmptyCollection GamesEmptyCollection;
typedef struct _GamesEmptyCollectionClass GamesEmptyCollectionClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define GAMES_TYPE_GAME_ICON_VIEW (games_game_icon_view_get_type ())
#define GAMES_GAME_ICON_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_GAME_ICON_VIEW, GamesGameIconView))
#define GAMES_GAME_ICON_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_GAME_ICON_VIEW, GamesGameIconViewClass))
#define GAMES_IS_GAME_ICON_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_GAME_ICON_VIEW))
#define GAMES_IS_GAME_ICON_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_GAME_ICON_VIEW))
#define GAMES_GAME_ICON_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_GAME_ICON_VIEW, GamesGameIconViewClass))

typedef struct _GamesGameIconView GamesGameIconView;
typedef struct _GamesGameIconViewClass GamesGameIconViewClass;

#define GAMES_TYPE_GAME (games_game_get_type ())
#define GAMES_GAME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_GAME, GamesGame))
#define GAMES_IS_GAME(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_GAME))
#define GAMES_GAME_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GAMES_TYPE_GAME, GamesGameIface))

typedef struct _GamesGame GamesGame;
typedef struct _GamesGameIface GamesGameIface;

#define GAMES_TYPE_ICON (games_icon_get_type ())
#define GAMES_ICON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_ICON, GamesIcon))
#define GAMES_IS_ICON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_ICON))
#define GAMES_ICON_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GAMES_TYPE_ICON, GamesIconIface))

typedef struct _GamesIcon GamesIcon;
typedef struct _GamesIconIface GamesIconIface;

#define GAMES_TYPE_COVER (games_cover_get_type ())
#define GAMES_COVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_COVER, GamesCover))
#define GAMES_IS_COVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_COVER))
#define GAMES_COVER_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GAMES_TYPE_COVER, GamesCoverIface))

typedef struct _GamesCover GamesCover;
typedef struct _GamesCoverIface GamesCoverIface;

#define GAMES_TYPE_RUNNER (games_runner_get_type ())
#define GAMES_RUNNER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_RUNNER, GamesRunner))
#define GAMES_IS_RUNNER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_RUNNER))
#define GAMES_RUNNER_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GAMES_TYPE_RUNNER, GamesRunnerIface))

typedef struct _GamesRunner GamesRunner;
typedef struct _GamesRunnerIface GamesRunnerIface;

#define GAMES_TYPE_MEDIA_SET (games_media_set_get_type ())
#define GAMES_MEDIA_SET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_MEDIA_SET, GamesMediaSet))
#define GAMES_MEDIA_SET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_MEDIA_SET, GamesMediaSetClass))
#define GAMES_IS_MEDIA_SET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_MEDIA_SET))
#define GAMES_IS_MEDIA_SET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_MEDIA_SET))
#define GAMES_MEDIA_SET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_MEDIA_SET, GamesMediaSetClass))

typedef struct _GamesMediaSet GamesMediaSet;
typedef struct _GamesMediaSetClass GamesMediaSetClass;
#define _g_free0(var) (var = (g_free (var), NULL))
enum  {
	GAMES_COLLECTION_ICON_VIEW_GAME_ACTIVATED_SIGNAL,
	GAMES_COLLECTION_ICON_VIEW_NUM_SIGNALS
};
static guint games_collection_icon_view_signals[GAMES_COLLECTION_ICON_VIEW_NUM_SIGNALS] = {0};
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _GamesCollectionIconView {
	GtkStack parent_instance;
	GamesCollectionIconViewPrivate * priv;
};

struct _GamesCollectionIconViewClass {
	GtkStackClass parent_class;
};

struct _GamesCollectionIconViewPrivate {
	gchar** filtering_terms;
	gint filtering_terms_length1;
	gint _filtering_terms_size_;
	gulong model_changed_id;
	GListModel* _model;
	GamesEmptyCollection* empty_collection;
	GtkScrolledWindow* scrolled_window;
	GtkFlowBox* flow_box;
};

struct _GamesIconIface {
	GTypeInterface parent_iface;
	GIcon* (*get_icon) (GamesIcon* self);
};

struct _GamesCoverIface {
	GTypeInterface parent_iface;
	GIcon* (*get_cover) (GamesCover* self);
};

struct _GamesRunnerIface {
	GTypeInterface parent_iface;
	gboolean (*check_is_valid) (GamesRunner* self, gchar* * error_message, GError** error);
	GtkWidget* (*get_display) (GamesRunner* self);
	void (*start) (GamesRunner* self, GError** error);
	void (*resume) (GamesRunner* self, GError** error);
	void (*pause) (GamesRunner* self);
	void (*stop) (GamesRunner* self);
	gboolean (*get_can_fullscreen) (GamesRunner* self);
	gboolean (*get_can_quit_safely) (GamesRunner* self);
	gboolean (*get_can_resume) (GamesRunner* self);
	GamesMediaSet* (*get_media_set) (GamesRunner* self);
};

struct _GamesGameIface {
	GTypeInterface parent_iface;
	GamesIcon* (*get_icon) (GamesGame* self);
	GamesCover* (*get_cover) (GamesGame* self);
	GamesRunner* (*get_runner) (GamesGame* self, GError** error);
	const gchar* (*get_name) (GamesGame* self);
};


static gpointer games_collection_icon_view_parent_class = NULL;

GType games_collection_icon_view_get_type (void) G_GNUC_CONST;
GType games_empty_collection_get_type (void) G_GNUC_CONST;
#define GAMES_COLLECTION_ICON_VIEW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GAMES_TYPE_COLLECTION_ICON_VIEW, GamesCollectionIconViewPrivate))
enum  {
	GAMES_COLLECTION_ICON_VIEW_0_PROPERTY,
	GAMES_COLLECTION_ICON_VIEW_FILTERING_TEXT_PROPERTY,
	GAMES_COLLECTION_ICON_VIEW_MODEL_PROPERTY
};
static void games_collection_icon_view_on_child_activated (GamesCollectionIconView* self, GtkFlowBoxChild* child);
GType games_game_icon_view_get_type (void) G_GNUC_CONST;
static void games_collection_icon_view_on_game_view_activated (GamesCollectionIconView* self, GamesGameIconView* game_view);
static void _games_collection_icon_view_on_child_activated_gtk_flow_box_child_activated (GtkFlowBox* _sender, GtkFlowBoxChild* child, gpointer self);
GType games_icon_get_type (void) G_GNUC_CONST;
GType games_cover_get_type (void) G_GNUC_CONST;
GType games_media_set_get_type (void) G_GNUC_CONST;
GType games_runner_get_type (void) G_GNUC_CONST;
GType games_game_get_type (void) G_GNUC_CONST;
GamesGame* games_game_icon_view_get_game (GamesGameIconView* self);
static void games_collection_icon_view_on_items_changed (GamesCollectionIconView* self, guint position, guint removed, guint added);
GListModel* games_collection_icon_view_get_model (GamesCollectionIconView* self);
static void games_collection_icon_view_add_game (GamesCollectionIconView* self, GamesGame* game);
static void games_collection_icon_view_update_collection (GamesCollectionIconView* self);
GamesGameIconView* games_game_icon_view_new (GamesGame* game);
GamesGameIconView* games_game_icon_view_construct (GType object_type, GamesGame* game);
static void games_collection_icon_view_clear_content (GamesCollectionIconView* self);
static void __lambda7_ (GamesCollectionIconView* self, GtkWidget* child);
static void ___lambda7__gtk_callback (GtkWidget* widget, gpointer self);
static gboolean games_collection_icon_view_filter_box (GamesCollectionIconView* self, GtkFlowBoxChild* child);
static gboolean games_collection_icon_view_filter_game (GamesCollectionIconView* self, GamesGame* game);
const gchar* games_game_get_name (GamesGame* self);
static gint games_collection_icon_view_sort_boxes (GamesCollectionIconView* self, GtkFlowBoxChild* child1, GtkFlowBoxChild* child2);
static gint games_collection_icon_view_sort_games (GamesCollectionIconView* self, GamesGame* game1, GamesGame* game2);
GamesCollectionIconView* games_collection_icon_view_new (void);
GamesCollectionIconView* games_collection_icon_view_construct (GType object_type);
void games_collection_icon_view_set_filtering_text (GamesCollectionIconView* self, const gchar* value);
void games_collection_icon_view_set_model (GamesCollectionIconView* self, GListModel* value);
static void _games_collection_icon_view_on_items_changed_g_list_model_items_changed (GListModel* _sender, guint position, guint removed, guint added, gpointer self);
static GObject * games_collection_icon_view_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
static gboolean _games_collection_icon_view_filter_box_gtk_flow_box_filter_func (GtkFlowBoxChild* child, gpointer self);
static gint _games_collection_icon_view_sort_boxes_gtk_flow_box_sort_func (GtkFlowBoxChild* child1, GtkFlowBoxChild* child2, gpointer self);
static void games_collection_icon_view_finalize (GObject * obj);
static void _vala_games_collection_icon_view_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_games_collection_icon_view_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);
static gint _vala_array_length (gpointer array);


static void games_collection_icon_view_on_child_activated (GamesCollectionIconView* self, GtkFlowBoxChild* child) {
	GtkFlowBoxChild* _tmp0_;
	GtkWidget* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (child != NULL);
	_tmp0_ = child;
	_tmp1_ = gtk_bin_get_child ((GtkBin*) _tmp0_);
	if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp1_, GAMES_TYPE_GAME_ICON_VIEW)) {
		GtkFlowBoxChild* _tmp2_;
		GtkWidget* _tmp3_;
		_tmp2_ = child;
		_tmp3_ = gtk_bin_get_child ((GtkBin*) _tmp2_);
		games_collection_icon_view_on_game_view_activated (self, G_TYPE_CHECK_INSTANCE_TYPE (_tmp3_, GAMES_TYPE_GAME_ICON_VIEW) ? ((GamesGameIconView*) _tmp3_) : NULL);
	}
}


static void _games_collection_icon_view_on_child_activated_gtk_flow_box_child_activated (GtkFlowBox* _sender, GtkFlowBoxChild* child, gpointer self) {
	games_collection_icon_view_on_child_activated ((GamesCollectionIconView*) self, child);
}


static void games_collection_icon_view_on_game_view_activated (GamesCollectionIconView* self, GamesGameIconView* game_view) {
	GamesGameIconView* _tmp0_;
	GamesGame* _tmp1_;
	GamesGame* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (game_view != NULL);
	_tmp0_ = game_view;
	_tmp1_ = games_game_icon_view_get_game (_tmp0_);
	_tmp2_ = _tmp1_;
	g_signal_emit (self, games_collection_icon_view_signals[GAMES_COLLECTION_ICON_VIEW_GAME_ACTIVATED_SIGNAL], 0, _tmp2_);
}


static void games_collection_icon_view_on_items_changed (GamesCollectionIconView* self, guint position, guint removed, guint added) {
	guint _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = removed;
	_vala_assert (_tmp0_ == ((guint) 0), "removed == 0");
	{
		guint i = 0U;
		guint _tmp1_;
		_tmp1_ = position;
		i = _tmp1_;
		{
			gboolean _tmp2_ = FALSE;
			_tmp2_ = TRUE;
			while (TRUE) {
				guint _tmp4_;
				guint _tmp5_;
				guint _tmp6_;
				GamesGame* game = NULL;
				GListModel* _tmp7_;
				GListModel* _tmp8_;
				guint _tmp9_;
				GObject* _tmp10_;
				GamesGame* _tmp11_;
				GamesGame* _tmp12_;
				if (!_tmp2_) {
					guint _tmp3_;
					_tmp3_ = i;
					i = _tmp3_ + 1;
				}
				_tmp2_ = FALSE;
				_tmp4_ = i;
				_tmp5_ = position;
				_tmp6_ = added;
				if (!(_tmp4_ < (_tmp5_ + _tmp6_))) {
					break;
				}
				_tmp7_ = games_collection_icon_view_get_model (self);
				_tmp8_ = _tmp7_;
				_tmp9_ = i;
				_tmp10_ = g_list_model_get_item (_tmp8_, _tmp9_);
				_tmp11_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp10_, GAMES_TYPE_GAME) ? ((GamesGame*) _tmp10_) : NULL;
				if (_tmp11_ == NULL) {
					_g_object_unref0 (_tmp10_);
				}
				game = _tmp11_;
				_tmp12_ = game;
				games_collection_icon_view_add_game (self, _tmp12_);
				_g_object_unref0 (game);
			}
		}
	}
	games_collection_icon_view_update_collection (self);
}


static void games_collection_icon_view_add_game (GamesCollectionIconView* self, GamesGame* game) {
	GamesGameIconView* game_view = NULL;
	GamesGame* _tmp0_;
	GamesGameIconView* _tmp1_;
	GtkFlowBoxChild* child = NULL;
	GtkFlowBoxChild* _tmp2_;
	GtkFlowBox* _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (game != NULL);
	_tmp0_ = game;
	_tmp1_ = games_game_icon_view_new (_tmp0_);
	g_object_ref_sink (_tmp1_);
	game_view = _tmp1_;
	_tmp2_ = (GtkFlowBoxChild*) gtk_flow_box_child_new ();
	g_object_ref_sink (_tmp2_);
	child = _tmp2_;
	gtk_widget_set_visible ((GtkWidget*) game_view, TRUE);
	gtk_widget_set_visible ((GtkWidget*) child, TRUE);
	gtk_container_add ((GtkContainer*) child, (GtkWidget*) game_view);
	_tmp3_ = self->priv->flow_box;
	gtk_container_add ((GtkContainer*) _tmp3_, (GtkWidget*) child);
	_g_object_unref0 (child);
	_g_object_unref0 (game_view);
}


static void __lambda7_ (GamesCollectionIconView* self, GtkWidget* child) {
	GtkFlowBox* _tmp0_;
	GtkWidget* _tmp1_;
	g_return_if_fail (child != NULL);
	_tmp0_ = self->priv->flow_box;
	_tmp1_ = child;
	gtk_container_remove ((GtkContainer*) _tmp0_, _tmp1_);
}


static void ___lambda7__gtk_callback (GtkWidget* widget, gpointer self) {
	__lambda7_ ((GamesCollectionIconView*) self, widget);
}


static void games_collection_icon_view_clear_content (GamesCollectionIconView* self) {
	GtkFlowBox* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->flow_box;
	gtk_container_forall ((GtkContainer*) _tmp0_, ___lambda7__gtk_callback, self);
}


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


static gboolean games_collection_icon_view_filter_box (GamesCollectionIconView* self, GtkFlowBoxChild* child) {
	gboolean result = FALSE;
	GamesGameIconView* game_view = NULL;
	GtkFlowBoxChild* _tmp0_;
	GtkWidget* _tmp1_;
	GamesGameIconView* _tmp2_;
	GamesGameIconView* _tmp3_;
	GamesGameIconView* _tmp4_;
	GamesGame* _tmp5_;
	GamesGame* _tmp6_;
	GamesGameIconView* _tmp7_;
	GamesGame* _tmp8_;
	GamesGame* _tmp9_;
	gboolean _tmp10_;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (child != NULL, FALSE);
	_tmp0_ = child;
	_tmp1_ = gtk_bin_get_child ((GtkBin*) _tmp0_);
	_tmp2_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp1_, GAMES_TYPE_GAME_ICON_VIEW) ? ((GamesGameIconView*) _tmp1_) : NULL);
	game_view = _tmp2_;
	_tmp3_ = game_view;
	if (_tmp3_ == NULL) {
		result = FALSE;
		_g_object_unref0 (game_view);
		return result;
	}
	_tmp4_ = game_view;
	_tmp5_ = games_game_icon_view_get_game (_tmp4_);
	_tmp6_ = _tmp5_;
	if (_tmp6_ == NULL) {
		result = FALSE;
		_g_object_unref0 (game_view);
		return result;
	}
	_tmp7_ = game_view;
	_tmp8_ = games_game_icon_view_get_game (_tmp7_);
	_tmp9_ = _tmp8_;
	_tmp10_ = games_collection_icon_view_filter_game (self, _tmp9_);
	result = _tmp10_;
	_g_object_unref0 (game_view);
	return result;
}


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


static gboolean games_collection_icon_view_filter_game (GamesCollectionIconView* self, GamesGame* game) {
	gboolean result = FALSE;
	gchar** _tmp0_;
	gint _tmp0__length1;
	gchar** _tmp1_;
	gint _tmp1__length1;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (game != NULL, FALSE);
	_tmp0_ = self->priv->filtering_terms;
	_tmp0__length1 = self->priv->filtering_terms_length1;
	if (_tmp0__length1 == 0) {
		result = TRUE;
		return result;
	}
	_tmp1_ = self->priv->filtering_terms;
	_tmp1__length1 = self->priv->filtering_terms_length1;
	{
		gchar** term_collection = NULL;
		gint term_collection_length1 = 0;
		gint _term_collection_size_ = 0;
		gint term_it = 0;
		term_collection = _tmp1_;
		term_collection_length1 = _tmp1__length1;
		for (term_it = 0; term_it < _tmp1__length1; term_it = term_it + 1) {
			gchar* _tmp2_;
			gchar* term = NULL;
			_tmp2_ = g_strdup (term_collection[term_it]);
			term = _tmp2_;
			{
				GamesGame* _tmp3_;
				const gchar* _tmp4_;
				const gchar* _tmp5_;
				gchar* _tmp6_;
				gchar* _tmp7_;
				const gchar* _tmp8_;
				gchar* _tmp9_;
				gchar* _tmp10_;
				gboolean _tmp11_;
				gboolean _tmp12_;
				_tmp3_ = game;
				_tmp4_ = games_game_get_name (_tmp3_);
				_tmp5_ = _tmp4_;
				_tmp6_ = g_utf8_casefold (_tmp5_, (gssize) -1);
				_tmp7_ = _tmp6_;
				_tmp8_ = term;
				_tmp9_ = g_utf8_casefold (_tmp8_, (gssize) -1);
				_tmp10_ = _tmp9_;
				_tmp11_ = string_contains (_tmp7_, _tmp10_);
				_tmp12_ = !_tmp11_;
				_g_free0 (_tmp10_);
				_g_free0 (_tmp7_);
				if (_tmp12_) {
					result = FALSE;
					_g_free0 (term);
					return result;
				}
				_g_free0 (term);
			}
		}
	}
	result = TRUE;
	return result;
}


static gint games_collection_icon_view_sort_boxes (GamesCollectionIconView* self, GtkFlowBoxChild* child1, GtkFlowBoxChild* child2) {
	gint result = 0;
	GamesGameIconView* game_view1 = NULL;
	GtkFlowBoxChild* _tmp0_;
	GtkWidget* _tmp1_;
	GamesGameIconView* _tmp2_;
	GamesGameIconView* game_view2 = NULL;
	GtkFlowBoxChild* _tmp3_;
	GtkWidget* _tmp4_;
	GamesGameIconView* _tmp5_;
	GamesGame* _tmp6_;
	GamesGame* _tmp7_;
	GamesGame* _tmp8_;
	GamesGame* _tmp9_;
	gint _tmp10_;
	g_return_val_if_fail (self != NULL, 0);
	g_return_val_if_fail (child1 != NULL, 0);
	g_return_val_if_fail (child2 != NULL, 0);
	_tmp0_ = child1;
	_tmp1_ = gtk_bin_get_child ((GtkBin*) _tmp0_);
	_tmp2_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp1_, GAMES_TYPE_GAME_ICON_VIEW) ? ((GamesGameIconView*) _tmp1_) : NULL);
	game_view1 = _tmp2_;
	_tmp3_ = child2;
	_tmp4_ = gtk_bin_get_child ((GtkBin*) _tmp3_);
	_tmp5_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp4_, GAMES_TYPE_GAME_ICON_VIEW) ? ((GamesGameIconView*) _tmp4_) : NULL);
	game_view2 = _tmp5_;
	_vala_assert (game_view1 != NULL, "game_view1 != null");
	_vala_assert (game_view2 != NULL, "game_view2 != null");
	_tmp6_ = games_game_icon_view_get_game (game_view1);
	_tmp7_ = _tmp6_;
	_tmp8_ = games_game_icon_view_get_game (game_view2);
	_tmp9_ = _tmp8_;
	_tmp10_ = games_collection_icon_view_sort_games (self, _tmp7_, _tmp9_);
	result = _tmp10_;
	_g_object_unref0 (game_view2);
	_g_object_unref0 (game_view1);
	return result;
}


static gint games_collection_icon_view_sort_games (GamesCollectionIconView* self, GamesGame* game1, GamesGame* game2) {
	gint result = 0;
	GamesGame* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	GamesGame* _tmp3_;
	const gchar* _tmp4_;
	const gchar* _tmp5_;
	gint _tmp6_;
	g_return_val_if_fail (self != NULL, 0);
	g_return_val_if_fail (game1 != NULL, 0);
	g_return_val_if_fail (game2 != NULL, 0);
	_tmp0_ = game1;
	_tmp1_ = games_game_get_name (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = game2;
	_tmp4_ = games_game_get_name (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = g_utf8_collate (_tmp2_, _tmp5_);
	result = _tmp6_;
	return result;
}


static void games_collection_icon_view_update_collection (GamesCollectionIconView* self) {
	GListModel* _tmp0_;
	GListModel* _tmp1_;
	guint _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = games_collection_icon_view_get_model (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_list_model_get_n_items (_tmp1_);
	if (_tmp2_ == ((guint) 0)) {
		GamesEmptyCollection* _tmp3_;
		_tmp3_ = self->priv->empty_collection;
		gtk_stack_set_visible_child ((GtkStack*) self, (GtkWidget*) _tmp3_);
	} else {
		GtkScrolledWindow* _tmp4_;
		_tmp4_ = self->priv->scrolled_window;
		gtk_stack_set_visible_child ((GtkStack*) self, (GtkWidget*) _tmp4_);
	}
}


GamesCollectionIconView* games_collection_icon_view_construct (GType object_type) {
	GamesCollectionIconView * self = NULL;
	self = (GamesCollectionIconView*) g_object_new (object_type, NULL);
	return self;
}


GamesCollectionIconView* games_collection_icon_view_new (void) {
	return games_collection_icon_view_construct (GAMES_TYPE_COLLECTION_ICON_VIEW);
}


void games_collection_icon_view_set_filtering_text (GamesCollectionIconView* self, const gchar* value) {
	const gchar* _tmp0_;
	gchar** _tmp1_;
	gchar** _tmp2_;
	GtkFlowBox* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	_tmp2_ = _tmp1_ = g_strsplit (_tmp0_, " ", 0);
	self->priv->filtering_terms = (_vala_array_free (self->priv->filtering_terms, self->priv->filtering_terms_length1, (GDestroyNotify) g_free), NULL);
	self->priv->filtering_terms = _tmp2_;
	self->priv->filtering_terms_length1 = _vala_array_length (_tmp1_);
	self->priv->_filtering_terms_size_ = self->priv->filtering_terms_length1;
	_tmp3_ = self->priv->flow_box;
	gtk_flow_box_invalidate_filter (_tmp3_);
	g_object_notify ((GObject *) self, "filtering-text");
}


GListModel* games_collection_icon_view_get_model (GamesCollectionIconView* self) {
	GListModel* result;
	GListModel* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_model;
	result = _tmp0_;
	return result;
}


static void _games_collection_icon_view_on_items_changed_g_list_model_items_changed (GListModel* _sender, guint position, guint removed, guint added, gpointer self) {
	games_collection_icon_view_on_items_changed ((GamesCollectionIconView*) self, position, removed, added);
}


void games_collection_icon_view_set_model (GamesCollectionIconView* self, GListModel* value) {
	GListModel* _tmp0_;
	GListModel* _tmp1_;
	GListModel* _tmp5_;
	GListModel* _tmp6_;
	GListModel* _tmp7_;
	GListModel* _tmp8_;
	GListModel* _tmp21_;
	GListModel* _tmp22_;
	gulong _tmp23_;
	GtkFlowBox* _tmp24_;
	g_return_if_fail (self != NULL);
	_tmp0_ = games_collection_icon_view_get_model (self);
	_tmp1_ = _tmp0_;
	if (_tmp1_ != NULL) {
		GListModel* _tmp2_;
		GListModel* _tmp3_;
		gulong _tmp4_;
		_tmp2_ = games_collection_icon_view_get_model (self);
		_tmp3_ = _tmp2_;
		_tmp4_ = self->priv->model_changed_id;
		g_signal_handler_disconnect ((GObject*) _tmp3_, _tmp4_);
	}
	_tmp5_ = value;
	_tmp6_ = _g_object_ref0 (_tmp5_);
	_g_object_unref0 (self->priv->_model);
	self->priv->_model = _tmp6_;
	games_collection_icon_view_clear_content (self);
	_tmp7_ = games_collection_icon_view_get_model (self);
	_tmp8_ = _tmp7_;
	if (_tmp8_ == NULL) {
		return;
	}
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp9_ = FALSE;
			_tmp9_ = TRUE;
			while (TRUE) {
				gint _tmp11_;
				GListModel* _tmp12_;
				GListModel* _tmp13_;
				guint _tmp14_;
				GamesGame* game = NULL;
				GListModel* _tmp15_;
				GListModel* _tmp16_;
				gint _tmp17_;
				GObject* _tmp18_;
				GamesGame* _tmp19_;
				GamesGame* _tmp20_;
				if (!_tmp9_) {
					gint _tmp10_;
					_tmp10_ = i;
					i = _tmp10_ + 1;
				}
				_tmp9_ = FALSE;
				_tmp11_ = i;
				_tmp12_ = games_collection_icon_view_get_model (self);
				_tmp13_ = _tmp12_;
				_tmp14_ = g_list_model_get_n_items (_tmp13_);
				if (!(((guint) _tmp11_) < _tmp14_)) {
					break;
				}
				_tmp15_ = games_collection_icon_view_get_model (self);
				_tmp16_ = _tmp15_;
				_tmp17_ = i;
				_tmp18_ = g_list_model_get_item (_tmp16_, (guint) _tmp17_);
				_tmp19_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp18_, GAMES_TYPE_GAME) ? ((GamesGame*) _tmp18_) : NULL;
				if (_tmp19_ == NULL) {
					_g_object_unref0 (_tmp18_);
				}
				game = _tmp19_;
				_tmp20_ = game;
				games_collection_icon_view_add_game (self, _tmp20_);
				_g_object_unref0 (game);
			}
		}
	}
	_tmp21_ = games_collection_icon_view_get_model (self);
	_tmp22_ = _tmp21_;
	_tmp23_ = g_signal_connect_object (_tmp22_, "items-changed", (GCallback) _games_collection_icon_view_on_items_changed_g_list_model_items_changed, self, 0);
	self->priv->model_changed_id = _tmp23_;
	_tmp24_ = self->priv->flow_box;
	gtk_flow_box_invalidate_sort (_tmp24_);
	g_object_notify ((GObject *) self, "model");
}


static gboolean _games_collection_icon_view_filter_box_gtk_flow_box_filter_func (GtkFlowBoxChild* child, gpointer self) {
	gboolean result;
	result = games_collection_icon_view_filter_box ((GamesCollectionIconView*) self, child);
	return result;
}


static gint _games_collection_icon_view_sort_boxes_gtk_flow_box_sort_func (GtkFlowBoxChild* child1, GtkFlowBoxChild* child2, gpointer self) {
	gint result;
	result = games_collection_icon_view_sort_boxes ((GamesCollectionIconView*) self, child1, child2);
	return result;
}


static GObject * games_collection_icon_view_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	GObjectClass * parent_class;
	GamesCollectionIconView * self;
	GtkFlowBox* _tmp0_;
	GtkFlowBox* _tmp1_;
	GtkFlowBox* _tmp2_;
	parent_class = G_OBJECT_CLASS (games_collection_icon_view_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_COLLECTION_ICON_VIEW, GamesCollectionIconView);
	_tmp0_ = self->priv->flow_box;
	gtk_flow_box_set_max_children_per_line (_tmp0_, G_MAXUINT);
	_tmp1_ = self->priv->flow_box;
	gtk_flow_box_set_filter_func (_tmp1_, _games_collection_icon_view_filter_box_gtk_flow_box_filter_func, g_object_ref (self), g_object_unref);
	_tmp2_ = self->priv->flow_box;
	gtk_flow_box_set_sort_func (_tmp2_, _games_collection_icon_view_sort_boxes_gtk_flow_box_sort_func, g_object_ref (self), g_object_unref);
	return obj;
}


static void games_collection_icon_view_class_init (GamesCollectionIconViewClass * klass) {
	gint GamesCollectionIconView_private_offset;
	games_collection_icon_view_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GamesCollectionIconViewPrivate));
	G_OBJECT_CLASS (klass)->get_property = _vala_games_collection_icon_view_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_games_collection_icon_view_set_property;
	G_OBJECT_CLASS (klass)->constructor = games_collection_icon_view_constructor;
	G_OBJECT_CLASS (klass)->finalize = games_collection_icon_view_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GAMES_COLLECTION_ICON_VIEW_FILTERING_TEXT_PROPERTY, g_param_spec_string ("filtering-text", "filtering-text", "filtering-text", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GAMES_COLLECTION_ICON_VIEW_MODEL_PROPERTY, g_param_spec_object ("model", "model", "model", g_list_model_get_type (), G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	GamesCollectionIconView_private_offset = g_type_class_get_instance_private_offset (klass);
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/Games/ui/collection-icon-view.ui");
	games_collection_icon_view_signals[GAMES_COLLECTION_ICON_VIEW_GAME_ACTIVATED_SIGNAL] = g_signal_new ("game-activated", GAMES_TYPE_COLLECTION_ICON_VIEW, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GAMES_TYPE_GAME);
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "empty_collection", FALSE, GamesCollectionIconView_private_offset + G_STRUCT_OFFSET (GamesCollectionIconViewPrivate, empty_collection));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "scrolled_window", FALSE, GamesCollectionIconView_private_offset + G_STRUCT_OFFSET (GamesCollectionIconViewPrivate, scrolled_window));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "flow_box", FALSE, GamesCollectionIconView_private_offset + G_STRUCT_OFFSET (GamesCollectionIconViewPrivate, flow_box));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_child_activated", G_CALLBACK(_games_collection_icon_view_on_child_activated_gtk_flow_box_child_activated));
	gtk_widget_class_set_css_name (GTK_WIDGET_CLASS (klass), "gamescollectioniconview");
}


static void games_collection_icon_view_instance_init (GamesCollectionIconView * self) {
	self->priv = GAMES_COLLECTION_ICON_VIEW_GET_PRIVATE (self);
	g_type_ensure (GAMES_TYPE_EMPTY_COLLECTION);
	gtk_widget_init_template (GTK_WIDGET (self));
}


static void games_collection_icon_view_finalize (GObject * obj) {
	GamesCollectionIconView * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_COLLECTION_ICON_VIEW, GamesCollectionIconView);
	self->priv->filtering_terms = (_vala_array_free (self->priv->filtering_terms, self->priv->filtering_terms_length1, (GDestroyNotify) g_free), NULL);
	_g_object_unref0 (self->priv->_model);
	_g_object_unref0 (self->priv->empty_collection);
	_g_object_unref0 (self->priv->scrolled_window);
	_g_object_unref0 (self->priv->flow_box);
	G_OBJECT_CLASS (games_collection_icon_view_parent_class)->finalize (obj);
}


GType games_collection_icon_view_get_type (void) {
	static volatile gsize games_collection_icon_view_type_id__volatile = 0;
	if (g_once_init_enter (&games_collection_icon_view_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (GamesCollectionIconViewClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_collection_icon_view_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesCollectionIconView), 0, (GInstanceInitFunc) games_collection_icon_view_instance_init, NULL };
		GType games_collection_icon_view_type_id;
		games_collection_icon_view_type_id = g_type_register_static (gtk_stack_get_type (), "GamesCollectionIconView", &g_define_type_info, 0);
		g_once_init_leave (&games_collection_icon_view_type_id__volatile, games_collection_icon_view_type_id);
	}
	return games_collection_icon_view_type_id__volatile;
}


static void _vala_games_collection_icon_view_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	GamesCollectionIconView * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GAMES_TYPE_COLLECTION_ICON_VIEW, GamesCollectionIconView);
	switch (property_id) {
		case GAMES_COLLECTION_ICON_VIEW_MODEL_PROPERTY:
		g_value_set_object (value, games_collection_icon_view_get_model (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_games_collection_icon_view_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	GamesCollectionIconView * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GAMES_TYPE_COLLECTION_ICON_VIEW, GamesCollectionIconView);
	switch (property_id) {
		case GAMES_COLLECTION_ICON_VIEW_FILTERING_TEXT_PROPERTY:
		games_collection_icon_view_set_filtering_text (self, g_value_get_string (value));
		break;
		case GAMES_COLLECTION_ICON_VIEW_MODEL_PROPERTY:
		games_collection_icon_view_set_model (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int 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, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}


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



