Allow to modify default UI theme

PR #18214.
This commit is contained in:
Vladimir Golovnev 2023-01-14 14:02:20 +03:00 committed by GitHub
parent 209850064a
commit 8db2d04dbb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -41,6 +41,7 @@
#include "base/logger.h" #include "base/logger.h"
#include "base/path.h" #include "base/path.h"
#include "base/preferences.h" #include "base/preferences.h"
#include "base/profile.h"
#include "base/utils/fs.h" #include "base/utils/fs.h"
namespace namespace
@ -72,17 +73,18 @@ namespace
QByteArray readFile(const Path &filePath) QByteArray readFile(const Path &filePath)
{ {
QFile file {filePath.data()}; QFile file {filePath.data()};
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) if (!file.exists())
{ return {};
if (file.open(QIODevice::ReadOnly | QIODevice::Text))
return file.readAll();
LogMsg(UIThemeManager::tr("UITheme - Failed to open \"%1\". Reason: %2") LogMsg(UIThemeManager::tr("UITheme - Failed to open \"%1\". Reason: %2")
.arg(filePath.filename(), file.errorString()) .arg(filePath.filename(), file.errorString())
, Log::WARNING); , Log::WARNING);
return {}; return {};
} }
return file.readAll();
}
class QRCThemeSource final : public UIThemeSource class QRCThemeSource final : public UIThemeSource
{ {
public: public:
@ -172,9 +174,9 @@ UIThemeManager::UIThemeManager()
, m_useSystemIcons {Preferences::instance()->useSystemIcons()} , m_useSystemIcons {Preferences::instance()->useSystemIcons()}
#endif #endif
{ {
if (m_useCustomTheme) const Path themePath = m_useCustomTheme
{ ? Preferences::instance()->customUIThemePath()
const Path themePath = Preferences::instance()->customUIThemePath(); : specialFolderLocation(SpecialFolder::Config) / Path(u"themes/default/config.json"_qs);
m_themeSource = createUIThemeSource(themePath); m_themeSource = createUIThemeSource(themePath);
if (!m_themeSource) if (!m_themeSource)
{ {
@ -187,7 +189,6 @@ UIThemeManager::UIThemeManager()
applyStyleSheet(); applyStyleSheet();
} }
} }
}
UIThemeManager *UIThemeManager::instance() UIThemeManager *UIThemeManager::instance()
{ {
@ -295,7 +296,7 @@ Path UIThemeManager::getIconPath(const QString &iconId) const
Path UIThemeManager::getIconPathFromResources(const QString &iconId) const Path UIThemeManager::getIconPathFromResources(const QString &iconId) const
{ {
if (m_useCustomTheme && m_themeSource) if (m_themeSource)
{ {
const Path customIcon = m_themeSource->iconPath(iconId); const Path customIcon = m_themeSource->iconPath(iconId);
if (!customIcon.isEmpty()) if (!customIcon.isEmpty())