From 7324ea723041ee2c20e1f66e174888566f32522d Mon Sep 17 00:00:00 2001 From: Alberto Griggio Date: Wed, 6 Jul 2022 07:04:24 -0700 Subject: [PATCH] replace Glib::filename_to_utf8 with custom fname_to_utf8 (cherry picked from commit 30b4daf9077e3c6780cefbf6c4223da4698b8612) --- rtgui/main-cli.cc | 19 ------------------- rtgui/main.cc | 23 ++--------------------- rtgui/pathutils.cc | 21 +++++++++++++++++++++ rtgui/pathutils.h | 5 ++++- 4 files changed, 27 insertions(+), 41 deletions(-) diff --git a/rtgui/main-cli.cc b/rtgui/main-cli.cc index feef93564..00272357e 100644 --- a/rtgui/main-cli.cc +++ b/rtgui/main-cli.cc @@ -67,25 +67,6 @@ Glib::ustring argv1; 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; } diff --git a/rtgui/main.cc b/rtgui/main.cc index 9f623a6df..08891ef46 100644 --- a/rtgui/main.cc +++ b/rtgui/main.cc @@ -44,6 +44,7 @@ #include "extprog.h" #include "../rtengine/dynamicprofile.h" #include "../rtengine/procparams.h" +#include "pathutils.h" #ifndef WIN32 #include @@ -71,27 +72,7 @@ bool remote = false; unsigned char initialGdkScale = 1; //Glib::Threads::Thread* mainThread; -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 -} +namespace { // This recursive mutex will be used by gdk_threads_enter/leave instead of a simple mutex static Glib::Threads::RecMutex myGdkRecMutex; diff --git a/rtgui/pathutils.cc b/rtgui/pathutils.cc index fc47a0e25..ef67564b2 100644 --- a/rtgui/pathutils.cc +++ b/rtgui/pathutils.cc @@ -16,6 +16,7 @@ * along with RawTherapee. If not, see . */ +#include #include #include "pathutils.h" @@ -48,3 +49,23 @@ Glib::ustring getExtension (const Glib::ustring& filename) 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 +} diff --git a/rtgui/pathutils.h b/rtgui/pathutils.h index 482dfb82f..8ac1533b7 100644 --- a/rtgui/pathutils.h +++ b/rtgui/pathutils.h @@ -1,4 +1,5 @@ -/* +/* -*- C++ -*- + * * This file is part of RawTherapee. * * Copyright (c) 2004-2010 Gabor Horvath @@ -18,7 +19,9 @@ */ #pragma once #include +#include // Removed from guiutils because used by rawtherapee-cli Glib::ustring removeExtension (const Glib::ustring& filename); Glib::ustring getExtension (const Glib::ustring& filename); +Glib::ustring fname_to_utf8(const std::string& fname);