diff options
| author | EXL <exlmotodev@gmail.com> | 2014-08-13 04:20:11 +0700 |
|---|---|---|
| committer | EXL <exlmotodev@gmail.com> | 2014-08-14 03:14:26 +0700 |
| commit | 51e579c2278c12ea04bc16b69051ce4a6de47632 (patch) | |
| tree | 348065b73cd34853672b3a2d78595bac78ad01d3 | |
| parent | 20942d8ec1c26b5755e98e245686219003888ed4 (diff) | |
| download | pica-pica-51e579c2278c12ea04bc16b69051ce4a6de47632.tar.gz pica-pica-51e579c2278c12ea04bc16b69051ce4a6de47632.zip | |
Disallow sending empty message
| -rw-r--r-- | pica-client/chatwindow.cpp | 34 | ||||
| -rw-r--r-- | pica-client/chatwindow.h | 1 |
2 files changed, 25 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) diff --git a/pica-client/chatwindow.h b/pica-client/chatwindow.h index 73a053e..a099130 100644 --- a/pica-client/chatwindow.h +++ b/pica-client/chatwindow.h @@ -60,6 +60,7 @@ private: QPushButton *btAddCtBlacklist; QLabel *lbAddCtQuestion; + bool isEmptyMessage(const QString &msg) const; void put_message(QString msg, QByteArray id, bool is_me); int draw_message(QString msg, QString nickname, QString datetime, QString color, bool is_delivered); void print_history(QList<History::HistoryRecord> H); |
