1 #include "secondauthdialog.h"
2 #include "ui_secondauthdialog.h"
4 #include "addressbookpage.h"
7 #include "dialogwindowflags.h"
10 #include "optionsmodel.h"
11 #include "walletmodel.h"
20 SecondAuthDialog::SecondAuthDialog(QWidget *parent) :
21 QWidget(parent, DIALOGWINDOWHINTS),
22 ui(new Ui::SecondAuthDialog),
27 #if (QT_VERSION >= 0x040700)
28 /* Do not move this to the XML file, Qt before 4.7 will choke on it */
29 ui->addressIn->setPlaceholderText(tr("Enter a NovaCoin address (e.g. 4Zo1ga6xuKuQ7JV7M9rGDoxdbYwV5zgQJ5)"));
30 ui->signatureOut->setPlaceholderText(tr("Click \"Sign data\" to generate signature"));
33 GUIUtil::setupAddressWidget(ui->addressIn, this);
35 ui->addressIn->installEventFilter(this);
36 ui->messageIn->installEventFilter(this);
37 ui->signatureOut->installEventFilter(this);
39 ui->signatureOut->setFont(GUIUtil::bitcoinAddressFont());
42 SecondAuthDialog::~SecondAuthDialog()
47 void SecondAuthDialog::setModel(WalletModel *model)
52 void SecondAuthDialog::on_addressBookButton_clicked()
54 if (model && model->getAddressTableModel())
56 AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::ReceivingTab, this);
57 dlg.setModel(model->getAddressTableModel());
60 ui->addressIn->setText(dlg.getReturnValue());
65 void SecondAuthDialog::on_pasteButton_clicked()
67 ui->messageIn->setText(QApplication::clipboard()->text());
70 void SecondAuthDialog::on_signMessageButton_clicked()
72 /* Clear old signature to ensure users don't get confused on error with an old signature displayed */
73 ui->signatureOut->clear();
75 CBitcoinAddress addr(ui->addressIn->text().toStdString());
78 ui->addressIn->setValid(false);
79 ui->statusLabel->setStyleSheet("QLabel { color: red; }");
80 ui->statusLabel->setText(tr("The entered address is invalid.") + QString(" ") + tr("Please check the address and try again."));
85 if (!addr.GetKeyID(keyID))
87 ui->addressIn->setValid(false);
88 ui->statusLabel->setStyleSheet("QLabel { color: red; }");
89 ui->statusLabel->setText(tr("The entered address does not refer to a key.") + QString(" ") + tr("Please check the address and try again."));
93 WalletModel::UnlockContext ctx(model->requestUnlock());
96 ui->statusLabel->setStyleSheet("QLabel { color: red; }");
97 ui->statusLabel->setText(tr("Wallet unlock was cancelled."));
102 if (!pwalletMain->GetKey(keyID, key))
104 ui->statusLabel->setStyleSheet("QLabel { color: red; }");
105 ui->statusLabel->setText(tr("Private key for the entered address is not available."));
110 hash.SetHex(ui->messageIn->text().toStdString());
112 uint256 hashBlock = 0;
113 if (!GetTransaction(hash, tx, hashBlock) || !hashBlock) {
114 ui->statusLabel->setStyleSheet("QLabel { color: red; }");
115 ui->statusLabel->setText(tr("No information available about transaction."));
119 CDataStream ss(SER_GETHASH, 0);
120 ss << strMessageMagic;
121 ss << ui->messageIn->text().toStdString();
123 std::vector<unsigned char> vchSig;
124 if (!key.SignCompact(Hash(ss.begin(), ss.end()), vchSig))
126 ui->statusLabel->setStyleSheet("QLabel { color: red; }");
127 ui->statusLabel->setText(QString("<nobr>") + tr("Message signing failed.") + QString("</nobr>"));
131 ui->statusLabel->setStyleSheet("QLabel { color: green; }");
132 ui->statusLabel->setText(QString("<nobr>") + tr("Message signed.") + QString("</nobr>"));
134 ui->signatureOut->setText(QString::fromStdString(EncodeBase64(&vchSig[0], vchSig.size())));
137 void SecondAuthDialog::on_copySignatureButton_clicked()
139 QApplication::clipboard()->setText(ui->signatureOut->text());
142 void SecondAuthDialog::on_clearButton_clicked()
144 ui->addressIn->clear();
145 ui->messageIn->clear();
146 ui->signatureOut->clear();
147 ui->statusLabel->clear();
149 ui->addressIn->setFocus();
152 bool SecondAuthDialog::eventFilter(QObject *object, QEvent *event)
154 return QWidget::eventFilter(object, event);
157 void SecondAuthDialog::keyPressEvent(QKeyEvent *event)
160 if(event->key() == Qt::Key_Back)
165 if(event->key() == Qt::Key_Escape)