Skip to content

Commit

Permalink
ui: Support wallets loaded dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
promag committed Apr 26, 2018
1 parent 0885d40 commit 11b76ed
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
35 changes: 23 additions & 12 deletions src/qt/bitcoin.cpp
Expand Up @@ -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(std::shared_ptr<interfaces::Wallet> wallet);

Q_SIGNALS:
void requestedInitialize();
Expand All @@ -251,6 +252,7 @@ public Q_SLOTS:
#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;
Expand Down Expand Up @@ -447,6 +449,20 @@ void BitcoinApplication::requestShutdown()
Q_EMIT requestedShutdown();
}

void BitcoinApplication::addWallet(std::shared_ptr<interfaces::Wallet> wallet) {
WalletModel * const walletModel = new WalletModel(std::move(wallet), m_node, platformStyle, optionsModel);

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);
}

void BitcoinApplication::initializeResult(bool success)
{
qDebug() << __func__ << ": Initialization result: " << success;
Expand All @@ -465,19 +481,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());
}

connect(walletModel, SIGNAL(coinsSent(WalletModel*,SendCoinsRecipient,QByteArray)),
paymentServer, SLOT(fetchPaymentACK(WalletModel*,const SendCoinsRecipient&,QByteArray)));
m_handler_load_wallet = m_node.handleLoadWallet([this](std::unique_ptr<interfaces::Wallet> wallet) {
QMetaObject::invokeMethod(this, "addWallet", Qt::QueuedConnection,
Q_ARG(std::shared_ptr<interfaces::Wallet>, std::move(wallet)));
});

m_wallet_models.push_back(walletModel);
for (auto& wallet : m_node.getWallets()) {
addWallet(std::move(wallet));
}
#endif

Expand Down Expand Up @@ -577,6 +587,7 @@ 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)>");
qRegisterMetaType< std::shared_ptr<interfaces::Wallet> >("std::shared_ptr<interfaces::Wallet>");

/// 3. Application identification
// must be set before OptionsModel is initialized or translations are loaded,
Expand Down
2 changes: 1 addition & 1 deletion src/qt/walletmodel.cpp
Expand Up @@ -28,7 +28,7 @@
#include <QTimer>


WalletModel::WalletModel(std::unique_ptr<interfaces::Wallet> wallet, interfaces::Node& node, const PlatformStyle *platformStyle, OptionsModel *_optionsModel, QObject *parent) :
WalletModel::WalletModel(std::shared_ptr<interfaces::Wallet> wallet, interfaces::Node& node, const PlatformStyle *platformStyle, OptionsModel *_optionsModel, QObject *parent) :
QObject(parent), m_wallet(std::move(wallet)), m_node(node), optionsModel(_optionsModel), addressTableModel(0),
transactionTableModel(0),
recentRequestsTableModel(0),
Expand Down
6 changes: 4 additions & 2 deletions src/qt/walletmodel.h
Expand Up @@ -45,6 +45,8 @@ QT_BEGIN_NAMESPACE
class QTimer;
QT_END_NAMESPACE

Q_DECLARE_METATYPE(std::shared_ptr<interfaces::Wallet>);

class SendCoinsRecipient
{
public:
Expand Down Expand Up @@ -111,7 +113,7 @@ class WalletModel : public QObject
Q_OBJECT

public:
explicit WalletModel(std::unique_ptr<interfaces::Wallet> wallet, interfaces::Node& node, const PlatformStyle *platformStyle, OptionsModel *optionsModel, QObject *parent = 0);
explicit WalletModel(std::shared_ptr<interfaces::Wallet> wallet, interfaces::Node& node, const PlatformStyle *platformStyle, OptionsModel *optionsModel, QObject *parent = 0);
~WalletModel();

enum StatusCode // Returned by sendCoins
Expand Down Expand Up @@ -205,7 +207,7 @@ class WalletModel : public QObject

bool isMultiwallet();
private:
std::unique_ptr<interfaces::Wallet> m_wallet;
std::shared_ptr<interfaces::Wallet> m_wallet;
std::unique_ptr<interfaces::Handler> m_handler_status_changed;
std::unique_ptr<interfaces::Handler> m_handler_address_book_changed;
std::unique_ptr<interfaces::Handler> m_handler_transaction_changed;
Expand Down

0 comments on commit 11b76ed

Please sign in to comment.