diff --git a/shell/scripting/containment.cpp b/shell/scripting/containment.cpp index 47b854f40..1669f4e83 100644 --- a/shell/scripting/containment.cpp +++ b/shell/scripting/containment.cpp @@ -1,292 +1,292 @@ /* * Copyright 2009 Aaron Seigo * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "containment.h" #include #include #include #include #include #include #include #include #include "shellcorona.h" #include "scriptengine.h" #include "widget.h" namespace WorkspaceScripting { class Containment::Private { public: QPointer engine; QPointer containment; ShellCorona *corona; QString oldWallpaperPlugin; QString wallpaperPlugin; QString oldWallpaperMode; QString wallpaperMode; QString type; QString plugin; }; Containment::Containment(Plasma::Containment *containment, ScriptEngine *engine) : Applet(engine), d(new Containment::Private) { d->engine = engine; d->containment = containment; d->corona = qobject_cast(containment->corona()); setCurrentConfigGroup(QStringList()); setCurrentGlobalConfigGroup(QStringList()); if (containment) { d->oldWallpaperPlugin = d->wallpaperPlugin = containment->wallpaper(); } } Containment::~Containment() { if (d->containment) { Plasma::Containment *containment = d->containment.data(); if (d->oldWallpaperPlugin != d->wallpaperPlugin || d->oldWallpaperMode != d->wallpaperMode) { containment->setWallpaper(d->wallpaperPlugin); } } reloadConfigIfNeeded(); delete d; } ShellCorona *Containment::corona() const { return d->corona; } int Containment::screen() const { if (!d->containment) { return -1; } return d->containment.data()->screen(); } QString Containment::wallpaperPlugin() const { return d->wallpaperPlugin; } void Containment::setWallpaperPlugin(const QString &wallpaperPlugin) { d->wallpaperPlugin = wallpaperPlugin; } QString Containment::wallpaperMode() const { return d->wallpaperMode; } void Containment::setWallpaperMode(const QString &wallpaperMode) { d->wallpaperMode = wallpaperMode; } QString Containment::formFactor() const { if (!d->containment) { return QStringLiteral("Planar"); } switch (d->containment.data()->formFactor()) { case Plasma::Types::Planar: return QStringLiteral("planar"); case Plasma::Types::MediaCenter: return QStringLiteral("mediacenter"); case Plasma::Types::Horizontal: return QStringLiteral("horizontal"); case Plasma::Types::Vertical: return QStringLiteral("vertical"); case Plasma::Types::Application: return QStringLiteral("application"); } return QStringLiteral("Planar"); } QList Containment::widgetIds() const { //FIXME: the ints could overflow since Applet::id() returns a uint, // however QScript deals with QList very, very poory QList w; if (d->containment) { foreach (const Plasma::Applet *applet, d->containment.data()->applets()) { w.append(applet->id()); } } return w; } QJSValue Containment::widgetById(const QJSValue ¶mId) const { if (!paramId.isNumber()) { return d->engine->newError(i18n("widgetById requires an id")); } const uint id = paramId.toInt(); if (d->containment) { foreach (Plasma::Applet *w, d->containment.data()->applets()) { if (w->id() == id) { return d->engine->wrap(w); } } } return QJSValue(); } -QJSValue Containment::addWidget(const QJSValue &v, qreal x, qreal y, qreal w, qreal h) +QJSValue Containment::addWidget(const QJSValue &v, qreal x, qreal y, qreal w, qreal h, const QVariantList &args) { if (!v.isString() && !v.isQObject()) { return d->engine->newError(i18n("addWidget requires a name of a widget or a widget object")); } if (!d->containment) { return QJSValue(); } QRectF geometry(x, y, w, h); Plasma::Applet *applet = nullptr; if (v.isString()) { //A position has been supplied: search for the containment's graphics object QQuickItem *containmentItem = nullptr; if (geometry.x() >= 0 && geometry.y() >= 0) { containmentItem = d->containment.data()->property("_plasma_graphicObject").value(); if (containmentItem) { - QMetaObject::invokeMethod(containmentItem , "createApplet", Qt::DirectConnection, Q_RETURN_ARG(Plasma::Applet *, applet), Q_ARG(QString, v.toString()), Q_ARG(QVariantList, QVariantList()), Q_ARG(QRectF, geometry)); + QMetaObject::invokeMethod(containmentItem , "createApplet", Qt::DirectConnection, Q_RETURN_ARG(Plasma::Applet *, applet), Q_ARG(QString, v.toString()), Q_ARG(QVariantList, args), Q_ARG(QRectF, geometry)); } if (applet) { return d->engine->wrap(applet); } return d->engine->newError(i18n("Could not create the %1 widget!", v.toString())); } //Case in which either: // * a geometry wasn't provided // * containmentItem wasn't found - applet = d->containment.data()->createApplet(v.toString()); + applet = d->containment.data()->createApplet(v.toString(), args); if (applet) { return d->engine->wrap(applet); } return d->engine->newError(i18n("Could not create the %1 widget!", v.toString())); } else if (Widget *widget = qobject_cast(v.toQObject())) { applet = widget->applet(); d->containment.data()->addApplet(applet); return v; } return QJSValue(); } QJSValue Containment::widgets(const QString &widgetType) const { if (!d->containment) { return QJSValue(); } QJSValue widgets = d->engine->newArray(); int count = 0; foreach (Plasma::Applet *widget, d->containment.data()->applets()) { if (widgetType.isEmpty() || widget->pluginMetaData().pluginId() == widgetType) { widgets.setProperty(count, d->engine->wrap(widget)); ++count; } } widgets.setProperty(QStringLiteral("length"), count); return widgets; } uint Containment::id() const { if (!d->containment) { return 0; } return d->containment.data()->id(); } QString Containment::type() const { if (!d->containment) { return QString(); } return d->containment.data()->pluginMetaData().pluginId(); } void Containment::remove() { if (d->containment) { d->containment.data()->destroy(); } } void Containment::showConfigurationInterface() { if (d->containment) { QAction *configAction = d->containment.data()->actions()->action(QStringLiteral("configure")); if (configAction && configAction->isEnabled()) { configAction->trigger(); } } } Plasma::Applet *Containment::applet() const { return d->containment.data(); } Plasma::Containment *Containment::containment() const { return d->containment.data(); } } diff --git a/shell/scripting/containment.h b/shell/scripting/containment.h index 29000b1aa..455ba2ac9 100644 --- a/shell/scripting/containment.h +++ b/shell/scripting/containment.h @@ -1,97 +1,97 @@ /* * Copyright 2009 Aaron Seigo * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef CONTAINMENT #define CONTAINMENT #include #include #include "applet.h" namespace Plasma { class Containment; } // namespace Plasma class ShellCorona; namespace WorkspaceScripting { class ScriptEngine; class Containment : public Applet { Q_OBJECT ///FIXME: add NOTIFY Q_PROPERTY(QString version READ version) Q_PROPERTY(QStringList configKeys READ configKeys) Q_PROPERTY(QStringList configGroups READ configGroups) Q_PROPERTY(QStringList globalConfigKeys READ globalConfigKeys) Q_PROPERTY(QStringList globalConfigGroups READ globalConfigGroups) Q_PROPERTY(QStringList currentConfigGroup WRITE setCurrentConfigGroup READ currentConfigGroup) Q_PROPERTY(QString wallpaperPlugin READ wallpaperPlugin WRITE setWallpaperPlugin) Q_PROPERTY(QString wallpaperMode READ wallpaperMode WRITE setWallpaperMode) Q_PROPERTY(bool locked READ locked WRITE setLocked) Q_PROPERTY(QString type READ type) Q_PROPERTY(QString formFactor READ formFactor) Q_PROPERTY(QList widgetIds READ widgetIds) Q_PROPERTY(int screen READ screen) Q_PROPERTY(int id READ id) public: explicit Containment(Plasma::Containment *containment, ScriptEngine *parent); ~Containment() override; uint id() const; QString type() const; QString formFactor() const; QList widgetIds() const; int screen() const; Plasma::Applet *applet() const override; Plasma::Containment *containment() const; QString wallpaperPlugin() const; void setWallpaperPlugin(const QString &wallpaperPlugin); QString wallpaperMode() const; void setWallpaperMode(const QString &wallpaperMode); Q_INVOKABLE QJSValue widgetById(const QJSValue ¶mId = QJSValue()) const; - Q_INVOKABLE QJSValue addWidget(const QJSValue &v = QJSValue(), qreal x = -1, qreal y = -1, qreal w = -1, qreal h = -1); + Q_INVOKABLE QJSValue addWidget(const QJSValue &v = QJSValue(), qreal x = -1, qreal y = -1, qreal w = -1, qreal h = -1, const QVariantList &args = QVariantList()); Q_INVOKABLE QJSValue widgets(const QString &widgetType = QString()) const; public Q_SLOTS: void remove(); void showConfigurationInterface(); protected: ShellCorona *corona() const; private: class Private; Private * const d; }; } #endif