[gthumb] added ability to specify the file extension to use when creating jpeg and tiff files



commit 8438fd24ec2c1b63aa62b41a1a12e0d39d2327dc
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sat Jan 15 22:05:36 2011 +0100

    added ability to specify the file extension to use when creating jpeg and tiff files
    
    Allow the user to use .jpeg or .jpg as file extension when creating new jpeg images, and .tiff or .tif for Tiff images.
    
    [new feature]

 .../data/gthumb-pixbuf-savers.schemas.in           |   26 +++
 extensions/pixbuf_savers/data/ui/jpeg-options.ui   |  233 ++++++++++++--------
 extensions/pixbuf_savers/data/ui/tiff-options.ui   |   58 +++++-
 extensions/pixbuf_savers/gth-jpeg-saver.c          |   51 ++++-
 extensions/pixbuf_savers/gth-png-saver.c           |    2 +-
 extensions/pixbuf_savers/gth-tga-saver.c           |    2 +-
 extensions/pixbuf_savers/gth-tiff-saver.c          |   49 ++++-
 extensions/pixbuf_savers/preferences.h             |    2 +
 gthumb/gth-pixbuf-saver.c                          |    5 +-
 gthumb/gth-pixbuf-saver.h                          |   22 +-
 10 files changed, 334 insertions(+), 116 deletions(-)
---
diff --git a/extensions/pixbuf_savers/data/gthumb-pixbuf-savers.schemas.in b/extensions/pixbuf_savers/data/gthumb-pixbuf-savers.schemas.in
index 3b2e3d7..2796ceb 100644
--- a/extensions/pixbuf_savers/data/gthumb-pixbuf-savers.schemas.in
+++ b/extensions/pixbuf_savers/data/gthumb-pixbuf-savers.schemas.in
@@ -4,6 +4,19 @@
       <!-- JPEG Options -->
 
       <schema>
+	<key>/schemas/apps/gthumb/save_options/jpeg/default_ext</key>
+	<applyto>/apps/gthumb/save_options/jpeg/default_ext</applyto>
+	<owner>gthumb</owner>
+	<type>string</type>
+	<default>jpeg</default>
+	<locale name="C">
+	  <short></short>
+	  <long> Possible values are: jpeg, jpg.
+	  </long>
+	</locale>
+      </schema>
+
+      <schema>
 	<key>/schemas/apps/gthumb/save_options/jpeg/quality</key>
 	<applyto>/apps/gthumb/save_options/jpeg/quality</applyto>
 	<owner>gthumb</owner>
@@ -88,6 +101,19 @@
       <!-- TIFF Options -->
 
       <schema>
+	<key>/schemas/apps/gthumb/save_options/tiff/default_ext</key>
+	<applyto>/apps/gthumb/save_options/tiff/default_ext</applyto>
+	<owner>gthumb</owner>
+	<type>string</type>
+	<default>tiff</default>
+	<locale name="C">
+	  <short></short>
+	  <long> Possible values are: tiff, tif.
+	  </long>
+	</locale>
+      </schema>
+
+      <schema>
 	<key>/schemas/apps/gthumb/save_options/tiff/compression</key>
 	<applyto>/apps/gthumb/save_options/tiff/compression</applyto>
 	<owner>gthumb</owner>
diff --git a/extensions/pixbuf_savers/data/ui/jpeg-options.ui b/extensions/pixbuf_savers/data/ui/jpeg-options.ui
index a84b60d..9f255ae 100644
--- a/extensions/pixbuf_savers/data/ui/jpeg-options.ui
+++ b/extensions/pixbuf_savers/data/ui/jpeg-options.ui
@@ -13,107 +13,162 @@
     <property name="step_increment">0.5</property>
     <property name="page_increment">1</property>
   </object>
-  <object class="GtkTable" id="jpeg_options">
+  <object class="GtkListStore" id="jpeg_default_ext_liststore">
+    <columns>
+      <!-- column-name name -->
+      <column type="gchararray"/>
+    </columns>
+  </object>
+  <object class="GtkVBox" id="jpeg_options">
     <property name="visible">True</property>
     <property name="border_width">6</property>
