Commit 6effcdf1 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

[Task Manager] Support places categories

This adds submenus for subsequent categories in places model.
Now that baloo search and others are in there the menu would grow enormous otherwise.

Differential Revision:
parent 11b6ea80
......@@ -33,6 +33,7 @@
#include <QActionGroup>
#include <QApplication>
#include <QJsonArray>
#include <QMenu>
#include <QScopedPointer>
#include <QQuickItem>
#include <QQuickWindow>
......@@ -216,21 +217,24 @@ QVariantList Backend::placesActions(const QUrl &launcherUrl, bool showAllPlaces,
return actions;
QString previousGroup;
QMenu *subMenu = nullptr;
QScopedPointer<KFilePlacesModel> placesModel(new KFilePlacesModel());
for (int i = 0; i < placesModel->rowCount(); ++i) {
QModelIndex idx = placesModel->index(i, 0);
if (placesModel->data(idx, KFilePlacesModel::HiddenRole).toBool()) {
if ( {
const QString &title = placesModel->data(idx, Qt::DisplayRole).toString();
const QIcon &icon = placesModel->data(idx, Qt::DecorationRole).value<QIcon>();
const QUrl &url = placesModel->data(idx, KFilePlacesModel::UrlRole).toUrl();
const QString &title =;
const QIcon &icon =<QIcon>();
const QUrl &url =;
QAction *action = new QAction(icon, title, parent);
QAction *placeAction = new QAction(icon, title, parent);
connect(action, &QAction::triggered, this, [this, action, url, desktopEntryUrl] {
connect(placeAction, &QAction::triggered, this, [this, url, desktopEntryUrl] {
KService::Ptr service = KService::serviceByDesktopPath(desktopEntryUrl.toLocalFile());
if (!service) {
......@@ -239,7 +243,29 @@ QVariantList Backend::placesActions(const QUrl &launcherUrl, bool showAllPlaces,
KRun::runService(*service, {url}, QApplication::activeWindow());
actions << QVariant::fromValue(action);
const QString &groupName =;
if (previousGroup.isEmpty()) { // Skip first group heading.
previousGroup = groupName;
// Put all subsequent categories into a submenu.
if (previousGroup != groupName) {
QAction *subMenuAction = new QAction(groupName, parent);
subMenu = new QMenu();
// Cannot parent a QMenu to a QAction, need to delete it manually.
connect(parent, &QObject::destroyed, subMenu, &QObject::deleteLater);
actions << QVariant::fromValue(subMenuAction);
previousGroup = groupName;
if (subMenu) {
} else {
actions << QVariant::fromValue(placeAction);
// There is nothing more frustrating than having a "More" entry that ends up showing just one or two
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment