Commit b7eb1da6 authored by Martin Straka's avatar Martin Straka

Download account info tasks is asynchronous

parent 187bf93e
......@@ -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)
}
}
}
}
......@@ -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
......
......@@ -51,6 +51,16 @@ 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,
......@@ -60,11 +70,6 @@ IsdsWrapper::IsdsWrapper(QObject *parent)
SIGNAL(downloadMessageListFinishedSignal(QString, bool, QString, QString, bool)),
this,
SLOT(downloadMessageListFinished(QString, bool, QString, QString, bool)));
connect(&globMsgProcEmitter,
SIGNAL(downloadDeliveryInfoFinishedSignal(QString, qint64, bool, QString)),
this,
SLOT(downloadDeliveryInfoFinished(QString, qint64, bool, QString)));
}
IsdsWrapper::~IsdsWrapper(void)
......@@ -149,33 +154,15 @@ void IsdsWrapper::syncSingleAccount(const QVariant &acntModelVariant,
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: messages").arg(userName),
tr("Failed to download list of messages for user name '%1'.").arg(userName),
errTxt);
} else {
emit statusBarTextChanged(statusBarText, false, true);
}
}
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)) {
......@@ -189,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").
......@@ -201,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,
......@@ -274,19 +246,6 @@ void IsdsWrapper::getDeliveryInfo(const QString &userName, qint64 msgId)
}
}
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);
}
}
bool IsdsWrapper::changePassword(const QString &userName,
const QString &accountName)
{
......@@ -483,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);
......@@ -517,23 +537,6 @@ void IsdsWrapper::downloadMessage(MessageListModel *messageModel,
m_workPool.assignLo(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),
errTxt);
return;
} else {
emit statusBarTextChanged(tr("Message %1 has been downloaded").arg(msgId),
false, true);
}
}
void IsdsWrapper::showLoginProblemDialog(const QString &userName,
const QString &errTxt)
{
......
......@@ -98,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.
......@@ -205,14 +204,36 @@ signals:
*/
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 Removed ISDS context of account. Run this slot
* when account is deleted or its setting was updated.
* @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 removeIsdsCtx(const QString &userName);
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.
......@@ -239,15 +260,12 @@ public slots:
bool isMsgReceived);
/*!
* @brief Do some actions when download delivery info finished.
* @brief Removed ISDS context of account. Run this slot
* when account is deleted or its setting was updated.
*
* @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);
void removeIsdsCtx(const QString &userName);
private:
......
......@@ -34,6 +34,27 @@ class MessageProcessingEmitter : public QObject {
signals:
/*!
* @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 downloadAccountInfoFinishedSignal(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 downloadDeliveryInfoFinishedSignal(const QString &userName,
qint64 msgId, bool success, const QString &errTxt);
/*!
* @brief Do some actions when download message finished.
*
......@@ -57,17 +78,6 @@ signals:
void downloadMessageListFinishedSignal(const QString &userName,
bool success, const QString &statusBarText, const QString &errTxt,
bool isMsgReceived);
/*!
* @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 downloadDeliveryInfoFinishedSignal(const QString &userName,
qint64 msgId, bool success, const QString &errTxt);
};
/*!
......
......@@ -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_account_info.h"
......@@ -62,6 +63,9 @@ void TaskDownloadAccountInfo::run(void)
/* ### Worker task end. ### */
emit globMsgProcEmitter.downloadAccountInfoFinishedSignal(m_ctx.username,
TaskDownloadAccountInfo::DL_SUCCESS == m_result, m_ctx.last_isds_msg);
logDebugLv0NL("Download account info 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