[libgdata] Added initial contacts service work



commit 87066f62ecd474423ff00359d27852e67d829e42
Author: Philip Withnall <philip tecnocode co uk>
Date:   Sun Apr 19 10:54:10 2009 +0100

    Added initial contacts service work
    
    Added GDataContactsService with skeleton code for querying for contacts.
    Added the necessary support for more elements in the GData namespace to
    gdata-gdata.[ch], and also added a GDataContactsQuery with contact-specific
    query parameters.
---
 configure.in                                     |    1 +
 docs/reference/gdata-sections.txt                |   15 ++
 gdata/gdata-gdata.c                              |  231 +++++++++++++++++++++
 gdata/gdata-gdata.h                              |  120 +++++++++++
 gdata/gdata.h                                    |    4 +
 gdata/gdata.symbols                              |   25 +++
 gdata/services/Makefile.am                       |    2 +-
 gdata/services/contacts/Makefile.am              |   36 ++++
 gdata/services/contacts/gdata-contacts-query.c   |  234 ++++++++++++++++++++++
 gdata/services/contacts/gdata-contacts-query.h   |   64 ++++++
 gdata/services/contacts/gdata-contacts-service.c |   89 ++++++++
 gdata/services/contacts/gdata-contacts-service.h |   60 ++++++
 12 files changed, 880 insertions(+), 1 deletions(-)

diff --git a/configure.in b/configure.in
index 7e2c91b..e1d7b1c 100644
--- a/configure.in
+++ b/configure.in
@@ -75,6 +75,7 @@ libgdata.pc
 gdata/Makefile
 gdata/services/Makefile
 gdata/services/calendar/Makefile
+gdata/services/contacts/Makefile
 gdata/services/youtube/Makefile
 gdata/tests/Makefile
 po/Makefile.in
diff --git a/docs/reference/gdata-sections.txt b/docs/reference/gdata-sections.txt
index 1f321cc..99692da 100644
--- a/docs/reference/gdata-sections.txt
+++ b/docs/reference/gdata-sections.txt
@@ -173,9 +173,24 @@ gdata_generator_free
 <SECTION>
 <FILE>gdata-gdata</FILE>
 <TITLE>GData API</TITLE>
+GDataGDEmailAddress
+gdata_gd_email_address_new
+gdata_gd_email_address_free
 GDataGDFeedLink
 gdata_gd_feed_link_new
 gdata_gd_feed_link_free
+GDataGDIMAddress
+gdata_gd_im_address_new
+gdata_gd_im_address_free
+GDataGDOrganization
+gdata_gd_organization_new
+gdata_gd_organization_free
+GDataGDPhoneNumber
+gdata_gd_phone_number_new
+gdata_gd_phone_number_free
+GDataGDPostalAddress
+gdata_gd_postal_address_new
+gdata_gd_postal_address_free
 GDataGDRating
 gdata_gd_rating_new
 gdata_gd_rating_free
diff --git a/gdata/gdata-gdata.c b/gdata/gdata-gdata.c
index e10c78c..208018d 100644
--- a/gdata/gdata-gdata.c
+++ b/gdata/gdata-gdata.c
@@ -196,3 +196,234 @@ gdata_gd_where_free (GDataGDWhere *self)
 	g_free (self->value_string);
 	g_slice_free (GDataGDWhere, self);
 }
