allow loading applets from packages directly
svn path=/trunk/KDE/kdelibs/; revision=959317
This commit is contained in:
parent
1ceabde6ea
commit
d4c7994472
35
applet.cpp
35
applet.cpp
@ -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()));
|
||||
}
|
||||
|
||||
|
32
applet.h
32
applet.h
@ -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
|
||||
*
|
||||
@ -567,13 +584,12 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
||||
* instances of the same Applet type
|
||||
* @param args a list of strings containing two entries: the service id
|
||||
* and the applet id
|
||||
* @since KDE4.3
|
||||
* @since KDE4.3
|
||||
*/
|
||||
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())
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user