Commit 9e734afd authored by Karel Slaný's avatar Karel Slaný

Unsupported ZFO content notification.

parent 5fa524a7
......@@ -49,13 +49,7 @@ Component {
property string msgAnnotation
property string msgDescrHtml /* Message HTML description. */
property string emailBody
/*
* showDeliveryInfo modify visibility of some elements on this page.
* False means that zfo is message and attachment list with files is shown.
* True means that zfo is delivery info and attachment list with files is hidden.
*/
property bool showDeliveryInfo: false
property int zfoType: MsgInfo.TYPE_UNKNOWN
function setTopButtonVisibility() {
/* More than two visible icons causes problems on iOS devices. */
......@@ -71,21 +65,20 @@ Component {
/* This method also sets the attachment model. */
var msgInfo = files.zfoData(attachmentModel, rawZfoContent)
/* If not valid zfo content, close this page */
if (msgInfo.idStr.length == 0) {
msgInfo.descrHtml = qsTr("File either doesn't contain a valid message or delivery information or it is corrupt.")
}
zfoId = msgInfo.idStr
msgAnnotation = msgInfo.annotation
msgDescrHtml = msgInfo.descrHtml
emailBody = msgInfo.emailBody
showDeliveryInfo = msgInfo.deliveryInfo
zfoType = msgInfo.type
if (zfoType == MsgInfo.TYPE_UNKNOWN) {
errorNotification.text = qsTr("File doesn't contain a valid message nor does it contain valid delivery information or the file is corrupt.")
errorNotification.visible = true
}
attachmentLabel.visible = !showDeliveryInfo
emptyList.visible = !showDeliveryInfo
attachmentList.visible = !showDeliveryInfo
attachmentLabel.visible = zfoType == MsgInfo.TYPE_MESSAGE
emptyList.visible = zfoType == MsgInfo.TYPE_MESSAGE
attachmentList.visible = zfoType == MsgInfo.TYPE_MESSAGE
console.log("Loaded page content from ZFO.")
rawZfoContent = null /* There is no need to remember this. */
......@@ -98,6 +91,8 @@ Component {
msgDescrHtml = messages.getMessageDetail(userName, zfoId)
attachmentModel.setFromDb(userName, zfoId)
zfoType = MsgInfo.TYPE_MESSAGE
console.log("Loaded page content from database.")
}
......@@ -160,10 +155,12 @@ Component {
Text {
text: if (fromLocalDb) {
acntName + " (" + userName + ")"
} else if (showDeliveryInfo) {
} else if (zfoType == MsgInfo.TYPE_MESSAGE) {
qsTr("Message from ZFO")
} else if (zfoType == MsgInfo.TYPE_DELIVERY_INFO) {
qsTr("Delivery info from ZFO")
} else {
qsTr("Message from ZFO")
qsTr("Unknown ZFO content")
}
font.bold: true
color: datovkaPalette.text
......@@ -174,8 +171,10 @@ Component {
qsTr("Received message") + " " + zfoId
} else if (fromLocalDb && (msgType == MessageType.TYPE_SENT)) {
qsTr("Sent message") + " " + zfoId
} else {
} else if (zfoType != MsgInfo.TYPE_UNKNOWN) {
qsTr("Message ID") + " " + zfoId
} else {
"" /* Empty string. */
}
}
font.bold: true
......@@ -262,7 +261,7 @@ Component {
id: messageDetail
anchors.top: header.bottom
width: parent.width
height: (showDeliveryInfo) ? parent.height - headerHeight : parent.height * 0.5
height: (zfoType == MsgInfo.TYPE_MESSAGE) ? parent.height * 0.5 : parent.height - headerHeight
color: datovkaPalette.base
ListModel {
id: messageDetailModel
......@@ -289,6 +288,17 @@ Component {
text: msgDescrHtml
}
}
Text {
id: errorNotification
visible: false
color: datovkaPalette.text
anchors.left: parent.left
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
horizontalAlignment: Text.AlignHCenter
wrapMode: Text.WordWrap
text: ""
}
}
Item {
id: attachmentLabel
......
......@@ -28,7 +28,7 @@
#include <QFileDialog>
#include <QMessageBox>
#include <QMimeType>
#include <QStack>
#include <QQmlEngine> /* qmlRegisterType */
#include "src/files.h"
#include "src/common.h"
......@@ -127,7 +127,6 @@ void finishEmailMessage(QString &message, const QString &boundary)
message += newLine + "--" + boundary + "--" + newLine;
}
Files::Files(QObject *parent) : QObject(parent)
{
}
......@@ -522,15 +521,15 @@ QByteArray Files::base64ToRaw(const QByteArray &base64Data)
MsgInfo *Files::zfoData(const QVariant &attachModelVariant,
const QByteArray &rawZfoData)
{
bool deliveryInfo = false;
enum MsgInfo::ZfoType type = MsgInfo::TYPE_UNKNOWN;
QString idStr, annot, htmlDescr, emailBody;
bool ret = parseXmlData(&deliveryInfo, &idStr, &annot, &htmlDescr,
bool ret = parseXmlData(&type, &idStr, &annot, &htmlDescr,
FileListModel::modelFromVariant(attachModelVariant),
&emailBody, getXmlFromCms(rawZfoData));
return ret ?
new (std::nothrow) MsgInfo(deliveryInfo, idStr, annot, htmlDescr,
new (std::nothrow) MsgInfo(type, idStr, annot, htmlDescr,
emailBody) :
new (std::nothrow) MsgInfo();
}
......@@ -830,7 +829,7 @@ QByteArray Files::decodeZfoFile(const QByteArray &base64ZfoData)
return getXmlFromCms(QByteArray::fromBase64(base64ZfoData));
}
bool Files::parseXmlData(bool *deliveryInfo, QString *idStr,
bool Files::parseXmlData(enum MsgInfo::ZfoType *type, QString *idStr,
QString *annotation, QString *msgDescrHtml, FileListModel *attachModel,
QString *emailBody, QByteArray xmlData)
{
......@@ -850,28 +849,30 @@ bool Files::parseXmlData(bool *deliveryInfo, QString *idStr,
"<SOAP-ENV:Body>");
xmlData.append("</SOAP-ENV:Body></SOAP-ENV:Envelope>");
/* Test if zfo is message, delivery info or unknow format */
/* Test if zfo is message, delivery info or unknown format */
if (xmlData.contains(QByteArray("MessageDownloadResponse"))) {
if (deliveryInfo != Q_NULLPTR) {
*deliveryInfo = false;
if (type != Q_NULLPTR) {
*type = MsgInfo::TYPE_MESSAGE;
}
return parseAndShowXmlData(false, idStr, annotation,
msgDescrHtml, attachModel, emailBody, xmlData);
return parseAndShowXmlData(MsgInfo::TYPE_MESSAGE, idStr,
annotation, msgDescrHtml, attachModel, emailBody, xmlData);
} else if (xmlData.contains(QByteArray("GetDeliveryInfoResponse"))) {
if (deliveryInfo != Q_NULLPTR) {
*deliveryInfo = true;
if (type != Q_NULLPTR) {
*type = MsgInfo::TYPE_DELIVERY_INFO;
}
return parseAndShowXmlData(true, idStr, annotation,
msgDescrHtml, attachModel, emailBody, xmlData);
return parseAndShowXmlData(MsgInfo::TYPE_DELIVERY_INFO, idStr,
annotation, msgDescrHtml, attachModel, emailBody, xmlData);
} else {
qCritical() << "Unknow ZFO format";
Q_ASSERT(0);
if (type != Q_NULLPTR) {
*type = MsgInfo::TYPE_UNKNOWN;
}
qCritical() << "Unknown ZFO format";
}
return false;
}
bool Files::parseAndShowXmlData(bool isDeliveryInfo, QString *idStr,
bool Files::parseAndShowXmlData(enum MsgInfo::ZfoType type, QString *idStr,
QString *annotation, QString *msgDescrHtml, FileListModel *attachModel,
QString *emailBody, QByteArray &xmlData)
{
......@@ -883,6 +884,11 @@ bool Files::parseAndShowXmlData(bool isDeliveryInfo, QString *idStr,
QList<Files::File> fileList;
QList<Messages::Event> eventList;
if (type == MsgInfo::TYPE_UNKNOWN) {
Q_ASSERT(0);
return false;
}
/* parse message envelope and files */
xml.addData(xmlData);
while(!xml.atEnd() && !xml.hasError()) {
......@@ -900,7 +906,7 @@ bool Files::parseAndShowXmlData(bool isDeliveryInfo, QString *idStr,
}
}
if (isDeliveryInfo) {
if (type == MsgInfo::TYPE_DELIVERY_INFO) {
/* parse delivery info */
xml.clear();
xml.addData(xmlData);
......@@ -997,7 +1003,7 @@ bool Files::parseAndShowXmlData(bool isDeliveryInfo, QString *idStr,
html += strongInfoLine(QObject::tr("Status"),
QString::number(msg.dmMessageStatus));
if (isDeliveryInfo) {
if (type == MsgInfo::TYPE_DELIVERY_INFO) {
html += "<h3>" + QObject::tr("Events") + "</h3>";
foreach (const Messages::Event &event, eventList) {
html += divStart +
......
......@@ -296,8 +296,7 @@ private:
* @todo This function must be reworked as it is called multiple times
* on a single message to obtain various data.
*
* @param[out] deliveryInfo Set to true if ZFO contains delivery
* information.
* @param[out] type ZFO type.
* @param[out] idStr Message identifier number held in a string.
* @param[out] annotation Annotation string.
* @param[out] msgDescrHtml Message text.
......@@ -307,14 +306,14 @@ private:
* @return true if success.
*/
static
bool parseXmlData(bool *deliveryInfo, QString *idStr,
bool parseXmlData(enum MsgInfo::ZfoType *type, QString *idStr,
QString *annotation, QString *msgDescrHtml,
FileListModel *attachModel, QString *emailBody, QByteArray xmlData);
/*!
* @brief Parse and show xml data of zfo file.
*
* @param[in] isDeliveryInfo True if zfo file is delivery infos.
* @param[in] type ZFO file type.
* @param[out] idStr Message identifier number held in a string.
* @param[out] annotation Annotation string.
* @param[out] msgDescrHtml Message text.
......@@ -324,7 +323,7 @@ private:
* @return true if success.
*/
static
bool parseAndShowXmlData(bool isDeliveryInfo, QString *idStr,
bool parseAndShowXmlData(enum MsgInfo::ZfoType type, QString *idStr,
QString *annotation, QString *msgDescrHtml,
FileListModel *attachModel, QString *emailBody, QByteArray &xmlData);
};
......
/*
* Copyright (C) 2014-2016 CZ.NIC
* Copyright (C) 2014-2017 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -41,14 +41,14 @@ public:
};
Q_ENUMS(MessageType)
/* Don't forget to declare various propertiers to the QML system. */
/* Don't forget to declare various properties to the QML system. */
static
void declareQML(void);
Messages(QObject* parent = 0);
Messages(QObject* parent = Q_NULLPTR);
/*!
* @brief Load messages from databse and fill QML listview via model.
* @brief Load messages from database and fill QML listview via model.
*/
Q_INVOKABLE void fillMessageList(const QString &userName,
enum MessageType msgType);
......
......@@ -33,7 +33,7 @@ void MsgInfo::declareQML(void)
MsgInfo::MsgInfo(QObject *parent)
: QObject(parent),
m_deliveryInfo(false),
m_type(TYPE_UNKNOWN),
m_idStr(),
m_annotation(),
m_descrHtml(),
......@@ -43,7 +43,7 @@ MsgInfo::MsgInfo(QObject *parent)
MsgInfo::MsgInfo(const MsgInfo &info)
: QObject(),
m_deliveryInfo(info.m_deliveryInfo),
m_type(info.m_type),
m_idStr(info.m_idStr),
m_annotation(info.m_annotation),
m_descrHtml(info.m_descrHtml),
......@@ -51,11 +51,11 @@ MsgInfo::MsgInfo(const MsgInfo &info)
{
}
MsgInfo::MsgInfo(bool deliveryInfo, const QString &idStr,
MsgInfo::MsgInfo(enum ZfoType type, const QString &idStr,
const QString &annotation, const QString &descrHtml,
const QString &emailBody, QObject *parent)
: QObject(parent),
m_deliveryInfo(deliveryInfo),
m_type(type),
m_idStr(idStr),
m_annotation(annotation),
m_descrHtml(descrHtml),
......@@ -63,15 +63,15 @@ MsgInfo::MsgInfo(bool deliveryInfo, const QString &idStr,
{
}
bool MsgInfo::deliveryInfo(void) const
enum MsgInfo::ZfoType MsgInfo::type(void) const
{
return m_deliveryInfo;
return m_type;
}
void MsgInfo::setDeliveryInfo(bool deliveryInfo)
void MsgInfo::setType(enum ZfoType type)
{
m_deliveryInfo = deliveryInfo;
emit deliveryInfoChanged(m_deliveryInfo);
m_type = type;
emit typeChanged(m_type);
}
QString MsgInfo::idStr(void) const
......
......@@ -32,13 +32,21 @@
*/
class MsgInfo : public QObject {
Q_OBJECT
Q_PROPERTY(bool deliveryInfo READ deliveryInfo WRITE setDeliveryInfo NOTIFY deliveryInfoChanged)
Q_PROPERTY(enum ZfoType type READ type WRITE setType NOTIFY typeChanged)
Q_PROPERTY(QString idStr READ idStr WRITE setIdStr NOTIFY idStrChanged)
Q_PROPERTY(QString annotation READ annotation WRITE setAnnotation NOTIFY annotationChanged)
Q_PROPERTY(QString descrHtml READ descrHtml WRITE setDescrHtml NOTIFY descrHtmlChanged)
Q_PROPERTY(QString emailBody READ emailBody WRITE setEmailBody NOTIFY emailBodyChanged)
public:
/* Specifies type of ZFO. */
enum ZfoType {
TYPE_UNKNOWN, /*!< Unknown or unsupported type. */
TYPE_MESSAGE, /*!< Message or message envelope. */
TYPE_DELIVERY_INFO /*!< Delivery information. */
};
Q_ENUMS(ZfoType)
/* Don't forget to declare various properties to the QML system. */
static
void declareQML(void);
......@@ -59,12 +67,12 @@ public:
*/
MsgInfo(const MsgInfo &info);
MsgInfo(bool deliveryInfo, const QString &idStr,
MsgInfo(enum ZfoType type, const QString &idStr,
const QString &annotation, const QString &descrHtml,
const QString &emailBody, QObject *parent = Q_NULLPTR);
bool deliveryInfo(void) const;
void setDeliveryInfo(bool deliveryInfo);
enum ZfoType type(void) const;
void setType(enum ZfoType type);
QString idStr(void) const;
void setIdStr(const QString &idStr);
......@@ -79,14 +87,14 @@ public:
void setEmailBody(const QString &emailBody);
signals:
void deliveryInfoChanged(bool newDeliveryInfo);
void typeChanged(enum ZfoType newType);
void idStrChanged(const QString &newIdStr);
void annotationChanged(const QString &newAnnotation);
void descrHtmlChanged(const QString &newDescrHtml);
void emailBodyChanged(const QString &newEmailBody);
private:
bool m_deliveryInfo; /*!< True if it is a delivery information. */
enum ZfoType m_type;
QString m_idStr; /*!< Message identifier as a string. */
QString m_annotation; /*!< Message annotation. */
QString m_descrHtml; /*!< Description in HTML. */
......@@ -95,5 +103,6 @@ private:
/* QML passes its arguments via QVariant. */
Q_DECLARE_METATYPE(MsgInfo)
Q_DECLARE_METATYPE(MsgInfo::ZfoType)
#endif /* _MESSAGE_INFO_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