File indexing completed on 2024-05-05 17:44:50
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 "abstracttasksmodel.h" 0010 0011 #include "taskmanager_export.h" 0012 0013 #include <QUrl> 0014 0015 namespace TaskManager 0016 { 0017 /** 0018 * @short A tasks model for launchers. 0019 * 0020 * This model presents tasks sourced from list of launcher URLs. The 0021 * list can be read from and written to from a notifiable prop, enabling 0022 * storage outside the instance (e.g. in config). 0023 * 0024 * Extends AbstractTasksModel API with API for adding, removing, checking 0025 * for and moving launchers by URL or row index. 0026 * 0027 * Launcher URLs can use the preferred:// protocol to request system 0028 * default applications such as "browser" and "mailer". 0029 * 0030 * @see defaultApplication 0031 * 0032 * @author Eike Hein <hein@kde.org> 0033 */ 0034 0035 class TASKMANAGER_EXPORT LauncherTasksModel : public AbstractTasksModel 0036 { 0037 Q_OBJECT 0038 0039 Q_PROPERTY(QStringList launcherList READ launcherList WRITE setLauncherList NOTIFY launcherListChanged) 0040 0041 public: 0042 explicit LauncherTasksModel(QObject *parent = nullptr); 0043 ~LauncherTasksModel() override; 0044 0045 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0046 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0047 int rowCountForActivity(const QString &activity) const; 0048 0049 /** 0050 * The list of launcher URLs serialized to strings along with 0051 * the activities they belong to. 0052 * 0053 * @see setLauncherList 0054 * @returns the list of launcher URLs serialized to strings. 0055 **/ 0056 QStringList launcherList() const; 0057 0058 /** 0059 * Replace the list of launcher URL strings. 0060 * 0061 * Invalid or empty URLs will be rejected. Duplicate URLs will be 0062 * collapsed. 0063 * 0064 * @see launcherList 0065 * @param launchers A list of launcher URL strings. 0066 **/ 0067 void setLauncherList(const QStringList &launchers); 0068 0069 /** 0070 * Request adding a launcher with the given URL. 0071 * 0072 * If this URL is already in the list, the request will fail. URLs are 0073 * compared for equality after removing the query string used to hold 0074 * metadata. 0075 * 0076 * @see launcherUrlsMatch 0077 * @param url A launcher URL. 0078 * @returns @c true if a launcher was added. 0079 */ 0080 bool requestAddLauncher(const QUrl &url); 0081 0082 /** 0083 * Request removing the launcher with the given URL. 0084 * 0085 * If this URL is already in the list, the request will fail. URLs are 0086 * compared for equality after removing the query string used to hold 0087 * metadata. 0088 * 0089 * @see launcherUrlsMatch 0090 * @param url A launcher URL. 0091 * @returns @c true if the launcher was removed. 0092 */ 0093 bool requestRemoveLauncher(const QUrl &url); 0094 0095 /** 0096 * Request adding a launcher with the given URL to current activity. 0097 * 0098 * If this URL is already in the list, the request will fail. URLs are 0099 * compared for equality after removing the query string used to hold 0100 * metadata. 0101 * 0102 * @see launcherUrlsMatch 0103 * @param url A launcher URL. 0104 * @returns @c true if a launcher was added. 0105 */ 0106 bool requestAddLauncherToActivity(const QUrl &url, const QString &activity); 0107 0108 /** 0109 * Request removing the launcher with the given URL from the current activity. 0110 * 0111 * If this URL is already in the list, the request will fail. URLs are 0112 * compared for equality after removing the query string used to hold 0113 * metadata. 0114 * 0115 * @see launcherUrlsMatch 0116 * @param url A launcher URL. 0117 * @returns @c true if the launcher was removed. 0118 */ 0119 bool requestRemoveLauncherFromActivity(const QUrl &url, const QString &activity); 0120 0121 /** 0122 * Return the list of activities the launcher belongs to. 0123 * If there is no launcher with that url, the list will be empty, 0124 * while if the launcher is on all activities, it will contain a 0125 * null uuid. 0126 * 0127 * URLs are compared for equality after removing the query string used 0128 * to hold metadata. 0129 */ 0130 QStringList launcherActivities(const QUrl &url) const; 0131 0132 /** 0133 * Return the position of the launcher with the given URL. 0134 * 0135 * URLs are compared for equality after removing the query string used 0136 * to hold metadata. 0137 * 0138 * @see launcherUrlsMatch 0139 * @param url A launcher URL. 0140 * @returns @c -1 if no launcher exists for the given URL. 0141 */ 0142 int launcherPosition(const QUrl &url) const; 0143 0144 /** 0145 * Runs the URL (i.e. launches the application) at the given index. 0146 * 0147 * @param index An index in this launcher tasks model. 0148 */ 0149 void requestActivate(const QModelIndex &index) override; 0150 0151 /** 0152 * Runs the URL (i.e. launches the application) at the given index. 0153 * 0154 * @param index An index in this launcher tasks model. 0155 */ 0156 void requestNewInstance(const QModelIndex &index) override; 0157 0158 /** 0159 * Runs the application backing the launcher at the given index with the given URLs. 0160 * 0161 * @param index An index in this launcher tasks model 0162 * @param urls The URLs to be passed to the application 0163 */ 0164 void requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls) override; 0165 0166 Q_SIGNALS: 0167 void launcherListChanged() const; 0168 0169 private: 0170 class Private; 0171 QScopedPointer<Private> d; 0172 }; 0173 0174 }