[gthumb] picasaweb: allow to resize the images before uploading



commit 3e421ca7f4573af94309308145bc6eb2d2a4544e
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Tue Sep 4 18:29:39 2012 +0200

    picasaweb: allow to resize the images before uploading

 data/org.gnome.gthumb.picasaweb.gschema.xml.in     |   19 +++--
 .../picasaweb/data/ui/export-to-picasaweb.ui       |   69 ++++++++++++++++++++
 extensions/picasaweb/dlg-export-to-picasaweb.c     |   47 +++++++++++++
 extensions/picasaweb/picasa-web-service.c          |   30 ++++++++-
 extensions/picasaweb/picasa-web-service.h          |    2 +
 extensions/picasaweb/preferences.h                 |    3 +-
 6 files changed, 160 insertions(+), 10 deletions(-)
---
diff --git a/data/org.gnome.gthumb.picasaweb.gschema.xml.in b/data/org.gnome.gthumb.picasaweb.gschema.xml.in
index f7beaa9..0333f15 100644
--- a/data/org.gnome.gthumb.picasaweb.gschema.xml.in
+++ b/data/org.gnome.gthumb.picasaweb.gschema.xml.in
@@ -1,26 +1,29 @@
 <!--
   gThumb
- 
-  Copyright  2011 Free Software Foundation, Inc.
- 
+
+  Copyright  2011-2012 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, see <http://www.gnu.org/licenses/>.
 -->
 <schemalist>
-  
+
   <schema id="org.gnome.gthumb.picasaweb" path="/org/gnome/gthumb/picasaweb/">
-    <key name="synchronize" type="b">
-      <default>true</default>
+    <key name="resize-width" type="i">
+      <default>-1</default>
+    </key>
+    <key name="resize-height" type="i">
+      <default>-1</default>
     </key>
   </schema>
 
diff --git a/extensions/picasaweb/data/ui/export-to-picasaweb.ui b/extensions/picasaweb/data/ui/export-to-picasaweb.ui
index b2e28a9..b6becd3 100644
--- a/extensions/picasaweb/data/ui/export-to-picasaweb.ui
+++ b/extensions/picasaweb/data/ui/export-to-picasaweb.ui
@@ -408,6 +408,67 @@
                     <property name="position">1</property>
                   </packing>
                 </child>
+                <child>
+                  <object class="GtkHBox" id="resize_images_hbox">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="spacing">6</property>
+                    <child>
+                      <object class="GtkCheckButton" id="resize_checkbutton">
+                        <property name="label" translatable="yes">_Resize if larger than:</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="use_underline">True</property>
+                        <property name="xalign">0</property>
+                        <property name="draw_indicator">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkHBox" id="resize_images_options_hbox">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="spacing">6</property>
+                        <child>
+                          <object class="GtkComboBox" id="resize_combobox">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="model">resize_liststore</property>
+                            <property name="active">0</property>
+                            <child>
+                              <object class="GtkCellRendererText" id="cellrenderertext5"/>
+                              <attributes>
+                                <attribute name="text">0</attribute>
+                              </attributes>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">True</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">True</property>
+                        <property name="fill">True</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
               </object>
               <packing>
                 <property name="resize">False</property>
@@ -429,6 +490,14 @@
       <action-widget response="-11">button1</action-widget>
     </action-widgets>
   </object>
+  <object class="GtkListStore" id="resize_liststore">
+    <columns>
+      <!-- column-name description -->
+      <column type="gchararray"/>
+      <!-- column-name size -->
+      <column type="gint"/>
+    </columns>
+  </object>
   <object class="GtkImage" id="upload_image">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
diff --git a/extensions/picasaweb/dlg-export-to-picasaweb.c b/extensions/picasaweb/dlg-export-to-picasaweb.c
index 823f056..e5dec8d 100644
--- a/extensions/picasaweb/dlg-export-to-picasaweb.c
+++ b/extensions/picasaweb/dlg-export-to-picasaweb.c
@@ -33,6 +33,7 @@
 #include "picasa-web-album.h"
 #include "picasa-web-service.h"
 #include "picasa-web-user.h"
+#include "preferences.h"
 
 
 #define GET_WIDGET(x) (_gtk_builder_get_widget (data->builder, (x)))
