Commit 6c3e7848 authored by Karel Slaný's avatar Karel Slaný
Browse files

Merge branch 'async-tasks' into 'develop'

Some message tasks are asynchronous

See merge request !62
parents 331df0c7 b7eb1da6
......@@ -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 \
......
......@@ -67,7 +67,6 @@ Component {
anchors.fill: parent
onClicked: {
isds.getAccountInfo(userName, false)
accounts.fillAccountInfo(userName)
}
}
}
......@@ -109,5 +108,11 @@ Component {
anchors.centerIn: parent
text: qsTr("Account info has not been downloaded yet.")
} // Text
Connections {
target: isds
onDownloadAccountInfoFinishedSig: {
accounts.fillAccountInfo(userName)
}
}
}
}
......@@ -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)
}
}
}
}
}
......@@ -78,16 +78,7 @@ Item {
passwordTextField.text.toString(),
testAccount.checked, rememberPassword.checked,
useLS.checked, certPathLabelId.text.toString())) {
if (isds.getAccountInfo(userNameTextField.text.toString(), true)) {
settings.saveAllSettings(accountModel)
pageView.pop(StackView.Immediate)
} else {
if (accounts.removeAccount(accountModel,
userNameTextField.text.toString(),
false)) {
settings.saveAllSettings(accountModel)
}
}
isds.getAccountInfo(userNameTextField.text.toString(), true)
}
} else {
if (accounts.updateAccount(accountModel, sLoginMethod,
......@@ -102,6 +93,19 @@ Item {
}
}
}
Connections {
target: isds
onDownloadAccountInfoFinishedSig: {
if (isLogged) {
settings.saveAllSettings(accountModel)
pageView.pop(StackView.Immediate)
} else {
if (accounts.removeAccount(accountModel, userName, false)) {
settings.saveAllSettings(accountModel)
}
}
}
}
}
}
} // PageHeader
......
......@@ -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,27 @@ IsdsWrapper::IsdsWrapper(QObject *parent)
*/
{
m_workPool.start();
/* Worker-related processing signals. */
connect(&globMsgProcEmitter,
SIGNAL(downloadAccountInfoFinishedSignal(QString, bool, QString)),
this,
SLOT(downloadAccountInfoFinished(QString, bool, QString)));
connect(&globMsgProcEmitter,
SIGNAL(downloadDeliveryInfoFinishedSignal(QString, qint64, bool, QString)),
this,
SLOT(downloadDeliveryInfoFinished(QString, qint64, bool, QString)));
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 +78,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 +120,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,36 +150,19 @@ 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;
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);
} else {
emit statusBarTextChanged(statusBarText, false, true);
}
return success;
task->setAutoDelete(true);
m_workPool.assignHi(task);
}
bool IsdsWrapper::getAccountInfo(const QString &userName, bool isFirstLogin)
void IsdsWrapper::getAccountInfo(const QString &userName, bool isFirstLogin)
{
qDebug("%s()", __func__);
bool success = true;
QString errTxt = tr("Wrong username");
if (userName.isEmpty()) {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Error"), errTxt, tr("Internal error"));
return false;
return;
}
if (!isLoggedToIsds(userName, errTxt)) {
......@@ -182,10 +176,11 @@ bool IsdsWrapper::getAccountInfo(const QString &userName, bool isFirstLogin)
tr("ISDS returns:") + " " + errTxt + "\n\n" +
tr("Check your login data and try again."));
}
emit downloadAccountInfoFinishedSig(userName, false);
} else {
showLoginProblemDialog(userName, errTxt);
}
return false;
return;
}
emit statusBarTextChanged(tr("Getting account info %1").
......@@ -194,24 +189,8 @@ bool IsdsWrapper::getAccountInfo(const QString &userName, bool isFirstLogin)
TaskDownloadAccountInfo *task;
task = new (std::nothrow) TaskDownloadAccountInfo(
m_isdsSession.isdsCtxMap[userName], &m_netLayer, &m_dbWrapper);
task->setAutoDelete(false);
m_workPool.runSingle(task);
success = TaskDownloadAccountInfo::DL_SUCCESS == task->m_result;
delete task;
if (!success) {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Account info: %1").arg(userName),
tr("Failed to get account info for username %1.").arg(userName),
m_isdsSession.isdsCtxMap[userName].last_isds_msg);
} else {
emit statusBarTextChanged(
m_isdsSession.isdsCtxMap[userName].last_isds_msg,
false, true);
}
return true;
task->setAutoDelete(true);
m_workPool.assignHi(task);
}
void IsdsWrapper::downloadMessage(const QVariant &msgModelVariant,
......@@ -249,8 +228,8 @@ void IsdsWrapper::getDeliveryInfo(const QString &userName, qint64 msgId)
TaskDownloadDeliveryInfo *task;
task = new (std::nothrow) TaskDownloadDeliveryInfo(
m_isdsSession.isdsCtxMap[userName], &m_netLayer, &m_dbWrapper, msgId);
task->setAutoDelete(false);
m_workPool.runSingle(task);
task->setAutoDelete(true);
m_workPool.assignHi(task);
bool success = TaskDownloadDeliveryInfo::DL_SUCCESS == task->m_result;
delete task;
......@@ -463,6 +442,67 @@ void IsdsWrapper::closeAllOtpConnections(void)
}
}
void IsdsWrapper::downloadAccountInfoFinished(const QString &userName,
bool success, const QString &errTxt)
{
emit downloadAccountInfoFinishedSig(userName, true);
if (!success) {
Dialogues::errorMessage(Dialogues::WARNING,
tr("Account info: %1").arg(userName),
tr("Failed to get account info for username %1.").arg(userName),
errTxt);
} else {
emit statusBarTextChanged(errTxt, false, true);
}
}
void IsdsWrapper::downloadDeliveryInfoFinished(const QString &userName,
qint64 msgId, bool success, const QString &errTxt)
{
if (!success) {
Dialogues::errorMessage(Dialogues::WARNING,
tr("Delivery info: %1").arg(userName),
tr("Failed to download delivery info for message %1.").arg(msgId),
errTxt);
} else {
emit statusBarTextChanged(errTxt, false, true);
}
}
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),
errTxt);
return;
} else {
emit statusBarTextChanged(tr("Message %1 has been downloaded").arg(msgId),
false, true);
}
}
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: messages").arg(userName),
tr("Failed to download list of messages for user name '%1'.").arg(userName),
errTxt);
} else {
emit statusBarTextChanged(statusBarText, false, true);
}
}
void IsdsWrapper::removeIsdsCtx(const QString &userName)
{
m_isdsSession.removeIsdsCtx(userName);
......@@ -493,22 +533,8 @@ 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);
bool success = TaskDownloadMessage::DL_SUCCESS == task->m_result;
delete task;
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);
return;
} else {
emit statusBarTextChanged(tr("Message %1 has been downloaded").arg(msgId),
false, true);
}
task->setAutoDelete(true);
m_workPool.assignLo(task);
}
void IsdsWrapper::showLoginProblemDialog(const QString &userName,
......
......@@ -51,11 +51,9 @@ public:
*
* @param[in,out] acntModelVariant QVariant holding account model
* to be altered.
* @return True if at least one account has been successfully
* synchronised.
*/
Q_INVOKABLE
bool syncAllAccounts(const QVariant &acntModelVariant);
void syncAllAccounts(const QVariant &acntModelVariant);
/*!
* @brief Download message list of one account.
......@@ -63,10 +61,9 @@ public:
* @param[in,out] acntModelVariant QVariant holding account model
* to be altered.
* @param[in] userName Account username string.
* @return True on success.
*/
Q_INVOKABLE
bool syncOneAccount(const QVariant &acntModelVariant,
void syncOneAccount(const QVariant &acntModelVariant,
const QString &userName);
/*!
......@@ -77,10 +74,9 @@ public:
* @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 QVariant &acntModelVariant,
void syncSingleAccountReceived(const QVariant &acntModelVariant,
const QVariant &msgModelVariant, const QString &userName);
/*!
......@@ -91,10 +87,9 @@ public:
* @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 QVariant &acntModelVariant,
void syncSingleAccountSent(const QVariant &acntModelVariant,
const QVariant &msgModelVariant, const QString &userName);
/*!
......@@ -103,10 +98,9 @@ public:
* @param[in] userName Account username string.
* @param[in] isFirstLogin Set on True if it is first login
* into databox (when add account to Datovka).
* @return True on success.
*/
Q_INVOKABLE
bool getAccountInfo(const QString &userName, bool isFirstLogin);
void getAccountInfo(const QString &userName, bool isFirstLogin);
/*!
* @brief Downloads complete message.
......@@ -198,7 +192,73 @@ 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);
/*!
* @brief Update account info model in QML.
*
* @param[in] userName Account user name string.
* @param[in] isLogged True if a new account was login to DS.
*/
void downloadAccountInfoFinishedSig(QString userName, bool isLogged);
public slots:
/*!
* @brief Do some actions when download account info finished.
*
* @param[in] userName Account username string.
* @param[in] success True if success.
* @param[in] errTxt Errot description.
*/
void downloadAccountInfoFinished(const QString &userName,
bool success, const QString &errTxt);
/*!
* @brief Do some actions when download delivery info finished.
*
* @param[in] userName Account username string.
* @param[in] msgId Message ID.
* @param[in] success True if success.
* @param[in] errTxt Errot description.
*/
void downloadDeliveryInfoFinished(const QString &userName,
qint64 msgId, bool success, const QString &errTxt);
/*!
* @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);
/*!
* @brief Removed ISDS context of account. Run this slot
* when account is deleted or its setting was updated.
......@@ -217,9 +277,8 @@ private:
* @param[in,out] msgModelVariant QVariant holding message model
* to be altered.
* @param[in] userName Account username string.
* @return True on success.
*/