diff --git a/applets/kicker/package/contents/ui/main.qml b/applets/kicker/package/contents/ui/main.qml --- a/applets/kicker/package/contents/ui/main.qml +++ b/applets/kicker/package/contents/ui/main.qml @@ -87,6 +87,7 @@ appletInterface: plasmoid showAllApps: isDash + showAllAppsCategorized: true showTopLevelItems: !isDash showRecentApps: plasmoid.configuration.showRecentApps showRecentDocs: plasmoid.configuration.showRecentDocs diff --git a/applets/kicker/plugin/rootmodel.h b/applets/kicker/plugin/rootmodel.h --- a/applets/kicker/plugin/rootmodel.h +++ b/applets/kicker/plugin/rootmodel.h @@ -53,6 +53,7 @@ Q_PROPERTY(QObject* systemFavoritesModel READ systemFavoritesModel NOTIFY systemFavoritesModelChanged) Q_PROPERTY(bool showAllApps READ showAllApps WRITE setShowAllApps NOTIFY showAllAppsChanged) + Q_PROPERTY(bool showAllAppsCategorized READ showAllAppsCategorized WRITE setShowAllAppsCategorized NOTIFY showAllAppsCategorizedChanged) Q_PROPERTY(bool showRecentApps READ showRecentApps WRITE setShowRecentApps NOTIFY showRecentAppsChanged) Q_PROPERTY(bool showRecentDocs READ showRecentDocs WRITE setShowRecentDocs NOTIFY showRecentDocsChanged) Q_PROPERTY(bool showRecentContacts READ showRecentContacts WRITE setShowRecentContacts NOTIFY showRecentContactsChanged) @@ -70,6 +71,9 @@ bool showAllApps() const; void setShowAllApps(bool show); + bool showAllAppsCategorized() const; + void setShowAllAppsCategorized(bool showCategorized); + bool showRecentApps() const; void setShowRecentApps(bool show); @@ -92,6 +96,7 @@ void refreshed() const; void systemFavoritesModelChanged() const; void showAllAppsChanged() const; + void showAllAppsCategorizedChanged() const; void showRecentAppsChanged() const; void showRecentDocsChanged() const; void showRecentContactsChanged() const; @@ -107,6 +112,7 @@ SystemModel *m_systemModel; bool m_showAllApps; + bool m_showAllAppsCategorized; bool m_showRecentApps; bool m_showRecentDocs; bool m_showRecentContacts; diff --git a/applets/kicker/plugin/rootmodel.cpp b/applets/kicker/plugin/rootmodel.cpp --- a/applets/kicker/plugin/rootmodel.cpp +++ b/applets/kicker/plugin/rootmodel.cpp @@ -66,6 +66,7 @@ , m_favorites(new KAStatsFavoritesModel(this)) , m_systemModel(nullptr) , m_showAllApps(false) +, m_showAllAppsCategorized(false) , m_showRecentApps(true) , m_showRecentDocs(true) , m_showRecentContacts(false) @@ -159,6 +160,22 @@ } } +bool RootModel::showAllAppsCategorized() const +{ + return m_showAllAppsCategorized; +} + +void RootModel::setShowAllAppsCategorized(bool showCategorized) +{ + if (m_showAllAppsCategorized != showCategorized) { + m_showAllAppsCategorized = showCategorized; + + refresh(); + + emit showAllAppsCategorizedChanged(); + } +} + bool RootModel::showRecentApps() const { return m_showRecentApps; @@ -269,55 +286,55 @@ m_recentContactsModel = nullptr; if (m_showAllApps) { - QList groups; - - if (m_paginate) { - m_favorites = new KAStatsFavoritesModel(this); - emit favoritesModelChanged(); - - QHash appsHash; - QList apps; - - foreach (const AbstractEntry *groupEntry, m_entryList) { + QHash appsHash; + + std::function processEntry = [&](AbstractEntry *entry) { + if (entry->type() == AbstractEntry::RunnableType) { + AppEntry *appEntry = static_cast(entry); + appsHash.insert(appEntry->service()->menuId(), appEntry); + } else if (entry->type() == AbstractEntry::GroupType) { + GroupEntry *groupEntry = static_cast(entry); AbstractModel *model = groupEntry->childModel(); - if (!model) continue; + if (!model) { + return; + } for (int i = 0; i < model->count(); ++i) { - GroupEntry *subGroupEntry = static_cast(model->index(i, 0).internalPointer()); - AbstractModel *subModel = subGroupEntry->childModel(); - - for (int j = 0; j < subModel->count(); ++j) { - AppEntry *appEntry = static_cast(subModel->index(j, 0).internalPointer()); - - if (appEntry->name().isEmpty()) { - continue; - } - - appsHash.insert(appEntry->service()->menuId(), appEntry); - } + processEntry(static_cast(model->index(i, 0).internalPointer())); } } + }; - apps = appsHash.values(); + for (AbstractEntry *entry : m_entryList) { + processEntry(entry); + } - QCollator c; + QList apps(appsHash.values()); + QCollator c; - std::sort(apps.begin(), apps.end(), - [&c](AbstractEntry* a, AbstractEntry* b) { - if (a->type() != b->type()) { - return a->type() > b->type(); - } else { - return c.compare(a->name(), b->name()) < 0; - } - }); + std::sort(apps.begin(), apps.end(), + [&c](AbstractEntry* a, AbstractEntry* b) { + if (a->type() != b->type()) { + return a->type() > b->type(); + } else { + return c.compare(a->name(), b->name()) < 0; + } + }); + if (!m_showAllAppsCategorized && !m_paginate) { // The app list built above goes into a model. + allModel = new AppsModel(apps, false, this); + } else if (m_paginate) { // We turn the apps list into a subtree of pages. + m_favorites = new KAStatsFavoritesModel(this); + emit favoritesModelChanged(); + + QList groups; int at = 0; QList page; page.reserve(m_pageSize); - foreach(AppEntry *app, apps) { + foreach(AbstractEntry *app, apps) { page.append(app); if (at == (m_pageSize - 1)) { @@ -336,7 +353,10 @@ } groups.prepend(new GroupEntry(this, QString(), QString(), m_favorites)); - } else { + + allModel = new AppsModel(groups, true, this); + } else { // We turn the apps list into a subtree of apps by starting letter. + QList groups; QHash> m_categoryHash; foreach (const AbstractEntry *groupEntry, m_entryList) { @@ -364,9 +384,10 @@ model->setDescription(i.key()); groups.append(new GroupEntry(this, i.key(), QString(), model)); } + + allModel = new AppsModel(groups, true, this); } - allModel = new AppsModel(groups, true, this); allModel->setDescription(QStringLiteral("KICKER_ALL_MODEL")); // Intentionally no i18n. }