Skip to content

Commit

Permalink
Migrate -lang setting from QSettings to settings.json
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanofsky committed May 26, 2022
1 parent 9a016a3 commit 504b06b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/qt/forms/optionsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@
<item>
<widget class="QLabel" name="overriddenByCommandLineInfoLabel">
<property name="text">
<string>Options set in this dialog are overridden by the command line or in the configuration file:</string>
<string>Options set in this dialog are overridden by the command line:</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
Expand Down
21 changes: 7 additions & 14 deletions src/qt/optionsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ static const char* SettingName(OptionsModel::OptionID option)
case OptionsModel::ProxyIPTor: return "onion";
case OptionsModel::ProxyPortTor: return "onion";
case OptionsModel::ProxyUseTor: return "onion";
case OptionsModel::Language: return "lang";
default: throw std::logic_error(strprintf("GUI option %i has no corresponding node setting.", option));
}
}
Expand Down Expand Up @@ -137,6 +138,7 @@ bool OptionsModel::Init(bilingual_str& error)
ProxySetting onion = ParseProxyString(SettingToString(node().getPersistentSetting("onion"), GetDefaultProxyAddress().toStdString()));
m_onion_ip = onion.ip;
m_onion_port = onion.port;
language = QString::fromStdString(SettingToString(node().getPersistentSetting("lang"), ""));

checkAndMigrate();

Expand Down Expand Up @@ -190,7 +192,7 @@ bool OptionsModel::Init(bilingual_str& error)
// These are shared with the core or have a command-line parameter
// and we want command-line parameters to overwrite the GUI settings.
for (OptionID option : {DatabaseCache, ThreadsScriptVerif, SpendZeroConfChange, ExternalSignerPath, MapPortUPnP,
MapPortNatpmp, Listen, Server, Prune, ProxyUse, ProxyUseTor}) {
MapPortNatpmp, Listen, Server, Prune, ProxyUse, ProxyUseTor, Language}) {
std::string setting = SettingName(option);
if (node().isSettingIgnored(setting)) addOverriddenOption("-" + setting);
try {
Expand All @@ -205,9 +207,6 @@ bool OptionsModel::Init(bilingual_str& error)
}

// If setting doesn't exist create it with defaults.
//
// If gArgs.SoftSetArg() or gArgs.SoftSetBoolArg() return false we were overridden
// by command-line and show this in the UI.

// Main
if (!settings.contains("strDataDir"))
Expand All @@ -222,13 +221,6 @@ bool OptionsModel::Init(bilingual_str& error)
#endif

// Display
if (!settings.contains("language"))
settings.setValue("language", "");
if (!gArgs.SoftSetArg("-lang", settings.value("language").toString().toStdString()))
addOverriddenOption("-lang");

language = settings.value("language").toString();

if (!settings.contains("UseEmbeddedMonospacedFont")) {
settings.setValue("UseEmbeddedMonospacedFont", "true");
}
Expand Down Expand Up @@ -421,7 +413,7 @@ QVariant OptionsModel::getOption(OptionID option) const
case ThirdPartyTxUrls:
return strThirdPartyTxUrls;
case Language:
return settings.value("language");
return QString::fromStdString(SettingToString(setting(), ""));
case UseEmbeddedMonospacedFont:
return m_use_embedded_monospaced_font;
case CoinControlFeatures:
Expand Down Expand Up @@ -564,8 +556,8 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value)
}
break;
case Language:
if (settings.value("language") != value) {
settings.setValue("language", value);
if (changed()) {
update(value.toString().toStdString());
setRestartRequired(true);
}
break;
Expand Down Expand Up @@ -711,6 +703,7 @@ void OptionsModel::checkAndMigrate()
migrate_setting(ProxyUse, "fUseProxy");
migrate_setting(ProxyIPTor, "addrSeparateProxyTor");
migrate_setting(ProxyUseTor, "fUseSeparateProxyTor");
migrate_setting(Language, "language");

// In case migrating QSettings caused any settings value to change, rerun
// parameter interaction code to update other settings. This is particularly
Expand Down

0 comments on commit 504b06b

Please sign in to comment.