Skip to content

Commit fbdf4e5

Browse files
committed
Merge pull request #3844
c52c4e5 qt: Make it possible again to specify -testnet in config file (Wladimir J. van der Laan)
2 parents 669264c + c52c4e5 commit fbdf4e5

File tree

4 files changed

+46
-32
lines changed

4 files changed

+46
-32
lines changed

src/qt/bitcoin.cpp

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTrans
7878
{
7979
QSettings settings;
8080

81+
// Remove old translators
82+
QApplication::removeTranslator(&qtTranslatorBase);
83+
QApplication::removeTranslator(&qtTranslator);
84+
QApplication::removeTranslator(&translatorBase);
85+
QApplication::removeTranslator(&translator);
86+
8187
// Get desired locale (e.g. "de_DE")
8288
// 1) System default language
8389
QString lang_territory = QLocale::system().name();
@@ -439,21 +445,9 @@ void BitcoinApplication::handleRunawayException(const QString &message)
439445
#ifndef BITCOIN_QT_TEST
440446
int main(int argc, char *argv[])
441447
{
442-
bool fSelParFromCLFailed = false;
443448
/// 1. Parse command-line options. These take precedence over anything else.
444449
// Command-line options take precedence:
445450
ParseParameters(argc, argv);
446-
// Check for -testnet or -regtest parameter (TestNet() calls are only valid after this clause)
447-
if (!SelectParamsFromCommandLine()) {
448-
fSelParFromCLFailed = true;
449-
}
450-
#ifdef ENABLE_WALLET
451-
// Parse URIs on command line -- this can affect Params()
452-
if (!PaymentServer::ipcParseCommandLine(argc, argv))
453-
exit(0);
454-
#endif
455-
456-
bool isaTestNet = Params().NetworkID() != CChainParams::MAIN;
457451

458452
// Do not refer to data directory yet, this can be overridden by Intro::pickDataDirectory
459453

@@ -480,12 +474,9 @@ int main(int argc, char *argv[])
480474
/// 3. Application identification
481475
// must be set before OptionsModel is initialized or translations are loaded,
482476
// as it is used to locate QSettings
483-
QApplication::setOrganizationName("Bitcoin");
484-
QApplication::setOrganizationDomain("bitcoin.org");
485-
if (isaTestNet) // Separate UI settings for testnets
486-
QApplication::setApplicationName("Bitcoin-Qt-testnet");
487-
else
488-
QApplication::setApplicationName("Bitcoin-Qt");
477+
QApplication::setOrganizationName(QAPP_ORG_NAME);
478+
QApplication::setOrganizationDomain(QAPP_ORG_DOMAIN);
479+
QApplication::setApplicationName(QAPP_APP_NAME_DEFAULT);
489480

490481
/// 4. Initialization of translations, so that intro dialog is in user's language
491482
// Now that QSettings are accessible, initialize translations
@@ -501,17 +492,13 @@ int main(int argc, char *argv[])
501492
help.showOrPrint();
502493
return 1;
503494
}
504-
// Now that translations are initialized, check for earlier errors and show a translatable error message
505-
if (fSelParFromCLFailed) {
506-
QMessageBox::critical(0, QObject::tr("Bitcoin"), QObject::tr("Error: Invalid combination of -regtest and -testnet."));
507-
return 1;
508-
}
509495

510496
/// 5. Now that settings and translations are available, ask user for data directory
511497
// User language is set up: pick a data directory
512-
Intro::pickDataDirectory(isaTestNet);
498+
Intro::pickDataDirectory();
513499

514500
/// 6. Determine availability of data directory and parse bitcoin.conf
501+
/// - Do not call GetDataDir(true) before this step finishes
515502
if (!boost::filesystem::is_directory(GetDataDir(false)))
516503
{
517504
QMessageBox::critical(0, QObject::tr("Bitcoin"),
@@ -520,8 +507,33 @@ int main(int argc, char *argv[])
520507
}
521508
ReadConfigFile(mapArgs, mapMultiArgs);
522509

510+
/// 7. Determine network (and switch to network specific options)
511+
// - Do not call Params() before this step
512+
// - Do this after parsing the configuration file, as the network can be switched there
513+
// - QSettings() will use the new application name after this, resulting in network-specific settings
514+
// - Needs to be done before createOptionsModel
515+
516+
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
517+
if (!SelectParamsFromCommandLine()) {
518+
QMessageBox::critical(0, QObject::tr("Bitcoin"), QObject::tr("Error: Invalid combination of -regtest and -testnet."));
519+
return 1;
520+
}
521+
#ifdef ENABLE_WALLET
522+
// Parse URIs on command line -- this can affect Params()
523+
if (!PaymentServer::ipcParseCommandLine(argc, argv))
524+
exit(0);
525+
#endif
526+
bool isaTestNet = Params().NetworkID() != CChainParams::MAIN;
527+
// Allow for separate UI settings for testnets
528+
if (isaTestNet)
529+
QApplication::setApplicationName(QAPP_APP_NAME_TESTNET);
530+
else
531+
QApplication::setApplicationName(QAPP_APP_NAME_DEFAULT);
532+
// Re-initialize translations after changing application name (language in network-specific settings can be different)
533+
initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);
534+
523535
#ifdef ENABLE_WALLET
524-
/// 7. URI IPC sending
536+
/// 8. URI IPC sending
525537
// - Do this early as we don't want to bother initializing if we are just calling IPC
526538
// - Do this *after* setting up the data directory, as the data directory hash is used in the name
527539
// of the server.
@@ -535,7 +547,7 @@ int main(int argc, char *argv[])
535547
app.createPaymentServer();
536548
#endif
537549

538-
/// 8. Main GUI initialization
550+
/// 9. Main GUI initialization
539551
// Install global event filter that makes sure that long tooltips can be word-wrapped
540552
app.installEventFilter(new GUIUtil::ToolTipToRichTextFilter(TOOLTIP_WRAP_THRESHOLD, &app));
541553
// Install qDebug() message handler to route to debug.log

src/qt/guiconstants.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,9 @@ static const int MAX_PAYMENT_REQUEST_SIZE = 50000; // bytes
4141
/* Number of frames in spinner animation */
4242
#define SPINNER_FRAMES 35
4343

44+
#define QAPP_ORG_NAME "Bitcoin"
45+
#define QAPP_ORG_DOMAIN "bitcoin.org"
46+
#define QAPP_APP_NAME_DEFAULT "Bitcoin-Qt"
47+
#define QAPP_APP_NAME_TESTNET "Bitcoin-Qt-testnet"
48+
4449
#endif // GUICONSTANTS_H

src/qt/intro.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ QString Intro::getDefaultDataDirectory()
146146
return QString::fromStdString(GetDefaultDataDir().string());
147147
}
148148

149-
void Intro::pickDataDirectory(bool fIsTestnet)
149+
void Intro::pickDataDirectory()
150150
{
151151
namespace fs = boost::filesystem;
152152
QSettings settings;
@@ -164,10 +164,7 @@ void Intro::pickDataDirectory(bool fIsTestnet)
164164
/* If current default data directory does not exist, let the user choose one */
165165
Intro intro;
166166
intro.setDataDirectory(dataDir);
167-
if (!fIsTestnet)
168-
intro.setWindowIcon(QIcon(":icons/bitcoin"));
169-
else
170-
intro.setWindowIcon(QIcon(":icons/bitcoin_testnet"));
167+
intro.setWindowIcon(QIcon(":icons/bitcoin"));
171168

172169
while(true)
173170
{

src/qt/intro.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Intro : public QDialog
3636
* @note do NOT call global GetDataDir() before calling this function, this
3737
* will cause the wrong path to be cached.
3838
*/
39-
static void pickDataDirectory(bool fIsTestnet);
39+
static void pickDataDirectory();
4040

4141
/**
4242
* Determine default data directory for operating system.

0 commit comments

Comments
 (0)