Skip to content

Commit 84d388d

Browse files
committed
Merge #284: Only write options after onboarding
9e56907 qml: only write options after onboarding (johnny9) c0ebff2 qml: Set OptionQmlModel initial property values (johnny9) Pull request description: [![Windows](https://img.shields.io/badge/OS-Windows-green)](https://api.cirrus-ci.com/v1/artifact/github/bitcoin-core/gui-qml/win64/insecure_win_gui.zip?branch=pull/284) [![Intel macOS](https://img.shields.io/badge/OS-Intel%20macOS-green)](https://api.cirrus-ci.com/v1/artifact/github/bitcoin-core/gui-qml/macos/insecure_mac_gui.zip?branch=pull/284) [![Apple Silicon macOS](https://img.shields.io/badge/OS-Apple%20Silicon%20macOS-green)](https://api.cirrus-ci.com/v1/artifact/github/bitcoin-core/gui-qml/macos_arm64/insecure_mac_arm64_gui.zip?branch=pull/284) [![ARM64 Android](https://img.shields.io/badge/OS-Android-green)](https://api.cirrus-ci.com/v1/artifact/github/bitcoin-core/gui-qml/android/unsecure_android_apk.zip?branch=pull/284) ACKs for top commit: D33r-Gee: re ACK 9e56907 on Ubuntu 22.04 works as expected pablomartin4btc: re-ACK 9e56907 Tree-SHA512: 6835569e9a3ab340c94c507867c578e46bb86d8c0c8cad639ed97dd09e7edcdbe2b21c1b58fab74c989cbda22acc768dc6004e27d9a6a66b085ea5ac3ec49474
2 parents 085805f + 9e56907 commit 84d388d

File tree

4 files changed

+68
-13
lines changed

4 files changed

+68
-13
lines changed

src/qml/bitcoin.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,8 @@ int QmlGuiMain(int argc, char* argv[])
298298
engine.rootContext()->setContextProperty("peerTableModel", &peer_model);
299299
engine.rootContext()->setContextProperty("peerListModelProxy", &peer_model_sort_proxy);
300300

301-
OptionsQmlModel options_model{*node};
301+
OptionsQmlModel options_model(*node, !need_onboarding.toBool());
302302
engine.rootContext()->setContextProperty("optionsModel", &options_model);
303-
304303
engine.rootContext()->setContextProperty("needOnboarding", need_onboarding);
305304

306305
AppMode app_mode = SetupAppMode();

src/qml/models/options_model.cpp

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <common/settings.h>
99
#include <common/system.h>
1010
#include <interfaces/node.h>
11+
#include <mapport.h>
1112
#include <qt/guiconstants.h>
1213
#include <qt/guiutil.h>
1314
#include <qt/optionsmodel.h>
@@ -23,23 +24,34 @@
2324
#include <QDir>
2425
#include <QSettings>
2526

26-
OptionsQmlModel::OptionsQmlModel(interfaces::Node& node)
27+
OptionsQmlModel::OptionsQmlModel(interfaces::Node& node, bool is_onboarded)
2728
: m_node{node}
29+
, m_onboarded{is_onboarded}
2830
{
2931
m_dbcache_size_mib = SettingToInt(m_node.getPersistentSetting("dbcache"), nDefaultDbCache);
3032

33+
m_listen = SettingToBool(m_node.getPersistentSetting("listen"), DEFAULT_LISTEN);
34+
35+
m_natpmp = SettingToBool(m_node.getPersistentSetting("natpmp"), DEFAULT_NATPMP);
36+
3137
int64_t prune_value{SettingToInt(m_node.getPersistentSetting("prune"), 0)};
3238
m_prune = (prune_value > 1);
3339
m_prune_size_gb = m_prune ? PruneMiBtoGB(prune_value) : DEFAULT_PRUNE_TARGET_GB;
3440

3541
m_script_threads = SettingToInt(m_node.getPersistentSetting("par"), DEFAULT_SCRIPTCHECK_THREADS);
42+
43+
m_server = SettingToBool(m_node.getPersistentSetting("server"), false);
44+
45+
m_upnp = SettingToBool(m_node.getPersistentSetting("upnp"), DEFAULT_UPNP);
3646
}
3747

3848
void OptionsQmlModel::setDbcacheSizeMiB(int new_dbcache_size_mib)
3949
{
4050
if (new_dbcache_size_mib != m_dbcache_size_mib) {
4151
m_dbcache_size_mib = new_dbcache_size_mib;
42-
m_node.updateRwSetting("dbcache", new_dbcache_size_mib);
52+
if (m_onboarded) {
53+
m_node.updateRwSetting("dbcache", new_dbcache_size_mib);
54+
}
4355
Q_EMIT dbcacheSizeMiBChanged(new_dbcache_size_mib);
4456
}
4557
}
@@ -48,7 +60,9 @@ void OptionsQmlModel::setListen(bool new_listen)
4860
{
4961
if (new_listen != m_listen) {
5062
m_listen = new_listen;
51-
m_node.updateRwSetting("listen", new_listen);
63+
if (m_onboarded) {
64+
m_node.updateRwSetting("listen", new_listen);
65+
}
5266
Q_EMIT listenChanged(new_listen);
5367
}
5468
}
@@ -57,7 +71,9 @@ void OptionsQmlModel::setNatpmp(bool new_natpmp)
5771
{
5872
if (new_natpmp != m_natpmp) {
5973
m_natpmp = new_natpmp;
60-
m_node.updateRwSetting("natpmp", new_natpmp);
74+
if (m_onboarded) {
75+
m_node.updateRwSetting("natpmp", new_natpmp);
76+
}
6177
Q_EMIT natpmpChanged(new_natpmp);
6278
}
6379
}
@@ -66,7 +82,9 @@ void OptionsQmlModel::setPrune(bool new_prune)
6682
{
6783
if (new_prune != m_prune) {
6884
m_prune = new_prune;
69-
m_node.updateRwSetting("prune", pruneSetting());
85+
if (m_onboarded) {
86+
m_node.updateRwSetting("prune", pruneSetting());
87+
}
7088
Q_EMIT pruneChanged(new_prune);
7189
}
7290
}
@@ -75,7 +93,9 @@ void OptionsQmlModel::setPruneSizeGB(int new_prune_size_gb)
7593
{
7694
if (new_prune_size_gb != m_prune_size_gb) {
7795
m_prune_size_gb = new_prune_size_gb;
78-
m_node.updateRwSetting("prune", pruneSetting());
96+
if (m_onboarded) {
97+
m_node.updateRwSetting("prune", pruneSetting());
98+
}
7999
Q_EMIT pruneSizeGBChanged(new_prune_size_gb);
80100
}
81101
}
@@ -84,7 +104,9 @@ void OptionsQmlModel::setScriptThreads(int new_script_threads)
84104
{
85105
if (new_script_threads != m_script_threads) {
86106
m_script_threads = new_script_threads;
87-
m_node.updateRwSetting("par", new_script_threads);
107+
if (m_onboarded) {
108+
m_node.updateRwSetting("par", new_script_threads);
109+
}
88110
Q_EMIT scriptThreadsChanged(new_script_threads);
89111
}
90112
}
@@ -93,7 +115,9 @@ void OptionsQmlModel::setServer(bool new_server)
93115
{
94116
if (new_server != m_server) {
95117
m_server = new_server;
96-
m_node.updateRwSetting("server", new_server);
118+
if (m_onboarded) {
119+
m_node.updateRwSetting("server", new_server);
120+
}
97121
Q_EMIT serverChanged(new_server);
98122
}
99123
}
@@ -102,7 +126,9 @@ void OptionsQmlModel::setUpnp(bool new_upnp)
102126
{
103127
if (new_upnp != m_upnp) {
104128
m_upnp = new_upnp;
105-
m_node.updateRwSetting("upnp", new_upnp);
129+
if (m_onboarded) {
130+
m_node.updateRwSetting("upnp", new_upnp);
131+
}
106132
Q_EMIT upnpChanged(new_upnp);
107133
}
108134
}
@@ -136,4 +162,31 @@ void OptionsQmlModel::setCustomDataDirArgs(QString path)
136162
// TODO: add actual custom data wiring
137163
qDebug() << "PlaceHolder: Created data directory: " << path;
138164
}
139-
}
165+
}
166+
167+
void OptionsQmlModel::onboard()
168+
{
169+
m_node.resetSettings();
170+
if (m_dbcache_size_mib != nDefaultDbCache) {
171+
m_node.updateRwSetting("dbcache", m_dbcache_size_mib);
172+
}
173+
if (m_listen) {
174+
m_node.updateRwSetting("listen", m_listen);
175+
}
176+
if (m_natpmp) {
177+
m_node.updateRwSetting("natpmp", m_natpmp);
178+
}
179+
if (m_prune) {
180+
m_node.updateRwSetting("prune", pruneSetting());
181+
}
182+
if (m_script_threads != DEFAULT_SCRIPTCHECK_THREADS) {
183+
m_node.updateRwSetting("par", m_script_threads);
184+
}
185+
if (m_server) {
186+
m_node.updateRwSetting("server", m_server);
187+
}
188+
if (m_upnp) {
189+
m_node.updateRwSetting("upnp", m_upnp);
190+
}
191+
m_onboarded = true;
192+
}

