Package replaces PackageStructure+Package

This commit is contained in:
Aaron Seigo 2011-07-15 13:04:16 +02:00
parent 722c77e7ce
commit 94e4f35208
10 changed files with 20 additions and 84 deletions

View File

@ -186,7 +186,7 @@ Animation *AppletScript::loadAnimationFromPackage(const QString &name, QObject *
if (applet()) {
const QString scopedName = applet()->pluginName() + ":" + name;
if (!AnimationScriptEngine::isAnimationRegistered(scopedName)) {
KConfig conf(applet()->package()->path() + "/metadata.desktop", KConfig::SimpleConfig);
KConfig conf(applet()->package().path() + "/metadata.desktop", KConfig::SimpleConfig);
KConfigGroup animConf(&conf, "Animations");
QString file;
foreach (const QString &possibleFile, animConf.keyList()) {
@ -201,7 +201,7 @@ Animation *AppletScript::loadAnimationFromPackage(const QString &name, QObject *
return 0;
}
const QString path = applet()->package()->filePath("animations", file);
const QString path = applet()->package().filePath("animations", file);
if (path.isEmpty()) {
kDebug() << "file path was empty for" << file;
return 0;
@ -234,10 +234,10 @@ DataEngine *AppletScript::dataEngine(const QString &engine) const
QString AppletScript::mainScript() const
{
Q_ASSERT(d->applet);
return d->applet->package()->filePath("mainscript");
return d->applet->package().filePath("mainscript");
}
const Package *AppletScript::package() const
Package AppletScript::package() const
{
Q_ASSERT(d->applet);
return d->applet->package();

View File

@ -210,7 +210,7 @@ protected:
* be used to request resources, such as images and
* interface files.
*/
const Package *package() const;
Package package() const;
/**
* @return the KPluginInfo associated with this plasmoid

View File

@ -79,10 +79,10 @@ Service *DataEngineScript::serviceForSource(const QString &source)
QString DataEngineScript::mainScript() const
{
Q_ASSERT(d->dataEngine);
return d->dataEngine->package()->filePath("mainscript");
return d->dataEngine->package().filePath("mainscript");
}
const Package *DataEngineScript::package() const
Package DataEngineScript::package() const
{
Q_ASSERT(d->dataEngine);
return d->dataEngine->package();

View File

@ -109,7 +109,7 @@ protected:
* be used to request resources, such as images and
* interface files.
*/
const Package *package() const;
Package package() const;
/**
* @return the KPluginInfo associated with this plasmoid

View File

@ -171,9 +171,9 @@ void RunnerScript::setSyntaxes(const QList<RunnerSyntax> &syns)
}
}
const Package *RunnerScript::package() const
Package RunnerScript::package() const
{
return d->runner ? d->runner->package() : 0;
return d->runner ? d->runner->package() : Package();
}
KPluginInfo RunnerScript::description() const
@ -183,11 +183,7 @@ KPluginInfo RunnerScript::description() const
QString RunnerScript::mainScript() const
{
if (!package()) {
return QString();
} else {
return package()->filePath("mainscript");
}
return package().filePath("mainscript");
}
} // Plasma namespace

View File

@ -94,7 +94,7 @@ protected:
* be used to request resources, such as images and
* interface files.
*/
const Package *package() const;
Package package() const;
/**
* @return the KPluginInfo associated with this plasmoid

View File

@ -32,8 +32,6 @@
#include "scripting/runnerscript.h"
#include "scripting/wallpaperscript.h"
#include "private/packages_p.h"
namespace Plasma
{
@ -53,9 +51,9 @@ bool ScriptEngine::init()
return true;
}
const Package *ScriptEngine::package() const
Package ScriptEngine::package() const
{
return 0;
return Package();
}
QString ScriptEngine::mainScript() const
@ -225,8 +223,7 @@ DataEngineScript *loadScriptEngine(const QString &language, DataEngine *dataEngi
RunnerScript *loadScriptEngine(const QString &language, AbstractRunner *runner)
{
RunnerScript *engine =
static_cast<RunnerScript*>(loadEngine(language, RunnerComponent, runner));
RunnerScript *engine = static_cast<RunnerScript*>(loadEngine(language, RunnerComponent, runner));
if (engine) {
engine->setRunner(runner);
@ -247,44 +244,6 @@ WallpaperScript *loadScriptEngine(const QString &language, Wallpaper *wallpaper)
return engine;
}
PackageStructure::Ptr defaultPackageStructure(ComponentType type)
{
switch (type) {
case AppletComponent:
case WallpaperComponent:
case RunnerComponent:
return PackageStructure::Ptr(new PlasmoidPackage());
break;
case DataEngineComponent:
return PackageStructure::Ptr(new DataEnginePackage());
break;
default:
// TODO: we don't have any special structures for other components yet
break;
}
return PackageStructure::Ptr(new PackageStructure());
}
PackageStructure::Ptr packageStructure(const QString &language, ComponentType type)
{
KService::List offers = engineOffers(language, type);
if (offers.isEmpty()) {
return defaultPackageStructure(type);
}
KService::Ptr offer = offers.first();
QString packageFormat = offer->property("X-Plasma-PackageFormat").toString();
if (packageFormat.isEmpty()) {
return defaultPackageStructure(type);
} else {
PackageStructure::Ptr structure = PackageStructure::load(packageFormat);
return structure;
}
}
} // namespace Plasma
#include <scriptengine.moc>

View File

@ -20,8 +20,8 @@
#ifndef PLASMA_SCRIPTENGINE_H
#define PLASMA_SCRIPTENGINE_H
#include <plasma/package.h>
#include <plasma/plasma_export.h>
#include <plasma/packagestructure.h>
#include <plasma/plasma.h>
#include <QtCore/QObject>
@ -42,7 +42,6 @@ class DataEngineScript;
class RunnerScript;
class Wallpaper;
class WallpaperScript;
class Package;
class ScriptEnginePrivate;
/**
@ -50,16 +49,6 @@ class ScriptEnginePrivate;
*
* @short The base class for scripting interfaces to be used in loading
* plasmoids of a given language.
*
* All ScriptEngines should export as consistent an interface as possible
* so that the learning curve is limited. In particular, the following
* API should be made available in the script environment:
*
* TODO: define the actual scripting APIas ...
* PlasmaApplet - the applet of this plasmoid
* LoadUserInterface(String uiFile) - loads and returns a given UI file
* LoadImage - loads an image resource out of the plasmoid's package
* PlasmaSvg - creates and returns an Svg file
**/
class PLASMA_EXPORT ScriptEngine : public QObject
@ -87,7 +76,7 @@ protected:
* be used to request resources, such as images and
* interface files.
*/
virtual const Package *package() const;
virtual Package package() const;
private:
ScriptEnginePrivate *const d;
@ -140,14 +129,6 @@ PLASMA_EXPORT RunnerScript *loadScriptEngine(const QString &language, AbstractRu
**/
PLASMA_EXPORT WallpaperScript *loadScriptEngine(const QString &language, Wallpaper *wallpaper);
/**
* Loads an appropriate PackageStructure for the given language and type
*
* @param language the language to load the PackageStructure for
* @param type the component type
* @return a guarded PackageStructure pointer
*/
PLASMA_EXPORT PackageStructure::Ptr packageStructure(const QString &language, ComponentType type);
} // namespace Plasma

View File

@ -57,10 +57,10 @@ Wallpaper *WallpaperScript::wallpaper() const
QString WallpaperScript::mainScript() const
{
Q_ASSERT(d->wallpaper);
return d->wallpaper->package()->filePath("mainscript");
return d->wallpaper->package().filePath("mainscript");
}
const Package *WallpaperScript::package() const
Package WallpaperScript::package() const
{
Q_ASSERT(d->wallpaper);
return d->wallpaper->package();

View File

@ -153,7 +153,7 @@ protected:
* be used to request resources, such as images and
* interface files.
*/
const Package *package() const;
Package package() const;
/**
* @return the KPluginInfo associated with this wallpaper