diff --git a/pcsx2-qt/Settings/DEV9SettingsWidget.cpp b/pcsx2-qt/Settings/DEV9SettingsWidget.cpp index 7626a3970a..94a8798220 100644 --- a/pcsx2-qt/Settings/DEV9SettingsWidget.cpp +++ b/pcsx2-qt/Settings/DEV9SettingsWidget.cpp @@ -251,8 +251,7 @@ DEV9SettingsWidget::DEV9SettingsWidget(SettingsDialog* dialog, QWidget* parent) connect(m_ui.ethHostExport, &QPushButton::clicked, this, &DEV9SettingsWidget::onEthHostExport); connect(m_ui.ethHostImport, &QPushButton::clicked, this, &DEV9SettingsWidget::onEthHostImport); - if (m_dialog->isPerGameSettings()) - m_ui.ethTabWidget->setTabEnabled(1, false); + connect(m_ui.ethHostPerGame, &QPushButton::clicked, this, &DEV9SettingsWidget::onEthHostPerGame); ////////////////////////////////////////////////////////////////////////// // HDD Settings @@ -495,7 +494,7 @@ void DEV9SettingsWidget::onEthHostDel() void DEV9SettingsWidget::onEthHostExport() { - std::vector hosts = ListHostsConfig(); + std::vector hosts = ListHostsConfig().value(); DEV9DnsHostDialog exportDialog(hosts, this); @@ -609,6 +608,55 @@ void DEV9SettingsWidget::onEthHostImport() QMessageBox::StandardButton::Ok, QMessageBox::StandardButton::Ok); } +void DEV9SettingsWidget::onEthHostPerGame() +{ + const std::optional hostLengthOpt = m_dialog->getIntValue("DEV9/Eth/Hosts", "Count", std::nullopt); + if (!hostLengthOpt.has_value()) + { + QMessageBox::StandardButton ret = QMessageBox::question(this, tr("Per Game Host list"), + tr("Copy global settings?"), + QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No | QMessageBox::StandardButton::Cancel, QMessageBox::StandardButton::Yes); + + switch (ret) + { + case QMessageBox::StandardButton::No: + m_dialog->setIntSettingValue("DEV9/Eth/Hosts", "Count", 0); + break; + + case QMessageBox::StandardButton::Yes: + { + m_dialog->setIntSettingValue("DEV9/Eth/Hosts", "Count", 0); + std::vector hosts = ListBaseHostsConfig(); + for (size_t i = 0; i < hosts.size(); i++) + AddNewHostConfig(hosts[i]); + break; + } + + case QMessageBox::StandardButton::Cancel: + return; + + default: + return; + } + } + else + { + QMessageBox::StandardButton ret = QMessageBox::question(this, tr("Per Game Host list"), + tr("Delete per game host list?"), + QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::Cancel, QMessageBox::StandardButton::Yes); + + if (ret == QMessageBox::StandardButton::Yes) + { + const int hostLength = CountHostsConfig(); + for (int i = hostLength - 1; i >= 0; i--) + DeleteHostConfig(i); + } + m_dialog->setIntSettingValue("DEV9/Eth/Hosts", nullptr, std::nullopt); + } + + RefreshHostList(); +} + void DEV9SettingsWidget::onEthHostEdit(QStandardItem* item) { const int row = item->row(); @@ -825,9 +873,42 @@ void DEV9SettingsWidget::RefreshHostList() while (m_ethHost_model->rowCount() > 0) m_ethHost_model->removeRow(0); - //Load list - std::vector hosts = ListHostsConfig(); + bool enableHostsUi; + std::vector hosts; + + if (m_dialog->isPerGameSettings()) + { + m_ui.ethHostPerGame->setVisible(true); + + std::optional> hostsOpt = ListHostsConfig(); + if (hostsOpt.has_value()) + { + m_ui.ethHostPerGame->setText(tr("Use Global")); + hosts = hostsOpt.value(); + enableHostsUi = true; + } + else + { + m_ui.ethHostPerGame->setText(tr("Override")); + hosts = ListBaseHostsConfig(); + enableHostsUi = false; + } + } + else + { + m_ui.ethHostPerGame->setVisible(false); + hosts = ListHostsConfig().value(); + enableHostsUi = true; + } + + m_ui.ethHosts->setEnabled(enableHostsUi); + m_ui.ethHostAdd->setEnabled(enableHostsUi); + m_ui.ethHostDel->setEnabled(enableHostsUi); + m_ui.ethHostExport->setEnabled(enableHostsUi); + m_ui.ethHostImport->setEnabled(enableHostsUi); + + //Load list for (size_t i = 0; i < hosts.size(); i++) { HostEntryUi entry = hosts[i]; @@ -863,11 +944,21 @@ int DEV9SettingsWidget::CountHostsConfig() return m_dialog->getIntValue("DEV9/Eth/Hosts", "Count", 0).value(); } -std::vector DEV9SettingsWidget::ListHostsConfig() +std::optional> DEV9SettingsWidget::ListHostsConfig() { std::vector hosts; - const int hostLength = CountHostsConfig(); + std::optional hostLengthOpt; + if (m_dialog->isPerGameSettings()) + { + hostLengthOpt = m_dialog->getIntValue("DEV9/Eth/Hosts", "Count", std::nullopt); + if (!hostLengthOpt.has_value()) + return std::nullopt; + } + else + hostLengthOpt = m_dialog->getIntValue("DEV9/Eth/Hosts", "Count", 0); + + const int hostLength = hostLengthOpt.value(); for (int i = 0; i < hostLength; i++) { std::string section = "DEV9/Eth/Hosts/Host" + std::to_string(i); @@ -883,6 +974,26 @@ std::vector DEV9SettingsWidget::ListHostsConfig() return hosts; } +std::vector DEV9SettingsWidget::ListBaseHostsConfig() +{ + std::vector hosts; + + const int hostLength = Host::GetBaseIntSettingValue("DEV9/Eth/Hosts", "Count", 0); + for (int i = 0; i < hostLength; i++) + { + std::string section = "DEV9/Eth/Hosts/Host" + std::to_string(i); + + HostEntryUi entry; + entry.Url = Host::GetBaseStringSettingValue(section.c_str(), "Url", ""); + entry.Desc = Host::GetBaseStringSettingValue(section.c_str(), "Desc", ""); + entry.Address = Host::GetBaseStringSettingValue(section.c_str(), "Address", ""); + entry.Enabled = Host::GetBaseBoolSettingValue(section.c_str(), "Enabled", false); + hosts.push_back(entry); + } + + return hosts; +} + void DEV9SettingsWidget::AddNewHostConfig(const HostEntryUi& host) { const int hostLength = CountHostsConfig(); diff --git a/pcsx2-qt/Settings/DEV9SettingsWidget.h b/pcsx2-qt/Settings/DEV9SettingsWidget.h index 8bf21f87be..c66d5be48e 100644 --- a/pcsx2-qt/Settings/DEV9SettingsWidget.h +++ b/pcsx2-qt/Settings/DEV9SettingsWidget.h @@ -42,6 +42,7 @@ private Q_SLOTS: void onEthHostDel(); void onEthHostExport(); void onEthHostImport(); + void onEthHostPerGame(); void onEthHostEdit(QStandardItem* item); void onHddEnabledChanged(int state); @@ -63,7 +64,8 @@ private: void AddAdapter(const AdapterEntry& adapter); void RefreshHostList(); int CountHostsConfig(); - std::vector ListHostsConfig(); + std::optional> ListHostsConfig(); + std::vector ListBaseHostsConfig(); void AddNewHostConfig(const HostEntryUi& host); void DeleteHostConfig(int index); diff --git a/pcsx2-qt/Settings/DEV9SettingsWidget.ui b/pcsx2-qt/Settings/DEV9SettingsWidget.ui index bfbbd8cda5..fb64505c54 100644 --- a/pcsx2-qt/Settings/DEV9SettingsWidget.ui +++ b/pcsx2-qt/Settings/DEV9SettingsWidget.ui @@ -206,6 +206,13 @@ + + + + Per game + + +