Changeset View
Changeset View
Standalone View
Standalone View
src/qt/walletcontroller.h
// 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. | ||||
#ifndef BITCOIN_QT_WALLETCONTROLLER_H | #ifndef BITCOIN_QT_WALLETCONTROLLER_H | ||||
#define BITCOIN_QT_WALLETCONTROLLER_H | #define BITCOIN_QT_WALLETCONTROLLER_H | ||||
#include <qt/walletmodel.h> | #include <qt/walletmodel.h> | ||||
#include <sync.h> | #include <sync.h> | ||||
#include <QMutex> | #include <QMutex> | ||||
#include <list> | #include <list> | ||||
#include <memory> | #include <memory> | ||||
#include <vector> | #include <vector> | ||||
#include <QMessageBox> | |||||
#include <QThread> | #include <QThread> | ||||
class OptionsModel; | class OptionsModel; | ||||
class PlatformStyle; | class PlatformStyle; | ||||
namespace interfaces { | namespace interfaces { | ||||
class Handler; | class Handler; | ||||
class Node; | class Node; | ||||
} // namespace interfaces | } // namespace interfaces | ||||
class OpenWalletActivity; | |||||
/** | /** | ||||
* Controller between interfaces::Node, WalletModel instances and the GUI. | * Controller between interfaces::Node, WalletModel instances and the GUI. | ||||
*/ | */ | ||||
class WalletController : public QObject { | class WalletController : public QObject { | ||||
Q_OBJECT | Q_OBJECT | ||||
WalletModel *getOrCreateWallet(std::unique_ptr<interfaces::Wallet> wallet); | WalletModel *getOrCreateWallet(std::unique_ptr<interfaces::Wallet> wallet); | ||||
void removeAndDeleteWallet(WalletModel *wallet_model); | void removeAndDeleteWallet(WalletModel *wallet_model); | ||||
public: | public: | ||||
WalletController(interfaces::Node &node, | WalletController(interfaces::Node &node, | ||||
const PlatformStyle *platform_style, | const PlatformStyle *platform_style, | ||||
OptionsModel *options_model, QObject *parent); | OptionsModel *options_model, QObject *parent); | ||||
~WalletController(); | ~WalletController(); | ||||
std::vector<WalletModel *> getWallets() const; | std::vector<WalletModel *> getWallets() const; | ||||
std::vector<std::string> getWalletsAvailableToOpen() const; | std::vector<std::string> getWalletsAvailableToOpen() const; | ||||
WalletModel *openWallet(const CChainParams ¶ms, const std::string &name, | OpenWalletActivity *openWallet(const CChainParams ¶ms, | ||||
const std::string &name, | |||||
QWidget *parent = nullptr); | QWidget *parent = nullptr); | ||||
private Q_SLOTS: | private Q_SLOTS: | ||||
void addWallet(WalletModel *wallet_model); | void addWallet(WalletModel *wallet_model); | ||||
Q_SIGNALS: | Q_SIGNALS: | ||||
void walletAdded(WalletModel *wallet_model); | void walletAdded(WalletModel *wallet_model); | ||||
void walletRemoved(WalletModel *wallet_model); | void walletRemoved(WalletModel *wallet_model); | ||||
void coinsSent(WalletModel *wallet_model, SendCoinsRecipient recipient, | void coinsSent(WalletModel *wallet_model, SendCoinsRecipient recipient, | ||||
QByteArray transaction); | QByteArray transaction); | ||||
private: | private: | ||||
QThread m_activity_thread; | QThread m_activity_thread; | ||||
interfaces::Node &m_node; | interfaces::Node &m_node; | ||||
const PlatformStyle *const m_platform_style; | const PlatformStyle *const m_platform_style; | ||||
OptionsModel *const m_options_model; | OptionsModel *const m_options_model; | ||||
mutable QMutex m_mutex; | mutable QMutex m_mutex; | ||||
std::vector<WalletModel *> m_wallets; | std::vector<WalletModel *> m_wallets; | ||||
std::unique_ptr<interfaces::Handler> m_handler_load_wallet; | std::unique_ptr<interfaces::Handler> m_handler_load_wallet; | ||||
friend class OpenWalletActivity; | |||||
}; | |||||
class OpenWalletActivity : public QObject { | |||||
Q_OBJECT | |||||
public: | |||||
OpenWalletActivity(WalletController *wallet_controller, | |||||
const std::string &name, const CChainParams ¶ms); | |||||
public Q_SLOTS: | |||||
void open(); | |||||
Q_SIGNALS: | |||||
void message(QMessageBox::Icon icon, const QString text); | |||||
void finished(); | |||||
void opened(WalletModel *wallet_model); | |||||
private: | |||||
WalletController *const m_wallet_controller; | |||||
std::string const m_name; | |||||
const CChainParams &m_chain_params; | |||||
}; | }; | ||||
#endif // BITCOIN_QT_WALLETCONTROLLER_H | #endif // BITCOIN_QT_WALLETCONTROLLER_H |