From b7f0f2fae7b66c683943f64c19bbccfc8ac7bceb Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Tue, 21 Jun 2016 10:57:52 +0100 Subject: [PATCH] Add TaskManager requestActivities Summary: Acts like requestVirtualDesktops only with a QStringList make runningActivities invokable Test Plan: See subsequent plasma-desktop review Reviewers: hein, #plasma Reviewed By: hein, #plasma Subscribers: hein, mart, plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D1814 --- libtaskmanager/abstracttasksmodel.cpp | 6 ++++++ libtaskmanager/abstracttasksmodel.h | 13 ++++++++++++ libtaskmanager/abstracttasksmodeliface.h | 12 +++++++++++ libtaskmanager/activityinfo.h | 2 +- libtaskmanager/concatenatetasksproxymodel.cpp | 17 +++++++++++++++ libtaskmanager/concatenatetasksproxymodel.h | 13 ++++++++++++ .../flattentaskgroupsproxymodel.cpp | 7 +++++++ libtaskmanager/flattentaskgroupsproxymodel.h | 11 ++++++++++ libtaskmanager/taskfilterproxymodel.cpp | 7 +++++++ libtaskmanager/taskfilterproxymodel.h | 13 ++++++++++++ libtaskmanager/taskgroupingproxymodel.cpp | 21 +++++++++++++++++++ libtaskmanager/taskgroupingproxymodel.h | 13 ++++++++++++ libtaskmanager/tasksmodel.cpp | 7 +++++++ libtaskmanager/tasksmodel.h | 13 ++++++++++++ libtaskmanager/waylandtasksmodel.cpp | 6 ++++++ libtaskmanager/waylandtasksmodel.h | 10 +++++++++ libtaskmanager/xwindowtasksmodel.cpp | 12 +++++++++++ libtaskmanager/xwindowtasksmodel.h | 11 ++++++++++ 18 files changed, 193 insertions(+), 1 deletion(-) diff --git a/libtaskmanager/abstracttasksmodel.cpp b/libtaskmanager/abstracttasksmodel.cpp index b4b0b4162..18e062385 100644 --- a/libtaskmanager/abstracttasksmodel.cpp +++ b/libtaskmanager/abstracttasksmodel.cpp @@ -113,6 +113,12 @@ void AbstractTasksModel::requestVirtualDesktop(const QModelIndex &index, qint32 Q_UNUSED(desktop) } +void AbstractTasksModel::requestActivities(const QModelIndex &index, const QStringList &activities) +{ + Q_UNUSED(index) + Q_UNUSED(activities) +} + void AbstractTasksModel::requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) { Q_UNUSED(index) diff --git a/libtaskmanager/abstracttasksmodel.h b/libtaskmanager/abstracttasksmodel.h index 8a1e5af31..743b75276 100644 --- a/libtaskmanager/abstracttasksmodel.h +++ b/libtaskmanager/abstracttasksmodel.h @@ -232,6 +232,19 @@ public: **/ virtual void requestVirtualDesktop(const QModelIndex &index, qint32 desktop) override; + /** + * Request moving the task at the given index to the specified activities. + * + * This is meant for tasks that have an associated window, and may be + * a no-op when there is no window. + * + * This base implementation does nothing. + * + * @param index An index in this tasks model. + * @param activities The new list of activities. + **/ + virtual void requestActivities(const QModelIndex &index, const QStringList &activities); + /** * Request informing the window manager of new geometry for a visual * delegate for the task at the given index. The geometry should be in diff --git a/libtaskmanager/abstracttasksmodeliface.h b/libtaskmanager/abstracttasksmodeliface.h index e3941a730..c162e89bb 100644 --- a/libtaskmanager/abstracttasksmodeliface.h +++ b/libtaskmanager/abstracttasksmodeliface.h @@ -159,6 +159,18 @@ public: **/ virtual void requestVirtualDesktop(const QModelIndex &index, qint32 desktop = -1) = 0; + /** + * Request moving the task at the given index to the specified virtual + * activities. + * + * This is meant for tasks that have an associated window, and may be + * a no-op when there is no window. + * + * @param index An index in this tasks model. + * @param activities The new list of activities. + **/ + virtual void requestActivities(const QModelIndex &index, const QStringList &activities) = 0; + /** * Request informing the window manager of new geometry for a visual * delegate for the task at the given index. The geometry should be in diff --git a/libtaskmanager/activityinfo.h b/libtaskmanager/activityinfo.h index 35bfe72e3..33552cb73 100644 --- a/libtaskmanager/activityinfo.h +++ b/libtaskmanager/activityinfo.h @@ -72,7 +72,7 @@ public: * * @returns the list of currently-running activities defined in the session. **/ - QStringList runningActivities() const; + Q_INVOKABLE QStringList runningActivities() const; /** * The name of the activity of the given id. diff --git a/libtaskmanager/concatenatetasksproxymodel.cpp b/libtaskmanager/concatenatetasksproxymodel.cpp index 5c8902084..3b1fd15c6 100644 --- a/libtaskmanager/concatenatetasksproxymodel.cpp +++ b/libtaskmanager/concatenatetasksproxymodel.cpp @@ -223,6 +223,23 @@ void ConcatenateTasksProxyModel::requestVirtualDesktop(const QModelIndex &index, } } +void ConcatenateTasksProxyModel::requestActivities(const QModelIndex &index, const QStringList &activities) +{ + if (!index.isValid() || index.model() != this) { + return; + } + + const QModelIndex &sourceIndex = mapToSource(index); + const AbstractTasksModelIface *m = dynamic_cast(sourceIndex.model()); + + if (m) { + // NOTE: KConcatenateRowsProxyModel offers no way to get a non-const pointer + // to one of the source models, so we have to go through a mapped index. + const_cast(m)->requestActivities(sourceIndex, activities); + } +} + + void ConcatenateTasksProxyModel::requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) { if (!index.isValid() || index.model() != this) { diff --git a/libtaskmanager/concatenatetasksproxymodel.h b/libtaskmanager/concatenatetasksproxymodel.h index 7da4dcc8d..0e94cb81a 100644 --- a/libtaskmanager/concatenatetasksproxymodel.h +++ b/libtaskmanager/concatenatetasksproxymodel.h @@ -164,6 +164,19 @@ public: **/ void requestVirtualDesktop(const QModelIndex &index, qint32 desktop); + /** + * Request moving the task at the given index to the specified activities. + * + * This is meant for tasks that have an associated window, and may be + * a no-op when there is no window. + * + * This base implementation does nothing. + * + * @param index An index in this tasks model. + * @param activities The new list of activities. + **/ + void requestActivities(const QModelIndex &index, const QStringList &activities); + /** * Request informing the window manager of new geometry for a visual * delegate for the task at the given index. The geometry should be in diff --git a/libtaskmanager/flattentaskgroupsproxymodel.cpp b/libtaskmanager/flattentaskgroupsproxymodel.cpp index e21dc524b..f100aedac 100644 --- a/libtaskmanager/flattentaskgroupsproxymodel.cpp +++ b/libtaskmanager/flattentaskgroupsproxymodel.cpp @@ -140,6 +140,13 @@ void FlattenTaskGroupsProxyModel::requestVirtualDesktop(const QModelIndex &index } } +void FlattenTaskGroupsProxyModel::requestActivities(const QModelIndex &index, const QStringList &activities) +{ + if (d->sourceTasksModel && index.isValid() && index.model() == this) { + d->sourceTasksModel->requestActivities(mapToSource(index), activities); + } +} + void FlattenTaskGroupsProxyModel::requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) { if (index.isValid() && index.model() == this) { diff --git a/libtaskmanager/flattentaskgroupsproxymodel.h b/libtaskmanager/flattentaskgroupsproxymodel.h index 0b5ec3cfb..ac2d3980a 100644 --- a/libtaskmanager/flattentaskgroupsproxymodel.h +++ b/libtaskmanager/flattentaskgroupsproxymodel.h @@ -167,6 +167,17 @@ public: **/ void requestVirtualDesktop(const QModelIndex &index, qint32 desktop) override; + /** + * Request moving the task at the given index to the specified activities. + * + * This is meant for tasks that have an associated window, and may be + * a no-op when there is no window. + * * + * @param index An index in this tasks model. + * @param activities The new list of activities. + **/ + void requestActivities(const QModelIndex &index, const QStringList &activities); + /** * Request informing the window manager of new geometry for a visual * delegate for the task at the given index. The geometry should be in diff --git a/libtaskmanager/taskfilterproxymodel.cpp b/libtaskmanager/taskfilterproxymodel.cpp index 79b902e5b..cd3824cbc 100644 --- a/libtaskmanager/taskfilterproxymodel.cpp +++ b/libtaskmanager/taskfilterproxymodel.cpp @@ -268,6 +268,13 @@ void TaskFilterProxyModel::requestVirtualDesktop(const QModelIndex &index, qint3 } } +void TaskFilterProxyModel::requestActivities(const QModelIndex &index, const QStringList &activities) +{ + if (d->sourceTasksModel && index.isValid() && index.model() == this) { + d->sourceTasksModel->requestActivities(mapToSource(index), activities); + } +} + void TaskFilterProxyModel::requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) { if (index.isValid() && index.model() == this) { diff --git a/libtaskmanager/taskfilterproxymodel.h b/libtaskmanager/taskfilterproxymodel.h index 80ba54b04..4f18444ca 100644 --- a/libtaskmanager/taskfilterproxymodel.h +++ b/libtaskmanager/taskfilterproxymodel.h @@ -324,6 +324,19 @@ public: **/ void requestVirtualDesktop(const QModelIndex &index, qint32 desktop) override; + /** + * Request moving the task at the given index to the specified activities. + * + * This is meant for tasks that have an associated window, and may be + * a no-op when there is no window. + * + * This base implementation does nothing. + * + * @param index An index in this tasks model. + * @param activities The new list of activities. + **/ + void requestActivities(const QModelIndex &index, const QStringList &activities); + /** * Request informing the window manager of new geometry for a visual * delegate for the task at the given index. The geometry should be in diff --git a/libtaskmanager/taskgroupingproxymodel.cpp b/libtaskmanager/taskgroupingproxymodel.cpp index 5839c52d7..767f375ff 100644 --- a/libtaskmanager/taskgroupingproxymodel.cpp +++ b/libtaskmanager/taskgroupingproxymodel.cpp @@ -1127,6 +1127,27 @@ void TaskGroupingProxyModel::requestVirtualDesktop(const QModelIndex &index, qin } } +void TaskGroupingProxyModel::requestActivities(const QModelIndex &index, const QStringList &activities) +{ + if (!d->abstractTasksSourceModel || !index.isValid() || index.model() != this) { + return; + } + + if (index.parent().isValid() || !d->isGroup(index.row())) { + d->abstractTasksSourceModel->requestActivities(mapToSource(index), activities); + } else { + const int row = index.row(); + + for (int i = (rowCount(index) - 1); i >= 1; --i) { + const QModelIndex &sourceChild = mapToSource(index.child(i, 0)); + d->abstractTasksSourceModel->requestActivities(sourceChild, activities); + } + + d->abstractTasksSourceModel->requestActivities(mapToSource(TaskGroupingProxyModel::index(row, 0)), + activities); + } +} + void TaskGroupingProxyModel::requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) { if (!d->abstractTasksSourceModel || !index.isValid() || index.model() != this) { diff --git a/libtaskmanager/taskgroupingproxymodel.h b/libtaskmanager/taskgroupingproxymodel.h index 341a5acc4..590ab7a56 100644 --- a/libtaskmanager/taskgroupingproxymodel.h +++ b/libtaskmanager/taskgroupingproxymodel.h @@ -316,6 +316,19 @@ public: **/ void requestVirtualDesktop(const QModelIndex &index, qint32 desktop) override; + /** + * Request moving the task at the given index to the specified activities. + * + * This is meant for tasks that have an associated window, and may be + * a no-op when there is no window. + * + * This base implementation does nothing. + * + * @param index An index in this tasks model. + * @param activities The new list of activities. + **/ + virtual void requestActivities(const QModelIndex &index, const QStringList &activities); + /** * Request informing the window manager of new geometry for a visual * delegate for the task at the given index. The geometry should be in diff --git a/libtaskmanager/tasksmodel.cpp b/libtaskmanager/tasksmodel.cpp index 166a3716c..0dfde5da0 100644 --- a/libtaskmanager/tasksmodel.cpp +++ b/libtaskmanager/tasksmodel.cpp @@ -1232,6 +1232,13 @@ void TasksModel::requestVirtualDesktop(const QModelIndex &index, qint32 desktop) } } +void TasksModel::requestActivities(const QModelIndex &index, const QStringList &activities) +{ + if (index.isValid() && index.model() == this) { + d->groupingProxyModel->requestActivities(mapToSource(index), activities); + } +} + void TasksModel::requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) { if (index.isValid() && index.model() == this) { diff --git a/libtaskmanager/tasksmodel.h b/libtaskmanager/tasksmodel.h index 5074f7554..a9968d578 100644 --- a/libtaskmanager/tasksmodel.h +++ b/libtaskmanager/tasksmodel.h @@ -622,6 +622,19 @@ public: **/ Q_INVOKABLE void requestVirtualDesktop(const QModelIndex &index, qint32 desktop) override; + /** + * Request moving the task at the given index to the specified activities. + * + * This is meant for tasks that have an associated window, and may be + * a no-op when there is no window. + * + * This base implementation does nothing. + * + * @param index An index in this tasks model. + * @param activities The new list of activities. + **/ + Q_INVOKABLE virtual void requestActivities(const QModelIndex &index, const QStringList &activities); + /** * Request informing the window manager of new geometry for a visual * delegate for the task at the given index. The geometry should be in diff --git a/libtaskmanager/waylandtasksmodel.cpp b/libtaskmanager/waylandtasksmodel.cpp index 2cbdf188d..0ea545113 100644 --- a/libtaskmanager/waylandtasksmodel.cpp +++ b/libtaskmanager/waylandtasksmodel.cpp @@ -462,6 +462,12 @@ void WaylandTasksModel::requestVirtualDesktop(const QModelIndex &index, qint32 d d->windows.at(index.row())->requestVirtualDesktop(desktop); } +void WaylandTasksModel::requestActivities(const QModelIndex &index, const QStringList &activities) +{ + Q_UNUSED(index) + Q_UNUSED(activities) +} + void WaylandTasksModel::requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) { /* diff --git a/libtaskmanager/waylandtasksmodel.h b/libtaskmanager/waylandtasksmodel.h index 5bd30a2db..f93529620 100644 --- a/libtaskmanager/waylandtasksmodel.h +++ b/libtaskmanager/waylandtasksmodel.h @@ -162,6 +162,16 @@ public: **/ void requestVirtualDesktop(const QModelIndex &index, qint32 desktop) override; + /** + * Request moving the window at the given index to the specified activities + * + * FIXME: This currently does nothing as activities is not implementated in kwin/kwayland + * + * @param index An index in this window tasks model. + * @param desktop A virtual desktop number. + **/ + void requestActivities(const QModelIndex &index, const QStringList &activities) override; + /** * Request informing the window manager of new geometry for a visual * delegate for the window at the given index. The geometry is retrieved diff --git a/libtaskmanager/xwindowtasksmodel.cpp b/libtaskmanager/xwindowtasksmodel.cpp index 8c253de2c..6ab879765 100644 --- a/libtaskmanager/xwindowtasksmodel.cpp +++ b/libtaskmanager/xwindowtasksmodel.cpp @@ -1199,6 +1199,18 @@ void XWindowTasksModel::requestVirtualDesktop(const QModelIndex &index, qint32 d } } +void XWindowTasksModel::requestActivities(const QModelIndex &index, const QStringList &activities) +{ + if (!index.isValid() || index.model() != this || index.row() < 0 || index.row() >= d->windows.count()) { + return; + } + + const WId window = d->windows.at(index.row()); + + KWindowSystem::setOnActivities(window, activities); +} + + void XWindowTasksModel::requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) { Q_UNUSED(delegate) diff --git a/libtaskmanager/xwindowtasksmodel.h b/libtaskmanager/xwindowtasksmodel.h index d24a7d5e0..55fc49cfb 100644 --- a/libtaskmanager/xwindowtasksmodel.h +++ b/libtaskmanager/xwindowtasksmodel.h @@ -176,6 +176,17 @@ public: **/ void requestVirtualDesktop(const QModelIndex &index, qint32 desktop) override; + /** + * Request moving the task at the given index to the specified activities. + * + * This is meant for tasks that have an associated window, and may be + * a no-op when there is no window. + * * + * @param index An index in this tasks model. + * @param activities The new list of activities. + **/ + void requestActivities(const QModelIndex &index, const QStringList &activities) override; + /** * Request informing the window manager of new geometry for a visual * delegate for the window at the given index.