#include <QMap>
#include <QFile>
#include <QDir>
+#include <QCryptographicHash>
+#include <QByteArray>
+
+static QDomDocument* constructDocumentForPage(DCContainer *container, const DCVCPage *page);
DCContainerSaver::DCContainerSaver(DCContainer *container) : d_container(container)
{
}
+QString DCContainerSaver::calculateHashForPage(const DCVCPage *page)
+{
+ QCryptographicHash hash(QCryptographicHash::Md5);
+ QDomDocument *pDoc1 = constructDocumentForPage(d_container, page);
+ if (pDoc1)
+ {
+ hash.addData(pDoc1->toString(-1).toLocal8Bit());
+ delete pDoc1;
+ }
+
+ QDomDocument doc2;
+ QDomElement doc2Root = doc2.createElement("denncoCreator");
+ page->saveAttributesToXML(&doc2, &doc2Root);
+ doc2.appendChild(doc2Root);
+ hash.addData(doc2.toString(-1).toLocal8Bit());
+
+ return QString(hash.result().toHex());
+}
+
bool DCContainerSaver::saveAll(const QString& containerRootPath)
{
const QMap<QString,DCVCPage*> *pages = d_container->getScene()->getPages();
QString pageFilePath = containerRootPath;
pageFilePath.append(page->getLocationPath());
- QDomDocument doc("html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"");
- doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\"");
+ QDomDocument *doc = constructDocumentForPage(d_container, page);
+ if (!doc)
+ return false;
+
+ QFile file(pageFilePath);
+ QFileInfo pathInfo = QFileInfo(pageFilePath);
+ QDir dir = pathInfo.dir();
+ if (!dir.exists())
+ dir.mkpath(dir.absolutePath());
+
+ bool r = false;
+ if (file.open(QFile::WriteOnly | QFile::Truncate))
+ {
+ QTextStream out(&file);
+ doc->save(out, 4);
+ r = true;
+ }
+ file.close();
+
+ delete doc;
+
+ if (r)
+ {
+ r = d_container->getScene()->saveSceneForPage(containerRootPath, page);
+ }
+
+ if (r)
+ {
+ page->updateSavedState(d_container);
+ }
+
+ return r;
+}
+
+QDomDocument* constructDocumentForPage(DCContainer *conteinr, const DCVCPage *page)
+{
+ QDomDocument *doc = new QDomDocument("html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"");
+ doc->createProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\"");
- QDomElement root = doc.createElementNS("http://www.w3.org/1999/xhtml","html");
+ QDomElement root = doc->createElementNS("http://www.w3.org/1999/xhtml","html");
root.setAttribute("lang", "en");
- QDomElement body = doc.createElement("body");
+ QDomElement body = doc->createElement("body");
root.appendChild(body);
const QList<DCVPageComponent*>* vcells = page->getCells();
DCCell *cell = vcells->at(i)->getOwnerCell();
QString cellName = QString::fromStdString(cell->getName());
- QDomElement aCellTag = doc.createElement("a");
+ QDomElement aCellTag = doc->createElement("a");
aCellTag.setAttribute("define", "cell");
aCellTag.setAttribute("name", cellName);
- QDomElement aCellCodeTag = doc.createElement("a");
+ QDomElement aCellCodeTag = doc->createElement("a");
aCellCodeTag.setAttribute("parameter", "cellcode");
- if (cell->getIsCellCodeClassAssgined())
+ if (cell->getIsCellCodeAssgined())
{
aCellCodeTag.setAttribute("href", QString::fromStdString(cell->getCellCode()->getFQNName()));
}
connectionPath.append(QString::fromStdString(targetCell->getName()));
QString receptorName = QString::fromStdString(targetCell->getReceptorName(receptor));
- QDomElement aConnectionTag = doc.createElement("a");
+ QDomElement aConnectionTag = doc->createElement("a");
aConnectionTag.setAttribute("parameter", "connection");
aConnectionTag.setAttribute("href", connectionPath);
aConnectionTag.setAttribute("receptor", receptorName);
}
}
}
- QDomElement preScriptTag = doc.createElement("pre");
+ QDomElement preScriptTag = doc->createElement("pre");
preScriptTag.setAttribute("parameter", "script");
- QDomCDATASection scriptCData = doc.createCDATASection(d_container->readCustomScriptFromWorkFile(cell));
+ QDomCDATASection scriptCData = doc->createCDATASection(conteinr->readCustomScriptFromWorkFile(cell));
preScriptTag.appendChild(scriptCData);
aCellTag.appendChild(preScriptTag);
body.appendChild(aCellTag);
DCCellCode *cellcodeclass = dynamic_cast<DCVCCellCode*>(vcellcodeclasses->at(i))->getOwnerCellCodeClass();
QString cellCodeClassName = DCUtil::getNameFromFQNPath(QString::fromStdString(cellcodeclass->getFQNName()));
- QDomElement aCellCodeTag = doc.createElement("a");
+ QDomElement aCellCodeTag = doc->createElement("a");
aCellCodeTag.setAttribute("define", "cellcode");
aCellCodeTag.setAttribute("name", cellCodeClassName);
aCellCodeTag.setAttribute("type", QString::fromStdString(cellcodeclass->getCellAPIName()));
- QDomElement preScriptTag = doc.createElement("pre");
+ QDomElement preScriptTag = doc->createElement("pre");
preScriptTag.setAttribute("parameter", "script");
- QDomCDATASection scriptCData = doc.createCDATASection(d_container->readCellCodeScriptFromFile(cellcodeclass));
+ QDomCDATASection scriptCData = doc->createCDATASection(conteinr->readCellCodeScriptFromFile(cellcodeclass));
preScriptTag.appendChild(scriptCData);
aCellCodeTag.appendChild(preScriptTag);
body.appendChild(aCellCodeTag);
}
- doc.appendChild(root);
-
- QFile file(pageFilePath);
- QFileInfo pathInfo = QFileInfo(pageFilePath);
- QDir dir = pathInfo.dir();
- if (!dir.exists())
- dir.mkpath(dir.absolutePath());
-
- bool r = false;
- if (file.open(QFile::WriteOnly | QFile::Truncate))
- {
- QTextStream out(&file);
- doc.save(out, 4);
- r = true;
- }
- file.close();
+ doc->appendChild(root);
- if (r)
- {
- r = d_container->getScene()->saveSceneForPage(containerRootPath, page);
- }
- return r;
+ return doc;
}