[gimp/gimp-2-10] Issue #1299 - Add selection of default export file type



commit acc15e614af0cbc3d416484ea2a0bd93e72ddb0b
Author: Richard McLean <programmer_ceds yahoo co uk>
Date:   Wed Dec 5 21:59:19 2018 +0300

    Issue #1299 - Add selection of default export file type
    
    Patch cleaned up by Alexandre Prokoudine and Michael Natterer.
    
    (cherry picked from commit bfbad0a5cae2dd4b29fc0ee8915194fde62fdcb4)

 app/config/config-enums.c        | 41 ++++++++++++++++++++++++++++++++++++++++
 app/config/config-enums.h        | 17 +++++++++++++++++
 app/config/gimpcoreconfig.c      | 15 +++++++++++++++
 app/config/gimpcoreconfig.h      |  1 +
 app/config/gimprc-blurbs.h       |  3 +++
 app/dialogs/preferences-dialog.c | 33 +++++++++++++++++++++++++-------
 app/widgets/gimpexportdialog.c   | 22 ++++++++++++++++++---
 7 files changed, 122 insertions(+), 10 deletions(-)
---
diff --git a/app/config/config-enums.c b/app/config/config-enums.c
index 9c9d9c22ce..70da0248a1 100644
--- a/app/config/config-enums.c
+++ b/app/config/config-enums.c
@@ -101,6 +101,47 @@ gimp_cursor_mode_get_type (void)
   return type;
 }
 
+GType
+gimp_export_file_type_get_type (void)
+{
+  static const GEnumValue values[] =
+  {
+    { GIMP_EXPORT_FILE_PNG, "GIMP_EXPORT_FILE_PNG", "png" },
+    { GIMP_EXPORT_FILE_JPG, "GIMP_EXPORT_FILE_JPG", "jpg" },
+    { GIMP_EXPORT_FILE_ORA, "GIMP_EXPORT_FILE_ORA", "ora" },
+    { GIMP_EXPORT_FILE_PSD, "GIMP_EXPORT_FILE_PSD", "psd" },
+    { GIMP_EXPORT_FILE_PDF, "GIMP_EXPORT_FILE_PDF", "pdf" },
+    { GIMP_EXPORT_FILE_TIF, "GIMP_EXPORT_FILE_TIF", "tif" },
+    { GIMP_EXPORT_FILE_BMP, "GIMP_EXPORT_FILE_BMP", "bmp" },
+    { GIMP_EXPORT_FILE_WEBP, "GIMP_EXPORT_FILE_WEBP", "webp" },
+    { 0, NULL, NULL }
+  };
+
+  static const GimpEnumDesc descs[] =
+  {
+    { GIMP_EXPORT_FILE_PNG, NC_("export-file-type", "PNG Image"), NULL },
+    { GIMP_EXPORT_FILE_JPG, NC_("export-file-type", "JPEG Image"), NULL },
+    { GIMP_EXPORT_FILE_ORA, NC_("export-file-type", "OpenRaster Image"), NULL },
+    { GIMP_EXPORT_FILE_PSD, NC_("export-file-type", "Photoshop Image"), NULL },
+    { GIMP_EXPORT_FILE_PDF, NC_("export-file-type", "Portable Document Format"), NULL },
+    { GIMP_EXPORT_FILE_TIF, NC_("export-file-type", "TIFF Image"), NULL },
+    { GIMP_EXPORT_FILE_BMP, NC_("export-file-type", "Windows BMP Image"), NULL },
+    { GIMP_EXPORT_FILE_WEBP, NC_("export-file-type", "WebP Image"), NULL },
+    { 0, NULL, NULL }
+  };
+
+  static GType type = 0;
+
+  if (G_UNLIKELY (! type))
+    {
+      type = g_enum_register_static ("GimpExportFileType", values);
+      gimp_type_set_translation_context (type, "export-file-type");
+      gimp_enum_set_value_descriptions (type, descs);
+    }
+
+  return type;
+}
+
 GType
 gimp_handedness_get_type (void)
 {
diff --git a/app/config/config-enums.h b/app/config/config-enums.h
index 8ec6dc4d67..3881dbabc7 100644
--- a/app/config/config-enums.h
+++ b/app/config/config-enums.h
@@ -56,6 +56,23 @@ typedef enum
 } GimpCursorMode;
 
 
