Commit 47836391 authored by Martin Straka's avatar Martin Straka

Added support for zfo import to isds wrapper.

parent 30e58de2
......@@ -27,6 +27,7 @@
#include "src/auxiliaries/attachment_helper.h"
#include "src/datovka_shared/utility/strings.h"
#include "src/dialogues/dialogues.h"
#include "src/io/filesystem.h"
#include "src/models/accountmodel.h"
#include "src/models/databoxmodel.h"
#include "src/models/messagemodel.h"
......@@ -44,6 +45,7 @@
#include "src/worker/task_download_message_list.h"
#include "src/worker/task_find_databox.h"
#include "src/worker/task_find_databox_fulltext.h"
#include "src/worker/task_import_zfo.h"
#include "src/worker/task_keep_alive.h"
#include "src/worker/task_send_sms.h"
......@@ -81,6 +83,9 @@ IsdsWrapper::IsdsWrapper(QObject *parent)
this,
SLOT(downloadMessageListFinished(QString, bool, QString, QString, bool)));
connect(&globMsgProcEmitter, SIGNAL(importZFOFinishedSignal(int, int, QString)),
this, SLOT(importZFOFinished(int, int, QString)));
connect(&globMsgProcEmitter,
SIGNAL(sendMessageFinishedSignal(QString, QString, QString, QString, qint64, bool, QString)),
this,
......@@ -93,6 +98,69 @@ IsdsWrapper::~IsdsWrapper(void)
m_workPool.stop();
}
QString IsdsWrapper::importZfoMessages(const QString &userName,
const QStringList &fileList, bool authenticate)
{
qDebug("%s()", __func__);
if (fileList.isEmpty()) {
return tr("No zfo files or selected folder.");
}
/* Get user names of all accounts if an user name is not specified */
QStringList userNameList;
if (userName.isEmpty()) {
userNameList = AccountListModel::globAccounts.keys();
} else {
userNameList.append(userName);
}
if (userNameList.isEmpty()) {
return tr("No account for zfo import.");
}
/* User must be logged to isds if messages must be verified */
if (authenticate) {
foreach (const QString &userName, userNameList) {
if (!isLoggedToIsds(userName)) {
continue;
}
}
}
/* Test, if folder or file(s) was selected */
QStringList filePathList = fileList;
if (1 == fileList.count()) {
if (!QFileInfo(fileList.at(0)).isFile()) {
filePathList = getZfoFilesFromDir(fileList.at(0), true);
if (filePathList.isEmpty()) {
return tr("No zfo files in the selected directory.");
}
}
}
int zfoTotal = filePathList.count();
int zfoNumber = 0;
if (zfoTotal < 1) {
return tr("No zfo file for import.");
}
emit statusBarTextChanged(tr("ZFO import"), true, true);
foreach (const QString &file, filePathList) {
zfoNumber++;
TaskImportZfo *task;
task = new (std::nothrow) TaskImportZfo(&m_isdsSession,
&m_netLayer, &m_dbWrapper, userNameList, file,
authenticate, zfoNumber, zfoTotal);
task->setAutoDelete(true);
m_workPool.assignLo(task);
}
return tr("ZFO import is running... Wait until import will finished!");
}
bool IsdsWrapper::changePassword(const QString &userName, const QString &oldPwd,
const QString &newPwd, const QString &otpCode)
{
......@@ -798,6 +866,21 @@ void IsdsWrapper::downloadMessageListFinished(const QString &userName,
}
}
void IsdsWrapper::importZFOFinished(int zfoNumber, int zfoTotal,
QString infoText)
{
if (zfoNumber < zfoTotal) {
emit zfoImportProgressSig(QString::number(zfoNumber) + ". " + infoText);
emit statusBarTextChanged(
tr("ZFO import: %1/%2").arg(zfoNumber).arg(zfoTotal), true,
true);
} else {
emit zfoImportProgressSig(QString::number(zfoNumber) + ". " + infoText);
emit zfoImportFinishedSig(tr("ZFO import has been finished with the result:"));
emit statusBarTextChanged(tr("ZFO import: done"), false, true);
}
}
void IsdsWrapper::sendMessageFinished(const QString &userName,
const QString &transactId, const QString &dbIDRecipient,
const QString &dmRecipient, qint64 msgId, bool success,
......
......@@ -54,6 +54,18 @@ public:
*/
~IsdsWrapper(void);
/*!
* @brief Import ZFO files to local database.
*
* @param[in] userName Account username string (may be NULL).
* @param[in] fileList File list or dir path.
* @param[in] authenticate True if message must be authenticate in ISDS.
* @return info/error text.
*/
Q_INVOKABLE
QString importZfoMessages(const QString &userName,
const QStringList &fileList, bool authenticate);
/*!
* @brief Change ISDS login password.
*
......@@ -415,6 +427,20 @@ signals:
*/
void unsuccessedLoginToIsdsSig(QString userName);
/*!
* @brief Send info to QML that ZFO import has been finished.
*
* @param[in] txt Result text.
*/
void zfoImportFinishedSig(QString txt);
/*!
* @brief Send info to QML that one ZFO file has been imported.
*
* @param[in] txt Result text.
*/
void zfoImportProgressSig(QString txt);
public slots:
/*!
......@@ -462,6 +488,16 @@ public slots:
bool success, const QString &statusBarText, const QString &errTxt,
bool isMsgReceived);
/*!
* @brief Do some actions when import of one ZFO has been finished.
*
* @param[in] zfoNumber ZFO number in import process.
* @param[in] zfoTotal Overall number of ZFO for import.
* @param[in] infoText Import result description (may be NULL).
*/
void importZFOFinished(int zfoNumber, int zfoTotal,
QString infoText);
/*!
* @brief Do post actions when send message finished.
*
......
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