Bitcoin Core  0.20.99
P2P Digital Currency
walletcontroller.h
Go to the documentation of this file.
1 // Copyright (c) 2019-2020 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 
10 #include <sync.h>
11 #include <util/translation.h>
12 
13 #include <map>
14 #include <memory>
15 #include <string>
16 #include <vector>
17 
18 #include <QMessageBox>
19 #include <QMutex>
20 #include <QProgressDialog>
21 #include <QThread>
22 #include <QTimer>
23 #include <QString>
24 
25 class ClientModel;
26 class OptionsModel;
27 class PlatformStyle;
28 class WalletModel;
29 
30 namespace interfaces {
31 class Handler;
32 class Node;
33 class Wallet;
34 } // namespace interfaces
35 
38 class CreateWalletDialog;
39 class OpenWalletActivity;
41 
45 class WalletController : public QObject
46 {
47  Q_OBJECT
48 
49  void removeAndDeleteWallet(WalletModel* wallet_model);
50 
51 public:
52  WalletController(ClientModel& client_model, const PlatformStyle* platform_style, QObject* parent);
54 
56  std::vector<WalletModel*> getOpenWallets() const;
57 
58  WalletModel* getOrCreateWallet(std::unique_ptr<interfaces::Wallet> wallet);
59 
62  std::map<std::string, bool> listWalletDir() const;
63 
64  void closeWallet(WalletModel* wallet_model, QWidget* parent = nullptr);
65  void closeAllWallets(QWidget* parent = nullptr);
66 
67 Q_SIGNALS:
68  void walletAdded(WalletModel* wallet_model);
69  void walletRemoved(WalletModel* wallet_model);
70 
71  void coinsSent(WalletModel* wallet_model, SendCoinsRecipient recipient, QByteArray transaction);
72 
73 private:
74  QThread* const m_activity_thread;
75  QObject* const m_activity_worker;
80  mutable QMutex m_mutex;
81  std::vector<WalletModel*> m_wallets;
82  std::unique_ptr<interfaces::Handler> m_handler_load_wallet;
83 
85 };
86 
87 class WalletControllerActivity : public QObject
88 {
89  Q_OBJECT
90 
91 public:
92  WalletControllerActivity(WalletController* wallet_controller, QWidget* parent_widget);
93  virtual ~WalletControllerActivity();
94 
95 Q_SIGNALS:
96  void finished();
97 
98 protected:
99  interfaces::Node& node() const { return m_wallet_controller->m_node; }
100  QObject* worker() const { return m_wallet_controller->m_activity_worker; }
101 
102  void showProgressDialog(const QString& label_text);
103  void destroyProgressDialog();
104 
106  QWidget* const m_parent_widget;
107  QProgressDialog* m_progress_dialog{nullptr};
108  WalletModel* m_wallet_model{nullptr};
110  std::vector<bilingual_str> m_warning_message;
111 };
112 
113 
115 {
116  Q_OBJECT
117 
118 public:
119  CreateWalletActivity(WalletController* wallet_controller, QWidget* parent_widget);
120  virtual ~CreateWalletActivity();
121 
122  void create();
123 
124 Q_SIGNALS:
125  void created(WalletModel* wallet_model);
126 
127 private:
128  void askPassphrase();
129  void createWallet();
130  void finish();
131 
133  CreateWalletDialog* m_create_wallet_dialog{nullptr};
134  AskPassphraseDialog* m_passphrase_dialog{nullptr};
135 };
136 
138 {
139  Q_OBJECT
140 
141 public:
142  OpenWalletActivity(WalletController* wallet_controller, QWidget* parent_widget);
143 
144  void open(const std::string& path);
145 
146 Q_SIGNALS:
147  void opened(WalletModel* wallet_model);
148 
149 private:
150  void finish();
151 };
152 
153 #endif // BITCOIN_QT_WALLETCONTROLLER_H
std::vector< WalletModel * > m_wallets
interfaces::Node & node() const
Bilingual messages:
Definition: translation.h:16
const PlatformStyle *const m_platform_style
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:60
Controller between interfaces::Node, WalletModel instances and the GUI.
QObject *const m_activity_worker
QWidget *const m_parent_widget
std::vector< bilingual_str > m_warning_message
ClientModel & m_client_model
interfaces::Node & m_node
Model for Bitcoin network client.
Definition: clientmodel.h:46
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:39
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:51
Multifunctional dialog to ask for passphrases.
Dialog for creating wallets.
QObject * worker() const
QThread *const m_activity_thread
std::unique_ptr< interfaces::Handler > m_handler_load_wallet
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:52
OptionsModel *const m_options_model
WalletController *const m_wallet_controller