Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only write options after onboarding #284

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/qml/bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this?

Suggested change
#include <qt/optionsmodel.h>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is needed for PruneMiBtoGB i believe

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: accidentally removed the last line break?

Suggested change
}
}

Copy link
Contributor Author

@johnny9 johnny9 May 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

already has a newline character at the end of the file. don't need an additional blank line.

}
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