From f5b5570a3b64f5b1def0e27d4a601ff4a055c755 Mon Sep 17 00:00:00 2001 From: Vladimir Golovnev Date: Sat, 12 Aug 2023 18:57:34 +0300 Subject: [PATCH 1/2] Correctly load colors from custom themes PR #19448. Closes #19447. --- src/gui/uithemesource.cpp | 33 ++++++++++++++++++++------------- src/gui/uithemesource.h | 11 ++++++----- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/gui/uithemesource.cpp b/src/gui/uithemesource.cpp index 8565c6414..c4e4ef7f4 100644 --- a/src/gui/uithemesource.cpp +++ b/src/gui/uithemesource.cpp @@ -161,13 +161,13 @@ void DefaultThemeSource::loadColors() return; } - const QByteArray configData = readResult.value(); + const QByteArray &configData = readResult.value(); if (configData.isEmpty()) return; const QJsonObject config = parseThemeConfig(configData); - QHash lightModeColorOverrides = colorsFromJSON(config.value(KEY_COLORS_LIGHT).toObject()); + const QHash lightModeColorOverrides = colorsFromJSON(config.value(KEY_COLORS_LIGHT).toObject()); for (auto overridesIt = lightModeColorOverrides.cbegin(); overridesIt != lightModeColorOverrides.cend(); ++overridesIt) { auto it = m_colors.find(overridesIt.key()); @@ -175,7 +175,7 @@ void DefaultThemeSource::loadColors() it.value().light = overridesIt.value(); } - QHash darkModeColorOverrides = colorsFromJSON(config.value(KEY_COLORS_DARK).toObject()); + const QHash darkModeColorOverrides = colorsFromJSON(config.value(KEY_COLORS_DARK).toObject()); for (auto overridesIt = darkModeColorOverrides.cbegin(); overridesIt != darkModeColorOverrides.cend(); ++overridesIt) { auto it = m_colors.find(overridesIt.key()); @@ -184,6 +184,12 @@ void DefaultThemeSource::loadColors() } } +CustomThemeSource::CustomThemeSource(const Path &themeRootPath) + : m_themeRootPath {themeRootPath} +{ + loadColors(); +} + QColor CustomThemeSource::getColor(const QString &colorId, const ColorMode colorMode) const { if (colorMode == ColorMode::Dark) @@ -246,6 +252,11 @@ DefaultThemeSource *CustomThemeSource::defaultThemeSource() const return m_defaultThemeSource.get(); } +Path CustomThemeSource::themeRootPath() const +{ + return m_themeRootPath; +} + void CustomThemeSource::loadColors() { const auto readResult = Utils::IO::readFile((themeRootPath() / Path(CONFIG_FILE_NAME)), FILE_MAX_SIZE, QIODevice::Text); @@ -257,7 +268,7 @@ void CustomThemeSource::loadColors() return; } - const QByteArray configData = readResult.value(); + const QByteArray &configData = readResult.value(); if (configData.isEmpty()) return; @@ -267,13 +278,9 @@ void CustomThemeSource::loadColors() m_darkModeColors.insert(colorsFromJSON(config.value(KEY_COLORS_DARK).toObject())); } -Path QRCThemeSource::themeRootPath() const -{ - return Path(u":/uitheme"_s); -} - FolderThemeSource::FolderThemeSource(const Path &folderPath) - : m_folder {folderPath} + : CustomThemeSource(folderPath) + , m_folder {folderPath} { } @@ -285,10 +292,10 @@ QByteArray FolderThemeSource::readStyleSheet() const QString stylesheetResourcesDir = u":/uitheme"_s; QByteArray styleSheetData = CustomThemeSource::readStyleSheet(); - return styleSheetData.replace(stylesheetResourcesDir.toUtf8(), themeRootPath().data().toUtf8()); + return styleSheetData.replace(stylesheetResourcesDir.toUtf8(), m_folder.data().toUtf8()); } -Path FolderThemeSource::themeRootPath() const +QRCThemeSource::QRCThemeSource() + : CustomThemeSource(Path(u":/uitheme"_s)) { - return m_folder; } diff --git a/src/gui/uithemesource.h b/src/gui/uithemesource.h index 4969c3cee..5c0920303 100644 --- a/src/gui/uithemesource.h +++ b/src/gui/uithemesource.h @@ -84,21 +84,24 @@ public: QByteArray readStyleSheet() override; protected: - virtual Path themeRootPath() const = 0; + explicit CustomThemeSource(const Path &themeRootPath); + DefaultThemeSource *defaultThemeSource() const; private: + Path themeRootPath() const; void loadColors(); const std::unique_ptr m_defaultThemeSource = std::make_unique(); + Path m_themeRootPath; QHash m_colors; QHash m_darkModeColors; }; class QRCThemeSource final : public CustomThemeSource { -private: - Path themeRootPath() const override; +public: + QRCThemeSource(); }; class FolderThemeSource : public CustomThemeSource @@ -109,7 +112,5 @@ public: QByteArray readStyleSheet() override; private: - Path themeRootPath() const override; - const Path m_folder; }; From 3088b38d7e891c3d9a54fe5f156214a4c515d8d8 Mon Sep 17 00:00:00 2001 From: Omar Abdul Azeez <49833164+Omar-Abdul-Azeez@users.noreply.github.com> Date: Sun, 13 Aug 2023 00:59:24 +0900 Subject: [PATCH 2/2] Fix overwriting feeds.json with an incomplete load of it PR #19444. Closes #19439. --------- Co-authored-by: Vladimir Golovnev --- src/base/rss/rss_session.cpp | 14 +++++++------- src/base/rss/rss_session.h | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/base/rss/rss_session.cpp b/src/base/rss/rss_session.cpp index 6de5c26d7..ec4959eeb 100644 --- a/src/base/rss/rss_session.cpp +++ b/src/base/rss/rss_session.cpp @@ -271,6 +271,7 @@ void Session::load() if (readResult.error().status == Utils::IO::ReadError::NotExist) { loadLegacy(); + store(); // convert to new format return; } @@ -294,10 +295,11 @@ void Session::load() return; } - loadFolder(jsonDoc.object(), rootFolder()); + if (loadFolder(jsonDoc.object(), rootFolder())) + store(); // convert to updated format } -void Session::loadFolder(const QJsonObject &jsonObj, Folder *folder) +bool Session::loadFolder(const QJsonObject &jsonObj, Folder *folder) { bool updated = false; for (const QString &key : asConst(jsonObj.keys())) @@ -353,7 +355,8 @@ void Session::loadFolder(const QJsonObject &jsonObj, Folder *folder) } else { - loadFolder(valObj, addSubfolder(key, folder)); + if (loadFolder(valObj, addSubfolder(key, folder))) + updated = true; } } else @@ -363,8 +366,7 @@ void Session::loadFolder(const QJsonObject &jsonObj, Folder *folder) } } - if (updated) - store(); // convert to updated format + return updated; } void Session::loadLegacy() @@ -394,8 +396,6 @@ void Session::loadLegacy() addFeed(feedUrl, feedPath); ++i; } - - store(); // convert to new format } void Session::store() diff --git a/src/base/rss/rss_session.h b/src/base/rss/rss_session.h index 79c920066..9fee14c1e 100644 --- a/src/base/rss/rss_session.h +++ b/src/base/rss/rss_session.h @@ -149,7 +149,7 @@ namespace RSS private: QUuid generateUID() const; void load(); - void loadFolder(const QJsonObject &jsonObj, Folder *folder); + bool loadFolder(const QJsonObject &jsonObj, Folder *folder); void loadLegacy(); void store(); nonstd::expected prepareItemDest(const QString &path);