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

/*
 * Copyright (C) 2009 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 <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib-object.h>
#include "rygel-server.h"
#include <glib/gi18n-lib.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_YEARS_0_PROPERTY,
	RYGEL_LOCAL_SEARCH_YEARS_NUM_PROPERTIES
};
static GParamSpec* rygel_local_search_years_properties[RYGEL_LOCAL_SEARCH_YEARS_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))

static gpointer rygel_local_search_years_parent_class = NULL;

static gchar* rygel_local_search_years_real_create_title_for_value (RygelLocalSearchMetadataContainer* base,
                                                             const gchar* value);
static gchar* rygel_local_search_years_real_create_filter (RygelLocalSearchMetadataContainer* base,
                                                    const gchar* variable,
                                                    const gchar* value);
static GType rygel_local_search_years_get_type_once (void);

RygelLocalSearchYears*
rygel_local_search_years_construct (GType object_type,
                                    RygelMediaContainer* parent,
                                    RygelLocalSearchItemFactory* item_factory)
{
	RygelLocalSearchYears * self = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	g_return_val_if_fail (parent != NULL, NULL);
	g_return_val_if_fail (item_factory != NULL, NULL);
	_tmp0_ = rygel_media_object_get_id ((RygelMediaObject*) parent);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_strconcat (_tmp1_, "Year", NULL);
	_tmp3_ = _tmp2_;
	self = (RygelLocalSearchYears*) rygel_local_search_metadata_values_construct (object_type, _tmp3_, parent, _ ("Year"), item_factory, "date", NULL);
	_g_free0 (_tmp3_);
	return self;
}

RygelLocalSearchYears*
rygel_local_search_years_new (RygelMediaContainer* parent,
                              RygelLocalSearchItemFactory* item_factory)
{
	return rygel_local_search_years_construct (RYGEL_LOCAL_SEARCH_TYPE_YEARS, parent, item_factory);
}

static glong
string_strnlen (gchar* str,
                glong maxlen)
{
	gchar* end = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	glong result;
	_tmp0_ = memchr (str, 0, (gsize) maxlen);
	end = _tmp0_;
	_tmp1_ = end;
	if (_tmp1_ == NULL) {
		result = maxlen;
		return result;
	} else {
		gchar* _tmp2_;
		_tmp2_ = end;
		result = (glong) (_tmp2_ - str);
		return result;
	}
}

static gchar*
string_substring (const gchar* self,
                  glong offset,
                  glong len)
{
	glong string_length = 0L;
	gboolean _tmp0_ = FALSE;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (offset >= ((glong) 0)) {
		_tmp0_ = len >= ((glong) 0);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		string_length = string_strnlen ((gchar*) self, offset + len);
	} else {
		gint _tmp1_;
		gint _tmp2_;
		_tmp1_ = strlen (self);
		_tmp2_ = _tmp1_;
		string_length = (glong) _tmp2_;
	}
	if (offset < ((glong) 0)) {
		offset = string_length + offset;
		g_return_val_if_fail (offset >= ((glong) 0), NULL);
	} else {
		g_return_val_if_fail (offset <= string_length, NULL);
	}
	if (len < ((glong) 0)) {
		len = string_length - offset;
	}
	g_return_val_if_fail ((offset + len) <= string_length, NULL);
	_tmp3_ = g_strndup (((gchar*) self) + offset, (gsize) len);
	result = _tmp3_;
	return result;
}

static gchar*
rygel_local_search_years_real_create_title_for_value (RygelLocalSearchMetadataContainer* base,
                                                      const gchar* value)
{
	RygelLocalSearchYears * self;
	gchar* _tmp0_;
	gchar* result;
	self = (RygelLocalSearchYears*) base;
	g_return_val_if_fail (value != NULL, NULL);
	_tmp0_ = string_substring (value, (glong) 0, (glong) 4);
	result = _tmp0_;
	return result;
}

static gchar*
rygel_local_search_years_real_create_filter (RygelLocalSearchMetadataContainer* base,
                                             const gchar* variable,
                                             const gchar* value)
{
	RygelLocalSearchYears * self;
	gchar* year = NULL;
	gchar* _tmp0_;
	gchar* next_year = NULL;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	const gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	const gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	gchar* _tmp14_;
	gchar* _tmp15_;
	gchar* _tmp16_;
	gchar* _tmp17_;
	const gchar* _tmp18_;
	gchar* _tmp19_;
	gchar* _tmp20_;
	gchar* _tmp21_;
	gchar* _tmp22_;
	gchar* result;
	self = (RygelLocalSearchYears*) base;
	g_return_val_if_fail (variable != NULL, NULL);
	g_return_val_if_fail (value != NULL, NULL);
	_tmp0_ = rygel_local_search_metadata_container_create_title_for_value ((RygelLocalSearchMetadataContainer*) self, value);
	year = _tmp0_;
	_tmp1_ = year;
	_tmp2_ = g_strdup_printf ("%i", atoi (_tmp1_) + 1);
	next_year = _tmp2_;
	_tmp3_ = year;
	_tmp4_ = g_strconcat (_tmp3_, "-01-01T00:00:00Z", NULL);
	_g_free0 (year);
	year = _tmp4_;
	_tmp5_ = next_year;
	_tmp6_ = g_strconcat (_tmp5_, "-01-01T00:00:00Z", NULL);
	_g_free0 (next_year);
	next_year = _tmp6_;
	_tmp7_ = g_strconcat (variable, " > \"", NULL);
	_tmp8_ = _tmp7_;
	_tmp9_ = year;
	_tmp10_ = g_strconcat (_tmp8_, _tmp9_, NULL);
	_tmp11_ = _tmp10_;
	_tmp12_ = g_strconcat (_tmp11_, "\"^^xsd:dateTime && ", NULL);
	_tmp13_ = _tmp12_;
	_tmp14_ = g_strconcat (_tmp13_, variable, NULL);
	_tmp15_ = _tmp14_;
	_tmp16_ = g_strconcat (_tmp15_, " < \"", NULL);
	_tmp17_ = _tmp16_;
	_tmp18_ = next_year;
	_tmp19_ = g_strconcat (_tmp17_, _tmp18_, NULL);
	_tmp20_ = _tmp19_;
	_tmp21_ = g_strconcat (_tmp20_, "\"^^xsd:dateTime", NULL);
	_tmp22_ = _tmp21_;
	_g_free0 (_tmp20_);
	_g_free0 (_tmp17_);
	_g_free0 (_tmp15_);
	_g_free0 (_tmp13_);
	_g_free0 (_tmp11_);
	_g_free0 (_tmp8_);
	result = _tmp22_;
	_g_free0 (next_year);
	_g_free0 (year);
	return result;
}

static void
rygel_local_search_years_class_init (RygelLocalSearchYearsClass * klass,
                                     gpointer klass_data)
{
	rygel_local_search_years_parent_class = g_type_class_peek_parent (klass);
	((RygelLocalSearchMetadataContainerClass *) klass)->create_title_for_value = (gchar* (*) (RygelLocalSearchMetadataContainer*, const gchar*)) rygel_local_search_years_real_create_title_for_value;
	((RygelLocalSearchMetadataContainerClass *) klass)->create_filter = (gchar* (*) (RygelLocalSearchMetadataContainer*, const gchar*, const gchar*)) rygel_local_search_years_real_create_filter;
}

static void
rygel_local_search_years_instance_init (RygelLocalSearchYears * self,
                                        gpointer klass)
{
}

/**
 * Container listing content hierarchy by year of creation.
 */
 G_GNUC_NO_INLINE static GType
rygel_local_search_years_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (RygelLocalSearchYearsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_local_search_years_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelLocalSearchYears), 0, (GInstanceInitFunc) rygel_local_search_years_instance_init, NULL };
	GType rygel_local_search_years_type_id;
	rygel_local_search_years_type_id = g_type_register_static (RYGEL_LOCAL_SEARCH_TYPE_METADATA_VALUES, "RygelLocalSearchYears", &g_define_type_info, 0);
	return rygel_local_search_years_type_id;
}

GType
rygel_local_search_years_get_type (void)
{
	static volatile gsize rygel_local_search_years_type_id__once = 0;
	if (g_once_init_enter (&rygel_local_search_years_type_id__once)) {
		GType rygel_local_search_years_type_id;
		rygel_local_search_years_type_id = rygel_local_search_years_get_type_once ();
		g_once_init_leave (&rygel_local_search_years_type_id__once, rygel_local_search_years_type_id);
	}
	return rygel_local_search_years_type_id__once;
}

