From fb8d5d353f3219bb8b54e82767070c3fca1d2da9 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Wed, 20 Jun 2007 08:11:59 +0000 Subject: [PATCH] * take an optional list of arguments to passs into applets * create button applets not icon widgets on drop honestly, not sure i like the qstringlist of argument approach, but that's what klibloader gives me svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=677941 --- applet.cpp | 12 ++++++------ applet.h | 7 +++++-- corona.cpp | 25 ++++++++++++++----------- corona.h | 3 ++- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/applet.cpp b/applet.cpp index 70f876e8d..b0fc5ff55 100644 --- a/applet.cpp +++ b/applet.cpp @@ -229,7 +229,7 @@ KPluginInfo::List Applet::knownApplets() return KPluginInfo::fromServices(offers); } -Applet* Applet::loadApplet(const QString& appletName, uint appletId) +Applet* Applet::loadApplet(const QString& appletName, uint appletId, const QStringList& args) { if (appletName.isEmpty()) { return 0; @@ -249,11 +249,11 @@ Applet* Applet::loadApplet(const QString& appletName, uint appletId) appletId = Private::nextId(); } - QStringList sillyness; + QStringList allArgs; QString id; id.setNum(appletId); - sillyness << offers.first()->storageId() << id; - Applet* applet = KService::createInstance(offers.first(), 0, sillyness); + allArgs << offers.first()->storageId() << id << args; + Applet* applet = KService::createInstance(offers.first(), 0, allArgs); if (!applet) { kDebug() << "Couldn't load applet \"" << appletName << "\"!" << endl; @@ -262,13 +262,13 @@ Applet* Applet::loadApplet(const QString& appletName, uint appletId) return applet; } -Applet* Applet::loadApplet(const KPluginInfo* info, uint appletId) +Applet* Applet::loadApplet(const KPluginInfo* info, uint appletId, const QStringList& args) { if (!info) { return 0; } - return loadApplet(info->pluginName(), appletId); + return loadApplet(info->pluginName(), appletId, args); } } // Plasma namespace diff --git a/applet.h b/applet.h index b401f007f..8d186e0a8 100644 --- a/applet.h +++ b/applet.h @@ -150,9 +150,11 @@ class PLASMA_EXPORT Applet : public QObject, public QGraphicsItem * @param name the plugin name, as returned by KPluginInfo::pluginName() * @param applet 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 **/ - static Applet* loadApplet(const QString &name, uint appletId = 0); + static Applet* loadApplet(const QString &name, uint appletId = 0, + const QStringList& args = QStringList()); /** * Attempts to load an applet, returning a pointer to the applet if @@ -164,7 +166,8 @@ class PLASMA_EXPORT Applet : public QObject, public QGraphicsItem * assigned automatically. * @return a pointer to the loaded applet, or 0 on load failure **/ - static Applet* loadApplet(const KPluginInfo* info, uint appletId = 0); + static Applet* loadApplet(const KPluginInfo* info, uint appletId = 0, + const QStringList& args = QStringList()); /** * Returns the user-visible name for the applet, as specified in the diff --git a/corona.cpp b/corona.cpp index b30e9b04a..2fa3343b3 100644 --- a/corona.cpp +++ b/corona.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -183,9 +184,9 @@ QRectF Corona::maxSizeHint() const return sceneRect(); } -void Corona::addPlasmoid(const QString& name) +Applet* Corona::addPlasmoid(const QString& name, const QStringList& args) { - Applet* applet = Applet::loadApplet(name); + Applet* applet = Applet::loadApplet(name, 0, args); if (applet) { addItem(applet); //applet->constraintsUpdated(); @@ -196,6 +197,8 @@ void Corona::addPlasmoid(const QString& name) } else { kDebug() << "Plasmoid " << name << " could not be loaded." << endl; } + + return applet; } void Corona::addKaramba(const KUrl& path) @@ -252,15 +255,15 @@ void Corona::dropEvent(QGraphicsSceneDragDropEvent *event) } else if (KUrl::List::canDecode(event->mimeData())) { KUrl::List urls = KUrl::List::fromMimeData(event->mimeData()); foreach (const KUrl& url, urls) { - Plasma::Icon *icon = new Plasma::Icon(0); - icon->setIcon(KMimeType::iconNameForUrl(url)); - icon->setUrl(url); - icon->setSize(128,128); - //TODO: associate the url with the icon, use the Button plasmoid here - icon->setPos(event->scenePos() - QPoint(icon->boundingRect().width()/2, - icon->boundingRect().height()/2)); - icon->show(); - addItem(icon); + QStringList args; + args << url.url(); + Applet* button = addPlasmoid("url", args); + if (button) { + //button->setSize(128,128); + button->setPos(event->scenePos() - QPoint(button->boundingRect().width()/2, + button->boundingRect().height()/2)); + } + addItem(button); } event->acceptProposedAction(); } diff --git a/corona.h b/corona.h index 0b6998c29..165568a47 100644 --- a/corona.h +++ b/corona.h @@ -87,8 +87,9 @@ public Q_SLOTS: * * @param name the plugin name for the applet, as given by * KPluginInfo::pluginName() + * @param args argument list to pass to the plasmoid */ - void addPlasmoid(const QString& name); + Applet* addPlasmoid(const QString& name, const QStringList& args = QStringList()); /** * Adds a SuperKaramba theme to the scene