From 54650eb2af2c93ac11988df367273d6709c6cb42 Mon Sep 17 00:00:00 2001 From: Martchus Date: Wed, 15 Mar 2023 20:07:10 +0100 Subject: [PATCH] Improve setting icon theme from CLI arguments * Use `qEnvironmentVariable()` to read env variables into `QString`s * Treat CLI arguments as UTF-8 (they will be converted to UTF-8 on Windows) which is consistent with the CLI argument handling in tag editor * Add comment about processing of `m_iconThemeArg` and reserve the correct size when building the `QStringLiteral` --- resources/qtconfigarguments.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/resources/qtconfigarguments.cpp b/resources/qtconfigarguments.cpp index 7de67e9..f331199 100644 --- a/resources/qtconfigarguments.cpp +++ b/resources/qtconfigarguments.cpp @@ -1,5 +1,7 @@ #include "./qtconfigarguments.h" +#include "../misc/compat.h" + #include #include @@ -127,14 +129,14 @@ void QtConfigArguments::applySettings(bool preventApplyingDefaultFont) const } #endif if (m_iconThemeArg.isPresent()) { - auto i = m_iconThemeArg.values().cbegin(), end = m_iconThemeArg.values().end(); - if (i != end) { - QIcon::setThemeName(QString::fromLocal8Bit(*i)); + // set first value of m_iconThemeArg as icon theme and add further values as search paths + if (auto i = m_iconThemeArg.values().cbegin(), end = m_iconThemeArg.values().cend(); i != end) { + QIcon::setThemeName(QString::fromUtf8(*i)); if (++i != end) { - QStringList searchPaths; - searchPaths.reserve(static_cast(m_iconThemeArg.values().size() - 1)); + auto searchPaths = QStringList(); + searchPaths.reserve(static_cast(m_iconThemeArg.values().size())); for (; i != end; ++i) { - searchPaths << QString::fromLocal8Bit(*i); + searchPaths << QString::fromUtf8(*i); } searchPaths << QStringLiteral(":/icons"); QIcon::setThemeSearchPaths(searchPaths); @@ -142,16 +144,12 @@ void QtConfigArguments::applySettings(bool preventApplyingDefaultFont) const } } else { if (qEnvironmentVariableIsSet("ICON_THEME_SEARCH_PATH")) { - QString path; - path.append(qgetenv("ICON_THEME_SEARCH_PATH")); - QIcon::setThemeSearchPaths(QStringList({ path, QStringLiteral(":/icons") })); + QIcon::setThemeSearchPaths(QStringList({ qEnvironmentVariable("ICON_THEME_SEARCH_PATH"), QStringLiteral(":/icons") })); } else { QIcon::setThemeSearchPaths(QIcon::themeSearchPaths() << QStringLiteral("../share/icons") << QStringLiteral(":/icons")); } if (qEnvironmentVariableIsSet("ICON_THEME")) { - QString themeName; - themeName.append(qgetenv("ICON_THEME")); - QIcon::setThemeName(themeName); + QIcon::setThemeName(qEnvironmentVariable("ICON_THEME")); } } #ifdef Q_OS_WIN32