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

/*
 * Copyright (C) 2008 Zeeshan Ali <zeenix@gmail.com>.
 * Copyright (C) 2008-2012 Nokia Corporation.
 *
 * Author: Zeeshan Ali <zeenix@gmail.com>
 *         Jens Georg <jensg@openismus.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 <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib-object.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_METADATA_VALUES_0_PROPERTY,
	RYGEL_LOCAL_SEARCH_METADATA_VALUES_NUM_PROPERTIES
};
static GParamSpec* rygel_local_search_metadata_values_properties[RYGEL_LOCAL_SEARCH_METADATA_VALUES_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _rygel_local_search_query_triplet_unref0(var) ((var == NULL) ? NULL : (var = (rygel_local_search_query_triplet_unref (var), NULL)))

struct _RygelLocalSearchMetadataValuesPrivate {
	gchar* property;
};

static gint RygelLocalSearchMetadataValues_private_offset;
static gpointer rygel_local_search_metadata_values_parent_class = NULL;

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_);
static RygelLocalSearchSelectionQuery* rygel_local_search_metadata_values_real_create_query (RygelLocalSearchMetadataContainer* base);
static RygelLocalSearchSearchContainer* rygel_local_search_metadata_values_real_create_container (RygelLocalSearchMetadataContainer* base,
                                                                                           const gchar* id,
                                                                                           const gchar* title,
                                                                                           const gchar* value);
static void rygel_local_search_metadata_values_finalize (GObject * obj);
static GType rygel_local_search_metadata_values_get_type_once (void);

static inline gpointer
rygel_local_search_metadata_values_get_instance_private (RygelLocalSearchMetadataValues* self)
{
	return G_STRUCT_MEMBER_P (self, RygelLocalSearchMetadataValues_private_offset);
}

RygelLocalSearchMetadataValues*
rygel_local_search_metadata_values_construct (GType object_type,
                                              const gchar* id,
                                              RygelMediaContainer* parent,
                                              const gchar* title,
                                              RygelLocalSearchItemFactory* item_factory,
                                              const gchar* property,
                                              const gchar* child_class)
{
	RygelLocalSearchMetadataValues * self = NULL;
	gchar* _tmp0_;
	RygelLocalSearchQueryTriplets* _tmp1_;
	RygelLocalSearchQueryTriplets* _tmp2_;
	RygelLocalSearchItemFactory* _tmp3_;
	const gchar* _tmp4_;
	RygelLocalSearchQueryTriplet* _tmp5_;
	RygelLocalSearchQueryTriplet* _tmp6_;
	RygelLocalSearchQueryTriplets* _tmp7_;
	RygelLocalSearchQueryTriplet* _tmp8_;
	RygelLocalSearchQueryTriplet* _tmp9_;
	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);
	g_return_val_if_fail (property != NULL, NULL);
	self = (RygelLocalSearchMetadataValues*) rygel_local_search_metadata_container_construct (object_type, id, parent, title, item_factory, child_class);
	_tmp0_ = g_strdup (property);
	_g_free0 (self->priv->property);
	self->priv->property = _tmp0_;
	_tmp1_ = rygel_local_search_query_triplets_new ();
	_g_object_unref0 (((RygelLocalSearchMetadataContainer*) self)->triplets);
	((RygelLocalSearchMetadataContainer*) self)->triplets = _tmp1_;
	_tmp2_ = ((RygelLocalSearchMetadataContainer*) self)->triplets;
	_tmp3_ = ((RygelLocalSearchMetadataContainer*) self)->item_factory;
	_tmp4_ = _tmp3_->category;
	_tmp5_ = rygel_local_search_query_triplet_new (RYGEL_LOCAL_SEARCH_SELECTION_QUERY_ITEM_VARIABLE, "a", _tmp4_);
	_tmp6_ = _tmp5_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp2_, _tmp6_);
	_rygel_local_search_query_triplet_unref0 (_tmp6_);
	_tmp7_ = ((RygelLocalSearchMetadataContainer*) self)->triplets;
	_tmp8_ = rygel_local_search_query_triplet_new (RYGEL_LOCAL_SEARCH_SELECTION_QUERY_ITEM_VARIABLE, "nie:isStoredAs", RYGEL_LOCAL_SEARCH_SELECTION_QUERY_STORAGE_VARIABLE);
	_tmp9_ = _tmp8_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp7_, _tmp9_);
	_rygel_local_search_query_triplet_unref0 (_tmp9_);
	rygel_local_search_metadata_container_fetch_metadata_values ((RygelLocalSearchMetadataContainer*) self, NULL, NULL);
	return self;
}

static RygelLocalSearchSelectionQuery*
rygel_local_search_metadata_values_real_create_query (RygelLocalSearchMetadataContainer* base)
{
	RygelLocalSearchMetadataValues * self;
	RygelLocalSearchUPnPPropertyMap* property_map = NULL;
	RygelLocalSearchUPnPPropertyMap* _tmp0_;
	GeeArrayList* selected = NULL;
	GeeArrayList* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	RygelLocalSearchSelectionQuery* q = NULL;
	RygelLocalSearchQueryTriplets* _tmp9_;
	RygelLocalSearchItemFactory* _tmp10_;
	const gchar* _tmp11_;
	RygelLocalSearchSelectionQuery* _tmp12_;
	RygelLocalSearchSelectionQuery* result;
	self = (RygelLocalSearchMetadataValues*) base;
	_tmp0_ = rygel_local_search_upn_pproperty_map_get_property_map ();
	property_map = _tmp0_;
	_tmp1_ = gee_array_list_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL);
	selected = _tmp1_;
	_tmp2_ = self->priv->property;
	_tmp3_ = rygel_local_search_upn_pproperty_map_get (property_map, _tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = g_strconcat ("DISTINCT ", _tmp4_, NULL);
	_tmp6_ = _tmp5_;
	_tmp7_ = g_strconcat (_tmp6_, " AS ?x", NULL);
	_tmp8_ = _tmp7_;
	gee_abstract_collection_add ((GeeAbstractCollection*) selected, _tmp8_);
	_g_free0 (_tmp8_);
	_g_free0 (_tmp6_);
	_g_free0 (_tmp4_);
	_tmp9_ = ((RygelLocalSearchMetadataContainer*) self)->triplets;
	_tmp10_ = ((RygelLocalSearchMetadataContainer*) self)->item_factory;
	_tmp11_ = _tmp10_->graph;
	_tmp12_ = rygel_local_search_selection_query_new (selected, _tmp9_, NULL, _tmp11_, "?x", 0, -1);
	q = _tmp12_;
	result = q;
	_g_object_unref0 (selected);
	_g_object_unref0 (property_map);
	return result;
}

static RygelLocalSearchSearchContainer*
rygel_local_search_metadata_values_real_create_container (RygelLocalSearchMetadataContainer* base,
                                                          const gchar* id,
                                                          const gchar* title,
                                                          const gchar* value)
{
	RygelLocalSearchMetadataValues * self;
	RygelLocalSearchQueryTriplets* child_triplets = NULL;
	RygelLocalSearchQueryTriplets* _tmp0_;
	RygelLocalSearchQueryTriplets* _tmp1_;
	GeeArrayList* filters = NULL;
	GeeArrayList* _tmp2_;
	RygelLocalSearchUPnPPropertyMap* property_map = NULL;
	RygelLocalSearchUPnPPropertyMap* _tmp3_;
	gchar* property = NULL;
	RygelLocalSearchUPnPPropertyMap* _tmp4_;
	const gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* filter = NULL;
	const gchar* _tmp7_;
	gchar* _tmp8_;
	GeeArrayList* _tmp9_;
	const gchar* _tmp10_;
	RygelLocalSearchSearchContainer* child = NULL;
	RygelLocalSearchItemFactory* _tmp11_;
	RygelLocalSearchQueryTriplets* _tmp12_;
	GeeArrayList* _tmp13_;
	RygelLocalSearchSearchContainer* _tmp14_;
	const gchar* _tmp15_;
	RygelLocalSearchSearchContainer* result;
	self = (RygelLocalSearchMetadataValues*) base;
	g_return_val_if_fail (id != NULL, NULL);
	g_return_val_if_fail (title != NULL, NULL);
	g_return_val_if_fail (value != NULL, NULL);
	_tmp0_ = ((RygelLocalSearchMetadataContainer*) self)->triplets;
	_tmp1_ = rygel_local_search_query_triplets_new_clone (_tmp0_);
	child_triplets = _tmp1_;
	_tmp2_ = gee_array_list_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL);
	filters = _tmp2_;
	_tmp3_ = rygel_local_search_upn_pproperty_map_get_property_map ();
	property_map = _tmp3_;
	_tmp4_ = property_map;
	_tmp5_ = self->priv->property;
	_tmp6_ = rygel_local_search_upn_pproperty_map_get (_tmp4_, _tmp5_);
	property = _tmp6_;
	_tmp7_ = property;
	_tmp8_ = rygel_local_search_metadata_container_create_filter ((RygelLocalSearchMetadataContainer*) self, _tmp7_, value);
	filter = _tmp8_;
	_tmp9_ = filters;
	_tmp10_ = filter;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp9_, _tmp10_);
	_tmp11_ = ((RygelLocalSearchMetadataContainer*) self)->item_factory;
	_tmp12_ = child_triplets;
	_tmp13_ = filters;
	_tmp14_ = rygel_local_search_search_container_new (id, (RygelMediaContainer*) self, title, _tmp11_, _tmp12_, _tmp13_);
	child = _tmp14_;
	_tmp15_ = self->priv->property;
	if (g_strcmp0 (_tmp15_, "upnp:album") == 0) {
		RygelLocalSearchSearchContainer* _tmp16_;
		_tmp16_ = child;
		rygel_media_container_set_sort_criteria ((RygelMediaContainer*) _tmp16_, RYGEL_MEDIA_CONTAINER_ALBUM_SORT_CRITERIA);
	}
	result = child;
	_g_free0 (filter);
	_g_free0 (property);
	_g_object_unref0 (property_map);
	_g_object_unref0 (filters);
	_g_object_unref0 (child_triplets);
	return result;
}

static void
rygel_local_search_metadata_values_class_init (RygelLocalSearchMetadataValuesClass * klass,
                                               gpointer klass_data)
{
	rygel_local_search_metadata_values_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &RygelLocalSearchMetadataValues_private_offset);
	((RygelLocalSearchMetadataContainerClass *) klass)->create_query = (RygelLocalSearchSelectionQuery* (*) (RygelLocalSearchMetadataContainer*)) rygel_local_search_metadata_values_real_create_query;
	((RygelLocalSearchMetadataContainerClass *) klass)->create_container = (RygelLocalSearchSearchContainer* (*) (RygelLocalSearchMetadataContainer*, const gchar*, const gchar*, const gchar*)) rygel_local_search_metadata_values_real_create_container;
	G_OBJECT_CLASS (klass)->finalize = rygel_local_search_metadata_values_finalize;
}

static void
rygel_local_search_metadata_values_instance_init (RygelLocalSearchMetadataValues * self,
                                                  gpointer klass)
{
	self->priv = rygel_local_search_metadata_values_get_instance_private (self);
}

static void
rygel_local_search_metadata_values_finalize (GObject * obj)
{
	RygelLocalSearchMetadataValues * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, RYGEL_LOCAL_SEARCH_TYPE_METADATA_VALUES, RygelLocalSearchMetadataValues);
	_g_free0 (self->priv->property);
	G_OBJECT_CLASS (rygel_local_search_metadata_values_parent_class)->finalize (obj);
}

/**
 * Container listing possible values of a particuler LocalSearch metadata key.
 * The key needs to be single-valued.
 */
 G_GNUC_NO_INLINE static GType
