Commit 15b83565 authored by Martin Straka's avatar Martin Straka

Some message tasks are asynchronous

parent 331df0c7
......@@ -118,6 +118,7 @@ SOURCES += \
src/sqlite/file_db.cpp \
src/sqlite/message_db_container.cpp \
src/sqlite/message_db.cpp \
src/worker/emitter.cpp \
src/worker/pool.cpp \
src/worker/task.cpp \
src/worker/task_change_password.cpp \
......@@ -165,6 +166,7 @@ HEADERS += \
src/sqlite/file_db.h \
src/sqlite/message_db_container.h \
src/sqlite/message_db.h \
src/worker/emitter.h \
src/worker/pool.h \
src/worker/task.h \
src/worker/task_change_password.h \
......
......@@ -110,10 +110,7 @@ Component {
anchors.fill: parent
onClicked: {
statusBarText.text = ""
if (isds.syncAllAccounts(accountModel)) {
settings.setLastUpdateToNow()
settings.saveAllSettings(accountModel)
}
isds.syncAllAccounts(accountModel)
}
}
}
......@@ -263,10 +260,7 @@ Component {
MouseArea {
anchors.fill: parent
onClicked: {
if (isds.syncOneAccount(accountModel, rUserName)) {
settings.setLastUpdateToNow()
settings.saveAllSettings(accountModel)
}
isds.syncOneAccount(accountModel, rUserName)
}
}
}
......@@ -424,5 +418,14 @@ Component {
}
ScrollIndicator.vertical: ScrollIndicator {}
}
Connections {
target: isds
onDownloadMessageListFinishedSig: {
if (isMsgReceived) {
settings.setLastUpdateToNow()
settings.saveAllSettings(accountModel)
}
}
}
}
}
......@@ -110,6 +110,13 @@ Component {
}
}
Connections {
target: isds
onDownloadMessageFinishedSig: {
fillContentFromDb()
}
}
PageHeader {
id: headerBar
title: {
......@@ -195,10 +202,6 @@ Component {
onClicked: {
if (fromLocalDb) {
isds.downloadMessage(messageModel, userName, msgType, zfoId)
msgDescrHtml = messages.getMessageDetail(userName, zfoId)
attachmentModel.setFromDb(userName, zfoId)
emptyList.visible = (attachmentList.count == 0)
setTopButtonVisibility()
}
}
}
......@@ -392,8 +395,6 @@ Component {
downloadStart = false
if (fromLocalDb) {
isds.downloadMessage(messageModel, userName, msgType, zfoId)
msgDescrHtml = messages.getMessageDetail(userName, zfoId)
attachmentModel.setFromDb(userName, zfoId)
}
}
}
......@@ -416,10 +417,6 @@ Component {
onClicked: {
if (fromLocalDb) {
isds.downloadMessage(messageModel, userName, msgType, zfoId)
msgDescrHtml = messages.getMessageDetail(userName, zfoId)
attachmentModel.setFromDb(userName, zfoId)
emptyList.visible = (attachmentList.count == 0)
setTopButtonVisibility()
}
}
}
......
......@@ -215,19 +215,25 @@ Component {
if (downloadStart) {
downloadStart = false
if (msgType == MessageType.TYPE_RECEIVED) {
if (isds.syncSingleAccountReceived(accountModel, messageModel, userName)) {
settings.setLastUpdateToNow()
settings.saveAllSettings(accountModel)
}
isds.syncSingleAccountReceived(accountModel, messageModel, userName)
} else if (msgType == MessageType.TYPE_SENT) {
isds.syncSingleAccountSent(accountModel, messageModel, userName)
}
messages.fillMessageList(messageModel, userName, msgType)
}
}
onDragEnded: {
downloadStart = contentY < -120
}
Connections {
target: isds
onDownloadMessageListFinishedSig: {
if (isMsgReceived) {
settings.setLastUpdateToNow()
settings.saveAllSettings(accountModel)
}
messages.fillMessageList(messageModel, userName, msgType)
}
}
}
}
}
......@@ -29,6 +29,7 @@
#include "src/net/isds_wrapper.h"
#include "src/net/xml_layer.h"
#include "src/settings.h"
#include "src/worker/emitter.h"
#include "src/worker/task_change_password.h"
#include "src/worker/task_download_account_info.h"
#include "src/worker/task_download_delivery_info.h"
......@@ -48,6 +49,17 @@ IsdsWrapper::IsdsWrapper(QObject *parent)
*/
{
m_workPool.start();
/* Worker-related processing signals. */
connect(&globMsgProcEmitter,
SIGNAL(downloadMessageFinishedSignal(QString, qint64, bool, QString)),
this,
SLOT(downloadMessageFinished(QString, qint64, bool, QString)));
connect(&globMsgProcEmitter,
SIGNAL(downloadMessageListFinishedSignal(QString, bool, QString, QString, bool)),
this,
SLOT(downloadMessageListFinished(QString, bool, QString, QString, bool)));
}
IsdsWrapper::~IsdsWrapper(void)
......@@ -56,51 +68,40 @@ IsdsWrapper::~IsdsWrapper(void)
m_workPool.stop();
}
bool IsdsWrapper::syncAllAccounts(const QVariant &acntModelVariant)
void IsdsWrapper::syncAllAccounts(const QVariant &acntModelVariant)
{
qDebug("%s()", __func__);
bool ret = false;
QList<QString> userNameList = AccountListModel::globAccounts.keys();
foreach (const QString userName, userNameList) {
if (syncOneAccount(acntModelVariant, userName)) {
ret = true;
}
syncOneAccount(acntModelVariant, userName);
}
return ret;
}
bool IsdsWrapper::syncOneAccount(const QVariant &acntModelVariant,
void IsdsWrapper::syncOneAccount(const QVariant &acntModelVariant,
const QString &userName)
{
qDebug("%s()", __func__);
if (syncSingleAccountSent(acntModelVariant, QVariant(), userName)) {
/* Download received only when sent successfully downloaded. */
return syncSingleAccountReceived(acntModelVariant, QVariant(),
userName);
}
return false;
syncSingleAccountSent(acntModelVariant, QVariant(), userName);
syncSingleAccountReceived(acntModelVariant, QVariant(), userName);
}
bool IsdsWrapper::syncSingleAccountReceived(const QVariant &acntModelVariant,
void IsdsWrapper::syncSingleAccountReceived(const QVariant &acntModelVariant,
const QVariant &msgModelVariant, const QString &userName)
{
return syncSingleAccount(acntModelVariant, msgModelVariant, userName,
syncSingleAccount(acntModelVariant, msgModelVariant, userName,
Messages::TYPE_RECEIVED);
}
bool IsdsWrapper::syncSingleAccountSent(const QVariant &acntModelVariant,
void IsdsWrapper::syncSingleAccountSent(const QVariant &acntModelVariant,
const QVariant &msgModelVariant, const QString &userName)
{
return syncSingleAccount(acntModelVariant, msgModelVariant, userName,
syncSingleAccount(acntModelVariant, msgModelVariant, userName,
Messages::TYPE_SENT);
}
bool IsdsWrapper::syncSingleAccount(const QVariant &acntModelVariant,
void IsdsWrapper::syncSingleAccount(const QVariant &acntModelVariant,
const QVariant &msgModelVariant, const QString &userName,
enum Messages::MessageType msgDirect)
{
......@@ -109,13 +110,13 @@ bool IsdsWrapper::syncSingleAccount(const QVariant &acntModelVariant,
if (userName.isEmpty()) {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Error"), tr("Empty user name"), tr("Internal error"));
return false;
return;
}
QString errText;
if (!isLoggedToIsds(userName, errText)) {
showLoginProblemDialog(userName, errText);
return false;
return;
}
QString msgType = tr("received");
......@@ -139,23 +140,24 @@ bool IsdsWrapper::syncSingleAccount(const QVariant &acntModelVariant,
msgDirect, (globSet.downloadOnlyNewMsgs) ? DOWNLOAD_NEW_MESSAGES : DOWNLOAD_ALL_MESSAGES,
1, MESSAGE_LIST_LIMIT, &m_workPool, messageModel, accountModel,
globSet.downloadCompleteMsgs, globSet.dbsLocation);
task->setAutoDelete(false);
m_workPool.runSingle(task);
/* Results from task */
const QString statusBarText = task->m_statusBarText;
bool success = TaskDownloadMessageList::DL_SUCCESS == task->m_result;
delete task;
task->setAutoDelete(true);
m_workPool.assignHi(task);
}
void IsdsWrapper::downloadMessageListFinished(const QString &userName,
bool success, const QString &statusBarText, const QString &errTxt,
bool isMsgReceived)
{
emit downloadMessageListFinishedSig(isMsgReceived);
if (!success) {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("%1: %2 messages").arg(userName).arg(msgType),
tr("Failed to download list of %1 messages for user name '%2'.").arg(msgType).arg(userName),
m_isdsSession.isdsCtxMap[userName].last_isds_msg);
tr("%1: messages").arg(userName),
tr("Failed to download list of messages for user name '%1'.").arg(userName),
errTxt);
} else {
emit statusBarTextChanged(statusBarText, false, true);
}
return success;
}
bool IsdsWrapper::getAccountInfo(const QString &userName, bool isFirstLogin)
......@@ -493,17 +495,20 @@ void IsdsWrapper::downloadMessage(MessageListModel *messageModel,
task = new (std::nothrow) TaskDownloadMessage(
m_isdsSession.isdsCtxMap[userName], &m_netLayer, &m_dbWrapper,
msgId, messageType, messageModel);
task->setAutoDelete(false);
m_workPool.runSingle(task);
task->setAutoDelete(true);
m_workPool.assignLo(task);
}
bool success = TaskDownloadMessage::DL_SUCCESS == task->m_result;
delete task;
void IsdsWrapper::downloadMessageFinished(const QString &userName, qint64 msgId,
bool success, const QString &errTxt)
{
emit downloadMessageFinishedSig();
if (!success) {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Downloading message: %1").arg(userName),
tr("Failed to download complete message %1.").arg(msgId),
m_isdsSession.isdsCtxMap[userName].last_isds_msg);
errTxt);
return;
} else {
emit statusBarTextChanged(tr("Message %1 has been downloaded").arg(msgId),
......
......@@ -55,7 +55,7 @@ public:
* synchronised.
*/
Q_INVOKABLE
bool syncAllAccounts(const QVariant &acntModelVariant);
void syncAllAccounts(const QVariant &acntModelVariant);
/*!
* @brief Download message list of one account.
......@@ -66,7 +66,7 @@ public:
* @return True on success.
*/
Q_INVOKABLE
bool syncOneAccount(const QVariant &acntModelVariant,
void syncOneAccount(const QVariant &acntModelVariant,
const QString &userName);
/*!
......@@ -80,7 +80,7 @@ public:
* @return True on success.
*/
Q_INVOKABLE
bool syncSingleAccountReceived(const QVariant &acntModelVariant,
void syncSingleAccountReceived(const QVariant &acntModelVariant,
const QVariant &msgModelVariant, const QString &userName);
/*!
......@@ -94,7 +94,7 @@ public:
* @return True on success.
*/
Q_INVOKABLE
bool syncSingleAccountSent(const QVariant &acntModelVariant,
void syncSingleAccountSent(const QVariant &acntModelVariant,
const QVariant &msgModelVariant, const QString &userName);
/*!
......@@ -198,6 +198,18 @@ signals:
*/
void statusBarTextChanged(QString txt, bool busy, bool isVisible);
/*!
* @brief Update message model in QML.
*/
void downloadMessageFinishedSig(void);
/*!
* @brief Update account and message model in QML.
*
* @param[in] isMsgReceived Message type, true = received.
*/
void downloadMessageListFinishedSig(bool isMsgReceived);
public slots:
/*!
* @brief Removed ISDS context of account. Run this slot
......@@ -207,6 +219,30 @@ public slots:
*/
void removeIsdsCtx(const QString &userName);
/*!
* @brief Do some actions when download message finished.
*
* @param[in] userName Account username string.
* @param[in] msgId Message ID.
* @param[in] success True if success.
* @param[in] errTxt Errot description.
*/
void downloadMessageFinished(const QString &userName, qint64 msgId,
bool success, const QString &errTxt);
/*!
* @brief Do some actions when download message list finished.
*
* @param[in] userName Account username string.
* @param[in] success True if success.
* @param[in] statusBarText Text for statusBar.
* @param[in] errTxt Errot description.
* @param[in] isMsgReceived True if message type is received.
*/
void downloadMessageListFinished(const QString &userName,
bool success, const QString &statusBarText, const QString &errTxt,
bool isMsgReceived);
private:
/*!
......@@ -219,7 +255,7 @@ private:
* @param[in] userName Account username string.
* @return True on success.
*/
bool syncSingleAccount(const QVariant &acntModelVariant,
void syncSingleAccount(const QVariant &acntModelVariant,
const QVariant &msgModelVariant, const QString &userName,
enum Messages::MessageType msgDirect);
......
/*
* 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 "src/worker/emitter.h"
MessageProcessingEmitter globMsgProcEmitter;
/*
* 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_EMITTER_H_
#define _MESSAGE_EMITTER_H_
#include <QObject>
/*!
* @brief Message processing status emitter.
*/
class MessageProcessingEmitter : public QObject {
Q_OBJECT
signals:
/*!
* @brief Do some actions when download message finished.
*
* @param[in] userName Account username string.
* @param[in] msgId Message ID.
* @param[in] success True if success.
* @param[in] errTxt Errot description.
*/
void downloadMessageFinishedSignal(const QString &userName, qint64 msgId,
bool success, const QString &errTxt);
/*!
* @brief Do some actions when download message list finished.
*
* @param[in] userName Account username string.
* @param[in] success True if success.
* @param[in] statusBarText Text for statusBar.
* @param[in] errTxt Errot description.
* @param[in] isMsgReceived True if message type is received.
*/
void downloadMessageListFinishedSignal(const QString &userName,
bool success, const QString &statusBarText, const QString &errTxt,
bool isMsgReceived);
};
/*!
* @brief This object is used to emit signals from message processing workers.
*/
extern MessageProcessingEmitter globMsgProcEmitter;
#endif /* _MESSAGE_EMITTER_H_ */
......@@ -24,6 +24,7 @@
#include "src/log/log.h"
#include "src/net/isds_const.h"
#include "src/net/xml_layer.h"
#include "src/worker/emitter.h"
#include "src/worker/pool.h" /* List with whole messages. */
#include "src/worker/task_download_message.h"
#include "src/sqlite/message_db_container.h"
......@@ -75,6 +76,10 @@ void TaskDownloadMessage::run(void)
/* ### Worker task end. ### */
emit globMsgProcEmitter.downloadMessageFinishedSignal(m_ctx.username,
m_msgId, TaskDownloadMessage::DL_SUCCESS == m_result,
m_ctx.last_isds_msg);
logDebugLv0NL("Download message task finished in thread '%p'",
(void *) QThread::currentThreadId());
}
......
......@@ -24,6 +24,7 @@
#include "src/log/log.h"
#include "src/net/isds_const.h"
#include "src/net/xml_layer.h"
#include "src/worker/emitter.h"
#include "src/worker/pool.h" /* List with whole messages. */
#include "src/worker/task_download_message.h"
#include "src/worker/task_download_message_list.h"
......@@ -87,6 +88,10 @@ void TaskDownloadMessageList::run(void)
/* ### Worker task end. ### */
emit globMsgProcEmitter.downloadMessageListFinishedSignal(m_ctx.username,
TaskDownloadMessageList::DL_SUCCESS == m_result, m_statusBarText,
m_ctx.last_isds_msg, m_msgDirect == Messages::TYPE_RECEIVED);
logDebugLv0NL("Download message list task finished in thread '%p'",
(void *) QThread::currentThreadId());
}
......
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