Skip to content

Commit 986ac11

Browse files
committed
chore: implement dock item menus for DockGlobalElementModel
This patch is to continue prepare for #1201, by add previously missing changed signal for Docked and Menu role when docked state is changed, and implementing actions for menu entries. This patch also make DnD on dock item works without using the legacy ItemModel class by implementing requestOpenUrls(). Log:
1 parent 332f038 commit 986ac11

7 files changed

Lines changed: 53 additions & 18 deletions

File tree

panels/dock/taskmanager/desktopfileabstractparser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ void DesktopfileAbstractParser::setDocked(bool docked)
148148
auto desktopElement = QStringLiteral("desktop/%1").arg(id());
149149

150150
if (docked) {
151-
TaskManagerSettings::instance()->appendDockedElements(desktopElement);
151+
TaskManagerSettings::instance()->appendDockedElement(desktopElement);
152152
} else {
153-
TaskManagerSettings::instance()->removeDockedElements(desktopElement);
153+
TaskManagerSettings::instance()->removeDockedElement(desktopElement);
154154
}
155155

156156
Q_EMIT dockedChanged();

panels/dock/taskmanager/dockglobalelementmodel.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

55
#include "dockglobalelementmodel.h"
6+
#include "applicationinterface.h"
67
#include "globals.h"
78
#include "taskmanager.h"
89
#include "taskmanagersettings.h"
910

1011
#include <QAbstractListModel>
12+
#include <QDBusConnection>
1113
#include <QJsonDocument>
1214
#include <QJsonObject>
1315
#include <QProcess>
@@ -234,6 +236,11 @@ void DockGlobalElementModel::loadDockedElements()
234236
}
235237

236238
m_dockedElements = newDocked;
239+
240+
if (!m_data.isEmpty()) {
241+
// MenusRole should also be handled here due to it contains the copywriting of docked or undocked
242+
Q_EMIT dataChanged(index(0, 0), index(m_data.size() - 1, 0), {TaskManager::DockedRole, TaskManager::MenusRole});
243+
}
237244
}
238245

239246
QString DockGlobalElementModel::getMenus(const QModelIndex &index) const
@@ -318,15 +325,33 @@ void DockGlobalElementModel::requestActivate(const QModelIndex &index) const
318325

319326
void DockGlobalElementModel::requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls) const
320327
{
321-
Q_UNUSED(index)
322-
Q_UNUSED(urls)
328+
auto data = m_data.value(index.row());
329+
auto id = std::get<0>(data);
330+
331+
QStringList urlStrings;
332+
for (const QUrl &url : urls) {
333+
urlStrings.append(url.toLocalFile());
334+
}
335+
336+
QString dbusPath = QStringLiteral("/org/desktopspec/ApplicationManager1/") + escapeToObjectPath(id);
337+
using Application = org::desktopspec::ApplicationManager1::Application;
338+
Application appInterface(QStringLiteral("org.desktopspec.ApplicationManager1"), dbusPath, QDBusConnection::sessionBus());
339+
340+
if (appInterface.isValid()) {
341+
appInterface.Launch(QString(), urlStrings, QVariantMap());
342+
}
323343
}
324344

325345
void DockGlobalElementModel::requestNewInstance(const QModelIndex &index, const QString &action) const
326346
{
327347
if (action == DOCK_ACTION_DOCK) {
348+
auto data = m_data.value(index.row());
349+
auto id = std::get<0>(data);
350+
TaskManagerSettings::instance()->toggleDockedElement(QStringLiteral("desktop/%1").arg(id));
328351
} else if (action == DOCK_ACTION_FORCEQUIT) {
352+
requestClose(index, true);
329353
} else if (action == DOCK_ACTION_CLOSEALL) {
354+
requestClose(index);
330355
} else {
331356
auto data = m_data.value(index.row());
332357
auto id = std::get<0>(data);

panels/dock/taskmanager/dockgroupmodel.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,6 @@ void DockGroupModel::requestActivate(const QModelIndex &index) const
117117
interface->requestActivate(sourceIndex);
118118
}
119119

120-
void DockGroupModel::requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls) const
121-
{
122-
Q_UNUSED(index)
123-
Q_UNUSED(urls)
124-
}
125-
126120
void DockGroupModel::requestClose(const QModelIndex &index, bool force) const
127121
{
128122
auto interface = dynamic_cast<AbstractTaskManagerInterface *>(sourceModel());

panels/dock/taskmanager/dockgroupmodel.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class DockGroupModel : public RoleGroupModel, public AbstractTaskManagerInterfac
2020
Q_INVOKABLE virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
2121

2222
void requestActivate(const QModelIndex &index) const override;
23-
void requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls) const override;
2423
void requestClose(const QModelIndex &index, bool force = false) const override;
2524
void requestUpdateWindowGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate = nullptr) const override;
2625
void requestPreview(const QModelIndexList &indexes,

panels/dock/taskmanager/taskmanager.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,17 @@ void TaskManager::clickItem(const QString& itemId, const QString& menuId)
271271

272272
void TaskManager::dropFilesOnItem(const QString& itemId, const QStringList& urls)
273273
{
274-
auto item = ItemModel::instance()->getItemById(itemId);
275-
if(!item) return;
274+
auto indexes = m_itemModel->match(m_itemModel->index(0, 0), TaskManager::ItemIdRole, itemId, 1, Qt::MatchExactly);
275+
if (indexes.isEmpty()) {
276+
return;
277+
}
278+
279+
QList<QUrl> urlList;
280+
for (const QString &url : urls) {
281+
urlList.append(QUrl::fromLocalFile(url));
282+
}
276283

277-
item->handleFileDrop(urls);
284+
m_itemModel->requestOpenUrls(indexes.first(), urlList);
278285
}
279286

280287
void TaskManager::showItemPreview(const QString &itemId, QObject *relativePositionItem, int32_t previewXoffset, int32_t previewYoffset, uint32_t direction)

panels/dock/taskmanager/taskmanagersettings.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,23 @@ void TaskManagerSettings::setDockedElements(const QStringList &elements)
148148
saveDockedElements();
149149
}
150150

151-
void TaskManagerSettings::appendDockedElements(const QString &element)
151+
void TaskManagerSettings::toggleDockedElement(const QString &element)
152+
{
153+
if (isDocked(element)) {
154+
removeDockedElement(element);
155+
} else {
156+
appendDockedElement(element);
157+
}
158+
}
159+
160+
void TaskManagerSettings::appendDockedElement(const QString &element)
152161
{
153162
m_dockedElements.append(element);
154163
Q_EMIT dockedElementsChanged();
155164
saveDockedElements();
156165
}
157166

158-
void TaskManagerSettings::removeDockedElements(const QString &element)
167+
void TaskManagerSettings::removeDockedElement(const QString &element)
159168
{
160169
m_dockedElements.removeAll(element);
161170
Q_EMIT dockedElementsChanged();

panels/dock/taskmanager/taskmanagersettings.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ class TaskManagerSettings : public QObject
3232
bool cgroupsBasedGrouping() const;
3333

3434
void setDockedElements(const QStringList &elements);
35-
void appendDockedElements(const QString &element);
36-
void removeDockedElements(const QString &element);
35+
void toggleDockedElement(const QString &element);
36+
void appendDockedElement(const QString &element);
37+
void removeDockedElement(const QString &element);
3738
QStringList dockedElements() const;
3839
bool isDocked(const QString &elementId) const;
3940

0 commit comments

Comments
 (0)