Browse Source

add contact on Chattab

pull/130/head
DenioD 4 years ago
parent
commit
dc61bb38c7
  1. 2
      application.qrc
  2. 0
      res/Stag.png
  3. 23
      src/addressbook.cpp
  4. 2
      src/addressbook.ui
  5. 137
      src/chatmodel.cpp
  6. 1
      src/chatmodel.h
  7. 1
      src/contactmodel.cpp
  8. 338
      src/contactrequest.ui
  9. 46
      src/mainwindow.cpp
  10. 2
      src/mainwindow.h
  11. 54
      src/mainwindow.ui

2
application.qrc

@ -21,7 +21,7 @@
<file>res/Popey.png</file>
<file>res/Garfield.png</file>
<file>res/Pinguin.png</file>
<file>res/Hirsch.png</file>
<file>res/Stag.png</file>
</qresource>
<qresource prefix="/img">
<file>res/hushdlogo.gif</file>

0
res/Hirsch.png → res/Stag.png

Before

Width:  |  Height:  |  Size: 140 KiB

After

Width:  |  Height:  |  Size: 140 KiB

23
src/addressbook.cpp

@ -335,34 +335,11 @@ void AddressBook::open(MainWindow* parent, QLineEdit* target)
}
};
// Get Avatar Data
// int avatar_index = ab.comboBoxAvatar->findText(AddressBook::getInstance()->get_avatar_name(), Qt::MatchExactly);
// ab.comboBoxAvatar->setCurrentIndex(avatar_index);
// QObject::connect(ab.comboBoxAvatar, &QComboBox::currentTextChanged, [=] (QString avatar_name) {
// parent->slot_change_avatar(avatar_name);
// rpc->refresh(true);
// });
// Refresh after the dialog is closed to update the labels everywhere.
parent->getRPC()->refresh(true);
model.updateUi(); //todo fix updating gui after adding
}
QString AddressBook::get_avatar_name() {
// Load from the QT Settings.
// QString avatar = ab.comboBoxAvatar.text();
// return QString()
}
void AddressBook::set_avatar_name(QString avatar_name) {
avatar_name = "abs.comboBoxAvatar.text()";
}
//=============
// AddressBook singleton class
//=============

2
src/addressbook.ui

@ -69,7 +69,7 @@
</property>
<property name="icon">
<iconset>
<activeon>:/icons/res/Hirsch.png</activeon>
<activeon>:/icons/res/Stag.png</activeon>
</iconset>
</property>
</item>

137
src/chatmodel.cpp

