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