From 1be2f94d03d8d2c57a050413ca734c605a8795a9 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Tue, 14 Jan 2020 23:17:53 +0300 Subject: [PATCH] Only load valid themes, fallback to "Light" theme otherwise (#3285) * Only load valid themes, fallback to "light" otherwise * Refactor PR3285 a bit * fix Co-authored-by: Nathan Marley --- src/qt/dash.qrc | 8 +++++--- src/qt/guiutil.cpp | 20 +++++++++----------- src/qt/optionsdialog.cpp | 7 ++++--- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/qt/dash.qrc b/src/qt/dash.qrc index 0f293af43c..d105dbc1be 100644 --- a/src/qt/dash.qrc +++ b/src/qt/dash.qrc @@ -54,10 +54,12 @@ res/icons/network_disabled.png - res/css/dark.css - res/css/light.css res/css/scrollbars.css - res/css/trad.css + + + res/css/dark.css + res/css/light.css + res/css/trad.css res/images/arrow_down.png diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 700e5e5e2e..4cea767ddc 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -941,25 +941,23 @@ void migrateQtSettings() // Open CSS when configured QString loadStyleSheet() { - QString styleSheet; QSettings settings; - QString cssName; QString theme = settings.value("theme", "").toString(); - if(!theme.isEmpty()){ - cssName = QString(":/css/") + theme; - } - else { - cssName = QString(":/css/light"); - settings.setValue("theme", "light"); + QDir themes(":themes"); + // Make sure settings are pointing to an existent theme + // Set "Light" theme by default if settings are missing or incorrect + if (theme.isEmpty() || !themes.exists(theme)) { + theme = "Light"; + settings.setValue("theme", theme); } - QFile qFile(cssName); + QFile qFile(":themes/" + theme); if (qFile.open(QFile::ReadOnly)) { - styleSheet = QLatin1String(qFile.readAll()); + return QLatin1String(qFile.readAll()); } - return styleSheet; + return QString(); } void setClipboard(const QString& str) diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index 983aa559fc..c54371163d 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -89,9 +89,10 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) : } /* Theme selector */ - ui->theme->addItem(QString("Dark"), QVariant("dark")); - ui->theme->addItem(QString("Light"), QVariant("light")); - ui->theme->addItem(QString("Traditional"), QVariant("trad")); + QDir themes(":themes"); + for (const QString &entry : themes.entryList()) { + ui->theme->addItem(entry, QVariant(entry)); + } /* Language selector */ QDir translations(":translations");