Replace showMessageBox with Qt builtin

This commit is contained in:
tobtoht 2020-12-14 03:20:05 +01:00
parent b6459d1b64
commit 85a06007a1
No known key found for this signature in database
GPG key ID: 1CADD27F41F45C3C
13 changed files with 29 additions and 52 deletions

View file

@ -36,8 +36,6 @@
<file>assets/images/eye_blind.png</file> <file>assets/images/eye_blind.png</file>
<file>assets/images/feather.png</file> <file>assets/images/feather.png</file>
<file>assets/images/file.png</file> <file>assets/images/file.png</file>
<file>assets/images/ghost.png</file>
<file>assets/images/ghost_icon.png</file>
<file>assets/images/gnome-calc.png</file> <file>assets/images/gnome-calc.png</file>
<file>assets/images/history.png</file> <file>assets/images/history.png</file>
<file>assets/images/info.png</file> <file>assets/images/info.png</file>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 127 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

View file

@ -14,6 +14,7 @@
#include <QKeyEvent> #include <QKeyEvent>
#include <QMenu> #include <QMenu>
#include <QAction> #include <QAction>
#include <QMessageBox>
CoinsWidget::CoinsWidget(QWidget *parent) CoinsWidget::CoinsWidget(QWidget *parent)
: QWidget(parent) : QWidget(parent)
@ -197,7 +198,7 @@ void CoinsWidget::onSweepOutput() {
qCritical() << "key image: " << keyImage; qCritical() << "key image: " << keyImage;
if (!keyImageKnown) { if (!keyImageKnown) {
Utils::showMessageBox("Unable to sweep output", "Unable to sweep output: key image unknown", true); QMessageBox::warning(this, "Unable to sweep output", "Unable to sweep output: key image unknown");
return; return;
} }

View file

@ -104,7 +104,7 @@ MainWindow::MainWindow(AppContext *ctx, QWidget *parent) :
"Try to explain not only what the bug is, but how it occurs.</body>"); "Try to explain not only what the bug is, but how it occurs.</body>");
}); });
connect(ui->actionShow_debug_info, &QAction::triggered, this, &MainWindow::showDebugInfo); connect(ui->actionShow_debug_info, &QAction::triggered, this, &MainWindow::showDebugInfo);
connect(ui->actionOfficialWebsite, &QAction::triggered, [=] { Utils::externalLinkWarning("https://featherwallet.org"); }); connect(ui->actionOfficialWebsite, &QAction::triggered, [=] { Utils::externalLinkWarning(this, "https://featherwallet.org"); });
#if defined(HAS_XMRTO) #if defined(HAS_XMRTO)
// xmr.to connects/widget // xmr.to connects/widget
@ -115,7 +115,7 @@ MainWindow::MainWindow(AppContext *ctx, QWidget *parent) :
connect(m_ctx->XMRTo, &XmrTo::connectionError, ui->xmrToWidget, &XMRToWidget::onConnectionError); connect(m_ctx->XMRTo, &XmrTo::connectionError, ui->xmrToWidget, &XMRToWidget::onConnectionError);
connect(m_ctx->XMRTo, &XmrTo::connectionSuccess, ui->xmrToWidget, &XMRToWidget::onConnectionSuccess); connect(m_ctx->XMRTo, &XmrTo::connectionSuccess, ui->xmrToWidget, &XMRToWidget::onConnectionSuccess);
connect(m_ctx, &AppContext::balanceUpdated, ui->xmrToWidget, &XMRToWidget::onBalanceUpdated); connect(m_ctx, &AppContext::balanceUpdated, ui->xmrToWidget, &XMRToWidget::onBalanceUpdated);
connect(m_ctx->XMRTo, &XmrTo::openURL, this, [=](const QString &url){ Utils::externalLinkWarning(url); }); connect(m_ctx->XMRTo, &XmrTo::openURL, this, [=](const QString &url){ Utils::externalLinkWarning(this, url); });
ui->xmrToWidget->setHistoryModel(m_ctx->XMRTo->tableModel); ui->xmrToWidget->setHistoryModel(m_ctx->XMRTo->tableModel);
#else #else
ui->tabExchanges->setTabVisible(0, false); ui->tabExchanges->setTabVisible(0, false);
@ -243,13 +243,13 @@ MainWindow::MainWindow(AppContext *ctx, QWidget *parent) :
"for developers only. Your coins are WORTHLESS."); "for developers only. Your coins are WORTHLESS.");
if(m_ctx->networkType == NetworkType::STAGENET) { if(m_ctx->networkType == NetworkType::STAGENET) {
if (config()->get(Config::warnOnStagenet).toBool()) { if (config()->get(Config::warnOnStagenet).toBool()) {
Utils::showMessageBox("Warning", worthlessWarning.arg("stagenet"), true); QMessageBox::warning(this, "Warning", worthlessWarning.arg("stagenet"));
config()->set(Config::warnOnStagenet, false); config()->set(Config::warnOnStagenet, false);
} }
} }
else if(m_ctx->networkType == NetworkType::TESTNET){ else if(m_ctx->networkType == NetworkType::TESTNET){
if (config()->get(Config::warnOnTestnet).toBool()) { if (config()->get(Config::warnOnTestnet).toBool()) {
Utils::showMessageBox("Warning", worthlessWarning.arg("testnet"), true); QMessageBox::warning(this, "Warning", worthlessWarning.arg("testnet"));
config()->set(Config::warnOnTestnet, false); config()->set(Config::warnOnTestnet, false);
} }
} }
@ -463,7 +463,7 @@ void MainWindow::initMenu() {
if(fn.isEmpty()) return; if(fn.isEmpty()) return;
if(!fn.endsWith(".csv")) fn += ".csv"; if(!fn.endsWith(".csv")) fn += ".csv";
m_ctx->currentWallet->history()->writeCSV(fn); m_ctx->currentWallet->history()->writeCSV(fn);
Utils::showMessageBox("CSV export", QString("Transaction history exported to %1").arg(fn), false); QMessageBox::information(this, "CSV export", QString("Transaction history exported to %1").arg(fn));
}); });
// Contact widget // Contact widget
@ -471,7 +471,7 @@ void MainWindow::initMenu() {
if(m_ctx->currentWallet == nullptr) return; if(m_ctx->currentWallet == nullptr) return;
auto *model = m_ctx->currentWallet->addressBookModel(); auto *model = m_ctx->currentWallet->addressBookModel();
if (model->rowCount() <= 0){ if (model->rowCount() <= 0){
Utils::showMessageBox("Error", "Addressbook empty", true); QMessageBox::warning(this, "Error", "Addressbook empty");
return; return;
} }
@ -481,7 +481,7 @@ void MainWindow::initMenu() {
qint64 now = QDateTime::currentDateTime().currentMSecsSinceEpoch(); qint64 now = QDateTime::currentDateTime().currentMSecsSinceEpoch();
QString fn = QString("%1/monero-contacts_%2.csv").arg(targetDir, QString::number(now / 1000)); QString fn = QString("%1/monero-contacts_%2.csv").arg(targetDir, QString::number(now / 1000));
if(model->writeCSV(fn)) if(model->writeCSV(fn))
Utils::showMessageBox("Address book exported", QString("Address book exported to %1").arg(fn), false); QMessageBox::information(this, "Address book exported", QString("Address book exported to %1").arg(fn));
}); });
connect(ui->actionImportContactsCSV, &QAction::triggered, this, &MainWindow::importContacts); connect(ui->actionImportContactsCSV, &QAction::triggered, this, &MainWindow::importContacts);
@ -560,7 +560,7 @@ void MainWindow::touchbarShowWallet() {
} }
void MainWindow::onWalletCreatedError(const QString &err) { void MainWindow::onWalletCreatedError(const QString &err) {
Utils::showMessageBox("Wallet creation error", err, true); QMessageBox::warning(this, "Wallet creation error", err);
this->showWizard(WalletWizard::Page_CreateWallet); this->showWizard(WalletWizard::Page_CreateWallet);
} }
@ -737,12 +737,12 @@ void MainWindow::onCreateTransactionSuccess(PendingTransaction *tx, const QStrin
err = QString("%1 %2").arg(err).arg(tx_err); err = QString("%1 %2").arg(err).arg(tx_err);
qDebug() << Q_FUNC_INFO << err; qDebug() << Q_FUNC_INFO << err;
Utils::showMessageBox("Transaction error", err, true); QMessageBox::warning(this, "Transactions error", err);
m_ctx->currentWallet->disposeTransaction(tx); m_ctx->currentWallet->disposeTransaction(tx);
} else if (tx->txCount() == 0) { } else if (tx->txCount() == 0) {
err = QString("%1 %2").arg(err).arg("No unmixable outputs to sweep."); err = QString("%1 %2").arg(err).arg("No unmixable outputs to sweep.");
qDebug() << Q_FUNC_INFO << err; qDebug() << Q_FUNC_INFO << err;
Utils::showMessageBox("Transaction error", err, true); QMessageBox::warning(this, "Transaction error", err);
m_ctx->currentWallet->disposeTransaction(tx); m_ctx->currentWallet->disposeTransaction(tx);
} else { } else {
const auto &description = m_ctx->tmpTxDescription; const auto &description = m_ctx->tmpTxDescription;
@ -968,12 +968,12 @@ void MainWindow::menuWalletOpenClicked() {
QFileInfo infoPath(path); QFileInfo infoPath(path);
if(!infoPath.isReadable()) { if(!infoPath.isReadable()) {
Utils::showMessageBox("Cannot read wallet file", "Permission error.", true); QMessageBox::warning(this, "Cannot read wallet file", "Permission error.");
return; return;
} }
if(path == m_ctx->walletPath) { if(path == m_ctx->walletPath) {
Utils::showMessageBox("Wallet already opened", "Please open another wallet.", true); QMessageBox::warning(this, "Wallet already opened", "Please open another wallet.");
return; return;
} }
@ -1051,7 +1051,7 @@ void MainWindow::showSendScreen(const CCSEntry &entry) {
void MainWindow::onViewOnBlockExplorer(const QString &txid) { void MainWindow::onViewOnBlockExplorer(const QString &txid) {
QString blockExplorerLink = Utils::blockExplorerLink(config()->get(Config::blockExplorer).toString(), m_ctx->networkType, txid); QString blockExplorerLink = Utils::blockExplorerLink(config()->get(Config::blockExplorer).toString(), m_ctx->networkType, txid);
Utils::externalLinkWarning(blockExplorerLink); Utils::externalLinkWarning(this, blockExplorerLink);
} }
void MainWindow::onAddContact(const QString &address, const QString &name) { void MainWindow::onAddContact(const QString &address, const QString &name) {

View file

@ -276,7 +276,7 @@ bool Utils::testSocks5(const QString &host, quint16 port){
return false; return false;
} }
void Utils::externalLinkWarning(const QString &url){ void Utils::externalLinkWarning(QWidget *parent, const QString &url){
if(!config()->get(Config::warnOnExternalLink).toBool()) { if(!config()->get(Config::warnOnExternalLink).toBool()) {
QDesktopServices::openUrl(QUrl(url)); QDesktopServices::openUrl(QUrl(url));
return; return;
@ -286,7 +286,7 @@ void Utils::externalLinkWarning(const QString &url){
body += QString("%1\n\n").arg(url); body += QString("%1\n\n").arg(url);
body += "You will NOT be using Tor."; body += "You will NOT be using Tor.";
switch (Utils::showMessageBox("External link warning", body, true)) { switch (QMessageBox::warning(parent, "External link warning", body, QMessageBox::Cancel|QMessageBox::Ok)) {
case QMessageBox::Cancel: case QMessageBox::Cancel:
break; break;
default: default:
@ -327,26 +327,6 @@ bool Utils::walletExists(QString name, const QString &path) {
return Utils::fileExists(walletPath); return Utils::fileExists(walletPath);
} }
int Utils::showMessageBox(const QString &windowTitle, const QString &body, bool warning){
QMessageBox msgBox(QApplication::activeWindow());
msgBox.setWindowTitle(windowTitle);
msgBox.setText(body);
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Ok);
if(warning) {
QPixmap iconWarning = QPixmap(":/assets/images/ghost_icon.png");
msgBox.setIconPixmap(iconWarning);
}
else {
QPixmap iconInfo = QPixmap(":/assets/images/info.png")
.scaled(QSize(48,48), Qt::KeepAspectRatio, Qt::SmoothTransformation);
msgBox.setIconPixmap(iconInfo);
}
return msgBox.exec();
}
void Utils::copyToClipboard(const QString &string){ void Utils::copyToClipboard(const QString &string){
QClipboard * clipboard = QApplication::clipboard(); QClipboard * clipboard = QApplication::clipboard();
if (!clipboard) { if (!clipboard) {

View file

@ -75,8 +75,7 @@ public:
static QStringList readJsonStringToQStringList(const QString &input); static QStringList readJsonStringToQStringList(const QString &input);
static void applicationLogHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg); static void applicationLogHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg);
static void openWindow(QWidget *w); static void openWindow(QWidget *w);
static void externalLinkWarning(const QString &url); static void externalLinkWarning(QWidget *parent, const QString &url);
static int showMessageBox(const QString &windowTitle, const QString &body, bool warning);
static QList<processStruct> procList(); static QList<processStruct> procList();
static bool dirExists(const QString &path); static bool dirExists(const QString &path);
static QString barrayToString(const QByteArray &data); static QString barrayToString(const QByteArray &data);
@ -98,8 +97,6 @@ public:
static QString formatBytes(quint64 bytes); static QString formatBytes(quint64 bytes);
static QString amountToCurrencyString(double amount, const QString &currencyCode); static QString amountToCurrencyString(double amount, const QString &currencyCode);
static QStringList randomHTTPAgents;
template<typename QEnum> template<typename QEnum>
static QString QtEnumToString (const QEnum value) static QString QtEnumToString (const QEnum value)
{ {

View file

@ -42,7 +42,7 @@ void CCSWidget::linkClicked() {
auto entry = m_model->entry(index.row()); auto entry = m_model->entry(index.row());
if (entry) if (entry)
Utils::externalLinkWarning(entry->url); Utils::externalLinkWarning(this, entry->url);
} }
void CCSWidget::donateClicked() { void CCSWidget::donateClicked() {

View file

@ -113,14 +113,14 @@ void NodeWidget::onContextWSStatusURL() {
QModelIndex index = ui->wsView->currentIndex(); QModelIndex index = ui->wsView->currentIndex();
if (!index.isValid()) return; if (!index.isValid()) return;
FeatherNode node = m_wsModel->node(index.row()); FeatherNode node = m_wsModel->node(index.row());
Utils::externalLinkWarning(node.as_url()); Utils::externalLinkWarning(this, node.as_url());
} }
void NodeWidget::onContextCustomStatusURL() { void NodeWidget::onContextCustomStatusURL() {
QModelIndex index = ui->customView->currentIndex(); QModelIndex index = ui->customView->currentIndex();
if (!index.isValid()) return; if (!index.isValid()) return;
FeatherNode node = m_customModel->node(index.row()); FeatherNode node = m_customModel->node(index.row());
Utils::externalLinkWarning(node.as_url()); Utils::externalLinkWarning(this, node.as_url());
} }
void NodeWidget::onContextDisconnect() { void NodeWidget::onContextDisconnect() {

View file

@ -37,7 +37,7 @@ void RedditWidget::linkClicked() {
auto post = m_model->post(index.row()); auto post = m_model->post(index.row());
if (post) { if (post) {
Utils::externalLinkWarning(post->url); Utils::externalLinkWarning(this, post->url);
} }
} }

View file

@ -155,7 +155,7 @@ void XMRigWidget::onStartClicked() {
if(username.isEmpty()) { if(username.isEmpty()) {
QString err = "Please specify a receiving address on the Settings screen"; QString err = "Please specify a receiving address on the Settings screen";
ui->console->appendPlainText(err); ui->console->appendPlainText(err);
Utils::showMessageBox("Error", err, true); QMessageBox::warning(this, "Error", err);
return; return;
} }
@ -286,7 +286,7 @@ void XMRigWidget::onSoloChecked(int state) {
void XMRigWidget::linkClicked() { void XMRigWidget::linkClicked() {
QModelIndex index = ui->tableView->currentIndex(); QModelIndex index = ui->tableView->currentIndex();
auto download_link = m_urls.at(index.row()); auto download_link = m_urls.at(index.row());
Utils::externalLinkWarning(download_link); Utils::externalLinkWarning(this, download_link);
} }
QStandardItemModel *XMRigWidget::model() { QStandardItemModel *XMRigWidget::model() {

View file

@ -8,6 +8,7 @@
#include <QPushButton> #include <QPushButton>
#include <QFileDialog> #include <QFileDialog>
#include <QMessageBox>
// @TODO: rescan wallet dir on wizard open // @TODO: rescan wallet dir on wizard open
@ -27,7 +28,7 @@ OpenWalletPage::OpenWalletPage(AppContext *ctx, QWidget *parent) :
QFileInfo infoPath(path); QFileInfo infoPath(path);
if(!infoPath.isReadable()) { if(!infoPath.isReadable()) {
Utils::showMessageBox("Cannot read wallet file", "Permission error.", true); QMessageBox::warning(this, "Cannot read wallet file", "Permission error.");
return; return;
} }
@ -67,7 +68,7 @@ int OpenWalletPage::nextId() const {
bool OpenWalletPage::validatePage() { bool OpenWalletPage::validatePage() {
QModelIndex index = ui->walletTable->currentIndex(); QModelIndex index = ui->walletTable->currentIndex();
if(!index.isValid()) { if(!index.isValid()) {
Utils::showMessageBox("Wallet not selected", "Please select a wallet from the list.", true); QMessageBox::warning(this, "Wallet not selected", "Please select a wallet from the list.");
return false; return false;
} }
QString walletPath = index.model()->data(index.siblingAtColumn(WalletKeysFilesModel::ModelColumns::Path), Qt::UserRole).toString(); QString walletPath = index.model()->data(index.siblingAtColumn(WalletKeysFilesModel::ModelColumns::Path), Qt::UserRole).toString();

View file

@ -86,7 +86,7 @@ void XMRToWidget::onCreateOrder() {
auto amount = ui->lineAmount->text(); auto amount = ui->lineAmount->text();
if(amount.isEmpty()) { if(amount.isEmpty()) {
Utils::showMessageBox("Cannot create XMR.To order", "Invalid amount", false); QMessageBox::warning(this, "Cannot create XMR.To order", "Invalid amount");
return; return;
} }
@ -99,7 +99,7 @@ void XMRToWidget::onCreateOrder() {
auto available = m_unlockedBalance; auto available = m_unlockedBalance;
if(amount_xmr > available){ if(amount_xmr > available){
Utils::showMessageBox("Cannot create XMR.To order", "Not enough Monero to create order.", false); QMessageBox::warning(this, "Cannot create XMR.To order", "Not enough Monero to create order.");
return; return;
} }