Sorting and invalid reset
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
parent
f55120654a
commit
96ebdfc9a8
@ -23,6 +23,7 @@
|
|||||||
class IconTheme {
|
class IconTheme {
|
||||||
public:
|
public:
|
||||||
IconTheme(const QString& id, const QString& path);
|
IconTheme(const QString& id, const QString& path);
|
||||||
|
IconTheme() = default;
|
||||||
|
|
||||||
bool load();
|
bool load();
|
||||||
QString id();
|
QString id();
|
||||||
|
@ -53,6 +53,13 @@ ITheme* ThemeManager::getTheme(QString themeId)
|
|||||||
return m_themes[themeId].get();
|
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()
|
void ThemeManager::initializeThemes()
|
||||||
{
|
{
|
||||||
// Icon themes
|
// Icon themes
|
||||||
@ -82,7 +89,7 @@ void ThemeManager::initializeIcons()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_icons.append(theme);
|
addIconTheme(std::move(theme));
|
||||||
themeDebugLog() << "Loaded Built-In Icon Theme" << id;
|
themeDebugLog() << "Loaded Built-In Icon Theme" << id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +100,7 @@ void ThemeManager::initializeIcons()
|
|||||||
if (!theme.load())
|
if (!theme.load())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
m_icons.append(theme);
|
addIconTheme(std::move(theme));
|
||||||
themeDebugLog() << "Loaded Custom Icon Theme from" << dir.path();
|
themeDebugLog() << "Loaded Custom Icon Theme from" << dir.path();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,25 +157,39 @@ QList<IconTheme*> ThemeManager::getValidIconThemes()
|
|||||||
{
|
{
|
||||||
QList<IconTheme*> ret;
|
QList<IconTheme*> ret;
|
||||||
ret.reserve(m_icons.size());
|
ret.reserve(m_icons.size());
|
||||||
for (IconTheme& theme : m_icons)
|
for (auto&& [id, theme] : m_icons) {
|
||||||
ret.append(&theme);
|
ret.append(&theme);
|
||||||
|
}
|
||||||
return ret;
|
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);
|
QIcon::setThemeName(name);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThemeManager::applyCurrentlySelectedTheme(bool initial)
|
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.";
|
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.";
|
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 systemPalette = qApp->palette();
|
||||||
auto themeIter = m_themes.find(name);
|
auto themeIter = m_themes.find(name);
|
||||||
@ -176,8 +197,10 @@ void ThemeManager::setApplicationTheme(const QString& name, bool initial)
|
|||||||
auto& theme = themeIter->second;
|
auto& theme = themeIter->second;
|
||||||
themeDebugLog() << "applying theme" << theme->name();
|
themeDebugLog() << "applying theme" << theme->name();
|
||||||
theme->apply(initial);
|
theme->apply(initial);
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
themeWarningLog() << "Tried to set invalid theme:" << name;
|
themeWarningLog() << "Tried to set invalid theme:" << name;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,9 +39,9 @@ class ThemeManager {
|
|||||||
|
|
||||||
QList<ITheme*> getValidApplicationThemes();
|
QList<ITheme*> getValidApplicationThemes();
|
||||||
QList<IconTheme*> getValidIconThemes();
|
QList<IconTheme*> getValidIconThemes();
|
||||||
void setIconTheme(const QString& name);
|
bool setIconTheme(const QString& name);
|
||||||
void applyCurrentlySelectedTheme(bool initial = false);
|
void applyCurrentlySelectedTheme(bool initial = false);
|
||||||
void setApplicationTheme(const QString& name, bool initial = false);
|
bool setApplicationTheme(const QString& name, bool initial = false);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the cat based on selected cat and with events (Birthday, XMas, etc.)
|
/// Returns the cat based on selected cat and with events (Birthday, XMas, etc.)
|
||||||
@ -52,12 +52,13 @@ class ThemeManager {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<QString, std::unique_ptr<ITheme>> m_themes;
|
std::map<QString, std::unique_ptr<ITheme>> m_themes;
|
||||||
QList<IconTheme> m_icons;
|
std::map<QString, IconTheme> m_icons;
|
||||||
MainWindow* m_mainWindow;
|
MainWindow* m_mainWindow;
|
||||||
|
|
||||||
void initializeThemes();
|
void initializeThemes();
|
||||||
QString addTheme(std::unique_ptr<ITheme> theme);
|
QString addTheme(std::unique_ptr<ITheme> theme);
|
||||||
ITheme* getTheme(QString themeId);
|
ITheme* getTheme(QString themeId);
|
||||||
|
QString addIconTheme(IconTheme theme);
|
||||||
void initializeIcons();
|
void initializeIcons();
|
||||||
void initializeWidgets();
|
void initializeWidgets();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user