author | alfadur |
Sat, 13 Oct 2018 00:43:04 +0300 | |
changeset 13895 | 2a3d119b9fe9 |
parent 13681 | 05fde8e30041 |
child 15260 | 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); |
|
13681
05fde8e30041
Add a few translator comments for frontend strings
Wuzzy <Wuzzy2@mail.ru>
parents:
12902
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() |
|
13681
05fde8e30041
Add a few translator comments for frontend strings
Wuzzy <Wuzzy2@mail.ru>
parents:
12902
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 |
); |
|
12902
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); |
8157 | 104 |
twBans->setEditTriggers(QAbstractItemView::NoEditTriggers); |
105 |
twBans->setSelectionBehavior(QAbstractItemView::SelectRows); |
|
106 |
twBans->setSelectionMode(QAbstractItemView::SingleSelection); |
|
107 |
twBans->setAlternatingRowColors(true); |
|
108 |
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
|
109 |
|
8157 | 110 |
QPushButton * btnRefresh = addButton(tr("Refresh"), tab2Layout, 0, 0); |
111 |
QPushButton * btnAdd = addButton(tr("Add"), tab2Layout, 1, 0); |
|
112 |
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
|
113 |
|
8157 | 114 |
connect(btnRefresh, SIGNAL(clicked()), this, SIGNAL(bansListRequest())); |
115 |
connect(btnRefresh, SIGNAL(clicked()), this, SLOT(onRefreshClicked())); |
|
116 |
connect(btnAdd, SIGNAL(clicked()), this, SLOT(onAddClicked())); |
|
117 |
connect(btnRemove, SIGNAL(clicked()), this, SLOT(onRemoveClicked())); |
|
118 |
} |
|
5078
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
119 |
|
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
|
120 |
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
|
121 |
} |
6009 | 122 |
|
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
|
123 |
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
|
124 |
{ |
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 |
connect(pbAsk, SIGNAL(clicked()), this, SIGNAL(askServerVars())); |
6680 | 126 |
connect(leServerMessageNew, SIGNAL(textChanged(QString)), tb, SLOT(setHtml(const QString &))); |
127 |
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
|
128 |
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
|
129 |
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
|
130 |
} |
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 |
|
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 |
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
|
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 |
initPage(); |
5078
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
135 |
} |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
136 |
|
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
137 |
void PageAdmin::smChanged() |
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 |
emit setServerMessageNew(leServerMessageNew->text()); |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
140 |
emit setServerMessageOld(leServerMessageOld->text()); |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
141 |
emit setProtocol(sbProtocol->value()); |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
142 |
} |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
143 |
|
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
144 |
void PageAdmin::serverMessageNew(const QString & str) |
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 |
leServerMessageNew->setText(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 |
|
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
149 |
void PageAdmin::serverMessageOld(const QString & str) |
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 |
leServerMessageOld->setText(str); |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
152 |
} |
8157 | 153 |
|
5078
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
154 |
void PageAdmin::protocol(int proto) |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
155 |
{ |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
156 |
sbProtocol->setValue(proto); |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
157 |
} |
8157 | 158 |
|
159 |
void PageAdmin::onAddClicked() |
|
160 |
{ |
|
8177 | 161 |
BanDialog dialog(this); |
8157 | 162 |
|
163 |
if(dialog.exec()) |
|
164 |
{ |
|
165 |
if(dialog.byIP()) |
|
166 |
{ |
|
167 |
emit banIP(dialog.banId(), dialog.reason(), dialog.duration()); |
|
168 |
} else |
|
169 |
{ |
|
170 |
emit banNick(dialog.banId(), dialog.reason(), dialog.duration()); |
|
171 |
} |
|
172 |
||
173 |
emit bansListRequest(); |
|
174 |
} |
|
175 |
} |
|
176 |
||
177 |
void PageAdmin::onRemoveClicked() |
|
178 |
{ |
|
179 |
QList<QTableWidgetItem *> sel = twBans->selectedItems(); |
|
180 |
||
181 |
if(sel.size()) |
|
182 |
{ |
|
183 |
emit removeBan(twBans->item(sel[0]->row(), 0)->data(Qt::DisplayRole).toString()); |
|
184 |
emit bansListRequest(); |
|
185 |
} |
|
186 |
} |
|
187 |
||
188 |
void PageAdmin::setBansList(const QStringList & bans) |
|
189 |
{ |
|
190 |
if(bans.size() % 4) |
|
191 |
return; |
|
192 |
||
193 |
twBans->setRowCount(bans.size() / 4); |
|
194 |
||
195 |
for(int i = 0; i < bans.size(); i += 4) |
|
196 |
{ |
|
197 |
if(!twBans->item(i / 4, 0)) |
|
198 |
{ |
|
199 |
twBans->setItem(i / 4, 0, new QTableWidgetItem()); |
|
200 |
twBans->setItem(i / 4, 1, new QTableWidgetItem()); |
|
201 |
twBans->setItem(i / 4, 2, new QTableWidgetItem()); |
|
202 |
} |
|
203 |
||
204 |
twBans->item(i / 4, 0)->setData(Qt::DisplayRole, bans[i + 1]); |
|
205 |
twBans->item(i / 4, 1)->setData(Qt::DisplayRole, bans[i + 3]); |
|
206 |
twBans->item(i / 4, 2)->setData(Qt::DisplayRole, bans[i + 2]); |
|
207 |
} |
|
208 |
} |
|
209 |
||
210 |
void PageAdmin::onRefreshClicked() |
|
211 |
{ |
|
212 |
twBans->setRowCount(0); |
|
213 |
} |