Files
triangles_v5/src/qt/sendmessagesentry.cpp
T
sami7777 0d6e143398
Build All Platforms / test-linux-unit (push) Failing after 40s
Build All Platforms / build-linux-qt (push) Failing after 40s
Build All Platforms / build-linux-daemon (push) Failing after 40s
Build All Platforms / build-windows-qt (push) Has been cancelled
Build All Platforms / build-windows-daemon (push) Has been cancelled
Build All Platforms / build-macos (push) Has been cancelled
Build All Platforms / release (push) Has been cancelled
Build All Platforms / Trigger TRI-PI ARM64 Build (push) Has been cancelled
Send TX and messages to .onion addresses
- Address validator accepts V3 .onion format (62 chars, base32 + .onion)
- WalletModel::validateAddress() recognizes .onion via ValidateOnionAddress()
- Send coins/messages dialogs resolve .onion to TRI before sending
- Auto-request getwalletaddr from onion peers after version handshake
- Placeholder text updated to "Enter a TRI address or .onion address"
- Shows info dialog if resolution is pending (async connect + resolve)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 23:07:12 -07:00

205 lines
4.9 KiB
C++

#include "sendmessagesentry.h"
#include "ui_sendmessagesentry.h"
#include "guiutil.h"
#include "addressbookpage.h"
#include "walletmodel.h"
#include "messagemodel.h"
#include "optionsmodel.h"
#include "addresstablemodel.h"
#include "smessage.h"
#include <QApplication>
#include <QClipboard>
SendMessagesEntry::SendMessagesEntry(QWidget *parent) :
QFrame(parent),
ui(new Ui::SendMessagesEntry),
model(0)
{
ui->setupUi(this);
#ifdef Q_OS_MAC
ui->sendToLayout->setSpacing(4);
#endif
#if QT_VERSION >= 0x040700
/* Do not move this to the XML file, Qt before 4.7 will choke on it */
ui->addAsLabel->setPlaceholderText(tr("Enter a label for this address to add it to your address book"));
ui->sendTo->setPlaceholderText(tr("Enter a TRI address or .onion address"));
ui->publicKey->setPlaceholderText(tr("Enter the public key for the address above, it is not in the blockchain"));
ui->messageText->setErrorText(tr("You cannot send a blank message!"));
#endif
setFocusPolicy(Qt::TabFocus);
setFocusProxy(ui->sendTo);
GUIUtil::setupAddressWidget(ui->sendTo, this);
}
SendMessagesEntry::~SendMessagesEntry()
{
delete ui;
}
void SendMessagesEntry::on_pasteButton_clicked()
{
// Paste text from clipboard into recipient field
ui->sendTo->setText(QApplication::clipboard()->text());
}
void SendMessagesEntry::on_addressBookButton_clicked()
{
if(!model)
return;
AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::SendingTab, this);
dlg.setModel(model->getWalletModel()->getAddressTableModel());
if(dlg.exec())
{
ui->sendTo->setText(dlg.getReturnValue());
if(ui->publicKey->text() == "")
ui->publicKey->setFocus();
else
ui->messageText->setFocus();
}
}
void SendMessagesEntry::on_sendTo_textChanged(const QString &address)
{
if(!model)
return;
QString pubkey;
QString sendTo = address;
if(model->getAddressOrPubkey(sendTo, pubkey))
{
ui->publicKey->setText(pubkey);
}
else
{
ui->publicKey->show();
ui->publicKeyLabel->show();
}
// Fill in label from address book, if address has an associated label
QString associatedLabel = model->getWalletModel()->getAddressTableModel()->labelForAddress(address);
if(!associatedLabel.isEmpty())
ui->addAsLabel->setText(associatedLabel);
}
void SendMessagesEntry::setModel(MessageModel *model)
{
this->model = model;
//clear();
}
void SendMessagesEntry::loadRow(int row)
{
if(model->data(model->index(row, model->Type, QModelIndex()), Qt::DisplayRole).toString() == MessageModel::Received)
ui->sendTo->setText(model->data(model->index(row, model->FromAddress, QModelIndex()), Qt::DisplayRole).toString());
else
ui->sendTo->setText(model->data(model->index(row, model->ToAddress, QModelIndex()), Qt::DisplayRole).toString());
}
void SendMessagesEntry::setRemoveEnabled(bool enabled)
{
ui->deleteButton->setEnabled(enabled);
}
void SendMessagesEntry::clear()
{
ui->sendTo->clear();
ui->addAsLabel->clear();
ui->messageText->clear();
ui->sendTo->setFocus();
}
void SendMessagesEntry::on_deleteButton_clicked()
{
emit removeEntry(this);
}
bool SendMessagesEntry::validate()
{
// Check input validity
bool retval = true;
if(ui->messageText->toPlainText() == "")
{
ui->messageText->setValid(false);
retval = false;
}
if(!ui->sendTo->hasAcceptableInput() || (!model->getWalletModel()->validateAddress(ui->sendTo->text())))
{
ui->sendTo->setValid(false);
retval = false;
}
if(ui->publicKey->text() == "")
{
ui->publicKey->setValid(false);
ui->publicKey->show();
retval = false;
}
return retval;
}
SendMessagesRecipient SendMessagesEntry::getValue()
{
SendMessagesRecipient rv;
rv.address = ui->sendTo->text();
rv.label = ui->addAsLabel->text();
rv.pubkey = ui->publicKey->text();
rv.message = ui->messageText->toPlainText();
return rv;
}
QWidget *SendMessagesEntry::setupTabChain(QWidget *prev)
{
QWidget::setTabOrder(prev, ui->sendTo);
QWidget::setTabOrder(ui->sendTo, ui->addressBookButton);
QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton);
QWidget::setTabOrder(ui->pasteButton, ui->deleteButton);
QWidget::setTabOrder(ui->deleteButton, ui->addAsLabel);
QWidget::setTabOrder(ui->addAsLabel, ui->publicKey);
QWidget::setTabOrder(ui->publicKey, ui->messageText);
return ui->messageText;
}
void SendMessagesEntry::setValue(const SendMessagesRecipient &value)
{
ui->sendTo->setText(value.address);
ui->addAsLabel->setText(value.label);
ui->publicKey->setText(value.pubkey);
ui->messageText->setPlainText(value.message);
}
bool SendMessagesEntry::isClear()
{
return ui->sendTo->text().isEmpty();
}
void SendMessagesEntry::setFocus()
{
ui->sendTo->setFocus();
}