Browse Source

Fixes for new import dialog.

cl-refactor
Gav Wood 10 years ago
parent
commit
d5776ef0b4
  1. 65
      alethzero/plugins/keys/ImportKey.cpp
  2. 132
      alethzero/plugins/keys/ImportKey.ui

65
alethzero/plugins/keys/ImportKey.cpp

@ -55,16 +55,44 @@ void ImportKey::import()
string lastKey; string lastKey;
Secret lastSecret; Secret lastSecret;
string lastPassword; string lastPassword;
Address lastAddress;
auto updateAction = [&](){
if (!u.import_2->isEnabled())
u.action->clear();
else if (lastKey.empty() && !lastSecret)
u.action->setText("Import brainwallet with given address and hint");
else if (!lastKey.empty() && !lastSecret)
{
h256 ph;
DEV_IGNORE_EXCEPTIONS(ph = h256(u.passwordHash->text().toStdString()));
if (ph)
u.action->setText("Import untouched key with given address and hint");
else
u.action->setText("Import untouched key with given address, password hash and hint");
}
else
{
bool mp = u.noPassword->isChecked();
if (mp)
u.action->setText("Import recast key using master password and given hint");
else
u.action->setText("Import recast key with given password and hint");
}
};
auto updateImport = [&](){ auto updateImport = [&](){
u.import_2->setDisabled(u.addressOut->text().isEmpty() || u.name->text().isEmpty()); u.import_2->setDisabled(u.addressOut->text().isEmpty() || u.name->text().isEmpty() || !(u.oldPassword->isChecked() || u.newPassword->isChecked() || u.noPassword->isChecked()));
updateAction();
}; };
auto updateAddress = [&](){ auto updateAddress = [&](){
lastAddress.clear();
string as = u.address->text().toStdString(); string as = u.address->text().toStdString();
try try
{ {
u.addressOut->setText(QString::fromStdString(main()->render(eth::toAddress(as)))); lastAddress = eth::toAddress(as);
u.addressOut->setText(QString::fromStdString(main()->render(lastAddress)));
} }
catch (...) catch (...)
{ {
@ -75,6 +103,7 @@ void ImportKey::import()
auto updatePassword = [&](){ auto updatePassword = [&](){
u.passwordHash->setText(QString::fromStdString(sha3(u.password->text().toStdString()).hex())); u.passwordHash->setText(QString::fromStdString(sha3(u.password->text().toStdString()).hex()));
updateAction();
}; };
function<void()> updateKey = [&](){ function<void()> updateKey = [&](){
@ -116,9 +145,12 @@ void ImportKey::import()
u.oldPassword->setEnabled(!!lastSecret); u.oldPassword->setEnabled(!!lastSecret);
u.newPassword->setEnabled(!!lastSecret); u.newPassword->setEnabled(!!lastSecret);
u.noPassword->setEnabled(!!lastSecret); u.noPassword->setEnabled(!!lastSecret);
u.masterLabel->setEnabled(!!lastSecret);
u.oldLabel->setEnabled(!!lastSecret);
u.showPassword->setEnabled(!!lastSecret);
u.password->setEnabled(!!lastSecret); u.password->setEnabled(!!lastSecret);
u.passwordHash->setReadOnly(!!lastSecret); u.passwordHash->setReadOnly(!!lastSecret);
u.address->setReadOnly(!lastSecret); u.address->setReadOnly(!!lastSecret);
if (lastSecret) if (lastSecret)
{ {
u.oldPassword->setEnabled(!lastPassword.empty()); u.oldPassword->setEnabled(!lastPassword.empty());
@ -129,15 +161,18 @@ void ImportKey::import()
} }
else else
u.address->clear(); u.address->clear();
updateImport();
}; };
connect(u.noPassword, &QRadioButton::clicked, [&](){ connect(u.noPassword, &QRadioButton::clicked, [&](){
u.passwordHash->clear(); u.passwordHash->clear();
u.hint->setText("Same as master password."); u.hint->setText("No additional password (same as master password).");
updateAction();
}); });
connect(u.oldPassword, &QRadioButton::clicked, [&](){ connect(u.oldPassword, &QRadioButton::clicked, [&](){
u.passwordHash->setText(QString::fromStdString(sha3(lastPassword).hex())); u.passwordHash->setText(QString::fromStdString(sha3(lastPassword).hex()));
u.hint->setText("Same as original password for file " + QString::fromStdString(lastKey)); u.hint->setText("Same as original password for file " + QString::fromStdString(lastKey));
updateAction();
}); });
connect(u.newPassword, &QRadioButton::clicked, [&](){ connect(u.newPassword, &QRadioButton::clicked, [&](){
u.hint->setText(""); u.hint->setText("");
@ -147,6 +182,7 @@ void ImportKey::import()
connect(u.address, &QLineEdit::textChanged, [&](){ updateAddress(); }); connect(u.address, &QLineEdit::textChanged, [&](){ updateAddress(); });
connect(u.key, &QLineEdit::textEdited, [&](){ updateKey(); }); connect(u.key, &QLineEdit::textEdited, [&](){ updateKey(); });
connect(u.name, &QLineEdit::textEdited, [&](){ updateImport(); }); connect(u.name, &QLineEdit::textEdited, [&](){ updateImport(); });
connect(u.showPassword, &QCheckBox::toggled, [&](bool show){ u.password->setEchoMode(show ? QLineEdit::Normal : QLineEdit::Password); });
connect(u.openKey, &QToolButton::clicked, [&](){ connect(u.openKey, &QToolButton::clicked, [&](){
QString fn = QFileDialog::getOpenFileName(main(), "Open Key File", QDir::homePath(), "JSON Files (*.json);;All Files (*)"); QString fn = QFileDialog::getOpenFileName(main(), "Open Key File", QDir::homePath(), "JSON Files (*.json);;All Files (*)");
if (!fn.isEmpty()) if (!fn.isEmpty())
@ -158,23 +194,28 @@ void ImportKey::import()
if (d.exec() == QDialog::Accepted) if (d.exec() == QDialog::Accepted)
{ {
Address a = ICAP::decoded(u.addressOut->text().toStdString()).direct(); Address a = ICAP::decoded(lastAddress).direct();
string n = u.name->text().toStdString(); string n = u.name->text().toStdString();
h256 ph;
DEV_IGNORE_EXCEPTIONS(ph = h256(u.passwordHash->text().toStdString()));
string h = u.hint->text().toStdString(); string h = u.hint->text().toStdString();
bool mp = u.noPassword->isChecked();
string p = mp ? string() : u.oldPassword ? lastPassword : u.password->text().toStdString();
// check for a brain wallet import // check for a brain wallet import
if (lastKey.empty() && !lastSecret) if (lastKey.empty() && !lastSecret)
main()->keyManager().importExistingBrain(a, n, h); main()->keyManager().importExistingBrain(a, n, h);
else if (!lastKey.empty() && !lastSecret) else if (!lastKey.empty() && !lastSecret)
{
h256 ph;
DEV_IGNORE_EXCEPTIONS(ph = h256(u.passwordHash->text().toStdString()));
main()->keyManager().importExisting(main()->keyManager().store().importKey(lastKey), n, a, ph, h); main()->keyManager().importExisting(main()->keyManager().store().importKey(lastKey), n, a, ph, h);
else if (mp) }
main()->keyManager().import(lastSecret, n);
else else
main()->keyManager().import(lastSecret, n, p, h); {
bool mp = u.noPassword->isChecked();
string p = mp ? string() : u.oldPassword ? lastPassword : u.password->text().toStdString();
if (mp)
main()->keyManager().import(lastSecret, n);
else
main()->keyManager().import(lastSecret, n, p, h);
}
main()->noteKeysChanged(); main()->noteKeysChanged();
} }

132
alethzero/plugins/keys/ImportKey.ui

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>575</width> <width>530</width>
<height>315</height> <height>389</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -16,20 +16,6 @@
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="1" column="2" colspan="2">
<widget class="QLineEdit" name="key">
<property name="placeholderText">
<string>Leave blank for a brain wallet</string>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QToolButton" name="openKey">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="10" column="2" colspan="3"> <item row="10" column="2" colspan="3">
<widget class="QLineEdit" name="passwordHash"> <widget class="QLineEdit" name="passwordHash">
<property name="readOnly"> <property name="readOnly">
@ -39,6 +25,9 @@
</item> </item>
<item row="8" column="3" colspan="2"> <item row="8" column="3" colspan="2">
<widget class="QCheckBox" name="showPassword"> <widget class="QCheckBox" name="showPassword">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text"> <property name="text">
<string>Show</string> <string>Show</string>
</property> </property>
@ -47,17 +36,27 @@
<item row="4" column="0" colspan="2"> <item row="4" column="0" colspan="2">
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_2">
<property name="text"> <property name="text">
<string>Address:</string> <string>&amp;Address:</string>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>address</cstring> <cstring>address</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="4">
<widget class="QToolButton" name="openKey">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="8" column="0" colspan="2"> <item row="8" column="0" colspan="2">
<widget class="QRadioButton" name="newPassword"> <widget class="QRadioButton" name="newPassword">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text"> <property name="text">
<string>New Password:</string> <string>New &amp;Password:</string>
</property> </property>
<attribute name="buttonGroup"> <attribute name="buttonGroup">
<string notr="true">buttonGroup</string> <string notr="true">buttonGroup</string>
@ -74,7 +73,7 @@
<item row="2" column="0" colspan="2"> <item row="2" column="0" colspan="2">
<widget class="QLabel" name="label_4"> <widget class="QLabel" name="label_4">
<property name="text"> <property name="text">
<string>Name:</string> <string>&amp;Name:</string>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>name</cstring> <cstring>name</cstring>
@ -83,8 +82,11 @@
</item> </item>
<item row="6" column="0" colspan="2"> <item row="6" column="0" colspan="2">
<widget class="QRadioButton" name="noPassword"> <widget class="QRadioButton" name="noPassword">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text"> <property name="text">
<string>Master password</string> <string>&amp;Master password</string>
</property> </property>
<property name="checked"> <property name="checked">
<bool>true</bool> <bool>true</bool>
@ -103,7 +105,7 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="text"> <property name="text">
<string>Old password</string> <string>&amp;Old password</string>
</property> </property>
<attribute name="buttonGroup"> <attribute name="buttonGroup">
<string notr="true">buttonGroup</string> <string notr="true">buttonGroup</string>
@ -117,16 +119,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="5" column="2" colspan="3">
<widget class="QLineEdit" name="addressOut">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>Unknown Address</string>
</property>
</widget>
</item>
<item row="2" column="2" colspan="3"> <item row="2" column="2" colspan="3">
<widget class="QLineEdit" name="name"> <widget class="QLineEdit" name="name">
<property name="placeholderText"> <property name="placeholderText">
@ -137,7 +129,7 @@
<item row="10" column="0" colspan="2"> <item row="10" column="0" colspan="2">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_3">
<property name="text"> <property name="text">
<string>Password Hash:</string> <string>Password &amp;Hash:</string>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>passwordHash</cstring> <cstring>passwordHash</cstring>
@ -147,7 +139,7 @@
<item row="11" column="0" colspan="2"> <item row="11" column="0" colspan="2">
<widget class="QLabel" name="label_5"> <widget class="QLabel" name="label_5">
<property name="text"> <property name="text">
<string>Password Hint:</string> <string>Password Hin&amp;t:</string>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>hint</cstring> <cstring>hint</cstring>
@ -155,7 +147,10 @@
</widget> </widget>
</item> </item>
<item row="6" column="2" colspan="3"> <item row="6" column="2" colspan="3">
<widget class="QLabel" name="label_6"> <widget class="QLabel" name="masterLabel">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text"> <property name="text">
<string>Use same password for the key as for the master.</string> <string>Use same password for the key as for the master.</string>
</property> </property>
@ -164,10 +159,20 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0" colspan="2"> <item row="3" column="2" colspan="2">
<widget class="QLineEdit" name="key">
<property name="placeholderText">
<string>Brain wallet (no key file)</string>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
<string>Key:</string> <string>&amp;Key:</string>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>key</cstring> <cstring>key</cstring>
@ -175,12 +180,25 @@
</widget> </widget>
</item> </item>
<item row="7" column="2" colspan="3"> <item row="7" column="2" colspan="3">
<widget class="QLabel" name="label_7"> <widget class="QLabel" name="oldLabel">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text"> <property name="text">
<string>Use the same password as in the key file.</string> <string>Use the same password as in the key file.</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="5" column="2" colspan="3">
<widget class="QLineEdit" name="addressOut">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>Unknown Address</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item>
@ -198,6 +216,13 @@
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="action">
<property name="text">
<string/>
</property>
</widget>
</item>
<item> <item>
<spacer name="horizontalSpacer"> <spacer name="horizontalSpacer">
<property name="orientation"> <property name="orientation">
@ -216,6 +241,9 @@
<property name="text"> <property name="text">
<string>Cancel</string> <string>Cancel</string>
</property> </property>
<property name="shortcut">
<string>Esc</string>
</property>
</widget> </widget>
</item> </item>
<item> <item>
@ -236,8 +264,6 @@
</layout> </layout>
</widget> </widget>
<tabstops> <tabstops>
<tabstop>key</tabstop>
<tabstop>openKey</tabstop>
<tabstop>name</tabstop> <tabstop>name</tabstop>
<tabstop>address</tabstop> <tabstop>address</tabstop>
<tabstop>noPassword</tabstop> <tabstop>noPassword</tabstop>
@ -259,12 +285,12 @@
<slot>accept()</slot> <slot>accept()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>564</x> <x>519</x>
<y>304</y> <y>378</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>449</x> <x>449</x>
<y>504</y> <y>388</y>
</hint> </hint>
</hints> </hints>
</connection> </connection>
@ -275,12 +301,28 @@
<slot>reject()</slot> <slot>reject()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>478</x> <x>433</x>
<y>304</y> <y>378</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>351</x> <x>351</x>
<y>506</y> <y>388</y>
</hint>
</hints>
</connection>
<connection>
<sender>newPassword</sender>
<signal>pressed()</signal>
<receiver>password</receiver>
<slot>setFocus()</slot>
<hints>
<hint type="sourcelabel">
<x>80</x>
<y>211</y>
</hint>
<hint type="destinationlabel">
<x>185</x>
<y>215</y>
</hint> </hint>
</hints> </hints>
</connection> </connection>

Loading…
Cancel
Save