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:
parent
14e42206b0
commit
9ab4acd23a
@ -75,6 +75,7 @@ Applet::Applet(const KPluginInfo &info, QObject *parent, uint appletId)
|
||||
// WARNING: do not access config() OR globalConfig() in this method!
|
||||
// that requires a scene, which is not available at this point
|
||||
d->init();
|
||||
d->setupPackage();
|
||||
}
|
||||
|
||||
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!
|
||||
// that requires a scene, which is not available at this point
|
||||
d->init();
|
||||
}
|
||||
|
||||
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();
|
||||
d->setupPackage();
|
||||
}
|
||||
|
||||
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,
|
||||
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);
|
||||
|
||||
// WARNING: do not access config() OR globalConfig() in this method!
|
||||
// that requires a scene, which is not available at this point
|
||||
d->init();
|
||||
|
||||
// the brain damage seen in the initialization list is due to the
|
||||
// inflexibility of KService::createInstance
|
||||
d->setupPackage();
|
||||
}
|
||||
|
||||
Applet::Applet(const QString &packagePath, uint appletId, const QVariantList &args)
|
||||
Applet::Applet(const QString &packagePath, uint appletId)
|
||||
: QObject(0),
|
||||
d(new AppletPrivate(KService::Ptr(new KService(packagePath + "/metadata.desktop")), 0, appletId, this))
|
||||
{
|
||||
Q_UNUSED(args) // FIXME?
|
||||
d->init(packagePath);
|
||||
d->setupPackage();
|
||||
}
|
||||
|
||||
Applet::~Applet()
|
||||
@ -159,8 +123,6 @@ Applet::~Applet()
|
||||
void Applet::init()
|
||||
{
|
||||
if (d->script) {
|
||||
d->setupScriptSupport();
|
||||
|
||||
if (!d->script->init() && !d->failed) {
|
||||
setLaunchErrorMessage(i18n("Script initialization failed"));
|
||||
}
|
||||
@ -447,11 +409,6 @@ void Applet::setConfigurationRequired(bool needsConfig, const QString &reason)
|
||||
d->showConfigurationRequiredMessage(needsConfig, reason);
|
||||
}
|
||||
|
||||
QVariantList Applet::startupArguments() const
|
||||
{
|
||||
return d->args;
|
||||
}
|
||||
|
||||
ItemStatus Applet::status() const
|
||||
{
|
||||
return d->itemStatus;
|
||||
@ -865,16 +822,16 @@ bool Applet::hasValidAssociatedApplication() const
|
||||
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")) {
|
||||
KService service(path + "/metadata.desktop");
|
||||
const QStringList &types = service.serviceTypes();
|
||||
|
||||
if (types.contains("Plasma/Containment")) {
|
||||
return new Containment(path, appletId, args);
|
||||
return new Containment(path, appletId);
|
||||
} else {
|
||||
return new Applet(path, appletId, args);
|
||||
return new Applet(path, appletId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,18 +91,6 @@ class PLASMA_EXPORT Applet : public QObject
|
||||
*/
|
||||
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();
|
||||
|
||||
//BOOKKEEPING
|
||||
@ -277,13 +265,10 @@ class PLASMA_EXPORT Applet : public QObject
|
||||
* @param path the path to the package
|
||||
* @param appletId unique ID to assign the applet, or zero to have one
|
||||
* assigned automatically.
|
||||
* @param args to send the applet extra arguments
|
||||
* @return a pointer to the loaded applet, or 0 on load failure
|
||||
* @since 4.3
|
||||
**/
|
||||
static Applet *loadPlasmoid(const QString &path, uint appletId = 0,
|
||||
const QVariantList &args = QVariantList());
|
||||
|
||||
static Applet *loadPlasmoid(const QString &path, uint appletId = 0);
|
||||
|
||||
/**
|
||||
* Returns the icon related to this applet
|
||||
@ -465,12 +450,6 @@ class PLASMA_EXPORT Applet : public QObject
|
||||
*/
|
||||
void setStatus(const ItemStatus stat);
|
||||
|
||||
/**
|
||||
* @return the list of arguments which the applet was called with
|
||||
* @since KDE4.3
|
||||
*/
|
||||
QVariantList startupArguments() const;
|
||||
|
||||
//CONFIGURATION
|
||||
/**
|
||||
* Lets the user interact with the plasmoid options.
|
||||
@ -644,7 +623,7 @@ class PLASMA_EXPORT Applet : public QObject
|
||||
* and the applet id
|
||||
* @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 configDialogFinished())
|
||||
|
@ -78,8 +78,8 @@ Containment::Containment(QObject *parent, const QVariantList &args)
|
||||
setHasConfigurationInterface(false);
|
||||
}
|
||||
|
||||
Containment::Containment(const QString &packagePath, uint appletId, const QVariantList &args)
|
||||
: Applet(packagePath, appletId, args),
|
||||
Containment::Containment(const QString &packagePath, uint appletId)
|
||||
: Applet(packagePath, appletId),
|
||||
d(new ContainmentPrivate(this))
|
||||
{
|
||||
// WARNING: do not access config() OR globalConfig() in this method!
|
||||
|
@ -319,11 +319,9 @@ Q_SIGNALS:
|
||||
* @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 args a list of strings containing two entries: the service id
|
||||
* and the applet id
|
||||
* @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 triggerShowAddWidgets())
|
||||
|
@ -97,9 +97,8 @@ AppletPrivate::~AppletPrivate()
|
||||
void AppletPrivate::init(const QString &packagePath)
|
||||
{
|
||||
// WARNING: do not access config() OR globalConfig() in this method!
|
||||
// that requires a scene, which is not available at this point
|
||||
|
||||
q->setHasConfigurationInterface(true); //FIXME why not default it to true in the constructor?
|
||||
// that requires a Corona, which is not available at this point
|
||||
q->setHasConfigurationInterface(true);
|
||||
|
||||
QAction *closeApplet = actions->action("remove");
|
||||
if (closeApplet) {
|
||||
@ -123,13 +122,11 @@ void AppletPrivate::init(const QString &packagePath)
|
||||
|
||||
QString api = appletDescription.property("X-Plasma-API").toString();
|
||||
|
||||
// we have a scripted plasmoid
|
||||
if (api.isEmpty()) {
|
||||
q->setLaunchErrorMessage(i18n("The %2 widget did not define which ScriptEngine to use.", appletDescription.name()));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const QString path = packagePath.isEmpty() ? appletDescription.pluginName() : packagePath;
|
||||
package = new Package(PluginLoader::self()->loadPackage("Plasma/Applet", api));
|
||||
package->setPath(path);
|
||||
@ -143,13 +140,9 @@ void AppletPrivate::init(const QString &packagePath)
|
||||
return;
|
||||
}
|
||||
|
||||
// create the package and see if we have something real
|
||||
//kDebug() << "trying for" << path;
|
||||
|
||||
// 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);
|
||||
|
||||
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
|
||||
// package exists and that we have a script engine
|
||||
void AppletPrivate::setupScriptSupport()
|
||||
void AppletPrivate::setupPackage()
|
||||
{
|
||||
if (!package) {
|
||||
delete configLoader;
|
||||
configLoader = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ public:
|
||||
|
||||
// put all setup routines for script here. at this point we can assume that
|
||||
// package exists and that we have a script engin
|
||||
void setupScriptSupport();
|
||||
void setupPackage();
|
||||
|
||||
/**
|
||||
* 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
|
||||
KPluginInfo appletDescription;
|
||||
QVariantList args;
|
||||
QString customTitle;
|
||||
|
||||
// bookkeeping
|
||||
|
Loading…
Reference in New Issue
Block a user