author | Periklis Ntanasis <pntanasis@gmail.com> |
Tue, 27 Aug 2013 03:44:19 +0300 | |
branch | spacecampaign |
changeset 9588 | 797b8a41f8ca |
parent 9080 | 9b42757d7e71 |
child 9998 | 736015b847e3 |
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 |
9080 | 3 |
* Copyright (c) 2004-2013 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 |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
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); |
|
76 |
lblPreview->setText(tr("MOTD preview:")); |
|
77 |
tab1Layout->addWidget(lblPreview, 4, 0); |
|
5078
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
78 |
|
8157 | 79 |
tb = new QTextBrowser(this); |
80 |
tb->setOpenExternalLinks(true); |
|
81 |
tb->document()->setDefaultStyleSheet(HWChatWidget::styleSheet()); |
|
82 |
tab1Layout->addWidget(tb, 4, 1, 1, 2); |
|
83 |
||
84 |
// 5 |
|
85 |
pbClearAccountsCache = addButton(tr("Clear Accounts Cache"), tab1Layout, 5, 0); |
|
86 |
||
87 |
// 6 |
|
88 |
pbSetSM = addButton(tr("Set data"), tab1Layout, 6, 0, 1, 3); |
|
89 |
} |
|
5078
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
90 |
|
8157 | 91 |
// page 2 |
92 |
{ |
|
93 |
QGridLayout * tab2Layout = new QGridLayout(page2); |
|
94 |
twBans = new QTableWidget(this); |
|
95 |
twBans->setColumnCount(3); |
|
96 |
twBans->setHorizontalHeaderLabels(QStringList() |
|
97 |
<< tr("IP/Nick") |
|
98 |
<< tr("Expiration") |
|
99 |
<< tr("Reason") |
|
100 |
); |
|
101 |
twBans->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch); |
|
102 |
twBans->setEditTriggers(QAbstractItemView::NoEditTriggers); |
|
103 |
twBans->setSelectionBehavior(QAbstractItemView::SelectRows); |
|
104 |
twBans->setSelectionMode(QAbstractItemView::SingleSelection); |
|
105 |
twBans->setAlternatingRowColors(true); |
|
106 |
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
|
107 |
|
8157 | 108 |
QPushButton * btnRefresh = addButton(tr("Refresh"), tab2Layout, 0, 0); |
109 |
QPushButton * btnAdd = addButton(tr("Add"), tab2Layout, 1, 0); |
|
110 |
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
|
111 |
|
8157 | 112 |
connect(btnRefresh, SIGNAL(clicked()), this, SIGNAL(bansListRequest())); |
113 |
connect(btnRefresh, SIGNAL(clicked()), this, SLOT(onRefreshClicked())); |
|
114 |
connect(btnAdd, SIGNAL(clicked()), this, SLOT(onAddClicked())); |
|
115 |
connect(btnRemove, SIGNAL(clicked()), this, SLOT(onRemoveClicked())); |
|
116 |
} |
|
5078
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
117 |
|
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
|
118 |
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
|
119 |
} |
6009 | 120 |
|
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
|
121 |
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
|
122 |
{ |
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 |
connect(pbAsk, SIGNAL(clicked()), this, SIGNAL(askServerVars())); |
6680 | 124 |
connect(leServerMessageNew, SIGNAL(textChanged(QString)), tb, SLOT(setHtml(const QString &))); |
125 |
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
|
126 |
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
|
127 |
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
|
128 |
} |
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 |
|
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 |
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
|
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 |
initPage(); |
5078
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
133 |
} |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
134 |
|
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
135 |
void PageAdmin::smChanged() |
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 |
emit setServerMessageNew(leServerMessageNew->text()); |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
138 |
emit setServerMessageOld(leServerMessageOld->text()); |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
139 |
emit setProtocol(sbProtocol->value()); |
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 |
|
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
142 |
void PageAdmin::serverMessageNew(const QString & str) |
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 |
leServerMessageNew->setText(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 |
|
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
147 |
void PageAdmin::serverMessageOld(const QString & str) |
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 |
leServerMessageOld->setText(str); |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
150 |
} |
8157 | 151 |
|
5078
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
152 |
void PageAdmin::protocol(int proto) |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
153 |
{ |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
154 |
sbProtocol->setValue(proto); |
3527f0e7bb21
Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff
changeset
|
155 |
} |
8157 | 156 |
|
157 |
void PageAdmin::onAddClicked() |
|
158 |
{ |
|
8177 | 159 |
BanDialog dialog(this); |
8157 | 160 |
|
161 |
if(dialog.exec()) |
|
162 |
{ |
|
163 |
if(dialog.byIP()) |
|
164 |
{ |
|
165 |
emit banIP(dialog.banId(), dialog.reason(), dialog.duration()); |
|
166 |
} else |
|
167 |
{ |
|
168 |
emit banNick(dialog.banId(), dialog.reason(), dialog.duration()); |
|
169 |
} |
|
170 |
||
171 |
emit bansListRequest(); |
|
172 |
} |
|
173 |
} |
|
174 |
||
175 |
void PageAdmin::onRemoveClicked() |
|
176 |
{ |
|
177 |
QList<QTableWidgetItem *> sel = twBans->selectedItems(); |
|
178 |
||
179 |
if(sel.size()) |
|
180 |
{ |
|
181 |
emit removeBan(twBans->item(sel[0]->row(), 0)->data(Qt::DisplayRole).toString()); |
|
182 |
emit bansListRequest(); |
|
183 |
} |
|
184 |
} |
|
185 |
||
186 |
void PageAdmin::setBansList(const QStringList & bans) |
|
187 |
{ |
|
188 |
if(bans.size() % 4) |
|
189 |
return; |
|
190 |
||
191 |
twBans->setRowCount(bans.size() / 4); |
|
192 |
||
193 |
for(int i = 0; i < bans.size(); i += 4) |
|
194 |
{ |
|
195 |
if(!twBans->item(i / 4, 0)) |
|
196 |
{ |
|
197 |
twBans->setItem(i / 4, 0, new QTableWidgetItem()); |
|
198 |
twBans->setItem(i / 4, 1, new QTableWidgetItem()); |
|
199 |
twBans->setItem(i / 4, 2, new QTableWidgetItem()); |
|
200 |
} |
|
201 |
||
202 |
twBans->item(i / 4, 0)->setData(Qt::DisplayRole, bans[i + 1]); |
|
203 |
twBans->item(i / 4, 1)->setData(Qt::DisplayRole, bans[i + 3]); |
|
204 |
twBans->item(i / 4, 2)->setData(Qt::DisplayRole, bans[i + 2]); |
|
205 |
} |
|
206 |
} |
|
207 |
||
208 |
void PageAdmin::onRefreshClicked() |
|
209 |
{ |
|
210 |
twBans->setRowCount(0); |
|
211 |
} |