mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-27 16:39:29 -05:00
Merge pull request #2215 from defnax/checkmessage
Added to show the message length on Composer and Message Widget
This commit is contained in:
commit
2f1b4e1995
@ -22,6 +22,7 @@
|
||||
#include <QMessageBox>
|
||||
#include <QCloseEvent>
|
||||
#include <QClipboard>
|
||||
#include <QLabel>
|
||||
#include <QTextCodec>
|
||||
#include <QPrintDialog>
|
||||
#include <QPrinter>
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
}
|
@ -86,6 +86,7 @@ private slots:
|
||||
void loadImagesAlways();
|
||||
void buttonStyle();
|
||||
void viewSource();
|
||||
void checkLength();
|
||||
|
||||
private:
|
||||
void clearTagLabels();
|
||||
|
@ -621,7 +621,7 @@
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
@ -682,6 +682,27 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Message Size:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="sizeLabel">
|
||||
<property name="text">
|
||||
<string>Size</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="filesHSpacer">
|
||||
<property name="orientation">
|
||||
|
@ -18,7 +18,7 @@
|
||||
</property>
|
||||
<widget class="QWidget" name="tabFeed">
|
||||
<attribute name="title">
|
||||
<string>Log</string>
|
||||
<string>Activity</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="tabFeedVLayout">
|
||||
<item>
|
||||
|
Loading…
Reference in New Issue
Block a user