mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-28 17:09:34 -05:00
Merge pull request #1707 from defnax/added-message-length-check-for-Channels
Added message length check for channels
This commit is contained in:
commit
583f9db3b5
@ -24,6 +24,7 @@
|
||||
#include <QMenu>
|
||||
#include <QDir>
|
||||
#include <QMimeData>
|
||||
#include <QTextDocumentFragment>
|
||||
|
||||
#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
|
||||
|
@ -69,6 +69,8 @@ private slots:
|
||||
void contextMenu(QPoint) ;
|
||||
|
||||
void addThumbnail();
|
||||
void addPicture();
|
||||
void checkLength();
|
||||
void allowAutoMediaThumbNail(bool);
|
||||
|
||||
private:
|
||||
|
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>875</width>
|
||||
<height>659</height>
|
||||
<width>671</width>
|
||||
<height>513</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="acceptDrops">
|
||||
@ -96,19 +96,6 @@
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<layout class="QGridLayout" name="channelAttachGLayout">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QLabel" name="channelAttachLabel">
|
||||
<property name="text">
|
||||
<string><!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></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="addfilepushButton">
|
||||
<property name="text">
|
||||
@ -131,6 +118,30 @@ p, li { white-space: pre-wrap; }
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QPushButton" name="addPictureButton">
|
||||
<property name="text">
|
||||
<string>Add Picture</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/add_image24.png</normaloff>:/images/add_image24.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="3">
|
||||
<widget class="QLabel" name="channelAttachLabel">
|
||||
<property name="text">
|
||||
<string><!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></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
@ -194,6 +205,13 @@ p, li { white-space: pre-wrap; }
|
||||
<item>
|
||||
<widget class="MimeTextEdit" name="msgEdit"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="infoLabel">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
@ -302,8 +320,8 @@ p, li { white-space: pre-wrap; }
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>767</width>
|
||||
<height>42</height>
|
||||
<width>812</width>
|
||||
<height>24</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
@ -390,17 +408,17 @@ p, li { white-space: pre-wrap; }
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>MimeTextEdit</class>
|
||||
<extends>QTextEdit</extends>
|
||||
<header location="global">gui/common/MimeTextEdit.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>HeaderFrame</class>
|
||||
<extends>QFrame</extends>
|
||||
<header>gui/common/HeaderFrame.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>MimeTextEdit</class>
|
||||
<extends>QTextEdit</extends>
|
||||
<header location="global">gui/common/MimeTextEdit.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../images.qrc"/>
|
||||
|
Loading…
Reference in New Issue
Block a user