[gthumb] allow to specify the format options when saving a file



commit 73e53814b024140e413fd48c3c7fa0746404b56e
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun Aug 26 11:50:28 2012 +0200

    allow to specify the format options when saving a file

 data/org.gnome.gthumb.gschema.xml.in            |   29 +++++---
 extensions/image_viewer/gth-image-viewer-page.c |    3 +
 gthumb/gth-file-chooser-dialog.c                |   88 +++++++++++++++++++++-
 gthumb/gth-preferences.h                        |    5 ++
 4 files changed, 110 insertions(+), 15 deletions(-)
---
diff --git a/data/org.gnome.gthumb.gschema.xml.in b/data/org.gnome.gthumb.gschema.xml.in
index 3083545..c2cbb3c 100644
--- a/data/org.gnome.gthumb.gschema.xml.in
+++ b/data/org.gnome.gthumb.gschema.xml.in
@@ -1,18 +1,18 @@
 <!--
   gThumb
- 
+
   Copyright  2011 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/>.
 -->
@@ -29,7 +29,7 @@
     <child name="browser" schema="org.gnome.gthumb.browser" />
     <child name="dialogs" schema="org.gnome.gthumb.dialogs" />
   </schema>
-  
+
   <schema id="org.gnome.gthumb.general" path="/org/gnome/gthumb/general/">
     <key name="active-extensions" type="as">
       <default>[ 'default' ]</default>
@@ -38,13 +38,13 @@
       <default>true</default>
     </key>
   </schema>
-  
+
   <schema id="org.gnome.gthumb.data-migration" path="/org/gnome/gthumb/data-migration/">
     <key name="catalogs-2-10" type="b">
       <default>false</default>
     </key>
   </schema>
-  
+
   <schema id="org.gnome.gthumb.browser" path="/org/gnome/gthumb/browser/">
     <key name="go-to-last-location" type="b">
       <default>true</default>
@@ -143,12 +143,13 @@
       <_description>Open files in the active window</_description>
     </key>
   </schema>
-  
+
   <schema id="org.gnome.gthumb.dialogs" path="/org/gnome/gthumb/dialogs/">
     <child name="messages" schema="org.gnome.gthumb.dialogs.messages" />
     <child name="add-to-catalog" schema="org.gnome.gthumb.dialogs.add-to-catalog" />
+    <child name="save-file" schema="org.gnome.gthumb.dialogs.save-file" />
   </schema>
-  
+
   <schema id="org.gnome.gthumb.dialogs.messages" path="/org/gnome/gthumb/dialogs/messages/">
     <key name="cannot-move-to-trash" type="b">
       <default>true</default>
@@ -165,6 +166,12 @@
     <key name="view" type="b">
       <default>false</default>
     </key>
-  </schema>  
-  
+  </schema>
+
+  <schema id="org.gnome.gthumb.dialogs.save-file" path="/org/gnome/gthumb/dialogs/save-file/">
+    <key name="show-options" type="b">
+      <default>true</default>
+    </key>
+  </schema>
+
 </schemalist>
diff --git a/extensions/image_viewer/gth-image-viewer-page.c b/extensions/image_viewer/gth-image-viewer-page.c
index b872dfb..7c35570 100644
--- a/extensions/image_viewer/gth-image-viewer-page.c
+++ b/extensions/image_viewer/gth-image-viewer-page.c
@@ -1222,12 +1222,15 @@ save_as_response_cb (GtkDialog  *file_sel,
 	if (! gth_file_chooser_dialog_get_file (GTH_FILE_CHOOSER_DIALOG (file_sel), &file, &mime_type))
 		return;
 
+	gtk_widget_hide (GTK_WIDGET (data->file_sel));
+
 	gth_file_data_set_file (data->file_data, file);
 	_gth_image_viewer_page_real_save ((GthViewerPage *) data->self,
 					  file,
 					  mime_type,
 					  data->func,
 					  data->user_data);
+
 	gtk_widget_destroy (GTK_WIDGET (data->file_sel));
 
 	g_object_unref (file);
diff --git a/gthumb/gth-file-chooser-dialog.c b/gthumb/gth-file-chooser-dialog.c
index 2ecece9..29328a8 100644
--- a/gthumb/gth-file-chooser-dialog.c
+++ b/gthumb/gth-file-chooser-dialog.c
@@ -26,6 +26,8 @@
 #include "glib-utils.h"
 #include "gth-file-chooser-dialog.h"
 #include "gth-main.h"
+#include "gth-preferences.h"
+#include "gtk-utils.h"
 
 
 #define FORMAT_KEY "gthumb-format"
@@ -50,7 +52,8 @@ format_free (Format *format)
 
 
 struct _GthFileChooserDialogPrivate {
-	GList *supported_formats;
+	GList     *supported_formats;
+	GtkWidget *options_checkbutton;
 };
 
 
@@ -69,14 +72,34 @@ gth_file_chooser_dialog_finalize (GObject *object)
 
 
 static void
+gth_file_chooser_dialog_unmap (GtkWidget *widget)
+{
+	GthFileChooserDialog *self;
+	GSettings            *settings;
+
+	self = GTH_FILE_CHOOSER_DIALOG (widget);
+
+	settings = g_settings_new (GTHUMB_SAVE_FILE_SCHEMA);
+	g_settings_set_boolean (settings, PREF_SAVE_FILE_SHOW_OPTIONS, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->priv->options_checkbutton)));
+	g_object_unref (settings);
+
+	GTK_WIDGET_CLASS (gth_file_chooser_dialog_parent_class)->unmap (widget);
+}
+
+
+static void
 gth_file_chooser_dialog_class_init (GthFileChooserDialogClass *class)
 {
-	GObjectClass *object_class;
+	GObjectClass   *object_class;
+	GtkWidgetClass *widget_class;
 
 	g_type_class_add_private (class, sizeof (GthFileChooserDialogPrivate));
 
 	object_class = (GObjectClass*) class;
 	object_class->finalize = gth_file_chooser_dialog_finalize;
+
+	widget_class = (GtkWidgetClass*) class;
+	widget_class->unmap = gth_file_chooser_dialog_unmap;
 }
 
 
