diff --git a/retroshare-gui/src/gui/msgs/MessageComposer.cpp b/retroshare-gui/src/gui/msgs/MessageComposer.cpp index 1662ab2a8..2be5efb35 100644 --- a/retroshare-gui/src/gui/msgs/MessageComposer.cpp +++ b/retroshare-gui/src/gui/msgs/MessageComposer.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -94,6 +95,8 @@ #define STYLE_NORMAL "QLineEdit#%1 { border : none; }" #define STYLE_FAIL "QLineEdit#%1 { border : none; color : red; }" +static const uint32_t MAX_ALLOWED_GXS_MESSAGE_SIZE = 199000; + class MessageItemDelegate : public QItemDelegate { public: @@ -213,6 +216,8 @@ MessageComposer::MessageComposer(QWidget *parent, Qt::WindowFlags flags) connect(ui.friendSelectionWidget, SIGNAL(doubleClicked(int,QString)), this, SLOT(addTo())); connect(ui.friendSelectionWidget, SIGNAL(itemSelectionChanged()), this, SLOT(friendSelectionChanged())); + connect(ui.msgText, SIGNAL(textChanged()), this, SLOT(checkLength())); + /* hide the Tree +/- */ ui.msgFileList -> setRootIsDecorated( false ); @@ -352,6 +357,15 @@ MessageComposer::MessageComposer(QWidget *parent, Qt::WindowFlags flags) /* set focus to subject */ ui.titleEdit->setFocus(); + infoLabel = new QLabel( "", this ); + statusBar()->addPermanentWidget(infoLabel); + + lineLabel = new QLabel( "", this ); + statusBar()->addPermanentWidget(lineLabel); + + lengthLabel = new QLabel( "", this ); + statusBar()->addPermanentWidget(lengthLabel); + // create tag menu TagsMenu *menu = new TagsMenu (tr("Tags"), this); connect(menu, SIGNAL(aboutToShow()), this, SLOT(tagAboutToShow())); @@ -379,7 +393,7 @@ void MessageComposer::updateCells(int,int) { int rowCount = ui.recipientWidget->rowCount(); int row; - bool has_gxs = false ; + has_gxs = false ; for (row = 0; row < rowCount; ++row) { @@ -396,6 +410,7 @@ void MessageComposer::updateCells(int,int) ui.respond_to_CB->show(); ui.distantFrame->show(); ui.fromLabel->show(); + checkLength(); } else { @@ -2853,3 +2868,30 @@ void MessageComposer::sendInvite(const RsGxsId &to, bool autoSend) /* window will destroy itself! */ } +void MessageComposer::checkLength() +{ + QString text; + RsHtml::optimizeHtml(ui.msgText, text); + std::wstring msg = text.toStdWString(); + int charlength = msg.length(); + int charRemains = MAX_ALLOWED_GXS_MESSAGE_SIZE - msg.length(); + + text = tr("Message Size: %1").arg(misc::friendlyUnit(charlength)); + lengthLabel->setText(text); + + lineLabel->setText("|"); + + if(has_gxs) { + 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.actionSend->setEnabled(charRemains>=0); + infoLabel->setText(text); + } + else { + infoLabel->setText(""); + ui.actionSend->setEnabled(true); + } +} diff --git a/retroshare-gui/src/gui/msgs/MessageComposer.h b/retroshare-gui/src/gui/msgs/MessageComposer.h index c5ffb51e7..a5f6d773c 100644 --- a/retroshare-gui/src/gui/msgs/MessageComposer.h +++ b/retroshare-gui/src/gui/msgs/MessageComposer.h @@ -168,6 +168,8 @@ private slots: static QString inviteMessage(); + void checkLength(); + private: static QString buildReplyHeader(const MessageInfo &msgInfo); @@ -257,6 +259,12 @@ private: RSTreeWidgetItemCompareRole *m_compareRole; QCompleter *m_completer; + QLabel *infoLabel; + QLabel *lengthLabel; + QLabel *lineLabel; + + bool has_gxs; + /** Qt Designer generated object */ Ui::MessageComposer ui; diff --git a/retroshare-gui/src/gui/msgs/MessageWidget.cpp b/retroshare-gui/src/gui/msgs/MessageWidget.cpp index 3d92fbe9a..9b671129f 100644 --- a/retroshare-gui/src/gui/msgs/MessageWidget.cpp +++ b/retroshare-gui/src/gui/msgs/MessageWidget.cpp @@ -509,6 +509,7 @@ void MessageWidget::fill(const std::string &msgId) ui.msgText->resetImagesStatus(false); clearTagLabels(); + checkLength(); ui.inviteFrame->hide(); ui.expandFilesButton->setChecked(false); @@ -690,6 +691,7 @@ void MessageWidget::fill(const std::string &msgId) ui.filesSize->setText(QString(misc::friendlyUnit(msgInfo.size))); showTagLabels(); + checkLength(); currMsgFlags = msgInfo.msgflags; } @@ -903,3 +905,15 @@ void MessageWidget::viewSource() delete dialog; } + +void MessageWidget::checkLength() +{ + QString text; + RsHtml::optimizeHtml(ui.msgText, text); + std::wstring msg = text.toStdWString(); + int charlength = msg.length(); + + text = tr("%1 (%2) ").arg(charlength).arg(misc::friendlyUnit(charlength)); + + ui.sizeLabel->setText(text); +} \ No newline at end of file diff --git a/retroshare-gui/src/gui/msgs/MessageWidget.h b/retroshare-gui/src/gui/msgs/MessageWidget.h index 2bd630cb3..5acf627f6 100644 --- a/retroshare-gui/src/gui/msgs/MessageWidget.h +++ b/retroshare-gui/src/gui/msgs/MessageWidget.h @@ -86,6 +86,7 @@ private slots: void loadImagesAlways(); void buttonStyle(); void viewSource(); + void checkLength(); private: void clearTagLabels(); diff --git a/retroshare-gui/src/gui/msgs/MessageWidget.ui b/retroshare-gui/src/gui/msgs/MessageWidget.ui index 24373dedb..c781dc5d1 100644 --- a/retroshare-gui/src/gui/msgs/MessageWidget.ui +++ b/retroshare-gui/src/gui/msgs/MessageWidget.ui @@ -621,7 +621,7 @@ 0 - 0 + 3 0 @@ -682,6 +682,27 @@ + + + + Qt::Vertical + + + + + + + Message Size: + + + + + + + Size + + + diff --git a/retroshare-gui/src/gui/settings/NotifyPage.ui b/retroshare-gui/src/gui/settings/NotifyPage.ui index 64807a235..8237b8c3a 100755 --- a/retroshare-gui/src/gui/settings/NotifyPage.ui +++ b/retroshare-gui/src/gui/settings/NotifyPage.ui @@ -18,7 +18,7 @@ - Log + Activity