+#define GIMP_TYPE_EXPORT_FILE_TYPE (gimp_export_file_type_get_type ())
+
+GType gimp_export_file_type_get_type (void) G_GNUC_CONST;
+
+typedef enum
+{
+  GIMP_EXPORT_FILE_PNG,  /*< desc="PNG Image"                >*/
+  GIMP_EXPORT_FILE_JPG,  /*< desc="JPEG Image"               >*/
+  GIMP_EXPORT_FILE_ORA,  /*< desc="OpenRaster Image"         >*/
+  GIMP_EXPORT_FILE_PSD,  /*< desc="Photoshop Image"          >*/
+  GIMP_EXPORT_FILE_PDF,  /*< desc="Portable Document Format" >*/
+  GIMP_EXPORT_FILE_TIF,  /*< desc="TIFF Image"               >*/
+  GIMP_EXPORT_FILE_BMP,  /*< desc="Windows BMP Image"        >*/
+  GIMP_EXPORT_FILE_WEBP, /*< desc="WebP Image"               >*/
+} GimpExportFileType;
+
+
 #define GIMP_TYPE_HANDEDNESS (gimp_handedness_get_type ())
 
 GType gimp_handedness_get_type (void) G_GNUC_CONST;
diff --git a/app/config/gimpcoreconfig.c b/app/config/gimpcoreconfig.c
index bb80fce212..59b614b93a 100644
--- a/app/config/gimpcoreconfig.c
+++ b/app/config/gimpcoreconfig.c
@@ -111,6 +111,7 @@ enum
   PROP_IMPORT_PROMOTE_DITHER,
   PROP_IMPORT_ADD_ALPHA,
   PROP_IMPORT_RAW_PLUG_IN,
+  PROP_EXPORT_FILE_TYPE,
   PROP_EXPORT_COLOR_PROFILE,
   PROP_EXPORT_METADATA_EXIF,
   PROP_EXPORT_METADATA_XMP,
@@ -650,6 +651,14 @@ gimp_core_config_class_init (GimpCoreConfigClass *klass)
                          GIMP_PARAM_STATIC_STRINGS |
                          GIMP_CONFIG_PARAM_RESTART);
 
+  GIMP_CONFIG_PROP_ENUM (object_class, PROP_EXPORT_FILE_TYPE,
+                         "export-file-type",
+                         "Default export file type",
+                         EXPORT_FILE_TYPE_BLURB,
+                         GIMP_TYPE_EXPORT_FILE_TYPE,
+                         GIMP_EXPORT_FILE_PNG,
+                         GIMP_PARAM_STATIC_STRINGS);
+
   GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_EXPORT_COLOR_PROFILE,
                             "export-color-profile",
                             "Export Color Profile",
