Skip to content

Commit 1c885bb

Browse files
UdjinM6nmarley
authored andcommitted
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 <nathan.marley@gmail.com>
1 parent 617c588 commit 1c885bb

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

src/qt/dash.qrc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@
5454
<file alias="network_disabled">res/icons/network_disabled.png</file>
5555
</qresource>
5656
<qresource prefix="/css">
57-
<file alias="dark">res/css/dark.css</file>
58-
<file alias="light">res/css/light.css</file>
5957
<file alias="scrollbars">res/css/scrollbars.css</file>
60-
<file alias="trad">res/css/trad.css</file>
58+
</qresource>
59+
<qresource prefix="/themes">
60+
<file alias="Dark">res/css/dark.css</file>
61+
<file alias="Light">res/css/light.css</file>
62+
<file alias="Traditional">res/css/trad.css</file>
6163
</qresource>
6264
<qresource prefix="/images">
6365
<file alias="arrow_down">res/images/arrow_down.png</file>

src/qt/guiutil.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -922,25 +922,23 @@ void migrateQtSettings()
922922
// Open CSS when configured
923923
QString loadStyleSheet()
924924
{
925-
QString styleSheet;
926925
QSettings settings;
927-
QString cssName;
928926
QString theme = settings.value("theme", "").toString();
929927

930-
if(!theme.isEmpty()){
931-
cssName = QString(":/css/") + theme;
932-
}
933-
else {
934-
cssName = QString(":/css/light");
935-
settings.setValue("theme", "light");
928+
QDir themes(":themes");
929+
// Make sure settings are pointing to an existent theme
930+
// Set "Light" theme by default if settings are missing or incorrect
931+
if (theme.isEmpty() || !themes.exists(theme)) {
932+
theme = "Light";
933+
settings.setValue("theme", theme);
936934
}
937935

938-
QFile qFile(cssName);
936+
QFile qFile(":themes/" + theme);
939937
if (qFile.open(QFile::ReadOnly)) {
940-
styleSheet = QLatin1String(qFile.readAll());
938+
return QLatin1String(qFile.readAll());
941939
}
942940

943-
return styleSheet;
941+
return QString();
944942
}
945943

946944
void setClipboard(const QString& str)

src/qt/optionsdialog.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
9191
}
9292

9393
/* Theme selector */
94-
ui->theme->addItem(QString("Dark"), QVariant("dark"));
95-
ui->theme->addItem(QString("Light"), QVariant("light"));
96-
ui->theme->addItem(QString("Traditional"), QVariant("trad"));
94+
QDir themes(":themes");
95+
for (const QString &entry : themes.entryList()) {
96+
ui->theme->addItem(entry, QVariant(entry));
97+
}
9798

9899
/* Language selector */
99100
QDir translations(":translations");

0 commit comments

Comments
 (0)