Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GUI] Accept dialogs with ENTER, reject with ESC #1392

Merged
merged 4 commits into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions doc/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,28 @@ Wallets under a tree derivation structure in which keypairs are generated determ

Enabling major improvements over the keystore management, the PIVX wallet doesn't require regular backups as before, keys are following a deterministic creation path that can be verified at any time (before HD Wallet, every keypair was randomly created and added to the keypool, forcing the user to backup the wallet every certain amount of time or could end up loosing coins forever if the latest `wallet.dat` was not being used).
As well as new possibilities like the account extended public key that enables deterministic public keys creation without the private keys requisite inside the wallet (A good use case could be online stores generating fresh addresses).

This work includes a customization/extension to the [BIP44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki) standard. We have included an unique staking keys derivation path which introduced the deterministic generation/recovery of staking addresses.

An extended description of this large work can be found in the PR [here](https://github.com/PIVX-Project/PIVX/pull/1327).

#### HD Wallet FAQ

- How do i upgrade to HD Wallet?

GUI:
1) A dialog will appear on every wallet startup notifying you that you are running a pre-HD wallet and letting you upgrade it from there.
2) If you haven't upgraded your wallet, the topbar (bar with icons that appears at the top of your wallet) will have an "HD" icon. Click it and the upgrade dialog will be launched.

RPC:
1) If your wallet is unlocked, use the `-upgradewallet` flag at startup and will automatically upgrade your wallet.
2) If your wallet is encrypted, use the `upgradewallet` rpc command. It will upgrade your wallet to the latest wallet version.

- How do i know if i'm already running an HD Wallet?

1) GUI: Go to settings, press on the Debug option, then Information.
2) RPC: call `getwalletinfo`, the `walletversion` field must be `169900` (HD Wallet Feature).


### Functional Changes

