From 836a872fd63f74d06f9b5d9f11fe9535d525c9b6 Mon Sep 17 00:00:00 2001 From: defnax Date: Mon, 18 Nov 2019 18:52:27 +0100 Subject: [PATCH] Added for Channel Messages to checkt the length --- .../gui/gxschannels/CreateGxsChannelMsg.cpp | 36 ++++++++++- .../src/gui/gxschannels/CreateGxsChannelMsg.h | 2 + .../gui/gxschannels/CreateGxsChannelMsg.ui | 62 ++++++++++++------- 3 files changed, 77 insertions(+), 23 deletions(-) diff --git a/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp b/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp index 66e871fd1..fa038f7fc 100644 --- a/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp +++ b/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include "CreateGxsChannelMsg.h" #include "gui/gxs/GxsIdDetails.h" @@ -72,7 +73,8 @@ CreateGxsChannelMsg::CreateGxsChannelMsg(const RsGxsGroupId &cId, RsGxsMessageId connect(thumbNailCb, SIGNAL(toggled(bool)), this, SLOT(allowAutoMediaThumbNail(bool))); connect(tabWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenu(QPoint))); connect(generateCheckBox, SIGNAL(toggled(bool)), generateSpinBox, SLOT(setEnabled(bool))); - + connect(addPictureButton, SIGNAL(clicked()), this, SLOT(addPicture())); + connect(msgEdit, SIGNAL(textChanged()), this, SLOT(checkLength())); generateSpinBox->setEnabled(false); thumbNailCb->setVisible(false); @@ -94,6 +96,26 @@ CreateGxsChannelMsg::CreateGxsChannelMsg(const RsGxsGroupId &cId, RsGxsMessageId #endif } +static const uint32_t MAX_ALLOWED_GXS_MESSAGE_SIZE = 199000; + +void CreateGxsChannelMsg::checkLength() +{ + QString text; + RsHtml::optimizeHtml(msgEdit, text); + std::wstring msg = text.toStdWString(); + int charRemains = MAX_ALLOWED_GXS_MESSAGE_SIZE - msg.length(); + if(charRemains >= 0) { + text = tr("It remains %1 characters after HTML conversion.").arg(charRemains); + infoLabel->setStyleSheet("QLabel#infoLabel { }"); + }else{ + text = tr("Warning: This message is too big of %1 characters after HTML conversion.").arg((0-charRemains)); + infoLabel->setStyleSheet("QLabel#infoLabel {color: red; font: bold; }"); + } + buttonBox->button(QDialogButtonBox::Ok)->setToolTip(text); + buttonBox->button(QDialogButtonBox::Ok)->setEnabled(charRemains>=0); + infoLabel->setText(text); +} + CreateGxsChannelMsg::~CreateGxsChannelMsg() { Settings->saveWidgetInformation(this); @@ -741,6 +763,18 @@ void CreateGxsChannelMsg::addThumbnail() thumbnail_label->setPixmap(picture); } +void CreateGxsChannelMsg::addPicture() +{ + QString file; + if (misc::getOpenFileName(window(), RshareSettings::LASTDIR_IMAGES, tr("Load Picture File"), "Pictures (*.png *.xpm *.jpg *.jpeg)", file)) { + QString encodedImage; + if (RsHtml::makeEmbeddedImage(file, encodedImage, 640*480, MAX_ALLOWED_GXS_MESSAGE_SIZE - 200)) { + QTextDocumentFragment fragment = QTextDocumentFragment::fromHtml(encodedImage); + msgEdit->textCursor().insertFragment(fragment); + } + } +} + void CreateGxsChannelMsg::loadChannelPostInfo(const uint32_t &token) { #ifdef DEBUG_CREATE_GXS_MSG diff --git a/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.h b/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.h index bb8f15518..96b9dd6d3 100644 --- a/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.h +++ b/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.h @@ -69,6 +69,8 @@ private slots: void contextMenu(QPoint) ; void addThumbnail(); + void addPicture(); + void checkLength(); void allowAutoMediaThumbNail(bool); private: diff --git a/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.ui b/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.ui index 3f4cd7d4b..8b53c93d6 100644 --- a/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.ui +++ b/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.ui @@ -6,8 +6,8 @@ 0 0 - 875 - 659 + 671 + 513 @@ -96,19 +96,6 @@ - - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2'; font-size:10pt; font-weight:600;">Attachments:</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><img src=":/images/feedback_arrow.png" /><span style=" font-family:'MS Shell Dlg 2'; font-size:8pt;"> Use Drag and Drop / Add Files button, to Hash new files.</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><img src=":/images/feedback_arrow.png" /><span style=" font-family:'MS Shell Dlg 2'; font-size:8pt;"> Copy/Paste RetroShare links from your shares</span></p></body></html> - - - @@ -131,6 +118,30 @@ p, li { white-space: pre-wrap; } + + + + Add Picture + + + + :/images/add_image24.png:/images/add_image24.png + + + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2'; font-size:10pt; font-weight:600;">Attachments:</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><img src=":/images/feedback_arrow.png" /><span style=" font-family:'MS Shell Dlg 2'; font-size:8pt;"> Use Drag and Drop / Add Files button, to Hash new files.</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><img src=":/images/feedback_arrow.png" /><span style=" font-family:'MS Shell Dlg 2'; font-size:8pt;"> Copy/Paste RetroShare links from your shares</span></p></body></html> + + + @@ -194,6 +205,13 @@ p, li { white-space: pre-wrap; } + + + + + + + @@ -302,8 +320,8 @@ p, li { white-space: pre-wrap; } 0 0 - 767 - 42 + 812 + 24 @@ -390,17 +408,17 @@ p, li { white-space: pre-wrap; } + + MimeTextEdit + QTextEdit +
gui/common/MimeTextEdit.h
+
HeaderFrame QFrame
gui/common/HeaderFrame.h
1
- - MimeTextEdit - QTextEdit -
gui/common/MimeTextEdit.h
-