Changeset View
Changeset View
Standalone View
Standalone View
applets/kicker/plugin/actionlist.cpp
Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | |||||
47 | namespace KAStats = KActivities::Stats; | 47 | namespace KAStats = KActivities::Stats; | ||
48 | 48 | | |||
49 | using namespace KAStats; | 49 | using namespace KAStats; | ||
50 | using namespace KAStats::Terms; | 50 | using namespace KAStats::Terms; | ||
51 | 51 | | |||
52 | namespace Kicker | 52 | namespace Kicker | ||
53 | { | 53 | { | ||
54 | 54 | | |||
55 | QVariantMap createActionItem(const QString &label, const QString &actionId, const QVariant &argument) | 55 | QVariantMap createActionItem(const QString &label, const QString &icon, const QString &actionId, const QVariant &argument) | ||
56 | { | 56 | { | ||
57 | QVariantMap map; | 57 | QVariantMap map; | ||
58 | 58 | | |||
59 | map[QStringLiteral("text")] = label; | 59 | map[QStringLiteral("text")] = label; | ||
60 | map[QStringLiteral("actionId")] = actionId; | 60 | map[QStringLiteral("actionId")] = actionId; | ||
61 | 61 | | |||
62 | if (!icon.isEmpty()) { | ||||
meven: Remove this if | |||||
63 | map[QStringLiteral("icon")] = icon; | ||||
64 | } | ||||
65 | | ||||
62 | if (argument.isValid()) { | 66 | if (argument.isValid()) { | ||
63 | map[QStringLiteral("actionArgument")] = argument; | 67 | map[QStringLiteral("actionArgument")] = argument; | ||
64 | } | 68 | } | ||
65 | 69 | | |||
66 | return map; | 70 | return map; | ||
67 | } | 71 | } | ||
68 | 72 | | |||
69 | QVariantMap createTitleActionItem(const QString &label) | 73 | QVariantMap createTitleActionItem(const QString &label) | ||
Show All 21 Lines | 93 | { | |||
91 | 95 | | |||
92 | KService::List services = KMimeTypeTrader::self()->query(fileItem.mimetype(), QStringLiteral("Application")); | 96 | KService::List services = KMimeTypeTrader::self()->query(fileItem.mimetype(), QStringLiteral("Application")); | ||
93 | 97 | | |||
94 | if (!services.isEmpty()) { | 98 | if (!services.isEmpty()) { | ||
95 | list << createTitleActionItem(i18n("Open with:")); | 99 | list << createTitleActionItem(i18n("Open with:")); | ||
96 | 100 | | |||
97 | foreach (const KService::Ptr service, services) { | 101 | foreach (const KService::Ptr service, services) { | ||
98 | const QString text = service->name().replace(QLatin1Char('&'), QStringLiteral("&&")); | 102 | const QString text = service->name().replace(QLatin1Char('&'), QStringLiteral("&&")); | ||
99 | QVariantMap item = createActionItem(text, QStringLiteral("_kicker_fileItem_openWith"), service->entryPath()); | 103 | QVariantMap item = createActionItem(text, service->icon(), QStringLiteral("_kicker_fileItem_openWith"), service->entryPath()); | ||
100 | item[QStringLiteral("icon")] = service->icon(); | | |||
101 | 104 | | |||
102 | list << item; | 105 | list << item; | ||
103 | } | 106 | } | ||
104 | 107 | | |||
105 | list << createSeparatorActionItem(); | 108 | list << createSeparatorActionItem(); | ||
106 | } | 109 | } | ||
107 | 110 | | |||
108 | QVariantMap propertiesItem = createActionItem(i18n("Properties"), QStringLiteral("_kicker_fileItem_properties")); | 111 | const QVariantMap &propertiesItem = createActionItem(i18n("Properties"), QStringLiteral("document-properties"), QStringLiteral("_kicker_fileItem_properties")); | ||
109 | propertiesItem[QStringLiteral("icon")] = QStringLiteral("document-properties"); | | |||
110 | list << propertiesItem; | 112 | list << propertiesItem; | ||
111 | 113 | | |||
112 | return list; | 114 | return list; | ||
113 | } | 115 | } | ||
114 | 116 | | |||
115 | bool handleFileItemAction(const KFileItem &fileItem, const QString &actionId, const QVariant &argument, bool *close) | 117 | bool handleFileItemAction(const KFileItem &fileItem, const QString &actionId, const QVariant &argument, bool *close) | ||
116 | { | 118 | { | ||
117 | if (actionId == QLatin1String("_kicker_fileItem_properties")) { | 119 | if (actionId == QLatin1String("_kicker_fileItem_properties")) { | ||
Show All 27 Lines | |||||
145 | QVariantList createAddLauncherActionList(QObject *appletInterface, const KService::Ptr &service) | 147 | QVariantList createAddLauncherActionList(QObject *appletInterface, const KService::Ptr &service) | ||
146 | { | 148 | { | ||
147 | QVariantList actionList; | 149 | QVariantList actionList; | ||
148 | if (!service) { | 150 | if (!service) { | ||
149 | return actionList; | 151 | return actionList; | ||
150 | } | 152 | } | ||
151 | 153 | | |||
152 | if (ContainmentInterface::mayAddLauncher(appletInterface, ContainmentInterface::Desktop)) { | 154 | if (ContainmentInterface::mayAddLauncher(appletInterface, ContainmentInterface::Desktop)) { | ||
153 | QVariantMap addToDesktopAction = Kicker::createActionItem(i18n("Add to Desktop"), QStringLiteral("addToDesktop")); | 155 | QVariantMap addToDesktopAction = Kicker::createActionItem(i18n("Add to Desktop"), QStringLiteral("list-add"), QStringLiteral("addToDesktop")); | ||
154 | addToDesktopAction[QStringLiteral("icon")] = QStringLiteral("list-add"); | | |||
155 | actionList << addToDesktopAction; | 156 | actionList << addToDesktopAction; | ||
156 | } | 157 | } | ||
157 | 158 | | |||
158 | if (ContainmentInterface::mayAddLauncher(appletInterface, ContainmentInterface::Panel)) { | 159 | if (ContainmentInterface::mayAddLauncher(appletInterface, ContainmentInterface::Panel)) { | ||
159 | QVariantMap addToPanelAction = Kicker::createActionItem(i18n("Add to Panel (Widget)"), QStringLiteral("addToPanel")); | 160 | QVariantMap addToPanelAction = Kicker::createActionItem(i18n("Add to Panel (Widget)"), QStringLiteral("list-add"), QStringLiteral("addToPanel")); | ||
160 | addToPanelAction[QStringLiteral("icon")] = QStringLiteral("list-add"); | | |||
161 | actionList << addToPanelAction; | 161 | actionList << addToPanelAction; | ||
162 | } | 162 | } | ||
163 | 163 | | |||
164 | if (service && ContainmentInterface::mayAddLauncher(appletInterface, ContainmentInterface::TaskManager, Kicker::resolvedServiceEntryPath(service))) { | 164 | if (service && ContainmentInterface::mayAddLauncher(appletInterface, ContainmentInterface::TaskManager, Kicker::resolvedServiceEntryPath(service))) { | ||
165 | QVariantMap addToTaskManagerAction = Kicker::createActionItem(i18n("Pin to Task Manager"), QStringLiteral("addToTaskManager")); | 165 | QVariantMap addToTaskManagerAction = Kicker::createActionItem(i18n("Pin to Task Manager"), QStringLiteral("pin"), QStringLiteral("addToTaskManager")); | ||
166 | addToTaskManagerAction[QStringLiteral("icon")] = QStringLiteral("pin"); | | |||
167 | actionList << addToTaskManagerAction; | 166 | actionList << addToTaskManagerAction; | ||
168 | } | 167 | } | ||
169 | 168 | | |||
170 | return actionList; | 169 | return actionList; | ||
171 | } | 170 | } | ||
172 | 171 | | |||
173 | bool handleAddLauncherAction(const QString &actionId, QObject *appletInterface, const KService::Ptr &service) | 172 | bool handleAddLauncherAction(const QString &actionId, QObject *appletInterface, const KService::Ptr &service) | ||
174 | { | 173 | { | ||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | 210 | { | |||
216 | } | 215 | } | ||
217 | 216 | | |||
218 | const auto &actions = service->actions(); | 217 | const auto &actions = service->actions(); | ||
219 | foreach (const KServiceAction &action, actions) { | 218 | foreach (const KServiceAction &action, actions) { | ||
220 | if (action.text().isEmpty() || action.exec().isEmpty()) { | 219 | if (action.text().isEmpty() || action.exec().isEmpty()) { | ||
221 | continue; | 220 | continue; | ||
222 | } | 221 | } | ||
223 | 222 | | |||
224 | QVariantMap item = createActionItem(action.text(), QStringLiteral("_kicker_jumpListAction"), action.exec()); | 223 | QVariantMap item = createActionItem(action.text(), action.icon(), QStringLiteral("_kicker_jumpListAction"), action.exec()); | ||
225 | item[QStringLiteral("icon")] = action.icon(); | | |||
226 | 224 | | |||
227 | list << item; | 225 | list << item; | ||
228 | } | 226 | } | ||
229 | 227 | | |||
230 | return list; | 228 | return list; | ||
231 | } | 229 | } | ||
232 | 230 | | |||
233 | QVariantList recentDocumentActions(KService::Ptr service) | 231 | QVariantList recentDocumentActions(KService::Ptr service) | ||
Show All 37 Lines | 257 | while (list.count() < 6 && resultIt != results.end()) { | |||
271 | if (!fileItem.isFile()) { | 269 | if (!fileItem.isFile()) { | ||
272 | continue; | 270 | continue; | ||
273 | } | 271 | } | ||
274 | 272 | | |||
275 | if (list.isEmpty()) { | 273 | if (list.isEmpty()) { | ||
276 | list << createTitleActionItem(i18n("Recent Documents")); | 274 | list << createTitleActionItem(i18n("Recent Documents")); | ||
277 | } | 275 | } | ||
278 | 276 | | |||
279 | QVariantMap item = createActionItem(url.fileName(), QStringLiteral("_kicker_recentDocument"), resource); | 277 | QVariantMap item = createActionItem(url.fileName(), fileItem.iconName(), QStringLiteral("_kicker_recentDocument"), resource); | ||
280 | item[QStringLiteral("icon")] = fileItem.iconName(); | | |||
281 | 278 | | |||
282 | list << item; | 279 | list << item; | ||
283 | } | 280 | } | ||
284 | 281 | | |||
285 | if (!list.isEmpty()) { | 282 | if (!list.isEmpty()) { | ||
286 | QVariantMap forgetAction = createActionItem(i18n("Forget Recent Documents"), QStringLiteral("_kicker_forgetRecentDocuments")); | 283 | QVariantMap forgetAction = createActionItem(i18n("Forget Recent Documents"), QStringLiteral("edit-clear-history"), QStringLiteral("_kicker_forgetRecentDocuments")); | ||
287 | forgetAction[QStringLiteral("icon")] = QStringLiteral("edit-clear-history"); | | |||
288 | list << forgetAction; | 284 | list << forgetAction; | ||
289 | } | 285 | } | ||
290 | 286 | | |||
291 | return list; | 287 | return list; | ||
292 | } | 288 | } | ||
293 | 289 | | |||
294 | bool handleRecentDocumentAction(KService::Ptr service, const QString &actionId, const QVariant &_argument) | 290 | bool handleRecentDocumentAction(KService::Ptr service, const QString &actionId, const QVariant &_argument) | ||
295 | { | 291 | { | ||
Show All 40 Lines | 331 | { | |||
336 | menuEntryEditor->edit(entryPath, menuId); | 332 | menuEntryEditor->edit(entryPath, menuId); | ||
337 | } | 333 | } | ||
338 | 334 | | |||
339 | QVariantList editApplicationAction(const KService::Ptr &service) | 335 | QVariantList editApplicationAction(const KService::Ptr &service) | ||
340 | { | 336 | { | ||
341 | QVariantList actionList; | 337 | QVariantList actionList; | ||
342 | 338 | | |||
343 | if (canEditApplication(service)) { | 339 | if (canEditApplication(service)) { | ||
344 | QVariantMap editAction = Kicker::createActionItem(i18n("Edit Application..."), QStringLiteral("editApplication")); | 340 | // TODO: Using the KMenuEdit icon might be misleading. | ||
345 | editAction[QStringLiteral("icon")] = QStringLiteral("kmenuedit"); // TODO: Using the KMenuEdit icon might be misleading. | 341 | QVariantMap editAction = Kicker::createActionItem(i18n("Edit Application..."), QStringLiteral("kmenuedit"), QStringLiteral("editApplication")); | ||
346 | actionList << editAction; | 342 | actionList << editAction; | ||
347 | } | 343 | } | ||
348 | 344 | | |||
349 | return actionList; | 345 | return actionList; | ||
350 | } | 346 | } | ||
351 | 347 | | |||
352 | bool handleEditApplicationAction(const QString &actionId, const KService::Ptr &service) | 348 | bool handleEditApplicationAction(const QString &actionId, const KService::Ptr &service) | ||
353 | { | 349 | { | ||
Show All 29 Lines | 368 | #ifdef HAVE_APPSTREAMQT | |||
383 | if (!appstreamPool.exists()) { | 379 | if (!appstreamPool.exists()) { | ||
384 | appstreamPool->load(); | 380 | appstreamPool->load(); | ||
385 | } | 381 | } | ||
386 | 382 | | |||
387 | const auto components = appstreamPool->componentsById(service->desktopEntryName()+QLatin1String(".desktop")); | 383 | const auto components = appstreamPool->componentsById(service->desktopEntryName()+QLatin1String(".desktop")); | ||
388 | for(const auto &component: components) { | 384 | for(const auto &component: components) { | ||
389 | const QString componentId = component.id(); | 385 | const QString componentId = component.id(); | ||
390 | 386 | | |||
391 | QVariantMap appstreamAction = Kicker::createActionItem(i18nc("@action opens a software center with the application", "Uninstall or Manage Add-Ons..."), "manageApplication", QVariant(QLatin1String("appstream://") + componentId)); | 387 | QVariantMap appstreamAction = Kicker::createActionItem( | ||
392 | appstreamAction[QStringLiteral("icon")] = appStreamHandler->icon(); | 388 | i18nc("@action opens a software center with the application", "Uninstall or Manage Add-Ons..."), | ||
389 | appStreamHandler->icon(), | ||||
390 | "manageApplication", QVariant(QLatin1String("appstream://") + componentId)); | ||||
393 | ret << appstreamAction; | 391 | ret << appstreamAction; | ||
394 | } | 392 | } | ||
395 | #else | 393 | #else | ||
396 | Q_UNUSED(service) | 394 | Q_UNUSED(service) | ||
397 | #endif | 395 | #endif | ||
398 | 396 | | |||
399 | return ret; | 397 | return ret; | ||
400 | } | 398 | } | ||
Show All 20 Lines |
Remove this if