GUI: Intro: Output a std::unique_ptr<Intro> from Intro::showIfNeeded

This commit is contained in:
Luke Dashjr 2020-12-10 22:26:17 +00:00
parent 96ec3b67a7
commit cda83e8ae1
3 changed files with 15 additions and 17 deletions

View File

@ -575,10 +575,9 @@ int GuiMain(int argc, char* argv[])
/// 5. Now that settings and translations are available, ask user for data directory /// 5. Now that settings and translations are available, ask user for data directory
// User language is set up: pick a data directory // User language is set up: pick a data directory
bool did_show_intro = false; std::unique_ptr<Intro> intro;
int64_t prune_MiB = 0; // Intro dialog prune configuration
// Gracefully exit if the user cancels // Gracefully exit if the user cancels
if (!Intro::showIfNeeded(did_show_intro, prune_MiB)) return EXIT_SUCCESS; if (!Intro::showIfNeeded(intro)) return EXIT_SUCCESS;
/// 6-7. Parse bitcoin.conf, determine network, switch to network specific /// 6-7. Parse bitcoin.conf, determine network, switch to network specific
/// options, and create datadir and settings.json. /// options, and create datadir and settings.json.
@ -651,9 +650,10 @@ int GuiMain(int argc, char* argv[])
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (did_show_intro) { if (intro) {
// Store intro dialog settings other than datadir (network specific) // Store intro dialog settings other than datadir (network specific)
app.InitPruneSetting(prune_MiB); app.InitPruneSetting(intro->getPruneMiB());
intro.reset();
} }
try try

View File

@ -202,9 +202,9 @@ int64_t Intro::getPruneMiB() const
} }
} }
bool Intro::showIfNeeded(bool& did_show_intro, int64_t& prune_MiB) bool Intro::showIfNeeded(std::unique_ptr<Intro>& intro)
{ {
did_show_intro = false; intro.reset();
QSettings settings; QSettings settings;
/* If data directory provided on command line, no need to look at settings /* If data directory provided on command line, no need to look at settings
@ -226,19 +226,18 @@ bool Intro::showIfNeeded(bool& did_show_intro, int64_t& prune_MiB)
} }
/* If current default data directory does not exist, let the user choose one */ /* If current default data directory does not exist, let the user choose one */
Intro intro(nullptr, Params().AssumedBlockchainSize(), Params().AssumedChainStateSize()); intro = std::make_unique<Intro>(nullptr, Params().AssumedBlockchainSize(), Params().AssumedChainStateSize());
intro.setDataDirectory(dataDir); intro->setDataDirectory(dataDir);
intro.setWindowIcon(QIcon(":icons/bitcoin")); intro->setWindowIcon(QIcon(QStringLiteral(":icons/bitcoin")));
did_show_intro = true;
while(true) while(true)
{ {
if(!intro.exec()) if(!intro->exec())
{ {
/* Cancel clicked */ /* Cancel clicked */
return false; return false;
} }
dataDir = intro.getDataDirectory(); dataDir = intro->getDataDirectory();
try { try {
if (TryCreateDirectories(GUIUtil::QStringToPath(dataDir))) { if (TryCreateDirectories(GUIUtil::QStringToPath(dataDir))) {
// If a new data directory has been created, make wallets subdirectory too // If a new data directory has been created, make wallets subdirectory too
@ -252,9 +251,6 @@ bool Intro::showIfNeeded(bool& did_show_intro, int64_t& prune_MiB)
} }
} }
// Additional preferences:
prune_MiB = intro.getPruneMiB();
settings.setValue("strDataDir", dataDir); settings.setValue("strDataDir", dataDir);
settings.setValue("fReset", false); settings.setValue("fReset", false);
} }

View File

@ -9,6 +9,8 @@
#include <QMutex> #include <QMutex>
#include <QThread> #include <QThread>
#include <memory>
static const bool DEFAULT_CHOOSE_DATADIR = false; static const bool DEFAULT_CHOOSE_DATADIR = false;
class FreespaceChecker; class FreespaceChecker;
@ -48,7 +50,7 @@ public:
* @note do NOT call global gArgs.GetDataDirNet() before calling this function, this * @note do NOT call global gArgs.GetDataDirNet() before calling this function, this
* will cause the wrong path to be cached. * will cause the wrong path to be cached.
*/ */
static bool showIfNeeded(bool& did_show_intro, int64_t& prune_MiB); static bool showIfNeeded(std::unique_ptr<Intro>& intro);
Q_SIGNALS: Q_SIGNALS:
void requestCheck(); void requestCheck();