* 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
This commit is contained in:
parent
2d0a8aa271
commit
fb8d5d353f
12
applet.cpp
12
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<Plasma::Applet>(offers.first(), 0, sillyness);
|
||||
allArgs << offers.first()->storageId() << id << args;
|
||||
Applet* applet = KService::createInstance<Plasma::Applet>(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
|
||||
|
|
7
applet.h
7
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
|
||||
|
|
25
corona.cpp
25
corona.cpp
|
@ -25,6 +25,7 @@
|
|||
#include <QMimeData>
|
||||
#include <QUrl>
|
||||
#include <QGraphicsView>
|
||||
#include <QStringList>
|
||||
|
||||
#include <KLocale>
|
||||
#include <KMenu>
|
||||
|
@ -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();
|
||||
}
|
||||
|
|
3
corona.h
3
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
|
||||
|
|
Loading…
Reference in New Issue
Block a user