From 2dc69cb0007a17292ed944845c96895a106fea50 Mon Sep 17 00:00:00 2001 From: RetroPooh Date: Fri, 27 Apr 2018 16:50:00 +0300 Subject: [PATCH] embed preview for images on file attach in chat --- retroshare-gui/src/gui/chat/ChatWidget.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/retroshare-gui/src/gui/chat/ChatWidget.cpp b/retroshare-gui/src/gui/chat/ChatWidget.cpp index 2859527cd..9aff65a64 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.cpp +++ b/retroshare-gui/src/gui/chat/ChatWidget.cpp @@ -1598,7 +1598,7 @@ void ChatWidget::fileHashingFinished(QList hashedFiles) QList::iterator it; for (it = hashedFiles.begin(); it != hashedFiles.end(); ++it) { HashedFile& hashedFile = *it; - //QString ext = QFileInfo(hashedFile.filename).suffix(); + QString ext = QFileInfo(hashedFile.filename).suffix().toUpper(); RetroShareLink link; @@ -1610,9 +1610,23 @@ void ChatWidget::fileHashingFinished(QList hashedFiles) message += QString("").arg(hashedFile.filepath); message+="
"; } else { - QString image = FilesDefs::getImageFromFilename(hashedFile.filename, false); - if (!image.isEmpty()) { - message += QString("").arg(image); + bool preview = false; + if(hashedFiles.size()==1 && (ext == "JPG" || ext == "PNG" || ext == "JPEG" || ext == "GIF")) + { + QString encodedImage; + uint32_t maxMessageSize = this->maxMessageSize(); + if (RsHtml::makeEmbeddedImage(hashedFile.filepath, encodedImage, 640*480, maxMessageSize - 200 - link.toHtmlSize().length())) + { QTextDocumentFragment fragment = QTextDocumentFragment::fromHtml(encodedImage); + ui->chatTextEdit->textCursor().insertFragment(fragment); + preview=true; + } + } + if(!preview) + { + QString image = FilesDefs::getImageFromFilename(hashedFile.filename, false); + if (!image.isEmpty()) { + message += QString("").arg(image); + } } } message += link.toHtmlSize();