Skip to content

Commit

Permalink
qml: only write options after onboarding
Browse files Browse the repository at this point in the history
  • Loading branch information
johnny9 committed Sep 1, 2023
1 parent abd3ba1 commit 51df97d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 13 deletions.
3 changes: 1 addition & 2 deletions src/qml/bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,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);
#ifdef __ANDROID__
AppMode app_mode(AppMode::MOBILE);
Expand Down
62 changes: 53 additions & 9 deletions src/qml/models/options_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

#include <cassert>

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);

Expand All @@ -32,7 +33,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);
}
}
Expand All @@ -41,7 +44,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);
}
}
Expand All @@ -50,7 +55,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);
}
}
Expand All @@ -59,7 +66,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);
}
}
Expand All @@ -68,7 +77,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);
}
}
Expand All @@ -77,7 +88,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);
}
}
Expand All @@ -86,7 +99,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);
}
}
Expand All @@ -95,7 +110,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);
}
}
Expand All @@ -105,3 +122,30 @@ common::SettingsValue OptionsQmlModel::pruneSetting() const
assert(!m_prune || m_prune_size_gb >= 1);
return m_prune ? PruneGBtoMiB(m_prune_size_gb) : 0;
}

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;
}
4 changes: 3 additions & 1 deletion src/qml/models/options_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class OptionsQmlModel : public QObject
Q_PROPERTY(bool upnp READ upnp WRITE setUpnp NOTIFY upnpChanged)

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);
Expand All @@ -56,6 +56,7 @@ class OptionsQmlModel : public QObject
void setServer(bool new_server);
bool upnp() const { return m_upnp; }
void setUpnp(bool new_upnp);
Q_INVOKABLE void onboard();

Q_SIGNALS:
void dbcacheSizeMiBChanged(int new_dbcache_size_mib);
Expand All @@ -69,6 +70,7 @@ class OptionsQmlModel : public QObject

private:
interfaces::Node& m_node;
bool m_onboarded;

// Properties that are exposed to QML.
int m_dbcache_size_mib;
Expand Down
5 changes: 4 additions & 1 deletion src/qml/pages/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ ApplicationWindow {
OnboardingStorageAmount {}
OnboardingConnection {}

onFinishedChanged: main.push(node)
onFinishedChanged: {
optionsModel.onboard()
main.push(node)
}
}
}

Expand Down

0 comments on commit 51df97d

Please sign in to comment.