Blame gdata/gd/gdata-gd-when.c

Packit 4b6dd7
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
Packit 4b6dd7
/*
Packit 4b6dd7
 * GData Client
Packit 4b6dd7
 * Copyright (C) Philip Withnall 2009–2010 <philip@tecnocode.co.uk>
Packit 4b6dd7
 *
Packit 4b6dd7
 * GData Client is free software; you can redistribute it and/or
Packit 4b6dd7
 * modify it under the terms of the GNU Lesser General Public
Packit 4b6dd7
 * License as published by the Free Software Foundation; either
Packit 4b6dd7
 * version 2.1 of the License, or (at your option) any later version.
Packit 4b6dd7
 *
Packit 4b6dd7
 * GData Client is distributed in the hope that it will be useful,
Packit 4b6dd7
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 4b6dd7
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 4b6dd7
 * Lesser General Public License for more details.
Packit 4b6dd7
 *
Packit 4b6dd7
 * You should have received a copy of the GNU Lesser General Public
Packit 4b6dd7
 * License along with GData Client.  If not, see <http://www.gnu.org/licenses/>.
Packit 4b6dd7
 */
Packit 4b6dd7
Packit 4b6dd7
/**
Packit 4b6dd7
 * SECTION:gdata-gd-when
Packit 4b6dd7
 * @short_description: GData when element
Packit 4b6dd7
 * @stability: Stable
Packit 4b6dd7
 * @include: gdata/gd/gdata-gd-when.h
Packit 4b6dd7
 *
Packit 4b6dd7
 * #GDataGDWhen represents a "when" element from the
Packit 4b6dd7
 * <ulink type="http" url="http://code.google.com/apis/gdata/docs/2.0/elements.html#gdWhen">GData specification</ulink>.
Packit 4b6dd7
 *
Packit 4b6dd7
 * Since: 0.4.0
Packit 4b6dd7
 */
Packit 4b6dd7
Packit 4b6dd7
#include <glib.h>
Packit 4b6dd7
#include <libxml/parser.h>
Packit 4b6dd7
Packit 4b6dd7
#include "gdata-gd-when.h"
Packit 4b6dd7
#include "gdata-gd-reminder.h"
Packit 4b6dd7
#include "gdata-private.h"
Packit 4b6dd7
#include "gdata-parsable.h"
Packit 4b6dd7
#include "gdata-parser.h"
Packit 4b6dd7
#include "gdata-types.h"
Packit 4b6dd7
#include "gdata-comparable.h"
Packit 4b6dd7
Packit 4b6dd7
static void gdata_gd_when_comparable_init (GDataComparableIface *iface);
Packit 4b6dd7
static void gdata_gd_when_dispose (GObject *object);
Packit 4b6dd7
static void gdata_gd_when_finalize (GObject *object);
Packit 4b6dd7
static void gdata_gd_when_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
Packit 4b6dd7
static void gdata_gd_when_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
Packit 4b6dd7
static gboolean pre_parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *root_node, gpointer user_data, GError **error);
Packit 4b6dd7
static gboolean parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *root_node, gpointer user_data, GError **error);
Packit 4b6dd7
static gboolean post_parse_xml (GDataParsable *parsable, gpointer user_data, GError **error);
Packit 4b6dd7
static void pre_get_xml (GDataParsable *parsable, GString *xml_string);
Packit 4b6dd7
static void get_xml (GDataParsable *parsable, GString *xml_string);
Packit 4b6dd7
static void get_namespaces (GDataParsable *parsable, GHashTable *namespaces);
Packit 4b6dd7
Packit 4b6dd7
struct _GDataGDWhenPrivate {
Packit 4b6dd7
	gint64 start_time;
Packit 4b6dd7
	gint64 end_time;
Packit 4b6dd7
	gboolean is_date;
Packit 4b6dd7
	gchar *value_string;
Packit 4b6dd7
	GList *reminders;
Packit 4b6dd7
};
Packit 4b6dd7
Packit 4b6dd7
enum {
Packit 4b6dd7
	PROP_START_TIME = 1,
Packit 4b6dd7
	PROP_END_TIME,
Packit 4b6dd7
	PROP_IS_DATE,
Packit 4b6dd7
	PROP_VALUE_STRING
Packit 4b6dd7
};
Packit 4b6dd7
Packit 4b6dd7
G_DEFINE_TYPE_WITH_CODE (GDataGDWhen, gdata_gd_when, GDATA_TYPE_PARSABLE,
Packit 4b6dd7
                         G_IMPLEMENT_INTERFACE (GDATA_TYPE_COMPARABLE, gdata_gd_when_comparable_init))
