From 5006a8c7d7069ccdbd3824ff65d2266606525742 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Fri, 8 May 2020 21:25:43 +0200 Subject: [PATCH 1/2] add incoming contact Request windows --- src/chatmodel.cpp | 17 +++++------------ src/chatmodel.h | 2 +- src/mainwindow.cpp | 1 + src/mainwindow.h | 1 + 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index 078a56f..6f80f37 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -100,10 +100,7 @@ void ChatModel::renderChatBox(Ui::MainWindow* ui, QListView &view) void ChatModel::renderChatBox(Ui::MainWindow* ui, QListView *view) { - QObject::connect(ui->pushContact, &QPushButton::clicked,[&] () - { - renderContactRequest(); - }); + QStandardItemModel* chat = new QStandardItemModel(); // ui->lcdNumber->setStyleSheet("background-color: red"); @@ -149,17 +146,17 @@ void ChatModel::renderChatBox(Ui::MainWindow* ui, QListView *view) } -void ChatModel::renderContactRequest(){ +void MainWindow::renderContactRequest(){ Ui_requestDialog requestContact; - QDialog dialog(main); + QDialog dialog(this); requestContact.setupUi(&dialog); Settings::saveRestore(&dialog); { QStandardItemModel* contactRequest = new QStandardItemModel(); - + for (auto &c : DataStore::getChatDataStore()->getAllRawChatItems())//this->chatItems) { @@ -214,8 +211,6 @@ void ChatModel::renderContactRequest(){ } }); - - QObject::connect(requestContact.pushButton, &QPushButton::clicked, [&] () { QString cid = requestContact.requestCID->text(); @@ -228,7 +223,7 @@ void ChatModel::renderContactRequest(){ qDebug()<<"Beginn kopiert" <addAddressLabel(newLabel, addr, myAddr, cid, avatar); - QMessageBox::information(main, "Added Contact","successfully added your new contact. You can now Chat with this contact"); + QMessageBox::information(this, "Added Contact","successfully added your new contact. You can now Chat with this contact"); @@ -238,8 +233,6 @@ void ChatModel::renderContactRequest(){ dialog.exec(); } - - void ChatModel::addCid(QString tx, QString cid) { this->cidMap[tx] = cid; diff --git a/src/chatmodel.h b/src/chatmodel.h index 984ce56..493e744 100644 --- a/src/chatmodel.h +++ b/src/chatmodel.h @@ -329,7 +329,7 @@ class ChatModel void setItems(std::vector items); void renderChatBox(Ui::MainWindow* ui, QListView &view); void renderChatBox(Ui::MainWindow* ui, QListView *view); - void renderContactRequest(); + // void renderContactRequest(); void triggerRequest(); void showMessages(); void clear(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 694178f..2957dbb 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1057,6 +1057,7 @@ void MainWindow::setupchatTab() { QObject::connect(ui->sendChatButton, &QPushButton::clicked, this, &MainWindow::sendChatButton); QObject::connect(ui->sendContact, &QPushButton::clicked, this, &MainWindow::ContactRequest); QObject::connect(ui->safeContactRequest, &QPushButton::clicked, this, &MainWindow::addContact); + QObject::connect(ui->pushContact, &QPushButton::clicked, this , &MainWindow::renderContactRequest); ///////// Set selected Zaddr for Chat with Klick diff --git a/src/mainwindow.h b/src/mainwindow.h index 9e91245..ff4b76a 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -62,6 +62,7 @@ public: void updateLabels(); void updateTAddrCombo(bool checked); + // void renderContactRequest(); // void setChatItem(ChatItem* item); //void ChatItem* getChatItem(); From eb263e5e0b87f3f2a618834ff376876984c1f700 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Fri, 8 May 2020 22:36:24 +0200 Subject: [PATCH 2/2] switch to datastore --- src/DataStore/ChatDataStore.cpp | 36 +++++++++++++ src/DataStore/ChatDataStore.h | 4 ++ src/chatmodel.cpp | 94 ++++++++++++++++++++------------- 3 files changed, 96 insertions(+), 38 deletions(-) diff --git a/src/DataStore/ChatDataStore.cpp b/src/DataStore/ChatDataStore.cpp index d3a79e4..4dfc605 100644 --- a/src/DataStore/ChatDataStore.cpp +++ b/src/DataStore/ChatDataStore.cpp @@ -37,6 +37,42 @@ std::map ChatDataStore::getAllRawChatItems() return this->data; } +std::map ChatDataStore::getAllContactRequests() +{ + std::map filteredItems; + for(auto &c: this->data) + { + if ( + (c.second.getType() == "cont") && + (c.second.isOutgoing() == false) && + (c.second.getMemo().startsWith("{")) + ) + { + filteredItems[c.first] = c.second; + } + } + return filteredItems; +} + + +std::map ChatDataStore::getAllMemos() +{ + std::map filteredItems; + for(auto &c: this->data) + { + if ( + + (c.second.getMemo().startsWith("{") == false) && + (c.second.getMemo().isEmpty() == false) + + ) + { + filteredItems[c.first] = c.second; + } + } + return filteredItems; +} + ChatDataStore* ChatDataStore::instance = nullptr; bool ChatDataStore::instanced = false; \ No newline at end of file diff --git a/src/DataStore/ChatDataStore.h b/src/DataStore/ChatDataStore.h index 85fd4b9..444c704 100644 --- a/src/DataStore/ChatDataStore.h +++ b/src/DataStore/ChatDataStore.h @@ -8,6 +8,8 @@ class ChatDataStore private: static bool instanced; static ChatDataStore* instance; + Ui::MainWindow* ui; + MainWindow* main; std::map data; ChatDataStore() { @@ -20,6 +22,8 @@ class ChatDataStore void setData(QString key, ChatItem value); ChatItem getData(QString key); std::map getAllRawChatItems(); + std::map getAllContactRequests(); + std::map getAllMemos(); QString dump(); ~ChatDataStore() diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index 6f80f37..41fbb2e 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -107,13 +107,20 @@ void ChatModel::renderChatBox(Ui::MainWindow* ui, QListView *view) // ui->lcdNumber->setPalette(Qt::red); // ui->lcdNumber->display("1"); - for (auto &c : DataStore::getChatDataStore()->getAllRawChatItems())//this->chatItems) + + + for (auto &p : AddressBook::getInstance()->getAllAddressLabels()) - { + for (auto &c : DataStore::getChatDataStore()->getAllMemos()) + { //////Render only Memos for selected contacts. Do not render empty Memos //// Render only memos where cid=cid - if ((c.second.getContact() == ui->contactNameMemo->text().trimmed()) && (p.getPartnerAddress() == c.second.getAddress()) && (c.second.getMemo().startsWith("{") == false) && (c.second.getMemo().isEmpty() == false) && (c.second.isOutgoing() == true)) + if ( + (c.second.getContact() == ui->contactNameMemo->text().trimmed()) && + (p.getPartnerAddress() == c.second.getAddress()) && + (c.second.isOutgoing() == true) + ) { QStandardItem* Items = new QStandardItem(c.second.toChatLine()); @@ -126,8 +133,13 @@ void ChatModel::renderChatBox(Ui::MainWindow* ui, QListView *view) ui->listChat->setModel(chat); } - - if ((c.second.getContact() == ui->contactNameMemo->text().trimmed()) && ((p.getMyAddress() == c.second.getAddress()) && c.second.getMemo().startsWith("{") == false) && (c.second.getMemo().isEmpty() == false) && (c.second.isOutgoing() == false)) + + if ( + (c.second.getContact() == ui->contactNameMemo->text().trimmed()) && + (p.getMyAddress() == c.second.getAddress()) && + (c.second.isOutgoing() == false) + ) + { QStandardItem* Items1 = new QStandardItem(c.second.toChatLine()); @@ -140,11 +152,13 @@ void ChatModel::renderChatBox(Ui::MainWindow* ui, QListView *view) ui->listChat->setModel(chat); } + + } + + +} - } - -} void MainWindow::renderContactRequest(){ @@ -153,35 +167,18 @@ void MainWindow::renderContactRequest(){ requestContact.setupUi(&dialog); Settings::saveRestore(&dialog); - { - QStandardItemModel* contactRequest = new QStandardItemModel(); + QStandardItemModel* contactRequest = new QStandardItemModel(); - - for (auto &c : DataStore::getChatDataStore()->getAllRawChatItems())//this->chatItems) - { - - if ((c.second.getType() == "cont") && (c.second.isOutgoing() == false) && (c.second.getMemo().startsWith("{"))) { + { + for (auto &c : DataStore::getChatDataStore()->getAllContactRequests()) + { - - - - - - QStandardItem* Items = new QStandardItem(c.second.getAddress()); - contactRequest->appendRow(Items); - requestContact.requestContact->setModel(contactRequest); - requestContact.requestContact->show(); - - - } - - - } - - - } - - + QStandardItem* Items = new QStandardItem(c.second.getAddress()); + contactRequest->appendRow(Items); + requestContact.requestContact->setModel(contactRequest); + requestContact.requestContact->show(); + } + } QObject::connect(requestContact.requestContact, &QTableView::clicked, [&] () { @@ -220,12 +217,33 @@ void MainWindow::renderContactRequest(){ QString avatar = QString(":/icons/res/") + requestContact.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; + } + qDebug()<<"Beginn kopiert" <addAddressLabel(newLabel, addr, myAddr, cid, avatar); - QMessageBox::information(this, "Added Contact","successfully added your new contact. You can now Chat with this contact"); - - + QMessageBox::information(this, "Added Contact","successfully added your new contact. You can now Chat with this contact"); });