/* rygel-lms-image-years.c generated by valac 0.56.1, the Vala compiler
 * generated from rygel-lms-image-years.vala, do not modify */

/*
 * Copyright (C) 2013 Intel Corporation.
 *
 * Author: Jussi Kukkonen <jussi.kukkonen@intel.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-lms.h"
#include <sqlite3.h>
#include "rygel-server.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib/gi18n-lib.h>

#define RYGEL_LMS_IMAGE_YEARS_SQL_ALL "SELECT DISTINCT(strftime('%Y', images.date, 'unixepoch')) as year " "FROM images " "LIMIT ? OFFSET ?;"
#define RYGEL_LMS_IMAGE_YEARS_SQL_COUNT "SELECT COUNT(DISTINCT(strftime('%Y', images.date, 'unixepoch'))) " "FROM images;"
#define RYGEL_LMS_IMAGE_YEARS_SQL_FIND_OBJECT "SELECT strftime('%Y', images.date, 'unixepoch') as year " "FROM images " "WHERE year = CAST(? AS TEXT)"

enum  {
	RYGEL_LMS_IMAGE_YEARS_0_PROPERTY,
	RYGEL_LMS_IMAGE_YEARS_NUM_PROPERTIES
};
static GParamSpec* rygel_lms_image_years_properties[RYGEL_LMS_IMAGE_YEARS_NUM_PROPERTIES];

static gpointer rygel_lms_image_years_parent_class = NULL;

static RygelMediaObject* rygel_lms_image_years_real_object_from_statement (RygelLMSCategoryContainer* base,
                                                                    sqlite3_stmt* statement);
static GType rygel_lms_image_years_get_type_once (void);

static RygelMediaObject*
rygel_lms_image_years_real_object_from_statement (RygelLMSCategoryContainer* base,
                                                  sqlite3_stmt* statement)
{
	RygelLMSImageYears * self;
	const gchar* _tmp0_;
	RygelLMSDatabase* _tmp1_;
	RygelLMSDatabase* _tmp2_;
	RygelLMSImageYear* _tmp3_;
	RygelMediaObject* result;
	self = (RygelLMSImageYears*) base;
	g_return_val_if_fail (statement != NULL, NULL);
	_tmp0_ = (const gchar*) sqlite3_column_text (statement, 0);
	_tmp1_ = rygel_lms_category_container_get_lms_db ((RygelLMSCategoryContainer*) self);
	_tmp2_ = _tmp1_;
	_tmp3_ = rygel_lms_image_year_new ((RygelMediaContainer*) self, _tmp0_, _tmp2_);
	result = (RygelMediaObject*) _tmp3_;
	return result;
}

RygelLMSImageYears*
rygel_lms_image_years_construct (GType object_type,
                                 RygelMediaContainer* parent,
                                 RygelLMSDatabase* lms_db)
{
	RygelLMSImageYears * self = NULL;
	g_return_val_if_fail (parent != NULL, NULL);
	g_return_val_if_fail (lms_db != NULL, NULL);
	self = (RygelLMSImageYears*) rygel_lms_category_container_construct (object_type, "years", parent, _ ("Years"), lms_db, RYGEL_LMS_IMAGE_YEARS_SQL_ALL, RYGEL_LMS_IMAGE_YEARS_SQL_FIND_OBJECT, RYGEL_LMS_IMAGE_YEARS_SQL_COUNT, NULL, NULL);
	return self;
}

RygelLMSImageYears*
rygel_lms_image_years_new (RygelMediaContainer* parent,
                           RygelLMSDatabase* lms_db)
{
	return rygel_lms_image_years_construct (RYGEL_LMS_TYPE_IMAGE_YEARS, parent, lms_db);
}

static void
rygel_lms_image_years_class_init (RygelLMSImageYearsClass * klass,
                                  gpointer klass_data)
{
	rygel_lms_image_years_parent_class = g_type_class_peek_parent (klass);
	((RygelLMSCategoryContainerClass *) klass)->object_from_statement = (RygelMediaObject* (*) (RygelLMSCategoryContainer*, sqlite3_stmt*)) rygel_lms_image_years_real_object_from_statement;
}

static void
rygel_lms_image_years_instance_init (RygelLMSImageYears * self,
                                     gpointer klass)
{
}

static GType
rygel_lms_image_years_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (RygelLMSImageYearsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_lms_image_years_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelLMSImageYears), 0, (GInstanceInitFunc) rygel_lms_image_years_instance_init, NULL };
	GType rygel_lms_image_years_type_id;
	rygel_lms_image_years_type_id = g_type_register_static (RYGEL_LMS_TYPE_CATEGORY_CONTAINER, "RygelLMSImageYears", &g_define_type_info, 0);
	return rygel_lms_image_years_type_id;
}

GType
rygel_lms_image_years_get_type (void)
{
	static volatile gsize rygel_lms_image_years_type_id__once = 0;
	if (g_once_init_enter (&rygel_lms_image_years_type_id__once)) {
		GType rygel_lms_image_years_type_id;
		rygel_lms_image_years_type_id = rygel_lms_image_years_get_type_once ();
		g_once_init_leave (&rygel_lms_image_years_type_id__once, rygel_lms_image_years_type_id);
	}
	return rygel_lms_image_years_type_id__once;
}

