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