author | unC0Rr |
Sun, 12 Feb 2023 15:10:10 +0100 | |
branch | transitional_engine |
changeset 15919 | 659c92124c26 |
parent 15255 | 2dc98f688c65 |
permissions | -rw-r--r-- |
5078
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
1 |
/* |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
2 |
* Hedgewars, a free turn based strategy game |
11046 | 3 |
* Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
5078
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
4 |
* |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
7 |
* the Free Software Foundation; version 2 of the License |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
8 |
* |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
13 |
* |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
9998
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
5078
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
17 |
*/ |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
18 |
|
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
19 |
#include <QGridLayout> |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
20 |
#include <QLabel> |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
21 |
#include <QLineEdit> |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
22 |
#include <QSpinBox> |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
23 |
#include <QPushButton> |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
24 |
#include <QTextBrowser> |
8157 | 25 |
#include <QTableWidget> |
26 |
#include <QHeaderView> |
|
5078
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
27 |
|
5204 | 28 |
#include "pageadmin.h" |
5078
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
29 |
#include "chatwidget.h" |
8157 | 30 |
#include "bandialog.h" |
5078
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
31 |
|
6042
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6010
diff
changeset
|
32 |
QLayout * PageAdmin::bodyLayoutDefinition() |
5078
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
33 |
{ |
8157 | 34 |
QVBoxLayout * pageLayout = new QVBoxLayout(); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6180
diff
changeset
|
35 |
|
8157 | 36 |
QTabWidget * tabs = new QTabWidget(this); |
37 |
pageLayout->addWidget(tabs); |
|
38 |
QWidget * page1 = new QWidget(this); |
|
39 |
QWidget * page2 = new QWidget(this); |
|
40 |
tabs->addTab(page1, tr("General")); |
|
41 |
tabs->addTab(page2, tr("Bans")); |
|
42 |
||
43 |
// page 1 |
|
44 |
{ |
|
45 |
QGridLayout * tab1Layout = new QGridLayout(page1); |
|
46 |
||
47 |
// 0 |
|
48 |
pbAsk = addButton(tr("Fetch data"), tab1Layout, 0, 0, 1, 3); |
|
5078
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
49 |
|
8157 | 50 |
// 1 |
51 |
QLabel * lblSMN = new QLabel(this); |
|
52 |
lblSMN->setText(tr("Server message for latest version:")); |
|
53 |
tab1Layout->addWidget(lblSMN, 1, 0); |
|
54 |
||
55 |
leServerMessageNew = new QLineEdit(this); |
|
56 |
tab1Layout->addWidget(leServerMessageNew, 1, 1); |
|
5078
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
57 |
|
8157 | 58 |
// 2 |
59 |
QLabel * lblSMO = new QLabel(this); |
|
60 |
lblSMO->setText(tr("Server message for previous versions:")); |
|
61 |
tab1Layout->addWidget(lblSMO, 2, 0); |
|
62 |
||
63 |
leServerMessageOld = new QLineEdit(this); |
|
64 |
tab1Layout->addWidget(leServerMessageOld, 2, 1); |
|
5078
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
65 |
|
8157 | 66 |
// 3 |
67 |
QLabel * lblP = new QLabel(this); |
|
68 |
lblP->setText(tr("Latest version protocol number:")); |
|
69 |
tab1Layout->addWidget(lblP, 3, 0); |
|
70 |
||
71 |
sbProtocol = new QSpinBox(this); |
|
72 |
tab1Layout->addWidget(sbProtocol, 3, 1); |
|
5078
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
73 |
|
8157 | 74 |
// 4 |
75 |
QLabel * lblPreview = new QLabel(this); |
|
13676
05fde8e30041
Add a few translator comments for frontend strings
Wuzzy <Wuzzy2@mail.ru>
parents:
12897
diff
changeset
|
76 |
//: MOTD = Message Of The Day, the message which is shown to players joining the server |
8157 | 77 |
lblPreview->setText(tr("MOTD preview:")); |
78 |
tab1Layout->addWidget(lblPreview, 4, 0); |
|
5078
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
79 |
|
8157 | 80 |
tb = new QTextBrowser(this); |
81 |
tb->setOpenExternalLinks(true); |
|
82 |
tb->document()->setDefaultStyleSheet(HWChatWidget::styleSheet()); |
|
83 |
tab1Layout->addWidget(tb, 4, 1, 1, 2); |
|
84 |
||
85 |
// 5 |
|
86 |
pbClearAccountsCache = addButton(tr("Clear Accounts Cache"), tab1Layout, 5, 0); |
|
87 |
||
88 |
// 6 |
|
89 |
pbSetSM = addButton(tr("Set data"), tab1Layout, 6, 0, 1, 3); |
|
90 |
} |
|
5078
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
91 |
|
8157 | 92 |
// page 2 |
93 |
{ |
|
94 |
QGridLayout * tab2Layout = new QGridLayout(page2); |
|
95 |
twBans = new QTableWidget(this); |
|
96 |
twBans->setColumnCount(3); |
|
97 |
twBans->setHorizontalHeaderLabels(QStringList() |
|
13676
05fde8e30041
Add a few translator comments for frontend strings
Wuzzy <Wuzzy2@mail.ru>
parents:
12897
diff
changeset
|
98 |
//: IP = short for "IP address" (Internet Protocol). Nick = short for "nick name" |
8157 | 99 |
<< tr("IP/Nick") |
100 |
<< tr("Expiration") |
|
101 |
<< tr("Reason") |
|
102 |
); |
|
12897
fc47fc4af6bd
Finish porting. Seems to work, but no thorough testing has been performed
unc0rr
parents:
11046
diff
changeset
|
103 |
twBans->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch); |
15255
2dc98f688c65
Bans list: Remove vertical header, make horizontal header non-clickable
Wuzzy <Wuzzy2@mail.ru>
parents:
13676
diff
changeset
|
104 |
twBans->horizontalHeader()->setSectionsClickable(false); |
2dc98f688c65
Bans list: Remove vertical header, make horizontal header non-clickable
Wuzzy <Wuzzy2@mail.ru>
parents:
13676
diff
changeset
|
105 |
twBans->verticalHeader()->hide(); |
8157 | 106 |
twBans->setEditTriggers(QAbstractItemView::NoEditTriggers); |
107 |
twBans->setSelectionBehavior(QAbstractItemView::SelectRows); |
|
108 |
twBans->setSelectionMode(QAbstractItemView::SingleSelection); |
|
109 |
twBans->setAlternatingRowColors(true); |
|
110 |
tab2Layout->addWidget(twBans, 0, 1, 4, 1); |
|
5078
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
111 |
|
8157 | 112 |
QPushButton * btnRefresh = addButton(tr("Refresh"), tab2Layout, 0, 0); |
113 |
QPushButton * btnAdd = addButton(tr("Add"), tab2Layout, 1, 0); |
|
114 |
QPushButton * btnRemove = addButton(tr("Remove"), tab2Layout, 2, 0); |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6180
diff
changeset
|
115 |
|
8157 | 116 |
connect(btnRefresh, SIGNAL(clicked()), this, SIGNAL(bansListRequest())); |
117 |
connect(btnRefresh, SIGNAL(clicked()), this, SLOT(onRefreshClicked())); |
|
118 |
connect(btnAdd, SIGNAL(clicked()), this, SLOT(onAddClicked())); |
|
119 |
connect(btnRemove, SIGNAL(clicked()), this, SLOT(onRemoveClicked())); |
|
120 |
} |
|
5078
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
121 |
|
6042
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6010
diff
changeset
|
122 |
return pageLayout; |
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6010
diff
changeset
|
123 |
} |
6009 | 124 |
|
6042
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6010
diff
changeset
|
125 |
void PageAdmin::connectSignals() |
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6010
diff
changeset
|
126 |
{ |
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6010
diff
changeset
|
127 |
connect(pbAsk, SIGNAL(clicked()), this, SIGNAL(askServerVars())); |
6680 | 128 |
connect(leServerMessageNew, SIGNAL(textChanged(QString)), tb, SLOT(setHtml(const QString &))); |
129 |
connect(leServerMessageOld, SIGNAL(textChanged(QString)), tb, SLOT(setHtml(const QString &))); |
|
6042
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6010
diff
changeset
|
130 |
connect(pbClearAccountsCache, SIGNAL(clicked()), this, SIGNAL(clearAccountsCache())); |
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6010
diff
changeset
|
131 |
connect(pbSetSM, SIGNAL(clicked()), this, SLOT(smChanged())); |
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6010
diff
changeset
|
132 |
} |
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6010
diff
changeset
|
133 |
|
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6010
diff
changeset
|
134 |
PageAdmin::PageAdmin(QWidget* parent) : AbstractPage(parent) |
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6010
diff
changeset
|
135 |
{ |
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6010
diff
changeset
|
136 |
initPage(); |
5078
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
137 |
} |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
138 |
|
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
139 |
void PageAdmin::smChanged() |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
140 |
{ |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
141 |
emit setServerMessageNew(leServerMessageNew->text()); |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
142 |
emit setServerMessageOld(leServerMessageOld->text()); |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
143 |
emit setProtocol(sbProtocol->value()); |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
144 |
} |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
145 |
|
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
146 |
void PageAdmin::serverMessageNew(const QString & str) |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
147 |
{ |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
148 |
leServerMessageNew->setText(str); |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
149 |
} |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
150 |
|
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
151 |
void PageAdmin::serverMessageOld(const QString & str) |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
152 |
{ |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
153 |
leServerMessageOld->setText(str); |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
154 |
} |
8157 | 155 |
|
5078
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
156 |
void PageAdmin::protocol(int proto) |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
157 |
{ |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
158 |
sbProtocol->setValue(proto); |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
159 |
} |
8157 | 160 |
|
161 |
void PageAdmin::onAddClicked() |
|
162 |
{ |
|
8177 | 163 |
BanDialog dialog(this); |
8157 | 164 |
|
165 |
if(dialog.exec()) |
|
166 |
{ |
|
167 |
if(dialog.byIP()) |
|
168 |
{ |
|
169 |
emit banIP(dialog.banId(), dialog.reason(), dialog.duration()); |
|
170 |
} else |
|
171 |
{ |
|
172 |
emit banNick(dialog.banId(), dialog.reason(), dialog.duration()); |
|
173 |
} |
|
174 |
||
175 |
emit bansListRequest(); |
|
176 |
} |
|
177 |
} |
|
178 |
||
179 |
void PageAdmin::onRemoveClicked() |
|
180 |
{ |
|
181 |
QList<QTableWidgetItem *> sel = twBans->selectedItems(); |
|
182 |
||
183 |
if(sel.size()) |
|
184 |
{ |
|
185 |
emit removeBan(twBans->item(sel[0]->row(), 0)->data(Qt::DisplayRole).toString()); |
|
186 |
emit bansListRequest(); |
|
187 |
} |
|
188 |
} |
|
189 |
||
190 |
void PageAdmin::setBansList(const QStringList & bans) |
|
191 |
{ |
|
192 |
if(bans.size() % 4) |
|
193 |
return; |
|
194 |
||
195 |
twBans->setRowCount(bans.size() / 4); |
|
196 |
||
197 |
for(int i = 0; i < bans.size(); i += 4) |
|
198 |
{ |
|
199 |
if(!twBans->item(i / 4, 0)) |
|
200 |
{ |
|
201 |
twBans->setItem(i / 4, 0, new QTableWidgetItem()); |
|
202 |
twBans->setItem(i / 4, 1, new QTableWidgetItem()); |
|
203 |
twBans->setItem(i / 4, 2, new QTableWidgetItem()); |
|
204 |
} |
|
205 |
||
206 |
twBans->item(i / 4, 0)->setData(Qt::DisplayRole, bans[i + 1]); |
|
207 |
twBans->item(i / 4, 1)->setData(Qt::DisplayRole, bans[i + 3]); |
|
208 |
twBans->item(i / 4, 2)->setData(Qt::DisplayRole, bans[i + 2]); |
|
209 |
} |
|
210 |
} |
|
211 |
||
212 |
void PageAdmin::onRefreshClicked() |
|
213 |
{ |
|
214 |
twBans->setRowCount(0); |
|
215 |
} |