Browse Source

make Addressbook HushChat address changeable and show it earlier

pull/130/head
DenioD 4 years ago
parent
commit
70302829b7
  1. 51
      src/addressbook.cpp
  2. 28
      src/addressbook.ui

51
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<json::array_t>()[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<json::array_t>()[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

28
src/addressbook.ui

@ -20,7 +20,17 @@
<string>Add New Address</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0" colspan="2">
<item row="0" column="0">
<widget class="QLabel" name="label_1">
<property name="text">
<string>Address (z-Addr or t-Addr)</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLineEdit" name="addr"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>HushChat Address - give this Address only to your contact</string>
@ -30,10 +40,10 @@
<item row="3" column="0">
<widget class="QLineEdit" name="addr_chat"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_1">
<item row="4" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Address (z-Addr or t-Addr)</string>
<string>Label</string>
</property>
</widget>
</item>
@ -47,16 +57,6 @@
<item row="6" column="0">
<layout class="QHBoxLayout" name="horizontalLayout"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Label</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLineEdit" name="addr"/>
</item>
<item row="6" column="1">
<widget class="QPushButton" name="addNew">
<property name="text">

Loading…
Cancel
Save