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..
#include "DNAlert.h"
#include "DNXML.h"
#include "DNGlobal.h"
+#include "DNUtils.h"
#include <stdlib.h>
if (!mDoTickThread)
mDoTickThread = DNThread::createThread(DNEngine::doTickThread, this);
- mDoTickThread->start();
+ return mDoTickThread->start();
}
bool DNEngine::stopEngine()
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)
{
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;
return "";
}
+std::string DNEngine::getUIPath()
+{
+ //TODO
+ return "/ui/index.html";
+}
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; }
--- /dev/null
+// 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 <http://www.gnu.org/licenses/>.
+
+//
+// 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());
+}
--- /dev/null
+// 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 <http://www.gnu.org/licenses/>.
+
+//
+// Created by tkawata on Mar-4/2012.
+//
+//
+#ifndef DNWEBINTERFACE_H
+#define DNWEBINTERFACE_H
+
+#include <QObject>
+
+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
+// 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 <http://www.gnu.org/licenses/>.
+
+//
+// Created by tkawata on 2/25/2012.
+//
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <QDir>
#include <QDebug>
+#include <QSettings>
+#include <QWebFrame>
+
#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()
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));
+ }
}
qDebug()<< "start button clicked";
if (QString::compare(ui->startButton->text(), "Start", Qt::CaseInsensitive) == 0)
{
- if (mEngine)
- {
- delete mEngine;
- }
+ deleteCurrentEngine();
if (startEngine())
{
if (!initializationFailed)
{
mEngine->startEngine();
+ loadUI();
}
return !initializationFailed;
}
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;
+ }
+}
+
+// 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 <http://www.gnu.org/licenses/>.
+
+//
+// Created by tkawata on 2/25/2012.
+//
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
-#include "DNEngine.h"
-#include "TKConsole.h"
+class DNEngine;
+class TKConsole;
+class DNWebInterface;
namespace Ui {
class MainWindow;
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
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QFrame" name="frame">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
DNQSContainer::~DNQSContainer()
{
+ if (mQSEngine)
+ delete mQSEngine;
}
TKCell* DNQSContainer::createCell(std::string theLocation, std::string theName, TKCellCode *cellCode, std::string startupScript)
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 \
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