Cleanup some methods to make them easier to read
This commit is contained in:
@@ -18,101 +18,11 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
// Status Bar
|
||||
loadingLabel = new QLabel();
|
||||
loadingMovie = new QMovie(":/icons/res/loading.gif");
|
||||
loadingMovie->setScaledSize(QSize(32, 16));
|
||||
loadingMovie->start();
|
||||
loadingLabel->setAttribute(Qt::WA_NoSystemBackground);
|
||||
loadingLabel->setMovie(loadingMovie);
|
||||
|
||||
ui->statusBar->addPermanentWidget(loadingLabel);
|
||||
loadingLabel->setVisible(false);
|
||||
|
||||
// Custom status bar menu
|
||||
ui->statusBar->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
QObject::connect(ui->statusBar, &QStatusBar::customContextMenuRequested, [=](QPoint pos) {
|
||||
auto msg = ui->statusBar->currentMessage();
|
||||
QMenu menu(this);
|
||||
|
||||
if (!msg.isEmpty() && msg.startsWith(Utils::txidStatusMessage)) {
|
||||
auto txid = msg.split(":")[1].trimmed();
|
||||
menu.addAction("Copy txid", [=]() {
|
||||
QGuiApplication::clipboard()->setText(txid);
|
||||
});
|
||||
menu.addAction("View tx on block explorer", [=]() {
|
||||
QString url;
|
||||
if (Settings::getInstance()->isTestnet()) {
|
||||
url = "https://explorer.testnet.z.cash/tx/" + txid;
|
||||
} else {
|
||||
url = "https://explorer.zcha.in/transactions/" + txid;
|
||||
}
|
||||
QDesktopServices::openUrl(QUrl(url));
|
||||
});
|
||||
}
|
||||
|
||||
menu.addAction("Refresh", [=]() {
|
||||
rpc->refresh();
|
||||
});
|
||||
QPoint gpos(mapToGlobal(pos).x(), mapToGlobal(pos).y() + this->height() - ui->statusBar->height());
|
||||
menu.exec(gpos);
|
||||
});
|
||||
|
||||
statusLabel = new QLabel();
|
||||
ui->statusBar->addPermanentWidget(statusLabel);
|
||||
|
||||
statusIcon = new QLabel();
|
||||
ui->statusBar->addPermanentWidget(statusIcon);
|
||||
// Status Bar
|
||||
setupStatusBar();
|
||||
|
||||
// Set up File -> Settings action
|
||||
QObject::connect(ui->actionSettings, &QAction::triggered, [=]() {
|
||||
QDialog settingsDialog(this);
|
||||
Ui_Settings settings;
|
||||
settings.setupUi(&settingsDialog);
|
||||
|
||||
QIntValidator validator(0, 65535);
|
||||
settings.port->setValidator(&validator);
|
||||
|
||||
|
||||
// If values are coming from zcash.conf, then disable all the fields
|
||||
auto zcashConfLocation = Settings::getInstance()->getZcashdConfLocation();
|
||||
if (!zcashConfLocation.isEmpty()) {
|
||||
settings.confMsg->setText("Values are configured from\n" + zcashConfLocation);
|
||||
settings.hostname->setEnabled(false);
|
||||
settings.port->setEnabled(false);
|
||||
settings.rpcuser->setEnabled(false);
|
||||
settings.rpcpassword->setEnabled(false);
|
||||
}
|
||||
else {
|
||||
settings.hostname->setEnabled(true);
|
||||
settings.port->setEnabled(true);
|
||||
settings.rpcuser->setEnabled(true);
|
||||
settings.rpcpassword->setEnabled(true);
|
||||
|
||||
// Load previous values into the dialog
|
||||
settings.hostname->setText(Settings::getInstance()->getHost());
|
||||
settings.port->setText(Settings::getInstance()->getPort());
|
||||
settings.rpcuser->setText(Settings::getInstance()->getUsernamePassword().split(":")[0]);
|
||||
settings.rpcpassword->setText(Settings::getInstance()->getUsernamePassword().split(":")[1]);
|
||||
}
|
||||
|
||||
if (settingsDialog.exec() == QDialog::Accepted) {
|
||||
if (zcashConfLocation.isEmpty()) {
|
||||
// Save settings
|
||||
QSettings s;
|
||||
s.setValue("connection/host", settings.hostname->text());
|
||||
s.setValue("connection/port", settings.port->text());
|
||||
s.setValue("connection/rpcuser", settings.rpcuser->text());
|
||||
s.setValue("connection/rpcpassword", settings.rpcpassword->text());
|
||||
|
||||
s.sync();
|
||||
|
||||
// Then refresh everything.
|
||||
this->rpc->reloadConnectionInfo();
|
||||
this->rpc->refresh();
|
||||
}
|
||||
};
|
||||
});
|
||||
// Settings editor
|
||||
setupSettingsModal();
|
||||
|
||||
// Set up exit action
|
||||
QObject::connect(ui->actionExit, &QAction::triggered, this, &MainWindow::close);
|
||||
@@ -151,6 +61,106 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
rpc->refresh();
|
||||
}
|
||||
|
||||
void MainWindow::setupStatusBar() {
|
||||
// Status Bar
|
||||
loadingLabel = new QLabel();
|
||||
loadingMovie = new QMovie(":/icons/res/loading.gif");
|
||||
loadingMovie->setScaledSize(QSize(32, 16));
|
||||
loadingMovie->start();
|
||||
loadingLabel->setAttribute(Qt::WA_NoSystemBackground);
|
||||
loadingLabel->setMovie(loadingMovie);
|
||||
|
||||
ui->statusBar->addPermanentWidget(loadingLabel);
|
||||
loadingLabel->setVisible(false);
|
||||
|
||||
// Custom status bar menu
|
||||
ui->statusBar->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
QObject::connect(ui->statusBar, &QStatusBar::customContextMenuRequested, [=](QPoint pos) {
|
||||
auto msg = ui->statusBar->currentMessage();
|
||||
QMenu menu(this);
|
||||
|
||||
if (!msg.isEmpty() && msg.startsWith(Utils::txidStatusMessage)) {
|
||||
auto txid = msg.split(":")[1].trimmed();
|
||||
menu.addAction("Copy txid", [=]() {
|
||||
QGuiApplication::clipboard()->setText(txid);
|
||||
});
|
||||
menu.addAction("View tx on block explorer", [=]() {
|
||||
QString url;
|
||||
if (Settings::getInstance()->isTestnet()) {
|
||||
url = "https://explorer.testnet.z.cash/tx/" + txid;
|
||||
}
|
||||
else {
|
||||
url = "https://explorer.zcha.in/transactions/" + txid;
|
||||
}
|
||||
QDesktopServices::openUrl(QUrl(url));
|
||||
});
|
||||
}
|
||||
|
||||
menu.addAction("Refresh", [=]() {
|
||||
rpc->refresh();
|
||||
});
|
||||
QPoint gpos(mapToGlobal(pos).x(), mapToGlobal(pos).y() + this->height() - ui->statusBar->height());
|
||||
menu.exec(gpos);
|
||||
});
|
||||
|
||||
statusLabel = new QLabel();
|
||||
ui->statusBar->addPermanentWidget(statusLabel);
|
||||
|
||||
statusIcon = new QLabel();
|
||||
ui->statusBar->addPermanentWidget(statusIcon);
|
||||
}
|
||||
|
||||
void MainWindow::setupSettingsModal() {
|
||||
// Set up File -> Settings action
|
||||
QObject::connect(ui->actionSettings, &QAction::triggered, [=]() {
|
||||
QDialog settingsDialog(this);
|
||||
Ui_Settings settings;
|
||||
settings.setupUi(&settingsDialog);
|
||||
|
||||
QIntValidator validator(0, 65535);
|
||||
settings.port->setValidator(&validator);
|
||||
|
||||
// If values are coming from zcash.conf, then disable all the fields
|
||||
auto zcashConfLocation = Settings::getInstance()->getZcashdConfLocation();
|
||||
if (!zcashConfLocation.isEmpty()) {
|
||||
settings.confMsg->setText("Values are configured from\n" + zcashConfLocation);
|
||||
settings.hostname->setEnabled(false);
|
||||
settings.port->setEnabled(false);
|
||||
settings.rpcuser->setEnabled(false);
|
||||
settings.rpcpassword->setEnabled(false);
|
||||
}
|
||||
else {
|
||||
settings.hostname->setEnabled(true);
|
||||
settings.port->setEnabled(true);
|
||||
settings.rpcuser->setEnabled(true);
|
||||
settings.rpcpassword->setEnabled(true);
|
||||
|
||||
// Load previous values into the dialog
|
||||
settings.hostname->setText(Settings::getInstance()->getHost());
|
||||
settings.port->setText(Settings::getInstance()->getPort());
|
||||
settings.rpcuser->setText(Settings::getInstance()->getUsernamePassword().split(":")[0]);
|
||||
settings.rpcpassword->setText(Settings::getInstance()->getUsernamePassword().split(":")[1]);
|
||||
}
|
||||
|
||||
if (settingsDialog.exec() == QDialog::Accepted) {
|
||||
if (zcashConfLocation.isEmpty()) {
|
||||
// Save settings
|
||||
QSettings s;
|
||||
s.setValue("connection/host", settings.hostname->text());
|
||||
s.setValue("connection/port", settings.port->text());
|
||||
s.setValue("connection/rpcuser", settings.rpcuser->text());
|
||||
s.setValue("connection/rpcpassword", settings.rpcpassword->text());
|
||||
|
||||
s.sync();
|
||||
|
||||
// Then refresh everything.
|
||||
this->rpc->reloadConnectionInfo();
|
||||
this->rpc->refresh();
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
void MainWindow::donate() {
|
||||
// Set up a donation to me :)
|
||||
ui->Address1->setText("zcEgrceTwvoiFdEvPWcsJHAMrpLsprMF6aRJiQa3fan5ZphyXLPuHghnEPrEPRoEVzUy65GnMVyCTRdkT6BYBepnXh6NBYs");
|
||||
|
||||
@@ -39,6 +39,9 @@ private:
|
||||
void setupRecieveTab();
|
||||
void setupBalancesTab();
|
||||
|
||||
void setupSettingsModal();
|
||||
void setupStatusBar();
|
||||
|
||||
void removeExtraAddresses();
|
||||
void setDefaultPayFrom();
|
||||
|
||||
|
||||
@@ -243,10 +243,6 @@ void RPC::handleConnectionError(const QString& error) {
|
||||
% "\n\nA zcash.conf was found at\n" % confLocation
|
||||
% "\nbut we can't connect to zcashd. Is rpcuser=<user> and rpcpassword=<pass> set in the zcash.conf file?";
|
||||
}
|
||||
} else if (error.contains("bad request", Qt::CaseInsensitive)) {
|
||||
explanation = QString()
|
||||
% "\n\nThis is most likely an internal error. Are you using zcashd v2.0 or higher? You might "
|
||||
% "need to file a bug report here: https://github.com/adityapk00/zcash-qt-wallet/issues";
|
||||
} else if (error.contains("internal server error", Qt::CaseInsensitive) ||
|
||||
error.contains("rewinding", Qt::CaseInsensitive) ||
|
||||
error.contains("loading", Qt::CaseInsensitive)) {
|
||||
|
||||
Reference in New Issue
Block a user