mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-21 09:05:10 -07:00
[UserList] Refactor: split dialog code to separate file (#7189)
Some checks are pending
CodeQL / Analyze (cpp) (push) Waiting to run
CodeQL / Analyze (actions) (push) Waiting to run
Build Desktop / Configure (push) Waiting to run
Build Desktop / Debian 13 (push) Blocked by required conditions
Build Desktop / Debian 12 (push) Blocked by required conditions
Build Desktop / Fedora 44 (push) Blocked by required conditions
Build Desktop / Fedora 43 (push) Blocked by required conditions
Build Desktop / Servatrice_Debian 12 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 (push) Blocked by required conditions
Build Desktop / Ubuntu 24.04 (push) Blocked by required conditions
Build Desktop / Arch (push) Blocked by required conditions
Build Desktop / macOS 13 Intel (push) Blocked by required conditions
Build Desktop / macOS 14 (push) Blocked by required conditions
Build Desktop / macOS 15 (push) Blocked by required conditions
Build Desktop / macOS 26 Debug (push) Blocked by required conditions
Build Desktop / Windows 10 (push) Blocked by required conditions
Build Docker / Servatrice (arm) (push) Waiting to run
Build Docker / Servatrice (x86) (push) Waiting to run
Build Docker / Publish multi-platform Servatrice image (push) Blocked by required conditions
Some checks are pending
CodeQL / Analyze (cpp) (push) Waiting to run
CodeQL / Analyze (actions) (push) Waiting to run
Build Desktop / Configure (push) Waiting to run
Build Desktop / Debian 13 (push) Blocked by required conditions
Build Desktop / Debian 12 (push) Blocked by required conditions
Build Desktop / Fedora 44 (push) Blocked by required conditions
Build Desktop / Fedora 43 (push) Blocked by required conditions
Build Desktop / Servatrice_Debian 12 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 (push) Blocked by required conditions
Build Desktop / Ubuntu 24.04 (push) Blocked by required conditions
Build Desktop / Arch (push) Blocked by required conditions
Build Desktop / macOS 13 Intel (push) Blocked by required conditions
Build Desktop / macOS 14 (push) Blocked by required conditions
Build Desktop / macOS 15 (push) Blocked by required conditions
Build Desktop / macOS 26 Debug (push) Blocked by required conditions
Build Desktop / Windows 10 (push) Blocked by required conditions
Build Docker / Servatrice (arm) (push) Waiting to run
Build Docker / Servatrice (x86) (push) Waiting to run
Build Docker / Publish multi-platform Servatrice image (push) Blocked by required conditions
This commit is contained in:
parent
0a09884c78
commit
83833f4684
6 changed files with 387 additions and 390 deletions
|
|
@ -271,6 +271,7 @@ set(cockatrice_SOURCES
|
|||
src/interface/widgets/server/user/user_context_menu.cpp
|
||||
src/interface/widgets/server/user/user_info_box.cpp
|
||||
src/interface/widgets/server/user/user_info_connection.cpp
|
||||
src/interface/widgets/server/user/user_list_dialog.cpp
|
||||
src/interface/widgets/server/user/user_list_manager.cpp
|
||||
src/interface/widgets/server/user/user_list_painter.cpp
|
||||
src/interface/widgets/server/user/user_list_panel_widget.cpp
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@
|
|||
#include "../chat_view/chat_view.h"
|
||||
#include "../game_selector.h"
|
||||
#include "user_info_box.h"
|
||||
#include "user_list_dialog.h"
|
||||
#include "user_list_manager.h"
|
||||
#include "user_list_proxy.h"
|
||||
#include "user_list_widget.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,302 @@
|
|||
#include "user_list_dialog.h"
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QGroupBox>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QMessageBox>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QPushButton>
|
||||
#include <QRadioButton>
|
||||
#include <QSpinBox>
|
||||
#include <QVBoxLayout>
|
||||
#include <libcockatrice/utility/string_limits.h>
|
||||
|
||||
BanDialog::BanDialog(const ServerInfo_User &info, QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
nameBanCheckBox = new QCheckBox(tr("ban &user name"));
|
||||
nameBanCheckBox->setChecked(true);
|
||||
nameBanEdit = new QLineEdit(QString::fromStdString(info.name()));
|
||||
nameBanEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
ipBanCheckBox = new QCheckBox(tr("ban &IP address"));
|
||||
ipBanCheckBox->setChecked(true);
|
||||
ipBanEdit = new QLineEdit(QString::fromStdString(info.address()));
|
||||
ipBanEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
idBanCheckBox = new QCheckBox(tr("ban client I&D"));
|
||||
idBanCheckBox->setChecked(true);
|
||||
idBanEdit = new QLineEdit(QString::fromStdString(info.clientid()));
|
||||
idBanEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
if (QString::fromStdString(info.clientid()).isEmpty()) {
|
||||
idBanCheckBox->setChecked(false);
|
||||
}
|
||||
|
||||
QGridLayout *banTypeGrid = new QGridLayout;
|
||||
banTypeGrid->addWidget(nameBanCheckBox, 0, 0);
|
||||
banTypeGrid->addWidget(nameBanEdit, 0, 1);
|
||||
banTypeGrid->addWidget(ipBanCheckBox, 1, 0);
|
||||
banTypeGrid->addWidget(ipBanEdit, 1, 1);
|
||||
banTypeGrid->addWidget(idBanCheckBox, 2, 0);
|
||||
banTypeGrid->addWidget(idBanEdit, 2, 1);
|
||||
QGroupBox *banTypeGroupBox = new QGroupBox(tr("Ban type"));
|
||||
banTypeGroupBox->setLayout(banTypeGrid);
|
||||
|
||||
permanentRadio = new QRadioButton(tr("&permanent ban"));
|
||||
temporaryRadio = new QRadioButton(tr("&temporary ban"));
|
||||
temporaryRadio->setChecked(true);
|
||||
connect(temporaryRadio, &QRadioButton::toggled, this, &BanDialog::enableTemporaryEdits);
|
||||
daysLabel = new QLabel(tr("&Days:"));
|
||||
daysEdit = new QSpinBox;
|
||||
daysEdit->setMinimum(0);
|
||||
daysEdit->setValue(0);
|
||||
daysEdit->setMaximum(10000);
|
||||
daysLabel->setBuddy(daysEdit);
|
||||
hoursLabel = new QLabel(tr("&Hours:"));
|
||||
hoursEdit = new QSpinBox;
|
||||
hoursEdit->setMinimum(0);
|
||||
hoursEdit->setValue(0);
|
||||
hoursEdit->setMaximum(24);
|
||||
hoursLabel->setBuddy(hoursEdit);
|
||||
minutesLabel = new QLabel(tr("&Minutes:"));
|
||||
minutesEdit = new QSpinBox;
|
||||
minutesEdit->setMinimum(0);
|
||||
minutesEdit->setValue(5);
|
||||
minutesEdit->setMaximum(60);
|
||||
minutesLabel->setBuddy(minutesEdit);
|
||||
QGridLayout *durationLayout = new QGridLayout;
|
||||
durationLayout->addWidget(permanentRadio, 0, 0, 1, 6);
|
||||
durationLayout->addWidget(temporaryRadio, 1, 0, 1, 6);
|
||||
durationLayout->addWidget(daysLabel, 2, 0);
|
||||
durationLayout->addWidget(daysEdit, 2, 1);
|
||||
durationLayout->addWidget(hoursLabel, 2, 2);
|
||||
durationLayout->addWidget(hoursEdit, 2, 3);
|
||||
durationLayout->addWidget(minutesLabel, 2, 4);
|
||||
durationLayout->addWidget(minutesEdit, 2, 5);
|
||||
QGroupBox *durationGroupBox = new QGroupBox(tr("Duration of the ban"));
|
||||
durationGroupBox->setLayout(durationLayout);
|
||||
|
||||
QLabel *reasonLabel = new QLabel(tr("Please enter the reason for the ban.\n"
|
||||
"This is only saved for moderators and cannot be seen by the banned person."));
|
||||
reasonEdit = new QPlainTextEdit;
|
||||
|
||||
QLabel *visibleReasonLabel =
|
||||
new QLabel(tr("Please enter the reason for the ban that will be visible to the banned person."));
|
||||
visibleReasonEdit = new QPlainTextEdit;
|
||||
|
||||
deleteMessages = new QCheckBox(tr("Redact all messages from this user in all rooms"));
|
||||
|
||||
QPushButton *okButton = new QPushButton(tr("&OK"));
|
||||
okButton->setAutoDefault(true);
|
||||
connect(okButton, &QPushButton::clicked, this, &BanDialog::okClicked);
|
||||
QPushButton *cancelButton = new QPushButton(tr("&Cancel"));
|
||||
connect(cancelButton, &QPushButton::clicked, this, &BanDialog::reject);
|
||||
|
||||
QHBoxLayout *buttonLayout = new QHBoxLayout;
|
||||
buttonLayout->addStretch();
|
||||
buttonLayout->addWidget(okButton);
|
||||
buttonLayout->addWidget(cancelButton);
|
||||
|
||||
QVBoxLayout *vbox = new QVBoxLayout;
|
||||
vbox->addWidget(banTypeGroupBox);
|
||||
vbox->addWidget(durationGroupBox);
|
||||
vbox->addWidget(reasonLabel);
|
||||
vbox->addWidget(reasonEdit);
|
||||
vbox->addWidget(visibleReasonLabel);
|
||||
vbox->addWidget(visibleReasonEdit);
|
||||
vbox->addWidget(deleteMessages);
|
||||
vbox->addLayout(buttonLayout);
|
||||
|
||||
setLayout(vbox);
|
||||
setWindowTitle(tr("Ban user from server"));
|
||||
}
|
||||
|
||||
WarningDialog::WarningDialog(const QString &userName, const QString &clientID, QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
descriptionLabel = new QLabel(tr("Which warning would you like to send?"));
|
||||
nameWarning = new QLineEdit(userName);
|
||||
nameWarning->setMaxLength(MAX_NAME_LENGTH);
|
||||
warnClientID = new QLineEdit(clientID);
|
||||
warnClientID->setMaxLength(MAX_NAME_LENGTH);
|
||||
warningOption = new QComboBox();
|
||||
warningOption->addItem("", "");
|
||||
|
||||
deleteMessages = new QCheckBox(tr("Redact all messages from this user in all rooms"));
|
||||
|
||||
QPushButton *okButton = new QPushButton(tr("&OK"));
|
||||
okButton->setAutoDefault(true);
|
||||
connect(okButton, &QPushButton::clicked, this, &WarningDialog::okClicked);
|
||||
QPushButton *cancelButton = new QPushButton(tr("&Cancel"));
|
||||
connect(cancelButton, &QPushButton::clicked, this, &WarningDialog::reject);
|
||||
|
||||
QHBoxLayout *buttonLayout = new QHBoxLayout;
|
||||
buttonLayout->addStretch();
|
||||
buttonLayout->addWidget(okButton);
|
||||
buttonLayout->addWidget(cancelButton);
|
||||
|
||||
QVBoxLayout *vbox = new QVBoxLayout;
|
||||
vbox->addWidget(descriptionLabel);
|
||||
vbox->addWidget(nameWarning);
|
||||
vbox->addWidget(warningOption);
|
||||
vbox->addWidget(deleteMessages);
|
||||
vbox->addLayout(buttonLayout);
|
||||
setLayout(vbox);
|
||||
setWindowTitle(tr("Warn user for misconduct"));
|
||||
}
|
||||
|
||||
void WarningDialog::okClicked()
|
||||
{
|
||||
if (nameWarning->text().simplified().isEmpty()) {
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
tr("User name to send a warning to can not be blank, please specify a user to warn."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (warningOption->currentData().toString().simplified().isEmpty()) {
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
tr("Warning to use can not be blank, please select a valid warning to send."));
|
||||
return;
|
||||
}
|
||||
|
||||
accept();
|
||||
}
|
||||
|
||||
QString WarningDialog::getName() const
|
||||
{
|
||||
return nameWarning->text().simplified();
|
||||
}
|
||||
|
||||
QString WarningDialog::getWarnID() const
|
||||
{
|
||||
return warnClientID->text().simplified();
|
||||
}
|
||||
|
||||
QString WarningDialog::getReason() const
|
||||
{
|
||||
return warningOption->currentData().toString().simplified();
|
||||
}
|
||||
|
||||
int WarningDialog::getDeleteMessages() const
|
||||
{
|
||||
return deleteMessages->isChecked() ? -1 : 0;
|
||||
}
|
||||
|
||||
void WarningDialog::addWarningOption(const QString &warning, int startingIl)
|
||||
{
|
||||
if (startingIl > 1) {
|
||||
warningOption->addItem(tr("%1 (IL %2)").arg(warning).arg(startingIl), warning);
|
||||
} else {
|
||||
warningOption->addItem(warning, warning);
|
||||
}
|
||||
}
|
||||
|
||||
void BanDialog::okClicked()
|
||||
{
|
||||
if (!nameBanCheckBox->isChecked() && !ipBanCheckBox->isChecked() && !idBanCheckBox->isChecked()) {
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
tr("You have to select a name-based, IP-based, clientId based, or some combination of "
|
||||
"the three to place a ban."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (nameBanCheckBox->isChecked()) {
|
||||
if (nameBanEdit->text().simplified() == "") {
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
tr("You must have a value in the name ban when selecting the name ban checkbox."));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (ipBanCheckBox->isChecked()) {
|
||||
if (ipBanEdit->text().simplified() == "") {
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
tr("You must have a value in the ip ban when selecting the ip ban checkbox."));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (idBanCheckBox->isChecked()) {
|
||||
if (idBanEdit->text().simplified() == "") {
|
||||
QMessageBox::critical(
|
||||
this, tr("Error"),
|
||||
tr("You must have a value in the clientid ban when selecting the clientid ban checkbox."));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
accept();
|
||||
}
|
||||
|
||||
void BanDialog::enableTemporaryEdits(bool enabled)
|
||||
{
|
||||
daysLabel->setEnabled(enabled);
|
||||
daysEdit->setEnabled(enabled);
|
||||
hoursLabel->setEnabled(enabled);
|
||||
hoursEdit->setEnabled(enabled);
|
||||
minutesLabel->setEnabled(enabled);
|
||||
minutesEdit->setEnabled(enabled);
|
||||
}
|
||||
|
||||
QString BanDialog::getBanId() const
|
||||
{
|
||||
return idBanCheckBox->isChecked() ? idBanEdit->text() : QString();
|
||||
}
|
||||
|
||||
QString BanDialog::getBanName() const
|
||||
{
|
||||
return nameBanCheckBox->isChecked() ? nameBanEdit->text() : QString();
|
||||
}
|
||||
|
||||
QString BanDialog::getBanIP() const
|
||||
{
|
||||
return ipBanCheckBox->isChecked() ? ipBanEdit->text() : QString();
|
||||
}
|
||||
|
||||
int BanDialog::getMinutes() const
|
||||
{
|
||||
return permanentRadio->isChecked() ? 0
|
||||
: (daysEdit->value() * 24 * 60 + hoursEdit->value() * 60 + minutesEdit->value());
|
||||
}
|
||||
|
||||
QString BanDialog::getReason() const
|
||||
{
|
||||
return reasonEdit->toPlainText();
|
||||
}
|
||||
|
||||
QString BanDialog::getVisibleReason() const
|
||||
{
|
||||
return visibleReasonEdit->toPlainText();
|
||||
}
|
||||
|
||||
int BanDialog::getDeleteMessages() const
|
||||
{
|
||||
return deleteMessages->isChecked() ? -1 : 0;
|
||||
}
|
||||
|
||||
AdminNotesDialog::AdminNotesDialog(const QString &_userName, const QString &_notes, QWidget *_parent)
|
||||
: QDialog(_parent), userName(_userName)
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
auto *updateButton = new QPushButton(tr("Update Notes"));
|
||||
updateButton->setEnabled(false);
|
||||
connect(updateButton, &QPushButton::clicked, this, &AdminNotesDialog::accept);
|
||||
|
||||
notes = new QPlainTextEdit(_notes);
|
||||
notes->setMinimumWidth(500);
|
||||
connect(notes, &QPlainTextEdit::textChanged, this, [=]() { updateButton->setEnabled(true); });
|
||||
|
||||
auto *vbox = new QVBoxLayout;
|
||||
vbox->addWidget(notes);
|
||||
vbox->addWidget(updateButton);
|
||||
|
||||
setLayout(vbox);
|
||||
setWindowTitle(tr("Admin Notes for %1").arg(_userName));
|
||||
}
|
||||
|
||||
QString AdminNotesDialog::getNotes() const
|
||||
{
|
||||
return notes->toPlainText();
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
#ifndef COCKATRICE_USER_LIST_DIALOG_H
|
||||
#define COCKATRICE_USER_LIST_DIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <libcockatrice/protocol/pb/serverinfo_user.pb.h>
|
||||
|
||||
class QComboBox;
|
||||
class QLabel;
|
||||
class QPlainTextEdit;
|
||||
class QRadioButton;
|
||||
class QSpinBox;
|
||||
class QLineEdit;
|
||||
class QCheckBox;
|
||||
|
||||
class BanDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QLabel *daysLabel, *hoursLabel, *minutesLabel;
|
||||
QCheckBox *nameBanCheckBox, *ipBanCheckBox, *idBanCheckBox, *deleteMessages;
|
||||
QLineEdit *nameBanEdit, *ipBanEdit, *idBanEdit;
|
||||
QSpinBox *daysEdit, *hoursEdit, *minutesEdit;
|
||||
QRadioButton *permanentRadio, *temporaryRadio;
|
||||
QPlainTextEdit *reasonEdit, *visibleReasonEdit;
|
||||
|
||||
private slots:
|
||||
void okClicked();
|
||||
void enableTemporaryEdits(bool enabled);
|
||||
|
||||
public:
|
||||
explicit BanDialog(const ServerInfo_User &info, QWidget *parent = nullptr);
|
||||
[[nodiscard]] QString getBanName() const;
|
||||
[[nodiscard]] QString getBanIP() const;
|
||||
[[nodiscard]] QString getBanId() const;
|
||||
[[nodiscard]] int getMinutes() const;
|
||||
[[nodiscard]] QString getReason() const;
|
||||
[[nodiscard]] QString getVisibleReason() const;
|
||||
[[nodiscard]] int getDeleteMessages() const;
|
||||
};
|
||||
|
||||
class WarningDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QLabel *descriptionLabel;
|
||||
QLineEdit *nameWarning;
|
||||
QComboBox *warningOption;
|
||||
QLineEdit *warnClientID;
|
||||
QCheckBox *deleteMessages;
|
||||
|
||||
private slots:
|
||||
void okClicked();
|
||||
|
||||
public:
|
||||
WarningDialog(const QString &userName, const QString &clientID, QWidget *parent = nullptr);
|
||||
[[nodiscard]] QString getName() const;
|
||||
[[nodiscard]] QString getWarnID() const;
|
||||
[[nodiscard]] QString getReason() const;
|
||||
[[nodiscard]] int getDeleteMessages() const;
|
||||
void addWarningOption(const QString &warning, int startingIl = 1);
|
||||
};
|
||||
|
||||
class AdminNotesDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QString userName;
|
||||
QPlainTextEdit *notes;
|
||||
|
||||
public:
|
||||
explicit AdminNotesDialog(const QString &_userName, const QString &_notes, QWidget *_parent = nullptr);
|
||||
[[nodiscard]] QString getName() const
|
||||
{
|
||||
return userName;
|
||||
}
|
||||
[[nodiscard]] QString getNotes() const;
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_USER_LIST_DIALOG_H
|
||||
|
|
@ -1,335 +1,21 @@
|
|||
#include "user_list_widget.h"
|
||||
|
||||
#include "../../../../client/settings/cache_settings.h"
|
||||
#include "../../../card_picture_loader/card_picture_loader.h"
|
||||
#include "../../cards/art_crop_attribution.h"
|
||||
#include "../../interface/pixel_map_generator.h"
|
||||
#include "../../interface/theme_manager.h"
|
||||
#include "../../interface/widgets/tabs/tab_account.h"
|
||||
#include "../../interface/widgets/tabs/tab_supervisor.h"
|
||||
#include "../game_selector.h"
|
||||
#include "user_context_menu.h"
|
||||
#include "user_list_painter.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QCheckBox>
|
||||
#include <QCursor>
|
||||
#include <QFont>
|
||||
#include <QFontMetrics>
|
||||
#include <QFrame>
|
||||
#include <QHBoxLayout>
|
||||
#include <QEvent>
|
||||
#include <QHeaderView>
|
||||
#include <QInputDialog>
|
||||
#include <QKeyEvent>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QPainterPath>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QPushButton>
|
||||
#include <QRadioButton>
|
||||
#include <QScreen>
|
||||
#include <QSignalBlocker>
|
||||
#include <QSpinBox>
|
||||
#include <QWidget>
|
||||
#include <libcockatrice/card/database/card_database_manager.h>
|
||||
#include <libcockatrice/network/client/abstract/abstract_client.h>
|
||||
#include <libcockatrice/protocol/pb/response_get_games_of_user.pb.h>
|
||||
#include <libcockatrice/protocol/pb/response_get_user_info.pb.h>
|
||||
#include <libcockatrice/protocol/pending_command.h>
|
||||
#include <QScrollBar>
|
||||
#include <QTimer>
|
||||
#include <QVBoxLayout>
|
||||
#include <libcockatrice/settings/appearance_settings.h>
|
||||
#include <libcockatrice/utility/string_limits.h>
|
||||
|
||||
BanDialog::BanDialog(const ServerInfo_User &info, QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
nameBanCheckBox = new QCheckBox(tr("ban &user name"));
|
||||
nameBanCheckBox->setChecked(true);
|
||||
nameBanEdit = new QLineEdit(QString::fromStdString(info.name()));
|
||||
nameBanEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
ipBanCheckBox = new QCheckBox(tr("ban &IP address"));
|
||||
ipBanCheckBox->setChecked(true);
|
||||
ipBanEdit = new QLineEdit(QString::fromStdString(info.address()));
|
||||
ipBanEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
idBanCheckBox = new QCheckBox(tr("ban client I&D"));
|
||||
idBanCheckBox->setChecked(true);
|
||||
idBanEdit = new QLineEdit(QString::fromStdString(info.clientid()));
|
||||
idBanEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
if (QString::fromStdString(info.clientid()).isEmpty()) {
|
||||
idBanCheckBox->setChecked(false);
|
||||
}
|
||||
|
||||
QGridLayout *banTypeGrid = new QGridLayout;
|
||||
banTypeGrid->addWidget(nameBanCheckBox, 0, 0);
|
||||
banTypeGrid->addWidget(nameBanEdit, 0, 1);
|
||||
banTypeGrid->addWidget(ipBanCheckBox, 1, 0);
|
||||
banTypeGrid->addWidget(ipBanEdit, 1, 1);
|
||||
banTypeGrid->addWidget(idBanCheckBox, 2, 0);
|
||||
banTypeGrid->addWidget(idBanEdit, 2, 1);
|
||||
QGroupBox *banTypeGroupBox = new QGroupBox(tr("Ban type"));
|
||||
banTypeGroupBox->setLayout(banTypeGrid);
|
||||
|
||||
permanentRadio = new QRadioButton(tr("&permanent ban"));
|
||||
temporaryRadio = new QRadioButton(tr("&temporary ban"));
|
||||
temporaryRadio->setChecked(true);
|
||||
connect(temporaryRadio, &QRadioButton::toggled, this, &BanDialog::enableTemporaryEdits);
|
||||
daysLabel = new QLabel(tr("&Days:"));
|
||||
daysEdit = new QSpinBox;
|
||||
daysEdit->setMinimum(0);
|
||||
daysEdit->setValue(0);
|
||||
daysEdit->setMaximum(10000);
|
||||
daysLabel->setBuddy(daysEdit);
|
||||
hoursLabel = new QLabel(tr("&Hours:"));
|
||||
hoursEdit = new QSpinBox;
|
||||
hoursEdit->setMinimum(0);
|
||||
hoursEdit->setValue(0);
|
||||
hoursEdit->setMaximum(24);
|
||||
hoursLabel->setBuddy(hoursEdit);
|
||||
minutesLabel = new QLabel(tr("&Minutes:"));
|
||||
minutesEdit = new QSpinBox;
|
||||
minutesEdit->setMinimum(0);
|
||||
minutesEdit->setValue(5);
|
||||
minutesEdit->setMaximum(60);
|
||||
minutesLabel->setBuddy(minutesEdit);
|
||||
QGridLayout *durationLayout = new QGridLayout;
|
||||
durationLayout->addWidget(permanentRadio, 0, 0, 1, 6);
|
||||
durationLayout->addWidget(temporaryRadio, 1, 0, 1, 6);
|
||||
durationLayout->addWidget(daysLabel, 2, 0);
|
||||
durationLayout->addWidget(daysEdit, 2, 1);
|
||||
durationLayout->addWidget(hoursLabel, 2, 2);
|
||||
durationLayout->addWidget(hoursEdit, 2, 3);
|
||||
durationLayout->addWidget(minutesLabel, 2, 4);
|
||||
durationLayout->addWidget(minutesEdit, 2, 5);
|
||||
QGroupBox *durationGroupBox = new QGroupBox(tr("Duration of the ban"));
|
||||
durationGroupBox->setLayout(durationLayout);
|
||||
|
||||
QLabel *reasonLabel = new QLabel(tr("Please enter the reason for the ban.\nThis is only saved for moderators and "
|
||||
"cannot be seen by the banned person."));
|
||||
reasonEdit = new QPlainTextEdit;
|
||||
|
||||
QLabel *visibleReasonLabel =
|
||||
new QLabel(tr("Please enter the reason for the ban that will be visible to the banned person."));
|
||||
visibleReasonEdit = new QPlainTextEdit;
|
||||
|
||||
deleteMessages = new QCheckBox(tr("Redact all messages from this user in all rooms"));
|
||||
|
||||
QPushButton *okButton = new QPushButton(tr("&OK"));
|
||||
okButton->setAutoDefault(true);
|
||||
connect(okButton, &QPushButton::clicked, this, &BanDialog::okClicked);
|
||||
QPushButton *cancelButton = new QPushButton(tr("&Cancel"));
|
||||
connect(cancelButton, &QPushButton::clicked, this, &BanDialog::reject);
|
||||
|
||||
QHBoxLayout *buttonLayout = new QHBoxLayout;
|
||||
buttonLayout->addStretch();
|
||||
buttonLayout->addWidget(okButton);
|
||||
buttonLayout->addWidget(cancelButton);
|
||||
|
||||
QVBoxLayout *vbox = new QVBoxLayout;
|
||||
vbox->addWidget(banTypeGroupBox);
|
||||
vbox->addWidget(durationGroupBox);
|
||||
vbox->addWidget(reasonLabel);
|
||||
vbox->addWidget(reasonEdit);
|
||||
vbox->addWidget(visibleReasonLabel);
|
||||
vbox->addWidget(visibleReasonEdit);
|
||||
vbox->addWidget(deleteMessages);
|
||||
vbox->addLayout(buttonLayout);
|
||||
|
||||
setLayout(vbox);
|
||||
setWindowTitle(tr("Ban user from server"));
|
||||
}
|
||||
|
||||
WarningDialog::WarningDialog(const QString userName, const QString clientID, QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
descriptionLabel = new QLabel(tr("Which warning would you like to send?"));
|
||||
nameWarning = new QLineEdit(userName);
|
||||
nameWarning->setMaxLength(MAX_NAME_LENGTH);
|
||||
warnClientID = new QLineEdit(clientID);
|
||||
warnClientID->setMaxLength(MAX_NAME_LENGTH);
|
||||
warningOption = new QComboBox();
|
||||
warningOption->addItem("", "");
|
||||
|
||||
deleteMessages = new QCheckBox(tr("Redact all messages from this user in all rooms"));
|
||||
|
||||
QPushButton *okButton = new QPushButton(tr("&OK"));
|
||||
okButton->setAutoDefault(true);
|
||||
connect(okButton, &QPushButton::clicked, this, &WarningDialog::okClicked);
|
||||
QPushButton *cancelButton = new QPushButton(tr("&Cancel"));
|
||||
connect(cancelButton, &QPushButton::clicked, this, &WarningDialog::reject);
|
||||
|
||||
QHBoxLayout *buttonLayout = new QHBoxLayout;
|
||||
buttonLayout->addStretch();
|
||||
buttonLayout->addWidget(okButton);
|
||||
buttonLayout->addWidget(cancelButton);
|
||||
|
||||
QVBoxLayout *vbox = new QVBoxLayout;
|
||||
vbox->addWidget(descriptionLabel);
|
||||
vbox->addWidget(nameWarning);
|
||||
vbox->addWidget(warningOption);
|
||||
vbox->addWidget(deleteMessages);
|
||||
vbox->addLayout(buttonLayout);
|
||||
setLayout(vbox);
|
||||
setWindowTitle(tr("Warn user for misconduct"));
|
||||
}
|
||||
|
||||
void WarningDialog::okClicked()
|
||||
{
|
||||
if (nameWarning->text().simplified().isEmpty()) {
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
tr("User name to send a warning to can not be blank, please specify a user to warn."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (warningOption->currentData().toString().simplified().isEmpty()) {
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
tr("Warning to use can not be blank, please select a valid warning to send."));
|
||||
return;
|
||||
}
|
||||
|
||||
accept();
|
||||
}
|
||||
|
||||
QString WarningDialog::getName() const
|
||||
{
|
||||
return nameWarning->text().simplified();
|
||||
}
|
||||
|
||||
QString WarningDialog::getWarnID() const
|
||||
{
|
||||
return warnClientID->text().simplified();
|
||||
}
|
||||
|
||||
QString WarningDialog::getReason() const
|
||||
{
|
||||
return warningOption->currentData().toString().simplified();
|
||||
}
|
||||
|
||||
int WarningDialog::getDeleteMessages() const
|
||||
{
|
||||
return deleteMessages->isChecked() ? -1 : 0;
|
||||
}
|
||||
|
||||
void WarningDialog::addWarningOption(const QString warning, int startingIl)
|
||||
{
|
||||
if (startingIl > 1) {
|
||||
warningOption->addItem(tr("%1 (IL %2)").arg(warning).arg(startingIl), warning);
|
||||
} else {
|
||||
warningOption->addItem(warning, warning);
|
||||
}
|
||||
}
|
||||
|
||||
void BanDialog::okClicked()
|
||||
{
|
||||
if (!nameBanCheckBox->isChecked() && !ipBanCheckBox->isChecked() && !idBanCheckBox->isChecked()) {
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
tr("You have to select a name-based, IP-based, clientId based, or some combination of "
|
||||
"the three to place a ban."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (nameBanCheckBox->isChecked()) {
|
||||
if (nameBanEdit->text().simplified() == "") {
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
tr("You must have a value in the name ban when selecting the name ban checkbox."));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (ipBanCheckBox->isChecked()) {
|
||||
if (ipBanEdit->text().simplified() == "") {
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
tr("You must have a value in the ip ban when selecting the ip ban checkbox."));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (idBanCheckBox->isChecked()) {
|
||||
if (idBanEdit->text().simplified() == "") {
|
||||
QMessageBox::critical(
|
||||
this, tr("Error"),
|
||||
tr("You must have a value in the clientid ban when selecting the clientid ban checkbox."));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
accept();
|
||||
}
|
||||
|
||||
void BanDialog::enableTemporaryEdits(bool enabled)
|
||||
{
|
||||
daysLabel->setEnabled(enabled);
|
||||
daysEdit->setEnabled(enabled);
|
||||
hoursLabel->setEnabled(enabled);
|
||||
hoursEdit->setEnabled(enabled);
|
||||
minutesLabel->setEnabled(enabled);
|
||||
minutesEdit->setEnabled(enabled);
|
||||
}
|
||||
|
||||
QString BanDialog::getBanId() const
|
||||
{
|
||||
return idBanCheckBox->isChecked() ? idBanEdit->text() : QString();
|
||||
}
|
||||
|
||||
QString BanDialog::getBanName() const
|
||||
{
|
||||
return nameBanCheckBox->isChecked() ? nameBanEdit->text() : QString();
|
||||
}
|
||||
|
||||
QString BanDialog::getBanIP() const
|
||||
{
|
||||
return ipBanCheckBox->isChecked() ? ipBanEdit->text() : QString();
|
||||
}
|
||||
|
||||
int BanDialog::getMinutes() const
|
||||
{
|
||||
return permanentRadio->isChecked() ? 0
|
||||
: (daysEdit->value() * 24 * 60 + hoursEdit->value() * 60 + minutesEdit->value());
|
||||
}
|
||||
|
||||
QString BanDialog::getReason() const
|
||||
{
|
||||
return reasonEdit->toPlainText();
|
||||
}
|
||||
|
||||
QString BanDialog::getVisibleReason() const
|
||||
{
|
||||
return visibleReasonEdit->toPlainText();
|
||||
}
|
||||
|
||||
int BanDialog::getDeleteMessages() const
|
||||
{
|
||||
return deleteMessages->isChecked() ? -1 : 0;
|
||||
}
|
||||
|
||||
AdminNotesDialog::AdminNotesDialog(const QString &_userName, const QString &_notes, QWidget *_parent)
|
||||
: QDialog(_parent), userName(_userName)
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
auto *updateButton = new QPushButton(tr("Update Notes"));
|
||||
updateButton->setEnabled(false);
|
||||
connect(updateButton, &QPushButton::clicked, this, &AdminNotesDialog::accept);
|
||||
|
||||
notes = new QPlainTextEdit(_notes);
|
||||
notes->setMinimumWidth(500);
|
||||
connect(notes, &QPlainTextEdit::textChanged, this, [=]() { updateButton->setEnabled(true); });
|
||||
|
||||
auto *vbox = new QVBoxLayout;
|
||||
vbox->addWidget(notes);
|
||||
vbox->addWidget(updateButton);
|
||||
|
||||
setLayout(vbox);
|
||||
setWindowTitle(tr("Admin Notes for %1").arg(_userName));
|
||||
}
|
||||
|
||||
QString AdminNotesDialog::getNotes() const
|
||||
{
|
||||
return notes->toPlainText();
|
||||
}
|
||||
|
||||
namespace UserListRoles
|
||||
{
|
||||
|
|
|
|||
|
|
@ -16,95 +16,24 @@
|
|||
#include "user_list_painter.h"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QDialog>
|
||||
#include <QGroupBox>
|
||||
#include <QQueue>
|
||||
#include <QSet>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QTextEdit>
|
||||
#include <QTreeWidgetItem>
|
||||
#include <functional>
|
||||
#include <libcockatrice/network/server/remote/user_level.h>
|
||||
#include <libcockatrice/protocol/pb/moderator_commands.pb.h>
|
||||
|
||||
class QTreeWidget;
|
||||
class ServerInfo_User;
|
||||
class AbstractClient;
|
||||
class TabSupervisor;
|
||||
class QLabel;
|
||||
class QCheckBox;
|
||||
class QSpinBox;
|
||||
class QRadioButton;
|
||||
class QPlainTextEdit;
|
||||
class Response;
|
||||
class CommandContainer;
|
||||
class UserContextMenu;
|
||||
class UserListWidget;
|
||||
class QShowEvent;
|
||||
|
||||
class BanDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
QLabel *daysLabel, *hoursLabel, *minutesLabel;
|
||||
QCheckBox *nameBanCheckBox, *ipBanCheckBox, *idBanCheckBox, *deleteMessages;
|
||||
QLineEdit *nameBanEdit, *ipBanEdit, *idBanEdit;
|
||||
QSpinBox *daysEdit, *hoursEdit, *minutesEdit;
|
||||
QRadioButton *permanentRadio, *temporaryRadio;
|
||||
QPlainTextEdit *reasonEdit, *visibleReasonEdit;
|
||||
private slots:
|
||||
void okClicked();
|
||||
void enableTemporaryEdits(bool enabled);
|
||||
|
||||
public:
|
||||
explicit BanDialog(const ServerInfo_User &info, QWidget *parent = nullptr);
|
||||
[[nodiscard]] QString getBanName() const;
|
||||
[[nodiscard]] QString getBanIP() const;
|
||||
[[nodiscard]] QString getBanId() const;
|
||||
[[nodiscard]] int getMinutes() const;
|
||||
[[nodiscard]] QString getReason() const;
|
||||
[[nodiscard]] QString getVisibleReason() const;
|
||||
[[nodiscard]] int getDeleteMessages() const;
|
||||
};
|
||||
|
||||
class WarningDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
QLabel *descriptionLabel;
|
||||
QLineEdit *nameWarning;
|
||||
QComboBox *warningOption;
|
||||
QLineEdit *warnClientID;
|
||||
QCheckBox *deleteMessages;
|
||||
private slots:
|
||||
void okClicked();
|
||||
|
||||
public:
|
||||
WarningDialog(const QString userName, const QString clientID, QWidget *parent = nullptr);
|
||||
[[nodiscard]] QString getName() const;
|
||||
[[nodiscard]] QString getWarnID() const;
|
||||
[[nodiscard]] QString getReason() const;
|
||||
[[nodiscard]] int getDeleteMessages() const;
|
||||
void addWarningOption(const QString warning, int startingIl = 1);
|
||||
};
|
||||
|
||||
class AdminNotesDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
QString userName;
|
||||
QPlainTextEdit *notes;
|
||||
|
||||
public:
|
||||
explicit AdminNotesDialog(const QString &_userName, const QString &_notes, QWidget *_parent = nullptr);
|
||||
[[nodiscard]] QString getName() const
|
||||
{
|
||||
return userName;
|
||||
}
|
||||
[[nodiscard]] QString getNotes() const;
|
||||
};
|
||||
|
||||
class UserListItemDelegate : public QStyledItemDelegate
|
||||
{
|
||||
QTreeWidget *tree;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue