Skip to content

Commit

Permalink
Merge #284: Only write options after onboarding
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed May 14, 2024
2 parents 085805f + 9e56907 commit 84d388d
Show file tree
Hide file tree
Showing 4 changed files with 68 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 @@ -298,9 +298,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();
Expand Down
73 changes: 63 additions & 10 deletions src/qml/models/options_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <common/settings.h>
#include <common/system.h>
#include <interfaces/node.h>
#include <mapport.h>
#include <qt/guiconstants.h>
#include <qt/guiutil.h>
#include <qt/optionsmodel.h>
Expand All @@ -23,23 +24,34 @@
#include <QDir>
#include <QSettings>

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

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)
{
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 @@ -48,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);
}
}
Expand All @@ -57,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);
}
}
Expand All @@ -66,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);
}
}
Expand All @@ -75,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);
}
}
Expand All @@ -84,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);
}
}
Expand All @@ -93,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);
}
}
Expand All @@ -102,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);
}
}
Expand Down Expand Up @@ -136,4 +162,31 @@ void OptionsQmlModel::setCustomDataDirArgs(QString path)
// TODO: add actual custom data wiring
qDebug() << "PlaceHolder: Created data directory: " << path;
}
}
}

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 @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/qml/pages/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ ApplicationWindow {
OnboardingConnection {}

onFinishedChanged: {
optionsModel.onboard()
if (AppMode.walletEnabled && AppMode.isDesktop) {
main.push(desktopWallets)
} else {
Expand Down

0 comments on commit 84d388d

Please sign in to comment.