diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index 1561d4e..b799abd 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -6,6 +6,8 @@ #include "ui_mainwindow.h" #include "addressbook.h" #include "ui_memodialog.h" +#include "addressbook.h" +#include @@ -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()< #include #include +#include "precompiled.h" class ChatItem { @@ -117,21 +118,4 @@ class ChatModel 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 \ No newline at end of file diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index b243a6f..a6af0d0 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -983,6 +983,54 @@ void MainWindow::setupTransactionsTab() { }); } +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_40) { + this->lenDisplayLabel = label_40; +} + +void ChatMemoEdit::setSendChatButton(QPushButton* button) { + this->sendChatButton = button; +} + + void MainWindow::updateChat() { qDebug() << "Called MainWindow::updateChat()"; diff --git a/src/mainwindow.h b/src/mainwindow.h index 17194b4..6ce5fd5 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -76,6 +76,7 @@ public: Logger* logger; void doClose(); + QString createHeaderMemo(QString cid, QString zaddr, int version, int headerNumnber); public slots: void slot_change_theme(const QString& themeName); @@ -153,4 +154,21 @@ private: QMovie* loadingMovie; }; +class ChatMemoEdit : public QPlainTextEdit +{ +public: + ChatMemoEdit(QWidget* parent); + + void setMaxLen(int len); + void setLenDisplayLabel(QLabel* label_40); + void setSendChatButton(QPushButton* button); + void includeReplyTo(QString replyToAddress); + void updateDisplay(); + +private: + int maxlen = 512; + QLabel* lenDisplayLabel = nullptr; + QPushButton* sendChatButton = nullptr; +}; + #endif // MAINWINDOW_H diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 6d493af..f08d9be 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -1388,14 +1388,6 @@ - - - 1150 - 460 - 91 - 17 - - 0 / 512