Commit 355eb473 authored by Martin Straka's avatar Martin Straka
Browse files

Use standalone asynchronous task for recipient adding.

parent 94c7f4e1
......@@ -217,6 +217,7 @@ SOURCES += \
src/sqlite/message_db_tables.cpp \
src/sqlite/zfo_db.cpp \
src/sqlite/zfo_db_tables.cpp \
src/worker/task_add_recipient.cpp \
src/worker/task_change_password.cpp \
src/worker/task_credit_info.cpp \
src/worker/task_download_account_info.cpp \
......@@ -386,6 +387,7 @@ HEADERS += \
src/sqlite/zfo_db_tables.h \
src/worker/emitter.h \
src/worker/task.h \
src/worker/task_add_recipient.h \
src/worker/task_change_password.h \
src/worker/task_credit_info.h \
src/worker/task_download_account_info.h \
......
......@@ -118,12 +118,10 @@ Item {
canDeselectBoxes: recipBoxModel != null
localContactFormat: true
onBoxSelect: {
var boxEntry = foundBoxModel.entry(boxId)
if (recipBoxModel != null) {
var boxEntry = foundBoxModel.entry(boxId)
foundBoxModel.selectEntry(boxEntry.dbID, true)
if (!isds.addRecipient(acntId, boxEntry.dbID, boxEntry.dbName, boxEntry.dbAddress, false, recipBoxModel)) {
foundBoxModel.selectEntry(boxEntry.dbID, false)
}
isds.addRecipient(acntId, boxEntry.dbID, boxEntry.dbName, boxEntry.dbAddress, false, recipBoxModel)
}
}
onBoxDeselect: {
......
......@@ -277,12 +277,10 @@ Item {
canSelectBoxes: recipBoxModel != null
canDeselectBoxes: recipBoxModel != null
onBoxSelect: {
var boxEntry = foundBoxModel.entry(boxId)
if (recipBoxModel != null) {
var boxEntry = foundBoxModel.entry(boxId)
foundBoxModel.selectEntry(boxEntry.dbID, true)
if (!isds.addRecipient(acntId, boxEntry.dbID, boxEntry.dbName, boxEntry.dbAddress, false, recipBoxModel)) {
foundBoxModel.selectEntry(boxEntry.dbID, false)
}
isds.addRecipient(acntId, boxEntry.dbID, boxEntry.dbName, boxEntry.dbAddress, false, recipBoxModel)
}
}
onBoxDeselect: {
......
......@@ -40,6 +40,7 @@
#include "src/settings/prefs_specific.h"
#include "src/setwrapper.h"
#include "src/sqlite/zfo_db.h"
#include "src/worker/task_add_recipient.h"
#include "src/worker/task_change_password.h"
#include "src/worker/task_credit_info.h"
#include "src/worker/task_download_account_info.h"
......@@ -61,6 +62,26 @@
# define macroStdMove(x) (x)
#endif /* Q_COMPILER_RVALUE_REFS */
void Isds::Tasks::addRecipient(const AcntId &acntId, const QString &dbID,
bool senderOvm, const QString &dbName, const QString &dbAddress,
bool canUseInitReply, const QList<Isds::PDZInfoRec> &pdzInfos)
{
debugFuncCall();
if (Q_UNLIKELY((GlobInstcs::workPoolPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return;
}
TaskAddRecipient *task = new (::std::nothrow) TaskAddRecipient(
acntId, dbID, senderOvm, dbName, dbAddress, canUseInitReply,
pdzInfos);
if (task != Q_NULLPTR) {
task->setAutoDelete(true);
GlobInstcs::workPoolPtr->assignHi(task);
}
}
bool Isds::Tasks::changePassword(const AcntId &acntId, const QString &oldPwd,
const QString &newPwd, const QString &otpCode)
{
......
......@@ -30,6 +30,7 @@
class AccountListModel; /* Forward declaration. */
class AcntId; /* Forward declaration. */
class DataboxListModel; /* Forward declaration. */
class FileListModel; /* Forward declaration. */
namespace Isds {
......@@ -38,6 +39,25 @@ namespace Isds {
Q_DECLARE_TR_FUNCTIONS(Tasks)
public:
/*!
* @brief Add recipient and set pdz payment methods.
*
* @param[in] acntId Account identifier.
* @param[in] dbID Recipient data box id.
* @param[in] senderOvm True if sender is OVM.
* @param[in] dbName Recipient data box name.
* @param[in] dbAddress Recipient data box address.
* @param[in] canUseInitReply True if can use reply
* on initiatory message.
* @param[in] pdzInfos List of pdz info.
*/
static
void addRecipient(const AcntId &acntId,
const QString &dbID, bool senderOvm, const QString &dbName,
const QString &dbAddress, bool canUseInitReply,
const QList<Isds::PDZInfoRec> &pdzInfos);
/*!
* @brief Change ISDS login password.
*
......
......@@ -40,6 +40,7 @@
#include "src/qml_identifiers/qml_account_id.h"
#include "src/settings/accounts.h"
#include "src/worker/emitter.h"
#include "src/worker/task_add_recipient.h"
#include "src/wrap_accounts.h"
IsdsWrapper::IsdsWrapper(QObject *parent)
......@@ -47,9 +48,8 @@ IsdsWrapper::IsdsWrapper(QObject *parent)
m_mepRunning(false),
m_transactIds(),
m_pdzInfos(),
m_dmType(Isds::Type::MT_UNKNOWN),
m_pdzCredit(),
m_dmSenderRefNumber()
m_databoxModel()
{
if (GlobInstcs::msgProcEmitterPtr == Q_NULLPTR) {
logErrorNL("%s", "Cannot connect to status message emitter.");
......@@ -57,6 +57,7 @@ IsdsWrapper::IsdsWrapper(QObject *parent)
}
qRegisterMetaType<QList<Isds::PDZInfoRec>>("QList<Isds::PDZInfoRec");
qRegisterMetaType<DataboxModelEntry>("DataboxModelEntry");
/* Worker-related processing signals. */
connect(GlobInstcs::msgProcEmitterPtr,
......@@ -99,6 +100,10 @@ IsdsWrapper::IsdsWrapper(QObject *parent)
this,
SLOT(pdzInfoFinished(AcntId, qint64,
QList<Isds::PDZInfoRec>, bool, QString)));
connect(GlobInstcs::msgProcEmitterPtr,
SIGNAL(addRecipientFinishedSignal(DataboxModelEntry, int)),
this, SLOT(addRecipientIntoModel(DataboxModelEntry, int)));
}
void IsdsWrapper::closeAllOtpConnections(void)
......@@ -505,25 +510,6 @@ void IsdsWrapper::syncSingleAccountSent(const QmlAcntId *qAcntId)
Isds::Tasks::syncSingleAccount(*qAcntId, Messages::TYPE_SENT);
}
/*!
* @brief Download data box credit info.
*
* @param[in] acntId Account identifier.
* @param[in] dbId Data box ID.
* @return Remaining credit in CZK.
*/
static
QString getPDZCreditFromISDS(const AcntId &acntId, const QString &dbId)
{
qint64 currentCredit;
QString notifEmail;
const QList<Isds::CreditEvent> cEvents =
Isds::Tasks::downloadCreditInfo(acntId, dbId, QDate(), QDate(),
currentCredit, notifEmail);
}
void IsdsWrapper::getPdzInfo(const QmlAcntId *qAcntId, const QString &dbID)
{
if (Q_UNLIKELY(qAcntId == Q_NULLPTR) || dbID.isEmpty()) {
......@@ -534,233 +520,93 @@ void IsdsWrapper::getPdzInfo(const QmlAcntId *qAcntId, const QString &dbID)
Isds::Tasks::downloadPdzInfo(*qAcntId, dbID);
}
/*!
* @brief Set possible PDZ payment methods based on PDZinfos of data box.
*
* @param[in] pdzInfos List of available PDZ payment methods.
* @param[in] canSendPdz True if can receive a commercial messages.
* @param[in] canSendInitiatory True if can receive initiatory commercial messages.
* @param[in] canUseInitReply True if can use prepaid reply commercial messages.
* @return List of possible PDZ payment methods.
*/
static
QList<Isds::Type::DmType> setPossiblePdzPaymentMethods(
const QList<Isds::PDZInfoRec> &pdzInfos, bool canSendPdz,
bool canSendInitiatory, bool canUseInitReply)
{
QList<Isds::Type::DmType> dmPaymentTypes;
/* Warning: Do not change order of append and prepend of items. */
/* Priority: O->G->K->E */
foreach (const Isds::PDZInfoRec &info, pdzInfos) {
if (info.pdzType() == Isds::Type::PPT_G) {
/*
* The payment type G may be present only once.
* If it is active, it will always be used.
* Cannot be changed to another payment type
* but can be used type I.
*/
dmPaymentTypes.clear();
dmPaymentTypes.append(Isds::Type::MT_G);
if (canSendInitiatory) {
dmPaymentTypes.append(Isds::Type::MT_I);
}
break;
} else if (info.pdzType() == Isds::Type::PPT_K) {
/* Can be selected also I when K is available. */
if (canSendInitiatory) {
dmPaymentTypes.append(Isds::Type::MT_I);
}
dmPaymentTypes.prepend(Isds::Type::MT_K);
} else if (info.pdzType() == Isds::Type::PPT_E) {
dmPaymentTypes.append(Isds::Type::MT_E);
} else if (info.pdzType() == Isds::Type::PPT_O) {
/* Not used now. */
}
}
/* Use PDZSendInfo results if PDZInfo is empty or unknown. */
if (pdzInfos.isEmpty()) {
if (canSendPdz == Isds::Type::BOOL_TRUE) {
dmPaymentTypes.append(Isds::Type::MT_K);
dmPaymentTypes.append(Isds::Type::MT_E);
}
if (canSendInitiatory) {
dmPaymentTypes.append(Isds::Type::MT_I);
}
}
/* Add prepaid reply payment method if it is available. */
if (canUseInitReply) {
dmPaymentTypes.prepend(Isds::Type::MT_O);
}
return dmPaymentTypes;
}
bool IsdsWrapper::addRecipient(const QmlAcntId *qAcntId, const QString &dbID,
void IsdsWrapper::addRecipient(const QmlAcntId *qAcntId, const QString &dbID,
const QString &dbName, const QString &dbAddress, bool canUseInitReply,
DataboxListModel *databoxModel)
{
if (Q_UNLIKELY((qAcntId == Q_NULLPTR) || (dbID.isEmpty())) ||
(databoxModel == Q_NULLPTR)) {
Q_ASSERT(0);
return false;
return;
}
m_databoxModel = databoxModel;
bool senderOvm = Accounts::isOvm(qAcntId);
/* Search for box information according to supplied identifier. */
bool lastPage;
QString lastError;
QList<Isds::DbResult2> foundBoxes;
long int totalCount, currentCount, position;
bool success = Isds::Tasks::findDataboxFulltext(*qAcntId, dbID,
Isds::Type::FST_BOX_ID, Isds::Type::BT_NULL, 0, foundBoxes,
totalCount, currentCount, position, lastPage, lastError);
QString recipDbType;
QString recipIc;
QString recipName = tr("Unknown");
QString recipAddress = tr("Unknown");
enum Isds::Type::NilBool recipDbEffectiveOVM = Isds::Type::BOOL_NULL;
if (foundBoxes.size() == 1) {
const Isds::DbResult2 &entry(foundBoxes.first());
/* Recipient data box is not active. */
if (!entry.active()) {
Dialogues::message(Dialogues::CRITICAL,
tr("Data box is not active"),
tr("Recipient with data box ID '%1' does not have active data box.").arg(dbID),
tr("The message cannot be delivered."),
Dialogues::OK, Dialogues::OK);
return false;
}
Isds::Tasks::addRecipient(*qAcntId, dbID, senderOvm, dbName,
dbAddress, canUseInitReply, m_pdzInfos);
}
/* Set current recipient name and address, data box type. */
recipIc = entry.ic();
recipName = entry.dbName();
recipAddress = entry.dbAddress();
recipDbType= dbType2Str(foundBoxes.at(0).dbType());
/* Test if recipient data box is OVM or sub-OVM */
recipDbEffectiveOVM = (entry.dbType() < Isds::Type::BT_PO)
? Isds::Type::BOOL_TRUE : Isds::Type::BOOL_FALSE;
} else if (foundBoxes.isEmpty()) {
if (success) {
/* No data box found. */
Dialogues::message(Dialogues::CRITICAL,
tr("Wrong Recipient"),
tr("Recipient with data box ID '%1' does not exist.").arg(dbID),
tr("The message cannot be delivered."),
Dialogues::OK, Dialogues::OK);
return false;
} else {
/* Search error. */
void IsdsWrapper::addRecipientIntoModel(const DataboxModelEntry &dbEntry,
int errCode)
{
if (Q_UNLIKELY((m_databoxModel == Q_NULLPTR)
|| (dbEntry.dbID().isEmpty()))) {
Q_ASSERT(0);
return;
}
switch (errCode) {
case TaskAddRecipient::TR_DB_NO_ACTIVE:
Dialogues::message(Dialogues::CRITICAL,
tr("Data box is not active"),
tr("Recipient with data box ID '%1' does not have active data box.").arg(dbEntry.dbID()),
tr("The message cannot be delivered."),
Dialogues::OK, Dialogues::OK);
return;
break;
case TaskAddRecipient::TR_DB_NOT_EXISTS:
Dialogues::message(Dialogues::CRITICAL,
tr("Wrong Recipient"),
tr("Recipient with data box ID '%1' does not exist.").arg(dbEntry.dbID()),
tr("The message cannot be delivered."),
Dialogues::OK, Dialogues::OK);
return;
break;
case TaskAddRecipient::TR_DB_SEARCH_ERROR:
{
int msgResponse = Dialogues::message(Dialogues::QUESTION,
tr("Recipient Search Failed"),
tr("Information about recipient data box '%1' could not be obtained.").arg(dbID),
tr("Do you still want to add the box '%1' into the recipient list?").arg(dbID),
tr("Information about recipient data box '%1' could not be obtained.").arg(dbEntry.dbID()),
tr("Do you still want to add the box '%1' into the recipient list?").arg(dbEntry.dbID()),
Dialogues::NO | Dialogues::YES, Dialogues::NO);
if (msgResponse == Dialogues::NO) {
return false;
return;
}
recipName = dbName;
recipAddress = dbAddress;
}
} else {
Q_ASSERT(0);
return false;
}
const bool sendPublic = senderOvm || (recipDbEffectiveOVM == Isds::Type::BOOL_TRUE);
enum Isds::Type::NilBool canSendNormalPDZ = sendPublic ? Isds::Type::BOOL_FALSE : Isds::Type::BOOL_NULL;
bool canSendInitiatoryPDZ = false;
QList<Isds::Type::DmType> dmTypes;
/* Sender is non-OVM, recipient is non-OVM so get PDZ send info. */
if (!sendPublic) {
bool canSendNormal = sendPublic;
Isds::Tasks::downloadPdzSendInfo(*qAcntId, dbID,
canSendNormal, canSendInitiatoryPDZ);
canSendNormalPDZ = canSendNormal ? Isds::Type::BOOL_TRUE
: Isds::Type::BOOL_FALSE;
dmTypes = setPossiblePdzPaymentMethods(m_pdzInfos,
canSendNormal, canSendInitiatoryPDZ, canUseInitReply);
}
if (senderOvm) {
/* I'm always sending public messages because I'm OVM. */
} else if ((recipDbEffectiveOVM == Isds::Type::BOOL_NULL) &&
(canSendNormalPDZ == Isds::Type::BOOL_NULL)) {
/*
* I'm not OVM and I could not download any information about
* the recipient.
*/
break;
case TaskAddRecipient::TR_DB_NOT_OVM_NO_DB_INFO:
Dialogues::message(Dialogues::WARNING,
tr("Unknown Message Type"),
tr("No information about the recipient data box '%1' could be obtained. It is unknown whether public or commercial messages can be sent to this recipient.").arg(dbID),
tr("No information about the recipient data box '%1' could be obtained. It is unknown whether public or commercial messages can be sent to this recipient.").arg(dbEntry.dbID()),
QString(), Dialogues::OK, Dialogues::OK);
} else if ((recipDbEffectiveOVM == Isds::Type::BOOL_NULL) &&
(canSendNormalPDZ == Isds::Type::BOOL_FALSE)) {
/*
* Don't know whether I can send public and I cannot send PDZs.
*/
break;
case TaskAddRecipient::TR_DB_NO_PUBLIC_NO_PDZ:
Dialogues::message(Dialogues::WARNING,
tr("Unknown Message Type"),
tr("No commercial message to the recipient data box '%1' can be sent. It is unknown whether a public messages can be sent to this recipient.").arg(dbID),
tr("No commercial message to the recipient data box '%1' can be sent. It is unknown whether a public messages can be sent to this recipient.").arg(dbEntry.dbID()),
QString(), Dialogues::OK, Dialogues::OK);
} else if ((recipDbEffectiveOVM == Isds::Type::BOOL_FALSE) &&
(canSendNormalPDZ == Isds::Type::BOOL_NULL)) {
/*
* Cannot send public message and don't know whether I can send
* PDZs.
*/
break;
case TaskAddRecipient::TR_DB_UNKNOWN_PUBLIC_NO_PDZ:
Dialogues::message(Dialogues::WARNING,
tr("Unknown Message Type"),
tr("No public message to the recipient data box '%1' can be sent. It is unknown whether a commercial messages can be sent to this recipient.").arg(dbID),
tr("No public message to the recipient data box '%1' can be sent. It is unknown whether a commercial messages can be sent to this recipient.").arg(dbEntry.dbID()),
QString(), Dialogues::OK, Dialogues::OK);
} else if ((recipDbEffectiveOVM == Isds::Type::BOOL_FALSE) &&
(canSendNormalPDZ == Isds::Type::BOOL_FALSE)) {
/* I cannot send a public nor a commercial message. */
break;
case TaskAddRecipient::TR_DB_NO_PUBLIC_PDZ_UNKNOWN:
Dialogues::message(Dialogues::CRITICAL,
tr("Cannot send message"),
tr("No public data message nor a commercial data message (PDZ) can be sent to the recipient data box '%1'.").arg(dbID),
tr("No public data message nor a commercial data message (PDZ) can be sent to the recipient data box '%1'.").arg(dbEntry.dbID()),
tr("Receiving of PDZs has been disabled in the recipient data box or there are no available payment methods for PDZs."),
Dialogues::OK, Dialogues::OK);
canSendNormalPDZ = Isds::Type::BOOL_NULL;
}
/* Add recipient information into recipient model.*/
DataboxModelEntry dbEntry;
dbEntry.setDbID(dbID);
dbEntry.setDbName(recipName);
dbEntry.setDbAddress(recipAddress);
dbEntry.setDbType(recipDbType);
dbEntry.setDbIC(recipIc);
dbEntry.setPdz(canSendNormalPDZ);
if (!dmTypes.isEmpty()) {
dbEntry.setDmType(dmTypes.at(0));
} else {
dbEntry.setDmType(Isds::Type::MT_UNKNOWN);
return;
break;
default:
break;
}
dbEntry.setDmTypes(dmTypes);
return databoxModel->addEntry(dbEntry);
m_databoxModel->addEntry(dbEntry);
}
void IsdsWrapper::removeIsdsCtx(const AcntId &acntId)
......@@ -1236,14 +1082,14 @@ void IsdsWrapper::pdzInfoFinished(const AcntId &acntId, qint64 currentCredit,
pdzSending = insertSeparator(tr("PDZ sending: Active"));
foreach (const Isds::PDZInfoRec &info, m_pdzInfos) {
if (info.pdzType() == Isds::Type::PPT_G) {
pdzSending += insertSeparator(tr("Sponsored by data box %1.").arg(info.pdzPayer()));
break;
} else if (info.pdzType() == Isds::Type::PPT_K) {
pdzSending += insertSeparator(tr("Contract"));
} else if (info.pdzType() == Isds::Type::PPT_E) {
m_pdzCredit = QString::number((float)currentCredit / 100, 'f', 2);
m_pdzCredit =
QString::number((float)currentCredit / 100, 'f', 2);
pdzSending += insertSeparator(tr("Remaining credit: %1 Kč").arg(m_pdzCredit));
}
}
......
......@@ -27,6 +27,7 @@
#include "src/datovka_shared/isds/box_interface.h"
#include "src/messages.h"
#include "src/models/databoxmodel.h"
#include "src/settings/account.h"
#include "src/worker/task_send_message.h"
......@@ -313,10 +314,9 @@ public:
* @param[in] dbAddress Recipient data box address.
* @param[in] canUseInitReply True if can use reply on initiatory message.
* @param[in,out] databoxModel Data box list model.
* @return True if a message can send to the recipient.
*/
Q_INVOKABLE
bool addRecipient(const QmlAcntId *qAcntId, const QString &dbID,
void addRecipient(const QmlAcntId *qAcntId, const QString &dbID,
const QString &dbName, const QString &dbAddress,
bool canUseInitReply, DataboxListModel *databoxModel);
......@@ -405,9 +405,8 @@ private:
QList<TaskSendMessage::ResultData> m_sentMsgResultList; /*!< Send status list. */
QList<Isds::PDZInfoRec> m_pdzInfos; /*!< PDZ info list. */
enum Isds::Type::DmType m_dmType; /*!< Message type. */
QString m_pdzCredit; /*! String containing credit value. */
QString m_dmSenderRefNumber; /*!< Message reference number. */
DataboxListModel *m_databoxModel; /*! Hold recipient model. */
public slots:
/*!
......@@ -494,6 +493,15 @@ public slots:
const QList<Isds::PDZInfoRec> &infos, bool success,
const QString &errTxt);
/*!
* @brief Add recipient into model.
*
* @param[in] dbEntry Data box entry.
* @param[in] errCode Error code.
*/
void addRecipientIntoModel(const DataboxModelEntry &dbEntry,
int errCode);
signals:
/*!
* @brief Update message model in QML.
......
......@@ -27,6 +27,7 @@
#include "src/datovka_shared/identifiers/account_id.h"
#include "src/datovka_shared/isds/box_interface.h"
#include "src/models/databoxmodel.h"
/*!
* @brief Message processing status emitter.
......@@ -128,6 +129,15 @@ signals:
void pdzInfoFinishedSignal(const AcntId &acntId, qint64 currentCredit,
const QList<Isds::PDZInfoRec> &infos, bool success,
const QString &errTxt);
/*!
* @brief Add recipient into model.
*
* @param[in] dbEntry Data box entry.
* @param[in] errCode Error code.
*/
void addRecipientFinishedSignal(const DataboxModelEntry &dbEntry,
int errCode);
};
Q_DECLARE_METATYPE(QList<Isds::PDZInfoRec>)
Supports Markdown
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