Changeset View
Changeset View
Standalone View
Standalone View
src/qt/bitcoin.cpp
Show All 28 Lines | |||||
#include <ui_interface.h> | #include <ui_interface.h> | ||||
#include <uint256.h> | #include <uint256.h> | ||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <walletinitinterface.h> | #include <walletinitinterface.h> | ||||
#include <warnings.h> | #include <warnings.h> | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
#include <qt/paymentserver.h> | #include <qt/paymentserver.h> | ||||
#include <qt/walletmodel.h> | #include <qt/walletcontroller.h> | ||||
#endif | #endif | ||||
#include <QApplication> | #include <QApplication> | ||||
#include <QDebug> | #include <QDebug> | ||||
#include <QLibraryInfo> | #include <QLibraryInfo> | ||||
#include <QLocale> | #include <QLocale> | ||||
#include <QMessageBox> | #include <QMessageBox> | ||||
#include <QSettings> | #include <QSettings> | ||||
▲ Show 20 Lines • Show All 138 Lines • ▼ Show 20 Lines | void BitcoinABC::shutdown() { | ||||
} 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(0), m_node(node), optionsModel(0), | ||||
clientModel(0), window(0), pollShutdownTimer(0), | clientModel(0), window(0), pollShutdownTimer(0), returnValue(0), | ||||
#ifdef ENABLE_WALLET | platformStyle(0) { | ||||
paymentServer(0), m_wallet_models(), | |||||
#endif | |||||
returnValue(0), platformStyle(0) { | |||||
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 20 Lines • Show All 132 Lines • ▼ Show 20 Lines | void BitcoinApplication::requestShutdown(Config &config) { | ||||
qDebug() << __func__ << ": Requesting shutdown"; | qDebug() << __func__ << ": Requesting shutdown"; | ||||
startThread(); | startThread(); | ||||
window->hide(); | window->hide(); | ||||
window->setClientModel(0); | window->setClientModel(0); | ||||
pollShutdownTimer->stop(); | pollShutdownTimer->stop(); | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
window->removeAllWallets(); | delete m_wallet_controller; | ||||
for (const WalletModel *walletModel : m_wallet_models) { | m_wallet_controller = nullptr; | ||||
delete walletModel; | |||||
} | |||||
m_wallet_models.clear(); | |||||
#endif | #endif | ||||
delete clientModel; | delete clientModel; | ||||
clientModel = 0; | clientModel = 0; | ||||
m_node.startShutdown(); | m_node.startShutdown(); | ||||
// Request shutdown from core thread | // Request shutdown from core thread | ||||
Q_EMIT requestedShutdown(); | Q_EMIT requestedShutdown(); | ||||
} | } | ||||
void BitcoinApplication::addWallet(WalletModel *walletModel) { | |||||
#ifdef ENABLE_WALLET | |||||
window->addWallet(walletModel); | |||||
if (m_wallet_models.empty()) { | |||||
window->setCurrentWallet(walletModel); | |||||
} | |||||
#ifdef ENABLE_BIP70 | |||||
connect(walletModel, &WalletModel::coinsSent, paymentServer, | |||||
&PaymentServer::fetchPaymentACK); | |||||
#endif | |||||
connect(walletModel, &WalletModel::unload, this, | |||||
&BitcoinApplication::removeWallet); | |||||
m_wallet_models.push_back(walletModel); | |||||
#endif | |||||
} | |||||
void BitcoinApplication::removeWallet() { | |||||
#ifdef ENABLE_WALLET | |||||
WalletModel *walletModel = static_cast<WalletModel *>(sender()); | |||||
m_wallet_models.erase( | |||||
std::find(m_wallet_models.begin(), m_wallet_models.end(), walletModel)); | |||||
window->removeWallet(walletModel); | |||||
walletModel->deleteLater(); | |||||
#endif | |||||
} | |||||
void BitcoinApplication::initializeResult(bool success) { | void BitcoinApplication::initializeResult(bool success) { | ||||
qDebug() << __func__ << ": Initialization result: " << success; | qDebug() << __func__ << ": Initialization result: " << success; | ||||
returnValue = success ? EXIT_SUCCESS : EXIT_FAILURE; | returnValue = success ? EXIT_SUCCESS : EXIT_FAILURE; | ||||
if (!success) { | if (!success) { | ||||
// Make sure splash screen doesn't stick around during shutdown. | // Make sure splash screen doesn't stick around during shutdown. | ||||
Q_EMIT splashFinished(window); | Q_EMIT splashFinished(window); | ||||
// Exit first main loop invocation. | // Exit first main loop invocation. | ||||
quit(); | quit(); | ||||
return; | return; | ||||
} | } | ||||
// Log this only after AppInitMain finishes, as then logging setup is | // Log this only after AppInitMain finishes, as then logging setup is | ||||
// guaranteed complete. | // guaranteed complete. | ||||
qWarning() << "Platform customization:" << platformStyle->getName(); | qWarning() << "Platform customization:" << platformStyle->getName(); | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
m_wallet_controller = | |||||
new WalletController(m_node, platformStyle, optionsModel, this); | |||||
#ifdef ENABLE_BIP70 | #ifdef ENABLE_BIP70 | ||||
PaymentServer::LoadRootCAs(); | PaymentServer::LoadRootCAs(); | ||||
#endif | #endif | ||||
if (paymentServer) { | if (paymentServer) { | ||||
paymentServer->setOptionsModel(optionsModel); | paymentServer->setOptionsModel(optionsModel); | ||||
#ifdef ENABLE_BIP70 | |||||
connect(m_wallet_controller, &WalletController::coinsSent, | |||||
paymentServer, &PaymentServer::fetchPaymentACK); | |||||
#endif | |||||
} | } | ||||
#endif | #endif | ||||
clientModel = new ClientModel(m_node, optionsModel); | clientModel = new ClientModel(m_node, optionsModel); | ||||
window->setClientModel(clientModel); | window->setClientModel(clientModel); | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
m_handler_load_wallet = m_node.handleLoadWallet( | window->setWalletController(m_wallet_controller); | ||||
[this](std::unique_ptr<interfaces::Wallet> wallet) { | |||||
WalletModel *wallet_model = | |||||
new WalletModel(std::move(wallet), m_node, platformStyle, | |||||
optionsModel, nullptr); | |||||
// Fix wallet model thread affinity. | |||||
wallet_model->moveToThread(thread()); | |||||
QMetaObject::invokeMethod(this, "addWallet", Qt::QueuedConnection, | |||||
Q_ARG(WalletModel *, wallet_model)); | |||||
}); | |||||
for (auto &wallet : m_node.getWallets()) { | |||||
addWallet(new WalletModel(std::move(wallet), m_node, platformStyle, | |||||
optionsModel)); | |||||
} | |||||
#endif | #endif | ||||
// If -min option passed, start window minimized. | // If -min option passed, start window minimized. | ||||
if (gArgs.GetBoolArg("-min", false)) { | if (gArgs.GetBoolArg("-min", false)) { | ||||
window->showMinimized(); | window->showMinimized(); | ||||
} else { | } else { | ||||
window->show(); | window->show(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Lines | #endif | ||||
// Register meta types used for QMetaObject::invokeMethod | // Register meta types used for QMetaObject::invokeMethod | ||||
qRegisterMetaType<bool *>(); | qRegisterMetaType<bool *>(); | ||||
// Need to pass name here as Amount is a typedef (see | // Need to pass name here as Amount is a typedef (see | ||||
// http://qt-project.org/doc/qt-5/qmetatype.html#qRegisterMetaType) | // http://qt-project.org/doc/qt-5/qmetatype.html#qRegisterMetaType) | ||||
// IMPORTANT if it is no longer a typedef use the normal variant above | // IMPORTANT if it is no longer a typedef use the normal variant above | ||||
qRegisterMetaType<Amount>("Amount"); | qRegisterMetaType<Amount>("Amount"); | ||||
qRegisterMetaType<std::function<void()>>("std::function<void()>"); | qRegisterMetaType<std::function<void()>>("std::function<void()>"); | ||||
#ifdef ENABLE_WALLET | |||||
qRegisterMetaType<WalletModel *>("WalletModel*"); | |||||
#endif | |||||
// Need to register any types Qt doesn't know about if you intend | // Need to register any types Qt doesn't know about if you intend | ||||
// to use them with the signal/slot mechanism Qt provides. Even pointers. | // to use them with the signal/slot mechanism Qt provides. Even pointers. | ||||
// Note that class Config is noncopyable and so we can't register a | // Note that class Config is noncopyable and so we can't register a | ||||
// non-pointer version of it with Qt, because Qt expects to be able to | // non-pointer version of it with Qt, because Qt expects to be able to | ||||
// copy-construct non-pointers to objects for invoking slots | // copy-construct non-pointers to objects for invoking slots | ||||
// behind-the-scenes in the 'Queued' connection case. | // behind-the-scenes in the 'Queued' connection case. | ||||
qRegisterMetaType<Config *>(); | qRegisterMetaType<Config *>(); | ||||
▲ Show 20 Lines • Show All 189 Lines • Show Last 20 Lines |