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

UI improvements #1475

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
19 changes: 1 addition & 18 deletions src/Makefile.qt.include
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,8 @@ QT_FORMS_UI = \
qt/forms/debugwindow.ui \
qt/forms/sendcoinsdialog.ui \
qt/forms/sendcoinsentry.ui \
qt/forms/sendtopcodedialog.ui \
qt/forms/signverifymessagedialog.ui \
qt/forms/transactiondescdialog.ui \
qt/forms/lelantusdialog.ui
qt/forms/transactiondescdialog.ui

QT_MOC_CPP = \
qt/moc_addressbookpage.cpp \
Expand Down Expand Up @@ -162,7 +160,6 @@ QT_MOC_CPP = \
qt/moc_rpcconsole.cpp \
qt/moc_sendcoinsdialog.cpp \
qt/moc_sendcoinsentry.cpp \
qt/moc_sendtopcodedialog.cpp \
qt/moc_signverifymessagedialog.cpp \
qt/moc_splashscreen.cpp \
qt/moc_trafficgraphwidget.cpp \
Expand All @@ -175,12 +172,8 @@ QT_MOC_CPP = \
qt/moc_walletframe.cpp \
qt/moc_walletmodel.cpp \
qt/moc_walletview.cpp \
qt/moc_lelantusmodel.cpp \
qt/moc_lelantusdialog.cpp \
qt/moc_lelantuscoincontroldialog.cpp \
qt/moc_automintmodel.cpp \
qt/moc_automintnotification.cpp \
qt/moc_pcodemodel.cpp \
qt/moc_sparkmodel.cpp

BITCOIN_MM = \
Expand Down Expand Up @@ -233,7 +226,6 @@ BITCOIN_QT_H = \
qt/optionsmodel.h \
qt/overviewpage.h \
qt/paymentserver.h \
qt/pcodemodel.h \
qt/peertablemodel.h \
qt/platformstyle.h \
qt/qvalidatedlineedit.h \
Expand All @@ -244,7 +236,6 @@ BITCOIN_QT_H = \
qt/rpcconsole.h \
qt/sendcoinsdialog.h \
qt/sendcoinsentry.h \
qt/sendtopcodedialog.h \
qt/signverifymessagedialog.h \
qt/splashscreen.h \
qt/trafficgraphwidget.h \
Expand All @@ -260,9 +251,6 @@ BITCOIN_QT_H = \
qt/walletmodeltransaction.h \
qt/walletview.h \
qt/winshutdownmonitor.h \
qt/lelantusmodel.h \
qt/lelantusdialog.h \
qt/lelantuscoincontroldialog.h \
qt/automintmodel.h \
qt/sparkmodel.h

Expand Down Expand Up @@ -430,14 +418,12 @@ BITCOIN_QT_WALLET_CPP = \
qt/manualmintdialog.cpp \
qt/openuridialog.cpp \
qt/overviewpage.cpp \
qt/pcodemodel.cpp \
qt/paymentserver.cpp \
qt/receivecoinsdialog.cpp \
qt/receiverequestdialog.cpp \
qt/recentrequeststablemodel.cpp \
qt/sendcoinsdialog.cpp \
qt/sendcoinsentry.cpp \
qt/sendtopcodedialog.cpp \
qt/signverifymessagedialog.cpp \
qt/transactiondesc.cpp \
qt/transactiondescdialog.cpp \
Expand All @@ -450,9 +436,6 @@ BITCOIN_QT_WALLET_CPP = \
qt/walletmodeltransaction.cpp \
qt/masternodelist.cpp \
qt/walletview.cpp \
qt/lelantusmodel.cpp \
qt/lelantusdialog.cpp \
qt/lelantuscoincontroldialog.cpp \
qt/automintmodel.cpp \
qt/sparkmodel.cpp

Expand Down
143 changes: 0 additions & 143 deletions src/qt/automintdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,156 +3,13 @@
#include "automintdialog.h"
#include "automintmodel.h"
#include "bitcoinunits.h"
#include "lelantusmodel.h"
#include "sparkmodel.h"
#include "ui_automintdialog.h"

#include <QMessageBox>
#include <QPushButton>
#include <QDebug>

AutoMintDialog::AutoMintDialog(AutoMintMode mode, QWidget *parent) :
QDialog(parent),
ui(new Ui::AutoMintDialog),
model(0),
lelantusModel(0),
requiredPassphase(true),
progress(AutoMintProgress::Start),
mode(mode)
{
ENTER_CRITICAL_SECTION(cs_main);
ENTER_CRITICAL_SECTION(pwalletMain->cs_wallet);

ui->setupUi(this);
ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Anonymize"));
ui->buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("Cancel"));
}

