diff --git a/shop/shopform.cpp b/shop/shopform.cpp index 1ed3c1f..cd02c6d 100644 --- a/shop/shopform.cpp +++ b/shop/shopform.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include "shop-odb.hxx" @@ -327,7 +328,19 @@ void ShopForm::on_payButton_clicked() if (!eetRet) { + QString errMsg = tr("EET communication error.\n"); + if (!eetMsg.isEmpty()) + { + errMsg += tr("Message from portal: ") + eetMsg + "\n"; + } + + errMsg += tr("Switch to offline?"); + + if (srv.isEetOnline() && QMessageBox::question(this, tr("EET error"), errMsg) == QMessageBox::Yes) + { + srv.setEetOnline(false); + } } ReceiptGenerator generator; diff --git a/shop/shopservice.cpp b/shop/shopservice.cpp index 5055c4d..2b515be 100644 --- a/shop/shopservice.cpp +++ b/shop/shopservice.cpp @@ -126,7 +126,7 @@ void ShopService::updateRelatedItem(VoucherItem* item, int countAdded) } } -bool ShopService::processEet(VoucherPtr voucher, QString message) +bool ShopService::processEet(VoucherPtr voucher, QString &message) { if (voucher->eetStatus() == Voucher::EET_NOT_ENTERING) { @@ -153,8 +153,9 @@ bool ShopService::processEet(VoucherPtr voucher, QString message) sender->setPlayground(settings->eetPlayground()); QEventLoop loop; + bool replyFinished = false; - connect(sender, &EetSender::sendFinished, [this, voucher, sender, &loop](){ + connect(sender, &EetSender::sendFinished, [this, voucher, sender, &loop, &replyFinished](){ Transaction tx; voucher->setEetBkp(sender->resut()->bkp()); @@ -176,10 +177,15 @@ bool ShopService::processEet(VoucherPtr voucher, QString message) sender->deleteLater(); loop.quit(); + replyFinished = true; }); sender->sendRequest(&request); - loop.exec(); + + if (!replyFinished) + { + loop.exec(); + } auto addMessage = [&message](EetMessage *msg, const QString &label){ if (message.isEmpty()) @@ -206,6 +212,11 @@ void ShopService::setEetOnline(bool online) EetSender::m_online = online; } +bool ShopService::isEetOnline() +{ + return EetSender::m_online; +} + void ShopService::moveItems(QList items, VoucherPtr source, VoucherPtr target) { Transaction tx; diff --git a/shop/shopservice.h b/shop/shopservice.h index 29e58c7..b3bb095 100644 --- a/shop/shopservice.h +++ b/shop/shopservice.h @@ -21,8 +21,9 @@ public: void pay(VoucherPtr voucher); void moveItems(QList items, VoucherPtr source, VoucherPtr target); void updateRelatedItem(VoucherItem* item, int countAdded); - bool processEet(VoucherPtr voucher, QString message); + bool processEet(VoucherPtr voucher, QString &message); void setEetOnline(bool online); + bool isEetOnline(); QList savedVouchers(); QList tempVouchers(); QList paiedVouchers();