00001 #include "datafolderhistory.h"
00002
00003 #include <QDomElement>
00004 #include <QDebug>
00005 #include "datahash.h"
00006 #include "project.h"
00007
00008 bool DataFolderHistory::loadDataNode(const QDomNode data)
00009 {
00010 QDomNode node = data.firstChild();
00011 while(!node.isNull())
00012 {
00013 if(node.nodeName() == "description")
00014 {
00015 m_description = node.firstChild().nodeValue().simplified();
00016 }
00017 else if(node.nodeName() == "ownerEmail")
00018 {
00019 m_ownerEmail = node.firstChild().nodeValue().simplified();
00020 }
00021 else if(node.nodeName() == "ownerName")
00022 {
00023 m_ownerName = node.firstChild().nodeValue().simplified();
00024 }
00025 else if(node.nodeName() == "title")
00026 {
00027 m_title = node.firstChild().nodeValue().simplified();
00028 }
00029 else if(node.nodeName() == "dateCreation")
00030 {
00031 m_dateCreation = QDateTime::fromString(node.firstChild().nodeValue().simplified(), "dd.MM.yyyy hh:mm:ss");
00032 if(!m_dateCreation.isValid())
00033 m_dateCreation = QDateTime::currentDateTime();
00034 }
00035 else if(node.nodeName() == "dateLastModification")
00036 {
00037 m_dateLastModification = QDateTime::fromString(node.firstChild().nodeValue().simplified(), "dd.MM.yyyy hh:mm:ss");
00038 if(!m_dateLastModification.isValid())
00039 m_dateLastModification = QDateTime::currentDateTime();
00040 }
00041 else if(node.nodeName() != "#comment")
00042 {
00043 qDebug() << "Unknown element in section tag:" << node.nodeName();
00044 }
00045 node = node.nextSibling();
00046 }
00047 return true;
00048 }
00049
00050 QDomElement DataFolderHistory::createTextElement(QDomDocument *xml, QString tagName, QString content)
00051 {
00052 QDomElement element = xml->createElement(tagName);
00053 element.appendChild(xml->createTextNode(content));
00054 return element;
00055 }
00056
00057 QDomElement DataFolderHistory::saveDataNode(QDomDocument* xml)
00058 {
00059 QDomElement entry = xml->createElement("historyEntry");
00060
00061 entry.appendChild(createTextElement(xml, "dateCreation", m_dateCreation.toString("dd.MM.yyyy hh:mm:ss")));
00062 entry.appendChild(createTextElement(xml, "dateLastModification", m_dateLastModification.toString("dd.MM.yyyy hh:mm:ss")));
00063 entry.appendChild(createTextElement(xml, "description", m_description));
00064 entry.appendChild(createTextElement(xml, "ownerEmail", m_ownerEmail));
00065 entry.appendChild(createTextElement(xml, "ownerName", m_ownerName));
00066 entry.appendChild(createTextElement(xml, "title", m_title));
00067
00068 return entry;
00069 }
00070
00071 void DataFolderHistory::hash(unsigned int &startValue)
00072 {
00073
00074
00075 DataHash::hash(m_dateCreation.toString("dd.MM.yyyy hh:mm:ss"), startValue);
00076 DataHash::hash(m_dateLastModification.toString("dd.MM.yyyy hh:mm:ss"), startValue);
00077 DataHash::hash(m_description, startValue);
00078 DataHash::hash(m_ownerEmail, startValue);
00079 DataHash::hash(m_ownerName, startValue);
00080 DataHash::hash(m_title, startValue);
00081 }
00082
00083 void DataFolderHistory::updateProjectData()
00084 {
00085 Project::setDateCreation(m_dateCreation);
00086 Project::setDateModified(m_dateLastModification);
00087 Project::setDescription(m_description);
00088 Project::setOwnerEmail(m_ownerEmail);
00089 Project::setOwnerName(m_ownerName);
00090 Project::setName(m_title);
00091 }
00092
00093 bool DataFolderHistory::differsFromProject()
00094 {
00095 return (m_description != Project::description() || m_ownerEmail != Project::ownerEmail() || m_ownerName != Project::ownerName() || m_title != Project::name());
00096 }
00097
00098 DataFolderHistory *DataFolderHistory::fromProject()
00099 {
00100 DataFolderHistory *history = new DataFolderHistory();
00101
00102 history->m_dateCreation = Project::dateCreation();
00103 history->m_dateLastModification = Project::dateModified();
00104 history->m_description = Project::description();
00105 history->m_ownerEmail = Project::ownerEmail();
00106 history->m_ownerName = Project::ownerName();
00107 history->m_title = Project::name();
00108
00109 return history;
00110 }
00111
00112 DataFolderHistory::DataFolderHistory()
00113 {
00114 }