Plasma-workspace

launchertasksmodel.h
1/*
2 SPDX-FileCopyrightText: 2016 Eike Hein <hein@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#pragma once
8
9#include "abstracttasksmodel.h"
10
11#include <memory>
12
13#include "taskmanager_export.h"
14
15#include <QUrl>
16
17namespace TaskManager
18{
19/**
20 * @short A tasks model for launchers.
21 *
22 * This model presents tasks sourced from list of launcher URLs. The
23 * list can be read from and written to from a notifiable prop, enabling
24 * storage outside the instance (e.g. in config).
25 *
26 * Extends AbstractTasksModel API with API for adding, removing, checking
27 * for and moving launchers by URL or row index.
28 *
29 * Launcher URLs can use the preferred:// protocol to request system
30 * default applications such as "browser" and "mailer".
31 *
32 * @see defaultApplication
33 *
34 * @author Eike Hein <hein@kde.org>
35 */
36
37class TASKMANAGER_EXPORT LauncherTasksModel : public AbstractTasksModel
38{
39 Q_OBJECT
40
41 Q_PROPERTY(QStringList launcherList READ launcherList WRITE setLauncherList NOTIFY launcherListChanged)
42
43public:
44 explicit LauncherTasksModel(QObject *parent = nullptr);
45 ~LauncherTasksModel() override;
46
47 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
48 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
49 int rowCountForActivity(const QString &activity) const;
50
51 /**
52 * The list of launcher URLs serialized to strings along with
53 * the activities they belong to.
54 *
55 * @see setLauncherList
56 * @returns the list of launcher URLs serialized to strings.
57 **/
58 QStringList launcherList() const;
59
60 /**
61 * Replace the list of launcher URL strings.
62 *
63 * Invalid or empty URLs will be rejected. Duplicate URLs will be
64 * collapsed.
65 *
66 * @see launcherList
67 * @param launchers A list of launcher URL strings.
68 **/
69 void setLauncherList(const QStringList &launchers);
70
71 /**
72 * Request adding a launcher with the given URL.
73 *
74 * If this URL is already in the list, the request will fail. URLs are
75 * compared for equality after removing the query string used to hold
76 * metadata.
77 *
78 * @see launcherUrlsMatch
79 * @param url A launcher URL.
80 * @returns @c true if a launcher was added.
81 */
82 bool requestAddLauncher(const QUrl &url);
83
84 /**
85 * Request removing the launcher with the given URL.
86 *
87 * If this URL is already in the list, the request will fail. URLs are
88 * compared for equality after removing the query string used to hold
89 * metadata.
90 *
91 * @see launcherUrlsMatch
92 * @param url A launcher URL.
93 * @returns @c true if the launcher was removed.
94 */
95 bool requestRemoveLauncher(const QUrl &url);
96
97 /**
98 * Request adding a launcher with the given URL to current activity.
99 *
100 * If this URL is already in the list, the request will fail. URLs are
101 * compared for equality after removing the query string used to hold
102 * metadata.
103 *
104 * @see launcherUrlsMatch
105 * @param url A launcher URL.
106 * @returns @c true if a launcher was added.
107 */
108 bool requestAddLauncherToActivity(const QUrl &url, const QString &activity);
109
110 /**
111 * Request removing the launcher with the given URL from the current activity.
112 *
113 * If this URL is already in the list, the request will fail. URLs are
114 * compared for equality after removing the query string used to hold
115 * metadata.
116 *
117 * @see launcherUrlsMatch
118 * @param url A launcher URL.
119 * @returns @c true if the launcher was removed.
120 */
121 bool requestRemoveLauncherFromActivity(const QUrl &url, const QString &activity);
122
123 /**
124 * Return the list of activities the launcher belongs to.
125 * If there is no launcher with that url, the list will be empty,
126 * while if the launcher is on all activities, it will contain a
127 * null uuid.
128 *
129 * URLs are compared for equality after removing the query string used
130 * to hold metadata.
131 */
132 QStringList launcherActivities(const QUrl &url) const;
133
134 /**
135 * Return the position of the launcher with the given URL.
136 *
137 * URLs are compared for equality after removing the query string used
138 * to hold metadata.
139 *
140 * @see launcherUrlsMatch
141 * @param url A launcher URL.
142 * @returns @c -1 if no launcher exists for the given URL.
143 */
144 int launcherPosition(const QUrl &url) const;
145
146 /**
147 * Runs the URL (i.e. launches the application) at the given index.
148 *
149 * @param index An index in this launcher tasks model.
150 */
151 void requestActivate(const QModelIndex &index) override;
152
153 /**
154 * Runs the URL (i.e. launches the application) at the given index.
155 *
156 * @param index An index in this launcher tasks model.
157 */
158 void requestNewInstance(const QModelIndex &index) override;
159
160 /**
161 * Runs the application backing the launcher at the given index with the given URLs.
162 *
163 * @param index An index in this launcher tasks model
164 * @param urls The URLs to be passed to the application
165 */
166 void requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls) override;
167
168Q_SIGNALS:
169 void launcherListChanged() const;
170
171private:
172 class Private;
173 std::unique_ptr<Private> d;
174};
175
176}
An abstract base class for (flat) tasks models.
A tasks model for launchers.
DisplayRole
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 12:00:00 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.