From 4db979187386326df64b9359b8de5e90468f7fc3 Mon Sep 17 00:00:00 2001 From: Salanto <62221668+Salanto@users.noreply.github.com> Date: Thu, 8 May 2025 21:21:37 +0200 Subject: Close punishment dialog when the user leaves (#1097) * Close punishment dialog when the user leaves Prevents silly moments where the wrong person gets banned/kicked * Fix formatting --------- Co-authored-by: stonedDiscord --- src/widgets/playerlistwidget.cpp | 8 ++++++++ src/widgets/playerlistwidget.h | 7 +++++++ 2 files changed, 15 insertions(+) (limited to 'src/widgets') diff --git a/src/widgets/playerlistwidget.cpp b/src/widgets/playerlistwidget.cpp index c2c65574..04147b82 100644 --- a/src/widgets/playerlistwidget.cpp +++ b/src/widgets/playerlistwidget.cpp @@ -117,6 +117,7 @@ void PlayerListWidget::onCustomContextMenuRequested(const QPoint &pos) ModeratorDialog *dialog = new ModeratorDialog(id, false, ao_app); dialog->setWindowTitle(tr("Kick %1").arg(name)); connect(this, &PlayerListWidget::destroyed, dialog, &ModeratorDialog::deleteLater); + active_moderator_menu = {id, dialog}; dialog->show(); }); @@ -125,6 +126,7 @@ void PlayerListWidget::onCustomContextMenuRequested(const QPoint &pos) ModeratorDialog *dialog = new ModeratorDialog(id, true, ao_app); dialog->setWindowTitle(tr("Ban %1").arg(name)); connect(this, &PlayerListWidget::destroyed, dialog, &ModeratorDialog::deleteLater); + active_moderator_menu = {id, dialog}; dialog->show(); }); } @@ -143,6 +145,12 @@ void PlayerListWidget::addPlayer(int playerId) void PlayerListWidget::removePlayer(int playerId) { + if (active_moderator_menu.first == playerId && active_moderator_menu.second) + { + delete active_moderator_menu.second; + Q_EMIT notify("Closed Moderation Dialog : User left the server."); + } + delete takeItem(row(m_item_map.take(playerId))); m_player_map.remove(playerId); } diff --git a/src/widgets/playerlistwidget.h b/src/widgets/playerlistwidget.h index 7886e28a..6fa929db 100644 --- a/src/widgets/playerlistwidget.h +++ b/src/widgets/playerlistwidget.h @@ -5,11 +5,14 @@ #include #include #include +#include class AOApplication; +class ModeratorDialog; class PlayerListWidget : public QListWidget { + Q_OBJECT public: explicit PlayerListWidget(AOApplication *ao_app, QWidget *parent = nullptr); virtual ~PlayerListWidget(); @@ -24,6 +27,7 @@ private: AOApplication *ao_app; QMap m_player_map; QMap m_item_map; + QPair> active_moderator_menu; bool m_is_authenticated = false; void addPlayer(int playerId); @@ -34,6 +38,9 @@ private: void filterPlayerList(); +Q_SIGNALS: + void notify(const QString &messasge); + private Q_SLOTS: void onCustomContextMenuRequested(const QPoint &pos); }; -- cgit