Fix ImHistoryBrowser Send Action

This commit is contained in:
Phenom 2021-01-27 18:00:59 +01:00
parent 67d1265eb2
commit 7f13505c54
2 changed files with 36 additions and 34 deletions

View File

@ -392,7 +392,7 @@ void ImHistoryBrowser::customContextMenuRequested(QPoint /*pos*/)
QAction *sendItem = NULL; QAction *sendItem = NULL;
if (textEdit) { if (textEdit) {
sendItem = new QAction(tr("Send"), &contextMnu); sendItem = new QAction(tr("Quote"), &contextMnu);
if (currentItem) { if (currentItem) {
connect(sendItem, SIGNAL(triggered()), this, SLOT(sendMessage())); connect(sendItem, SIGNAL(triggered()), this, SLOT(sendMessage()));
} else { } else {
@ -427,23 +427,7 @@ void ImHistoryBrowser::customContextMenuRequested(QPoint /*pos*/)
void ImHistoryBrowser::copyMessage() void ImHistoryBrowser::copyMessage()
{ {
QListWidgetItem *currentItem = ui.listWidget->currentItem(); QApplication::clipboard()->setText(getCurrentItemsQuotedText());
if (currentItem) {
uint32_t msgId = currentItem->data(ROLE_MSGID).toString().toInt();
HistoryMsg msg;
if (rsHistory->getMessage(msgId, msg)) {
RsIdentityDetails details;
QString name = (rsIdentity->getIdDetails(RsGxsId(msg.peerName), details))
? QString::fromUtf8(details.mNickname.c_str())
: QString::fromUtf8(msg.peerName.c_str());
QDateTime date = msg.incoming
? QDateTime::fromTime_t(msg.sendTime)
: QDateTime::fromTime_t(msg.recvTime);
QTextDocument doc;
doc.setHtml(QString::fromUtf8(msg.message.c_str()));
QApplication::clipboard()->setText("> " + date.toString() + " " + name + ":" + doc.toPlainText());
}
}
} }
void ImHistoryBrowser::removeMessages() void ImHistoryBrowser::removeMessages()
@ -461,20 +445,37 @@ void ImHistoryBrowser::clearHistory()
void ImHistoryBrowser::sendMessage() void ImHistoryBrowser::sendMessage()
{ {
if (textEdit) { if (textEdit) {
QListWidgetItem *currentItem = ui.listWidget->currentItem(); QString msg =getCurrentItemsQuotedText();
if (currentItem) { QTextCursor cursor = textEdit->textCursor();
uint32_t msgId = currentItem->data(ROLE_MSGID).toString().toInt(); cursor.movePosition(QTextCursor::End);
HistoryMsg msg; if (cursor.columnNumber()>0)
if (rsHistory->getMessage(msgId, msg)) { cursor.insertText("\n");
textEdit->clear(); cursor.insertText(msg);
textEdit->setText(QString::fromUtf8(msg.message.c_str())); textEdit->setFocus();
textEdit->setFocus(); close();
QTextCursor cursor = textEdit->textCursor(); }
cursor.movePosition(QTextCursor::End); }
textEdit->setTextCursor(cursor);
close(); QString ImHistoryBrowser::getCurrentItemsQuotedText()
} {
} QListWidgetItem *currentItem = ui.listWidget->currentItem();
} if (currentItem) {
uint32_t msgId = currentItem->data(ROLE_MSGID).toString().toInt();
HistoryMsg msg;
if (rsHistory->getMessage(msgId, msg)) {
RsIdentityDetails details;
QString name = (rsIdentity->getIdDetails(RsGxsId(msg.peerName), details))
? QString::fromUtf8(details.mNickname.c_str())
: QString::fromUtf8(msg.peerName.c_str());
QDateTime date = msg.incoming
? QDateTime::fromTime_t(msg.sendTime)
: QDateTime::fromTime_t(msg.recvTime);
QTextDocument doc;
doc.setHtml(QString::fromUtf8(msg.message.c_str()));
return "> " + date.toString() + " " + name + ":" + doc.toPlainText().replace("\n","\n> ");
}
}
return QString();
} }

View File

@ -73,6 +73,7 @@ private:
void filterItems(const QString &text, QListWidgetItem *item = NULL); void filterItems(const QString &text, QListWidgetItem *item = NULL);
void getSelectedItems(std::list<uint32_t> &items); void getSelectedItems(std::list<uint32_t> &items);
QString getCurrentItemsQuotedText();
ImHistoryBrowserCreateItemsThread *m_createThread; ImHistoryBrowserCreateItemsThread *m_createThread;