aboutsummaryrefslogtreecommitdiff
path: root/launcher
diff options
context:
space:
mode:
authorSefa Eyeoglu <contact@scrumplex.net>2023-08-15 10:43:29 +0200
committerGitHub <noreply@github.com>2023-08-15 10:43:29 +0200
commit7ba1e7d3569fcb04cb49d16247703bf2862172ba (patch)
tree9eb12949538323c2afa9545907057c4e575ce7c2 /launcher
parentf533173b9589a0c3bfca0845b0c3939f5131c018 (diff)
parent6ce7e426d2e3bbca74719da073eb46d05b001439 (diff)
downloadPrismLauncher-7ba1e7d3569fcb04cb49d16247703bf2862172ba.tar.gz
PrismLauncher-7ba1e7d3569fcb04cb49d16247703bf2862172ba.tar.bz2
PrismLauncher-7ba1e7d3569fcb04cb49d16247703bf2862172ba.zip
Merge pull request #1407 from TheKodeToad/icon-indexing
Diffstat (limited to 'launcher')
-rw-r--r--launcher/Application.cpp51
-rw-r--r--launcher/Application.h13
-rw-r--r--launcher/CMakeLists.txt2
-rw-r--r--launcher/DesktopServices.cpp2
-rw-r--r--launcher/resources/multimc/index.theme2
-rw-r--r--launcher/resources/pe_blue/index.theme2
-rw-r--r--launcher/resources/pe_colored/index.theme2
-rw-r--r--launcher/resources/pe_dark/index.theme2
-rw-r--r--launcher/resources/pe_light/index.theme2
-rw-r--r--launcher/ui/MainWindow.cpp32
-rw-r--r--launcher/ui/MainWindow.h9
-rw-r--r--launcher/ui/MainWindow.ui57
-rw-r--r--launcher/ui/instanceview/InstanceView.cpp4
-rw-r--r--launcher/ui/setupwizard/ThemeWizardPage.cpp2
-rw-r--r--launcher/ui/themes/IconTheme.cpp53
-rw-r--r--launcher/ui/themes/IconTheme.h37
-rw-r--r--launcher/ui/themes/ThemeManager.cpp192
-rw-r--r--launcher/ui/themes/ThemeManager.h23
-rw-r--r--launcher/ui/widgets/ThemeCustomizationWidget.cpp40
-rw-r--r--launcher/ui/widgets/ThemeCustomizationWidget.h16
-rw-r--r--launcher/ui/widgets/ThemeCustomizationWidget.ui98
21 files changed, 453 insertions, 188 deletions
diff --git a/launcher/Application.cpp b/launcher/Application.cpp
index 6194527c..a1393510 100644
--- a/launcher/Application.cpp
+++ b/launcher/Application.cpp
@@ -492,7 +492,7 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
m_settings.reset(new INISettingsObject({ BuildConfig.LAUNCHER_CONFIGFILE, "polymc.cfg", "multimc.cfg" }, this));
// Theming
- m_settings->registerSetting("IconTheme", QString("pe_colored"));
+ m_settings->registerSetting("IconTheme", QString());
m_settings->registerSetting("ApplicationTheme", QString());
m_settings->registerSetting("BackgroundCat", QString("kitteh"));
@@ -754,7 +754,7 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
}
// Themes
- m_themeManager = std::make_unique<ThemeManager>(m_mainWindow);
+ m_themeManager = std::make_unique<ThemeManager>();
// initialize and load all instances
{
@@ -840,14 +840,13 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
}
});
- applyCurrentlySelectedTheme(true);
-
updateCapabilities();
if (createSetupWizard()) {
return;
}
+ m_themeManager->applyCurrentlySelectedTheme(true);
performMainStartupAction();
}
@@ -873,10 +872,20 @@ bool Application::createSetupWizard()
}();
bool languageRequired = settings()->get("Language").toString().isEmpty();
bool pasteInterventionRequired = settings()->get("PastebinURL") != "";
- bool themeInterventionRequired = settings()->get("ApplicationTheme") == "";
+ bool validWidgets = m_themeManager->isValidApplicationTheme(settings()->get("ApplicationTheme").toString());
+ bool validIcons = m_themeManager->isValidIconTheme(settings()->get("IconTheme").toString());
+ bool themeInterventionRequired = !validWidgets || !validIcons;
bool wizardRequired = javaRequired || languageRequired || pasteInterventionRequired || themeInterventionRequired;
if (wizardRequired) {
+ // set default theme after going into theme wizard
+ if (!validIcons)
+ settings()->set("IconTheme", QString("pe_colored"));
+ if (!validWidgets)
+ settings()->set("ApplicationTheme", QString("system"));
+
+ m_themeManager->applyCurrentlySelectedTheme(true);
+
m_setupWizard = new SetupWizard(nullptr);
if (languageRequired) {
m_setupWizard->addPage(new LanguageWizardPage(m_setupWizard));
@@ -891,9 +900,9 @@ bool Application::createSetupWizard()
}
if (themeInterventionRequired) {
- settings()->set("ApplicationTheme", QString("system")); // set default theme after going into theme wizard
m_setupWizard->addPage(new ThemeWizardPage(m_setupWizard));
}
+
connect(m_setupWizard, &QDialog::finished, this, &Application::setupWizardFinished);
m_setupWizard->show();
return true;
@@ -1070,26 +1079,6 @@ std::shared_ptr<JavaInstallList> Application::javalist()
return m_javalist;
}
-QList<ITheme*> Application::getValidApplicationThemes()
-{
- return m_themeManager->getValidApplicationThemes();
-}
-
-void Application::applyCurrentlySelectedTheme(bool initial)
-{
- m_themeManager->applyCurrentlySelectedTheme(initial);
-}
-
-void Application::setApplicationTheme(const QString& name)
-{
- m_themeManager->setApplicationTheme(name);
-}
-
-void Application::setIconTheme(const QString& name)
-{
- m_themeManager->setIconTheme(name);
-}
-
QIcon Application::getThemedIcon(const QString& name)
{
if (name == "logo") {
@@ -1098,16 +1087,6 @@ QIcon Application::getThemedIcon(const QString& name)
return QIcon::fromTheme(name);
}
-QList<CatPack*> Application::getValidCatPacks()
-{
- return m_themeManager->getValidCatPacks();
-}
-
-QString Application::getCatPack(QString catName)
-{
- return m_themeManager->getCatPack(catName);
-}
-
bool Application::openJsonEditor(const QString& filename)
{
const QString file = QDir::current().absoluteFilePath(filename);
diff --git a/launcher/Application.h b/launcher/Application.h
index cf7967a5..6bc33274 100644
--- a/launcher/Application.h
+++ b/launcher/Application.h
@@ -71,6 +71,7 @@ class TranslationsModel;
class ITheme;
class MCEditTool;
class ThemeManager;
+class IconTheme;
namespace Meta {
class Index;
@@ -109,17 +110,7 @@ class Application : public QApplication {
QIcon getThemedIcon(const QString& name);
- void setIconTheme(const QString& name);
-
- void applyCurrentlySelectedTheme(bool initial = false);
-
- QList<ITheme*> getValidApplicationThemes();
-
- void setApplicationTheme(const QString& name);
-
- QList<CatPack*> getValidCatPacks();
-
- QString getCatPack(QString catName = "");
+ ThemeManager* themeManager() { return m_themeManager.get(); }
shared_qobject_ptr<ExternalUpdater> updater() { return m_updater; }
diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt
index 84edab59..18e0acab 100644
--- a/launcher/CMakeLists.txt
+++ b/launcher/CMakeLists.txt
@@ -774,6 +774,8 @@ SET(LAUNCHER_SOURCES
ui/themes/ITheme.h
ui/themes/SystemTheme.cpp
ui/themes/SystemTheme.h
+ ui/themes/IconTheme.cpp
+ ui/themes/IconTheme.h
ui/themes/ThemeManager.cpp
ui/themes/ThemeManager.h
ui/themes/CatPack.cpp
diff --git a/launcher/DesktopServices.cpp b/launcher/DesktopServices.cpp
index 6b738f2c..004e5e08 100644
--- a/launcher/DesktopServices.cpp
+++ b/launcher/DesktopServices.cpp
@@ -101,7 +101,7 @@ bool openDirectory(const QString& path, [[maybe_unused]] bool ensureExists)
qDebug() << "Opening directory" << path;
QDir parentPath;
QDir dir(path);
- if (!dir.exists()) {
+ if (ensureExists && !dir.exists()) {
parentPath.mkpath(dir.absolutePath());
}
auto f = [&]() { return QDesktopServices::openUrl(QUrl::fromLocalFile(dir.absolutePath())); };
diff --git a/launcher/resources/multimc/index.theme b/launcher/resources/multimc/index.theme
index 070e23f1..4da8072d 100644
--- a/launcher/resources/multimc/index.theme
+++ b/launcher/resources/multimc/index.theme
@@ -1,5 +1,5 @@
[Icon Theme]
-Name=multimc
+Name=Legacy
Comment=Default Icons
Inherits=default
Directories=8x8,16x16,22x22,24x24,32x32,32x32/instances,48x48,50x50/instances,64x64,128x128/instances,256x256,scalable,scalable/instances
diff --git a/launcher/resources/pe_blue/index.theme b/launcher/resources/pe_blue/index.theme
index c9e0d93a..6d842b5d 100644
--- a/launcher/resources/pe_blue/index.theme
+++ b/launcher/resources/pe_blue/index.theme
@@ -1,5 +1,5 @@
[Icon Theme]
-Name=pe_blue
+Name=Simple (Blue)
Comment=Icons by pexner (blue)
Inherits=multimc
Directories=scalable
diff --git a/launcher/resources/pe_colored/index.theme b/launcher/resources/pe_colored/index.theme
index b757bbd7..bca5494f 100644
--- a/launcher/resources/pe_colored/index.theme
+++ b/launcher/resources/pe_colored/index.theme
@@ -1,5 +1,5 @@
[Icon Theme]
-Name=pe_colored
+Name=Simple (Colored)
Comment=Icons by pexner (colored)
Inherits=multimc
Directories=scalable
diff --git a/launcher/resources/pe_dark/index.theme b/launcher/resources/pe_dark/index.theme
index b7d1ad01..4cfbf09c 100644
--- a/launcher/resources/pe_dark/index.theme
+++ b/launcher/resources/pe_dark/index.theme
@@ -1,5 +1,5 @@
[Icon Theme]
-Name=pe_dark
+Name=Simple (Dark)
Comment=Icons by pexner (dark)
Inherits=multimc
Directories=scalable
diff --git a/launcher/resources/pe_light/index.theme b/launcher/resources/pe_light/index.theme
index c106acc8..87b76d13 100644
--- a/launcher/resources/pe_light/index.theme
+++ b/launcher/resources/pe_light/index.theme
@@ -1,5 +1,5 @@
[Icon Theme]
-Name=pe_light
+Name=Simple (Light)
Comment=Icons by pexner (light)
Inherits=multimc
Directories=scalable
diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp
index bb88d74e..a83ff1a2 100644
--- a/launcher/ui/MainWindow.cpp
+++ b/launcher/ui/MainWindow.cpp
@@ -627,7 +627,7 @@ void MainWindow::updateThemeMenu()
themeMenu = new QMenu(this);
}
- auto themes = APPLICATION->getValidApplicationThemes();
+ auto themes = APPLICATION->themeManager()->getValidApplicationThemes();
QActionGroup* themesGroup = new QActionGroup(this);
@@ -641,7 +641,7 @@ void MainWindow::updateThemeMenu()
themeAction->setActionGroup(themesGroup);
connect(themeAction, &QAction::triggered, [theme]() {
- APPLICATION->setApplicationTheme(theme->id());
+ APPLICATION->themeManager()->setApplicationTheme(theme->id());
APPLICATION->settings()->set("ApplicationTheme", theme->id());
});
}
@@ -1134,26 +1134,40 @@ void MainWindow::undoTrashInstance()
ui->actionUndoTrashInstance->setEnabled(APPLICATION->instances()->trashedSomething());
}
+void MainWindow::on_actionViewLauncherRootFolder_triggered()
+{
+ DesktopServices::openDirectory(".");
+}
+
void MainWindow::on_actionViewInstanceFolder_triggered()
{
QString str = APPLICATION->settings()->get("InstanceDir").toString();
DesktopServices::openDirectory(str);
}
-void MainWindow::on_actionViewLauncherRootFolder_triggered()
+void MainWindow::on_actionViewCentralModsFolder_triggered()
{
- const QString dataPath = QDir::currentPath();
- DesktopServices::openDirectory(dataPath);
+ DesktopServices::openDirectory(APPLICATION->settings()->get("CentralModsDir").toString(), true);
}
-void MainWindow::refreshInstances()
+void MainWindow::on_actionViewIconThemeFolder_triggered()
{
- APPLICATION->instances()->loadList();
+ DesktopServices::openDirectory(APPLICATION->themeManager()->getIconThemesFolder().path());
}
-void MainWindow::on_actionViewCentralModsFolder_triggered()
+void MainWindow::on_actionViewWidgetThemeFolder_triggered()
{
- DesktopServices::openDirectory(APPLICATION->settings()->get("CentralModsDir").toString(), true);
+ DesktopServices::openDirectory(APPLICATION->themeManager()->getApplicationThemesFolder().path());
+}
+
+void MainWindow::on_actionViewCatPackFolder_triggered()
+{
+ DesktopServices::openDirectory(APPLICATION->themeManager()->getCatPacksFolder().path());
+}
+
+void MainWindow::refreshInstances()
+{
+ APPLICATION->instances()->loadList();
}
void MainWindow::checkForUpdates()
diff --git a/launcher/ui/MainWindow.h b/launcher/ui/MainWindow.h
index e6434dae..be9c4994 100644
--- a/launcher/ui/MainWindow.h
+++ b/launcher/ui/MainWindow.h
@@ -109,16 +109,19 @@ class MainWindow : public QMainWindow {
void on_actionChangeInstIcon_triggered();
+ void on_actionViewLauncherRootFolder_triggered();
+
void on_actionViewInstanceFolder_triggered();
+ void on_actionViewCentralModsFolder_triggered();
- void on_actionViewLauncherRootFolder_triggered();
+ void on_actionViewIconThemeFolder_triggered();
+ void on_actionViewWidgetThemeFolder_triggered();
+ void on_actionViewCatPackFolder_triggered();
void on_actionViewSelectedInstFolder_triggered();
void refreshInstances();
- void on_actionViewCentralModsFolder_triggered();
-
void checkForUpdates();
void on_actionSettings_triggered();
diff --git a/launcher/ui/MainWindow.ui b/launcher/ui/MainWindow.ui
index e4421d40..6ef32099 100644
--- a/launcher/ui/MainWindow.ui
+++ b/launcher/ui/MainWindow.ui
@@ -186,9 +186,14 @@
<property name="toolTipsVisible">
<bool>true</bool>
</property>
- <addaction name="actionViewInstanceFolder"/>
<addaction name="actionViewLauncherRootFolder"/>
+ <addaction name="separator"/>
+ <addaction name="actionViewInstanceFolder"/>
<addaction name="actionViewCentralModsFolder"/>
+ <addaction name="separator"/>
+ <addaction name="actionViewIconThemeFolder"/>
+ <addaction name="actionViewWidgetThemeFolder"/>
+ <addaction name="actionViewCatPackFolder"/>
</widget>
<widget class="QMenu" name="accountsMenu">
<property name="title">
@@ -465,7 +470,8 @@
</action>
<action name="actionExportInstanceZip">
<property name="icon">
- <iconset theme="launcher"/>
+ <iconset theme="launcher">
+ <normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>Prism Launcher (zip)</string>
@@ -473,7 +479,8 @@
</action>
<action name="actionExportInstanceMrPack">
<property name="icon">
- <iconset theme="modrinth"/>
+ <iconset theme="modrinth">
+ <normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>Modrinth (mrpack)</string>
@@ -481,15 +488,17 @@
</action>
<action name="actionExportInstanceFlamePack">
<property name="icon">
- <iconset theme="flame"/>
+ <iconset theme="flame">
+ <normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
- <string>CurseForge (zip)</string>
+ <string>CurseForge (zip)</string>
</property>
</action>
<action name="actionExportInstanceToModList">
<property name="icon">
- <iconset theme="new"/>
+ <iconset theme="new">
+ <normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>Mod List</string>
@@ -552,7 +561,7 @@
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
- <string>&amp;View Instance Folder</string>
+ <string>View &amp;Instance Folder</string>
</property>
<property name="toolTip">
<string>Open the instance folder in a file browser.</string>
@@ -564,7 +573,7 @@
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
- <string>&amp;View Launcher Root Folder</string>
+ <string>View Launcher &amp;Root Folder</string>
</property>
<property name="toolTip">
<string>Open the launcher's root folder in a file browser.</string>
@@ -719,6 +728,38 @@
<string>Open the %1 wiki</string>
</property>
</action>
+ <action name="actionViewWidgetThemeFolder">
+ <property name="icon">
+ <iconset theme="viewfolder">
+ <normaloff>.</normaloff>.</iconset>
+ </property>
+ <property name="text">
+ <string>View &amp;Widget Themes Folder</string>
+ </property>
+ <property name="toolTip">
+ <string>View Widget Theme Folder</string>
+ </property>
+ </action>
+ <action name="actionViewIconThemeFolder">
+ <property name="icon">
+ <iconset theme="viewfolder">
+ <normaloff>.</normaloff>.</iconset>
+ </property>
+ <property name="text">
+ <string>View I&amp;con Theme Folder</string>
+ </property>
+ <property name="toolTip">
+ <string>View Icon Theme Folder</string>
+ </property>
+ </action>
+ <action name="actionViewCatPackFolder">
+ <property name="icon">
+ <iconset theme="viewfolder"/>
+ </property>
+ <property name="text">
+ <string>View Cat Packs Folder</string>
+ </property>
+ </action>
</widget>
<customwidgets>
<customwidget>
diff --git a/launcher/ui/instanceview/InstanceView.cpp b/launcher/ui/instanceview/InstanceView.cpp
index 607f3cad..690dc917 100644
--- a/launcher/ui/instanceview/InstanceView.cpp
+++ b/launcher/ui/instanceview/InstanceView.cpp
@@ -47,8 +47,8 @@
#include <QScrollBar>
#include <QtMath>
-#include <QDebug>
#include "VisualGroup.h"
+#include "ui/themes/ThemeManager.h"
#include <Application.h>
#include <InstanceList.h>
@@ -446,7 +446,7 @@ void InstanceView::setPaintCat(bool visible)
{
m_catVisible = visible;
if (visible)
- m_catPixmap.load(APPLICATION->getCatPack());
+ m_catPixmap.load(APPLICATION->themeManager()->getCatPack());
else
m_catPixmap = QPixmap();
}
diff --git a/launcher/ui/setupwizard/ThemeWizardPage.cpp b/launcher/ui/setupwizard/ThemeWizardPage.cpp
index 1c336921..fe11ed9a 100644
--- a/launcher/ui/setupwizard/ThemeWizardPage.cpp
+++ b/launcher/ui/setupwizard/ThemeWizardPage.cpp
@@ -61,7 +61,7 @@ void ThemeWizardPage::updateIcons()
void ThemeWizardPage::updateCat()
{
qDebug() << "Setting Cat";
- ui->catImagePreviewButton->setIcon(QIcon(QString(R"(%1)").arg(APPLICATION->getCatPack())));
+ ui->catImagePreviewButton->setIcon(QIcon(QString(R"(%1)").arg(APPLICATION->themeManager()->getCatPack())));
}
void ThemeWizardPage::retranslate()
diff --git a/launcher/ui/themes/IconTheme.cpp b/launcher/ui/themes/IconTheme.cpp
new file mode 100644
index 00000000..4bd88985
--- /dev/null
+++ b/launcher/ui/themes/IconTheme.cpp
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include "IconTheme.h"
+
+#include <QFile>
+#include <QSettings>
+
+IconTheme::IconTheme(const QString& id, const QString& path) : m_id(id), m_path(path) {}
+
+bool IconTheme::load()
+{
+ const QString path = m_path + "/index.theme";
+
+ if (!QFile::exists(path))
+ return false;
+
+ QSettings settings(path, QSettings::IniFormat);
+ settings.beginGroup("Icon Theme");
+ m_name = settings.value("Name").toString();
+ settings.endGroup();
+ return !m_name.isNull();
+}
+
+QString IconTheme::id()
+{
+ return m_id;
+}
+
+QString IconTheme::path()
+{
+ return m_path;
+}
+
+QString IconTheme::name()
+{
+ return m_name;
+}
diff --git a/launcher/ui/themes/IconTheme.h b/launcher/ui/themes/IconTheme.h
new file mode 100644
index 00000000..4e466c6a
--- /dev/null
+++ b/launcher/ui/themes/IconTheme.h
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <QString>
+
+class IconTheme {
+ public:
+ IconTheme(const QString& id, const QString& path);
+ IconTheme() = default;
+
+ bool load();
+ QString id();
+ QString path();
+ QString name();
+
+ private:
+ QString m_id;
+ QString m_path;
+ QString m_name;
+};
diff --git a/launcher/ui/themes/ThemeManager.cpp b/launcher/ui/themes/ThemeManager.cpp
index 321f7db4..0bcac100 100644
--- a/launcher/ui/themes/ThemeManager.cpp
+++ b/launcher/ui/themes/ThemeManager.cpp
@@ -2,6 +2,7 @@
/*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Tayou <git@tayou.org>
+ * Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -31,9 +32,8 @@
#include "Application.h"
-ThemeManager::ThemeManager(MainWindow* mainWindow)
+ThemeManager::ThemeManager()
{
- m_mainWindow = mainWindow;
initializeThemes();
initializeCatPacks();
}
@@ -59,53 +59,110 @@ ITheme* ThemeManager::getTheme(QString themeId)
return m_themes[themeId].get();
}
+QString ThemeManager::addIconTheme(IconTheme theme)
+{
+ QString id = theme.id();
+ if (m_icons.find(id) == m_icons.end())
+ m_icons.emplace(id, std::move(theme));
+ else
+ themeWarningLog() << "IconTheme(" << id << ") not added to prevent id duplication";
+ return id;
+}
+
void ThemeManager::initializeThemes()
{
// Icon themes
- {
- // TODO: icon themes and instance icons do not mesh well together. Rearrange and fix discrepancies!
- // set icon theme search path!
- auto searchPaths = QIcon::themeSearchPaths();
- searchPaths.append("iconthemes");
- QIcon::setThemeSearchPaths(searchPaths);
- themeDebugLog() << "<> Icon themes initialized.";
- }
+ initializeIcons();
// Initialize widget themes
- {
- themeDebugLog() << "<> Initializing Widget Themes";
- themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<SystemTheme>());
- auto darkThemeId = addTheme(std::make_unique<DarkTheme>());
- themeDebugLog() << "Loading Built-in Theme:" << darkThemeId;
- themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<BrightTheme>());
-
- // TODO: need some way to differentiate same name themes in different subdirectories (maybe smaller grey text next to theme name in
- // dropdown?)
- QString themeFolder = QDir("./themes/").absoluteFilePath("");
- themeDebugLog() << "Theme Folder Path: " << themeFolder;
-
- QDirIterator directoryIterator(themeFolder, QDir::Dirs | QDir::NoDotAndDotDot);
- while (directoryIterator.hasNext()) {
- QDir dir(directoryIterator.next());
- QFileInfo themeJson(dir.absoluteFilePath("theme.json"));
- if (themeJson.exists()) {
- // Load "theme.json" based themes
- themeDebugLog() << "Loading JSON Theme from:" << themeJson.absoluteFilePath();
- addTheme(std::make_unique<CustomTheme>(getTheme(darkThemeId), themeJson, true));
- } else {
- // Load pure QSS Themes
- QDirIterator stylesheetFileIterator(dir.absoluteFilePath(""), { "*.qss", "*.css" }, QDir::Files);
- while (stylesheetFileIterator.hasNext()) {
- QFile customThemeFile(stylesheetFileIterator.next());
- QFileInfo customThemeFileInfo(customThemeFile);
- themeDebugLog() << "Loading QSS Theme from:" << customThemeFileInfo.absoluteFilePath();
- addTheme(std::make_unique<CustomTheme>(getTheme(darkThemeId), customThemeFileInfo, false));
- }
+ initializeWidgets();
+}
+
+void ThemeManager::initializeIcons()
+{
+ // TODO: icon themes and instance icons do not mesh well together. Rearrange and fix discrepancies!
+ // set icon theme search path!
+ themeDebugLog() << "<> Initializing Icon Themes";
+
+ auto searchPaths = QIcon::themeSearchPaths();
+ searchPaths.append(m_iconThemeFolder.path());
+ QIcon::setThemeSearchPaths(searchPaths);
+
+ for (const QString& id : builtinIcons) {
+ IconTheme theme(id, QString(":/icons/%1").arg(id));
+ if (!theme.load()) {
+ themeWarningLog() << "Couldn't load built-in icon theme" << id;
+ continue;
+ }
+
+ addIconTheme(std::move(theme));
+ themeDebugLog() << "Loaded Built-In Icon Theme" << id;
+ }
+
+ if (!m_iconThemeFolder.mkpath("."))
+ themeWarningLog() << "Couldn't create icon theme folder";
+ themeDebugLog() << "Icon Theme Folder Path: " << m_iconThemeFolder.absolutePath();
+
+ QDirIterator directoryIterator(m_iconThemeFolder.path(), QDir::Dirs | QDir::NoDotAndDotDot);
+ while (directoryIterator.hasNext()) {
+ QDir dir(directoryIterator.next());
+ IconTheme theme(dir.dirName(), dir.path());
+ if (!theme.load())
+ continue;
+
+ addIconTheme(std::move(theme));
+ themeDebugLog() << "Loaded Custom Icon Theme from" << dir.path();
+ }
+
+ themeDebugLog() << "<> Icon themes initialized.";
+}
+
+void ThemeManager::initializeWidgets()
+{
+ themeDebugLog() << "<> Initializing Widget Themes";
+ themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<SystemTheme>());
+ auto darkThemeId = addTheme(std::make_unique<DarkTheme>());
+ themeDebugLog() << "Loading Built-in Theme:" << darkThemeId;
+ themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<BrightTheme>());
+
+ // TODO: need some way to differentiate same name themes in different subdirectories (maybe smaller grey text next to theme name in
+ // dropdown?)
+
+ if (!m_applicationThemeFolder.mkpath("."))
+ themeWarningLog() << "Couldn't create theme folder";
+ themeDebugLog() << "Theme Folder Path: " << m_applicationThemeFolder.absolutePath();
+
+ QDirIterator directoryIterator(m_applicationThemeFolder.path(), QDir::Dirs | QDir::NoDotAndDotDot);
+ while (directoryIterator.hasNext()) {
+ QDir dir(directoryIterator.next());
+ QFileInfo themeJson(dir.absoluteFilePath("theme.json"));
+ if (themeJson.exists()) {
+ // Load "theme.json" based themes
+ themeDebugLog() << "Loading JSON Theme from:" << themeJson.absoluteFilePath();
+ addTheme(std::make_unique<CustomTheme>(getTheme(darkThemeId), themeJson, true));
+ } else {
+ // Load pure QSS Themes
+ QDirIterator stylesheetFileIterator(dir.absoluteFilePath(""), { "*.qss", "*.css" }, QDir::Files);
+ while (stylesheetFileIterator.hasNext()) {
+ QFile customThemeFile(stylesheetFileIterator.next());
+ QFileInfo customThemeFileInfo(customThemeFile);
+ themeDebugLog() << "Loading QSS Theme from:" << customThemeFileInfo.absoluteFilePath();
+ addTheme(std::make_unique<CustomTheme>(getTheme(darkThemeId), customThemeFileInfo, false));
}
}
+ }
- themeDebugLog() << "<> Widget themes initialized.";
+ themeDebugLog() << "<> Widget themes initialized.";
+}
+
+QList<IconTheme*> ThemeManager::getValidIconThemes()
+{
+ QList<IconTheme*> ret;
+ ret.reserve(m_icons.size());
+ for (auto&& [id, theme] : m_icons) {
+ ret.append(&theme);
}
+ return ret;
}
QList<ITheme*> ThemeManager::getValidApplicationThemes()
@@ -128,17 +185,39 @@ QList<CatPack*> ThemeManager::getValidCatPacks()
return ret;
}
-void ThemeManager::setIconTheme(const QString& name)
+bool ThemeManager::isValidIconTheme(const QString& id)
{
- QIcon::setThemeName(name);
+ return !id.isEmpty() && m_icons.find(id) != m_icons.end();
}
-void ThemeManager::applyCurrentlySelectedTheme(bool initial)
+bool ThemeManager::isValidApplicationTheme(const QString& id)
{
- setIconTheme(APPLICATION->settings()->get("IconTheme").toString());
- themeDebugLog() << "<> Icon theme set.";
- setApplicationTheme(APPLICATION->settings()->get("ApplicationTheme").toString(), initial);
- themeDebugLog() << "<> Application theme set.";
+ return !id.isEmpty() && m_themes.find(id) != m_themes.end();
+}
+
+QDir ThemeManager::getIconThemesFolder()
+{
+ return m_iconThemeFolder;
+}
+
+QDir ThemeManager::getApplicationThemesFolder()
+{
+