diff --git a/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.cpp b/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.cpp index 1e1b7c43f..f10332a30 100644 --- a/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.cpp +++ b/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -103,6 +104,8 @@ CreateGxsForumMsg::CreateGxsForumMsg(const RsGxsGroupId &fId, const RsGxsMessage connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(reject())); connect(ui.emoticonButton, SIGNAL(clicked()), this, SLOT(smileyWidgetForums())); connect(ui.attachFileButton, SIGNAL(clicked()), this, SLOT(addFile())); + connect(ui.attachPictureButton, SIGNAL(clicked()), this, SLOT(addPicture())); + connect(ui.forumMessage, SIGNAL(textChanged()), this, SLOT(checkLength())); connect(ui.generateCheckBox, SIGNAL(toggled(bool)), ui.generateSpinBox, SLOT(setEnabled(bool))); setAcceptDrops(true); @@ -337,6 +340,23 @@ void CreateGxsForumMsg::loadFormInformation() //ui.forumMessage->setText(""); } +static const uint32_t MAX_ALLOWED_GXS_MESSAGE_SIZE = 199000; + +void CreateGxsForumMsg::checkLength() +{ + QString text; + RsHtml::optimizeHtml(ui.forumMessage, 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); + else + text = tr("Warning: This message is too big of %1 characters after HTML conversion.").arg((0-charRemains)); + ui.buttonBox->button(QDialogButtonBox::Ok)->setToolTip(text); + ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(charRemains>=0); + ui.infoLabel->setText(text); +} + void CreateGxsForumMsg::createMsg() { QString name = misc::removeNewLine(ui.forumSubject->text()); @@ -489,6 +509,18 @@ void CreateGxsForumMsg::addFile() } } +void CreateGxsForumMsg::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); + ui.forumMessage->textCursor().insertFragment(fragment); + } + } +} + void CreateGxsForumMsg::fileHashingFinished(QList hashedFiles) { //std::cerr << "CreateGxsForumMsg::fileHashingFinished() started." << std::endl; diff --git a/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.h b/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.h index 3b551bda0..4951795c1 100644 --- a/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.h +++ b/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.h @@ -51,6 +51,8 @@ private slots: void smileyWidgetForums(); void addSmileys(); void addFile(); + void addPicture(); + void checkLength(); void reject(); protected: diff --git a/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.ui b/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.ui index 37b11b308..4c6838558 100644 --- a/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.ui +++ b/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.ui @@ -200,6 +200,29 @@ + + + + Qt::NoFocus + + + Attach a Picture + + + + :/icons/png/attach-image.png:/icons/png/attach-image.png + + + + 24 + 24 + + + + true + + + @@ -259,6 +282,13 @@ p, li { white-space: pre-wrap; } + + + + + + + @@ -268,7 +298,7 @@ p, li { white-space: pre-wrap; } Attach files via drag and drop - + @@ -369,6 +399,7 @@ p, li { white-space: pre-wrap; } +