recompute actions text on sycoca change

it can update the app name it's opening it with
if the file association has been changed
This commit is contained in:
Marco Martin 2014-08-11 19:32:30 +02:00
parent b5dfbdb0c8
commit 90cac04202
2 changed files with 27 additions and 0 deletions

View File

@ -26,6 +26,7 @@
#include <QFile>
#include <QDebug>
#include <QMimeDatabase>
#include <KSycoca>
#include <qstandardpaths.h>
#include <klocalizedstring.h>
@ -62,6 +63,27 @@ public:
urlLists.remove(applet);
}
void updateActionNames()
{
QMimeDatabase mimeDb;
KService::List apps;
QHash<const Plasma::Applet *, QList<QUrl> >::iterator i;
for (i = urlLists.begin(); i != urlLists.end(); ++i) {
QAction *a = i.key()->actions()->action("run associated application");
if (a) {
apps = KFileItemActions::associatedApplications(mimeDb.mimeTypeForUrl(i.value().first()).aliases(), QString());
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()));
} else {
a->setIcon(QIcon::fromTheme("system-run"));
a->setText(i18n("Run the Associated Application"));
}
}
}
}
QHash<const Plasma::Applet *, QString> applicationNames;
QHash<const Plasma::Applet *, QList<QUrl> > urlLists;
};
@ -78,6 +100,7 @@ AssociatedApplicationManager::AssociatedApplicationManager(QObject *parent)
: QObject(parent),
d(new AssociatedApplicationManagerPrivate())
{
connect(KSycoca::self(), SIGNAL(databaseChanged()), this, SLOT(updateActionNames()));
}
AssociatedApplicationManager::~AssociatedApplicationManager()
@ -123,6 +146,9 @@ void AssociatedApplicationManager::setUrls(Plasma::Applet *applet, const QList<Q
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()));
} else {
a->setIcon(QIcon::fromTheme("system-run"));
a->setText(i18n("Run the Associated Application"));
}
}
}

View File

@ -59,6 +59,7 @@ private:
friend class AssociatedApplicationManagerSingleton;
Q_PRIVATE_SLOT(d, void cleanupApplet(QObject *obj))
Q_PRIVATE_SLOT(d, void updateActionNames())
};
} // namespace Plasma