src/qml/models/options_model.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class OptionsQmlModel : public QObject
3838
Q_PROPERTY(QUrl getDefaultDataDirectory READ getDefaultDataDirectory CONSTANT)
3939

4040
public:
41-
explicit OptionsQmlModel(interfaces::Node& node);
41+
explicit OptionsQmlModel(interfaces::Node& node, bool is_onboarded);
4242

4343
int dbcacheSizeMiB() const { return m_dbcache_size_mib; }
4444
void setDbcacheSizeMiB(int new_dbcache_size_mib);
@@ -69,6 +69,7 @@ public Q_SLOTS:
6969
m_custom_datadir_string = new_custom_datadir_string;
7070
m_signalReceived = true;
7171
}
72+
Q_INVOKABLE void onboard();
7273

7374
Q_SIGNALS:
7475
void dbcacheSizeMiBChanged(int new_dbcache_size_mib);
@@ -83,6 +84,7 @@ public Q_SLOTS:
8384

8485
private:
8586
interfaces::Node& m_node;
87+
bool m_onboarded;
8688

8789
// Properties that are exposed to QML.
8890
int m_dbcache_size_mib;

src/qml/pages/main.qml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ ApplicationWindow {
7878
OnboardingConnection {}
7979

8080
onFinishedChanged: {
81+
optionsModel.onboard()
8182
if (AppMode.walletEnabled && AppMode.isDesktop) {
8283
main.push(desktopWallets)
8384
} else {

0 commit comments

Comments
 (0)