[gthumb] flickr: allow to scale the images before uploading
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] flickr: allow to scale the images before uploading
- Date: Tue, 4 Sep 2012 18:49:20 +0000 (UTC)
commit fc07f91de0867eed143b0a253cfaf18fa942e383
Author: Paolo Bacchilega <paobac src gnome org>
Date: Tue Sep 4 20:31:49 2012 +0200
flickr: allow to scale the images before uploading
data/Makefile.am | 1 +
data/org.gnome.gthumb.flickr.gschema.xml.in | 30 ++++++++
extensions/flicker_utils/Makefile.am | 3 +-
.../flicker_utils/data/ui/export-to-flickr.ui | 76 +++++++++++++++++++-
extensions/flicker_utils/dlg-export-to-flickr.c | 47 ++++++++++++
extensions/flicker_utils/flickr-service.c | 30 ++++++++-
extensions/flicker_utils/flickr-service.h | 2 +
extensions/flicker_utils/preferences.h | 34 +++++++++
8 files changed, 218 insertions(+), 5 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index f5ccdde..1bc5747 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -18,6 +18,7 @@ gsettings_schema_in_files = \
org.gnome.gthumb.crop.gschema.xml.in \
org.gnome.gthumb.facebook.gschema.xml.in \
org.gnome.gthumb.file-manager.gschema.xml.in \
+ org.gnome.gthumb.flickr.gschema.xml.in \
org.gnome.gthumb.gstreamer-tools.gschema.xml.in \
org.gnome.gthumb.image-print.gschema.xml.in \
org.gnome.gthumb.image-viewer.gschema.xml.in \
diff --git a/data/org.gnome.gthumb.flickr.gschema.xml.in b/data/org.gnome.gthumb.flickr.gschema.xml.in
new file mode 100644
index 0000000..91e39fd
--- /dev/null
+++ b/data/org.gnome.gthumb.flickr.gschema.xml.in
@@ -0,0 +1,30 @@
+<!--
+ gThumb
+
+ Copyright  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.flickr" path="/org/gnome/gthumb/flickr/">
+ <key name="resize-width" type="i">
+ <default>-1</default>
+ </key>
+ <key name="resize-height" type="i">
+ <default>-1</default>
+ </key>
+ </schema>
+
+</schemalist>
diff --git a/extensions/flicker_utils/Makefile.am b/extensions/flicker_utils/Makefile.am
index 8da4b15..b596e57 100644
--- a/extensions/flicker_utils/Makefile.am
+++ b/extensions/flicker_utils/Makefile.am
@@ -29,7 +29,8 @@ libflicker_utils_la_SOURCES = \
flickr-types.h \
flickr-user.c \
flickr-user.h \
- main.c
+ main.c \
+ preferences.h
libflicker_utils_la_CFLAGS = $(GTHUMB_CFLAGS) $(LIBSOUP_CFLAGS) $(GNOME_KEYRING_CFLAGS) -I$(top_srcdir) -I$(top_builddir)/gthumb
libflicker_utils_la_LDFLAGS = $(EXTENSION_LIBTOOL_FLAGS)
diff --git a/extensions/flicker_utils/data/ui/export-to-flickr.ui b/extensions/flicker_utils/data/ui/export-to-flickr.ui
index cc93d93..0bc531a 100644
--- a/extensions/flicker_utils/data/ui/export-to-flickr.ui
+++ b/extensions/flicker_utils/data/ui/export-to-flickr.ui
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <requires lib="gtk+" version="2.24"/>
+ <!-- interface-requires gtk+ 3.0 -->
<object class="GtkListStore" id="account_liststore">
<columns>
<!-- column-name account -->
@@ -123,7 +123,7 @@
<object class="GtkTable" id="table2">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="n_rows">5</property>
+ <property name="n_rows">6</property>
<property name="n_columns">2</property>
<property name="column_spacing">6</property>
<property name="row_spacing">5</property>
@@ -325,7 +325,7 @@
<property name="right_attach">2</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
- <property name="y_options">GTK_FILL</property>
+ <property name="y_options"/>
</packing>
</child>
<child>
@@ -381,6 +381,68 @@
<property name="y_options">GTK_FILL</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="cellrenderertext1"/>
+ <attributes>
+ <attribute name="text">0</attribute>
+ </attributes>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="right_attach">2</property>
+ <property name="top_attach">5</property>
+ <property name="bottom_attach">6</property>
+ <property name="y_options"/>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
@@ -452,6 +514,14 @@
</row>
</data>
</object>
+ <object class="GtkListStore" id="resize_liststore">
+ <columns>
+ <!-- column-name description -->
+ <column type="gchararray"/>
+ <!-- column-name size -->
+ <column type="gint"/>
+ </columns>
+ </object>
<object class="GtkListStore" id="safety_liststore">
<columns>
<!-- column-name value -->
diff --git a/extensions/flicker_utils/dlg-export-to-flickr.c b/extensions/flicker_utils/dlg-export-to-flickr.c
index f2afc44..9847dcf 100644
--- a/extensions/flicker_utils/dlg-export-to-flickr.c
+++ b/extensions/flicker_utils/dlg-export-to-flickr.c
@@ -27,6 +27,7 @@
#include "flickr-photoset.h"
#include "flickr-service.h"
#include "flickr-user.h"
+#include "preferences.h"
#define GET_WIDGET(x) (_gtk_builder_get_widget (data->builder, (x)))
@@ -50,6 +51,7 @@ enum {
typedef struct {
FlickrServer *server;
GthBrowser *browser;
+ GSettings *settings;
GthFileData *location;
GList *file_list;
GtkBuilder *builder;
@@ -86,6 +88,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);
}
@@ -301,6 +304,8 @@ export_dialog_response_cb (GtkDialog *dialog,
{
const char *photoset_title;
GList *file_list;
+ int max_width;
+ int max_height;
gtk_widget_hide (data->dialog);
gth_task_dialog (GTH_TASK (data->conn), FALSE, NULL);
@@ -321,10 +326,23 @@ export_dialog_response_cb (GtkDialog *dialog,
}
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_FLICKR_RESIZE_WIDTH, max_width);
+ g_settings_set_int (data->settings, PREF_FLICKR_RESIZE_HEIGHT, max_height);
+
flickr_service_post_photos (data->service,
gtk_combo_box_get_active (GTK_COMBO_BOX (GET_WIDGET ("privacy_combobox"))),
gtk_combo_box_get_active (GTK_COMBO_BOX (GET_WIDGET ("safety_combobox"))),
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("hidden_checkbutton"))),
+ max_width,
+ max_height,
file_list,
data->cancellable,
post_photos_ready_cb,
@@ -479,6 +497,21 @@ account_combobox_changed_cb (GtkComboBox *widget,
}
+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_flickr (FlickrServer *server,
GthBrowser *browser,
@@ -495,6 +528,7 @@ dlg_export_to_flickr (FlickrServer *server,
data = g_new0 (DialogData, 1);
data->server = server;
data->browser = browser;
+ data->settings = g_settings_new (GTHUMB_FLICKR_SCHEMA);
data->location = gth_file_data_dup (gth_browser_get_location_data (browser));
data->builder = _gtk_builder_new_from_file ("export-to-flickr.ui", "flicker_utils");
data->dialog = _gtk_builder_get_widget (data->builder, "export_dialog");
@@ -590,6 +624,13 @@ dlg_export_to_flickr (FlickrServer *server,
gtk_window_set_title (GTK_WINDOW (data->dialog), title);
g_free (title);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("resize_checkbutton")),
+ g_settings_get_int (data->settings, PREF_FLICKR_RESIZE_WIDTH) != -1);
+
+ _gtk_combo_box_add_image_sizes (GTK_COMBO_BOX (GET_WIDGET ("resize_combobox")),
+ g_settings_get_int (data->settings, PREF_FLICKR_RESIZE_WIDTH),
+ g_settings_get_int (data->settings, PREF_FLICKR_RESIZE_HEIGHT));
+
/* Set the signals handlers. */
g_signal_connect (data->dialog,
@@ -608,6 +649,12 @@ dlg_export_to_flickr (FlickrServer *server,
"changed",
G_CALLBACK (account_combobox_changed_cb),
data);
+ g_signal_connect (GET_WIDGET ("resize_checkbutton"),
+ "toggled",
+ G_CALLBACK (resize_checkbutton_toggled_cb),
+ data);
+
+ update_sensitivity (data);
data->conn = flickr_connection_new (data->server);
data->service = flickr_service_new (data->conn);
diff --git a/extensions/flicker_utils/flickr-service.c b/extensions/flicker_utils/flickr-service.c
index 79fc0ac..f63b47c 100644
--- a/extensions/flicker_utils/flickr-service.c
+++ b/extensions/flicker_utils/flickr-service.c
@@ -41,6 +41,8 @@ typedef struct {
FlickrPrivacyType privacy_level;
FlickrSafetyType safety_level;
gboolean hidden;
+ int max_width;
+ int max_height;
GList *file_list;
GCancellable *cancellable;
GAsyncReadyCallback callback;
@@ -765,6 +767,8 @@ post_photo_file_buffer_ready_cb (void **buffer,
SoupMultipart *multipart;
char *uri;
SoupBuffer *body;
+ void *resized_buffer;
+ gsize resized_count;
SoupMessage *msg;
if (error != NULL) {
@@ -823,8 +827,28 @@ post_photo_file_buffer_ready_cb (void **buffer,
/* the file part */
+ 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;
+ }
+
uri = g_file_get_uri (file_data->file);
- body = soup_buffer_new (SOUP_MEMORY_TEMPORARY, *buffer, count);
soup_multipart_append_form_file (multipart,
"photo",
uri,
@@ -906,6 +930,8 @@ flickr_service_post_photos (FlickrService *self,
FlickrPrivacyType privacy_level,
FlickrSafetyType safety_level,
gboolean hidden,
+ int max_width,
+ int max_height,
GList *file_list, /* GFile list */
GCancellable *cancellable,
GAsyncReadyCallback callback,
@@ -918,6 +944,8 @@ flickr_service_post_photos (FlickrService *self,
self->priv->post_photos->privacy_level = privacy_level;
self->priv->post_photos->safety_level = safety_level;
self->priv->post_photos->hidden = hidden;
+ 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/flicker_utils/flickr-service.h b/extensions/flicker_utils/flickr-service.h
index 558c261..8eb89ac 100644
--- a/extensions/flicker_utils/flickr-service.h
+++ b/extensions/flicker_utils/flickr-service.h
@@ -102,6 +102,8 @@ void flickr_service_post_photos (FlickrService
FlickrPrivacyType privacy_level,
FlickrSafetyType safety_level,
gboolean hidden,
+ int max_width,
+ int max_height,
GList *file_list, /* GFile list */
GCancellable *cancellable,
GAsyncReadyCallback callback,
diff --git a/extensions/flicker_utils/preferences.h b/extensions/flicker_utils/preferences.h
new file mode 100644
index 0000000..62b38f1
--- /dev/null
+++ b/extensions/flicker_utils/preferences.h
@@ -0,0 +1,34 @@
+/* -*- 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef PREFERENCES_H
+#define PREFERENCES_H
+
+/* schema */
+
+#define GTHUMB_FLICKR_SCHEMA GTHUMB_SCHEMA ".flickr"
+
+/* keys */
+
+#define PREF_FLICKR_RESIZE_WIDTH "resize-width"
+#define PREF_FLICKR_RESIZE_HEIGHT "resize-height"
+
+#endif /* PREFERENCES_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]