Merge branch 'mart/AssociatedApplicationFromMime'

reviewed by: Eike Hein
This commit is contained in:
Marco Martin 2014-08-08 16:11:25 +02:00
commit 6a19de43fa
2 changed files with 30 additions and 5 deletions

View File

@ -21,12 +21,16 @@
#include "config-plasma.h"
#include <QAction>
#include <QHash>
#include <QFile>
#include <QDebug>
#include <QMimeDatabase>
#include <qstandardpaths.h>
#include <klocalizedstring.h>
#include <kactioncollection.h>
#include <kfileitemactions.h>
#if !PLASMA_NO_KIO
#include <krun.h>
@ -93,6 +97,12 @@ void AssociatedApplicationManager::setApplication(Plasma::Applet *applet, const
d->applicationNames[applet] = application;
if (!d->urlLists.contains(applet)) {
connect(applet, SIGNAL(destroyed(QObject*)), this, SLOT(cleanupApplet(QObject*)));
} else {
QAction *a = applet->actions()->action("run associated application");
if (a) {
a->setIcon(QIcon::fromTheme("system-run"));
a->setText(i18n("Run the Associated Application"));
}
}
}
}
@ -105,6 +115,17 @@ QString AssociatedApplicationManager::application(const Plasma::Applet *applet)
void AssociatedApplicationManager::setUrls(Plasma::Applet *applet, const QList<QUrl> &urls)
{
d->urlLists[applet] = urls;
if (!d->applicationNames.contains(applet)) {
QAction *a = applet->actions()->action("run associated application");
if (a) {
QMimeDatabase mimeDb;
KService::List apps = KFileItemActions::associatedApplications(mimeDb.mimeTypeForUrl(urls.first()).aliases(), QString());
if (!apps.isEmpty()) {
a->setIcon(QIcon::fromTheme(apps.first()->icon()));
a->setText(i18n("Open in %1", apps.first()->genericName().isEmpty() ? apps.first()->genericName() : apps.first()->name()));
}
}
}
}
QList<QUrl> AssociatedApplicationManager::urls(const Plasma::Applet *applet) const

View File

@ -750,6 +750,11 @@ void ContainmentInterface::addAppletActions(QMenu &desktopMenu, Plasma::Applet *
}
if (!applet->failedToLaunch()) {
QAction *runAssociatedApplication = applet->actions()->action("run associated application");
if (runAssociatedApplication && runAssociatedApplication->isEnabled()) {
desktopMenu.addAction(runAssociatedApplication);
}
QAction *configureApplet = applet->actions()->action("configure");
if (configureApplet && configureApplet->isEnabled()) {
desktopMenu.addAction(configureApplet);
@ -758,11 +763,6 @@ void ContainmentInterface::addAppletActions(QMenu &desktopMenu, Plasma::Applet *
if (appletAlternatives && appletAlternatives->isEnabled()) {
desktopMenu.addAction(appletAlternatives);
}
QAction *runAssociatedApplication = applet->actions()->action("run associated application");
if (runAssociatedApplication && runAssociatedApplication->isEnabled()) {
desktopMenu.addAction(runAssociatedApplication);
}
}
QMenu *containmentMenu = new QMenu(i18nc("%1 is the name of the containment", "%1 Options", m_containment->title()), &desktopMenu);
@ -845,6 +845,10 @@ void ContainmentInterface::addContainmentActions(QMenu &desktopMenu, QEvent *eve
desktopMenu.addAction(m_containment->actions()->action("configure"));
}
} else {
QAction *runAssociatedApplication = m_containment->actions()->action("run associated application");
if (runAssociatedApplication && runAssociatedApplication->isEnabled()) {
desktopMenu.addAction(runAssociatedApplication);
}
desktopMenu.addActions(actions);
}