18#include "iconcachewatcher.h"
24IconCacheWatcher::IconCacheWatcher(QObject *parent)
26 m_watcher(new QFileSystemWatcher(this))
29 QStringList baseDirs = {
32 QDir::homePath() +
"/.local/share"
35 QStringList cacheFiles;
36 QStringList foldersToWatch;
37 for (
const QString &base : baseDirs) {
39 QString iconsDir = base +
"/icons";
42 foldersToWatch << iconsDir;
43 QFileInfoList subdirs = icons.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
44 for (
const QFileInfo &subdir : subdirs) {
45 QString cachePath = subdir.absoluteFilePath() +
"/icon-theme.cache";
46 if (QFile::exists(cachePath)) {
47 cacheFiles << cachePath;
52 QString pixmapsDir = base +
"/pixmaps";
53 QDir pixmaps(pixmapsDir);
54 if (pixmaps.exists()) {
55 foldersToWatch << pixmapsDir;
58 QString metaGuiDir = base +
"/meta/gui";
59 QDir metaGui(metaGuiDir);
60 if (metaGui.exists()) {
61 foldersToWatch << metaGuiDir;
65 if (!cacheFiles.isEmpty()) {
66 m_watcher->addPaths(cacheFiles);
67 connect(m_watcher, &QFileSystemWatcher::fileChanged,
68 this, &IconCacheWatcher::onCacheFileChanged);
71 if (!foldersToWatch.isEmpty()) {
72 m_watcher->addPaths(foldersToWatch);
73 connect(m_watcher, &QFileSystemWatcher::directoryChanged,
74 this, &IconCacheWatcher::onIconDirectoryChanged);
77 if (foldersToWatch.isEmpty() && cacheFiles.isEmpty()) {
78 qWarning() <<
"No icon-theme.cache files found in standard icon directories.";
80 qDebug() <<
"IconCacheWatcher initialized with" << foldersToWatch.size() <<
"directories and"
81 << cacheFiles.size() <<
"cache files.";
85void IconCacheWatcher::onCacheFileChanged(
const QString &path)
87 Q_EMIT iconCacheChanged();
89 if (QFile::exists(path)) {
90 m_watcher->addPath(path);
94void IconCacheWatcher::onIconDirectoryChanged(
const QString &path)
98 QStringList dpkgNewFiles = dir.entryList(QStringList(
"*.dpkg-new"), QDir::Files);
99 if (!dpkgNewFiles.isEmpty())
102 Q_EMIT iconCacheChanged();