From bcbee161eb277d4c5f4cef532a34ae186d4c41b2 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Sun, 3 May 2020 23:37:02 +0200 Subject: [PATCH] activate contact request hm, for testing --- src/chatmodel.cpp | 111 ++++++++++++++++------------ src/contactrequest.ui | 167 ++++++++++++++++++++++++++++++++---------- src/mainwindow.cpp | 5 +- src/mainwindow.h | 3 +- 4 files changed, 201 insertions(+), 85 deletions(-) diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index de38e97..550081c 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -377,12 +377,28 @@ QString MainWindow::doSendChatTxValidations(Tx tx) { return ""; } -// Create a Contact Request. + +// Create a Tx from the current state of the Chat page. Tx MainWindow::createTxForSafeContactRequest() { - Tx tx; - CAmount totalAmt; - { + + Ui_Dialog request; + QDialog dialog(this); + request.setupUi(&dialog); + Settings::saveRestore(&dialog); +dialog.exec(); + + Tx tx; + QObject::connect(request.cancel, &QPushButton::clicked, [&] () { + + dialog.close(); + }); + + + QObject::connect(request.sendRequestButton, &QPushButton::clicked, this, &MainWindow::ContactRequest); + // For each addr/amt in the Chat tab + { + CAmount totalAmt; QString amtStr = "0"; CAmount amt; @@ -392,48 +408,46 @@ Tx MainWindow::createTxForSafeContactRequest() { for(auto &c : AddressBook::getInstance()->getAllAddressLabels()) + if (request.zaddr->text().trimmed() != c.getPartnerAddress()) { - if (ui->contactNameMemo->text().trimmed() == c.getName()) { - - // QString cid = c.getCid(); // This has to be a new cid for the contact - // QString myAddr = c.getMyAddress(); // this should be a new HushChat zaddr - // QString addr = c.getPartnerAddress(); // this address will be insert by the user - QString cid = c.getCid(); - QString myAddr = c.getMyAddress(); - QString addr = c.getPartnerAddress(); - QString type = "cont"; - - + QString cid = c.getCid(); + QString myAddr = c.getMyAddress(); + QString type = "cont"; + QString addr = request.zaddr->text(); + + - QString hmemo= createHeaderMemo(type,cid,myAddr); - - tx.toAddrs.push_back(ToFields{addr, amt, hmemo}) ; + QString hmemo= createHeaderMemo(type,cid,myAddr,0,0); + QString memo = request.requestmemo->toPlainText().trimmed(); - qDebug() << "pushback chattx"; - } -} + + tx.toAddrs.push_back(ToFields{addr, amt, hmemo}); + tx.toAddrs.push_back(ToFields{addr, amt, memo}); - - tx.fee = Settings::getMinerFee(); + qDebug() << "pushback chattx"; + tx.fee = Settings::getMinerFee(); return tx; qDebug() << "ChatTx created"; + } if (request.zaddr->text().trimmed().isEmpty() == false){ + + QMessageBox msg(QMessageBox::Critical, tr("Please insert a contact Address"), request.zaddr->text(), + QMessageBox::Ok, this); + + msg.exec(); + + } + + } + } -//////////////////De-activated for now/////////////////// -void MainWindow::safeContactRequest() { +void MainWindow::ContactRequest() { - // Ui_ContactRequest contactRequest; - // QDialog dialog(this); - // contactRequest.setupUi(&dialog); - // Settings::saveRestore(&dialog); - // memoDialog.memoTxt->setLenDisplayLabel(memoDialog.memoSize); - // memoDialog.memoTxt->setAcceptButton(memoDialog.buttonBox->button(QDialogButtonBox::Ok)); - - ////////////////////////////Todo: Check if its a zaddr////////// + ////////////////////////////Todo: Check if a Contact is selected////////// // Create a Tx from the values on the send tab. Note that this Tx object // might not be valid yet. @@ -441,21 +455,24 @@ void MainWindow::safeContactRequest() { // Memos can only be used with zAddrs. So check that first // for(auto &c : AddressBook::getInstance()->getAllAddressLabels()) - // if (ui->ContactZaddr->text().trimmed() == c.getName()) { + // if (ui->contactNameMemo->text().trimmed().isEmpty() || ui->memoTxtChat->toPlainText().trimmed().isEmpty()) { // auto addr = ""; // if (! Settings::isZAddress(AddressBook::addressFromAddressLabel(addr->text()))) { - // QMessageBox msg(QMessageBox::Critical, tr("Contact requests can only be used with z-addresses"), - // tr("The memo field can only be used with a z-address.\n") + addr->text() + tr("\ndoesn't look like a z-address"), - // QMessageBox::Ok, this); + // QMessageBox msg(QMessageBox::Critical, tr("You have to select a contact and insert a Memo"), + // tr("You have selected no Contact from Contactlist,\n") + tr("\nor your Memo is empty"), + // QMessageBox::Ok, this); - // msg.exec(); - // return; + // msg.exec(); + // return; // } - Tx tx = createTxForSafeContactRequest(); + +//}; - QString error = doSendRequestTxValidations(tx); + Tx tx = createTxForSafeContactRequest(); + + QString error = doSendChatTxValidations(tx); if (!error.isEmpty()) { // Something went wrong, so show an error and exit @@ -469,7 +486,6 @@ void MainWindow::safeContactRequest() { qDebug() << "Tx aborted"; } - // Create a new Dialog to show that we are computing/sending the Tx // Create a new Dialog to show that we are computing/sending the Tx auto d = new QDialog(this); auto connD = new Ui_ConnectionDialog(); @@ -488,9 +504,10 @@ void MainWindow::safeContactRequest() { } connD->status->setText(tr("Please wait...")); - connD->statusDetail->setText(tr("Your Contact Request will be send")); + connD->statusDetail->setText(tr("Your Message will be send")); d->show(); + ui->memoTxtChat->clear(); // And send the Tx rpc->executeTransaction(tx, @@ -509,7 +526,8 @@ void MainWindow::safeContactRequest() { }); // Force a UI update so we get the unconfirmed Tx - rpc->refresh(true); + // rpc->refresh(true); + ui->memoTxtChat->clear(); }, // Errored out @@ -527,7 +545,8 @@ void MainWindow::safeContactRequest() { QMessageBox::critical(this, QObject::tr("Transaction Error"), errStr, QMessageBox::Ok); } ); - } + + } QString MainWindow::doSendRequestTxValidations(Tx tx) { @@ -558,4 +577,4 @@ QString MainWindow::doSendRequestTxValidations(Tx tx) { } return ""; -} +} \ No newline at end of file diff --git a/src/contactrequest.ui b/src/contactrequest.ui index fb923db..1bd758f 100644 --- a/src/contactrequest.ui +++ b/src/contactrequest.ui @@ -1,72 +1,165 @@ - - - - + + Dialog - - + + 0 0 - 400 - 300 + 780 + 416 - + Dialog - - + + - 30 - 240 - 341 - 32 + 0 + 100 + 351 + 17 - - Qt::Horizontal + + <html><head/><body><p>Please insert the Address of your contact :</p></body></html> - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + 10 + 190 + 461 + 17 + + + + <html><head/><body><p>Insert a Message, and ask your friend for the contact request : </p><p><br/></p></body></html> + + + + + + 0 + 240 + 591 + 101 + + + + + + + 0 + 140 + 591 + 25 + + + + + + + 490 + 360 + 114 + 25 + + + + + 100 + 0 + + + + Send + + + false + + + + + + 320 + 360 + 114 + 25 + + + + + 100 + 0 + + + + Cancel + + + false + + + + + + 0 + 10 + 351 + 17 + + + + <html><head/><body><p>Please insert a Nickname for your contact :</p></body></html> + + + + + + 0 + 50 + 591 + 25 + - - buttonBox - accepted() + sendRequestButton + clicked() Dialog accept() - - 248 - 254 + + 536 + 262 - - 157 - 274 + + 389 + 207 - buttonBox - rejected() + cancel + clicked() Dialog reject() - - 316 - 260 + + 396 + 262 - - 286 - 274 + + 389 + 207 - diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index a45f5b5..d685005 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -14,6 +14,7 @@ #include "settings.h" #include "version.h" #include "connection.h" +#include "ui_contactrequest.h" #include "requestdialog.h" #include "websockets.h" #include @@ -1006,7 +1007,8 @@ void MainWindow::setupchatTab() { // Send button QObject::connect(ui->sendChatButton, &QPushButton::clicked, this, &MainWindow::sendChatButton); - QObject::connect(ui->safeContactRequest, &QPushButton::clicked, this, &MainWindow::safeContactRequest); + QObject::connect(ui->safeContactRequest, &QPushButton::clicked, this, &MainWindow::ContactRequest); + ///////// Set selected Zaddr for Chat with Doubleklick @@ -1032,6 +1034,7 @@ void MainWindow::setupchatTab() { } + ChatMemoEdit::ChatMemoEdit(QWidget* parent) : QPlainTextEdit(parent) { QObject::connect(this, &QPlainTextEdit::textChanged, this, &ChatMemoEdit::updateDisplay); } diff --git a/src/mainwindow.h b/src/mainwindow.h index 1110f67..c767128 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -108,13 +108,14 @@ private: Tx createTxFromChatPage(); Tx createTxForSafeContactRequest(); + void encryptWallet(); void removeWalletEncryption(); void cancelButton(); void sendButton(); void sendChatButton(); - void safeContactRequest(); + void ContactRequest(); void addAddressSection(); void maxAmountChecked(int checked);