[libgdata] Bug 589855 – Obsolete <rights> not handled in GDataPicasaWebAlbum parse_xml()
- From: Philip Withnall <pwithnall src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libgdata] Bug 589855 – Obsolete <rights> not handled in GDataPicasaWebAlbum parse_xml()
- Date: Sun, 2 Aug 2009 16:10:02 +0000 (UTC)
commit c04a3fa92d193c2ae1cd68174129dfb3bb56f2be
Author: Philip Withnall <philip tecnocode co uk>
Date: Sun Aug 2 17:08:42 2009 +0100
Bug 589855 â?? Obsolete <rights> not handled in GDataPicasaWebAlbum parse_xml()
Changes based on a patch from Richard Schwarting <aquarichy gmail com> to
handle the Atom <rights> element in GDataEntry. Closes: bgo#589855
docs/reference/gdata-sections.txt | 2 +
gdata/gdata-entry.c | 72 +++++++++++++++++++++-
gdata/gdata-entry.h | 2 +
gdata/gdata.symbols | 2 +
gdata/services/picasaweb/gdata-picasaweb-album.c | 63 +++++++++++++++++--
gdata/tests/picasaweb.c | 27 ++++++++
6 files changed, 160 insertions(+), 8 deletions(-)
---
diff --git a/docs/reference/gdata-sections.txt b/docs/reference/gdata-sections.txt
index fa49db7..3a0f518 100644
--- a/docs/reference/gdata-sections.txt
+++ b/docs/reference/gdata-sections.txt
@@ -149,6 +149,8 @@ gdata_entry_add_link
gdata_entry_look_up_link
gdata_entry_look_up_links
gdata_entry_is_inserted
+gdata_entry_get_rights
+gdata_entry_set_rights
<SUBSECTION Standard>
gdata_entry_get_type
GDATA_ENTRY
diff --git a/gdata/gdata-entry.c b/gdata/gdata-entry.c
index 7a2f7d4..d996af3 100644
--- a/gdata/gdata-entry.c
+++ b/gdata/gdata-entry.c
@@ -64,6 +64,7 @@ struct _GDataEntryPrivate {
gchar *content;
GList *links; /* GDataLink */
GList *authors; /* GDataAuthor */
+ gchar *rights;
};
enum {
@@ -74,7 +75,8 @@ enum {
PROP_UPDATED,
PROP_PUBLISHED,
PROP_CONTENT,
- PROP_IS_INSERTED
+ PROP_IS_INSERTED,
+ PROP_RIGHTS
};
G_DEFINE_TYPE (GDataEntry, gdata_entry, GDATA_TYPE_PARSABLE)
@@ -154,6 +156,21 @@ gdata_entry_class_init (GDataEntryClass *klass)
"Inserted?", "Whether the entry has been inserted on the server.",
FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+ /**
+ * GDataEntry:rights:
+ *
+ * The ownership rights pertaining to this entry.
+ *
+ * For more information, see the <ulink type="http://www.atomenabled.org/developers/syndication/atom-format-spec.php#element.rights">
+ * Atom specification</ulink>.
+ *
+ * Since: 0.5.0
+ **/
+ g_object_class_install_property (gobject_class, PROP_RIGHTS,
+ g_param_spec_string ("rights",
+ "Rights", "Rights pertaining to the entry.",
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
}
static void
@@ -198,6 +215,7 @@ gdata_entry_finalize (GObject *object)
g_free (priv->summary);
xmlFree (priv->id);
xmlFree (priv->etag);
+ g_free (priv->rights);
g_free (priv->content);
/* Chain up to the parent class */
@@ -234,6 +252,9 @@ gdata_entry_get_property (GObject *object, guint property_id, GValue *value, GPa
case PROP_IS_INSERTED:
g_value_set_boolean (value, gdata_entry_is_inserted (GDATA_ENTRY (object)));
break;
+ case PROP_RIGHTS:
+ g_value_set_string (value, priv->rights);
+ break;
default:
/* We don't have any other property... */
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -264,6 +285,9 @@ gdata_entry_set_property (GObject *object, guint property_id, const GValue *valu
case PROP_CONTENT:
gdata_entry_set_content (self, g_value_get_string (value));
break;
+ case PROP_RIGHTS:
+ gdata_entry_set_rights (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);
@@ -366,6 +390,11 @@ parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_da
xmlChar *summary = xmlNodeListGetString (doc, node->children, TRUE);
gdata_entry_set_summary (self, (gchar*) summary);
xmlFree (summary);
+ } else if (xmlStrcmp (node->name, (xmlChar*) "rights") == 0) {
+ /* atom:rights */
+ xmlChar *rights = xmlNodeListGetString (doc, node->children, TRUE);
+ gdata_entry_set_rights (self, (gchar*) rights);
+ xmlFree (rights);
} else if (GDATA_PARSABLE_CLASS (gdata_entry_parent_class)->parse_xml (parsable, doc, node, user_data, error) == FALSE) {
/* Error! */
return FALSE;
@@ -438,6 +467,12 @@ get_xml (GDataParsable *parsable, GString *xml_string)
g_free (summary);
}
+ if (priv->rights != NULL) {
+ gchar *rights = g_markup_escape_text (priv->rights, -1);
+ g_string_append_printf (xml_string, "<rights>%s</rights>", rights);
+ g_free (rights);
+ }
+
if (priv->content != NULL) {
gchar *content = g_markup_escape_text (priv->content, -1);
g_string_append_printf (xml_string, "<content type='text'>%s</content>", content);
@@ -795,3 +830,38 @@ gdata_entry_is_inserted (GDataEntry *self)
return TRUE;
return FALSE;
}
+
+/**
+ * gdata_entry_get_rights:
+ * @self: a #GDataEntry
+ *
+ * Returns the rights pertaining to the entry, or %NULL if not set.
+ *
+ * Return value: the entry's rights information
+ *
+ * Since: 0.5.0
+ **/
+const gchar *
+gdata_entry_get_rights (GDataEntry *self)
+{
+ g_return_val_if_fail (GDATA_IS_ENTRY (self), NULL);
+ return self->priv->rights;
+}
+
+/**
+ * gdata_entry_set_rights:
+ * @self: a #GDataEntry
+ * @rights: the new rights, or %NULL
+ *
+ * Sets the rights for this entry.
+ *
+ * Since: 0.5.0
+ **/
+void
+gdata_entry_set_rights (GDataEntry *self, const gchar *rights)
+{
+ g_return_if_fail (GDATA_IS_ENTRY (self));
+ g_free (self->priv->rights);
+ self->priv->rights = g_strdup (rights);
+ g_object_notify (G_OBJECT (self), "rights");
+}
diff --git a/gdata/gdata-entry.h b/gdata/gdata-entry.h
index b21e8c0..9a683f9 100644
--- a/gdata/gdata-entry.h
+++ b/gdata/gdata-entry.h
@@ -79,6 +79,8 @@ void gdata_entry_add_link (GDataEntry *self, GDataLink *link);
GDataLink *gdata_entry_look_up_link (GDataEntry *self, const gchar *rel);
GList *gdata_entry_look_up_links (GDataEntry *self, const gchar *rel);
void gdata_entry_add_author (GDataEntry *self, GDataAuthor *author);
+const gchar *gdata_entry_get_rights (GDataEntry *self);
+void gdata_entry_set_rights (GDataEntry *self, const gchar *rights);
gboolean gdata_entry_is_inserted (GDataEntry *self);
diff --git a/gdata/gdata.symbols b/gdata/gdata.symbols
index 7e3fae1..d197e05 100644
--- a/gdata/gdata.symbols
+++ b/gdata/gdata.symbols
@@ -20,6 +20,8 @@ gdata_entry_look_up_link
gdata_entry_look_up_links
gdata_entry_add_author
gdata_entry_is_inserted
+gdata_entry_get_rights
+gdata_entry_set_rights
gdata_feed_get_type
gdata_feed_get_entries
gdata_feed_look_up_entry
diff --git a/gdata/services/picasaweb/gdata-picasaweb-album.c b/gdata/services/picasaweb/gdata-picasaweb-album.c
index 643d972..5289b5f 100644
--- a/gdata/services/picasaweb/gdata-picasaweb-album.c
+++ b/gdata/services/picasaweb/gdata-picasaweb-album.c
@@ -200,7 +200,6 @@ gdata_picasaweb_album_class_init (GDataPicasaWebAlbumClass *klass)
*
* Since: 0.4.0
**/
- /* TODO: atom:rights duplicates this? */
g_object_class_install_property (gobject_class, PROP_VISIBILITY,
g_param_spec_enum ("visibility",
"Visibility", "The visibility (or access rights) of the album.",
@@ -346,6 +345,48 @@ notify_title_cb (GDataPicasaWebAlbum *self, GParamSpec *pspec, gpointer user_dat
gdata_media_group_set_title (self->priv->media_group, gdata_entry_get_title (GDATA_ENTRY (self)));
}
+static void notify_visibility_cb (GDataPicasaWebAlbum *self, GParamSpec *pspec, gpointer user_data);
+
+static void
+notify_rights_cb (GDataPicasaWebAlbum *self, GParamSpec *pspec, gpointer user_data)
+{
+ const gchar *rights = gdata_entry_get_rights (GDATA_ENTRY (self));
+
+ /* Update our gphoto:visibility */
+ g_signal_handlers_block_by_func (self, notify_visibility_cb, NULL);
+
+ if (rights == NULL || strcmp (rights, "public") == 0) {
+ gdata_picasaweb_album_set_visibility (self, GDATA_PICASAWEB_PUBLIC);
+ } else if (strcmp (rights, "private") == 0) {
+ gdata_picasaweb_album_set_visibility (self, GDATA_PICASAWEB_PRIVATE);
+ } else {
+ /* Print out a warning and leave the visibility as it is */
+ g_warning ("Unknown <rights> or <gd:access> value: %s", rights);
+ }
+
+ g_signal_handlers_unblock_by_func (self, notify_visibility_cb, NULL);
+}
+
+static void
+notify_visibility_cb (GDataPicasaWebAlbum *self, GParamSpec *pspec, gpointer user_data)
+{
+ /* Update our GDataEntry's atom:rights */
+ g_signal_handlers_block_by_func (self, notify_rights_cb, NULL);
+
+ switch (self->priv->visibility) {
+ case GDATA_PICASAWEB_PUBLIC:
+ gdata_entry_set_rights (GDATA_ENTRY (self), "public");
+ break;
+ case GDATA_PICASAWEB_PRIVATE:
+ gdata_entry_set_rights (GDATA_ENTRY (self), "private");
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+
+ g_signal_handlers_unblock_by_func (self, notify_rights_cb, NULL);
+}
+
static void
gdata_picasaweb_album_init (GDataPicasaWebAlbum *self)
{
@@ -354,6 +395,10 @@ gdata_picasaweb_album_init (GDataPicasaWebAlbum *self)
/* Connect to the notify::title signal from GDataEntry so our media:group title can be kept in sync */
g_signal_connect (GDATA_ENTRY (self), "notify::title", G_CALLBACK (notify_title_cb), NULL);
+ /* Connect to the notify::rights signal from GDataEntry so our gphoto:visibility can be kept in sync */
+ g_signal_connect (GDATA_ENTRY (self), "notify::rights", G_CALLBACK (notify_rights_cb), NULL);
+ /* Connect to the notify::visibility signal so our rights can be kept in sync */
+ g_signal_connect (self, "notify::visibility", G_CALLBACK (notify_visibility_cb), NULL);
}
static void
@@ -615,12 +660,16 @@ get_xml (GDataParsable *parsable, GString *xml_string)
g_free (location);
}
- if (priv->visibility == GDATA_PICASAWEB_PUBLIC)
- g_string_append (xml_string, "<gphoto:access>public</gphoto:access>");
- else if (priv->visibility == GDATA_PICASAWEB_PRIVATE)
- g_string_append (xml_string, "<gphoto:access>private</gphoto:access>");
- else
- g_assert_not_reached ();
+ switch (priv->visibility) {
+ case GDATA_PICASAWEB_PUBLIC:
+ g_string_append (xml_string, "<gphoto:access>public</gphoto:access>");
+ break;
+ case GDATA_PICASAWEB_PRIVATE:
+ g_string_append (xml_string, "<gphoto:access>private</gphoto:access>");
+ break;
+ default:
+ g_assert_not_reached ();
+ }
if (priv->timestamp.tv_sec != 0 || priv->timestamp.tv_usec != 0) {
/* in milliseconds */
diff --git a/gdata/tests/picasaweb.c b/gdata/tests/picasaweb.c
index f09ded5..51e5853 100644
--- a/gdata/tests/picasaweb.c
+++ b/gdata/tests/picasaweb.c
@@ -362,6 +362,7 @@ test_album (GDataService *service)
GList *albums;
GTimeVal _time;
gchar *str;
+ gchar *original_rights;
album_feed = gdata_picasaweb_service_query_all_albums (GDATA_PICASAWEB_SERVICE (service), NULL, NULL, NULL, NULL, NULL, &error);
g_assert_no_error (error);
@@ -394,6 +395,30 @@ test_album (GDataService *service)
g_assert_cmpuint (gdata_picasaweb_album_get_num_photos (album), ==, 1);
g_assert_cmpuint (gdata_picasaweb_album_get_num_photos_remaining (album), ==, 499);
g_assert_cmpuint (gdata_picasaweb_album_get_bytes_used (album), ==, 1124730);
+
+ /* Test visibility and its synchronisation with its GDataEntry's rights */
+ original_rights = g_strdup (gdata_entry_get_rights (GDATA_ENTRY (album)));
+
+ gdata_entry_set_rights (GDATA_ENTRY (album), "private");
+ g_assert_cmpstr (gdata_entry_get_rights (GDATA_ENTRY (album)), ==, "private");
+ g_assert_cmpint (gdata_picasaweb_album_get_visibility (album), ==, GDATA_PICASAWEB_PRIVATE);
+
+ gdata_entry_set_rights (GDATA_ENTRY (album), "public");
+ g_assert_cmpstr (gdata_entry_get_rights (GDATA_ENTRY (album)), ==, "public");
+ g_assert_cmpint (gdata_picasaweb_album_get_visibility (album), ==, GDATA_PICASAWEB_PUBLIC);
+
+ gdata_picasaweb_album_set_visibility (album, GDATA_PICASAWEB_PRIVATE);
+ g_assert_cmpstr (gdata_entry_get_rights (GDATA_ENTRY (album)), ==, "private");
+ g_assert_cmpint (gdata_picasaweb_album_get_visibility (album), ==, GDATA_PICASAWEB_PRIVATE);
+
+ gdata_picasaweb_album_set_visibility (album, GDATA_PICASAWEB_PUBLIC);
+ g_assert_cmpstr (gdata_entry_get_rights (GDATA_ENTRY (album)), ==, "public");
+ g_assert_cmpint (gdata_picasaweb_album_get_visibility (album), ==, GDATA_PICASAWEB_PUBLIC);
+
+ gdata_entry_set_rights (GDATA_ENTRY (album), original_rights);
+ g_free (original_rights);
+
+ g_object_unref (album_feed);
}
static void
@@ -424,6 +449,7 @@ test_album_feed_entry (GDataService *service)
g_assert_cmpstr (gdata_entry_get_title (entry), ==, "Test Album 1 - Venice - Public");
g_assert_cmpstr (gdata_entry_get_id (entry), ==, "5328889949261497249");
g_assert_cmpstr (gdata_entry_get_etag (entry), !=, NULL);
+ g_assert_cmpstr (gdata_entry_get_rights (entry), ==, "public");
gdata_entry_get_updated (entry, &_time);
str = g_time_val_to_iso8601 (&_time);
@@ -531,6 +557,7 @@ test_query_all_albums_async (GDataService *service)
}
/* TODO: test private, public albums, test uploading */
+/* TODO: add queries to update albums, files on the server; test those */
int
main (int argc, char *argv[])
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]