Added FormLoader plugin
This commit is contained in:
parent
46a8eddd95
commit
ad60c6978a
6 changed files with 155 additions and 0 deletions
19
telldus-gui/Plugins/FormLoader/FormLoader.pro
Normal file
19
telldus-gui/Plugins/FormLoader/FormLoader.pro
Normal file
|
@ -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
|
||||||
|
}
|
57
telldus-gui/Plugins/FormLoader/formloaderobject.cpp
Normal file
57
telldus-gui/Plugins/FormLoader/formloaderobject.cpp
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
#include "formloaderobject.h"
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QScriptEngine>
|
||||||
|
#include <QUiLoader>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
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!";
|
||||||
|
}
|
||||||
|
|
22
telldus-gui/Plugins/FormLoader/formloaderobject.h
Normal file
22
telldus-gui/Plugins/FormLoader/formloaderobject.h
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef FORMLOADEROBJECT_H
|
||||||
|
#define FORMLOADEROBJECT_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
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
|
35
telldus-gui/Plugins/FormLoader/formloaderplugin.cpp
Normal file
35
telldus-gui/Plugins/FormLoader/formloaderplugin.cpp
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
#include "formloaderplugin.h"
|
||||||
|
#include "formloaderobject.h"
|
||||||
|
#include <QScriptEngine>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
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)
|
21
telldus-gui/Plugins/FormLoader/formloaderplugin.h
Normal file
21
telldus-gui/Plugins/FormLoader/formloaderplugin.h
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#ifndef FORMLOADERPLUGIN_H
|
||||||
|
#define FORMLOADERPLUGIN_H
|
||||||
|
|
||||||
|
#include <QScriptExtensionPlugin>
|
||||||
|
|
||||||
|
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
|
|
@ -1,5 +1,6 @@
|
||||||
TEMPLATE=subdirs
|
TEMPLATE=subdirs
|
||||||
SUBDIRS = Devices \
|
SUBDIRS = Devices \
|
||||||
|
FormLoader \
|
||||||
Systray \
|
Systray \
|
||||||
TouchInterface
|
TouchInterface
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue