/* localsearch-category-container.c generated by valac 0.56.19, the Vala compiler
 * generated from localsearch-category-container.vala, do not modify */

/*
 * Copyright (C) 2010 Nokia Corporation.
 *
 * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
 *                               <zeeshan.ali@nokia.com>
 *
 * This file is part of Rygel.
 *
 * Rygel is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * Rygel is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "rygel-localsearch.h"
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "rygel-server.h"
#include <gee.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

enum  {
	RYGEL_LOCAL_SEARCH_CATEGORY_CONTAINER_0_PROPERTY,
	RYGEL_LOCAL_SEARCH_CATEGORY_CONTAINER_NUM_PROPERTIES
};
static GParamSpec* rygel_local_search_category_container_properties[RYGEL_LOCAL_SEARCH_CATEGORY_CONTAINER_NUM_PROPERTIES];
#define _rygel_local_search_item_factory_unref0(var) ((var == NULL) ? NULL : (var = (rygel_local_search_item_factory_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block1Data Block1Data;

struct _RygelLocalSearchCategoryContainerPrivate {
	RygelLocalSearchCategoryAllContainer* all_container;
};

struct _Block1Data {
	int _ref_count_;
	RygelLocalSearchCategoryContainer* self;
	gulong signal_id;
};

static gint RygelLocalSearchCategoryContainer_private_offset;
static gpointer rygel_local_search_category_container_parent_class = NULL;

static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static void __lambda6_ (Block1Data* _data1_);
static void rygel_local_search_category_container_on_all_container_updated (RygelLocalSearchCategoryContainer* self,
                                                                     RygelMediaContainer* other);
static void _rygel_local_search_category_container_on_all_container_updated_rygel_media_container_container_updated (RygelMediaContainer* _sender,
                                                                                                              RygelMediaContainer* container,
                                                                                                              RygelMediaObject* object,
                                                                                                              RygelObjectEventType event_type,
                                                                                                              gboolean sub_tree_update,
                                                                                                              gpointer self);
static void ___lambda6__rygel_media_container_container_updated (RygelMediaContainer* _sender,
                                                          RygelMediaContainer* container,
                                                          RygelMediaObject* object,
                                                          RygelObjectEventType event_type,
                                                          gboolean sub_tree_update,
                                                          gpointer self);
static void rygel_local_search_category_container_trigger_child_update (RygelLocalSearchCategoryContainer* self,
                                                                 RygelMediaObjects* children);
VALA_EXTERN void rygel_local_search_metadata_container_fetch_metadata_values (RygelLocalSearchMetadataContainer* self,
                                                                  GAsyncReadyCallback _callback_,
                                                                  gpointer _user_data_);
VALA_EXTERN void rygel_local_search_metadata_container_fetch_metadata_values_finish (RygelLocalSearchMetadataContainer* self,
                                                                         GAsyncResult* _res_);
VALA_EXTERN void rygel_local_search_search_container_get_children_count (RygelLocalSearchSearchContainer* self,
                                                             GAsyncReadyCallback _callback_,
                                                             gpointer _user_data_);
VALA_EXTERN void rygel_local_search_search_container_get_children_count_finish (RygelLocalSearchSearchContainer* self,
                                                                    GAsyncResult* _res_);
static void rygel_local_search_category_container_finalize (GObject * obj);
static GType rygel_local_search_category_container_get_type_once (void);

static inline gpointer
rygel_local_search_category_container_get_instance_private (RygelLocalSearchCategoryContainer* self)
{
	return G_STRUCT_MEMBER_P (self, RygelLocalSearchCategoryContainer_private_offset);
}

static Block1Data*
block1_data_ref (Block1Data* _data1_)
{
	g_atomic_int_inc (&_data1_->_ref_count_);
	return _data1_;
}

static void
block1_data_unref (void * _userdata_)
{
	Block1Data* _data1_;
	_data1_ = (Block1Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) {
		RygelLocalSearchCategoryContainer* self;
		self = _data1_->self;
		_g_object_unref0 (self);
		g_slice_free (Block1Data, _data1_);
	}
}

static gpointer
_rygel_local_search_item_factory_ref0 (gpointer self)
{
	return self ? rygel_local_search_item_factory_ref (self) : NULL;
}

static void
_rygel_local_search_category_container_on_all_container_updated_rygel_media_container_container_updated (RygelMediaContainer* _sender,
                                                                                                         RygelMediaContainer* container,
                                                                                                         RygelMediaObject* object,
                                                                                                         RygelObjectEventType event_type,
                                                                                                         gboolean sub_tree_update,
                                                                                                         gpointer self)
{
	rygel_local_search_category_container_on_all_container_updated ((RygelLocalSearchCategoryContainer*) self, container);
}

static void
__lambda6_ (Block1Data* _data1_)
{
	RygelLocalSearchCategoryContainer* self;
	RygelLocalSearchCategoryAllContainer* _tmp0_;
	RygelLocalSearchCategoryAllContainer* _tmp1_;
	self = _data1_->self;
	_tmp0_ = self->priv->all_container;
	g_signal_connect_object ((RygelMediaContainer*) _tmp0_, "container-updated", (GCallback) _rygel_local_search_category_container_on_all_container_updated_rygel_media_container_container_updated, self, 0);
	_tmp1_ = self->priv->all_container;
	g_signal_handler_disconnect ((GObject*) _tmp1_, _data1_->signal_id);
}

static void
___lambda6__rygel_media_container_container_updated (RygelMediaContainer* _sender,
                                                     RygelMediaContainer* container,
                                                     RygelMediaObject* object,
                                                     RygelObjectEventType event_type,
                                                     gboolean sub_tree_update,
                                                     gpointer self)
{
	__lambda6_ (self);
}

RygelLocalSearchCategoryContainer*
rygel_local_search_category_container_construct (GType object_type,
                                                 const gchar* id,
                                                 RygelMediaContainer* parent,
                                                 const gchar* title,
                                                 RygelLocalSearchItemFactory* item_factory)
{
	RygelLocalSearchCategoryContainer * self = NULL;
	Block1Data* _data1_;
	RygelLocalSearchItemFactory* _tmp0_;
	RygelLocalSearchCategoryAllContainer* _tmp1_;
	RygelLocalSearchCategoryAllContainer* _tmp2_;
	RygelLocalSearchTags* _tmp3_;
	RygelLocalSearchTags* _tmp4_;
	RygelLocalSearchItemFactory* _tmp5_;
	RygelLocalSearchTitles* _tmp6_;
	RygelLocalSearchTitles* _tmp7_;
	RygelLocalSearchItemFactory* _tmp8_;
	RygelLocalSearchNew* _tmp9_;
	RygelLocalSearchNew* _tmp10_;
	RygelLocalSearchCategoryAllContainer* _tmp11_;
	gulong _tmp12_;
	g_return_val_if_fail (id != NULL, NULL);
	g_return_val_if_fail (parent != NULL, NULL);
	g_return_val_if_fail (title != NULL, NULL);
	g_return_val_if_fail (item_factory != NULL, NULL);
	_data1_ = g_slice_new0 (Block1Data);
	_data1_->_ref_count_ = 1;
	self = (RygelLocalSearchCategoryContainer*) rygel_simple_container_construct (object_type, id, parent, title);
	_data1_->self = g_object_ref (self);
	_tmp0_ = _rygel_local_search_item_factory_ref0 (item_factory);
	_rygel_local_search_item_factory_unref0 (self->item_factory);
	self->item_factory = _tmp0_;
	_tmp1_ = rygel_local_search_category_all_container_new (self);
	_g_object_unref0 (self->priv->all_container);
	self->priv->all_container = _tmp1_;
	_tmp2_ = self->priv->all_container;
	rygel_simple_container_add_child_container ((RygelSimpleContainer*) self, (RygelMediaContainer*) _tmp2_);
	_tmp3_ = rygel_local_search_tags_new ((RygelMediaContainer*) self, item_factory);
	_tmp4_ = _tmp3_;
	rygel_simple_container_add_child_container ((RygelSimpleContainer*) self, (RygelMediaContainer*) _tmp4_);
	_g_object_unref0 (_tmp4_);
	_tmp5_ = self->item_factory;
	_tmp6_ = rygel_local_search_titles_new ((RygelMediaContainer*) self, _tmp5_);
	_tmp7_ = _tmp6_;
	rygel_simple_container_add_child_container ((RygelSimpleContainer*) self, (RygelMediaContainer*) _tmp7_);
	_g_object_unref0 (_tmp7_);
	_tmp8_ = self->item_factory;
	_tmp9_ = rygel_local_search_new_new ((RygelMediaContainer*) self, _tmp8_);
	_tmp10_ = _tmp9_;
	rygel_simple_container_add_child_container ((RygelSimpleContainer*) self, (RygelMediaContainer*) _tmp10_);
	_g_object_unref0 (_tmp10_);
	_data1_->signal_id = (gulong) 0;
	_tmp11_ = self->priv->all_container;
	_tmp12_ = g_signal_connect_data ((RygelMediaContainer*) _tmp11_, "container-updated", (GCallback) ___lambda6__rygel_media_container_container_updated, block1_data_ref (_data1_), (GClosureNotify) block1_data_unref, 0);
	_data1_->signal_id = _tmp12_;
	block1_data_unref (_data1_);
	_data1_ = NULL;
	return self;
}

void
rygel_local_search_category_container_add_create_class (RygelLocalSearchCategoryContainer* self,
                                                        const gchar* create_class)
{
	RygelLocalSearchCategoryAllContainer* _tmp0_;
	GeeArrayList* _tmp1_;
	GeeArrayList* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (create_class != NULL);
	_tmp0_ = self->priv->all_container;
	_tmp1_ = rygel_writable_container_get_create_classes ((RygelWritableContainer*) _tmp0_);
	_tmp2_ = _tmp1_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp2_, create_class);
}

static void
rygel_local_search_category_container_trigger_child_update (RygelLocalSearchCategoryContainer* self,
                                                            RygelMediaObjects* children)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (children != NULL);
	{
		RygelMediaObjects* _container_list = NULL;
		gint _container_size = 0;
		RygelMediaObjects* _tmp0_;
		gint _tmp1_;
		gint _tmp2_;
		gint _container_index = 0;
		_container_list = children;
		_tmp0_ = _container_list;
		_tmp1_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp0_);
		_tmp2_ = _tmp1_;
		_container_size = _tmp2_;
		_container_index = -1;
		while (TRUE) {
			gint _tmp3_;
			gint _tmp4_;
			RygelMediaObject* container = NULL;
			RygelMediaObjects* _tmp5_;
			gpointer _tmp6_;
			gboolean _tmp7_ = FALSE;
			RygelMediaObject* _tmp8_;
			RygelLocalSearchCategoryAllContainer* _tmp9_;
			RygelMediaObject* _tmp11_;
			_container_index = _container_index + 1;
			_tmp3_ = _container_index;
			_tmp4_ = _container_size;
			if (!(_tmp3_ < _tmp4_)) {
				break;
			}
			_tmp5_ = _container_list;
			_tmp6_ = gee_abstract_list_get ((GeeAbstractList*) _tmp5_, _container_index);
			container = (RygelMediaObject*) _tmp6_;
			_tmp8_ = container;
			_tmp9_ = self->priv->all_container;
			if (_tmp8_ == G_TYPE_CHECK_INSTANCE_CAST (_tmp9_, RYGEL_TYPE_MEDIA_OBJECT, RygelMediaObject)) {
				_tmp7_ = TRUE;
			} else {
				RygelMediaObject* _tmp10_;
				_tmp10_ = container;
				_tmp7_ = _tmp10_ == NULL;
			}
			if (_tmp7_) {
				_g_object_unref0 (container);
				continue;
			}
			_tmp11_ = container;
			if (RYGEL_LOCAL_SEARCH_IS_METADATA_VALUES (_tmp11_)) {
				RygelMediaObject* _tmp12_;
				_tmp12_ = container;
				rygel_local_search_metadata_container_fetch_metadata_values ((RygelLocalSearchMetadataContainer*) G_TYPE_CHECK_INSTANCE_CAST (_tmp12_, RYGEL_LOCAL_SEARCH_TYPE_METADATA_VALUES, RygelLocalSearchMetadataValues), NULL, NULL);
			} else {
				RygelMediaObject* _tmp13_;
				_tmp13_ = container;
				if (RYGEL_LOCAL_SEARCH_IS_SEARCH_CONTAINER (_tmp13_)) {
					RygelMediaObject* _tmp14_;
					_tmp14_ = container;
					rygel_local_search_search_container_get_children_count (G_TYPE_CHECK_INSTANCE_CAST (_tmp14_, RYGEL_LOCAL_SEARCH_TYPE_SEARCH_CONTAINER, RygelLocalSearchSearchContainer), NULL, NULL);
				}
			}
			_g_object_unref0 (container);
		}
	}
}

static void
rygel_local_search_category_container_on_all_container_updated (RygelLocalSearchCategoryContainer* self,
                                                                RygelMediaContainer* other)
{
	RygelLocalSearchCategoryAllContainer* _tmp0_;
	RygelMediaObjects* _tmp1_;
	RygelMediaObjects* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (other != NULL);
	_tmp0_ = self->priv->all_container;
	if (other != G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, RYGEL_TYPE_MEDIA_CONTAINER, RygelMediaContainer)) {
		return;
	}
	_tmp1_ = rygel_simple_container_get_all_children ((RygelSimpleContainer*) self);
	_tmp2_ = _tmp1_;
	rygel_local_search_category_container_trigger_child_update (self, _tmp2_);
	_g_object_unref0 (_tmp2_);
}

static void
rygel_local_search_category_container_class_init (RygelLocalSearchCategoryContainerClass * klass,
                                                  gpointer klass_data)
{
	rygel_local_search_category_container_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &RygelLocalSearchCategoryContainer_private_offset);
	G_OBJECT_CLASS (klass)->finalize = rygel_local_search_category_container_finalize;
}

static void
rygel_local_search_category_container_instance_init (RygelLocalSearchCategoryContainer * self,
                                                     gpointer klass)
{
	self->priv = rygel_local_search_category_container_get_instance_private (self);
}

static void
rygel_local_search_category_container_finalize (GObject * obj)
{
	RygelLocalSearchCategoryContainer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, RYGEL_LOCAL_SEARCH_TYPE_CATEGORY_CONTAINER, RygelLocalSearchCategoryContainer);
	_rygel_local_search_item_factory_unref0 (self->item_factory);
	_g_object_unref0 (self->priv->all_container);
	G_OBJECT_CLASS (rygel_local_search_category_container_parent_class)->finalize (obj);
}

/**
 * Container listing content hierarchy for a specific category.
 */
 G_GNUC_NO_INLINE static GType
rygel_local_search_category_container_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (RygelLocalSearchCategoryContainerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_local_search_category_container_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelLocalSearchCategoryContainer), 0, (GInstanceInitFunc) rygel_local_search_category_container_instance_init, NULL };
	GType rygel_local_search_category_container_type_id;
	rygel_local_search_category_container_type_id = g_type_register_static (RYGEL_TYPE_SIMPLE_CONTAINER, "RygelLocalSearchCategoryContainer", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
	RygelLocalSearchCategoryContainer_private_offset = g_type_add_instance_private (rygel_local_search_category_container_type_id, sizeof (RygelLocalSearchCategoryContainerPrivate));
	return rygel_local_search_category_container_type_id;
}

GType
rygel_local_search_category_container_get_type (void)
{
	static volatile gsize rygel_local_search_category_container_type_id__once = 0;
	if (g_once_init_enter (&rygel_local_search_category_container_type_id__once)) {
		GType rygel_local_search_category_container_type_id;
		rygel_local_search_category_container_type_id = rygel_local_search_category_container_get_type_once ();
		g_once_init_leave (&rygel_local_search_category_container_type_id__once, rygel_local_search_category_container_type_id);
	}
	return rygel_local_search_category_container_type_id__once;
}

