diff --git a/silentdragon-lite.pro b/silentdragon-lite.pro index 5c7dd21..da53d6d 100644 --- a/silentdragon-lite.pro +++ b/silentdragon-lite.pro @@ -78,7 +78,8 @@ SOURCES += \ src/Model/ChatItem.cpp \ src/Model/ContactRequestChatItem.cpp \ src/Model/ContactItem.cpp \ - src/Chat/Helper/ChatIDGenerator.cpp + src/Chat/Helper/ChatIDGenerator.cpp \ + src/Chat/Chat.cpp HEADERS += \ src/firsttimewizard.h \ diff --git a/src/Chat/Chat.cpp b/src/Chat/Chat.cpp new file mode 100644 index 0000000..c2719ee --- /dev/null +++ b/src/Chat/Chat.cpp @@ -0,0 +1,53 @@ +#include "Chat.h" +#include "../addressbook.h" +#include "../DataStore/DataStore.h" +Chat::Chat() {} + +void Chat::renderChatBox(Ui::MainWindow *ui, QListView *view) +{ + QStandardItemModel *chat = new QStandardItemModel(); + // ui->lcdNumber->setStyleSheet("background-color: red"); + // ui->lcdNumber->setPalette(Qt::red); + // ui->lcdNumber->display("1"); + + 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.isOutgoing() == true)) + { + + QStandardItem *Items = new QStandardItem(c.second.toChatLine()); + Items->setData("Outgoing", Qt::UserRole + 1); + chat->appendRow(Items); + ui->listChat->setModel(chat); + } + else + { + ui->listChat->setModel(chat); + } + + if ( + (c.second.getContact() == ui->contactNameMemo->text().trimmed()) && + (p.getMyAddress() == c.second.getAddress()) && + (c.second.isOutgoing() == false)) + + { + QStandardItem *Items1 = new QStandardItem(c.second.toChatLine()); + Items1->setData("Incoming", Qt::UserRole + 1); + chat->appendRow(Items1); + ui->listChat->setModel(chat); + } + else + { + + ui->listChat->setModel(chat); + } + } + } +} \ No newline at end of file diff --git a/src/Chat/Chat.h b/src/Chat/Chat.h index 969f98c..526aa36 100644 --- a/src/Chat/Chat.h +++ b/src/Chat/Chat.h @@ -1,28 +1,36 @@ #ifndef CHAT_H #define CHAT_H +#include +#include +#include +#include +#include +#include +#include +#include "precompiled.h" +#include "mainwindow.h" +#include "controller.h" +#include "settings.h" +#include "camount.h" + +#include "../Model/ChatItem.h" + + class Chat // Chat Controller { private: - std::map chatItems; QTableView* parent; Ui::MainWindow* ui; MainWindow* main; std::map cidMap; std::map requestZaddrMap; public: - ChatModel() {}; - ChatModel(std::map chatItems); - ChatModel(std::vector chatItems); - QString generateChatItemID(ChatItem item); // helper - std::map getItems(); - void setItems(std::map items); - QString zaddr(); - void setItems(std::vector items); - void renderChatBox(Ui::MainWindow* ui, QListView &view); // action + Chat(); + //QString zaddr(); void renderChatBox(Ui::MainWindow* ui, QListView *view); // action // void renderContactRequest(); - void triggerRequest(); + /*void triggerRequest(); void showMessages(); void clear(); //void renderContactRequest(Ui::MainWindow* ui, QListView *view); @@ -33,7 +41,7 @@ class Chat // Chat Controller QString getCidByTx(QString tx); QString getrequestZaddrByTx(QString tx); void killCidCache(); - void killrequestZaddrCache(); + void killrequestZaddrCache();*/ }; diff --git a/src/controller.cpp b/src/controller.cpp index e757190..730e906 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -16,6 +16,7 @@ DataStore* DataStore::instance = nullptr; template<> bool DataStore::instanced = false;*/ ChatModel *chatModel = new ChatModel(); +Chat *chat = new Chat(); ContactModel *contactModel = new ContactModel(); using json = nlohmann::json; @@ -1022,7 +1023,7 @@ void Controller::refreshTransactions() { // Update model data, which updates the table view transactionsTableModel->replaceData(txdata); - chatModel->renderChatBox(ui, ui->listChat); + chat->renderChatBox(ui, ui->listChat); refreshContacts( ui->listContactWidget @@ -1032,7 +1033,7 @@ void Controller::refreshTransactions() { void Controller::refreshChat(QListView *listWidget) { - chatModel->renderChatBox(ui, listWidget); + chat->renderChatBox(ui, listWidget); } diff --git a/src/controller.h b/src/controller.h index 05e1f97..cfd3bbb 100644 --- a/src/controller.h +++ b/src/controller.h @@ -12,6 +12,7 @@ #include "liteinterface.h" #include "connection.h" #include "chatmodel.h" +#include "Chat/Chat.h" #include "Model/ContactRequestChatItem.h" #include "Model/ContactItem.h" #include "contactmodel.h"