OSDN Git Service

[dennco creator] Initial implementation for [Add new] menu.
authortkawata <tkawata@users.sourceforge.jp>
Sun, 30 Sep 2012 15:30:17 +0000 (00:30 +0900)
committertkawata <tkawata@users.sourceforge.jp>
Sun, 30 Sep 2012 15:30:17 +0000 (00:30 +0900)
15 files changed:
Source/command/dceditcommands.cpp
Source/command/dceditcommands.h
Source/dccontainer.cpp
Source/dccontainer.h
Source/dccreator.cpp
Source/dccreator.h
Source/denncoCreator.pro
Source/mainwindow.cpp
Source/treeview/dctreeviewwidget.cpp
Source/utils/dccommandutil.cpp
Source/utils/dccommandutil.h
Source/utils/dcskeltoncreatorutil.cpp [new file with mode: 0644]
Source/utils/dcskeltoncreatorutil.h [new file with mode: 0644]
Source/utils/dcutil.cpp [new file with mode: 0644]
Source/utils/dcutil.h [new file with mode: 0644]

index f3adb1c..efa2de6 100644 (file)
@@ -318,8 +318,8 @@ static const char *SKELTON_PAGE =
         "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">\n"
         "</html>\n" ;
 
-DCAddPageCommand::DCAddPageCommand(const void *requester, DCCreator *creator, const QString &contentBasedPath)
-    : DCCommand(requester, creator), d_path(contentBasedPath)
+DCAddPageCommand::DCAddPageCommand(const void *requester, DCCreator *creator, const QString &containerBasedPath)
+    : DCCommand(requester, creator), d_path(containerBasedPath)
 {
 
 }
index 96e9899..6575bc0 100644 (file)
@@ -158,7 +158,7 @@ class DCAddPageCommand : public DCCommand
 {
     QString d_path;
 public:
-    DCAddPageCommand(const void *requester, DCCreator *creator, const QString& contentBasedPathName);
+    DCAddPageCommand(const void *requester, DCCreator *creator, const QString& containerBasedPathName);
     virtual ~DCAddPageCommand() {}
     void undo();
     void redo();
index c6abb7a..007ff9b 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "DNFileList.h"
 #include "DNDirectory.h"
+#include "utils/dcutil.h"
 
 #include <QMutexLocker>
 #include <QDir>
@@ -262,7 +263,7 @@ void DCContainer::endedParsePage(const char *docRoot, const char *path)
 
 void DCContainer::beganBuildContainer()
 {
-    removeDirRecursive(d_workDirRoot);
+    DCUtil::removeDirRecursive(d_workDirRoot);
 }
 
 void DCContainer::endedBuildContainer()
@@ -364,24 +365,3 @@ QString DCContainer::readCellCodeScriptFromFile(const DCCellCode *cellCode)
     return out;
 }
 
