summaryrefslogtreecommitdiffstats
path: root/pica-client/chatwindow.cpp
diff options
context:
space:
mode:
authorme_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac>2014-08-17 17:31:32 +0000
committerme_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac>2014-08-17 17:31:32 +0000
commit402a7a84c1b0def7e776dc97243c40da1bb38a2c (patch)
tree348065b73cd34853672b3a2d78595bac78ad01d3 /pica-client/chatwindow.cpp
parent20942d8ec1c26b5755e98e245686219003888ed4 (diff)
downloadpica-pica-402a7a84c1b0def7e776dc97243c40da1bb38a2c.tar.gz
pica-pica-402a7a84c1b0def7e776dc97243c40da1bb38a2c.zip
Disallow sending empty message
git-svn-id: svn://localhost/project_picapica/trunk@325 fb96df88-216d-11de-830c-f3023f12d8ac
Diffstat (limited to 'pica-client/chatwindow.cpp')
-rw-r--r--pica-client/chatwindow.cpp34
1 files changed, 24 insertions, 10 deletions
diff --git a/pica-client/chatwindow.cpp b/pica-client/chatwindow.cpp
index 9cb1c8c..c00d0fc 100644
--- a/pica-client/chatwindow.cpp
+++ b/pica-client/chatwindow.cpp
@@ -264,21 +264,35 @@ void ChatWindow::msg_informational(QString text)
chatw->moveCursor(QTextCursor::End, QTextCursor::KeepAnchor);
}
+bool ChatWindow::isEmptyMessage(const QString &msg) const
+{
+ int size = msg.size();
+ for (int i = 0; i < size; ++i) {
+ if (!msg.at(i).isSpace()) {
+ return false;
+ }
+ }
+ return true;
+}
+
void ChatWindow::send_message()
{
- put_message(sendtextw->toPlainText(), Accounts::GetCurrentAccount().id, true);
- hist.Add(peer_id_, sendtextw->toPlainText(), true);
+ QString message = sendtextw->toPlainText();
+ if (!isEmptyMessage(message)) {
+ put_message(message, Accounts::GetCurrentAccount().id, true);
+ hist.Add(peer_id_, message, true);
- if (!hist.isOK())
- {
- QMessageBox mbx;
- mbx.setText(hist.GetLastError());
- mbx.exec();
- }
+ if (!hist.isOK())
+ {
+ QMessageBox mbx;
+ mbx.setText(hist.GetLastError());
+ mbx.exec();
+ }
- emit msg_input(sendtextw->toPlainText(), this);
+ emit msg_input(message, this);
- sendtextw->clear();
+ sendtextw->clear();
+ }
}
void ChatWindow::closeEvent(QCloseEvent *e)