diff --git a/applets/kicker/plugin/actionlist.cpp b/applets/kicker/plugin/actionlist.cpp index 422a883f7..c161eda15 100644 --- a/applets/kicker/plugin/actionlist.cpp +++ b/applets/kicker/plugin/actionlist.cpp @@ -285,6 +285,7 @@ QVariantList recentDocumentActions(KService::Ptr service) while (list.count() < 6 && resultIt != results.end()) { const QString resource = (*resultIt).resource(); + const QString mimeType = (*resultIt).mimetype(); ++resultIt; const QUrl url(resource); @@ -303,7 +304,7 @@ QVariantList recentDocumentActions(KService::Ptr service) list << createTitleActionItem(i18n("Recent Files")); } - QVariantMap item = createActionItem(url.fileName(), fileItem.iconName(), QStringLiteral("_kicker_recentDocument"), resource); + QVariantMap item = createActionItem(url.fileName(), fileItem.iconName(), QStringLiteral("_kicker_recentDocument"), QStringList{resource, mimeType}); list << item; } @@ -343,14 +344,30 @@ bool handleRecentDocumentAction(KService::Ptr service, const QString &actionId, return false; } - QString argument = _argument.toString(); + const QStringList argument = _argument.toStringList(); + const auto resource = argument.at(0); + const auto mimeType = argument.at(1); + + // prevents using a service file that does not support opening a mime type for a file it created + // for instance a screenshot tool + if (!mimeType.isEmpty()) { + if (!service->hasMimeType(mimeType)) { + // needs to find the application that supports this mimetype + service = KApplicationTrader::preferredService(mimeType); + + if (!service) { + // no service found to handle the mimetype + return false; + } + } + } if (argument.isEmpty()) { return false; } auto *job = new KIO::ApplicationLauncherJob(service); - job->setUrls({QUrl(argument)}); + job->setUrls({QUrl::fromUserInput(resource)}); job->setUiDelegate(new KNotificationJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled)); return job->exec(); } diff --git a/applets/kicker/plugin/recentusagemodel.cpp b/applets/kicker/plugin/recentusagemodel.cpp index fda5f82f3..4b51a224d 100644 --- a/applets/kicker/plugin/recentusagemodel.cpp +++ b/applets/kicker/plugin/recentusagemodel.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -159,14 +160,19 @@ QString RecentUsageModel::description() const } QString RecentUsageModel::resourceAt(int row) const +{ + return rowValueAt(row, ResultModel::ResourceRole).toString(); +} + +QVariant RecentUsageModel::rowValueAt(int row, ResultModel::Roles role) const { QSortFilterProxyModel *sourceProxy = qobject_cast(sourceModel()); if (sourceProxy) { - return sourceProxy->sourceModel()->data(sourceProxy->mapToSource(sourceProxy->index(row, 0)), ResultModel::ResourceRole).toString(); + return sourceProxy->sourceModel()->data(sourceProxy->mapToSource(sourceProxy->index(row, 0)), role).toString(); } - return sourceModel()->data(index(row, 0), ResultModel::ResourceRole).toString(); + return sourceModel()->data(index(row, 0), role); } QVariant RecentUsageModel::data(const QModelIndex &index, int role) const @@ -339,6 +345,7 @@ bool RecentUsageModel::trigger(int row, const QString &actionId, const QVariant if (actionId.isEmpty() && withinBounds) { const QString &resource = resourceAt(row); + const QString &mimeType = rowValueAt(row, ResultModel::MimeType).toString(); if (!resource.startsWith(QLatin1String("applications:"))) { const QUrl resourceUrl = docData(resource, Kicker::UrlRole).toUrl(); @@ -364,6 +371,20 @@ bool RecentUsageModel::trigger(int row, const QString &actionId, const QVariant } #endif + // prevents using a service file that does not support opening a mime type for a file it created + // for instance a screenshot tool + if (!mimeType.isEmpty()) { + if (!service->hasMimeType(mimeType)) { + // needs to find the application that supports this mimetype + service = KApplicationTrader::preferredService(mimeType); + + if (!service) { + // no service found to handle the mimetype + return false; + } + } + } + auto *job = new KIO::ApplicationLauncherJob(service); job->setUiDelegate(new KNotificationJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled)); job->setStartupId(KStartupInfo::createNewStartupIdForTimestamp(timeStamp)); diff --git a/applets/kicker/plugin/recentusagemodel.h b/applets/kicker/plugin/recentusagemodel.h index c609d3b7d..64ddc7fed 100644 --- a/applets/kicker/plugin/recentusagemodel.h +++ b/applets/kicker/plugin/recentusagemodel.h @@ -11,6 +11,7 @@ #include #include #include +#include class QModelIndex; class KFileItem; @@ -100,6 +101,7 @@ private: QVariant docData(const QString &resource, int role) const; QString resourceAt(int row) const; + QVariant rowValueAt(int row, KActivities::Stats::ResultModel::Roles role) const; QString forgetAllActionName() const;