[libgdata] Bug 639610 — Allow access to a contact's photo ETag



commit a23845177803a78b7b4d605c3e8e934924328fea
Author: Philip Withnall <philip tecnocode co uk>
Date:   Tue Mar 22 13:43:02 2011 +0000

    Bug 639610 â?? Allow access to a contact's photo ETag
    
    Deprecate gdata_contacts_contact_has_photo() (and the corresponding property)
    in favour of a new gdata_contacts_contact_get_photo_etag() and property
    which work in exactly the same way, but return the photo's ETag or NULL,
    rather than TRUE or FALSE.
    
    Closes: bgo#639610

 gdata/gdata.symbols                              |    1 +
 gdata/services/contacts/gdata-contacts-contact.c |   43 +++++++++++++++++++++-
 gdata/services/contacts/gdata-contacts-contact.h |    3 +-
 gdata/tests/contacts.c                           |   31 ++++++++--------
 4 files changed, 60 insertions(+), 18 deletions(-)
---
diff --git a/gdata/gdata.symbols b/gdata/gdata.symbols
index 93c683b..fa30c7d 100644
--- a/gdata/gdata.symbols
+++ b/gdata/gdata.symbols
@@ -300,6 +300,7 @@ gdata_contacts_contact_is_group_deleted
 gdata_contacts_contact_get_groups
 gdata_contacts_contact_is_deleted
 gdata_contacts_contact_has_photo
+gdata_contacts_contact_get_photo_etag
 gdata_contacts_contact_get_photo
 gdata_contacts_contact_set_photo
 gdata_access_handler_get_type
diff --git a/gdata/services/contacts/gdata-contacts-contact.c b/gdata/services/contacts/gdata-contacts-contact.c
index bedb2c8..093b5d6 100644
--- a/gdata/services/contacts/gdata-contacts-contact.c
+++ b/gdata/services/contacts/gdata-contacts-contact.c
@@ -229,7 +229,8 @@ enum {
 	PROP_PRIORITY,
 	PROP_SENSITIVITY,
 	PROP_SHORT_NAME,
-	PROP_SUBJECT
+	PROP_SUBJECT,
+	PROP_PHOTO_ETAG
 };
 
 G_DEFINE_TYPE (GDataContactsContact, gdata_contacts_contact, GDATA_TYPE_ENTRY)
@@ -291,11 +292,26 @@ gdata_contacts_contact_class_init (GDataContactsContactClass *klass)
 	 * Whether the contact has a photo.
 	 *
 	 * Since: 0.4.0
