Changeset View
Changeset View
Standalone View
Standalone View
applets/taskmanager/plugin/backend.cpp
Show All 16 Lines | |||||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * | 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * | ||
18 | ***************************************************************************/ | 18 | ***************************************************************************/ | ||
19 | 19 | | |||
20 | #include "backend.h" | 20 | #include "backend.h" | ||
21 | 21 | | |||
22 | #include <KConfigGroup> | 22 | #include <KConfigGroup> | ||
23 | #include <KDesktopFile> | 23 | #include <KDesktopFile> | ||
24 | #include <KFileItem> | 24 | #include <KFileItem> | ||
25 | #include <KFilePlacesModel> | ||||
25 | #include <KLocalizedString> | 26 | #include <KLocalizedString> | ||
26 | #include <KRun> | 27 | #include <KRun> | ||
27 | #include <KService> | 28 | #include <KService> | ||
28 | #include <kwindoweffects.h> | 29 | #include <kwindoweffects.h> | ||
29 | #include <KWindowSystem> | 30 | #include <KWindowSystem> | ||
30 | 31 | | |||
31 | #include <QAction> | 32 | #include <QAction> | ||
32 | #include <QActionGroup> | 33 | #include <QActionGroup> | ||
33 | #include <QApplication> | 34 | #include <QApplication> | ||
34 | #include <QJsonArray> | 35 | #include <QJsonArray> | ||
36 | #include <QScopedPointer> | ||||
35 | #include <QQuickItem> | 37 | #include <QQuickItem> | ||
36 | #include <QQuickWindow> | 38 | #include <QQuickWindow> | ||
37 | 39 | | |||
38 | #include <KActivities/Consumer> | 40 | #include <KActivities/Consumer> | ||
39 | #include <KActivities/Stats/Cleaning> | 41 | #include <KActivities/Stats/Cleaning> | ||
40 | #include <KActivities/Stats/ResultSet> | 42 | #include <KActivities/Stats/ResultSet> | ||
41 | #include <KActivities/Stats/Terms> | 43 | #include <KActivities/Stats/Terms> | ||
42 | 44 | | |||
▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Line(s) | 124 | foreach (const QString &actionName, jumpListActions) { | |||
152 | connect(action, &QAction::triggered, this, &Backend::handleJumpListAction); | 154 | connect(action, &QAction::triggered, this, &Backend::handleJumpListAction); | ||
153 | 155 | | |||
154 | actions << QVariant::fromValue<QAction *>(action); | 156 | actions << QVariant::fromValue<QAction *>(action); | ||
155 | } | 157 | } | ||
156 | 158 | | |||
157 | return actions; | 159 | return actions; | ||
158 | } | 160 | } | ||
159 | 161 | | |||
162 | QVariantList Backend::placesActions(const QUrl &launcherUrl, bool showAllPlaces, QObject *parent) | ||||
163 | { | ||||
164 | QVariantList actions; | ||||
165 | | ||||
166 | if (!parent || !launcherUrl.isValid() || !launcherUrl.isLocalFile() | ||||
167 | || !KDesktopFile::isDesktopFile(launcherUrl.toLocalFile())) { | ||||
168 | return actions; | ||||
169 | } | ||||
170 | | ||||
171 | KDesktopFile desktopFile(launcherUrl.toLocalFile()); | ||||
172 | | ||||
173 | // Since we can't have dynamic jump list actions, at least add the user's "Places" for file managers. | ||||
174 | const QStringList &categories = desktopFile.desktopGroup().readXdgListEntry(QStringLiteral("Categories")); | ||||
broulik: I just spotted this memory leak in backend, jumpListActions and recentDocumentActions both take… | |||||
175 | if (!categories.contains(QLatin1String("FileManager"))) { | ||||
176 | return actions; | ||||
177 | } | ||||
178 | | ||||
179 | QScopedPointer<KFilePlacesModel> placesModel(new KFilePlacesModel()); | ||||
180 | for (int i = 0; i < placesModel->rowCount(); ++i) { | ||||
181 | QModelIndex idx = placesModel->index(i, 0); | ||||
182 | | ||||
183 | if (placesModel->data(idx, KFilePlacesModel::HiddenRole).toBool()) { | ||||
184 | continue; | ||||
185 | } | ||||
186 | | ||||
187 | const QString &title = placesModel->data(idx, Qt::DisplayRole).toString(); | ||||
188 | const QIcon &icon = placesModel->data(idx, Qt::DecorationRole).value<QIcon>(); | ||||
189 | const QUrl &url = placesModel->data(idx, KFilePlacesModel::UrlRole).toUrl(); | ||||
190 | | ||||
191 | QAction *action = new QAction(icon, title, parent); | ||||
192 | | ||||
193 | connect(action, &QAction::triggered, this, [this, action, url, launcherUrl] { | ||||
194 | KService::Ptr service = KService::serviceByDesktopPath(launcherUrl.toLocalFile()); | ||||
195 | if (!service) { | ||||
196 | return; | ||||
197 | } | ||||
198 | | ||||
199 | KRun::runService(*service, {url}, QApplication::activeWindow()); | ||||
200 | }); | ||||
201 | | ||||
202 | actions << QVariant::fromValue(action); | ||||
203 | } | ||||
204 | | ||||
205 | // There is nothing more frustrating than having a "More" entry that ends up showing just one or two | ||||
hein: Some comments to explain why 7 here and 5 below might be good. | |||||
206 | // additional entries. Therefore we truncate to max. 5 entries only if there are more than 7 in total. | ||||
207 | if (!showAllPlaces && actions.count() > 7) { | ||||
208 | const int totalActionCount = actions.count(); | ||||
209 | | ||||
210 | while (actions.count() > 5) { | ||||
211 | actions.removeLast(); | ||||
212 | } | ||||
213 | | ||||
214 | QAction *action = new QAction(parent); | ||||
215 | action->setText(i18ncp("Show all user Places", "%1 more Place", "%1 more Places", totalActionCount - actions.count())); | ||||
216 | connect(action, &QAction::triggered, this, &Backend::showAllPlaces); | ||||
217 | actions << QVariant::fromValue(action); | ||||
218 | } | ||||
219 | | ||||
220 | return actions; | ||||
221 | } | ||||
222 | | ||||
160 | QVariantList Backend::recentDocumentActions(const QUrl &launcherUrl, QObject *parent) | 223 | QVariantList Backend::recentDocumentActions(const QUrl &launcherUrl, QObject *parent) | ||
161 | { | 224 | { | ||
162 | QVariantList actions; | 225 | QVariantList actions; | ||
163 | 226 | | |||
164 | if (!parent || !launcherUrl.isValid() || !launcherUrl.isLocalFile() | 227 | if (!parent || !launcherUrl.isValid() || !launcherUrl.isLocalFile() | ||
165 | || !KDesktopFile::isDesktopFile(launcherUrl.toLocalFile())) { | 228 | || !KDesktopFile::isDesktopFile(launcherUrl.toLocalFile())) { | ||
166 | return actions; | 229 | return actions; | ||
167 | } | 230 | } | ||
▲ Show 20 Lines • Show All 264 Lines • Show Last 20 Lines |
I just spotted this memory leak in backend, jumpListActions and recentDocumentActions both take a "parent" argument which is never used. I'll make a follow-up patch to change new QAction(this) to new QAction(menu) and I verified that this causes the QActions to be disposed of once the menu closes