From c8340e35037a6896d6c700b096e234c85afc6994 Mon Sep 17 00:00:00 2001 From: tkawata Date: Sun, 4 Mar 2012 17:05:30 +0900 Subject: [PATCH] alpha1 development (Qt). Basic functionalities are completed. Unfinished works are: 1. parse property.xml file 2. re-factor the dennco definition file format. 3. make test contents 4. persistent storage functionality for cells 5. Script error log functionality 6. Determine the rule of doInit and doDestroy and implement the future 7. Source view functionality 8. HTTPServer (for Qt) 9. And more.. --- Source/DNEngine.cpp | 21 +++++++-- Source/DNEngine.h | 2 + Source/QtDennco/dnwebinterface.cpp | 38 +++++++++++++++ Source/QtDennco/dnwebinterface.h | 43 +++++++++++++++++ Source/QtDennco/mainwindow.cpp | 94 +++++++++++++++++++++++++++++++++++--- Source/QtDennco/mainwindow.h | 37 ++++++++++++--- Source/QtDennco/mainwindow.ui | 6 +++ Source/QtScript/dnqscontainer.cpp | 2 + dennco.pro | 6 ++- 9 files changed, 231 insertions(+), 18 deletions(-) create mode 100644 Source/QtDennco/dnwebinterface.cpp create mode 100644 Source/QtDennco/dnwebinterface.h diff --git a/Source/DNEngine.cpp b/Source/DNEngine.cpp index 93c1b8f..cf5e3c5 100644 --- a/Source/DNEngine.cpp +++ b/Source/DNEngine.cpp @@ -29,6 +29,7 @@ #include "DNAlert.h" #include "DNXML.h" #include "DNGlobal.h" +#include "DNUtils.h" #include @@ -155,7 +156,7 @@ bool DNEngine::startEngine() if (!mDoTickThread) mDoTickThread = DNThread::createThread(DNEngine::doTickThread, this); - mDoTickThread->start(); + return mDoTickThread->start(); } bool DNEngine::stopEngine() @@ -191,7 +192,8 @@ void DNEngine::doTickThread(void *self) float DNEngine::doClientGetRequest(const char* path) { - TKUICell *cell = (TKUICell*)mContainer->getInterfaceCell(path); + std::string fqn = getFQNString("/",path); + TKUICell *cell = (TKUICell*)mContainer->getInterfaceCell(fqn); float result = 0; if (cell) { @@ -202,11 +204,17 @@ float DNEngine::doClientGetRequest(const char* path) bool DNEngine::doClientSetRequest(const char* path, const char* value) { - TKUICell *cell = (TKUICell*)mContainer->getInterfaceCell(path); + return doClientSetRequest(path, atof(value)); +} + +bool DNEngine::doClientSetRequest(const char* path, float value) +{ + std::string fqn = getFQNString("/",path); + TKUICell *cell = (TKUICell*)mContainer->getInterfaceCell(fqn); bool result = false; if (cell) { - cell->setValue(atof(value)); + cell->setValue(value); result = true; } return result; @@ -220,3 +228,8 @@ std::string DNEngine::getContentPath() return ""; } +std::string DNEngine::getUIPath() +{ + //TODO + return "/ui/index.html"; +} diff --git a/Source/DNEngine.h b/Source/DNEngine.h index 27500d3..e04345c 100644 --- a/Source/DNEngine.h +++ b/Source/DNEngine.h @@ -46,8 +46,10 @@ public: static void doTickThread(void *self); float doClientGetRequest(const char* path); bool doClientSetRequest(const char* path, const char* value); + bool doClientSetRequest(const char* path, float value); std::string getContentPath(); + std::string getUIPath(); bool isValid() { return mValid; } diff --git a/Source/QtDennco/dnwebinterface.cpp b/Source/QtDennco/dnwebinterface.cpp new file mode 100644 index 0000000..db9427b --- /dev/null +++ b/Source/QtDennco/dnwebinterface.cpp @@ -0,0 +1,38 @@ +// Copyright (c) 2012 Dennco Project +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// +// Created by tkawata on Mar-4/2012. +// +// +#include "dnwebinterface.h" + +#include "DNEngine.h" +#include "TKLog.h" + +DNWebInterface::DNWebInterface(DNEngine *engine) : + QObject(0), mEngine(engine) +{ +} + +void DNWebInterface::setValue(const QString name, float value) +{ + mEngine->doClientSetRequest(name.toLocal8Bit().data(), value); +} + +float DNWebInterface::getValue(const QString name) +{ + return mEngine->doClientGetRequest(name.toLocal8Bit().data()); +} diff --git a/Source/QtDennco/dnwebinterface.h b/Source/QtDennco/dnwebinterface.h new file mode 100644 index 0000000..2f5ad37 --- /dev/null +++ b/Source/QtDennco/dnwebinterface.h @@ -0,0 +1,43 @@ +// Copyright (c) 2012 Dennco Project +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// +// Created by tkawata on Mar-4/2012. +// +// +#ifndef DNWEBINTERFACE_H +#define DNWEBINTERFACE_H + +#include + +class DNEngine; + +class DNWebInterface : public QObject +{ + Q_OBJECT +public: + DNWebInterface(DNEngine *engine); + +signals: + +public slots: + void setValue(const QString name, float value); + float getValue(const QString name); + +private: + DNEngine *mEngine; +}; + +#endif // DNWEBINTERFACE_H diff --git a/Source/QtDennco/mainwindow.cpp b/Source/QtDennco/mainwindow.cpp index addd42f..b33a813 100644 --- a/Source/QtDennco/mainwindow.cpp +++ b/Source/QtDennco/mainwindow.cpp @@ -1,23 +1,51 @@ +// Copyright (c) 2012 Dennco Project +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// +// Created by tkawata on 2/25/2012. +// #include "mainwindow.h" #include "ui_mainwindow.h" #include #include #include +#include +#include + #include "TKLog.h" #include "DNGlobal.h" #include "DNAlert.h" +#include "DNEngine.h" +#include "TKConsole.h" +#include "dnwebinterface.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), - mEngine(NULL) + mEngine(NULL), mWebInterface(NULL) { ui->setupUi(this); + QSettings settings("dennco project", "dennco engine"); + QVariant defaultPath(QDir::homePath()); + QString contentPath = settings.value("content_path", defaultPath).toString(); + mConsole = new TKConsole(); TKLog::setDestination(mConsole); - ui->filePath->setText(QDir::homePath()); + ui->filePath->setText(contentPath); } MainWindow::~MainWindow() @@ -25,14 +53,30 @@ MainWindow::~MainWindow() delete ui; } +void MainWindow::closeEvent(QCloseEvent *event) +{ + stopEngine(); + deleteCurrentEngine(); + QMainWindow::closeEvent(event); +} + void MainWindow::on_chooseDirButton_clicked() { + if (QString::compare(ui->startButton->text(), "Stop", Qt::CaseInsensitive) == 0) + { + DNAlert::show("Please stop engine", "Dennco engine is running.\nPlease stop engine before switching directory."); + return; + } QString dirPath = QFileDialog::getExistingDirectory(this,"Set dennco setting file",ui->filePath->text()); qDebug()<< dirPath; if (dirPath.length() > 0) + { ui->filePath->setText(dirPath); + QSettings settings("dennco project", "dennco engine"); + settings.setValue("content_path", QVariant(dirPath)); + } } @@ -41,10 +85,7 @@ void MainWindow::on_startButton_clicked() qDebug()<< "start button clicked"; if (QString::compare(ui->startButton->text(), "Start", Qt::CaseInsensitive) == 0) { - if (mEngine) - { - delete mEngine; - } + deleteCurrentEngine(); if (startEngine()) { @@ -78,6 +119,7 @@ bool MainWindow::startEngine() if (!initializationFailed) { mEngine->startEngine(); + loadUI(); } return !initializationFailed; } @@ -91,3 +133,43 @@ bool MainWindow::stopEngine() return true; } +void MainWindow::loadUI() +{ + QString path = ui->filePath->text().append(QString::fromStdString(mEngine->getUIPath())); + QUrl pathUrl(path); + ui->webView->load(pathUrl); + mWebInterface = new DNWebInterface(mEngine); + attachWebInterface(); +} + +void MainWindow::attachWebInterface() +{ + if (!mWebInterface) + return; + + QWebPage *page = ui->webView->page(); + if (page) + { + QWebFrame *frame = page->mainFrame(); + if (frame) + { + frame->addToJavaScriptWindowObject("dennco", mWebInterface); + connect(frame, SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(attachWebInterface())); + } + } +} + +void MainWindow::deleteCurrentEngine() +{ + if (mEngine) + { + delete mEngine; + mEngine = NULL; + } + if (mWebInterface) + { + delete mWebInterface; + mWebInterface = NULL; + } +} + diff --git a/Source/QtDennco/mainwindow.h b/Source/QtDennco/mainwindow.h index 0e3ac57..8c94b05 100644 --- a/Source/QtDennco/mainwindow.h +++ b/Source/QtDennco/mainwindow.h @@ -1,10 +1,29 @@ +// Copyright (c) 2012 Dennco Project +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// +// Created by tkawata on 2/25/2012. +// #ifndef MAINWINDOW_H #define MAINWINDOW_H #include -#include "DNEngine.h" -#include "TKConsole.h" +class DNEngine; +class TKConsole; +class DNWebInterface; namespace Ui { class MainWindow; @@ -18,18 +37,24 @@ public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); - +protected: + virtual void closeEvent(QCloseEvent *event); + private slots: void on_chooseDirButton_clicked(); void on_startButton_clicked(); + void attachWebInterface(); private: bool startEngine(); bool stopEngine(); + void loadUI(); + void deleteCurrentEngine(); - Ui::MainWindow *ui; - DNEngine *mEngine; - TKConsole *mConsole; + Ui::MainWindow *ui; + DNEngine *mEngine; + TKConsole *mConsole; + DNWebInterface *mWebInterface; }; #endif // MAINWINDOW_H diff --git a/Source/QtDennco/mainwindow.ui b/Source/QtDennco/mainwindow.ui index f1937e3..638e76b 100644 --- a/Source/QtDennco/mainwindow.ui +++ b/Source/QtDennco/mainwindow.ui @@ -23,6 +23,12 @@ + + + 0 + 0 + + QFrame::StyledPanel diff --git a/Source/QtScript/dnqscontainer.cpp b/Source/QtScript/dnqscontainer.cpp index 593ba1e..135a6e1 100644 --- a/Source/QtScript/dnqscontainer.cpp +++ b/Source/QtScript/dnqscontainer.cpp @@ -80,6 +80,8 @@ DNQSContainer::DNQSContainer() DNQSContainer::~DNQSContainer() { + if (mQSEngine) + delete mQSEngine; } TKCell* DNQSContainer::createCell(std::string theLocation, std::string theName, TKCellCode *cellCode, std::string startupScript) diff --git a/dennco.pro b/dennco.pro index 1ba82b3..bc30fbd 100644 --- a/dennco.pro +++ b/dennco.pro @@ -49,7 +49,8 @@ SOURCES += Source/QtDennco/mainwindow.cpp \ Source/platform/qt/QtTKConsole.cpp \ Source/DNGlobal.cpp \ Source/DNThread.cpp \ - Source/platform/qt/qtdnthreadimpl.cpp + Source/platform/qt/qtdnthreadimpl.cpp \ + Source/QtDennco/dnwebinterface.cpp HEADERS += Source/QtDennco/mainwindow.h \ Source/TKUICell.h \ @@ -97,7 +98,8 @@ HEADERS += Source/QtDennco/mainwindow.h \ Source/DNGlobal.h \ Source/DNThread.h \ Source/DNThreadImpl.h \ - Source/platform/qt/qtdnthreadimpl.h + Source/platform/qt/qtdnthreadimpl.h \ + Source/QtDennco/dnwebinterface.h FORMS += Source/QtDennco/mainwindow.ui Debug:DEFINES+=DEBUG -- 2.11.0