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

KDE's Doxygen guidelines are available online.