[libgdata] core: Add gdata_entry_remove_link() to allow removing links from entries
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgdata] core: Add gdata_entry_remove_link() to allow removing links from entries
- Date: Sat, 9 Jul 2011 19:02:48 +0000 (UTC)
commit 4554cc0490460d2c9f62bced9287bdb721447f76
Author: Philip Withnall <philip tecnocode co uk>
Date: Sat Jul 9 14:51:51 2011 +0100
core: Add gdata_entry_remove_link() to allow removing links from entries
This adds the following API:
â gdata_entry_remove_link()
docs/reference/gdata-sections.txt | 1 +
gdata/gdata-entry.c | 32 ++++++++++++++++++++++++++++
gdata/gdata-entry.h | 1 +
gdata/gdata.symbols | 1 +
gdata/tests/general.c | 41 +++++++++++++++++++++++++++++++++++++
5 files changed, 76 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gdata-sections.txt b/docs/reference/gdata-sections.txt
index 84db5bc..fda5a7b 100644
--- a/docs/reference/gdata-sections.txt
+++ b/docs/reference/gdata-sections.txt
@@ -150,6 +150,7 @@ gdata_entry_add_author
gdata_entry_add_category
gdata_entry_get_categories
gdata_entry_add_link
+gdata_entry_remove_link
gdata_entry_look_up_link
gdata_entry_look_up_links
gdata_entry_is_inserted
diff --git a/gdata/gdata-entry.c b/gdata/gdata-entry.c
index f38382d..7ae9702 100644
--- a/gdata/gdata-entry.c
+++ b/gdata/gdata-entry.c
@@ -930,6 +930,38 @@ gdata_entry_add_link (GDataEntry *self, GDataLink *_link)
self->priv->links = g_list_prepend (self->priv->links, g_object_ref (_link));
}
+/**
+ * gdata_entry_remove_link:
+ * @self: a #GDataEntry
+ * @_link: a #GDataLink to remove
+ *
+ * Removes @_link from the list of links in the given #GDataEntry and decrements its reference count (since the #GDataEntry held a reference to it
+ * while it was in the list).
+ *
+ * Return value: %TRUE if @_link was found in the #GDataEntry and removed, %FALSE if it was not found
+ *
+ * Since: 0.9.2
+ */
+gboolean
+gdata_entry_remove_link (GDataEntry *self, GDataLink *_link)
+{
+ GList *i;
+
+ g_return_val_if_fail (GDATA_IS_ENTRY (self), FALSE);
+ g_return_val_if_fail (GDATA_IS_LINK (_link), FALSE);
+
+ i = g_list_find_custom (self->priv->links, _link, (GCompareFunc) gdata_comparable_compare);
+
+ if (i == NULL) {
+ return FALSE;
+ }
+
+ self->priv->links = g_list_delete_link (self->priv->links, i);
+ g_object_unref (_link);
+
+ return TRUE;
+}
+
static gint
link_compare_cb (const GDataLink *_link, const gchar *rel)
{
diff --git a/gdata/gdata-entry.h b/gdata/gdata-entry.h
index b0d83bb..92478cb 100644
--- a/gdata/gdata-entry.h
+++ b/gdata/gdata-entry.h
@@ -84,6 +84,7 @@ void gdata_entry_set_content (GDataEntry *self, const gchar *content);
const gchar *gdata_entry_get_content_uri (GDataEntry *self) G_GNUC_PURE;
void gdata_entry_set_content_uri (GDataEntry *self, const gchar *content_uri);
void gdata_entry_add_link (GDataEntry *self, GDataLink *_link);
+gboolean gdata_entry_remove_link (GDataEntry *self, GDataLink *_link);
GDataLink *gdata_entry_look_up_link (GDataEntry *self, const gchar *rel) G_GNUC_PURE;
GList *gdata_entry_look_up_links (GDataEntry *self, const gchar *rel) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
void gdata_entry_add_author (GDataEntry *self, GDataAuthor *author);
diff --git a/gdata/gdata.symbols b/gdata/gdata.symbols
index cf4ac9c..c84a339 100644
--- a/gdata/gdata.symbols
+++ b/gdata/gdata.symbols
@@ -18,6 +18,7 @@ gdata_entry_set_content
gdata_entry_get_content_uri
gdata_entry_set_content_uri
gdata_entry_add_link
+gdata_entry_remove_link
gdata_entry_look_up_link
gdata_entry_look_up_links
gdata_entry_add_author
diff --git a/gdata/tests/general.c b/gdata/tests/general.c
index 377c0fe..4fe2b01 100644
--- a/gdata/tests/general.c
+++ b/gdata/tests/general.c
@@ -579,6 +579,46 @@ test_entry_escaping (void)
}
static void
+test_entry_links_remove (void)
+{
+ GDataEntry *entry;
+ GDataLink *link_, *link2_;
+ GError *error = NULL;
+
+ /* Since we can't construct a GDataEntry directly, we need to parse it from XML. */
+ entry = GDATA_ENTRY (gdata_parsable_new_from_xml (GDATA_TYPE_ENTRY,
+ "<?xml version='1.0' encoding='UTF-8'?>"
+ "<entry xmlns='http://www.w3.org/2005/Atom'>"
+ "<title type='text'>Escaped content & stuff</title>"
+ "<id>http://foo.com/?foo&bar</id>"
+ "<updated>2010-12-10T17:21:24Z</updated>"
+ "<published>2010-12-10T17:21:24Z</published>"
+ "<summary type='text'>Summary & stuff</summary>"
+ "<rights>Free & open source</rights>"
+ "<content type='text'>Content & things.</content>"
+ "</entry>", -1, &error));
+ g_assert_no_error (error);
+ g_assert (GDATA_IS_ENTRY (entry));
+
+ link_ = gdata_link_new ("http://example.com/", GDATA_LINK_RELATED);
+
+ /* Add a link. */
+ gdata_entry_add_link (entry, link_);
+ g_assert (gdata_entry_look_up_link (entry, GDATA_LINK_RELATED) == link_);
+
+ /* Remove the link. */
+ g_assert (gdata_entry_remove_link (entry, link_) == TRUE);
+ g_assert (gdata_entry_look_up_link (entry, GDATA_LINK_RELATED) == NULL);
+
+ /* Attempt to remove a non-existent link. */
+ link2_ = gdata_link_new ("http://foobar.com/", GDATA_LINK_SELF);
+ g_assert (gdata_entry_remove_link (entry, link2_) == FALSE);
+
+ g_object_unref (link2_);
+ g_object_unref (link_);
+}
+
+static void
test_feed_parse_xml (void)
{
GDataFeed *feed;
@@ -3639,6 +3679,7 @@ main (int argc, char *argv[])
g_test_add_func ("/entry/parse_xml", test_entry_parse_xml);
g_test_add_func ("/entry/error_handling", test_entry_error_handling);
g_test_add_func ("/entry/escaping", test_entry_escaping);
+ g_test_add_func ("/entry/links/remove", test_entry_links_remove);
g_test_add_func ("/feed/parse_xml", test_feed_parse_xml);
g_test_add_func ("/feed/error_handling", test_feed_error_handling);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]