[gthumb] [flicker] added list_photos support to the flickr service
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] [flicker] added list_photos support to the flickr service
- Date: Sat, 3 Apr 2010 20:44:55 +0000 (UTC)
commit cd59c49d2ca7ec0e05847199ea14d3bee9fee3b5
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sat Apr 3 22:21:41 2010 +0200
[flicker] added list_photos support to the flickr service
extensions/flicker/flickr-photo.c | 252 +++++++++++++++++++++++++++++++++++
extensions/flicker/flickr-photo.h | 92 +++++++++++++
extensions/flicker/flickr-service.c | 96 +++++++------
extensions/flicker/flickr-service.h | 5 +-
4 files changed, 398 insertions(+), 47 deletions(-)
---
diff --git a/extensions/flicker/flickr-photo.c b/extensions/flicker/flickr-photo.c
new file mode 100644
index 0000000..6e79100
--- /dev/null
+++ b/extensions/flicker/flickr-photo.c
@@ -0,0 +1,252 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * GThumb
+ *
+ * Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+#include <stdlib.h>
+#include <string.h>
+#include <gthumb.h>
+#include "flickr-photo.h"
+
+
+static gpointer flickr_photo_parent_class = NULL;
+
+
+static void
+flickr_photo_finalize (GObject *obj)
+{
+ FlickrPhoto *self;
+
+ self = FLICKR_PHOTO (obj);
+
+ g_free (self->id);
+ g_free (self->secret);
+ g_free (self->server);
+ g_free (self->title);
+
+ G_OBJECT_CLASS (flickr_photo_parent_class)->finalize (obj);
+}
+
+
+static void
+flickr_photo_class_init (FlickrPhotoClass *klass)
+{
+ flickr_photo_parent_class = g_type_class_peek_parent (klass);
+ G_OBJECT_CLASS (klass)->finalize = flickr_photo_finalize;
+}
+
+
+static DomElement*
+flickr_photo_create_element (DomDomizable *base,
+ DomDocument *doc)
+{
+ FlickrPhoto *self;
+ DomElement *element;
+
+ self = FLICKR_PHOTO (base);
+
+ element = dom_document_create_element (doc, "photo", NULL);
+ if (self->id != NULL)
+ dom_element_set_attribute (element, "id", self->id);
+ if (self->secret != NULL)
+ dom_element_set_attribute (element, "secret", self->secret);
+ if (self->server != NULL)
+ dom_element_set_attribute (element, "server", self->server);
+ if (self->title != NULL)
+ dom_element_set_attribute (element, "title", self->title);
+ if (self->is_primary)
+ dom_element_set_attribute (element, "isprimary", "1");
+
+ return element;
+}
+
+
+static void
+flickr_photo_load_from_element (DomDomizable *base,
+ DomElement *element)
+{
+ FlickrPhoto *self;
+
+ if ((element == NULL) || (g_strcmp0 (element->tag_name, "photo") != 0))
+ return;
+
+ self = FLICKR_PHOTO (base);
+
+ flickr_photo_set_id (self, dom_element_get_attribute (element, "id"));
+ flickr_photo_set_secret (self, dom_element_get_attribute (element, "secret"));
+ flickr_photo_set_server (self, dom_element_get_attribute (element, "server"));
+ flickr_photo_set_title (self, dom_element_get_attribute (element, "title"));
+ flickr_photo_set_is_primary (self, dom_element_get_attribute (element, "isprimary"));
+ flickr_photo_set_url_sq (self, dom_element_get_attribute (element, "url_sq"));
+ flickr_photo_set_url_t (self, dom_element_get_attribute (element, "url_t"));
+ flickr_photo_set_url_s (self, dom_element_get_attribute (element, "url_s"));
+ flickr_photo_set_url_m (self, dom_element_get_attribute (element, "url_m"));
+ flickr_photo_set_url_o (self, dom_element_get_attribute (element, "url_o"));
+}
+
+
+static void
+flickr_photo_dom_domizable_interface_init (DomDomizableIface *iface)
+{
+ iface->create_element = flickr_photo_create_element;
+ iface->load_from_element = flickr_photo_load_from_element;
+}
+
+
+static void
+flickr_photo_instance_init (FlickrPhoto *self)
+{
+}
+
+
+GType
+flickr_photo_get_type (void)
+{
+ static GType flickr_photo_type_id = 0;
+
+ if (flickr_photo_type_id == 0) {
+ static const GTypeInfo g_define_type_info = {
+ sizeof (FlickrPhotoClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) flickr_photo_class_init,
+ (GClassFinalizeFunc) NULL,
+ NULL,
+ sizeof (FlickrPhoto),
+ 0,
+ (GInstanceInitFunc) flickr_photo_instance_init,
+ NULL
+ };
+ static const GInterfaceInfo dom_domizable_info = {
+ (GInterfaceInitFunc) flickr_photo_dom_domizable_interface_init,
+ (GInterfaceFinalizeFunc) NULL,
+ NULL
+ };
+
+ flickr_photo_type_id = g_type_register_static (G_TYPE_OBJECT,
+ "FlickrPhoto",
+ &g_define_type_info,
+ 0);
+ g_type_add_interface_static (flickr_photo_type_id, DOM_TYPE_DOMIZABLE, &dom_domizable_info);
+ }
+
+ return flickr_photo_type_id;
+}
+
+
+FlickrPhoto *
+flickr_photo_new (void)
+{
+ return g_object_new (FLICKR_TYPE_PHOTO, NULL);
+}
+
+
+void
+flickr_photo_set_id (FlickrPhoto *self,
+ const char *value)
+{
+ _g_strset (&self->id, value);
+}
+
+
+void
+flickr_photo_set_secret (FlickrPhoto *self,
+ const char *value)
+{
+ _g_strset (&self->secret, value);
+}
+
+
+void
+flickr_photo_set_server (FlickrPhoto *self,
+ const char *value)
+{
+ _g_strset (&self->server, value);
+}
+
+
+void
+flickr_photo_set_title (FlickrPhoto *self,
+ const char *value)
+{
+ _g_strset (&self->title, value);
+}
+
+
+void
+flickr_photo_set_is_primary (FlickrPhoto *self,
+ const char *value)
+{
+ self->is_primary = (g_strcmp0 (value, "1") == 0);
+}
+
+
+void
+flickr_photo_set_url_sq (FlickrPhoto *self,
+ const char *value)
+{
+ _g_strset (&self->url_sq, value);
+}
+
+
+void
+flickr_photo_set_url_t (FlickrPhoto *self,
+ const char *value)
+{
+ _g_strset (&self->url_t, value);
+}
+
+
+void
+flickr_photo_set_url_s (FlickrPhoto *self,
+ const char *value)
+{
+ _g_strset (&self->url_s, value);
+}
+
+
+void
+flickr_photo_set_url_m (FlickrPhoto *self,
+ const char *value)
+{
+ _g_strset (&self->url_m, value);
+}
+
+
+void
+flickr_photo_set_url_o (FlickrPhoto *self,
+ const char *value)
+{
+ _g_strset (&self->url_o, value);
+}
+
+
+void
+flickr_photo_set_original_format (FlickrPhoto *self,
+ const char *value)
+{
+ _g_strset (&self->original_format, value);
+
+ g_free (self->mime_type);
+ self->mime_type = NULL;
+ if (self->original_format != NULL)
+ self->mime_type = g_strconcat ("image/", self->original_format, NULL);
+}
diff --git a/extensions/flicker/flickr-photo.h b/extensions/flicker/flickr-photo.h
new file mode 100644
index 0000000..f63e2f1
--- /dev/null
+++ b/extensions/flicker/flickr-photo.h
@@ -0,0 +1,92 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * GThumb
+ *
+ * Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef FLICKR_PHOTO_H
+#define FLICKR_PHOTO_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define FLICKR_TYPE_PHOTO (flickr_photo_get_type ())
+#define FLICKR_PHOTO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FLICKR_TYPE_PHOTO, FlickrPhoto))
+#define FLICKR_PHOTO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FLICKR_TYPE_PHOTO, FlickrPhotoClass))
+#define FLICKR_IS_PHOTO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FLICKR_TYPE_PHOTO))
+#define FLICKR_IS_PHOTO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FLICKR_TYPE_PHOTO))
+#define FLICKR_PHOTO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FLICKR_TYPE_PHOTO, FlickrPhotoClass))
+
+typedef struct _FlickrPhoto FlickrPhoto;
+typedef struct _FlickrPhotoClass FlickrPhotoClass;
+typedef struct _FlickrPhotoPrivate FlickrPhotoPrivate;
+
+struct _FlickrPhoto {
+ GObject parent_instance;
+ FlickrPhotoPrivate *priv;
+
+ char *id;
+ char *secret;
+ char *server;
+ char *title;
+ gboolean is_primary;
+ char *url_sq;
+ char *url_t;
+ char *url_s;
+ char *url_m;
+ char *url_o;
+ char *original_format;
+ char *mime_type;
+ int position;
+};
+
+struct _FlickrPhotoClass {
+ GObjectClass parent_class;
+};
+
+GType flickr_photo_get_type (void);
+FlickrPhoto * flickr_photo_new (void);
+void flickr_photo_set_id (FlickrPhoto *self,
+ const char *value);
+void flickr_photo_set_secret (FlickrPhoto *self,
+ const char *value);
+void flickr_photo_set_server (FlickrPhoto *self,
+ const char *value);
+void flickr_photo_set_title (FlickrPhoto *self,
+ const char *value);
+void flickr_photo_set_is_primary (FlickrPhoto *self,
+ const char *value);
+void flickr_photo_set_url_sq (FlickrPhoto *self,
+ const char *value);
+void flickr_photo_set_url_t (FlickrPhoto *self,
+ const char *value);
+void flickr_photo_set_url_s (FlickrPhoto *self,
+ const char *value);
+void flickr_photo_set_url_m (FlickrPhoto *self,
+ const char *value);
+void flickr_photo_set_url_o (FlickrPhoto *self,
+ const char *value);
+void flickr_photo_set_original_format (FlickrPhoto *self,
+ const char *value);
+
+G_END_DECLS
+
+#endif /* FLICKR_PHOTO_H */
diff --git a/extensions/flicker/flickr-service.c b/extensions/flicker/flickr-service.c
index 42f87aa..895fa4b 100644
--- a/extensions/flicker/flickr-service.c
+++ b/extensions/flicker/flickr-service.c
@@ -26,6 +26,7 @@
#include <gthumb.h>
#include "flickr-account.h"
#include "flickr-connection.h"
+#include "flickr-photo.h"
#include "flickr-photoset.h"
#include "flickr-service.h"
#include "flickr-user.h"
@@ -938,8 +939,6 @@ flickr_service_post_photos_finish (FlickrService *self,
}
-#if 0
-
/* -- flickr_service_list_photos -- */
@@ -948,13 +947,13 @@ list_photos_ready_cb (SoupSession *session,
SoupMessage *msg,
gpointer user_data)
{
- FlickrService *self = user_data;
+ FlickrService *self = user_data;
GSimpleAsyncResult *result;
SoupBuffer *body;
- DomDocument *doc;
+ DomDocument *doc = NULL;
GError *error = NULL;
- result = google_connection_get_result (self->priv->conn);
+ result = flickr_connection_get_result (self->priv->conn);
if (msg->status_code != 200) {
g_simple_async_result_set_error (result,
@@ -967,72 +966,81 @@ list_photos_ready_cb (SoupSession *session,
}
body = soup_message_body_flatten (msg->response_body);
- doc = dom_document_new ();
- if (dom_document_load (doc, body->data, body->length, &error)) {
- DomElement *feed_node;
+ if (flickr_utils_parse_response (body, &doc, &error)) {
+ DomElement *response;
+ DomElement *node;
GList *photos = NULL;
- feed_node = DOM_ELEMENT (doc)->first_child;
- while ((feed_node != NULL) && g_strcmp0 (feed_node->tag_name, "feed") != 0)
- feed_node = feed_node->next_sibling;
-
- if (feed_node != NULL) {
- DomElement *node;
- PicasaWebPhoto *photo;
+ response = DOM_ELEMENT (doc)->first_child;
+ for (node = response->first_child; node; node = node->next_sibling) {
+ if (g_strcmp0 (node->tag_name, "photoset") == 0) {
+ DomElement *child;
+ int position;
- self->priv->user = flickr_user_new ();
- dom_domizable_load_from_element (DOM_DOMIZABLE (self->priv->user), feed_node);
+ position = 0;
+ for (child = node->first_child; child; child = child->next_sibling) {
+ if (g_strcmp0 (child->tag_name, "photo") == 0) {
+ FlickrPhoto *photo;
- photo = NULL;
- for (node = feed_node->first_child;
- node != NULL;
- node = node->next_sibling)
- {
- if (g_strcmp0 (node->tag_name, "entry") == 0) { /* read the photo data */
- if (photo != NULL)
+ photo = flickr_photo_new ();
+ dom_domizable_load_from_element (DOM_DOMIZABLE (photo), child);
+ photo->position = position++;
photos = g_list_prepend (photos, photo);
- photo = flickr_photo_new ();
- dom_domizable_load_from_element (DOM_DOMIZABLE (photo), node);
+ }
}
}
- if (photo != NULL)
- photos = g_list_prepend (photos, photo);
}
+
photos = g_list_reverse (photos);
g_simple_async_result_set_op_res_gpointer (result, photos, (GDestroyNotify) _g_object_list_unref);
+
+ g_object_unref (doc);
}
- else {
+ else
g_simple_async_result_set_from_error (result, error);
- g_error_free (error);
- }
+
g_simple_async_result_complete_in_idle (result);
- g_object_unref (doc);
soup_buffer_free (body);
}
void
flickr_service_list_photos (FlickrService *self,
- FlickrPhotoset *album,
+ FlickrPhotoset *photoset,
+ const char *extras,
+ int per_page,
+ int page,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
- char *url;
+ GHashTable *data_set;
+ char *s;
SoupMessage *msg;
- g_return_if_fail (album != NULL);
+ g_return_if_fail (photoset != NULL);
gth_task_progress (GTH_TASK (self->priv->conn), _("Getting the photo list"), NULL, TRUE, 0.0);
- url = g_strconcat ("http://picasaweb.google.com/data/feed/api/user/",
- self->priv->user->id,
- "/albumid/",
- album->id,
- NULL);
- msg = soup_message_new ("GET", url);
- google_connection_send_message (self->priv->conn,
+ data_set = g_hash_table_new (g_str_hash, g_str_equal);
+ g_hash_table_insert (data_set, "method", "flickr.photosets.getPhotos");
+ g_hash_table_insert (data_set, "photoset_id", photoset->id);
+ if (extras != NULL)
+ g_hash_table_insert (data_set, "extras", (char *) extras);
+ if (per_page > 0) {
+ s = g_strdup_printf ("%d", per_page);
+ g_hash_table_insert (data_set, "per_page", s);
+ g_free (s);
+ }
+ if (page > 0) {
+ s = g_strdup_printf ("%d", page);
+ g_hash_table_insert (data_set, "page", s);
+ g_free (s);
+ }
+ flickr_connection_add_api_sig (self->priv->conn, data_set);
+ msg = soup_form_request_new_from_hash ("GET", "http://api.flickr.com/services/rest", data_set);
+ flickr_connection_send_message (self->priv->conn,
msg,
cancellable,
callback,
@@ -1041,7 +1049,7 @@ flickr_service_list_photos (FlickrService *self,
list_photos_ready_cb,
self);
- g_free (url);
+ g_hash_table_destroy (data_set);
}
@@ -1056,8 +1064,6 @@ flickr_service_list_photos_finish (FlickrService *self,
return _g_object_list_ref (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result)));
}
-#endif
-
/* utilities */
diff --git a/extensions/flicker/flickr-service.h b/extensions/flicker/flickr-service.h
index 90db608..1bd50bc 100644
--- a/extensions/flicker/flickr-service.h
+++ b/extensions/flicker/flickr-service.h
@@ -110,16 +110,17 @@ void flickr_service_post_photos (FlickrService
GList * flickr_service_post_photos_finish (FlickrService *self,
GAsyncResult *result,
GError **error);
-#if 0
void flickr_service_list_photos (FlickrService *self,
FlickrPhotoset *photoset,
+ const char *extras,
+ int per_page,
+ int page,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GList * flickr_service_list_photos_finish (FlickrService *self,
GAsyncResult *result,
GError **error);
-#endif
/* utilities */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]