aboutsummaryrefslogtreecommitdiff
path: root/src/qt/bitcoin.cpp
diff options
context:
space:
mode:
authorJoão Barbosa <joao.paulo.barbosa@gmail.com>2018-04-26 18:28:41 +0100
committerJoão Barbosa <joao.paulo.barbosa@gmail.com>2018-05-16 20:48:48 +0100
commit0e674ba5572275bcc1eb8f91c6292f871925f965 (patch)
tree1a33d074541a5b427c4697d164f9262e71f8a762 /src/qt/bitcoin.cpp
parent1c8fe0bf90253f316af138ac8c088ae708ced357 (diff)
downloadbitcoin-0e674ba5572275bcc1eb8f91c6292f871925f965.tar.xz
ui: Support wallets loaded dynamically
Diffstat (limited to 'src/qt/bitcoin.cpp')
-rw-r--r--src/qt/bitcoin.cpp39
1 files changed, 27 insertions, 12 deletions
diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
index a0f2702d39..d317070e91 100644
--- a/src/qt/bitcoin.cpp
+++ b/src/qt/bitcoin.cpp
@@ -234,6 +234,7 @@ public Q_SLOTS:
void shutdownResult();
/// Handle runaway exceptions. Shows a message box with the problem and quits the program.
void handleRunawayException(const QString &message);
+ void addWallet(WalletModel* walletModel);
Q_SIGNALS:
void requestedInitialize();
@@ -251,6 +252,7 @@ private:
#ifdef ENABLE_WALLET
PaymentServer* paymentServer;
std::vector<WalletModel*> m_wallet_models;
+ std::unique_ptr<interfaces::Handler> m_handler_load_wallet;
#endif
int returnValue;
const PlatformStyle *platformStyle;
@@ -447,6 +449,22 @@ void BitcoinApplication::requestShutdown()
Q_EMIT requestedShutdown();
}
+void BitcoinApplication::addWallet(WalletModel* walletModel)
+{
+#ifdef ENABLE_WALLET
+ window->addWallet(walletModel);
+
+ if (m_wallet_models.empty()) {
+ window->setCurrentWallet(walletModel->getWalletName());
+ }
+
+ connect(walletModel, SIGNAL(coinsSent(WalletModel*, SendCoinsRecipient, QByteArray)),
+ paymentServer, SLOT(fetchPaymentACK(WalletModel*, const SendCoinsRecipient&, QByteArray)));
+
+ m_wallet_models.push_back(walletModel);
+#endif
+}
+
void BitcoinApplication::initializeResult(bool success)
{
qDebug() << __func__ << ": Initialization result: " << success;
@@ -465,19 +483,13 @@ void BitcoinApplication::initializeResult(bool success)
window->setClientModel(clientModel);
#ifdef ENABLE_WALLET
- auto wallets = m_node.getWallets();
- for (auto& wallet : wallets) {
- WalletModel * const walletModel = new WalletModel(std::move(wallet), m_node, platformStyle, optionsModel);
-
- window->addWallet(walletModel);
- if (m_wallet_models.empty()) {
- window->setCurrentWallet(walletModel->getWalletName());
- }
+ m_handler_load_wallet = m_node.handleLoadWallet([this](std::unique_ptr<interfaces::Wallet> wallet) {
+ QMetaObject::invokeMethod(this, "addWallet", Qt::QueuedConnection,
+ Q_ARG(WalletModel*, new WalletModel(std::move(wallet), m_node, platformStyle, optionsModel)));
+ });
- connect(walletModel, SIGNAL(coinsSent(WalletModel*,SendCoinsRecipient,QByteArray)),
- paymentServer, SLOT(fetchPaymentACK(WalletModel*,const SendCoinsRecipient&,QByteArray)));
-
- m_wallet_models.push_back(walletModel);
+ for (auto& wallet : m_node.getWallets()) {
+ addWallet(new WalletModel(std::move(wallet), m_node, platformStyle, optionsModel));
}
#endif
@@ -593,6 +605,9 @@ int main(int argc, char *argv[])
// IMPORTANT if it is no longer a typedef use the normal variant above
qRegisterMetaType< CAmount >("CAmount");
qRegisterMetaType< std::function<void(void)> >("std::function<void(void)>");
+#ifdef ENABLE_WALLET
+ qRegisterMetaType<WalletModel*>("WalletModel*");
+#endif
/// 3. Application identification
// must be set before OptionsModel is initialized or translations are loaded,