From b84e570f500a19fec0f6a35fe775061116be283b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=B6ssie?= Date: Thu, 9 Mar 2017 17:10:33 +0100 Subject: [PATCH] Revise `SaveAsDialog::okPressed()` (fixes #3737) --- rtgui/options.h | 15 ++++++++-- rtgui/saveasdlg.cc | 72 +++++++++++++++++++++++++++++----------------- 2 files changed, 57 insertions(+), 30 deletions(-) diff --git a/rtgui/options.h b/rtgui/options.h index efc649417..522fe2bf5 100644 --- a/rtgui/options.h +++ b/rtgui/options.h @@ -42,10 +42,20 @@ // Special name for the Dynamic profile #define DEFPROFILE_DYNAMIC "Dynamic" -class SaveFormat +struct SaveFormat { + SaveFormat() : + format("jpg"), + pngBits(8), + pngCompression(6), + jpegQuality(90), + jpegSubSamp(2), + tiffBits(8), + tiffUncompressed(true), + saveParams(true) + { + } -public: Glib::ustring format; int pngBits; int pngCompression; @@ -54,7 +64,6 @@ public: int tiffBits; bool tiffUncompressed; bool saveParams; - SaveFormat () : format("jpg"), pngBits(8), pngCompression(6), jpegQuality(90), jpegSubSamp(2), tiffBits(8), tiffUncompressed(true), saveParams(true) {}; }; enum ThFileType {FT_Invalid = -1, FT_None = 0, FT_Raw = 1, FT_Jpeg = 2, FT_Tiff = 3, FT_Png = 4, FT_Custom = 5, FT_Tiff16 = 6, FT_Png16 = 7, FT_Custom16 = 8}; diff --git a/rtgui/saveasdlg.cc b/rtgui/saveasdlg.cc index 9ca26d217..865373b60 100644 --- a/rtgui/saveasdlg.cc +++ b/rtgui/saveasdlg.cc @@ -21,6 +21,8 @@ #include "guiutils.h" #include "rtimage.h" +#include "../rtengine/utils.h" + extern Options options; SaveAsDialog::SaveAsDialog (const Glib::ustring &initialDir, Gtk::Window* parent) @@ -217,41 +219,57 @@ SaveFormat SaveAsDialog::getFormat () void SaveAsDialog::okPressed () { - fname = fchooser->get_filename(); - // checking if the filename field is empty. The user have to click Cancel if he don't want to specify a filename // NB: There seem to be a bug in Gtkmm2.22 / FileChooserWidget : if you suppress the filename entry and // click on a folder in the list, the filename field is empty but get_filename will return the folder's path :/ - if (!fname.length() || Glib::file_test (fname, Glib::FILE_TEST_IS_DIR)) { - Glib::ustring msg_ = Glib::ustring("") + M("MAIN_MSG_EMPTYFILENAME") + ""; - Gtk::MessageDialog msgd (*this, msg_, true, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_OK, true); - msgd.run (); + if (Glib::file_test(fname, Glib::FILE_TEST_IS_DIR)) { + fname = fchooser->get_current_name(); + } + + // Checking if the filename field is empty. The user have to click Cancel if he don't want to specify a filename + if (fname.empty()) { + Gtk::MessageDialog( + *this, + Glib::ustring("") + + M("MAIN_MSG_EMPTYFILENAME") + + "", + true, + Gtk::MESSAGE_WARNING, + Gtk::BUTTONS_OK, + true + ).run(); return; } - // resolve extension ambiguities - SaveFormat sf = formatOpts->getFormat (); - Glib::ustring extLower = getExtension (fname).lowercase (); - bool extIsEmpty = (extLower == ""); - bool extIsJpeg = (extLower == "jpg" || extLower == "jpeg" || extLower == "jpe"); - bool extIsTiff = (extLower == "tif" || extLower == "tiff"); - bool extIsPng = (extLower == "png"); + if (getExtension(fname).empty()) { + // Extension is either empty or unfamiliar + fname += '.' + formatOpts->getFormat().format; + } else if ( + !rtengine::hasJpegExtension(fname) + && !rtengine::hasTiffExtension(fname) + && !rtengine::hasPngExtension(fname) + ) { + // Create dialog to warn user that the filename may have two extensions on the end + Gtk::MessageDialog msgd( + *this, + Glib::ustring("") + + M("GENERAL_WARNING") + + ": " + + M("SAVEDLG_WARNFILENAME") + + " \"" + + Glib::path_get_basename (fname) + + '.' + + formatOpts->getFormat().format + + "\"", + true, + Gtk::MESSAGE_WARNING, + Gtk::BUTTONS_OK_CANCEL, + true + ); - if (extIsEmpty || !(extIsJpeg || extIsTiff || extIsPng)) { - // extension is either empty or unfamiliar. - fname += Glib::ustring (".") + sf.format; - } else if ( !(sf.format == "jpg" && extIsJpeg) - && !(sf.format == "tif" && extIsTiff) - && !(sf.format == "png" && extIsPng ) ) { - // create dialog to warn user that the filename may have two extensions on the end. - Glib::ustring msg_ = Glib::ustring ("") + M("GENERAL_WARNING") + ": " - + M("SAVEDLG_WARNFILENAME") + " \"" + Glib::path_get_basename (fname) - + "." + sf.format + "\""; - Gtk::MessageDialog msgd (*this, msg_, true, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_OK_CANCEL, true); - - if (msgd.run () == Gtk::RESPONSE_OK) { - fname += Glib::ustring (".") + sf.format; + if (msgd.run() == Gtk::RESPONSE_OK) { + fname += "." + formatOpts->getFormat().format; } else { return; }