Bitcoin Core  0.18.99
P2P Digital Currency
walletcontroller.h
Go to the documentation of this file.
1 // Copyright (c) 2019 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_QT_WALLETCONTROLLER_H
6 #define BITCOIN_QT_WALLETCONTROLLER_H
7 
8 #include <qt/walletmodel.h>
9 #include <sync.h>
10 
11 #include <list>
12 #include <memory>
13 #include <vector>
14 
15 #include <QMessageBox>
16 #include <QMutex>
17 #include <QThread>
18 
19 class OptionsModel;
20 class PlatformStyle;
21 
22 namespace interfaces {
23 class Handler;
24 class Node;
25 } // namespace interfaces
26 
27 class OpenWalletActivity;
28 
32 class WalletController : public QObject
33 {
34  Q_OBJECT
35 
36  WalletModel* getOrCreateWallet(std::unique_ptr<interfaces::Wallet> wallet);
37  void removeAndDeleteWallet(WalletModel* wallet_model);
38 
39 public:
40  WalletController(interfaces::Node& node, const PlatformStyle* platform_style, OptionsModel* options_model, QObject* parent);
42 
43  std::vector<WalletModel*> getWallets() const;
44  std::vector<std::string> getWalletsAvailableToOpen() const;
45 
46  OpenWalletActivity* openWallet(const std::string& name, QWidget* parent = nullptr);
47  void closeWallet(WalletModel* wallet_model, QWidget* parent = nullptr);
48 
49 private Q_SLOTS:
50  void addWallet(WalletModel* wallet_model);
51 
52 Q_SIGNALS:
53  void walletAdded(WalletModel* wallet_model);
54  void walletRemoved(WalletModel* wallet_model);
55 
56  void coinsSent(WalletModel* wallet_model, SendCoinsRecipient recipient, QByteArray transaction);
57 
58 private:
63  mutable QMutex m_mutex;
64  std::vector<WalletModel*> m_wallets;
65  std::unique_ptr<interfaces::Handler> m_handler_load_wallet;
66 
67  friend class OpenWalletActivity;
68 };
69 
70 class OpenWalletActivity : public QObject
71 {
72  Q_OBJECT
73 
74 public:
75  OpenWalletActivity(WalletController* wallet_controller, const std::string& name);
76 
77 public Q_SLOTS:
78  void open();
79 
80 Q_SIGNALS:
81  void message(QMessageBox::Icon icon, const QString text);
82  void finished();
83  void opened(WalletModel* wallet_model);
84 
85 private:
87  std::string const m_name;
88 };
89 
90 #endif // BITCOIN_QT_WALLETCONTROLLER_H
std::vector< WalletModel * > m_wallets
std::string const m_name
const PlatformStyle *const m_platform_style
Controller between interfaces::Node, WalletModel instances and the GUI.
const char * name
Definition: rest.cpp:38
interfaces::Node & m_node
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:29
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:125
std::unique_ptr< interfaces::Handler > m_handler_load_wallet
WalletController *const m_wallet_controller
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:36
OptionsModel *const m_options_model