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 Sep-30, 2012.
19 #include "dccontent.h"
21 #include "dccontainer.h"
22 #include "DNContainerBuilder.h"
25 #include "DNXMLElement.h"
27 #include "dccontainersaver.h"
28 #include "uieditor/dcuieditor.h"
29 #include "propertyeditor/dcpropertyeditor.h"
35 DCContent::DCContent(DCCreator *creator, std::string contentPath) :
36 d_creator(creator), d_valid(false), d_container(0)
38 d_contentRootPath = QString::fromStdString(contentPath);
39 d_container = (DCContainer*) TKContainer::createContainer();
40 d_container->setContent(this);
42 dnGlobal()->updateRunningStatus(DNGlobal::STOPPED);
43 dnGlobal()->resetErrorStatus();
45 std::string containerRoot = contentPath;
46 containerRoot.append("/Container");
48 bool succeeded = false;
49 succeeded = parseSettingFile(contentPath.c_str());
50 if (!succeeded || !dnGlobal()->isErrorStatusNormal())
52 dnNotifyError("property.xml parse error", "failed to parse setting file /property.xml");
56 std::string dataStorePath = containerRoot;
57 dataStorePath.append("/data.db");
59 succeeded = d_container->setDataStore(dataStorePath.c_str());
62 dnNotifyError("Initialization failed","Failed to the setup data store");
66 succeeded = parseContainerFile(containerRoot.c_str());
69 dnNotifyError("Initialization failed", "Failed to parse container file");
76 DCContent::~DCContent()
86 bool DCContent::getIsModified() const
88 if (d_valid && d_container && d_container->getIsModified())
93 if (DCPropertyEditor::getEditor()->isVisible())
94 DCPropertyEditor::getEditor()->close();
96 if (DCUIEditor::getEditor()->isVisible())
97 DCUIEditor::getEditor()->close();
102 bool DCContent::parseSettingFile(const char *contentRoot)
106 DNXML *xml = DNXML::createXMLFromFile(contentRoot, "property.xml");
110 DNXMLElement *element = xml->getRoot();
114 std::string message = "Failed to load property.xml file";
115 dnNotifyError("Initialization failed",message);
118 if (valid && element->name != "dennco")
121 std::string message = "First element of property.xml should be <dennco>";
122 dnNotifyError("Initialization failed",message);
127 DNXMLElement *e = element->inner;
130 std::string pname = upperString(e->name);
132 if (pname == "TICKINTERVALSEC")
134 std::istringstream is(e->text);
144 std::string message = "Error in property.xml. TickIntervalSec is not configured properly.";
145 dnNotifyError("Initialization failed",message);
148 else if (pname == "UIPATH")
152 else if (pname == "ENABLEHTTPSERVER")
156 else if (pname == "ENABLESERIALSERVER")
158 if ( upperString(e->text) == "YES")
167 else if (pname == "SERIALSPEED")
180 bool DCContent::parseContainerFile(const char *containerRoot)
182 DNContainerBuilder builder(d_container);
183 d_container->beganBuildContainer();
184 bool r = builder.buildContainerFromXHTML(containerRoot);
185 d_container->endedBuildContainer();
190 bool DCContent::saveAll(const QString& contentRoot)
192 DCContainerSaver containerSaver(d_container);
194 QString containerRoot = contentRoot + "/Container";
195 return containerSaver.saveAll(containerRoot);
198 bool DCContent::saveForPage(const QString &contentRoot, DCVCPage *page)
200 DCContainerSaver containerSaver(d_container);
202 QString containerRoot = contentRoot + "/Container";
203 return containerSaver.saveForPage(containerRoot, page);