Prepend the error/warning prefix for GUI messages

This commit is contained in:
Hennadii Stepanov 2019-04-30 00:39:45 +03:00
parent 0221420d1a
commit f0641f274f
No known key found for this signature in database
GPG key ID: 410108112E7EA81F
2 changed files with 15 additions and 14 deletions

View file

@ -1038,9 +1038,10 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer
progressBar->setToolTip(tooltip); progressBar->setToolTip(tooltip);
} }
void BitcoinGUI::message(const QString &title, const QString &message, unsigned int style, bool *ret) void BitcoinGUI::message(const QString& title, QString message, unsigned int style, bool* ret)
{ {
QString strTitle = tr("Bitcoin"); // default title // Default title. On macOS, the window title is ignored (as required by the macOS Guidelines).
QString strTitle{PACKAGE_NAME};
// Default to information icon // Default to information icon
int nMBoxIcon = QMessageBox::Information; int nMBoxIcon = QMessageBox::Information;
int nNotifyIcon = Notificator::Information; int nNotifyIcon = Notificator::Information;
@ -1050,37 +1051,37 @@ void BitcoinGUI::message(const QString &title, const QString &message, unsigned
// Prefer supplied title over style based title // Prefer supplied title over style based title
if (!title.isEmpty()) { if (!title.isEmpty()) {
msgType = title; msgType = title;
} } else {
else {
switch (style) { switch (style) {
case CClientUIInterface::MSG_ERROR: case CClientUIInterface::MSG_ERROR:
msgType = tr("Error"); msgType = tr("Error");
message = tr("Error: %1").arg(message);
break; break;
case CClientUIInterface::MSG_WARNING: case CClientUIInterface::MSG_WARNING:
msgType = tr("Warning"); msgType = tr("Warning");
message = tr("Warning: %1").arg(message);
break; break;
case CClientUIInterface::MSG_INFORMATION: case CClientUIInterface::MSG_INFORMATION:
msgType = tr("Information"); msgType = tr("Information");
// No need to prepend the prefix here.
break; break;
default: default:
break; break;
} }
} }
// Append title to "Bitcoin - "
if (!msgType.isEmpty())
strTitle += " - " + msgType;
// Check for error/warning icon if (!msgType.isEmpty()) {
strTitle += " - " + msgType;
}
if (style & CClientUIInterface::ICON_ERROR) { if (style & CClientUIInterface::ICON_ERROR) {
nMBoxIcon = QMessageBox::Critical; nMBoxIcon = QMessageBox::Critical;
nNotifyIcon = Notificator::Critical; nNotifyIcon = Notificator::Critical;
} } else if (style & CClientUIInterface::ICON_WARNING) {
else if (style & CClientUIInterface::ICON_WARNING) {
nMBoxIcon = QMessageBox::Warning; nMBoxIcon = QMessageBox::Warning;
nNotifyIcon = Notificator::Warning; nNotifyIcon = Notificator::Warning;
} }
// Display message
if (style & CClientUIInterface::MODAL) { if (style & CClientUIInterface::MODAL) {
// Check for buttons, use OK as default, if none was supplied // Check for buttons, use OK as default, if none was supplied
QMessageBox::StandardButton buttons; QMessageBox::StandardButton buttons;
@ -1093,9 +1094,9 @@ void BitcoinGUI::message(const QString &title, const QString &message, unsigned
int r = mBox.exec(); int r = mBox.exec();
if (ret != nullptr) if (ret != nullptr)
*ret = r == QMessageBox::Ok; *ret = r == QMessageBox::Ok;
} } else {
else
notificator->notify(static_cast<Notificator::Class>(nNotifyIcon), strTitle, message); notificator->notify(static_cast<Notificator::Class>(nNotifyIcon), strTitle, message);
}
} }
void BitcoinGUI::changeEvent(QEvent *e) void BitcoinGUI::changeEvent(QEvent *e)

View file

@ -219,7 +219,7 @@ public Q_SLOTS:
@see CClientUIInterface::MessageBoxFlags @see CClientUIInterface::MessageBoxFlags
@param[in] ret pointer to a bool that will be modified to whether Ok was clicked (modal only) @param[in] ret pointer to a bool that will be modified to whether Ok was clicked (modal only)
*/ */
void message(const QString &title, const QString &message, unsigned int style, bool *ret = nullptr); void message(const QString& title, QString message, unsigned int style, bool* ret = nullptr);
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
void setCurrentWallet(WalletModel* wallet_model); void setCurrentWallet(WalletModel* wallet_model);