| 71 | } |
| 72 | |
| 73 | void ChatWidget::sendChatMessage() { |
| 74 | QString line = input()->text(); |
| 75 | if (line.isEmpty()) { |
| 76 | // Ignore empty lines. |
| 77 | } else if (line.startsWith('/')) { |
| 78 | vector<string> words; |
| 79 | auto utf8 = QStringView{line}.mid(1).toUtf8(); |
| 80 | auto sv = std::string_view{utf8.constData(), |
| 81 | static_cast<size_t>(utf8.size())}; |
| 82 | split(words, sv, is_any_of(" ")); |
| 83 | if (words.size() == 2 && words[0] == "setName") { |
| 84 | auto name = QString::fromUtf8(words[1]); |
| 85 | if (!name.isEmpty()) |
| 86 | name_ = name; |
| 87 | } else { |
| 88 | print("*** list of commands:\n" |
| 89 | "/setName <new name>\n"); |
| 90 | } |
| 91 | } else { |
| 92 | auto msg = name_; |
| 93 | msg += ": "; |
| 94 | msg += line; |
| 95 | print("<you>: " + input()->text()); |
| 96 | if (publisher_) { |
| 97 | publisher_->push(msg); |
| 98 | } |
| 99 | } |
| 100 | input()->setText(QString()); |
| 101 | } |
| 102 | |
| 103 | void ChatWidget::changeName() { |
| 104 | auto name = QInputDialog::getText(this, "Change Name", |