Skip to content

Commit c8de347

Browse files
committed
[gui] intro: add prune preference
Adds a checkbox to the introduction screen letting the user enable pruning from the start. Disable checkbox when launched with -prune
1 parent 1bbc49d commit c8de347

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

src/qt/bitcoin.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,9 @@ int GuiMain(int argc, char* argv[])
492492
/// 5. Now that settings and translations are available, ask user for data directory
493493
// User language is set up: pick a data directory
494494
bool did_show_intro = false;
495+
bool prune = false; // Intro dialog prune check box
495496
// Gracefully exit if the user cancels
496-
if (!Intro::showIfNeeded(*node, did_show_intro)) return EXIT_SUCCESS;
497+
if (!Intro::showIfNeeded(*node, did_show_intro, prune)) return EXIT_SUCCESS;
497498

498499
/// 6. Determine availability of data directory and parse bitcoin.conf
499500
/// - Do not call GetDataDir(true) before this step finishes
@@ -567,6 +568,11 @@ int GuiMain(int argc, char* argv[])
567568
// Load GUI settings from QSettings
568569
app.createOptionsModel(gArgs.GetBoolArg("-resetguisettings", false));
569570

571+
if (did_show_intro) {
572+
// Store intro dialog settings other than datadir (network specific)
573+
app.SetPrune(prune, true);
574+
}
575+
570576
if (gArgs.GetBoolArg("-splash", DEFAULT_SPLASHSCREEN) && !gArgs.GetBoolArg("-min", false))
571577
app.createSplashScreen(networkStyle.data());
572578

src/qt/forms/intro.ui

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,16 @@
210210
</property>
211211
</widget>
212212
</item>
213+
<item>
214+
<widget class="QCheckBox" name="prune">
215+
<property name="toolTip">
216+
<string>Reverting this setting requires re-downloading the entire blockchain. It is faster to download the full chain first and prune it later. Disables some advanced features.</string>
217+
</property>
218+
<property name="text">
219+
<string></string>
220+
</property>
221+
</widget>
222+
</item>
213223
<item>
214224
<widget class="QLabel" name="lblExplanation2">
215225
<property name="text">

src/qt/intro.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ Intro::Intro(QWidget *parent, uint64_t blockchain_size, uint64_t chain_state_siz
131131
ui->lblExplanation2->setText(ui->lblExplanation2->text().arg(PACKAGE_NAME));
132132

133133
uint64_t pruneTarget = std::max<int64_t>(0, gArgs.GetArg("-prune", 0));
134+
if (pruneTarget > 1) { // -prune=1 means enabled, above that it's a size in MB
135+
ui->prune->setChecked(true);
136+
ui->prune->setEnabled(false);
137+
}
138+
ui->prune->setText(tr("Discard blocks after verification, except most recent %1 GB (prune)").arg(pruneTarget ? pruneTarget / 1000 : 2));
134139
requiredSpace = m_blockchain_size;
135140
QString storageRequiresMsg = tr("At least %1 GB of data will be stored in this directory, and it will grow over time.");
136141
if (pruneTarget) {
@@ -180,7 +185,7 @@ void Intro::setDataDirectory(const QString &dataDir)
180185
}
181186
}
182187

183-
bool Intro::showIfNeeded(interfaces::Node& node, bool& did_show_intro)
188+
bool Intro::showIfNeeded(interfaces::Node& node, bool& did_show_intro, bool& prune)
184189
{
185190
did_show_intro = false;
186191

@@ -230,6 +235,9 @@ bool Intro::showIfNeeded(interfaces::Node& node, bool& did_show_intro)
230235
}
231236
}
232237

238+
// Additional preferences:
239+
prune = intro.ui->prune->isChecked();
240+
233241
settings.setValue("strDataDir", dataDir);
234242
settings.setValue("fReset", false);
235243
}

src/qt/intro.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,15 @@ class Intro : public QDialog
3939

4040
/**
4141
* Determine data directory. Let the user choose if the current one doesn't exist.
42+
* Let the user configure additional preferences such as pruning.
4243
*
4344
* @returns true if a data directory was selected, false if the user cancelled the selection
4445
* dialog.
4546
*
4647
* @note do NOT call global GetDataDir() before calling this function, this
4748
* will cause the wrong path to be cached.
4849
*/
49-
static bool showIfNeeded(interfaces::Node& node, bool& did_show_intro);
50+
static bool showIfNeeded(interfaces::Node& node, bool& did_show_intro, bool& prune);
5051

5152
Q_SIGNALS:
5253
void requestCheck();

0 commit comments

Comments
 (0)