/* rygel-tracker-new.c generated by valac 0.56.1, the Vala compiler
 * generated from rygel-tracker-new.vala, do not modify */

/*
 * Copyright (C) 2008 Zeeshan Ali (Khattak) <zeeshanak@gnome.org>.
 * Copyright (C) 2008,2010 Nokia Corporation.
 *
 * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
 *
 * 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-tracker3.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "rygel-server.h"
#include <gee.h>
#include <glib-object.h>

#define RYGEL_TRACKER_NEW_ADDED_PREDICATE "nrl:added"
#define RYGEL_TRACKER_NEW_ADDED_VARIABLE "?added"

enum  {
	RYGEL_TRACKER_NEW_0_PROPERTY,
	RYGEL_TRACKER_NEW_NUM_PROPERTIES
};
static GParamSpec* rygel_tracker_new_properties[RYGEL_TRACKER_NEW_NUM_PROPERTIES];
#define _rygel_tracker_query_triplet_unref0(var) ((var == NULL) ? NULL : (var = (rygel_tracker_query_triplet_unref (var), NULL)))
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

static gpointer rygel_tracker_new_parent_class = NULL;

static GType rygel_tracker_new_get_type_once (void);

RygelTrackerNew*
rygel_tracker_new_construct (GType object_type,
                             RygelMediaContainer* parent,
                             RygelTrackerItemFactory* item_factory)
{
	RygelTrackerNew * self = NULL;
	RygelTrackerQueryTriplets* triplets = NULL;
	RygelTrackerQueryTriplets* _tmp0_;
	const gchar* _tmp1_;
	RygelTrackerQueryTriplet* _tmp2_;
	RygelTrackerQueryTriplet* _tmp3_;
	RygelTrackerQueryTriplet* _tmp4_;
	RygelTrackerQueryTriplet* _tmp5_;
	GDateTime* now = NULL;
	GDateTime* _tmp6_;
	GDateTime* _tmp7_;
	GDateTime* _tmp8_;
	gchar* three_days_ago = NULL;
	GDateTime* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	GeeArrayList* filters = NULL;
	GeeArrayList* _tmp14_;
	gchar* _tmp15_;
	gchar* _tmp16_;
	gchar* _tmp17_;
	gchar* _tmp18_;
	const gchar* _tmp19_;
	const gchar* _tmp20_;
	gchar* _tmp21_;
	gchar* _tmp22_;
	g_return_val_if_fail (parent != NULL, NULL);
	g_return_val_if_fail (item_factory != NULL, NULL);
	_tmp0_ = rygel_tracker_query_triplets_new ();
	triplets = _tmp0_;
	_tmp1_ = item_factory->category;
	_tmp2_ = rygel_tracker_query_triplet_new (RYGEL_TRACKER_SELECTION_QUERY_ITEM_VARIABLE, "a", _tmp1_);
	_tmp3_ = _tmp2_;
	gee_abstract_collection_add ((GeeAbstractCollection*) triplets, _tmp3_);
	_rygel_tracker_query_triplet_unref0 (_tmp3_);
	_tmp4_ = rygel_tracker_query_triplet_new (RYGEL_TRACKER_SELECTION_QUERY_ITEM_VARIABLE, RYGEL_TRACKER_NEW_ADDED_PREDICATE, RYGEL_TRACKER_NEW_ADDED_VARIABLE);
	_tmp5_ = _tmp4_;
	gee_abstract_collection_add ((GeeAbstractCollection*) triplets, _tmp5_);
	_rygel_tracker_query_triplet_unref0 (_tmp5_);
	_tmp6_ = g_date_time_new_now_utc ();
	now = _tmp6_;
	_tmp7_ = now;
	_tmp8_ = g_date_time_add_days (_tmp7_, -3);
	_g_date_time_unref0 (now);
	now = _tmp8_;
	_tmp9_ = now;
	_tmp10_ = g_date_time_format (_tmp9_, "%Y-%m-%dT%H:%M:%S");
	_tmp11_ = _tmp10_;
	_tmp12_ = g_strdup_printf ("%sZ", _tmp11_);
	_tmp13_ = _tmp12_;
	_g_free0 (_tmp11_);
	three_days_ago = _tmp13_;
	_tmp14_ = gee_array_list_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL);
	filters = _tmp14_;
	_tmp15_ = g_strconcat (RYGEL_TRACKER_NEW_ADDED_VARIABLE " > \"", three_days_ago, NULL);
	_tmp16_ = _tmp15_;
	_tmp17_ = g_strconcat (_tmp16_, "\"^^xsd:dateTime", NULL);
	_tmp18_ = _tmp17_;
	gee_abstract_collection_add ((GeeAbstractCollection*) filters, _tmp18_);
	_g_free0 (_tmp18_);
	_g_free0 (_tmp16_);
	_tmp19_ = rygel_media_object_get_id ((RygelMediaObject*) parent);
	_tmp20_ = _tmp19_;
	_tmp21_ = g_strconcat (_tmp20_, "New", NULL);
	_tmp22_ = _tmp21_;
	self = (RygelTrackerNew*) rygel_tracker_search_container_construct (object_type, _tmp22_, parent, "New", item_factory, triplets, filters);
	_g_free0 (_tmp22_);
	_g_object_unref0 (filters);
	_g_free0 (three_days_ago);
	_g_date_time_unref0 (now);
	_g_object_unref0 (triplets);
	return self;
}

RygelTrackerNew*
rygel_tracker_new_new (RygelMediaContainer* parent,
                       RygelTrackerItemFactory* item_factory)
{
	return rygel_tracker_new_construct (RYGEL_TRACKER_TYPE_NEW, parent, item_factory);
}

static void
rygel_tracker_new_class_init (RygelTrackerNewClass * klass,
                              gpointer klass_data)
{
	rygel_tracker_new_parent_class = g_type_class_peek_parent (klass);
}

static void
rygel_tracker_new_instance_init (RygelTrackerNew * self,
                                 gpointer klass)
{
}

/**
 * A container listing all newly (<3 days) added items.
 */
static GType
rygel_tracker_new_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (RygelTrackerNewClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_tracker_new_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelTrackerNew), 0, (GInstanceInitFunc) rygel_tracker_new_instance_init, NULL };
	GType rygel_tracker_new_type_id;
	rygel_tracker_new_type_id = g_type_register_static (RYGEL_TRACKER_TYPE_SEARCH_CONTAINER, "RygelTrackerNew", &g_define_type_info, 0);
	return rygel_tracker_new_type_id;
}

GType
rygel_tracker_new_get_type (void)
{
	static volatile gsize rygel_tracker_new_type_id__once = 0;
	if (g_once_init_enter (&rygel_tracker_new_type_id__once)) {
		GType rygel_tracker_new_type_id;
		rygel_tracker_new_type_id = rygel_tracker_new_get_type_once ();
		g_once_init_leave (&rygel_tracker_new_type_id__once, rygel_tracker_new_type_id);
	}
	return rygel_tracker_new_type_id__once;
}

