pull/163/head
David Cernat 8 years ago
commit bcee35ca1d

@ -11,6 +11,7 @@ set(BROWSER
ServerModel.cpp
NetController.cpp
ServerInfoDialog.cpp
MySortFilterProxyModel.cpp
netutils/HTTPNetwork.cpp
netutils/Utils.cpp
${CMAKE_SOURCE_DIR}/files/tes3mp/browser.rc
@ -20,6 +21,7 @@ set(BROWSER_HEADER_MOC
MainWindow.hpp
ServerModel.hpp
ServerInfoDialog.hpp
MySortFilterProxyModel.hpp
)
set(BROWSER_HEADER

@ -23,7 +23,7 @@ MainWindow::MainWindow(QWidget *parent)
browser = new ServerModel;
favorites = new ServerModel;
proxyModel = new QSortFilterProxyModel;
proxyModel = new MySortFilterProxyModel(this);
proxyModel->setSourceModel(browser);
tblServerBrowser->setModel(proxyModel);
tblFavorites->setModel(proxyModel);
@ -39,7 +39,12 @@ MainWindow::MainWindow(QWidget *parent)
connect(actionPlay, SIGNAL(triggered(bool)), this, SLOT(play()));
connect(tblServerBrowser, SIGNAL(clicked(QModelIndex)), this, SLOT(serverSelected()));
connect(tblFavorites, SIGNAL(clicked(QModelIndex)), this, SLOT(serverSelected()));
connect(tblFavorites, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(play()));
connect(tblServerBrowser, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(play()));
connect(cBoxNotFully, SIGNAL(toggled(bool)), this, SLOT(notFullySwitch(bool)));
connect(cBoxWithPlayers, SIGNAL(toggled(bool)), this, SLOT(havePlayersSwitch(bool)));
connect(comboLatency, SIGNAL(currentIndexChanged(int)), this, SLOT(maxLatencyChanged(int)));
connect(leGamemode, SIGNAL(textChanged(const QString &)), this, SLOT(gamemodeChanged(const QString &)));
loadFavorites();
}
@ -184,4 +189,27 @@ void MainWindow::loadFavorites()
addServerAndUpdate(server.toString());
file.close();
}
}
void MainWindow::notFullySwitch(bool state)
{
proxyModel->filterFullServer(state);
}
void MainWindow::havePlayersSwitch(bool state)
{
proxyModel->filterEmptyServers(state);
}
void MainWindow::maxLatencyChanged(int index)
{
int maxLatency = index * 50;
proxyModel->pingLessThan(maxLatency);
}
void MainWindow::gamemodeChanged(const QString &text)
{
proxyModel->setFilterFixedString(text);
proxyModel->setFilterKeyColumn(ServerData::MODNAME);
}

@ -8,7 +8,7 @@
#include "ui_Main.h"
#include "ServerModel.hpp"
#include <QSortFilterProxyModel>
#include "MySortFilterProxyModel.hpp"
#include <components/process/processinvoker.hpp>
class MainWindow : public QMainWindow, private Ui::MainWindow
@ -29,10 +29,14 @@ protected slots:
void deleteServer();
void play();
void serverSelected();
void notFullySwitch(bool state);
void havePlayersSwitch(bool state);
void maxLatencyChanged(int index);
void gamemodeChanged(const QString &text);
private:
Process::ProcessInvoker *mGameInvoker;
ServerModel *browser, *favorites;
QSortFilterProxyModel *proxyModel;
MySortFilterProxyModel *proxyModel;
void loadFavorites();
};

