Commit b7eb1da6 authored by Martin Straka's avatar Martin Straka

Download account info tasks is asynchronous

parent 187bf93e
...@@ -67,7 +67,6 @@ Component { ...@@ -67,7 +67,6 @@ Component {
anchors.fill: parent anchors.fill: parent
onClicked: { onClicked: {
isds.getAccountInfo(userName, false) isds.getAccountInfo(userName, false)
accounts.fillAccountInfo(userName)
} }
} }
} }
...@@ -109,5 +108,11 @@ Component { ...@@ -109,5 +108,11 @@ Component {
anchors.centerIn: parent anchors.centerIn: parent
text: qsTr("Account info has not been downloaded yet.") text: qsTr("Account info has not been downloaded yet.")
} // Text } // Text
Connections {
target: isds
onDownloadAccountInfoFinishedSig: {
accounts.fillAccountInfo(userName)
}
}
} }
} }
...@@ -78,16 +78,7 @@ Item { ...@@ -78,16 +78,7 @@ Item {
passwordTextField.text.toString(), passwordTextField.text.toString(),
testAccount.checked, rememberPassword.checked, testAccount.checked, rememberPassword.checked,
useLS.checked, certPathLabelId.text.toString())) { useLS.checked, certPathLabelId.text.toString())) {
if (isds.getAccountInfo(userNameTextField.text.toString(), true)) { 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)
}
}
} }
} else { } else {
if (accounts.updateAccount(accountModel, sLoginMethod, if (accounts.updateAccount(accountModel, sLoginMethod,
...@@ -102,6 +93,19 @@ Item { ...@@ -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 } // PageHeader
......
...@@ -51,6 +51,16 @@ IsdsWrapper::IsdsWrapper(QObject *parent) ...@@ -51,6 +51,16 @@ IsdsWrapper::IsdsWrapper(QObject *parent)
m_workPool.start(); m_workPool.start();
/* Worker-related processing signals. */ /* 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, connect(&globMsgProcEmitter,
SIGNAL(downloadMessageFinishedSignal(QString, qint64, bool, QString)), SIGNAL(downloadMessageFinishedSignal(QString, qint64, bool, QString)),
this, this,
...@@ -60,11 +70,6 @@ IsdsWrapper::IsdsWrapper(QObject *parent) ...@@ -60,11 +70,6 @@ IsdsWrapper::IsdsWrapper(QObject *parent)
SIGNAL(downloadMessageListFinishedSignal(QString, bool, QString, QString, bool)), SIGNAL(downloadMessageListFinishedSignal(QString, bool, QString, QString, bool)),
this, this,
SLOT(downloadMessageListFinished(QString, bool, QString, QString, bool))); 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) IsdsWrapper::~IsdsWrapper(void)
...@@ -149,33 +154,15 @@ void IsdsWrapper::syncSingleAccount(const QVariant &acntModelVariant, ...@@ -149,33 +154,15 @@ void IsdsWrapper::syncSingleAccount(const QVariant &acntModelVariant,
m_workPool.assignHi(task); m_workPool.assignHi(task);
} }
void IsdsWrapper::downloadMessageListFinished(const QString &userName, void IsdsWrapper::getAccountInfo(const QString &userName, bool isFirstLogin)
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)
{ {
qDebug("%s()", __func__); qDebug("%s()", __func__);
bool success = true;
QString errTxt = tr("Wrong username"); QString errTxt = tr("Wrong username");
if (userName.isEmpty()) { if (userName.isEmpty()) {
Dialogues::errorMessage(Dialogues::CRITICAL, Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Error"), errTxt, tr("Internal error")); tr("Error"), errTxt, tr("Internal error"));
return false; return;
} }
if (!isLoggedToIsds(userName, errTxt)) { if (!isLoggedToIsds(userName, errTxt)) {
...@@ -189,10 +176,11 @@ bool IsdsWrapper::getAccountInfo(const QString &userName, bool isFirstLogin) ...@@ -189,10 +176,11 @@ bool IsdsWrapper::getAccountInfo(const QString &userName, bool isFirstLogin)
tr("ISDS returns:") + " " + errTxt + "\n\n" + tr("ISDS returns:") + " " + errTxt + "\n\n" +
tr("Check your login data and try again.")); tr("Check your login data and try again."));
} }
emit downloadAccountInfoFinishedSig(userName, false);
} else { } else {
showLoginProblemDialog(userName, errTxt); showLoginProblemDialog(userName, errTxt);
} }
return false; return;
} }
emit statusBarTextChanged(tr("Getting account info %1"). emit statusBarTextChanged(tr("Getting account info %1").
...@@ -201,24 +189,8 @@ bool IsdsWrapper::getAccountInfo(const QString &userName, bool isFirstLogin) ...@@ -201,24 +189,8 @@ bool IsdsWrapper::getAccountInfo(const QString &userName, bool isFirstLogin)
TaskDownloadAccountInfo *task; TaskDownloadAccountInfo *task;
task = new (std::nothrow) TaskDownloadAccountInfo( task = new (std::nothrow) TaskDownloadAccountInfo(
m_isdsSession.isdsCtxMap[userName], &m_netLayer, &m_dbWrapper); m_isdsSession.isdsCtxMap[userName], &m_netLayer, &m_dbWrapper);
task->setAutoDelete(false); task->setAutoDelete(true);
m_workPool.runSingle(task); m_workPool.assignHi(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;
} }
void IsdsWrapper::downloadMessage(const QVariant &msgModelVariant, void IsdsWrapper::downloadMessage(const QVariant &msgModelVariant,
...@@ -274,19 +246,6 @@ void IsdsWrapper::getDeliveryInfo(const QString &userName, qint64 msgId) ...@@ -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, bool IsdsWrapper::changePassword(const QString &userName,
const QString &accountName) const QString &accountName)
{ {
...@@ -483,6 +442,67 @@ void IsdsWrapper::closeAllOtpConnections(void) ...@@ -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) void IsdsWrapper::removeIsdsCtx(const QString &userName)
{ {
m_isdsSession.removeIsdsCtx(userName); m_isdsSession.removeIsdsCtx(userName);
...@@ -517,23 +537,6 @@ void IsdsWrapper::downloadMessage(MessageListModel *messageModel, ...@@ -517,23 +537,6 @@ void IsdsWrapper::downloadMessage(MessageListModel *messageModel,
m_workPool.assignLo(task); 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, void IsdsWrapper::showLoginProblemDialog(const QString &userName,
const QString &errTxt) const QString &errTxt)
{ {
......
...@@ -98,10 +98,9 @@ public: ...@@ -98,10 +98,9 @@ public:
* @param[in] userName Account username string. * @param[in] userName Account username string.
* @param[in] isFirstLogin Set on True if it is first login * @param[in] isFirstLogin Set on True if it is first login
* into databox (when add account to Datovka). * into databox (when add account to Datovka).
* @return True on success.
*/ */
Q_INVOKABLE Q_INVOKABLE
bool getAccountInfo(const QString &userName, bool isFirstLogin); void getAccountInfo(const QString &userName, bool isFirstLogin);
/*! /*!
* @brief Downloads complete message. * @brief Downloads complete message.
...@@ -205,14 +204,36 @@ signals: ...@@ -205,14 +204,36 @@ signals:
*/ */
void downloadMessageListFinishedSig(bool isMsgReceived); 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: public slots:
/*! /*!
* @brief Removed ISDS context of account. Run this slot * @brief Do some actions when download account info finished.
* when account is deleted or its setting was updated.
* *
* @param[in] userName Account username string. * @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. * @brief Do some actions when download message finished.
...@@ -239,15 +260,12 @@ public slots: ...@@ -239,15 +260,12 @@ public slots:
bool isMsgReceived); 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] 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, void removeIsdsCtx(const QString &userName);
qint64 msgId, bool success, const QString &errTxt);
private: private:
......
...@@ -34,6 +34,27 @@ class MessageProcessingEmitter : public QObject { ...@@ -34,6 +34,27 @@ class MessageProcessingEmitter : public QObject {
signals: 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. * @brief Do some actions when download message finished.
* *
...@@ -57,17 +78,6 @@ signals: ...@@ -57,17 +78,6 @@ signals:
void downloadMessageListFinishedSignal(const QString &userName, void downloadMessageListFinishedSignal(const QString &userName,
bool success, const QString &statusBarText, const QString &errTxt, bool success, const QString &statusBarText, const QString &errTxt,
bool isMsgReceived); 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 @@ ...@@ -24,6 +24,7 @@
#include "src/log/log.h" #include "src/log/log.h"
#include "src/net/isds_const.h" #include "src/net/isds_const.h"
#include "src/net/xml_layer.h" #include "src/net/xml_layer.h"
#include "src/worker/emitter.h"
#include "src/worker/pool.h" /* List with whole messages. */ #include "src/worker/pool.h" /* List with whole messages. */
#include "src/worker/task_download_account_info.h" #include "src/worker/task_download_account_info.h"
...@@ -62,6 +63,9 @@ void TaskDownloadAccountInfo::run(void) ...@@ -62,6 +63,9 @@ void TaskDownloadAccountInfo::run(void)
/* ### Worker task end. ### */ /* ### 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'", logDebugLv0NL("Download account info task finished in thread '%p'",
(void *) QThread::currentThreadId()); (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