@@ -58,6 +59,7 @@ enum {
 
 typedef struct {
 	GthBrowser       *browser;
+	GSettings        *settings;
 	GthFileData      *location;
 	GList            *file_list;
 	GtkBuilder       *builder;
@@ -97,6 +99,7 @@ destroy_dialog (DialogData *data)
 	_g_object_unref (data->builder);
 	_g_object_list_unref (data->file_list);
 	_g_object_unref (data->location);
+	g_object_unref (data->settings);
 	g_free (data);
 }
 
@@ -221,6 +224,8 @@ export_dialog_response_cb (GtkDialog *dialog,
 			GtkTreeModel *tree_model;
 			GtkTreeIter   iter;
 			GList        *file_list;
+			int           max_width;
+			int           max_height;
 
 			if (! gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (GET_WIDGET ("albums_treeview"))), &tree_model, &iter)) {
 				gtk_widget_set_sensitive (GET_WIDGET ("upload_button"), FALSE);
@@ -236,9 +241,22 @@ export_dialog_response_cb (GtkDialog *dialog,
 			gth_task_dialog (GTH_TASK (data->conn), FALSE, NULL);
 
 			file_list = gth_file_data_list_to_file_list (data->file_list);
+
+			max_width = -1;
+			max_height = -1;
+			if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("resize_checkbutton")))) {
+				int idx = gtk_combo_box_get_active (GTK_COMBO_BOX (GET_WIDGET ("resize_combobox")));
+				max_width = ImageSizeValues[idx].width;
+				max_height = ImageSizeValues[idx].height;
+			}
+			g_settings_set_int (data->settings, PREF_PICASAWEB_RESIZE_WIDTH, max_width);
+			g_settings_set_int (data->settings, PREF_PICASAWEB_RESIZE_HEIGHT, max_height);
+
 			picasa_web_service_post_photos (data->picasaweb,
 							data->album,
 							file_list,
+							max_width,
+							max_height,
 							data->cancellable,
 							post_photos_ready_cb,
 							data);
@@ -927,6 +945,21 @@ albums_treeview_selection_changed_cb (GtkTreeSelection *treeselection,
 }
 
 
+static void
+update_sensitivity (DialogData *data)
+{
+	gtk_widget_set_sensitive (GET_WIDGET ("resize_combobox"), gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("resize_checkbutton"))));
+}
+
+
+static void
+resize_checkbutton_toggled_cb (GtkToggleButton *button,
+			       gpointer         user_data)
+{
+	update_sensitivity (user_data);
+}
+
+
 void
 dlg_export_to_picasaweb (GthBrowser *browser,
 		         GList      *file_list)
@@ -941,6 +974,7 @@ dlg_export_to_picasaweb (GthBrowser *browser,
 
 	data = g_new0 (DialogData, 1);
 	data->browser = browser;
+	data->settings = g_settings_new (GTHUMB_PICASAWEB_SCHEMA);
 	data->location = gth_file_data_dup (gth_browser_get_location_data (browser));
 	data->builder = _gtk_builder_new_from_file ("export-to-picasaweb.ui", "picasaweb");
 	data->dialog = _gtk_builder_get_widget (data->builder, "export_dialog");
@@ -1028,6 +1062,13 @@ dlg_export_to_picasaweb (GthBrowser *browser,
 
 	gtk_widget_set_sensitive (GET_WIDGET ("upload_button"), FALSE);
 
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("resize_checkbutton")),
+				      g_settings_get_int (data->settings, PREF_PICASAWEB_RESIZE_WIDTH) != -1);
+
+	_gtk_combo_box_add_image_sizes (GTK_COMBO_BOX (GET_WIDGET ("resize_combobox")),
+					g_settings_get_int (data->settings, PREF_PICASAWEB_RESIZE_WIDTH),
+					g_settings_get_int (data->settings, PREF_PICASAWEB_RESIZE_HEIGHT));
+
 	/* Set the signals handlers. */
 
 	g_signal_connect (data->dialog,
@@ -1050,6 +1091,10 @@ dlg_export_to_picasaweb (GthBrowser *browser,
 			  "changed",
 			  G_CALLBACK (account_combobox_changed_cb),
 			  data);
+	g_signal_connect (GET_WIDGET ("resize_checkbutton"),
+			  "toggled",
+			  G_CALLBACK (resize_checkbutton_toggled_cb),
+			  data);
 
 	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (GET_WIDGET ("albums_treeview")));
 	gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
@@ -1058,6 +1103,8 @@ dlg_export_to_picasaweb (GthBrowser *browser,
 			  G_CALLBACK (albums_treeview_selection_changed_cb),
 			  data);
 
