From ba8613a179936631d6c5fa7ae6dedb8a5f3eb684 Mon Sep 17 00:00:00 2001 From: Koncord Date: Sat, 21 Oct 2017 12:42:38 +0800 Subject: [PATCH] [Browser] Add "no password" filter to browser --- apps/browser/MainWindow.cpp | 6 ++++++ apps/browser/MainWindow.hpp | 1 + apps/browser/MySortFilterProxyModel.cpp | 10 ++++++++++ apps/browser/MySortFilterProxyModel.hpp | 3 ++- files/tes3mp/ui/Main.ui | 7 +++++++ 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/apps/browser/MainWindow.cpp b/apps/browser/MainWindow.cpp index 901e401cc..56f25604b 100644 --- a/apps/browser/MainWindow.cpp +++ b/apps/browser/MainWindow.cpp @@ -54,6 +54,7 @@ MainWindow::MainWindow(QWidget *parent) connect(tblServerBrowser, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(play())); connect(cBoxNotFull, SIGNAL(toggled(bool)), this, SLOT(notFullSwitch(bool))); connect(cBoxWithPlayers, SIGNAL(toggled(bool)), this, SLOT(havePlayersSwitch(bool))); + connect(cBBoxWOPass, SIGNAL(toggled(bool)), this, SLOT(noPasswordSwitch(bool))); connect(comboLatency, SIGNAL(currentIndexChanged(int)), this, SLOT(maxLatencyChanged(int))); connect(leGamemode, SIGNAL(textChanged(const QString &)), this, SLOT(gamemodeChanged(const QString &))); loadFavorites(); @@ -229,6 +230,11 @@ void MainWindow::havePlayersSwitch(bool state) proxyModel->filterEmptyServers(state); } +void MainWindow::noPasswordSwitch(bool state) +{ + proxyModel->filterPassworded(state); +} + void MainWindow::maxLatencyChanged(int index) { int maxLatency = index * 50; diff --git a/apps/browser/MainWindow.hpp b/apps/browser/MainWindow.hpp index 02a8fb74e..31e686295 100644 --- a/apps/browser/MainWindow.hpp +++ b/apps/browser/MainWindow.hpp @@ -31,6 +31,7 @@ protected slots: void serverSelected(); void notFullSwitch(bool state); void havePlayersSwitch(bool state); + void noPasswordSwitch(bool state); void maxLatencyChanged(int index); void gamemodeChanged(const QString &text); private: diff --git a/apps/browser/MySortFilterProxyModel.cpp b/apps/browser/MySortFilterProxyModel.cpp index dbd11e7f5..5ae3c7797 100644 --- a/apps/browser/MySortFilterProxyModel.cpp +++ b/apps/browser/MySortFilterProxyModel.cpp @@ -14,6 +14,7 @@ bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex & 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); + QModelIndex passwordIndex = sourceModel()->index(sourceRow, ServerData::PASSW, sourceParent); bool pingOk; int ping = sourceModel()->data(pingIndex).toInt(&pingOk); @@ -26,6 +27,8 @@ bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex & return false; if (filterFull && players >= maxPlayers) return false; + if(filterPasswEnabled && sourceModel()->data(passwordIndex).toString() == "Yes") + return false; return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent); } @@ -51,6 +54,7 @@ MySortFilterProxyModel::MySortFilterProxyModel(QObject *parent) : QSortFilterPro { filterEmpty = false; filterFull = false; + filterPasswEnabled = false; maxPing = 0; setSortCaseSensitivity(Qt::CaseSensitivity::CaseInsensitive); } @@ -72,3 +76,9 @@ void MySortFilterProxyModel::pingLessThan(int maxPing) this->maxPing = maxPing; invalidateFilter(); } + +void MySortFilterProxyModel::filterPassworded(bool state) +{ + filterPasswEnabled = state; + invalidateFilter(); +} diff --git a/apps/browser/MySortFilterProxyModel.hpp b/apps/browser/MySortFilterProxyModel.hpp index a36a37d38..496f711ee 100644 --- a/apps/browser/MySortFilterProxyModel.hpp +++ b/apps/browser/MySortFilterProxyModel.hpp @@ -18,9 +18,10 @@ public: explicit MySortFilterProxyModel(QObject *parent); void filterFullServer(bool state); void filterEmptyServers(bool state); + void filterPassworded(bool state); void pingLessThan(int maxPing); private: - bool filterEmpty, filterFull; + bool filterEmpty, filterFull, filterPasswEnabled; int maxPing; }; diff --git a/files/tes3mp/ui/Main.ui b/files/tes3mp/ui/Main.ui index c3de17df5..5a370a7fe 100644 --- a/files/tes3mp/ui/Main.ui +++ b/files/tes3mp/ui/Main.ui @@ -166,6 +166,13 @@ + + + + No password + + +