make a new constructor with arguments to make possible for non-plugin

scripted applet to have arguments and a new accessor to have the applet
arguments at any moment

svn path=/trunk/KDE/kdelibs/; revision=923308
This commit is contained in:
Marco Martin 2009-02-08 15:24:56 +00:00
parent 2cc63a17e7
commit 05577817bf
3 changed files with 60 additions and 3 deletions

View File

@ -105,6 +105,30 @@ Applet::Applet(QGraphicsItem *parent,
d->init();
}
Applet::Applet(QGraphicsItem *parent,
const QString &serviceID,
uint appletId,
const QVariantList &args)
: QGraphicsWidget(parent),
d(new AppletPrivate(KService::serviceByStorageId(serviceID), appletId, this))
{
// WARNING: do not access config() OR globalConfig() in this method!
// that requires a scene, which is not available at this point
QVariantList &mutableArgs = const_cast<QVariantList &>(args);
if (!mutableArgs.isEmpty()) {
mutableArgs.removeFirst();
if (!mutableArgs.isEmpty()) {
mutableArgs.removeFirst();
}
}
d->args = mutableArgs;
d->init();
}
Applet::Applet(QObject *parentObject, const QVariantList &args)
: QGraphicsWidget(0),
d(new AppletPrivate(
@ -123,6 +147,8 @@ Applet::Applet(QObject *parentObject, const QVariantList &args)
}
}
d->args = mutableArgs;
setParent(parentObject);
// WARNING: do not access config() OR globalConfig() in this method!
@ -977,6 +1003,11 @@ void Applet::showMessage(const QIcon &icon, const QString &message, const Messag
}
QVariantList Applet::startupArguments() const
{
return d->args;
}
void Applet::flushPendingConstraintsEvents()
{
if (d->pendingConstraints == NoConstraint) {
@ -1709,13 +1740,16 @@ Applet *Applet::load(const QString &appletName, uint appletId, const QVariantLis
appletId = ++AppletPrivate::s_maxAppletId;
}
QVariantList allArgs;
allArgs << offer->storageId() << appletId << args;
if (!offer->property("X-Plasma-API").toString().isEmpty()) {
kDebug() << "we have a script using the"
<< offer->property("X-Plasma-API").toString() << "API";
if (isContainment) {
return new Containment(0, offer->storageId(), appletId);
}
return new Applet(0, offer->storageId(), appletId);
return new Applet(0, offer->storageId(), appletId, allArgs);
}
KPluginLoader plugin(*offer);
@ -1725,8 +1759,7 @@ Applet *Applet::load(const QString &appletName, uint appletId, const QVariantLis
return 0;
}
QVariantList allArgs;
allArgs << offer->storageId() << appletId << args;
QString error;
Applet *applet;

View File

@ -559,6 +559,23 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
const QString &serviceId = QString(),
uint appletId = 0);
/**
* @param parent the QGraphicsItem this applet is parented to
* @param serviceId the name of the .desktop file containing the
* information about the widget
* @param appletId a unique id used to differentiate between multiple
* instances of the same Applet type
* @param args a list of strings containing two entries: the service id
* and the applet id
* @since KDE4.3
*/
explicit Applet(QGraphicsItem *parent,
const QString &serviceId,
uint appletId,
const QVariantList &args
);
/**
* @return true if destroy() was called; useful for Applets which should avoid
* certain tasks if they are about to be deleted permanently
@ -691,6 +708,12 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*/
void setBusy(bool busy);
/**
* @return the list of arguments which the applet was called
* @since KDE4.3
*/
QVariantList startupArguments() const;
protected:
/**
* This constructor is to be used with the plugin loading systems

View File

@ -106,6 +106,7 @@ public:
QStringList loadedEngines;
Plasma::FrameSvg *background;
AppletScript *script;
QVariantList args;
Package *package;
ConfigLoader *configLoader;
KConfigGroup *mainConfig;