From b79334a497dbcca30f57bd5795d4931a88f660ff Mon Sep 17 00:00:00 2001 From: Strider Date: Mon, 27 Apr 2020 21:53:37 +0200 Subject: [PATCH] update// added chatmessages to chatwindow --- src/chatmodel.cpp | 27 ++++++++++++++++++++------- src/chatmodel.h | 6 +++--- src/controller.cpp | 10 ++++++++-- src/controller.h | 1 + src/mainwindow.cpp | 7 ++++++- src/mainwindow.h | 1 + src/mainwindow.ui | 2 +- 7 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index f6fbb84..e1962c9 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -51,7 +51,7 @@ void ChatModel::showMessages() } } -void ChatModel::renderChatBox(QListView &view) +void ChatModel::renderChatBox(QListWidget &view) { /*for(auto &c : this->chatItems) { @@ -61,12 +61,25 @@ void ChatModel::renderChatBox(QListView &view) //todo render items to view } -void ChatModel::renderChatBox(QListView *view) +void ChatModel::renderChatBox(QListWidget *view) { - /*for(auto &c : this->chatItems) + qDebug() << "called ChatModel::renderChatBox(QListWidget *view)"; + QString line = ""; + while(view->count() > 0) { - //view->getItems().add(QString("[Timestamp] : lorem ipsum ....")); - }*/ - qDebug() << "not implemented yet blyat"; - //todo render items to view + view->takeItem(0); + } + + for(auto &c : this->chatItems) + { + QDateTime myDateTime; + + myDateTime.setTime_t(c.second.getTimestamp()); + qDebug() << "[" << myDateTime.toString("dd.MM.yyyy hh:mm:ss ") << "] " << "<" << c.second.getAddress() << "> :" << c.second.getMemo(); + line += QString("[") + myDateTime.toString("dd.MM.yyyy hh:mm:ss ") + QString("] "); + line += QString("<") + QString(c.second.getAddress()) + QString("> :"); + line += QString(c.second.getMemo()); + view->addItem(line); + line =""; + } } \ No newline at end of file diff --git a/src/chatmodel.h b/src/chatmodel.h index d44a35f..56db136 100644 --- a/src/chatmodel.h +++ b/src/chatmodel.h @@ -3,7 +3,7 @@ #include #include #include -#include +#include class ChatItem { @@ -109,8 +109,8 @@ class ChatModel std::map getItems(); void setItems(std::map items); void setItems(std::vector items); - void renderChatBox(QListView &view); - void renderChatBox(QListView *view); + void renderChatBox(QListWidget &view); + void renderChatBox(QListWidget *view); void showMessages(); void clear(); void addMessage(ChatItem item); diff --git a/src/controller.cpp b/src/controller.cpp index b7c5dba..daace4e 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -982,11 +982,17 @@ void Controller::refreshTransactions() // Update model data, which updates the table view transactionsTableModel->replaceData(txdata); - //chatModel->renderChatBox(); - chatModel->showMessages(); + chatModel->renderChatBox(ui->listChatMemo); + //chatModel->showMessages(); }); } +void Controller::refreshChat(QListWidget *listWidget) +{ + qDebug() << "Called Controller::refreshChat(QListWidget *listWidget)"; + chatModel->renderChatBox(listWidget); +} + // If the wallet is encrpyted and locked, we need to unlock it void Controller::unlockIfEncrypted(std::function cb, std::function error) { diff --git a/src/controller.h b/src/controller.h index a5f0fee..32d843b 100644 --- a/src/controller.h +++ b/src/controller.h @@ -71,6 +71,7 @@ public: void refreshGBPCAP(); void refreshAUDCAP(); + void refreshChat(QListWidget *listWidget); void executeStandardUITransaction(Tx tx); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 5352a95..b268750 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -900,7 +900,6 @@ void MainWindow::setupTransactionsTab() { // Set up context menu on transactions tab ui->transactionsTable->setContextMenuPolicy(Qt::CustomContextMenu); - // Table right click QObject::connect(ui->transactionsTable, &QTableView::customContextMenuRequested, [=] (QPoint pos) { QModelIndex index = ui->transactionsTable->indexAt(pos); @@ -983,6 +982,12 @@ void MainWindow::setupTransactionsTab() { }); } +void MainWindow::updateChat() +{ + qDebug() << "Called MainWindow::updateChat()"; + rpc->refreshChat(ui->listChatMemo); +} + void MainWindow::addNewZaddr(bool sapling) { rpc->createNewZaddr(sapling, [=] (json reply) { QString addr = QString::fromStdString(reply.get()[0]); diff --git a/src/mainwindow.h b/src/mainwindow.h index 50f833a..85f3595 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -85,6 +85,7 @@ private: void setupSendTab(); void setupTransactionsTab(); + void updateChat(); void setupReceiveTab(); void setupBalancesTab(); void setuphushdTab(); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 39e5e9e..6e8dcfe 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -1432,7 +1432,7 @@ <html><head/><body><p align="center">Messages</p></body></html> - + 340