replace Glib::filename_to_utf8 with custom fname_to_utf8

(cherry picked from commit 30b4daf9077e3c6780cefbf6c4223da4698b8612)
This commit is contained in:
Alberto Griggio 2022-07-06 07:04:24 -07:00 committed by Lawrence Lee
parent eb7c151260
commit 7324ea7230
No known key found for this signature in database
GPG Key ID: 048FF2B76A63895F
4 changed files with 27 additions and 41 deletions

View File

@ -67,25 +67,6 @@ Glib::ustring argv1;
namespace namespace
{ {
// For an unknown reason, Glib::filename_to_utf8 doesn't work on reliably Windows,
// so we're using Glib::filename_to_utf8 for Linux/Apple and Glib::locale_to_utf8 for Windows.
Glib::ustring fname_to_utf8 (const char* fname)
{
#ifdef WIN32
try {
return Glib::locale_to_utf8 (fname);
} catch (Glib::Error&) {
return Glib::convert_with_fallback (fname, "UTF-8", "ISO-8859-1", "?");
}
#else
return Glib::filename_to_utf8 (fname);
#endif
}
bool fast_export = false; bool fast_export = false;
} }

View File

@ -44,6 +44,7 @@
#include "extprog.h" #include "extprog.h"
#include "../rtengine/dynamicprofile.h" #include "../rtengine/dynamicprofile.h"
#include "../rtengine/procparams.h" #include "../rtengine/procparams.h"
#include "pathutils.h"
#ifndef WIN32 #ifndef WIN32
#include <glibmm/fileutils.h> #include <glibmm/fileutils.h>
@ -71,27 +72,7 @@ bool remote = false;
unsigned char initialGdkScale = 1; unsigned char initialGdkScale = 1;
//Glib::Threads::Thread* mainThread; //Glib::Threads::Thread* mainThread;
namespace namespace {
{
// For an unknown reason, Glib::filename_to_utf8 doesn't work on reliably Windows,
// so we're using Glib::filename_to_utf8 for Linux/Apple and Glib::locale_to_utf8 for Windows.
Glib::ustring fname_to_utf8 (const char* fname)
{
#ifdef WIN32
try {
return Glib::locale_to_utf8 (fname);
} catch (Glib::Error&) {
return Glib::convert_with_fallback (fname, "UTF-8", "ISO-8859-1", "?");
}
#else
return Glib::filename_to_utf8 (fname);
#endif
}
// This recursive mutex will be used by gdk_threads_enter/leave instead of a simple mutex // This recursive mutex will be used by gdk_threads_enter/leave instead of a simple mutex
static Glib::Threads::RecMutex myGdkRecMutex; static Glib::Threads::RecMutex myGdkRecMutex;

View File

@ -16,6 +16,7 @@
* along with RawTherapee. If not, see <https://www.gnu.org/licenses/>. * along with RawTherapee. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <glibmm/convert.h>
#include <glibmm/miscutils.h> #include <glibmm/miscutils.h>
#include "pathutils.h" #include "pathutils.h"
@ -48,3 +49,23 @@ Glib::ustring getExtension (const Glib::ustring& filename)
return ""; return "";
} }
} }
// For an unknown reason, Glib::filename_to_utf8 doesn't work on reliably Windows,
// so we're using Glib::filename_to_utf8 for Linux/Apple and Glib::locale_to_utf8 for Windows.
Glib::ustring fname_to_utf8(const std::string &fname)
{
#ifdef WIN32
try {
return Glib::locale_to_utf8(fname);
} catch (Glib::Error&) {
return Glib::convert_with_fallback(fname, "UTF-8", "ISO-8859-1", "?");
}
#else
return Glib::filename_to_utf8(fname);
#endif
}

View File

@ -1,4 +1,5 @@
/* /* -*- C++ -*-
*
* This file is part of RawTherapee. * This file is part of RawTherapee.
* *
* Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com> * Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
@ -18,7 +19,9 @@
*/ */
#pragma once #pragma once
#include <glibmm/ustring.h> #include <glibmm/ustring.h>
#include <string>
// Removed from guiutils because used by rawtherapee-cli // Removed from guiutils because used by rawtherapee-cli
Glib::ustring removeExtension (const Glib::ustring& filename); Glib::ustring removeExtension (const Glib::ustring& filename);
Glib::ustring getExtension (const Glib::ustring& filename); Glib::ustring getExtension (const Glib::ustring& filename);
Glib::ustring fname_to_utf8(const std::string& fname);