Bitcoin Core 28.99.0
P2P Digital Currency
createwalletdialog.cpp
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#include <bitcoin-build-config.h> // IWYU pragma: keep
6
7#include <interfaces/node.h>
9#include <qt/forms/ui_createwalletdialog.h>
10
11#include <qt/guiutil.h>
12
13#include <QPushButton>
14
16 QDialog(parent, GUIUtil::dialog_flags),
17 ui(new Ui::CreateWalletDialog)
18{
19 ui->setupUi(this);
20 ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Create"));
21 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
22 ui->wallet_name_line_edit->setFocus(Qt::ActiveWindowFocusReason);
23
24 connect(ui->wallet_name_line_edit, &QLineEdit::textEdited, [this](const QString& text) {
25 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!text.isEmpty());
26 });
27
28 connect(ui->encrypt_wallet_checkbox, &QCheckBox::toggled, [this](bool checked) {
29 // Disable the disable_privkeys_checkbox and external_signer_checkbox when isEncryptWalletChecked is
30 // set to true, enable it when isEncryptWalletChecked is false.
31 ui->disable_privkeys_checkbox->setEnabled(!checked);
32#ifdef ENABLE_EXTERNAL_SIGNER
33 ui->external_signer_checkbox->setEnabled(m_has_signers && !checked);
34#endif
35 // When the disable_privkeys_checkbox is disabled, uncheck it.
36 if (!ui->disable_privkeys_checkbox->isEnabled()) {
37 ui->disable_privkeys_checkbox->setChecked(false);
38 }
39
40 // When the external_signer_checkbox box is disabled, uncheck it.
41 if (!ui->external_signer_checkbox->isEnabled()) {
42 ui->external_signer_checkbox->setChecked(false);
43 }
44
45 });
46
47 connect(ui->external_signer_checkbox, &QCheckBox::toggled, [this](bool checked) {
48 ui->encrypt_wallet_checkbox->setEnabled(!checked);
49 ui->blank_wallet_checkbox->setEnabled(!checked);
50 ui->disable_privkeys_checkbox->setEnabled(!checked);
51
52 // The external signer checkbox is only enabled when a device is detected.
53 // In that case it is checked by default. Toggling it restores the other
54 // options to their default.
55 ui->encrypt_wallet_checkbox->setChecked(false);
56 ui->disable_privkeys_checkbox->setChecked(checked);
57 ui->blank_wallet_checkbox->setChecked(false);
58 });
59
60 connect(ui->disable_privkeys_checkbox, &QCheckBox::toggled, [this](bool checked) {
61 // Disable the encrypt_wallet_checkbox when isDisablePrivateKeysChecked is
62 // set to true, enable it when isDisablePrivateKeysChecked is false.
63 ui->encrypt_wallet_checkbox->setEnabled(!checked);
64
65 // Wallets without private keys cannot set blank
66 ui->blank_wallet_checkbox->setEnabled(!checked);
67 if (checked) {
68 ui->blank_wallet_checkbox->setChecked(false);
69 }
70
71 // When the encrypt_wallet_checkbox is disabled, uncheck it.
72 if (!ui->encrypt_wallet_checkbox->isEnabled()) {
73 ui->encrypt_wallet_checkbox->setChecked(false);
74 }
75 });
76
77 connect(ui->blank_wallet_checkbox, &QCheckBox::toggled, [this](bool checked) {
78 // Disable the disable_privkeys_checkbox when blank_wallet_checkbox is checked
79 // as blank-ness only pertains to wallets with private keys.
80 ui->disable_privkeys_checkbox->setEnabled(!checked);
81 if (checked) {
82 ui->disable_privkeys_checkbox->setChecked(false);
83 }
84 });
85
86#ifndef ENABLE_EXTERNAL_SIGNER
87 //: "External signing" means using devices such as hardware wallets.
88 ui->external_signer_checkbox->setToolTip(tr("Compiled without external signing support (required for external signing)"));
89 ui->external_signer_checkbox->setEnabled(false);
90 ui->external_signer_checkbox->setChecked(false);
91#endif
92
93}
94
96{
97 delete ui;
98}
99
100void CreateWalletDialog::setSigners(const std::vector<std::unique_ptr<interfaces::ExternalSigner>>& signers)
101{
102 m_has_signers = !signers.empty();
103 if (m_has_signers) {
104 ui->external_signer_checkbox->setEnabled(true);
105 ui->external_signer_checkbox->setChecked(true);
106 ui->encrypt_wallet_checkbox->setEnabled(false);
107 ui->encrypt_wallet_checkbox->setChecked(false);
108 // The order matters, because connect() is called when toggling a checkbox:
109 ui->blank_wallet_checkbox->setEnabled(false);
110 ui->blank_wallet_checkbox->setChecked(false);
111 ui->disable_privkeys_checkbox->setEnabled(false);
112 ui->disable_privkeys_checkbox->setChecked(true);
113 const std::string label = signers[0]->getName();
114 ui->wallet_name_line_edit->setText(QString::fromStdString(label));
115 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
116 } else {
117 ui->external_signer_checkbox->setEnabled(false);
118 }
119}
120
122{
123 return ui->wallet_name_line_edit->text();
124}
125
127{
128 return ui->encrypt_wallet_checkbox->isChecked();
129}
130
132{
133 return ui->disable_privkeys_checkbox->isChecked();
134}
135
137{
138 return ui->blank_wallet_checkbox->isChecked();
139}
140
142{
143 return ui->external_signer_checkbox->isChecked();
144}
if(!SetupNetworking())
Dialog for creating wallets.
bool isMakeBlankWalletChecked() const
QString walletName() const
Ui::CreateWalletDialog * ui
bool isDisablePrivateKeysChecked() const
bool isEncryptWalletChecked() const
void setSigners(const std::vector< std::unique_ptr< interfaces::ExternalSigner > > &signers)
bool isExternalSignerChecked() const
CreateWalletDialog(QWidget *parent)
Utility functions used by the Bitcoin Qt UI.
Definition: bitcoingui.h:58
constexpr auto dialog_flags
Definition: guiutil.h:60