From 4c6562ef84f5ddf3c1b14837484cbd4d079a61fd Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Wed, 26 Oct 2022 09:54:36 +0100 Subject: [PATCH 1/3] qml, build: Add `OptionsQmlModel` class with basic implementation --- src/Makefile.qt.include | 3 +++ src/qml/bitcoin.cpp | 4 ++++ src/qml/options_model.cpp | 12 ++++++++++++ src/qml/options_model.h | 26 ++++++++++++++++++++++++++ 4 files changed, 45 insertions(+) create mode 100644 src/qml/options_model.cpp create mode 100644 src/qml/options_model.h diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 8f7e560357..749ab2c614 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -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 \ @@ -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 \ @@ -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 = \ diff --git a/src/qml/bitcoin.cpp b/src/qml/bitcoin.cpp index 489171d3ed..5eccb1a43a 100644 --- a/src/qml/bitcoin.cpp +++ b/src/qml/bitcoin.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -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 diff --git a/src/qml/options_model.cpp b/src/qml/options_model.cpp new file mode 100644 index 0000000000..7406fb946d --- /dev/null +++ b/src/qml/options_model.cpp @@ -0,0 +1,12 @@ +// 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 + +#include + +OptionsQmlModel::OptionsQmlModel(interfaces::Node& node) + : m_node{node} +{ +} diff --git a/src/qml/options_model.h b/src/qml/options_model.h new file mode 100644 index 0000000000..d405d9b0db --- /dev/null +++ b/src/qml/options_model.h @@ -0,0 +1,26 @@ +// 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 + +namespace interfaces { +class Node; +} + +/** Model for Bitcoin client options. */ +class OptionsQmlModel : public QObject +{ + Q_OBJECT + +public: + explicit OptionsQmlModel(interfaces::Node& node); + +private: + interfaces::Node& m_node; +}; + +#endif // BITCOIN_QML_OPTIONS_MODEL_H From 93f78f87696bdd9add564531414b7a6d382e7ca9 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Wed, 14 Dec 2022 03:58:48 -0500 Subject: [PATCH 2/3] qml: Add "-prune" settings to `OptionsQmlModel` class --- src/qml/options_model.cpp | 34 ++++++++++++++++++++++++++++++++++ src/qml/options_model.h | 19 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/qml/options_model.cpp b/src/qml/options_model.cpp index 7406fb946d..ed934121d4 100644 --- a/src/qml/options_model.cpp +++ b/src/qml/options_model.cpp @@ -5,8 +5,42 @@ #include #include +#include +#include +#include +#include +#include + +#include 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; } diff --git a/src/qml/options_model.h b/src/qml/options_model.h index d405d9b0db..7e227ee6b1 100644 --- a/src/qml/options_model.h +++ b/src/qml/options_model.h @@ -5,6 +5,8 @@ #ifndef BITCOIN_QML_OPTIONS_MODEL_H #define BITCOIN_QML_OPTIONS_MODEL_H +#include + #include namespace interfaces { @@ -15,12 +17,29 @@ class Node; 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 From 63162b0f6a1a168f158804d17ad80907caa1f44e Mon Sep 17 00:00:00 2001 From: jarolrod Date: Wed, 14 Dec 2022 03:59:14 -0500 Subject: [PATCH 3/3] qml: Wire Storage amount options to OptionsModel backend Wires both the easy and advanced configuration options related to storage amount to the options model backend. Additionally, this removes an unused and unwanted storage location setting from the advanced storage amount settings table. --- src/qml/components/StorageOptions.qml | 7 +++++++ src/qml/components/StorageSettings.qml | 17 +++++++---------- src/qml/pages/settings/SettingsStorage.qml | 8 +++++++- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/qml/components/StorageOptions.qml b/src/qml/components/StorageOptions.qml index fbd1f2aa33..b8e42a5146 100644 --- a/src/qml/components/StorageOptions.qml +++ b/src/qml/components/StorageOptions.qml @@ -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 + } } } diff --git a/src/qml/components/StorageSettings.qml b/src/qml/components/StorageSettings.qml index d8bd83e14c..236653356b 100644 --- a/src/qml/components/StorageSettings.qml +++ b/src/qml/components/StorageSettings.qml @@ -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) } } } diff --git a/src/qml/pages/settings/SettingsStorage.qml b/src/qml/pages/settings/SettingsStorage.qml index 3c880b416c..14233059a8 100644 --- a/src/qml/pages/settings/SettingsStorage.qml +++ b/src/qml/pages/settings/SettingsStorage.qml @@ -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 + } + } }