Simplify getting associated apps list in AssociatedApplicationManager
REVIEW: 125105
This commit is contained in:
parent
fd9a936393
commit
e07778d97b
@ -31,7 +31,7 @@
|
||||
#include <qstandardpaths.h>
|
||||
#include <klocalizedstring.h>
|
||||
#include <kactioncollection.h>
|
||||
#include <kfileitemactions.h>
|
||||
#include <KMimeTypeTrader>
|
||||
|
||||
#if !PLASMA_NO_KIO
|
||||
#include <krun.h>
|
||||
@ -72,15 +72,8 @@ public:
|
||||
for (i = urlLists.begin(); i != urlLists.end(); ++i) {
|
||||
QAction *a = i.key()->actions()->action("run associated application");
|
||||
if (a) {
|
||||
// This gets the current mimetype _and_ a list of its aliases, because aliases()
|
||||
// do not return the current mimetype in it, so it needs to be prepended,
|
||||
// especially for the cases where there are no aliases to be returned,
|
||||
// this would then just return an empty list, returning the generic action even
|
||||
// when there is a valid mimetype and an associated app
|
||||
QStringList mimeTypes{mimeDb.mimeTypeForUrl(i.value().first()).name()};
|
||||
mimeTypes << mimeDb.mimeTypeForUrl(i.value().first()).aliases();
|
||||
|
||||
apps = KFileItemActions::associatedApplications(mimeTypes, QString());
|
||||
const QString mimeType = mimeDb.mimeTypeForUrl(i.value().first()).name();
|
||||
const KService::List apps = KMimeTypeTrader::self()->query(mimeType);
|
||||
if (!apps.isEmpty()) {
|
||||
a->setIcon(QIcon::fromTheme(apps.first()->icon()));
|
||||
a->setText(i18n("Open with %1", apps.first()->genericName().isEmpty() ? apps.first()->genericName() : apps.first()->name()));
|
||||
@ -149,7 +142,8 @@ void AssociatedApplicationManager::setUrls(Plasma::Applet *applet, const QList<Q
|
||||
QAction *a = applet->actions()->action("run associated application");
|
||||
if (a) {
|
||||
QMimeDatabase mimeDb;
|
||||
KService::List apps = KFileItemActions::associatedApplications(mimeDb.mimeTypeForUrl(urls.first()).aliases(), QString());
|
||||
const QString mimeType = mimeDb.mimeTypeForUrl(urls.first()).name();
|
||||
const KService::List apps = KMimeTypeTrader::self()->query(mimeType);
|
||||
if (!apps.isEmpty()) {
|
||||
a->setIcon(QIcon::fromTheme(apps.first()->icon()));
|
||||
a->setText(i18n("Open with %1", apps.first()->genericName().isEmpty() ? apps.first()->genericName() : apps.first()->name()));
|
||||
|
Loading…
Reference in New Issue
Block a user