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:
parent
b5dfbdb0c8
commit
90cac04202
@ -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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,6 +59,7 @@ private:
|
||||
friend class AssociatedApplicationManagerSingleton;
|
||||
|
||||
Q_PRIVATE_SLOT(d, void cleanupApplet(QObject *obj))
|
||||
Q_PRIVATE_SLOT(d, void updateActionNames())
|
||||
};
|
||||
|
||||
} // namespace Plasma
|
||||
|
Loading…
Reference in New Issue
Block a user