From 70302829b7618c8285df9f3f870e5a68ab247df2 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Fri, 1 May 2020 00:02:28 +0200 Subject: [PATCH] make Addressbook HushChat address changeable and show it earlier --- src/addressbook.cpp | 51 ++++++++++++++++++++++++++++----------------- src/addressbook.ui | 28 ++++++++++++------------- 2 files changed, 46 insertions(+), 33 deletions(-) diff --git a/src/addressbook.cpp b/src/addressbook.cpp index 522ec60..4725959 100644 --- a/src/addressbook.cpp +++ b/src/addressbook.cpp @@ -138,6 +138,24 @@ void AddressBook::open(MainWindow* parent, QLineEdit* target) // Connect the dialog's closing to updating the label address completor QObject::connect(&d, &QDialog::finished, [=] (auto) { parent->updateLabels(); }); + Controller* rpc = parent->getRPC(); + bool sapling = true; + rpc->createNewZaddr(sapling, [=] (json reply) { + QString myAddr = QString::fromStdString(reply.get()[0]); + // QString myAddr = "zs1flslqurcnummsw37mfxkhx6d7uwpevlc78cdjyqrgng7357t8f3stm9fneeqtuupfnrt7f933a9"; + QString message = QString("New Chat Address for your partner: ") + myAddr; + + parent->ui->listReceiveAddresses->insertItem(0, myAddr); + parent->ui->listReceiveAddresses->setCurrentIndex(0); + // ab.addr_chat->setText(myAddr); + qDebug() << "new generated myAddr" << myAddr; + // + ab.addr_chat->setText(myAddr); + // AddressBook::getInstance()->addAddressLabel(newLabel, ab.addr->text(), myAddr, cid); + }); + model.updateUi(); //todo fix updating gui after adding + rpc->refresh(true); + // If there is a target then make it the addr for the "Add to" button if (target != nullptr && Settings::isValidAddress(target->text())) { @@ -148,7 +166,11 @@ void AddressBook::open(MainWindow* parent, QLineEdit* target) // Add new address button QObject::connect(ab.addNew, &QPushButton::clicked, [&] () { auto addr = ab.addr->text().trimmed(); + auto myAddr = ab.addr->text().trimmed(); QString newLabel = ab.label->text(); + QString cid = QUuid::createUuid().toString(QUuid::WithoutBraces); + + if (addr.isEmpty() || newLabel.isEmpty()) { @@ -183,32 +205,23 @@ void AddressBook::open(MainWindow* parent, QLineEdit* target) ); return; } - Controller* rpc = parent->getRPC(); - bool sapling = true; - rpc->createNewZaddr(sapling, [=] (json reply) { - QString myAddr = QString::fromStdString(reply.get()[0]); - QString message = QString("New Chat Address for your partner: ") + myAddr; + + ////// We need a better popup here. + AddressBook::getInstance()->addAddressLabel(newLabel, addr, myAddr, cid); QMessageBox::critical( parent, - QObject::tr("Success"), - message, //todo translate this + QObject::tr("Add Successfully"), + QObject::tr("juhu").arg(newLabel), QMessageBox::Ok ); - parent->ui->listReceiveAddresses->insertItem(0, addr); - parent->ui->listReceiveAddresses->setCurrentIndex(0); - // ab.addr_chat->setText(myAddr); - qDebug() << "new generated myAddr" << myAddr; - QString cid = QUuid::createUuid().toString(QUuid::WithoutBraces); // - AddressBook::getInstance()->addAddressLabel(newLabel, ab.addr->text(), myAddr, cid); - }); - model.updateUi(); //todo fix updating gui after adding + return; + + + rpc->refresh(true); + model.updateUi(); }); - /// Generate CID for Contact - - - // AddressBook::getInstance()->addAddressLabel(newLabel, ab.addr->text(), cid); // Import Button diff --git a/src/addressbook.ui b/src/addressbook.ui index 20104b9..1c6ed52 100644 --- a/src/addressbook.ui +++ b/src/addressbook.ui @@ -20,7 +20,17 @@ Add New Address - + + + + Address (z-Addr or t-Addr) + + + + + + + HushChat Address - give this Address only to your contact @@ -30,10 +40,10 @@ - - + + - Address (z-Addr or t-Addr) + Label @@ -47,16 +57,6 @@ - - - - Label - - - - - -