Commit 5bf65894 authored by Karel Slaný's avatar Karel Slaný

Removed globMessagesModel calls from C++ code.

parent 8052c201
......@@ -160,7 +160,7 @@ Component {
anchors.fill: parent
onClicked: {
if (index == 0) {
isds.downloadMessage(userName, msgType, msgId)
isds.downloadMessage(messageListModel, userName, msgType, msgId)
} else if (index == 1) {
messages.markMessageAsLocallyRead(messageListModel, userName, msgId, true)
} else if (index == 2) {
......
......@@ -29,6 +29,7 @@ import QtQuick.Dialogs 1.2
import QtGraphicalEffects 1.0
import cz.nic.mobileDatovka 1.0
import cz.nic.mobileDatovka.messages 1.0
import cz.nic.mobileDatovka.models 1.0
Component {
id: menuMessageDetail
......@@ -151,7 +152,7 @@ Component {
anchors.fill: parent
onClicked: {
if (index == 0) {
isds.downloadMessage(userName, msgType, msgId)
isds.downloadMessage(messageListModel, userName, msgType, msgId)
} else if (index == 1) {
files.sendAttachmentsWithEmailFromDb(userName, msgId)
} else if (index == 2) {
......
......@@ -204,7 +204,7 @@ Component {
anchors.fill: parent
onClicked: {
if (fromLocalDb) {
isds.downloadMessage(userName, msgType, zfoId)
isds.downloadMessage(messageListModel, userName, msgType, zfoId)
msgDescrHtml = messages.getMessageDetail(userName, zfoId)
attachmentModel.setFromDb(userName, zfoId)
emptyList.visible = (attachmentList.count == 0)
......@@ -415,7 +415,7 @@ Component {
if (downloadStart) {
downloadStart = false
if (fromLocalDb) {
isds.downloadMessage(userName, msgType, zfoId)
isds.downloadMessage(messageListModel, userName, msgType, zfoId)
msgDescrHtml = messages.getMessageDetail(userName, zfoId)
attachmentModel.setFromDb(userName, zfoId)
}
......
......@@ -193,11 +193,11 @@ Component {
if (downloadStart) {
downloadStart = false
if (msgType == MessageType.TYPE_RECEIVED) {
isds.syncSingleAccountReceived(userName)
isds.syncSingleAccountReceived(messageListModel, userName)
} else if (msgType == MessageType.TYPE_SENT) {
isds.syncSingleAccountSent(userName)
isds.syncSingleAccountSent(messageListModel, userName)
}
messages.fillMessageList(userName, msgType)
messages.fillMessageList(messageListModel, userName, msgType)
}
}
onDragEnded: {
......
......@@ -52,13 +52,14 @@ void IsdsWrapper::syncOneAccount(const QString &userName)
{
qDebug("%s()", __func__);
if (syncSingleAccountSent(userName)) {
if (syncSingleAccountSent(QVariant(), userName)) {
/* Download received only when sent successfully downloaded. */
syncSingleAccountReceived(userName);
syncSingleAccountReceived(QVariant(), userName);
}
}
bool IsdsWrapper::syncSingleAccountReceived(const QString &userName)
bool IsdsWrapper::syncSingleAccountReceived(const QVariant &msgModelVariant,
const QString &userName)
{
if (userName.isEmpty()) {
Dialogues::errorMessage(Dialogues::CRITICAL,
......@@ -95,16 +96,23 @@ bool IsdsWrapper::syncSingleAccountReceived(const QString &userName)
saveAllSettings();
if (globSet.downloadCompleteMsgs) {
MessageListModel *messageModel =
MessageListModel::fromVariant(msgModelVariant);
if (messageModel == Q_NULLPTR) {
qWarning("%s", "Cannot access message model.");
}
foreach (qint64 msgId, receivedMsgIds) {
downloadMessage(userName, MessageDb::TYPE_RECEIVED,
msgId);
downloadMessage(messageModel, userName,
MessageDb::TYPE_RECEIVED, msgId);
}
}
return true;
}
bool IsdsWrapper::syncSingleAccountSent(const QString &userName)
bool IsdsWrapper::syncSingleAccountSent(const QVariant &msgModelVariant,
const QString &userName)
{
if (userName.isEmpty()) {
Dialogues::errorMessage(Dialogues::CRITICAL,
......@@ -137,8 +145,15 @@ bool IsdsWrapper::syncSingleAccountSent(const QString &userName)
}
if (globSet.downloadCompleteMsgs) {
MessageListModel *messageModel =
MessageListModel::fromVariant(msgModelVariant);
if (messageModel == Q_NULLPTR) {
qWarning("%s", "Cannot access message model.");
}
foreach (qint64 msgId, sentMsgIds) {
downloadMessage(userName, MessageDb::TYPE_SENT, msgId);
downloadMessage(messageModel, userName,
MessageDb::TYPE_SENT, msgId);
}
}
......@@ -206,66 +221,16 @@ bool IsdsWrapper::getAccountInfo(const QString &userName, bool isFirstLogin)
return true;
}
void IsdsWrapper::downloadMessage(const QString &userName, int mesasgeType,
qint64 msgId)
void IsdsWrapper::downloadMessage(const QVariant &msgModelVariant,
const QString &userName, int messageType, qint64 msgId)
{
qDebug("%s()", __func__);
QString errTxt = tr("Wrong username or message ID");
if (userName.isEmpty() || msgId <= 0) {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Error"), errTxt, tr("Internal error"));
return;
MessageListModel *messageModel =
MessageListModel::fromVariant(msgModelVariant);
if (messageModel == Q_NULLPTR) {
qWarning("%s", "Cannot access message model.");
}
if (!isLoggedToIsds(userName, errTxt)) {
showLoginProblemDialog(userName, errTxt);
return;
}
emit statusBarTextChanged(tr("Downloading message %1").
arg(QString::number(msgId)), true, true);
if (mesasgeType == MessageDb::TYPE_RECEIVED) {
/* NOTE: Method isdsGetCompleteMsgWithoutCms() is obsolete
* according ISDS specification. Not used now.
* The isdsGetCompleteReceivedMsgWithCms() method is used.
*/
if (!m_xmlLayer.isdsGetCompleteReceivedMsgWithCms(
m_isdsSession.isdsCtxMap[userName], msgId)) {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Downloading message: %1").arg(userName),
tr("Failed to download complete received message %1.").arg(msgId),
m_isdsSession.isdsCtxMap[userName].last_isds_msg);
return;
}
} else {
if (!m_xmlLayer.isdsGetCompleteSentMsgWithCms(
m_isdsSession.isdsCtxMap[userName], msgId)) {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Downloading message: %1").arg(userName),
tr("Failed to download complete sent message %1.").arg(msgId),
m_isdsSession.isdsCtxMap[userName].last_isds_msg);
return;
}
}
/* Downloading complete message succeeded. */
globMessagesModel.overrideDownloaded(msgId, true);
m_xmlLayer.isdsGetMsgAuthorInfo(m_isdsSession.isdsCtxMap[userName], msgId);
m_xmlLayer.isdsMarkMsgAsDownloaded(m_isdsSession.isdsCtxMap[userName],
msgId);
/* NOTE: Method isdsGetMsgDeliveryInfoWithoutCms() is obsolete
* according ISDS specification. Not used now.
* The isdsGetMsgDeliveryInfoWithCms() method is used.
*/
m_xmlLayer.isdsGetMsgDeliveryInfoWithCms(
m_isdsSession.isdsCtxMap[userName], msgId);
emit statusBarTextChanged(tr("Message %1 has been downloaded").arg(msgId),
false, true);
downloadMessage(messageModel, userName, messageType, msgId);
}
void IsdsWrapper::getDeliveryInfo(const QString &userName, qint64 msgId)
......@@ -453,6 +418,71 @@ void IsdsWrapper::removeIsdsCtx(const QString &userName)
m_isdsSession.removeIsdsCtx(userName);
}
void IsdsWrapper::downloadMessage(MessageListModel *messageModel,
const QString &userName, int messageType, qint64 msgId)
{
qDebug("%s()", __func__);
QString errTxt = tr("Wrong username or message ID");
if (userName.isEmpty() || msgId <= 0) {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Error"), errTxt, tr("Internal error"));
return;
}
if (!isLoggedToIsds(userName, errTxt)) {
showLoginProblemDialog(userName, errTxt);
return;
}
emit statusBarTextChanged(tr("Downloading message %1").
arg(QString::number(msgId)), true, true);
if (messageType == MessageDb::TYPE_RECEIVED) {
/*
* NOTE: Method isdsGetCompleteMsgWithoutCms() is obsolete
* according ISDS specification. Not used now.
* The isdsGetCompleteReceivedMsgWithCms() method is used.
*/
if (!m_xmlLayer.isdsGetCompleteReceivedMsgWithCms(
m_isdsSession.isdsCtxMap[userName], msgId)) {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Downloading message: %1").arg(userName),
tr("Failed to download complete received message %1.").arg(msgId),
m_isdsSession.isdsCtxMap[userName].last_isds_msg);
return;
}
} else {
if (!m_xmlLayer.isdsGetCompleteSentMsgWithCms(
m_isdsSession.isdsCtxMap[userName], msgId)) {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Downloading message: %1").arg(userName),
tr("Failed to download complete sent message %1.").arg(msgId),
m_isdsSession.isdsCtxMap[userName].last_isds_msg);
return;
}
}
/* Downloading complete message succeeded. */
if (messageModel != Q_NULLPTR) {
messageModel->overrideDownloaded(msgId, true);
}
m_xmlLayer.isdsGetMsgAuthorInfo(m_isdsSession.isdsCtxMap[userName], msgId);
m_xmlLayer.isdsMarkMsgAsDownloaded(m_isdsSession.isdsCtxMap[userName],
msgId);
/* NOTE: Method isdsGetMsgDeliveryInfoWithoutCms() is obsolete
* according ISDS specification. Not used now.
* The isdsGetMsgDeliveryInfoWithCms() method is used.
*/
m_xmlLayer.isdsGetMsgDeliveryInfoWithCms(
m_isdsSession.isdsCtxMap[userName], msgId);
emit statusBarTextChanged(tr("Message %1 has been downloaded").arg(msgId),
false, true);
}
void IsdsWrapper::showLoginProblemDialog(const QString &userName,
const QString &errTxt)
{
......
......@@ -29,6 +29,8 @@
#include "src/net/isds_session.h"
#include "src/net/xml_layer.h"
class MessageListModel; /* Forward declaration. */
/*
* Class IsdsWrapper provides interface between QML and isds core.
* Class is initialised in main function (main.cpp).
......@@ -57,20 +59,26 @@ public:
/*!
* @brief Download received message list.
*
* @param[in] userName Account username string.
* @param[in,out] msgModelVariant QVariant holding message model
* to be altered.
* @param[in] userName Account username string.
* @return True on success.
*/
Q_INVOKABLE
bool syncSingleAccountReceived(const QString &userName);
bool syncSingleAccountReceived(const QVariant &msgModelVariant,
const QString &userName);
/*!
* @brief Download list of sent messages.
*
* @param[in] userName Account username string.
* @param[in,out] msgModelVariant QVariant holding message model
* to be altered.
* @param[in] userName Account username string.
* @return True on success.
*/
Q_INVOKABLE
bool syncSingleAccountSent(const QString &userName);
bool syncSingleAccountSent(const QVariant &msgModelVariant,
const QString &userName);
/*!
* @brief Download account info.
......@@ -86,13 +94,15 @@ public:
/*!
* @brief Downloads complete message.
*
* @param[in] userName Account username string.
* @param[in] mesasgeType Message orientation.
* @param[in] msgId Message ID.
* @param[in,out] msgModelVariant QVariant holding message model
* to be altered.
* @param[in] userName Account username string.
* @param[in] messageType Message orientation.
* @param[in] msgId Message ID.
*/
Q_INVOKABLE
void downloadMessage(const QString &userName, int mesasgeType,
qint64 msgId);
void downloadMessage(const QVariant &msgModelVariant,
const QString &userName, int messageType, qint64 msgId);
/*!
* @brief Downloads delivery info.
......@@ -155,6 +165,17 @@ public slots:
void removeIsdsCtx(const QString &userName);
private:
/*!
* @brief Downloads complete message.
*
* @param[in,out] messageModel Message model to be altered.
* @param[in] userName Account username string.
* @param[in] messageType Message orientation.
* @param[in] msgId Message ID.
*/
void downloadMessage(MessageListModel *messageModel,
const QString &userName, int messageType, qint64 msgId);
/*!
* @brief Show notification dialog when any login problem was occurred.
*
......
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