From 511390cf5b929f154d7a80492d67c18c8c866f90 Mon Sep 17 00:00:00 2001
From: Capsia <cmsuser3754@zoho.eu>
Date: Sun, 17 Aug 2025 19:22:41 +0200
Subject: [PATCH 3/7] Expands icon monitoring

Extends the icon cache watcher to monitor pixmaps and meta/gui directories in standard share locations.
This ensures that changes to icons in these locations trigger a launcher refresh.

Signed-off-by: Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
---
 plugins/Lomiri/Launcher/iconcachewatcher.cpp | 66 +++++++++++++++-----
 plugins/Lomiri/Launcher/iconcachewatcher.h   |  1 +
 2 files changed, 50 insertions(+), 17 deletions(-)

diff --git a/plugins/Lomiri/Launcher/iconcachewatcher.cpp b/plugins/Lomiri/Launcher/iconcachewatcher.cpp
index 187971a88..3cf61560e 100644
--- a/plugins/Lomiri/Launcher/iconcachewatcher.cpp
+++ b/plugins/Lomiri/Launcher/iconcachewatcher.cpp
@@ -25,34 +25,61 @@ IconCacheWatcher::IconCacheWatcher(QObject *parent)
     : QObject(parent),
       m_watcher(new QFileSystemWatcher(this))
 {
-    // Standard icon directories
-    QStringList iconDirs = {
-        "/usr/share/icons",
-        "/usr/local/share/icons",
-        QDir::homePath() + "/.local/share/icons"
+    // List of base directories
+    QStringList baseDirs = {
+        "/usr/share",
+        "/usr/local/share",
+        QDir::homePath() + "/.local/share"
     };
 
     QStringList cacheFiles;
-    for (const QString &dir : iconDirs) {
-        QDir d(dir);
-        if (!d.exists()) continue;
-        // Look for icon-theme.cache in all subdirs
-        QFileInfoList subdirs = d.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
-        for (const QFileInfo &subdir : subdirs) {
-            QString cachePath = subdir.absoluteFilePath() + "/icon-theme.cache";
-            if (QFile::exists(cachePath)) {
-                cacheFiles << cachePath;
+    QStringList foldersToWatch;
+    for (const QString &base : baseDirs) {
+        // icons
+        QString iconsDir = base + "/icons";
+        QDir icons(iconsDir);
+        if (icons.exists()) {
+            foldersToWatch << iconsDir;
+            QFileInfoList subdirs = icons.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
+            for (const QFileInfo &subdir : subdirs) {
+                QString cachePath = subdir.absoluteFilePath() + "/icon-theme.cache";
+                if (QFile::exists(cachePath)) {
+                    cacheFiles << cachePath;
+                }
             }
         }
+        // pixmaps
+        QString pixmapsDir = base + "/pixmaps";
+        QDir pixmaps(pixmapsDir);
+        if (pixmaps.exists()) {
+            foldersToWatch << pixmapsDir;
+        }
+        // meta/gui
+        QString metaGuiDir = base + "/meta/gui";
+        QDir metaGui(metaGuiDir);
+        if (metaGui.exists()) {
+            foldersToWatch << metaGuiDir;
+        }
     }
 
-    if (cacheFiles.isEmpty()) {
-        qWarning() << "No icon-theme.cache files found in standard icon directories.";
-    } else {
+    if (!cacheFiles.isEmpty()) {
         m_watcher->addPaths(cacheFiles);
         connect(m_watcher, &QFileSystemWatcher::fileChanged,
                 this, &IconCacheWatcher::onCacheFileChanged);
     }
+
+    if (!foldersToWatch.isEmpty()) {
+        m_watcher->addPaths(foldersToWatch);
+        connect(m_watcher, &QFileSystemWatcher::directoryChanged,
+                this, &IconCacheWatcher::onIconDirectoryChanged);
+    }
+
+    if (foldersToWatch.isEmpty() && cacheFiles.isEmpty()) {
+        qWarning() << "No icon-theme.cache files found in standard icon directories.";
+    } else {
+        qDebug() << "IconCacheWatcher initialized with" << foldersToWatch.size() << "directories and"
+                 << cacheFiles.size() << "cache files.";
+    }
 }
 
 void IconCacheWatcher::onCacheFileChanged(const QString &path)
@@ -63,3 +90,8 @@ void IconCacheWatcher::onCacheFileChanged(const QString &path)
         m_watcher->addPath(path);
     }
 }
+
+void IconCacheWatcher::onIconDirectoryChanged(const QString &path)
+{
+    Q_EMIT iconCacheChanged();
+}
diff --git a/plugins/Lomiri/Launcher/iconcachewatcher.h b/plugins/Lomiri/Launcher/iconcachewatcher.h
index 4fd60aead..fe8930160 100644
--- a/plugins/Lomiri/Launcher/iconcachewatcher.h
+++ b/plugins/Lomiri/Launcher/iconcachewatcher.h
@@ -28,6 +28,7 @@ Q_SIGNALS:
 
 private Q_SLOTS:
     void onCacheFileChanged(const QString &path);
+    void onIconDirectoryChanged(const QString &path);
 
 private:
     QFileSystemWatcher *m_watcher;
-- 
2.47.2

