Changeset View
Changeset View
Standalone View
Standalone View
src/qt/bitcoin.cpp
Show First 20 Lines • Show All 183 Lines • ▼ Show 20 Lines | try { | ||||
handleRunawayException(&e); | handleRunawayException(&e); | ||||
} catch (...) { | } catch (...) { | ||||
handleRunawayException(nullptr); | handleRunawayException(nullptr); | ||||
} | } | ||||
} | } | ||||
BitcoinApplication::BitcoinApplication(interfaces::Node &node, int &argc, | BitcoinApplication::BitcoinApplication(interfaces::Node &node, int &argc, | ||||
char **argv) | char **argv) | ||||
: QApplication(argc, argv), coreThread(0), m_node(node), optionsModel(0), | : QApplication(argc, argv), coreThread(nullptr), m_node(node), | ||||
clientModel(0), window(0), pollShutdownTimer(0), returnValue(0), | optionsModel(nullptr), clientModel(nullptr), window(nullptr), | ||||
platformStyle(0) { | pollShutdownTimer(nullptr), returnValue(0), platformStyle(nullptr) { | ||||
setQuitOnLastWindowClosed(false); | setQuitOnLastWindowClosed(false); | ||||
} | } | ||||
void BitcoinApplication::setupPlatformStyle() { | void BitcoinApplication::setupPlatformStyle() { | ||||
// UI per-platform customization | // UI per-platform customization | ||||
// This must be done inside the BitcoinApplication constructor, or after it, | // This must be done inside the BitcoinApplication constructor, or after it, | ||||
// because PlatformStyle::instantiate requires a QApplication. | // because PlatformStyle::instantiate requires a QApplication. | ||||
std::string platformName; | std::string platformName; | ||||
Show All 11 Lines | BitcoinApplication::~BitcoinApplication() { | ||||
if (coreThread) { | if (coreThread) { | ||||
qDebug() << __func__ << ": Stopping thread"; | qDebug() << __func__ << ": Stopping thread"; | ||||
Q_EMIT stopThread(); | Q_EMIT stopThread(); | ||||
coreThread->wait(); | coreThread->wait(); | ||||
qDebug() << __func__ << ": Stopped thread"; | qDebug() << __func__ << ": Stopped thread"; | ||||
} | } | ||||
delete window; | delete window; | ||||
window = 0; | window = nullptr; | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
delete paymentServer; | delete paymentServer; | ||||
paymentServer = 0; | paymentServer = nullptr; | ||||
#endif | #endif | ||||
delete optionsModel; | delete optionsModel; | ||||
optionsModel = 0; | optionsModel = nullptr; | ||||
delete platformStyle; | delete platformStyle; | ||||
platformStyle = 0; | platformStyle = nullptr; | ||||
} | } | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
void BitcoinApplication::createPaymentServer() { | void BitcoinApplication::createPaymentServer() { | ||||
paymentServer = new PaymentServer(this); | paymentServer = new PaymentServer(this); | ||||
} | } | ||||
#endif | #endif | ||||
void BitcoinApplication::createOptionsModel(bool resetSettings) { | void BitcoinApplication::createOptionsModel(bool resetSettings) { | ||||
optionsModel = new OptionsModel(m_node, nullptr, resetSettings); | optionsModel = new OptionsModel(m_node, nullptr, resetSettings); | ||||
} | } | ||||
void BitcoinApplication::createWindow(const Config *config, | void BitcoinApplication::createWindow(const Config *config, | ||||
const NetworkStyle *networkStyle) { | const NetworkStyle *networkStyle) { | ||||
window = new BitcoinGUI(m_node, config, platformStyle, networkStyle, 0); | window = | ||||
new BitcoinGUI(m_node, config, platformStyle, networkStyle, nullptr); | |||||
pollShutdownTimer = new QTimer(window); | pollShutdownTimer = new QTimer(window); | ||||
connect(pollShutdownTimer, &QTimer::timeout, window, | connect(pollShutdownTimer, &QTimer::timeout, window, | ||||
&BitcoinGUI::detectShutdown); | &BitcoinGUI::detectShutdown); | ||||
} | } | ||||
void BitcoinApplication::createSplashScreen(const NetworkStyle *networkStyle) { | void BitcoinApplication::createSplashScreen(const NetworkStyle *networkStyle) { | ||||
SplashScreen *splash = new SplashScreen(m_node, 0, networkStyle); | SplashScreen *splash = new SplashScreen(m_node, nullptr, networkStyle); | ||||
// We don't hold a direct pointer to the splash screen after creation, but | // We don't hold a direct pointer to the splash screen after creation, but | ||||
// the splash screen will take care of deleting itself when slotFinish | // the splash screen will take care of deleting itself when slotFinish | ||||
// happens. | // happens. | ||||
splash->show(); | splash->show(); | ||||
connect(this, &BitcoinApplication::splashFinished, splash, | connect(this, &BitcoinApplication::splashFinished, splash, | ||||
&SplashScreen::slotFinish); | &SplashScreen::slotFinish); | ||||
connect(this, &BitcoinApplication::requestedShutdown, splash, | connect(this, &BitcoinApplication::requestedShutdown, splash, | ||||
&QWidget::close); | &QWidget::close); | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | void BitcoinApplication::requestShutdown(Config &config) { | ||||
// Show a simple window indicating shutdown status. Do this first as some of | // Show a simple window indicating shutdown status. Do this first as some of | ||||
// the steps may take some time below, for example the RPC console may still | // the steps may take some time below, for example the RPC console may still | ||||
// be executing a command. | // be executing a command. | ||||
shutdownWindow.reset(ShutdownWindow::showShutdownWindow(window)); | shutdownWindow.reset(ShutdownWindow::showShutdownWindow(window)); | ||||
qDebug() << __func__ << ": Requesting shutdown"; | qDebug() << __func__ << ": Requesting shutdown"; | ||||
startThread(); | startThread(); | ||||
window->hide(); | window->hide(); | ||||
window->setClientModel(0); | window->setClientModel(nullptr); | ||||
pollShutdownTimer->stop(); | pollShutdownTimer->stop(); | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
delete m_wallet_controller; | delete m_wallet_controller; | ||||
m_wallet_controller = nullptr; | m_wallet_controller = nullptr; | ||||
#endif | #endif | ||||
delete clientModel; | delete clientModel; | ||||
clientModel = 0; | clientModel = nullptr; | ||||
m_node.startShutdown(); | m_node.startShutdown(); | ||||
// Request shutdown from core thread | // Request shutdown from core thread | ||||
Q_EMIT requestedShutdown(); | Q_EMIT requestedShutdown(); | ||||
} | } | ||||
void BitcoinApplication::initializeResult(bool success) { | void BitcoinApplication::initializeResult(bool success) { | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | |||||
void BitcoinApplication::shutdownResult() { | void BitcoinApplication::shutdownResult() { | ||||
// Exit second main loop invocation after shutdown finished. | // Exit second main loop invocation after shutdown finished. | ||||
quit(); | quit(); | ||||
} | } | ||||
void BitcoinApplication::handleRunawayException(const QString &message) { | void BitcoinApplication::handleRunawayException(const QString &message) { | ||||
QMessageBox::critical( | QMessageBox::critical( | ||||
0, "Runaway exception", | nullptr, "Runaway exception", | ||||
BitcoinGUI::tr("A fatal error occurred. Bitcoin can no longer continue " | BitcoinGUI::tr("A fatal error occurred. Bitcoin can no longer continue " | ||||
"safely and will quit.") + | "safely and will quit.") + | ||||
QString("\n\n") + message); | QString("\n\n") + message); | ||||
::exit(EXIT_FAILURE); | ::exit(EXIT_FAILURE); | ||||
} | } | ||||
WId BitcoinApplication::getMainWinId() const { | WId BitcoinApplication::getMainWinId() const { | ||||
if (!window) { | if (!window) { | ||||
▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | #endif | ||||
/// 2. Parse command-line options. We do this after qt in order to show an | /// 2. Parse command-line options. We do this after qt in order to show an | ||||
/// error if there are problems parsing these | /// error if there are problems parsing these | ||||
// Command-line options take precedence: | // Command-line options take precedence: | ||||
node->setupServerArgs(); | node->setupServerArgs(); | ||||
SetupUIArgs(); | SetupUIArgs(); | ||||
std::string error; | std::string error; | ||||
if (!node->parseParameters(argc, argv, error)) { | if (!node->parseParameters(argc, argv, error)) { | ||||
QMessageBox::critical( | QMessageBox::critical( | ||||
0, QObject::tr(PACKAGE_NAME), | nullptr, QObject::tr(PACKAGE_NAME), | ||||
QObject::tr("Error parsing command line arguments: %1.") | QObject::tr("Error parsing command line arguments: %1.") | ||||
.arg(QString::fromStdString(error))); | .arg(QString::fromStdString(error))); | ||||
return EXIT_FAILURE; | return EXIT_FAILURE; | ||||
} | } | ||||
// Now that the QApplication is setup and we have parsed our parameters, we | // Now that the QApplication is setup and we have parsed our parameters, we | ||||
// can set the platform style | // can set the platform style | ||||
app.setupPlatformStyle(); | app.setupPlatformStyle(); | ||||
Show All 33 Lines | if (!Intro::pickDataDirectory(*node)) { | ||||
return EXIT_SUCCESS; | return EXIT_SUCCESS; | ||||
} | } | ||||
/// 6. Determine availability of data and blocks directory and parse | /// 6. Determine availability of data and blocks directory and parse | ||||
/// bitcoin.conf | /// bitcoin.conf | ||||
/// - Do not call GetDataDir(true) before this step finishes. | /// - Do not call GetDataDir(true) before this step finishes. | ||||
if (!fs::is_directory(GetDataDir(false))) { | if (!fs::is_directory(GetDataDir(false))) { | ||||
QMessageBox::critical( | QMessageBox::critical( | ||||
0, QObject::tr(PACKAGE_NAME), | nullptr, QObject::tr(PACKAGE_NAME), | ||||
QObject::tr( | QObject::tr( | ||||
"Error: Specified data directory \"%1\" does not exist.") | "Error: Specified data directory \"%1\" does not exist.") | ||||
.arg(QString::fromStdString(gArgs.GetArg("-datadir", "")))); | .arg(QString::fromStdString(gArgs.GetArg("-datadir", "")))); | ||||
return EXIT_FAILURE; | return EXIT_FAILURE; | ||||
} | } | ||||
if (!node->readConfigFiles(error)) { | if (!node->readConfigFiles(error)) { | ||||
QMessageBox::critical( | QMessageBox::critical( | ||||
0, QObject::tr(PACKAGE_NAME), | nullptr, QObject::tr(PACKAGE_NAME), | ||||
QObject::tr("Error: Cannot parse configuration file: %1.") | QObject::tr("Error: Cannot parse configuration file: %1.") | ||||
.arg(QString::fromStdString(error))); | .arg(QString::fromStdString(error))); | ||||
return EXIT_FAILURE; | return EXIT_FAILURE; | ||||
} | } | ||||
/// 7. Determine network (and switch to network specific options) | /// 7. Determine network (and switch to network specific options) | ||||
// - Do not call Params() before this step. | // - Do not call Params() before this step. | ||||
// - Do this after parsing the configuration file, as the network can be | // - Do this after parsing the configuration file, as the network can be | ||||
// switched there. | // switched there. | ||||
// - QSettings() will use the new application name after this, resulting in | // - QSettings() will use the new application name after this, resulting in | ||||
// network-specific settings. | // network-specific settings. | ||||
// - Needs to be done before createOptionsModel. | // - Needs to be done before createOptionsModel. | ||||
// Check for -testnet or -regtest parameter (Params() calls are only valid | // Check for -testnet or -regtest parameter (Params() calls are only valid | ||||
// after this clause) | // after this clause) | ||||
try { | try { | ||||
node->selectParams(gArgs.GetChainName()); | node->selectParams(gArgs.GetChainName()); | ||||
} catch (std::exception &e) { | } catch (std::exception &e) { | ||||
QMessageBox::critical(0, QObject::tr(PACKAGE_NAME), | QMessageBox::critical(nullptr, QObject::tr(PACKAGE_NAME), | ||||
QObject::tr("Error: %1").arg(e.what())); | QObject::tr("Error: %1").arg(e.what())); | ||||
return EXIT_FAILURE; | return EXIT_FAILURE; | ||||
} | } | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
// Parse URIs on command line -- this can affect Params() | // Parse URIs on command line -- this can affect Params() | ||||
PaymentServer::ipcParseCommandLine(*node, argc, argv); | PaymentServer::ipcParseCommandLine(*node, argc, argv); | ||||
#endif | #endif | ||||
▲ Show 20 Lines • Show All 94 Lines • Show Last 20 Lines |