Changeset View
Changeset View
Standalone View
Standalone View
applets/kicker/plugin/actionlist.cpp
Show All 13 Lines | |||||
14 | * * | 14 | * * | ||
15 | * You should have received a copy of the GNU General Public License * | 15 | * You should have received a copy of the GNU General Public License * | ||
16 | * along with this program; if not, write to the * | 16 | * along with this program; if not, write to the * | ||
17 | * Free Software Foundation, Inc., * | 17 | * Free Software Foundation, Inc., * | ||
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * | 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * | ||
19 | ***************************************************************************/ | 19 | ***************************************************************************/ | ||
20 | 20 | | |||
21 | #include "actionlist.h" | 21 | #include "actionlist.h" | ||
22 | #include "menuentryeditor.h" | ||||
23 | | ||||
24 | #include <config-appstream.h> | ||||
22 | 25 | | |||
23 | #include <QApplication> | 26 | #include <QApplication> | ||
27 | #include <QDesktopServices> | ||||
24 | 28 | | |||
25 | #include <KLocalizedString> | 29 | #include <KLocalizedString> | ||
26 | #include <KMimeTypeTrader> | 30 | #include <KMimeTypeTrader> | ||
27 | #include <KPropertiesDialog> | 31 | #include <KPropertiesDialog> | ||
32 | #include <KProtocolInfo> | ||||
28 | #include <KRun> | 33 | #include <KRun> | ||
29 | 34 | | |||
30 | #include <KActivities/Stats/Cleaning> | 35 | #include <KActivities/Stats/Cleaning> | ||
31 | #include <KActivities/Stats/ResultSet> | 36 | #include <KActivities/Stats/ResultSet> | ||
32 | #include <KActivities/Stats/Terms> | 37 | #include <KActivities/Stats/Terms> | ||
33 | 38 | | |||
34 | #include "containmentinterface.h" | 39 | #include "containmentinterface.h" | ||
35 | 40 | | |||
41 | #ifdef HAVE_APPSTREAMQT | ||||
42 | #include <AppStreamQt/pool.h> | ||||
43 | #endif | ||||
44 | | ||||
36 | namespace KAStats = KActivities::Stats; | 45 | namespace KAStats = KActivities::Stats; | ||
37 | 46 | | |||
38 | using namespace KAStats; | 47 | using namespace KAStats; | ||
39 | using namespace KAStats::Terms; | 48 | using namespace KAStats::Terms; | ||
40 | 49 | | |||
41 | namespace Kicker | 50 | namespace Kicker | ||
42 | { | 51 | { | ||
43 | 52 | | |||
▲ Show 20 Lines • Show All 259 Lines • ▼ Show 20 Line(s) | 288 | { | |||
303 | 312 | | |||
304 | if (argument.isEmpty()) { | 313 | if (argument.isEmpty()) { | ||
305 | return false; | 314 | return false; | ||
306 | } | 315 | } | ||
307 | 316 | | |||
308 | return (KRun::runService(*service, QList<QUrl>() << QUrl(argument), QApplication::activeWindow()) != 0); | 317 | return (KRun::runService(*service, QList<QUrl>() << QUrl(argument), QApplication::activeWindow()) != 0); | ||
309 | } | 318 | } | ||
310 | 319 | | |||
320 | Q_GLOBAL_STATIC(MenuEntryEditor, menuEntryEditor) | ||||
321 | | ||||
322 | bool canEditApplication(const QString &entryPath) | ||||
broulik: canEditApplication | |||||
323 | { | ||||
324 | return menuEntryEditor->canEdit(entryPath); | ||||
325 | } | ||||
326 | | ||||
327 | void editApplication(const QString &entryPath, const QString &menuId) | ||||
broulik: editApplication | |||||
328 | { | ||||
329 | menuEntryEditor->edit(entryPath, menuId); | ||||
330 | } | ||||
331 | | ||||
332 | QVariantList editApplicationAction(const KService::Ptr &service) | ||||
333 | { | ||||
334 | QVariantList actionList; | ||||
335 | | ||||
336 | if (canEditApplication(service->entryPath())) { | ||||
337 | QVariantMap editAction = Kicker::createActionItem(i18n("Edit Application..."), "editApplication"); | ||||
338 | editAction["icon"] = "kmenuedit"; // TODO: Using the KMenuEdit icon might be misleading. | ||||
339 | actionList << editAction; | ||||
340 | } | ||||
341 | | ||||
342 | return actionList; | ||||
343 | } | ||||
344 | | ||||
345 | bool handleEditApplicationAction(const QString &actionId, const KService::Ptr &service) | ||||
346 | { | ||||
347 | | ||||
348 | if (service && actionId == "editApplication" && canEditApplication(service->entryPath())) { | ||||
349 | Kicker::editApplication(service->entryPath(), service->menuId()); | ||||
350 | | ||||
351 | return true; | ||||
352 | } | ||||
353 | | ||||
354 | return false; | ||||
355 | } | ||||
356 | | ||||
357 | #ifdef HAVE_APPSTREAMQT | ||||
358 | Q_GLOBAL_STATIC(AppStream::Pool, appstreamPool) | ||||
359 | #endif | ||||
360 | | ||||
361 | QVariantList appstreamActions(const KService::Ptr &service) | ||||
362 | { | ||||
363 | QVariantList ret; | ||||
364 | | ||||
365 | #ifdef HAVE_APPSTREAMQT | ||||
366 | const KService::Ptr appStreamHandler = KMimeTypeTrader::self()->preferredService(QStringLiteral("x-scheme-handler/appstream")); | ||||
367 | | ||||
368 | // Don't show action if we can't find any app to handle appstream:// URLs. | ||||
369 | if (!appStreamHandler) { | ||||
370 | if (!KProtocolInfo::isHelperProtocol(QStringLiteral("appstream")) | ||||
371 | || KProtocolInfo::exec(QStringLiteral("appstream")).isEmpty()) { | ||||
372 | return ret; | ||||
373 | } | ||||
374 | } | ||||
375 | | ||||
376 | if (!appstreamPool.exists()) { | ||||
377 | appstreamPool->load(); | ||||
378 | } | ||||
379 | | ||||
380 | const auto components = appstreamPool->componentsById(service->desktopEntryName()+QLatin1String(".desktop")); | ||||
This will not work, because the component-ID can be an arbitrary reverse-DNS string identifying the application, and doesn't have to resemble the .desktop-entry-id at all. If that happens, it's purely accidental. I was planning to add a componentsByLaunchable(TYPE, STR) method to AppStream anyway, I could probably do that for the next release of AS. mak: This will not work, because the component-ID can be an arbitrary reverse-DNS string identifying… | |||||
That code wasn't touched during this refactoring, so this is immaterial to the review. Please inform Aleix Pol about it. hein: That code wasn't touched during this refactoring, so this is immaterial to the review. Please… | |||||
I know, that's why I didn't flag this as change request (just a general observation). mak: I know, that's why I didn't flag this as change request (just a general observation). | |||||
Aye, just gut reaction to avoid bike shedding etc :) Thanks for the note, it's important hein: Aye, just gut reaction to avoid bike shedding etc :) Thanks for the note, it's important | |||||
381 | for(const auto &component: components) { | ||||
382 | const QString componentId = component.id(); | ||||
383 | | ||||
384 | QVariantMap appstreamAction = Kicker::createActionItem(i18nc("@action opens a software center with the application", "Manage '%1'...", component.name()), "manageApplication", QVariant(QStringLiteral("appstream://") + componentId)); | ||||
385 | appstreamAction[QStringLiteral("icon")] = QStringLiteral("applications-other"); | ||||
386 | ret << appstreamAction; | ||||
387 | } | ||||
388 | #else | ||||
389 | Q_UNUSED(service) | ||||
390 | #endif | ||||
391 | | ||||
392 | return ret; | ||||
393 | } | ||||
394 | | ||||
395 | bool handleAppstreamActions(const QString &actionId, const QVariant &argument) | ||||
396 | { | ||||
397 | if (actionId == "manageApplication") { | ||||
398 | return QDesktopServices::openUrl(QUrl(argument.toString())); | ||||
399 | } | ||||
400 | | ||||
401 | return false; | ||||
402 | } | ||||
403 | | ||||
404 | | ||||
311 | } | 405 | } |
canEditApplication