mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 06:52:36 +01:00
Migrate -upnp and -natpmp settings from QSettings to settings.json
This also effectively reverts 58e8364dcd
from
#18077, applying upnp and natpmp settings from the optionsmodel class instead
of the optionsdialog class. This makes sense because model code, not view code
is responsible for applying all other settings, and because leaving these
settings half-applied in optionsmodel seems error prone and could lead to bugs.
(These things were discussed a little in
https://github.com/bitcoin/bitcoin/pull/18077#discussion_r560381734)
This commit is contained in:
parent
1dc4fc29c1
commit
d2ada6e635
3 changed files with 18 additions and 22 deletions
|
@ -26,7 +26,6 @@
|
||||||
#include <QIntValidator>
|
#include <QIntValidator>
|
||||||
#include <QLocale>
|
#include <QLocale>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QSettings>
|
|
||||||
#include <QSystemTrayIcon>
|
#include <QSystemTrayIcon>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
|
@ -56,10 +55,6 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
|
||||||
#ifndef USE_NATPMP
|
#ifndef USE_NATPMP
|
||||||
ui->mapPortNatpmp->setEnabled(false);
|
ui->mapPortNatpmp->setEnabled(false);
|
||||||
#endif
|
#endif
|
||||||
connect(this, &QDialog::accepted, [this](){
|
|
||||||
QSettings settings;
|
|
||||||
model->node().mapPort(settings.value("fUseUPnP").toBool(), settings.value("fUseNatpmp").toBool());
|
|
||||||
});
|
|
||||||
|
|
||||||
ui->proxyIp->setEnabled(false);
|
ui->proxyIp->setEnabled(false);
|
||||||
ui->proxyPort->setEnabled(false);
|
ui->proxyPort->setEnabled(false);
|
||||||
|
|
|
@ -41,6 +41,8 @@ static const char* SettingName(OptionsModel::OptionID option)
|
||||||
case OptionsModel::ThreadsScriptVerif: return "par";
|
case OptionsModel::ThreadsScriptVerif: return "par";
|
||||||
case OptionsModel::SpendZeroConfChange: return "spendzeroconfchange";
|
case OptionsModel::SpendZeroConfChange: return "spendzeroconfchange";
|
||||||
case OptionsModel::ExternalSignerPath: return "signer";
|
case OptionsModel::ExternalSignerPath: return "signer";
|
||||||
|
case OptionsModel::MapPortUPnP: return "upnp";
|
||||||
|
case OptionsModel::MapPortNatpmp: return "natpmp";
|
||||||
default: throw std::logic_error(strprintf("GUI option %i has no corresponding node setting.", option));
|
default: throw std::logic_error(strprintf("GUI option %i has no corresponding node setting.", option));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,7 +130,8 @@ bool OptionsModel::Init(bilingual_str& error)
|
||||||
|
|
||||||
// These are shared with the core or have a command-line parameter
|
// These are shared with the core or have a command-line parameter
|
||||||
// and we want command-line parameters to overwrite the GUI settings.
|
// and we want command-line parameters to overwrite the GUI settings.
|
||||||
for (OptionID option : {DatabaseCache, ThreadsScriptVerif, SpendZeroConfChange, ExternalSignerPath}) {
|
for (OptionID option : {DatabaseCache, ThreadsScriptVerif, SpendZeroConfChange, ExternalSignerPath, MapPortUPnP,
|
||||||
|
MapPortNatpmp}) {
|
||||||
std::string setting = SettingName(option);
|
std::string setting = SettingName(option);
|
||||||
if (node().isSettingIgnored(setting)) addOverriddenOption("-" + setting);
|
if (node().isSettingIgnored(setting)) addOverriddenOption("-" + setting);
|
||||||
try {
|
try {
|
||||||
|
@ -165,18 +168,6 @@ bool OptionsModel::Init(bilingual_str& error)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Network
|
// Network
|
||||||
if (!settings.contains("fUseUPnP"))
|
|
||||||
settings.setValue("fUseUPnP", DEFAULT_UPNP);
|
|
||||||
if (!gArgs.SoftSetBoolArg("-upnp", settings.value("fUseUPnP").toBool()))
|
|
||||||
addOverriddenOption("-upnp");
|
|
||||||
|
|
||||||
if (!settings.contains("fUseNatpmp")) {
|
|
||||||
settings.setValue("fUseNatpmp", DEFAULT_NATPMP);
|
|
||||||
}
|
|
||||||
if (!gArgs.SoftSetBoolArg("-natpmp", settings.value("fUseNatpmp").toBool())) {
|
|
||||||
addOverriddenOption("-natpmp");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!settings.contains("fListen"))
|
if (!settings.contains("fListen"))
|
||||||
settings.setValue("fListen", DEFAULT_LISTEN);
|
settings.setValue("fListen", DEFAULT_LISTEN);
|
||||||
const bool listen{settings.value("fListen").toBool()};
|
const bool listen{settings.value("fListen").toBool()};
|
||||||
|
@ -390,13 +381,13 @@ QVariant OptionsModel::getOption(OptionID option) const
|
||||||
return fMinimizeToTray;
|
return fMinimizeToTray;
|
||||||
case MapPortUPnP:
|
case MapPortUPnP:
|
||||||
#ifdef USE_UPNP
|
#ifdef USE_UPNP
|
||||||
return settings.value("fUseUPnP");
|
return SettingToBool(setting(), DEFAULT_UPNP);
|
||||||
#else
|
#else
|
||||||
return false;
|
return false;
|
||||||
#endif // USE_UPNP
|
#endif // USE_UPNP
|
||||||
case MapPortNatpmp:
|
case MapPortNatpmp:
|
||||||
#ifdef USE_NATPMP
|
#ifdef USE_NATPMP
|
||||||
return settings.value("fUseNatpmp");
|
return SettingToBool(setting(), DEFAULT_NATPMP);
|
||||||
#else
|
#else
|
||||||
return false;
|
return false;
|
||||||
#endif // USE_NATPMP
|
#endif // USE_NATPMP
|
||||||
|
@ -478,10 +469,16 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value)
|
||||||
settings.setValue("fMinimizeToTray", fMinimizeToTray);
|
settings.setValue("fMinimizeToTray", fMinimizeToTray);
|
||||||
break;
|
break;
|
||||||
case MapPortUPnP: // core option - can be changed on-the-fly
|
case MapPortUPnP: // core option - can be changed on-the-fly
|
||||||
settings.setValue("fUseUPnP", value.toBool());
|
if (changed()) {
|
||||||
|
update(value.toBool());
|
||||||
|
node().mapPort(value.toBool(), getOption(MapPortNatpmp).toBool());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case MapPortNatpmp: // core option - can be changed on-the-fly
|
case MapPortNatpmp: // core option - can be changed on-the-fly
|
||||||
settings.setValue("fUseNatpmp", value.toBool());
|
if (changed()) {
|
||||||
|
update(value.toBool());
|
||||||
|
node().mapPort(getOption(MapPortUPnP).toBool(), value.toBool());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case MinimizeOnClose:
|
case MinimizeOnClose:
|
||||||
fMinimizeOnClose = value.toBool();
|
fMinimizeOnClose = value.toBool();
|
||||||
|
@ -698,4 +695,6 @@ void OptionsModel::checkAndMigrate()
|
||||||
migrate_setting(SpendZeroConfChange, "bSpendZeroConfChange");
|
migrate_setting(SpendZeroConfChange, "bSpendZeroConfChange");
|
||||||
migrate_setting(ExternalSignerPath, "external_signer_path");
|
migrate_setting(ExternalSignerPath, "external_signer_path");
|
||||||
#endif
|
#endif
|
||||||
|
migrate_setting(MapPortUPnP, "fUseUPnP");
|
||||||
|
migrate_setting(MapPortNatpmp, "fUseNatpmp");
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ void OptionTests::migrateSettings()
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
settings.setValue("nDatabaseCache", 600);
|
settings.setValue("nDatabaseCache", 600);
|
||||||
settings.setValue("nThreadsScriptVerif", 12);
|
settings.setValue("nThreadsScriptVerif", 12);
|
||||||
|
settings.setValue("fUseUPnP", false);
|
||||||
|
|
||||||
settings.sync();
|
settings.sync();
|
||||||
|
|
||||||
|
@ -42,6 +43,7 @@ void OptionTests::migrateSettings()
|
||||||
QVERIFY(options.Init(error));
|
QVERIFY(options.Init(error));
|
||||||
QVERIFY(!settings.contains("nDatabaseCache"));
|
QVERIFY(!settings.contains("nDatabaseCache"));
|
||||||
QVERIFY(!settings.contains("nThreadsScriptVerif"));
|
QVERIFY(!settings.contains("nThreadsScriptVerif"));
|
||||||
|
QVERIFY(!settings.contains("fUseUPnP"));
|
||||||
|
|
||||||
std::ifstream file(gArgs.GetDataDirNet() / "settings.json");
|
std::ifstream file(gArgs.GetDataDirNet() / "settings.json");
|
||||||
QCOMPARE(std::string(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()).c_str(), "{\n"
|
QCOMPARE(std::string(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()).c_str(), "{\n"
|
||||||
|
|
Loading…
Add table
Reference in a new issue