Bitcoin Core  22.99.0
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 
55  WalletModel* getOrCreateWallet(std::unique_ptr<interfaces::Wallet> wallet);
56 
59  std::map<std::string, bool> listWalletDir() const;
60 
61  void closeWallet(WalletModel* wallet_model, QWidget* parent = nullptr);
62  void closeAllWallets(QWidget* parent = nullptr);
63 
64 Q_SIGNALS:
65  void walletAdded(WalletModel* wallet_model);
66  void walletRemoved(WalletModel* wallet_model);
67 
68  void coinsSent(WalletModel* wallet_model, SendCoinsRecipient recipient, QByteArray transaction);
69 
70 private:
71  QThread* const m_activity_thread;
72  QObject* const m_activity_worker;
77  mutable QMutex m_mutex;
78  std::vector<WalletModel*> m_wallets;
79  std::unique_ptr<interfaces::Handler> m_handler_load_wallet;
80 
82 };
83 
84 class WalletControllerActivity : public QObject
85 {
86  Q_OBJECT
87 
88 public:
89  WalletControllerActivity(WalletController* wallet_controller, QWidget* parent_widget);
90  virtual ~WalletControllerActivity() = default;
91 
92 Q_SIGNALS:
93  void finished();
94 
95 protected:
97  QObject* worker() const { return m_wallet_controller->m_activity_worker; }
98 
99  void showProgressDialog(const QString& title_text, const QString& label_text);
100 
102  QWidget* const m_parent_widget;
105  std::vector<bilingual_str> m_warning_message;
106 };
107 
108 
110 {
111  Q_OBJECT
112 
113 public:
114  CreateWalletActivity(WalletController* wallet_controller, QWidget* parent_widget);
115  virtual ~CreateWalletActivity();
116 
117  void create();
118 
119 Q_SIGNALS:
120  void created(WalletModel* wallet_model);
121 
122 private:
123  void askPassphrase();
124  void createWallet();
125  void finish();
126 
130 };
131 
133 {
134  Q_OBJECT
135 
136 public:
137  OpenWalletActivity(WalletController* wallet_controller, QWidget* parent_widget);
138 
139  void open(const std::string& path);
140 
141 Q_SIGNALS:
142  void opened(WalletModel* wallet_model);
143 
144 private:
145  void finish();
146 };
147 
149 {
150  Q_OBJECT
151 
152 public:
153  LoadWalletsActivity(WalletController* wallet_controller, QWidget* parent_widget);
154 
155  void load();
156 };
157 
158 #endif // BITCOIN_QT_WALLETCONTROLLER_H
WalletController::walletRemoved
void walletRemoved(WalletModel *wallet_model)
interfaces
Definition: dummywallet.cpp:11
CreateWalletActivity::~CreateWalletActivity
virtual ~CreateWalletActivity()
Definition: walletcontroller.cpp:210
WalletController::m_handler_load_wallet
std::unique_ptr< interfaces::Handler > m_handler_load_wallet
Definition: walletcontroller.h:79
WalletControllerActivity::m_warning_message
std::vector< bilingual_str > m_warning_message
Definition: walletcontroller.h:105
WalletModel
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:51
WalletControllerActivity::finished
void finished()
WalletController::removeAndDeleteWallet
void removeAndDeleteWallet(WalletModel *wallet_model)
Definition: walletcontroller.cpp:166
CreateWalletActivity::CreateWalletActivity
CreateWalletActivity(WalletController *wallet_controller, QWidget *parent_widget)
Definition: walletcontroller.cpp:204
LoadWalletsActivity
Definition: walletcontroller.h:148
sync.h
WalletControllerActivity::worker
QObject * worker() const
Definition: walletcontroller.h:97
bilingual_str
Bilingual messages:
Definition: translation.h:16
WalletControllerActivity::m_error_message
bilingual_str m_error_message
Definition: walletcontroller.h:104
CreateWalletActivity::m_create_wallet_dialog
CreateWalletDialog * m_create_wallet_dialog
Definition: walletcontroller.h:128
AskPassphraseDialog
Multifunctional dialog to ask for passphrases.
Definition: askpassphrasedialog.h:20
WalletController::listWalletDir
std::map< std::string, bool > listWalletDir() const
Returns all wallet names in the wallet dir mapped to whether the wallet is loaded.
Definition: walletcontroller.cpp:60
WalletController::walletAdded
void walletAdded(WalletModel *wallet_model)
WalletController::m_wallets
std::vector< WalletModel * > m_wallets
Definition: walletcontroller.h:78
wallet
Definition: interfaces.cpp:50
WalletController::m_client_model
ClientModel & m_client_model
Definition: walletcontroller.h:73
OpenWalletActivity::OpenWalletActivity
OpenWalletActivity(WalletController *wallet_controller, QWidget *parent_widget)
Definition: walletcontroller.cpp:309
CreateWalletActivity::createWallet
void createWallet()
Definition: walletcontroller.cpp:233
OpenWalletActivity::finish
void finish()
Definition: walletcontroller.cpp:314
CreateWalletActivity::askPassphrase
void askPassphrase()
Definition: walletcontroller.cpp:216
OpenWalletActivity
Definition: walletcontroller.h:132
SendCoinsRecipient
Definition: sendcoinsrecipient.h:19
OptionsModel
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:38
SecureString
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:59
OpenWalletActivity::opened
void opened(WalletModel *wallet_model)
WalletControllerActivity::m_parent_widget
QWidget *const m_parent_widget
Definition: walletcontroller.h:102
CreateWalletActivity::m_passphrase
SecureString m_passphrase
Definition: walletcontroller.h:127
WalletControllerActivity::m_wallet_model
WalletModel * m_wallet_model
Definition: walletcontroller.h:103
WalletController::m_platform_style
const PlatformStyle *const m_platform_style
Definition: walletcontroller.h:75
WalletController
Controller between interfaces::Node, WalletModel instances and the GUI.
Definition: walletcontroller.h:45
CreateWalletActivity::created
void created(WalletModel *wallet_model)
WalletControllerActivity::showProgressDialog
void showProgressDialog(const QString &title_text, const QString &label_text)
Definition: walletcontroller.cpp:187
CreateWalletActivity
Definition: walletcontroller.h:109
WalletController::coinsSent
void coinsSent(WalletModel *wallet_model, SendCoinsRecipient recipient, QByteArray transaction)
WalletControllerActivity::node
interfaces::Node & node() const
Definition: walletcontroller.h:96
WalletController::getOrCreateWallet
WalletModel * getOrCreateWallet(std::unique_ptr< interfaces::Wallet > wallet)
Definition: walletcontroller.cpp:107
interfaces::Node
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:54
WalletController::~WalletController
~WalletController()
Definition: walletcontroller.cpp:53
secure.h
LoadWalletsActivity::load
void load()
Definition: walletcontroller.cpp:352
WalletControllerActivity::m_wallet_controller
WalletController *const m_wallet_controller
Definition: walletcontroller.h:101
ClientModel
Model for Bitcoin network client.
Definition: clientmodel.h:47
WalletController::closeWallet
void closeWallet(WalletModel *wallet_model, QWidget *parent=nullptr)
Definition: walletcontroller.cpp:74
CreateWalletActivity::m_passphrase_dialog
AskPassphraseDialog * m_passphrase_dialog
Definition: walletcontroller.h:129
CreateWalletActivity::finish
void finish()
Definition: walletcontroller.cpp:266
WalletController::m_options_model
OptionsModel *const m_options_model
Definition: walletcontroller.h:76
translation.h
CreateWalletDialog
Dialog for creating wallets.
Definition: createwalletdialog.h:19
WalletController::m_activity_worker
QObject *const m_activity_worker
Definition: walletcontroller.h:72
WalletController::WalletController
WalletController(ClientModel &client_model, const PlatformStyle *platform_style, QObject *parent)
Definition: walletcontroller.cpp:31
WalletController::m_node
interfaces::Node & m_node
Definition: walletcontroller.h:74
WalletControllerActivity::WalletControllerActivity
WalletControllerActivity(WalletController *wallet_controller, QWidget *parent_widget)
Definition: walletcontroller.cpp:179
WalletController::m_activity_thread
QThread *const m_activity_thread
Definition: walletcontroller.h:71
WalletController::m_mutex
QMutex m_mutex
Definition: walletcontroller.h:77
LoadWalletsActivity::LoadWalletsActivity
LoadWalletsActivity(WalletController *wallet_controller, QWidget *parent_widget)
Definition: walletcontroller.cpp:347
OpenWalletActivity::open
void open(const std::string &path)
Definition: walletcontroller.cpp:327
WalletControllerActivity::~WalletControllerActivity
virtual ~WalletControllerActivity()=default
PlatformStyle
Definition: platformstyle.h:13
WalletController::closeAllWallets
void closeAllWallets(QWidget *parent=nullptr)
Definition: walletcontroller.cpp:90
CreateWalletActivity::create
void create()
Definition: walletcontroller.cpp:279
sendcoinsrecipient.h
WalletControllerActivity
Definition: walletcontroller.h:84