Port away from KMimeTypeTrader

It is about to be deprecated

See https://phabricator.kde.org/T12177
This commit is contained in:
Nicolas Fella 2020-08-11 23:41:10 +02:00
parent 0fe4fc53ef
commit 49bb7d152b

View File

@ -32,7 +32,7 @@
#include <QStandardPaths> #include <QStandardPaths>
#include <KLocalizedString> #include <KLocalizedString>
#include <KActionCollection> #include <KActionCollection>
#include <KMimeTypeTrader> #include <KApplicationTrader>
#include <KIO/ApplicationLauncherJob> #include <KIO/ApplicationLauncherJob>
#include <KIO/OpenUrlJob> #include <KIO/OpenUrlJob>
#include <KIO/JobUiDelegate> #include <KIO/JobUiDelegate>
@ -70,7 +70,7 @@ public:
QAction *a = i.key()->actions()->action(QStringLiteral("run associated application")); QAction *a = i.key()->actions()->action(QStringLiteral("run associated application"));
if (a) { if (a) {
const QString mimeType = mimeDb.mimeTypeForUrl(i.value().first()).name(); const QString mimeType = mimeDb.mimeTypeForUrl(i.value().first()).name();
const KService::List apps = KMimeTypeTrader::self()->query(mimeType); const KService::List apps = KApplicationTrader::queryByMimeType(mimeType);
if (!apps.isEmpty()) { if (!apps.isEmpty()) {
a->setIcon(QIcon::fromTheme(apps.first()->icon())); a->setIcon(QIcon::fromTheme(apps.first()->icon()));
a->setText(i18n("Open with %1", apps.first()->genericName().isEmpty() ? apps.first()->genericName() : apps.first()->name())); a->setText(i18n("Open with %1", apps.first()->genericName().isEmpty() ? apps.first()->genericName() : apps.first()->name()));
@ -171,7 +171,7 @@ void AssociatedApplicationManager::setUrls(Plasma::Applet *applet, const QList<Q
if (a) { if (a) {
QMimeDatabase mimeDb; QMimeDatabase mimeDb;
const QString mimeType = mimeDb.mimeTypeForUrl(urls.first()).name(); const QString mimeType = mimeDb.mimeTypeForUrl(urls.first()).name();
const KService::List apps = KMimeTypeTrader::self()->query(mimeType); const KService::List apps = KApplicationTrader::queryByMimeType(mimeType);
if (!apps.isEmpty()) { if (!apps.isEmpty()) {
a->setIcon(QIcon::fromTheme(apps.first()->icon())); a->setIcon(QIcon::fromTheme(apps.first()->icon()));
a->setText(i18n("Open with %1", apps.first()->genericName().isEmpty() ? apps.first()->genericName() : apps.first()->name())); a->setText(i18n("Open with %1", apps.first()->genericName().isEmpty() ? apps.first()->genericName() : apps.first()->name()));