+
+/**
+ * gdata_gd_email_address_new:
+ * @address: the e-mail address
+ * @rel: the relationship between the e-mail address and its owner, or %NULL
+ * @label: a human-readable label for the e-mail address, or %NULL
+ * @primary: %TRUE if this e-mail address is its owner's primary address, %FALSE otherwise
+ *
+ * Creates a new #GDataGDEmailAddress. More information is available in the <ulink type="http"
+ * url="http://code.google.com/apis/gdata/elements.html#gdEmail";>GData specification</ulink>.
+ *
+ * Return value: a new #GDataGDEmailAddress, or %NULL on error
+ **/
+GDataGDEmailAddress *
+gdata_gd_email_address_new (const gchar *address, const gchar *rel, const gchar *label, gboolean primary)
+{
+	GDataGDEmailAddress *self;
+
+	g_return_val_if_fail (address != NULL, NULL);
+
+	self = g_slice_new (GDataGDEmailAddress);
+	self->address = g_strdup (address);
+	self->rel = g_strdup (rel);
+	self->label = g_strdup (label);
+	self->primary = primary;
+	return self;
+}
+
+/**
+ * gdata_gd_email_address_free:
+ * @self: a #GDataGDEmailAddress
+ *
+ * Frees a #GDataGDEmailAddress.
+ **/
+void
+gdata_gd_email_address_free (GDataGDEmailAddress *self)
+{
+	if (G_UNLIKELY (self == NULL))
+		return;
+
+	g_free (self->address);
+	g_free (self->rel);
+	g_free (self->label);
+	g_slice_free (GDataGDEmailAddress, self);
+}
+
+/**
+ * gdata_gd_im_address_new:
+ * @address: the IM address
+ * @protocol: a URI identifying the IM protocol, or %NULL
+ * @rel: the relationship between the IM address and its owner, or %NULL
+ * @label: a human-readable label for the IM address, or %NULL
+ * @primary: %TRUE if this IM address is its owner's primary address, %FALSE otherwise
+ *
+ * Creates a new #GDataGDIMAddress. More information is available in the <ulink type="http"
+ * url="http://code.google.com/apis/gdata/elements.html#gdIm";>GData specification</ulink>.
+ *
+ * Return value: a new #GDataGDIMAddress, or %NULL on error
+ **/
+GDataGDIMAddress *
+gdata_gd_im_address_new (const gchar *address, const gchar *protocol, const gchar *rel, const gchar *label, gboolean primary)
+{
+	GDataGDIMAddress *self;
+
+	g_return_val_if_fail (address != NULL, NULL);
+
+	self = g_slice_new (GDataGDIMAddress);
+	self->address = g_strdup (address);
+	self->protocol = g_strdup (protocol);
+	self->rel = g_strdup (rel);
+	self->label = g_strdup (label);
+	self->primary = primary;
+	return self;
+}
+
+/**
+ * gdata_gd_im_address_free:
+ * @self: a #GDataGDIMAddress
+ *
+ * Frees a #GDataGDIMAddress.
+ **/
+void
+gdata_gd_im_address_free (GDataGDIMAddress *self)
+{
+	if (G_UNLIKELY (self == NULL))
+		return;
+
+	g_free (self->address);
+	g_free (self->protocol);
+	g_free (self->rel);
+	g_free (self->label);
+	g_slice_free (GDataGDIMAddress, self);
+}
+
+/**
+ * gdata_gd_phone_number_new:
+ * @phone_number: the phone number, in human-readable format
+ * @rel: the relationship between the phone number and its owner, or %NULL
+ * @label: a human-readable label for the phone number, or %NULL
+ * @uri: a "tel URI" to represent the number formally (see
+ * <ulink type="http" url="http://www.ietf.org/rfc/rfc3966.txt";>RFC 3966</ulink>), or %NULL
+ * @primary: %TRUE if this phone number is its owner's primary number, %FALSE otherwise
+ *
+ * Creates a new #GDataGDPhoneNumber. More information is available in the <ulink type="http"
+ * url="http://code.google.com/apis/gdata/elements.html#gdPhoneNumber";>GData specification</ulink>.
+ *
+ * Return value: a new #GDataGDPhoneNumber, or %NULL on error
+ **/
+GDataGDPhoneNumber *
+gdata_gd_phone_number_new (const gchar *phone_number, const gchar *rel, const gchar *label, const gchar *uri, gboolean primary)
+{
+	GDataGDPhoneNumber *self;
+
+	g_return_val_if_fail (phone_number != NULL, NULL);
+
+	self = g_slice_new (GDataGDPhoneNumber);
+	self->phone_number = g_strdup (phone_number);
+	self->rel = g_strdup (rel);
+	self->label = g_strdup (label);
+	self->uri = g_strdup (uri);
+	self->primary = primary;
+	return self;
+}
+
+/**
+ * gdata_gd_phone_number_free:
+ * @self: a #GDataGDPhoneNumber
+ *
+ * Frees a #GDataGDPhoneNumber.
+ **/
+void
+gdata_gd_phone_number_free (GDataGDPhoneNumber *self)
+{
+	if (G_UNLIKELY (self == NULL))
+		return;
+
+	g_free (self->phone_number);
+	g_free (self->rel);
+	g_free (self->label);
+	g_free (self->uri);
+	g_slice_free (GDataGDPhoneNumber, self);
+}
+
+/**
+ * gdata_gd_postal_address_new:
+ * @address: the postal address, in human-readable format (new lines are significant)
+ * @rel: the relationship between the address and its owner, or %NULL
+ * @label: a human-readable label for the address, or %NULL
+ * @primary: %TRUE if this phone number is its owner's primary number, %FALSE otherwise
+ *
+ * Creates a new #GDataGDPostalAddress. More information is available in the <ulink type="http"
+ * url="http://code.google.com/apis/gdata/elements.html#gdPostalAddress";>GData specification</ulink>.
+ *
+ * Return value: a new #GDataGDPostalAddress, or %NULL on error
+ **/
+GDataGDPostalAddress *
+gdata_gd_postal_address_new (const gchar *address, const gchar *rel, const gchar *label, gboolean primary)
+{
+	GDataGDPostalAddress *self;
+
+	g_return_val_if_fail (address != NULL, NULL);
+
+	self = g_slice_new (GDataGDPostalAddress);
+	self->address = g_strdup (address);
+	self->rel = g_strdup (rel);
+	self->label = g_strdup (label);
+	self->primary = primary;
+	return self;
+}
+
+/**
+ * gdata_gd_postal_address_free:
+ * @self: a #GDataGDPostalAddress
+ *
+ * Frees a #GDataGDPostalAddress.
+ **/
+void
+gdata_gd_postal_address_free (GDataGDPostalAddress *self)
+{
+	if (G_UNLIKELY (self == NULL))
+		return;
+
+	g_free (self->address);
+	g_free (self->rel);
+	g_free (self->label);
+	g_slice_free (GDataGDPostalAddress, self);
+}
+
+/**
+ * gdata_gd_organization_new:
+ * @name: the name of the organization, or %NULL
+ * @title: the owner's title within the organization, or %NULL
+ * @rel: the relationship between the organization and its owner, or %NULL
+ * @label: a human-readable label for the organization, or %NULL
+ * @primary: %TRUE if this organization is its owner's primary organization, %FALSE otherwise
+ *
+ * Creates a new #GDataGDOrganization. More information is available in the <ulink type="http"
+ * url="http://code.google.com/apis/gdata/elements.html#gdOrganization";>GData specification</ulink>.
+ *
+ * Return value: a new #GDataGDOrganization, or %NULL on error
+ **/
+GDataGDOrganization *
+gdata_gd_organization_new (const gchar *name, const gchar *title, const gchar *rel, const gchar *label, gboolean primary)
+{
+	GDataGDOrganization *self = g_slice_new (GDataGDOrganization);
+	self->name = g_strdup (name);
+	self->title = g_strdup (title);
+	self->rel = g_strdup (rel);
+	self->label = g_strdup (label);
+	self->primary = primary;
+	return self;
+}
+
+/**
+ * gdata_gd_organization_free:
+ * @self: a #GDataGDOrganization
+ *
+ * Frees a #GDataGDOrganization.
+ **/
+void
+gdata_gd_organization_free (GDataGDOrganization *self)
+{
+	if (G_UNLIKELY (self == NULL))
+		return;
+
+	g_free (self->name);
+	g_free (self->title);
+	g_free (self->rel);
+	g_free (self->label);
+	g_slice_free (GDataGDOrganization, self);
+}
diff --git a/gdata/gdata-gdata.h b/gdata/gdata-gdata.h
index de186da..02f1181 100644
--- a/gdata/gdata-gdata.h
+++ b/gdata/gdata-gdata.h
@@ -117,6 +117,126 @@ typedef struct {
 GDataGDWhere *gdata_gd_where_new (const gchar *rel, const gchar *value_string, const gchar *label);
 void gdata_gd_where_free (GDataGDWhere *self);
 
+/**
+ * GDataGDEmailAddress:
+ * @address: the e-mail address
+ * @rel: the relationship between the e-mail address and its owner, or %NULL
+ * @label: a human-readable label for the e-mail address, or %NULL
+ * @primary: %TRUE if this e-mail address is its owner's primary address, %FALSE otherwise
+ *
+ * A structure fully representing a GData "email" element. The @address field is required, but the others
+ * are optional.
+ *
+ * See the <ulink type="http" url="http://code.google.com/apis/gdata/elements.html#gdEmail";>GData specification</ulink>
+ * for more information.
+ **/
+typedef struct {
+	gchar *address;
+	gchar *rel;
+	gchar *label;
+	gboolean primary;
+} GDataGDEmailAddress;
+
+GDataGDEmailAddress *gdata_gd_email_address_new (const gchar *address, const gchar *rel, const gchar *label, gboolean primary);
+void gdata_gd_email_address_free (GDataGDEmailAddress *self);
+
+/**
+ * GDataGDIMAddress:
+ * @address: the IM address
+ * @protocol: a URI identifying the IM protocol, or %NULL
+ * @rel: the relationship between the IM address and its owner, or %NULL
+ * @label: a human-readable label for the IM address, or %NULL
+ * @primary: %TRUE if this IM address is its owner's primary address, %FALSE otherwise
+ *
+ * A structure fully representing a GData "im" element. The @address field is required, but the others are optional.
+ *
+ * See the <ulink type="http" url="http://code.google.com/apis/gdata/elements.html#gdIm";>GData specification</ulink>
+ * for more information.
+ **/
+typedef struct {
+	gchar *address;
+	gchar *protocol;
+	gchar *rel;
+	gchar *label;
+	gboolean primary;
+} GDataGDIMAddress;
+
+GDataGDIMAddress *gdata_gd_im_address_new (const gchar *address, const gchar *protocol, const gchar *rel, const gchar *label, gboolean primary);
+void gdata_gd_im_address_free (GDataGDIMAddress *self);
+
+/**
+ * GDataGDPhoneNumber:
+ * @phone_number: the phone number, in human-readable format
+ * @rel: the relationship between the phone number and its owner, or %NULL
+ * @label: a human-readable label for the phone number, or %NULL
+ * @uri: a "tel URI" to represent the number formally (see
+ * <ulink type="http" url="http://www.ietf.org/rfc/rfc3966.txt";>RFC 3966</ulink>), or %NULL
+ * @primary: %TRUE if this phone number is its owner's primary number, %FALSE otherwise
+ *
+ * A structure fully representing a GData "phoneNumber" element. The @phone_number field is required,
+ * but the others are optional.
+ *
+ * See the <ulink type="http" url="http://code.google.com/apis/gdata/elements.html#gdPhoneNumber";>GData specification</ulink>
+ * for more information.
+ **/
+typedef struct {
+	gchar *phone_number;
+	gchar *rel;
+	gchar *label;
+	gchar *uri;
+	gboolean primary;
+} GDataGDPhoneNumber;
+
+GDataGDPhoneNumber *gdata_gd_phone_number_new (const gchar *phone_number, const gchar *rel, const gchar *label, const gchar *uri, gboolean primary);
+void gdata_gd_phone_number_free (GDataGDPhoneNumber *self);
+
+/**
+ * GDataGDPostalAddress:
+ * @address: the postal address, in human-readable format (new lines are significant)
+ * @rel: the relationship between the address and its owner, or %NULL
+ * @label: a human-readable label for the address, or %NULL
+ * @primary: %TRUE if this phone number is its owner's primary number, %FALSE otherwise
+ *
+ * A structure fully representing a GData "postalAddress" element. The @address field is required,
+ * but the others are optional.
+ *
+ * See the <ulink type="http" url="http://code.google.com/apis/gdata/elements.html#gdPostalAddress";>GData specification</ulink>
+ * for more information.
+ **/
+typedef struct {
+	gchar *address;
+	gchar *rel;
+	gchar *label;
+	gboolean primary;
+} GDataGDPostalAddress;
+
+GDataGDPostalAddress *gdata_gd_postal_address_new (const gchar *address, const gchar *rel, const gchar *label, gboolean primary);
+void gdata_gd_postal_address_free (GDataGDPostalAddress *self);
+
+/**
+ * GDataGDOrganization:
+ * @name: the name of the organization, or %NULL
+ * @title: the owner's title within the organization, or %NULL
+ * @rel: the relationship between the organization and its owner, or %NULL
+ * @label: a human-readable label for the organization, or %NULL
+ * @primary: %TRUE if this organization is its owner's primary organization, %FALSE otherwise
+ *
+ * A structure fully representing a GData "organization" element. All fields are optional.
+ *
+ * See the <ulink type="http" url="http://code.google.com/apis/gdata/elements.html#gdOrganization";>GData specification</ulink>
+ * for more information.
+ **/
+typedef struct {
+	gchar *name;
+	gchar *title;
+	gchar *rel;
+	gchar *label;
+	gboolean primary;
+} GDataGDOrganization;
+
+GDataGDOrganization *gdata_gd_organization_new (const gchar *name, const gchar *title, const gchar *rel, const gchar *label, gboolean primary);
+void gdata_gd_organization_free (GDataGDOrganization *self);
+
 G_END_DECLS
 
 #endif /* !GDATA_GDATA_H */
diff --git a/gdata/gdata.h b/gdata/gdata.h
index 37e2b9e..edbe77d 100644
--- a/gdata/gdata.h
+++ b/gdata/gdata.h
@@ -49,4 +49,8 @@
 #include <gdata/services/calendar/gdata-calendar-event.h>
 #include <gdata/services/calendar/gdata-calendar-query.h>
 
+/* Google Contacts */
+#include <gdata/services/contacts/gdata-contacts-service.h>
+#include <gdata/services/contacts/gdata-contacts-query.h>
+
 #endif /* !GDATA_H */
diff --git a/gdata/gdata.symbols b/gdata/gdata.symbols
index 7e4325b..6637831 100644
--- a/gdata/gdata.symbols
+++ b/gdata/gdata.symbols
@@ -229,5 +229,30 @@ gdata_gd_who_new
 gdata_gd_who_free
 gdata_gd_where_new
 gdata_gd_where_free
+gdata_gd_email_address_new
+gdata_gd_email_address_free
+gdata_gd_im_address_new
+gdata_gd_im_address_free
+gdata_gd_phone_number_new
+gdata_gd_phone_number_free
+gdata_gd_postal_address_new
+gdata_gd_postal_address_free
+gdata_gd_organization_new
+gdata_gd_organization_free
 gdata_media_expression_get_type
 gdata_parser_error_get_type
+gdata_contacts_service_get_type
+gdata_contacts_service_new
+gdata_contacts_service_query_contacts
+gdata_contacts_service_query_contacts_async
+gdata_contacts_query_get_type
+gdata_contacts_query_new
+gdata_contacts_query_new_with_limits
+gdata_contacts_query_get_order_by
+gdata_contacts_query_set_order_by
+gdata_contacts_query_show_deleted
+gdata_contacts_query_set_show_deleted
+gdata_contacts_query_get_sort_order
+gdata_contacts_query_set_sort_order
+gdata_contacts_query_get_group
+gdata_contacts_query_set_group
diff --git a/gdata/services/Makefile.am b/gdata/services/Makefile.am
index 061f7e5..6d224f1 100644
--- a/gdata/services/Makefile.am
+++ b/gdata/services/Makefile.am
@@ -1,3 +1,3 @@
-SUBDIRS = youtube calendar
+SUBDIRS = youtube calendar contacts
 
 -include $(top_srcdir)/git.mk
diff --git a/gdata/services/contacts/Makefile.am b/gdata/services/contacts/Makefile.am
new file mode 100644
index 0000000..03069b6
--- /dev/null
+++ b/gdata/services/contacts/Makefile.am
@@ -0,0 +1,36 @@
+gdatacontactsincludedir = $(pkgincludedir)/gdata/services/contacts
+gdatacontactsinclude_HEADERS = \
+	gdata-contacts-service.h	\
+	gdata-contacts-query.h
+
+noinst_LTLIBRARIES = libgdatacontacts.la
+
+libgdatacontacts_headers =
+
+libgdatacontacts_la_SOURCES = \
+	gdata-contacts-service.c	\
+	gdata-contacts-service.h	\
+	gdata-contacts-query.c		\
+	gdata-contacts-query.h
+
+libgdatacontacts_la_CPPFLAGS = \
+	-I$(top_srcdir)				\
+	-I$(top_srcdir)/gdata			\
+	-I$(top_srcdir)/gdata/services/contacts	\
+	$(DISABLE_DEPRECATED)			\
+	$(AM_CPPFLAGS)
+
+libgdatacontacts_la_CFLAGS = \
+	$(GDATA_CFLAGS)	\
+	$(WARN_CFLAGS)	\
+	$(AM_CFLAGS)	\
+	-D_GNU_SOURCE
+
+libgdatacontacts_la_LIBADD = \
+	$(GDATA_LIBS)
+
+libgdatacontacts_la_LDFLAGS = \
+	-no-undefined	\
+	$(AM_LDFLAGS)
+
+-include $(top_srcdir)/git.mk
diff --git a/gdata/services/contacts/gdata-contacts-query.c b/gdata/services/contacts/gdata-contacts-query.c
new file mode 100644
index 0000000..bd2a00a
--- /dev/null
+++ b/gdata/services/contacts/gdata-contacts-query.c
@@ -0,0 +1,234 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ * GData Client
+ * Copyright (C) Philip Withnall 2009 <philip tecnocode co uk>
+ *
+ * GData Client 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.
+ *
+ * GData Client 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 GData Client.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <glib.h>
+#include <glib/gi18n-lib.h>
+#include <string.h>
+
+#include "gdata-contacts-query.h"
+#include "gdata-query.h"
+
+/* Reference: http://code.google.com/apis/contacts/docs/2.0/reference.html#Parameters */
+
+static void gdata_contacts_query_finalize (GObject *object);
+static void gdata_contacts_query_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void gdata_contacts_query_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+
+/* TODO: Actually override GDataQuery's get_query_uri function to return a URI including all our custom parameters */
+struct _GDataContactsQueryPrivate {
+	gchar *order_by; /* TODO: enum? #defined values? */
+	gboolean show_deleted;
+	gchar *sort_order; /* TODO: enum? */
+	gchar *group;
+};
+
+enum {
+	PROP_ORDER_BY = 1,
+	PROP_SHOW_DELETED
+	PROP_SORT_ORDER,
+	PROP_GROUP
+};
+
+G_DEFINE_TYPE (GDataContactsQuery, gdata_contacts_query, GDATA_TYPE_QUERY)
+#define GDATA_CONTACTS_QUERY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GDATA_TYPE_CONTACTS_QUERY, GDataContactsQueryPrivate))
+
+static void
+gdata_contacts_query_class_init (GDataContactsQueryClass *klass)
+{
+	GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+	g_type_class_add_private (klass, sizeof (GDataContactsQueryPrivate));
+
+	gobject_class->set_property = gdata_contacts_query_set_property;
+	gobject_class->get_property = gdata_contacts_query_get_property;
+	gobject_class->finalize = gdata_contacts_query_finalize;
+
+	g_object_class_install_property (gobject_class, PROP_ORDER_BY,
+				g_param_spec_string ("order-by",
+					"Order by", "TODO",
+					NULL,
+					G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+	g_object_class_install_property (gobject_class, PROP_SHOW_DELETED,
+				g_param_spec_boolean ("show-deleted",
+					"Show deleted", "TODO",
+					FALSE,
+					G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+	g_object_class_install_property (gobject_class, PROP_SORT_ORDER,
+				g_param_spec_string ("sort-order",
+					"Sort order", "TODO",
+					NULL,
+					G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+	g_object_class_install_property (gobject_class, PROP_GROUP,
+				g_param_spec_string ("group",
+					"Group", "TODO",
+					NULL,
+					G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+}
+
+static void
+gdata_contacts_query_init (GDataContactsQuery *self)
+{
+	self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GDATA_TYPE_CONTACTS_QUERY, GDataContactsQueryPrivate);
+}
+
+static void
+gdata_contacts_query_finalize (GObject *object)
+{
+	GDataContactsQueryPrivate *priv = GDATA_CONTACTS_QUERY_GET_PRIVATE (object);
+
+	g_free (priv->order_by);
+	g_free (priv->sort_order);
+	g_free (priv->group);
+
+	/* Chain up to the parent class */
+	G_OBJECT_CLASS (gdata_contacts_query_parent_class)->finalize (object);
+}
+
+static void
+gdata_contacts_query_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+	GDataContactsQueryPrivate *priv = GDATA_CONTACTS_QUERY_GET_PRIVATE (object);
+
+	switch (property_id) {
+		case PROP_ORDER_BY:
+			g_value_set_string (value, priv->order_by);
+			break;
+		case PROP_SHOW_DELETED:
+			g_value_set_boolean (value, priv->show_deleted);
+			break;
+		case PROP_SORT_ORDER:
+			g_value_set_string (value, priv->sort_order);
+			break;
+		case PROP_GROUP:
+			g_value_set_string (value, priv->group);
+			break;
+		default:
+			/* We don't have any other property... */
+			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+			break;
+	}
+}
+
+static void
+gdata_contacts_query_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+	GDataContactsQuery *self = GDATA_CONTACTS_QUERY (object);
+
+	switch (property_id) {
+		case PROP_ORDER_BY:
+			gdata_contacts_query_set_order_by (self, g_value_get_string (value));
+			break;
+		case PROP_SHOW_DELETED:
+			gdata_contacts_query_set_show_deleted (self, g_value_get_boolean (value));
+			break;
+		case PROP_SORT_ORDER:
+			gdata_contacts_query_set_sort_order (self, g_value_get_string (value));
+			break;
+		case PROP_GROUP:
+			gdata_contacts_query_set_group (self, g_value_get_string (value));
+			break;
+		default:
+			/* We don't have any other property... */
+			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+			break;
+	}
+}
+
+GDataContactsQuery *
+gdata_contacts_query_new (const gchar *q)
+{
+	return g_object_new (GDATA_TYPE_CONTACTS_QUERY, "q", q, NULL);
+}
+
+GDataContactsQuery *
+gdata_contacts_query_new_with_limits (const gchar *q, GTimeVal *start_min, GTimeVal *start_max)
+{
+	return g_object_new (GDATA_TYPE_CONTACTS_QUERY,
+			     "q", q,
+			     "start-min", start_min,
+			     "start-max", start_max,
+			     NULL);
+}
+
+const gchar *
+gdata_contacts_query_get_order_by (GDataContactsQuery *self)
+{
+	g_return_val_if_fail (GDATA_IS_CONTACTS_QUERY (self), NULL);
+	return self->priv->order_by;
+}
+
+void
+gdata_contacts_query_set_order_by (GDataContactsQuery *self, const gchar *order_by)
+{
+	g_return_if_fail (GDATA_IS_CONTACTS_QUERY (self));
+
+	g_free (self->priv->order_by);
+	self->priv->order_by = g_strdup (order_by);
+	g_object_notify (G_OBJECT (self), "order-by");
+}
+
+gboolean
+gdata_contacts_query_get_show_deleted (GDataContactsQuery *self)
+{
+	g_return_val_if_fail (GDATA_IS_CONTACTS_QUERY (self), FALSE);
+	return self->priv->show_deleted;
+}
+
+void
+gdata_contacts_query_set_show_deleted (GDataContactsQuery *self, gboolean show_deleted)
+{
+	g_return_if_fail (GDATA_IS_CONTACTS_QUERY (self));
+	self->priv->show_deleted = show_deleted;
+	g_object_notify (G_OBJECT (self), "show-deleted");
+}
+
+const gchar *
+gdata_contacts_query_get_sort_order (GDataContactsQuery *self)
+{
+	g_return_val_if_fail (GDATA_IS_CONTACTS_QUERY (self), NULL);
+	return self->priv->sort_order;
+}
+
+void
+gdata_contacts_query_set_sort_order (GDataContactsQuery *self, const gchar *sort_order)
+{
+	g_return_if_fail (GDATA_IS_CONTACTS_QUERY (self));
+
+	g_free (self->priv->sort_order);
+	self->priv->sort_order = g_strdup (sort_order);
+	g_object_notify (G_OBJECT (self), "sort-order");
+}
+
+const gchar *
+gdata_contacts_query_get_group (GDataContactsQuery *self)
+{
+	g_return_val_if_fail (GDATA_IS_CONTACTS_QUERY (self), NULL);
+	return self->priv->group;
+}
+
+void
+gdata_contacts_query_set_group (GDataContactsQuery *self, const gchar *group)
+{
+	g_return_if_fail (GDATA_IS_CONTACTS_QUERY (self));
+
+	g_free (self->priv->group);
+	self->priv->group = g_strdup (group);
+	g_object_notify (G_OBJECT (self), "group");
+}
diff --git a/gdata/services/contacts/gdata-contacts-query.h b/gdata/services/contacts/gdata-contacts-query.h
new file mode 100644
index 0000000..2cd7c69
--- /dev/null
+++ b/gdata/services/contacts/gdata-contacts-query.h
@@ -0,0 +1,64 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ * GData Client
+ * Copyright (C) Philip Withnall 2009 <philip tecnocode co uk>
+ *
+ * GData Client 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.
+ *
+ * GData Client 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 GData Client.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GDATA_CONTACTS_QUERY_H
+#define GDATA_CONTACTS_QUERY_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <gdata/gdata-query.h>
+
+G_BEGIN_DECLS
+
+#define GDATA_TYPE_CONTACTS_QUERY		(gdata_contacts_query_get_type ())
+#define GDATA_CONTACTS_QUERY(o)			(G_TYPE_CHECK_INSTANCE_CAST ((o), GDATA_TYPE_CONTACTS_QUERY, GDataContactsQuery))
+#define GDATA_CONTACTS_QUERY_CLASS(k)		(G_TYPE_CHECK_CLASS_CAST((k), GDATA_TYPE_CONTACTS_QUERY, GDataContactsQueryClass))
+#define GDATA_IS_CONTACTS_QUERY(o)		(G_TYPE_CHECK_INSTANCE_TYPE ((o), GDATA_TYPE_CONTACTS_QUERY))
+#define GDATA_IS_CONTACTS_QUERY_CLASS(k)	(G_TYPE_CHECK_CLASS_TYPE ((k), GDATA_TYPE_CONTACTS_QUERY))
+#define GDATA_CONTACTS_QUERY_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), GDATA_TYPE_CONTACTS_QUERY, GDataContactsQueryClass))
+
+typedef struct _GDataContactsQueryPrivate	GDataContactsQueryPrivate;
+
+typedef struct {
+	GDataQuery parent;
+	GDataContactsQueryPrivate *priv;
+} GDataContactsQuery;
+
+typedef struct {
+	GDataQueryClass parent;
+} GDataContactsQueryClass;
+
+GType gdata_contacts_query_get_type (void);
+
+GDataContactsQuery *gdata_contacts_query_new (const gchar *q);
+GDataContactsQuery *gdata_contacts_query_new_with_limits (const gchar *q, GTimeVal *start_min, GTimeVal *start_max);
+
+const gchar *gdata_contacts_query_get_order_by (GDataContactsQuery *self);
+void gdata_contacts_query_set_order_by (GDataContactsQuery *self, const gchar *order_by);
+gboolean gdata_contacts_query_show_deleted (GDataContactsQuery *self);
+void gdata_contacts_query_set_show_deleted (GDataContactsQuery *self, gboolean show_deleted);
+const gchar *gdata_contacts_query_get_sort_order (GDataContactsQuery *self);
+void gdata_contacts_query_set_sort_order (GDataContactsQuery *self, const gchar *sort_order);
+const gchar *gdata_contacts_query_get_group (GDataContactsQuery *self);
+void gdata_contacts_query_set_group (GDataContactsQuery *self, const gchar *group);
+
+G_END_DECLS
+
+#endif /* !GDATA_CONTACTS_QUERY_H */
diff --git a/gdata/services/contacts/gdata-contacts-service.c b/gdata/services/contacts/gdata-contacts-service.c
new file mode 100644
index 0000000..d249ae8
--- /dev/null
+++ b/gdata/services/contacts/gdata-contacts-service.c
@@ -0,0 +1,89 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ * GData Client
+ * Copyright (C) Philip Withnall 2009 <philip tecnocode co uk>
+ *
+ * GData Client 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.
+ *
+ * GData Client 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 GData Client.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <glib.h>
+#include <glib/gi18n-lib.h>
+#include <libsoup/soup.h>
+#include <string.h>
+
+#include "gdata-contacts-service.h"
+#include "gdata-service.h"
+#include "gdata-private.h"
+#include "gdata-contacts-query.h"
+
+/* Standards reference here: http://code.google.com/apis/contacts/docs/2.0/reference.html */
+
+G_DEFINE_TYPE (GDataContactsService, gdata_contacts_service, GDATA_TYPE_SERVICE)
+#define GDATA_CONTACTS_SERVICE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GDATA_TYPE_CONTACTS_SERVICE, GDataContactsServicePrivate))
+
+static void
+gdata_contacts_service_class_init (GDataContactsServiceClass *klass)
+{
+	GDataServiceClass *service_class = GDATA_SERVICE_CLASS (klass);
+	service_class->service_name = "cp";
+}
+
+static void
+gdata_contacts_service_init (GDataContactsService *self)
+{
+	/* Nothing to see here */
+}
+
+GDataContactsService *
+gdata_contacts_service_new (const gchar *client_id)
+{
+	g_return_val_if_fail (client_id != NULL, NULL);
+
+	return g_object_new (GDATA_TYPE_CONTACTS_SERVICE,
+			     "client-id", client_id,
+			     NULL);
+}
+
+GDataFeed *
+gdata_contacts_service_query_contacts (GDataContactsService *self, GDataContactsQuery *query, GCancellable *cancellable,
+				       GDataQueryProgressCallback progress_callback, gpointer progress_user_data, GError **error)
+{
+	/* Ensure we're authenticated first */
+	if (gdata_service_is_authenticated (GDATA_SERVICE (self)) == FALSE) {
+		g_set_error_literal (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED,
+				     _("You must be authenticated to query contacts."));
+		return NULL;
+	}
+
+	return gdata_service_query (GDATA_SERVICE (self), "http://www.google.com/m8/feeds/contacts/default/full";, GDATA_QUERY (query),
+				    GDATA_TYPE_CONTACTS_CONTACT, cancellable, progress_callback, progress_user_data, error);
+}
+
+void
+gdata_contacts_service_query_contacts_async (GDataContactsService *self, GDataContactsQuery *query, GCancellable *cancellable,
+					     GDataQueryProgressCallback progress_callback, gpointer progress_user_data,
+					     GAsyncReadyCallback callback, gpointer user_data)
+{
+	/* Ensure we're authenticated first */
+	if (gdata_service_is_authenticated (GDATA_SERVICE (self)) == FALSE) {
+		g_simple_async_report_error_in_idle (G_OBJECT (self), callback, user_data,
+						     GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED,
+						     _("You must be authenticated to query contacts."));
+		return;
+	}
+
+	gdata_service_query_async (GDATA_SERVICE (self), "http://www.google.com/m8/feeds/contacts/default/full";, GDATA_QUERY (query),
+				   GDATA_TYPE_CONTACTS_CONTACT, cancellable, progress_callback, progress_user_data, callback, user_data);
+}
diff --git a/gdata/services/contacts/gdata-contacts-service.h b/gdata/services/contacts/gdata-contacts-service.h
new file mode 100644
index 0000000..719f231
--- /dev/null
+++ b/gdata/services/contacts/gdata-contacts-service.h
@@ -0,0 +1,60 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ * GData Client
+ * Copyright (C) Philip Withnall 2009 <philip tecnocode co uk>
+ *
+ * GData Client 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.
+ *
+ * GData Client 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 GData Client.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GDATA_CONTACTS_SERVICE_H
+#define GDATA_CONTACTS_SERVICE_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <gdata/gdata-service.h>
+#include <gdata/services/contacts/gdata-contacts-contacts.h>
+
+G_BEGIN_DECLS
+
+#define GDATA_TYPE_CONTACTS_SERVICE		(gdata_contacts_service_get_type ())
+#define GDATA_CONTACTS_SERVICE(o)		(G_TYPE_CHECK_INSTANCE_CAST ((o), GDATA_TYPE_CONTACTS_SERVICE, GDataContactsService))
+#define GDATA_CONTACTS_SERVICE_CLASS(k)		(G_TYPE_CHECK_CLASS_CAST((k), GDATA_TYPE_CONTACTS_SERVICE, GDataContactsServiceClass))
+#define GDATA_IS_CONTACTS_SERVICE(o)		(G_TYPE_CHECK_INSTANCE_TYPE ((o), GDATA_TYPE_CONTACTS_SERVICE))
+#define GDATA_IS_CONTACTS_SERVICE_CLASS(k)	(G_TYPE_CHECK_CLASS_TYPE ((k), GDATA_TYPE_CONTACTS_SERVICE))
+#define GDATA_CONTACTS_SERVICE_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), GDATA_TYPE_CONTACTS_SERVICE, GDataContactsServiceClass))
+
+typedef struct _GDataContactsServicePrivate	GDataContactsServicePrivate;
+
+typedef struct {
+	GDataService parent;
+} GDataContactsService;
+
+typedef struct {
+	GDataServiceClass parent;
+} GDataContactsServiceClass;
+
+GType gdata_contacts_service_get_type (void);
+
+GDataContactsService *gdata_contacts_service_new (const gchar *client_id);
+
+GDataFeed *gdata_contacts_service_query_contacts (GDataContactsService *self, GDataContactsQuery *query, GCancellable *cancellable,
+						  GDataQueryProgressCallback progress_callback, gpointer progress_user_data, GError **error);
+void gdata_contacts_service_query_contacts_async (GDataContactsService *self, GDataContactsQuery *query, GCancellable *cancellable,
+						  GDataQueryProgressCallback progress_callback, gpointer progress_user_data,
+						  GAsyncReadyCallback callback, gpointer user_data);
+
+G_END_DECLS
+
+#endif /* !GDATA_CONTACTS_SERVICE_H */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]