Bitcoin Core  24.99.0
P2P Digital Currency
walletcontroller.h
Go to the documentation of this file.
1 // Copyright (c) 2019-2021 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 
36 namespace fs {
37 class path;
38 }
39 
42 class CreateWalletDialog;
43 class OpenWalletActivity;
45 
49 class WalletController : public QObject
50 {
51  Q_OBJECT
52 
53  void removeAndDeleteWallet(WalletModel* wallet_model);
54 
55 public:
56  WalletController(ClientModel& client_model, const PlatformStyle* platform_style, QObject* parent);
58 
59  WalletModel* getOrCreateWallet(std::unique_ptr<interfaces::Wallet> wallet);
60 
63  std::map<std::string, bool> listWalletDir() const;
64 
65  void closeWallet(WalletModel* wallet_model, QWidget* parent = nullptr);
66  void closeAllWallets(QWidget* parent = nullptr);
67 
68 Q_SIGNALS:
69  void walletAdded(WalletModel* wallet_model);
70  void walletRemoved(WalletModel* wallet_model);
71 
72  void coinsSent(WalletModel* wallet_model, SendCoinsRecipient recipient, QByteArray transaction);
73 
74 private:
75  QThread* const m_activity_thread;
76  QObject* const m_activity_worker;
81  mutable QMutex m_mutex;
82  std::vector<WalletModel*> m_wallets;
83  std::unique_ptr<interfaces::Handler> m_handler_load_wallet;
84 
86 };
87 
88 class WalletControllerActivity : public QObject
89 {
90  Q_OBJECT
91 
92 public:
93  WalletControllerActivity(WalletController* wallet_controller, QWidget* parent_widget);
94  virtual ~WalletControllerActivity() = default;
95 
96 Q_SIGNALS:
97  void finished();
98 
99 protected:
101  QObject* worker() const { return m_wallet_controller->m_activity_worker; }
102 
103  void showProgressDialog(const QString& title_text, const QString& label_text);
104 
106  QWidget* const m_parent_widget;
109  std::vector<bilingual_str> m_warning_message;
110 };
111 
112 
114 {
115  Q_OBJECT
116 
117 public:
118  CreateWalletActivity(WalletController* wallet_controller, QWidget* parent_widget);
119  virtual ~CreateWalletActivity();
120 
121  void create();
122 
123 Q_SIGNALS:
124  void created(WalletModel* wallet_model);
125 
126 private:
127  void askPassphrase();
128  void createWallet();
129  void finish();
130 
134 };
135 
137 {
138  Q_OBJECT
139 
140 public:
141  OpenWalletActivity(WalletController* wallet_controller, QWidget* parent_widget);
142 
143  void open(const std::string& path);
144 
145 Q_SIGNALS:
146  void opened(WalletModel* wallet_model);
147 
148 private:
149  void finish();
150 };
151 
153 {
154  Q_OBJECT
155 
156 public:
157  LoadWalletsActivity(WalletController* wallet_controller, QWidget* parent_widget);
158 
159  void load();
160 };
161 
163 {
164  Q_OBJECT
165 
166 public:
167  RestoreWalletActivity(WalletController* wallet_controller, QWidget* parent_widget);
168 
169  void restore(const fs::path& backup_file, const std::string& wallet_name);
170 
171 Q_SIGNALS:
172  void restored(WalletModel* wallet_model);
173 
174 private:
175  void finish();
176 };
177 
178 #endif // BITCOIN_QT_WALLETCONTROLLER_H
Multifunctional dialog to ask for passphrases.
Model for Bitcoin network client.
Definition: clientmodel.h:54
AskPassphraseDialog * m_passphrase_dialog
CreateWalletDialog * m_create_wallet_dialog
CreateWalletActivity(WalletController *wallet_controller, QWidget *parent_widget)
void created(WalletModel *wallet_model)
Dialog for creating wallets.
LoadWalletsActivity(WalletController *wallet_controller, QWidget *parent_widget)
void opened(WalletModel *wallet_model)
OpenWalletActivity(WalletController *wallet_controller, QWidget *parent_widget)
void open(const std::string &path)
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:41
void restore(const fs::path &backup_file, const std::string &wallet_name)
void restored(WalletModel *wallet_model)
RestoreWalletActivity(WalletController *wallet_controller, QWidget *parent_widget)
std::vector< bilingual_str > m_warning_message
QObject * worker() const
WalletController *const m_wallet_controller
interfaces::Node & node() const
void showProgressDialog(const QString &title_text, const QString &label_text)
virtual ~WalletControllerActivity()=default
WalletControllerActivity(WalletController *wallet_controller, QWidget *parent_widget)
QWidget *const m_parent_widget
Controller between interfaces::Node, WalletModel instances and the GUI.
WalletController(ClientModel &client_model, const PlatformStyle *platform_style, QObject *parent)
WalletModel * getOrCreateWallet(std::unique_ptr< interfaces::Wallet > wallet)
ClientModel & m_client_model
void removeAndDeleteWallet(WalletModel *wallet_model)
void walletAdded(WalletModel *wallet_model)
void closeAllWallets(QWidget *parent=nullptr)
std::unique_ptr< interfaces::Handler > m_handler_load_wallet
QThread *const m_activity_thread
std::map< std::string, bool > listWalletDir() const
Returns all wallet names in the wallet dir mapped to whether the wallet is loaded.
void coinsSent(WalletModel *wallet_model, SendCoinsRecipient recipient, QByteArray transaction)
QObject *const m_activity_worker
void walletRemoved(WalletModel *wallet_model)
const PlatformStyle *const m_platform_style
interfaces::Node & m_node
void closeWallet(WalletModel *wallet_model, QWidget *parent=nullptr)
OptionsModel *const m_options_model
std::vector< WalletModel * > m_wallets
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:53
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:31
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:70
Filesystem operations and types.
Definition: fs.h:20
Definition: node.h:39
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:60
Bilingual messages:
Definition: translation.h:18