Revise SaveAsDialog::okPressed()
(fixes #3737)
This commit is contained in:
parent
1593335485
commit
b84e570f50
@ -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};
|
||||
|
@ -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("<b>") + M("MAIN_MSG_EMPTYFILENAME") + "</b>";
|
||||
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("<b>")
|
||||
+ M("MAIN_MSG_EMPTYFILENAME")
|
||||
+ "</b>",
|
||||
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("<b>")
|
||||
+ M("GENERAL_WARNING")
|
||||
+ ": "
|
||||
+ M("SAVEDLG_WARNFILENAME")
|
||||
+ " \""
|
||||
+ Glib::path_get_basename (fname)
|
||||
+ '.'
|
||||
+ formatOpts->getFormat().format
|
||||
+ "\"</b>",
|
||||
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 ("<b>") + M("GENERAL_WARNING") + ": "
|
||||
+ M("SAVEDLG_WARNFILENAME") + " \"" + Glib::path_get_basename (fname)
|
||||
+ "." + sf.format + "\"</b>";
|
||||
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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user