25 #include <QApplication>
26 #include <QMessageBox>
27 #include <QMetaObject>
28 #include <QMutexLocker>
40 , m_activity_thread(new QThread(this))
41 , m_activity_worker(new QObject)
42 , m_client_model(client_model)
44 , m_platform_style(platform_style)
45 , m_options_model(client_model.getOptionsModel())
70 std::map<std::string, bool> wallets;
72 wallets[
name] =
false;
75 auto it = wallets.find(wallet_model->wallet().getWalletName());
76 if (it != wallets.end()) it->second =
true;
83 QMessageBox box(parent);
84 box.setWindowTitle(tr(
"Close wallet"));
86 box.setInformativeText(tr(
"Closing the wallet for too long can result in having to resync the entire chain if pruning is enabled."));
87 box.setStandardButtons(QMessageBox::Yes|QMessageBox::Cancel);
88 box.setDefaultButton(QMessageBox::Yes);
89 if (box.exec() != QMessageBox::Yes)
return;
99 QMessageBox::StandardButton button = QMessageBox::question(parent, tr(
"Close all wallets"),
100 tr(
"Are you sure you wish to close all wallets?"),
101 QMessageBox::Yes|QMessageBox::Cancel,
103 if (button != QMessageBox::Yes)
return;
107 wallet_model->wallet().remove();
122 if (wallet_model->wallet().getWalletName() ==
name) {
137 wallet_model->moveToThread(thread());
139 QMetaObject::invokeMethod(
this, [wallet_model,
this] {
140 wallet_model->setParent(
this);
148 const bool called = QMetaObject::invokeMethod(wallet_model,
"startPollBalance");
154 if (QApplication::activeModalWidget()) {
155 connect(qApp, &QApplication::focusWindowChanged, wallet_model, [
this, wallet_model]() {
156 if (!QApplication::activeModalWidget()) {
159 }, Qt::QueuedConnection);
163 }, Qt::QueuedConnection);
187 : QObject(wallet_controller)
188 , m_wallet_controller(wallet_controller)
189 , m_parent_widget(parent_widget)
197 progress_dialog->setAttribute(Qt::WA_DeleteOnClose);
200 progress_dialog->setWindowTitle(title_text);
201 progress_dialog->setLabelText(label_text);
202 progress_dialog->setRange(0, 0);
203 progress_dialog->setCancelButton(
nullptr);
204 progress_dialog->setWindowModality(Qt::ApplicationModal);
208 progress_dialog->setValue(0);
294 std::vector<std::unique_ptr<interfaces::ExternalSigner>> signers;
297 }
catch (
const std::runtime_error& e) {
298 QMessageBox::critical(
nullptr, tr(
"Can't list signers"), e.what());
300 if (signers.size() > 1) {
301 QMessageBox::critical(
nullptr, tr(
"Too many external signers found"), QString::fromStdString(
"More than one external signer found. Please connect only one at a time."));
344 QString
name = path.empty() ? QString(
"["+tr(
"default wallet")+
"]") : QString::fromStdString(path);
351 tr(
"Opening Wallet <b>%1</b>…").arg(
name.toHtmlEscaped()));
353 QTimer::singleShot(0,
worker(), [
this, path] {
378 tr(
"Loading wallets…"));
380 QTimer::singleShot(0,
worker(), [
this] {
381 for (
auto&
wallet :
node().walletLoader().getWallets()) {
385 QTimer::singleShot(0,
this, [
this] { Q_EMIT
finished(); });
396 QString
name = QString::fromStdString(wallet_name);
400 tr(
"Restore Wallet"),
403 tr(
"Restoring Wallet <b>%1</b>…").arg(
name.toHtmlEscaped()));
405 QTimer::singleShot(0,
worker(), [
this, backup_file, wallet_name] {
428 QMessageBox::information(
m_parent_widget, tr(
"Restore wallet message"), QString::fromStdString(
Untranslated(
"Wallet restored successfully \n").translated));
Multifunctional dialog to ask for passphrases.
@ Encrypt
Ask passphrase twice and encrypt.
Model for Bitcoin network client.
virtual ~CreateWalletActivity()
AskPassphraseDialog * m_passphrase_dialog
CreateWalletDialog * m_create_wallet_dialog
SecureString m_passphrase
CreateWalletActivity(WalletController *wallet_controller, QWidget *parent_widget)
void created(WalletModel *wallet_model)
Dialog for creating wallets.
bool isMakeBlankWalletChecked() const
QString walletName() const
bool isDisablePrivateKeysChecked() const
void setSigners(const std::vector< std::unique_ptr< interfaces::ExternalSigner >> &signers)
bool isEncryptWalletChecked() const
bool isDescriptorWalletChecked() const
bool isExternalSignerChecked() const
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)
void restore(const fs::path &backup_file, const std::string &wallet_name)
void restored(WalletModel *wallet_model)
RestoreWalletActivity(WalletController *wallet_controller, QWidget *parent_widget)
WalletModel * m_wallet_model
std::vector< bilingual_str > m_warning_message
WalletController *const m_wallet_controller
interfaces::Node & node() const
void showProgressDialog(const QString &title_text, const QString &label_text)
bilingual_str m_error_message
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)
std::vector< WalletModel * > m_wallets
Interface to Bitcoin wallet from Qt view code.
interfaces::Wallet & wallet() const
void coinsSent(WalletModel *wallet, SendCoinsRecipient recipient, QByteArray transaction)
QString getDisplayName() const
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
virtual std::vector< std::unique_ptr< ExternalSigner > > listExternalSigners()=0
Return list of external signers (attached devices which can sign transactions).
virtual WalletLoader & walletLoader()=0
Get wallet loader.
virtual util::Result< std::unique_ptr< Wallet > > createWallet(const std::string &name, const SecureString &passphrase, uint64_t wallet_creation_flags, std::vector< bilingual_str > &warnings)=0
Create new wallet.
virtual std::vector< std::string > listWalletDir()=0
Return available wallets in wallet directory.
virtual util::Result< std::unique_ptr< Wallet > > loadWallet(const std::string &name, std::vector< bilingual_str > &warnings)=0
Load existing wallet.
virtual util::Result< std::unique_ptr< Wallet > > restoreWallet(const fs::path &backup_file, const std::string &wallet_name, std::vector< bilingual_str > &warnings)=0
Restore backup wallet.
virtual std::unique_ptr< Handler > handleLoadWallet(LoadWalletFn fn)=0
static const int MAX_PASSPHRASE_SIZE
Qt::ConnectionType blockingGUIThreadConnection()
Get connection type to call object slot in GUI thread with invokeMethod.
QString HtmlEscape(const QString &str, bool fMultiLine)
void PolishProgressDialog(QProgressDialog *dialog)
bilingual_str ErrorString(const Result< T > &result)
void ThreadRename(std::string &&)
Rename a thread both in terms of an internal (in-memory) name as well as its system thread name.
@ WALLET_FLAG_EXTERNAL_SIGNER
Indicates that the wallet needs an external signer.
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
@ WALLET_FLAG_BLANK_WALLET
Flag set when a wallet contains no HD seed and no private keys, scripts, addresses,...
auto Join(const C &container, const S &separator, UnaryOp unary_op)
Join all container items.
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.