@@ -986,6 +995,9 @@ gimp_core_config_set_property (GObject      *object,
       g_free (core_config->import_raw_plug_in);
       core_config->import_raw_plug_in = g_value_dup_string (value);
       break;
+    case PROP_EXPORT_FILE_TYPE:
+      core_config->export_file_type = g_value_get_enum (value);
+      break;
     case PROP_EXPORT_COLOR_PROFILE:
       core_config->export_color_profile = g_value_get_boolean (value);
       break;
@@ -1191,6 +1203,9 @@ gimp_core_config_get_property (GObject    *object,
     case PROP_IMPORT_RAW_PLUG_IN:
       g_value_set_string (value, core_config->import_raw_plug_in);
       break;
+    case PROP_EXPORT_FILE_TYPE:
+      g_value_set_enum (value, core_config->export_file_type);
+      break;
     case PROP_EXPORT_COLOR_PROFILE:
       g_value_set_boolean (value, core_config->export_color_profile);
       break;
diff --git a/app/config/gimpcoreconfig.h b/app/config/gimpcoreconfig.h
index f3ce41f38d..747616f62f 100644
--- a/app/config/gimpcoreconfig.h
+++ b/app/config/gimpcoreconfig.h
@@ -96,6 +96,7 @@ struct _GimpCoreConfig
   gboolean                import_promote_dither;
   gboolean                import_add_alpha;
   gchar                  *import_raw_plug_in;
+  GimpExportFileType      export_file_type;
   gboolean                export_color_profile;
   gboolean                export_metadata_exif;
   gboolean                export_metadata_xmp;
diff --git a/app/config/gimprc-blurbs.h b/app/config/gimprc-blurbs.h
index 237daca3f9..21be915d5a 100644
--- a/app/config/gimprc-blurbs.h
+++ b/app/config/gimprc-blurbs.h
@@ -204,6 +204,9 @@ _("Add an alpha channel to all layers of imported images.")
 #define IMPORT_RAW_PLUG_IN_BLURB \
 _("Which plug-in to use for importing raw digital camera files.")
 
+#define EXPORT_FILE_TYPE_BLURB \
+_("Export file type used by default.")
+
 #define EXPORT_COLOR_PROFILE_BLURB \
 _("Export the image's color profile by default.")
 
diff --git a/app/dialogs/preferences-dialog.c b/app/dialogs/preferences-dialog.c
index b95e102b64..f146d36ccc 100644
--- a/app/dialogs/preferences-dialog.c
+++ b/app/dialogs/preferences-dialog.c
@@ -1484,6 +1484,10 @@ prefs_dialog_new (Gimp       *gimp,
                                   NULL,
                                   &top_iter);
 
+  gimp_prefs_box_set_page_scrollable (GIMP_PREFS_BOX (prefs_box), vbox, TRUE);
+
+  size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
+
   /*  Import Policies  */
   vbox2 = prefs_frame_new (_("Import Policies"),
                            GTK_CONTAINER (vbox), FALSE);
@@ -1509,7 +1513,7 @@ prefs_dialog_new (Gimp       *gimp,
   table = prefs_table_new (1, GTK_CONTAINER (vbox2));
   button = prefs_enum_combo_box_add (object, "color-profile-policy", 0, 0,
                                      _("Color profile policy:"),
-                                     GTK_TABLE (table), 0, NULL);
+                                     GTK_TABLE (table), 0, size_group);
 
   /*  Export Policies  */
   vbox2 = prefs_frame_new (_("Export Policies"),
@@ -1519,20 +1523,26 @@ prefs_dialog_new (Gimp       *gimp,
                                    _("Export the image's color profile by default"),
                                    GTK_BOX (vbox2));
   button = prefs_check_button_add (object, "export-metadata-exif",
-                                   /* Translators: label for configuration option (checkbox).
-                                    * It determines how file export plug-ins handle Exif by default.
+                                   /* Translators: label for
+                                    * configuration option (checkbox).
+                                    * It determines how file export
+                                    * plug-ins handle Exif by default.
                                     */
                                    _("Export Exif metadata by default when available"),
                                    GTK_BOX (vbox2));
   button = prefs_check_button_add (object, "export-metadata-xmp",
-                                   /* Translators: label for configuration option (checkbox).
-                                    * It determines how file export plug-ins handle XMP by default.
+                                   /* Translators: label for
+                                    * configuration option (checkbox).
+                                    * It determines how file export
+                                    * plug-ins handle XMP by default.
                                     */
                                    _("Export XMP metadata by default when available"),
                                    GTK_BOX (vbox2));
   button = prefs_check_button_add (object, "export-metadata-iptc",
-                                   /* Translators: label for configuration option (checkbox).
-                                    * It determines how file export plug-ins handle IPTC by default.
+                                   /* Translators: label for
+                                    * configuration option (checkbox).
+                                    * It determines how file export
+                                    * plug-ins handle IPTC by default.
                                     */
                                    _("Export IPTC metadata by default when available"),
                                    GTK_BOX (vbox2));
@@ -1540,6 +1550,13 @@ prefs_dialog_new (Gimp       *gimp,
                              _("Metadata can contain sensitive information."));
   gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
 
+  /*  Export File Type  */
+  vbox2 = prefs_frame_new (_("Export File Type"), GTK_CONTAINER (vbox), FALSE);
+  table = prefs_table_new (1, GTK_CONTAINER (vbox2));
+
+  prefs_enum_combo_box_add (object, "export-file-type", 0, 0,
+                            _("Default export file type:"),
+                            GTK_TABLE (table), 0, size_group);
 
   /*  Raw Image Importer  */
   vbox2 = prefs_frame_new (_("Raw Image Importer"),
@@ -1568,6 +1585,8 @@ prefs_dialog_new (Gimp       *gimp,
                       config);
   }
 
+  g_object_unref (size_group);
+
   /****************/
   /*  Playground  */
   /****************/
diff --git a/app/widgets/gimpexportdialog.c b/app/widgets/gimpexportdialog.c
index 4566a80c7c..eebf98e66f 100644
--- a/app/widgets/gimpexportdialog.c
+++ b/app/widgets/gimpexportdialog.c
@@ -32,6 +32,8 @@
 #include "core/gimp-utils.h"
 #include "core/gimpimage.h"
 
+#include "config/gimpcoreconfig.h"
+
 #include "file/gimp-file.h"
 
 #include "gimpexportdialog.h"
@@ -158,7 +160,7 @@ gimp_export_dialog_set_image (GimpExportDialog *dialog,
    *   1. Type of last Export
    *   2. Type of the image Import
    *   3. Type of latest Export of any document
-   *   4. .png
+   *   4. Default file type set in Preferences
    */
 
   ext_file = gimp_image_get_exported_file (image);
@@ -171,9 +173,23 @@ gimp_export_dialog_set_image (GimpExportDialog *dialog,
                                   GIMP_FILE_EXPORT_LAST_FILE_KEY);
 
   if (ext_file)
-    g_object_ref (ext_file);
+    {
+      g_object_ref (ext_file);
+    }
   else
-    ext_file = g_file_new_for_uri ("file:///we/only/care/about/extension.png");
+    {
+      const gchar *extension;
+      gchar       *uri;
+
+      gimp_enum_get_value (GIMP_TYPE_EXPORT_FILE_TYPE,
+                           image->gimp->config->export_file_type,
+                           NULL, &extension, NULL, NULL);
+
+      uri = g_strconcat ("file:///we/only/care/about/extension.",
+                         extension, NULL);
+      ext_file = g_file_new_for_uri (uri);
+      g_free (uri);
+    }
 
   if (ext_file)
     {


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