@ -0,0 +1,52 @@
//
// Created by koncord on 30.01.17.
//
#include "MySortFilterProxyModel.hpp"
#include "ServerModel.hpp"
#include <qdebug.h>
bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
QModelIndex pingIndex = sourceModel()->index(sourceRow, ServerData::PING, sourceParent);
QModelIndex plIndex = sourceModel()->index(sourceRow, ServerData::PLAYERS, sourceParent);
QModelIndex maxPlIndex = sourceModel()->index(sourceRow, ServerData::MAX_PLAYERS, sourceParent);
int ping = sourceModel()->data(pingIndex).toInt();
int players = sourceModel()->data(plIndex).toInt();
int maxPlayers = sourceModel()->data(maxPlIndex).toInt();
if(maxPing > 0 && (ping == -1 || ping > maxPing))
return false;
if(filterEmpty && players == 0)
return false;
if(filterFull && players >= maxPlayers)
return false;
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
}
MySortFilterProxyModel::MySortFilterProxyModel(QObject *parent) : QSortFilterProxyModel(parent)
{
}
void MySortFilterProxyModel::filterEmptyServers(bool state)
{
filterEmpty = state;
invalidateFilter();
}
void MySortFilterProxyModel::filterFullServer(bool state)
{
filterFull = state;
invalidateFilter();
}
void MySortFilterProxyModel::pingLessThan(int maxPing)
{
this->maxPing = maxPing;
invalidateFilter();
}

@ -0,0 +1,27 @@
//
// Created by koncord on 30.01.17.
//
#ifndef OPENMW_MYSORTFILTERPROXYMODEL_HPP
#define OPENMW_MYSORTFILTERPROXYMODEL_HPP
#include <QSortFilterProxyModel>
class MySortFilterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const Q_DECL_FINAL;
public:
MySortFilterProxyModel(QObject *parent);
void filterFullServer(bool state);
void filterEmptyServers(bool state);
void pingLessThan(int maxPing);
private:
bool filterEmpty, filterFull;
int maxPing;
};
#endif //OPENMW_MYSORTFILTERPROXYMODEL_HPP

@ -217,7 +217,10 @@ void NetController::updateInfo()
QStringList addr = sd->addr.split(":");
sd->ping = PingRakNetServer(addr[0].toLatin1(), addr[1].toUShort());
sed = getExtendedData(addr[0].toLatin1(), addr[1].toUShort());
if(sd->ping != PING_UNREACHABLE)
sed = getExtendedData(addr[0].toLatin1(), addr[1].toUShort());
else
qDebug() << "Server is unreachable";
}
QStringList NetController::players()

@ -43,7 +43,6 @@ int main(int argc, char *argv[])
atexit(NetController::Destroy);
QApplication app(argc, argv);
MainWindow d;
d.setWindowTitle("tes3mp Server Browser");
if (d.refresh())
{

@ -20,7 +20,7 @@ unsigned int PingRakNetServer(const char *addr, unsigned short port)
RakNet::Packet *packet;
bool done = false;
int attempts = 0;
RakNet::TimeMS time = 999;
RakNet::TimeMS time = PING_UNREACHABLE;
RakNet::SocketDescriptor socketDescriptor {0, ""};
RakNet::RakPeerInterface *peer = RakNet::RakPeerInterface::GetInstance();

@ -9,6 +9,8 @@
#include <string>
#define PING_UNREACHABLE 999
unsigned int PingRakNetServer(const char *addr, unsigned short port);
struct ServerExtendedData

@ -11,10 +11,10 @@
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
<string>tes3mp Server Browser</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QHBoxLayout" name="horizontalLayout">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
@ -68,6 +68,122 @@
</widget>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBoxFilters">
<property name="title">
<string>Filters</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="lblMaxLatency">
<property name="text">
<string>Max latency:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboLatency">
<item>
<property name="text">
<string>All</string>
</property>
</item>
<item>
<property name="text">
<string>&lt;50</string>
</property>
</item>
<item>
<property name="text">
<string>&lt;100</string>
</property>
</item>
<item>
<property name="text">
<string>&lt;150</string>
</property>
</item>
<item>
<property name="text">
<string>&lt;200</string>
</property>
</item>
<item>
<property name="text">
<string>&lt;250</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="lblGameMode">
<property name="text">
<string>Game mode</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="leGamemode"/>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QCheckBox" name="cBoxNotFully">
<property name="text">
<string>Not fully</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cBoxWithPlayers">
<property name="text">
<string>With players</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QToolBar" name="toolBar">

Loading…
Cancel
Save