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:
parent
004c4b029b
commit
e781f69687
12
applet.cpp
12
applet.cpp
@ -164,15 +164,9 @@ public:
|
|||||||
} else {
|
} else {
|
||||||
// create the package and see if we have something real
|
// create the package and see if we have something real
|
||||||
//kDebug() << "trying for" << path;
|
//kDebug() << "trying for" << path;
|
||||||
QString packageFormat = appletDescription.property("X-Plasma-PackageFormat").toString();
|
PackageStructure::Ptr structure = Plasma::packageStructure(language, Plasma::AppletComponent);
|
||||||
|
structure->setPath(path);
|
||||||
if (packageFormat.isEmpty()) {
|
package = new Package(path, structure);
|
||||||
package = new Package(path, PackageStructure::Ptr(new PlasmoidPackage()));
|
|
||||||
} else {
|
|
||||||
PackageStructure::Ptr structure = PackageStructure::load(packageFormat);
|
|
||||||
structure->setPath(path);
|
|
||||||
package = new Package(path, structure);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (package->isValid()) {
|
if (package->isValid()) {
|
||||||
// now we try and set up the script engine.
|
// now we try and set up the script engine.
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "applet.h"
|
#include "applet.h"
|
||||||
#include "dataengine.h"
|
#include "dataengine.h"
|
||||||
#include "package.h"
|
#include "package.h"
|
||||||
|
#include "packages_p.h"
|
||||||
#include "scripting/appletscript.h"
|
#include "scripting/appletscript.h"
|
||||||
#include "scripting/dataenginescript.h"
|
#include "scripting/dataenginescript.h"
|
||||||
#include "scripting/runnerscript.h"
|
#include "scripting/runnerscript.h"
|
||||||
@ -96,16 +97,16 @@ QStringList knownLanguages(ComponentTypes types)
|
|||||||
return languages;
|
return languages;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptEngine* loadEngine(const QString &language, ComponentType type, QObject *parent)
|
KService::List engineOffers(const QString &language, ComponentType type)
|
||||||
{
|
{
|
||||||
if (language.isEmpty()) {
|
if (language.isEmpty()) {
|
||||||
return 0;
|
return KService::List();
|
||||||
}
|
}
|
||||||
|
|
||||||
QRegExp re("[^a-zA-Z0-9\\-_]");
|
QRegExp re("[^a-zA-Z0-9\\-_]");
|
||||||
if (re.indexIn(language) != -1) {
|
if (re.indexIn(language) != -1) {
|
||||||
kDebug() << "invalid language attempted:" << language;
|
kDebug() << "invalid language attempted:" << language;
|
||||||
return 0;
|
return KService::List();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString component;
|
QString component;
|
||||||
@ -120,7 +121,7 @@ ScriptEngine* loadEngine(const QString &language, ComponentType type, QObject *p
|
|||||||
component = "Runner";
|
component = "Runner";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return 0;
|
return KService::List();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,9 +132,15 @@ ScriptEngine* loadEngine(const QString &language, ComponentType type, QObject *p
|
|||||||
<< "resulting in" << offers.count() << "results";*/
|
<< "resulting in" << offers.count() << "results";*/
|
||||||
if (offers.isEmpty()) {
|
if (offers.isEmpty()) {
|
||||||
kDebug() << "ScriptEngine::load: no offers for \"" << language << "\"";
|
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;
|
QVariantList args;
|
||||||
QString error;
|
QString error;
|
||||||
|
|
||||||
@ -197,6 +204,39 @@ RunnerScript* loadScriptEngine(const QString &language, AbstractRunner *runner)
|
|||||||
return engine;
|
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
|
} // namespace Plasma
|
||||||
|
|
||||||
#include <scriptengine.moc>
|
#include <scriptengine.moc>
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#define PLASMA_SCRIPTENGINE_H
|
#define PLASMA_SCRIPTENGINE_H
|
||||||
|
|
||||||
#include <plasma/plasma_export.h>
|
#include <plasma/plasma_export.h>
|
||||||
|
#include <plasma/packagestructure.h>
|
||||||
#include <plasma/plasma.h>
|
#include <plasma/plasma.h>
|
||||||
|
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
@ -111,6 +112,15 @@ DataEngineScript* loadScriptEngine(const QString &language, DataEngine *dataEngi
|
|||||||
**/
|
**/
|
||||||
RunnerScript* loadScriptEngine(const QString &language, AbstractRunner *runner);
|
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
|
} // namespace Plasma
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user