|
|
@ -6,6 +6,8 @@ |
|
|
|
#include "ui_mainwindow.h" |
|
|
|
#include "addressbook.h" |
|
|
|
#include "ui_memodialog.h" |
|
|
|
#include "addressbook.h" |
|
|
|
#include <QUuid> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -93,51 +95,23 @@ void ChatModel::renderChatBox(QListWidget *view) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
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; |
|
|
|
QString MainWindow::createHeaderMemo(QString cid, QString zaddr, int version=0, int headerNumber=1) |
|
|
|
{ |
|
|
|
QString header=""; |
|
|
|
QJsonDocument j; |
|
|
|
QJsonObject h; |
|
|
|
// We use short keynames to use less space for metadata and so allow
|
|
|
|
// the user to send more actual data in memos
|
|
|
|
h["h"] = headerNumber; // header number
|
|
|
|
h["v"] = version; // HushChat version
|
|
|
|
h["z"] = zaddr; // zaddr to respond to
|
|
|
|
h["cid"] = cid; // conversation id
|
|
|
|
|
|
|
|
j.setObject(h); |
|
|
|
header = j.toJson(); |
|
|
|
qDebug() << "made header=" << header; |
|
|
|
|
|
|
|
return header; |
|
|
|
} |
|
|
|
|
|
|
|
// Create a Tx from the current state of the Chat page.
|
|
|
@ -158,13 +132,17 @@ Tx MainWindow::createTxFromChatPage() { |
|
|
|
|
|
|
|
amt = CAmount::fromDecimalString("0.00001"); |
|
|
|
totalAmt = totalAmt + amt; |
|
|
|
|
|
|
|
QString cid = QString::number( time(NULL) % std::rand() ); // low entropy for testing!
|
|
|
|
// QString cid = QUuid::createUuid().toString(QUuid::WithoutBraces); // Needs to get a fix
|
|
|
|
QString hmemo= createHeaderMemo(cid,"ZADDR"); |
|
|
|
|
|
|
|
QString memo = ui->memoTxtChat->toPlainText().trimmed(); |
|
|
|
//ui->chatmemoSize->setLenDisplayLabel()
|
|
|
|
// ui->memoSizeChat->setLenDisplayLabel();
|
|
|
|
|
|
|
|
|
|
|
|
tx.toAddrs.push_back(ToFields{addr, amt, memo,}) ; |
|
|
|
tx.toAddrs.push_back(ToFields{addr, amt, hmemo.toUtf8().toHex()}) ; |
|
|
|
qDebug()<<hmemo; |
|
|
|
tx.toAddrs.push_back( ToFields{addr, amt, memo.toUtf8().toHex()}); |
|
|
|
|
|
|
|
qDebug() << "pushback chattx"; |
|
|
|
} |
|
|
|