mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 20:03:34 -03:00
Merge bitcoin/bitcoin#22653: refactor: Rename JoinErrors and re-use it
bb56486a17
refactor: Reuse MakeUnorderedList where possible (Hennadii Stepanov)77a90f03ac
refactor: Move MakeUnorderedList into util/string.h to make it reusable (Hennadii Stepanov)6a5ccd65c7
scripted-diff: Rename JoinErrors in more general MakeUnorderedList (Hennadii Stepanov) Pull request description: A nice `JoinErrors` utility function was introduced in https://github.com/bitcoin-core/gui/pull/379 by Russell Yanofsky. This PR renames this function and re-uses it across the code base. ACKs for top commit: Zero-1729: Concept ACKbb56486a17
theStack: Code-review ACKbb56486a17
Talkless: utACKbb56486a17
ryanofsky: Code review ACKbb56486a17
. Nice deduping, thanks for this! Tree-SHA512: 6bdbfa61f2ffa69e075f46b733f247c6d5b8486779a1dac064285a199a4bb8bc5ef44eaee37086305646b5c88eb6a11990883219a4a9140a5117ee21ed529bb9
This commit is contained in:
commit
c3545a7396
4 changed files with 18 additions and 13 deletions
|
@ -28,6 +28,7 @@
|
|||
#include <qt/utilitydialog.h>
|
||||
#include <qt/winshutdownmonitor.h>
|
||||
#include <uint256.h>
|
||||
#include <util/string.h>
|
||||
#include <util/system.h>
|
||||
#include <util/threadnames.h>
|
||||
#include <util/translation.h>
|
||||
|
@ -144,11 +145,6 @@ static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTrans
|
|||
QApplication::installTranslator(&translator);
|
||||
}
|
||||
|
||||
static std::string JoinErrors(const std::vector<std::string>& errors)
|
||||
{
|
||||
return Join(errors, "\n", [](const std::string& error) { return "- " + error; });
|
||||
}
|
||||
|
||||
static bool InitSettings()
|
||||
{
|
||||
if (!gArgs.GetSettingsPath()) {
|
||||
|
@ -158,13 +154,13 @@ static bool InitSettings()
|
|||
std::vector<std::string> errors;
|
||||
if (!gArgs.ReadSettingsFile(&errors)) {
|
||||
bilingual_str error = _("Settings file could not be read");
|
||||
InitError(Untranslated(strprintf("%s:\n%s\n", error.original, JoinErrors(errors))));
|
||||
InitError(Untranslated(strprintf("%s:\n%s\n", error.original, MakeUnorderedList(errors))));
|
||||
|
||||
QMessageBox messagebox(QMessageBox::Critical, PACKAGE_NAME, QString::fromStdString(strprintf("%s.", error.translated)), QMessageBox::Reset | QMessageBox::Abort);
|
||||
/*: Explanatory text shown on startup when the settings file cannot be read.
|
||||
Prompts user to make a choice between resetting or aborting. */
|
||||
messagebox.setInformativeText(QObject::tr("Do you want to reset settings to default values, or to abort without making changes?"));
|
||||
messagebox.setDetailedText(QString::fromStdString(JoinErrors(errors)));
|
||||
messagebox.setDetailedText(QString::fromStdString(MakeUnorderedList(errors)));
|
||||
messagebox.setTextFormat(Qt::PlainText);
|
||||
messagebox.setDefaultButton(QMessageBox::Reset);
|
||||
switch (messagebox.exec()) {
|
||||
|
@ -180,14 +176,14 @@ static bool InitSettings()
|
|||
errors.clear();
|
||||
if (!gArgs.WriteSettingsFile(&errors)) {
|
||||
bilingual_str error = _("Settings file could not be written");
|
||||
InitError(Untranslated(strprintf("%s:\n%s\n", error.original, JoinErrors(errors))));
|
||||
InitError(Untranslated(strprintf("%s:\n%s\n", error.original, MakeUnorderedList(errors))));
|
||||
|
||||
QMessageBox messagebox(QMessageBox::Critical, PACKAGE_NAME, QString::fromStdString(strprintf("%s.", error.translated)), QMessageBox::Ok);
|
||||
/*: Explanatory text shown on startup when the settings file could not be written.
|
||||
Prompts user to check that we have the ability to write to the file.
|
||||
Explains that the user has the option of running without a settings file.*/
|
||||
messagebox.setInformativeText(QObject::tr("A fatal error occured. Check that settings file is writable, or try running with -nosettings."));
|
||||
messagebox.setDetailedText(QString::fromStdString(JoinErrors(errors)));
|
||||
messagebox.setInformativeText(QObject::tr("A fatal error occurred. Check that settings file is writable, or try running with -nosettings."));
|
||||
messagebox.setDetailedText(QString::fromStdString(MakeUnorderedList(errors)));
|
||||
messagebox.setTextFormat(Qt::PlainText);
|
||||
messagebox.setDefaultButton(QMessageBox::Ok);
|
||||
messagebox.exec();
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include <txmempool.h>
|
||||
#include <undo.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <util/string.h>
|
||||
#include <util/system.h>
|
||||
#include <util/translation.h>
|
||||
#include <validation.h>
|
||||
|
@ -1328,7 +1329,7 @@ static RPCHelpMan verifychain()
|
|||
"\nVerifies blockchain database.\n",
|
||||
{
|
||||
{"checklevel", RPCArg::Type::NUM, RPCArg::DefaultHint{strprintf("%d, range=0-4", DEFAULT_CHECKLEVEL)},
|
||||
strprintf("How thorough the block verification is:\n - %s", Join(CHECKLEVEL_DOC, "\n- "))},
|
||||
strprintf("How thorough the block verification is:\n%s", MakeUnorderedList(CHECKLEVEL_DOC))},
|
||||
{"nblocks", RPCArg::Type::NUM, RPCArg::DefaultHint{strprintf("%d, 0=all", DEFAULT_CHECKBLOCKS)}, "The number of blocks to check."},
|
||||
},
|
||||
RPCResult{
|
||||
|
|
|
@ -64,6 +64,14 @@ inline std::string Join(const std::vector<std::string>& list, const std::string&
|
|||
return Join<std::string>(list, separator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an unordered multi-line list of items.
|
||||
*/
|
||||
inline std::string MakeUnorderedList(const std::vector<std::string>& items)
|
||||
{
|
||||
return Join(items, "\n", [](const std::string& item) { return "- " + item; });
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a string does not contain any embedded NUL (\0) characters
|
||||
*/
|
||||
|
|
|
@ -502,11 +502,11 @@ bool ArgsManager::InitSettings(std::string& error)
|
|||
|
||||
std::vector<std::string> errors;
|
||||
if (!ReadSettingsFile(&errors)) {
|
||||
error = strprintf("Failed loading settings file:\n- %s\n", Join(errors, "\n- "));
|
||||
error = strprintf("Failed loading settings file:\n%s\n", MakeUnorderedList(errors));
|
||||
return false;
|
||||
}
|
||||
if (!WriteSettingsFile(&errors)) {
|
||||
error = strprintf("Failed saving settings file:\n- %s\n", Join(errors, "\n- "));
|
||||
error = strprintf("Failed saving settings file:\n%s\n", MakeUnorderedList(errors));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue