Browse Source

activate contact request hm, for testing

pull/130/head
DenioD 4 years ago
parent
commit
bcbee161eb
  1. 111
      src/chatmodel.cpp
  2. 165
      src/contactrequest.ui
  3. 5
      src/mainwindow.cpp
  4. 3
      src/mainwindow.h

111
src/chatmodel.cpp

@ -377,12 +377,28 @@ QString MainWindow::doSendChatTxValidations(Tx tx) {
return "";
}
// Create a Contact Request.
// Create a Tx from the current state of the Chat page.
Tx MainWindow::createTxForSafeContactRequest() {
Tx tx;
CAmount totalAmt;
{
Ui_Dialog request;
QDialog dialog(this);
request.setupUi(&dialog);
Settings::saveRestore(&dialog);
dialog.exec();
Tx tx;
QObject::connect(request.cancel, &QPushButton::clicked, [&] () {
dialog.close();
});
QObject::connect(request.sendRequestButton, &QPushButton::clicked, this, &MainWindow::ContactRequest);
// For each addr/amt in the Chat tab
{
CAmount totalAmt;
QString amtStr = "0";
CAmount amt;
@ -392,48 +408,46 @@ Tx MainWindow::createTxForSafeContactRequest() {
for(auto &c : AddressBook::getInstance()->getAllAddressLabels())
if (request.zaddr->text().trimmed() != c.getPartnerAddress()) {
if (ui->contactNameMemo->text().trimmed() == c.getName()) {
// QString cid = c.getCid(); // This has to be a new cid for the contact
// QString myAddr = c.getMyAddress(); // this should be a new HushChat zaddr
// QString addr = c.getPartnerAddress(); // this address will be insert by the user
QString cid = c.getCid();
QString myAddr = c.getMyAddress();
QString addr = c.getPartnerAddress();
QString type = "cont";
QString hmemo= createHeaderMemo(type,cid,myAddr);
tx.toAddrs.push_back(ToFields{addr, amt, hmemo}) ;
QString cid = c.getCid();
QString myAddr = c.getMyAddress();
QString type = "cont";
QString addr = request.zaddr->text();
qDebug() << "pushback chattx";
}
}
QString hmemo= createHeaderMemo(type,cid,myAddr,0,0);
QString memo = request.requestmemo->toPlainText().trimmed();
tx.toAddrs.push_back(ToFields{addr, amt, hmemo});
tx.toAddrs.push_back(ToFields{addr, amt, memo});
tx.fee = Settings::getMinerFee();
qDebug() << "pushback chattx";
tx.fee = Settings::getMinerFee();
return tx;
qDebug() << "ChatTx created";
}
//////////////////De-activated for now///////////////////
void MainWindow::safeContactRequest() {
} if (request.zaddr->text().trimmed().isEmpty() == false){
QMessageBox msg(QMessageBox::Critical, tr("Please insert a contact Address"), request.zaddr->text(),
QMessageBox::Ok, this);
msg.exec();
}
}
}
void MainWindow::ContactRequest() {
// Ui_ContactRequest contactRequest;
// QDialog dialog(this);
// contactRequest.setupUi(&dialog);
// Settings::saveRestore(&dialog);
// memoDialog.memoTxt->setLenDisplayLabel(memoDialog.memoSize);
// memoDialog.memoTxt->setAcceptButton(memoDialog.buttonBox->button(QDialogButtonBox::Ok));
////////////////////////////Todo: Check if its a zaddr//////////
////////////////////////////Todo: Check if a Contact is selected//////////
// Create a Tx from the values on the send tab. Note that this Tx object
// might not be valid yet.
@ -441,21 +455,24 @@ void MainWindow::safeContactRequest() {
// Memos can only be used with zAddrs. So check that first
// for(auto &c : AddressBook::getInstance()->getAllAddressLabels())
// if (ui->ContactZaddr->text().trimmed() == c.getName()) {
// if (ui->contactNameMemo->text().trimmed().isEmpty() || ui->memoTxtChat->toPlainText().trimmed().isEmpty()) {
// auto addr = "";
// if (! Settings::isZAddress(AddressBook::addressFromAddressLabel(addr->text()))) {
// QMessageBox msg(QMessageBox::Critical, tr("Contact requests 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);
// QMessageBox msg(QMessageBox::Critical, tr("You have to select a contact and insert a Memo"),
// tr("You have selected no Contact from Contactlist,\n") + tr("\nor your Memo is empty"),
// QMessageBox::Ok, this);
// msg.exec();
// return;
// msg.exec();
// return;
// }
Tx tx = createTxForSafeContactRequest();
//};
Tx tx = createTxForSafeContactRequest();
QString error = doSendRequestTxValidations(tx);
QString error = doSendChatTxValidations(tx);
if (!error.isEmpty()) {
// Something went wrong, so show an error and exit
@ -469,7 +486,6 @@ void MainWindow::safeContactRequest() {
qDebug() << "Tx aborted";
}
// Create a new Dialog to show that we are computing/sending the Tx
// Create a new Dialog to show that we are computing/sending the Tx
auto d = new QDialog(this);
auto connD = new Ui_ConnectionDialog();
@ -488,9 +504,10 @@ void MainWindow::safeContactRequest() {
}
connD->status->setText(tr("Please wait..."));
connD->statusDetail->setText(tr("Your Contact Request will be send"));
connD->statusDetail->setText(tr("Your Message will be send"));
d->show();
ui->memoTxtChat->clear();
// And send the Tx
rpc->executeTransaction(tx,
@ -509,7 +526,8 @@ void MainWindow::safeContactRequest() {
});
// Force a UI update so we get the unconfirmed Tx
rpc->refresh(true);
// rpc->refresh(true);
ui->memoTxtChat->clear();
},
// Errored out
@ -527,7 +545,8 @@ void MainWindow::safeContactRequest() {
QMessageBox::critical(this, QObject::tr("Transaction Error"), errStr, QMessageBox::Ok);
}
);
}
}
QString MainWindow::doSendRequestTxValidations(Tx tx) {
@ -558,4 +577,4 @@ QString MainWindow::doSendRequestTxValidations(Tx tx) {
}
return "";
}
}

165
src/contactrequest.ui

@ -1,72 +1,165 @@
<ui version="4.0" >
<author></author>
<comment></comment>
<exportmacro></exportmacro>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog" >
<property name="geometry" >
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>780</width>
<height>416</height>
</rect>
</property>
<property name="windowTitle" >
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox" >
<property name="geometry" >
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>30</x>
<x>0</x>
<y>100</y>
<width>351</width>
<height>17</height>
</rect>
</property>
<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>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>10</x>
<y>190</y>
<width>461</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Insert a Message, and ask your friend for the contact request : &lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QTextEdit" name="requestmemo">
<property name="geometry">
<rect>
<x>0</x>
<y>240</y>
<width>341</width>
<height>32</height>
<width>591</width>
<height>101</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="zaddr">
<property name="geometry">
<rect>
<x>0</x>
<y>140</y>
<width>591</width>
<height>25</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="sendRequestButton">
<property name="geometry">
<rect>
<x>490</x>
<y>360</y>
<width>114</width>
<height>25</height>
</rect>
</property>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
<property name="baseSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="standardButtons" >
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<property name="text">
<string>Send</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
<widget class="QPushButton" name="cancel">
<property name="geometry">
<rect>
<x>320</x>
<y>360</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>Cancel</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>0</x>
<y>10</y>
<width>351</width>
<height>17</height>
</rect>
</property>
<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>
</property>
</widget>
<widget class="QLineEdit" name="labelRequest">
<property name="geometry">
<rect>
<x>0</x>
<y>50</y>
<width>591</width>
<height>25</height>
</rect>
</property>
</widget>
</widget>
<pixmapfunction></pixmapfunction>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<sender>sendRequestButton</sender>
<signal>clicked()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel" >
<x>248</x>
<y>254</y>
<hint type="sourcelabel">
<x>536</x>
<y>262</y>
</hint>
<hint type="destinationlabel" >
<x>157</x>
<y>274</y>
<hint type="destinationlabel">
<x>389</x>
<y>207</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<sender>cancel</sender>
<signal>clicked()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel" >
<x>316</x>
<y>260</y>
<hint type="sourcelabel">
<x>396</x>
<y>262</y>
</hint>
<hint type="destinationlabel" >
<x>286</x>
<y>274</y>
<hint type="destinationlabel">
<x>389</x>
<y>207</y>
</hint>
</hints>
</connection>
</connections>
</ui>

5
src/mainwindow.cpp

@ -14,6 +14,7 @@
#include "settings.h"
#include "version.h"
#include "connection.h"
#include "ui_contactrequest.h"
#include "requestdialog.h"
#include "websockets.h"
#include <QRegularExpression>
@ -1006,7 +1007,8 @@ void MainWindow::setupchatTab() {
// Send button
QObject::connect(ui->sendChatButton, &QPushButton::clicked, this, &MainWindow::sendChatButton);
QObject::connect(ui->safeContactRequest, &QPushButton::clicked, this, &MainWindow::safeContactRequest);
QObject::connect(ui->safeContactRequest, &QPushButton::clicked, this, &MainWindow::ContactRequest);
///////// Set selected Zaddr for Chat with Doubleklick
@ -1032,6 +1034,7 @@ void MainWindow::setupchatTab() {
}
ChatMemoEdit::ChatMemoEdit(QWidget* parent) : QPlainTextEdit(parent) {
QObject::connect(this, &QPlainTextEdit::textChanged, this, &ChatMemoEdit::updateDisplay);
}

3
src/mainwindow.h

@ -108,13 +108,14 @@ private:
Tx createTxFromChatPage();
Tx createTxForSafeContactRequest();
void encryptWallet();
void removeWalletEncryption();
void cancelButton();
void sendButton();
void sendChatButton();
void safeContactRequest();
void ContactRequest();
void addAddressSection();
void maxAmountChecked(int checked);

Loading…
Cancel
Save