Skip to content

Commit 1957103

Browse files
committed
[gui] add explicit prune setter
This makes it possible to enable pruning after the OptionsModel has been initialized and reset.
1 parent 1bccf6a commit 1957103

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

src/qt/bitcoin.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ void BitcoinApplication::parameterSetup()
282282
m_node.initParameterInteraction();
283283
}
284284

285+
void BitcoinApplication::SetPrune(bool prune, bool force) {
286+
optionsModel->SetPrune(prune, force);
287+
}
288+
285289
void BitcoinApplication::requestInitialize()
286290
{
287291
qDebug() << __func__ << ": Requesting initialize";

src/qt/bitcoin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class BitcoinApplication: public QApplication
6767
void parameterSetup();
6868
/// Create options model
6969
void createOptionsModel(bool resetSettings);
70+
/// Update prune value
71+
void SetPrune(bool prune, bool force = false);
7072
/// Create main window
7173
void createWindow(const NetworkStyle *networkStyle);
7274
/// Create splash screen

src/qt/optionsmodel.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,7 @@ void OptionsModel::Init(bool resetSettings)
9292
settings.setValue("bPrune", false);
9393
if (!settings.contains("nPruneSize"))
9494
settings.setValue("nPruneSize", 2);
95-
// Convert prune size from GB to MiB:
96-
const uint64_t nPruneSizeMiB = (settings.value("nPruneSize").toInt() * GB_BYTES) >> 20;
97-
if (!m_node.softSetArg("-prune", settings.value("bPrune").toBool() ? std::to_string(nPruneSizeMiB) : "0")) {
98-
addOverriddenOption("-prune");
99-
}
95+
SetPrune(settings.value("bPrune").toBool());
10096

10197
if (!settings.contains("nDatabaseCache"))
10298
settings.setValue("nDatabaseCache", (qint64)nDefaultDbCache);
@@ -240,6 +236,22 @@ static const QString GetDefaultProxyAddress()
240236
return QString("%1:%2").arg(DEFAULT_GUI_PROXY_HOST).arg(DEFAULT_GUI_PROXY_PORT);
241237
}
242238

239+
void OptionsModel::SetPrune(bool prune, bool force)
240+
{
241+
QSettings settings;
242+
settings.setValue("bPrune", prune);
243+
// Convert prune size from GB to MiB:
244+
const uint64_t nPruneSizeMiB = (settings.value("nPruneSize").toInt() * GB_BYTES) >> 20;
245+
std::string prune_val = prune ? std::to_string(nPruneSizeMiB) : "0";
246+
if (force) {
247+
m_node.forceSetArg("-prune", prune_val);
248+
return;
249+
}
250+
if (!m_node.softSetArg("-prune", prune_val)) {
251+
addOverriddenOption("-prune");
252+
}
253+
}
254+
243255
// read QSettings values and return them
244256
QVariant OptionsModel::data(const QModelIndex & index, int role) const
245257
{

src/qt/optionsmodel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ class OptionsModel : public QAbstractListModel
7777
bool getCoinControlFeatures() const { return fCoinControlFeatures; }
7878
const QString& getOverriddenByCommandLine() { return strOverriddenByCommandLine; }
7979

80+
/* Explicit setters */
81+
void SetPrune(bool prune, bool force = false);
82+
8083
/* Restart flag helper */
8184
void setRestartRequired(bool fRequired);
8285
bool isRestartRequired() const;

0 commit comments

Comments
 (0)