Changeset View
Changeset View
Standalone View
Standalone View
src/qt/bitcoin.cpp
Show First 20 Lines • Show All 349 Lines • ▼ Show 20 Lines | 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, 0); | ||||
pollShutdownTimer = new QTimer(window); | pollShutdownTimer = new QTimer(window); | ||||
connect(pollShutdownTimer, SIGNAL(timeout()), window, | connect(pollShutdownTimer, &QTimer::timeout, window, | ||||
SLOT(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, 0, 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, SIGNAL(splashFinished(QWidget *)), splash, | connect(this, &BitcoinApplication::splashFinished, splash, | ||||
SLOT(slotFinish(QWidget *))); | &SplashScreen::slotFinish); | ||||
connect(this, SIGNAL(requestedShutdown()), splash, SLOT(close())); | connect(this, &BitcoinApplication::requestedShutdown, splash, | ||||
&QWidget::close); | |||||
} | } | ||||
void BitcoinApplication::startThread() { | void BitcoinApplication::startThread() { | ||||
if (coreThread) { | if (coreThread) { | ||||
return; | return; | ||||
} | } | ||||
coreThread = new QThread(this); | coreThread = new QThread(this); | ||||
BitcoinABC *executor = new BitcoinABC(m_node); | BitcoinABC *executor = new BitcoinABC(m_node); | ||||
executor->moveToThread(coreThread); | executor->moveToThread(coreThread); | ||||
/* communication to and from thread */ | /* communication to and from thread */ | ||||
connect(executor, SIGNAL(initializeResult(bool)), this, | connect(executor, &BitcoinABC::initializeResult, this, | ||||
SLOT(initializeResult(bool))); | &BitcoinApplication::initializeResult); | ||||
connect(executor, SIGNAL(shutdownResult()), this, SLOT(shutdownResult())); | connect(executor, &BitcoinABC::shutdownResult, this, | ||||
connect(executor, SIGNAL(runawayException(QString)), this, | &BitcoinApplication::shutdownResult); | ||||
SLOT(handleRunawayException(QString))); | connect(executor, &BitcoinABC::runawayException, this, | ||||
&BitcoinApplication::handleRunawayException); | |||||
// Note on how Qt works: it tries to directly invoke methods if the signal | // Note on how Qt works: it tries to directly invoke methods if the signal | ||||
// is emitted on the same thread that the target object 'lives' on. | // is emitted on the same thread that the target object 'lives' on. | ||||
// But if the target object 'lives' on another thread (executor here does) | // But if the target object 'lives' on another thread (executor here does) | ||||
// the SLOT will be invoked asynchronously at a later time in the thread | // the SLOT will be invoked asynchronously at a later time in the thread | ||||
// of the target object. So.. we pass a pointer around. If you pass | // of the target object. So.. we pass a pointer around. If you pass | ||||
// a reference around (even if it's non-const) you'll get Qt generating | // a reference around (even if it's non-const) you'll get Qt generating | ||||
// code to copy-construct the parameter in question (Q_DECLARE_METATYPE | // code to copy-construct the parameter in question (Q_DECLARE_METATYPE | ||||
// and qRegisterMetaType generate this code). For the Config class, | // and qRegisterMetaType generate this code). For the Config class, | ||||
// which is noncopyable, we can't do this. So.. we have to pass | // which is noncopyable, we can't do this. So.. we have to pass | ||||
// pointers to Config around. Make sure Config &/Config * isn't a | // pointers to Config around. Make sure Config &/Config * isn't a | ||||
// temporary (eg it lives somewhere aside from the stack) or this will | // temporary (eg it lives somewhere aside from the stack) or this will | ||||
// crash because initialize() gets executed in another thread at some | // crash because initialize() gets executed in another thread at some | ||||
// unspecified time (after) requestedInitialize() is emitted! | // unspecified time (after) requestedInitialize() is emitted! | ||||
connect(this, | connect(this, &BitcoinApplication::requestedInitialize, executor, | ||||
SIGNAL(requestedInitialize(Config *, RPCServer *, | &BitcoinABC::initialize); | ||||
HTTPRPCRequestProcessor *)), | |||||
executor, | |||||
SLOT(initialize(Config *, RPCServer *, HTTPRPCRequestProcessor *))); | |||||
connect(this, SIGNAL(requestedShutdown()), executor, SLOT(shutdown())); | connect(this, &BitcoinApplication::requestedShutdown, executor, | ||||
&BitcoinABC::shutdown); | |||||
/* make sure executor object is deleted in its own thread */ | /* make sure executor object is deleted in its own thread */ | ||||
connect(this, SIGNAL(stopThread()), executor, SLOT(deleteLater())); | connect(this, &BitcoinApplication::stopThread, executor, | ||||
connect(this, SIGNAL(stopThread()), coreThread, SLOT(quit())); | &QObject::deleteLater); | ||||
connect(this, &BitcoinApplication::stopThread, coreThread, &QThread::quit); | |||||
coreThread->start(); | coreThread->start(); | ||||
} | } | ||||
void BitcoinApplication::parameterSetup() { | void BitcoinApplication::parameterSetup() { | ||||
m_node.initLogging(); | m_node.initLogging(); | ||||
m_node.initParameterInteraction(); | m_node.initParameterInteraction(); | ||||
} | } | ||||
Show All 40 Lines | |||||
void BitcoinApplication::addWallet(WalletModel *walletModel) { | void BitcoinApplication::addWallet(WalletModel *walletModel) { | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
window->addWallet(walletModel); | window->addWallet(walletModel); | ||||
if (m_wallet_models.empty()) { | if (m_wallet_models.empty()) { | ||||
window->setCurrentWallet(walletModel->getWalletName()); | window->setCurrentWallet(walletModel->getWalletName()); | ||||
} | } | ||||
connect(walletModel, | connect(walletModel, &WalletModel::coinsSent, paymentServer, | ||||
SIGNAL(coinsSent(WalletModel *, SendCoinsRecipient, QByteArray)), | &PaymentServer::fetchPaymentACK); | ||||
paymentServer, | connect(walletModel, &WalletModel::unload, this, | ||||
SLOT(fetchPaymentACK(WalletModel *, const SendCoinsRecipient &, | &BitcoinApplication::removeWallet); | ||||
QByteArray))); | |||||
connect(walletModel, SIGNAL(unload()), this, SLOT(removeWallet())); | |||||
m_wallet_models.push_back(walletModel); | m_wallet_models.push_back(walletModel); | ||||
#endif | #endif | ||||
} | } | ||||
void BitcoinApplication::removeWallet() { | void BitcoinApplication::removeWallet() { | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
WalletModel *walletModel = static_cast<WalletModel *>(sender()); | WalletModel *walletModel = static_cast<WalletModel *>(sender()); | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | #endif | ||||
} else { | } else { | ||||
window->show(); | window->show(); | ||||
} | } | ||||
Q_EMIT splashFinished(window); | Q_EMIT splashFinished(window); | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
// Now that initialization/startup is done, process any command-line | // Now that initialization/startup is done, process any command-line | ||||
// bitcoincash: URIs or payment requests: | // bitcoincash: URIs or payment requests: | ||||
connect(paymentServer, SIGNAL(receivedPaymentRequest(SendCoinsRecipient)), | connect(paymentServer, &PaymentServer::receivedPaymentRequest, window, | ||||
window, SLOT(handlePaymentRequest(SendCoinsRecipient))); | &BitcoinGUI::handlePaymentRequest); | ||||
connect(window, SIGNAL(receivedURI(QString)), paymentServer, | connect(window, &BitcoinGUI::receivedURI, paymentServer, | ||||
SLOT(handleURIOrFile(QString))); | &PaymentServer::handleURIOrFile); | ||||
connect(paymentServer, SIGNAL(message(QString, QString, unsigned int)), | connect( | ||||
window, SLOT(message(QString, QString, unsigned int))); | paymentServer, &PaymentServer::message, | ||||
QTimer::singleShot(100, paymentServer, SLOT(uiReady())); | [this](const QString &title, const QString &message, | ||||
unsigned int style) { window->message(title, message, style); }); | |||||
QTimer::singleShot(100, paymentServer, &PaymentServer::uiReady); | |||||
#endif | #endif | ||||
pollShutdownTimer->start(200); | pollShutdownTimer->start(200); | ||||
} | } | ||||
void BitcoinApplication::shutdownResult() { | void BitcoinApplication::shutdownResult() { | ||||
// Exit second main loop invocation after shutdown finished. | // Exit second main loop invocation after shutdown finished. | ||||
quit(); | quit(); | ||||
▲ Show 20 Lines • Show All 338 Lines • Show Last 20 Lines |