File indexing completed on 2024-05-05 17:44:49

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 "abstracttasksmodeliface.h"
0010 
0011 #include <QAbstractListModel>
0012 
0013 #include "taskmanager_export.h"
0014 
0015 namespace TaskManager
0016 {
0017 /**
0018  * @short An abstract base class for (flat) tasks models.
0019  *
0020  * This class serves as abstract base class for flat tasks model implementations.
0021  * It provides data roles and no-op default implementations of methods in the
0022  * AbstractTasksModelIface interface.
0023  *
0024  * @author Eike Hein <hein@kde.org>
0025  **/
0026 class TASKMANAGER_EXPORT AbstractTasksModel : public QAbstractListModel, public AbstractTasksModelIface
0027 {
0028     Q_OBJECT
0029 
0030 public:
0031     enum AdditionalRoles {
0032         AppId = Qt::UserRole + 1, /**< KService storage id (.desktop name sans extension). */
0033         AppName, /**< Application name. */
0034         GenericName, /**< Generic application name. */
0035         LauncherUrl, /**< URL that can be used to launch this application (.desktop or executable). */
0036         LauncherUrlWithoutIcon, /**< Special path to get a launcher URL while skipping fallback icon encoding. Used as speed optimization. */
0037         WinIdList, /**< NOTE: On Wayland, these ids are only useful within the same process. On X11, they are global window ids. */
0038         MimeType, /**< MIME type for this task (window, window group), needed for DND. */
0039         MimeData, /**< Data for MimeType. */
0040         IsWindow, /**< This is a window task. */
0041         IsStartup, /**< This is a startup task. */
0042         IsLauncher, /**< This is a launcher task. */
0043         HasLauncher, /**< A launcher exists for this task. Only implemented by TasksModel, not by either the single-type or munging tasks models. */
0044         IsGroupParent, /**< This is a parent item for a group of child tasks. */
0045         ChildCount, /**< The number of tasks in this group. */
0046         IsGroupable, /**< Whether this task is being ignored by grouping or not. */
0047         IsActive, /**< This is the currently active task. */
0048         IsClosable, /**< requestClose (see below) available. */
0049         IsMovable, /**< requestMove (see below) available. */
0050         IsResizable, /**< requestResize (see below) available. */
0051         IsMaximizable, /**< requestToggleMaximize (see below) available. */
0052         IsMaximized, /**< Task (i.e. window) is maximized. */
0053         IsMinimizable, /**< requestToggleMinimize (see below) available. */
0054         IsMinimized, /**< Task (i.e. window) is minimized. */
0055         IsKeepAbove, /**< Task (i.e. window) is keep-above. */
0056         IsKeepBelow, /**< Task (i.e. window) is keep-below. */
0057         IsFullScreenable, /**< requestToggleFullScreen (see below) available. */
0058         IsFullScreen, /**< Task (i.e. window) is fullscreen. */
0059         IsShadeable, /**< requestToggleShade (see below) available. */
0060         IsShaded, /**< Task (i.e. window) is shaded. */
0061         IsVirtualDesktopsChangeable, /**< requestVirtualDesktop (see below) available. */
0062         VirtualDesktops, /**< Virtual desktops for the task (i.e. window). */
0063         IsOnAllVirtualDesktops, /**< Task is on all virtual desktops. */
0064         Geometry, /**< The task's geometry (i.e. the window's). */
0065         ScreenGeometry, /**< Screen geometry for the task (i.e. the window's screen). */
0066         Activities, /**< Activities for the task (i.e. window). */
0067         IsDemandingAttention, /**< Task is demanding attention. */
0068         SkipTaskbar, /**< Task should not be shown in a 'task bar' user interface. */
0069         SkipPager, /**< Task should not to be shown in a 'pager' user interface. */
0070         AppPid, /**< Application Process ID. This is provided best-effort, and may not
0071                      be what you expect: For window tasks owned by processes started
0072                      from e.g. kwin_wayland, it would be the process id of kwin
0073                      itself. DO NOT use this for destructive actions such as closing
0074                      the application. The intended use case is to try and (smartly)
0075                      gather more information about the task when needed. */
0076         StackingOrder, /**< A window task's index in the window stacking order. Care must be
0077                             taken not to assume this index to be unique when iterating over
0078                             model contents due to the asynchronous nature of the windowing
0079                             system. */
0080         LastActivated, /**< The timestamp of the last time a task was the active task. */
0081         ApplicationMenuServiceName, /**< The DBus service name for the application's menu.
0082                                          May be empty. @since 5.19 */
0083         ApplicationMenuObjectPath, /**< The DBus object path for the application's menu.
0084                                         May be empty. @since 5.19 */
0085         IsHidden, /**< Task (i.e window) is hidden on screen. A minimzed
0086                        window is not necessarily hidden. */
0087         CanLaunchNewInstance, /**< A new instance of the task can be launched. @since 5.24 */
0088     };
0089     Q_ENUM(AdditionalRoles)
0090 
0091     explicit AbstractTasksModel(QObject *parent = nullptr);
0092     ~AbstractTasksModel() override;
0093 
0094     QHash<int, QByteArray> roleNames() const override;
0095 
0096     QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const override;
0097 
0098     /**
0099      * Request activation of the task at the given index. Derived classes are
0100      * free to interpret the meaning of "activate" themselves depending on
0101      * the nature and state of the task, e.g. launch or raise a window task.
0102      *
0103      * This base implementation does nothing.
0104      *
0105      * @param index An index in this tasks model.
0106      **/
0107     void requestActivate(const QModelIndex &index) override;
0108 
0109     /**
0110      * Request an additional instance of the application backing the task
0111      * at the given index.
0112      *
0113      * This base implementation does nothing.
0114      *
0115      * @param index An index in this tasks model.
0116      **/
0117     void requestNewInstance(const QModelIndex &index) override;
0118 
0119     /**
0120      * Requests to open the given URLs with the application backing the task
0121      * at the given index.
0122      *
0123      * This base implementation does nothing.
0124      *
0125      * @param index An index in this tasks model.
0126      * @param urls The URLs to be passed to the application.
0127      **/
0128     void requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls) override;
0129 
0130     /**
0131      * Request the task at the given index be closed.
0132      *
0133      * This base implementation does nothing.
0134      *
0135      * @param index An index in this tasks model.
0136      **/
0137     void requestClose(const QModelIndex &index) override;
0138 
0139     /**
0140      * Request starting an interactive move for the task at the given index.
0141      *
0142      * This is meant for tasks that have an associated window, and may be
0143      * a no-op when there is no window.
0144      *
0145      * This base implementation does nothing.
0146      *
0147      * @param index An index in this tasks model.
0148      **/
0149     void requestMove(const QModelIndex &index) override;
0150 
0151     /**
0152      * Request starting an interactive resize for the task at the given index.
0153      *
0154      * This is meant for tasks that have an associated window, and may be a
0155      * no-op when there is no window.
0156      *
0157      * This base implementation does nothing.
0158      *
0159      * @param index An index in this tasks model.
0160      **/
0161     void requestResize(const QModelIndex &index) override;
0162 
0163     /**
0164      * Request toggling the minimized state of the task at the given index.
0165      *
0166      * This is meant for tasks that have an associated window, and may be
0167      * a no-op when there is no window.
0168      *
0169      * This base implementation does nothing.
0170      *
0171      * @param index An index in this tasks model.
0172      **/
0173     void requestToggleMinimized(const QModelIndex &index) override;
0174 
0175     /**
0176      * Request toggling the maximized state of the task at the given index.
0177      *
0178      * This is meant for tasks that have an associated window, and may be
0179      * a no-op when there is no window.
0180      *
0181      * This base implementation does nothing.
0182      *
0183      * @param index An index in this tasks model.
0184      **/
0185     void requestToggleMaximized(const QModelIndex &index) override;
0186 
0187     /**
0188      * Request toggling the keep-above state of the task at the given index.
0189      *
0190      * This is meant for tasks that have an associated window, and may be
0191      * a no-op when there is no window.
0192      *
0193      * This base implementation does nothing.
0194      *
0195      * @param index An index in this tasks model.
0196      **/
0197     void requestToggleKeepAbove(const QModelIndex &index) override;
0198 
0199     /**
0200      * Request toggling the keep-below state of the task at the given index.
0201      *
0202      * This is meant for tasks that have an associated window, and may be
0203      * a no-op when there is no window.
0204      *
0205      * This base implementation does nothing.
0206      *
0207      * @param index An index in this tasks model.
0208      **/
0209     void requestToggleKeepBelow(const QModelIndex &index) override;
0210 
0211     /**
0212      * Request toggling the fullscreen state of the task at the given index.
0213      *
0214      * This is meant for tasks that have an associated window, and may be
0215      * a no-op when there is no window.
0216      *
0217      * This base implementation does nothing.
0218      *
0219      * @param index An index in this tasks model.
0220      **/
0221     void requestToggleFullScreen(const QModelIndex &index) override;
0222 
0223     /**
0224      * Request toggling the shaded state of the task at the given index.
0225      *
0226      * This is meant for tasks that have an associated window, and may be
0227      * a no-op when there is no window.
0228      *
0229      * This base implementation does nothing.
0230      *
0231      * @param index An index in this tasks model.
0232      **/
0233     void requestToggleShaded(const QModelIndex &index) override;
0234 
0235     /**
0236      * Request entering the window at the given index on the specified virtual desktops,
0237      * leaving any other desktops.
0238      *
0239      * On Wayland, virtual desktop ids are QStrings. On X11, they are uint >0.
0240      *
0241      * An empty list has a special meaning: The window is entered on all virtual desktops
0242      * in the session.
0243      *
0244      * On X11, a window can only be on one or all virtual desktops. Therefore, only the
0245      * first list entry is actually used.
0246      *
0247      * On X11, the id 0 has a special meaning: The window is entered on all virtual
0248      * desktops in the session.
0249      *
0250      * @param index An index in this window tasks model.
0251      * @param desktops A list of virtual desktop ids.
0252      **/
0253     void requestVirtualDesktops(const QModelIndex &index, const QVariantList &desktops) override;
0254 
0255     /**
0256      * Request entering the window at the given index on a new virtual desktop,
0257      * which is created in response to this request.
0258      *
0259      * @param index An index in this window tasks model.
0260      **/
0261     void requestNewVirtualDesktop(const QModelIndex &index) override;
0262 
0263     /**
0264      * Request moving the task at the given index to the specified activities.
0265      *
0266      * This is meant for tasks that have an associated window, and may be
0267      * a no-op when there is no window.
0268      *
0269      * This base implementation does nothing.
0270      *
0271      * @param index An index in this tasks model.
0272      * @param activities The new list of activities.
0273      **/
0274     void requestActivities(const QModelIndex &index, const QStringList &activities) override;
0275 
0276     /**
0277      * Request informing the window manager of new geometry for a visual
0278      * delegate for the task at the given index. The geometry should be in
0279      * screen coordinates.
0280      *
0281      * This base implementation does nothing.
0282      *
0283      * @param index An index in this tasks model.
0284      * @param geometry Visual delegate geometry in screen coordinates.
0285      * @param delegate The delegate. Implementations are on their own with
0286      * regard to extracting information from this, and should take care to
0287      * reject invalid objects.
0288      **/
0289     void requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate = nullptr) override;
0290 };
0291 
0292 }