From 16f0864a4f0de73afc0594b5ae5f5c22e4bb319b Mon Sep 17 00:00:00 2001 From: Christian Aguilera Date: Mon, 13 Apr 2020 14:32:10 +0200 Subject: [PATCH] DolphinQt: Saving and restoring NetPlay Session Browser dialog's settings. --- Source/Core/DolphinQt/MainWindow.cpp | 1 + .../Core/DolphinQt/NetPlay/NetPlayBrowser.cpp | 55 +++++++++++++++++++ .../Core/DolphinQt/NetPlay/NetPlayBrowser.h | 3 + 3 files changed, 59 insertions(+) diff --git a/Source/Core/DolphinQt/MainWindow.cpp b/Source/Core/DolphinQt/MainWindow.cpp index 270f4394c6..f1ec4bf338 100644 --- a/Source/Core/DolphinQt/MainWindow.cpp +++ b/Source/Core/DolphinQt/MainWindow.cpp @@ -1162,6 +1162,7 @@ void MainWindow::ShowNetPlaySetupDialog() void MainWindow::ShowNetPlayBrowser() { auto* browser = new NetPlayBrowser(this); + browser->setAttribute(Qt::WA_DeleteOnClose, true); connect(browser, &NetPlayBrowser::Join, this, &MainWindow::NetPlayJoin); browser->exec(); } diff --git a/Source/Core/DolphinQt/NetPlay/NetPlayBrowser.cpp b/Source/Core/DolphinQt/NetPlay/NetPlayBrowser.cpp index 3c68a5c274..fc8f201b90 100644 --- a/Source/Core/DolphinQt/NetPlay/NetPlayBrowser.cpp +++ b/Source/Core/DolphinQt/NetPlay/NetPlayBrowser.cpp @@ -27,6 +27,7 @@ #include "DolphinQt/QtUtils/ModalMessageBox.h" #include "DolphinQt/QtUtils/RunOnObject.h" +#include "DolphinQt/Settings.h" NetPlayBrowser::NetPlayBrowser(QWidget* parent) : QDialog(parent) { @@ -44,6 +45,8 @@ NetPlayBrowser::NetPlayBrowser(QWidget* parent) : QDialog(parent) m_refresh_run.Set(true); m_refresh_thread = std::thread([this] { RefreshLoop(); }); + RestoreSettings(); + UpdateList(); Refresh(); } @@ -54,6 +57,8 @@ NetPlayBrowser::~NetPlayBrowser() m_refresh_event.Set(); if (m_refresh_thread.joinable()) m_refresh_thread.join(); + + SaveSettings(); } void NetPlayBrowser::CreateWidgets() @@ -323,3 +328,53 @@ void NetPlayBrowser::accept() emit Join(); } + +void NetPlayBrowser::SaveSettings() const +{ + auto& settings = Settings::Instance().GetQSettings(); + + settings.setValue(QStringLiteral("netplaybrowser/geometry"), saveGeometry()); + settings.setValue(QStringLiteral("netplaybrowser/region"), m_region_combo->currentText()); + settings.setValue(QStringLiteral("netplaybrowser/name"), m_edit_name->text()); + settings.setValue(QStringLiteral("netplaybrowser/game_id"), m_edit_game_id->text()); + + QString visibility(QStringLiteral("all")); + if (m_radio_public->isChecked()) + visibility = QStringLiteral("public"); + else if (m_radio_private->isChecked()) + visibility = QStringLiteral("private"); + settings.setValue(QStringLiteral("netplaybrowser/visibility"), visibility); + + settings.setValue(QStringLiteral("netplaybrowser/hide_incompatible"), + m_check_hide_incompatible->isChecked()); + settings.setValue(QStringLiteral("netplaybrowser/hide_ingame"), m_check_hide_ingame->isChecked()); +} + +void NetPlayBrowser::RestoreSettings() +{ + const auto& settings = Settings::Instance().GetQSettings(); + + const QByteArray geometry = + settings.value(QStringLiteral("netplaybrowser/geometry")).toByteArray(); + if (!geometry.isEmpty()) + restoreGeometry(geometry); + + const QString region = settings.value(QStringLiteral("netplaybrowser/region")).toString(); + const bool valid_region = m_region_combo->findText(region) != -1; + if (valid_region) + m_region_combo->setCurrentText(region); + + m_edit_name->setText(settings.value(QStringLiteral("netplaybrowser/name")).toString()); + m_edit_game_id->setText(settings.value(QStringLiteral("netplaybrowser/game_id")).toString()); + + const QString visibility = settings.value(QStringLiteral("netplaybrowser/visibility")).toString(); + if (visibility == QStringLiteral("public")) + m_radio_public->setChecked(true); + else if (visibility == QStringLiteral("private")) + m_radio_private->setChecked(true); + + m_check_hide_incompatible->setChecked( + settings.value(QStringLiteral("netplaybrowser/hide_incompatible"), true).toBool()); + m_check_hide_ingame->setChecked( + settings.value(QStringLiteral("netplaybrowser/hide_ingame")).toBool()); +} diff --git a/Source/Core/DolphinQt/NetPlay/NetPlayBrowser.h b/Source/Core/DolphinQt/NetPlay/NetPlayBrowser.h index b484e852bd..3a7648be51 100644 --- a/Source/Core/DolphinQt/NetPlay/NetPlayBrowser.h +++ b/Source/Core/DolphinQt/NetPlay/NetPlayBrowser.h @@ -46,6 +46,9 @@ private: void OnSelectionChanged(); + void SaveSettings() const; + void RestoreSettings(); + QComboBox* m_region_combo; QLabel* m_status_label; QPushButton* m_button_refresh;