Skip to content

Commit d20a2e5

Browse files
committed
core/desktopentry: fix OnlyShowIn and NotShowIn, they are similar to NoDisplay, not Hidden, expose as bindable
1 parent 305202f commit d20a2e5

4 files changed

Lines changed: 36 additions & 41 deletions

File tree

.claude/scheduled_tasks.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"sessionId":"a2f2f313-f472-4e0f-8a6d-6a1bc4fe14a7","pid":62266,"acquiredAt":1773841457406}

CLAUDE.md

Whitespace-only changes.

src/core/desktopentry.cpp

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ void DesktopEntry::updateState(const ParsedDesktopEntryData& newState) {
226226
this->bGenericName = newState.genericName;
227227
this->bStartupClass = newState.startupClass;
228228
this->bNoDisplay = newState.noDisplay;
229+
this->bOnlyShowIn = newState.onlyShowIn;
230+
this->bNotShowIn = newState.notShowIn;
229231
this->bComment = newState.comment;
230232
this->bIcon = newState.icon;
231233
this->bExecString = newState.execString;
@@ -611,51 +613,20 @@ void DesktopEntryManager::onScanCompleted(const QList<ParsedDesktopEntryData>& s
611613
auto newLowercaseEntries = QHash<QString, DesktopEntry*>();
612614
auto desktopNames = qEnvironmentVariable("XDG_CURRENT_DESKTOP").split(':', Qt::SkipEmptyParts);
613615

614-
auto maskEntry = [&](const QString& id, const QString& lowerId, const char* reason) {
615-
if (auto* victim = newEntries.take(id)) victim->deleteLater();
616-
newLowercaseEntries.remove(lowerId);
617-
618-
if (auto it = oldEntries.find(id); it != oldEntries.end()) {
619-
it.value()->deleteLater();
620-
oldEntries.erase(it);
621-
}
622-
623-
qCDebug(logDesktopEntry) << reason << id;
624-
};
625-
626616
for (const auto& data: scanResults) {
627617
auto lowerId = data.id.toLower();
628618

629619
if (data.hidden) {
630-
maskEntry(data.id, lowerId, "Masking hidden desktop entry");
631-
continue;
632-
}
633-
634-
if (data.onlyShowIn.has_value() && data.notShowIn.has_value()) {
635-
qCWarning(logDesktopEntry) << "Desktop entry" << data.id
636-
<< "defines both OnlyShowIn and NotShowIn, skipping";
637-
maskEntry(data.id, lowerId, "Masking invalid desktop entry");
638-
continue;
639-
}
620+
if (auto* victim = newEntries.take(data.id)) victim->deleteLater();
621+
newLowercaseEntries.remove(lowerId);
640622

641-
if (data.onlyShowIn.has_value()) {
642-
auto found = std::ranges::any_of(desktopNames, [&](const QString& name) {
643-
return data.onlyShowIn->contains(name);
644-
});
645-
if (!found) {
646-
maskEntry(data.id, lowerId, "Masking desktop entry (OnlyShowIn)");
647-
continue;
623+
if (auto it = oldEntries.find(data.id); it != oldEntries.end()) {
624+
it.value()->deleteLater();
625+
oldEntries.erase(it);
648626
}
649-
}
650627

651-
if (data.notShowIn.has_value()) {
652-
auto dominated = std::ranges::any_of(desktopNames, [&](const QString& name) {
653-
return data.notShowIn->contains(name);
654-
});
655-
if (dominated) {
656-
maskEntry(data.id, lowerId, "Masking desktop entry (NotShowIn)");
657-
continue;
658-
}
628+
qCDebug(logDesktopEntry) << "Masking hidden desktop entry" << data.id;
629+
continue;
659630
}
660631

661632
DesktopEntry* dentry = nullptr;
@@ -705,8 +676,27 @@ void DesktopEntryManager::onScanCompleted(const QList<ParsedDesktopEntryData>& s
705676
this->lowercaseDesktopEntries = newLowercaseEntries;
706677

707678
auto newApplications = QVector<DesktopEntry*>();
708-
for (auto* entry: this->desktopEntries.values())
709-
if (!entry->bNoDisplay) newApplications.append(entry);
679+
for (auto* entry: this->desktopEntries.values()) {
680+
if (entry->bNoDisplay) continue;
681+
682+
auto& onlyShowIn = entry->bOnlyShowIn.value();
683+
auto& notShowIn = entry->bNotShowIn.value();
684+
if (onlyShowIn.has_value() && notShowIn.has_value()) {
685+
qCWarning(logDesktopEntry) << "Desktop entry" << entry->mId
686+
<< "defines both OnlyShowIn and NotShowIn (skipping display)";
687+
continue;
688+
}
689+
if (onlyShowIn.has_value() && !std::ranges::any_of(desktopNames, [&](const QString& name) {
690+
return onlyShowIn->contains(name);
691+
}))
692+
continue;
693+
if (notShowIn.has_value() && std::ranges::any_of(desktopNames, [&](const QString& name) {
694+
return notShowIn->contains(name);
695+
}))
696+
continue;
697+
698+
newApplications.append(entry);
699+
}
710700

711701
this->mApplications.diffUpdate(newApplications);
712702

src/core/desktopentry.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ struct ParsedDesktopEntryData {
3434
QString genericName;
3535
QString startupClass;
3636
bool noDisplay = false;
37-
bool hidden = false;
3837
std::optional<QVector<QString>> onlyShowIn;
3938
std::optional<QVector<QString>> notShowIn;
39+
bool hidden = false;
4040
QString comment;
4141
QString icon;
4242
QString execString;
@@ -173,6 +173,8 @@ class DesktopEntry: public QObject {
173173
void runInTerminalChanged();
174174
void categoriesChanged();
175175
void keywordsChanged();
176+
void onlyShowInChanged();
177+
void notShowInChanged();
176178

177179
public:
178180
QString mId;
@@ -182,6 +184,8 @@ class DesktopEntry: public QObject {
182184
Q_OBJECT_BINDABLE_PROPERTY(DesktopEntry, QString, bGenericName, &DesktopEntry::genericNameChanged);
183185
Q_OBJECT_BINDABLE_PROPERTY(DesktopEntry, QString, bStartupClass, &DesktopEntry::startupClassChanged);
184186
Q_OBJECT_BINDABLE_PROPERTY(DesktopEntry, bool, bNoDisplay, &DesktopEntry::noDisplayChanged);
187+
Q_OBJECT_BINDABLE_PROPERTY(DesktopEntry, std::optional<QVector<QString>>, bOnlyShowIn, &DesktopEntry::onlyShowInChanged);
188+
Q_OBJECT_BINDABLE_PROPERTY(DesktopEntry, std::optional<QVector<QString>>, bNotShowIn, &DesktopEntry::notShowInChanged);
185189
Q_OBJECT_BINDABLE_PROPERTY(DesktopEntry, QString, bComment, &DesktopEntry::commentChanged);
186190
Q_OBJECT_BINDABLE_PROPERTY(DesktopEntry, QString, bIcon, &DesktopEntry::iconChanged);
187191
Q_OBJECT_BINDABLE_PROPERTY(DesktopEntry, QString, bExecString, &DesktopEntry::execStringChanged);

0 commit comments

Comments
 (0)