make PackageStructure loading actually work and abstract that all away into a cute little method elsewhere

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=793416
This commit is contained in:
Aaron J. Seigo 2008-04-03 22:45:09 +00:00
parent 004c4b029b
commit e781f69687
3 changed files with 58 additions and 14 deletions

View File

@ -164,15 +164,9 @@ public:
} else {
// create the package and see if we have something real
//kDebug() << "trying for" << path;
QString packageFormat = appletDescription.property("X-Plasma-PackageFormat").toString();
if (packageFormat.isEmpty()) {
package = new Package(path, PackageStructure::Ptr(new PlasmoidPackage()));
} else {
PackageStructure::Ptr structure = PackageStructure::load(packageFormat);
structure->setPath(path);
package = new Package(path, structure);
}
PackageStructure::Ptr structure = Plasma::packageStructure(language, Plasma::AppletComponent);
structure->setPath(path);
package = new Package(path, structure);
if (package->isValid()) {
// now we try and set up the script engine.

View File

@ -27,6 +27,7 @@
#include "applet.h"
#include "dataengine.h"
#include "package.h"
#include "packages_p.h"
#include "scripting/appletscript.h"
#include "scripting/dataenginescript.h"
#include "scripting/runnerscript.h"
@ -96,16 +97,16 @@ QStringList knownLanguages(ComponentTypes types)
return languages;
}
ScriptEngine* loadEngine(const QString &language, ComponentType type, QObject *parent)
KService::List engineOffers(const QString &language, ComponentType type)
{
if (language.isEmpty()) {
return 0;
return KService::List();
}
QRegExp re("[^a-zA-Z0-9\\-_]");
if (re.indexIn(language) != -1) {
kDebug() << "invalid language attempted:" << language;
return 0;
return KService::List();
}
QString component;
@ -120,7 +121,7 @@ ScriptEngine* loadEngine(const QString &language, ComponentType type, QObject *p
component = "Runner";
break;
default:
return 0;
return KService::List();
break;
}
@ -131,9 +132,15 @@ ScriptEngine* loadEngine(const QString &language, ComponentType type, QObject *p
<< "resulting in" << offers.count() << "results";*/
if (offers.isEmpty()) {
kDebug() << "ScriptEngine::load: no offers for \"" << language << "\"";
return 0;
}
return offers;
}
ScriptEngine* loadEngine(const QString &language, ComponentType type, QObject *parent)
{
KService::List offers = engineOffers(language, type);
QVariantList args;
QString error;
@ -197,6 +204,39 @@ RunnerScript* loadScriptEngine(const QString &language, AbstractRunner *runner)
return engine;
}
PackageStructure::Ptr defaultPackageStructure(ComponentType type)
{
switch (type) {
case AppletComponent:
return PackageStructure::Ptr(new PlasmoidPackage());
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

@ -21,6 +21,7 @@
#define PLASMA_SCRIPTENGINE_H
#include <plasma/plasma_export.h>
#include <plasma/packagestructure.h>
#include <plasma/plasma.h>
#include <QtCore/QObject>
@ -111,6 +112,15 @@ DataEngineScript* loadScriptEngine(const QString &language, DataEngine *dataEngi
**/
RunnerScript* loadScriptEngine(const QString &language, AbstractRunner *runner);
/**
* Loads an appropriate PackageStructure for the given language and type
*
* @param langauge the language to load the PackageStructure for
* @param type the component type
* @return a guarded PackageStructure pointer
*/
PackageStructure::Ptr packageStructure(const QString &language, ComponentType type);
} // namespace Plasma
#endif