+	update_sensitivity (data);
+
 	data->accounts = picasa_web_accounts_load_from_file (&data->email);
 	auto_select_account (data);
 }
diff --git a/extensions/picasaweb/picasa-web-service.c b/extensions/picasaweb/picasa-web-service.c
index a7b9499..61a57cd 100644
--- a/extensions/picasaweb/picasa-web-service.c
+++ b/extensions/picasaweb/picasa-web-service.c
@@ -34,6 +34,8 @@ G_DEFINE_TYPE (PicasaWebService, picasa_web_service, G_TYPE_OBJECT)
 typedef struct {
 	PicasaWebAlbum      *album;
 	GList               *file_list;
+	int                  max_width;
+	int                  max_height;
 	GCancellable        *cancellable;
         GAsyncReadyCallback  callback;
         gpointer             user_data;
@@ -439,6 +441,8 @@ post_photo_file_buffer_ready_cb (void     **buffer,
 	gsize               entry_len;
 	SoupMessageHeaders *headers;
 	SoupBuffer         *body;
+	void               *resized_buffer;
+	gsize               resized_count;
 	char               *url;
 	SoupMessage        *msg;
 
@@ -507,7 +511,27 @@ post_photo_file_buffer_ready_cb (void     **buffer,
 
 	/* the file part */
 
-	body = soup_buffer_new (SOUP_MEMORY_TEMPORARY, *buffer, count);
+	if (_g_buffer_resize_image (*buffer,
+				    count,
+				    file_data,
+				    self->priv->post_photos->max_width,
+				    self->priv->post_photos->max_height,
+				    &resized_buffer,
+				    &resized_count,
+				    self->priv->post_photos->cancellable,
+				    &error))
+	{
+		body = soup_buffer_new (SOUP_MEMORY_TAKE, resized_buffer, resized_count);
+	}
+	else if (error == NULL) {
+		body = soup_buffer_new (SOUP_MEMORY_TEMPORARY, *buffer, count);
+	}
+	else {
+		soup_multipart_free (multipart);
+		post_photos_done (self, error);
+		return;
+	}
+
 	soup_multipart_append_form_file (multipart,
 					 "file",
 					 NULL,
@@ -595,6 +619,8 @@ void
 picasa_web_service_post_photos (PicasaWebService    *self,
 			        PicasaWebAlbum      *album,
 			        GList               *file_list, /* GFile list */
+			        int                  max_width,
+			        int                  max_height,
 			        GCancellable        *cancellable,
 			        GAsyncReadyCallback  callback,
 			        gpointer             user_data)
@@ -606,6 +632,8 @@ picasa_web_service_post_photos (PicasaWebService    *self,
 
 	self->priv->post_photos = g_new0 (PostPhotosData, 1);
 	self->priv->post_photos->album = g_object_ref (album);
+	self->priv->post_photos->max_width = max_width;
+	self->priv->post_photos->max_height = max_height;
 	self->priv->post_photos->cancellable = _g_object_ref (cancellable);
 	self->priv->post_photos->callback = callback;
 	self->priv->post_photos->user_data = user_data;
diff --git a/extensions/picasaweb/picasa-web-service.h b/extensions/picasaweb/picasa-web-service.h
index 9bfc89d..8f1b48f 100644
--- a/extensions/picasaweb/picasa-web-service.h
+++ b/extensions/picasaweb/picasa-web-service.h
@@ -71,6 +71,8 @@ PicasaWebAlbum *     picasa_web_service_create_album_finish (PicasaWebService
 void                 picasa_web_service_post_photos         (PicasaWebService     *self,
 							     PicasaWebAlbum       *album,
 							     GList                *file_list, /* GFile list */
+							     int                   max_width,
+							     int                   max_height,
 							     GCancellable         *cancellable,
 							     GAsyncReadyCallback   callback,
 							     gpointer              user_data);
diff --git a/extensions/picasaweb/preferences.h b/extensions/picasaweb/preferences.h
index 24fd0c3..1bbc4da 100644
--- a/extensions/picasaweb/preferences.h
+++ b/extensions/picasaweb/preferences.h
@@ -28,6 +28,7 @@
 
 /* keys */
 
-#define  PREF_PICASAWEB_SYNCHRONIZE "synchronize"
+#define  PREF_PICASAWEB_RESIZE_WIDTH "resize-width"
+#define  PREF_PICASAWEB_RESIZE_HEIGHT "resize-height"
 
 #endif /* PREFERENCES_H */



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