-    <property name="n_rows">4</property>
-    <property name="n_columns">2</property>
-    <property name="column_spacing">12</property>
-    <property name="row_spacing">6</property>
-    <child>
-      <object class="GtkCheckButton" id="jpeg_optimize_checkbutton">
-        <property name="label" translatable="yes">Opti_mize</property>
-        <property name="visible">True</property>
-        <property name="can_focus">True</property>
-        <property name="receives_default">False</property>
-        <property name="use_underline">True</property>
-        <property name="active">True</property>
-        <property name="draw_indicator">True</property>
-      </object>
-      <packing>
-        <property name="right_attach">2</property>
-        <property name="top_attach">2</property>
-        <property name="bottom_attach">3</property>
-        <property name="x_options">GTK_FILL</property>
-        <property name="y_options"></property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkCheckButton" id="jpeg_progressive_checkbutton">
-        <property name="label" translatable="yes">_Progressive</property>
-        <property name="visible">True</property>
-        <property name="can_focus">True</property>
-        <property name="receives_default">False</property>
-        <property name="use_underline">True</property>
-        <property name="draw_indicator">True</property>
-      </object>
-      <packing>
-        <property name="right_attach">2</property>
-        <property name="top_attach">3</property>
-        <property name="bottom_attach">4</property>
-        <property name="x_options">GTK_FILL</property>
-        <property name="y_options"></property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkLabel" id="label127">
-        <property name="visible">True</property>
-        <property name="xalign">0</property>
-        <property name="label" translatable="yes">_Quality:</property>
-        <property name="use_underline">True</property>
-        <property name="mnemonic_widget">jpeg_quality_hscale</property>
-      </object>
-      <packing>
-        <property name="x_options">GTK_FILL</property>
-        <property name="y_options">GTK_FILL</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkHScale" id="jpeg_quality_hscale">
-        <property name="width_request">150</property>
-        <property name="visible">True</property>
-        <property name="can_focus">True</property>
-        <property name="adjustment">jpeg_quality_adjustment</property>
-        <property name="digits">0</property>
-        <property name="value_pos">left</property>
-      </object>
-      <packing>
-        <property name="left_attach">1</property>
-        <property name="right_attach">2</property>
-        <property name="y_options">GTK_FILL</property>
-      </packing>
-    </child>
+    <property name="spacing">12</property>
     <child>
-      <object class="GtkHScale" id="jpeg_smooth_hscale">
-        <property name="width_request">150</property>
+      <object class="GtkHBox" id="hbox2">
         <property name="visible">True</property>
-        <property name="can_focus">True</property>
-        <property name="adjustment">jpeg_smooth_adjustment</property>
-        <property name="digits">0</property>
-        <property name="value_pos">left</property>
+        <property name="spacing">6</property>
+        <child>
+          <object class="GtkLabel" id="label1">
+            <property name="visible">True</property>
+            <property name="xalign">0</property>
+            <property name="label" translatable="yes">_Default extension:</property>
+            <property name="use_underline">True</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkComboBox" id="jpeg_default_extension_combobox">
+            <property name="visible">True</property>
+            <property name="model">jpeg_default_ext_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="position">1</property>
+          </packing>
+        </child>
       </object>
       <packing>
-        <property name="left_attach">1</property>
-        <property name="right_attach">2</property>
-        <property name="top_attach">1</property>
-        <property name="bottom_attach">2</property>
-        <property name="x_options">GTK_FILL</property>
-        <property name="y_options">GTK_FILL</property>
+        <property name="expand">False</property>
+        <property name="position">0</property>
       </packing>
     </child>
     <child>
-      <object class="GtkLabel" id="label130">
+      <object class="GtkTable" id="table1">
         <property name="visible">True</property>