Packit 4b6dd7
Packit 4b6dd7
static void
Packit 4b6dd7
gdata_gd_when_class_init (GDataGDWhenClass *klass)
Packit 4b6dd7
{
Packit 4b6dd7
	GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
Packit 4b6dd7
	GDataParsableClass *parsable_class = GDATA_PARSABLE_CLASS (klass);
Packit 4b6dd7
Packit 4b6dd7
	g_type_class_add_private (klass, sizeof (GDataGDWhenPrivate));
Packit 4b6dd7
Packit 4b6dd7
	gobject_class->get_property = gdata_gd_when_get_property;
Packit 4b6dd7
	gobject_class->set_property = gdata_gd_when_set_property;
Packit 4b6dd7
	gobject_class->dispose = gdata_gd_when_dispose;
Packit 4b6dd7
	gobject_class->finalize = gdata_gd_when_finalize;
Packit 4b6dd7
Packit 4b6dd7
	parsable_class->pre_parse_xml = pre_parse_xml;
Packit 4b6dd7
	parsable_class->parse_xml = parse_xml;
Packit 4b6dd7
	parsable_class->post_parse_xml = post_parse_xml;
Packit 4b6dd7
	parsable_class->pre_get_xml = pre_get_xml;
Packit 4b6dd7
	parsable_class->get_xml = get_xml;
Packit 4b6dd7
	parsable_class->get_namespaces = get_namespaces;
Packit 4b6dd7
	parsable_class->element_name = "when";
Packit 4b6dd7
	parsable_class->element_namespace = "gd";
Packit 4b6dd7
Packit 4b6dd7
	/**
Packit 4b6dd7
	 * GDataGDWhen:start-time:
Packit 4b6dd7
	 *
Packit 4b6dd7
	 * The name of the when.
Packit 4b6dd7
	 *
Packit 4b6dd7
	 * For more information, see the
Packit 4b6dd7
	 * <ulink type="http" url="http://code.google.com/apis/gdata/docs/2.0/elements.html#gdWhen">GData specification</ulink>.
Packit 4b6dd7
	 *
Packit 4b6dd7
	 * Since: 0.4.0
Packit 4b6dd7
	 */
Packit 4b6dd7
	g_object_class_install_property (gobject_class, PROP_START_TIME,
Packit 4b6dd7
	                                 g_param_spec_int64 ("start-time",
Packit 4b6dd7
	                                                     "Start time", "The name of the when.",
Packit 4b6dd7
	                                                     0, G_MAXINT64, 0,
Packit 4b6dd7
	                                                     G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
Packit 4b6dd7
Packit 4b6dd7
	/**
Packit 4b6dd7
	 * GDataGDWhen:end-time:
Packit 4b6dd7
	 *
Packit 4b6dd7
	 * The title of a person within the when.
Packit 4b6dd7
	 *
Packit 4b6dd7
	 * For more information, see the
Packit 4b6dd7
	 * <ulink type="http" url="http://code.google.com/apis/gdata/docs/2.0/elements.html#gdWhen">GData specification</ulink>.
Packit 4b6dd7
	 *
Packit 4b6dd7
	 * Since: 0.4.0
Packit 4b6dd7
	 */
Packit 4b6dd7
	g_object_class_install_property (gobject_class, PROP_END_TIME,
Packit 4b6dd7
	                                 g_param_spec_int64 ("end-time",
Packit 4b6dd7
	                                                     "End time", "The title of a person within the when.",
Packit 4b6dd7
	                                                     -1, G_MAXINT64, -1,
Packit 4b6dd7
	                                                     G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
Packit 4b6dd7
Packit 4b6dd7
	/**
Packit 4b6dd7
	 * GDataGDWhen:is-date:
Packit 4b6dd7
	 *
Packit 4b6dd7
	 * A programmatic value that identifies the type of when.
Packit 4b6dd7
	 *
Packit 4b6dd7
	 * For more information, see the
Packit 4b6dd7
	 * <ulink type="http" url="http://code.google.com/apis/gdata/docs/2.0/elements.html#gdWhen">GData specification</ulink>.
Packit 4b6dd7
	 *
Packit 4b6dd7
	 * Since: 0.4.0
Packit 4b6dd7
	 */
Packit 4b6dd7
	g_object_class_install_property (gobject_class, PROP_IS_DATE,
Packit 4b6dd7
	                                 g_param_spec_boolean ("is-date",
Packit 4b6dd7
	                                                       "Date?", "A programmatic value that identifies the type of when.",
Packit 4b6dd7
	                                                       FALSE,
Packit 4b6dd7
	                                                       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
Packit 4b6dd7
Packit 4b6dd7
	/**
Packit 4b6dd7
	 * GDataGDWhen:value-string:
Packit 4b6dd7
	 *
Packit 4b6dd7
	 * A simple string value used to name this when. It allows UIs to display a label such as "Work", "Volunteer",
Packit 4b6dd7
	 * "Professional Society", etc.
Packit 4b6dd7
	 *
Packit 4b6dd7
	 * For more information, see the
Packit 4b6dd7
	 * <ulink type="http" url="http://code.google.com/apis/gdata/docs/2.0/elements.html#gdWhen">GData specification</ulink>.
Packit 4b6dd7
	 *
Packit 4b6dd7
	 * Since: 0.4.0
Packit 4b6dd7
	 */
Packit 4b6dd7
	g_object_class_install_property (gobject_class, PROP_VALUE_STRING,
Packit 4b6dd7
	                                 g_param_spec_string ("value-string",
Packit 4b6dd7
	                                                      "Value string", "A simple string value used to name this when.",
Packit 4b6dd7
	                                                      NULL,
Packit 4b6dd7
	                                                      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
static gint
Packit 4b6dd7
compare_with (GDataComparable *self, GDataComparable *other)
Packit 4b6dd7
{
Packit 4b6dd7
	gint64 start_diff, end_diff;
Packit 4b6dd7
	GDataGDWhenPrivate *a = ((GDataGDWhen*) self)->priv, *b = ((GDataGDWhen*) other)->priv;
Packit 4b6dd7
Packit 4b6dd7
	if (a->is_date != b->is_date)
Packit 4b6dd7
		return CLAMP (b->is_date - a->is_date, -1, 1);
Packit 4b6dd7
Packit 4b6dd7
	start_diff = b->start_time - a->start_time;
Packit 4b6dd7
	end_diff = b->end_time - a->end_time;
Packit 4b6dd7
Packit 4b6dd7
	if (start_diff == 0)
Packit 4b6dd7
		return CLAMP (end_diff, -1, 1);
Packit 4b6dd7
	return CLAMP (start_diff, -1, 1);
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
static void
Packit 4b6dd7
gdata_gd_when_comparable_init (GDataComparableIface *iface)
Packit 4b6dd7
{
Packit 4b6dd7
	iface->compare_with = compare_with;
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
static void
Packit 4b6dd7
gdata_gd_when_init (GDataGDWhen *self)
Packit 4b6dd7
{
Packit 4b6dd7
	self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GDATA_TYPE_GD_WHEN, GDataGDWhenPrivate);
Packit 4b6dd7
	self->priv->end_time = -1;
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
static void
Packit 4b6dd7
gdata_gd_when_dispose (GObject *object)
Packit 4b6dd7
{
Packit 4b6dd7
	GDataGDWhenPrivate *priv = GDATA_GD_WHEN (object)->priv;
Packit 4b6dd7
Packit 4b6dd7
	if (priv->reminders != NULL) {
Packit 4b6dd7
		g_list_foreach (priv->reminders, (GFunc) g_object_unref, NULL);
Packit 4b6dd7
		g_list_free (priv->reminders);
Packit 4b6dd7
	}
Packit 4b6dd7
	priv->reminders = NULL;
Packit 4b6dd7
Packit 4b6dd7
	/* Chain up to the parent class */
Packit 4b6dd7
	G_OBJECT_CLASS (gdata_gd_when_parent_class)->dispose (object);
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
static void
Packit 4b6dd7
gdata_gd_when_finalize (GObject *object)
Packit 4b6dd7
{
Packit 4b6dd7
	GDataGDWhenPrivate *priv = GDATA_GD_WHEN (object)->priv;
Packit 4b6dd7
Packit 4b6dd7
	g_free (priv->value_string);
Packit 4b6dd7
Packit 4b6dd7
	/* Chain up to the parent class */
Packit 4b6dd7
	G_OBJECT_CLASS (gdata_gd_when_parent_class)->finalize (object);
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
static void
Packit 4b6dd7
gdata_gd_when_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
Packit 4b6dd7
{
Packit 4b6dd7
	GDataGDWhenPrivate *priv = GDATA_GD_WHEN (object)->priv;
Packit 4b6dd7
Packit 4b6dd7
	switch (property_id) {
Packit 4b6dd7
		case PROP_START_TIME:
Packit 4b6dd7
			g_value_set_int64 (value, priv->start_time);
Packit 4b6dd7
			break;
Packit 4b6dd7
		case PROP_END_TIME:
Packit 4b6dd7
			g_value_set_int64 (value, priv->end_time);
Packit 4b6dd7
			break;
Packit 4b6dd7
		case PROP_IS_DATE:
Packit 4b6dd7
			g_value_set_boolean (value, priv->is_date);
Packit 4b6dd7
			break;
Packit 4b6dd7
		case PROP_VALUE_STRING:
Packit 4b6dd7
			g_value_set_string (value, priv->value_string);
Packit 4b6dd7
			break;
Packit 4b6dd7
		default:
Packit 4b6dd7
			/* We don't have any other property... */
Packit 4b6dd7
			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
Packit 4b6dd7
			break;
Packit 4b6dd7
	}
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
static void
Packit 4b6dd7
gdata_gd_when_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
Packit 4b6dd7
{
Packit 4b6dd7
	GDataGDWhen *self = GDATA_GD_WHEN (object);
Packit 4b6dd7
Packit 4b6dd7
	switch (property_id) {
Packit 4b6dd7
		case PROP_START_TIME:
Packit 4b6dd7
			gdata_gd_when_set_start_time (self, g_value_get_int64 (value));
Packit 4b6dd7
			break;
Packit 4b6dd7
		case PROP_END_TIME:
Packit 4b6dd7
			gdata_gd_when_set_end_time (self, g_value_get_int64 (value));
Packit 4b6dd7
			break;
Packit 4b6dd7
		case PROP_IS_DATE:
Packit 4b6dd7
			gdata_gd_when_set_is_date (self, g_value_get_boolean (value));
Packit 4b6dd7
			break;
Packit 4b6dd7
		case PROP_VALUE_STRING:
Packit 4b6dd7
			gdata_gd_when_set_value_string (self, g_value_get_string (value));
Packit 4b6dd7
			break;
Packit 4b6dd7
		default:
Packit 4b6dd7
			/* We don't have any other property... */
Packit 4b6dd7
			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
Packit 4b6dd7
			break;
Packit 4b6dd7
	}
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
static gboolean
Packit 4b6dd7
pre_parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *root_node, gpointer user_data, GError **error)
Packit 4b6dd7
{
Packit 4b6dd7
	GDataGDWhenPrivate *priv = GDATA_GD_WHEN (parsable)->priv;
Packit 4b6dd7
	xmlChar *start_time, *end_time;
Packit 4b6dd7
	gint64 start_time_int64, end_time_int64;
Packit 4b6dd7
	gboolean is_date = FALSE;
Packit 4b6dd7
Packit 4b6dd7
	/* Start time */
Packit 4b6dd7
	start_time = xmlGetProp (root_node, (xmlChar*) "startTime");
Packit 4b6dd7
	if (gdata_parser_int64_from_date ((gchar*) start_time, &start_time_int64) == TRUE) {
Packit 4b6dd7
		is_date = TRUE;
Packit 4b6dd7
	} else if (gdata_parser_int64_from_iso8601 ((gchar*) start_time, &start_time_int64) == FALSE) {
Packit 4b6dd7
		/* Error */
Packit 4b6dd7
		gdata_parser_error_not_iso8601_format (root_node, (gchar*) start_time, error);
Packit 4b6dd7
		xmlFree (start_time);
Packit 4b6dd7
		return FALSE;
Packit 4b6dd7
	}
Packit 4b6dd7
	xmlFree (start_time);
Packit 4b6dd7
Packit 4b6dd7
	/* End time (optional) */
Packit 4b6dd7
	end_time = xmlGetProp (root_node, (xmlChar*) "endTime");
Packit 4b6dd7
	if (end_time != NULL) {
Packit 4b6dd7
		gboolean success;
Packit 4b6dd7
Packit 4b6dd7
		if (is_date == TRUE)
Packit 4b6dd7
			success = gdata_parser_int64_from_date ((gchar*) end_time, &end_time_int64);
Packit 4b6dd7
		else
Packit 4b6dd7
			success = gdata_parser_int64_from_iso8601 ((gchar*) end_time, &end_time_int64);
Packit 4b6dd7
Packit 4b6dd7
		if (success == FALSE) {
Packit 4b6dd7
			/* Error */
Packit 4b6dd7
			gdata_parser_error_not_iso8601_format (root_node, (gchar*) end_time, error);
Packit 4b6dd7
			xmlFree (end_time);
Packit 4b6dd7
			return FALSE;
Packit 4b6dd7
		}
Packit 4b6dd7
		xmlFree (end_time);
Packit 4b6dd7
	} else {
Packit 4b6dd7
		/* Give a default */
Packit 4b6dd7
		end_time_int64 = -1;
Packit 4b6dd7
	}
Packit 4b6dd7
Packit 4b6dd7
	priv->start_time = start_time_int64;
Packit 4b6dd7
	priv->end_time = end_time_int64;
Packit 4b6dd7
	priv->is_date = is_date;
Packit 4b6dd7
	priv->value_string = (gchar*) xmlGetProp (root_node, (xmlChar*) "valueString");
Packit 4b6dd7
Packit 4b6dd7
	return TRUE;
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
static gboolean
Packit 4b6dd7
parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_data, GError **error)
Packit 4b6dd7
{
Packit 4b6dd7
	gboolean success;
Packit 4b6dd7
Packit 4b6dd7
	if (gdata_parser_is_namespace (node, "http://schemas.google.com/g/2005") == TRUE &&
Packit 4b6dd7
	    gdata_parser_object_from_element_setter (node, "reminder", P_REQUIRED, GDATA_TYPE_GD_REMINDER,
Packit 4b6dd7
	                                             gdata_gd_when_add_reminder, parsable, &success, error) == TRUE) {
Packit 4b6dd7
		return success;
Packit 4b6dd7
	} else {
Packit 4b6dd7
		return GDATA_PARSABLE_CLASS (gdata_gd_when_parent_class)->parse_xml (parsable, doc, node, user_data, error);
Packit 4b6dd7
	}
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
static gboolean
Packit 4b6dd7
post_parse_xml (GDataParsable *parsable, gpointer user_data, GError **error)
Packit 4b6dd7
{
Packit 4b6dd7
	GDataGDWhenPrivate *priv = GDATA_GD_WHEN (parsable)->priv;
Packit 4b6dd7
Packit 4b6dd7
	/* Reverse our lists of stuff */
Packit 4b6dd7
	priv->reminders = g_list_reverse (priv->reminders);
Packit 4b6dd7
Packit 4b6dd7
	return TRUE;
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
static void
Packit 4b6dd7
pre_get_xml (GDataParsable *parsable, GString *xml_string)
Packit 4b6dd7
{
Packit 4b6dd7
	GDataGDWhenPrivate *priv = GDATA_GD_WHEN (parsable)->priv;
Packit 4b6dd7
	gchar *start_time;
Packit 4b6dd7
Packit 4b6dd7
	if (priv->is_date == TRUE)
Packit 4b6dd7
		start_time = gdata_parser_date_from_int64 (priv->start_time);
Packit 4b6dd7
	else
Packit 4b6dd7
		start_time = gdata_parser_int64_to_iso8601 (priv->start_time);
Packit 4b6dd7
Packit 4b6dd7
	g_string_append_printf (xml_string, " startTime='%s'", start_time);
Packit 4b6dd7
	g_free (start_time);
Packit 4b6dd7
Packit 4b6dd7
	if (priv->end_time != -1) {
Packit 4b6dd7
		gchar *end_time;
Packit 4b6dd7
Packit 4b6dd7
		if (priv->is_date == TRUE)
Packit 4b6dd7
			end_time = gdata_parser_date_from_int64 (priv->end_time);
Packit 4b6dd7
		else
Packit 4b6dd7
			end_time = gdata_parser_int64_to_iso8601 (priv->end_time);
Packit 4b6dd7
Packit 4b6dd7
		g_string_append_printf (xml_string, " endTime='%s'", end_time);
Packit 4b6dd7
		g_free (end_time);
Packit 4b6dd7
	}
Packit 4b6dd7
Packit 4b6dd7
	if (priv->value_string != NULL)
Packit 4b6dd7
		gdata_parser_string_append_escaped (xml_string, " valueString='", priv->value_string, "'");
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
static void
Packit 4b6dd7
get_xml (GDataParsable *parsable, GString *xml_string)
Packit 4b6dd7
{
Packit 4b6dd7
	GList *reminders;
Packit 4b6dd7
	GDataGDWhenPrivate *priv = GDATA_GD_WHEN (parsable)->priv;
Packit 4b6dd7
Packit 4b6dd7
	for (reminders = priv->reminders; reminders != NULL; reminders = reminders->next)
Packit 4b6dd7
		_gdata_parsable_get_xml (GDATA_PARSABLE (reminders->data), xml_string, FALSE);
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
static void
Packit 4b6dd7
get_namespaces (GDataParsable *parsable, GHashTable *namespaces)
Packit 4b6dd7
{
Packit 4b6dd7
	g_hash_table_insert (namespaces, (gchar*) "gd", (gchar*) "http://schemas.google.com/g/2005");
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
/**
Packit 4b6dd7
 * gdata_gd_when_new:
Packit 4b6dd7
 * @start_time: when the event starts or (for zero-duration events) when it occurs
Packit 4b6dd7
 * @end_time: when the event ends, or -1
Packit 4b6dd7
 * @is_date: %TRUE if @start_time and @end_time specify dates rather than times, %FALSE otherwise
Packit 4b6dd7
 *
Packit 4b6dd7
 * Creates a new #GDataGDWhen. More information is available in the 
Packit 4b6dd7
 * url="http://code.google.com/apis/gdata/docs/2.0/elements.html#gdWhen">GData specification</ulink>.
Packit 4b6dd7
 *
Packit 4b6dd7
 * Return value: a new #GDataGDWhen, or %NULL; unref with g_object_unref()
Packit 4b6dd7
 *
Packit 4b6dd7
 * Since: 0.2.0
Packit 4b6dd7
 */
Packit 4b6dd7
GDataGDWhen *
Packit 4b6dd7
gdata_gd_when_new (gint64 start_time, gint64 end_time, gboolean is_date)
Packit 4b6dd7
{
Packit 4b6dd7
	g_return_val_if_fail (start_time >= 0, NULL);
Packit 4b6dd7
	g_return_val_if_fail (end_time >= -1, NULL);
Packit 4b6dd7
Packit 4b6dd7
	return g_object_new (GDATA_TYPE_GD_WHEN, "start-time", start_time, "end-time", end_time, "is-date", is_date, NULL);
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
/**
Packit 4b6dd7
 * gdata_gd_when_get_start_time:
Packit 4b6dd7
 * @self: a #GDataGDWhen
Packit 4b6dd7
 *
Packit 4b6dd7
 * Gets the #GDataGDWhen:start-time property.
Packit 4b6dd7
 *
Packit 4b6dd7
 * Return value: the UNIX timestamp for the start time of the event
Packit 4b6dd7
 *
Packit 4b6dd7
 * Since: 0.4.0
Packit 4b6dd7
 */
Packit 4b6dd7
gint64
Packit 4b6dd7
gdata_gd_when_get_start_time (GDataGDWhen *self)
Packit 4b6dd7
{
Packit 4b6dd7
	g_return_val_if_fail (GDATA_IS_GD_WHEN (self), -1);
Packit 4b6dd7
	return self->priv->start_time;
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
/**
Packit 4b6dd7
 * gdata_gd_when_set_start_time:
Packit 4b6dd7
 * @self: a #GDataGDWhen
Packit 4b6dd7
 * @start_time: the new start time
Packit 4b6dd7
 *
Packit 4b6dd7
 * Sets the #GDataGDWhen:start-time property to @start_time.
Packit 4b6dd7
 *
Packit 4b6dd7
 * Since: 0.4.0
Packit 4b6dd7
 */
Packit 4b6dd7
void
Packit 4b6dd7
gdata_gd_when_set_start_time (GDataGDWhen *self, gint64 start_time)
Packit 4b6dd7
{
Packit 4b6dd7
	g_return_if_fail (GDATA_IS_GD_WHEN (self));
Packit 4b6dd7
	g_return_if_fail (start_time >= 0);
Packit 4b6dd7
Packit 4b6dd7
	self->priv->start_time = start_time;
Packit 4b6dd7
	g_object_notify (G_OBJECT (self), "start-time");
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
/**
Packit 4b6dd7
 * gdata_gd_when_get_end_time:
Packit 4b6dd7
 * @self: a #GDataGDWhen
Packit 4b6dd7
 *
Packit 4b6dd7
 * Gets the #GDataGDWhen:end-time property.
Packit 4b6dd7
 *
Packit 4b6dd7
 * If the end time is unset, -1 will be returned.
Packit 4b6dd7
 *
Packit 4b6dd7
 * Return value: the UNIX timestamp for the end time of the event, or
Packit 4b6dd7
 * -1
Packit 4b6dd7
 *
Packit 4b6dd7
 * Since: 0.4.0
Packit 4b6dd7
 */
Packit 4b6dd7
gint64
Packit 4b6dd7
gdata_gd_when_get_end_time (GDataGDWhen *self)
Packit 4b6dd7
{
Packit 4b6dd7
	g_return_val_if_fail (GDATA_IS_GD_WHEN (self), -1);
Packit 4b6dd7
	return self->priv->end_time;
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
/**
Packit 4b6dd7
 * gdata_gd_when_set_end_time:
Packit 4b6dd7
 * @self: a #GDataGDWhen
Packit 4b6dd7
 * @end_time: the new end time, or -1
Packit 4b6dd7
 *
Packit 4b6dd7
 * Sets the #GDataGDWhen:end-time property to @end_time.
Packit 4b6dd7
 *
Packit 4b6dd7
 * Set @end_time to -1 to unset the property.
Packit 4b6dd7
 *
Packit 4b6dd7
 * Since: 0.4.0
Packit 4b6dd7
 */
Packit 4b6dd7
void
Packit 4b6dd7
gdata_gd_when_set_end_time (GDataGDWhen *self, gint64 end_time)
Packit 4b6dd7
{
Packit 4b6dd7
	g_return_if_fail (GDATA_IS_GD_WHEN (self));
Packit 4b6dd7
	g_return_if_fail (end_time >= -1);
Packit 4b6dd7
Packit 4b6dd7
	self->priv->end_time = end_time;
Packit 4b6dd7
	g_object_notify (G_OBJECT (self), "end-time");
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
/**
Packit 4b6dd7
 * gdata_gd_when_is_date:
Packit 4b6dd7
 * @self: a #GDataGDWhen
Packit 4b6dd7
 *
Packit 4b6dd7
 * Gets the #GDataGDWhen:is-date property.
Packit 4b6dd7
 *
Packit 4b6dd7
 * Return value: %TRUE if #GDataGDWhen:start-time and #GDataGDWhen:end-time are dates rather than times, %FALSE otherwise
Packit 4b6dd7
 *
Packit 4b6dd7
 * Since: 0.4.0
Packit 4b6dd7
 */
Packit 4b6dd7
gboolean
Packit 4b6dd7
gdata_gd_when_is_date (GDataGDWhen *self)
Packit 4b6dd7
{
Packit 4b6dd7
	g_return_val_if_fail (GDATA_IS_GD_WHEN (self), FALSE);
Packit 4b6dd7
	return self->priv->is_date;
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
/**
Packit 4b6dd7
 * gdata_gd_when_set_is_date:
Packit 4b6dd7
 * @self: a #GDataGDWhen
Packit 4b6dd7
 * @is_date: %TRUE if #GDataGDWhen:start-time and #GDataGDWhen:end-time should be dates rather than times, %FALSE otherwise
Packit 4b6dd7
 *
Packit 4b6dd7
 * Sets the #GDataGDWhen:is-date property to @is_date.
Packit 4b6dd7
 *
Packit 4b6dd7
 * Since: 0.4.0
Packit 4b6dd7
 */
Packit 4b6dd7
void
Packit 4b6dd7
gdata_gd_when_set_is_date (GDataGDWhen *self, gboolean is_date)
Packit 4b6dd7
{
Packit 4b6dd7
	g_return_if_fail (GDATA_IS_GD_WHEN (self));
Packit 4b6dd7
Packit 4b6dd7
	self->priv->is_date = is_date;
Packit 4b6dd7
	g_object_notify (G_OBJECT (self), "is-date");
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
/**
Packit 4b6dd7
 * gdata_gd_when_get_value_string:
Packit 4b6dd7
 * @self: a #GDataGDWhen
Packit 4b6dd7
 *
Packit 4b6dd7
 * Gets the #GDataGDWhen:value-string property.
Packit 4b6dd7
 *
Packit 4b6dd7
 * Return value: the value string, or %NULL
Packit 4b6dd7
 *
Packit 4b6dd7
 * Since: 0.4.0
Packit 4b6dd7
 */
Packit 4b6dd7
const gchar *
Packit 4b6dd7
gdata_gd_when_get_value_string (GDataGDWhen *self)
Packit 4b6dd7
{
Packit 4b6dd7
	g_return_val_if_fail (GDATA_IS_GD_WHEN (self), NULL);
Packit 4b6dd7
	return self->priv->value_string;
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
/**
Packit 4b6dd7
 * gdata_gd_when_set_value_string:
Packit 4b6dd7
 * @self: a #GDataGDWhen
Packit 4b6dd7
 * @value_string: (allow-none): the new value string, or %NULL
Packit 4b6dd7
 *
Packit 4b6dd7
 * Sets the #GDataGDWhen:value-string property to @value_string.
Packit 4b6dd7
 *
Packit 4b6dd7
 * Set @value_string to %NULL to unset the property.
Packit 4b6dd7
 *
Packit 4b6dd7
 * Since: 0.4.0
Packit 4b6dd7
 */
Packit 4b6dd7
void
Packit 4b6dd7
gdata_gd_when_set_value_string (GDataGDWhen *self, const gchar *value_string)
Packit 4b6dd7
{
Packit 4b6dd7
	g_return_if_fail (GDATA_IS_GD_WHEN (self));
Packit 4b6dd7
Packit 4b6dd7
	g_free (self->priv->value_string);
Packit 4b6dd7
	self->priv->value_string = g_strdup (value_string);
Packit 4b6dd7
	g_object_notify (G_OBJECT (self), "value-string");
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
/**
Packit 4b6dd7
 * gdata_gd_when_get_reminders:
Packit 4b6dd7
 * @self: a #GDataGDWhen
Packit 4b6dd7
 *
Packit 4b6dd7
 * Returns a list of the #GDataGDReminders which are associated with this #GDataGDWhen.
Packit 4b6dd7
 *
Packit 4b6dd7
 * Return value: (element-type GData.GDReminder) (transfer none): a #GList of #GDataGDReminders, or %NULL
Packit 4b6dd7
 *
Packit 4b6dd7
 * Since: 0.4.0
Packit 4b6dd7
 */
Packit 4b6dd7
GList *
Packit 4b6dd7
gdata_gd_when_get_reminders (GDataGDWhen *self)
Packit 4b6dd7
{
Packit 4b6dd7
	g_return_val_if_fail (GDATA_IS_GD_WHEN (self), NULL);
Packit 4b6dd7
	return self->priv->reminders;
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
/**
Packit 4b6dd7
 * gdata_gd_when_add_reminder:
Packit 4b6dd7
 * @self: a #GDataGDWhen
Packit 4b6dd7
 * @reminder: a #GDataGDReminder to add
Packit 4b6dd7
 *
Packit 4b6dd7
 * Adds a reminder to the #GDataGDWhen's list of reminders and increments its reference count.
Packit 4b6dd7
 *
Packit 4b6dd7
 * Duplicate reminders will not be added to the list.
Packit 4b6dd7
 *
Packit 4b6dd7
 * Since: 0.7.0
Packit 4b6dd7
 */
Packit 4b6dd7
void
Packit 4b6dd7
gdata_gd_when_add_reminder (GDataGDWhen *self, GDataGDReminder *reminder)
Packit 4b6dd7
{
Packit 4b6dd7
	g_return_if_fail (GDATA_IS_GD_WHEN (self));
Packit 4b6dd7
	g_return_if_fail (GDATA_IS_GD_REMINDER (reminder));
Packit 4b6dd7
Packit 4b6dd7
	if (g_list_find_custom (self->priv->reminders, reminder, (GCompareFunc) gdata_comparable_compare) == NULL)
Packit 4b6dd7
		self->priv->reminders = g_list_append (self->priv->reminders, g_object_ref (reminder));
Packit 4b6dd7
}