1 // Copyright (c) 2012 Dennco Project
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 // Created by tkawata on Oct-1, 2012.
19 #include "dcskeltoncreatorutil.h"
21 #include "utils/dcutil.h"
24 #include <QTextStream>
26 static QString SKELTON_PROPERTY_XML =
28 "<TickIntervalSec>1.0</TickIntervalSec>\n"
29 "<UIPath>/ui/index.html</UIPath>\n"
30 "<EnableHTTPServer>no</EnableHTTPServer>\n"
31 "<EnableSerialServer>no</EnableSerialServer>\n"
34 static QString SKELTON_UI_TOP =
38 "<script type=\"text/javascript\">\n"
39 "var timerId = setInterval(\"updateOutput()\", 500);\n"
40 "function updateOutput()\n"
42 " //function for getting updated data from cells\n"
45 "function stopTimer()\n"
47 " clearInterval(timerId);\n"
51 "<body onunload=\"stopTimer()\">\n"
55 static QString SKELTON_CELLCODE =
56 "// Function: doInit\n"
57 "// This function will be called once when a cell is instantiated.\n"
63 "// Function: doTick\n"
64 "// This function will be called once every tick interval time.\n"
65 "// The parameter time holds the elasped time from the beginning of the container in millisecond.\n"
66 "function doTick(time)\n"
70 "// Function: doDestroy\n"
71 "// This function will be called once just before the cell instance is destroyed.\n"
73 "function doDestroy()\n"
78 static QString SKELTOM_CUSTOMSCRIPT =
79 "// Script below will be called once when a cell is instantiated.\n"
80 "// When a cell has a attached cell code class, custom script here will be called first and \n"
81 "// doInit function in cell code class follows. \n"
82 "// You can define functions here, too.\n"
83 "// In the case a cell doesn't have a cell code class attached, you can define doInit, \n"
84 "// doTick and doDestroy functions here then they work jast as like functions defined in \n"
85 "// cell code class does.\n\n";
88 bool DCSkeltonCreatorUtil::createNewContent(const QString &contentRootPath)
90 if (QFileInfo(contentRootPath).exists())
93 msgBox.setText(tr("ERROR! The file already exist"));
98 if (!dir.mkdir(contentRootPath))
101 msgBox.setText(tr("ERROR! Failed to create a directory"));
105 QString conteinerRoot = contentRootPath + "/Container";
106 if (!dir.mkdir(conteinerRoot))
109 msgBox.setText(tr("ERROR! Failed to create a directory"));
110 DCUtil::removeDirRecursive(contentRootPath);
114 QFile propertyFile(contentRootPath + "/property.xml");
115 propertyFile.open(QIODevice::WriteOnly);
116 QTextStream out(&propertyFile);
117 out << SKELTON_PROPERTY_XML;
118 propertyFile.close();
120 QString uiRoot = contentRootPath + "/ui";
121 if (!dir.mkdir(uiRoot))
124 msgBox.setText(tr("ERROR! Failed to create a directory"));
125 DCUtil::removeDirRecursive(contentRootPath);
130 QFile uiTopPage(uiRoot + "/index.html");
131 uiTopPage.open(QIODevice::WriteOnly);
132 QTextStream out2(&uiTopPage);
133 out2 << SKELTON_UI_TOP;
139 QString DCSkeltonCreatorUtil::getDefaultCellCodeClassScript()
141 return SKELTON_CELLCODE;
144 QString DCSkeltonCreatorUtil::getDefaultCustomScript()
146 return SKELTOM_CUSTOMSCRIPT;