[libgdata] [atom] Added #defined values for the standard link relation types



commit 362a970abd6623d09fc4194d57e840996c9b702c
Author: Philip Withnall <philip tecnocode co uk>
Date:   Tue Jun 30 18:36:26 2009 +0100

    [atom] Added #defined values for the standard link relation types

 docs/reference/gdata-sections.txt |    7 +++
 gdata/atom/gdata-link.c           |    7 ++-
 gdata/atom/gdata-link.h           |   84 +++++++++++++++++++++++++++++++++++++
 gdata/gdata-access-handler.c      |    2 +-
 gdata/gdata-entry.c               |    3 +-
 gdata/gdata-service.c             |    4 +-
 gdata/tests/general.c             |    5 +-
 7 files changed, 103 insertions(+), 9 deletions(-)
---
diff --git a/docs/reference/gdata-sections.txt b/docs/reference/gdata-sections.txt
index 4acc178..bd23172 100644
--- a/docs/reference/gdata-sections.txt
+++ b/docs/reference/gdata-sections.txt
@@ -660,6 +660,13 @@ gdata_link_get_title
 gdata_link_set_title
 gdata_link_get_length
 gdata_link_set_length
+GDATA_LINK_ALTERNATE
+GDATA_LINK_EDIT
+GDATA_LINK_EDIT_MEDIA
+GDATA_LINK_ENCLOSURE
+GDATA_LINK_RELATED
+GDATA_LINK_SELF
+GDATA_LINK_VIA
 <SUBSECTION Standard>
 gdata_link_get_type
 GDATA_IS_LINK
