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>
This commit is contained in:
UdjinM6 2020-01-14 23:17:53 +03:00 committed by Alexander Block
parent 617c588488
commit 1c885bbedf
3 changed files with 18 additions and 17 deletions

View File

@ -54,10 +54,12 @@
<file alias="network_disabled">res/icons/network_disabled.png</file> <file alias="network_disabled">res/icons/network_disabled.png</file>
</qresource> </qresource>
<qresource prefix="/css"> <qresource prefix="/css">
<file alias="dark">res/css/dark.css</file>
<file alias="light">res/css/light.css</file>
<file alias="scrollbars">res/css/scrollbars.css</file> <file alias="scrollbars">res/css/scrollbars.css</file>
<file alias="trad">res/css/trad.css</file> </qresource>
<qresource prefix="/themes">
<file alias="Dark">res/css/dark.css</file>
<file alias="Light">res/css/light.css</file>
<file alias="Traditional">res/css/trad.css</file>
</qresource> </qresource>
<qresource prefix="/images"> <qresource prefix="/images">
<file alias="arrow_down">res/images/arrow_down.png</file> <file alias="arrow_down">res/images/arrow_down.png</file>

View File

@ -922,25 +922,23 @@ void migrateQtSettings()
// Open CSS when configured // Open CSS when configured
QString loadStyleSheet() QString loadStyleSheet()
{ {
QString styleSheet;
QSettings settings; QSettings settings;
QString cssName;
QString theme = settings.value("theme", "").toString(); QString theme = settings.value("theme", "").toString();
if(!theme.isEmpty()){ QDir themes(":themes");
cssName = QString(":/css/") + theme; // Make sure settings are pointing to an existent theme
} // Set "Light" theme by default if settings are missing or incorrect
else { if (theme.isEmpty() || !themes.exists(theme)) {
cssName = QString(":/css/light"); theme = "Light";
settings.setValue("theme", "light"); settings.setValue("theme", theme);
} }
QFile qFile(cssName); QFile qFile(":themes/" + theme);
if (qFile.open(QFile::ReadOnly)) { if (qFile.open(QFile::ReadOnly)) {
styleSheet = QLatin1String(qFile.readAll()); return QLatin1String(qFile.readAll());
} }
return styleSheet; return QString();
} }
void setClipboard(const QString& str) void setClipboard(const QString& str)

View File

@ -91,9 +91,10 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
} }
/* Theme selector */ /* Theme selector */
ui->theme->addItem(QString("Dark"), QVariant("dark")); QDir themes(":themes");
ui->theme->addItem(QString("Light"), QVariant("light")); for (const QString &entry : themes.entryList()) {
ui->theme->addItem(QString("Traditional"), QVariant("trad")); ui->theme->addItem(entry, QVariant(entry));
}
/* Language selector */ /* Language selector */
QDir translations(":translations"); QDir translations(":translations");