-void DCContainer::removeDirRecursive(QString path)
-{
-    QDir  dir(path);
-
-    QFileInfoList list = dir.entryInfoList(QDir::NoDot | QDir::NoDotDot | QDir::AllEntries);
-
-    for (int i = 0; i < list.length(); i++)
-    {
-        QFileInfo info = list.at(i);
-        if (info.isDir())
-        {
-            removeDirRecursive(info.absoluteFilePath());
-            info.dir().rmdir(info.absoluteFilePath());
-        }
-        else
-        {
-            QFile file(info.absoluteFilePath());
-            file.remove();
-        }
-    }
-}
index 73484e4..3f9bfbf 100644 (file)
@@ -36,8 +36,6 @@ class DCUIGraphicsScene;
 
 class DCContainer : public TKContainer
 {
-    void            removeDirRecursive(QString path);
-
     DCContent       *d_content;
     DCScene         *d_scene;
 
index e864548..c197cc7 100644 (file)
@@ -398,14 +398,14 @@ void DCCreator::doCommandAddCellCodeClass(const void *requester, DCContainer *co
     DCCommandUtil::postAddCellCodeClassCommand(requester, this, container, name, type);
 }
 
-void DCCreator::doCommandAddCell(const void *requester, DCContainer *container, const QString& contentBasedPath, const QString& name, const QString& type)
+void DCCreator::doCommandAddCell(const void *requester, DCContainer *container, const QString& containerBasedPath, const QString& name, const QString& type)
 {
-    DCCommandUtil::postAddCellCommand(requester, this, container, contentBasedPath, name, type);
+    DCCommandUtil::postAddCellCommand(requester, this, container, containerBasedPath, name, type);
 }
 
-void DCCreator::doCommandAddPage(const void *requester, const QString &contentBasedPath)
+void DCCreator::doCommandAddPage(const void *requester, const QString &containerBasedPath)
 {
-    DCCommandUtil::postAddPageCommand(requester, this, contentBasedPath);
+    DCCommandUtil::postAddPageCommand(requester, this, containerBasedPath);
 }
 
 void DCCreator::doCommandAddDirectory(const void *requester, const QString &sysFilePath)
@@ -418,7 +418,7 @@ void DCCreator::doCommandRemoveDirectory(const void *requester, const QString &s
     DCCommandUtil::postRemoveDirectoryCommand(requester, this, sysFilePath);
 }
 
-bool DCCreator::doCommandRenameDirectoryImmidiate(const void *requester, const QString &contentBasedPath, const QString &oldName, const QString &newName)
+bool DCCreator::doCommandRenameDirectoryImmidiate(const void *requester, const QString &containerBasedPath, const QString &oldName, const QString &newName)
 {
     //TODO
     QMessageBox msgBox;
index a54d956..79700cf 100644 (file)
@@ -101,13 +101,13 @@ public:
     void doCommandUnsetCellCodeClass(const void *requester, DCCell *cell);
 
     void doCommandAddCellCodeClass(const void *requester, DCContainer *container, const QString& name, const QString& type);
-    void doCommandAddCell(const void *requester, DCContainer *container, const QString& contentBasedPath, const QString& name, const QString& type);
-    void doCommandAddPage(const void *requester, const QString& contentBasedPath);
+    void doCommandAddCell(const void *requester, DCContainer *container, const QString& containerBasedPath, const QString& name, const QString& type);
+    void doCommandAddPage(const void *requester, const QString& containerBasedPath);
 
     void doCommandAddDirectory(const void *requester, const QString& sysFilePath);
     void doCommandRemoveDirectory(const void *requester, const QString& sysFilePath);
 
-    bool doCommandRenameDirectoryImmidiate(const void *requester, const QString& contentBasedPath, const QString& oldName, const QString &newName);
+    bool doCommandRenameDirectoryImmidiate(const void *requester, const QString& containerBasedPath, const QString& oldName, const QString &newName);
 
 private slots:
     void slotSceneSelectedPageChanged(const void *requester);
index b8e0cf6..2ba3559 100644 (file)
@@ -85,7 +85,9 @@ HEADERS       = mainwindow.h \
     dialog/dcaddcellcodeclassdialog.h \
     dialog/dcsinglecolumntableview.h \
     dialog/dcinputnewpagenamedialog.h \
-    dialog/dcaddcelldialog.h
+    dialog/dcaddcelldialog.h \
+    utils/dcskeltoncreatorutil.h \
+    utils/dcutil.h
 
 SOURCES       = main.cpp \
                 mainwindow.cpp \
@@ -165,7 +167,9 @@ SOURCES       = main.cpp \
     dialog/dcaddcellcodeclassdialog.cpp \
     dialog/dcsinglecolumntableview.cpp \
     dialog/dcinputnewpagenamedialog.cpp \
-    dialog/dcaddcelldialog.cpp
+    dialog/dcaddcelldialog.cpp \
+    utils/dcskeltoncreatorutil.cpp \
+    utils/dcutil.cpp
 
 RESOURCES     = denncoCreator.qrc
 
index 63fa8c5..9ba7703 100644 (file)
@@ -26,6 +26,7 @@
 #include "dctreeviewwidget.h"
 #include "TKConsole.h"
 #include "utils/dcresources.h"
+#include "utils/dcskeltoncreatorutil.h"
 
 #include <QCloseEvent>
 #include <QFileDialog>
@@ -79,25 +80,20 @@ void MainWindow::closeEvent(QCloseEvent *event)
         event->ignore();
     }
 }