-        <property name="xalign">0</property>
-        <property name="label" translatable="yes">_Smoothing:</property>
-        <property name="use_underline">True</property>
-        <property name="mnemonic_widget">jpeg_smooth_hscale</property>
+        <property name="n_rows">4</property>
+        <property name="n_columns">2</property>
+        <property name="column_spacing">12</property>
+        <property name="row_spacing">6</property>
+        <child>
+          <object class="GtkCheckButton" id="jpeg_optimize_checkbutton">
+            <property name="label" translatable="yes">Opti_mize</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">False</property>
+            <property name="use_underline">True</property>
+            <property name="active">True</property>
+            <property name="draw_indicator">True</property>
+          </object>
+          <packing>
+            <property name="right_attach">2</property>
+            <property name="top_attach">2</property>
+            <property name="bottom_attach">3</property>
+            <property name="x_options">GTK_FILL</property>
+            <property name="y_options"></property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkCheckButton" id="jpeg_progressive_checkbutton">
+            <property name="label" translatable="yes">_Progressive</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">False</property>
+            <property name="use_underline">True</property>
+            <property name="draw_indicator">True</property>
+          </object>
+          <packing>
+            <property name="right_attach">2</property>
+            <property name="top_attach">3</property>
+            <property name="bottom_attach">4</property>
+            <property name="x_options">GTK_FILL</property>
+            <property name="y_options"></property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label127">
+            <property name="visible">True</property>
+            <property name="xalign">0</property>
+            <property name="label" translatable="yes">_Quality:</property>
+            <property name="use_underline">True</property>
+            <property name="mnemonic_widget">jpeg_quality_hscale</property>
+          </object>
+          <packing>
+            <property name="x_options">GTK_FILL</property>
+            <property name="y_options">GTK_FILL</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkHScale" id="jpeg_quality_hscale">
+            <property name="width_request">150</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="adjustment">jpeg_quality_adjustment</property>
+            <property name="digits">0</property>
+            <property name="value_pos">left</property>
+          </object>
+          <packing>
+            <property name="left_attach">1</property>
+            <property name="right_attach">2</property>
+            <property name="x_options">GTK_FILL</property>
+            <property name="y_options">GTK_FILL</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkHScale" id="jpeg_smooth_hscale">
+            <property name="width_request">150</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="adjustment">jpeg_smooth_adjustment</property>
+            <property name="digits">0</property>
+            <property name="value_pos">left</property>
+          </object>
+          <packing>
+            <property name="left_attach">1</property>
+            <property name="right_attach">2</property>
+            <property name="top_attach">1</property>
+            <property name="bottom_attach">2</property>
+            <property name="x_options">GTK_FILL</property>
+            <property name="y_options">GTK_FILL</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label130">
+            <property name="visible">True</property>
+            <property name="xalign">0</property>
+            <property name="label" translatable="yes">_Smoothing:</property>
+            <property name="use_underline">True</property>
+            <property name="mnemonic_widget">jpeg_smooth_hscale</property>
+          </object>
+          <packing>
+            <property name="top_attach">1</property>
+            <property name="bottom_attach">2</property>
+            <property name="x_options">GTK_FILL</property>
+            <property name="y_options">GTK_FILL</property>
+          </packing>
+        </child>
       </object>
       <packing>
-        <property name="top_attach">1</property>
-        <property name="bottom_attach">2</property>
-        <property name="x_options">GTK_FILL</property>
-        <property name="y_options">GTK_FILL</property>
+        <property name="position">1</property>
       </packing>
     </child>
   </object>
diff --git a/extensions/pixbuf_savers/data/ui/tiff-options.ui b/extensions/pixbuf_savers/data/ui/tiff-options.ui
index e33c512..b84d3be 100644
--- a/extensions/pixbuf_savers/data/ui/tiff-options.ui
+++ b/extensions/pixbuf_savers/data/ui/tiff-options.ui
@@ -3,28 +3,66 @@
   <requires lib="gtk+" version="2.16"/>
   <!-- interface-naming-policy toplevel-contextual -->
   <object class="GtkAdjustment" id="tiff_hdpi_adjustment">
