diff --git a/telldus-gui/Plugins/FormLoader/FormLoader.pro b/telldus-gui/Plugins/FormLoader/FormLoader.pro new file mode 100644 index 00000000..c2fce4db --- /dev/null +++ b/telldus-gui/Plugins/FormLoader/FormLoader.pro @@ -0,0 +1,19 @@ +# ------------------------------------------------- +# Project created by QtCreator 2009-03-10T12:16:44 +# ------------------------------------------------- +QT += core \ + gui \ + script +TARGET = FormLoader +TEMPLATE = lib +CONFIG += plugin uitools +SOURCES += formloaderplugin.cpp \ + formloaderobject.cpp +HEADERS += formloaderplugin.h \ + formloaderobject.h +macx { + DESTDIR = ../../TelldusCenter/TelldusCenter.app/Contents/Plugins/script +} +!macx { + DESTDIR = ../../TelldusCenter/Plugins/script +} diff --git a/telldus-gui/Plugins/FormLoader/formloaderobject.cpp b/telldus-gui/Plugins/FormLoader/formloaderobject.cpp new file mode 100644 index 00000000..22760b08 --- /dev/null +++ b/telldus-gui/Plugins/FormLoader/formloaderobject.cpp @@ -0,0 +1,57 @@ +#include "formloaderobject.h" +#include +#include +#include +#include +#include +#include +#include + +FormLoaderObject::FormLoaderObject( QScriptEngine *e, QObject * parent ) + : QObject(parent), + engine(e) +{ +} + +FormLoaderObject::~FormLoaderObject() { +} + +void FormLoaderObject::load( const QString &name ) { + foreach( QString path, qApp->libraryPaths() ) { + QDir dir(path); + if (!dir.cd("Forms")) { + continue; + } + if (!dir.cd(name)) { + continue; + } + if (!dir.exists( QString("%1.ui").arg(name) )) { + qDebug() << "UI-file not found for form" << name; + continue; + } + if (!dir.exists( QString("%1.js").arg(name) )) { + qDebug() << "JS-file not found for form" << name; + continue; + } + QString scriptFileName( dir.filePath(QString("%1.js").arg(name)) ); + QFile scriptFile(scriptFileName); + scriptFile.open(QIODevice::ReadOnly); + engine->evaluate(scriptFile.readAll(), scriptFileName); + scriptFile.close(); + + QUiLoader loader; + QFile uiFile( dir.filePath(QString("%1.ui").arg(name)) ); + uiFile.open( QIODevice::ReadOnly ); + QWidget *ui = loader.load(&uiFile); + uiFile.close(); + + QScriptValue ctor = engine->evaluate(name); + QScriptValue scriptUi = engine->newQObject(ui, QScriptEngine::ScriptOwnership); + QScriptValue calc = ctor.construct(QScriptValueList() << scriptUi); + + ui->show(); + return; + } + qDebug() << "Form" << name << "not found!"; +} + diff --git a/telldus-gui/Plugins/FormLoader/formloaderobject.h b/telldus-gui/Plugins/FormLoader/formloaderobject.h new file mode 100644 index 00000000..ddf492e5 --- /dev/null +++ b/telldus-gui/Plugins/FormLoader/formloaderobject.h @@ -0,0 +1,22 @@ +#ifndef FORMLOADEROBJECT_H +#define FORMLOADEROBJECT_H + +#include + +class QScriptEngine; + +class FormLoaderObject : public QObject +{ + Q_OBJECT +public: + FormLoaderObject( QScriptEngine *engine, QObject * parent = 0 ); + virtual ~FormLoaderObject(); + +public slots: + void load( const QString &name ); + +private: + QScriptEngine *engine; +}; + +#endif // FORMLOADEROBJECT_H diff --git a/telldus-gui/Plugins/FormLoader/formloaderplugin.cpp b/telldus-gui/Plugins/FormLoader/formloaderplugin.cpp new file mode 100644 index 00000000..0e215bb9 --- /dev/null +++ b/telldus-gui/Plugins/FormLoader/formloaderplugin.cpp @@ -0,0 +1,35 @@ +#include "formloaderplugin.h" +#include "formloaderobject.h" +#include +#include + +class FormLoaderPluginPrivate { +public: + FormLoaderObject *formloader; +}; + +FormLoaderPlugin::FormLoaderPlugin ( QObject * parent ) + :QScriptExtensionPlugin( parent ) +{ + d = new FormLoaderPluginPrivate; + d->formloader = 0; +} + +FormLoaderPlugin::~FormLoaderPlugin() { + delete d; +} + +void FormLoaderPlugin::initialize ( const QString & key, QScriptEngine * engine ) { + if (key == "com.telldus.form") { + d->formloader = new FormLoaderObject(engine, this); + + QScriptValue value = engine->newQObject(d->formloader); + engine->globalObject().property("com").property("telldus").setProperty("form", value); + } +} + +QStringList FormLoaderPlugin::keys () const { + return QStringList() << "com.telldus.form"; +} + +Q_EXPORT_PLUGIN2(FormLoaderInterface, FormLoaderPlugin) diff --git a/telldus-gui/Plugins/FormLoader/formloaderplugin.h b/telldus-gui/Plugins/FormLoader/formloaderplugin.h new file mode 100644 index 00000000..5c3cee85 --- /dev/null +++ b/telldus-gui/Plugins/FormLoader/formloaderplugin.h @@ -0,0 +1,21 @@ +#ifndef FORMLOADERPLUGIN_H +#define FORMLOADERPLUGIN_H + +#include + +class FormLoaderPluginPrivate; + +class FormLoaderPlugin : public QScriptExtensionPlugin { +public: + FormLoaderPlugin ( QObject * parent = 0 ); + ~FormLoaderPlugin (); + + virtual void initialize ( const QString & key, QScriptEngine * engine ); + virtual QStringList keys () const; + +private: + FormLoaderPluginPrivate *d; +}; + + +#endif // FORMLOADERPLUGIN_H diff --git a/telldus-gui/Plugins/Plugins.pro b/telldus-gui/Plugins/Plugins.pro index d7a26c19..2f207a5f 100644 --- a/telldus-gui/Plugins/Plugins.pro +++ b/telldus-gui/Plugins/Plugins.pro @@ -1,5 +1,6 @@ TEMPLATE=subdirs SUBDIRS = Devices \ + FormLoader \ Systray \ TouchInterface