allow loading applets from packages directly

svn path=/trunk/KDE/kdelibs/; revision=959317
This commit is contained in:
Aaron J. Seigo 2009-04-26 00:43:20 +00:00
parent 1ceabde6ea
commit d4c7994472
3 changed files with 54 additions and 15 deletions

View File

@ -94,9 +94,7 @@
namespace Plasma
{
Applet::Applet(QGraphicsItem *parent,
const QString &serviceID,
uint appletId)
Applet::Applet(QGraphicsItem *parent, const QString &serviceID, uint appletId)
: QGraphicsWidget(parent),
d(new AppletPrivate(KService::serviceByStorageId(serviceID), appletId, this))
{
@ -1733,6 +1731,23 @@ QStringList Applet::listCategories(const QString &parentApp, bool visibleOnly)
return categories;
}
Applet::Applet(const QString &packagePath, uint appletId, const QVariantList &args)
: QGraphicsWidget(0),
d(new AppletPrivate(KService::Ptr(new KService(packagePath + "/metadata.desktop")), appletId, this))
{
Q_UNUSED(args) // FIXME?
d->init(packagePath);
}
Applet *Applet::loadPlasmoid(const QString &path, uint appletId, const QVariantList &args)
{
if (QFile::exists(path + "/metadata.desktop")) {
return new Applet(path, appletId, args);
}
return 0;
}
Applet *Applet::load(const QString &appletName, uint appletId, const QVariantList &args)
{
if (appletName.isEmpty()) {
@ -2058,7 +2073,7 @@ AppletPrivate::~AppletPrivate()
mainConfig = 0;
}
void AppletPrivate::init()
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
@ -2082,9 +2097,10 @@ void AppletPrivate::init()
// we have a scripted plasmoid
if (!api.isEmpty()) {
// find where the Package is
QString path = KStandardDirs::locate(
"data",
"plasma/plasmoids/" + appletDescription.pluginName() + '/');
QString path = packagePath;
if (path.isEmpty()) {
KStandardDirs::locate("data", "plasma/plasmoids/" + appletDescription.pluginName() + '/');
}
if (path.isEmpty()) {
q->setFailedToLaunch(
@ -2095,8 +2111,7 @@ void AppletPrivate::init()
} else {
// create the package and see if we have something real
//kDebug() << "trying for" << path;
PackageStructure::Ptr structure =
Plasma::packageStructure(api, Plasma::AppletComponent);
PackageStructure::Ptr structure = Plasma::packageStructure(api, Plasma::AppletComponent);
structure->setPath(path);
package = new Package(path, structure);
@ -2129,9 +2144,7 @@ void AppletPrivate::init()
}
q->setBackgroundHints(Applet::DefaultBackground);
q->setHasConfigurationInterface(true);
QObject::connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), q, SLOT(themeChanged()));
}

View File

@ -310,6 +310,23 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
static QStringList listCategories(const QString &parentApp = QString(),
bool visibleOnly = true);
/**
* Attempts to load an apppet from a package
*
* Returns a pointer to the applet if successful.
* The caller takes responsibility for the applet, including
* deleting it when no longer needed.
*
* @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());
/**
* Attempts to load an applet
*
@ -572,8 +589,7 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
explicit Applet(QGraphicsItem *parent,
const QString &serviceId,
uint appletId,
const QVariantList &args
);
const QVariantList &args);
/**
@ -907,6 +923,16 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
void timerEvent (QTimerEvent *event);
private:
/**
* @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
*/
Applet(const QString &packagePath, uint appletId, const QVariantList &args);
Q_PRIVATE_SLOT(d, void setFocus())
Q_PRIVATE_SLOT(d, void checkImmutability())
Q_PRIVATE_SLOT(d, void themeChanged())

View File

@ -62,7 +62,7 @@ public:
AppletPrivate(KService::Ptr service, int uniqueID, Applet *applet);
~AppletPrivate();
void init();
void init(const QString &packagePath = QString());
// put all setup routines for script here. at this point we can assume that
// package exists and that we have a script engin