Skip to content

Commit 78863e2

Browse files
achow101promag
andcommitted
Add CreateWalletDialog to create wallets from the GUI
Co-authored-by: João Barbosa <[email protected]>
1 parent 60adb21 commit 78863e2

File tree

5 files changed

+252
-0
lines changed

5 files changed

+252
-0
lines changed

contrib/bitcoin-qt.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ FORMS += \
1616
../src/qt/forms/sendcoinsentry.ui \
1717
../src/qt/forms/signverifymessagedialog.ui \
1818
../src/qt/forms/transactiondescdialog.ui \
19+
../src/qt/forms/createwalletdialog.ui
1920

2021
RESOURCES += \
2122
../src/qt/bitcoin.qrc

src/Makefile.qt.include

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ QT_FORMS_UI = \
9898
qt/forms/addressbookpage.ui \
9999
qt/forms/askpassphrasedialog.ui \
100100
qt/forms/coincontroldialog.ui \
101+
qt/forms/createwalletdialog.ui \
101102
qt/forms/editaddressdialog.ui \
102103
qt/forms/helpmessagedialog.ui \
103104
qt/forms/intro.ui \
@@ -117,6 +118,7 @@ QT_MOC_CPP = \
117118
qt/moc_addressbookpage.cpp \
118119
qt/moc_addresstablemodel.cpp \
119120
qt/moc_askpassphrasedialog.cpp \
121+
qt/moc_createwalletdialog.cpp \
120122
qt/moc_bantablemodel.cpp \
121123
qt/moc_bitcoinaddressvalidator.cpp \
122124
qt/moc_bitcoinamountfield.cpp \
@@ -202,6 +204,7 @@ BITCOIN_QT_H = \
202204
qt/clientmodel.h \
203205
qt/coincontroldialog.h \
204206
qt/coincontroltreewidget.h \
207+
qt/createwalletdialog.h \
205208
qt/csvmodelwriter.h \
206209
qt/editaddressdialog.h \
207210
qt/guiconstants.h \
@@ -328,6 +331,7 @@ BITCOIN_QT_WALLET_CPP = \
328331
qt/askpassphrasedialog.cpp \
329332
qt/coincontroldialog.cpp \
330333
qt/coincontroltreewidget.cpp \
334+
qt/createwalletdialog.cpp \
331335
qt/editaddressdialog.cpp \
332336
qt/openuridialog.cpp \
333337
qt/overviewpage.cpp \

src/qt/createwalletdialog.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
#if defined(HAVE_CONFIG_H)
6+
#include <config/bitcoin-config.h>
7+
#endif
8+
9+
#include <qt/createwalletdialog.h>
10+
#include <qt/forms/ui_createwalletdialog.h>
11+
12+
#include <QPushButton>
13+
14+
CreateWalletDialog::CreateWalletDialog(QWidget* parent) :
15+
QDialog(parent),
16+
ui(new Ui::CreateWalletDialog)
17+
{
18+
ui->setupUi(this);
19+
ui->buttonBox->button(QDialogButtonBox::Ok)->setText("Create");
20+
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
21+
ui->wallet_name_line_edit->setFocus(Qt::ActiveWindowFocusReason);
22+
23+
connect(ui->wallet_name_line_edit, &QLineEdit::textEdited, [this](const QString& text) {
24+
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!text.isEmpty());
25+
});
26+
27+
connect(ui->encrypt_wallet_checkbox, &QCheckBox::toggled, [this](bool checked) {
28+
// Disable disable_privkeys_checkbox when encrypt is set to true, enable it when encrypt is false
29+
ui->disable_privkeys_checkbox->setEnabled(!checked);
30+
31+
// When the disable_privkeys_checkbox is disabled, uncheck it.
32+
if (!ui->disable_privkeys_checkbox->isEnabled()) {
33+
ui->disable_privkeys_checkbox->setChecked(false);
34+
}
35+
});
36+
}
37+
38+
CreateWalletDialog::~CreateWalletDialog()
39+
{
40+
delete ui;
41+
}
42+
43+
QString CreateWalletDialog::walletName() const
44+
{
45+
return ui->wallet_name_line_edit->text();
46+
}
47+
48+
bool CreateWalletDialog::encrypt() const
49+
{
50+
return ui->encrypt_wallet_checkbox->isChecked();
51+
}
52+
53+
bool CreateWalletDialog::disablePrivateKeys() const
54+
{
55+
return ui->disable_privkeys_checkbox->isChecked();
56+
}
57+
58+
bool CreateWalletDialog::blank() const
59+
{
60+
return ui->blank_wallet_checkbox->isChecked();
61+
}

src/qt/createwalletdialog.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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_CREATEWALLETDIALOG_H
6+
#define BITCOIN_QT_CREATEWALLETDIALOG_H
7+
8+
#include <QDialog>
9+
10+
class WalletModel;
11+
12+
namespace Ui {
13+
class CreateWalletDialog;
14+
}
15+
16+
/** Dialog for creating wallets
17+
*/
18+
class CreateWalletDialog : public QDialog
19+
{
20+
Q_OBJECT
21+
22+
public:
23+
explicit CreateWalletDialog(QWidget* parent);
24+
virtual ~CreateWalletDialog();
25+
26+
QString walletName() const;
27+
bool encrypt() const;
28+
bool disablePrivateKeys() const;
29+
bool blank() const;
30+
31+
private:
32+
Ui::CreateWalletDialog *ui;
33+
};
34+
35+
#endif // BITCOIN_QT_CREATEWALLETDIALOG_H

