@@ -30,12 +30,6 @@ DesktopEntryMonitor::DesktopEntryMonitor(QObject* parent): QObject(parent) {
30
30
this ,
31
31
&DesktopEntryMonitor::onDirectoryChanged
32
32
);
33
- connect (
34
- this ->watcher ,
35
- &QFileSystemWatcher::fileChanged,
36
- this ,
37
- &DesktopEntryMonitor::onFileChanged
38
- );
39
33
connect (this ->debounceTimer , &QTimer::timeout, this , &DesktopEntryMonitor::processChanges);
40
34
41
35
// Start monitoring
@@ -68,18 +62,6 @@ void DesktopEntryMonitor::scanAndWatch(const QString& dirPath) {
68
62
qCDebug (logDesktopMonitor) << " Added directory to watcher:" << dirPath;
69
63
}
70
64
71
- // Add .desktop files
72
- for (const auto & entry: dir.entryInfoList ({" *.desktop" }, QDir::Files)) {
73
- auto path = entry.absoluteFilePath ();
74
- if (!this ->watchedFiles .contains (path)) {
75
- if (this ->watcher ->addPath (path)) {
76
- this ->fileTimestamps [path] = entry.lastModified ();
77
- this ->watchedFiles .insert (path);
78
- qCDebug (logDesktopMonitor) << " Monitoring file:" << path;
79
- }
80
- }
81
- }
82
-
83
65
// Recurse into subdirs
84
66
for (const auto & sub: dir.entryList (QDir::Dirs | QDir::NoDotAndDotDot)) {
85
67
this ->scanAndWatch (dir.absoluteFilePath (sub));
@@ -94,52 +76,11 @@ void DesktopEntryMonitor::onDirectoryChanged(const QString& path) {
94
76
if (!dir.exists ()) {
95
77
qCDebug (logDesktopMonitor) << " Directory no longer exists, cleaning up:" << path;
96
78
this ->watcher ->removePath (path);
97
-
98
- // Remove all watched files from this directory and its subdirectories
99
- for (auto it = this ->watchedFiles .begin (); it != this ->watchedFiles .end ();) {
100
- const QString& watchedFile = *it;
101
- if (watchedFile.startsWith (path + " /" ) || watchedFile == path) {
102
- this ->watcher ->removePath (watchedFile);
103
- this ->fileTimestamps .remove (watchedFile);
104
- this ->queueChange (ChangeEvent::Removed, watchedFile);
105
- qCDebug (logDesktopMonitor) << " Removed file due to directory deletion:" << watchedFile;
106
- it = this ->watchedFiles .erase (it);
107
- } else {
108
- ++it;
109
- }
110
- }
79
+ // Directory removal will be handled by full rescan
80
+ this ->queueChange (ChangeEvent::Modified, path); // Trigger full rescan
111
81
return ;
112
82
}
113
83
114
- QList<QString> currentFiles = dir.entryList ({" *.desktop" }, QDir::Files);
115
-
116
- // Check for new files
117
- for (const QString& file: currentFiles) {
118
- QString fullPath = dir.absoluteFilePath (file);
119
- if (!this ->watchedFiles .contains (fullPath)) {
120
- if (this ->watcher ->addPath (fullPath)) {
121
- this ->fileTimestamps [fullPath] = QFileInfo (fullPath).lastModified ();
122
- this ->watchedFiles .insert (fullPath);
123
- this ->queueChange (ChangeEvent::Added, fullPath);
124
- qCDebug (logDesktopMonitor) << " New desktop file detected:" << fullPath;
125
- }
126
- }
127
- }
128
-
129
- // Check for deleted files
130
- for (auto it = this ->watchedFiles .begin (); it != this ->watchedFiles .end ();) {
131
- const QString& watchedFile = *it;
132
- if (QFileInfo (watchedFile).dir ().absolutePath () == path && !QFile::exists (watchedFile)) {
133
- this ->watcher ->removePath (watchedFile);
134
- this ->fileTimestamps .remove (watchedFile);
135
- this ->queueChange (ChangeEvent::Removed, watchedFile);
136
- qCDebug (logDesktopMonitor) << " Desktop file removed:" << watchedFile;
137
- it = this ->watchedFiles .erase (it);
138
- } else {
139
- ++it;
140
- }
141
- }
142
-
143
84
// Check for new subdirectories
144
85
QList<QString> subdirs = dir.entryList (QDir::Dirs | QDir::NoDotAndDotDot);
145
86
for (const QString& subdir: subdirs) {
@@ -148,27 +89,9 @@ void DesktopEntryMonitor::onDirectoryChanged(const QString& path) {
148
89
this ->scanAndWatch (subdirPath);
149
90
}
150
91
}
151
- }
152
-
153
- void DesktopEntryMonitor::onFileChanged (const QString& path) {
154
- if (QFileInfo (path).suffix ().toLower () != " desktop" ) return ;
155
92
156
- QFileInfo info (path);
157
- if (info.exists ()) {
158
- QDateTime currentModified = info.lastModified ();
159
- if (this ->fileTimestamps .value (path) != currentModified) {
160
- this ->fileTimestamps [path] = currentModified;
161
- this ->queueChange (ChangeEvent::Modified, path);
162
- qCDebug (logDesktopMonitor) << " Desktop file modified:" << path;
163
- }
164
- } else {
165
- // File was deleted
166
- this ->watcher ->removePath (path);
167
- this ->fileTimestamps .remove (path);
168
- this ->watchedFiles .remove (path);
169
- this ->queueChange (ChangeEvent::Removed, path);
170
- qCDebug (logDesktopMonitor) << " Desktop file removed:" << path;
171
- }
93
+ // Queue a change to trigger full rescan of all desktop paths
94
+ this ->queueChange (ChangeEvent::Modified, path);
172
95
}
173
96
174
97
void DesktopEntryMonitor::queueChange (ChangeEvent event, const QString& path) {
@@ -179,10 +102,12 @@ void DesktopEntryMonitor::queueChange(ChangeEvent event, const QString& path) {
179
102
void DesktopEntryMonitor::processChanges () {
180
103
if (this ->pendingChanges .isEmpty ()) return ;
181
104
182
- qCDebug (logDesktopMonitor) << " Processing" << this -> pendingChanges . size () << " pending changes " ;
105
+ qCDebug (logDesktopMonitor) << " Processing directory changes, triggering full rescan " ;
183
106
184
- QHash<QString, ChangeEvent> changes = this -> pendingChanges ;
107
+ // Clear pending changes since we're doing a full rescan
185
108
this ->pendingChanges .clear ();
186
109
187
- emit desktopEntriesChanged (changes);
110
+ // Emit with empty hash to signal full rescan needed
111
+ QHash<QString, ChangeEvent> emptyChanges;
112
+ emit desktopEntriesChanged (emptyChanges);
188
113
}
0 commit comments