[gthumb: 3/11] [flicker] list the existing photosets
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb: 3/11] [flicker] list the existing photosets
- Date: Thu, 11 Mar 2010 17:12:20 +0000 (UTC)
commit b0f424e8faeca4eefea8ba521d8b7d4d5b89439e
Author: Paolo Bacchilega <paobac src gnome org>
Date: Tue Mar 9 00:31:22 2010 +0100
[flicker] list the existing photosets
extensions/flicker/data/ui/export-to-flickr.ui | 25 +++---
extensions/flicker/dlg-export-to-flickr.c | 99 ++++++++++++++++++++-
extensions/flicker/flickr-service.c | 111 +++++++++++-------------
extensions/flicker/flickr-service.h | 3 +-
4 files changed, 162 insertions(+), 76 deletions(-)
---
diff --git a/extensions/flicker/data/ui/export-to-flickr.ui b/extensions/flicker/data/ui/export-to-flickr.ui
index 8a30ddd..89ecb18 100644
--- a/extensions/flicker/data/ui/export-to-flickr.ui
+++ b/extensions/flicker/data/ui/export-to-flickr.ui
@@ -172,19 +172,20 @@
</packing>
</child>
<child>
- <object class="GtkComboBoxEntry" id="album_comboboxentry">
+ <object class="GtkComboBoxEntry" id="photoset_comboboxentry">
<property name="visible">True</property>
- <property name="model">album_liststore</property>
+ <property name="model">photoset_liststore</property>
+ <property name="text_column">2</property>
<child>
<object class="GtkCellRendererPixbuf" id="cellrenderertext1"/>
<attributes>
- <attribute name="icon-name">2</attribute>
+ <attribute name="icon-name">1</attribute>
</attributes>
</child>
<child>
<object class="GtkCellRendererText" id="cellrenderertext2"/>
<attributes>
- <attribute name="text">1</attribute>
+ <attribute name="text">2</attribute>
</attributes>
</child>
</object>
@@ -279,21 +280,21 @@
<property name="visible">True</property>
<property name="stock">gtk-goto-top</property>
</object>
- <object class="GtkListStore" id="album_liststore">
+ <object class="GtkListStore" id="account_liststore">
<columns>
- <!-- column-name data -->
+ <!-- column-name account -->
<column type="GObject"/>
- <!-- column-name name -->
- <column type="gchararray"/>
- <!-- column-name icon -->
+ <!-- column-name username -->
<column type="gchararray"/>
</columns>
</object>
- <object class="GtkListStore" id="account_liststore">
+ <object class="GtkListStore" id="photoset_liststore">
<columns>
- <!-- column-name account -->
+ <!-- column-name data -->
<column type="GObject"/>
- <!-- column-name username -->
+ <!-- column-name icon -->
+ <column type="gchararray"/>
+ <!-- column-name title -->
<column type="gchararray"/>
</columns>
</object>
diff --git a/extensions/flicker/dlg-export-to-flickr.c b/extensions/flicker/dlg-export-to-flickr.c
index 10c4cde..0c48d00 100644
--- a/extensions/flicker/dlg-export-to-flickr.c
+++ b/extensions/flicker/dlg-export-to-flickr.c
@@ -40,6 +40,14 @@ enum {
};
+enum {
+ PHOTOSET_DATA_COLUMN,
+ PHOTOSET_ICON_COLUMN,
+ PHOTOSET_TITLE_COLUMN,
+ PHOTOSET_N_PHOTOS_COLUMN
+};
+
+
typedef struct {
GthBrowser *browser;
GthFileData *location;
@@ -50,6 +58,7 @@ typedef struct {
GList *accounts;
FlickrAccount *account;
FlickrUser *user;
+ GList *photosets;
FlickrConnection *conn;
FlickrService *service;
GCancellable *cancellable;
@@ -68,6 +77,7 @@ export_dialog_destroy_cb (GtkWidget *widget,
_g_object_list_unref (data->accounts);
_g_object_unref (data->account);
_g_object_unref (data->user);
+ _g_object_list_unref (data->photosets);
_g_object_unref (data->builder);
_g_object_list_unref (data->file_list);
_g_object_unref (data->location);
@@ -75,6 +85,34 @@ export_dialog_destroy_cb (GtkWidget *widget,
}
+#if 0
+
+static void get_photoset_list (DialogData *data);
+
+
+static void
+post_photos_ready_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ DialogData *data = user_data;
+ GError *error = NULL;
+
+ gth_task_dialog (GTH_TASK (data->conn), TRUE);
+
+ if (! flickr_service_post_photos_finish (FLICKR_SERVICE (source_object), result, &error)) {
+ _gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->browser), _("Could not upload the files"), &error);
+ return;
+ }
+
+ /* FIXME */
+
+ get_photoset_list (data);
+}
+
+#endif
+
+
static void
export_dialog_response_cb (GtkDialog *dialog,
int response_id,
@@ -164,22 +202,44 @@ update_account_list (DialogData *data)
static void
-upload_status_ready_cb (GObject *source_object,
+photoset_list_ready_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
DialogData *data = user_data;
GError *error = NULL;
+ GList *scan;
- data->user = flickr_service_get_upload_status_finish (FLICKR_SERVICE (source_object), res, &error);
- if (data->user == NULL) {
+ _g_object_list_unref (data->photosets);
+ data->photosets = flickr_service_list_photosets_finish (FLICKR_SERVICE (source_object), res, &error);
+ if (error != NULL) {
_gtk_error_dialog_from_gerror_run (GTK_WINDOW (data->browser), _("Could not connect to the server"), &error);
gtk_widget_destroy (data->dialog);
return;
}
+ gtk_list_store_clear (GTK_LIST_STORE (GET_WIDGET ("photoset_liststore")));
+ for (scan = data->photosets; scan; scan = scan->next) {
+ FlickrPhotoset *photoset = scan->data;
+ char *n_photos;
+ GtkTreeIter iter;
+
+ n_photos = g_strdup_printf ("%d", photoset->n_photos);
+
+ gtk_list_store_append (GTK_LIST_STORE (GET_WIDGET ("photoset_liststore")), &iter);
+ gtk_list_store_set (GTK_LIST_STORE (GET_WIDGET ("photoset_liststore")), &iter,
+ PHOTOSET_DATA_COLUMN, photoset,
+ PHOTOSET_ICON_COLUMN, "file-catalog",
+ PHOTOSET_TITLE_COLUMN, photoset->title,
+ PHOTOSET_N_PHOTOS_COLUMN, n_photos,
+ -1);
+
+ g_free (n_photos);
+ }
+
+ gtk_widget_set_sensitive (GET_WIDGET ("upload_button"), TRUE);
+
gth_task_dialog (GTH_TASK (data->conn), TRUE);
- update_account_list (data);
gtk_window_set_transient_for (GTK_WINDOW (data->dialog), GTK_WINDOW (data->browser));
gtk_window_set_modal (GTK_WINDOW (data->dialog), FALSE);
@@ -188,6 +248,37 @@ upload_status_ready_cb (GObject *source_object,
static void
+get_photoset_list (DialogData *data)
+{
+ flickr_service_list_photosets (data->service,
+ NULL,
+ data->cancellable,
+ photoset_list_ready_cb,
+ data);
+}
+
+
+static void
+upload_status_ready_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ DialogData *data = user_data;
+ GError *error = NULL;
+
+ data->user = flickr_service_get_upload_status_finish (FLICKR_SERVICE (source_object), res, &error);
+ if (error != NULL) {
+ _gtk_error_dialog_from_gerror_run (GTK_WINDOW (data->browser), _("Could not connect to the server"), &error);
+ gtk_widget_destroy (data->dialog);
+ return;
+ }
+
+ update_account_list (data);
+ get_photoset_list (data);
+}
+
+
+static void
connect_to_server (DialogData *data)
{
g_return_if_fail (data->account != NULL);
diff --git a/extensions/flicker/flickr-service.c b/extensions/flicker/flickr-service.c
index 54fb92c..f557902 100644
--- a/extensions/flicker/flickr-service.c
+++ b/extensions/flicker/flickr-service.c
@@ -243,22 +243,21 @@ flickr_service_get_upload_status_finish (FlickrService *self,
}
-#if 0
-/* -- flickr_service_list_albums -- */
+/* -- flickr_service_list_photosets -- */
static void
-list_albums_ready_cb (SoupSession *session,
- SoupMessage *msg,
- gpointer user_data)
+list_photosets_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,
@@ -271,84 +270,77 @@ list_albums_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;
- GList *albums = 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 (flickr_utils_parse_response (body, &doc, &error)) {
+ DomElement *response;
+ DomElement *node;
+ GList *photosets = NULL;
- if (feed_node != NULL) {
- DomElement *node;
- FlickrPhotoset *album;
+ response = DOM_ELEMENT (doc)->first_child;
+ for (node = response->first_child; node; node = node->next_sibling) {
+ if (g_strcmp0 (node->tag_name, "photosets") == 0) {
+ DomElement *child;
- self->priv->user = flickr_user_new ();
- dom_domizable_load_from_element (DOM_DOMIZABLE (self->priv->user), feed_node);
+ for (child = node->first_child; child; child = child->next_sibling) {
+ if (g_strcmp0 (child->tag_name, "photoset") == 0) {
+ FlickrPhotoset *photoset;
- album = NULL;
- for (node = feed_node->first_child;
- node != NULL;
- node = node->next_sibling)
- {
- if (g_strcmp0 (node->tag_name, "entry") == 0) { /* read the album data */
- if (album != NULL)
- albums = g_list_prepend (albums, album);
- album = flickr_album_new ();
- dom_domizable_load_from_element (DOM_DOMIZABLE (album), node);
+ photoset = flickr_photoset_new ();
+ dom_domizable_load_from_element (DOM_DOMIZABLE (photoset), child);
+ photosets = g_list_prepend (photosets, photoset);
+ }
}
}
- if (album != NULL)
- albums = g_list_prepend (albums, album);
}
- albums = g_list_reverse (albums);
- g_simple_async_result_set_op_res_gpointer (result, albums, (GDestroyNotify) _g_object_list_unref);
+
+ photosets = g_list_reverse (photosets);
+ g_simple_async_result_set_op_res_gpointer (result, photosets, (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_albums (FlickrService *self,
- const char *user_id,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+flickr_service_list_photosets (FlickrService *self,
+ const char *user_id,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
- char *url;
+ GHashTable *data_set;
SoupMessage *msg;
- g_return_if_fail (user_id != NULL);
-
gth_task_progress (GTH_TASK (self->priv->conn), _("Getting the album list"), NULL, TRUE, 0.0);
- url = g_strconcat ("http://picasaweb.google.com/data/feed/api/user/", user_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.getList");
+ if (user_id != NULL)
+ g_hash_table_insert (data_set, "user_id", (char *) user_id);
+ 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,
user_data,
- flickr_service_list_albums,
- list_albums_ready_cb,
+ flickr_service_list_photosets,
+ list_photosets_ready_cb,
self);
- g_free (url);
+ g_hash_table_destroy (data_set);
}
GList *
-flickr_service_list_albums_finish (FlickrService *service,
- GAsyncResult *result,
- GError **error)
+flickr_service_list_photosets_finish (FlickrService *service,
+ GAsyncResult *result,
+ GError **error)
{
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
return NULL;
@@ -357,6 +349,7 @@ flickr_service_list_albums_finish (FlickrService *service,
}
+#if 0
/* -- flickr_service_create_album -- */
diff --git a/extensions/flicker/flickr-service.h b/extensions/flicker/flickr-service.h
index 941bef7..8966ceb 100644
--- a/extensions/flicker/flickr-service.h
+++ b/extensions/flicker/flickr-service.h
@@ -60,14 +60,15 @@ void flickr_service_get_upload_status (FlickrService
FlickrUser * flickr_service_get_upload_status_finish (FlickrService *self,
GAsyncResult *result,
GError **error);
-#if 0
void flickr_service_list_photosets (FlickrService *self,
+ const char *user_id,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GList * flickr_service_list_photosets_finish (FlickrService *self,
GAsyncResult *result,
GError **error);
+#if 0
void flickr_service_create_photoset (FlickrService *self,
FlickrPhotoset *photoset,
GCancellable *cancellable,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]