1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
#include "moderator_dialog.h"
#include "aoapplication.h"
#include "gui_utils.h"
#include "options.h"
#include <QDebug>
#include <QFile>
#include <QMessageBox>
#include <QUiLoader>
#include <QVBoxLayout>
const QString ModeratorDialog::UI_FILE_PATH = "moderator_action_dialog.ui";
ModeratorDialog::ModeratorDialog(int clientId, bool ban, AOApplication *ao_app, QWidget *parent)
: QWidget{parent}
, ao_app(ao_app)
, m_client_id(clientId)
, m_ban(ban)
{
QFile file(Options::getInstance().getUIAsset(UI_FILE_PATH));
if (!file.open(QFile::ReadOnly))
{
qFatal("Unable to open file %s", qPrintable(file.fileName()));
return;
}
QUiLoader loader;
ui_widget = loader.load(&file, this);
auto layout = new QVBoxLayout(this);
layout->addWidget(ui_widget);
FROM_UI(QComboBox, action);
FROM_UI(QSpinBox, duration);
FROM_UI(QLabel, duration_label);
FROM_UI(QCheckBox, permanent);
FROM_UI(QTextEdit, details);
FROM_UI(QDialogButtonBox, button_box);
if (m_ban)
{
ui_action->addItem(tr("Ban"));
}
else
{
ui_action->addItem(tr("Kick"));
}
ui_duration->setVisible(m_ban);
ui_duration_label->setVisible(m_ban);
ui_permanent->setVisible(m_ban);
connect(ui_button_box, &QDialogButtonBox::accepted, this, &ModeratorDialog::onAcceptedClicked);
connect(ui_button_box, &QDialogButtonBox::rejected, this, &ModeratorDialog::close);
}
ModeratorDialog::~ModeratorDialog()
{}
void ModeratorDialog::onAcceptedClicked()
{
QString reason = ui_details->toPlainText();
if (reason.isEmpty())
{
if (QMessageBox::question(this, tr("Confirmation"), tr("Are you sure you want to confirm without a reason?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
{
return;
}
}
bool permanent = ui_permanent->isChecked();
if (permanent)
{
if (QMessageBox::question(this, tr("Confirmation"), tr("Are you sure you want to ban permanently?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
{
return;
}
}
QStringList arglist;
arglist.append(QString::number(m_client_id));
if (m_ban)
{
if (permanent)
{
arglist.append("-1");
}
else
{
arglist.append(QString::number(ui_duration->value()));
}
}
else
{
arglist.append("0");
}
arglist.append(reason);
ao_app->send_server_packet(AOPacket("MA", arglist));
close();
}
|