@ -164,7 +164,7 @@ QString ChatModel::getCidByTx(QString tx)
{
for(auto& pair : this->cidMap)
{
// qDebug() << "TXID=" << pair.first << " CID=" << pair.second;
}
if(this->cidMap.count(tx) > 0)
@ -247,9 +247,7 @@ Tx MainWindow::createTxFromChatPage() {
void MainWindow::sendChatButton() {
////////////////////////////Todo: Check if a Contact is selected//////////
////////////////////////////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.
@ -377,25 +375,80 @@ QString MainWindow::doSendChatTxValidations(Tx tx) {
return "";
}
void::MainWindow::addContact() {
// Create a Tx from the current state of the Chat page.
Tx MainWindow::createTxForSafeContactRequest() {
Ui_Dialog request;
Ui_Dialog request;
QDialog dialog(this);
request.setupUi(&dialog);
Settings::saveRestore(&dialog);
dialog.exec();
Tx tx;
QObject::connect(request.cancel, &QPushButton::clicked, [&] () {
bool sapling = true;
rpc->createNewZaddr(sapling, [=] (json reply) {
QString myAddr = QString::fromStdString(reply.get<json::array_t>()[0]);
QString cid = QUuid::createUuid().toString(QUuid::WithoutBraces);
ui->listReceiveAddresses->insertItem(0, myAddr);
ui->listReceiveAddresses->setCurrentIndex(0);
qDebug() << "new generated myAddr" << myAddr;
request.myzaddr->setText(myAddr);
request.cid->setText(cid);
});
QObject::connect(request.sendRequestButton, &QPushButton::clicked, [&] () {
QString cid = request.cid->text();
auto addr = request.zaddr->text().trimmed();
QString newLabel = request.labelRequest->text().trimmed();
auto myAddr = request.myzaddr->text().trimmed();
QString avatar = QString("res/") + request.comboBoxAvatar->currentText() + QString(".png");
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;
}
////// We need a better popup here.
AddressBook::getInstance()->addAddressLabel(newLabel, addr, myAddr, cid, avatar);
QMessageBox::critical(
this,
QObject::tr("Add Successfully"),
QObject::tr("juhu").arg(newLabel),
QMessageBox::Ok
);
return;
dialog.close();
});
dialog.exec();
}
QObject::connect(request.sendRequestButton, &QPushButton::clicked, this, &MainWindow::ContactRequest);
// Create a Tx for a contact Request
Tx MainWindow::createTxForSafeContactRequest() {
Tx tx;
// For each addr/amt in the Chat tab
{
CAmount totalAmt;
@ -408,71 +461,41 @@ dialog.exec();
for(auto &c : AddressBook::getInstance()->getAllAddressLabels())
if (request.zaddr->text().trimmed() != c.getPartnerAddress()) {
if (ui->contactNameMemo->text().trimmed() == c.getName()) {
QString cid = c.getCid();
QString myAddr = c.getMyAddress();
QString type = "cont";
QString addr = request.zaddr->text();
QString addr = c.getPartnerAddress();
QString hmemo= createHeaderMemo(type,cid,myAddr,0,0);
QString memo = request.requestmemo->toPlainText().trimmed();
QString hmemo= createHeaderMemo(type,cid,myAddr);
QString memo = ui->memoTxtChat->toPlainText().trimmed();
tx.toAddrs.push_back(ToFields{addr, amt, hmemo});
tx.toAddrs.push_back(ToFields{addr, amt, memo});
qDebug() << "pushback chattx";
tx.fee = Settings::getMinerFee();
}
tx.fee = Settings::getMinerFee();
return tx;
qDebug() << "ChatTx created";
} if (request.zaddr->text().trimmed().isEmpty() == false){
qDebug() << "RequestTx created";
QMessageBox msg(QMessageBox::Critical, tr("Please insert a contact Address"), request.zaddr->text(),
QMessageBox::Ok, this);
msg.exec();
}
}
}
void MainWindow::ContactRequest() {
////////////////////////////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.
// Memos can only be used with zAddrs. So check that first
// for(auto &c : AddressBook::getInstance()->getAllAddressLabels())
// 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("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;
// }
//};
void MainWindow::ContactRequest() {
Tx tx = createTxForSafeContactRequest();
QString error = doSendChatTxValidations(tx);
QString error = doSendRequestTxValidations(tx);
if (!error.isEmpty()) {
// Something went wrong, so show an error and exit
@ -504,7 +527,7 @@ void MainWindow::ContactRequest() {
}
connD->status->setText(tr("Please wait..."));
connD->statusDetail->setText(tr("Your Message will be send"));
connD->statusDetail->setText(tr("Your Contact will be send"));
d->show();
ui->memoTxtChat->clear();

1
src/chatmodel.h

@ -310,6 +310,7 @@ class ChatModel
void addCid(QString tx, QString cid);
QString getCidByTx(QString tx);
void killCidCache();
};
#endif

1
src/contactmodel.cpp

@ -12,7 +12,6 @@ void ContactModel::renderContactList(QListView* view)
auto theme = Settings::getInstance()->get_theme_name();
if ((theme == "dark" || theme == "midnight")) {
// QIcon avatar = c.getAvatar();
QString avatar = c.getAvatar();
QStandardItem* Items1 = new QStandardItem(QIcon(avatar) ,c.getName());

338
src/contactrequest.ui

@ -13,130 +13,230 @@
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<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>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="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 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>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1" 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>
</property>
</widget>
</item>
<item row="1" column="0">
<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>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QComboBox" name="comboBoxAvatar">
<item>
<property name="text">
<string>Stag</string>
</property>
<property name="icon">
<iconset>
<activeon>:/icons/res/Hirsch.png</activeon>
</iconset>
</property>
</item>
<item>
<property name="text">
<string>Denio</string>
</property>
<property name="icon">
<iconset>
<activeon>:/icons/res/Denio.png</activeon>
</iconset>
</property>
</item>
<item>
<property name="text">
<string>Duke</string>
</property>
<property name="icon">
<iconset>
<activeon>:/icons/res/Duke.png</activeon>
</iconset>
</property>
</item>
<item>
<property name="text">
<string>Yoda</string>
</property>
<property name="icon">
<iconset>
<activeon>:/icons/res/Yoda.png</activeon>
</iconset>
</property>
</item>
<item>
<property name="text">
<string>Berg</string>
</property>
<property name="icon">
<iconset>
<activeon>:/icons/res/Berg.png</activeon>
</iconset>
</property>
</item>
<item>
<property name="text">
<string>Sharpee</string>
</property>
<property name="icon">
<iconset>
<activeon>:/icons/res/Sharpee.png</activeon>
</iconset>
</property>
</item>
<item>
<property name="text">
<string>Garfield</string>
</property>
<property name="icon">
<iconset>
<activeon>:/icons/res/Garfield.png</activeon>
</iconset>
</property>
</item>
<item>
<property name="text">
<string>Snoopy</string>
</property>
<property name="icon">
<iconset>
<activeon>:/icons/res/Snoopy.png</activeon>
</iconset>
</property>
</item>
<item>
<property name="text">
<string>Popey</string>
</property>
<property name="icon">
<iconset>
<activeon>:/icons/res/Popey.png</activeon>
</iconset>
</property>
</item>
<item>
<property name="text">
<string>Pinguin</string>
</property>
<property name="icon">
<iconset>
<activeon>:/icons/res/Pinguin.png</activeon>
</iconset>
</property>
</item>
<item>
<property name="text">
<string>Mickey</string>
</property>
<property name="icon">
<iconset>
<activeon>:/icons/res/Mickey.png</activeon>
</iconset>
</property>
</item>
<item>
<property name="text">
<string>SDLogo</string>
</property>
<property name="icon">
<iconset>
<activeon>:/icons/res/sdlogo2.png</activeon>
</iconset>
</property>
</item>
</widget>
</item>
<item row="2" column="0">
<widget class="QLineEdit" name="labelRequest"/>
</item>
<item row="3" column="0">
<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>
</property>
</widget>
</item>
<item row="4" column="0" colspan="3">
<widget class="QLineEdit" name="zaddr"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Your HushChat Address</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="3">
<widget class="QLabel" name="myzaddr">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>The Conversation ID </string>
</property>
</widget>
</item>
<item row="8" column="0" colspan="3">
<widget class="QLabel" name="cid">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QPushButton" name="cancel">
<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>
</item>
<item row="9" column="2">
<widget class="QPushButton" name="sendRequestButton">
<property name="baseSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Add Contact</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>sendRequestButton</sender>
<sender>cancel</sender>
<signal>clicked()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>536</x>
<x>396</x>
<y>262</y>
</hint>
<hint type="destinationlabel">
@ -146,13 +246,13 @@
</hints>
</connection>
<connection>
<sender>cancel</sender>
<sender>sendRequestButton</sender>
<signal>clicked()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>396</x>
<x>536</x>
<y>262</y>
</hint>
<hint type="destinationlabel">

46
src/mainwindow.cpp

@ -40,10 +40,9 @@ MainWindow::MainWindow(QWidget *parent) :
ui->setupUi(this);
// ui->checkBox->setChecked(true);
ui->request->setChecked(true);
logger = new Logger(this, QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)).filePath("silentdragonlite-wallet.log"));
ui->memoTxtChat->setAutoFillBackground(false);
// ui->memoTxtChat->setStyleSheet(QString::fromUtf8("background-color: rgb(224, 224, 224);"));
ui->memoTxtChat->setPlaceholderText("Send Message");
ui->memoTxtChat->setTextColor(Qt::white);
@ -436,11 +435,6 @@ void MainWindow::setupSettingsModal() {
this->slot_change_currency(currency_name);
// Include Avatar
// Setup theme combo
int theme_index = settings.comboBoxTheme->findText(Settings::getInstance()->get_theme_name(), Qt::MatchExactly);
settings.comboBoxTheme->setCurrentIndex(theme_index);
@ -1008,8 +1002,22 @@ void MainWindow::setupTransactionsTab() {
void MainWindow::setupchatTab() {
// Send button
QObject::connect(ui->sendChatButton, &QPushButton::clicked, this, &MainWindow::sendChatButton);
QObject::connect(ui->safeContactRequest, &QPushButton::clicked, this, &MainWindow::ContactRequest);
// Is request Contact checked?
if (ui->request->isChecked()) {
QObject::connect(ui->sendChatButton, &QPushButton::clicked, this, &MainWindow::ContactRequest);
// qDebug() <<ui->request->isChecked()->text();
}else{
QObject::connect(ui->sendChatButton, &QPushButton::clicked, this, &MainWindow::sendChatButton);
}
QObject::connect(ui->safeContactRequest, &QPushButton::clicked, this, &MainWindow::addContact);
///////// Set selected Zaddr for Chat with Doubleklick
@ -1470,26 +1478,6 @@ void MainWindow::slot_change_currency(const QString& currency_name)
}
}
void MainWindow::slot_change_avatar(const QString& avatar_name)
{
AddressBook::getInstance()->set_avatar_name(avatar_name);
// Include currency
QString saved_avatar_name;
try
{
saved_avatar_name = AddressBook::getInstance()->get_avatar_name();
}
catch (...)
{
saved_avatar_name = "Yoda";
}
}
void MainWindow::slot_change_theme(const QString& theme_name)

2
src/mainwindow.h

@ -83,7 +83,6 @@ public:
public slots:
void slot_change_theme(const QString& themeName);
void slot_change_currency(const QString& currencyName);
void slot_change_avatar(const QString& avatarName);
private:
void closeEvent(QCloseEvent* event);
@ -116,6 +115,7 @@ private:
void cancelButton();
void sendButton();
void sendChatButton();
void addContact();
void ContactRequest();
void addAddressSection();
void maxAmountChecked(int checked);

54
src/mainwindow.ui

@ -1334,7 +1334,7 @@
<x>0</x>
<y>40</y>
<width>341</width>
<height>551</height>
<height>601</height>
</rect>
</property>
</widget>
@ -1342,8 +1342,8 @@
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>311</width>
<y>20</y>
<width>341</width>
<height>20</height>
</rect>
</property>
@ -1355,9 +1355,9 @@
<property name="geometry">
<rect>
<x>340</x>
<y>460</y>
<y>560</y>
<width>921</width>
<height>131</height>
<height>81</height>
</rect>
</property>
<property name="styleSheet">
@ -1368,7 +1368,7 @@
<property name="geometry">
<rect>
<x>1190</x>
<y>610</y>
<y>650</y>
<width>47</width>
<height>17</height>
</rect>
@ -1396,8 +1396,8 @@
<widget class="QPushButton" name="sendChatButton">
<property name="geometry">
<rect>
<x>710</x>
<y>610</y>
<x>720</x>
<y>640</y>
<width>114</width>
<height>25</height>
</rect>
@ -1418,8 +1418,8 @@
<widget class="QPushButton" name="safeContactRequest">
<property name="geometry">
<rect>
<x>50</x>
<y>600</y>
<x>30</x>
<y>640</y>
<width>211</width>
<height>25</height>
</rect>
@ -1456,7 +1456,7 @@
<x>340</x>
<y>40</y>
<width>921</width>
<height>421</height>
<height>521</height>
</rect>
</property>
<property name="verticalScrollBarPolicy">
@ -1484,6 +1484,19 @@
<bool>true</bool>
</property>
</widget>
<widget class="QCheckBox" name="request">
<property name="geometry">
<rect>
<x>340</x>
<y>650</y>
<width>261</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Is this message a contact request?</string>
</property>
</widget>
</widget>
</widget>
</item>
@ -1694,5 +1707,22 @@
<resources>
<include location="../application.qrc"/>
</resources>
<connections/>
<connections>
<connection>
<sender>request</sender>
<signal>stateChanged(int)</signal>
<receiver>MainWindow</receiver>
<slot>update()</slot>
<hints>
<hint type="sourcelabel">
<x>481</x>
<y>721</y>
</hint>
<hint type="destinationlabel">
<x>636</x>
<y>389</y>
</hint>
</hints>
</connection>
</connections>
</ui>

Loading…
Cancel
Save