-//! [4]
 
-//! [5]
 void MainWindow::newFile()
-//! [5] //! [6]
 {
-    if (maybeSave()) {
-//        textEdit->clear();
-        setCurrentContent("");
+    QString dirName = QFileDialog::getSaveFileName(this, tr("Create new content"));
+    if (!dirName.isEmpty() && DCSkeltonCreatorUtil::createNewContent(dirName))
+    {
+        loadContent(dirName);
     }
 }
-//! [6]
 
-//! [7]
 void MainWindow::open()
-//! [7] //! [8]
 {
     if (maybeSave()) {
-        QString dirName = QFileDialog::getExistingDirectory(this);
+        QString dirName = QFileDialog::getExistingDirectory(this, tr("Open a content"));
         if (!dirName.isEmpty())
             loadContent(dirName);
     }
index 592bb0e..13770f7 100644 (file)
@@ -40,10 +40,9 @@ static bool IsIndexUnderContainer(const QFileSystemModel *model, QModelIndex ind
     bool r = false;
     while (index.isValid())
     {
-        if (index.parent().isValid()
-                && model->fileName(index.parent()) == "Container"
-                && index.parent().parent().isValid()
-                && index.parent().parent() == model->index(model->rootPath()))
+        if (model->fileName(index) == "Container"
+                && index.parent().isValid()
+                && index.parent() == model->index(model->rootPath()))
         {
             r = true;
         }
@@ -76,8 +75,8 @@ bool DCTreeViewModel::setData(const QModelIndex &index, const QVariant &value, i
         if (QFileInfo(oldFilePath).isDir() && IsIndexUnderContainer(this, index))
         {
             QString contentPath = QString::fromStdString(d_creator->getCurrentContainer()->getContentPath());
-            QString contentBasedPath = "/" + QDir(contentPath).relativeFilePath(baseDirPath);
-            if (d_creator->doCommandRenameDirectoryImmidiate(this, contentBasedPath, oldFileName, value.toString()))
+            QString containerBasedPath = "/" + QDir(contentPath).relativeFilePath(baseDirPath);
+            if (d_creator->doCommandRenameDirectoryImmidiate(this, containerBasedPath, oldFileName, value.toString()))
             {
                 r = QFileSystemModel::setData(index, value, role);
                 if (!r)
@@ -241,12 +240,12 @@ void DCTreeViewWidget::doContextMenu(const QPoint &pos)
     if (showMenu)
     {
         QString contentPath;
-        QString contentBasedPath;
+        QString containerBasedPath;
 
         if (index.isValid())
         {
             contentPath = QString::fromStdString(d_creator->getCurrentContainer()->getContentPath());
-            contentBasedPath = "/" + QDir(contentPath).relativeFilePath(fileModel->filePath(index));
+            containerBasedPath = "/" + QDir(contentPath).relativeFilePath(fileModel->filePath(index));
         }
 
         QAction* selectedItem = menu.exec(globalPos);
@@ -266,7 +265,7 @@ void DCTreeViewWidget::doContextMenu(const QPoint &pos)
             {
                 if (index.isValid())
                 {
-                    if (contentBasedPath.length() > 1)
+                    if (containerBasedPath.length() >= 1)
                     {
                         DCInputNewPageNameDialog dialog;
                         if (dialog.exec())
@@ -274,7 +273,10 @@ void DCTreeViewWidget::doContextMenu(const QPoint &pos)
                             QString pageName = dialog.getName();
                             if (pageName.length() > 0)
                             {
-                                QString pathName = contentBasedPath + "/" + pageName;
+                                QString pathName = containerBasedPath;
+                                if (containerBasedPath.length()>1)
+                                    pathName.append("/");
+                                pathName.append(pageName);
                                 d_creator->doCommandAddPage(this, pathName);
                             }
                         }
@@ -299,7 +301,7 @@ void DCTreeViewWidget::doContextMenu(const QPoint &pos)
             {
                 if (index.isValid())
                 {
-                    DCAddCellDialog dialog(d_creator->getCurrentContainer(), d_creator, contentBasedPath);
+                    DCAddCellDialog dialog(d_creator->getCurrentContainer(), d_creator, containerBasedPath);
                     dialog.exec();
                 }
             }
@@ -307,7 +309,7 @@ void DCTreeViewWidget::doContextMenu(const QPoint &pos)
             {
                 if (index.isValid())
                 {
-                    DCAddCellCodeClassDialog dialog(d_creator->getCurrentContainer(), d_creator, contentBasedPath);
+                    DCAddCellCodeClassDialog dialog(d_creator->getCurrentContainer(), d_creator, containerBasedPath);
                     dialog.exec();
                 }
             }
index 759027c..ef508fe 100644 (file)
@@ -105,15 +105,15 @@ void DCCommandUtil::postAddCellCodeClassCommand(const void *requester, DCCreator
 }
 
 //static
-void DCCommandUtil::postAddCellCommand(const void *requester, DCCreator *creator, DCContainer *container, const QString &contentBasedPath, const QString &name, const QString &type)
+void DCCommandUtil::postAddCellCommand(const void *requester, DCCreator *creator, DCContainer *container, const QString &containerBasedPath, const QString &name, const QString &type)
 {
-    postEvent(creator, new DCAddCellCommand(requester, creator, container, contentBasedPath, name, type));
+    postEvent(creator, new DCAddCellCommand(requester, creator, container, containerBasedPath, name, type));
 }
 
 //static
-void DCCommandUtil::postAddPageCommand(const void *requester, DCCreator *creator, const QString& contentBasedPath)
+void DCCommandUtil::postAddPageCommand(const void *requester, DCCreator *creator, const QString& containerBasedPath)
 {
-    postEvent(creator, new DCAddPageCommand(requester, creator, contentBasedPath));
+    postEvent(creator, new DCAddPageCommand(requester, creator, containerBasedPath));
 }
 
 //static
index ca4a2c8..a65e3b1 100644 (file)
@@ -48,8 +48,8 @@ struct DCCommandUtil
     static void postUnsetCellCodeClassCommand(const void *requester,  DCCreator *creator, DCCell *cell);
 
     static void postAddCellCodeClassCommand(const void *requester, DCCreator *creator, DCContainer *container, const QString& name, const QString& type);
-    static void postAddCellCommand(const void *requester, DCCreator *creator, DCContainer *container, const QString& contentBasedPath, const QString& name, const QString& type);
-    static void postAddPageCommand(const void *requester, DCCreator *creator, const QString& contentBasedPath);
+    static void postAddCellCommand(const void *requester, DCCreator *creator, DCContainer *container, const QString& containerBasedPath, const QString& name, const QString& type);
+    static void postAddPageCommand(const void *requester, DCCreator *creator, const QString& containerBasedPath);
 
     static void postAddDirectoryCommand(const void *requester, DCCreator *creator, const QString& sysFilePath);
     static void postRemoveDirectoryCommand(const void *requester, DCCreator *creator, const QString& sysFilePath);
diff --git a/Source/utils/dcskeltoncreatorutil.cpp b/Source/utils/dcskeltoncreatorutil.cpp
new file mode 100644 (file)
index 0000000..c7b8ff6
--- /dev/null
@@ -0,0 +1,106 @@
+//  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 Oct-1, 2012.
+//
+#include "dcskeltoncreatorutil.h"
+
+#include "utils/dcutil.h"
+
+#include <QFile>
+#include <QTextStream>
+
+static QString SKELTON_PROPERTY_XML =
+        "<dennco>\n"
+        "<TickIntervalSec>1.0</TickIntervalSec>\n"
+        "<UIPath>/ui/index.html</UIPath>\n"
+        "<EnableHTTPServer>no</EnableHTTPServer>\n"
+        "<EnableSerialServer>no</EnableSerialServer>\n"
+        "</dennco>";
+
+static QString SKELTON_UI_TOP =
+        "<html>\n"
+        "<head>\n"
+        "<title></title>\n"
+        "<script type=\"text/javascript\">\n"
+        "var timerId = setInterval(\"updateOutput()\", 500);\n"
+        "function updateOutput()\n"
+        "{\n"
+        "    //function for getting updated data from cells\n"
+        "}\n"
+        "\n"
+        "function stopTimer()\n"
+        "{\n"
+        "    clearInterval(timerId);\n"
+        "}\n"
+        "</script>\n"
+        "</head>\n"
+        "<body onunload=\"stopTimer()\">\n"
+        "</body>\n"
+        "</html>\n";
+
+//static
+bool DCSkeltonCreatorUtil::createNewContent(const QString &contentRootPath)
+{
+    if (QFileInfo(contentRootPath).exists())
+    {
+        QMessageBox msgBox;
+        msgBox.setText(tr("ERROR! The file already exist"));
+        return false;
+    }
+
+    QDir dir;
+    if (!dir.mkdir(contentRootPath))
+    {
+        QMessageBox msgBox;
+        msgBox.setText(tr("ERROR! Failed to create a directory"));
+        return false;
+    }
+
+    QString conteinerRoot = contentRootPath + "/Container";
+    if (!dir.mkdir(conteinerRoot))
+    {
+        QMessageBox msgBox;
+        msgBox.setText(tr("ERROR! Failed to create a directory"));
+        DCUtil::removeDirRecursive(contentRootPath);
+        return false;
+    }
+
+    QFile propertyFile(contentRootPath + "/property.xml");
+    propertyFile.open(QIODevice::WriteOnly);
+    QTextStream out(&propertyFile);
+    out << SKELTON_PROPERTY_XML;
+    propertyFile.close();
+
+    QString uiRoot = contentRootPath + "/ui";
+    if (!dir.mkdir(uiRoot))
+    {
+        QMessageBox msgBox;
+        msgBox.setText(tr("ERROR! Failed to create a directory"));
+        DCUtil::removeDirRecursive(contentRootPath);
+        return false;
+    }
+
+
+    QFile uiTopPage(uiRoot + "/index.html");
+    uiTopPage.open(QIODevice::WriteOnly);
+    QTextStream out2(&uiTopPage);
+    out2 << SKELTON_UI_TOP;
+    uiTopPage.close();
+
+    return true;
+}
+
diff --git a/Source/utils/dcskeltoncreatorutil.h b/Source/utils/dcskeltoncreatorutil.h
new file mode 100644 (file)
index 0000000..1db1666
--- /dev/null
@@ -0,0 +1,31 @@
+//  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 Oct-1, 2012.
+//
+#ifndef DCSKELTONCREATORUTIL_H
+#define DCSKELTONCREATORUTIL_H
+
+#include <QtGui>
+
+class DCSkeltonCreatorUtil : public QObject
+{
+public:
+    static bool createNewContent(const QString& contentRootPath);
+
+};
+
+#endif // DCSKELTONCREATORUTIL_H
diff --git a/Source/utils/dcutil.cpp b/Source/utils/dcutil.cpp
new file mode 100644 (file)
index 0000000..893d2fa
--- /dev/null
@@ -0,0 +1,45 @@
+//  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 Oct-1, 2012.
+//
+#include "dcutil.h"
+
+#include <QDir>
+#include <QFileInfoList>
+
+//static
+void DCUtil::removeDirRecursive(QString path)
+{
+    QDir  dir(path);
+
+    QFileInfoList list = dir.entryInfoList(QDir::NoDot | QDir::NoDotDot | QDir::AllEntries);
+
+    for (int i = 0; i < list.length(); i++)
+    {
+        QFileInfo info = list.at(i);
+        if (info.isDir())
+        {
+            removeDirRecursive(info.absoluteFilePath());
+            info.dir().rmdir(info.absoluteFilePath());
+        }
+        else
+        {
+            QFile file(info.absoluteFilePath());
+            file.remove();
+        }
+    }
+}
diff --git a/Source/utils/dcutil.h b/Source/utils/dcutil.h
new file mode 100644 (file)
index 0000000..7dc8b2d
--- /dev/null
@@ -0,0 +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 Oct-1, 2012.
+//
+#ifndef DCUTIL_H
+#define DCUTIL_H
+
+#include <QString>
+
+struct DCUtil
+{
+    static void removeDirRecursive(QString path);
+};
+
+#endif // DCUTIL_H