From c0ebff2971221cad1cf4819544505a3b22ed8055 Mon Sep 17 00:00:00 2001 From: johnny9 <985648+johnny9@users.noreply.github.com> Date: Thu, 28 Mar 2024 23:25:28 -0400 Subject: [PATCH 1/2] qml: Set OptionQmlModel initial property values --- src/qml/models/options_model.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/qml/models/options_model.cpp b/src/qml/models/options_model.cpp index 082ed06513..60b2989e49 100644 --- a/src/qml/models/options_model.cpp +++ b/src/qml/models/options_model.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -28,11 +29,19 @@ OptionsQmlModel::OptionsQmlModel(interfaces::Node& node) { m_dbcache_size_mib = SettingToInt(m_node.getPersistentSetting("dbcache"), nDefaultDbCache); + m_listen = SettingToBool(m_node.getPersistentSetting("listen"), DEFAULT_LISTEN); + + m_natpmp = SettingToBool(m_node.getPersistentSetting("natpmp"), DEFAULT_NATPMP); + int64_t prune_value{SettingToInt(m_node.getPersistentSetting("prune"), 0)}; m_prune = (prune_value > 1); m_prune_size_gb = m_prune ? PruneMiBtoGB(prune_value) : DEFAULT_PRUNE_TARGET_GB; m_script_threads = SettingToInt(m_node.getPersistentSetting("par"), DEFAULT_SCRIPTCHECK_THREADS); + + m_server = SettingToBool(m_node.getPersistentSetting("server"), false); + + m_upnp = SettingToBool(m_node.getPersistentSetting("upnp"), DEFAULT_UPNP); } void OptionsQmlModel::setDbcacheSizeMiB(int new_dbcache_size_mib) From 9e569074a1735976ffb324dfb5531c24591f3252 Mon Sep 17 00:00:00 2001 From: johnny9 <985648+johnny9@users.noreply.github.com> Date: Wed, 8 Mar 2023 22:26:56 -0500 Subject: [PATCH 2/2] qml: only write options after onboarding --- src/qml/bitcoin.cpp | 3 +- src/qml/models/options_model.cpp | 64 +++++++++++++++++++++++++++----- src/qml/models/options_model.h | 4 +- src/qml/pages/main.qml | 1 + 4 files changed, 59 insertions(+), 13 deletions(-) diff --git a/src/qml/bitcoin.cpp b/src/qml/bitcoin.cpp index ee427347fa..5315d0d623 100644 --- a/src/qml/bitcoin.cpp +++ b/src/qml/bitcoin.cpp @@ -299,9 +299,8 @@ int QmlGuiMain(int argc, char* argv[]) engine.rootContext()->setContextProperty("peerTableModel", &peer_model); engine.rootContext()->setContextProperty("peerListModelProxy", &peer_model_sort_proxy); - OptionsQmlModel options_model{*node}; + OptionsQmlModel options_model(*node, !need_onboarding.toBool()); engine.rootContext()->setContextProperty("optionsModel", &options_model); - engine.rootContext()->setContextProperty("needOnboarding", need_onboarding); AppMode app_mode = SetupAppMode(); diff --git a/src/qml/models/options_model.cpp b/src/qml/models/options_model.cpp index 60b2989e49..0125e56354 100644 --- a/src/qml/models/options_model.cpp +++ b/src/qml/models/options_model.cpp @@ -24,8 +24,9 @@ #include #include -OptionsQmlModel::OptionsQmlModel(interfaces::Node& node) +OptionsQmlModel::OptionsQmlModel(interfaces::Node& node, bool is_onboarded) : m_node{node} + , m_onboarded{is_onboarded} { m_dbcache_size_mib = SettingToInt(m_node.getPersistentSetting("dbcache"), nDefaultDbCache); @@ -48,7 +49,9 @@ void OptionsQmlModel::setDbcacheSizeMiB(int new_dbcache_size_mib) { if (new_dbcache_size_mib != m_dbcache_size_mib) { m_dbcache_size_mib = new_dbcache_size_mib; - m_node.updateRwSetting("dbcache", new_dbcache_size_mib); + if (m_onboarded) { + m_node.updateRwSetting("dbcache", new_dbcache_size_mib); + } Q_EMIT dbcacheSizeMiBChanged(new_dbcache_size_mib); } } @@ -57,7 +60,9 @@ void OptionsQmlModel::setListen(bool new_listen) { if (new_listen != m_listen) { m_listen = new_listen; - m_node.updateRwSetting("listen", new_listen); + if (m_onboarded) { + m_node.updateRwSetting("listen", new_listen); + } Q_EMIT listenChanged(new_listen); } } @@ -66,7 +71,9 @@ void OptionsQmlModel::setNatpmp(bool new_natpmp) { if (new_natpmp != m_natpmp) { m_natpmp = new_natpmp; - m_node.updateRwSetting("natpmp", new_natpmp); + if (m_onboarded) { + m_node.updateRwSetting("natpmp", new_natpmp); + } Q_EMIT natpmpChanged(new_natpmp); } } @@ -75,7 +82,9 @@ void OptionsQmlModel::setPrune(bool new_prune) { if (new_prune != m_prune) { m_prune = new_prune; - m_node.updateRwSetting("prune", pruneSetting()); + if (m_onboarded) { + m_node.updateRwSetting("prune", pruneSetting()); + } Q_EMIT pruneChanged(new_prune); } } @@ -84,7 +93,9 @@ void OptionsQmlModel::setPruneSizeGB(int new_prune_size_gb) { if (new_prune_size_gb != m_prune_size_gb) { m_prune_size_gb = new_prune_size_gb; - m_node.updateRwSetting("prune", pruneSetting()); + if (m_onboarded) { + m_node.updateRwSetting("prune", pruneSetting()); + } Q_EMIT pruneSizeGBChanged(new_prune_size_gb); } } @@ -93,7 +104,9 @@ void OptionsQmlModel::setScriptThreads(int new_script_threads) { if (new_script_threads != m_script_threads) { m_script_threads = new_script_threads; - m_node.updateRwSetting("par", new_script_threads); + if (m_onboarded) { + m_node.updateRwSetting("par", new_script_threads); + } Q_EMIT scriptThreadsChanged(new_script_threads); } } @@ -102,7 +115,9 @@ void OptionsQmlModel::setServer(bool new_server) { if (new_server != m_server) { m_server = new_server; - m_node.updateRwSetting("server", new_server); + if (m_onboarded) { + m_node.updateRwSetting("server", new_server); + } Q_EMIT serverChanged(new_server); } } @@ -111,7 +126,9 @@ void OptionsQmlModel::setUpnp(bool new_upnp) { if (new_upnp != m_upnp) { m_upnp = new_upnp; - m_node.updateRwSetting("upnp", new_upnp); + if (m_onboarded) { + m_node.updateRwSetting("upnp", new_upnp); + } Q_EMIT upnpChanged(new_upnp); } } @@ -145,4 +162,31 @@ void OptionsQmlModel::setCustomDataDirArgs(QString path) // TODO: add actual custom data wiring qDebug() << "PlaceHolder: Created data directory: " << path; } -} \ No newline at end of file +} + +void OptionsQmlModel::onboard() +{ + m_node.resetSettings(); + if (m_dbcache_size_mib != nDefaultDbCache) { + m_node.updateRwSetting("dbcache", m_dbcache_size_mib); + } + if (m_listen) { + m_node.updateRwSetting("listen", m_listen); + } + if (m_natpmp) { + m_node.updateRwSetting("natpmp", m_natpmp); + } + if (m_prune) { + m_node.updateRwSetting("prune", pruneSetting()); + } + if (m_script_threads != DEFAULT_SCRIPTCHECK_THREADS) { + m_node.updateRwSetting("par", m_script_threads); + } + if (m_server) { + m_node.updateRwSetting("server", m_server); + } + if (m_upnp) { + m_node.updateRwSetting("upnp", m_upnp); + } + m_onboarded = true; +} diff --git a/src/qml/models/options_model.h b/src/qml/models/options_model.h index 86bdacd8f8..d5f3b0b957 100644 --- a/src/qml/models/options_model.h +++ b/src/qml/models/options_model.h @@ -38,7 +38,7 @@ class OptionsQmlModel : public QObject Q_PROPERTY(QUrl getDefaultDataDirectory READ getDefaultDataDirectory CONSTANT) public: - explicit OptionsQmlModel(interfaces::Node& node); + explicit OptionsQmlModel(interfaces::Node& node, bool is_onboarded); int dbcacheSizeMiB() const { return m_dbcache_size_mib; } void setDbcacheSizeMiB(int new_dbcache_size_mib); @@ -69,6 +69,7 @@ public Q_SLOTS: m_custom_datadir_string = new_custom_datadir_string; m_signalReceived = true; } + Q_INVOKABLE void onboard(); Q_SIGNALS: void dbcacheSizeMiBChanged(int new_dbcache_size_mib); @@ -83,6 +84,7 @@ public Q_SLOTS: private: interfaces::Node& m_node; + bool m_onboarded; // Properties that are exposed to QML. int m_dbcache_size_mib; diff --git a/src/qml/pages/main.qml b/src/qml/pages/main.qml index 4c1c964d7c..471fe127c0 100644 --- a/src/qml/pages/main.qml +++ b/src/qml/pages/main.qml @@ -78,6 +78,7 @@ ApplicationWindow { OnboardingConnection {} onFinishedChanged: { + optionsModel.onboard() if (AppMode.walletEnabled && AppMode.isDesktop) { main.push(desktopWallets) } else {