Added configuration dialog
This commit is contained in:
parent
6281cf8b95
commit
68f55ac85d
7 changed files with 66 additions and 16 deletions
|
@ -9,6 +9,7 @@ endif(COMMAND cmake_policy)
|
||||||
|
|
||||||
######## Non configurable options ########
|
######## Non configurable options ########
|
||||||
SET( telldus-center_SRCS
|
SET( telldus-center_SRCS
|
||||||
|
configurationdialog.cpp
|
||||||
main.cpp
|
main.cpp
|
||||||
mainwindow.cpp
|
mainwindow.cpp
|
||||||
scriptenvironment.cpp
|
scriptenvironment.cpp
|
||||||
|
@ -26,6 +27,7 @@ SET( telldus-center_HDRS
|
||||||
)
|
)
|
||||||
|
|
||||||
SET( telldus-center_MOC_HDRS
|
SET( telldus-center_MOC_HDRS
|
||||||
|
configurationdialog.h
|
||||||
mainwindow.h
|
mainwindow.h
|
||||||
scriptenvironment.h
|
scriptenvironment.h
|
||||||
tellduscenterapplication.h
|
tellduscenterapplication.h
|
||||||
|
|
11
telldus-gui/TelldusCenter/configurationdialog.cpp
Normal file
11
telldus-gui/TelldusCenter/configurationdialog.cpp
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#include "configurationdialog.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
ConfigurationDialog::ConfigurationDialog(QWidget *parent) :
|
||||||
|
QDialog(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigurationDialog::open() {
|
||||||
|
this->exec();
|
||||||
|
}
|
19
telldus-gui/TelldusCenter/configurationdialog.h
Normal file
19
telldus-gui/TelldusCenter/configurationdialog.h
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#ifndef CONFIGURATIONDIALOG_H
|
||||||
|
#define CONFIGURATIONDIALOG_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
|
||||||
|
class ConfigurationDialog : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ConfigurationDialog(QWidget *parent = 0);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void open();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CONFIGURATIONDIALOG_H
|
|
@ -9,12 +9,14 @@
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QCloseEvent>
|
#include <QCloseEvent>
|
||||||
|
#include <QScriptEngine>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include "tellduscenterapplication.h"
|
#include "tellduscenterapplication.h"
|
||||||
#include "tellduscenterplugin.h"
|
#include "tellduscenterplugin.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "plugintree.h"
|
#include "plugintree.h"
|
||||||
|
#include "scriptenvironment.h"
|
||||||
|
|
||||||
#define VERSION_STRING_HELPER(X) #X
|
#define VERSION_STRING_HELPER(X) #X
|
||||||
#define VERSION_STRING(X) VERSION_STRING_HELPER(X)
|
#define VERSION_STRING(X) VERSION_STRING_HELPER(X)
|
||||||
|
@ -26,15 +28,17 @@ public:
|
||||||
QStackedLayout *stackedLayout;
|
QStackedLayout *stackedLayout;
|
||||||
PluginTree pluginTree;
|
PluginTree pluginTree;
|
||||||
QActionGroup *pagesActionGroup;
|
QActionGroup *pagesActionGroup;
|
||||||
|
ScriptEnvironment *env;
|
||||||
};
|
};
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent, Qt::WFlags flags)
|
MainWindow::MainWindow(ScriptEnvironment *env, QWidget *parent, Qt::WFlags flags)
|
||||||
: QMainWindow(parent, flags)
|
: QMainWindow(parent, flags)
|
||||||
{
|
{
|
||||||
d = new MainWindowPrivate;
|
d = new MainWindowPrivate;
|
||||||
d->pagesActionGroup = new QActionGroup( this );
|
d->pagesActionGroup = new QActionGroup( this );
|
||||||
d->message = new Message();
|
d->message = new Message();
|
||||||
connect(qApp, SIGNAL(showMessage(QString,QString,QString)), d->message, SLOT(showMessage(QString,QString,QString)));
|
connect(qApp, SIGNAL(showMessage(QString,QString,QString)), d->message, SLOT(showMessage(QString,QString,QString)));
|
||||||
|
d->env = env;
|
||||||
|
|
||||||
//setAttribute(Qt::WA_DeleteOnClose, true);
|
//setAttribute(Qt::WA_DeleteOnClose, true);
|
||||||
|
|
||||||
|
@ -81,6 +85,8 @@ void MainWindow::setupMenu() {
|
||||||
|
|
||||||
// File
|
// File
|
||||||
QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
|
QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
|
||||||
|
QAction *config = fileMenu->addAction(tr("&Configure"), this, SLOT(slotConfigure()));
|
||||||
|
fileMenu->addSeparator();
|
||||||
QAction *quit = fileMenu->addAction(tr("&Quit"), qApp, SLOT(quit()));
|
QAction *quit = fileMenu->addAction(tr("&Quit"), qApp, SLOT(quit()));
|
||||||
quit->setMenuRole( QAction::QuitRole );
|
quit->setMenuRole( QAction::QuitRole );
|
||||||
|
|
||||||
|
@ -130,6 +136,10 @@ void MainWindow::slotAboutApplication() {
|
||||||
"<p>Copyright © 2010 Telldus Technologies AB<p></center>").arg(VERSION_STRING(VERSION)));
|
"<p>Copyright © 2010 Telldus Technologies AB<p></center>").arg(VERSION_STRING(VERSION)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::slotConfigure() {
|
||||||
|
d->env->engine()->evaluate("application.configuration.open();");
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::slotPagesClick() {
|
void MainWindow::slotPagesClick() {
|
||||||
QAction *action = qobject_cast<QAction *>(sender());
|
QAction *action = qobject_cast<QAction *>(sender());
|
||||||
if (action) {
|
if (action) {
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
class QToolBar;
|
class QToolBar;
|
||||||
class Message;
|
class Message;
|
||||||
|
class ScriptEnvironment;
|
||||||
|
|
||||||
class MainWindowPrivate;
|
class MainWindowPrivate;
|
||||||
|
|
||||||
|
@ -14,7 +15,7 @@ class MainWindow : public QMainWindow
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MainWindow(QWidget *parent = 0, Qt::WFlags flags = 0);
|
MainWindow(ScriptEnvironment *env, QWidget *parent = 0, Qt::WFlags flags = 0);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
@ -25,6 +26,7 @@ protected:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void slotAboutApplication();
|
void slotAboutApplication();
|
||||||
|
void slotConfigure();
|
||||||
void slotPagesClick();
|
void slotPagesClick();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "scriptenvironment.h"
|
#include "scriptenvironment.h"
|
||||||
|
#include "configurationdialog.h"
|
||||||
#include <QScriptEngine>
|
#include <QScriptEngine>
|
||||||
#include <QScriptValueIterator>
|
#include <QScriptValueIterator>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
@ -35,6 +36,13 @@ ScriptEnvironment::ScriptEnvironment(QObject *parent) :
|
||||||
self.setProperty("self", self);
|
self.setProperty("self", self);
|
||||||
d->scriptEngine.setGlobalObject(self);
|
d->scriptEngine.setGlobalObject(self);
|
||||||
|
|
||||||
|
QScriptValue application = d->scriptEngine.newQObject(parent);
|
||||||
|
d->scriptEngine.globalObject().setProperty("application", application);
|
||||||
|
|
||||||
|
//Create configuration dialog
|
||||||
|
QScriptValue configurationDialogObject = d->scriptEngine.newQObject(new ConfigurationDialog(), QScriptEngine::ScriptOwnership, QScriptEngine::ExcludeSuperClassContents);
|
||||||
|
d->scriptEngine.globalObject().property("application").setProperty("configuration", configurationDialogObject);
|
||||||
|
|
||||||
//Collect garbage (ie our old global object)
|
//Collect garbage (ie our old global object)
|
||||||
d->scriptEngine.collectGarbage();
|
d->scriptEngine.collectGarbage();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ class TelldusCenterApplicationPrivate {
|
||||||
public:
|
public:
|
||||||
PluginList plugins;
|
PluginList plugins;
|
||||||
MainWindow *mainWindow;
|
MainWindow *mainWindow;
|
||||||
ScriptEnvironment scriptEnvironment;
|
ScriptEnvironment *scriptEnvironment;
|
||||||
};
|
};
|
||||||
|
|
||||||
TelldusCenterApplication::TelldusCenterApplication(int &argc, char **argv)
|
TelldusCenterApplication::TelldusCenterApplication(int &argc, char **argv)
|
||||||
|
@ -28,6 +28,7 @@ TelldusCenterApplication::TelldusCenterApplication(int &argc, char **argv)
|
||||||
{
|
{
|
||||||
d = new TelldusCenterApplicationPrivate;
|
d = new TelldusCenterApplicationPrivate;
|
||||||
connect(this, SIGNAL(messageReceived(const QString &)), this, SLOT(msgReceived(const QString &)));
|
connect(this, SIGNAL(messageReceived(const QString &)), this, SLOT(msgReceived(const QString &)));
|
||||||
|
d->scriptEnvironment = new ScriptEnvironment(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
TelldusCenterApplication::~TelldusCenterApplication() {
|
TelldusCenterApplication::~TelldusCenterApplication() {
|
||||||
|
@ -36,7 +37,7 @@ TelldusCenterApplication::~TelldusCenterApplication() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TelldusCenterApplication::initialize() {
|
void TelldusCenterApplication::initialize() {
|
||||||
d->mainWindow = new MainWindow( );
|
d->mainWindow = new MainWindow( d->scriptEnvironment );
|
||||||
|
|
||||||
this->setActivationWindow(d->mainWindow, false);
|
this->setActivationWindow(d->mainWindow, false);
|
||||||
|
|
||||||
|
@ -55,7 +56,7 @@ PluginList TelldusCenterApplication::plugins() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
QScriptValue TelldusCenterApplication::mainWindow() {
|
QScriptValue TelldusCenterApplication::mainWindow() {
|
||||||
QScriptValue value = d->scriptEnvironment.engine()->newQObject(d->mainWindow);
|
QScriptValue value = d->scriptEnvironment->engine()->newQObject(d->mainWindow);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,11 +101,8 @@ void TelldusCenterApplication::loadPlugins() {
|
||||||
|
|
||||||
this->setLibraryPaths( QStringList(pluginsDir.absolutePath()) );
|
this->setLibraryPaths( QStringList(pluginsDir.absolutePath()) );
|
||||||
|
|
||||||
QScriptValue object = d->scriptEnvironment.engine()->newQObject(this);
|
QScriptValue mainWindowObject = d->scriptEnvironment->engine()->newQObject(d->mainWindow);
|
||||||
d->scriptEnvironment.engine()->globalObject().setProperty("application", object);
|
d->scriptEnvironment->engine()->globalObject().property("application").setProperty("mainwindow", mainWindowObject);
|
||||||
|
|
||||||
QScriptValue mainWindowObject = d->scriptEnvironment.engine()->newQObject(d->mainWindow);
|
|
||||||
d->scriptEnvironment.engine()->globalObject().property("application").setProperty("mainwindow", mainWindowObject);
|
|
||||||
|
|
||||||
foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
|
foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
|
||||||
QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
|
QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
|
||||||
|
@ -130,7 +128,7 @@ void TelldusCenterApplication::loadPlugin(QObject *plugin) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TelldusCenterApplication::loadScripts() {
|
void TelldusCenterApplication::loadScripts() {
|
||||||
foreach (QString extension, d->scriptEnvironment.engine()->availableExtensions()) {
|
foreach (QString extension, d->scriptEnvironment->engine()->availableExtensions()) {
|
||||||
if (extension.startsWith("...")) {
|
if (extension.startsWith("...")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -150,12 +148,12 @@ void TelldusCenterApplication::loadScripts() {
|
||||||
this->installTranslator(translator);
|
this->installTranslator(translator);
|
||||||
}
|
}
|
||||||
|
|
||||||
d->scriptEnvironment.engine()->importExtension( extension );
|
d->scriptEnvironment->engine()->importExtension( extension );
|
||||||
if (d->scriptEnvironment.engine()->hasUncaughtException()) {
|
if (d->scriptEnvironment->engine()->hasUncaughtException()) {
|
||||||
qDebug() << QString("Error in %1:%2:").arg(extension).arg(d->scriptEnvironment.engine()->uncaughtExceptionLineNumber())
|
qDebug() << QString("Error in %1:%2:").arg(extension).arg(d->scriptEnvironment->engine()->uncaughtExceptionLineNumber())
|
||||||
<< d->scriptEnvironment.engine()->uncaughtException().toString();
|
<< d->scriptEnvironment->engine()->uncaughtException().toString();
|
||||||
}
|
}
|
||||||
d->scriptEnvironment.engine()->clearExceptions();
|
d->scriptEnvironment->engine()->clearExceptions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue