File indexing completed on 2024-05-05 05:38:35
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 <QAbstractProxyModel> 0010 0011 #include <memory> 0012 0013 #include "abstracttasksmodeliface.h" 0014 #include "tasksmodel.h" 0015 0016 #include "taskmanager_export.h" 0017 0018 namespace TaskManager 0019 { 0020 /** 0021 * @short A proxy tasks model for grouping tasks, forming a tree. 0022 * 0023 * This proxy model groups tasks in its source tasks model, forming a tree 0024 * of tasks. Gouping behavior is influenced by various properties set on 0025 * the proxy model instance. 0026 * 0027 * @author Eike Hein <hein@kde.org> 0028 **/ 0029 0030 class TASKMANAGER_EXPORT TaskGroupingProxyModel : public QAbstractProxyModel, public AbstractTasksModelIface 0031 { 0032 Q_OBJECT 0033 0034 Q_PROPERTY(TasksModel::GroupMode groupMode READ groupMode WRITE setGroupMode NOTIFY groupModeChanged) 0035 Q_PROPERTY(bool groupDemandingAttention READ groupDemandingAttention WRITE setGroupDemandingAttention NOTIFY groupDemandingAttentionChanged) 0036 Q_PROPERTY(int windowTasksThreshold READ windowTasksThreshold WRITE setWindowTasksThreshold NOTIFY windowTasksThresholdChanged) 0037 Q_PROPERTY(QStringList blacklistedAppIds READ blacklistedAppIds WRITE setBlacklistedAppIds NOTIFY blacklistedAppIdsChanged) 0038 Q_PROPERTY(QStringList blacklistedLauncherUrls READ blacklistedLauncherUrls WRITE setBlacklistedLauncherUrls NOTIFY blacklistedLauncherUrlsChanged) 0039 0040 public: 0041 explicit TaskGroupingProxyModel(QObject *parent = nullptr); 0042 ~TaskGroupingProxyModel() override; 0043 0044 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; 0045 QModelIndex parent(const QModelIndex &child) const override; 0046 0047 QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override; 0048 QModelIndex mapToSource(const QModelIndex &proxyIndex) const override; 0049 0050 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0051 bool hasChildren(const QModelIndex &parent = QModelIndex()) const override; 0052 int columnCount(const QModelIndex &parent = QModelIndex()) const override; 0053 0054 QVariant data(const QModelIndex &proxyIndex, int role) const override; 0055 0056 void setSourceModel(QAbstractItemModel *sourceModel) override; 0057 0058 /** 0059 * Returns the current group mode, i.e. the criteria by which tasks should 0060 * be grouped. 0061 * 0062 * Defaults to TasksModel::GroupApplication, which groups tasks backed by 0063 * the same application. 0064 * 0065 * If the group mode is TasksModel::GroupDisabled, no grouping is done. 0066 * 0067 * @see TasksModel 0068 * @see setGroupMode 0069 * @returns the active group mode. 0070 **/ 0071 TasksModel::GroupMode groupMode() const; 0072 0073 /** 0074 * Sets the group mode, i.e. the criteria by which tasks should be grouped. 0075 * 0076 * The group mode can be set to TasksModel::GroupDisabled to disable grouping 0077 * entirely, breaking apart any existing groups. 0078 * 0079 * @see TasksModel 0080 * @see groupMode 0081 * @param mode A TasksModel group mode. 0082 **/ 0083 void setGroupMode(TasksModel::GroupMode mode); 0084 0085 /** 0086 * Whether new tasks which demand attention 0087 * (AbstractTasksModel::IsDemandingAttention) should be grouped immediately, 0088 * or only once they have stopped demanding attention. Defaults to @c false. 0089 * 0090 * @see setGroupDemandingAttention 0091 * @returns whether tasks which demand attention are grouped immediately. 0092 **/ 0093 bool groupDemandingAttention() const; 0094 0095 /** 0096 * Sets whether new tasks which demand attention 0097 * (AbstractTasksModel::IsDemandingAttention) should be grouped immediately, 0098 * or only once they have stopped demanding attention. 0099 * 0100 * @see groupDemandingAttention 0101 * @param group Whether tasks with demand attention should be grouped immediately. 0102 **/ 0103 void setGroupDemandingAttention(bool group); 0104 0105 /** 0106 * As window tasks (AbstractTasksModel::IsWindow) come and go in the source 0107 * model, groups will be formed when this threshold value is exceeded, and 0108 * broken apart when it matches or falls below. 0109 * 0110 * Defaults to @c -1, which means grouping is done regardless of the number 0111 * of window tasks in the source model. 0112 * 0113 * @see setWindowTasksThreshold 0114 * @return the threshold number of source window tasks used in grouping 0115 * decisions. 0116 **/ 0117 int windowTasksThreshold() const; 0118 0119 /** 0120 * Sets the number of source model window tasks (AbstractTasksModel::IsWindow) 0121 * above which groups will be formed, and at or below which groups will be broken 0122 * apart. 0123 * 0124 * If set to -1, grouping will be done regardless of the number of window tasks 0125 * in the source model. 0126 * 0127 * @see windowTasksThreshold 0128 * @param threshold A threshold number of source window tasks used in grouping 0129 * decisions. 0130 **/ 0131 void setWindowTasksThreshold(int threshold); 0132 0133 /** 0134 * A blacklist of app ids (AbstractTasksModel::AppId) that is consulted before 0135 * grouping a task. If a task's app id is found on the blacklist, it is not 0136 * grouped. 0137 * 0138 * The default app id blacklist is empty. 0139 * 0140 * @see setBlacklistedAppIds 0141 * @returns the blacklist of app ids consulted before grouping a task. 0142 **/ 0143 QStringList blacklistedAppIds() const; 0144 0145 /** 0146 * Sets the blacklist of app ids (AbstractTasksModel::AppId) that is consulted 0147 * before grouping a task. If a task's app id is found on the blacklist, it is 0148 * not grouped. 0149 * 0150 * When set, groups will be formed and broken apart as necessary. 0151 * 0152 * @see blacklistedAppIds 0153 * @param list a blacklist of app ids to be consulted before grouping a task. 0154 **/ 0155 void setBlacklistedAppIds(const QStringList &list); 0156 0157 /** 0158 * A blacklist of launcher URLs (AbstractTasksModel::LauncherUrl) that is 0159 * consulted before grouping a task. If a task's launcher URL is found on the 0160 * blacklist, it is not grouped. 0161 * 0162 * The default launcher URL blacklist is empty. 0163 * 0164 * @see setBlacklistedLauncherUrls 0165 * @returns the blacklist of launcher URLs consulted before grouping a task. 0166 **/ 0167 QStringList blacklistedLauncherUrls() const; 0168 0169 /** 0170 * Sets the blacklist of launcher URLs (AbstractTasksModel::LauncherUrl) that 0171 * is consulted before grouping a task. If a task's launcher URL is found on 0172 * the blacklist, it is not grouped. 0173 * 0174 * When set, groups will be formed and broken apart as necessary. 0175 * 0176 * @see blacklistedLauncherUrls 0177 * @param list a blacklist of launcher URLs to be consulted before grouping a task. 0178 **/ 0179 void setBlacklistedLauncherUrls(const QStringList &list); 0180 0181 /** 0182 * Request activation of the task at the given index. Derived classes are 0183 * free to interpret the meaning of "activate" themselves depending on 0184 * the nature and state of the task, e.g. launch or raise a window task. 0185 * 0186 * @param index An index in this tasks model. 0187 **/ 0188 void requestActivate(const QModelIndex &index) override; 0189 0190 /** 0191 * Request an additional instance of the application backing the task 0192 * at the given index. 0193 * 0194 * @param index An index in this tasks model. 0195 **/ 0196 void requestNewInstance(const QModelIndex &index) override; 0197 0198 /** 0199 * Requests to open the given URLs with the application backing the task 0200 * at the given index. 0201 * 0202 * @param index An index in this tasks model. 0203 * @param urls The URLs to be passed to the application. 0204 **/ 0205 void requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls) override; 0206 0207 /** 0208 * Request the task at the given index be closed. 0209 * 0210 * @param index An index in this tasks model. 0211 **/ 0212 void requestClose(const QModelIndex &index) override; 0213 0214 /** 0215 * Request starting an interactive move for the task at the given index. 0216 * 0217 * This is meant for tasks that have an associated window, and may be 0218 * a no-op when there is no window. 0219 * 0220 * This base implementation does nothing. 0221 * 0222 * @param index An index in this tasks model. 0223 **/ 0224 void requestMove(const QModelIndex &index) override; 0225 0226 /** 0227 * Request starting an interactive resize for the task at the given index. 0228 * 0229 * This is meant for tasks that have an associated window, and may be a 0230 * no-op when there is no window. 0231 * 0232 * @param index An index in this tasks model. 0233 **/ 0234 void requestResize(const QModelIndex &index) override; 0235 0236 /** 0237 * Request toggling the minimized state of the task at the given index. 0238 * 0239 * This is meant for tasks that have an associated window, and may be 0240 * a no-op when there is no window. 0241 * 0242 * This base implementation does nothing. 0243 * 0244 * @param index An index in this tasks model. 0245 **/ 0246 void requestToggleMinimized(const QModelIndex &index) override; 0247 0248 /** 0249 * Request toggling the maximized state of the task at the given index. 0250 * 0251 * This is meant for tasks that have an associated window, and may be 0252 * a no-op when there is no window. 0253 * 0254 * @param index An index in this tasks model. 0255 **/ 0256 void requestToggleMaximized(const QModelIndex &index) override; 0257 0258 /** 0259 * Request toggling the keep-above state of the task at the given index. 0260 * 0261 * This is meant for tasks that have an associated window, and may be 0262 * a no-op when there is no window. 0263 * 0264 * @param index An index in this tasks model. 0265 **/ 0266 void requestToggleKeepAbove(const QModelIndex &index) override; 0267 0268 /** 0269 * Request toggling the keep-below state of the task at the given index. 0270 * 0271 * This is meant for tasks that have an associated window, and may be 0272 * a no-op when there is no window. 0273 * 0274 * @param index An index in this tasks model. 0275 **/ 0276 void requestToggleKeepBelow(const QModelIndex &index) override; 0277 0278 /** 0279 * Request toggling the fullscreen state of the task at the given index. 0280 * 0281 * This is meant for tasks that have an associated window, and may be 0282 * a no-op when there is no window. 0283 * 0284 * This base implementation does nothing. 0285 * 0286 * @param index An index in this tasks model. 0287 **/ 0288 void requestToggleFullScreen(const QModelIndex &index) override; 0289 0290 /** 0291 * Request toggling the shaded state of the task at the given index. 0292 * 0293 * This is meant for tasks that have an associated window, and may be 0294 * a no-op when there is no window. 0295 * 0296 * @param index An index in this tasks model. 0297 **/ 0298 void requestToggleShaded(const QModelIndex &index) override; 0299 0300 /** 0301 * Request entering the window at the given index on the specified virtual desktops, 0302 * leaving any other desktops. 0303 * 0304 * On Wayland, virtual desktop ids are QStrings. On X11, they are uint >0. 0305 * 0306 * An empty list has a special meaning: The window is entered on all virtual desktops 0307 * in the session. 0308 * 0309 * On X11, a window can only be on one or all virtual desktops. Therefore, only the 0310 * first list entry is actually used. 0311 * 0312 * On X11, the id 0 has a special meaning: The window is entered on all virtual 0313 * desktops in the session. 0314 * 0315 * @param index An index in this window tasks model. 0316 * @param desktops A list of virtual desktop ids. 0317 **/ 0318 void requestVirtualDesktops(const QModelIndex &index, const QVariantList &desktops) override; 0319 0320 /** 0321 * Request entering the window at the given index on a new virtual desktop, 0322 * which is created in response to this request. 0323 * 0324 * @param index An index in this window tasks model. 0325 **/ 0326 void requestNewVirtualDesktop(const QModelIndex &index) override; 0327 0328 /** 0329 * Request moving the task at the given index to the specified activities. 0330 * 0331 * This is meant for tasks that have an associated window, and may be 0332 * a no-op when there is no window. 0333 * 0334 * This base implementation does nothing. 0335 * 0336 * @param index An index in this tasks model. 0337 * @param activities The new list of activities. 0338 **/ 0339 void requestActivities(const QModelIndex &index, const QStringList &activities) override; 0340 0341 /** 0342 * Request informing the window manager of new geometry for a visual 0343 * delegate for the task at the given index. The geometry should be in 0344 * screen coordinates. 0345 * 0346 * If the task at the given index is a group parent, the geometry is 0347 * set for all of its children. If the task at the given index is a 0348 * group member, the geometry is set for all of its siblings. 0349 * 0350 * @param index An index in this tasks model. 0351 * @param geometry Visual delegate geometry in screen coordinates. 0352 * @param delegate The delegate. Implementations are on their own with 0353 * regard to extracting information from this, and should take care to 0354 * reject invalid objects. 0355 **/ 0356 void requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate = nullptr) override; 0357 0358 /** 0359 * Request toggling whether the task at the given index, along with any 0360 * tasks matching its kind, should be grouped or not. Task groups will be 0361 * formed or broken apart as needed, along with affecting future grouping 0362 * decisions as new tasks appear in the source model. 0363 * 0364 * As grouping is toggled for a task, updates are made to the blacklisted* 0365 * properties of the model instance. 0366 * 0367 * @see blacklistedAppIds 0368 * @see blacklistedLauncherUrls 0369 * 0370 * @param index An index in this tasks model. 0371 **/ 0372 void requestToggleGrouping(const QModelIndex &index); 0373 0374 Q_SIGNALS: 0375 void groupModeChanged() const; 0376 void groupDemandingAttentionChanged() const; 0377 void windowTasksThresholdChanged() const; 0378 void blacklistedAppIdsChanged() const; 0379 void blacklistedLauncherUrlsChanged() const; 0380 0381 private: 0382 class Private; 0383 std::unique_ptr<Private> d; 0384 0385 Q_PRIVATE_SLOT(d, void sourceRowsAboutToBeInserted(const QModelIndex &parent, int first, int last)) 0386 Q_PRIVATE_SLOT(d, void sourceRowsInserted(const QModelIndex &parent, int start, int end)) 0387 Q_PRIVATE_SLOT(d, void sourceRowsAboutToBeRemoved(const QModelIndex &parent, int first, int last)) 0388 Q_PRIVATE_SLOT(d, void sourceRowsRemoved(const QModelIndex &parent, int start, int end)) 0389 Q_PRIVATE_SLOT(d, void sourceModelAboutToBeReset()) 0390 Q_PRIVATE_SLOT(d, void sourceModelReset()) 0391 Q_PRIVATE_SLOT(d, void sourceDataChanged(QModelIndex, QModelIndex, QList<int>)) 0392 }; 0393 0394 }