From 75f1a5d0cc1814fa02b24e98873eb99e17cce685 Mon Sep 17 00:00:00 2001 From: spycrab Date: Sun, 7 Apr 2019 23:53:13 +0200 Subject: [PATCH] Qt/NetPlayBrowser: Various small fixes --- .../Core/DolphinQt/NetPlay/NetPlayBrowser.cpp | 38 +++++++++++++------ .../Core/DolphinQt/NetPlay/NetPlayBrowser.h | 2 + Source/Core/UICommon/NetPlayIndex.cpp | 5 ++- Source/Core/UICommon/NetPlayIndex.h | 1 + 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/Source/Core/DolphinQt/NetPlay/NetPlayBrowser.cpp b/Source/Core/DolphinQt/NetPlay/NetPlayBrowser.cpp index 8097a0a48a..4ea2c21bbe 100644 --- a/Source/Core/DolphinQt/NetPlay/NetPlayBrowser.cpp +++ b/Source/Core/DolphinQt/NetPlay/NetPlayBrowser.cpp @@ -4,6 +4,7 @@ #include "DolphinQt/NetPlay/NetPlayBrowser.h" +#include #include #include #include @@ -67,6 +68,9 @@ void NetPlayBrowser::CreateWidgets() m_button_refresh = new QPushButton(tr("Refresh")); m_edit_name = new QLineEdit; m_edit_game_id = new QLineEdit; + m_check_hide_incompatible = new QCheckBox(tr("Hide Incompatible Sessions")); + + m_check_hide_incompatible->setChecked(true); m_radio_all = new QRadioButton(tr("Private and Public")); m_radio_private = new QRadioButton(tr("Private")); @@ -88,6 +92,7 @@ void NetPlayBrowser::CreateWidgets() filter_layout->addWidget(m_radio_public, 3, 2); filter_layout->addWidget(m_radio_private, 3, 3); filter_layout->addItem(new QSpacerItem(4, 1, QSizePolicy::Expanding), 2, 4); + filter_layout->addWidget(m_check_hide_incompatible, 4, 1); layout->addWidget(m_table_widget); layout->addWidget(filter_box); @@ -108,6 +113,7 @@ void NetPlayBrowser::ConnectWidgets() connect(m_radio_all, &QRadioButton::toggled, this, &NetPlayBrowser::Refresh); connect(m_radio_private, &QRadioButton::toggled, this, &NetPlayBrowser::Refresh); + connect(m_check_hide_incompatible, &QRadioButton::toggled, this, &NetPlayBrowser::Refresh); connect(m_edit_name, &QLineEdit::textChanged, this, &NetPlayBrowser::Refresh); connect(m_edit_game_id, &QLineEdit::textChanged, this, &NetPlayBrowser::Refresh); @@ -120,20 +126,26 @@ void NetPlayBrowser::Refresh() m_status_label->setText(tr("Refreshing...")); m_table_widget->clear(); - m_table_widget->setColumnCount(6); - m_table_widget->setHorizontalHeaderLabels( - {tr("Region"), tr("Name"), tr("Password?"), tr("In-Game?"), tr("Game"), tr("Players")}); - m_table_widget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents); - m_table_widget->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch); - m_table_widget->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents); - m_table_widget->horizontalHeader()->setSectionResizeMode(3, QHeaderView::ResizeToContents); - m_table_widget->horizontalHeader()->setSectionResizeMode(4, QHeaderView::Stretch); + m_table_widget->setColumnCount(7); + m_table_widget->setHorizontalHeaderLabels({tr("Region"), tr("Name"), tr("Password?"), + tr("In-Game?"), tr("Game"), tr("Players"), + tr("Version")}); + + auto* hor_header = m_table_widget->horizontalHeader(); + + hor_header->setSectionResizeMode(0, QHeaderView::ResizeToContents); + hor_header->setSectionResizeMode(1, QHeaderView::Stretch); + hor_header->setSectionResizeMode(2, QHeaderView::ResizeToContents); + hor_header->setSectionResizeMode(3, QHeaderView::ResizeToContents); + hor_header->setSectionResizeMode(4, QHeaderView::Stretch); + hor_header->setHighlightSections(false); NetPlayIndex client; std::map filters; - filters["version"] = Common::scm_desc_str; + if (m_check_hide_incompatible->isChecked()) + filters["version"] = Common::scm_desc_str; if (!m_edit_name->text().isEmpty()) filters["name"] = m_edit_name->text().toStdString(); @@ -170,9 +182,12 @@ void NetPlayBrowser::Refresh() auto* in_game = new QTableWidgetItem(entry.in_game ? tr("Yes") : tr("No")); auto* game_id = new QTableWidgetItem(QString::fromStdString(entry.game_id)); auto* player_count = new QTableWidgetItem(QStringLiteral("%1").arg(entry.player_count)); + auto* version = new QTableWidgetItem(QString::fromStdString(entry.version)); - for (const auto& item : {region, name, password, game_id, player_count}) - item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); + const bool enabled = Common::scm_desc_str == entry.version; + + for (const auto& item : {region, name, password, in_game, game_id, player_count, version}) + item->setFlags(enabled ? Qt::ItemIsEnabled | Qt::ItemIsSelectable : Qt::NoItemFlags); m_table_widget->setItem(i, 0, region); m_table_widget->setItem(i, 1, name); @@ -180,6 +195,7 @@ void NetPlayBrowser::Refresh() m_table_widget->setItem(i, 3, in_game); m_table_widget->setItem(i, 4, game_id); m_table_widget->setItem(i, 5, player_count); + m_table_widget->setItem(i, 6, version); } m_status_label->setText( diff --git a/Source/Core/DolphinQt/NetPlay/NetPlayBrowser.h b/Source/Core/DolphinQt/NetPlay/NetPlayBrowser.h index f6cdfdfc5a..12c7f85963 100644 --- a/Source/Core/DolphinQt/NetPlay/NetPlayBrowser.h +++ b/Source/Core/DolphinQt/NetPlay/NetPlayBrowser.h @@ -10,6 +10,7 @@ #include "UICommon/NetPlayIndex.h" +class QCheckBox; class QComboBox; class QDialogButtonBox; class QLabel; @@ -43,6 +44,7 @@ private: QDialogButtonBox* m_button_box; QLineEdit* m_edit_name; QLineEdit* m_edit_game_id; + QCheckBox* m_check_hide_incompatible; QRadioButton* m_radio_all; QRadioButton* m_radio_private; diff --git a/Source/Core/UICommon/NetPlayIndex.cpp b/Source/Core/UICommon/NetPlayIndex.cpp index b41920c647..039eca0e8b 100644 --- a/Source/Core/UICommon/NetPlayIndex.cpp +++ b/Source/Core/UICommon/NetPlayIndex.cpp @@ -95,10 +95,12 @@ NetPlayIndex::List(const std::map& filters) const auto& player_count = entry.get("player_count"); const auto& port = entry.get("port"); const auto& in_game = entry.get("in_game"); + const auto& version = entry.get("version"); if (!name.is() || !region.is() || !method.is() || !server_id.is() || !game_id.is() || !has_password.is() || - !player_count.is() || !port.is() || !in_game.is()) + !player_count.is() || !port.is() || !in_game.is() || + !version.is()) { continue; } @@ -108,6 +110,7 @@ NetPlayIndex::List(const std::map& filters) session.game_id = game_id.to_str(); session.server_id = server_id.to_str(); session.method = method.to_str(); + session.version = version.to_str(); session.has_password = has_password.get(); session.player_count = static_cast(player_count.get()); session.port = static_cast(port.get()); diff --git a/Source/Core/UICommon/NetPlayIndex.h b/Source/Core/UICommon/NetPlayIndex.h index 2bc778efa0..75663373e7 100644 --- a/Source/Core/UICommon/NetPlayIndex.h +++ b/Source/Core/UICommon/NetPlayIndex.h @@ -20,6 +20,7 @@ struct NetPlaySession std::string method; std::string server_id; std::string game_id; + std::string version; int player_count; int port;