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;
Secret lastSecret;
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 = [&](){
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 = [&](){
lastAddress.clear();
string as = u.address->text().toStdString();
try
{
u.addressOut->setText(QString::fromStdString(main()->render(eth::toAddress(as))));
lastAddress = eth::toAddress(as);
u.addressOut->setText(QString::fromStdString(main()->render(lastAddress)));
}
catch (...)
{
@ -75,6 +103,7 @@ void ImportKey::import()
auto updatePassword = [&](){
u.passwordHash->setText(QString::fromStdString(sha3(u.password->text().toStdString()).hex()));
updateAction();
};
function<void()> updateKey = [&](){
@ -116,9 +145,12 @@ void ImportKey::import()
u.oldPassword->setEnabled(!!lastSecret);
u.newPassword->setEnabled(!!lastSecret);
u.noPassword->setEnabled(!!lastSecret);
u.masterLabel->setEnabled(!!lastSecret);
u.oldLabel->setEnabled(!!lastSecret);
u.showPassword->setEnabled(!!lastSecret);
u.password->setEnabled(!!lastSecret);
u.passwordHash->setReadOnly(!!lastSecret);
u.address->setReadOnly(!lastSecret);
u.address->setReadOnly(!!lastSecret);
if (lastSecret)
{
u.oldPassword->setEnabled(!lastPassword.empty());
@ -129,15 +161,18 @@ void ImportKey::import()
}
else
u.address->clear();
updateImport();
};
connect(u.noPassword, &QRadioButton::clicked, [&](){
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, [&](){
u.passwordHash->setText(QString::fromStdString(sha3(lastPassword).hex()));
u.hint->setText("Same as original password for file " + QString::fromStdString(lastKey));
updateAction();
});
connect(u.newPassword, &QRadioButton::clicked, [&](){
u.hint->setText("");
@ -147,6 +182,7 @@ void ImportKey::import()
connect(u.address, &QLineEdit::textChanged, [&](){ updateAddress(); });
connect(u.key, &QLineEdit::textEdited, [&](){ updateKey(); });
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, [&](){
QString fn = QFileDialog::getOpenFileName(main(), "Open Key File", QDir::homePath(), "JSON Files (*.json);;All Files (*)");
if (!fn.isEmpty())
@ -158,23 +194,28 @@ void ImportKey::import()
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();
h256 ph;
DEV_IGNORE_EXCEPTIONS(ph = h256(u.passwordHash->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
if (lastKey.empty() && !lastSecret)
main()->keyManager().importExistingBrain(a, n, h);
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);
else if (mp)
main()->keyManager().import(lastSecret, n);
}
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();
}

132
alethzero/plugins/keys/ImportKey.ui

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

Loading…
Cancel
Save