Make alphabetic categorization of the "All Applications" section optional

Summary:
Introduces a new prop and turns it off by default.

Also rewrites the initial "all applications" data gathering avoid
a crash uncovered while working on this (it didn't check EntryType)
and reduces assumptions about the model topology.

It also makes it collect root-level apps now, which was forgotten
to be added when support for root-level apps were added.

This supercedes D22762 and D22890. It does less duplicate work and fixes
more bugs while also not breaking the Dashboard UI.

Reviewers: #plasma, davidedmundson, tcanabrava

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D22901
wilder-5.17
Eike Hein 7 years ago
parent f3860b555c
commit 656bb8469e
  1. 93
      rootmodel.cpp
  2. 6
      rootmodel.h

@ -66,6 +66,7 @@ RootModel::RootModel(QObject *parent) : AppsModel(QString(), parent)
, 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 @@ void RootModel::setShowAllApps(bool show)
}
}
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 @@ void RootModel::refresh()
m_recentContactsModel = nullptr;
if (m_showAllApps) {
QList<AbstractEntry *> groups;
if (m_paginate) {
m_favorites = new KAStatsFavoritesModel(this);
emit favoritesModelChanged();
QHash<QString, AppEntry *> appsHash;
QList<AppEntry *> apps;
foreach (const AbstractEntry *groupEntry, m_entryList) {
QHash<QString, AbstractEntry *> appsHash;
std::function<void(AbstractEntry *)> processEntry = [&](AbstractEntry *entry) {
if (entry->type() == AbstractEntry::RunnableType) {
AppEntry *appEntry = static_cast<AppEntry*>(entry);
appsHash.insert(appEntry->service()->menuId(), appEntry);
} else if (entry->type() == AbstractEntry::GroupType) {
GroupEntry *groupEntry = static_cast<GroupEntry*>(entry);
AbstractModel *model = groupEntry->childModel();
if (!model) continue;
if (!model) {
return;
}
for (int i = 0; i < model->count(); ++i) {
GroupEntry *subGroupEntry = static_cast<GroupEntry*>(model->index(i, 0).internalPointer());
AbstractModel *subModel = subGroupEntry->childModel();
for (int j = 0; j < subModel->count(); ++j) {
AppEntry *appEntry = static_cast<AppEntry*>(subModel->index(j, 0).internalPointer());
if (appEntry->name().isEmpty()) {
continue;
}
appsHash.insert(appEntry->service()->menuId(), appEntry);
}
processEntry(static_cast<AbstractEntry*>(model->index(i, 0).internalPointer()));
}
}
};
apps = appsHash.values();
for (AbstractEntry *entry : m_entryList) {
processEntry(entry);
}
QCollator c;
QList<AbstractEntry *> 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<AbstractEntry *> groups;
int at = 0;
QList<AbstractEntry *> 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 @@ void RootModel::refresh()
}
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<AbstractEntry *> groups;
QHash<QString, QList<AbstractEntry *>> m_categoryHash;
foreach (const AbstractEntry *groupEntry, m_entryList) {
@ -364,9 +384,10 @@ void RootModel::refresh()
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.
}

@ -53,6 +53,7 @@ class RootModel : public AppsModel
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 @@ class RootModel : public AppsModel
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 @@ class RootModel : public AppsModel
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 @@ class RootModel : public AppsModel
SystemModel *m_systemModel;
bool m_showAllApps;
bool m_showAllAppsCategorized;
bool m_showRecentApps;
bool m_showRecentDocs;
bool m_showRecentContacts;

Loading…
Cancel
Save