Remove FindSDL2 find-module, use sdl2-config.cmake instead
This requires SDL >= 2.0.4.
Since <https://bugzilla.libsdl.org/show_bug.cgi?id=2464> was fixed in
SDL 2.0.4, SDL behaves as a CMake "config-file package", even if it was
not itself built using CMake: it installs a sdl2-config.cmake file to
${libdir}/cmake/SDL2, which tells CMake where to find SDL's headers and
library, analogous to a pkg-config .pc file.
As a result, we no longer need to copy/paste a "find-module package"
to be able to find a system copy of SDL >= 2.0.4 with find_package(SDL2).
Find-module packages are now discouraged by the CMake developers, in
favour of having upstream projects behave as config-file packages.
This results in a small API change: FindSDL2 used to set SDL2_INCLUDE_DIR
and SDL2_LIBRARY, but the standard behaviour for config-file packages is
to set <name>_INCLUDE_DIRS and <name>_LIBRARIES. Use the CONFIG keyword
to make sure we search in config-file package mode, and will not find a
FindSDL2.cmake in some other directory that implements the old interface.
In addition to deleting redundant code, this avoids some assumptions in
FindSDL2 about the layout of a SDL installation. The current libsdl2-dev
package in Debian breaks those assumptions; this is considered a bug
and will hopefully be fixed soon, but it illustrates how fragile these
assumptions can be. We can be more robust against different installation
layouts by relying on SDL's own CMake integration.
When linking to a copy of CMake in a non-standard location, users can
now set the SDL2_DIR or CMAKE_PREFIX_PATH environment variable to point
to it; previously, these users would have used the SDL2DIR environment
variable. This continues to be unnecessary if using matching system-wide
installations of CMake and SDL2, for example both from Debian.
/*
* Hedgewars, a free turn based strategy game
* Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <QGridLayout>
#include <QLabel>
#include <QLineEdit>
#include <QSpinBox>
#include <QPushButton>
#include <QTextBrowser>
#include <QTableWidget>
#include <QHeaderView>
#include "pageadmin.h"
#include "chatwidget.h"
#include "bandialog.h"
QLayout * PageAdmin::bodyLayoutDefinition()
{
QVBoxLayout * pageLayout = new QVBoxLayout();
QTabWidget * tabs = new QTabWidget(this);
pageLayout->addWidget(tabs);
QWidget * page1 = new QWidget(this);
QWidget * page2 = new QWidget(this);
tabs->addTab(page1, tr("General"));
tabs->addTab(page2, tr("Bans"));
// page 1
{
QGridLayout * tab1Layout = new QGridLayout(page1);
// 0
pbAsk = addButton(tr("Fetch data"), tab1Layout, 0, 0, 1, 3);
// 1
QLabel * lblSMN = new QLabel(this);
lblSMN->setText(tr("Server message for latest version:"));
tab1Layout->addWidget(lblSMN, 1, 0);
leServerMessageNew = new QLineEdit(this);
tab1Layout->addWidget(leServerMessageNew, 1, 1);
// 2
QLabel * lblSMO = new QLabel(this);
lblSMO->setText(tr("Server message for previous versions:"));
tab1Layout->addWidget(lblSMO, 2, 0);
leServerMessageOld = new QLineEdit(this);
tab1Layout->addWidget(leServerMessageOld, 2, 1);
// 3
QLabel * lblP = new QLabel(this);
lblP->setText(tr("Latest version protocol number:"));
tab1Layout->addWidget(lblP, 3, 0);
sbProtocol = new QSpinBox(this);
tab1Layout->addWidget(sbProtocol, 3, 1);
// 4
QLabel * lblPreview = new QLabel(this);
//: MOTD = Message Of The Day, the message which is shown to players joining the server
lblPreview->setText(tr("MOTD preview:"));
tab1Layout->addWidget(lblPreview, 4, 0);
tb = new QTextBrowser(this);
tb->setOpenExternalLinks(true);
tb->document()->setDefaultStyleSheet(HWChatWidget::styleSheet());
tab1Layout->addWidget(tb, 4, 1, 1, 2);
// 5
pbClearAccountsCache = addButton(tr("Clear Accounts Cache"), tab1Layout, 5, 0);
// 6
pbSetSM = addButton(tr("Set data"), tab1Layout, 6, 0, 1, 3);
}
// page 2
{
QGridLayout * tab2Layout = new QGridLayout(page2);
twBans = new QTableWidget(this);
twBans->setColumnCount(3);
twBans->setHorizontalHeaderLabels(QStringList()
//: IP = short for "IP address" (Internet Protocol). Nick = short for "nick name"
<< tr("IP/Nick")
<< tr("Expiration")
<< tr("Reason")
);
twBans->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);
twBans->horizontalHeader()->setSectionsClickable(false);
twBans->verticalHeader()->hide();
twBans->setEditTriggers(QAbstractItemView::NoEditTriggers);
twBans->setSelectionBehavior(QAbstractItemView::SelectRows);
twBans->setSelectionMode(QAbstractItemView::SingleSelection);
twBans->setAlternatingRowColors(true);
tab2Layout->addWidget(twBans, 0, 1, 4, 1);
QPushButton * btnRefresh = addButton(tr("Refresh"), tab2Layout, 0, 0);
QPushButton * btnAdd = addButton(tr("Add"), tab2Layout, 1, 0);
QPushButton * btnRemove = addButton(tr("Remove"), tab2Layout, 2, 0);
connect(btnRefresh, SIGNAL(clicked()), this, SIGNAL(bansListRequest()));
connect(btnRefresh, SIGNAL(clicked()), this, SLOT(onRefreshClicked()));
connect(btnAdd, SIGNAL(clicked()), this, SLOT(onAddClicked()));
connect(btnRemove, SIGNAL(clicked()), this, SLOT(onRemoveClicked()));
}
return pageLayout;
}
void PageAdmin::connectSignals()
{
connect(pbAsk, SIGNAL(clicked()), this, SIGNAL(askServerVars()));
connect(leServerMessageNew, SIGNAL(textChanged(QString)), tb, SLOT(setHtml(const QString &)));
connect(leServerMessageOld, SIGNAL(textChanged(QString)), tb, SLOT(setHtml(const QString &)));
connect(pbClearAccountsCache, SIGNAL(clicked()), this, SIGNAL(clearAccountsCache()));
connect(pbSetSM, SIGNAL(clicked()), this, SLOT(smChanged()));
}
PageAdmin::PageAdmin(QWidget* parent) : AbstractPage(parent)
{
initPage();
}
void PageAdmin::smChanged()
{
emit setServerMessageNew(leServerMessageNew->text());
emit setServerMessageOld(leServerMessageOld->text());
emit setProtocol(sbProtocol->value());
}
void PageAdmin::serverMessageNew(const QString & str)
{
leServerMessageNew->setText(str);
}
void PageAdmin::serverMessageOld(const QString & str)
{
leServerMessageOld->setText(str);
}
void PageAdmin::protocol(int proto)
{
sbProtocol->setValue(proto);
}
void PageAdmin::onAddClicked()
{
BanDialog dialog(this);
if(dialog.exec())
{
if(dialog.byIP())
{
emit banIP(dialog.banId(), dialog.reason(), dialog.duration());
} else
{
emit banNick(dialog.banId(), dialog.reason(), dialog.duration());
}
emit bansListRequest();
}
}
void PageAdmin::onRemoveClicked()
{
QList<QTableWidgetItem *> sel = twBans->selectedItems();
if(sel.size())
{
emit removeBan(twBans->item(sel[0]->row(), 0)->data(Qt::DisplayRole).toString());
emit bansListRequest();
}
}
void PageAdmin::setBansList(const QStringList & bans)
{
if(bans.size() % 4)
return;
twBans->setRowCount(bans.size() / 4);
for(int i = 0; i < bans.size(); i += 4)
{
if(!twBans->item(i / 4, 0))
{
twBans->setItem(i / 4, 0, new QTableWidgetItem());
twBans->setItem(i / 4, 1, new QTableWidgetItem());
twBans->setItem(i / 4, 2, new QTableWidgetItem());
}
twBans->item(i / 4, 0)->setData(Qt::DisplayRole, bans[i + 1]);
twBans->item(i / 4, 1)->setData(Qt::DisplayRole, bans[i + 3]);
twBans->item(i / 4, 2)->setData(Qt::DisplayRole, bans[i + 2]);
}
}
void PageAdmin::onRefreshClicked()
{
twBans->setRowCount(0);
}