From cf9e2ecf491de0e5c993d705548a1e491bfdf080 Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Tue, 24 Jun 2025 15:12:26 -0400 Subject: [PATCH] refactor: simplify setting the fallback theme search path, does require sub dirs but we should only need the theme root refactor: set the Icon theme in deskflow-gui insetead of MainWindow --- src/apps/deskflow-gui/deskflow-gui.cpp | 9 +++++++-- src/lib/gui/MainWindow.cpp | 6 ------ src/lib/gui/StyleUtils.h | 27 -------------------------- 3 files changed, 7 insertions(+), 35 deletions(-) diff --git a/src/apps/deskflow-gui/deskflow-gui.cpp b/src/apps/deskflow-gui/deskflow-gui.cpp index e55b6d0c4..8d6cb03f1 100644 --- a/src/apps/deskflow-gui/deskflow-gui.cpp +++ b/src/apps/deskflow-gui/deskflow-gui.cpp @@ -111,8 +111,13 @@ int main(int argc, char *argv[]) } #endif - // Sets the fallback icon path - setIconFallbackPaths(); + // Sets the fallback icon path and fallback theme + const auto themeName = QStringLiteral("deskflow-%1").arg(iconMode()); + if (QIcon::themeName().isEmpty()) + QIcon::setThemeName(themeName); + else + QIcon::setFallbackThemeName(themeName); + QIcon::setFallbackSearchPaths({QStringLiteral(":/icons/%1").arg(themeName)}); qInstallMessageHandler(deskflow::gui::messages::messageHandler); qInfo("%s v%s", kAppName, qPrintable(kVersion)); diff --git a/src/lib/gui/MainWindow.cpp b/src/lib/gui/MainWindow.cpp index d49c00e11..96afb2f5a 100644 --- a/src/lib/gui/MainWindow.cpp +++ b/src/lib/gui/MainWindow.cpp @@ -83,12 +83,6 @@ MainWindow::MainWindow() m_actionRestartCore{new QAction(tr("Rest&art"), this)}, m_actionStopCore{new QAction(tr("S&top"), this)} { - const auto themeName = QStringLiteral("deskflow-%1").arg(iconMode()); - if (QIcon::themeName().isEmpty()) - QIcon::setThemeName(themeName); - else - QIcon::setFallbackThemeName(themeName); - ui->setupUi(this); // Setup Actions diff --git a/src/lib/gui/StyleUtils.h b/src/lib/gui/StyleUtils.h index d88a05c45..1ef899387 100644 --- a/src/lib/gui/StyleUtils.h +++ b/src/lib/gui/StyleUtils.h @@ -35,31 +35,4 @@ inline QString iconMode() return isDarkMode() ? QStringLiteral("dark") : QStringLiteral("light"); } -/** - * @brief checkSubDir checks for subdirs in a dir - * @param path The path to check for subdirs - * @return list of subdirs - */ -inline QStringList checkSubDir(const QString &path) -{ - QStringList paths; - auto dir = QDir(path); - const QFileInfoList items = dir.entryInfoList({"*"}, QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); - for (const QFileInfo &item : items) { - if (item.isDir()) { - paths.append(item.absoluteFilePath()); - paths.append(checkSubDir(item.absoluteFilePath())); - } - } - return paths; -} - -/** - * @brief setIconFallbackPaths Set the icon fallback path to our light or dark theme - */ -inline void setIconFallbackPaths() -{ - QStringList paths = checkSubDir(QStringLiteral(":/icons/deskflow-%1").arg(iconMode())); - QIcon::setFallbackSearchPaths(paths); -} } // namespace deskflow::gui