+	 * Deprecated: 0.9.0: Use #GDataContactsContact:photo-etag and gdata_contacts_contact_get_photo_etag() instead. It is %NULL exactly when this
+	 * would've been %FALSE.
 	 **/
 	g_object_class_install_property (gobject_class, PROP_HAS_PHOTO,
 	                                 g_param_spec_boolean ("has-photo",
 	                                                       "Has photo?", "Whether the contact has a photo.",
 	                                                       FALSE,
+	                                                       G_PARAM_READABLE | G_PARAM_STATIC_STRINGS | G_PARAM_DEPRECATED));
+
+	/**
+	 * GDataContactsContact:photo-etag:
+	 *
+	 * The ETag of the contact's photo, if the contact has a photo; %NULL otherwise.
+	 *
+	 * Since: 0.9.0
+	 **/
+	g_object_class_install_property (gobject_class, PROP_PHOTO_ETAG,
+	                                 g_param_spec_string ("photo-etag",
+	                                                       "Photo ETag", "The ETag of the contact's photo.",
+	                                                       NULL,
 	                                                       G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
 
 	/**
@@ -652,6 +668,9 @@ gdata_contacts_contact_get_property (GObject *object, guint property_id, GValue
 		case PROP_HAS_PHOTO:
 			g_value_set_boolean (value, (priv->photo_etag != NULL) ? TRUE : FALSE);
 			break;
+		case PROP_PHOTO_ETAG:
+			g_value_set_string (value, priv->photo_etag);
+			break;
 		case PROP_NAME:
 			g_value_set_object (value, priv->name);
 			break;
@@ -3021,6 +3040,7 @@ gdata_contacts_contact_is_deleted (GDataContactsContact *self)
  * does have a photo, it can be returned using gdata_contacts_contact_get_photo().
  *
  * Return value: %TRUE if the contact has a photo, %FALSE otherwise
+ * Deprecated: 0.9.0: Use gdata_contacts_contact_get_photo_etag() instead; it returns %NULL exactly when this function would've returned %FALSE.
  *
  * Since: 0.4.0
  **/
@@ -3032,6 +3052,25 @@ gdata_contacts_contact_has_photo (GDataContactsContact *self)
 }
 
 /**
+ * gdata_contacts_contact_get_photo_etag:
+ * @self: a #GDataContactsContact
+ *
+ * Returns the ETag for the contact's attached photo, if it exists. If it does exist, the contact's photo can be retrieved using
+ * gdata_contacts_contact_get_photo(). If it doesn't exist, %NULL will be returned, and the contact doesn't have a photo (so calling
+ * gdata_contacts_contact_get_photo() will also return %NULL)
+ *
+ * Return value: the contact's photo's ETag if it exists, %NULL otherwise
+ *
+ * Since: 0.9.0
+ **/
+const gchar *
+gdata_contacts_contact_get_photo_etag (GDataContactsContact *self)
+{
+	g_return_val_if_fail (GDATA_IS_CONTACTS_CONTACT (self), NULL);
+	return self->priv->photo_etag;
+}
+
+/**
  * gdata_contacts_contact_get_photo:
  * @self: a #GDataContactsContact
  * @service: a #GDataContactsService
@@ -3069,7 +3108,7 @@ gdata_contacts_contact_get_photo (GDataContactsContact *self, GDataContactsServi
 	g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
 	/* Return if there is no photo */
-	if (gdata_contacts_contact_has_photo (self) == FALSE)
+	if (gdata_contacts_contact_get_photo_etag (self) == NULL)
 		return NULL;
 
 	/* Get the photo URI */
diff --git a/gdata/services/contacts/gdata-contacts-contact.h b/gdata/services/contacts/gdata-contacts-contact.h
index 5b6b3a7..768a77b 100644
--- a/gdata/services/contacts/gdata-contacts-contact.h
+++ b/gdata/services/contacts/gdata-contacts-contact.h
@@ -277,7 +277,8 @@ GList *gdata_contacts_contact_get_groups (GDataContactsContact *self) G_GNUC_WAR
 
 #include <gdata/services/contacts/gdata-contacts-service.h>
 
-gboolean gdata_contacts_contact_has_photo (GDataContactsContact *self) G_GNUC_PURE;
+gboolean gdata_contacts_contact_has_photo (GDataContactsContact *self) G_GNUC_PURE G_GNUC_DEPRECATED_FOR(gdata_contacts_contact_get_photo_etag);
+const gchar *gdata_contacts_contact_get_photo_etag (GDataContactsContact *self) G_GNUC_PURE;
 
 guint8 *gdata_contacts_contact_get_photo (GDataContactsContact *self, GDataContactsService *service, gsize *length, gchar **content_type,
                                           GCancellable *cancellable, GError **error) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
diff --git a/gdata/tests/contacts.c b/gdata/tests/contacts.c
index e22184f..732443f 100644
--- a/gdata/tests/contacts.c
+++ b/gdata/tests/contacts.c
@@ -163,13 +163,13 @@ test_insert_simple (gconstpointer service)
 	GDataGContactExternalID *external_id;
 	GDataGContactLanguage *language;
 	gchar *nickname, *billing_information, *directory_server, *gender, *initials, *maiden_name, *mileage, *occupation;
-	gchar *priority, *sensitivity, *short_name, *subject;
+	gchar *priority, *sensitivity, *short_name, *subject, *photo_etag;
 	GList *list;
 	GDate date, *date2;
 	GHashTable *properties;
 	GTimeVal current_time;
 	gint64 edited, creation_time;
-	gboolean deleted, has_photo, birthday_has_year;
+	gboolean deleted, birthday_has_year;
 	GError *error = NULL;
 
 	contact = gdata_contacts_contact_new (NULL);
@@ -281,7 +281,7 @@ test_insert_simple (gconstpointer service)
 	g_object_get (G_OBJECT (contact),
 	              "edited", &edited,
 	              "deleted", &deleted,
-	              "has-photo", &has_photo,
+	              "photo-etag", &photo_etag,
 	              "name", &name,
 	              "nickname", &nickname,
 	              "birthday", &date2,
@@ -301,7 +301,7 @@ test_insert_simple (gconstpointer service)
 
 	g_assert_cmpint (edited, ==, current_time.tv_sec);
 	g_assert (deleted == FALSE);
-	g_assert (has_photo == FALSE);
+	g_assert (photo_etag == NULL);
 	g_assert (name2 == name);
 	g_assert_cmpstr (nickname, ==, "Big J");
 	g_assert (g_date_valid (date2) == TRUE);
@@ -334,6 +334,7 @@ test_insert_simple (gconstpointer service)
 	g_free (sensitivity);
 	g_free (short_name);
 	g_free (subject);
+	g_free (photo_etag);
 
 	/* Check the XML */
 	gdata_test_assert_xml (contact,
@@ -1524,7 +1525,7 @@ test_photo_has_photo (gconstpointer service)
 	g_clear_error (&error);
 
 	/* Check for no photo */
-	g_assert (gdata_contacts_contact_has_photo (contact) == FALSE);
+	g_assert (gdata_contacts_contact_get_photo_etag (contact) == NULL);
 	g_assert (gdata_contacts_contact_get_photo (contact, GDATA_CONTACTS_SERVICE (service), &length, &content_type, NULL, &error) == NULL);
 	g_assert_cmpint (length, ==, 0);
 	g_assert (content_type == NULL);
@@ -1551,7 +1552,7 @@ test_photo_has_photo (gconstpointer service)
 	check_kind (GDATA_ENTRY (contact), "http://schemas.google.com/contact/2008#contact";);
 	g_clear_error (&error);
 
-	g_assert (gdata_contacts_contact_has_photo (contact) == TRUE);
+	g_assert (gdata_contacts_contact_get_photo_etag (contact) != NULL);
 	g_object_unref (contact);
 }
 
@@ -1588,7 +1589,7 @@ test_photo_add_async_cb (GDataContactsContact *contact, GAsyncResult *result, GM
 	g_assert_no_error (error);
 	g_assert (success == TRUE);
 
-	g_assert (gdata_contacts_contact_has_photo (contact) == TRUE);
+	g_assert (gdata_contacts_contact_get_photo_etag (contact) != NULL);
 
 	g_main_loop_quit (main_loop);
 }
@@ -1627,7 +1628,7 @@ test_photo_get (gconstpointer service)
 	GError *error = NULL;
 
 	contact = get_contact (service);
-	g_assert (gdata_contacts_contact_has_photo (contact) == TRUE);
+	g_assert (gdata_contacts_contact_get_photo_etag (contact) != NULL);
 
 	/* Get the photo from the network */
 	data = gdata_contacts_contact_get_photo (contact, GDATA_CONTACTS_SERVICE (service), &length, &content_type, NULL, &error);
@@ -1636,7 +1637,7 @@ test_photo_get (gconstpointer service)
 	g_assert (length != 0);
 	g_assert_cmpstr (content_type, ==, "image/jpeg");
 
-	g_assert (gdata_contacts_contact_has_photo (contact) == TRUE);
+	g_assert (gdata_contacts_contact_get_photo_etag (contact) != NULL);
 
 	g_free (content_type);
 	g_free (data);
@@ -1659,7 +1660,7 @@ test_photo_get_async_cb (GDataContactsContact *contact, GAsyncResult *result, GM
 	g_assert (length != 0);
 	g_assert_cmpstr (content_type, ==, "image/jpeg");
 
-	g_assert (gdata_contacts_contact_has_photo (contact) == TRUE);
+	g_assert (gdata_contacts_contact_get_photo_etag (contact) != NULL);
 
 	g_main_loop_quit (main_loop);
 
@@ -1674,7 +1675,7 @@ test_photo_get_async (gconstpointer service)
 	GMainLoop *main_loop;
 
 	contact = get_contact (service);
-	g_assert (gdata_contacts_contact_has_photo (contact) == TRUE);
+	g_assert (gdata_contacts_contact_get_photo_etag (contact) != NULL);
 
 	main_loop = g_main_loop_new (NULL, TRUE);
 
@@ -1694,13 +1695,13 @@ test_photo_delete (gconstpointer service)
 	GError *error = NULL;
 
 	contact = get_contact (service);
-	g_assert (gdata_contacts_contact_has_photo (contact) == TRUE);
+	g_assert (gdata_contacts_contact_get_photo_etag (contact) != NULL);
 
 	/* Remove the contact's photo */
 	g_assert (gdata_contacts_contact_set_photo (contact, GDATA_CONTACTS_SERVICE (service), NULL, 0, NULL, NULL, &error) == TRUE);
 	g_assert_no_error (error);
 
-	g_assert (gdata_contacts_contact_has_photo (contact) == FALSE);
+	g_assert (gdata_contacts_contact_get_photo_etag (contact) == NULL);
 
 	g_clear_error (&error);
 	g_object_unref (contact);
@@ -1716,7 +1717,7 @@ test_photo_delete_async_cb (GDataContactsContact *contact, GAsyncResult *result,
 	g_assert_no_error (error);
 	g_assert (success == TRUE);
 
-	g_assert (gdata_contacts_contact_has_photo (contact) == FALSE);
+	g_assert (gdata_contacts_contact_get_photo_etag (contact) == NULL);
 
 	g_main_loop_quit (main_loop);
 }
@@ -1730,7 +1731,7 @@ test_photo_delete_async (gconstpointer service)
 	contact = get_contact (service);
 	main_loop = g_main_loop_new (NULL, TRUE);
 
-	g_assert (gdata_contacts_contact_has_photo (contact) == TRUE);
+	g_assert (gdata_contacts_contact_get_photo_etag (contact) != NULL);
 
 	/* Delete it from the contact asynchronously */
 	gdata_contacts_contact_set_photo_async (contact, GDATA_CONTACTS_SERVICE (service), NULL, 0, NULL, NULL,



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