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

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     QVariant data(const QModelIndex &index, int role) const override;
0097     QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const override;
0098 
0099     /**
0100      * Request activation of the task at the given index. Derived classes are
0101      * free to interpret the meaning of "activate" themselves depending on
0102      * the nature and state of the task, e.g. launch or raise a window task.
0103      *
0104      * This base implementation does nothing.
0105      *
0106      * @param index An index in this tasks model.
0107      **/
0108     void requestActivate(const QModelIndex &index) override;
0109 
0110     /**
0111      * Request an additional instance of the application backing the task
0112      * at the given index.
0113      *
0114      * This base implementation does nothing.
0115      *
0116      * @param index An index in this tasks model.
0117      **/
0118     void requestNewInstance(const QModelIndex &index) override;
0119 
0120     /**
0121      * Requests to open the given URLs with the application backing the task
0122      * at the given index.
0123      *
0124      * This base implementation does nothing.
0125      *
0126      * @param index An index in this tasks model.
0127      * @param urls The URLs to be passed to the application.
0128      **/
0129     void requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls) override;
0130 
0131     /**
0132      * Request the task at the given index be closed.
0133      *
0134      * This base implementation does nothing.
0135      *
0136      * @param index An index in this tasks model.
0137      **/
0138     void requestClose(const QModelIndex &index) override;
0139 
0140     /**
0141      * Request starting an interactive move for the task at the given index.
0142      *
0143      * This is meant for tasks that have an associated window, and may be
0144      * a no-op when there is no window.
0145      *
0146      * This base implementation does nothing.
0147      *
0148      * @param index An index in this tasks model.
0149      **/
0150     void requestMove(const QModelIndex &index) override;
0151 
0152     /**
0153      * Request starting an interactive resize for the task at the given index.
0154      *
0155      * This is meant for tasks that have an associated window, and may be a
0156      * no-op when there is no window.
0157      *
0158      * This base implementation does nothing.
0159      *
0160      * @param index An index in this tasks model.
0161      **/
0162     void requestResize(const QModelIndex &index) override;
0163 
0164     /**
0165      * Request toggling the minimized state of the task at the given index.
0166      *
0167      * This is meant for tasks that have an associated window, and may be
0168      * a no-op when there is no window.
0169      *
0170      * This base implementation does nothing.
0171      *
0172      * @param index An index in this tasks model.
0173      **/
0174     void requestToggleMinimized(const QModelIndex &index) override;
0175 
0176     /**
0177      * Request toggling the maximized state of the task at the given index.
0178      *
0179      * This is meant for tasks that have an associated window, and may be
0180      * a no-op when there is no window.
0181      *
0182      * This base implementation does nothing.
0183      *
0184      * @param index An index in this tasks model.
0185      **/
0186     void requestToggleMaximized(const QModelIndex &index) override;
0187 
0188     /**
0189      * Request toggling the keep-above state of the task at the given index.
0190      *
0191      * This is meant for tasks that have an associated window, and may be
0192      * a no-op when there is no window.
0193      *
0194      * This base implementation does nothing.
0195      *
0196      * @param index An index in this tasks model.
0197      **/
0198     void requestToggleKeepAbove(const QModelIndex &index) override;
0199 
0200     /**
0201      * Request toggling the keep-below state of the task at the given index.
0202      *
0203      * This is meant for tasks that have an associated window, and may be
0204      * a no-op when there is no window.
0205      *
0206      * This base implementation does nothing.
0207      *
0208      * @param index An index in this tasks model.
0209      **/
0210     void requestToggleKeepBelow(const QModelIndex &index) override;
0211 
0212     /**
0213      * Request toggling the fullscreen state of the task at the given index.
0214      *
0215      * This is meant for tasks that have an associated window, and may be
0216      * a no-op when there is no window.
0217      *
0218      * This base implementation does nothing.
0219      *
0220      * @param index An index in this tasks model.
0221      **/
0222     void requestToggleFullScreen(const QModelIndex &index) override;
0223 
0224     /**
0225      * Request toggling the shaded state of the task at the given index.
0226      *
0227      * This is meant for tasks that have an associated window, and may be
0228      * a no-op when there is no window.
0229      *
0230      * This base implementation does nothing.
0231      *
0232      * @param index An index in this tasks model.
0233      **/
0234     void requestToggleShaded(const QModelIndex &index) override;
0235 
0236     /**
0237      * Request entering the window at the given index on the specified virtual desktops,
0238      * leaving any other desktops.
0239      *
0240      * On Wayland, virtual desktop ids are QStrings. On X11, they are uint >0.
0241      *
0242      * An empty list has a special meaning: The window is entered on all virtual desktops
0243      * in the session.
0244      *
0245      * On X11, a window can only be on one or all virtual desktops. Therefore, only the
0246      * first list entry is actually used.
0247      *
0248      * On X11, the id 0 has a special meaning: The window is entered on all virtual
0249      * desktops in the session.
0250      *
0251      * @param index An index in this window tasks model.
0252      * @param desktops A list of virtual desktop ids.
0253      **/
0254     void requestVirtualDesktops(const QModelIndex &index, const QVariantList &desktops) override;
0255 
0256     /**
0257      * Request entering the window at the given index on a new virtual desktop,
0258      * which is created in response to this request.
0259      *
0260      * @param index An index in this window tasks model.
0261      **/
0262     void requestNewVirtualDesktop(const QModelIndex &index) override;
0263 
0264     /**
0265      * Request moving the task at the given index to the specified activities.
0266      *
0267      * This is meant for tasks that have an associated window, and may be
0268      * a no-op when there is no window.
0269      *
0270      * This base implementation does nothing.
0271      *
0272      * @param index An index in this tasks model.
0273      * @param activities The new list of activities.
0274      **/
0275     void requestActivities(const QModelIndex &index, const QStringList &activities) override;
0276 
0277     /**
0278      * Request informing the window manager of new geometry for a visual
0279      * delegate for the task at the given index. The geometry should be in
0280      * screen coordinates.
0281      *
0282      * This base implementation does nothing.
0283      *
0284      * @param index An index in this tasks model.
0285      * @param geometry Visual delegate geometry in screen coordinates.
0286      * @param delegate The delegate. Implementations are on their own with
0287      * regard to extracting information from this, and should take care to
0288      * reject invalid objects.
0289      **/
0290     void requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate = nullptr) override;
0291 };
0292 
0293 }