DolphinQt: Store name of user style, not path

This makes user styles not break when for instance
moving a portable.txt install between different folders.
This commit is contained in:
JosJuice
2020-05-01 16:31:47 +02:00
parent 66c91b9dfb
commit aab694e6b5
3 changed files with 15 additions and 11 deletions

View File

@ -7,6 +7,7 @@
#include <QApplication>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QSize>
#include "AudioCommon/AudioCommon.h"
@ -72,17 +73,22 @@ void Settings::SetThemeName(const QString& theme_name)
QString Settings::GetCurrentUserStyle() const
{
return GetQSettings().value(QStringLiteral("userstyle/path"), false).toString();
if (GetQSettings().contains(QStringLiteral("userstyle/name")))
return GetQSettings().value(QStringLiteral("userstyle/name")).toString();
// Migration code for the old way of storing this setting
return QFileInfo(GetQSettings().value(QStringLiteral("userstyle/path")).toString()).fileName();
}
void Settings::SetCurrentUserStyle(const QString& stylesheet_path)
void Settings::SetCurrentUserStyle(const QString& stylesheet_name)
{
QString stylesheet_contents;
if (!stylesheet_path.isEmpty() && AreUserStylesEnabled())
if (!stylesheet_name.isEmpty() && AreUserStylesEnabled())
{
// Load custom user stylesheet
QFile stylesheet(stylesheet_path);
QDir directory = QDir(QString::fromStdString(File::GetUserPath(D_STYLES_IDX)));
QFile stylesheet(directory.filePath(stylesheet_name));
if (stylesheet.open(QFile::ReadOnly))
stylesheet_contents = QString::fromUtf8(stylesheet.readAll().data());
@ -90,7 +96,7 @@ void Settings::SetCurrentUserStyle(const QString& stylesheet_path)
qApp->setStyleSheet(stylesheet_contents);
GetQSettings().setValue(QStringLiteral("userstyle/path"), stylesheet_path);
GetQSettings().setValue(QStringLiteral("userstyle/name"), stylesheet_name);
}
bool Settings::AreUserStylesEnabled() const