File indexing completed on 2024-05-05 05:38:36

0001 /*
0002     SPDX-FileCopyrightText: 2016 Eike Hein <hein@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QQmlParserStatus>
0010 #include <QSortFilterProxyModel>
0011 
0012 #include <memory>
0013 
0014 #include "abstracttasksmodeliface.h"
0015 #include "regionfiltermode.h"
0016 
0017 #include "taskmanager_export.h"
0018 
0019 namespace TaskManager
0020 {
0021 class ActivityInfo;
0022 class VirtualDesktopInfo;
0023 
0024 /**
0025  * @short A unified tasks model.
0026  *
0027  * This model presents tasks sourced from supplied launcher URLs, startup
0028  * notification data and window data retrieved from the windowing server
0029  * the host process is connected to. The underlying windowing system is
0030  * abstracted away.
0031  *
0032  * The source data is abstracted into a unified lifecycle for tasks
0033  * suitable for presentation in a user interface.
0034  *
0035  * Matching startup and window tasks replace launcher tasks. Startup
0036  * tasks are omitted when matching window tasks exist. Tasks that desire
0037  * not to be shown in a user interface are omitted.
0038  *
0039  * Tasks may be filtered, sorted or grouped by setting properties on the
0040  * model.
0041  *
0042  * Tasks may be interacted with by calling methods on the model.
0043  *
0044  * @author Eike Hein <hein@kde.org>
0045  **/
0046 
0047 class TASKMANAGER_EXPORT TasksModel : public QSortFilterProxyModel, public AbstractTasksModelIface, public QQmlParserStatus
0048 {
0049     Q_OBJECT
0050     Q_INTERFACES(QQmlParserStatus)
0051 
0052     Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
0053     Q_PROPERTY(int launcherCount READ launcherCount NOTIFY launcherCountChanged)
0054 
0055     Q_PROPERTY(QStringList launcherList READ launcherList WRITE setLauncherList NOTIFY launcherListChanged)
0056 
0057     Q_PROPERTY(bool anyTaskDemandsAttention READ anyTaskDemandsAttention NOTIFY anyTaskDemandsAttentionChanged)
0058 
0059     Q_PROPERTY(QVariant virtualDesktop READ virtualDesktop WRITE setVirtualDesktop NOTIFY virtualDesktopChanged)
0060     Q_PROPERTY(QRect screenGeometry READ screenGeometry WRITE setScreenGeometry NOTIFY screenGeometryChanged)
0061     Q_PROPERTY(QRect regionGeometry READ regionGeometry WRITE setRegionGeometry NOTIFY regionGeometryChanged)
0062     Q_PROPERTY(QString activity READ activity WRITE setActivity NOTIFY activityChanged)
0063 
0064     Q_PROPERTY(bool filterByVirtualDesktop READ filterByVirtualDesktop WRITE setFilterByVirtualDesktop NOTIFY filterByVirtualDesktopChanged)
0065     Q_PROPERTY(bool filterByScreen READ filterByScreen WRITE setFilterByScreen NOTIFY filterByScreenChanged)
0066     Q_PROPERTY(bool filterByActivity READ filterByActivity WRITE setFilterByActivity NOTIFY filterByActivityChanged)
0067     Q_PROPERTY(RegionFilterMode::Mode filterByRegion READ filterByRegion WRITE setFilterByRegion NOTIFY filterByRegionChanged)
0068     Q_PROPERTY(bool filterMinimized READ filterMinimized WRITE setFilterMinimized NOTIFY filterMinimizedChanged)
0069     Q_PROPERTY(bool filterNotMinimized READ filterNotMinimized WRITE setFilterNotMinimized NOTIFY filterNotMinimizedChanged)
0070     Q_PROPERTY(bool filterNotMaximized READ filterNotMaximized WRITE setFilterNotMaximized NOTIFY filterNotMaximizedChanged)
0071     Q_PROPERTY(bool filterHidden READ filterHidden WRITE setFilterHidden NOTIFY filterHiddenChanged)
0072 
0073     Q_PROPERTY(SortMode sortMode READ sortMode WRITE setSortMode NOTIFY sortModeChanged)
0074     Q_PROPERTY(bool separateLaunchers READ separateLaunchers WRITE setSeparateLaunchers NOTIFY separateLaunchersChanged)
0075     Q_PROPERTY(bool launchInPlace READ launchInPlace WRITE setLaunchInPlace NOTIFY launchInPlaceChanged)
0076     Q_PROPERTY(bool hideActivatedLaunchers READ hideActivatedLaunchers WRITE setHideActivatedLaunchers NOTIFY hideActivatedLaunchersChanged)
0077 
0078     Q_PROPERTY(GroupMode groupMode READ groupMode WRITE setGroupMode NOTIFY groupModeChanged)
0079     Q_PROPERTY(bool groupInline READ groupInline WRITE setGroupInline NOTIFY groupInlineChanged)
0080     Q_PROPERTY(
0081         int groupingWindowTasksThreshold READ groupingWindowTasksThreshold WRITE setGroupingWindowTasksThreshold NOTIFY groupingWindowTasksThresholdChanged)
0082     Q_PROPERTY(QStringList groupingAppIdBlacklist READ groupingAppIdBlacklist WRITE setGroupingAppIdBlacklist NOTIFY groupingAppIdBlacklistChanged)
0083     Q_PROPERTY(QStringList groupingLauncherUrlBlacklist READ groupingLauncherUrlBlacklist WRITE setGroupingLauncherUrlBlacklist NOTIFY
0084                    groupingLauncherUrlBlacklistChanged)
0085     Q_PROPERTY(bool taskReorderingEnabled READ taskReorderingEnabled WRITE setTaskReorderingEnabled NOTIFY taskReorderingEnabledChanged)
0086     Q_PROPERTY(QModelIndex activeTask READ activeTask NOTIFY activeTaskChanged)
0087 
0088 public:
0089     enum SortMode {
0090         SortDisabled = 0, /**< No sorting is done. */
0091         SortManual, /**< Tasks can be moved with move() and syncLaunchers(). */
0092         SortAlpha, /**< Tasks are sorted alphabetically, by AbstractTasksModel::AppName and Qt::DisplayRole. */
0093         SortVirtualDesktop, /**< Tasks are sorted by the virtual desktop they are on. */
0094         SortActivity, /**< Tasks are sorted by the number of tasks on the activities they're on. */
0095         SortLastActivated, /**< Tasks are sorted by the last time they were active. */
0096     };
0097     Q_ENUM(SortMode)
0098 
0099     enum GroupMode {
0100         GroupDisabled = 0, /**< No grouping is done. */
0101         GroupApplications, /**< Tasks are grouped by the application backing them. */
0102     };
0103     Q_ENUM(GroupMode)
0104 
0105     explicit TasksModel(QObject *parent = nullptr);
0106     ~TasksModel() override;
0107 
0108     QHash<int, QByteArray> roleNames() const override;
0109 
0110     Q_INVOKABLE int rowCount(const QModelIndex &parent = QModelIndex()) const override; // Invokable.
0111 
0112     QVariant data(const QModelIndex &proxyIndex, int role) const override;
0113 
0114     /**
0115      * The number of launcher tasks in the tast list.
0116      *
0117      * @returns the number of launcher tasks in the task list.
0118      **/
0119     int launcherCount() const;
0120 
0121     /**
0122      * The list of launcher URLs serialized to strings along with
0123      * the activities they belong to.
0124      *
0125      * @see setLauncherList
0126      * @returns the list of launcher URLs serialized to strings.
0127      **/
0128     QStringList launcherList() const;
0129 
0130     /**
0131      * Replace the list of launcher URL strings.
0132      *
0133      * Invalid or empty URLs will be rejected. Duplicate URLs will be
0134      * collapsed.
0135      *
0136      * @see launcherList
0137      * @param launchers A list of launcher URL strings.
0138      **/
0139     void setLauncherList(const QStringList &launchers);
0140 
0141     /**
0142      * Returns whether any task in the model currently demands attention
0143      * (AbstractTasksModel::IsDemandingAttention).
0144      *
0145      * @returns whether any task in the model currently demands attention.
0146      **/
0147     bool anyTaskDemandsAttention() const;
0148 
0149     /**
0150      * The id of the virtual desktop used in filtering by virtual
0151      * desktop. Usually set to the id of the current virtual desktop.
0152      * Defaults to empty.
0153      *
0154      * @see setVirtualDesktop
0155      * @returns the number of the virtual desktop used in filtering.
0156      **/
0157     QVariant virtualDesktop() const;
0158 
0159     /**
0160      * Set the id of the virtual desktop to use in filtering by virtual
0161      * desktop.
0162      *
0163      * If set to an empty id, filtering by virtual desktop is disabled.
0164      *
0165      * @see virtualDesktop
0166      * @param desktop A virtual desktop id (QString on Wayland; uint >0 on X11).
0167      **/
0168     void setVirtualDesktop(const QVariant &desktop = QVariant());
0169 
0170     /**
0171      * The geometry of the screen used in filtering by screen. Defaults
0172      * to a null QRect.
0173      *
0174      * @see setGeometryScreen
0175      * @returns the geometry of the screen used in filtering.
0176      **/
0177     QRect screenGeometry() const;
0178 
0179     /**
0180      * Set the geometry of the screen to use in filtering by screen.
0181      *
0182      * If set to an invalid QRect, filtering by screen is disabled.
0183      *
0184      * @see screenGeometry
0185      * @param geometry A screen geometry.
0186      **/
0187     void setScreenGeometry(const QRect &geometry);
0188 
0189     /**
0190      * The geometry of the region used in filtering by region. Defaults
0191      * to a null QRect.
0192      *
0193      * @see setRegionGeometry
0194      * @since 6.0
0195      * @returns the geometry of the region used in filtering.
0196      **/
0197     QRect regionGeometry() const;
0198 
0199     /**
0200      * Set the geometry of the screen to use in filtering by region.
0201      *
0202      * If set to an invalid QRect, filtering by region is disabled.
0203      *
0204      * @see regionGeometry
0205      * @since 6.0
0206      * @param geometry A region geometry.
0207      **/
0208     void setRegionGeometry(const QRect &geometry);
0209 
0210     /**
0211      * The id of the activity used in filtering by activity. Usually
0212      * set to the id of the current activity. Defaults to an empty id.
0213      *
0214      * @see setActivity
0215      * @returns the id of the activity used in filtering.
0216      **/
0217     QString activity() const;
0218 
0219     /**
0220      * Set the id of the activity to use in filtering by activity.
0221      *
0222      * @see activity
0223      * @param activity An activity id.
0224      **/
0225     void setActivity(const QString &activity);
0226 
0227     /**
0228      * Whether tasks should be filtered by virtual desktop. Defaults to
0229      * @c false.
0230      *
0231      * Filtering by virtual desktop only happens if a virtual desktop
0232      * number is set, even if this returns @c true.
0233      *
0234      * @see setFilterByVirtualDesktop
0235      * @see setVirtualDesktop
0236      * @returns @c true if tasks should be filtered by virtual desktop.
0237      **/
0238     bool filterByVirtualDesktop() const;
0239 
0240     /**
0241      * Set whether tasks should be filtered by virtual desktop.
0242      *
0243      * Filtering by virtual desktop only happens if a virtual desktop
0244      * number is set, even if this is set to @c true.
0245      *
0246      * @see filterByVirtualDesktop
0247      * @see setVirtualDesktop
0248      * @param filter Whether tasks should be filtered by virtual desktop.
0249      **/
0250     void setFilterByVirtualDesktop(bool filter);
0251 
0252     /**
0253      * Whether tasks should be filtered by screen. Defaults to @c false.
0254      *
0255      * Filtering by screen only happens if a screen number is set, even
0256      * if this returns @c true.
0257      *
0258      * @see setFilterByScreen
0259      * @see setScreenGeometry
0260      * @returns @c true if tasks should be filtered by screen.
0261      **/
0262     bool filterByScreen() const;
0263 
0264     /**
0265      * Set whether tasks should be filtered by screen.
0266      *
0267      * Filtering by screen only happens if a screen number is set, even
0268      * if this is set to @c true.
0269      *
0270      * @see filterByScreen
0271      * @see setScreenGeometry
0272      * @param filter Whether tasks should be filtered by screen.
0273      **/
0274     void setFilterByScreen(bool filter);
0275 
0276     /**
0277      * Whether tasks should be filtered by activity. Defaults to @c false.
0278      *
0279      * Filtering by activity only happens if an activity id is set, even
0280      * if this returns @c true.
0281      *
0282      * @see setFilterByActivity
0283      * @see setActivity
0284      * @returns @c true if tasks should be filtered by activity.
0285      **/
0286     bool filterByActivity() const;
0287 
0288     /**
0289      * Set whether tasks should be filtered by activity. Defaults to
0290      * @c false.
0291      *
0292      * Filtering by activity only happens if an activity id is set,
0293      * even if this is set to @c true.
0294      *
0295      * @see filterByActivity
0296      * @see setActivity
0297      * @param filter Whether tasks should be filtered by activity.
0298      **/
0299     void setFilterByActivity(bool filter);
0300 
0301     /**
0302      * Whether tasks should be filtered by region. Defaults to @c RegionFilterMode::Disabled.
0303      *
0304      * Filtering by region only happens if a region is set, even
0305      * if the filter is enabled.
0306      *
0307      * @see RegionFilterMode
0308      * @see setFilterByRegion
0309      * @see setRegionGeometry
0310      * @since 6.0
0311      * @returns Region filter mode.
0312      **/
0313     RegionFilterMode::Mode filterByRegion() const;
0314 
0315     /**
0316      * Set whether tasks should be filtered by region. Defaults to
0317      * @c RegionFilterMode::Disabled.
0318      *
0319      * Filtering by region only happens if a region is set,
0320      * even if the filter is enabled.
0321      *
0322      * @see RegionFilterMode
0323      * @see filterByRegion
0324      * @see setRegionGeometry
0325      * @since 6.0
0326      * @param mode Region filter mode.
0327      **/
0328     void setFilterByRegion(RegionFilterMode::Mode mode);
0329 
0330     /**
0331      * Whether minimized tasks should be filtered out. Defaults to
0332      * @c false.
0333      *
0334      * @returns @c true if minimized tasks should be filtered out.
0335      * @see setFilterMinimized
0336      * @since 5.27
0337      **/
0338     bool filterMinimized() const;
0339 
0340     /**
0341      * Sets whether non-minimized tasks should be filtered out.
0342      *
0343      * @param filter Whether minimized tasks should be filtered out.
0344      * @see filterMinimized
0345      * @since 5.27
0346      **/
0347     void setFilterMinimized(bool filter);
0348 
0349     /**
0350      * Whether non-minimized tasks should be filtered. Defaults to
0351      * @c false.
0352      *
0353      * @see setFilterNotMinimized
0354      * @returns @c true if non-minimized tasks should be filtered.
0355      **/
0356     bool filterNotMinimized() const;
0357 
0358     /**
0359      * Set whether non-minimized tasks should be filtered.
0360      *
0361      * @see filterNotMinimized
0362      * @param filter Whether non-minimized tasks should be filtered.
0363      **/
0364     void setFilterNotMinimized(bool filter);
0365 
0366     /**
0367      * Whether non-maximized tasks should be filtered. Defaults to
0368      * @c false.
0369      *
0370      * @see setFilterNotMaximized
0371      * @returns @c true if non-maximized tasks should be filtered.
0372      **/
0373     bool filterNotMaximized() const;
0374 
0375     /**
0376      * Set whether non-maximized tasks should be filtered.
0377      *
0378      * @see filterNotMaximized
0379      * @param filter Whether non-maximized tasks should be filtered.
0380      **/
0381     void setFilterNotMaximized(bool filter);
0382 
0383     /**
0384      * Whether hidden tasks should be filtered. Defaults to
0385      * @c false.
0386      *
0387      * @see setFilterHidden
0388      * @returns @c true if hidden tasks should be filtered.
0389      **/
0390     bool filterHidden() const;
0391 
0392     /**
0393      * Set whether hidden tasks should be filtered.
0394      *
0395      * @see filterHidden
0396      * @param filter Whether hidden tasks should be filtered.
0397      **/
0398     void setFilterHidden(bool filter);
0399 
0400     /**
0401      * The sort mode used in sorting tasks. Defaults to SortAlpha.
0402      *
0403      * @see setSortMode
0404      * @returns the current sort mode.
0405      **/
0406     SortMode sortMode() const;
0407 
0408     /**
0409      * Sets the sort mode used in sorting tasks.
0410      *
0411      * @see sortMode
0412      * @param mode A sort mode.
0413      **/
0414     void setSortMode(SortMode mode);
0415 
0416     /**
0417      * Whether launchers are kept separate from other kinds of tasks.
0418      * Defaults to @c true.
0419      *
0420      * When enabled, launcher tasks are sorted first in the tasks model
0421      * and move() disallows moving them below the last launcher task,
0422      * or moving a different kind of task above the first launcher. New
0423      * launcher tasks are inserted after the last launcher task. When
0424      * disabled, move() allows mixing, and new launcher tasks are
0425      * appended to the model.
0426      *
0427      * Further, when disabled, the model always behaves as if
0428      * launchInPlace is enabled: A window task takes the place of the
0429      * first matching launcher task.
0430      *
0431      * @see LauncherTasksModel
0432      * @see move
0433      * @see launchInPlace
0434      * @see setSeparateLaunchers
0435      * @return whether launcher tasks are kept separate.
0436      */
0437     bool separateLaunchers() const;
0438 
0439     /**
0440      * Sets whether launchers are kept separate from other kinds of tasks.
0441      *
0442      * When enabled, launcher tasks are sorted first in the tasks model
0443      * and move() disallows moving them below the last launcher task,
0444      * or moving a different kind of task above the first launcher. New
0445      * launcher tasks are inserted after the last launcher task. When
0446      * disabled, move() allows mixing, and new launcher tasks are
0447      * appended to the model.
0448      *
0449      * Further, when disabled, the model always behaves as if
0450      * launchInPlace is enabled: A window task takes the place of the
0451      * first matching launcher task.
0452      *
0453      * @see LauncherTasksModel
0454      * @see move
0455      * @see launchInPlace
0456      * @see separateLaunchers
0457      * @param separate Whether to keep launcher tasks separate.
0458      */
0459     void setSeparateLaunchers(bool separate);
0460 
0461     /**
0462      * Whether window tasks should be sorted as their associated launcher
0463      * tasks or separately. Defaults to @c false.
0464      *
0465      * @see setLaunchInPlace
0466      * @returns whether window tasks should be sorted as their associated
0467      * launcher tasks.
0468      **/
0469     bool launchInPlace() const;
0470 
0471     /**
0472      * Sets whether window tasks should be sorted as their associated launcher
0473      * tasks or separately.
0474      *
0475      * @see launchInPlace
0476      * @param launchInPlace Whether window tasks should be sorted as their
0477      * associated launcher tasks.
0478      **/
0479     void setLaunchInPlace(bool launchInPlace);
0480 
0481     /**
0482      * Whether launchers should be hidden after they have been
0483      * activated. Defaults to @c true.
0484      *
0485      * @see hideActivatedLaunchers
0486      * @returns whether launchers will be hidden after they have been
0487      * activated.
0488      **/
0489     bool hideActivatedLaunchers() const;
0490 
0491     /**
0492      * Sets whether launchers should be hidden after they have been
0493      * activated. Defaults to @c true.
0494      *
0495      * @see hideActivatedLaunchers
0496      * @param hideActivatedLaunchers Whether launchers should be hidden
0497      * after they have been activated.
0498      **/
0499     void setHideActivatedLaunchers(bool hideActivatedLaunchers);
0500 
0501     /**
0502      * Returns the current group mode, i.e. the criteria by which tasks should
0503      * be grouped.
0504      *
0505      * Defaults to TasksModel::GroupApplication, which groups tasks backed by
0506      * the same application.
0507      *
0508      * If the group mode is TasksModel::GroupDisabled, no grouping is done.
0509      *
0510      * @see setGroupMode
0511      * @returns the current group mode.
0512      **/
0513     TasksModel::GroupMode groupMode() const;
0514 
0515     /**
0516      * Sets the group mode, i.e. the criteria by which tasks should be grouped.
0517      *
0518      * The group mode can be set to TasksModel::GroupDisabled to disable grouping
0519      * entirely, breaking apart any existing groups.
0520      *
0521      * @see groupMode
0522      * @param mode A group mode.
0523      **/
0524     void setGroupMode(TasksModel::GroupMode mode);
0525 
0526     /**
0527      * Returns whether grouping is done "inline" or not, i.e. whether groups
0528      * are maintained inside the flat, top-level list, or by forming a tree.
0529      * In inline grouping mode, move() on a group member will move all siblings
0530      * as well, and sorting is first done among groups, then group members.
0531      *
0532      * Further, in inline grouping mode, the groupingWindowTasksThreshold
0533      * setting is ignored: Grouping is always done.
0534      *
0535      * @see setGroupInline
0536      * @see move
0537      * @see groupingWindowTasksThreshold
0538      * @returns whether grouping is done inline or not.
0539      **/
0540     bool groupInline() const;
0541 
0542     /**
0543      * Sets whether grouping is done "inline" or not, i.e. whether groups
0544      * are maintained inside the flat, top-level list, or by forming a tree.
0545      * In inline grouping mode, move() on a group member will move all siblings
0546      * as well, and sorting is first done among groups, then group members.
0547      *
0548      * @see groupInline
0549      * @see move
0550      * @see groupingWindowTasksThreshold
0551      * @param inline Whether to do grouping inline or not.
0552      **/
0553     void setGroupInline(bool groupInline);
0554 
0555     /**
0556      * As window tasks (AbstractTasksModel::IsWindow) come and go, groups will
0557      * be formed when this threshold value is exceeded, and  broken apart when
0558      * it matches or falls below.
0559      *
0560      * Defaults to @c -1, which means grouping is done regardless of the number
0561      * of window tasks.
0562      *
0563      * When the groupInline property is set to @c true, the threshold is ignored:
0564      * Grouping is always done.
0565      *
0566      * @see setGroupingWindowTasksThreshold
0567      * @see groupInline
0568      * @return the threshold number of window tasks used in grouping decisions.
0569      **/
0570     int groupingWindowTasksThreshold() const;
0571 
0572     /**
0573      * Sets the number of window tasks (AbstractTasksModel::IsWindow) above which
0574      * groups will be formed, and at or below which groups will be broken apart.
0575      *
0576      * If set to -1, grouping will be done regardless of the number of window tasks
0577      * in the source model.
0578      *
0579      * When the groupInline property is set to @c true, the threshold is ignored:
0580      * Grouping is always done.
0581      *
0582      * @see groupingWindowTasksThreshold
0583      * @see groupInline
0584      * @param threshold A threshold number of window tasks used in grouping
0585      * decisions.
0586      **/
0587     void setGroupingWindowTasksThreshold(int threshold);
0588 
0589     /**
0590      * A blacklist of app ids (AbstractTasksModel::AppId) that is consulted before
0591      * grouping a task. If a task's app id is found on the blacklist, it is not
0592      * grouped.
0593      *
0594      * The default app id blacklist is empty.
0595      *
0596      * @see setGroupingAppIdBlacklist
0597      * @returns the blacklist of app ids consulted before grouping a task.
0598      **/
0599     QStringList groupingAppIdBlacklist() const;
0600 
0601     /**
0602      * Sets the blacklist of app ids (AbstractTasksModel::AppId) that is consulted
0603      * before grouping a task. If a task's app id is found on the blacklist, it is
0604      * not grouped.
0605      *
0606      * When set, groups will be formed and broken apart as necessary.
0607      *
0608      * @see groupingAppIdBlacklist
0609      * @param list a blacklist of app ids to be consulted before grouping a task.
0610      **/
0611     void setGroupingAppIdBlacklist(const QStringList &list);
0612 
0613     /**
0614      * A blacklist of launcher URLs (AbstractTasksModel::LauncherUrl) that is
0615      * consulted before grouping a task. If a task's launcher URL is found on the
0616      * blacklist, it is not grouped.
0617      *
0618      * The default launcher URL blacklist is empty.
0619      *
0620      * @see setGroupingLauncherUrlBlacklist
0621      * @returns the blacklist of launcher URLs consulted before grouping a task.
0622      **/
0623     QStringList groupingLauncherUrlBlacklist() const;
0624 
0625     /**
0626      * Sets the blacklist of launcher URLs (AbstractTasksModel::LauncherUrl) that
0627      * is consulted before grouping a task. If a task's launcher URL is found on
0628      * the blacklist, it is not grouped.
0629      *
0630      * When set, groups will be formed and broken apart as necessary.
0631      *
0632      * @see groupingLauncherUrlBlacklist
0633      * @param list a blacklist of launcher URLs to be consulted before grouping a task.
0634      **/
0635     void setGroupingLauncherUrlBlacklist(const QStringList &list);
0636 
0637     /**
0638      * Enables or disables tasks reordering.
0639      *
0640      * @param enabled enables tasks reordering if @c true; disables it otherwise.
0641      */
0642     void setTaskReorderingEnabled(bool enabled);
0643 
0644     /**
0645      * Returns whether tasks reordering is enabled or not.
0646      *
0647      * @returns whether tasks reordering is enabled or not.
0648      */
0649     bool taskReorderingEnabled() const;
0650 
0651     /**
0652      * Finds the first active (AbstractTasksModel::IsActive) task in the model
0653      * and returns its QModelIndex, or a null QModelIndex if no active task is
0654      * found.
0655      *
0656      * @returns the model index for the first active task, if any.
0657      */
0658     QModelIndex activeTask() const;
0659 
0660     /**
0661      * Request adding a launcher with the given URL.
0662      *
0663      * If this URL is already in the list, the request will fail. URLs are
0664      * compared for equality after removing the query string used to hold
0665      * metadata.
0666      *
0667      * @see launcherUrlsMatch
0668      * @param url A launcher URL.
0669      * @returns @c true if a launcher was added.
0670      */
0671     Q_INVOKABLE bool requestAddLauncher(const QUrl &url);
0672 
0673     /**
0674      * Request removing the launcher with the given URL.
0675      *
0676      * If this URL is already in the list, the request will fail. URLs are
0677      * compared for equality after removing the query string used to hold
0678      * metadata.
0679      *
0680      * @see launcherUrlsMatch
0681      * @param url A launcher URL.
0682      * @returns @c true if the launcher was removed.
0683      */
0684     Q_INVOKABLE bool requestRemoveLauncher(const QUrl &url);
0685 
0686     /**
0687      * Request adding a launcher with the given URL to current activity.
0688      *
0689      * If this URL is already in the list, the request will fail. URLs are
0690      * compared for equality after removing the query string used to hold
0691      * metadata.
0692      *
0693      * @see launcherUrlsMatch
0694      * @param url A launcher URL.
0695      * @returns @c true if a launcher was added.
0696      */
0697     Q_INVOKABLE bool requestAddLauncherToActivity(const QUrl &url, const QString &activity);
0698 
0699     /**
0700      * Request removing the launcher with the given URL from the current activity.
0701      *
0702      * If this URL is already in the list, the request will fail. URLs are
0703      * compared for equality after removing the query string used to hold
0704      * metadata.
0705      *
0706      * @see launcherUrlsMatch
0707      * @param url A launcher URL.
0708      * @returns @c true if the launcher was removed.
0709      */
0710     Q_INVOKABLE bool requestRemoveLauncherFromActivity(const QUrl &url, const QString &activity);
0711 
0712     /**
0713      * Return the list of activities the launcher belongs to.
0714      * If there is no launcher with that url, the list will be empty,
0715      * while if the launcher is on all activities, it will contain a
0716      * null uuid.
0717      *
0718      * URLs are compared for equality after removing the query string used
0719      * to hold metadata.
0720      */
0721     Q_INVOKABLE QStringList launcherActivities(const QUrl &url);
0722 
0723     /**
0724      * Return the position of the launcher with the given URL.
0725      *
0726      * URLs are compared for equality after removing the query string used
0727      * to hold metadata.
0728      *
0729      * @see launcherUrlsMatch
0730      * @param url A launcher URL.
0731      * @returns @c -1 if no launcher exists for the given URL.
0732      */
0733     Q_INVOKABLE int launcherPosition(const QUrl &url) const;
0734 
0735     /**
0736      * Request activation of the task at the given index. Derived classes are
0737      * free to interpret the meaning of "activate" themselves depending on
0738      * the nature and state of the task, e.g. launch or raise a window task.
0739      *
0740      * @param index An index in this tasks model.
0741      **/
0742     Q_INVOKABLE void requestActivate(const QModelIndex &index) override;
0743 
0744     /**
0745      * Request an additional instance of the application backing the task
0746      * at the given index.
0747      *
0748      * @param index An index in this tasks model.
0749      **/
0750     Q_INVOKABLE void requestNewInstance(const QModelIndex &index) override;
0751 
0752     /**
0753      * Requests to open the given URLs with the application backing the task
0754      * at the given index.
0755      *
0756      * @param index An index in this tasks model.
0757      * @param urls The URLs to be passed to the application.
0758      **/
0759     Q_INVOKABLE void requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls) override;
0760 
0761     /**
0762      * Request the task at the given index be closed.
0763      *
0764      * @param index An index in this tasks model.
0765      **/
0766     Q_INVOKABLE void requestClose(const QModelIndex &index) override;
0767 
0768     /**
0769      * Request starting an interactive move for the task at the given index.
0770      *
0771      * This is meant for tasks that have an associated window, and may be
0772      * a no-op when there is no window.
0773      *
0774      * @param index An index in this tasks model.
0775      **/
0776     Q_INVOKABLE void requestMove(const QModelIndex &index) override;
0777 
0778     /**
0779      * Request starting an interactive resize for the task at the given index.
0780      *
0781      * This is meant for tasks that have an associated window, and may be a
0782      * no-op when there is no window.
0783      *
0784      * @param index An index in this tasks model.
0785      **/
0786     Q_INVOKABLE void requestResize(const QModelIndex &index) override;
0787 
0788     /**
0789      * Request toggling the minimized state of the task at the given index.
0790      *
0791      * This is meant for tasks that have an associated window, and may be
0792      * a no-op when there is no window.
0793      *
0794      * @param index An index in this tasks model.
0795      **/
0796     Q_INVOKABLE void requestToggleMinimized(const QModelIndex &index) override;
0797 
0798     /**
0799      * Request toggling the maximized state of the task at the given index.
0800      *
0801      * This is meant for tasks that have an associated window, and may be
0802      * a no-op when there is no window.
0803      *
0804      * @param index An index in this tasks model.
0805      **/
0806     Q_INVOKABLE void requestToggleMaximized(const QModelIndex &index) override;
0807 
0808     /**
0809      * Request toggling the keep-above state of the task at the given index.
0810      *
0811      * This is meant for tasks that have an associated window, and may be
0812      * a no-op when there is no window.
0813      *
0814      * @param index An index in this tasks model.
0815      **/
0816     Q_INVOKABLE void requestToggleKeepAbove(const QModelIndex &index) override;
0817 
0818     /**
0819      * Request toggling the keep-below state of the task at the given index.
0820      *
0821      * This is meant for tasks that have an associated window, and may be
0822      * a no-op when there is no window.
0823      *
0824      * @param index An index in this tasks model.
0825      **/
0826     Q_INVOKABLE void requestToggleKeepBelow(const QModelIndex &index) override;
0827 
0828     /**
0829      * Request toggling the fullscreen state of the task at the given index.
0830      *
0831      * This is meant for tasks that have an associated window, and may be
0832      * a no-op when there is no window.
0833      *
0834      * @param index An index in this tasks model.
0835      **/
0836     Q_INVOKABLE void requestToggleFullScreen(const QModelIndex &index) override;
0837 
0838     /**
0839      * Request toggling the shaded state of the task at the given index.
0840      *
0841      * This is meant for tasks that have an associated window, and may be
0842      * a no-op when there is no window.
0843      *
0844      * @param index An index in this tasks model.
0845      **/
0846     Q_INVOKABLE void requestToggleShaded(const QModelIndex &index) override;
0847 
0848     /**
0849      * Request entering the window at the given index on the specified virtual desktops.
0850      *
0851      * On Wayland, virtual desktop ids are QStrings. On X11, they are uint >0.
0852      *
0853      * An empty list has a special meaning: The window is entered on all virtual desktops
0854      * in the session.
0855      *
0856      * On X11, a window can only be on one or all virtual desktops. Therefore, only the
0857      * first list entry is actually used.
0858      *
0859      * On X11, the id 0 has a special meaning: The window is entered on all virtual
0860      * desktops in the session.
0861      *
0862      * @param index An index in this window tasks model.
0863      * @param desktops A list of virtual desktop ids.
0864      **/
0865     Q_INVOKABLE void requestVirtualDesktops(const QModelIndex &index, const QVariantList &desktops) override;
0866 
0867     /**
0868      * Request entering the window at the given index on a new virtual desktop,
0869      * which is created in response to this request.
0870      *
0871      * @param index An index in this window tasks model.
0872      **/
0873     Q_INVOKABLE void requestNewVirtualDesktop(const QModelIndex &index) override;
0874 
0875     /**
0876      * Request moving the task at the given index to the specified activities.
0877      *
0878      * This is meant for tasks that have an associated window, and may be
0879      * a no-op when there is no window.
0880      *
0881      * This base implementation does nothing.
0882      *
0883      * @param index An index in this tasks model.
0884      * @param activities The new list of activities.
0885      **/
0886     Q_INVOKABLE void requestActivities(const QModelIndex &index, const QStringList &activities) override;
0887 
0888     /**
0889      * Request informing the window manager of new geometry for a visual
0890      * delegate for the task at the given index. The geometry should be in
0891      * screen coordinates.
0892      *
0893      * If the task at the given index is a group parent, the geometry is
0894      * set for all of its children. If the task at the given index is a
0895      * group member, the geometry is set for all of its siblings.
0896      *
0897      * @param index An index in this tasks model.
0898      * @param geometry Visual delegate geometry in screen coordinates.
0899      * @param delegate The delegate. Implementations are on their own with
0900      * regard to extracting information from this, and should take care to
0901      * reject invalid objects.
0902      **/
0903     Q_INVOKABLE void requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate = nullptr) override;
0904 
0905     /**
0906      * Request toggling whether the task at the given index, along with any
0907      * tasks matching its kind, should be grouped or not. Task groups will be
0908      * formed or broken apart as needed, along with affecting future grouping
0909      * decisions as new tasks appear.
0910      *
0911      * As grouping is toggled for a task, updates are made to the
0912      * grouping*Blacklist properties of the model instance.
0913      *
0914      * @see groupingAppIdBlacklist
0915      * @see groupingLauncherUrlBlacklist
0916      *
0917      * @param index An index in this tasks model.
0918      **/
0919     Q_INVOKABLE void requestToggleGrouping(const QModelIndex &index);
0920 
0921     /**
0922      * Moves a task to a new position in the list. The insert position is
0923      * is bounded to the list start and end.
0924      *
0925      * syncLaunchers() should be called after a set of move operations to
0926      * update the launcherList property to reflect the new order.
0927      *
0928      * When the groupInline property is set to @c true, a move request
0929      * for a group member will bring all siblings along.
0930      *
0931      * @see syncLaunchers
0932      * @see launcherList
0933      * @see setGroupInline
0934      * @param index An index in this tasks model.
0935      * @param newPos The new list position to move the task to.
0936      */
0937     Q_INVOKABLE bool move(int row, int newPos, const QModelIndex &parent = QModelIndex());
0938 
0939     /**
0940      * Updates the launcher list to reflect the new order after calls to
0941      * move(), if needed.
0942      *
0943      * @see move
0944      * @see launcherList
0945      */
0946     Q_INVOKABLE void syncLaunchers();
0947 
0948     /**
0949      * Given a row in the model, returns a QModelIndex for it. To get an index
0950      * for a child in a task group, an optional child row may be passed as well.
0951      *
0952      * This easier to use from Qt Quick views than QAbstractItemModel::index is.
0953      *
0954      * @param row A row index in the model.
0955      * @param childRow A row index for a child of the task group at the given row.
0956      * @returns a model index for the task at the given row, or for one of its
0957      * child tasks.
0958      */
0959     Q_INVOKABLE QModelIndex makeModelIndex(int row, int childRow = -1) const;
0960 
0961     /**
0962      * Given a row in the model, returns a QPersistentModelIndex for it. To get an index
0963      * for a child in a task group, an optional child row may be passed as well.
0964      *
0965      * @param row A row index in the model.
0966      * @param childRow A row index for a child of the task group at the given row.
0967      * @returns a model index for the task at the given row, or for one of its
0968      * child tasks.
0969      */
0970     Q_INVOKABLE QPersistentModelIndex makePersistentModelIndex(int row, int childRow = -1) const;
0971 
0972     void classBegin() override;
0973     void componentComplete() override;
0974 
0975 Q_SIGNALS:
0976     void countChanged() const;
0977     void launcherCountChanged() const;
0978     void launcherListChanged() const;
0979     void anyTaskDemandsAttentionChanged() const;
0980     void virtualDesktopChanged() const;
0981     void screenGeometryChanged() const;
0982     void regionGeometryChanged();
0983     void activityChanged() const;
0984     void filterByVirtualDesktopChanged() const;
0985     void filterByScreenChanged() const;
0986     void filterByActivityChanged() const;
0987     void filterByRegionChanged();
0988     void filterMinimizedChanged();
0989     void filterNotMinimizedChanged() const;
0990     void filterNotMaximizedChanged() const;
0991     void filterHiddenChanged() const;
0992     void sortModeChanged() const;
0993     void separateLaunchersChanged() const;
0994     void launchInPlaceChanged() const;
0995     void hideActivatedLaunchersChanged() const;
0996     void groupModeChanged() const;
0997     void groupInlineChanged() const;
0998     void groupingWindowTasksThresholdChanged() const;
0999     void groupingAppIdBlacklistChanged() const;
1000     void groupingLauncherUrlBlacklistChanged() const;
1001     void taskReorderingEnabledChanged() const;
1002     void activeTaskChanged() const;
1003 
1004 protected:
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 
1018 private:
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 }