1 /*
2     SPDX-FileCopyrightText: 2016 Eike Hein <hein@kde.org>
3 
4     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 
7 #pragma once
8 
9 #include "abstracttasksmodeliface.h"
10 
11 #include <QAbstractListModel>
12 
13 #include "taskmanager_export.h"
14 
15 namespace TaskManager
16 {
17 /**
18  * @short An abstract base class for (flat) tasks models.
19  *
20  * This class serves as abstract base class for flat tasks model implementations.
21  * It provides data roles and no-op default implementations of methods in the
22  * AbstractTasksModelIface interface.
23  *
24  * @author Eike Hein <hein@kde.org>
25  **/
26 class TASKMANAGER_EXPORT AbstractTasksModel : public QAbstractListModel, public AbstractTasksModelIface
27 {
28     Q_OBJECT
29 
30 public:
31     enum AdditionalRoles {
32         AppId = Qt::UserRole + 1, /**< KService storage id (.desktop name sans extension). */
33         AppName, /**< Application name. */
34         GenericName, /**< Generic application name. */
35         LauncherUrl, /**< URL that can be used to launch this application (.desktop or executable). */
36         LauncherUrlWithoutIcon, /**< Special path to get a launcher URL while skipping fallback icon encoding. Used as speed optimization. */
37         WinIdList, /**< NOTE: On Wayland, these ids are only useful within the same process. On X11, they are global window ids. */
38         MimeType, /**< MIME type for this task (window, window group), needed for DND. */
39         MimeData, /**< Data for MimeType. */
40         IsWindow, /**< This is a window task. */
41         IsStartup, /**< This is a startup task. */
42         IsLauncher, /**< This is a launcher task. */
43         HasLauncher, /**< A launcher exists for this task. Only implemented by TasksModel, not by either the single-type or munging tasks models. */
44         IsGroupParent, /**< This is a parent item for a group of child tasks. */
45         ChildCount, /**< The number of tasks in this group. */
46         IsGroupable, /**< Whether this task is being ignored by grouping or not. */
47         IsActive, /**< This is the currently active task. */
48         IsClosable, /**< requestClose (see below) available. */
49         IsMovable, /**< requestMove (see below) available. */
50         IsResizable, /**< requestResize (see below) available. */
51         IsMaximizable, /**< requestToggleMaximize (see below) available. */
52         IsMaximized, /**< Task (i.e. window) is maximized. */
53         IsMinimizable, /**< requestToggleMinimize (see below) available. */
54         IsMinimized, /**< Task (i.e. window) is minimized. */
55         IsKeepAbove, /**< Task (i.e. window) is keep-above. */
56         IsKeepBelow, /**< Task (i.e. window) is keep-below. */
57         IsFullScreenable, /**< requestToggleFullScreen (see below) available. */
58         IsFullScreen, /**< Task (i.e. window) is fullscreen. */
59         IsShadeable, /**< requestToggleShade (see below) available. */
60         IsShaded, /**< Task (i.e. window) is shaded. */
61         IsVirtualDesktopsChangeable, /**< requestVirtualDesktop (see below) available. */
62         VirtualDesktops, /**< Virtual desktops for the task (i.e. window). */
63         IsOnAllVirtualDesktops, /**< Task is on all virtual desktops. */
64         Geometry, /**< The task's geometry (i.e. the window's). */
65         ScreenGeometry, /**< Screen geometry for the task (i.e. the window's screen). */
66         Activities, /**< Activities for the task (i.e. window). */
67         IsDemandingAttention, /**< Task is demanding attention. */
68         SkipTaskbar, /**< Task should not be shown in a 'task bar' user interface. */
69         SkipPager, /**< Task should not to be shown in a 'pager' user interface. */
70         AppPid, /**< Application Process ID. This is provided best-effort, and may not
71                      be what you expect: For window tasks owned by processes started
72                      from e.g. kwin_wayland, it would be the process id of kwin
73                      itself. DO NOT use this for destructive actions such as closing
74                      the application. The intended use case is to try and (smartly)
75                      gather more information about the task when needed. */
76         StackingOrder, /**< A window task's index in the window stacking order. Care must be
77                             taken not to assume this index to be unique when iterating over
78                             model contents due to the asynchronous nature of the windowing
79                             system. */
80         LastActivated, /**< The timestamp of the last time a task was the active task. */
81         ApplicationMenuServiceName, /**< The DBus service name for the application's menu.
82                                          May be empty. @since 5.19 */
83         ApplicationMenuObjectPath, /**< The DBus object path for the application's menu.
84                                         May be empty. @since 5.19 */
85         IsHidden, /**< Task (i.e window) is hidden on screen. A minimzed
86                        window is not necessarily hidden. */
87     };
88     Q_ENUM(AdditionalRoles)
89 
90     explicit AbstractTasksModel(QObject *parent = nullptr);
91     ~AbstractTasksModel() override;
92 
93     QHash<int, QByteArray> roleNames() const override;
94 
95     QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const override;
96 
97     /**
98      * Request activation of the task at the given index. Derived classes are
99      * free to interpret the meaning of "activate" themselves depending on
100      * the nature and state of the task, e.g. launch or raise a window task.
101      *
102      * This base implementation does nothing.
103      *
104      * @param index An index in this tasks model.
105      **/
106     void requestActivate(const QModelIndex &index) override;
107 
108     /**
109      * Request an additional instance of the application backing the task
110      * at the given index.
111      *
112      * This base implementation does nothing.
113      *
114      * @param index An index in this tasks model.
115      **/
116     void requestNewInstance(const QModelIndex &index) override;
117 
118     /**
119      * Requests to open the given URLs with the application backing the task
120      * at the given index.
121      *
122      * This base implementation does nothing.
123      *
124      * @param index An index in this tasks model.
125      * @param urls The URLs to be passed to the application.
126      **/
127     void requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls) override;
128 
129     /**
130      * Request the task at the given index be closed.
131      *
132      * This base implementation does nothing.
133      *
134      * @param index An index in this tasks model.
135      **/
136     void requestClose(const QModelIndex &index) override;
137 
138     /**
139      * Request starting an interactive move for the task at the given index.
140      *
141      * This is meant for tasks that have an associated window, and may be
142      * a no-op when there is no window.
143      *
144      * This base implementation does nothing.
145      *
146      * @param index An index in this tasks model.
147      **/
148     void requestMove(const QModelIndex &index) override;
149 
150     /**
151      * Request starting an interactive resize for the task at the given index.
152      *
153      * This is meant for tasks that have an associated window, and may be a
154      * no-op when there is no window.
155      *
156      * This base implementation does nothing.
157      *
158      * @param index An index in this tasks model.
159      **/
160     void requestResize(const QModelIndex &index) override;
161 
162     /**
163      * Request toggling the minimized state of the task at the given index.
164      *
165      * This is meant for tasks that have an associated window, and may be
166      * a no-op when there is no window.
167      *
168      * This base implementation does nothing.
169      *
170      * @param index An index in this tasks model.
171      **/
172     void requestToggleMinimized(const QModelIndex &index) override;
173 
174     /**
175      * Request toggling the maximized state of the task at the given index.
176      *
177      * This is meant for tasks that have an associated window, and may be
178      * a no-op when there is no window.
179      *
180      * This base implementation does nothing.
181      *
182      * @param index An index in this tasks model.
183      **/
184     void requestToggleMaximized(const QModelIndex &index) override;
185 
186     /**
187      * Request toggling the keep-above state of the task at the given index.
188      *
189      * This is meant for tasks that have an associated window, and may be
190      * a no-op when there is no window.
191      *
192      * This base implementation does nothing.
193      *
194      * @param index An index in this tasks model.
195      **/
196     void requestToggleKeepAbove(const QModelIndex &index) override;
197 
198     /**
199      * Request toggling the keep-below state of the task at the given index.
200      *
201      * This is meant for tasks that have an associated window, and may be
202      * a no-op when there is no window.
203      *
204      * This base implementation does nothing.
205      *
206      * @param index An index in this tasks model.
207      **/
208     void requestToggleKeepBelow(const QModelIndex &index) override;
209 
210     /**
211      * Request toggling the fullscreen state of the task at the given index.
212      *
213      * This is meant for tasks that have an associated window, and may be
214      * a no-op when there is no window.
215      *
216      * This base implementation does nothing.
217      *
218      * @param index An index in this tasks model.
219      **/
220     void requestToggleFullScreen(const QModelIndex &index) override;
221 
222     /**
223      * Request toggling the shaded state of the task at the given index.
224      *
225      * This is meant for tasks that have an associated window, and may be
226      * a no-op when there is no window.
227      *
228      * This base implementation does nothing.
229      *
230      * @param index An index in this tasks model.
231      **/
232     void requestToggleShaded(const QModelIndex &index) override;
233 
234     /**
235      * Request entering the window at the given index on the specified virtual desktops,
236      * leaving any other desktops.
237      *
238      * On Wayland, virtual desktop ids are QStrings. On X11, they are uint >0.
239      *
240      * An empty list has a special meaning: The window is entered on all virtual desktops
241      * in the session.
242      *
243      * On X11, a window can only be on one or all virtual desktops. Therefore, only the
244      * first list entry is actually used.
245      *
246      * On X11, the id 0 has a special meaning: The window is entered on all virtual
247      * desktops in the session.
248      *
249      * @param index An index in this window tasks model.
250      * @param desktops A list of virtual desktop ids.
251      **/
252     void requestVirtualDesktops(const QModelIndex &index, const QVariantList &desktops) override;
253 
254     /**
255      * Request entering the window at the given index on a new virtual desktop,
256      * which is created in response to this request.
257      *
258      * @param index An index in this window tasks model.
259      **/
260     void requestNewVirtualDesktop(const QModelIndex &index) override;
261 
262     /**
263      * Request moving the task at the given index to the specified activities.
264      *
265      * This is meant for tasks that have an associated window, and may be
266      * a no-op when there is no window.
267      *
268      * This base implementation does nothing.
269      *
270      * @param index An index in this tasks model.
271      * @param activities The new list of activities.
272      **/
273     void requestActivities(const QModelIndex &index, const QStringList &activities) override;
274 
275     /**
276      * Request informing the window manager of new geometry for a visual
277      * delegate for the task at the given index. The geometry should be in
278      * screen coordinates.
279      *
280      * This base implementation does nothing.
281      *
282      * @param index An index in this tasks model.
283      * @param geometry Visual delegate geometry in screen coordinates.
284      * @param delegate The delegate. Implementations are on their own with
285      * regard to extracting information from this, and should take care to
286      * reject invalid objects.
287      **/
288     void requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate = nullptr) override;
289 };
290 
291 }
292