+    <property name="value">72</property>
     <property name="lower">1</property>
     <property name="upper">10000</property>
-    <property name="value">72</property>
     <property name="step_increment">1</property>
     <property name="page_increment">10</property>
   </object>
   <object class="GtkAdjustment" id="tiff_vdpi_adjustment">
+    <property name="value">72</property>
     <property name="lower">1</property>
     <property name="upper">10000</property>
-    <property name="value">72</property>
     <property name="step_increment">1</property>
     <property name="page_increment">10</property>
   </object>
   <object class="GtkVBox" id="tiff_options">
     <property name="visible">True</property>
     <property name="border_width">6</property>
-    <property name="orientation">vertical</property>
     <property name="spacing">12</property>
     <child>
+      <object class="GtkHBox" id="hbox1">
+        <property name="visible">True</property>
+        <property name="spacing">6</property>
+        <child>
+          <object class="GtkLabel" id="label1">
+            <property name="visible">True</property>
+            <property name="xalign">0</property>
+            <property name="label" translatable="yes">_Default extension:</property>
+            <property name="use_underline">True</property>
+            <property name="mnemonic_widget">tiff_default_extension_combobox</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkComboBox" id="tiff_default_extension_combobox">
+            <property name="visible">True</property>
+            <property name="model">tiff_default_ext_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="position">1</property>
+          </packing>
+        </child>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="position">0</property>
+      </packing>
+    </child>
+    <child>
       <object class="GtkVBox" id="vbox43">
         <property name="visible">True</property>
-        <property name="orientation">vertical</property>
         <property name="spacing">6</property>
         <child>
           <object class="GtkLabel" id="label128">
@@ -48,7 +86,6 @@
             <child>
               <object class="GtkVBox" id="vbox44">
                 <property name="visible">True</property>
-                <property name="orientation">vertical</property>
                 <property name="spacing">6</property>
                 <child>
                   <object class="GtkRadioButton" id="tiff_comp_none_radiobutton">
@@ -108,13 +145,12 @@
       </object>
       <packing>
         <property name="expand">False</property>
-        <property name="position">0</property>
+        <property name="position">1</property>
       </packing>
     </child>
     <child>
       <object class="GtkVBox" id="vbox48">
         <property name="visible">True</property>
-        <property name="orientation">vertical</property>
         <property name="spacing">6</property>
         <child>
           <object class="GtkLabel" id="label132">
@@ -251,8 +287,14 @@
       </object>
       <packing>
         <property name="expand">False</property>
-        <property name="position">1</property>
+        <property name="position">2</property>
       </packing>
     </child>
   </object>
+  <object class="GtkListStore" id="tiff_default_ext_liststore">
+    <columns>
+      <!-- column-name name -->
+      <column type="gchararray"/>
+    </columns>
+  </object>
 </interface>
diff --git a/extensions/pixbuf_savers/gth-jpeg-saver.c b/extensions/pixbuf_savers/gth-jpeg-saver.c
index 2a5ea30..ced0738 100644
--- a/extensions/pixbuf_savers/gth-jpeg-saver.c
+++ b/extensions/pixbuf_savers/gth-jpeg-saver.c
@@ -37,6 +37,7 @@
 
 struct _GthJpegSaverPrivate {
 	GtkBuilder *builder;
+	char       *default_ext;
 };
 
 
@@ -47,6 +48,8 @@ static void
 gth_jpeg_saver_init (GthJpegSaver *self)
 {
 	self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTH_TYPE_JPEG_SAVER, GthJpegSaverPrivate);
+	self->priv->builder = NULL;
+	self->priv->default_ext = NULL;
 }
 
 
@@ -56,18 +59,51 @@ gth_jpeg_saver_finalize (GObject *object)
 	GthJpegSaver *self = GTH_JPEG_SAVER (object);
 
 	_g_object_unref (self->priv->builder);
+	g_free (self->priv->default_ext);
+
 	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 
