aboutsummaryrefslogtreecommitdiff
path: root/src/qt/bitcoin.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2014-01-05 12:37:51 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2014-01-05 12:55:03 +0100
commit2102ab9f5cb542e6727e0f25e670d8549aa1bf1a (patch)
treecad487646827981bacb34d1d102c143eb6e858f8 /src/qt/bitcoin.cpp
parent16403b42759205461918c652fdc5b71c422c44a2 (diff)
downloadbitcoin-2102ab9f5cb542e6727e0f25e670d8549aa1bf1a.tar.xz
ui: Fix GUI initialization order
Fixes at least #3478. Splits and documents the phases: 1. Parse command-line options. These take precedence over anything else. 2. Basic Qt initialization (not dependent on parameters or configuration) 3. Application identification 4. Initialization of translations 5. Now that settings and translations are available, ask user for data directory 6. Determine availability of data directory and parse bitcoin.conf 7. URI IPC sending 8. Main GUI initialization Splits command line parsing logic from ipcSendCommandLine into ipcParseCommandLine, as isTestNet() can only be overridden in the early stages before choosing a data directory. Sending however needs to happen after choosing a data directory.
Diffstat (limited to 'src/qt/bitcoin.cpp')
-rw-r--r--src/qt/bitcoin.cpp82
1 files changed, 46 insertions, 36 deletions
diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
index 657b42d16a..cd74fb4cef 100644
--- a/src/qt/bitcoin.cpp
+++ b/src/qt/bitcoin.cpp
@@ -161,22 +161,23 @@ void DebugMessageHandler(QtMsgType type, const QMessageLogContext& context, cons
#ifndef BITCOIN_QT_TEST
int main(int argc, char *argv[])
{
- bool fMissingDatadir = false;
bool fSelParFromCLFailed = false;
-
+ /// 1. Parse command-line options. These take precedence over anything else.
// Command-line options take precedence:
ParseParameters(argc, argv);
- // ... then bitcoin.conf:
- if (!boost::filesystem::is_directory(GetDataDir(false))) {
- fMissingDatadir = true;
- } else {
- ReadConfigFile(mapArgs, mapMultiArgs);
- }
// Check for -testnet or -regtest parameter (TestNet() calls are only valid after this clause)
if (!SelectParamsFromCommandLine()) {
fSelParFromCLFailed = true;
}
+ // Parse URIs on command line -- this can affect TestNet() / RegTest() mode
+ if (!PaymentServer::ipcParseCommandLine(argc, argv))
+ exit(0);
+
+ bool isaTestNet = TestNet() || RegTest();
+
+ // Do not refer to data directory yet, this can be overridden by Intro::pickDataDirectory
+ /// 2. Basic Qt initialization (not dependent on parameters or configuration)
#if QT_VERSION < 0x050000
// Internal string conversion is all UTF-8
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
@@ -196,9 +197,9 @@ int main(int argc, char *argv[])
// Register meta types used for QMetaObject::invokeMethod
qRegisterMetaType< bool* >();
- // Application identification (must be set before OptionsModel is initialized,
- // as it is used to locate QSettings)
- bool isaTestNet = TestNet() || RegTest();
+ /// 3. Application identification
+ // must be set before OptionsModel is initialized or translations are loaded,
+ // as it is used to locate QSettings
QApplication::setOrganizationName("Bitcoin");
QApplication::setOrganizationDomain("bitcoin.org");
if (isaTestNet) // Separate UI settings for testnets
@@ -206,34 +207,52 @@ int main(int argc, char *argv[])
else
QApplication::setApplicationName("Bitcoin-Qt");
+ /// 4. Initialization of translations, so that intro dialog is in user's language
// Now that QSettings are accessible, initialize translations
QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator;
initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);
- // Do this early as we don't want to bother initializing if we are just calling IPC
- // ... but do it after creating app and setting up translations, so errors are
- // translated properly.
- if (PaymentServer::ipcSendCommandLine(argc, argv))
- exit(0);
-
- // Now that translations are initialized check for errors and allow a translatable error message
- if (fMissingDatadir) {
- QMessageBox::critical(0, QObject::tr("Bitcoin"),
- QObject::tr("Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(mapArgs["-datadir"])));
+ // Show help message immediately after parsing command-line options (for "-lang") and setting locale,
+ // but before showing splash screen.
+ if (mapArgs.count("-?") || mapArgs.count("--help"))
+ {
+ GUIUtil::HelpMessageBox help;
+ help.showOrPrint();
return 1;
}
- else if (fSelParFromCLFailed) {
+ // Now that translations are initialized, check for earlier errors and show a translatable error message
+ if (fSelParFromCLFailed) {
QMessageBox::critical(0, QObject::tr("Bitcoin"), QObject::tr("Error: Invalid combination of -regtest and -testnet."));
return 1;
}
+ /// 5. Now that settings and translations are available, ask user for data directory
+ // User language is set up: pick a data directory
+ Intro::pickDataDirectory(isaTestNet);
+
+ /// 6. Determine availability of data directory and parse bitcoin.conf
+ if (!boost::filesystem::is_directory(GetDataDir(false)))
+ {
+ QMessageBox::critical(0, QObject::tr("Bitcoin"),
+ QObject::tr("Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(mapArgs["-datadir"])));
+ return 1;
+ }
+ ReadConfigFile(mapArgs, mapMultiArgs);
+
+ /// 7. URI IPC sending
+ // - Do this early as we don't want to bother initializing if we are just calling IPC
+ // - Do this *after* setting up the data directory, as the data directory hash is used in the name
+ // of the server.
+ // - Do this after creating app and setting up translations, so errors are
+ // translated properly.
+ if (PaymentServer::ipcSendCommandLine())
+ exit(0);
+
// Start up the payment server early, too, so impatient users that click on
// bitcoin: links repeatedly have their payment requests routed to this process:
PaymentServer* paymentServer = new PaymentServer(&app);
- // User language is set up: pick a data directory
- Intro::pickDataDirectory(isaTestNet);
-
+ /// 8. Main GUI initialization
// Install global event filter that makes sure that long tooltips can be word-wrapped
app.installEventFilter(new GUIUtil::ToolTipToRichTextFilter(TOOLTIP_WRAP_THRESHOLD, &app));
// Install qDebug() message handler to route to debug.log
@@ -242,8 +261,7 @@ int main(int argc, char *argv[])
#else
qInstallMessageHandler(DebugMessageHandler);
#endif
-
- // ... now GUI settings:
+ // Load GUI settings from QSettings
OptionsModel optionsModel;
// Subscribe to global signals from core
@@ -251,15 +269,7 @@ int main(int argc, char *argv[])
uiInterface.InitMessage.connect(InitMessage);
uiInterface.Translate.connect(Translate);
- // Show help message immediately after parsing command-line options (for "-lang") and setting locale,
- // but before showing splash screen.
- if (mapArgs.count("-?") || mapArgs.count("--help"))
- {
- GUIUtil::HelpMessageBox help;
- help.showOrPrint();
- return 1;
- }
-
+ // Show splash screen if appropriate
SplashScreen splash(QPixmap(), 0, isaTestNet);
if (GetBoolArg("-splash", true) && !GetBoolArg("-min", false))
{