Plasma-workspace

tasksmodel.h
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 <QQmlParserStatus>
10#include <QSortFilterProxyModel>
11
12#include <memory>
13
14#include "abstracttasksmodeliface.h"
15#include "regionfiltermode.h"
16
17#include "taskmanager_export.h"
18
19namespace TaskManager
20{
21class ActivityInfo;
22class VirtualDesktopInfo;
23
24/**
25 * @short A unified tasks model.
26 *
27 * This model presents tasks sourced from supplied launcher URLs, startup
28 * notification data and window data retrieved from the windowing server
29 * the host process is connected to. The underlying windowing system is
30 * abstracted away.
31 *
32 * The source data is abstracted into a unified lifecycle for tasks
33 * suitable for presentation in a user interface.
34 *
35 * Matching startup and window tasks replace launcher tasks. Startup
36 * tasks are omitted when matching window tasks exist. Tasks that desire
37 * not to be shown in a user interface are omitted.
38 *
39 * Tasks may be filtered, sorted or grouped by setting properties on the
40 * model.
41 *
42 * Tasks may be interacted with by calling methods on the model.
43 *
44 * @author Eike Hein <hein@kde.org>
45 **/
46
47class TASKMANAGER_EXPORT TasksModel : public QSortFilterProxyModel, public AbstractTasksModelIface, public QQmlParserStatus
48{
49 Q_OBJECT
50 QML_ELEMENT
51 Q_INTERFACES(QQmlParserStatus)
52
53 Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
54 Q_PROPERTY(int launcherCount READ launcherCount NOTIFY launcherCountChanged)
55
56 Q_PROPERTY(QStringList launcherList READ launcherList WRITE setLauncherList NOTIFY launcherListChanged)
57
58 Q_PROPERTY(bool anyTaskDemandsAttention READ anyTaskDemandsAttention NOTIFY anyTaskDemandsAttentionChanged)
59
60 Q_PROPERTY(QVariant virtualDesktop READ virtualDesktop WRITE setVirtualDesktop NOTIFY virtualDesktopChanged)
61 Q_PROPERTY(QRect screenGeometry READ screenGeometry WRITE setScreenGeometry NOTIFY screenGeometryChanged)
62 Q_PROPERTY(QRect regionGeometry READ regionGeometry WRITE setRegionGeometry NOTIFY regionGeometryChanged)
63 Q_PROPERTY(QString activity READ activity WRITE setActivity NOTIFY activityChanged)
64
65 Q_PROPERTY(bool filterByVirtualDesktop READ filterByVirtualDesktop WRITE setFilterByVirtualDesktop NOTIFY filterByVirtualDesktopChanged)
66 Q_PROPERTY(bool filterByScreen READ filterByScreen WRITE setFilterByScreen NOTIFY filterByScreenChanged)
67 Q_PROPERTY(bool filterByActivity READ filterByActivity WRITE setFilterByActivity NOTIFY filterByActivityChanged)
68 Q_PROPERTY(RegionFilterMode::Mode filterByRegion READ filterByRegion WRITE setFilterByRegion NOTIFY filterByRegionChanged)
69 Q_PROPERTY(bool filterMinimized READ filterMinimized WRITE setFilterMinimized NOTIFY filterMinimizedChanged)
70 Q_PROPERTY(bool filterNotMinimized READ filterNotMinimized WRITE setFilterNotMinimized NOTIFY filterNotMinimizedChanged)
71 Q_PROPERTY(bool filterNotMaximized READ filterNotMaximized WRITE setFilterNotMaximized NOTIFY filterNotMaximizedChanged)
72 Q_PROPERTY(bool filterHidden READ filterHidden WRITE setFilterHidden NOTIFY filterHiddenChanged)
73
74 Q_PROPERTY(SortMode sortMode READ sortMode WRITE setSortMode NOTIFY sortModeChanged)
75 Q_PROPERTY(bool separateLaunchers READ separateLaunchers WRITE setSeparateLaunchers NOTIFY separateLaunchersChanged)
76 Q_PROPERTY(bool launchInPlace READ launchInPlace WRITE setLaunchInPlace NOTIFY launchInPlaceChanged)
77 Q_PROPERTY(bool hideActivatedLaunchers READ hideActivatedLaunchers WRITE setHideActivatedLaunchers NOTIFY hideActivatedLaunchersChanged)
78
79 Q_PROPERTY(GroupMode groupMode READ groupMode WRITE setGroupMode NOTIFY groupModeChanged)
80 Q_PROPERTY(bool groupInline READ groupInline WRITE setGroupInline NOTIFY groupInlineChanged)
81 Q_PROPERTY(
82 int groupingWindowTasksThreshold READ groupingWindowTasksThreshold WRITE setGroupingWindowTasksThreshold NOTIFY groupingWindowTasksThresholdChanged)
83 Q_PROPERTY(QStringList groupingAppIdBlacklist READ groupingAppIdBlacklist WRITE setGroupingAppIdBlacklist NOTIFY groupingAppIdBlacklistChanged)
84 Q_PROPERTY(QStringList groupingLauncherUrlBlacklist READ groupingLauncherUrlBlacklist WRITE setGroupingLauncherUrlBlacklist NOTIFY
85 groupingLauncherUrlBlacklistChanged)
86 Q_PROPERTY(bool taskReorderingEnabled READ taskReorderingEnabled WRITE setTaskReorderingEnabled NOTIFY taskReorderingEnabledChanged)
87 Q_PROPERTY(QModelIndex activeTask READ activeTask NOTIFY activeTaskChanged)
88
89public:
90 enum SortMode {
91 SortDisabled = 0, /**< No sorting is done. */
92 SortManual, /**< Tasks can be moved with move() and syncLaunchers(). */
93 SortAlpha, /**< Tasks are sorted alphabetically, by AbstractTasksModel::AppName and Qt::DisplayRole. */
94 SortVirtualDesktop, /**< Tasks are sorted by the virtual desktop they are on. */
95 SortActivity, /**< Tasks are sorted by the number of tasks on the activities they're on. */
96 SortLastActivated, /**< Tasks are sorted by the last time they were active. */
97 };
98 Q_ENUM(SortMode)
99
101 GroupDisabled = 0, /**< No grouping is done. */
102 GroupApplications, /**< Tasks are grouped by the application backing them. */
103 };
104 Q_ENUM(GroupMode)
105
106 explicit TasksModel(QObject *parent = nullptr);
107 ~TasksModel() override;
108
109 QHash<int, QByteArray> roleNames() const override;
110
111 Q_INVOKABLE int rowCount(const QModelIndex &parent = QModelIndex()) const override; // Invokable.
112
113 QVariant data(const QModelIndex &proxyIndex, int role) const override;
114
115 /**
116 * The number of launcher tasks in the tast list.
117 *
118 * @returns the number of launcher tasks in the task list.
119 **/
120 int launcherCount() const;
121
122 /**
123 * The list of launcher URLs serialized to strings along with
124 * the activities they belong to.
125 *
126 * @see setLauncherList
127 * @returns the list of launcher URLs serialized to strings.
128 **/
129 QStringList launcherList() const;
130
131 /**
132 * Replace the list of launcher URL strings.
133 *
134 * Invalid or empty URLs will be rejected. Duplicate URLs will be
135 * collapsed.
136 *
137 * @see launcherList
138 * @param launchers A list of launcher URL strings.
139 **/
140 void setLauncherList(const QStringList &launchers);
141
142 /**
143 * Returns whether any task in the model currently demands attention
144 * (AbstractTasksModel::IsDemandingAttention).
145 *
146 * @returns whether any task in the model currently demands attention.
147 **/
148 bool anyTaskDemandsAttention() const;
149
150 /**
151 * The id of the virtual desktop used in filtering by virtual
152 * desktop. Usually set to the id of the current virtual desktop.
153 * Defaults to empty.
154 *
155 * @see setVirtualDesktop
156 * @returns the number of the virtual desktop used in filtering.
157 **/
158 QVariant virtualDesktop() const;
159
160 /**
161 * Set the id of the virtual desktop to use in filtering by virtual
162 * desktop.
163 *
164 * If set to an empty id, filtering by virtual desktop is disabled.
165 *
166 * @see virtualDesktop
167 * @param desktop A virtual desktop id (QString on Wayland; uint >0 on X11).
168 **/
169 void setVirtualDesktop(const QVariant &desktop = QVariant());
170
171 /**
172 * The geometry of the screen used in filtering by screen. Defaults
173 * to a null QRect.
174 *
175 * @see setGeometryScreen
176 * @returns the geometry of the screen used in filtering.
177 **/
178 QRect screenGeometry() const;
179
180 /**
181 * Set the geometry of the screen to use in filtering by screen.
182 *
183 * If set to an invalid QRect, filtering by screen is disabled.
184 *
185 * @see screenGeometry
186 * @param geometry A screen geometry.
187 **/
188 void setScreenGeometry(const QRect &geometry);
189
190 /**
191 * The geometry of the region used in filtering by region. Defaults
192 * to a null QRect.
193 *
194 * @see setRegionGeometry
195 * @since 6.0
196 * @returns the geometry of the region used in filtering.
197 **/
198 QRect regionGeometry() const;
199
200 /**
201 * Set the geometry of the screen to use in filtering by region.
202 *
203 * If set to an invalid QRect, filtering by region is disabled.
204 *
205 * @see regionGeometry
206 * @since 6.0
207 * @param geometry A region geometry.
208 **/
209 void setRegionGeometry(const QRect &geometry);
210
211 /**
212 * The id of the activity used in filtering by activity. Usually
213 * set to the id of the current activity. Defaults to an empty id.
214 *
215 * @see setActivity
216 * @returns the id of the activity used in filtering.
217 **/
218 QString activity() const;
219
220 /**
221 * Set the id of the activity to use in filtering by activity.
222 *
223 * @see activity
224 * @param activity An activity id.
225 **/
226 void setActivity(const QString &activity);
227
228 /**
229 * Whether tasks should be filtered by virtual desktop. Defaults to
230 * @c false.
231 *
232 * Filtering by virtual desktop only happens if a virtual desktop
233 * number is set, even if this returns @c true.
234 *
235 * @see setFilterByVirtualDesktop
236 * @see setVirtualDesktop
237 * @returns @c true if tasks should be filtered by virtual desktop.
238 **/
239 bool filterByVirtualDesktop() const;
240
241 /**
242 * Set whether tasks should be filtered by virtual desktop.
243 *
244 * Filtering by virtual desktop only happens if a virtual desktop
245 * number is set, even if this is set to @c true.
246 *
247 * @see filterByVirtualDesktop
248 * @see setVirtualDesktop
249 * @param filter Whether tasks should be filtered by virtual desktop.
250 **/
251 void setFilterByVirtualDesktop(bool filter);
252
253 /**
254 * Whether tasks should be filtered by screen. Defaults to @c false.
255 *
256 * Filtering by screen only happens if a screen number is set, even
257 * if this returns @c true.
258 *
259 * @see setFilterByScreen
260 * @see setScreenGeometry
261 * @returns @c true if tasks should be filtered by screen.
262 **/
263 bool filterByScreen() const;
264
265 /**
266 * Set whether tasks should be filtered by screen.
267 *
268 * Filtering by screen only happens if a screen number is set, even
269 * if this is set to @c true.
270 *
271 * @see filterByScreen
272 * @see setScreenGeometry
273 * @param filter Whether tasks should be filtered by screen.
274 **/
275 void setFilterByScreen(bool filter);
276
277 /**
278 * Whether tasks should be filtered by activity. Defaults to @c false.
279 *
280 * Filtering by activity only happens if an activity id is set, even
281 * if this returns @c true.
282 *
283 * @see setFilterByActivity
284 * @see setActivity
285 * @returns @c true if tasks should be filtered by activity.
286 **/
287 bool filterByActivity() const;
288
289 /**
290 * Set whether tasks should be filtered by activity. Defaults to
291 * @c false.
292 *
293 * Filtering by activity only happens if an activity id is set,
294 * even if this is set to @c true.
295 *
296 * @see filterByActivity
297 * @see setActivity
298 * @param filter Whether tasks should be filtered by activity.
299 **/
300 void setFilterByActivity(bool filter);
301
302 /**
303 * Whether tasks should be filtered by region. Defaults to @c RegionFilterMode::Disabled.
304 *
305 * Filtering by region only happens if a region is set, even
306 * if the filter is enabled.
307 *
308 * @see RegionFilterMode
309 * @see setFilterByRegion
310 * @see setRegionGeometry
311 * @since 6.0
312 * @returns Region filter mode.
313 **/
314 RegionFilterMode::Mode filterByRegion() const;
315
316 /**
317 * Set whether tasks should be filtered by region. Defaults to
318 * @c RegionFilterMode::Disabled.
319 *
320 * Filtering by region only happens if a region is set,
321 * even if the filter is enabled.
322 *
323 * @see RegionFilterMode
324 * @see filterByRegion
325 * @see setRegionGeometry
326 * @since 6.0
327 * @param mode Region filter mode.
328 **/
329 void setFilterByRegion(RegionFilterMode::Mode mode);
330
331 /**
332 * Whether minimized tasks should be filtered out. Defaults to
333 * @c false.
334 *
335 * @returns @c true if minimized tasks should be filtered out.
336 * @see setFilterMinimized
337 * @since 5.27
338 **/
339 bool filterMinimized() const;
340
341 /**
342 * Sets whether non-minimized tasks should be filtered out.
343 *
344 * @param filter Whether minimized tasks should be filtered out.
345 * @see filterMinimized
346 * @since 5.27
347 **/
348 void setFilterMinimized(bool filter);
349
350 /**
351 * Whether non-minimized tasks should be filtered. Defaults to
352 * @c false.
353 *
354 * @see setFilterNotMinimized
355 * @returns @c true if non-minimized tasks should be filtered.
356 **/
357 bool filterNotMinimized() const;
358
359 /**
360 * Set whether non-minimized tasks should be filtered.
361 *
362 * @see filterNotMinimized
363 * @param filter Whether non-minimized tasks should be filtered.
364 **/
365 void setFilterNotMinimized(bool filter);
366
367 /**
368 * Whether non-maximized tasks should be filtered. Defaults to
369 * @c false.
370 *
371 * @see setFilterNotMaximized
372 * @returns @c true if non-maximized tasks should be filtered.
373 **/
374 bool filterNotMaximized() const;
375
376 /**
377 * Set whether non-maximized tasks should be filtered.
378 *
379 * @see filterNotMaximized
380 * @param filter Whether non-maximized tasks should be filtered.
381 **/
382 void setFilterNotMaximized(bool filter);
383
384 /**
385 * Whether hidden tasks should be filtered. Defaults to
386 * @c false.
387 *
388 * @see setFilterHidden
389 * @returns @c true if hidden tasks should be filtered.
390 **/
391 bool filterHidden() const;
392
393 /**
394 * Set whether hidden tasks should be filtered.
395 *
396 * @see filterHidden
397 * @param filter Whether hidden tasks should be filtered.
398 **/
399 void setFilterHidden(bool filter);
400
401 /**
402 * The sort mode used in sorting tasks. Defaults to SortAlpha.
403 *
404 * @see setSortMode
405 * @returns the current sort mode.
406 **/
407 SortMode sortMode() const;
408
409 /**
410 * Sets the sort mode used in sorting tasks.
411 *
412 * @see sortMode
413 * @param mode A sort mode.
414 **/
415 void setSortMode(SortMode mode);
416
417 /**
418 * Whether launchers are kept separate from other kinds of tasks.
419 * Defaults to @c true.
420 *
421 * When enabled, launcher tasks are sorted first in the tasks model
422 * and move() disallows moving them below the last launcher task,
423 * or moving a different kind of task above the first launcher. New
424 * launcher tasks are inserted after the last launcher task. When
425 * disabled, move() allows mixing, and new launcher tasks are
426 * appended to the model.
427 *
428 * Further, when disabled, the model always behaves as if
429 * launchInPlace is enabled: A window task takes the place of the
430 * first matching launcher task.
431 *
432 * @see LauncherTasksModel
433 * @see move
434 * @see launchInPlace
435 * @see setSeparateLaunchers
436 * @return whether launcher tasks are kept separate.
437 */
438 bool separateLaunchers() const;
439
440 /**
441 * Sets whether launchers are kept separate from other kinds of tasks.
442 *
443 * When enabled, launcher tasks are sorted first in the tasks model
444 * and move() disallows moving them below the last launcher task,
445 * or moving a different kind of task above the first launcher. New
446 * launcher tasks are inserted after the last launcher task. When
447 * disabled, move() allows mixing, and new launcher tasks are
448 * appended to the model.
449 *
450 * Further, when disabled, the model always behaves as if
451 * launchInPlace is enabled: A window task takes the place of the
452 * first matching launcher task.
453 *
454 * @see LauncherTasksModel
455 * @see move
456 * @see launchInPlace
457 * @see separateLaunchers
458 * @param separate Whether to keep launcher tasks separate.
459 */
460 void setSeparateLaunchers(bool separate);
461
462 /**
463 * Whether window tasks should be sorted as their associated launcher
464 * tasks or separately. Defaults to @c false.
465 *
466 * @see setLaunchInPlace
467 * @returns whether window tasks should be sorted as their associated
468 * launcher tasks.
469 **/
470 bool launchInPlace() const;
471
472 /**
473 * Sets whether window tasks should be sorted as their associated launcher
474 * tasks or separately.
475 *
476 * @see launchInPlace
477 * @param launchInPlace Whether window tasks should be sorted as their
478 * associated launcher tasks.
479 **/
480 void setLaunchInPlace(bool launchInPlace);
481
482 /**
483 * Whether launchers should be hidden after they have been
484 * activated. Defaults to @c true.
485 *
486 * @see hideActivatedLaunchers
487 * @returns whether launchers will be hidden after they have been
488 * activated.
489 **/
490 bool hideActivatedLaunchers() const;
491
492 /**
493 * Sets whether launchers should be hidden after they have been
494 * activated. Defaults to @c true.
495 *
496 * @see hideActivatedLaunchers
497 * @param hideActivatedLaunchers Whether launchers should be hidden
498 * after they have been activated.
499 **/
500 void setHideActivatedLaunchers(bool hideActivatedLaunchers);
501
502 /**
503 * Returns the current group mode, i.e. the criteria by which tasks should
504 * be grouped.
505 *
506 * Defaults to TasksModel::GroupApplication, which groups tasks backed by
507 * the same application.
508 *
509 * If the group mode is TasksModel::GroupDisabled, no grouping is done.
510 *
511 * @see setGroupMode
512 * @returns the current group mode.
513 **/
514 TasksModel::GroupMode groupMode() const;
515
516 /**
517 * Sets the group mode, i.e. the criteria by which tasks should be grouped.
518 *
519 * The group mode can be set to TasksModel::GroupDisabled to disable grouping
520 * entirely, breaking apart any existing groups.
521 *
522 * @see groupMode
523 * @param mode A group mode.
524 **/
525 void setGroupMode(TasksModel::GroupMode mode);
526
527 /**
528 * Returns whether grouping is done "inline" or not, i.e. whether groups
529 * are maintained inside the flat, top-level list, or by forming a tree.
530 * In inline grouping mode, move() on a group member will move all siblings
531 * as well, and sorting is first done among groups, then group members.
532 *
533 * Further, in inline grouping mode, the groupingWindowTasksThreshold
534 * setting is ignored: Grouping is always done.
535 *
536 * @see setGroupInline
537 * @see move
538 * @see groupingWindowTasksThreshold
539 * @returns whether grouping is done inline or not.
540 **/
541 bool groupInline() const;
542
543 /**
544 * Sets whether grouping is done "inline" or not, i.e. whether groups
545 * are maintained inside the flat, top-level list, or by forming a tree.
546 * In inline grouping mode, move() on a group member will move all siblings
547 * as well, and sorting is first done among groups, then group members.
548 *
549 * @see groupInline
550 * @see move
551 * @see groupingWindowTasksThreshold
552 * @param inline Whether to do grouping inline or not.
553 **/
554 void setGroupInline(bool groupInline);
555
556 /**
557 * As window tasks (AbstractTasksModel::IsWindow) come and go, groups will
558 * be formed when this threshold value is exceeded, and broken apart when
559 * it matches or falls below.
560 *
561 * Defaults to @c -1, which means grouping is done regardless of the number
562 * of window tasks.
563 *
564 * When the groupInline property is set to @c true, the threshold is ignored:
565 * Grouping is always done.
566 *
567 * @see setGroupingWindowTasksThreshold
568 * @see groupInline
569 * @return the threshold number of window tasks used in grouping decisions.
570 **/
571 int groupingWindowTasksThreshold() const;
572
573 /**
574 * Sets the number of window tasks (AbstractTasksModel::IsWindow) above which
575 * groups will be formed, and at or below which groups will be broken apart.
576 *
577 * If set to -1, grouping will be done regardless of the number of window tasks
578 * in the source model.
579 *
580 * When the groupInline property is set to @c true, the threshold is ignored:
581 * Grouping is always done.
582 *
583 * @see groupingWindowTasksThreshold
584 * @see groupInline
585 * @param threshold A threshold number of window tasks used in grouping
586 * decisions.
587 **/
588 void setGroupingWindowTasksThreshold(int threshold);
589
590 /**
591 * A blacklist of app ids (AbstractTasksModel::AppId) that is consulted before
592 * grouping a task. If a task's app id is found on the blacklist, it is not
593 * grouped.
594 *
595 * The default app id blacklist is empty.
596 *
597 * @see setGroupingAppIdBlacklist
598 * @returns the blacklist of app ids consulted before grouping a task.
599 **/
600 QStringList groupingAppIdBlacklist() const;
601
602 /**
603 * Sets the blacklist of app ids (AbstractTasksModel::AppId) that is consulted
604 * before grouping a task. If a task's app id is found on the blacklist, it is
605 * not grouped.
606 *
607 * When set, groups will be formed and broken apart as necessary.
608 *
609 * @see groupingAppIdBlacklist
610 * @param list a blacklist of app ids to be consulted before grouping a task.
611 **/
612 void setGroupingAppIdBlacklist(const QStringList &list);
613
614 /**
615 * A blacklist of launcher URLs (AbstractTasksModel::LauncherUrl) that is
616 * consulted before grouping a task. If a task's launcher URL is found on the
617 * blacklist, it is not grouped.
618 *
619 * The default launcher URL blacklist is empty.
620 *
621 * @see setGroupingLauncherUrlBlacklist
622 * @returns the blacklist of launcher URLs consulted before grouping a task.
623 **/
624 QStringList groupingLauncherUrlBlacklist() const;
625
626 /**
627 * Sets the blacklist of launcher URLs (AbstractTasksModel::LauncherUrl) that
628 * is consulted before grouping a task. If a task's launcher URL is found on
629 * the blacklist, it is not grouped.
630 *
631 * When set, groups will be formed and broken apart as necessary.
632 *
633 * @see groupingLauncherUrlBlacklist
634 * @param list a blacklist of launcher URLs to be consulted before grouping a task.
635 **/
636 void setGroupingLauncherUrlBlacklist(const QStringList &list);
637
638 /**
639 * Enables or disables tasks reordering.
640 *
641 * @param enabled enables tasks reordering if @c true; disables it otherwise.
642 */
643 void setTaskReorderingEnabled(bool enabled);
644
645 /**
646 * Returns whether tasks reordering is enabled or not.
647 *
648 * @returns whether tasks reordering is enabled or not.
649 */
650 bool taskReorderingEnabled() const;
651
652 /**
653 * Finds the first active (AbstractTasksModel::IsActive) task in the model
654 * and returns its QModelIndex, or a null QModelIndex if no active task is
655 * found.
656 *
657 * @returns the model index for the first active task, if any.
658 */
659 QModelIndex activeTask() const;
660
661 /**
662 * Request adding a launcher with the given URL.
663 *
664 * If this URL is already in the list, the request will fail. URLs are
665 * compared for equality after removing the query string used to hold
666 * metadata.
667 *
668 * @see launcherUrlsMatch
669 * @param url A launcher URL.
670 * @returns @c true if a launcher was added.
671 */
672 Q_INVOKABLE bool requestAddLauncher(const QUrl &url);
673
674 /**
675 * Request removing the launcher with the given URL.
676 *
677 * If this URL is already in the list, the request will fail. URLs are
678 * compared for equality after removing the query string used to hold
679 * metadata.
680 *
681 * @see launcherUrlsMatch
682 * @param url A launcher URL.
683 * @returns @c true if the launcher was removed.
684 */
685 Q_INVOKABLE bool requestRemoveLauncher(const QUrl &url);
686
687 /**
688 * Request adding a launcher with the given URL to current activity.
689 *
690 * If this URL is already in the list, the request will fail. URLs are
691 * compared for equality after removing the query string used to hold
692 * metadata.
693 *
694 * @see launcherUrlsMatch
695 * @param url A launcher URL.
696 * @returns @c true if a launcher was added.
697 */
698 Q_INVOKABLE bool requestAddLauncherToActivity(const QUrl &url, const QString &activity);
699
700 /**
701 * Request removing the launcher with the given URL from the current activity.
702 *
703 * If this URL is already in the list, the request will fail. URLs are
704 * compared for equality after removing the query string used to hold
705 * metadata.
706 *
707 * @see launcherUrlsMatch
708 * @param url A launcher URL.
709 * @returns @c true if the launcher was removed.
710 */
711 Q_INVOKABLE bool requestRemoveLauncherFromActivity(const QUrl &url, const QString &activity);
712
713 /**
714 * Return the list of activities the launcher belongs to.
715 * If there is no launcher with that url, the list will be empty,
716 * while if the launcher is on all activities, it will contain a
717 * null uuid.
718 *
719 * URLs are compared for equality after removing the query string used
720 * to hold metadata.
721 */
722 Q_INVOKABLE QStringList launcherActivities(const QUrl &url);
723
724 /**
725 * Return the position of the launcher with the given URL.
726 *
727 * URLs are compared for equality after removing the query string used
728 * to hold metadata.
729 *
730 * @see launcherUrlsMatch
731 * @param url A launcher URL.
732 * @returns @c -1 if no launcher exists for the given URL.
733 */
734 Q_INVOKABLE int launcherPosition(const QUrl &url) const;
735
736 /**
737 * Request activation of the task at the given index. Derived classes are
738 * free to interpret the meaning of "activate" themselves depending on
739 * the nature and state of the task, e.g. launch or raise a window task.
740 *
741 * @param index An index in this tasks model.
742 **/
743 Q_INVOKABLE void requestActivate(const QModelIndex &index) override;
744
745 /**
746 * Request an additional instance of the application backing the task
747 * at the given index.
748 *
749 * @param index An index in this tasks model.
750 **/
751 Q_INVOKABLE void requestNewInstance(const QModelIndex &index) override;
752
753 /**
754 * Requests to open the given URLs with the application backing the task
755 * at the given index.
756 *
757 * @param index An index in this tasks model.
758 * @param urls The URLs to be passed to the application.
759 **/
760 Q_INVOKABLE void requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls) override;
761
762 /**
763 * Request the task at the given index be closed.
764 *
765 * @param index An index in this tasks model.
766 **/
767 Q_INVOKABLE void requestClose(const QModelIndex &index) override;
768
769 /**
770 * Request starting an interactive move for the task at the given index.
771 *
772 * This is meant for tasks that have an associated window, and may be
773 * a no-op when there is no window.
774 *
775 * @param index An index in this tasks model.
776 **/
777 Q_INVOKABLE void requestMove(const QModelIndex &index) override;
778
779 /**
780 * Request starting an interactive resize for the task at the given index.
781 *
782 * This is meant for tasks that have an associated window, and may be a
783 * no-op when there is no window.
784 *
785 * @param index An index in this tasks model.
786 **/
787 Q_INVOKABLE void requestResize(const QModelIndex &index) override;
788
789 /**
790 * Request toggling the minimized state of the task at the given index.
791 *
792 * This is meant for tasks that have an associated window, and may be
793 * a no-op when there is no window.
794 *
795 * @param index An index in this tasks model.
796 **/
797 Q_INVOKABLE void requestToggleMinimized(const QModelIndex &index) override;
798
799 /**
800 * Request toggling the maximized state of the task at the given index.
801 *
802 * This is meant for tasks that have an associated window, and may be
803 * a no-op when there is no window.
804 *
805 * @param index An index in this tasks model.
806 **/
807 Q_INVOKABLE void requestToggleMaximized(const QModelIndex &index) override;
808
809 /**
810 * Request toggling the keep-above state of the task at the given index.
811 *
812 * This is meant for tasks that have an associated window, and may be
813 * a no-op when there is no window.
814 *
815 * @param index An index in this tasks model.
816 **/
817 Q_INVOKABLE void requestToggleKeepAbove(const QModelIndex &index) override;
818
819 /**
820 * Request toggling the keep-below state of the task at the given index.
821 *
822 * This is meant for tasks that have an associated window, and may be
823 * a no-op when there is no window.
824 *
825 * @param index An index in this tasks model.
826 **/
827 Q_INVOKABLE void requestToggleKeepBelow(const QModelIndex &index) override;
828
829 /**
830 * Request toggling the fullscreen state of the task at the given index.
831 *
832 * This is meant for tasks that have an associated window, and may be
833 * a no-op when there is no window.
834 *
835 * @param index An index in this tasks model.
836 **/
837 Q_INVOKABLE void requestToggleFullScreen(const QModelIndex &index) override;
838
839 /**
840 * Request toggling the shaded state of the task at the given index.
841 *
842 * This is meant for tasks that have an associated window, and may be
843 * a no-op when there is no window.
844 *
845 * @param index An index in this tasks model.
846 **/
847 Q_INVOKABLE void requestToggleShaded(const QModelIndex &index) override;
848
849 /**
850 * Request entering the window at the given index on the specified virtual desktops.
851 *
852 * On Wayland, virtual desktop ids are QStrings. On X11, they are uint >0.
853 *
854 * An empty list has a special meaning: The window is entered on all virtual desktops
855 * in the session.
856 *
857 * On X11, a window can only be on one or all virtual desktops. Therefore, only the
858 * first list entry is actually used.
859 *
860 * On X11, the id 0 has a special meaning: The window is entered on all virtual
861 * desktops in the session.
862 *
863 * @param index An index in this window tasks model.
864 * @param desktops A list of virtual desktop ids.
865 **/
866 Q_INVOKABLE void requestVirtualDesktops(const QModelIndex &index, const QVariantList &desktops) override;
867
868 /**
869 * Request entering the window at the given index on a new virtual desktop,
870 * which is created in response to this request.
871 *
872 * @param index An index in this window tasks model.
873 **/
874 Q_INVOKABLE void requestNewVirtualDesktop(const QModelIndex &index) override;
875
876 /**
877 * Request moving the task at the given index to the specified activities.
878 *
879 * This is meant for tasks that have an associated window, and may be
880 * a no-op when there is no window.
881 *
882 * This base implementation does nothing.
883 *
884 * @param index An index in this tasks model.
885 * @param activities The new list of activities.
886 **/
887 Q_INVOKABLE void requestActivities(const QModelIndex &index, const QStringList &activities) override;
888
889 /**
890 * Request informing the window manager of new geometry for a visual
891 * delegate for the task at the given index. The geometry should be in
892 * screen coordinates.
893 *
894 * If the task at the given index is a group parent, the geometry is
895 * set for all of its children. If the task at the given index is a
896 * group member, the geometry is set for all of its siblings.
897 *
898 * @param index An index in this tasks model.
899 * @param geometry Visual delegate geometry in screen coordinates.
900 * @param delegate The delegate. Implementations are on their own with
901 * regard to extracting information from this, and should take care to
902 * reject invalid objects.
903 **/
904 Q_INVOKABLE void requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate = nullptr) override;
905
906 /**
907 * Request toggling whether the task at the given index, along with any
908 * tasks matching its kind, should be grouped or not. Task groups will be
909 * formed or broken apart as needed, along with affecting future grouping
910 * decisions as new tasks appear.
911 *
912 * As grouping is toggled for a task, updates are made to the
913 * grouping*Blacklist properties of the model instance.
914 *
915 * @see groupingAppIdBlacklist
916 * @see groupingLauncherUrlBlacklist
917 *
918 * @param index An index in this tasks model.
919 **/
920 Q_INVOKABLE void requestToggleGrouping(const QModelIndex &index);
921
922 /**
923 * Moves a task to a new position in the list. The insert position is
924 * is bounded to the list start and end.
925 *
926 * syncLaunchers() should be called after a set of move operations to
927 * update the launcherList property to reflect the new order.
928 *
929 * When the groupInline property is set to @c true, a move request
930 * for a group member will bring all siblings along.
931 *
932 * @see syncLaunchers
933 * @see launcherList
934 * @see setGroupInline
935 * @param index An index in this tasks model.
936 * @param newPos The new list position to move the task to.
937 */
938 Q_INVOKABLE bool move(int row, int newPos, const QModelIndex &parent = QModelIndex());
939
940 /**
941 * Updates the launcher list to reflect the new order after calls to
942 * move(), if needed.
943 *
944 * @see move
945 * @see launcherList
946 */
947 Q_INVOKABLE void syncLaunchers();
948
949 /**
950 * Given a row in the model, returns a QModelIndex for it. To get an index
951 * for a child in a task group, an optional child row may be passed as well.
952 *
953 * This easier to use from Qt Quick views than QAbstractItemModel::index is.
954 *
955 * @param row A row index in the model.
956 * @param childRow A row index for a child of the task group at the given row.
957 * @returns a model index for the task at the given row, or for one of its
958 * child tasks.
959 */
960 Q_INVOKABLE QModelIndex makeModelIndex(int row, int childRow = -1) const;
961
962 /**
963 * Given a row in the model, returns a QPersistentModelIndex for it. To get an index
964 * for a child in a task group, an optional child row may be passed as well.
965 *
966 * @param row A row index in the model.
967 * @param childRow A row index for a child of the task group at the given row.
968 * @returns a model index for the task at the given row, or for one of its
969 * child tasks.
970 */
971 Q_INVOKABLE QPersistentModelIndex makePersistentModelIndex(int row, int childRow = -1) const;
972
973 void classBegin() override;
974 void componentComplete() override;
975
976Q_SIGNALS:
977 void countChanged() const;
978 void launcherCountChanged() const;
979 void launcherListChanged() const;
980 void anyTaskDemandsAttentionChanged() const;
981 void virtualDesktopChanged() const;
982 void screenGeometryChanged() const;
983 void regionGeometryChanged();
984 void activityChanged() const;
985 void filterByVirtualDesktopChanged() const;
986 void filterByScreenChanged() const;
987 void filterByActivityChanged() const;
988 void filterByRegionChanged();
989 void filterMinimizedChanged();
990 void filterNotMinimizedChanged() const;
991 void filterNotMaximizedChanged() const;
992 void filterHiddenChanged() const;
993 void sortModeChanged() const;
994 void separateLaunchersChanged() const;
995 void launchInPlaceChanged() const;
996 void hideActivatedLaunchersChanged() const;
997 void groupModeChanged() const;
998 void groupInlineChanged() const;
999 void groupingWindowTasksThresholdChanged() const;
1000 void groupingAppIdBlacklistChanged() const;
1001 void groupingLauncherUrlBlacklistChanged() const;
1002 void taskReorderingEnabledChanged() const;
1003 void activeTaskChanged() const;
1004
1005protected:
1006 bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
1007 bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
1008
1009 /**
1010 * @return a shared pointer to VirtualDesktopInfo to access virtual desktop information
1011 */
1012 std::shared_ptr<VirtualDesktopInfo> virtualDesktopInfo() const;
1013
1014 /**
1015 * @return a shared pointer to ActivityInfo to access activity information
1016 */
1017 std::shared_ptr<ActivityInfo> activityInfo() const;
1018
1019private:
1020 Q_INVOKABLE void updateLauncherCount();
1021
1022 class Private;
1023 class TasksModelLessThan;
1024 friend class TasksModelLessThan;
1025 std::unique_ptr<Private> d;
1026};
1027
1028}
Pure virtual method interface for tasks model implementations.
A unified tasks model.
Definition tasksmodel.h:48
@ GroupApplications
Tasks are grouped by the application backing them.
Definition tasksmodel.h:102
@ SortLastActivated
Tasks are sorted by the last time they were active.
Definition tasksmodel.h:96
@ SortManual
Tasks can be moved with move() and syncLaunchers().
Definition tasksmodel.h:92
@ SortActivity
Tasks are sorted by the number of tasks on the activities they're on.
Definition tasksmodel.h:95
@ SortAlpha
Tasks are sorted alphabetically, by AbstractTasksModel::AppName and Qt::DisplayRole.
Definition tasksmodel.h:93
@ SortVirtualDesktop
Tasks are sorted by the virtual desktop they are on.
Definition tasksmodel.h:94
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:19:56 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.