framework part of the applet alternatives chooser

this is the little part in plasma-framework for the applet alternatives chooser.
works together the branch mart/alternativesConfig of plasma-workspace and plsma-desktop.
for how it looks and why, see the vdg forum thread:
https://forum.kde.org/viewtopic.php?f=285&t=122067&p=315919#p315919

still possible problems:

I'm not sure about using a new desktop file entry X-Plasma-Provides, maybe Categories could be enough, but it may produce many false positives as well

REVIEW:119409
This commit is contained in:
Marco Martin 2014-07-23 12:25:32 +02:00
parent fbb6166f84
commit 80516dbef0
5 changed files with 45 additions and 0 deletions

View File

@ -494,6 +494,12 @@ void Applet::flushPendingConstraintsEvents()
action->setEnabled(unlocked);
}
action = d->actions->action("alternatives");
if (action) {
action->setVisible(unlocked);
action->setEnabled(unlocked);
}
action = d->actions->action("configure");
if (action && d->hasConfigurationInterface) {
bool canConfig = unlocked || KAuthorized::authorize("plasma/allow_configure_when_locked");

View File

@ -235,6 +235,11 @@ Q_SIGNALS:
*/
void configureRequested(Plasma::Applet *applet);
/**
* Emitted when the user wants to chose an alternative for this applet or containment.
*/
void appletAlternativesRequested(Plasma::Applet *applet);
/**
* Emitted when the wallpaper plugin is changed
*/

View File

@ -49,3 +49,6 @@ Type=bool
[PropertyDef::X-Plasma-DBusActivationService]
Type=QString
[PropertyDef::X-Plasma-Provides]
Type=QStringList

View File

@ -34,6 +34,7 @@
#include <kkeysequencewidget.h>
#include <kglobalaccel.h>
#include <KConfigLoader>
#include <KServiceTypeTrader>
#include "containment.h"
#include "corona.h"
@ -157,6 +158,32 @@ void AppletPrivate::init(const QString &packagePath, const QVariantList &args)
"Could not create a %1 ScriptEngine for the %2 widget.",
api, appletDescription.name()));
}
if (!q->isContainment() && q->pluginInfo().isValid()) {
QString constraint;
QStringList provides = q->pluginInfo().property("X-Plasma-Provides").value<QStringList>();
if (!provides.isEmpty()) {
bool first = true;
foreach (const QString &prov, provides) {
if (!first) {
constraint += " or ";
first = false;
}
constraint += "'" + prov + "' in [X-Plasma-Provides]";
}
KPluginInfo::List applets = KPluginInfo::fromServices(KServiceTypeTrader::self()->query("Plasma/Applet", constraint));
if (applets.count() > 1) {
QAction *a = new QAction(QIcon::fromTheme("preferences-desktop-default-applications"), i18n("Alternatives..."), q);
q->actions()->addAction("alternatives", a);
QObject::connect(a, &QAction::triggered,[=] {
if (q->containment()) {
emit q->containment()->appletAlternativesRequested(q);
}
});
}
}
}
}
void AppletPrivate::cleanUpAndDelete()

View File

@ -751,6 +751,10 @@ void ContainmentInterface::addAppletActions(QMenu &desktopMenu, Plasma::Applet *
if (configureApplet && configureApplet->isEnabled()) {
desktopMenu.addAction(configureApplet);
}
QAction *appletAlternatives = applet->actions()->action("alternatives");
if (appletAlternatives && appletAlternatives->isEnabled()) {
desktopMenu.addAction(appletAlternatives);
}
QAction *runAssociatedApplication = applet->actions()->action("run associated application");
if (runAssociatedApplication && runAssociatedApplication->isEnabled()) {