Expand Down Expand Up @@ -161,6 +161,8 @@ The p2p alert system has been removed in [#1372](https://github.com/PIVX-Project

### GUI

Keyboard navigation: dialogs can now be accepted with the `ENTER` (`RETURN`) key, and dismissed with the `ESC` key ([#1392](https://github.com/PIVX-Project/PIVX/pull/1392)).

### RPC/REST

### Wallet
Expand Down
10 changes: 10 additions & 0 deletions src/qt/guiutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ class QUrl;
class QWidget;
QT_END_NAMESPACE

/*
* General GUI exception
*/
class GUIException : public std::exception
{
public:
std::string message;
GUIException(const std::string &message) : message(message) {}
};

/** Utility functions used by the PIVX Qt UI.
*/
namespace GUIUtil
Expand Down
30 changes: 28 additions & 2 deletions src/qt/pivx/defaultdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "qt/pivx/defaultdialog.h"
#include "qt/pivx/forms/ui_defaultdialog.h"
#include "guiutil.h"
#include <QKeyEvent>

DefaultDialog::DefaultDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::DefaultDialog)
Expand Down Expand Up @@ -35,10 +37,17 @@ DefaultDialog::DefaultDialog(QWidget *parent) :

connect(ui->btnEsc, SIGNAL(clicked()), this, SLOT(close()));
connect(ui->btnCancel, SIGNAL(clicked()), this, SLOT(close()));
connect(ui->btnSave, &QPushButton::clicked, [this](){this->isOk = true; accept();});
connect(ui->btnSave, &QPushButton::clicked, this, &DefaultDialog::accept);
}

void DefaultDialog::showEvent(QShowEvent *event)
{
setFocus();
}

void DefaultDialog::setText(QString title, QString message, QString okBtnText, QString cancelBtnText){

void DefaultDialog::setText(QString title, QString message, QString okBtnText, QString cancelBtnText)
{
if(!okBtnText.isNull()) ui->btnSave->setText(okBtnText);
if(!cancelBtnText.isNull()){
ui->btnCancel->setVisible(true);
Expand All @@ -50,6 +59,23 @@ void DefaultDialog::setText(QString title, QString message, QString okBtnText, Q
if(!title.isNull()) ui->labelTitle->setText(title);
}

void DefaultDialog::accept()
{
this->isOk = true;
QDialog::accept();
}

void DefaultDialog::keyPressEvent(QKeyEvent *event)
{
if (event->type() == QEvent::KeyPress) {
QKeyEvent* ke = static_cast<QKeyEvent*>(event);
// Detect Enter key press
if (ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Return) accept();
// Detect Esc key press
if (ke->key() == Qt::Key_Escape) close();
}
}

DefaultDialog::~DefaultDialog()
{
delete ui;
Expand Down
7 changes: 7 additions & 0 deletions src/qt/pivx/defaultdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ class DefaultDialog : public QDialog
explicit DefaultDialog(QWidget *parent = nullptr);
~DefaultDialog();

void showEvent(QShowEvent *event) override;
void setText(QString title = "", QString message = "", QString okBtnText = "", QString cancelBtnText = "");

bool isOk = false;

public Q_SLOTS:
void accept() override;

private:
Ui::DefaultDialog *ui;
protected:
void keyPressEvent(QKeyEvent *e) override;
};

#endif // DEFAULTDIALOG_H
37 changes: 32 additions & 5 deletions src/qt/pivx/sendconfirmdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
#include "qt/pivx/qtutils.h"
#include <QList>
#include <QDateTime>
#include <QKeyEvent>

TxDetailDialog::TxDetailDialog(QWidget *parent, bool isConfirmDialog, QString warningStr) :
TxDetailDialog::TxDetailDialog(QWidget *parent, bool _isConfirmDialog, QString warningStr) :
QDialog(parent),
ui(new Ui::TxDetailDialog)
ui(new Ui::TxDetailDialog),
isConfirmDialog(_isConfirmDialog)
{
ui->setupUi(this);

Expand Down Expand Up @@ -80,6 +82,11 @@ TxDetailDialog::TxDetailDialog(QWidget *parent, bool isConfirmDialog, QString wa
connect(ui->pushOutputs, SIGNAL(clicked()), this, SLOT(onOutputsClicked()));
}

void TxDetailDialog::showEvent(QShowEvent *event)
{
setFocus();
}

void TxDetailDialog::setData(WalletModel *model, const QModelIndex &index){
this->model = model;
TransactionRecord *rec = static_cast<TransactionRecord*>(index.internalPointer());
Expand Down Expand Up @@ -135,7 +142,10 @@ void TxDetailDialog::setData(WalletModel *model, WalletModelTransaction &tx){
ui->textFee->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, txFee, false, BitcoinUnits::separatorAlways));
}

void TxDetailDialog::acceptTx(){
void TxDetailDialog::acceptTx()
{
if (!isConfirmDialog)
throw GUIException(strprintf("%s called on non confirm dialog", __func__));
this->confirm = true;
this->sendStatus = model->sendCoins(*this->tx);
accept();
Expand Down Expand Up @@ -217,12 +227,29 @@ void TxDetailDialog::onOutputsClicked() {
}
}

void TxDetailDialog::closeDialog(){
void TxDetailDialog::keyPressEvent(QKeyEvent *event)
{
if (event->type() == QEvent::KeyPress) {
QKeyEvent* ke = static_cast<QKeyEvent*>(event);
// Detect Enter key press
if (ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Return) {
if (isConfirmDialog) acceptTx();
else accept();
}
// Detect Esc key press
if (ke->key() == Qt::Key_Escape)
closeDialog();
}
}

void TxDetailDialog::closeDialog()
{
if(snackBar && snackBar->isVisible()) snackBar->hide();
close();
}

TxDetailDialog::~TxDetailDialog(){
TxDetailDialog::~TxDetailDialog()
{
if(snackBar) delete snackBar;
delete ui;
}
5 changes: 5 additions & 0 deletions src/qt/pivx/sendconfirmdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class TxDetailDialog : public QDialog
explicit TxDetailDialog(QWidget *parent = nullptr, bool isConfirmDialog = true, QString warningStr = QString());
~TxDetailDialog();

void showEvent(QShowEvent *event) override;
bool isConfirm() { return this->confirm;}
WalletModel::SendCoinsReturn getStatus() { return this->sendStatus;}

Expand All @@ -45,6 +46,7 @@ public Q_SLOTS:
Ui::TxDetailDialog *ui;
SnackBar *snackBar = nullptr;
int nDisplayUnit = 0;
bool isConfirmDialog = false;
bool confirm = false;
WalletModel *model = nullptr;
WalletModel::SendCoinsReturn sendStatus;
Expand All @@ -53,6 +55,9 @@ public Q_SLOTS:

bool inputsLoaded = false;
bool outputsLoaded = false;

protected:
void keyPressEvent(QKeyEvent *e) override;
};

#endif // SENDCONFIRMDIALOG_H