Bitcoin Core 28.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
25class ClientModel;
26class OptionsModel;
27class PlatformStyle;
28class WalletModel;
29
30namespace interfaces {
31class Handler;
32class Node;
33class Wallet;
34} // namespace interfaces
35
36namespace fs {
37class path;
38}
39
46
50class WalletController : public QObject
51{
52 Q_OBJECT
53
54 void removeAndDeleteWallet(WalletModel* wallet_model);
55
56public:
57 WalletController(ClientModel& client_model, const PlatformStyle* platform_style, QObject* parent);
59
60 WalletModel* getOrCreateWallet(std::unique_ptr<interfaces::Wallet> wallet);
61
64 std::map<std::string, std::pair<bool, std::string>> listWalletDir() const;
65
66 void closeWallet(WalletModel* wallet_model, QWidget* parent = nullptr);
67 void closeAllWallets(QWidget* parent = nullptr);
68
69Q_SIGNALS:
70 void walletAdded(WalletModel* wallet_model);
71 void walletRemoved(WalletModel* wallet_model);
72
73 void coinsSent(WalletModel* wallet_model, SendCoinsRecipient recipient, QByteArray transaction);
74
75private:
76 QThread* const m_activity_thread;
77 QObject* const m_activity_worker;
82 mutable QMutex m_mutex;
83 std::vector<WalletModel*> m_wallets;
84 std::unique_ptr<interfaces::Handler> m_handler_load_wallet;
85
88
90 void removeWallet(WalletModel* wallet_model);
91};
92
93class WalletControllerActivity : public QObject
94{
95 Q_OBJECT
96
97public:
98 WalletControllerActivity(WalletController* wallet_controller, QWidget* parent_widget);
99 virtual ~WalletControllerActivity() = default;
100
101Q_SIGNALS:
102 void finished();
103
104protected:
106 QObject* worker() const { return m_wallet_controller->m_activity_worker; }
107
108 void showProgressDialog(const QString& title_text, const QString& label_text, bool show_minimized=false);
109
111 QWidget* const m_parent_widget;
114 std::vector<bilingual_str> m_warning_message;
115};
116
117
119{
120 Q_OBJECT
121
122public:
123 CreateWalletActivity(WalletController* wallet_controller, QWidget* parent_widget);
124 virtual ~CreateWalletActivity();
125
126 void create();
127
128Q_SIGNALS:
129 void created(WalletModel* wallet_model);
130
131private:
132 void askPassphrase();
133 void createWallet();
134 void finish();
135
139};
140
142{
143 Q_OBJECT
144
145public:
146 OpenWalletActivity(WalletController* wallet_controller, QWidget* parent_widget);
147
148 void open(const std::string& path);
149
150Q_SIGNALS:
151 void opened(WalletModel* wallet_model);
152
153private:
154 void finish();
155};
156
158{
159 Q_OBJECT
160
161public:
162 LoadWalletsActivity(WalletController* wallet_controller, QWidget* parent_widget);
163
164 void load(bool show_loading_minimized);
165};
166
168{
169 Q_OBJECT
170
171public:
172 RestoreWalletActivity(WalletController* wallet_controller, QWidget* parent_widget);
173
174 void restore(const fs::path& backup_file, const std::string& wallet_name);
175
176Q_SIGNALS:
177 void restored(WalletModel* wallet_model);
178
179private:
180 void finish();
181};
182
184{
185 Q_OBJECT
186
187public:
188 MigrateWalletActivity(WalletController* wallet_controller, QWidget* parent) : WalletControllerActivity(wallet_controller, parent) {}
189
190 void migrate(const std::string& path);
191
192Q_SIGNALS:
193 void migrated(WalletModel* wallet_model);
194
195private:
197
198 void finish();
199};
200
201#endif // BITCOIN_QT_WALLETCONTROLLER_H
Multifunctional dialog to ask for passphrases.
Model for Bitcoin network client.
Definition: clientmodel.h:57
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.
void load(bool show_loading_minimized)
LoadWalletsActivity(WalletController *wallet_controller, QWidget *parent_widget)
MigrateWalletActivity(WalletController *wallet_controller, QWidget *parent)
void migrated(WalletModel *wallet_model)
void migrate(const std::string &path)
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:43
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
WalletController *const m_wallet_controller
interfaces::Node & node() const
QObject * worker() const
void showProgressDialog(const QString &title_text, const QString &label_text, bool show_minimized=false)
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
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::map< std::string, std::pair< bool, std::string > > listWalletDir() const
Returns all wallet names in the wallet dir mapped to whether the wallet is loaded.
void removeWallet(WalletModel *wallet_model)
Starts the wallet closure procedure.
std::vector< WalletModel * > m_wallets
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:48
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:33
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:71
Filesystem operations and types.
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:58
Bilingual messages:
Definition: translation.h:21