[gthumb] web uploaders: update the progress bar during the files upload
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] web uploaders: update the progress bar during the files upload
- Date: Fri, 2 Sep 2011 13:36:31 +0000 (UTC)
commit 738639201b5d71ce371920da918c6e0559c362d4
Author: Paolo Bacchilega <paobac src gnome org>
Date: Fri Sep 2 15:33:04 2011 +0200
web uploaders: update the progress bar during the files upload
extensions/facebook/facebook-service.c | 1 -
extensions/flicker/flickr-service.c | 51 +++++++++++++++++++-------
extensions/photobucket/photobucket-service.c | 51 +++++++++++++++++++-------
extensions/picasaweb/picasa-web-service.c | 44 +++++++++++++++++++---
4 files changed, 114 insertions(+), 33 deletions(-)
---
diff --git a/extensions/facebook/facebook-service.c b/extensions/facebook/facebook-service.c
index 19e1c80..bb7f42b 100644
--- a/extensions/facebook/facebook-service.c
+++ b/extensions/facebook/facebook-service.c
@@ -840,7 +840,6 @@ upload_photo_file_buffer_ready_cb (void **buffer,
/* send the file */
self->priv->post_photos->wrote_body_data_size = 0;
-
msg = soup_form_request_new_from_multipart (FACEBOOK_HTTPS_REST_SERVER, multipart);
g_signal_connect (msg,
"wrote-body-data",
diff --git a/extensions/flicker/flickr-service.c b/extensions/flicker/flickr-service.c
index 5b9dca0..cb35cdb 100644
--- a/extensions/flicker/flickr-service.c
+++ b/extensions/flicker/flickr-service.c
@@ -42,6 +42,7 @@ typedef struct {
GList *current;
goffset total_size;
goffset uploaded_size;
+ goffset wrote_body_data_size;
int n_files;
int uploaded_files;
GList *ids;
@@ -749,6 +750,37 @@ get_safety_value (FlickrSafetyType safety_level)
static void
+upload_photo_wrote_body_data_cb (SoupMessage *msg,
+ SoupBuffer *chunk,
+ gpointer user_data)
+{
+ FlickrService *self = user_data;
+ GthFileData *file_data;
+ char *details;
+ double current_file_fraction;
+
+ if (self->priv->post_photos->current == NULL)
+ return;
+
+ self->priv->post_photos->wrote_body_data_size += chunk->length;
+ if (self->priv->post_photos->wrote_body_data_size > msg->request_body->length)
+ return;
+
+ file_data = self->priv->post_photos->current->data;
+ /* Translators: %s is a filename */
+ details = g_strdup_printf (_("Uploading '%s'"), g_file_info_get_display_name (file_data->info));
+ current_file_fraction = (double) self->priv->post_photos->wrote_body_data_size / msg->request_body->length;
+ gth_task_progress (GTH_TASK (self->priv->conn),
+ NULL,
+ details,
+ FALSE,
+ (double) (self->priv->post_photos->uploaded_size + (g_file_info_get_size (file_data->info) * current_file_fraction)) / self->priv->post_photos->total_size);
+
+ g_free (details);
+}
+
+
+static void
post_photo_file_buffer_ready_cb (void **buffer,
gsize count,
GError *error,
@@ -830,20 +862,13 @@ post_photo_file_buffer_ready_cb (void **buffer,
/* send the file */
- {
- char *details;
-
- /* Translators: %s is a filename */
- details = g_strdup_printf (_("Uploading '%s'"), g_file_info_get_display_name (file_data->info));
- gth_task_progress (GTH_TASK (self->priv->conn),
- NULL, details,
- FALSE,
- (double) (self->priv->post_photos->uploaded_size + (g_file_info_get_size (file_data->info) / 2.0)) / self->priv->post_photos->total_size);
-
- g_free (details);
- }
-
+ self->priv->post_photos->wrote_body_data_size = 0;
msg = soup_form_request_new_from_multipart (self->priv->conn->server->upload_url, multipart);
+ g_signal_connect (msg,
+ "wrote-body-data",
+ (GCallback) upload_photo_wrote_body_data_cb,
+ self);
+
flickr_connection_send_message (self->priv->conn,
msg,
self->priv->post_photos->cancellable,
diff --git a/extensions/photobucket/photobucket-service.c b/extensions/photobucket/photobucket-service.c
index 9f0ec44..27b5fd3 100644
--- a/extensions/photobucket/photobucket-service.c
+++ b/extensions/photobucket/photobucket-service.c
@@ -41,6 +41,7 @@ typedef struct {
GList *current;
goffset total_size;
goffset uploaded_size;
+ goffset wrote_body_data_size;
int n_files;
int uploaded_files;
} PostPhotosData;
@@ -437,6 +438,37 @@ upload_photo_ready_cb (SoupSession *session,
static void
+upload_photo_wrote_body_data_cb (SoupMessage *msg,
+ SoupBuffer *chunk,
+ gpointer user_data)
+{
+ PhotobucketService *self = user_data;
+ GthFileData *file_data;
+ char *details;
+ double current_file_fraction;
+
+ if (self->priv->post_photos->current == NULL)
+ return;
+
+ self->priv->post_photos->wrote_body_data_size += chunk->length;
+ if (self->priv->post_photos->wrote_body_data_size > msg->request_body->length)
+ return;
+
+ file_data = self->priv->post_photos->current->data;
+ /* Translators: %s is a filename */
+ details = g_strdup_printf (_("Uploading '%s'"), g_file_info_get_display_name (file_data->info));
+ current_file_fraction = (double) self->priv->post_photos->wrote_body_data_size / msg->request_body->length;
+ gth_task_progress (GTH_TASK (self->priv->conn),
+ NULL,
+ details,
+ FALSE,
+ (double) (self->priv->post_photos->uploaded_size + (g_file_info_get_size (file_data->info) * current_file_fraction)) / self->priv->post_photos->total_size);
+
+ g_free (details);
+}
+
+
+static void
upload_photo_file_buffer_ready_cb (void **buffer,
gsize count,
GError *error,
@@ -515,21 +547,14 @@ upload_photo_file_buffer_ready_cb (void **buffer,
/* send the file */
- {
- char *details;
-
- /* Translators: %s is a filename */
- details = g_strdup_printf (_("Uploading '%s'"), g_file_info_get_display_name (file_data->info));
- gth_task_progress (GTH_TASK (self->priv->conn),
- NULL, details,
- FALSE,
- (double) (self->priv->post_photos->uploaded_size + (g_file_info_get_size (file_data->info) / 2.0)) / self->priv->post_photos->total_size);
-
- g_free (details);
- }
-
+ self->priv->post_photos->wrote_body_data_size = 0;
url = g_strconcat ("http://", self->priv->post_photos->account->subdomain, "/album/", identifier, "/upload", NULL);
msg = soup_form_request_new_from_multipart (url, multipart);
+ g_signal_connect (msg,
+ "wrote-body-data",
+ (GCallback) upload_photo_wrote_body_data_cb,
+ self);
+
oauth_connection_send_message (self->priv->conn,
msg,
self->priv->post_photos->cancellable,
diff --git a/extensions/picasaweb/picasa-web-service.c b/extensions/picasaweb/picasa-web-service.c
index d344b93..ba38d38 100644
--- a/extensions/picasaweb/picasa-web-service.c
+++ b/extensions/picasaweb/picasa-web-service.c
@@ -37,6 +37,7 @@ typedef struct {
GList *current;
goffset total_size;
goffset uploaded_size;
+ goffset wrote_body_data_size;
int n_files;
int uploaded_files;
} PostPhotosData;
@@ -419,6 +420,37 @@ post_photo_ready_cb (SoupSession *session,
static void
+upload_photo_wrote_body_data_cb (SoupMessage *msg,
+ SoupBuffer *chunk,
+ gpointer user_data)
+{
+ PicasaWebService *self = user_data;
+ GthFileData *file_data;
+ char *details;
+ double current_file_fraction;
+
+ if (self->priv->post_photos->current == NULL)
+ return;
+
+ self->priv->post_photos->wrote_body_data_size += chunk->length;
+ if (self->priv->post_photos->wrote_body_data_size > msg->request_body->length)
+ return;
+
+ file_data = self->priv->post_photos->current->data;
+ /* Translators: %s is a filename */
+ details = g_strdup_printf (_("Uploading '%s'"), g_file_info_get_display_name (file_data->info));
+ current_file_fraction = (double) self->priv->post_photos->wrote_body_data_size / msg->request_body->length;
+ gth_task_progress (GTH_TASK (self->priv->conn),
+ NULL,
+ details,
+ FALSE,
+ (double) (self->priv->post_photos->uploaded_size + (g_file_info_get_size (file_data->info) * current_file_fraction)) / self->priv->post_photos->total_size);
+
+ g_free (details);
+}
+
+
+static void
post_photo_file_buffer_ready_cb (void **buffer,
gsize count,
GError *error,
@@ -436,7 +468,6 @@ post_photo_file_buffer_ready_cb (void **buffer,
gsize entry_len;
SoupMessageHeaders *headers;
SoupBuffer *body;
- char *details;
char *url;
SoupMessage *msg;
@@ -516,17 +547,18 @@ post_photo_file_buffer_ready_cb (void **buffer,
/* send the file */
- /* Translators: %s is a filename */
- details = g_strdup_printf (_("Uploading '%s'"), filename);
- gth_task_progress (GTH_TASK (self->priv->conn), NULL, details, TRUE, 0.0);
- g_free (details);
-
+ self->priv->post_photos->wrote_body_data_size = 0;
url = g_strconcat ("http://picasaweb.google.com/data/feed/api/user/",
self->priv->user->id,
"/albumid/",
self->priv->post_photos->album->id,
NULL);
msg = soup_form_request_new_from_multipart (url, multipart);
+ g_signal_connect (msg,
+ "wrote-body-data",
+ (GCallback) upload_photo_wrote_body_data_cb,
+ self);
+
google_connection_send_message (self->priv->conn,
msg,
self->priv->post_photos->cancellable,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]