From 3fc478bc4f5ec8e0b32c8a93ef1637f9549f600b Mon Sep 17 00:00:00 2001 From: argoneus Date: Mon, 6 Aug 2018 00:43:57 +0200 Subject: [PATCH] refactored modcall reason, added check for empty text --- courtroom.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index f6935ba..b3c3ba2 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -2019,21 +2019,26 @@ void Courtroom::on_spectator_clicked() void Courtroom::on_call_mod_clicked() { if (ao_app->modcall_reason_enabled) { - auto box = new QInputDialog(); - box->setLabelText("Enter a reason:"); - auto code = box->exec(); + QMessageBox errorBox; + QInputDialog input; - if (code != QDialog::Accepted) { - delete box; + input.setWindowFlags(Qt::WindowSystemMenuHint); + input.setLabelText("Reason:"); + input.setWindowTitle("Call Moderator"); + auto code = input.exec(); + + if (code != QDialog::Accepted) + return; + + QString text = input.textValue(); + if (text.isEmpty()) { + errorBox.critical(nullptr, "Error", "You must provide a reason."); + return; + } else if (text.length() > 256) { + errorBox.critical(nullptr, "Error", "The message is too long."); return; } - auto text = box->textValue(); - if (text.isEmpty()) - text = "N/A"; - - delete box; - QStringList mod_reason; mod_reason.append(text);