From 7d9054f74ee2d2fba63c442f444fc8a276ca0f1d Mon Sep 17 00:00:00 2001 From: Devin Lin Date: Thu, 13 Feb 2025 11:39:28 -0500 Subject: [PATCH] applicationlistmodel: Space out application list refreshes Use the same behavior as kickoff on desktop, to limit application list refreshes to once every 100ms. https://invent.kde.org/plasma/plasma-mobile/-/issues/440 --- .../folio/applicationlistmodel.cpp | 23 +++++++++++++------ .../homescreens/folio/applicationlistmodel.h | 2 ++ .../halcyon/plugin/applicationlistmodel.cpp | 23 +++++++++++++------ .../halcyon/plugin/applicationlistmodel.h | 2 ++ 4 files changed, 36 insertions(+), 14 deletions(-) diff --git a/containments/homescreens/folio/applicationlistmodel.cpp b/containments/homescreens/folio/applicationlistmodel.cpp index 4a517876..c3953239 100644 --- a/containments/homescreens/folio/applicationlistmodel.cpp +++ b/containments/homescreens/folio/applicationlistmodel.cpp @@ -18,10 +18,19 @@ #include #include +#include + +using namespace std::chrono_literals; + ApplicationListModel::ApplicationListModel(HomeScreen *parent) : QAbstractListModel(parent) + , m_reloadAppsTimer{new QTimer{this}} { - connect(KSycoca::self(), &KSycoca::databaseChanged, this, &ApplicationListModel::sycocaDbChanged); + m_reloadAppsTimer->setSingleShot(true); + m_reloadAppsTimer->setInterval(100ms); + connect(m_reloadAppsTimer, &QTimer::timeout, this, &ApplicationListModel::sycocaDbChanged); + + connect(KSycoca::self(), &KSycoca::databaseChanged, m_reloadAppsTimer, static_cast(&QTimer::start)); // initialize wayland window checking KWayland::Client::ConnectionThread *connection = KWayland::Client::ConnectionThread::fromApplication(this); @@ -51,12 +60,6 @@ void ApplicationListModel::load() const QStringList blacklist = blgroup.readEntry("blacklist", QStringList()); - beginResetModel(); - - m_delegates.clear(); - - QList unorderedList; - auto filter = [blacklist](const KService::Ptr &service) -> bool { if (service->noDisplay()) { return false; @@ -73,6 +76,12 @@ void ApplicationListModel::load() return true; }; + beginResetModel(); + + m_delegates.clear(); + + QList unorderedList; + const KService::List apps = KApplicationTrader::query(filter); for (const KService::Ptr &service : apps) { diff --git a/containments/homescreens/folio/applicationlistmodel.h b/containments/homescreens/folio/applicationlistmodel.h index 15a2ae9b..5e3a0ed0 100644 --- a/containments/homescreens/folio/applicationlistmodel.h +++ b/containments/homescreens/folio/applicationlistmodel.h @@ -44,6 +44,8 @@ public Q_SLOTS: protected: HomeScreen *m_homeScreen{nullptr}; QList m_delegates; + + QTimer *m_reloadAppsTimer{nullptr}; }; class ApplicationListSearchModel : public QSortFilterProxyModel diff --git a/containments/homescreens/halcyon/plugin/applicationlistmodel.cpp b/containments/homescreens/halcyon/plugin/applicationlistmodel.cpp index 1ede6712..ca6bf299 100644 --- a/containments/homescreens/halcyon/plugin/applicationlistmodel.cpp +++ b/containments/homescreens/halcyon/plugin/applicationlistmodel.cpp @@ -18,10 +18,19 @@ #include #include +#include + +using namespace std::chrono_literals; + ApplicationListModel::ApplicationListModel(QObject *parent) : QAbstractListModel(parent) + , m_reloadAppsTimer{new QTimer{this}} { - connect(KSycoca::self(), &KSycoca::databaseChanged, this, &ApplicationListModel::sycocaDbChanged); + m_reloadAppsTimer->setSingleShot(true); + m_reloadAppsTimer->setInterval(100ms); + connect(m_reloadAppsTimer, &QTimer::timeout, this, &ApplicationListModel::sycocaDbChanged); + + connect(KSycoca::self(), &KSycoca::databaseChanged, m_reloadAppsTimer, static_cast(&QTimer::start)); } ApplicationListModel::~ApplicationListModel() = default; @@ -49,12 +58,6 @@ void ApplicationListModel::loadApplications() const QStringList blacklist = blgroup.readEntry("blacklist", QStringList()); - beginResetModel(); - - m_applicationList.clear(); - - QList unorderedList; - auto filter = [blacklist](const KService::Ptr &service) -> bool { if (service->noDisplay()) { return false; @@ -71,6 +74,12 @@ void ApplicationListModel::loadApplications() return true; }; + beginResetModel(); + + m_applicationList.clear(); + + QList unorderedList; + const KService::List apps = KApplicationTrader::query(filter); for (const KService::Ptr &service : apps) { diff --git a/containments/homescreens/halcyon/plugin/applicationlistmodel.h b/containments/homescreens/halcyon/plugin/applicationlistmodel.h index 167ed6f6..0bebcfed 100644 --- a/containments/homescreens/halcyon/plugin/applicationlistmodel.h +++ b/containments/homescreens/halcyon/plugin/applicationlistmodel.h @@ -11,6 +11,7 @@ #include #include #include +#include /** * @short The base application list, used directly by the full app list page. @@ -37,4 +38,5 @@ public Q_SLOTS: protected: QList m_applicationList; + QTimer *m_reloadAppsTimer{nullptr}; };