get rid of constructors which take QVariantList args as much as possible

was used to pass in URLs to construct the applet with ... which is
not the nicest of APIs as it is entirely undocumentable
This commit is contained in:
Aaron Seigo 2013-02-25 17:20:29 +01:00
parent 14e42206b0
commit 9ab4acd23a
6 changed files with 22 additions and 94 deletions

View File

@ -75,6 +75,7 @@ Applet::Applet(const KPluginInfo &info, QObject *parent, uint appletId)
// WARNING: do not access config() OR globalConfig() in this method! // WARNING: do not access config() OR globalConfig() in this method!
// that requires a scene, which is not available at this point // that requires a scene, which is not available at this point
d->init(); d->init();
d->setupPackage();
} }
Applet::Applet(QObject *parent, const QString &serviceID, uint appletId) Applet::Applet(QObject *parent, const QString &serviceID, uint appletId)
@ -84,27 +85,7 @@ Applet::Applet(QObject *parent, const QString &serviceID, uint appletId)
// WARNING: do not access config() OR globalConfig() in this method! // WARNING: do not access config() OR globalConfig() in this method!
// that requires a scene, which is not available at this point // that requires a scene, which is not available at this point
d->init(); d->init();
} d->setupPackage();
Applet::Applet(QObject *parent, const QString &serviceID, uint appletId, const QVariantList &args)
: QObject(parent),
d(new AppletPrivate(KService::serviceByStorageId(serviceID), 0, 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) Applet::Applet(QObject *parentObject, const QVariantList &args)
@ -113,37 +94,20 @@ Applet::Applet(QObject *parentObject, const QVariantList &args)
KService::serviceByStorageId(args.count() > 0 ? args[0].toString() : QString()), 0, KService::serviceByStorageId(args.count() > 0 ? args[0].toString() : QString()), 0,
args.count() > 1 ? args[1].toInt() : 0, this)) args.count() > 1 ? args[1].toInt() : 0, this))
{ {
// now remove those first two items since those are managed by Applet and subclasses shouldn't
// need to worry about them. yes, it violates the constness of this var, but it lets us add
// or remove items later while applets can just pretend that their args always start at 0
QVariantList &mutableArgs = const_cast<QVariantList &>(args);
if (!mutableArgs.isEmpty()) {
mutableArgs.removeFirst();
if (!mutableArgs.isEmpty()) {
mutableArgs.removeFirst();
}
}
d->args = mutableArgs;
setParent(parentObject); setParent(parentObject);
// WARNING: do not access config() OR globalConfig() in this method! // WARNING: do not access config() OR globalConfig() in this method!
// that requires a scene, which is not available at this point // that requires a scene, which is not available at this point
d->init(); d->init();
d->setupPackage();
// the brain damage seen in the initialization list is due to the
// inflexibility of KService::createInstance
} }
Applet::Applet(const QString &packagePath, uint appletId, const QVariantList &args) Applet::Applet(const QString &packagePath, uint appletId)
: QObject(0), : QObject(0),
d(new AppletPrivate(KService::Ptr(new KService(packagePath + "/metadata.desktop")), 0, appletId, this)) d(new AppletPrivate(KService::Ptr(new KService(packagePath + "/metadata.desktop")), 0, appletId, this))
{ {
Q_UNUSED(args) // FIXME?
d->init(packagePath); d->init(packagePath);
d->setupPackage();
} }
Applet::~Applet() Applet::~Applet()
@ -159,8 +123,6 @@ Applet::~Applet()
void Applet::init() void Applet::init()
{ {
if (d->script) { if (d->script) {
d->setupScriptSupport();
if (!d->script->init() && !d->failed) { if (!d->script->init() && !d->failed) {
setLaunchErrorMessage(i18n("Script initialization failed")); setLaunchErrorMessage(i18n("Script initialization failed"));
} }
@ -447,11 +409,6 @@ void Applet::setConfigurationRequired(bool needsConfig, const QString &reason)
d->showConfigurationRequiredMessage(needsConfig, reason); d->showConfigurationRequiredMessage(needsConfig, reason);
} }
QVariantList Applet::startupArguments() const
{
return d->args;
}
ItemStatus Applet::status() const ItemStatus Applet::status() const
{ {
return d->itemStatus; return d->itemStatus;
@ -865,16 +822,16 @@ bool Applet::hasValidAssociatedApplication() const
return AssociatedApplicationManager::self()->appletHasValidAssociatedApplication(this); return AssociatedApplicationManager::self()->appletHasValidAssociatedApplication(this);
} }
Applet *Applet::loadPlasmoid(const QString &path, uint appletId, const QVariantList &args) Applet *Applet::loadPlasmoid(const QString &path, uint appletId)
{ {
if (QFile::exists(path + "/metadata.desktop")) { if (QFile::exists(path + "/metadata.desktop")) {
KService service(path + "/metadata.desktop"); KService service(path + "/metadata.desktop");
const QStringList &types = service.serviceTypes(); const QStringList &types = service.serviceTypes();
if (types.contains("Plasma/Containment")) { if (types.contains("Plasma/Containment")) {
return new Containment(path, appletId, args); return new Containment(path, appletId);
} else { } else {
return new Applet(path, appletId, args); return new Applet(path, appletId);
} }
} }

View File

@ -91,18 +91,6 @@ class PLASMA_EXPORT Applet : public QObject
*/ */
explicit Applet(const KPluginInfo &info, QObject *parent = 0, uint appletId = 0); explicit Applet(const KPluginInfo &info, QObject *parent = 0, uint appletId = 0);
/**
* @param parent the QObject 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 4.3
*/
explicit Applet(QObject *parent, const QString &serviceId, uint appletId, const QVariantList &args);
~Applet(); ~Applet();
//BOOKKEEPING //BOOKKEEPING
@ -277,13 +265,10 @@ class PLASMA_EXPORT Applet : public QObject
* @param path the path to the package * @param path the path to the package
* @param appletId unique ID to assign the applet, or zero to have one * @param appletId unique ID to assign the applet, or zero to have one
* assigned automatically. * assigned automatically.
* @param args to send the applet extra arguments
* @return a pointer to the loaded applet, or 0 on load failure * @return a pointer to the loaded applet, or 0 on load failure
* @since 4.3 * @since 4.3
**/ **/
static Applet *loadPlasmoid(const QString &path, uint appletId = 0, static Applet *loadPlasmoid(const QString &path, uint appletId = 0);
const QVariantList &args = QVariantList());
/** /**
* Returns the icon related to this applet * Returns the icon related to this applet
@ -465,12 +450,6 @@ class PLASMA_EXPORT Applet : public QObject
*/ */
void setStatus(const ItemStatus stat); void setStatus(const ItemStatus stat);
/**
* @return the list of arguments which the applet was called with
* @since KDE4.3
*/
QVariantList startupArguments() const;
//CONFIGURATION //CONFIGURATION
/** /**
* Lets the user interact with the plasmoid options. * Lets the user interact with the plasmoid options.
@ -644,7 +623,7 @@ class PLASMA_EXPORT Applet : public QObject
* and the applet id * and the applet id
* @since 4.3 * @since 4.3
*/ */
Applet(const QString &packagePath, uint appletId, const QVariantList &args); Applet(const QString &packagePath, uint appletId);
Q_PRIVATE_SLOT(d, void cleanUpAndDelete()) Q_PRIVATE_SLOT(d, void cleanUpAndDelete())
Q_PRIVATE_SLOT(d, void configDialogFinished()) Q_PRIVATE_SLOT(d, void configDialogFinished())

View File

@ -78,8 +78,8 @@ Containment::Containment(QObject *parent, const QVariantList &args)
setHasConfigurationInterface(false); setHasConfigurationInterface(false);
} }
Containment::Containment(const QString &packagePath, uint appletId, const QVariantList &args) Containment::Containment(const QString &packagePath, uint appletId)
: Applet(packagePath, appletId, args), : Applet(packagePath, appletId),
d(new ContainmentPrivate(this)) d(new ContainmentPrivate(this))
{ {
// WARNING: do not access config() OR globalConfig() in this method! // WARNING: do not access config() OR globalConfig() in this method!

View File

@ -319,11 +319,9 @@ Q_SIGNALS:
* @internal This constructor is to be used with the Package loading system. * @internal This constructor is to be used with the Package loading system.
* *
* @param parent a QObject parent; you probably want to pass in 0 * @param parent a QObject parent; you probably want to pass in 0
* @param args a list of strings containing two entries: the service id
* and the applet id
* @since 4.3 * @since 4.3
*/ */
Containment(const QString &packagePath, uint appletId, const QVariantList &args); Containment(const QString &packagePath, uint appletId);
Q_PRIVATE_SLOT(d, void appletDeleted(Plasma::Applet*)) Q_PRIVATE_SLOT(d, void appletDeleted(Plasma::Applet*))
Q_PRIVATE_SLOT(d, void triggerShowAddWidgets()) Q_PRIVATE_SLOT(d, void triggerShowAddWidgets())

View File

@ -97,9 +97,8 @@ AppletPrivate::~AppletPrivate()
void AppletPrivate::init(const QString &packagePath) void AppletPrivate::init(const QString &packagePath)
{ {
// WARNING: do not access config() OR globalConfig() in this method! // WARNING: do not access config() OR globalConfig() in this method!
// that requires a scene, which is not available at this point // that requires a Corona, which is not available at this point
q->setHasConfigurationInterface(true);
q->setHasConfigurationInterface(true); //FIXME why not default it to true in the constructor?
QAction *closeApplet = actions->action("remove"); QAction *closeApplet = actions->action("remove");
if (closeApplet) { if (closeApplet) {
@ -123,13 +122,11 @@ void AppletPrivate::init(const QString &packagePath)
QString api = appletDescription.property("X-Plasma-API").toString(); QString api = appletDescription.property("X-Plasma-API").toString();
// we have a scripted plasmoid
if (api.isEmpty()) { if (api.isEmpty()) {
q->setLaunchErrorMessage(i18n("The %2 widget did not define which ScriptEngine to use.", appletDescription.name())); q->setLaunchErrorMessage(i18n("The %2 widget did not define which ScriptEngine to use.", appletDescription.name()));
return; return;
} }
const QString path = packagePath.isEmpty() ? appletDescription.pluginName() : packagePath; const QString path = packagePath.isEmpty() ? appletDescription.pluginName() : packagePath;
package = new Package(PluginLoader::self()->loadPackage("Plasma/Applet", api)); package = new Package(PluginLoader::self()->loadPackage("Plasma/Applet", api));
package->setPath(path); package->setPath(path);
@ -143,13 +140,9 @@ void AppletPrivate::init(const QString &packagePath)
return; return;
} }
// create the package and see if we have something real // now we try and set up the script engine.
//kDebug() << "trying for" << path; // it will be parented to this applet and so will get
// deleted when the applet does
// now we try and set up the script engine.
// it will be parented to this applet and so will get
// deleted when the applet does
script = Plasma::loadScriptEngine(api, q); script = Plasma::loadScriptEngine(api, q);
if (!script) { if (!script) {
@ -360,9 +353,11 @@ void AppletPrivate::setIsContainment(bool nowIsContainment, bool forceUpdate)
// put all setup routines for script here. at this point we can assume that // put all setup routines for script here. at this point we can assume that
// package exists and that we have a script engine // package exists and that we have a script engine
void AppletPrivate::setupScriptSupport() void AppletPrivate::setupPackage()
{ {
if (!package) { if (!package) {
delete configLoader;
configLoader = 0;
return; return;
} }

View File

@ -82,7 +82,7 @@ public:
// put all setup routines for script here. at this point we can assume that // put all setup routines for script here. at this point we can assume that
// package exists and that we have a script engin // package exists and that we have a script engin
void setupScriptSupport(); void setupPackage();
/** /**
* Sets whether or not this Applet is acting as a Containment * Sets whether or not this Applet is acting as a Containment
@ -119,7 +119,6 @@ public:
// applet info we keep around in case its needed // applet info we keep around in case its needed
KPluginInfo appletDescription; KPluginInfo appletDescription;
QVariantList args;
QString customTitle; QString customTitle;
// bookkeeping // bookkeeping