[gthumb] Facebook plugin issues



commit 7f860d3c75e89b5f008e476dcecc255e22982650
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Wed Jul 7 17:15:20 2010 +0200

    Facebook plugin issues
    
    * automatically select a newly created catalog
    * apply embedded orientation before uploading
    * scale images to have 720 pixels as max dimension
    
    [bug #623617]

 extensions/facebook/dlg-export-to-facebook.c |   10 +++-
 extensions/facebook/facebook-service.c       |   61 +++++++++++++++++++++++++-
 gthumb/pixbuf-io.c                           |    3 +
 3 files changed, 70 insertions(+), 4 deletions(-)
---
diff --git a/extensions/facebook/dlg-export-to-facebook.c b/extensions/facebook/dlg-export-to-facebook.c
index 1de57be..9c34688 100644
--- a/extensions/facebook/dlg-export-to-facebook.c
+++ b/extensions/facebook/dlg-export-to-facebook.c
@@ -262,7 +262,8 @@ authentication_accounts_changed_cb (FacebookAuthentication *auth,
 
 
 static void
-update_album_list (DialogData *data)
+update_album_list (DialogData    *data,
+		   FacebookAlbum *to_select)
 {
 	GList *scan;
 
@@ -282,6 +283,9 @@ update_album_list (DialogData *data)
 				    ALBUM_SIZE_COLUMN, size,
 				    -1);
 
+		if ((to_select != NULL) && g_str_equal (to_select->id, album->id))
+			gtk_combo_box_set_active_iter (GTK_COMBO_BOX (GET_WIDGET ("album_combobox")), &iter);
+
 		g_free (size);
 	}
 }
@@ -306,7 +310,7 @@ get_albums_ready_cb (GObject      *source_object,
 	}
 
 	gtk_widget_set_sensitive (GET_WIDGET ("upload_button"), TRUE);
-	update_album_list (data);
+	update_album_list (data, NULL);
 
 	gth_task_dialog (GTH_TASK (data->conn), TRUE, NULL);
 	gtk_window_set_transient_for (GTK_WINDOW (data->dialog), GTK_WINDOW (data->browser));
@@ -381,7 +385,7 @@ create_album_ready_cb (GObject      *source_object,
 	}
 
 	data->albums = g_list_append (data->albums, album);
-	update_album_list (data);
+	update_album_list (data, album);
 }
 
 
diff --git a/extensions/facebook/facebook-service.c b/extensions/facebook/facebook-service.c
index 923e7ff..39c54a9 100644
--- a/extensions/facebook/facebook-service.c
+++ b/extensions/facebook/facebook-service.c
@@ -31,6 +31,7 @@
 #include "facebook-service.h"
 #include "facebook-user.h"
 
+#define FACEBOOK_MAX_IMAGE_SIZE 720
 
 typedef struct {
 	FacebookAlbum       *album;
@@ -683,6 +684,7 @@ upload_photo_file_buffer_ready_cb (void     **buffer,
 	FacebookService *self = user_data;
 	GthFileData     *file_data;
 	SoupMultipart   *multipart;
+	GthPixbufSaver  *saver;
 	char            *uri;
 	SoupBuffer      *body;
 	SoupMessage     *msg;
@@ -730,7 +732,64 @@ upload_photo_file_buffer_ready_cb (void     **buffer,
 		g_hash_table_unref (data_set);
 	}
 
-	/* the file part */
+	/* the file part: rotate and scale the image if required */
+
+	saver = gth_main_get_pixbuf_saver (gth_file_data_get_mime_type (file_data));
+	if (saver != NULL) {
+		GInputStream *stream;
+		GdkPixbuf    *pixbuf;
+		GdkPixbuf    *tmp_pixbuf;
+		int           width;
+		int           height;
+
+		stream = g_memory_input_stream_new_from_data (*buffer, count, NULL);
+		pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, &error);
+		if (pixbuf == NULL) {
+			g_object_unref (stream);
+			soup_multipart_free (multipart);
+			upload_photos_done (self, error);
+			return;
+		}
+
+		g_object_unref (stream);
+
+		tmp_pixbuf = gdk_pixbuf_apply_embedded_orientation (pixbuf);
+		g_object_unref (pixbuf);
+		pixbuf = tmp_pixbuf;
+
+		width = gdk_pixbuf_get_width (pixbuf);
+		height = gdk_pixbuf_get_height (pixbuf);
+		if (scale_keeping_ratio (&width,
+					 &height,
+					 FACEBOOK_MAX_IMAGE_SIZE,
+					 FACEBOOK_MAX_IMAGE_SIZE,
+					 FALSE))
+		{
+			tmp_pixbuf = _gdk_pixbuf_scale_simple_safe (pixbuf, width, height, GDK_INTERP_BILINEAR);
+			g_object_unref (pixbuf);
+			pixbuf = tmp_pixbuf;
+		}
+
+		g_free (*buffer);
+		*buffer = NULL;
+
+		if (! gth_pixbuf_saver_save_pixbuf (saver,
+						    pixbuf,
+						    (char **)buffer,
+						    &count,
+						    gth_file_data_get_mime_type (file_data),
+						    &error))
+		{
+			g_object_unref (pixbuf);
+			g_object_unref (saver);
+			soup_multipart_free (multipart);
+			upload_photos_done (self, error);
+			return;
+		}
+
+		g_object_unref (pixbuf);
+		g_object_unref (saver);
+	}
 
 	uri = g_file_get_uri (file_data->file);
 	body = soup_buffer_new (SOUP_MEMORY_TEMPORARY, *buffer, count);
diff --git a/gthumb/pixbuf-io.c b/gthumb/pixbuf-io.c
index 032b056..448a318 100644
--- a/gthumb/pixbuf-io.c
+++ b/gthumb/pixbuf-io.c
@@ -181,11 +181,14 @@ _gdk_pixbuf_save_async (GdkPixbuf        *pixbuf,
 					    mime_type,
 					    &error))
 	{
+		g_object_unref (saver);
 		g_object_unref (tmp_pixbuf);
 		gth_file_data_ready_with_error (file_data, ready_func, ready_data, error);
 		return;
 	}
 
+	g_object_unref (saver);
+
 	data = g_new0 (SavePixbufData, 1);
 	data->file_data = g_object_ref (file_data);
 	data->pixbuf = tmp_pixbuf;



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