refactor: Settings store envvar checks so they only need to be read once when checking

This commit is contained in:
sithlord48 2025-11-14 09:03:59 -05:00 committed by Chris Rizzitello
parent 204a6cca8a
commit 1a9e468c86

View file

@ -58,8 +58,8 @@ Settings::Settings(QObject *parent) : QObject(parent)
if (QFile(portableFile).exists()) if (QFile(portableFile).exists())
fileToLoad = portableFile; fileToLoad = portableFile;
#else #else
if (!qEnvironmentVariable("XDG_CONFIG_HOME").isEmpty()) if (const auto xdgConfigHome = qEnvironmentVariable("XDG_CONFIG_HOME"); !xdgConfigHome.isEmpty())
fileToLoad = QStringLiteral("%1/%2/%2.conf").arg(qEnvironmentVariable("XDG_CONFIG_HOME"), kAppName); fileToLoad = QStringLiteral("%1/%2/%2.conf").arg(xdgConfigHome, kAppName);
#endif #endif
else if (QFile(UserSettingFile).exists()) else if (QFile(UserSettingFile).exists())
fileToLoad = UserSettingFile; fileToLoad = UserSettingFile;
@ -73,8 +73,9 @@ Settings::Settings(QObject *parent) : QObject(parent)
m_settingsProxy->load(fileToLoad); m_settingsProxy->load(fileToLoad);
qInfo().noquote() << "initial settings file:" << m_settings->fileName(); qInfo().noquote() << "initial settings file:" << m_settings->fileName();
const auto stateBase = !qEnvironmentVariable("XDG_STATE_HOME").isEmpty() const auto xdgStateHome = qEnvironmentVariable("XDG_STATE_HOME");
? qEnvironmentVariable("XDG_STATE_HOME") const auto stateBase = !xdgStateHome.isEmpty()
? xdgStateHome
: QStandardPaths::standardLocations(QStandardPaths::GenericStateLocation).at(0); : QStandardPaths::standardLocations(QStandardPaths::GenericStateLocation).at(0);
const auto stateFile = QStringLiteral("%1/%2.state").arg(stateBase, kAppName); const auto stateFile = QStringLiteral("%1/%2.state").arg(stateBase, kAppName);