mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-08-02 09:48:50 +00:00
Simplify apps model
The current code iterates over each service group separately and adds its apps. This leads to duplicate entries when an app is in multiple groups. Since we are not actually interested in the group info, only in a flat list of all apps with some filters, we can simplify this.
This commit is contained in:
parent
0fc51bfb1e
commit
992950085d
1 changed files with 34 additions and 51 deletions
|
|
@ -16,13 +16,12 @@
|
||||||
#include <QQuickWindow>
|
#include <QQuickWindow>
|
||||||
|
|
||||||
// KDE
|
// KDE
|
||||||
|
#include <KApplicationTrader>
|
||||||
#include <KIO/ApplicationLauncherJob>
|
#include <KIO/ApplicationLauncherJob>
|
||||||
#include <KNotificationJobUiDelegate>
|
#include <KNotificationJobUiDelegate>
|
||||||
#include <KService>
|
#include <KService>
|
||||||
#include <KServiceGroup>
|
|
||||||
#include <KSharedConfig>
|
#include <KSharedConfig>
|
||||||
#include <KSycoca>
|
#include <KSycoca>
|
||||||
#include <KSycocaEntry>
|
|
||||||
|
|
||||||
#include <KWayland/Client/connection_thread.h>
|
#include <KWayland/Client/connection_thread.h>
|
||||||
#include <KWayland/Client/plasmawindowmanagement.h>
|
#include <KWayland/Client/plasmawindowmanagement.h>
|
||||||
|
|
@ -158,46 +157,35 @@ void ApplicationListModel::loadApplications()
|
||||||
auto cfg = KSharedConfig::openConfig(QStringLiteral("applications-blacklistrc"));
|
auto cfg = KSharedConfig::openConfig(QStringLiteral("applications-blacklistrc"));
|
||||||
auto blgroup = KConfigGroup(cfg, QStringLiteral("Applications"));
|
auto blgroup = KConfigGroup(cfg, QStringLiteral("Applications"));
|
||||||
|
|
||||||
QStringList blacklist = blgroup.readEntry("blacklist", QStringList());
|
const QStringList blacklist = blgroup.readEntry("blacklist", QStringList());
|
||||||
|
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
|
|
||||||
m_applicationList.clear();
|
m_applicationList.clear();
|
||||||
|
|
||||||
KServiceGroup::Ptr group = KServiceGroup::root();
|
|
||||||
if (!group || !group->isValid()) return;
|
|
||||||
KServiceGroup::List subGroupList = group->entries(true);
|
|
||||||
|
|
||||||
QMap<int, ApplicationData> orderedList;
|
QMap<int, ApplicationData> orderedList;
|
||||||
QList<ApplicationData> unorderedList;
|
QList<ApplicationData> unorderedList;
|
||||||
QSet<QString> foundFavorites;
|
QSet<QString> foundFavorites;
|
||||||
|
|
||||||
// Iterate over all entries in the group
|
auto filter = [blacklist](const KService::Ptr &service) -> bool {
|
||||||
while (!subGroupList.isEmpty()) {
|
if (service->noDisplay()) {
|
||||||
KSycocaEntry::Ptr groupEntry = subGroupList.first();
|
return false;
|
||||||
subGroupList.pop_front();
|
}
|
||||||
|
|
||||||
if (groupEntry->isType(KST_KServiceGroup)) {
|
if (!service->showOnCurrentPlatform()) {
|
||||||
KServiceGroup::Ptr serviceGroup(static_cast<KServiceGroup *>(groupEntry.data()));
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!serviceGroup->noDisplay()) {
|
if (blacklist.contains(service->desktopEntryName())) {
|
||||||
KServiceGroup::List entryGroupList = serviceGroup->entries(true);
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
for(KServiceGroup::List::ConstIterator it = entryGroupList.constBegin(); it != entryGroupList.constEnd(); it++) {
|
return true;
|
||||||
KSycocaEntry::Ptr entry = (*it);
|
};
|
||||||
|
|
||||||
if (entry->isType(KST_KServiceGroup)) {
|
const KService::List apps = KApplicationTrader::query(filter);
|
||||||
KServiceGroup::Ptr serviceGroup(static_cast<KServiceGroup *>(entry.data()));
|
|
||||||
subGroupList << serviceGroup;
|
|
||||||
|
|
||||||
} else if (entry->property(QStringLiteral("Exec")).isValid()) {
|
|
||||||
KService::Ptr service(static_cast<KService *>(entry.data()));
|
|
||||||
|
|
||||||
if (service->isApplication() &&
|
|
||||||
!blacklist.contains(service->desktopEntryName()) &&
|
|
||||||
service->showOnCurrentPlatform() &&
|
|
||||||
!service->property(QStringLiteral("Terminal"), QVariant::Bool).toBool()) {
|
|
||||||
|
|
||||||
|
for (const KService::Ptr &service : apps) {
|
||||||
ApplicationData data;
|
ApplicationData data;
|
||||||
data.name = service->name();
|
data.name = service->name();
|
||||||
data.icon = service->icon();
|
data.icon = service->icon();
|
||||||
|
|
@ -220,11 +208,6 @@ void ApplicationListModel::loadApplications()
|
||||||
unorderedList << data;
|
unorderedList << data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
blgroup.writeEntry("blacklist", blacklist);
|
blgroup.writeEntry("blacklist", blacklist);
|
||||||
cfg->sync();
|
cfg->sync();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue