Commit 0f2aefb7 authored by Martin Straka's avatar Martin Straka

Show records management operations in the statusbar

parent d7d6af8b
......@@ -75,6 +75,15 @@ Rectangle {
progressBar.visible = busy
}
}
Connections {
target: recordsManagement
onStatusBarTextChanged: {
root.visible = true
statusBarText.text = txt
timer.running = !busy
progressBar.visible = busy
}
}
}
ProgressBar {
id: progressBar
......
......@@ -47,7 +47,7 @@ Item {
infoButton.text = (updateRmDataButton.visible) ? qsTr("Update service info") : qsTr("Get service info")
}
/* Enable data update and anothers labels if service name and token are filled */
/* Clear all data and info */
function clearAll() {
urlTextField.clear()
tokenTextField.clear()
......
......@@ -31,6 +31,7 @@
#include "src/models/accountmodel.h"
#include "src/records_management.h"
#include "src/settings.h"
#include "src/worker/emitter.h"
#include "src/worker/pool.h"
#include "src/worker/task_records_management_stored_messages.h"
......@@ -95,6 +96,10 @@ RecordsManagement::RecordsManagement(QObject *parent)
m_logoSvg()
{
globWorkPool.start();
connect(&globMsgProcEmitter,
SIGNAL(rmSyncFinishedSignal(QString, int, int)),
this, SLOT(rmSyncFinished(QString, int, int)));
}
RecordsManagement::~RecordsManagement(void)
......@@ -107,6 +112,10 @@ void RecordsManagement::callServiceInfo(const QString &urlStr,
const QString &tokenStr)
{
QByteArray response;
QString errTitle = tr("Communication error");
QString errDesctiption = tr("Received invalid response.");
emit statusBarTextChanged(tr("Get service info"), true, true);
m_rmc.setConnection(urlStr.trimmed(), tokenStr.trimmed());
......@@ -117,31 +126,32 @@ void RecordsManagement::callServiceInfo(const QString &urlStr,
ServiceInfoResp siRes(
ServiceInfoResp::fromJson(response, &ok));
if (!ok || !siRes.isValid()) {
QMessageBox::critical(Q_NULLPTR,
tr("Communication Error"),
tr("Received invalid response."));
return;
goto fail;
}
m_logoSvg = siRes.logoSvg();
loadRecordsManagementPixmap(m_logoSvg);
emit serviceInfo(siRes.name(), siRes.tokenName());
} else {
QMessageBox::critical(Q_NULLPTR,
tr("Communication Error"),
tr("Received empty response."));
return;
errDesctiption = tr("Received empty response.");
goto fail;
}
} else {
return;
}
emit statusBarTextChanged(tr("Done"), false, true);
return;
fail:
emit statusBarTextChanged(errTitle, false, true);
QMessageBox::critical(Q_NULLPTR, errTitle, errDesctiption);
}
void RecordsManagement::callUploadHierarchy(const QString &urlStr,
const QString &tokenStr)
{
QByteArray response;
QString errTitle = tr("Communication error");
QString errDesctiption = tr("Received invalid response.");
emit statusBarTextChanged(tr("Upload hierarchy"), true, true);
/* Clear model. */
m_uploadModel.setHierarchy(UploadHierarchyResp());
......@@ -155,55 +165,60 @@ void RecordsManagement::callUploadHierarchy(const QString &urlStr,
UploadHierarchyResp uhRes(
UploadHierarchyResp::fromJson(response, &ok));
if (!ok || !uhRes.isValid()) {
QMessageBox::critical(Q_NULLPTR,
tr("Communication Error"),
tr("Received invalid response."));
return;
goto fail;
}
m_uploadModel.setHierarchy(uhRes);
} else {
QMessageBox::critical(Q_NULLPTR, tr("Communication Error"),
tr("Received empty response."));
return;
errDesctiption = tr("Received empty response.");
goto fail;
}
} else {
return;
}
emit statusBarTextChanged(tr("Done"), false, true);
return;
fail:
emit statusBarTextChanged(errTitle, false, true);
QMessageBox::critical(Q_NULLPTR, errTitle, errDesctiption);
}
void RecordsManagement::getStoredMsgInfoFromRecordsManagement(
const QString &urlStr, const QString &tokenStr)
{
emit statusBarTextChanged(tr("Sync service"), true, true);
TaskRecordsManagementStoredMessages *task =
new (::std::nothrow) TaskRecordsManagementStoredMessages(
urlStr, tokenStr,
TaskRecordsManagementStoredMessages::RM_UPDATE_STORED,
Q_NULLPTR);
Q_NULLPTR, QString(), 0, 0);
if (Q_NULLPTR == task) {
qCritical("%s", "Cannot create stored_files update task.");
emit statusBarTextChanged(tr("Sync failed"), false, true);
return;
}
task->setAutoDelete(true);
/* Run in background. */
globWorkPool.assignHi(task);
int accTotal = AccountListModel::globAccounts.keys().count();
int accNumber = 0;
foreach (const QString &userName, AccountListModel::globAccounts.keys()) {
accNumber++;
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qWarning("%s", "Cannot open message database.");
return;
continue;
}
TaskRecordsManagementStoredMessages *task =
new (::std::nothrow) TaskRecordsManagementStoredMessages(
urlStr, tokenStr,
TaskRecordsManagementStoredMessages::RM_DOWNLOAD_ALL,
msgDb);
msgDb, userName, accNumber, accTotal);
if (Q_NULLPTR == task) {
qWarning("Cannot create stored_files task for '%s'.",
userName.toUtf8().constData());
......@@ -214,8 +229,6 @@ void RecordsManagement::getStoredMsgInfoFromRecordsManagement(
globWorkPool.assignHi(task);
}
/* TODO - update message model */
}
void RecordsManagement::loadStoredServiceInfo(void)
......@@ -253,9 +266,12 @@ bool RecordsManagement::uploadMessage(const QString &urlStr,
}
QByteArray response;
QString errTitle = tr("Communication error");
QString errDesctiption = tr("Received invalid response.");
m_rmc.setConnection(urlStr.trimmed(), tokenStr.trimmed());
emit statusBarTextChanged(tr("Upload message"), true, true);
m_rmc.setConnection(urlStr.trimmed(), tokenStr.trimmed());
if (m_rmc.communicate(RecordsManagementConnection::SRVC_UPLOAD_FILE,
ufReq.toJson(), response)) {
if (!response.isEmpty()) {
......@@ -263,22 +279,22 @@ bool RecordsManagement::uploadMessage(const QString &urlStr,
UploadFileResp ufRes(
UploadFileResp::fromJson(response, &ok));
if (!ok || !ufRes.isValid()) {
QMessageBox::critical(Q_NULLPTR,
tr("Communication Error"),
tr("Received invalid response."));
qWarning("Received invalid response '%s'.",
QString(response).toUtf8().constData());
return false;
goto fail;
}
emit statusBarTextChanged(tr("Done"), false, true);
return processUploadFileResponse(ufRes, dmId);
} else {
QMessageBox::critical(Q_NULLPTR, tr("Communication Error"),
tr("Received empty response."));
return false;
errDesctiption = tr("Received empty response.");
goto fail;
}
} else {
return false;
}
emit statusBarTextChanged(tr("Done"), false, true);
return false;
fail:
emit statusBarTextChanged(errTitle, false, true);
QMessageBox::critical(Q_NULLPTR, errTitle, errDesctiption);
return false;
}
bool RecordsManagement::updateServiceInfo(const QString &urlStr,
......@@ -308,6 +324,18 @@ bool RecordsManagement::updateServiceInfo(const QString &urlStr,
return true;
}
void RecordsManagement::rmSyncFinished(const QString &userName, int accNumber,
int accTotal)
{
if (accNumber < accTotal) {
emit statusBarTextChanged(
tr("Sync account '%1' (%2/%3)").arg(userName).arg(accNumber).arg(accTotal),
true, true);
} else {
emit statusBarTextChanged(tr("Sync done"), false, true);
}
}
void RecordsManagement::loadRecordsManagementPixmap(const QByteArray &logoSvg)
{
if (Q_NULLPTR == globRecordsManagementDbPtr) {
......
......@@ -120,6 +120,29 @@ signals:
*/
void serviceInfo(QString srName, QString srToken);
/*!
* @brief Set new statusbar text and active busy indicator to QML.
*
* @param[in] txt Text message for statusbar.
* @param[in] busy True means the statusbar busy indicator is
* active and shown, false = disabled and hidden.
* @param[in] isVisible True means the statusbar is visible,
* false = hidden.
*/
void statusBarTextChanged(QString txt, bool busy, bool isVisible);
private slots:
/*!
* @brief Do some actions when records management sync has been finished.
*
* @param[in] userName Account username (may be NULL).
* @param[in] accNumber Account number in process.
* @param[in] accTotal Overall number of account for sync.
*/
void rmSyncFinished(const QString &userName, int accNumber,
int accTotal);
private:
/*!
......
......@@ -104,6 +104,15 @@ signals:
const QString &transactId, const QString &dbIDRecipient,
const QString &dmRecipient, qint64 msgId, bool success,
const QString &errTxt);
/*!
* @brief Do some actions when records management sync has been finished.
*
* @param[in] userName Account username (may be NULL).
* @param[in] accNumber Account number in process.
* @param[in] accTotal Overall number of account for sync.
*/
void rmSyncFinishedSignal(QString userName, int accNumber, int accTotal);
};
/*!
......
......@@ -32,11 +32,13 @@
#include "src/datovka_shared/records_management/json/entry_error.h"
#include "src/datovka_shared/records_management/json/stored_files.h"
#include "src/log/log.h"
#include "src/worker/emitter.h"
#include "src/worker/task_records_management_stored_messages.h"
TaskRecordsManagementStoredMessages::TaskRecordsManagementStoredMessages(
const QString &urlStr, const QString &tokenStr, enum Operation operation,
MessageDb *msgDb, const QList<qint64> &exludedDmIds)
MessageDb *msgDb, const QString &userName, int accNumber, int accTotal,
const QList<qint64> &exludedDmIds)
: m_result(DS_DSM_ERR),
m_id(QString::number(QDateTime::currentMSecsSinceEpoch()) +
QStringLiteral(":") + QString::number((quint64)this)),
......@@ -44,6 +46,9 @@ TaskRecordsManagementStoredMessages::TaskRecordsManagementStoredMessages(
m_token(tokenStr),
m_operation(operation),
m_msgDb(msgDb),
m_userName(userName),
m_accNumber(accNumber),
m_accTotal(accTotal),
m_exludedDmIds(exludedDmIds)
{
Q_ASSERT(!m_url.isEmpty() && !m_token.isEmpty());
......@@ -71,6 +76,9 @@ void TaskRecordsManagementStoredMessages::run(void)
m_result = downloadStoredMessages(m_url, m_token, m_operation, m_msgDb,
m_exludedDmIds);
emit globMsgProcEmitter.rmSyncFinishedSignal(m_userName, m_accNumber,
m_accTotal);
/* ### Worker task end. ### */
logDebugLv0NL("Download stored messages from records management service task '%s' finished in thread '%p'.",
......
......@@ -59,11 +59,15 @@ public:
* @param[in] tokenStr Records management access token.
* @param[in] operation Actual action to be performed.
* @param[in] msgDb Database set to be used to obtain message identifiers.
* @param[in] userName Account username.
* @param[in] accNumber Account number in process.
* @param[in] accTotal Overall number of account for sync.
* @patam[in] exludedDmIds Message identifiers that should not be queried.
*/
explicit TaskRecordsManagementStoredMessages(
const QString &urlStr, const QString &tokenStr,
enum Operation operation, MessageDb *msgDb,
const QString &userName, int accNumber, int accTotal,
const QList<qint64> &exludedDmIds = QList<qint64>());
/*!
......@@ -99,13 +103,14 @@ private:
MessageDb *msgDb, const QList<qint64> &exludedDmIds);
const QString m_id; /*!< Task identifier. */
const QString m_url; /*!< String containing records management URL. */
const QString m_token; /*!< Records management access token. */
const enum Operation m_operation; /*!< Operation to be performed. */
MessageDb *m_msgDb; /*!< Pointer to database container. */
const QString m_userName; /*!< Account username. */
int m_accNumber; /*!< Account number in process. */
int m_accTotal; /*!< Overall number of account for sync. */
const QList<qint64> m_exludedDmIds; /*!<
* List of messages that should
* not be queried.
......
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