gui: Refactor to use WalletController
This commit is contained in:
parent
8fa271f089
commit
0dd9bdefa1
4 changed files with 44 additions and 62 deletions
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
#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 <interfaces/handler.h>
|
#include <interfaces/handler.h>
|
||||||
|
@ -184,10 +184,6 @@ BitcoinApplication::BitcoinApplication(interfaces::Node& node, int &argc, char *
|
||||||
clientModel(nullptr),
|
clientModel(nullptr),
|
||||||
window(nullptr),
|
window(nullptr),
|
||||||
pollShutdownTimer(nullptr),
|
pollShutdownTimer(nullptr),
|
||||||
#ifdef ENABLE_WALLET
|
|
||||||
paymentServer(nullptr),
|
|
||||||
m_wallet_models(),
|
|
||||||
#endif
|
|
||||||
returnValue(0),
|
returnValue(0),
|
||||||
platformStyle(nullptr)
|
platformStyle(nullptr)
|
||||||
{
|
{
|
||||||
|
@ -316,11 +312,8 @@ void BitcoinApplication::requestShutdown()
|
||||||
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 = nullptr;
|
clientModel = nullptr;
|
||||||
|
@ -331,35 +324,6 @@ void BitcoinApplication::requestShutdown()
|
||||||
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;
|
||||||
|
@ -370,26 +334,22 @@ void BitcoinApplication::initializeResult(bool success)
|
||||||
// Log this only after AppInitMain finishes, as then logging setup is guaranteed complete
|
// Log this only after AppInitMain finishes, as then logging setup is 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) paymentServer->setOptionsModel(optionsModel);
|
if (paymentServer) {
|
||||||
|
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([this](std::unique_ptr<interfaces::Wallet> wallet) {
|
window->setWalletController(m_wallet_controller);
|
||||||
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 (iconified) or minimized to tray
|
// If -min option passed, start window minimized (iconified) or minimized to tray
|
||||||
|
@ -493,9 +453,6 @@ int GuiMain(int argc, char* argv[])
|
||||||
// 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< CAmount >("CAmount");
|
qRegisterMetaType< CAmount >("CAmount");
|
||||||
qRegisterMetaType< std::function<void()> >("std::function<void()>");
|
qRegisterMetaType< std::function<void()> >("std::function<void()>");
|
||||||
#ifdef ENABLE_WALLET
|
|
||||||
qRegisterMetaType<WalletModel*>("WalletModel*");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// 2. Parse command-line options. We do this after qt in order to show an error if there are problems parsing these
|
/// 2. Parse command-line options. We do this after qt in order to show an error if there are problems parsing these
|
||||||
// Command-line options take precedence:
|
// Command-line options take precedence:
|
||||||
|
|
|
@ -19,6 +19,7 @@ class NetworkStyle;
|
||||||
class OptionsModel;
|
class OptionsModel;
|
||||||
class PaymentServer;
|
class PaymentServer;
|
||||||
class PlatformStyle;
|
class PlatformStyle;
|
||||||
|
class WalletController;
|
||||||
class WalletModel;
|
class WalletModel;
|
||||||
|
|
||||||
namespace interfaces {
|
namespace interfaces {
|
||||||
|
@ -93,8 +94,6 @@ public Q_SLOTS:
|
||||||
void shutdownResult();
|
void shutdownResult();
|
||||||
/// Handle runaway exceptions. Shows a message box with the problem and quits the program.
|
/// Handle runaway exceptions. Shows a message box with the problem and quits the program.
|
||||||
void handleRunawayException(const QString &message);
|
void handleRunawayException(const QString &message);
|
||||||
void addWallet(WalletModel* walletModel);
|
|
||||||
void removeWallet();
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void requestedInitialize();
|
void requestedInitialize();
|
||||||
|
@ -111,9 +110,8 @@ private:
|
||||||
BitcoinGUI *window;
|
BitcoinGUI *window;
|
||||||
QTimer *pollShutdownTimer;
|
QTimer *pollShutdownTimer;
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
PaymentServer* paymentServer;
|
PaymentServer* paymentServer{nullptr};
|
||||||
std::vector<WalletModel*> m_wallet_models;
|
WalletController* m_wallet_controller{nullptr};
|
||||||
std::unique_ptr<interfaces::Handler> m_handler_load_wallet;
|
|
||||||
#endif
|
#endif
|
||||||
int returnValue;
|
int returnValue;
|
||||||
const PlatformStyle *platformStyle;
|
const PlatformStyle *platformStyle;
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include <qt/utilitydialog.h>
|
#include <qt/utilitydialog.h>
|
||||||
|
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
|
#include <qt/walletcontroller.h>
|
||||||
#include <qt/walletframe.h>
|
#include <qt/walletframe.h>
|
||||||
#include <qt/walletmodel.h>
|
#include <qt/walletmodel.h>
|
||||||
#include <qt/walletview.h>
|
#include <qt/walletview.h>
|
||||||
|
@ -565,18 +566,33 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
|
void BitcoinGUI::setWalletController(WalletController* wallet_controller)
|
||||||
|
{
|
||||||
|
assert(!m_wallet_controller);
|
||||||
|
assert(wallet_controller);
|
||||||
|
|
||||||
|
m_wallet_controller = wallet_controller;
|
||||||
|
|
||||||
|
connect(wallet_controller, &WalletController::walletAdded, this, &BitcoinGUI::addWallet);
|
||||||
|
connect(wallet_controller, &WalletController::walletRemoved, this, &BitcoinGUI::removeWallet);
|
||||||
|
|
||||||
|
for (WalletModel* wallet_model : m_wallet_controller->getWallets()) {
|
||||||
|
addWallet(wallet_model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void BitcoinGUI::addWallet(WalletModel* walletModel)
|
void BitcoinGUI::addWallet(WalletModel* walletModel)
|
||||||
{
|
{
|
||||||
if (!walletFrame) return;
|
if (!walletFrame) return;
|
||||||
const QString display_name = walletModel->getDisplayName();
|
const QString display_name = walletModel->getDisplayName();
|
||||||
setWalletActionsEnabled(true);
|
setWalletActionsEnabled(true);
|
||||||
|
rpcConsole->addWallet(walletModel);
|
||||||
|
walletFrame->addWallet(walletModel);
|
||||||
m_wallet_selector->addItem(display_name, QVariant::fromValue(walletModel));
|
m_wallet_selector->addItem(display_name, QVariant::fromValue(walletModel));
|
||||||
if (m_wallet_selector->count() == 2) {
|
if (m_wallet_selector->count() == 2) {
|
||||||
m_wallet_selector_label_action->setVisible(true);
|
m_wallet_selector_label_action->setVisible(true);
|
||||||
m_wallet_selector_action->setVisible(true);
|
m_wallet_selector_action->setVisible(true);
|
||||||
}
|
}
|
||||||
rpcConsole->addWallet(walletModel);
|
|
||||||
walletFrame->addWallet(walletModel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitcoinGUI::removeWallet(WalletModel* walletModel)
|
void BitcoinGUI::removeWallet(WalletModel* walletModel)
|
||||||
|
@ -599,13 +615,19 @@ void BitcoinGUI::setCurrentWallet(WalletModel* wallet_model)
|
||||||
{
|
{
|
||||||
if (!walletFrame) return;
|
if (!walletFrame) return;
|
||||||
walletFrame->setCurrentWallet(wallet_model);
|
walletFrame->setCurrentWallet(wallet_model);
|
||||||
|
for (int index = 0; index < m_wallet_selector->count(); ++index) {
|
||||||
|
if (m_wallet_selector->itemData(index).value<WalletModel*>() == wallet_model) {
|
||||||
|
m_wallet_selector->setCurrentIndex(index);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
updateWindowTitle();
|
updateWindowTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitcoinGUI::setCurrentWalletBySelectorIndex(int index)
|
void BitcoinGUI::setCurrentWalletBySelectorIndex(int index)
|
||||||
{
|
{
|
||||||
WalletModel* wallet_model = m_wallet_selector->itemData(index).value<WalletModel*>();
|
WalletModel* wallet_model = m_wallet_selector->itemData(index).value<WalletModel*>();
|
||||||
setCurrentWallet(wallet_model);
|
if (wallet_model) setCurrentWallet(wallet_model);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitcoinGUI::removeAllWallets()
|
void BitcoinGUI::removeAllWallets()
|
||||||
|
|
|
@ -33,6 +33,7 @@ class PlatformStyle;
|
||||||
class RPCConsole;
|
class RPCConsole;
|
||||||
class SendCoinsRecipient;
|
class SendCoinsRecipient;
|
||||||
class UnitDisplayStatusBarControl;
|
class UnitDisplayStatusBarControl;
|
||||||
|
class WalletController;
|
||||||
class WalletFrame;
|
class WalletFrame;
|
||||||
class WalletModel;
|
class WalletModel;
|
||||||
class HelpMessageDialog;
|
class HelpMessageDialog;
|
||||||
|
@ -74,6 +75,9 @@ public:
|
||||||
The client model represents the part of the core that communicates with the P2P network, and is wallet-agnostic.
|
The client model represents the part of the core that communicates with the P2P network, and is wallet-agnostic.
|
||||||
*/
|
*/
|
||||||
void setClientModel(ClientModel *clientModel);
|
void setClientModel(ClientModel *clientModel);
|
||||||
|
#ifdef ENABLE_WALLET
|
||||||
|
void setWalletController(WalletController* wallet_controller);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
/** Set the wallet model.
|
/** Set the wallet model.
|
||||||
|
@ -101,6 +105,7 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
interfaces::Node& m_node;
|
interfaces::Node& m_node;
|
||||||
|
WalletController* m_wallet_controller{nullptr};
|
||||||
std::unique_ptr<interfaces::Handler> m_handler_message_box;
|
std::unique_ptr<interfaces::Handler> m_handler_message_box;
|
||||||
std::unique_ptr<interfaces::Handler> m_handler_question;
|
std::unique_ptr<interfaces::Handler> m_handler_question;
|
||||||
ClientModel* clientModel = nullptr;
|
ClientModel* clientModel = nullptr;
|
||||||
|
|
Loading…
Add table
Reference in a new issue