Bitcoin
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 <map>
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 
44  std::vector<WalletModel*> getOpenWallets() const;
45 
48  std::map<std::string, bool> listWalletDir() const;
49 
50  OpenWalletActivity* openWallet(const std::string& name, QWidget* parent = nullptr);
51  void closeWallet(WalletModel* wallet_model, QWidget* parent = nullptr);
52 
53 private Q_SLOTS:
54  void addWallet(WalletModel* wallet_model);
55 
56 Q_SIGNALS:
57  void walletAdded(WalletModel* wallet_model);
58  void walletRemoved(WalletModel* wallet_model);
59 
60  void coinsSent(WalletModel* wallet_model, SendCoinsRecipient recipient, QByteArray transaction);
61 
62 private:
67  mutable QMutex m_mutex;
68  std::vector<WalletModel*> m_wallets;
69  std::unique_ptr<interfaces::Handler> m_handler_load_wallet;
70 
71  friend class OpenWalletActivity;
72 };
73 
74 class OpenWalletActivity : public QObject
75 {
76  Q_OBJECT
77 
78 public:
79  OpenWalletActivity(WalletController* wallet_controller, const std::string& name);
80 
81 public Q_SLOTS:
82  void open();
83 
84 Q_SIGNALS:
85  void message(QMessageBox::Icon icon, const QString text);
86  void finished();
87  void opened(WalletModel* wallet_model);
88 
89 private:
91  std::string const m_name;
92 };
93 
94 #endif // BITCOIN_QT_WALLETCONTROLLER_H
OptionsModel *const m_options_model
Definition: walletcontroller.h:66
void walletRemoved(WalletModel *wallet_model)
Definition: moc_walletcontroller.cpp:204
void closeWallet(WalletModel *wallet_model, QWidget *parent=nullptr)
Definition: walletcontroller.cpp:70
void message(QMessageBox::Icon icon, const QString text)
Definition: moc_walletcontroller.cpp:368
Definition: walletmodel.h:125
Definition: optionsmodel.h:29
void finished()
Definition: moc_walletcontroller.cpp:375
OpenWalletActivity(WalletController *wallet_controller, const std::string &name)
Definition: walletcontroller.cpp:155
std::unique_ptr< interfaces::Handler > m_handler_load_wallet
Definition: walletcontroller.h:69
std::string const m_name
Definition: walletcontroller.h:91
void removeAndDeleteWallet(WalletModel *wallet_model)
Definition: walletcontroller.cpp:141
void walletAdded(WalletModel *wallet_model)
Definition: moc_walletcontroller.cpp:197
std::map< std::string, bool > listWalletDir() const
Definition: walletcontroller.cpp:49
Definition: walletcontroller.h:32
WalletModel * getOrCreateWallet(std::unique_ptr< interfaces::Wallet > wallet)
Definition: walletcontroller.cpp:86
OpenWalletActivity * openWallet(const std::string &name, QWidget *parent=nullptr)
Definition: walletcontroller.cpp:63
Definition: dummywallet.cpp:11
QThread m_activity_thread
Definition: walletcontroller.h:63
const char * name
Definition: rest.cpp:39
WalletController *const m_wallet_controller
Definition: walletcontroller.h:90
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:36
void open()
Definition: walletcontroller.cpp:160
const PlatformStyle *const m_platform_style
Definition: walletcontroller.h:65
std::vector< WalletModel * > getOpenWallets() const
Returns wallet models currently open.
Definition: walletcontroller.cpp:43
std::vector< WalletModel * > m_wallets
Definition: walletcontroller.h:68
void opened(WalletModel *wallet_model)
Definition: moc_walletcontroller.cpp:381
Definition: walletcontroller.h:74
void addWallet(WalletModel *wallet_model)
Definition: walletcontroller.cpp:134
Definition: platformstyle.h:13
void coinsSent(WalletModel *wallet_model, SendCoinsRecipient recipient, QByteArray transaction)
Definition: moc_walletcontroller.cpp:211
WalletController(interfaces::Node &node, const PlatformStyle *platform_style, OptionsModel *options_model, QObject *parent)
Definition: walletcontroller.cpp:18
interfaces::Node & m_node
Definition: walletcontroller.h:64
~WalletController()
Definition: walletcontroller.cpp:37
Definition: walletmodel.h:54
QMutex m_mutex
Definition: walletcontroller.h:67