AutoMintDialog::~AutoMintDialog()
{
if (lelantusModel) {
LEAVE_CRITICAL_SECTION(lelantusModel->cs);
}

LEAVE_CRITICAL_SECTION(pwalletMain->cs_wallet);
LEAVE_CRITICAL_SECTION(cs_main);
}

void AutoMintDialog::accept()
{
ensureLelantusModel();

ui->buttonBox->setVisible(false);
ui->passEdit->setVisible(false);
ui->passLabel->setVisible(false);
ui->lockWarningLabel->setVisible(false);
ui->lockCheckBox->setVisible(false);

if (requiredPassphase) {
auto rawPassphase = ui->passEdit->text().toStdString();
SecureString passphase(rawPassphase.begin(), rawPassphase.end());
auto lock = ui->lockCheckBox->isChecked();

progress = AutoMintProgress::Unlocking;
repaint();

if (!lelantusModel->unlockWallet(passphase, lock ? 0 : 60 * 1000)) {
QMessageBox::critical(this, tr("Wallet unlock failed"),
tr("The passphrase was incorrect."));
QDialog::reject();
return;
}
}

progress = AutoMintProgress::Minting;
repaint();

AutoMintAck status;
CAmount minted = 0;
QString error;

try {
minted = lelantusModel->mintAll();
status = AutoMintAck::Success;
} catch (std::runtime_error const &e) {
status = AutoMintAck::FailToMint;
error = e.what();
QMessageBox::critical(this, tr("Unable to generate mint"),
tr(error.toLocal8Bit().data()));
}

QDialog::accept();

lelantusModel->sendAckMintAll(status, minted, error);
}

int AutoMintDialog::exec()
{
ensureLelantusModel();
if (lelantusModel->getMintableAmount() <= 0) {
lelantusModel->sendAckMintAll(AutoMintAck::NotEnoughFund);
return 0;
}

return QDialog::exec();
}

void AutoMintDialog::reject()
{
ensureLelantusModel();
lelantusModel->sendAckMintAll(AutoMintAck::UserReject);
QDialog::reject();
}

void AutoMintDialog::setModel(WalletModel *model)
{
this->model = model;
if (!this->model) {
return;
}

lelantusModel = this->model->getLelantusModel();
if (!lelantusModel) {
return;
}

ENTER_CRITICAL_SECTION(lelantusModel->cs);

if (this->model->getEncryptionStatus() != WalletModel::Locked) {
ui->passLabel->setVisible(false);
ui->passEdit->setVisible(false);
ui->lockCheckBox->setVisible(false);
ui->lockWarningLabel->setText(QString(tr("Do you want to anonymize all transparent funds?")));

requiredPassphase = false;
}
}

void AutoMintDialog::paintEvent(QPaintEvent *event)
{
QPainter painter;
painter.begin(this);

if (progress != AutoMintProgress::Start) {
auto progressMessage = progress == AutoMintProgress::Unlocking ? tr("Unlocking wallet...") : tr("Anonymizing...");
auto size = QFontMetrics(painter.font()).size(Qt::TextSingleLine, progressMessage);
painter.drawText(
(width() - size.width()) / 2,
(height() - size.height()) / 2,
QString(progressMessage));
}

QWidget::paintEvent(event);
painter.end();
}

void AutoMintDialog::ensureLelantusModel()
{
if (!lelantusModel) {
throw std::runtime_error("Lelantus model is not set");
}
}

AutoMintSparkDialog::AutoMintSparkDialog(AutoMintSparkMode mode, QWidget *parent) :
QDialog(parent),
ui(new Ui::AutoMintDialog),
Expand Down
40 changes: 0 additions & 40 deletions src/qt/automintdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,10 @@
#include <QPainter>
#include <QPaintEvent>

enum class AutoMintMode : uint8_t {
MintAll, // come from overview page
AutoMintAll // come from notification
};

namespace Ui {
class AutoMintDialog;
}

class AutoMintDialog : public QDialog
{
Q_OBJECT;

public:
explicit AutoMintDialog(AutoMintMode mode, QWidget *parent = 0);
~AutoMintDialog();

public:
int exec();
void setModel(WalletModel *model);

void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;

private Q_SLOTS:
void accept();
void reject();

private:
enum class AutoMintProgress : uint8_t {
Start,
Unlocking,
Minting
};

Ui::AutoMintDialog *ui;
WalletModel *model;
LelantusModel *lelantusModel;
bool requiredPassphase;
AutoMintProgress progress;
AutoMintMode mode;

void ensureLelantusModel();
};

enum class AutoMintSparkMode : uint8_t {
MintAll, // come from overview page
AutoMintAll // come from notification
Expand Down
Loading
Loading