+static const char *
+gth_jpeg_saver_get_default_ext (GthPixbufSaver *base)
+{
+	GthJpegSaver *self = GTH_JPEG_SAVER (base);
+
+	if (self->priv->default_ext == NULL)
+		self->priv->default_ext = eel_gconf_get_string (PREF_JPEG_DEFAULT_EXT, "jpeg");
+
+	return self->priv->default_ext;
+}
+
+
 static GtkWidget *
 gth_jpeg_saver_get_control (GthPixbufSaver *base)
 {
-	GthJpegSaver *self = GTH_JPEG_SAVER (base);
+	GthJpegSaver  *self = GTH_JPEG_SAVER (base);
+	char         **extensions;
+	int            i;
+	int            active_idx;
 
 	if (self->priv->builder == NULL)
 		self->priv->builder = _gtk_builder_new_from_file ("jpeg-options.ui", "pixbuf_savers");
 
+	active_idx = 0;
+	extensions = g_strsplit (gth_pixbuf_saver_get_extensions (base), " ", -1);
+	for (i = 0; extensions[i] != NULL; i++) {
+		GtkTreeIter iter;
+
+		gtk_list_store_append (GTK_LIST_STORE (gtk_builder_get_object (self->priv->builder, "jpeg_default_ext_liststore")), &iter);
+		gtk_list_store_set (GTK_LIST_STORE (gtk_builder_get_object (self->priv->builder, "jpeg_default_ext_liststore")),
+				    &iter,
+				    0, extensions[i],
+				    -1);
+		if (g_str_equal (extensions[i], gth_pixbuf_saver_get_default_ext (base)))
+			active_idx = i;
+	}
+	gtk_combo_box_set_active (GTK_COMBO_BOX (_gtk_builder_get_widget (self->priv->builder, "jpeg_default_extension_combobox")), active_idx);
+	g_strfreev (extensions);
+
 	gtk_adjustment_set_value (GTK_ADJUSTMENT (_gtk_builder_get_widget (self->priv->builder, "jpeg_quality_adjustment")),
 				  eel_gconf_get_integer (PREF_JPEG_QUALITY, 85));
 	gtk_adjustment_set_value (GTK_ADJUSTMENT (_gtk_builder_get_widget (self->priv->builder, "jpeg_smooth_adjustment")),
@@ -85,7 +121,16 @@ static void
 gth_jpeg_saver_save_options (GthPixbufSaver *base)
 {
 	GthJpegSaver *self = GTH_JPEG_SAVER (base);
-
+	GtkTreeIter   iter;
+
+	if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (_gtk_builder_get_widget (self->priv->builder, "jpeg_default_extension_combobox")), &iter)) {
+		g_free (self->priv->default_ext);
+		gtk_tree_model_get (GTK_TREE_MODEL (gtk_builder_get_object (self->priv->builder, "jpeg_default_ext_liststore")),
+				    &iter,
+				    0, &self->priv->default_ext,
+				    -1);
+		eel_gconf_set_string (PREF_JPEG_DEFAULT_EXT, self->priv->default_ext);
+	}
 	eel_gconf_set_integer (PREF_JPEG_QUALITY, (int) gtk_adjustment_get_value (GTK_ADJUSTMENT (_gtk_builder_get_widget (self->priv->builder, "jpeg_quality_adjustment"))));
 	eel_gconf_set_integer (PREF_JPEG_SMOOTHING, (int) gtk_adjustment_get_value (GTK_ADJUSTMENT (_gtk_builder_get_widget (self->priv->builder, "jpeg_smooth_adjustment"))));
 	eel_gconf_set_boolean (PREF_JPEG_OPTIMIZE, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (_gtk_builder_get_widget (self->priv->builder, "jpeg_optimize_checkbutton"))));
@@ -478,7 +523,7 @@ gth_jpeg_saver_class_init (GthJpegSaverClass *klass)
 	pixbuf_saver_class->display_name = _("JPEG");
 	pixbuf_saver_class->mime_type = "image/jpeg";
 	pixbuf_saver_class->extensions = "jpeg jpg";
