diff --git a/applets/kicker/plugin/actionlist.h b/applets/kicker/plugin/actionlist.h --- a/applets/kicker/plugin/actionlist.h +++ b/applets/kicker/plugin/actionlist.h @@ -57,4 +57,9 @@ QVariantList recentDocumentActions(KService::Ptr service); bool handleRecentDocumentAction(KService::Ptr service, const QString &actionId, const QVariant &argument); +QVariantList menuEditorActions(const KService::Ptr &service); +bool handleMenuEditorAction(const QString &actionId, const KService::Ptr &service); + +QVariantList appstreamActions(const KService::Ptr &service); + } diff --git a/applets/kicker/plugin/actionlist.cpp b/applets/kicker/plugin/actionlist.cpp --- a/applets/kicker/plugin/actionlist.cpp +++ b/applets/kicker/plugin/actionlist.cpp @@ -20,19 +20,30 @@ #include "actionlist.h" +#include + #include #include #include #include +#include #include #include #include #include #include "containmentinterface.h" +#include "menuentryeditor.h" + +#ifdef HAVE_APPSTREAMQT +#include + +Q_GLOBAL_STATIC(AppStream::Pool, appstreamPool) +#endif + namespace KAStats = KActivities::Stats; using namespace KAStats; @@ -308,4 +319,73 @@ return (KRun::runService(*service, QList() << QUrl(argument), QApplication::activeWindow()) != 0); } +QVariantList menuEditorActions(const KService::Ptr &service) +{ + QVariantList list; + + if (!service || !MenuEntryEditor::self()->canEdit(service->entryPath())) { + return list; + } + + QVariantMap editAction = Kicker::createActionItem(i18n("Edit Application..."), "editApplication"); + editAction["icon"] = "kmenuedit"; // TODO: Using the KMenuEdit icon might be misleading. + list << editAction; + + return list; +} + +bool handleMenuEditorAction(const QString &actionId, const KService::Ptr &service) +{ + if (!service) { + return false; + } + + if (actionId != QLatin1String("editApplication")) { + return false; + } + + if (!MenuEntryEditor::self()->canEdit(service->entryPath())) { + return false; + } + + MenuEntryEditor::self()->edit(service->entryPath(), service->menuId()); + return true; +} + +QVariantList appstreamActions(const KService::Ptr &service) +{ + QVariantList list; + + if (!service || !service->isApplication()) { + return list; + } + +#ifdef HAVE_APPSTREAMQT + const KService::Ptr appStreamHandler = KMimeTypeTrader::self()->preferredService(QStringLiteral("x-scheme-handler/appstream")); + + // Don't show action if we can't find any app to handle appstream:// URLs. + if (!appStreamHandler) { + if (!KProtocolInfo::isHelperProtocol(QStringLiteral("appstream")) + || KProtocolInfo::exec(QStringLiteral("appstream")).isEmpty()) { + return list; + } + } + + if (!appstreamPool.exists()) { + appstreamPool->load(); + } + + const auto components = appstreamPool->componentsById(service->desktopEntryName()+QLatin1String(".desktop")); + for(const auto &component: components) { + const QString componentId = component.id(); + + QVariantMap appstreamAction = Kicker::createActionItem(i18nc("@action opens a software center with the application", "Manage '%1'...", component.name()), "manageApplication", QVariant(QStringLiteral("appstream://") + componentId)); + appstreamAction[QStringLiteral("icon")] = QStringLiteral("applications-other"); + list << appstreamAction; + } +#endif + + return list; +} + } diff --git a/applets/kicker/plugin/appentry.h b/applets/kicker/plugin/appentry.h --- a/applets/kicker/plugin/appentry.h +++ b/applets/kicker/plugin/appentry.h @@ -69,7 +69,6 @@ QString m_description; mutable QIcon m_icon; KService::Ptr m_service; - static MenuEntryEditor *m_menuEntryEditor; }; class AppGroupEntry : public AbstractGroupEntry diff --git a/applets/kicker/plugin/appentry.cpp b/applets/kicker/plugin/appentry.cpp --- a/applets/kicker/plugin/appentry.cpp +++ b/applets/kicker/plugin/appentry.cpp @@ -25,7 +25,6 @@ #include "menuentryeditor.h" #include -#include #include #include @@ -40,21 +39,14 @@ #include #include #include -#include #include #include #include #include #include #include -#ifdef HAVE_APPSTREAMQT -#include -#endif - -MenuEntryEditor *AppEntry::m_menuEntryEditor = nullptr; - AppEntry::AppEntry(AbstractModel *owner, KService::Ptr service, NameFormat nameFormat) : AbstractEntry(owner) , m_service(service) @@ -89,10 +81,6 @@ } else { m_description = nameFromService(m_service, GenericNameOnly); } - - if (!m_menuEntryEditor) { - m_menuEntryEditor = new MenuEntryEditor(); - } } bool AppEntry::isValid() const @@ -142,39 +130,6 @@ return true; } -#ifdef HAVE_APPSTREAMQT -Q_GLOBAL_STATIC(AppStream::Pool, appstreamPool) - -QVariantList appstreamActions(const KService::Ptr &service) -{ - QVariantList ret; - - const KService::Ptr appStreamHandler = KMimeTypeTrader::self()->preferredService(QStringLiteral("x-scheme-handler/appstream")); - - // Don't show action if we can't find any app to handle appstream:// URLs. - if (!appStreamHandler) { - if (!KProtocolInfo::isHelperProtocol(QStringLiteral("appstream")) - || KProtocolInfo::exec(QStringLiteral("appstream")).isEmpty()) { - return ret; - } - } - - if (!appstreamPool.exists()) { - appstreamPool->load(); - } - - const auto components = appstreamPool->componentsById(service->desktopEntryName()+QLatin1String(".desktop")); - for(const auto &component: components) { - const QString componentId = component.id(); - - QVariantMap appstreamAction = Kicker::createActionItem(i18nc("@action opens a software center with the application", "Manage '%1'...", component.name()), "manageApplication", QVariant(QStringLiteral("appstream://") + componentId)); - appstreamAction[QStringLiteral("icon")] = QStringLiteral("applications-other"); - ret << appstreamAction; - } - return ret; -} -#endif - QVariantList AppEntry::actions() const { QVariantList actionList; @@ -205,19 +160,8 @@ return actionList; } - if (m_menuEntryEditor->canEdit(m_service->entryPath())) { - actionList << Kicker::createSeparatorActionItem(); - - QVariantMap editAction = Kicker::createActionItem(i18n("Edit Application..."), "editApplication"); - editAction["icon"] = "kmenuedit"; // TODO: Using the KMenuEdit icon might be misleading. - actionList << editAction; - } - -#ifdef HAVE_APPSTREAMQT - if (m_service->isApplication()) { - actionList << appstreamActions(m_service); - } -#endif + actionList << Kicker::menuEditorActions(m_service); + actionList << Kicker::appstreamActions(m_service); QQmlPropertyMap *appletConfig = qobject_cast(appletInterface->property("configuration").value()); @@ -260,9 +204,7 @@ if (Kicker::handleAddLauncherAction(actionId, appletInterface, m_service)) { return true; - } else if (actionId == "editApplication" && m_menuEntryEditor->canEdit(m_service->entryPath())) { - m_menuEntryEditor->edit(m_service->entryPath(), m_service->menuId()); - + } else if (Kicker::handleMenuEditorAction(actionId, m_service)) { return true; } else if (actionId == "manageApplication") { return QDesktopServices::openUrl(QUrl(argument.toString())); diff --git a/applets/kicker/plugin/menuentryeditor.h b/applets/kicker/plugin/menuentryeditor.h --- a/applets/kicker/plugin/menuentryeditor.h +++ b/applets/kicker/plugin/menuentryeditor.h @@ -27,13 +27,17 @@ Q_OBJECT public: - MenuEntryEditor(QObject *parent = 0); + static MenuEntryEditor *self(); ~MenuEntryEditor(); bool canEdit(const QString &entryPath) const; public Q_SLOTS: void edit(const QString &entryPath, const QString &menuId); + + private: + MenuEntryEditor(QObject *parent = 0); + }; #endif diff --git a/applets/kicker/plugin/menuentryeditor.cpp b/applets/kicker/plugin/menuentryeditor.cpp --- a/applets/kicker/plugin/menuentryeditor.cpp +++ b/applets/kicker/plugin/menuentryeditor.cpp @@ -33,6 +33,12 @@ { } +MenuEntryEditor *MenuEntryEditor::self() +{ + static MenuEntryEditor *s_self = new MenuEntryEditor(); + return s_self; +} + bool MenuEntryEditor::canEdit(const QString& entryPath) const { KFileItemList itemList; diff --git a/applets/kicker/plugin/runnermatchesmodel.cpp b/applets/kicker/plugin/runnermatchesmodel.cpp --- a/applets/kicker/plugin/runnermatchesmodel.cpp +++ b/applets/kicker/plugin/runnermatchesmodel.cpp @@ -23,6 +23,7 @@ #include "actionlist.h" #include +#include #include #include @@ -122,6 +123,9 @@ if (!recentDocuments.isEmpty()) { actionList << recentDocuments << Kicker::createSeparatorActionItem(); } + + actionList << Kicker::menuEditorActions(service); + actionList << Kicker::appstreamActions(service); } return actionList; @@ -153,6 +157,10 @@ if (Kicker::handleAddLauncherAction(actionId, appletInterface, service)) { return true; + } else if (Kicker::handleMenuEditorAction(actionId, service)) { + return true; + } else if (actionId == "manageApplication") { + return QDesktopServices::openUrl(QUrl(argument.toString())); } else if (actionId == QLatin1String("_kicker_jumpListAction")) { return KRun::run(argument.toString(), {}, nullptr, service ? service->name() : QString(), service ? service->icon() : QString()); } else if (actionId == QLatin1String("_kicker_recentDocument")