Changeset View
Changeset View
Standalone View
Standalone View
src/qt/walletcontroller.cpp
// Copyright (c) 2019 The Bitcoin Core developers | // Copyright (c) 2019 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <qt/walletcontroller.h> | #include <qt/walletcontroller.h> | ||||
#include <interfaces/handler.h> | #include <interfaces/handler.h> | ||||
#include <interfaces/node.h> | #include <interfaces/node.h> | ||||
#include <QApplication> | |||||
#include <QMutexLocker> | #include <QMutexLocker> | ||||
#include <QThread> | #include <QThread> | ||||
#include <QWindow> | |||||
#include <algorithm> | #include <algorithm> | ||||
WalletController::WalletController(interfaces::Node &node, | WalletController::WalletController(interfaces::Node &node, | ||||
const PlatformStyle *platform_style, | const PlatformStyle *platform_style, | ||||
OptionsModel *options_model, QObject *parent) | OptionsModel *options_model, QObject *parent) | ||||
: QObject(parent), m_node(node), m_platform_style(platform_style), | : QObject(parent), m_node(node), m_platform_style(platform_style), | ||||
m_options_model(options_model) { | m_options_model(options_model) { | ||||
Show All 30 Lines | if (!m_wallets.empty()) { | ||||
} | } | ||||
} | } | ||||
// Instantiate model and register it. | // Instantiate model and register it. | ||||
WalletModel *wallet_model = new WalletModel( | WalletModel *wallet_model = new WalletModel( | ||||
std::move(wallet), m_node, m_platform_style, m_options_model, nullptr); | std::move(wallet), m_node, m_platform_style, m_options_model, nullptr); | ||||
m_wallets.push_back(wallet_model); | m_wallets.push_back(wallet_model); | ||||
connect(wallet_model, &WalletModel::unload, | connect(wallet_model, &WalletModel::unload, [this, wallet_model] { | ||||
[this, wallet_model] { removeAndDeleteWallet(wallet_model); }); | // Defer removeAndDeleteWallet when no modal widget is active. | ||||
// TODO: remove this workaround by removing usage of QDiallog::exec. | |||||
if (QApplication::activeModalWidget()) { | |||||
connect( | |||||
qApp, &QApplication::focusWindowChanged, wallet_model, | |||||
[this, wallet_model]() { | |||||
if (!QApplication::activeModalWidget()) { | |||||
removeAndDeleteWallet(wallet_model); | |||||
} | |||||
}, | |||||
Qt::QueuedConnection); | |||||
} else { | |||||
removeAndDeleteWallet(wallet_model); | |||||
} | |||||
}); | |||||
// Re-emit coinsSent signal from wallet model. | // Re-emit coinsSent signal from wallet model. | ||||
connect(wallet_model, &WalletModel::coinsSent, this, | connect(wallet_model, &WalletModel::coinsSent, this, | ||||
&WalletController::coinsSent); | &WalletController::coinsSent); | ||||
// Notify walletAdded signal on the GUI thread. | // Notify walletAdded signal on the GUI thread. | ||||
if (QThread::currentThread() == thread()) { | if (QThread::currentThread() == thread()) { | ||||
addWallet(wallet_model); | addWallet(wallet_model); | ||||
Show All 29 Lines |