src/qt/forms/createwalletdialog.ui

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>CreateWalletDialog</class>
4+
<widget class="QDialog" name="CreateWalletDialog">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>364</width>
10+
<height>185</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Create Wallet</string>
15+
</property>
16+
<widget class="QDialogButtonBox" name="buttonBox">
17+
<property name="geometry">
18+
<rect>
19+
<x>10</x>
20+
<y>140</y>
21+
<width>341</width>
22+
<height>32</height>
23+
</rect>
24+
</property>
25+
<property name="orientation">
26+
<enum>Qt::Horizontal</enum>
27+
</property>
28+
<property name="standardButtons">
29+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
30+
</property>
31+
</widget>
32+
<widget class="QLineEdit" name="wallet_name_line_edit">
33+
<property name="geometry">
34+
<rect>
35+
<x>120</x>
36+
<y>20</y>
37+
<width>231</width>
38+
<height>24</height>
39+
</rect>
40+
</property>
41+
</widget>
42+
<widget class="QLabel" name="label">
43+
<property name="geometry">
44+
<rect>
45+
<x>20</x>
46+
<y>20</y>
47+
<width>101</width>
48+
<height>21</height>
49+
</rect>
50+
</property>
51+
<property name="text">
52+
<string>Wallet Name</string>
53+
</property>
54+
</widget>
55+
<widget class="QCheckBox" name="encrypt_wallet_checkbox">
56+
<property name="geometry">
57+
<rect>
58+
<x>20</x>
59+
<y>50</y>
60+
<width>171</width>
61+
<height>22</height>
62+
</rect>
63+
</property>
64+
<property name="toolTip">
65+
<string>Encrypt the wallet. The wallet will be encrypted with a password of your choice.</string>
66+
</property>
67+
<property name="text">
68+
<string>Encrypt Wallet</string>
69+
</property>
70+
<property name="checked">
71+
<bool>true</bool>
72+
</property>
73+
</widget>
74+
<widget class="QCheckBox" name="disable_privkeys_checkbox">
75+
<property name="enabled">
76+
<bool>false</bool>
77+
</property>
78+
<property name="geometry">
79+
<rect>
80+
<x>20</x>
81+
<y>80</y>
82+
<width>171</width>
83+
<height>22</height>
84+
</rect>
85+
</property>
86+
<property name="toolTip">
87+
<string>Disable private keys for this wallet. Wallets with private keys disabled will have no private keys and cannot have an HD seed or imported private keys. This is ideal for watch-only wallets.</string>
88+
</property>
89+
<property name="text">
90+
<string>Disable Private Keys</string>
91+
</property>
92+
</widget>
93+
<widget class="QCheckBox" name="blank_wallet_checkbox">
94+
<property name="geometry">
95+
<rect>
96+
<x>20</x>
97+
<y>110</y>
98+
<width>171</width>
99+
<height>22</height>
100+
</rect>
101+
</property>
102+
<property name="toolTip">
103+
<string>Make a blank wallet. Blank wallets do not initially have private keys or scripts. Private keys and addresses can be imported, or an HD seed can be set, at a later time.</string>
104+
</property>
105+
<property name="text">
106+
<string>Make Blank Wallet</string>
107+
</property>
108+
</widget>
109+
</widget>
110+
<tabstops>
111+
<tabstop>wallet_name_line_edit</tabstop>
112+
<tabstop>encrypt_wallet_checkbox</tabstop>
113+
<tabstop>disable_privkeys_checkbox</tabstop>
114+
<tabstop>blank_wallet_checkbox</tabstop>
115+
</tabstops>
116+
<resources/>
117+
<connections>
118+
<connection>
119+
<sender>buttonBox</sender>
120+
<signal>accepted()</signal>
121+
<receiver>CreateWalletDialog</receiver>
122+
<slot>accept()</slot>
123+
<hints>
124+
<hint type="sourcelabel">
125+
<x>248</x>
126+
<y>254</y>
127+
</hint>
128+
<hint type="destinationlabel">
129+
<x>157</x>
130+
<y>274</y>
131+
</hint>
132+
</hints>
133+
</connection>
134+
<connection>
135+
<sender>buttonBox</sender>
136+
<signal>rejected()</signal>
137+
<receiver>CreateWalletDialog</receiver>
138+
<slot>reject()</slot>
139+
<hints>
140+
<hint type="sourcelabel">
141+
<x>316</x>
142+
<y>260</y>
143+
</hint>
144+
<hint type="destinationlabel">
145+
<x>286</x>
146+
<y>274</y>
147+
</hint>
148+
</hints>
149+
</connection>
150+
</connections>
151+
</ui>

0 commit comments

Comments
 (0)