From 0528246cf9aedbb5e87c15228497f8b52188f777 Mon Sep 17 00:00:00 2001 From: defnax Date: Sun, 16 Jan 2022 15:00:37 +0100 Subject: [PATCH 1/5] Added preview for picture file attachments in forums --- .../src/gui/gxsforums/CreateGxsForumMsg.cpp | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.cpp b/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.cpp index ffbcb2493..600dfeacc 100644 --- a/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.cpp +++ b/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.cpp @@ -568,11 +568,43 @@ void CreateGxsForumMsg::fileHashingFinished(QList hashedFiles) QList::iterator it; for (it = hashedFiles.begin(); it != hashedFiles.end(); ++it) { HashedFile& hashedFile = *it; + QString ext = QFileInfo(hashedFile.filename).suffix().toUpper(); + RetroShareLink link = RetroShareLink::createFile(hashedFile.filename, hashedFile.size, QString::fromStdString(hashedFile.hash.toStdString())); - if (link.valid()) { - mesgString += link.toHtmlSize() + "
"; + + if (hashedFile.flag & HashedFile::Picture) { + mesgString += QString("").arg(hashedFile.filepath); + mesgString += "
"; + } else { + bool preview = false; + if(hashedFiles.size()==1 && (ext == "JPG" || ext == "PNG" || ext == "JPEG" || ext == "GIF" || ext == "WEBP")) + { + QString encodedImage; + uint32_t maxMessageSize = 32000; + if (RsHtml::makeEmbeddedImage(hashedFile.filepath, encodedImage, 640*480, maxMessageSize - 200 - link.toHtmlSize().length())) + { QTextDocumentFragment fragment = QTextDocumentFragment::fromHtml(encodedImage); + ui.forumMessage->textCursor().insertFragment(fragment); + preview=true; + } + } + if(!preview) + { + QString image = FilesDefs::getImageFromFilename(hashedFile.filename, false); + if (!image.isEmpty()) { + mesgString += QString("").arg(image); + //mesgString +="
"; + } + } + + if (preview) + { + mesgString += "
" + link.toHtmlSize() + "
"; + } else { + mesgString += link.toHtmlSize() + "
"; + } } + } if (!mesgString.isEmpty()) { From b13411ac457d0d13bf42475210b2b7868145c327 Mon Sep 17 00:00:00 2001 From: defnax Date: Sun, 16 Jan 2022 17:33:17 +0100 Subject: [PATCH 2/5] cleanup code --- .../src/gui/gxsforums/CreateGxsForumMsg.cpp | 47 ++++++++----------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.cpp b/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.cpp index 600dfeacc..0c3669c6d 100644 --- a/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.cpp +++ b/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.cpp @@ -573,36 +573,27 @@ void CreateGxsForumMsg::fileHashingFinished(QList hashedFiles) RetroShareLink link = RetroShareLink::createFile(hashedFile.filename, hashedFile.size, QString::fromStdString(hashedFile.hash.toStdString())); - if (hashedFile.flag & HashedFile::Picture) { - mesgString += QString("").arg(hashedFile.filepath); - mesgString += "
"; - } else { - bool preview = false; - if(hashedFiles.size()==1 && (ext == "JPG" || ext == "PNG" || ext == "JPEG" || ext == "GIF" || ext == "WEBP")) - { - QString encodedImage; - uint32_t maxMessageSize = 32000; - if (RsHtml::makeEmbeddedImage(hashedFile.filepath, encodedImage, 640*480, maxMessageSize - 200 - link.toHtmlSize().length())) - { QTextDocumentFragment fragment = QTextDocumentFragment::fromHtml(encodedImage); - ui.forumMessage->textCursor().insertFragment(fragment); - preview=true; - } + bool preview = false; + if(hashedFiles.size()==1 && (ext == "JPG" || ext == "PNG" || ext == "JPEG" || ext == "GIF" || ext == "WEBP")) + { + QString encodedImage; + uint32_t maxImageSize = 32000; + if (RsHtml::makeEmbeddedImage(hashedFile.filepath, encodedImage, 320*240, maxImageSize - 200 - link.toHtmlSize().length())) + { QTextDocumentFragment fragment = QTextDocumentFragment::fromHtml(encodedImage); + ui.forumMessage->textCursor().insertFragment(fragment); + preview=true; } - if(!preview) - { - QString image = FilesDefs::getImageFromFilename(hashedFile.filename, false); - if (!image.isEmpty()) { - mesgString += QString("").arg(image); - //mesgString +="
"; - } - } - - if (preview) - { - mesgString += "
" + link.toHtmlSize() + "
"; - } else { - mesgString += link.toHtmlSize() + "
"; + } + if(!preview) + { + QString image = FilesDefs::getImageFromFilename(hashedFile.filename, false); + if (!image.isEmpty()) { + mesgString += QString("").arg(image); } + mesgString += link.toHtmlSize() + "
"; + } else + { + mesgString += "
" + link.toHtmlSize() + "
"; } } From 6bcecec93fbe1ebff64c535f1560c2d4f25fb812 Mon Sep 17 00:00:00 2001 From: defnax Date: Sun, 16 Jan 2022 18:44:51 +0100 Subject: [PATCH 3/5] Fixed in Chat window to add a enter when a preview picture is attached --- retroshare-gui/src/gui/chat/ChatWidget.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/retroshare-gui/src/gui/chat/ChatWidget.cpp b/retroshare-gui/src/gui/chat/ChatWidget.cpp index a909e3e27..efd7265b5 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.cpp +++ b/retroshare-gui/src/gui/chat/ChatWidget.cpp @@ -1698,9 +1698,11 @@ void ChatWidget::fileHashingFinished(QList hashedFiles) if (!image.isEmpty()) { message += QString("").arg(image); } + message += link.toHtmlSize(); + } else { + message += "
" + link.toHtmlSize(); } } - message += link.toHtmlSize(); if (it != hashedFiles.end()) { message += "
"; From d508a8ea200d34294ad4b380e6265466e4dd7af6 Mon Sep 17 00:00:00 2001 From: defnax Date: Sun, 16 Jan 2022 20:32:08 +0100 Subject: [PATCH 4/5] Added to check if link is valid --- .../src/gui/gxsforums/CreateGxsForumMsg.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.cpp b/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.cpp index 0c3669c6d..ea05927cc 100644 --- a/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.cpp +++ b/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.cpp @@ -590,10 +590,13 @@ void CreateGxsForumMsg::fileHashingFinished(QList hashedFiles) if (!image.isEmpty()) { mesgString += QString("").arg(image); } - mesgString += link.toHtmlSize() + "
"; - } else - { - mesgString += "
" + link.toHtmlSize() + "
"; + if (link.valid()) { + mesgString += link.toHtmlSize() + "
"; + } + } else { + if (link.valid()) { + mesgString += "
" + link.toHtmlSize() + "
"; + } } } From f770f1fc8e175b95ae13d7ddf29548af53e4c17e Mon Sep 17 00:00:00 2001 From: defnax Date: Tue, 18 Jan 2022 18:51:48 +0100 Subject: [PATCH 5/5] Added a valid link check --- retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.cpp b/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.cpp index ea05927cc..ebf23f716 100644 --- a/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.cpp +++ b/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.cpp @@ -578,10 +578,12 @@ void CreateGxsForumMsg::fileHashingFinished(QList hashedFiles) { QString encodedImage; uint32_t maxImageSize = 32000; - if (RsHtml::makeEmbeddedImage(hashedFile.filepath, encodedImage, 320*240, maxImageSize - 200 - link.toHtmlSize().length())) - { QTextDocumentFragment fragment = QTextDocumentFragment::fromHtml(encodedImage); - ui.forumMessage->textCursor().insertFragment(fragment); - preview=true; + if (link.valid()){ + if (RsHtml::makeEmbeddedImage(hashedFile.filepath, encodedImage, 320*240, maxImageSize - 200 - link.toHtmlSize().length())) + { QTextDocumentFragment fragment = QTextDocumentFragment::fromHtml(encodedImage); + ui.forumMessage->textCursor().insertFragment(fragment); + preview=true; + } } } if(!preview)