diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index 32ecb78..6622416 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -115,9 +115,11 @@ void MainWindow::renderContactRequest(){ QStandardItemModel* contactRequest = new QStandardItemModel(); + + for (auto &c : DataStore::getChatDataStore()->getAllNewContactRequests()) - + { @@ -134,6 +136,7 @@ void MainWindow::renderContactRequest(){ } + QStandardItemModel* contactRequestOld = new QStandardItemModel(); for (auto &p : AddressBook::getInstance()->getAllAddressLabels()) @@ -157,13 +160,16 @@ void MainWindow::renderContactRequest(){ QModelIndex index = requestContact.requestContact->currentIndex(); QString label_contact = index.data(Qt::DisplayRole).toString(); QStandardItemModel* contactMemo = new QStandardItemModel(); + + + if ((c.second.isOutgoing() == false) && (requestContact.zaddrnew->text() == c.second.getAddress()) && (c.second.getType() != "Cont")) { QStandardItem* Items = new QStandardItem(c.second.getMemo()); - contactMemo->appendRow(Items); + contactMemo->appendRow(Items); requestContact.requestMemo->setModel(contactMemo); requestContact.requestMemo->show(); @@ -172,17 +178,18 @@ void MainWindow::renderContactRequest(){ requestContact.requestZaddr->setText(c.second.getRequestZaddr()); requestContact.requestMyAddr->setText(c.second.getAddress()); }else{} - } - + } }); + + QObject::connect(requestContact.requestContactOld, &QTableView::clicked, [&] () { for (auto &c : DataStore::getChatDataStore()->getAllRawChatItems()){ - /* QModelIndex index = requestContact.requestContactOld->currentIndex(); - QString label_contactold = index.data(Qt::DisplayRole).toString();*/ + QModelIndex index = requestContact.requestContactOld->currentIndex(); + QString label_contactold = index.data(Qt::DisplayRole).toString(); QStandardItemModel* contactMemo = new QStandardItemModel(); if ((c.second.isOutgoing() == false) && (requestContact.zaddrold->text() == c.second.getAddress()) && (c.second.getType() != "Cont")) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 6e9af7e..4e9a126 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -30,6 +30,7 @@ #include "FileSystem/FileSystem.h" #include "Crypto/passwd.h" #include "Crypto/FileEncryption.h" +#include "DataStore/DataStore.h" using json = nlohmann::json; @@ -1362,6 +1363,118 @@ void MainWindow::setupchatTab() { ui->contactNameMemo->setText(""); + /////Copy Chatmessages + + QMenu* contextMenuChat; + QAction* copymessage; + QAction* viewexplorer; + QAction* copytxid; + contextMenuChat = new QMenu(ui->listChat); + copymessage = new QAction("Copy message to clipboard",contextMenuChat); + viewexplorer = new QAction("View on block explorerr",contextMenuChat); + copytxid = new QAction("Copy txid to clipboard ",contextMenuChat); + + QObject::connect(ui->listContactWidget, &QTableView::clicked, [=] () { + + ui->listChat->setContextMenuPolicy(Qt::ActionsContextMenu); + ui->listChat->addAction(copymessage); + ui->listChat->addAction(viewexplorer); + ui->listChat->addAction(copytxid); + + QObject::connect(copymessage, &QAction::triggered, [=] { + + + QModelIndex index = ui->listChat->currentIndex(); + QString memo_chat = index.data(Qt::DisplayRole).toString(); + QClipboard *clipboard = QGuiApplication::clipboard(); + int startPos = memo_chat.indexOf("
") + 3; + int endPos = memo_chat.indexOf("
"); + int length = endPos - startPos; + QString copymemo = memo_chat.mid(startPos, length); + + clipboard->setText(copymemo); + ui->statusBar->showMessage(tr("Copied message to clipboard"), 3 * 1000); + +}); + QObject::connect(copytxid, &QAction::triggered, [=] { + + QModelIndex index = ui->listChat->currentIndex(); + QString memo_chat = index.data(Qt::DisplayRole).toString(); + QClipboard *clipboard = QGuiApplication::clipboard(); + + int startPos = memo_chat.indexOf("") + 3; + int endPos = memo_chat.indexOf("
"); + int length = endPos - startPos; + QString copymemo = memo_chat.mid(startPos, length); + int startPosT = memo_chat.indexOf("") + 7; + int endPosT = memo_chat.indexOf(""); + int lengthT = endPosT - startPosT; + + QString time = memo_chat.mid(startPosT, lengthT); + + for (auto &c : DataStore::getChatDataStore()->getAllRawChatItems()){ + + if (c.second.getMemo() == copymemo) + { + int timestamp = c.second.getTimestamp(); + QDateTime myDateTime; + QString lock; + myDateTime.setTime_t(timestamp); + QString timestamphtml = myDateTime.toString("yyyy-MM-dd hh:mm"); + + if(timestamphtml == time) + + { + clipboard->setText(c.second.getTxid()); + ui->statusBar->showMessage(tr("Copied Txid to clipboard"), 3 * 1000); + }else{} + + } + +} + +}); + + QObject::connect(viewexplorer, &QAction::triggered, [=] { + + QModelIndex index = ui->listChat->currentIndex(); + QString memo_chat = index.data(Qt::DisplayRole).toString(); + + int startPos = memo_chat.indexOf("") + 3; + int endPos = memo_chat.indexOf("
"); + int length = endPos - startPos; + QString copymemo = memo_chat.mid(startPos, length); + int startPosT = memo_chat.indexOf("") + 7; + int endPosT = memo_chat.indexOf(""); + int lengthT = endPosT - startPosT; + + QString time = memo_chat.mid(startPosT, lengthT); + + for (auto &c : DataStore::getChatDataStore()->getAllRawChatItems()){ + + if (c.second.getMemo() == copymemo) + { + int timestamp = c.second.getTimestamp(); + QDateTime myDateTime; + QString lock; + myDateTime.setTime_t(timestamp); + QString timestamphtml = myDateTime.toString("yyyy-MM-dd hh:mm"); + + if(timestamphtml == time) + + { + + Settings::openTxInExplorer(c.second.getTxid()); + + }else{} + + } + +} +}); + +}); + ///////// Add contextmenu QMenu* contextMenu; QAction* requestAction; diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 505be91..2fa544c 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -1602,6 +1602,9 @@