Commit 834a0935 authored by Martin Straka's avatar Martin Straka

Updated delivery info from zfo

parent 37b478d3
......@@ -46,6 +46,7 @@ Component {
/* These properties are set from within the page. */
property string zfoId /*Prevents infinite loop that would be caused by setting msgId from within the page. */
property bool showDeliveryInfo: false /* True = attachment list is shown */
property string msgAnnotation
property string msgDescrHtml /* Message HTML description. */
property string emailBody
......@@ -60,6 +61,7 @@ Component {
function fillContentFromDb() {
if (!fromLocalDb && (rawZfoContent != null)) {
var msgInfo = files.msgInfo(rawZfoContent)
zfoId = msgInfo.idStr
......@@ -68,9 +70,13 @@ Component {
emailBody = msgInfo.emailBody
attachmentModel.setZfo(rawZfoContent)
attachmentLabel.visible = !showDeliveryInfo
emptyList.visible = !showDeliveryInfo
attachmentList.visible = !showDeliveryInfo
console.log("Loaded page content from ZFO.")
rawZfoContent = null /* There is no need to remember this. */
} else if (fromLocalDb && (userName.length != 0) && (msgId.length != 0)) {
zfoId = msgId
......@@ -139,7 +145,13 @@ Component {
anchors.left: backElement3.right
anchors.leftMargin: defaultMargin
Text {
text: fromLocalDb ? (acntName + " (" + userName + ")") : qsTr("Message from ZFO")
text: if (fromLocalDb) {
acntName + " (" + userName + ")"
} else if (showDeliveryInfo) {
qsTr("Delivery info from ZFO")
} else {
qsTr("Message from ZFO")
}
font.bold: true
color: datovkaPalette.text
}
......@@ -237,7 +249,7 @@ Component {
id: messageDetail
anchors.top: header.bottom
width: parent.width
height: parent.height * 0.5
height: (showDeliveryInfo) ? parent.height - headerHeight : parent.height * 0.5
color: datovkaPalette.base
ListModel {
id: messageDetailModel
......
......@@ -843,12 +843,10 @@ bool Files::parseXmlData(QString *idStr, QString *annotation,
{
qDebug("%s()", __func__);
bool success = false;
if (xmlData.isEmpty()) {
Q_ASSERT(0);
qCritical() << "XML content is empty!";
return success;
return false;
}
//qDebug() << xmlData;
......@@ -860,56 +858,65 @@ bool Files::parseXmlData(QString *idStr, QString *annotation,
"<SOAP-ENV:Body>");
xmlData.append("</SOAP-ENV:Body></SOAP-ENV:Envelope>");
/* Test if zfo is meaage, delivery info or unknow format */
/* Test if zfo is message, delivery info or unknow format */
if (xmlData.contains(QByteArray("MessageDownloadResponse"))) {
return parseMesageXmlData(idStr, annotation, msgDescrHtml,
attachModel, emailBody, xmlData);
return parseAndShowXmlData(false, idStr, annotation,
msgDescrHtml, attachModel, emailBody, xmlData);
} else if (xmlData.contains(QByteArray("GetDeliveryInfoResponse"))) {
return parseDeliveryInfoXmlData(idStr, msgDescrHtml, xmlData);
return parseAndShowXmlData(true, idStr, annotation,
msgDescrHtml, attachModel, emailBody, xmlData);
} else {
qDebug() << "Unknow zfo format";
Q_ASSERT(0);
return success;
}
return success;
return false;
}
bool Files::parseMesageXmlData(QString *idStr, QString *annotation,
QString *msgDescrHtml, FileListModel *attachModel, QString *emailBody,
QByteArray &xmlData)
bool Files::parseAndShowXmlData(bool isDeliveryInfo, QString *idStr,
QString *annotation, QString *msgDescrHtml, FileListModel *attachModel,
QString *emailBody, QByteArray &xmlData)
{
qDebug("%s()", __func__);
Q_UNUSED(idStr);
bool success = false;
QXmlStreamReader xml;
xml.addData(xmlData);
XmlLayer xmlLayer;
Messages::Message msg;
QList<Files::File> fileList;
QList<Messages::Event> eventList;
/* parse message envelope and files */
xml.addData(xmlData);
while(!xml.atEnd() && !xml.hasError()) {
QXmlStreamReader::TokenType token = xml.readNext();
if (xml.error() != QXmlStreamReader::NoError) {
return success;
return false;
}
if (token == QXmlStreamReader::StartDocument) {
continue;
}
if (token == QXmlStreamReader::StartElement) {
if (xml.name() == "dmDm") {
success = xmlLayer.completeMessageParse(xml,
msg, fileList);
xmlLayer.completeMessageParse(xml, msg, fileList);
}
}
}
if (!success) {
return success;
if (isDeliveryInfo) {
/* parse delivery info */
xml.clear();
xml.addData(xmlData);
while(!xml.atEnd() && !xml.hasError()){
QXmlStreamReader::TokenType token = xml.readNext();
if (token == QXmlStreamReader::StartDocument) {
continue;
}
if (token == QXmlStreamReader::StartElement) {
if (xml.name() == "dmEvent") {
eventList.append(xmlLayer.parseEvent(xml));
}
}
}
}
QString html = divStart;
......@@ -992,6 +999,17 @@ bool Files::parseMesageXmlData(QString *idStr, QString *annotation,
html += strongInfoLine(QObject::tr("Status"),
QString::number(msg.dmMessageStatus));
if (isDeliveryInfo) {
html += "<h3>" + QObject::tr("Events") + "</h3>";
foreach (const Messages::Event &event, eventList) {
html += divStart +
strongInfoLine(dateTimeStrFromDbFormat(
dateTimeStrToUTCDbFormat(event.dmEventTime),
DATETIME_QML_FORMAT), event.dmEventDescr)
+ divEnd;
}
}
html += divEnd;
// Create body for email
......@@ -1002,7 +1020,10 @@ bool Files::parseMesageXmlData(QString *idStr, QString *annotation,
body += QObject::tr("TO") + ": ";
body += msg.dmRecipient + "\n";
body += QObject::tr("DELIVERED") + ": ";
body += dateTimeStrFromDbFormat(dateTimeStrToUTCDbFormat(msg.dmAcceptanceTime), DATETIME_QML_FORMAT) + "\n\n---\n";
body += dateTimeStrFromDbFormat(
dateTimeStrToUTCDbFormat(msg.dmAcceptanceTime),
DATETIME_QML_FORMAT)
+ "\n\n---\n";
body += QObject::tr("This email has been generated with Datovka "
"application based on a data message (%1) delivered "
"to databox.").arg(msg.dmID);
......@@ -1027,55 +1048,5 @@ bool Files::parseMesageXmlData(QString *idStr, QString *annotation,
stackFileList.push(fileList);
stackMessageDetail.push(html);
return success;
}
bool Files::parseDeliveryInfoXmlData(QString *idStr, QString *msgDescrHtml,
QByteArray &xmlData)
{
qDebug("%s()", __func__);
QString dmID;
QXmlStreamReader xml;
xml.addData(xmlData);
XmlLayer xmlLayer;
QList<Messages::Event> eventList;
while(!xml.atEnd() && !xml.hasError()){
QXmlStreamReader::TokenType token = xml.readNext();
if (token == QXmlStreamReader::StartDocument) {
continue;
}
if (token == QXmlStreamReader::StartElement) {
if (xml.name() == "dmEvent") {
eventList.append(xmlLayer.parseEvent(xml));
}
if (xml.name() == "dmID") {
xml.readNext();
dmID = xml.text().toString();
}
}
}
QString html = divStart;
html += "<h3>" + QObject::tr("Events") + "</h3>";
foreach (const Messages::Event &event, eventList) {
html += event.dmEventTime + ": " + event.dmEventDescr + "<br/>";
}
html += divEnd;
if (idStr != Q_NULLPTR) {
*idStr = dmID;
}
if (msgDescrHtml != Q_NULLPTR) {
*msgDescrHtml = html;
}
QList<Files::File> fileList;
// remember file list and message detail
stackFileList.push(fileList);
stackMessageDetail.push(html);
return true;
}
......@@ -318,8 +318,9 @@ private:
QString *emailBody, QByteArray xmlData);
/*!
* @brief Parse message xml data of zfo file.
* @brief Parse and show xml data of zfo file.
*
* @param[in] isDeliveryInfo True if zfo file is delivery infos.
* @param[out] idStr Message identifier number held in a string.
* @param[out] annotation Annotation string.
* @param[out] msgDescrHtml Message text.
......@@ -329,21 +330,9 @@ private:
* @return true if success.
*/
static
bool parseMesageXmlData(QString *idStr, QString *annotation,
QString *msgDescrHtml, FileListModel *attachModel, QString
*emailBody, QByteArray &xmlData);
/*!
* @brief Parse delivery info xml data of zfo file.
*
* @param[out] idStr Message identifier number held in a string.
* @param[out] msgDescrHtml Delivery info text.
* @param[in] xmlData Xml file data.
* @return true if success.
*/
static
bool parseDeliveryInfoXmlData(QString *idStr, QString *msgDescrHtml,
QByteArray &xmlData);
bool parseAndShowXmlData(bool isDeliveryInfo, QString *idStr,
QString *annotation, QString *msgDescrHtml,
FileListModel *attachModel, QString *emailBody, QByteArray &xmlData);
};
#endif // FILES_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment