[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
This commit is contained in:
Sjors Provoost 2019-08-24 19:13:04 +02:00
parent 1bbc49d207
commit c8de347a9d
No known key found for this signature in database
GPG key ID: 57FF9BDBCC301009
4 changed files with 28 additions and 3 deletions

View file

@ -492,8 +492,9 @@ int GuiMain(int argc, char* argv[])
/// 5. Now that settings and translations are available, ask user for data directory
// User language is set up: pick a data directory
bool did_show_intro = false;
bool prune = false; // Intro dialog prune check box
// Gracefully exit if the user cancels
if (!Intro::showIfNeeded(*node, did_show_intro)) return EXIT_SUCCESS;
if (!Intro::showIfNeeded(*node, did_show_intro, prune)) return EXIT_SUCCESS;
/// 6. Determine availability of data directory and parse bitcoin.conf
/// - Do not call GetDataDir(true) before this step finishes
@ -567,6 +568,11 @@ int GuiMain(int argc, char* argv[])
// Load GUI settings from QSettings
app.createOptionsModel(gArgs.GetBoolArg("-resetguisettings", false));
if (did_show_intro) {
// Store intro dialog settings other than datadir (network specific)
app.SetPrune(prune, true);
}
if (gArgs.GetBoolArg("-splash", DEFAULT_SPLASHSCREEN) && !gArgs.GetBoolArg("-min", false))
app.createSplashScreen(networkStyle.data());

View file

@ -210,6 +210,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="prune">
<property name="toolTip">
<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>
</property>
<property name="text">
<string></string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lblExplanation2">
<property name="text">

View file

@ -131,6 +131,11 @@ Intro::Intro(QWidget *parent, uint64_t blockchain_size, uint64_t chain_state_siz
ui->lblExplanation2->setText(ui->lblExplanation2->text().arg(PACKAGE_NAME));
uint64_t pruneTarget = std::max<int64_t>(0, gArgs.GetArg("-prune", 0));
if (pruneTarget > 1) { // -prune=1 means enabled, above that it's a size in MB
ui->prune->setChecked(true);
ui->prune->setEnabled(false);
}
ui->prune->setText(tr("Discard blocks after verification, except most recent %1 GB (prune)").arg(pruneTarget ? pruneTarget / 1000 : 2));
requiredSpace = m_blockchain_size;
QString storageRequiresMsg = tr("At least %1 GB of data will be stored in this directory, and it will grow over time.");
if (pruneTarget) {
@ -180,7 +185,7 @@ void Intro::setDataDirectory(const QString &dataDir)
}
}
bool Intro::showIfNeeded(interfaces::Node& node, bool& did_show_intro)
bool Intro::showIfNeeded(interfaces::Node& node, bool& did_show_intro, bool& prune)
{
did_show_intro = false;
@ -230,6 +235,9 @@ bool Intro::showIfNeeded(interfaces::Node& node, bool& did_show_intro)
}
}
// Additional preferences:
prune = intro.ui->prune->isChecked();
settings.setValue("strDataDir", dataDir);
settings.setValue("fReset", false);
}

View file

@ -39,6 +39,7 @@ public:
/**
* Determine data directory. Let the user choose if the current one doesn't exist.
* Let the user configure additional preferences such as pruning.
*
* @returns true if a data directory was selected, false if the user cancelled the selection
* dialog.
@ -46,7 +47,7 @@ public:
* @note do NOT call global GetDataDir() before calling this function, this
* will cause the wrong path to be cached.
*/
static bool showIfNeeded(interfaces::Node& node, bool& did_show_intro);
static bool showIfNeeded(interfaces::Node& node, bool& did_show_intro, bool& prune);
Q_SIGNALS:
void requestCheck();