Added QScript to TelldusCenter
This commit is contained in:
parent
755f212e1f
commit
bc623ef529
3 changed files with 19 additions and 2 deletions
|
@ -2,7 +2,7 @@
|
||||||
# Project created by QtCreator 2008-12-11T11:01:36
|
# Project created by QtCreator 2008-12-11T11:01:36
|
||||||
# -------------------------------------------------
|
# -------------------------------------------------
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
|
QT += script
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
mainwindow.cpp \
|
mainwindow.cpp \
|
||||||
tellduscenterapplication.cpp \
|
tellduscenterapplication.cpp \
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QPluginLoader>
|
#include <QPluginLoader>
|
||||||
|
#include <QScriptEngine>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <telldus-core.h>
|
#include <telldus-core.h>
|
||||||
|
@ -18,6 +19,7 @@ public:
|
||||||
SystrayIcon *systrayIcon;
|
SystrayIcon *systrayIcon;
|
||||||
PluginList plugins;
|
PluginList plugins;
|
||||||
QPointer<MainWindow> mainWindow;
|
QPointer<MainWindow> mainWindow;
|
||||||
|
QScriptEngine scriptEngine;
|
||||||
};
|
};
|
||||||
|
|
||||||
TelldusCenterApplication::TelldusCenterApplication(int &argc, char **argv)
|
TelldusCenterApplication::TelldusCenterApplication(int &argc, char **argv)
|
||||||
|
@ -36,6 +38,7 @@ TelldusCenterApplication::TelldusCenterApplication(int &argc, char **argv)
|
||||||
tdRegisterDeviceEvent( &TelldusCenterApplication::deviceEvent, 0 );
|
tdRegisterDeviceEvent( &TelldusCenterApplication::deviceEvent, 0 );
|
||||||
|
|
||||||
loadPlugins();
|
loadPlugins();
|
||||||
|
loadScripts();
|
||||||
}
|
}
|
||||||
|
|
||||||
TelldusCenterApplication::~TelldusCenterApplication() {
|
TelldusCenterApplication::~TelldusCenterApplication() {
|
||||||
|
@ -104,7 +107,10 @@ void TelldusCenterApplication::loadPlugins() {
|
||||||
pluginsDir.cdUp();
|
pluginsDir.cdUp();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
pluginsDir.cd("plugins");
|
if (!pluginsDir.cd("plugins")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this->addLibraryPath( pluginsDir.absolutePath() );
|
||||||
|
|
||||||
foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
|
foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
|
||||||
QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
|
QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
|
||||||
|
@ -129,6 +135,16 @@ void TelldusCenterApplication::loadPlugin(QObject *plugin) {
|
||||||
d->plugins.append(iPlugin);
|
d->plugins.append(iPlugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TelldusCenterApplication::loadScripts() {
|
||||||
|
foreach (QString extension, d->scriptEngine.availableExtensions()) {
|
||||||
|
d->scriptEngine.importExtension( extension );
|
||||||
|
if (d->scriptEngine.hasUncaughtException()) {
|
||||||
|
qDebug() << QString("Error in %1:%2:").arg(extension).arg(d->scriptEngine.uncaughtExceptionLineNumber())
|
||||||
|
<< d->scriptEngine.uncaughtException().toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TelldusCenterApplication::deviceEvent(int deviceId, int method, const QString &/*data*/) {
|
void TelldusCenterApplication::deviceEvent(int deviceId, int method, const QString &/*data*/) {
|
||||||
char *name = tdGetName(deviceId);
|
char *name = tdGetName(deviceId);
|
||||||
QString deviceName(name);
|
QString deviceName(name);
|
||||||
|
|
|
@ -44,6 +44,7 @@ private:
|
||||||
static void deviceEvent(int deviceId, int method, const char *data, int callbackId, void *context);
|
static void deviceEvent(int deviceId, int method, const char *data, int callbackId, void *context);
|
||||||
void loadPlugins();
|
void loadPlugins();
|
||||||
void loadPlugin(QObject *plugin);
|
void loadPlugin(QObject *plugin);
|
||||||
|
void loadScripts();
|
||||||
|
|
||||||
TelldusCenterApplicationPrivate *d;
|
TelldusCenterApplicationPrivate *d;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue