Browse Source

Merge pull request #26 from DenioD/chat

Chat
pull/130/head
Strider 4 years ago
committed by GitHub
parent
commit
cbbc19f47f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      application.qrc
  2. 53
      src/Chat/Chat.cpp
  3. 2
      src/Chat/Chat.h
  4. 2
      src/Chat/Helper/ChatDelegator.h
  5. 1
      src/DataStore/ChatDataStore.cpp
  6. 4
      src/Model/ChatItem.cpp
  7. 28
      src/Model/ContactRequest.cpp
  8. 8
      src/Model/ContactRequest.h
  9. 19
      src/addressbook.cpp
  10. 139
      src/chatmodel.cpp
  11. 183
      src/contactrequest.ui
  12. 6
      src/controller.cpp
  13. 2
      src/controller.h
  14. 39
      src/mainwindow.cpp
  15. 19
      src/mainwindow.h
  16. 296
      src/mainwindow.ui
  17. 143
      src/requestContactDialog.ui

5
application.qrc

@ -38,9 +38,8 @@
<file>res/message-icon.svg</file>
<file>res/lock.svg</file>
<file>res/lock.png</file>
<file>res/lock_green.svg</file>
<file>res/lock_blue.svg</file>
<file>res/unlocked.svg</file>
<file>res/lock_green.png</file>
<file>res/unlocked.png</file>
<file>res/getAddrWhite.png</file>
<file>res/send-white.png</file>
<file>res/requestWhite.png</file>

53
src/Chat/Chat.cpp

@ -6,12 +6,50 @@
#include "../DataStore/DataStore.h"
Chat::Chat() {}
void Chat::renderChatBox(Ui::MainWindow *ui, QListView *view)
ChatMemoEdit::ChatMemoEdit(QWidget* parent) : QTextEdit(parent) {
QObject::connect(this, &QTextEdit::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::SetSendChatButton(QPushButton* button) {
this->sendChatButton = button;
}
void ChatMemoEdit::setLenDisplayLabel(QLabel* label) {
this->lenDisplayLabel = label;
}
void Chat::renderChatBox(Ui::MainWindow *ui, QListView *view, QLabel *label)
{
QStandardItemModel *chat = new QStandardItemModel();
// ui->lcdNumber->setStyleSheet("background-color: red");
// ui->lcdNumber->setPalette(Qt::red);
// ui->lcdNumber->display("1");
DataStore::getChatDataStore()->dump(); // test to see if the chat items in datastore are correctly dumped to json
for (auto &p : AddressBook::getInstance()->getAllAddressLabels())
{
@ -22,7 +60,7 @@ void Chat::renderChatBox(Ui::MainWindow *ui, QListView *view)
if (
(p.getName() == ui->contactNameMemo->text().trimmed()) &&
(p.getPartnerAddress() == c.second.getAddress()) &&
(c.second.isOutgoing() == true))
(c.second.isOutgoing() == true))
{
QStandardItem *Items = new QStandardItem(c.second.toChatLine());
@ -40,8 +78,9 @@ void Chat::renderChatBox(Ui::MainWindow *ui, QListView *view)
if (
(p.getName() == ui->contactNameMemo->text().trimmed()) &&
(p.getMyAddress() == c.second.getAddress()) &&
(c.second.isOutgoing() == false))
(c.second.isOutgoing() == false) &&
(c.second.getCid() == p.getCid())
)
{
QStandardItem *Items1 = new QStandardItem(c.second.toChatLine());
Items1->setData(INCOMING, Qt::UserRole + 1);

2
src/Chat/Chat.h

@ -28,7 +28,7 @@ class Chat // Chat Controller
public:
Chat();
//QString zaddr();
void renderChatBox(Ui::MainWindow* ui, QListView *view); // action
void renderChatBox(Ui::MainWindow* ui, QListView *view, QLabel *label); // action
// void renderContactRequest();
/*void triggerRequest();
void showMessages();

2
src/Chat/Helper/ChatDelegator.h

@ -37,7 +37,7 @@ class ListViewDelegate : public QAbstractItemDelegate
inline QSize sizeHint(QStyleOptionViewItem const &option, QModelIndex const &index) const;
};
inline ListViewDelegate::ListViewDelegate(QObject *parent): QAbstractItemDelegate(parent), d_radius(5), d_toppadding(5), d_bottompadding(3), d_leftpadding(5), d_rightpadding(5), d_verticalmargin(5), d_horizontalmargin(10), d_pointerwidth(10), d_pointerheight(17), d_widthfraction(.6)
inline ListViewDelegate::ListViewDelegate(QObject *parent): QAbstractItemDelegate(parent), d_radius(5), d_toppadding(5), d_bottompadding(3), d_leftpadding(5), d_rightpadding(7), d_verticalmargin(5), d_horizontalmargin(10), d_pointerwidth(10), d_pointerheight(17), d_widthfraction(.7)
{
}

1
src/DataStore/ChatDataStore.cpp

@ -96,6 +96,7 @@ std::map<QString, ChatItem> ChatDataStore::getAllMemos()
(c.second.getMemo().startsWith("{") == false) &&
(c.second.getMemo().isEmpty() == false)
)
{

4
src/Model/ChatItem.cpp

@ -137,10 +137,10 @@ QString ChatItem::toChatLine()
myDateTime.setTime_t(_timestamp);
if (_confirmations == 0){
lock = "<b> <img src=':/icons/res/unlocked.svg'><b>";
lock = "<b> <img src=':/icons/res/unlocked.png'><b>";
}else{
lock = "<b> <img src=':/icons/res/lock_green.svg'><b>";
lock = "<b> <img src=':/icons/res/lock_green.png'><b>";
}

28
src/Model/ContactRequest.cpp

@ -5,12 +5,14 @@
ContactRequest::ContactRequest() {}
ContactRequest::ContactRequest(QString sender, QString receiver, QString memo, QString cid)
ContactRequest::ContactRequest(QString sender, QString receiver, QString memo, QString cid, QString label, QString avatar)
{
_senderAddress = sender;
_receiverAddress = receiver;
_memo = memo;
_cid = cid;
_label = label;
_avatar = avatar;
}
QString ContactRequest::getSenderAddress()
@ -33,6 +35,16 @@ QString ContactRequest::getCid()
return _cid;
}
QString ContactRequest::getLabel()
{
return _label;
}
QString ContactRequest::getAvatar()
{
return _avatar;
}
void ContactRequest::setSenderAddress(QString address)
{
_senderAddress = address;
@ -53,9 +65,19 @@ void ContactRequest::setCid(QString cid)
_cid = cid;
}
void ContactRequest::setLabel(QString label)
{
_label = label;
}
void ContactRequest::setAvatar(QString avatar)
{
_avatar = avatar;
}
QString ContactRequest::toString()
{
return "sender: " + _senderAddress + " receiver: " + _receiverAddress + " memo: " + _memo + " cid: " + _cid;
return "sender: " + _senderAddress + " receiver: " + _receiverAddress + " memo: " + _memo + " cid: " + _cid + " label: " + _label + " avatar: " + _avatar;
}
ContactRequest::~ContactRequest()
@ -64,4 +86,6 @@ ContactRequest::~ContactRequest()
_receiverAddress = "";
_memo = "";
_cid = "";
_label = "";
_avatar = "";
}

8
src/Model/ContactRequest.h

@ -14,18 +14,24 @@ class ContactRequest
QString _receiverAddress;
QString _memo;
QString _cid;
QString _label;
QString _avatar;
public:
ContactRequest();
ContactRequest(QString sender, QString receiver, QString memo, QString cid);
ContactRequest(QString sender, QString receiver, QString memo, QString cid, QString label, QString avatar);
QString getSenderAddress();
QString getReceiverAddress();
QString getMemo();
QString getCid();
QString getLabel();
QString getAvatar();
void setSenderAddress(QString address);
void setReceiverAddress(QString contact);
void setMemo(QString memo);
void setCid(QString cid);
void setLabel(QString label);
void setAvatar(QString avatar);
QString toString();
~ContactRequest();
};

19
src/addressbook.cpp

@ -144,22 +144,35 @@ void AddressBook::open(MainWindow* parent, QLineEdit* target)
// Connect the dialog's closing to updating the label address completor
QObject::connect(&d, &QDialog::finished, [=] (auto) { parent->updateLabels(); });
Controller* rpc = parent->getRPC();
bool sapling = true;
try
{
rpc->createNewZaddr(sapling, [=] (json reply) {
QString myAddr = QString::fromStdString(reply.get<json::array_t>()[0]);
QString message = QString("New Chat Address for your partner: ") + myAddr;
QString cid = QUuid::createUuid().toString(QUuid::WithoutBraces);
rpc->refreshAddresses();
parent->ui->listReceiveAddresses->insertItem(0, myAddr);
parent->ui->listReceiveAddresses->setCurrentIndex(0);
qDebug() << "new generated myAddr" << myAddr;
qDebug() << " new Addr in Addressbook" << myAddr;
ab.cid->setText(cid);
ab.addr_chat->setText(myAddr);
});
model.updateUi(); //todo fix updating gui after adding
//rpc->refresh(true);
}
catch(...)
{
qDebug() << QString("Caught something nasty with myZaddr Addressbook");
}
// model.updateUi(); //todo fix updating gui after adding
// If there is a target then make it the addr for the "Add to" button
if (target != nullptr && Settings::isValidAddress(target->text()))

139
src/chatmodel.cpp

@ -125,9 +125,9 @@ void MainWindow::renderContactRequest(){
requestContact.requestMemo->setModel(contactMemo);
requestContact.requestMemo->show();
requestContact.requestZaddr->setText(c.second.getRequestZaddr());
requestContact.requestCID->setText(c.second.getCid());
requestContact.requestCID->setVisible(false);
requestContact.requestZaddr->setText(c.second.getRequestZaddr());
requestContact.requestMyAddr->setText(c.second.getAddress());
}else{}
}
@ -152,9 +152,9 @@ void MainWindow::renderContactRequest(){
requestContact.requestMemo->setModel(contactMemo);
requestContact.requestMemo->show();
requestContact.requestZaddr->setText(c.second.getRequestZaddr());
requestContact.requestCID->setText(c.second.getCid());
requestContact.requestCID->setVisible(false);
requestContact.requestZaddr->setText(c.second.getRequestZaddr());
requestContact.requestMyAddr->setText(c.second.getAddress());
}else{}
}
@ -310,7 +310,7 @@ Tx MainWindow::createTxFromChatPage() {
QString memo = ui->memoTxtChat->toPlainText().trimmed();
// ui->memoSizeChat->setLenDisplayLabel();// Todo -> activate lendisplay for chat
tx.toAddrs.push_back(ToFields{addr, amt, hmemo});
tx.toAddrs.push_back(ToFields{addr, amt, memo});
@ -328,7 +328,7 @@ Tx MainWindow::createTxFromChatPage() {
qDebug() << "ChatTx created";
}
void MainWindow::sendChatButton() {
void MainWindow::sendChat() {
////////////////////////////Todo: Check if a Contact is selected//////////
@ -463,29 +463,59 @@ void::MainWindow::addContact()
QDialog dialog(this);
request.setupUi(&dialog);
Settings::saveRestore(&dialog);
bool sapling = true;
rpc->createNewZaddr(sapling, [=] (json reply) {
QString myAddr = QString::fromStdString(reply.get<json::array_t>()[0]);
rpc->refreshAddresses();
request.myzaddr->setText(myAddr);
ui->listReceiveAddresses->insertItem(0, myAddr);
ui->listReceiveAddresses->setCurrentIndex(0);
qDebug() << "new generated myAddr" << myAddr;
qDebug() << "new generated myAddr add Contact" << myAddr;
});
QString cid = QUuid::createUuid().toString(QUuid::WithoutBraces);
QString cid = QUuid::createUuid().toString(QUuid::WithoutBraces);
request.cid->setText(cid);
QObject::connect(request.sendRequestButton, &QPushButton::clicked, [&] () {
QString cid = request.cid->text();
QString addr = request.zaddr->text().trimmed();
QString getrequest = addr;
QString newLabel = request.labelRequest->text().trimmed();
QString addr = request.zaddr->text();
QString myAddr = request.myzaddr->text().trimmed();
QString memo = request.memorequest->text().trimmed();
QString avatar = QString(":/icons/res/") + request.comboBoxAvatar->currentText() + QString(".png");
QString label = request.labelRequest->text().trimmed();
contactRequest.setSenderAddress(myAddr);
contactRequest.setReceiverAddress(addr);
contactRequest.setMemo(newLabel);
contactRequest.setMemo(memo);
contactRequest.setCid(cid);
QString avatar = QString(":/icons/res/") + request.comboBoxAvatar->currentText() + QString(".png");
contactRequest.setAvatar(avatar);
contactRequest.setLabel(label);
});
QObject::connect(request.sendRequestButton, &QPushButton::clicked, this, &MainWindow::saveandsendContact);
QObject::connect(request.onlyAdd, &QPushButton::clicked, this, &MainWindow::saveContact);
dialog.exec();
rpc->refreshContacts(ui->listContactWidget);
}
void MainWindow::saveandsendContact()
{
this->ContactRequest();
QString addr = contactRequest.getReceiverAddress();
QString newLabel = contactRequest.getLabel();
QString myAddr = contactRequest.getSenderAddress();
QString cid = contactRequest.getCid();
QString avatar = contactRequest.getAvatar();
if (addr.isEmpty() || newLabel.isEmpty())
{
QMessageBox::critical(
@ -520,42 +550,83 @@ void::MainWindow::addContact()
QMessageBox::Ok
);
return;
});
dialog.exec();
rpc->refreshContacts(ui->listContactWidget);
}
void MainWindow::saveContact()
{
QString addr = contactRequest.getReceiverAddress();
QString newLabel = contactRequest.getLabel();
QString myAddr = contactRequest.getSenderAddress();
QString cid = contactRequest.getCid();
QString avatar = contactRequest.getAvatar();
if (addr.isEmpty() || newLabel.isEmpty())
{
QMessageBox::critical(
this,
QObject::tr("Address or Label Error"),
QObject::tr("Address or Label cannot be empty"),
QMessageBox::Ok
);
return;
}
// Test if address is valid.
if (!Settings::isValidAddress(addr))
{
QMessageBox::critical(
this,
QObject::tr("Address Format Error"),
QObject::tr("%1 doesn't seem to be a valid hush address.").arg(addr),
QMessageBox::Ok
);
return;
}
///////Todo: Test if label allready exist!
////// Success, so show it
AddressBook::getInstance()->addAddressLabel(newLabel, addr, myAddr, cid, avatar);
QMessageBox::information(
this,
QObject::tr("Added Contact"),
QObject::tr("successfully added your new contact").arg(newLabel),
QMessageBox::Ok
);
return;
}
// Create a Tx for a contact Request
Tx MainWindow::createTxForSafeContactRequest()
{
Tx tx;
{
CAmount totalAmt;
QString amtStr = "0";
CAmount amt;
amt = CAmount::fromDecimalString("0");
totalAmt = totalAmt + amt;
for(auto &c : AddressBook::getInstance()->getAllAddressLabels())
{
if (ui->contactNameMemo->text().trimmed() == c.getName())
{
QString cid = c.getCid();
QString myAddr = c.getMyAddress();
QString cid = contactRequest.getCid();
QString myAddr = contactRequest.getSenderAddress();
QString type = "Cont";
QString addr = c.getPartnerAddress();
qDebug() << contactRequest.toString();
QString addr = contactRequest.getReceiverAddress();
QString hmemo= createHeaderMemo(type,cid,myAddr);
QString memo = ui->memoTxtChat->toPlainText().trimmed();
// ui->memoSizeChat->setLenDisplayLabel();// Todo -> activate lendisplay for chat
QString memo = contactRequest.getMemo();
tx.toAddrs.push_back(ToFields{addr, amt, hmemo});
tx.toAddrs.push_back(ToFields{addr, amt, memo});
qDebug() << "pushback chattx";
tx.fee = Settings::getMinerFee();
}
}
}
return tx;
qDebug() << "RequestTx created";
@ -563,7 +634,7 @@ Tx MainWindow::createTxForSafeContactRequest()
void MainWindow::ContactRequest() {
/* if (request.labelRequest->text().trimmed().isEmpty() || request.memorequest->toPlainText().trimmed().isEmpty()) {
if (contactRequest.getReceiverAddress().isEmpty() || contactRequest.getMemo().isEmpty()) {
// auto addr = "";
// if (! Settings::isZAddress(AddressBook::addressFromAddressLabel(addr->text()))) {
@ -573,7 +644,7 @@ void MainWindow::ContactRequest() {
msg.exec();
return;
}*/
}
Tx tx = createTxForSafeContactRequest();

183
src/contactrequest.ui

@ -10,25 +10,31 @@
<height>427</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>780</width>
<height>427</height>
</size>
</property>
<property name="windowTitle">
<string>Send a contact request</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="2">
<item row="0" column="2" colspan="2">
<widget class="QLabel" name="label_6">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;right&quot;&gt;Choose a avatar for your contact :&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;right&quot;&gt;&lt;span style=&quot; font-weight:600; text-decoration: underline;&quot;&gt;Choose a avatar for your contact :&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="1" column="0">
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="label_3">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Please insert a Nickname for your contact :&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600; text-decoration: underline;&quot;&gt;Please insert a Nickname for your contact :&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="1" column="2">
<item row="1" column="4">
<widget class="QComboBox" name="comboBoxAvatar">
<item>
<property name="text">
@ -162,45 +168,126 @@
</item>
</widget>
</item>
<item row="2" column="0">
<item row="2" column="0" colspan="2">
<widget class="QLineEdit" name="labelRequest"/>
</item>
<item row="3" column="0">
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Please insert the Address of your contact :&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600; text-decoration: underline;&quot;&gt;Please insert the Address of your contact :&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLineEdit" name="zaddr"/>
<item row="4" column="0" colspan="4">
<widget class="QLineEdit" name="zaddr">
<property name="minimumSize">
<size>
<width>650</width>
<height>25</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>650</width>
<height>25</height>
</size>
</property>
</widget>
</item>
<item row="5" column="0">
<item row="5" column="0" colspan="2">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Your HushChat Address</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600; text-decoration: underline;&quot;&gt;Your HushChat Address :&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLineEdit" name="myzaddr"/>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_5">
<item row="6" column="0" colspan="4">
<widget class="QLabel" name="myzaddr">
<property name="minimumSize">
<size>
<width>650</width>
<height>25</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>650</width>
<height>25</height>
</size>
</property>
<property name="text">
<string>The Conversation ID </string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; color:#d3d7cf;&quot;&gt;Generate your HushChat Address - please wait a second - &lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="cid">
<item row="7" column="0" rowspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>148</height>
</size>
</property>
</spacer>
</item>
<item row="7" column="1" colspan="3">
<widget class="QLabel" name="label_2">
<property name="text">
<string/>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-weight:600; text-decoration: underline;&quot;&gt;Insert a memo for your request&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="9" column="1">
<item row="8" column="1" colspan="3">
<widget class="QLineEdit" name="memorequest">
<property name="minimumSize">
<size>
<width>500</width>
<height>71</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>500</width>
<height>71</height>
</size>
</property>
<property name="contextMenuPolicy">
<enum>Qt::NoContextMenu</enum>
</property>
<property name="acceptDrops">
<bool>false</bool>
</property>
<property name="inputMethodHints">
<set>Qt::ImhSensitiveData</set>
</property>
<property name="maxLength">
<number>512</number>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="dragEnabled">
<bool>false</bool>
</property>
<property name="placeholderText">
<string>Add some memo to your request</string>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QPushButton" name="cancel">
<property name="maximumSize">
<size>
<width>80</width>
<height>25</height>
</size>
</property>
<property name="baseSize">
<size>
<width>100</width>
@ -210,13 +297,60 @@
<property name="text">
<string>Cancel</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item row="9" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>278</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="9" column="2">
<widget class="QPushButton" name="onlyAdd">
<property name="maximumSize">
<size>
<width>152</width>
<height>25</height>
</size>
</property>
<property name="baseSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Only add this contact</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item row="9" column="3" colspan="2">
<widget class="QPushButton" name="sendRequestButton">
<property name="maximumSize">
<size>
<width>188</width>
<height>25</height>
</size>
</property>
<property name="baseSize">
<size>
<width>100</width>
@ -224,7 +358,10 @@
</size>
</property>
<property name="text">
<string>Add Contact</string>
<string>Add Contact &amp; send request</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="flat">
<bool>false</bool>

6
src/controller.cpp

@ -1009,7 +1009,7 @@ void Controller::refreshTransactions() {
// Update model data, which updates the table view
transactionsTableModel->replaceData(txdata);
chat->renderChatBox(ui, ui->listChat);
chat->renderChatBox(ui, ui->listChat,ui->memoSizeChat);
// refreshContacts(
// ui->listContactWidget
@ -1017,9 +1017,9 @@ void Controller::refreshTransactions() {
});
}
void Controller::refreshChat(QListView *listWidget)
void Controller::refreshChat(QListView *listWidget, QLabel *label)
{
chat->renderChatBox(ui, listWidget);
chat->renderChatBox(ui, listWidget, label);
}

2
src/controller.h

@ -74,7 +74,7 @@ public:
void refreshGBPCAP();
void refreshAUDCAP();
void refreshChat(QListView *listWidget);
void refreshChat(QListView *listWidget, QLabel *label);
void refreshContacts(QListView *listWidget);
void executeStandardUITransaction(Tx tx);

39
src/mainwindow.cpp

@ -50,6 +50,8 @@ MainWindow::MainWindow(QWidget *parent) :
ui->memoTxtChat->setAutoFillBackground(false);
ui->memoTxtChat->setPlaceholderText("Send Message");
ui->memoTxtChat->setTextColor(Qt::white);
// Status Bar
setupStatusBar();
@ -1053,7 +1055,7 @@ void MainWindow::setupchatTab() {
QObject::connect(ui->sendChatButton, &QPushButton::clicked, this, &MainWindow::sendChatButton);
QObject::connect(ui->sendChatButton, &QPushButton::clicked, this, &MainWindow::sendChat);
QObject::connect(ui->safeContactRequest, &QPushButton::clicked, this, &MainWindow::addContact);
QObject::connect(ui->pushContact, &QPushButton::clicked, this , &MainWindow::renderContactRequest);
@ -1078,45 +1080,16 @@ void MainWindow::setupchatTab() {
});
}
ChatMemoEdit::ChatMemoEdit(QWidget* parent) : QPlainTextEdit(parent) {
QObject::connect(this, &QPlainTextEdit::textChanged, this, &ChatMemoEdit::updateDisplay);
ui->memoTxtChat->setLenDisplayLabel(ui->memoSizeChat);
}
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 MainWindow::updateChat()
{
rpc->refreshChat(ui->listChat);
rpc->refreshChat(ui->listChat,ui->memoSizeChat);
rpc->refresh(true);
}

19
src/mainwindow.h

@ -56,6 +56,10 @@ public:
bool isWebsocketListening();
void createWebsocket(QString wormholecode);
void stopWebsocket();
void saveContact();
void saveandsendContact();
void setMaxLen(int len);
void updateDisplay();
void balancesReady();
@ -106,7 +110,7 @@ private:
void setuphushdTab();
void setupchatTab();
void renderContactRequest();
void setLenDisplayLabel(QLabel* label);
// void setLenDisplayLabel(QLabel* label);
void updateContacts();
void updateChat();
@ -128,9 +132,11 @@ private:
void cancelButton();
void sendButton();
void sendChatButton();
void sendChat();
void addContact();
void ContactRequest();
void addAddressSection();
void maxAmountChecked(int checked);
@ -169,6 +175,7 @@ private:
WSServer* wsserver = nullptr;
WormholeClient* wormhole = nullptr;
Controller* rpc = nullptr;
QCompleter* labelCompleter = nullptr;
@ -180,15 +187,14 @@ private:
QMovie* loadingMovie;
};
class ChatMemoEdit : public QPlainTextEdit
class ChatMemoEdit : public QTextEdit
{
public:
ChatMemoEdit(QWidget* parent);
void setMaxLen(int len);
void setSendChatButton(QPushButton* button);
void includeReplyTo(QString replyToAddress);
void setLenDisplayLabel(QLabel* label);
void SetSendChatButton(QPushButton* button);
void updateDisplay();
private:
@ -197,4 +203,5 @@ private:
QPushButton* sendChatButton = nullptr;
};
#endif // MAINWINDOW_H

296
src/mainwindow.ui

@ -1400,7 +1400,7 @@
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-weight:600; text-decoration: underline;&quot;&gt;Contactlist&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QTextEdit" name="memoTxtChat">
<widget class="ChatMemoEdit" name="memoTxtChat">
<property name="geometry">
<rect>
<x>340</x>
@ -1506,16 +1506,16 @@
</rect>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
<enum>Qt::ScrollBarAsNeeded</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
<enum>Qt::ScrollBarAsNeeded</enum>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
<set>QAbstractItemView::AllEditTriggers</set>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
@ -1533,12 +1533,24 @@
<widget class="QPushButton" name="safeContactRequest">
<property name="geometry">
<rect>
<x>270</x>
<y>580</y>
<x>10</x>
<y>20</y>
<width>51</width>
<height>51</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>51</width>
<height>51</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>51</width>
<height>51</height>
</size>
</property>
<property name="baseSize">
<size>
<width>100</width>
@ -1569,12 +1581,24 @@
<widget class="QPushButton" name="pushContact">
<property name="geometry">
<rect>
<x>50</x>
<x>80</x>
<y>20</y>
<width>61</width>
<width>51</width>
<height>51</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>51</width>
<height>51</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>51</width>
<height>51</height>
</size>
</property>
<property name="baseSize">
<size>
<width>100</width>
@ -1607,12 +1631,24 @@
<widget class="QPushButton" name="givemeZaddr">
<property name="geometry">
<rect>
<x>210</x>
<x>150</x>
<y>20</y>
<width>61</width>
<width>51</width>
<height>51</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>51</width>
<height>51</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>51</width>
<height>51</height>
</size>
</property>
<property name="toolTip">
<string>Get a new Address</string>
</property>
@ -1633,229 +1669,36 @@
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="label_40">
<widget class="QLabel" name="memoSizeChat">
<property name="geometry">
<rect>
<x>90</x>
<y>10</y>
<width>21</width>
<height>16</height>
<x>1140</x>
<y>640</y>
<width>91</width>
<height>17</height>
</rect>
</property>
<property name="palette">
<palette>
<active>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>204</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="Text">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>204</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="BrightText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>239</red>
<green>41</green>
<blue>41</blue>
</color>
</brush>
</colorrole>
<colorrole role="ButtonText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>204</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="LinkVisited">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>204</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="ToolTipText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>204</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="PlaceholderText">
<brush brushstyle="SolidPattern">
<color alpha="128">
<red>204</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>204</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="Text">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>204</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="BrightText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>239</red>
<green>41</green>
<blue>41</blue>
</color>
</brush>
</colorrole>
<colorrole role="ButtonText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>204</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="LinkVisited">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>204</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="ToolTipText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>204</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="PlaceholderText">
<brush brushstyle="SolidPattern">
<color alpha="128">
<red>204</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>190</red>
<green>190</green>
<blue>190</blue>
</color>
</brush>
</colorrole>
<colorrole role="Text">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>190</red>
<green>190</green>
<blue>190</blue>
</color>
</brush>
</colorrole>
<colorrole role="BrightText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>239</red>
<green>41</green>
<blue>41</blue>
</color>
</brush>
</colorrole>
<colorrole role="ButtonText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>190</red>
<green>190</green>
<blue>190</blue>
</color>
</brush>
</colorrole>
<colorrole role="LinkVisited">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>204</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="ToolTipText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>204</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="PlaceholderText">
<brush brushstyle="SolidPattern">
<color alpha="128">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="text">
<string>1</string>
<string notr="true">0 / 512</string>
</property>
<property name="textFormat">
<enum>Qt::AutoText</enum>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
<zorder>listContactWidget</zorder>
<zorder>label_39</zorder>
<zorder>contactNameMemo</zorder>
<zorder>contactNameMemo_3</zorder>
<zorder>safeContactRequest</zorder>
<zorder>pushContact</zorder>
<zorder>givemeZaddr</zorder>
<zorder>memoSizeChat</zorder>
<zorder>listChat</zorder>
<zorder>memoTxtChat</zorder>
<zorder>sendChatButton</zorder>
</widget>
</widget>
</item>
@ -2042,6 +1885,11 @@
<extends>QLabel</extends>
<header>fillediconlabel.h</header>
</customwidget>
<customwidget>
<class>ChatMemoEdit</class>
<extends>QTextEdit</extends>
<header>mainwindow.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>Address1</tabstop>

143
src/requestContactDialog.ui

@ -6,10 +6,16 @@
<rect>
<x>0</x>
<y>0</y>
<width>1025</width>
<height>562</height>
<width>812</width>
<height>495</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>812</width>
<height>495</height>
</size>
</property>
<property name="windowTitle">
<string>Incoming contact request</string>
</property>
@ -21,7 +27,7 @@
</property>
</widget>
</item>
<item row="0" column="1" colspan="4">
<item row="0" column="3" colspan="2">
<widget class="QLabel" name="label_3">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-weight:600; text-decoration: underline;&quot;&gt;Memo of the request&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@ -30,6 +36,12 @@
</item>
<item row="1" column="0">
<widget class="QListView" name="requestContact">
<property name="minimumSize">
<size>
<width>256</width>
<height>231</height>
</size>
</property>
<property name="mouseTracking">
<bool>true</bool>
</property>
@ -44,8 +56,14 @@
</property>
</widget>
</item>
<item row="1" column="1" colspan="4">
<item row="1" column="1" colspan="6">
<widget class="QListView" name="requestMemo">
<property name="minimumSize">
<size>
<width>521</width>
<height>231</height>
</size>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
@ -79,15 +97,14 @@
</property>
</widget>
</item>
<item row="2" column="1" rowspan="2" colspan="4">
<widget class="QLabel" name="label_4">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-weight:600; text-decoration: underline;&quot;&gt;Details of the request&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="3" column="0" rowspan="7">
<item row="3" column="0" rowspan="6" colspan="2">
<widget class="QListView" name="requestContactOld">
<property name="minimumSize">
<size>
<width>256</width>
<height>192</height>
</size>
</property>
<property name="mouseTracking">
<bool>true</bool>
</property>
@ -102,55 +119,83 @@
</property>
</widget>
</item>
<item row="4" column="1">
<item row="3" column="2" colspan="2">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Request from :</string>
</property>
</widget>
</item>
<item row="4" column="2" colspan="3">
<widget class="QLineEdit" name="requestZaddr"/>
</item>
<item row="5" column="1">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Cid :</string>
<item row="3" column="4" colspan="3">
<widget class="QLineEdit" name="requestZaddr">
<property name="minimumSize">
<size>
<width>351</width>
<height>25</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>351</width>
<height>25</height>
</size>
</property>
</widget>
</item>
<item row="5" column="2" colspan="3">
<widget class="QLineEdit" name="requestCID"/>
</item>
<item row="6" column="1">
<item row="4" column="2">
<widget class="QLabel" name="label_7">
<property name="text">
<string>My Zaddr :</string>
</property>
</widget>
</item>
<item row="6" column="2" colspan="3">
<widget class="QLineEdit" name="requestMyAddr"/>
<item row="4" column="4" colspan="3">
<widget class="QLineEdit" name="requestMyAddr">
<property name="minimumSize">
<size>
<width>351</width>
<height>25</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>351</width>
<height>25</height>
</size>
</property>
</widget>
</item>
<item row="7" column="1">
<item row="5" column="2" colspan="2">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Nickname</string>
<string>Give a Nickname:</string>
</property>
</widget>
</item>
<item row="7" column="2" colspan="2">
<item row="5" column="4" colspan="2">
<widget class="QLineEdit" name="requestLabel"/>
</item>
<item row="8" column="1" colspan="2">
<item row="6" column="2" colspan="3">
<widget class="QLabel" name="label_6">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;right&quot;&gt;Choose a avatar for your contact :&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="8" column="3">
<item row="7" column="2" colspan="2">
<widget class="QComboBox" name="comboBoxAvatar">
<property name="minimumSize">
<size>
<width>106</width>
<height>25</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>106</width>
<height>25</height>
</size>
</property>
<item>
<property name="text">
<string>Stag</string>
@ -283,8 +328,14 @@
</item>
</widget>
</item>
<item row="9" column="3">
<item row="7" column="5" rowspan="2">
<widget class="QPushButton" name="cancel">
<property name="maximumSize">
<size>
<width>80</width>
<height>25</height>
</size>
</property>
<property name="baseSize">
<size>
<width>100</width>
@ -294,16 +345,42 @@
<property name="text">
<string>Cancel</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item row="9" column="4">
<item row="7" column="6" rowspan="2">
<widget class="QPushButton" name="pushButton">
<property name="maximumSize">
<size>
<width>153</width>
<height>25</height>
</size>
</property>
<property name="text">
<string>Add this new Contact</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item row="8" column="3" colspan="2">
<widget class="QLabel" name="requestCID">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="2" colspan="5">
<widget class="QLabel" name="label_4">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-weight:600; text-decoration: underline;&quot;&gt;Details of the request&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
</layout>

Loading…
Cancel
Save