diff --git a/gdata/atom/gdata-link.c b/gdata/atom/gdata-link.c
index 57d4a19..6025e07 100644
--- a/gdata/atom/gdata-link.c
+++ b/gdata/atom/gdata-link.c
@@ -107,7 +107,7 @@ gdata_link_class_init (GDataLinkClass *klass)
 	g_object_class_install_property (gobject_class, PROP_RELATION_TYPE,
 				g_param_spec_string ("relation-type",
 					"Relation type", "The link relation type.",
-					"alternate",
+					"http://www.iana.org/assignments/relation/alternate";,
 					G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
 	/**
@@ -181,7 +181,7 @@ gdata_link_init (GDataLink *self)
 {
 	self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GDATA_TYPE_LINK, GDataLinkPrivate);
 	self->priv->length = -1;
-	self->priv->relation_type = g_strdup ("alternate");
+	self->priv->relation_type = g_strdup ("http://www.iana.org/assignments/relation/alternate";);
 }
 
 static void
@@ -450,7 +450,8 @@ gdata_link_get_relation_type (GDataLink *self)
  * @self: a #GDataLink
  * @relation_type: the new relation type for the link, or %NULL
  *
- * Sets the #GDataLink:relation-type property to @relation_type.
+ * Sets the #GDataLink:relation-type property to @relation_type. If @relation_type is one of the standard Atom relation types,
+ * use one of the defined relation type values, instead of a static string. e.g. %GDATA_LINK_EDIT or %GDATA_LINK_SELF.
  *
  * Set @relation_type to %NULL to unset the property in the link.
  *
diff --git a/gdata/atom/gdata-link.h b/gdata/atom/gdata-link.h
index 9e2810b..c948ac4 100644
--- a/gdata/atom/gdata-link.h
+++ b/gdata/atom/gdata-link.h
@@ -27,6 +27,90 @@
 
 G_BEGIN_DECLS
 
+/**
+ * GDATA_LINK_ALTERNATE:
+ *
+ * The relation type URI for alternate resources to the current one.
+ *
+ * For more information, see the <ulink type="http" url="http://www.atomenabled.org/developers/syndication/atom-format-spec.php#rel_attribute";>
+ * Atom specification</ulink>.
+ *
+ * Since: 0.4.0
+ **/
+#define GDATA_LINK_ALTERNATE "http://www.iana.org/assignments/relation/alternate";
+
+/**
+ * GDATA_LINK_RELATED:
+ *
+ * The relation type URI for resources related to the current one.
+ *
+ * For more information, see the <ulink type="http" url="http://www.atomenabled.org/developers/syndication/atom-format-spec.php#rel_attribute";>
+ * Atom specification</ulink>.
+ *
+ * Since: 0.4.0
+ **/
+#define GDATA_LINK_RELATED "http://www.iana.org/assignments/relation/related";
+
+/**
+ * GDATA_LINK_SELF:
+ *
+ * The relation type URI for the current resource.
+ *
+ * For more information, see the <ulink type="http" url="http://www.atomenabled.org/developers/syndication/atom-format-spec.php#rel_attribute";>
+ * Atom specification</ulink>.
+ *
+ * Since: 0.4.0
+ **/
+#define GDATA_LINK_SELF "http://www.iana.org/assignments/relation/self";
+
+/**
+ * GDATA_LINK_ENCLOSURE:
+ *
+ * The relation type URI for attached objects which may be large in size.
+ *
+ * For more information, see the <ulink type="http" url="http://www.atomenabled.org/developers/syndication/atom-format-spec.php#rel_attribute";>
+ * Atom specification</ulink>.
+ *
+ * Since: 0.4.0
+ **/
+#define GDATA_LINK_ENCLOSURE "http://www.iana.org/assignments/relation/enclosure";
+
+/**
+ * GDATA_LINK_VIA:
+ *
+ * The relation type URI for the source document of the current resource.
+ *
+ * For more information, see the <ulink type="http" url="http://www.atomenabled.org/developers/syndication/atom-format-spec.php#rel_attribute";>
+ * Atom specification</ulink>.
+ *
+ * Since: 0.4.0
+ **/
+#define GDATA_LINK_VIA "http://www.iana.org/assignments/relation/via";
+
+/**
+ * GDATA_LINK_EDIT:
+ *
+ * The relation type URI of the edit location for this resource.
+ *
+ * For more information, see the <ulink type="http" url="http://www.atomenabled.org/developers/protocol/atom-protocol-spec.php#new-link-relation";>
+ * Atom Publishing Protocol specification</ulink>.
+ *
+ * Since: 0.4.0
+ **/
+#define GDATA_LINK_EDIT "http://www.iana.org/assignments/relation/edit";
+
+/**
+ * GDATA_LINK_EDIT_MEDIA:
+ *
+ * The relation type URI of the edit location for media resources attached to this resource.
+ *
+ * For more information, see the <ulink type="http" url="http://www.atomenabled.org/developers/protocol/atom-protocol-spec.php#new-media-link-relation";>
+ * Atom Publishing Protocol specification</ulink>.
+ *
+ * Since: 0.4.0
+ **/
+#define GDATA_LINK_EDIT_MEDIA "http://www.iana.org/assignments/relation/edit-media";
+
 #define GDATA_TYPE_LINK			(gdata_link_get_type ())
 #define GDATA_LINK(o)			(G_TYPE_CHECK_INSTANCE_CAST ((o), GDATA_TYPE_LINK, GDataLink))
 #define GDATA_LINK_CLASS(k)		(G_TYPE_CHECK_CLASS_CAST((k), GDATA_TYPE_LINK, GDataLinkClass))
diff --git a/gdata/gdata-access-handler.c b/gdata/gdata-access-handler.c
index 527f150..9ed06b5 100644
--- a/gdata/gdata-access-handler.c
+++ b/gdata/gdata-access-handler.c
@@ -234,7 +234,7 @@ get_soup_message (GDataAccessHandler *access_handler, GDataAccessRule *rule, con
 	const gchar *scope_type, *scope_value;
 
 	/* Get the edit URI */
-	link = gdata_entry_look_up_link (GDATA_ENTRY (rule), "edit");
+	link = gdata_entry_look_up_link (GDATA_ENTRY (rule), GDATA_LINK_EDIT);
 	if (link != NULL)
 		return soup_message_new (method, gdata_link_get_uri (link));
 
diff --git a/gdata/gdata-entry.c b/gdata/gdata-entry.c
index 3e1c22f..72f1a73 100644
--- a/gdata/gdata-entry.c
+++ b/gdata/gdata-entry.c
@@ -711,7 +711,8 @@ link_compare_cb (const GDataLink *link, const gchar *rel)
  * @self: a #GDataEntry
  * @rel: the value of the <structfield>rel</structfield> attribute of the desired link
  *
- * Looks up a link by <structfield>rel</structfield> value from the list of links in the entry.
+ * Looks up a link by relation type from the list of links in the entry. If the link has one of the standard Atom relation types,
+ * use one of the defined @rel values, instead of a static string. e.g. %GDATA_LINK_EDIT or %GDATA_LINK_SELF.
  *
  * Return value: a #GDataLink, or %NULL if one was not found
  *
diff --git a/gdata/gdata-service.c b/gdata/gdata-service.c
index afcb67f..ddec843 100644
--- a/gdata/gdata-service.c
+++ b/gdata/gdata-service.c
@@ -1379,7 +1379,7 @@ gdata_service_update_entry (GDataService *self, GDataEntry *entry, GCancellable
 	g_return_val_if_fail (GDATA_IS_ENTRY (entry), NULL);
 
 	/* Get the edit URI */
-	link = gdata_entry_look_up_link (entry, "edit");
+	link = gdata_entry_look_up_link (entry, GDATA_LINK_EDIT);
 	g_assert (link != NULL);
 	message = soup_message_new (SOUP_METHOD_PUT, gdata_link_get_uri (link));
 
@@ -1547,7 +1547,7 @@ gdata_service_delete_entry (GDataService *self, GDataEntry *entry, GCancellable
 	g_return_val_if_fail (GDATA_IS_ENTRY (entry), FALSE);
 
 	/* Get the edit URI */
-	link = gdata_entry_look_up_link (entry, "edit");
+	link = gdata_entry_look_up_link (entry, GDATA_LINK_EDIT);
 	g_assert (link != NULL);
 	message = soup_message_new (SOUP_METHOD_DELETE, gdata_link_get_uri (link));
 
diff --git a/gdata/tests/general.c b/gdata/tests/general.c
index d4a20f0..860e8f3 100644
--- a/gdata/tests/general.c
+++ b/gdata/tests/general.c
@@ -55,14 +55,14 @@ test_entry_get_xml (void)
 	g_object_unref (category);
 
 	/* Links */
-	link = gdata_link_new ("http://test.com/";, "self");
+	link = gdata_link_new ("http://test.com/";, GDATA_LINK_SELF);
 	gdata_link_set_content_type (link, "application/atom+xml");
 	gdata_entry_add_link (entry, link);
 	g_object_unref (link);
 	link = gdata_link_new ("http://example.com/";, NULL);
 	gdata_entry_add_link (entry, link);
 	g_object_unref (link);
-	link = gdata_link_new ("http://test.mn/";, "related");
+	link = gdata_link_new ("http://test.mn/";, GDATA_LINK_RELATED);
 	gdata_link_set_content_type (link, "text/html");
 	gdata_link_set_language (link, "mn");
 	gdata_link_set_title (link, "A treatise on Mongolian test websites & other stuff.");
@@ -1121,6 +1121,7 @@ main (int argc, char *argv[])
 	g_test_add_func ("/gd/when", test_gd_when);
 	g_test_add_func ("/gd/where", test_gd_where);
 	g_test_add_func ("/gd/who", test_gd_who);
+
 	/*g_test_add_data_func ("/media/thumbnail/parse_time", "", test_media_thumbnail_parse_time);
 	g_test_add_data_func ("/media/thumbnail/parse_time", "de_DE", test_media_thumbnail_parse_time);*/
 



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