-	pixbuf_saver_class->default_ext = "jpeg";
+	pixbuf_saver_class->get_default_ext = gth_jpeg_saver_get_default_ext;
 	pixbuf_saver_class->get_control = gth_jpeg_saver_get_control;
 	pixbuf_saver_class->save_options = gth_jpeg_saver_save_options;
 	pixbuf_saver_class->can_save = gth_jpeg_saver_can_save;
diff --git a/extensions/pixbuf_savers/gth-png-saver.c b/extensions/pixbuf_savers/gth-png-saver.c
index f4537be..f471618 100644
--- a/extensions/pixbuf_savers/gth-png-saver.c
+++ b/extensions/pixbuf_savers/gth-png-saver.c
@@ -145,7 +145,7 @@ gth_png_saver_class_init (GthPngSaverClass *klass)
 	pixbuf_saver_class->display_name = _("PNG");
 	pixbuf_saver_class->mime_type = "image/png";
 	pixbuf_saver_class->extensions = "png";
-	pixbuf_saver_class->default_ext = "png";
+	pixbuf_saver_class->get_default_ext = NULL;
 	pixbuf_saver_class->get_control = gth_png_saver_get_control;
 	pixbuf_saver_class->save_options = gth_png_saver_save_options;
 	pixbuf_saver_class->can_save = gth_png_saver_can_save;
diff --git a/extensions/pixbuf_savers/gth-tga-saver.c b/extensions/pixbuf_savers/gth-tga-saver.c
index bc817ef..45e4224 100644
--- a/extensions/pixbuf_savers/gth-tga-saver.c
+++ b/extensions/pixbuf_savers/gth-tga-saver.c
@@ -378,7 +378,7 @@ gth_tga_saver_class_init (GthTgaSaverClass *klass)
 	pixbuf_saver_class->display_name = _("TGA");
 	pixbuf_saver_class->mime_type = "image/x-tga";
 	pixbuf_saver_class->extensions = "tga";
-	pixbuf_saver_class->default_ext = "tga";
+	pixbuf_saver_class->get_default_ext = NULL;
 	pixbuf_saver_class->get_control = gth_tga_saver_get_control;
 	pixbuf_saver_class->save_options = gth_tga_saver_save_options;
 	pixbuf_saver_class->can_save = gth_tga_saver_can_save;
diff --git a/extensions/pixbuf_savers/gth-tiff-saver.c b/extensions/pixbuf_savers/gth-tiff-saver.c
index 5e3dc6d..4ec5f93 100644
--- a/extensions/pixbuf_savers/gth-tiff-saver.c
+++ b/extensions/pixbuf_savers/gth-tiff-saver.c
@@ -32,6 +32,7 @@
 
 struct _GthTiffSaverPrivate {
 	GtkBuilder *builder;
+	char       *default_ext;
 };
 
 
@@ -42,6 +43,8 @@ static void
 gth_tiff_saver_init (GthTiffSaver *self)
 {
 	self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTH_TYPE_TIFF_SAVER, GthTiffSaverPrivate);
+	self->priv->builder = NULL;
+	self->priv->default_ext = NULL;
 }
 
 
@@ -51,21 +54,53 @@ gth_tiff_saver_finalize (GObject *object)
 	GthTiffSaver *self = GTH_TIFF_SAVER (object);
 
 	_g_object_unref (self->priv->builder);
+	g_free (self->priv->default_ext);
+
 	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 
