Merge pull request #19454 from glassez/v4.6

Backport changes to v4.6.x branch
This commit is contained in:
Vladimir Golovnev 2023-08-14 17:39:17 +03:00 committed by GitHub
commit 062e35e6b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 26 deletions

View file

@ -271,6 +271,7 @@ void Session::load()
if (readResult.error().status == Utils::IO::ReadError::NotExist) if (readResult.error().status == Utils::IO::ReadError::NotExist)
{ {
loadLegacy(); loadLegacy();
store(); // convert to new format
return; return;
} }
@ -294,10 +295,11 @@ void Session::load()
return; 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; bool updated = false;
for (const QString &key : asConst(jsonObj.keys())) for (const QString &key : asConst(jsonObj.keys()))
@ -353,7 +355,8 @@ void Session::loadFolder(const QJsonObject &jsonObj, Folder *folder)
} }
else else
{ {
loadFolder(valObj, addSubfolder(key, folder)); if (loadFolder(valObj, addSubfolder(key, folder)))
updated = true;
} }
} }
else else
@ -363,8 +366,7 @@ void Session::loadFolder(const QJsonObject &jsonObj, Folder *folder)
} }
} }
if (updated) return updated;
store(); // convert to updated format
} }
void Session::loadLegacy() void Session::loadLegacy()
@ -394,8 +396,6 @@ void Session::loadLegacy()
addFeed(feedUrl, feedPath); addFeed(feedUrl, feedPath);
++i; ++i;
} }
store(); // convert to new format
} }
void Session::store() void Session::store()

View file

@ -149,7 +149,7 @@ namespace RSS
private: private:
QUuid generateUID() const; QUuid generateUID() const;
void load(); void load();
void loadFolder(const QJsonObject &jsonObj, Folder *folder); bool loadFolder(const QJsonObject &jsonObj, Folder *folder);
void loadLegacy(); void loadLegacy();
void store(); void store();
nonstd::expected<Folder *, QString> prepareItemDest(const QString &path); nonstd::expected<Folder *, QString> prepareItemDest(const QString &path);

View file

@ -161,13 +161,13 @@ void DefaultThemeSource::loadColors()
return; return;
} }
const QByteArray configData = readResult.value(); const QByteArray &configData = readResult.value();
if (configData.isEmpty()) if (configData.isEmpty())
return; return;
const QJsonObject config = parseThemeConfig(configData); const QJsonObject config = parseThemeConfig(configData);
QHash<QString, QColor> lightModeColorOverrides = colorsFromJSON(config.value(KEY_COLORS_LIGHT).toObject()); const QHash<QString, QColor> lightModeColorOverrides = colorsFromJSON(config.value(KEY_COLORS_LIGHT).toObject());
for (auto overridesIt = lightModeColorOverrides.cbegin(); overridesIt != lightModeColorOverrides.cend(); ++overridesIt) for (auto overridesIt = lightModeColorOverrides.cbegin(); overridesIt != lightModeColorOverrides.cend(); ++overridesIt)
{ {
auto it = m_colors.find(overridesIt.key()); auto it = m_colors.find(overridesIt.key());
@ -175,7 +175,7 @@ void DefaultThemeSource::loadColors()
it.value().light = overridesIt.value(); it.value().light = overridesIt.value();
} }
QHash<QString, QColor> darkModeColorOverrides = colorsFromJSON(config.value(KEY_COLORS_DARK).toObject()); const QHash<QString, QColor> darkModeColorOverrides = colorsFromJSON(config.value(KEY_COLORS_DARK).toObject());
for (auto overridesIt = darkModeColorOverrides.cbegin(); overridesIt != darkModeColorOverrides.cend(); ++overridesIt) for (auto overridesIt = darkModeColorOverrides.cbegin(); overridesIt != darkModeColorOverrides.cend(); ++overridesIt)
{ {
auto it = m_colors.find(overridesIt.key()); 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 QColor CustomThemeSource::getColor(const QString &colorId, const ColorMode colorMode) const
{ {
if (colorMode == ColorMode::Dark) if (colorMode == ColorMode::Dark)
@ -246,6 +252,11 @@ DefaultThemeSource *CustomThemeSource::defaultThemeSource() const
return m_defaultThemeSource.get(); return m_defaultThemeSource.get();
} }
Path CustomThemeSource::themeRootPath() const
{
return m_themeRootPath;
}
void CustomThemeSource::loadColors() void CustomThemeSource::loadColors()
{ {
const auto readResult = Utils::IO::readFile((themeRootPath() / Path(CONFIG_FILE_NAME)), FILE_MAX_SIZE, QIODevice::Text); const auto readResult = Utils::IO::readFile((themeRootPath() / Path(CONFIG_FILE_NAME)), FILE_MAX_SIZE, QIODevice::Text);
@ -257,7 +268,7 @@ void CustomThemeSource::loadColors()
return; return;
} }
const QByteArray configData = readResult.value(); const QByteArray &configData = readResult.value();
if (configData.isEmpty()) if (configData.isEmpty())
return; return;
@ -267,13 +278,9 @@ void CustomThemeSource::loadColors()
m_darkModeColors.insert(colorsFromJSON(config.value(KEY_COLORS_DARK).toObject())); m_darkModeColors.insert(colorsFromJSON(config.value(KEY_COLORS_DARK).toObject()));
} }
Path QRCThemeSource::themeRootPath() const
{
return Path(u":/uitheme"_s);
}
FolderThemeSource::FolderThemeSource(const Path &folderPath) 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; const QString stylesheetResourcesDir = u":/uitheme"_s;
QByteArray styleSheetData = CustomThemeSource::readStyleSheet(); 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;
} }

View file

@ -84,21 +84,24 @@ public:
QByteArray readStyleSheet() override; QByteArray readStyleSheet() override;
protected: protected:
virtual Path themeRootPath() const = 0; explicit CustomThemeSource(const Path &themeRootPath);
DefaultThemeSource *defaultThemeSource() const; DefaultThemeSource *defaultThemeSource() const;
private: private:
Path themeRootPath() const;
void loadColors(); void loadColors();
const std::unique_ptr<DefaultThemeSource> m_defaultThemeSource = std::make_unique<DefaultThemeSource>(); const std::unique_ptr<DefaultThemeSource> m_defaultThemeSource = std::make_unique<DefaultThemeSource>();
Path m_themeRootPath;
QHash<QString, QColor> m_colors; QHash<QString, QColor> m_colors;
QHash<QString, QColor> m_darkModeColors; QHash<QString, QColor> m_darkModeColors;
}; };
class QRCThemeSource final : public CustomThemeSource class QRCThemeSource final : public CustomThemeSource
{ {
private: public:
Path themeRootPath() const override; QRCThemeSource();
}; };
class FolderThemeSource : public CustomThemeSource class FolderThemeSource : public CustomThemeSource
@ -109,7 +112,5 @@ public:
QByteArray readStyleSheet() override; QByteArray readStyleSheet() override;
private: private:
Path themeRootPath() const override;
const Path m_folder; const Path m_folder;
}; };