2008-01-25 01:04:03 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2007 by Aaron Seigo <aseigo@kde.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PLASMA_SCRIPTENGINE_H
|
|
|
|
#define PLASMA_SCRIPTENGINE_H
|
|
|
|
|
|
|
|
#include <plasma/plasma_export.h>
|
2008-04-04 00:45:09 +02:00
|
|
|
#include <plasma/packagestructure.h>
|
2008-01-25 01:04:03 +01:00
|
|
|
#include <plasma/plasma.h>
|
|
|
|
|
|
|
|
#include <QtCore/QObject>
|
|
|
|
#include <QtCore/QRect>
|
|
|
|
#include <QtCore/QSizeF>
|
|
|
|
|
|
|
|
class QPainter;
|
|
|
|
class QStyleOptionGraphicsItem;
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
class AbstractRunner;
|
|
|
|
class Applet;
|
|
|
|
class AppletScript;
|
|
|
|
class DataEngine;
|
|
|
|
class DataEngineScript;
|
|
|
|
class RunnerScript;
|
|
|
|
class Package;
|
2008-07-01 20:56:43 +02:00
|
|
|
class ScriptEnginePrivate;
|
2008-01-25 01:04:03 +01:00
|
|
|
|
|
|
|
/**
|
2008-08-25 19:47:48 +02:00
|
|
|
* @class ScriptEngine plasma/scripting/scriptengine.h <Plasma/Scripting/ScriptEngine>
|
|
|
|
*
|
|
|
|
* @short The base class for scripting interfaces to be used in loading
|
2008-01-25 01:04:03 +01:00
|
|
|
* 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
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
~ScriptEngine();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when it is safe to initialize the internal state of the engine
|
|
|
|
*/
|
|
|
|
virtual bool init();
|
|
|
|
|
2008-04-27 15:47:59 +02:00
|
|
|
protected:
|
2008-04-27 15:50:49 +02:00
|
|
|
explicit ScriptEngine(QObject *parent = 0);
|
|
|
|
|
2008-04-13 16:41:52 +02:00
|
|
|
/**
|
|
|
|
* @return absolute path to the main script file for this plasmoid
|
|
|
|
*/
|
|
|
|
virtual QString mainScript() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the Package associated with this plasmoid which can
|
|
|
|
* be used to request resources, such as images and
|
|
|
|
* interface files.
|
|
|
|
*/
|
|
|
|
virtual const Package* package() const;
|
|
|
|
|
2008-01-25 01:04:03 +01:00
|
|
|
private:
|
2008-07-01 20:56:43 +02:00
|
|
|
ScriptEnginePrivate * const d;
|
2008-01-25 01:04:03 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @arg types a set of ComponentTypes flags for which to look up the
|
|
|
|
* language support for
|
|
|
|
* @return a list of all supported languages for the given type(s).
|
|
|
|
**/
|
2008-05-13 11:39:19 +02:00
|
|
|
PLASMA_EXPORT QStringList knownLanguages(ComponentTypes types);
|
2008-01-25 01:04:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads an Applet script engine for the given language.
|
|
|
|
*
|
|
|
|
* @param language the language to load for
|
|
|
|
* @param applet the Plasma::Applet for this script
|
|
|
|
* @return pointer to the AppletScript or 0 on failure; the caller is responsible
|
|
|
|
* for the return object which will be parented to the Applet
|
|
|
|
**/
|
2008-05-13 11:39:19 +02:00
|
|
|
PLASMA_EXPORT AppletScript* loadScriptEngine(const QString &language, Applet *applet);
|
2008-01-25 01:04:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads an DataEngine script engine for the given language.
|
|
|
|
*
|
|
|
|
* @param language the language to load for
|
|
|
|
* @param dataEngine the Plasma::DataEngine for this script;
|
|
|
|
* @return pointer to the DataEngineScript or 0 on failure; the caller is responsible
|
|
|
|
* for the return object which will be parented to the DataEngine
|
|
|
|
**/
|
2008-05-13 11:39:19 +02:00
|
|
|
PLASMA_EXPORT DataEngineScript* loadScriptEngine(const QString &language, DataEngine *dataEngine);
|
2008-01-25 01:04:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads an Applet script engine for the given language.
|
|
|
|
*
|
|
|
|
* @param language the language to load for
|
|
|
|
* @param runner the Plasma::AbstractRunner for this script
|
|
|
|
* @return pointer to the RunnerScript or 0 on failure; the caller is responsible
|
|
|
|
* for the return object which will be parented to the AbstractRunner
|
|
|
|
**/
|
2008-05-13 11:39:19 +02:00
|
|
|
PLASMA_EXPORT RunnerScript* loadScriptEngine(const QString &language, AbstractRunner *runner);
|
2008-01-25 01:04:03 +01:00
|
|
|
|
2008-04-04 00:45:09 +02:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2008-05-13 11:39:19 +02:00
|
|
|
PLASMA_EXPORT PackageStructure::Ptr packageStructure(const QString &language, ComponentType type);
|
2008-04-04 00:45:09 +02:00
|
|
|
|
2008-01-25 01:04:03 +01:00
|
|
|
} // namespace Plasma
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|