+static const char *
+gth_tiff_saver_get_default_ext (GthPixbufSaver *base)
+{
+	GthTiffSaver *self = GTH_TIFF_SAVER (base);
+
+	if (self->priv->default_ext == NULL)
+		self->priv->default_ext = eel_gconf_get_string (PREF_TIFF_DEFAULT_EXT, "tiff");
+
+	return self->priv->default_ext;
+}
+
 static GtkWidget *
 gth_tiff_saver_get_control (GthPixbufSaver *base)
 {
 #ifdef HAVE_LIBTIFF
 
 	GthTiffSaver       *self = GTH_TIFF_SAVER (base);
+	char              **extensions;
+	int                 i;
+	int                 active_idx;
 	GthTiffCompression  compression_type;
 
 	if (self->priv->builder == NULL)
 		self->priv->builder = _gtk_builder_new_from_file ("tiff-options.ui", "pixbuf_savers");
 
+	active_idx = 0;
+	extensions = g_strsplit (gth_pixbuf_saver_get_extensions (base), " ", -1);
+	for (i = 0; extensions[i] != NULL; i++) {
+		GtkTreeIter iter;
+
+		gtk_list_store_append (GTK_LIST_STORE (gtk_builder_get_object (self->priv->builder, "tiff_default_ext_liststore")), &iter);
+		gtk_list_store_set (GTK_LIST_STORE (gtk_builder_get_object (self->priv->builder, "tiff_default_ext_liststore")),
+				    &iter,
+				    0, extensions[i],
+				    -1);
+		if (g_str_equal (extensions[i], gth_pixbuf_saver_get_default_ext (base)))
+			active_idx = i;
+	}
+	gtk_combo_box_set_active (GTK_COMBO_BOX (_gtk_builder_get_widget (self->priv->builder, "tiff_default_extension_combobox")), active_idx);
+	g_strfreev (extensions);
+
 	compression_type = eel_gconf_get_enum (PREF_TIFF_COMPRESSION, GTH_TYPE_TIFF_COMPRESSION, GTH_TIFF_COMPRESSION_DEFLATE);
 	switch (compression_type) {
 	case GTH_TIFF_COMPRESSION_NONE:
@@ -97,9 +132,19 @@ gth_tiff_saver_save_options (GthPixbufSaver *base)
 {
 #ifdef HAVE_LIBTIFF
 
-	GthTiffSaver     *self = GTH_TIFF_SAVER (base);
+	GthTiffSaver       *self = GTH_TIFF_SAVER (base);
+	GtkTreeIter         iter;
 	GthTiffCompression  compression_type;
 
+	if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (_gtk_builder_get_widget (self->priv->builder, "tiff_default_extension_combobox")), &iter)) {
+		g_free (self->priv->default_ext);
+		gtk_tree_model_get (GTK_TREE_MODEL (gtk_builder_get_object (self->priv->builder, "tiff_default_ext_liststore")),
+				    &iter,
+				    0, &self->priv->default_ext,
+				    -1);
+		eel_gconf_set_string (PREF_TIFF_DEFAULT_EXT, self->priv->default_ext);
+	}
+
 	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (_gtk_builder_get_widget (self->priv->builder, "tiff_comp_none_radiobutton"))))
 		compression_type = GTH_TIFF_COMPRESSION_NONE;
 	else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (_gtk_builder_get_widget (self->priv->builder, "tiff_comp_deflate_radiobutton"))))
@@ -497,7 +542,7 @@ gth_tiff_saver_class_init (GthTiffSaverClass *klass)
 	pixbuf_saver_class->display_name = _("TIFF");
 	pixbuf_saver_class->mime_type = "image/tiff";
 	pixbuf_saver_class->extensions = "tiff tif";
-	pixbuf_saver_class->default_ext = "tiff";
+	pixbuf_saver_class->get_default_ext = gth_tiff_saver_get_default_ext;
 	pixbuf_saver_class->get_control = gth_tiff_saver_get_control;
 	pixbuf_saver_class->save_options = gth_tiff_saver_save_options;
 	pixbuf_saver_class->can_save = gth_tiff_saver_can_save;
diff --git a/extensions/pixbuf_savers/preferences.h b/extensions/pixbuf_savers/preferences.h
index 3aa99b5..1ed890e 100644
--- a/extensions/pixbuf_savers/preferences.h
+++ b/extensions/pixbuf_savers/preferences.h
@@ -32,12 +32,14 @@ typedef enum {
 } GthTiffCompression;
 
 