rygel_local_search_metadata_values_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (RygelLocalSearchMetadataValuesClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_local_search_metadata_values_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelLocalSearchMetadataValues), 0, (GInstanceInitFunc) rygel_local_search_metadata_values_instance_init, NULL };
	GType rygel_local_search_metadata_values_type_id;
	rygel_local_search_metadata_values_type_id = g_type_register_static (RYGEL_LOCAL_SEARCH_TYPE_METADATA_CONTAINER, "RygelLocalSearchMetadataValues", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
	RygelLocalSearchMetadataValues_private_offset = g_type_add_instance_private (rygel_local_search_metadata_values_type_id, sizeof (RygelLocalSearchMetadataValuesPrivate));
	return rygel_local_search_metadata_values_type_id;
}

GType
rygel_local_search_metadata_values_get_type (void)
{
	static volatile gsize rygel_local_search_metadata_values_type_id__once = 0;
	if (g_once_init_enter (&rygel_local_search_metadata_values_type_id__once)) {
		GType rygel_local_search_metadata_values_type_id;
		rygel_local_search_metadata_values_type_id = rygel_local_search_metadata_values_get_type_once ();
		g_once_init_leave (&rygel_local_search_metadata_values_type_id__once, rygel_local_search_metadata_values_type_id);
	}
	return rygel_local_search_metadata_values_type_id__once;
}

