@@ -1,4 +1,13 @@
|
|||||||
#include "chatmodel.h"
|
#include "chatmodel.h"
|
||||||
|
#include "settings.h"
|
||||||
|
#include "ui_confirm.h"
|
||||||
|
#include "controller.h"
|
||||||
|
#include "mainwindow.h"
|
||||||
|
#include "ui_mainwindow.h"
|
||||||
|
#include "addressbook.h"
|
||||||
|
#include "ui_memodialog.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ChatModel::ChatModel(std::map<long, ChatItem> chatItems)
|
ChatModel::ChatModel(std::map<long, ChatItem> chatItems)
|
||||||
{
|
{
|
||||||
@@ -77,9 +86,203 @@ void ChatModel::renderChatBox(QListWidget *view)
|
|||||||
myDateTime.setTime_t(c.second.getTimestamp());
|
myDateTime.setTime_t(c.second.getTimestamp());
|
||||||
qDebug() << "[" << myDateTime.toString("dd.MM.yyyy hh:mm:ss ") << "] " << "<" << c.second.getAddress() << "> :" << c.second.getMemo();
|
qDebug() << "[" << myDateTime.toString("dd.MM.yyyy hh:mm:ss ") << "] " << "<" << c.second.getAddress() << "> :" << c.second.getMemo();
|
||||||
line += QString("[") + myDateTime.toString("dd.MM.yyyy hh:mm:ss ") + QString("] ");
|
line += QString("[") + myDateTime.toString("dd.MM.yyyy hh:mm:ss ") + QString("] ");
|
||||||
line += QString("<") + QString(c.second.getAddress()) + QString("> :");
|
line += QString("<") + QString(c.second.getAddress()) + QString("> :\n");
|
||||||
line += QString(c.second.getMemo());
|
line += QString(c.second.getMemo());
|
||||||
view->addItem(line);
|
view->addItem(line);
|
||||||
line ="";
|
line ="";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::setupchatTab() {
|
||||||
|
|
||||||
|
// Send button
|
||||||
|
QObject::connect(ui->sendChatButton, &QPushButton::clicked, this, &MainWindow::sendChatButton);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatMemoEdit::ChatMemoEdit(QWidget* parent) : QPlainTextEdit(parent) {
|
||||||
|
QObject::connect(this, &QPlainTextEdit::textChanged, this, &ChatMemoEdit::updateDisplay);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChatMemoEdit::updateDisplay() {
|
||||||
|
QString txt = this->toPlainText();
|
||||||
|
if (lenDisplayLabel)
|
||||||
|
lenDisplayLabel->setText(QString::number(txt.toUtf8().size()) + "/" + QString::number(maxlen));
|
||||||
|
|
||||||
|
if (txt.toUtf8().size() <= maxlen) {
|
||||||
|
// Everything is fine
|
||||||
|
if (sendChatButton)
|
||||||
|
sendChatButton->setEnabled(true);
|
||||||
|
|
||||||
|
if (lenDisplayLabel)
|
||||||
|
lenDisplayLabel->setStyleSheet("");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Overweight
|
||||||
|
if (sendChatButton)
|
||||||
|
sendChatButton->setEnabled(false);
|
||||||
|
|
||||||
|
if (lenDisplayLabel)
|
||||||
|
lenDisplayLabel->setStyleSheet("color: red;");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChatMemoEdit::setMaxLen(int len) {
|
||||||
|
this->maxlen = len;
|
||||||
|
updateDisplay();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChatMemoEdit::setLenDisplayLabel(QLabel* label) {
|
||||||
|
this->lenDisplayLabel = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChatMemoEdit::setSendChatButton(QPushButton* button) {
|
||||||
|
this->sendChatButton = button;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a Tx from the current state of the Chat page.
|
||||||
|
Tx MainWindow::createTxFromChatPage() {
|
||||||
|
Tx tx;
|
||||||
|
CAmount totalAmt;
|
||||||
|
// For each addr/amt in the Chat tab
|
||||||
|
{
|
||||||
|
QString addr = ""; // 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;
|
||||||
|
|
||||||
|
|
||||||
|
amt = CAmount::fromDecimalString("0.00001");
|
||||||
|
totalAmt = totalAmt + amt;
|
||||||
|
|
||||||
|
|
||||||
|
QString memo = ui->memoTxtChat->toPlainText().trimmed();
|
||||||
|
//ui->chatmemoSize->setLenDisplayLabel()
|
||||||
|
|
||||||
|
|
||||||
|
tx.toAddrs.push_back(ToFields{addr, amt, memo,}) ;
|
||||||
|
|
||||||
|
qDebug() << "pushback chattx";
|
||||||
|
}
|
||||||
|
|
||||||
|
tx.fee = Settings::getMinerFee();
|
||||||
|
|
||||||
|
return tx;
|
||||||
|
|
||||||
|
qDebug() << "ChatTx created";
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::sendChatButton() {
|
||||||
|
// Create a Tx from the values on the send tab. Note that this Tx object
|
||||||
|
// might not be valid yet.
|
||||||
|
|
||||||
|
// Memos can only be used with zAddrs. So check that first
|
||||||
|
//auto addr = "zs1fllv4hgrjddnz2yz5dng9kchcg3wkhs0j2v5v3nc89w3r3kntkgq2sefcz2a9k2ycc8f6t0gm2q";
|
||||||
|
// 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();
|
||||||
|
|
||||||
|
QString error = doSendChatTxValidations(tx);
|
||||||
|
|
||||||
|
if (!error.isEmpty()) {
|
||||||
|
// Something went wrong, so show an error and exit
|
||||||
|
QMessageBox msg(QMessageBox::Critical, tr("Message Error"), error,
|
||||||
|
QMessageBox::Ok, this);
|
||||||
|
|
||||||
|
msg.exec();
|
||||||
|
|
||||||
|
// abort the Tx
|
||||||
|
return;
|
||||||
|
qDebug() << "Tx aborted";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new Dialog to show that we are computing/sending the Tx
|
||||||
|
auto d = new QDialog(this);
|
||||||
|
auto connD = new Ui_ConnectionDialog();
|
||||||
|
connD->setupUi(d);
|
||||||
|
QPixmap logo(":/img/res/logobig.gif");
|
||||||
|
connD->topIcon->setBasePixmap(logo.scaled(256, 256, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||||
|
|
||||||
|
connD->status->setText(tr("Please wait..."));
|
||||||
|
connD->statusDetail->setText(tr("Your Message will be send"));
|
||||||
|
|
||||||
|
d->show();
|
||||||
|
|
||||||
|
// And send the Tx
|
||||||
|
rpc->executeTransaction(tx,
|
||||||
|
[=] (QString txid) {
|
||||||
|
ui->statusBar->showMessage(Settings::txidStatusMessage + " " + txid);
|
||||||
|
|
||||||
|
connD->status->setText(tr("Done!"));
|
||||||
|
connD->statusDetail->setText(txid);
|
||||||
|
|
||||||
|
QTimer::singleShot(1000, [=]() {
|
||||||
|
d->accept();
|
||||||
|
d->close();
|
||||||
|
delete connD;
|
||||||
|
delete d;
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// Force a UI update so we get the unconfirmed Tx
|
||||||
|
rpc->refresh(true);
|
||||||
|
|
||||||
|
},
|
||||||
|
// Errored out
|
||||||
|
[=] (QString opid, QString errStr) {
|
||||||
|
ui->statusBar->showMessage(QObject::tr(" Tx ") % opid % QObject::tr(" failed"), 15 * 1000);
|
||||||
|
|
||||||
|
d->accept();
|
||||||
|
d->close();
|
||||||
|
delete connD;
|
||||||
|
delete d;
|
||||||
|
|
||||||
|
if (!opid.isEmpty())
|
||||||
|
errStr = QObject::tr("The transaction with id ") % opid % QObject::tr(" failed. The error was") + ":\n\n" + errStr;
|
||||||
|
|
||||||
|
QMessageBox::critical(this, QObject::tr("Transaction Error"), errStr, QMessageBox::Ok);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString MainWindow::doSendChatTxValidations(Tx tx) {
|
||||||
|
// Check to see if we have enough verified funds to send the Tx.
|
||||||
|
|
||||||
|
CAmount total;
|
||||||
|
for (auto toAddr : tx.toAddrs) {
|
||||||
|
if (!Settings::isValidAddress(toAddr.addr)) {
|
||||||
|
QString addr = (toAddr.addr.length() > 100 ? toAddr.addr.left(100) + "..." : toAddr.addr);
|
||||||
|
return QString(tr("Recipient Address ")) % addr % tr(" is Invalid");
|
||||||
|
}
|
||||||
|
|
||||||
|
// This technically shouldn't be possible, but issue #62 seems to have discovered a bug
|
||||||
|
// somewhere, so just add a check to make sure.
|
||||||
|
if (toAddr.amount.toqint64() < 0) {
|
||||||
|
return QString(tr("Amount for address '%1' is invalid!").arg(toAddr.addr));
|
||||||
|
}
|
||||||
|
|
||||||
|
total = total + toAddr.amount;
|
||||||
|
}
|
||||||
|
total = total + tx.fee;
|
||||||
|
|
||||||
|
auto available = rpc->getModel()->getAvailableBalance();
|
||||||
|
|
||||||
|
if (available < total) {
|
||||||
|
return tr("Not enough available funds to send this transaction\n\nHave: %1\nNeed: %2\n\nNote: Funds need 5 confirmations before they can be spent")
|
||||||
|
.arg(available.toDecimalhushString(), total.toDecimalhushString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
@@ -116,4 +116,22 @@ class ChatModel
|
|||||||
void addMessage(ChatItem item);
|
void addMessage(ChatItem item);
|
||||||
void addMessage(long timestamp, ChatItem item);
|
void addMessage(long timestamp, ChatItem item);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ChatMemoEdit : public QPlainTextEdit
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ChatMemoEdit(QWidget* parent);
|
||||||
|
|
||||||
|
void setMaxLen(int len);
|
||||||
|
void setLenDisplayLabel(QLabel* label);
|
||||||
|
void setSendChatButton(QPushButton* button);
|
||||||
|
void includeReplyTo(QString replyToAddress);
|
||||||
|
void updateDisplay();
|
||||||
|
|
||||||
|
private:
|
||||||
|
int maxlen = 512;
|
||||||
|
QLabel* lenDisplayLabel = nullptr;
|
||||||
|
QPushButton* sendChatButton = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -152,6 +152,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
setupReceiveTab();
|
setupReceiveTab();
|
||||||
setupBalancesTab();
|
setupBalancesTab();
|
||||||
setuphushdTab();
|
setuphushdTab();
|
||||||
|
setupchatTab();
|
||||||
|
|
||||||
rpc = new Controller(this);
|
rpc = new Controller(this);
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ public:
|
|||||||
QRegExpValidator* getAmountValidator() { return amtValidator; }
|
QRegExpValidator* getAmountValidator() { return amtValidator; }
|
||||||
|
|
||||||
QString doSendTxValidations(Tx tx);
|
QString doSendTxValidations(Tx tx);
|
||||||
|
QString doSendChatTxValidations(Tx tx);
|
||||||
|
|
||||||
void replaceWormholeClient(WormholeClient* newClient);
|
void replaceWormholeClient(WormholeClient* newClient);
|
||||||
bool isWebsocketListening();
|
bool isWebsocketListening();
|
||||||
@@ -85,10 +86,11 @@ private:
|
|||||||
|
|
||||||
void setupSendTab();
|
void setupSendTab();
|
||||||
void setupTransactionsTab();
|
void setupTransactionsTab();
|
||||||
void updateChat();
|
|
||||||
void setupReceiveTab();
|
void setupReceiveTab();
|
||||||
void setupBalancesTab();
|
void setupBalancesTab();
|
||||||
void setuphushdTab();
|
void setuphushdTab();
|
||||||
|
void setupchatTab();
|
||||||
|
void updateChat();
|
||||||
|
|
||||||
void setupSettingsModal();
|
void setupSettingsModal();
|
||||||
void setupStatusBar();
|
void setupStatusBar();
|
||||||
@@ -98,11 +100,14 @@ private:
|
|||||||
Tx createTxFromSendPage();
|
Tx createTxFromSendPage();
|
||||||
bool confirmTx(Tx tx, RecurringPaymentInfo* rpi);
|
bool confirmTx(Tx tx, RecurringPaymentInfo* rpi);
|
||||||
|
|
||||||
|
Tx createTxFromChatPage();
|
||||||
|
|
||||||
void encryptWallet();
|
void encryptWallet();
|
||||||
void removeWalletEncryption();
|
void removeWalletEncryption();
|
||||||
|
|
||||||
void cancelButton();
|
void cancelButton();
|
||||||
void sendButton();
|
void sendButton();
|
||||||
|
void sendChatButton();
|
||||||
void addAddressSection();
|
void addAddressSection();
|
||||||
void maxAmountChecked(int checked);
|
void maxAmountChecked(int checked);
|
||||||
|
|
||||||
|
|||||||
@@ -1367,9 +1367,9 @@
|
|||||||
<widget class="MemoEdit" name="memoTxtChat">
|
<widget class="MemoEdit" name="memoTxtChat">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>357</x>
|
<x>347</x>
|
||||||
<y>483</y>
|
<y>483</y>
|
||||||
<width>891</width>
|
<width>901</width>
|
||||||
<height>128</height>
|
<height>128</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@@ -1387,22 +1387,6 @@
|
|||||||
<string>Include Reply Address</string>
|
<string>Include Reply Address</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QDialogButtonBox" name="buttonBox">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>692</x>
|
|
||||||
<y>618</y>
|
|
||||||
<width>189</width>
|
|
||||||
<height>25</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="standardButtons">
|
|
||||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
<widget class="QLabel" name="memoSizeChat">
|
<widget class="QLabel" name="memoSizeChat">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
@@ -1442,6 +1426,28 @@
|
|||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QPushButton" name="sendChatButton">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>1130</x>
|
||||||
|
<y>620</y>
|
||||||
|
<width>114</width>
|
||||||
|
<height>25</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="baseSize">
|
||||||
|
<size>
|
||||||
|
<width>100</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Send</string>
|
||||||
|
</property>
|
||||||
|
<property name="flat">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
Reference in New Issue
Block a user