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
|
||||
# -------------------------------------------------
|
||||
TEMPLATE = app
|
||||
|
||||
QT += script
|
||||
SOURCES += main.cpp \
|
||||
mainwindow.cpp \
|
||||
tellduscenterapplication.cpp \
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <QDir>
|
||||
#include <QIcon>
|
||||
#include <QPluginLoader>
|
||||
#include <QScriptEngine>
|
||||
|
||||
#include <QDebug>
|
||||
#include <telldus-core.h>
|
||||
|
@ -18,6 +19,7 @@ public:
|
|||
SystrayIcon *systrayIcon;
|
||||
PluginList plugins;
|
||||
QPointer<MainWindow> mainWindow;
|
||||
QScriptEngine scriptEngine;
|
||||
};
|
||||
|
||||
TelldusCenterApplication::TelldusCenterApplication(int &argc, char **argv)
|
||||
|
@ -36,6 +38,7 @@ TelldusCenterApplication::TelldusCenterApplication(int &argc, char **argv)
|
|||
tdRegisterDeviceEvent( &TelldusCenterApplication::deviceEvent, 0 );
|
||||
|
||||
loadPlugins();
|
||||
loadScripts();
|
||||
}
|
||||
|
||||
TelldusCenterApplication::~TelldusCenterApplication() {
|
||||
|
@ -104,7 +107,10 @@ void TelldusCenterApplication::loadPlugins() {
|
|||
pluginsDir.cdUp();
|
||||
}
|
||||
#endif
|
||||
pluginsDir.cd("plugins");
|
||||
if (!pluginsDir.cd("plugins")) {
|
||||
return;
|
||||
}
|
||||
this->addLibraryPath( pluginsDir.absolutePath() );
|
||||
|
||||
foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
|
||||
QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
|
||||
|
@ -129,6 +135,16 @@ void TelldusCenterApplication::loadPlugin(QObject *plugin) {
|
|||
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*/) {
|
||||
char *name = tdGetName(deviceId);
|
||||
QString deviceName(name);
|
||||
|
|
|
@ -44,6 +44,7 @@ private:
|
|||
static void deviceEvent(int deviceId, int method, const char *data, int callbackId, void *context);
|
||||
void loadPlugins();
|
||||
void loadPlugin(QObject *plugin);
|
||||
void loadScripts();
|
||||
|
||||
TelldusCenterApplicationPrivate *d;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue