[libgdata] [documents] Fixed gdata_documents_entry_get_path function
- From: Philip Withnall <pwithnall src gnome org>
- To: svn-commits-list gnome org
- Subject: [libgdata] [documents] Fixed gdata_documents_entry_get_path function
- Date: Mon, 20 Jul 2009 18:19:25 +0000 (UTC)
commit a1824d8706439c882f3e6fcb6496120fd4300e78
Author: Philip Withnall <philip tecnocode co uk>
Date: Mon Jul 20 19:18:16 2009 +0100
[documents] Fixed gdata_documents_entry_get_path function
Necessarily also fixed gdata_entry_look_up_links, and added test cases for
it. Based on patches by Thibault Saunier <saunierthibault gmail com>.
Closes: bgo#589067
gdata/atom/gdata-link.c | 4 +-
gdata/gdata-entry.c | 16 ++---
gdata/gdata.symbols | 1 +
gdata/services/documents/gdata-documents-entry.c | 71 ++++++++++++----------
gdata/services/documents/gdata-documents-entry.h | 2 +-
gdata/tests/general.c | 33 ++++++++++-
6 files changed, 84 insertions(+), 43 deletions(-)
---
diff --git a/gdata/atom/gdata-link.c b/gdata/atom/gdata-link.c
index d40c3b1..70bdc00 100644
--- a/gdata/atom/gdata-link.c
+++ b/gdata/atom/gdata-link.c
@@ -387,7 +387,9 @@ gdata_link_compare (const GDataLink *a, const GDataLink *b)
if (a == b)
return 0;
- return g_strcmp0 (a->priv->uri, b->priv->uri);
+ if (g_strcmp0 (a->priv->uri, b->priv->uri) == 0 && g_strcmp0 (a->priv->relation_type, b->priv->relation_type) == 0)
+ return 0;
+ return 1;
}
/**
diff --git a/gdata/gdata-entry.c b/gdata/gdata-entry.c
index 2a2ecb3..7a2f7d4 100644
--- a/gdata/gdata-entry.c
+++ b/gdata/gdata-entry.c
@@ -735,25 +735,23 @@ gdata_entry_look_up_link (GDataEntry *self, const gchar *rel)
*
* If you will only use the first link found, consider calling gdata_entry_look_up_link() instead.
*
- * Return value: a #GList of #GDataLink<!-- -->s, or %NULL if none were found
+ * Return value: a #GList of #GDataLink<!-- -->s, or %NULL if none were found; free the list with g_list_free()
*
* Since: 0.4.0
**/
GList *
gdata_entry_look_up_links (GDataEntry *self, const gchar *rel)
{
- GList *element = self->priv->links, *results = NULL;
+ GList *i, *results = NULL;
g_return_val_if_fail (GDATA_IS_ENTRY (self), NULL);
g_return_val_if_fail (rel != NULL, NULL);
- do {
- element = g_list_find_custom (element, rel, (GCompareFunc) link_compare_cb);
- if (element == NULL)
- return results;
- results = g_list_prepend (results, element);
- element = element->next;
- } while (element != NULL);
+ for (i = self->priv->links; i != NULL; i = i->next) {
+ const gchar *relation_type = gdata_link_get_relation_type (((GDataLink*) i->data));
+ if (strcmp (relation_type, rel) == 0)
+ results = g_list_prepend (results, i->data);
+ }
return g_list_reverse (results);
}
diff --git a/gdata/gdata.symbols b/gdata/gdata.symbols
index 9bb8645..56c764b 100644
--- a/gdata/gdata.symbols
+++ b/gdata/gdata.symbols
@@ -17,6 +17,7 @@ gdata_entry_get_content
gdata_entry_set_content
gdata_entry_add_link
gdata_entry_look_up_link
+gdata_entry_look_up_links
gdata_entry_add_author
gdata_entry_is_inserted
gdata_feed_get_type
diff --git a/gdata/services/documents/gdata-documents-entry.c b/gdata/services/documents/gdata-documents-entry.c
index 0245558..efb9b29 100644
--- a/gdata/services/documents/gdata-documents-entry.c
+++ b/gdata/services/documents/gdata-documents-entry.c
@@ -56,7 +56,6 @@ static gboolean parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node,
struct _GDataDocumentsEntryPrivate {
GTimeVal edited;
GTimeVal last_viewed;
- gchar *path;
gchar *document_id;
gboolean writers_can_invite;
GDataAuthor *last_modified_by;
@@ -65,7 +64,6 @@ struct _GDataDocumentsEntryPrivate {
enum {
PROP_EDITED = 1,
PROP_LAST_VIEWED,
- PROP_PATH,
PROP_DOCUMENT_ID,
PROP_LAST_MODIFIED_BY,
PROP_WRITERS_CAN_INVITE
@@ -135,19 +133,6 @@ gdata_documents_entry_class_init (GDataDocumentsEntryClass *klass)
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
- * GDataDocumentsEntry:path
- *
- * Indicates the folder hierarchy path containing the document.
- *
- * Since: 0.4.0
- **/
- g_object_class_install_property (gobject_class, PROP_PATH,
- g_param_spec_string ("path",
- "Path", "Indicates the folder hierarchy path containing the document.",
- NULL,
- G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
-
- /**
* GDataDocumentsEntry:document-id
*
* The document ID of the document, which is different from its entry ID (GDataEntry:id).
@@ -274,7 +259,6 @@ gdata_documents_entry_finalize (GObject *object)
{
GDataDocumentsEntryPrivate *priv = GDATA_DOCUMENTS_ENTRY_GET_PRIVATE (object);
- g_free (priv->path);
g_free (priv->document_id);
/* Chain up to the parent class */
@@ -300,9 +284,6 @@ gdata_documents_entry_get_property (GObject *object, guint property_id, GValue *
GDataDocumentsEntryPrivate *priv = GDATA_DOCUMENTS_ENTRY_GET_PRIVATE (object);
switch (property_id) {
- case PROP_PATH:
- g_value_set_string (value, priv->path);
- break;
case PROP_DOCUMENT_ID:
g_value_set_string (value, priv->document_id);
break;
@@ -409,29 +390,57 @@ gdata_documents_entry_get_last_viewed (GDataDocumentsEntry *self, GTimeVal *last
*
* Gets the #GDataDocumentsEntry:path property.
*
- * Return value: the folder hierarchy path containing the entry
+ * Note: the path is based on the entry ID, and not the entry human readable name (#GDataEntry::title).
+ *
+ * Return value: the folder hierarchy path containing the entry, or %NULL; free with g_free()
*
* Since: 0.4.0
**/
-const gchar *
+gchar *
gdata_documents_entry_get_path (GDataDocumentsEntry *self)
{
- GList *element, *parent_folders;
+ GList *element, *parent_folders_list = NULL;
+ GString *path;
g_return_val_if_fail (GDATA_IS_DOCUMENTS_ENTRY (self), NULL);
- if (self->priv->path != NULL)
- return self->priv->path;
+ path = g_string_new ("/");
+ parent_folders_list = gdata_entry_look_up_links (GDATA_ENTRY (self), "http://schemas.google.com/docs/2007#parent");
+
+ /* We check all the folders contained that are parents of the GDataDocumentsEntry */
+ for (element = parent_folders_list; element != NULL; element = element->next) {
+ guint i;
+ gchar *folder_id = NULL;
+ gchar **link_href_cut = g_strsplit (gdata_link_get_uri (GDATA_LINK (element->data)), "/", 0);
+
+ for (i = 0;; i++) {
+ gchar **path_cut = NULL;
+
+ if (link_href_cut[i] == NULL)
+ break;
+
+ path_cut = g_strsplit (link_href_cut[i], "%3A", 2);
+ if (*path_cut != NULL) {
+ if (strcmp (path_cut[0], "folder") == 0){
+ folder_id = g_strdup (path_cut[1]);
+ g_strfreev (path_cut);
+ break;
+ }
+ }
+ g_strfreev (path_cut);
+ }
+ g_strfreev (link_href_cut);
+ g_assert (folder_id != NULL);
- parent_folders = gdata_entry_look_up_links (GDATA_ENTRY (self), "http://schemas.google.com/docs/2007#parent");
- for (element = parent_folders; element != NULL; element = element->next) {
- if (self->priv->path == NULL)
- self->priv->path = g_strdup (gdata_link_get_title (((GDataLink*) element->data)));
- else
- self->priv->path = g_strconcat (self->priv->path, gdata_link_get_title (((GDataLink*) element->data)), NULL);
+ g_string_append (path, folder_id);
+ g_string_append_c (path, '/');
+ g_free (folder_id);
}
- return self->priv->path;
+ /* Append the document ID */
+ g_string_append (path, self->priv->document_id);
+
+ return g_string_free (path, FALSE);
}
/**
diff --git a/gdata/services/documents/gdata-documents-entry.h b/gdata/services/documents/gdata-documents-entry.h
index 81e64dc..ef97d21 100644
--- a/gdata/services/documents/gdata-documents-entry.h
+++ b/gdata/services/documents/gdata-documents-entry.h
@@ -64,7 +64,7 @@ typedef struct {
GType gdata_documents_entry_get_type (void) G_GNUC_CONST;
-const gchar *gdata_documents_entry_get_path (GDataDocumentsEntry *self);
+gchar *gdata_documents_entry_get_path (GDataDocumentsEntry *self);
const gchar *gdata_documents_entry_get_document_id (GDataDocumentsEntry *self);
diff --git a/gdata/tests/general.c b/gdata/tests/general.c
index 860e8f3..a0787f9 100644
--- a/gdata/tests/general.c
+++ b/gdata/tests/general.c
@@ -31,6 +31,7 @@ test_entry_get_xml (void)
GDataLink *link;
GDataAuthor *author;
gchar *xml;
+ GList *links;
GError *error = NULL;
entry = gdata_entry_new (NULL);
@@ -69,6 +70,12 @@ test_entry_get_xml (void)
gdata_link_set_length (link, 5010);
gdata_entry_add_link (entry, link);
g_object_unref (link);
+ link = gdata_link_new ("http://example.com/", "http://foobar.link");
+ gdata_entry_add_link (entry, link);
+ g_object_unref (link);
+ link = gdata_link_new ("http://example2.com/", "http://foobar.link");
+ gdata_entry_add_link (entry, link);
+ g_object_unref (link);
/* Authors */
author = gdata_author_new ("Joe Bloggs", "http://example.com/", "joe example com");
@@ -92,6 +99,8 @@ test_entry_get_xml (void)
"<category term='Film' scheme='http://gdata.youtube.com/schemas/2007/categories.cat' label='Film & Animation'/>"
"<category term='example' label='Example stuff'/>"
"<category term='test'/>"
+ "<link href='http://example2.com/' rel='http://foobar.link'/>"
+ "<link href='http://example.com/' rel='http://foobar.link'/>"
"<link href='http://test.mn/' title='A treatise on Mongolian test websites & other stuff.' rel='http://www.iana.org/assignments/relation/related' type='text/html' hreflang='mn' length='5010'/>"
"<link href='http://example.com/' rel='http://www.iana.org/assignments/relation/alternate'/>"
"<link href='http://test.com/' rel='http://www.iana.org/assignments/relation/self' type='application/atom+xml'/>"
@@ -121,8 +130,30 @@ test_entry_get_xml (void)
g_assert_cmpuint (published.tv_sec, ==, published2.tv_sec);
g_assert_cmpuint (published.tv_usec, ==, published2.tv_usec);*/
- /* TODO: Check categories, links and authors */
+ /* Check links */
+ link = gdata_entry_look_up_link (entry, GDATA_LINK_SELF);
+ g_assert (link != NULL);
+ g_assert_cmpstr (gdata_link_get_uri (link), ==, "http://test.com/");
+ g_assert_cmpstr (gdata_link_get_relation_type (link), ==, GDATA_LINK_SELF);
+ g_assert_cmpstr (gdata_link_get_content_type (link), ==, "application/atom+xml");
+
+ links = gdata_entry_look_up_links (entry, "http://foobar.link");
+ g_assert (links != NULL);
+ g_assert_cmpint (g_list_length (links), ==, 2);
+
+ link = GDATA_LINK (links->data);
+ g_assert (link != NULL);
+ g_assert_cmpstr (gdata_link_get_uri (link), ==, "http://example2.com/");
+ g_assert_cmpstr (gdata_link_get_relation_type (link), ==, "http://foobar.link");
+
+ link = GDATA_LINK (links->next->data);
+ g_assert (link != NULL);
+ g_assert_cmpstr (gdata_link_get_uri (link), ==, "http://example.com/");
+ g_assert_cmpstr (gdata_link_get_relation_type (link), ==, "http://foobar.link");
+
+ /* TODO: Check categories and authors */
+ g_list_free (links);
g_object_unref (entry);
g_object_unref (entry2);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]