1
1
#include " desktopentry.hpp"
2
2
#include < algorithm>
3
+ #include < utility>
3
4
4
5
#include < qcontainerfwd.h>
5
6
#include < qdebug.h>
@@ -192,6 +193,9 @@ ParsedDesktopEntryData DesktopEntry::parseText(const QString& id, const QString&
192
193
}
193
194
194
195
void DesktopEntry::updateState (const ParsedDesktopEntryData& newState) {
196
+ #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
197
+ QScopedPropertyUpdateGroup group;
198
+ #endif
195
199
this ->bName = newState.name ;
196
200
this ->bGenericName = newState.genericName ;
197
201
this ->bStartupClass = newState.startupClass ;
@@ -210,19 +214,33 @@ void DesktopEntry::updateState(const ParsedDesktopEntryData& newState) {
210
214
}
211
215
212
216
void DesktopEntry::updateActions (const QHash<QString, DesktopActionData>& newActions) {
213
- for (auto * action: this ->mActions .values ()) {
214
- action->deleteLater ();
217
+ auto old = this ->mActions ;
218
+
219
+ for (auto it = newActions.cbegin (); it != newActions.cend (); ++it) {
220
+ const auto & key = it.key ();
221
+ const auto & d = it.value ();
222
+
223
+ DesktopAction* act = nullptr ;
224
+ if (auto found = old.find (key); found != old.end ()) {
225
+ act = found.value ();
226
+ old.erase (found);
227
+ } else {
228
+ act = new DesktopAction (d.id , this );
229
+ this ->mActions .insert (key, act);
230
+ }
231
+
232
+ #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
233
+ QScopedPropertyUpdateGroup group;
234
+ #endif
235
+ act->bName = d.name ;
236
+ act->bIcon = d.icon ;
237
+ act->bExecString = d.execString ;
238
+ act->bCommand = d.command ;
239
+ act->mEntries = d.entries ;
215
240
}
216
- this ->mActions .clear ();
217
-
218
- for (const auto & [actionName, actionData]: newActions.asKeyValueRange ()) {
219
- auto * action = new DesktopAction (actionData.id , this );
220
- action->mEntries = actionData.entries ;
221
- action->mName = actionData.name ;
222
- action->mIcon = actionData.icon ;
223
- action->mExecString = actionData.execString ;
224
- action->mCommand = actionData.command ;
225
- this ->mActions .insert (actionName, action);
241
+
242
+ for (auto * leftover: std::as_const (old)) {
243
+ leftover->deleteLater ();
226
244
}
227
245
}
228
246
@@ -306,7 +324,7 @@ void DesktopEntry::doExec(const QList<QString>& execString, const QString& worki
306
324
}
307
325
308
326
void DesktopAction::execute () const {
309
- DesktopEntry::doExec (this ->mCommand , this ->entry ->bWorkingDirectory .value ());
327
+ DesktopEntry::doExec (this ->bCommand . value () , this ->entry ->bWorkingDirectory .value ());
310
328
}
311
329
312
330
DesktopEntryScanner::DesktopEntryScanner (DesktopEntryManager* manager): manager(manager) {
@@ -315,7 +333,7 @@ DesktopEntryScanner::DesktopEntryScanner(DesktopEntryManager* manager): manager(
315
333
316
334
void DesktopEntryScanner::run () {
317
335
auto desktopPaths = DesktopEntryManager::desktopPaths ();
318
- auto scanResults = DesktopEntryScanResults ();
336
+ auto scanResults = QList<ParsedDesktopEntryData> ();
319
337
320
338
for (int i = desktopPaths.size () - 1 ; i >= 0 ; --i) {
321
339
const auto & path = desktopPaths.at (i);
@@ -327,13 +345,12 @@ void DesktopEntryScanner::run() {
327
345
328
346
QMetaObject::invokeMethod (
329
347
this ->manager ,
330
- &DesktopEntryManager::onScanCompleted,
331
- Qt::QueuedConnection,
332
- scanResults
348
+ [mgr = this ->manager , results = std::move (scanResults)]() { mgr->onScanCompleted (results); },
349
+ Qt::QueuedConnection
333
350
);
334
351
}
335
352
336
- void DesktopEntryScanner::scanDirectory (const QDir& dir, DesktopEntryScanResults & entries) {
353
+ void DesktopEntryScanner::scanDirectory (const QDir& dir, QList<ParsedDesktopEntryData> & entries) {
337
354
auto dirEntries = dir.entryInfoList (QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
338
355
339
356
for (auto & entry: dirEntries) {
@@ -362,9 +379,6 @@ void DesktopEntryScanner::scanDirectory(const QDir& dir, DesktopEntryScanResults
362
379
}
363
380
364
381
DesktopEntryManager::DesktopEntryManager () {
365
- qRegisterMetaType<ParsedDesktopEntryData>(" ParsedDesktopEntryData" );
366
- qRegisterMetaType<DesktopEntryScanResults>(" DesktopEntryScanResults" );
367
-
368
382
this ->monitor = new DesktopEntryMonitor (this );
369
383
connect (
370
384
this ->monitor ,
@@ -466,33 +480,23 @@ const QStringList& DesktopEntryManager::desktopPaths() {
466
480
auto dataPaths = QStringList ();
467
481
468
482
auto dataHome = qEnvironmentVariable (" XDG_DATA_HOME" );
469
- if (dataHome.isEmpty ()) {
470
- if (qEnvironmentVariableIsSet (" HOME" )) {
471
- dataHome = qEnvironmentVariable (" HOME" ) + " /.local/share" ;
472
- }
473
- }
474
- if (!dataHome.isEmpty ()) {
475
- dataPaths.append (dataHome + " /applications" );
476
- }
483
+ if (dataHome.isEmpty () && qEnvironmentVariableIsSet (" HOME" ))
484
+ dataHome = qEnvironmentVariable (" HOME" ) + " /.local/share" ;
485
+ if (!dataHome.isEmpty ()) dataPaths.append (dataHome + " /applications" );
477
486
478
487
auto dataDirs = qEnvironmentVariable (" XDG_DATA_DIRS" );
479
- if (dataDirs.isEmpty ()) {
480
- dataDirs = " /usr/local/share:/usr/share" ;
481
- }
488
+ if (dataDirs.isEmpty ()) dataDirs = " /usr/local/share:/usr/share" ;
482
489
483
- for (const auto & dir: dataDirs.split (' :' , Qt::SkipEmptyParts)) {
484
- if (!dir.isEmpty ()) {
485
- dataPaths.append (dir + " /applications" );
486
- }
487
- }
490
+ for (const auto & dir: dataDirs.split (' :' , Qt::SkipEmptyParts))
491
+ dataPaths.append (dir + " /applications" );
488
492
489
493
return dataPaths;
490
494
}();
491
495
492
496
return paths;
493
497
}
494
498
495
- void DesktopEntryManager::onScanCompleted (const DesktopEntryScanResults & scanResults) {
499
+ void DesktopEntryManager::onScanCompleted (const QList<ParsedDesktopEntryData> & scanResults) {
496
500
auto guard = qScopeGuard ([this ] { this ->scanInProgress = false ; });
497
501
498
502
auto oldEntries = this ->desktopEntries ;
@@ -522,14 +526,11 @@ void DesktopEntryManager::onScanCompleted(const DesktopEntryScanResults& scanRes
522
526
qCDebug (logDesktopEntry) << " Found desktop entry" << data.id ;
523
527
524
528
auto lowerId = data.id .toLower ();
525
-
526
529
auto conflictingId = newEntries.contains (data.id );
527
530
528
531
if (conflictingId) {
529
532
qCDebug (logDesktopEntry) << " Replacing old entry for" << data.id ;
530
- if (auto * victim = newEntries.take (data.id )) {
531
- victim->deleteLater ();
532
- }
533
+ if (auto * victim = newEntries.take (data.id )) victim->deleteLater ();
533
534
newLowercaseEntries.remove (lowerId);
534
535
}
535
536
@@ -551,17 +552,12 @@ void DesktopEntryManager::onScanCompleted(const DesktopEntryScanResults& scanRes
551
552
this ->lowercaseDesktopEntries = newLowercaseEntries;
552
553
553
554
auto newApplications = QVector<DesktopEntry*>();
554
- for (auto & entry: this ->desktopEntries .values ()) {
555
- if (!entry->noDisplay ()) {
556
- newApplications.append (entry);
557
- }
558
- }
555
+ for (auto * entry: this ->desktopEntries .values ())
556
+ if (!entry->noDisplay ()) newApplications.append (entry);
559
557
560
558
this ->mApplications .diffUpdate (newApplications);
561
559
562
- for (auto * e: oldEntries) {
563
- e->deleteLater ();
564
- }
560
+ for (auto * e: oldEntries) e->deleteLater ();
565
561
566
562
emit applicationsChanged ();
567
563
}
0 commit comments