Commit 75e57704 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Attempt to mimic Shotcut's locale handling

Related to #780
parent 45cbc455
Pipeline #32481 passed with stage
in 21 minutes and 13 seconds
......@@ -39,6 +39,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "projectclip.h"
#include "projectfolder.h"
#include "projectsubclip.h"
#include "lib/localeHandling.h"
#include "xml/xml.hpp"
#include <KLocalizedString>
......@@ -993,8 +994,8 @@ void ProjectItemModel::loadBinPlaylist(Mlt::Tractor *documentTractor, Mlt::Tract
emit pCore->loadingMessageUpdated(i18n("Loading project clips..."));
}
// Load bin clips
auto currentLocale = strdup(setlocale(LC_ALL, nullptr));
qDebug() << "Init bin; Current LC_ALL" << currentLocale;
auto currentLocale = strdup(setlocale(MLT_LC_CATEGORY, nullptr));
qDebug() << "Init bin; Current LC" << currentLocale;
// Load folders
Mlt::Properties folderProperties;
Mlt::Properties playlistProps(playlist.get_properties());
......
......@@ -21,12 +21,12 @@ auto LocaleHandling::setLocale(const QString &lcName) -> QString
localesToTest << lcName << lcName + ".utf-8" << lcName + ".UTF-8" << lcName + ".utf8" << lcName + ".UTF8";
for (const auto &locale : qAsConst(localesToTest)) {
#ifdef Q_OS_FREEBSD
auto *result = setlocale(LC_NUMERIC, locale.toStdString().c_str());
auto *result = setlocale(MLT_LC_CATEGORY, locale.toStdString().c_str());
#else
auto *result = std::setlocale(LC_NUMERIC, locale.toStdString().c_str());
auto *result = std::setlocale(MLT_LC_CATEGORY, locale.toStdString().c_str());
#endif
if (result != nullptr) {
::qputenv("LC_NUMERIC", locale.toStdString().c_str());
::qputenv(MLT_LC_NAME, locale.toStdString().c_str());
newLocale = locale;
break;
}
......@@ -40,11 +40,11 @@ auto LocaleHandling::setLocale(const QString &lcName) -> QString
void LocaleHandling::resetLocale()
{
#ifdef Q_OS_FREEBSD
setlocale(LC_NUMERIC, "C");
setlocale(MLT_LC_CATEGORY, "C");
#else
std::setlocale(LC_NUMERIC, "C");
std::setlocale(MLT_LC_CATEGORY, "C");
#endif
::qputenv("LC_NUMERIC", "C");
::qputenv(MLT_LC_NAME, "C");
qDebug() << "LC_NUMERIC reset to C";
}
......
......@@ -13,6 +13,15 @@ the Free Software Foundation, either version 3 of the License, or
#include <QtCore/QLocale>
#include <QtCore/QString>
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
# define MLT_LC_CATEGORY LC_NUMERIC
# define MLT_LC_NAME "LC_NUMERIC"
#else
# define MLT_LC_CATEGORY LC_ALL
# define MLT_LC_NAME "LC_ALL"
#endif
class LocaleHandling
{
public:
......
......@@ -92,6 +92,7 @@ int main(int argc, char *argv[])
QCoreApplication::setAttribute(Qt::AA_UseOpenGLES, true);
}
#endif
qputenv("LANG", QLocale().name().toUtf8());
QApplication app(argc, argv);
app.setApplicationName(QStringLiteral("kdenlive"));
app.setOrganizationDomain(QStringLiteral("kde.org"));
......
......@@ -89,9 +89,9 @@ MltConnection::MltConnection(const QString &mltPath)
LocaleHandling::resetLocale();
#ifdef Q_OS_FREEBSD
auto locale = strdup(setlocale(LC_ALL, nullptr));
auto locale = strdup(setlocale(MLT_LC_CATEGORY, nullptr));
#else
auto locale = strdup(std::setlocale(LC_ALL, nullptr));
auto locale = strdup(std::setlocale(MLT_LC_CATEGORY, nullptr));
#endif
qDebug() << "NEW LC_ALL" << locale;
......
......@@ -1693,20 +1693,7 @@ void Monitor::resetConsumer(bool fullReset)
const QString Monitor::sceneList(const QString &root, const QString &fullPath)
{
// on Windows, the xml consumer doesn't follow LC_NUMERIC, so enforce locale
#ifdef Q_OS_WIN
auto currentLocale = strdup(setlocale(LC_ALL, nullptr));
std::setlocale(LC_ALL, "C");
::qputenv("LC_ALL", "C");
qDebug() << "Current locale is " << currentLocale;
#endif
const QString resultScene = m_glMonitor->sceneList(root, fullPath);
#ifdef Q_OS_WIN
::qputenv("LC_ALL", currentLocale);
std::setlocale(LC_ALL, currentLocale);
LocaleHandling::resetLocale();
#endif
return resultScene;
return m_glMonitor->sceneList(root, fullPath);
}
void Monitor::updateClipZone(const QPoint zone)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment