diff options
author | TheKodeToad <TheKodeToad@proton.me> | 2023-07-19 14:12:39 +0100 |
---|---|---|
committer | TheKodeToad <TheKodeToad@proton.me> | 2023-07-19 14:12:39 +0100 |
commit | 96ebdfc9a88004056b6ec581f071678e08c0c989 (patch) | |
tree | 187225930939e15bef24760b33baf75c26aa3fe6 /launcher/ui/themes/ThemeManager.cpp | |
parent | f55120654aed5244040e1de59707b176bb816405 (diff) | |
download | PrismLauncher-96ebdfc9a88004056b6ec581f071678e08c0c989.tar.gz PrismLauncher-96ebdfc9a88004056b6ec581f071678e08c0c989.tar.bz2 PrismLauncher-96ebdfc9a88004056b6ec581f071678e08c0c989.zip |
Sorting and invalid reset
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
Diffstat (limited to 'launcher/ui/themes/ThemeManager.cpp')
-rw-r--r-- | launcher/ui/themes/ThemeManager.cpp | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/launcher/ui/themes/ThemeManager.cpp b/launcher/ui/themes/ThemeManager.cpp index 84e11ccf..8c9a6a58 100644 --- a/launcher/ui/themes/ThemeManager.cpp +++ b/launcher/ui/themes/ThemeManager.cpp @@ -53,6 +53,13 @@ ITheme* ThemeManager::getTheme(QString themeId) return m_themes[themeId].get(); } +QString ThemeManager::addIconTheme(IconTheme theme) +{ + QString id = theme.id(); + m_icons.emplace(id, std::move(theme)); + return id; +} + void ThemeManager::initializeThemes() { // Icon themes @@ -82,7 +89,7 @@ void ThemeManager::initializeIcons() continue; } - m_icons.append(theme); + addIconTheme(std::move(theme)); themeDebugLog() << "Loaded Built-In Icon Theme" << id; } @@ -93,7 +100,7 @@ void ThemeManager::initializeIcons() if (!theme.load()) continue; - m_icons.append(theme); + addIconTheme(std::move(theme)); themeDebugLog() << "Loaded Custom Icon Theme from" << dir.path(); } @@ -150,25 +157,39 @@ QList<IconTheme*> ThemeManager::getValidIconThemes() { QList<IconTheme*> ret; ret.reserve(m_icons.size()); - for (IconTheme& theme : m_icons) + for (auto&& [id, theme] : m_icons) { ret.append(&theme); + } return ret; } -void ThemeManager::setIconTheme(const QString& name) +bool ThemeManager::setIconTheme(const QString& name) { + if (m_icons.find(name) == m_icons.end()) { + themeWarningLog() << "Tried to set invalid icon theme:" << name; + return false; + } + QIcon::setThemeName(name); + return true; } void ThemeManager::applyCurrentlySelectedTheme(bool initial) { - setIconTheme(APPLICATION->settings()->get("IconTheme").toString()); + auto settings = APPLICATION->settings(); + if (!setIconTheme(settings->get("IconTheme").toString())) { + APPLICATION->settings()->reset("IconTheme"); + setIconTheme(settings->get("IconTheme").toString()); + } themeDebugLog() << "<> Icon theme set."; - setApplicationTheme(APPLICATION->settings()->get("ApplicationTheme").toString(), initial); + if (!setApplicationTheme(settings->get("ApplicationTheme").toString(), initial)) { + APPLICATION->settings()->reset("ApplicationTheme"); + setApplicationTheme(settings->get("ApplicationTheme").toString(), initial); + } themeDebugLog() << "<> Application theme set."; } -void ThemeManager::setApplicationTheme(const QString& name, bool initial) +bool ThemeManager::setApplicationTheme(const QString& name, bool initial) { auto systemPalette = qApp->palette(); auto themeIter = m_themes.find(name); @@ -176,8 +197,10 @@ void ThemeManager::setApplicationTheme(const QString& name, bool initial) auto& theme = themeIter->second; themeDebugLog() << "applying theme" << theme->name(); theme->apply(initial); + return true; } else { themeWarningLog() << "Tried to set invalid theme:" << name; + return false; } } |