@@ -98,6 +121,7 @@ gth_file_chooser_dialog_construct (GthFileChooserDialog *self,
 	GArray        *savers;
 	int            i;
 	GList         *scan;
+	GSettings     *settings;
 
 	if (title != NULL)
     		gtk_window_set_title (GTK_WINDOW (self), title);
@@ -109,10 +133,12 @@ gth_file_chooser_dialog_construct (GthFileChooserDialog *self,
 	gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (self), TRUE);
 	gtk_dialog_set_default_response (GTK_DIALOG (self), GTK_RESPONSE_ACCEPT);
 
+	_gtk_dialog_add_to_window_group (GTK_DIALOG (self));
+
 	gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
 	gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_SAVE, GTK_RESPONSE_OK);
 
-	/**/
+	/* filters */
 
 	filter = gtk_file_filter_new ();
 	gtk_file_filter_set_name (filter, _("All Supported Files"));
@@ -160,6 +186,17 @@ gth_file_chooser_dialog_construct (GthFileChooserDialog *self,
 
 		g_object_set_data (G_OBJECT (filter), FORMAT_KEY, format);
 	}
+
+	/* extra widget */
+
+	settings = g_settings_new (GTHUMB_SAVE_FILE_SCHEMA);
+
+	self->priv->options_checkbutton = gtk_check_button_new_with_mnemonic ("_Show Format Options");
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->priv->options_checkbutton), g_settings_get_boolean (settings, PREF_SAVE_FILE_SHOW_OPTIONS));
+	gtk_widget_show (self->priv->options_checkbutton);
+	gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (self), self->priv->options_checkbutton);
+
+	g_object_unref (settings);
 }
 
 
@@ -204,6 +241,46 @@ get_format_from_extension (GthFileChooserDialog *self,
 }
 
 
+static gboolean
+_gth_file_chooser_change_format_options (GthFileChooserDialog *self,
+					 GthImageSaver        *saver)
+{
+	GtkWidget *d;
+	GtkWidget *control;
+	gboolean   result;
+
+	d = gtk_dialog_new_with_buttons (_("Options"),
+					 GTK_WINDOW (self),
+					 GTK_DIALOG_MODAL,
+					 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+					 GTK_STOCK_OK, GTK_RESPONSE_OK,
+					 NULL);
+	_gtk_dialog_add_to_window_group (GTK_DIALOG (d));
+
+	gtk_container_set_border_width (GTK_CONTAINER (d), 6);
+	gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (d))), 0);
+	gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (d))), 8);
+	gtk_window_set_default_size (GTK_WINDOW (d), 400, -1);
+
+	control = gth_image_saver_get_control (saver);
+	if (control == NULL) {
+		gtk_widget_destroy (d);
+		return TRUE;
+	}
+
+	gtk_widget_show (control);
+	gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (d))), control);
+
+	result = gtk_dialog_run (GTK_DIALOG (d)) == GTK_RESPONSE_OK;
+	if (result)
+		gth_image_saver_save_options (saver);
+
+	gtk_widget_destroy (d);
+
+	return result;
+}
+
+
 gboolean
 gth_file_chooser_dialog_get_file (GthFileChooserDialog  *self,
 				  GFile                **file,
@@ -231,5 +308,8 @@ gth_file_chooser_dialog_get_file (GthFileChooserDialog  *self,
 	if (mime_type != NULL)
 		*mime_type = gth_image_saver_get_mime_type (format->saver);
 
-	return TRUE;
+	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->priv->options_checkbutton)))
+		return _gth_file_chooser_change_format_options (self, format->saver);
+	else
+		return TRUE;
 }
diff --git a/gthumb/gth-preferences.h b/gthumb/gth-preferences.h
index 08702fe..f959e3c 100644
--- a/gthumb/gth-preferences.h
+++ b/gthumb/gth-preferences.h
@@ -37,6 +37,7 @@ G_BEGIN_DECLS
 #define GTHUMB_DIALOGS_SCHEMA                 GTHUMB_SCHEMA ".dialogs"
 #define GTHUMB_MESSAGES_SCHEMA                GTHUMB_DIALOGS_SCHEMA ".messages"
 #define GTHUMB_ADD_TO_CATALOG_SCHEMA          GTHUMB_DIALOGS_SCHEMA ".add-to-catalog"
+#define GTHUMB_SAVE_FILE_SCHEMA               GTHUMB_DIALOGS_SCHEMA ".save-file"
 
 /* keys: general */
 
@@ -86,6 +87,10 @@ G_BEGIN_DECLS
 #define PREF_ADD_TO_CATALOG_LAST_CATALOG      "last-catalog"
 #define PREF_ADD_TO_CATALOG_VIEW              "view"
 
+/* keys: save file */
+
+#define PREF_SAVE_FILE_SHOW_OPTIONS           "show-options"
+
 /* keys: messages */
 
 #define PREF_MSG_CANNOT_MOVE_TO_TRASH         "cannot-move-to-trash"



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