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 GitHub
parent c88a7b9e76
commit 1be2f94d03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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>
</qresource>
<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="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 prefix="/images">
<file alias="arrow_down">res/images/arrow_down.png</file>

View File

@ -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)

View File

@ -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");