Skip to content

Introduce OptionsModel backend, Wire up Storage Amount settings to backend #207

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

Merged
merged 3 commits into from
Jan 17, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Makefile.qt.include
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ QT_FORMS_UI = \
QT_MOC_CPP = \
qml/moc_appmode.cpp \
qml/moc_nodemodel.cpp \
qml/moc_options_model.cpp \
qt/moc_addressbookpage.cpp \
qt/moc_addresstablemodel.cpp \
qt/moc_askpassphrasedialog.cpp \
Expand Down Expand Up @@ -112,6 +113,7 @@ BITCOIN_QT_H = \
qml/bitcoin.h \
qml/imageprovider.h \
qml/nodemodel.h \
qml/options_model.h \
qml/util.h \
qt/addressbookpage.h \
qt/addresstablemodel.h \
Expand Down Expand Up @@ -291,6 +293,7 @@ BITCOIN_QML_BASE_CPP = \
qml/bitcoin.cpp \
qml/imageprovider.cpp \
qml/nodemodel.cpp \
qml/options_model.cpp \
qml/util.cpp

QML_RES_FONTS = \
Expand Down
4 changes: 4 additions & 0 deletions src/qml/bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <qml/appmode.h>
#include <qml/imageprovider.h>
#include <qml/nodemodel.h>
#include <qml/options_model.h>
#include <qml/util.h>
#include <qt/guiconstants.h>
#include <qt/guiutil.h>
Expand Down Expand Up @@ -185,6 +186,9 @@ int QmlGuiMain(int argc, char* argv[])

engine.rootContext()->setContextProperty("nodeModel", &node_model);

OptionsQmlModel options_model{*node};
engine.rootContext()->setContextProperty("optionsModel", &options_model);

#ifdef __ANDROID__
AppMode app_mode(AppMode::MOBILE);
#else
Expand Down
7 changes: 7 additions & 0 deletions src/qml/components/StorageOptions.qml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ ColumnLayout {
description: qsTr("Uses about 2GB. For simple wallet use.")
recommended: true
checked: true
onClicked: {
optionsModel.prune = true
optionsModel.pruneSizeGB = 2
}
}
OptionButton {
Layout.fillWidth: true
ButtonGroup.group: group
text: qsTr("Store all data")
description: qsTr("Uses about 550GB. Support the network.")
onClicked: {
optionsModel.prune = false
}
}
}
17 changes: 7 additions & 10 deletions src/qml/components/StorageSettings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,18 @@ ColumnLayout {
spacing: 20
Setting {
Layout.fillWidth: true
header: qsTr("Store Recent blocks only")
actionItem: OptionSwitch {}
}
Setting {
Layout.fillWidth: true
header: qsTr("Storage limit")
actionItem: ValueInput {
description: qsTr("2 GB")
header: qsTr("Store recent blocks only")
actionItem: OptionSwitch {
checked: optionsModel.prune
onToggled: optionsModel.prune = checked
}
}
Setting {
Layout.fillWidth: true
header: qsTr("Data location")
header: qsTr("Storage limit (GB)")
actionItem: ValueInput {
description: "c://.../data"
description: optionsModel.pruneSizeGB
onEditingFinished: optionsModel.pruneSizeGB = parseInt(text)
}
}
}
46 changes: 46 additions & 0 deletions src/qml/options_model.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) 2022 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <qml/options_model.h>

#include <interfaces/node.h>
#include <qt/guiconstants.h>
#include <qt/optionsmodel.h>
#include <univalue.h>
#include <util/settings.h>
#include <util/system.h>

#include <cassert>

OptionsQmlModel::OptionsQmlModel(interfaces::Node& node)
: m_node{node}
{
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;
}

void OptionsQmlModel::setPrune(bool new_prune)
{
if (new_prune != m_prune) {
m_prune = new_prune;
m_node.updateRwSetting("prune", pruneSetting());
Q_EMIT pruneChanged(new_prune);
}
}

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());
Q_EMIT pruneSizeGBChanged(new_prune_size_gb);
}
}

util::SettingsValue OptionsQmlModel::pruneSetting() const
{
assert(!m_prune || m_prune_size_gb >= 1);
return m_prune ? PruneGBtoMiB(m_prune_size_gb) : 0;
}
45 changes: 45 additions & 0 deletions src/qml/options_model.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) 2022 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_QML_OPTIONS_MODEL_H
#define BITCOIN_QML_OPTIONS_MODEL_H

#include <util/settings.h>

#include <QObject>

namespace interfaces {
class Node;
}

/** Model for Bitcoin client options. */
class OptionsQmlModel : public QObject
{
Q_OBJECT
Q_PROPERTY(bool prune READ prune WRITE setPrune NOTIFY pruneChanged)
Q_PROPERTY(int pruneSizeGB READ pruneSizeGB WRITE setPruneSizeGB NOTIFY pruneSizeGBChanged)

public:
explicit OptionsQmlModel(interfaces::Node& node);

bool prune() const { return m_prune; }
void setPrune(bool new_prune);
int pruneSizeGB() const { return m_prune_size_gb; }
void setPruneSizeGB(int new_prune_size);

Q_SIGNALS:
void pruneChanged(bool new_prune);
void pruneSizeGBChanged(int new_prune_size_gb);

private:
interfaces::Node& m_node;

// Properties that are exposed to QML.
bool m_prune;
int m_prune_size_gb;

util::SettingsValue pruneSetting() const;
};

#endif // BITCOIN_QML_OPTIONS_MODEL_H
8 changes: 7 additions & 1 deletion src/qml/pages/settings/SettingsStorage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,11 @@ InformationPage {
headerText: qsTr("Storage settings")
headerMargin: 0
detailActive: true
detailItem: StorageSettings {}
detailItem: StorageSettings {
// Set default prune values
Component.onCompleted: {
optionsModel.prune = true
optionsModel.pruneSizeGB = 2
}
}
}