Commit 3f4f797d authored by Karel Slaný's avatar Karel Slaný

Reduced number of ZFO file parsing when loading message detail page.

parent 311ac7a1
......@@ -95,6 +95,7 @@ SOURCES += \
src/models/filemodel.cpp \
src/models/messagemodel.cpp \
src/qml_interaction/interaction_zfo_file.cpp \
src/qml_interaction/message_info.cpp \
src/settings.cpp \
src/sqlite/account_db.cpp \
src/sqlite/dbs.cpp \
......@@ -125,6 +126,7 @@ HEADERS += \
src/models/filemodel.h \
src/models/messagemodel.h \
src/qml_interaction/interaction_zfo_file.h \
src/qml_interaction/message_info.h \
src/settings.h \
src/sqlite/account_db.h \
src/sqlite/dbs.h \
......
......@@ -27,6 +27,7 @@ import QtQuick.Window 2.1
import QtGraphicalEffects 1.0
import cz.nic.mobileDatovka.messages 1.0
import cz.nic.mobileDatovka.models 1.0
import cz.nic.mobileDatovka.msgInfo 1.0
Component {
id: componentMessageDetail
......@@ -52,17 +53,19 @@ Component {
function setTopButtonVisibility() {
/* More than two visible icons causes problems on iOS devices. */
msgEmailButton.visible = !fromLocalDb && (attachmentList.count > 0)
attachmentSaveButon.visible = !fromLocalDb && (attachmentList.count > 0)
attachmentSaveButon.visible = true //!fromLocalDb && (attachmentList.count > 0)
msgDownloadButton.visible = fromLocalDb && (attachmentList.count == 0)
attachmentMenuButon.visible = fromLocalDb && (attachmentList.count > 0)
}
function fillContentFromDb() {
if (!fromLocalDb && (rawZfoContent != null)) {
zfoId = files.msgIdString(rawZfoContent)
msgAnnotation = files.msgAnnotation(rawZfoContent),
msgDescrHtml = files.msgDescriptionHtml(rawZfoContent),
emailBody = files.msgEmailBody(rawZfoContent)
var msgInfo = files.msgInfo(rawZfoContent)
zfoId = msgInfo.idStr
msgAnnotation = msgInfo.annotation
msgDescrHtml = msgInfo.descrHtml
emailBody = msgInfo.emailBody
attachmentModel.setZfo(rawZfoContent)
......
......@@ -523,40 +523,16 @@ QByteArray Files::base64ToRaw(const QByteArray &base64Data)
return QByteArray::fromBase64(base64Data);
}
QString Files::msgIdString(const QByteArray &rawZfoData)
MsgInfo *Files::msgInfo(const QByteArray &rawZfoData)
{
QString msgId;
bool ret = parseXmlData(&msgId, Q_NULLPTR, Q_NULLPTR, Q_NULLPTR,
Q_NULLPTR, getXmlFromCms(rawZfoData));
return ret ? msgId : QString();
}
QString Files::msgAnnotation(const QByteArray &rawZfoData)
{
QString annotation;
bool ret = parseXmlData(Q_NULLPTR, &annotation, Q_NULLPTR, Q_NULLPTR,
Q_NULLPTR, getXmlFromCms(rawZfoData));
return ret ? annotation : QString();
}
QString Files::msgDescriptionHtml(const QByteArray &rawZfoData)
{
QString htmlDescr;
bool ret = parseXmlData(Q_NULLPTR, Q_NULLPTR, &htmlDescr, Q_NULLPTR,
Q_NULLPTR, getXmlFromCms(rawZfoData));
QString idStr, annot, htmlDescr, emailBody;
return ret ? htmlDescr : QString();
}
QString Files::msgEmailBody(const QByteArray &rawZfoData)
{
QString emailBody;
bool ret = parseXmlData(Q_NULLPTR, Q_NULLPTR, Q_NULLPTR, Q_NULLPTR,
bool ret = parseXmlData(&idStr, &annot, &htmlDescr, Q_NULLPTR,
&emailBody, getXmlFromCms(rawZfoData));
return ret ? emailBody : QString();
return ret ?
new (std::nothrow) MsgInfo(idStr, annot, htmlDescr, emailBody) :
new (std::nothrow) MsgInfo();
}
bool Files::setAttachmentModel(FileListModel &attachModel,
......
......@@ -27,6 +27,7 @@
#include <QObject>
#include "src/models/filemodel.h"
#include "src/qml_interaction/message_info.h"
/*
* Class Files provides interface between QML and file database.
......@@ -37,7 +38,7 @@ class Files : public QObject {
public:
/*!
* @brief Contructor.
* @brief Constructor.
*
* @param[in] parent Parent object.
*/
......@@ -147,44 +148,19 @@ public:
QByteArray base64ToRaw(const QByteArray &base64Data);
/*!
* @brief Return message id.
* @brief Parse content of ZFO file.
*
* @note QML hasn't got the faintest idea about qint64, therefore the
* number is passed as a string.
* @note QML handles deallocation of returned objects. For mode retail
* see section 'Data Ownerfhip'
* of 'Data Type Conversion Between QML and C++'
* at http://doc.qt.io/qt-5/qtqml-cppintegration-data.html .
*
* @param[in] rawZfoData Raw ZFO data.
* @return String containing message identifier number, or null string
* on error.
* @return Pointer to newly allocated structure containing message
* information.
*/
Q_INVOKABLE static
QString msgIdString(const QByteArray &rawZfoData);
/*!
* @brief Parses content of ZFO file.
*
* @param[in] rawZfoData Raw ZFO data.
* @return Annotation on success, empty string else.
*/
Q_INVOKABLE static
QString msgAnnotation(const QByteArray &rawZfoData);
/*!
* @brief Parses content of ZFO file.
*
* @param[in] rawZfoData Raw ZFO data.
* @return Message description on success, empty string else.
*/
Q_INVOKABLE static
QString msgDescriptionHtml(const QByteArray &rawZfoData);
/*!
* @brief Parses content of ZFO file.
*
* @param[in] rawZfoData Raw ZFO data.
* @return Email containing message on success, empty string else.
*/
Q_INVOKABLE static
QString msgEmailBody(const QByteArray &rawZfoData);
MsgInfo *msgInfo(const QByteArray &rawZfoData);
/*!
* @brief Sets attachment model.
......
......@@ -246,6 +246,7 @@ int main(int argc, char *argv[])
/* Register types into QML. */
FileListModel::declareQML();
Messages::declareQML();
MsgInfo::declareQML();
InteractionZfoFile interactionZfoFile;
......
......@@ -67,7 +67,7 @@ public:
ROLE_FILE_DATA
};
/* 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);
......
/*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
#include <QQmlEngine> /* qmlRegisterType */
#include "src/qml_interaction/message_info.h"
void MsgInfo::declareQML(void)
{
qmlRegisterType<MsgInfo>("cz.nic.mobileDatovka.msgInfo", 1, 0, "MsgInfo");
qRegisterMetaType<MsgInfo>();
}
MsgInfo::MsgInfo(QObject *parent)
: QObject(parent),
m_idStr(),
m_annotation(),
m_descrHtml(),
m_emailBody()
{
}
MsgInfo::MsgInfo(const MsgInfo &info)
: QObject(),
m_idStr(info.m_idStr),
m_annotation(info.m_annotation),
m_descrHtml(info.m_descrHtml),
m_emailBody(info.m_emailBody)
{
}
MsgInfo::MsgInfo(const QString &idStr, const QString &annotation,
const QString &descrHtml, const QString &emailBody, QObject *parent)
: QObject(parent),
m_idStr(idStr),
m_annotation(annotation),
m_descrHtml(descrHtml),
m_emailBody(emailBody)
{
}
QString MsgInfo::idStr(void) const
{
return m_idStr;
}
void MsgInfo::setIdStr(const QString &idStr)
{
m_idStr = idStr;
emit idStrChanged(m_idStr);
}
QString MsgInfo::annotation(void) const
{
return m_annotation;
}
void MsgInfo::setAnnotation(const QString &annotation)
{
m_annotation = annotation;
emit annotationChanged(m_annotation);
}
QString MsgInfo::descrHtml(void) const
{
return m_descrHtml;
}
void MsgInfo::setDescrHtml(const QString &descrHtml)
{
m_descrHtml = descrHtml;
emit descrHtmlChanged(m_descrHtml);
}
QString MsgInfo::emailBody(void) const
{
return m_emailBody;
}
void MsgInfo::setEmailBody(const QString &emailBody)
{
m_emailBody = emailBody;
emit emailBodyChanged(m_emailBody);
}
/*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
#ifndef _MESSAGE_INFO_H_
#define _MESSAGE_INFO_H_
#include <QObject>
#include <QString>
/*!
* @brief Just a convenience class to obtain some message information.
*/
class MsgInfo : public QObject {
Q_OBJECT
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:
/* Don't forget to declare various properties to the QML system. */
static
void declareQML(void);
/*!
* @brief Constructor.
*
* @param[in] parent Parent object.
*/
explicit MsgInfo(QObject *parent = Q_NULLPTR);
/*!
* @brief Copy constructor.
*
* @note Needed for QVariant conversion.
*
* @param[in] info Info to be copied.
*/
MsgInfo(const MsgInfo &info);
MsgInfo(const QString &idStr, const QString &annotation,
const QString &descrHtml, const QString &emailBody,
QObject *parent = Q_NULLPTR);
QString idStr(void) const;
void setIdStr(const QString &idStr);
QString annotation(void) const;
void setAnnotation(const QString &annotation);
QString descrHtml(void) const;
void setDescrHtml(const QString &descrHtml);
QString emailBody(void) const;
void setEmailBody(const QString &emailBody);
signals:
void idStrChanged(const QString &newIdStr);
void annotationChanged(const QString &newAnnotation);
void descrHtmlChanged(const QString &newDescrHtml);
void emailBodyChanged(const QString &newEmailBody);
private:
QString m_idStr; /*!< Message identifier as a string. */
QString m_annotation; /*!< Message annotation. */
QString m_descrHtml; /*!< Description in HTML. */
QString m_emailBody; /*!< Email body. */
};
/* QML passes its arguments via QVariant. */
Q_DECLARE_METATYPE(MsgInfo)
#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