add changing state for Send button in chat when msg size exceeds allowed size (Patch from Phenom)

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7438 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2014-07-06 11:33:04 +00:00
parent 24ad4b8880
commit 8667cf9f92
9 changed files with 56 additions and 3 deletions

View File

@ -384,6 +384,7 @@ virtual int getPrivateChatQueueCount(bool incoming) = 0;
virtual bool getPrivateChatQueueIds(bool incoming, std::list<RsPeerId> &ids) = 0;
virtual bool getPrivateChatQueue(bool incoming, const RsPeerId& id, std::list<ChatInfo> &chats) = 0;
virtual bool clearPrivateChatQueue(bool incoming, const RsPeerId& id) = 0;
virtual int getMaxMessageSecuritySize() = 0;
virtual void sendStatusString(const RsPeerId& id,const std::string& status_string) = 0 ;
virtual void sendGroupChatStatusString(const std::string& status_string) = 0 ;

View File

@ -252,6 +252,11 @@ bool p3Msgs::clearPrivateChatQueue(bool incoming, const RsPeerId& id)
return mChatSrv->clearPrivateChatQueue(incoming, id);
}
int p3Msgs::getMaxMessageSecuritySize()
{
return mChatSrv->getMaxMessageSecuritySize();
}
void p3Msgs::getOwnAvatarData(unsigned char *& data,int& size)
{
mChatSrv->getOwnAvatarJpegData(data,size) ;

View File

@ -158,6 +158,11 @@ class p3Msgs: public RsMsgs
*/
virtual bool clearPrivateChatQueue(bool incoming, const RsPeerId& id);
/*!
* Return the max message size for security forwarding
*/
virtual int getMaxMessageSecuritySize();
/*!
* sends immediate status string to a specific peer, e.g. in a private chat
* @param peer_id peer to send status string to

View File

@ -82,6 +82,7 @@ static const uint32_t MAX_AVATAR_JPEG_SIZE = 32767; // Maximum size
static const uint32_t MAX_ALLOWED_LOBBIES_IN_LIST_WARNING = 50 ;
static const uint32_t MAX_MESSAGES_PER_SECONDS_NUMBER = 5 ; // max number of messages from a given peer in a window for duration below
static const uint32_t MAX_MESSAGES_PER_SECONDS_PERIOD = 10 ; // duration window for max number of messages before messages get dropped.
static const uint32_t MAX_MESSAGE_SECURITY_SIZE = 6000 ; // Max message size to forward other friends
p3ChatService::p3ChatService(p3ServiceControl *sc,p3IdService *pids, p3LinkMgr *lm, p3HistoryMgr *historyMgr)
:p3Service(), p3Config(), mChatMtx("p3ChatService"), mIdService(pids),mServiceCtrl(sc), mLinkMgr(lm) , mHistoryMgr(historyMgr)
@ -1141,12 +1142,22 @@ void p3ChatService::handleRecvChatAvatarItem(RsChatAvatarItem *ca)
RsServer::notify()->notifyPeerHasNewAvatar(ca->PeerId().toStdString()) ;
}
int p3ChatService::getMaxMessageSecuritySize()
{
return MAX_MESSAGE_SECURITY_SIZE;
}
bool p3ChatService::checkForMessageSecurity(RsChatMsgItem *ci)
{
// Remove too big messages
if (ci->message.length() > 6000 && (ci->chatFlags & RS_CHAT_FLAG_LOBBY))
if (ci->message.length() > MAX_MESSAGE_SECURITY_SIZE && (ci->chatFlags & RS_CHAT_FLAG_LOBBY))
{
ci->message = "**** Security warning: Message bigger than 6000 characters, forwarded to you by ";
std::ostringstream os;
os << getMaxMessageSecuritySize();
ci->message = "**** Security warning: Message bigger than ";
ci->message += os.str();
ci->message += " characters, forwarded to you by ";
ci->message += rsPeers->getPeerName(ci->PeerId());
ci->message += ", dropped. ****";
return false;

View File

@ -160,6 +160,11 @@ class p3ChatService: public p3Service, public p3Config, public pqiServiceMonitor
*/
bool getPrivateChatQueue(bool incoming, const RsPeerId &id, std::list<ChatInfo> &chats);
/*!
* Return the max message size for security forwarding
*/
static int getMaxMessageSecuritySize();
/*!
* Checks message security, especially remove billion laughs attacks
*/

View File

@ -131,6 +131,7 @@ ChatWidget::ChatWidget(QWidget *parent) :
connect(ui->chatTextEdit, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenu(QPoint)));
// reset text and color after removing all characters from the QTextEdit and after calling QTextEdit::clear
connect(ui->chatTextEdit, SIGNAL(currentCharFormatChanged(QTextCharFormat)), this, SLOT(chatCharFormatChanged()));
connect(ui->chatTextEdit, SIGNAL(textChanged()), this, SLOT(updateLenOfChatTextEdit()));
ui->infoFrame->setVisible(false);
ui->statusMessageLabel->hide();
@ -837,8 +838,27 @@ void ChatWidget::updateStatusTyping()
}
}
void ChatWidget::updateLenOfChatTextEdit()
{
QTextEdit *chatWidget = ui->chatTextEdit;
QString text;
RsHtml::optimizeHtml(chatWidget, text);
std::wstring msg = text.toStdWString();
bool msgToLarge = (msg.length()>=size_t(rsMsgs->getMaxMessageSecuritySize()));
ui->sendButton->setEnabled(!msgToLarge);
text = tr("%1This message counts %2 characters.").arg(msgToLarge?tr("Warning: "):"").arg(msg.length());
ui->sendButton->setToolTip(text);
ui->chatTextEdit->setToolTip(msgToLarge?text:"");
}
void ChatWidget::sendChat()
{
if (!ui->sendButton->isEnabled()){
//Something block sending
return;
}
QTextEdit *chatWidget = ui->chatTextEdit;
if (chatWidget->toPlainText().isEmpty()) {

View File

@ -152,6 +152,7 @@ private slots:
void resetFont();
void setFont();
void updateLenOfChatTextEdit();
void sendChat();
void updatePeersCustomStateString(const QString& peer_id, const QString& status_string) ;

View File

@ -689,5 +689,8 @@
<file>images/library_add.png</file>
<file>images/library64.png</file>
<file>images/library16.png</file>
<file>images/btn_red_pressed.png</file>
<file>images/btn_red_hover.png</file>
<file>images/btn_red.png</file>
</qresource>
</RCC>

View File

@ -208,8 +208,10 @@ ChatWidget QPushButton#sendButton:hover {
ChatWidget QPushButton#sendButton:pressed {
border-image: url(:/images/btn_green_pressed.png) 4;
}
ChatWidget QPushButton#sendButton:disabled {
border-image: url(:/images/btn_red.png) 4;
}
PopupChatWindow QToolBar#chattoolBar{