diff --git a/src/addressbook.cpp b/src/addressbook.cpp index ca224b4..522ec60 100644 --- a/src/addressbook.cpp +++ b/src/addressbook.cpp @@ -194,6 +194,8 @@ void AddressBook::open(MainWindow* parent, QLineEdit* target) message, //todo translate this 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); // diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index 2b2b6a0..f449b99 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -62,9 +62,7 @@ void ChatModel::showMessages() } } - - -void ChatModel::renderChatBox(Ui::MainWindow* ui, QListWidget &view) +void ChatModel::renderChatBox(Ui::MainWindow* ui, QListWidget &view) { /*for(auto &c : this->chatItems) { @@ -90,14 +88,22 @@ void ChatModel::renderChatBox(Ui::MainWindow* ui, QListWidget *view) myDateTime.setTime_t(c.second.getTimestamp()); - ////// - if ((ui->ContactZaddr->text().trimmed() == c.second.getAddress()) && (c.second.getMemo().startsWith("{") == false)) { + //////Render only Memos for selected contacts. Do not render empty Memos + if ((ui->ContactZaddr->text().trimmed() == c.second.getAddress()) && (c.second.getMemo().startsWith("{") == false) && (c.second.getMemo().isEmpty() == false)) { + line += QString("[") + myDateTime.toString("dd.MM.yyyy hh:mm:ss ") + QString("] "); + line += QString("<") + QString(c.second.getContact()) + QString("> :\n"); + line += QString(c.second.getMemo()) + QString("\n"); + view->addItem(line); + line =""; + } + + if ((ui->MyZaddr->text().trimmed() == c.second.getAddress()) && (c.second.getMemo().startsWith("{") == false) && (c.second.getMemo().isEmpty() == false)){ line += QString("[") + myDateTime.toString("dd.MM.yyyy hh:mm:ss ") + QString("] "); line += QString("<") + QString(c.second.getContact()) + QString("> :\n"); line += QString(c.second.getMemo()) + QString("\n"); view->addItem(line); line =""; - }else {} + }else{} } @@ -130,14 +136,8 @@ Tx MainWindow::createTxFromChatPage() { CAmount totalAmt; // For each addr/amt in the Chat tab { - - // QString addr = ui->ContactZaddr->text().trimmed(); // We need to set the reply Address for our Contact here - // Remove label if it exists - // addr = AddressBook::addressFromAddressLabel(addr); - + QString amtStr = "0"; - - // bool ok; CAmount amt; @@ -151,17 +151,16 @@ Tx MainWindow::createTxFromChatPage() { QString cid = c.getCid(); QString myAddr = c.getMyAddress(); - QString type = "memo"; + QString type = "Memo"; QString addr = c.getPartnerAddress(); QString hmemo= createHeaderMemo(type,cid,myAddr); QString memo = ui->memoTxtChat->toPlainText().trimmed(); - // ui->memoSizeChat->setLenDisplayLabel(); - - + // ui->memoSizeChat->setLenDisplayLabel();// Todo -> activate lendisplay for chat + tx.toAddrs.push_back(ToFields{addr, amt, hmemo}) ; - qDebug()<text()))) { - // QMessageBox msg(QMessageBox::Critical, tr("Memos 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); + // for(auto &c : AddressBook::getInstance()->getAllAddressLabels()) - // msg.exec(); - //return; - //} + // if (ui->ContactZaddr->text().trimmed() == c.getName()) { + + // auto addr = ""; + // if (! Settings::isZAddress(AddressBook::addressFromAddressLabel(addr->text()))) { + // QMessageBox msg(QMessageBox::Critical, tr("Memos 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); + + // msg.exec(); + // return; + // } Tx tx = createTxFromChatPage(); @@ -287,20 +292,13 @@ QString MainWindow::doSendChatTxValidations(Tx tx) { return ""; } -// Create a Safe Contact Request. +// Create a Contact Request. Tx MainWindow::createTxForSafeContactRequest() { Tx tx; CAmount totalAmt; - // For each addr/amt in the Chat tab { - QString addr = ui->ContactZaddr->text().trimmed(); // We need to set the reply Address for our Contact here - // Remove label if it exists - addr = AddressBook::addressFromAddressLabel(addr); - QString amtStr = "0"; - - // bool ok; CAmount amt; @@ -318,20 +316,17 @@ Tx MainWindow::createTxForSafeContactRequest() { QString cid = ""; QString myAddr = ""; QString addr = ""; - QString safeContact = "true"; + QString type = "Request"; - QString hmemo= createHeaderMemo(safeContact,cid,myAddr); - QString memo = ui->memoTxtChat->toPlainText().trimmed(); - // ui->memoSizeChat->setLenDisplayLabel(); - - + QString hmemo= createHeaderMemo(type,cid,myAddr); + tx.toAddrs.push_back(ToFields{addr, amt, hmemo}) ; - qDebug()<text()))) { - // QMessageBox msg(QMessageBox::Critical, tr("Memos 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); - - // msg.exec(); - //return; - //} + // for(auto &c : AddressBook::getInstance()->getAllAddressLabels()) + + // if (ui->ContactZaddr->text().trimmed() == c.getName()) { + + // 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); + + // msg.exec(); + // return; + // } Tx tx = createTxForSafeContactRequest(); diff --git a/src/chatmodel.h b/src/chatmodel.h index e0a6dd0..43a0e88 100644 --- a/src/chatmodel.h +++ b/src/chatmodel.h @@ -118,8 +118,8 @@ class ChatModel void setItems(std::map items); QString zaddr(); void setItems(std::vector items); - void renderChatBox(Ui::MainWindow* ui, QListWidget &view); - void renderChatBox(Ui::MainWindow* ui, QListWidget *view); + void renderChatBox(Ui::MainWindow* ui, QListWidget &view); + void renderChatBox(Ui::MainWindow* ui, QListWidget *view); void showMessages(); void clear(); void addMessage(ChatItem item); diff --git a/src/controller.cpp b/src/controller.cpp index 0c557ca..644fdfb 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -840,48 +840,47 @@ void Controller::refreshBalances() }); } -void Controller::refreshTransactions() -{ +void Controller::refreshTransactions() { if (!zrpc->haveConnection()) return noConnection(); zrpc->fetchTransactions([=] (json reply) { QList txdata; - for (auto& it : reply.get()) - { + for (auto& it : reply.get()) { QString address; CAmount total_amount; QList items; long confirmations; - if (it.find("unconfirmed") != it.end() && it["unconfirmed"].get()) + if (it.find("unconfirmed") != it.end() && it["unconfirmed"].get()) { confirmations = 0; - else + } else { confirmations = model->getLatestBlock() - it["block_height"].get() + 1; + } auto txid = QString::fromStdString(it["txid"]); auto datetime = it["datetime"].get(); // First, check if there's outgoing metadata - if (!it["outgoing_metadata"].is_null()) - { - for (auto o: it["outgoing_metadata"].get()) - { - QString address; + if (!it["outgoing_metadata"].is_null()) { + + for (auto o: it["outgoing_metadata"].get()) { + + QString address; + address = QString::fromStdString(o["address"]); - + // Sent items are -ve CAmount amount = CAmount::fromqint64(-1* o["value"].get()); // Check for Memos QString memo; - if (!o["memo"].is_null()) - { + if (!o["memo"].is_null()) { memo = QString::fromStdString(o["memo"]); - - ChatItem item = ChatItem( + } + ChatItem item = ChatItem( datetime, address, QString(""), @@ -889,9 +888,6 @@ void Controller::refreshTransactions() true // is an outgoing message ); chatModel->addMessage(item); - - } - items.push_back(TransactionItemDetail{address, amount, memo}); total_amount = total_amount + amount; @@ -901,62 +897,46 @@ void Controller::refreshTransactions() // Concat all the addresses QList addresses; - for (auto item : items) - { - if (item.amount == 0 ) - { - } - else - { - addresses.push_back(item.address); - address = addresses.join(","); - } + for (auto item : items) { + + addresses.push_back(item.address); + + address = addresses.join(","); - } + } } - txdata.push_back( - TransactionItem{"send", datetime, address, txid,confirmations, items} - ); - - } - else - { + txdata.push_back(TransactionItem{ + "send", datetime, address, txid,confirmations, items + }); + } else { // Incoming Transaction address = (it["address"].is_null() ? "" : QString::fromStdString(it["address"])); model->markAddressUsed(address); + QString memo; - if (!it["memo"].is_null()) - { + if (!it["memo"].is_null()) { memo = QString::fromStdString(it["memo"]); - - ChatItem item = ChatItem( + } + + ChatItem item = ChatItem( datetime, address, QString(""), memo ); chatModel->addMessage(item); - } - - items.push_back( - TransactionItemDetail{ - address, - CAmount::fromqint64(it["amount"].get()), - memo - } - ); + items.push_back(TransactionItemDetail{ + address, + CAmount::fromqint64(it["amount"].get()), + memo + }); TransactionItem tx{ - "Receive", - datetime, - address, - txid, - confirmations, - items + "Receive", datetime, address, txid,confirmations, items }; txdata.push_back(tx); @@ -967,29 +947,25 @@ void Controller::refreshTransactions() // Calculate the total unspent amount that's pending. This will need to be // shown in the UI so the user can keep track of pending funds CAmount totalPending; - for (auto txitem : txdata) - { - if (txitem.confirmations == 0) - { - for (auto item: txitem.items) - { + for (auto txitem : txdata) { + if (txitem.confirmations == 0) { + for (auto item: txitem.items) { totalPending = totalPending + item.amount; } } } - - getModel()->setTotalPending(totalPending); + getModel()->setTotalPending(totalPending); // Update UI Balance updateUIBalances(); - // Update model data, which updates the table view + // Update model data, which updates the table view transactionsTableModel->replaceData(txdata); chatModel->renderChatBox(ui, ui->listChatMemo); refreshContacts( ui->listContactWidget ); - }); + }); } void Controller::refreshChat(QListWidget *listWidget) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index ab37b27..f6bb131 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -997,10 +997,12 @@ void MainWindow::setupchatTab() { QString label_contact = index.data(Qt::DisplayRole).toString(); for(auto &p : AddressBook::getInstance()->getAllAddressLabels()) - if (label_contact == p.getName()) + if (label_contact == p.getName()) { ui->ContactZaddr->setText(p.getPartnerAddress()); + ui->MyZaddr->setText(p.getMyAddress()); rpc->refresh(true); + } }); } diff --git a/src/mainwindow.ui b/src/mainwindow.ui index ed63164..1a0bb02 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -1354,8 +1354,8 @@ - 340 - 490 + 400 + 410 331 17 @@ -1453,8 +1453,8 @@ - 520 - 490 + 340 + 460 67 17 @@ -1466,21 +1466,21 @@ - 520 + 340 490 - 67 + 161 17 - + Your HushChat zaddr: - 550 - 490 + 370 + 460 691 20 @@ -1511,6 +1511,19 @@ false + + + + 490 + 490 + 691 + 20 + + + + + +