+#define  PREF_JPEG_DEFAULT_EXT          "/apps/gthumb/save_options/jpeg/default_ext"
 #define  PREF_JPEG_QUALITY              "/apps/gthumb/save_options/jpeg/quality"
 #define  PREF_JPEG_SMOOTHING            "/apps/gthumb/save_options/jpeg/smoothing"
 #define  PREF_JPEG_OPTIMIZE             "/apps/gthumb/save_options/jpeg/optimize"
 #define  PREF_JPEG_PROGRESSIVE          "/apps/gthumb/save_options/jpeg/progressive"
 #define  PREF_PNG_COMPRESSION_LEVEL     "/apps/gthumb/save_options/png/compression_level"
 #define  PREF_TGA_RLE_COMPRESSION       "/apps/gthumb/save_options/tga/rle_compression"
+#define  PREF_TIFF_DEFAULT_EXT          "/apps/gthumb/save_options/tiff/default_ext"
 #define  PREF_TIFF_COMPRESSION          "/apps/gthumb/save_options/tiff/compression"
 #define  PREF_TIFF_HORIZONTAL_RES       "/apps/gthumb/save_options/tiff/horizontal_resolution"
 #define  PREF_TIFF_VERTICAL_RES         "/apps/gthumb/save_options/tiff/vertical_resolution"
diff --git a/gthumb/gth-pixbuf-saver.c b/gthumb/gth-pixbuf-saver.c
index fed869d..fb74115 100644
--- a/gthumb/gth-pixbuf-saver.c
+++ b/gthumb/gth-pixbuf-saver.c
@@ -135,7 +135,10 @@ gth_pixbuf_saver_get_extensions (GthPixbufSaver *self)
 const char *
 gth_pixbuf_saver_get_default_ext (GthPixbufSaver *self)
 {
-	return GTH_PIXBUF_SAVER_GET_CLASS (self)->default_ext;
+	if (GTH_PIXBUF_SAVER_GET_CLASS (self)->get_default_ext != NULL)
+		return GTH_PIXBUF_SAVER_GET_CLASS (self)->get_default_ext (self);
+	else
+		return gth_pixbuf_saver_get_extensions (self);
 }
 
 
diff --git a/gthumb/gth-pixbuf-saver.h b/gthumb/gth-pixbuf-saver.h
index 5b6fbda..83eeaf3 100644
--- a/gthumb/gth-pixbuf-saver.h
+++ b/gthumb/gth-pixbuf-saver.h
@@ -53,20 +53,20 @@ struct _GthPixbufSaverClass
 	const char *display_name;
 	const char *mime_type;
 	const char *extensions;
-	const char *default_ext;
 
 	/*< virtual functions >*/
 
-	GtkWidget *  (*get_control)   (GthPixbufSaver   *self);
-	void         (*save_options)  (GthPixbufSaver   *self);
-	gboolean     (*can_save)      (GthPixbufSaver   *self,
-				       const char       *mime_type);
-	gboolean     (*save_pixbuf)   (GthPixbufSaver   *self,
-				       GdkPixbuf        *pixbuf,
-				       char            **buffer,
-				       gsize            *buffer_size,
-				       const char       *mime_type,
-				       GError          **error);
+	const char * (*get_default_ext) (GthPixbufSaver   *self);
+	GtkWidget *  (*get_control)     (GthPixbufSaver   *self);
+	void         (*save_options)    (GthPixbufSaver   *self);
+	gboolean     (*can_save)        (GthPixbufSaver   *self,
+				         const char       *mime_type);
+	gboolean     (*save_pixbuf)     (GthPixbufSaver   *self,
+				         GdkPixbuf        *pixbuf,
+				         char            **buffer,
+				         gsize            *buffer_size,
+				         const char       *mime_type,
+				         GError          **error);
 };
 
 GType         gth_pixbuf_saver_get_type          (void);



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