OSDN Git Service

alpha1 development (Qt).
authortkawata <takuji.kawata@gmail.com>
Sun, 4 Mar 2012 08:05:30 +0000 (17:05 +0900)
committertkawata <takuji.kawata@gmail.com>
Sun, 4 Mar 2012 08:05:30 +0000 (17:05 +0900)
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
Source/DNEngine.h
Source/QtDennco/dnwebinterface.cpp [new file with mode: 0644]
Source/QtDennco/dnwebinterface.h [new file with mode: 0644]
Source/QtDennco/mainwindow.cpp
Source/QtDennco/mainwindow.h
Source/QtDennco/mainwindow.ui
Source/QtScript/dnqscontainer.cpp
dennco.pro

index 93c1b8f..cf5e3c5 100644 (file)
@@ -29,6 +29,7 @@
 #include "DNAlert.h"
 #include "DNXML.h"
 #include "DNGlobal.h"
+#include "DNUtils.h"
 
 #include <stdlib.h>
 
@@ -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";
+}
index 27500d3..e04345c 100644 (file)
@@ -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 (file)
index 0000000..db9427b
--- /dev/null
@@ -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 <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());
+}
diff --git a/Source/QtDennco/dnwebinterface.h b/Source/QtDennco/dnwebinterface.h
new file mode 100644 (file)
index 0000000..2f5ad37
--- /dev/null
@@ -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 <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
index addd42f..b33a813 100644 (file)
@@ -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 <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()
@@ -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;
+    }
+}
+
index 0e3ac57..8c94b05 100644 (file)
@@ -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 <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;
@@ -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
index f1937e3..638e76b 100644 (file)
    <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>
index 593ba1e..135a6e1 100644 (file)
@@ -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)
index 1ba82b3..bc30fbd 100644 (file)
@@ -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