Changeset View
Changeset View
Standalone View
Standalone View
src/qt/bitcoingui.cpp
Show First 20 Lines • Show All 784 Lines • ▼ Show 20 Lines | void BitcoinGUI::setNetworkActive(bool networkActive) { | ||||
updateNetworkState(); | updateNetworkState(); | ||||
} | } | ||||
void BitcoinGUI::updateHeadersSyncProgressLabel() { | void BitcoinGUI::updateHeadersSyncProgressLabel() { | ||||
int64_t headersTipTime = clientModel->getHeaderTipTime(); | int64_t headersTipTime = clientModel->getHeaderTipTime(); | ||||
int headersTipHeight = clientModel->getHeaderTipHeight(); | int headersTipHeight = clientModel->getHeaderTipHeight(); | ||||
int estHeadersLeft = (GetTime() - headersTipTime) / | int estHeadersLeft = (GetTime() - headersTipTime) / | ||||
Params().GetConsensus().nPowTargetSpacing; | Params().GetConsensus().nPowTargetSpacing; | ||||
if (estHeadersLeft > HEADER_HEIGHT_DELTA_SYNC) | if (estHeadersLeft > HEADER_HEIGHT_DELTA_SYNC) { | ||||
progressBarLabel->setText( | progressBarLabel->setText( | ||||
tr("Syncing Headers (%1%)...") | tr("Syncing Headers (%1%)...") | ||||
.arg(QString::number(100.0 / | .arg(QString::number(100.0 / | ||||
(headersTipHeight + estHeadersLeft) * | (headersTipHeight + estHeadersLeft) * | ||||
headersTipHeight, | headersTipHeight, | ||||
'f', 1))); | 'f', 1))); | ||||
} | } | ||||
} | |||||
void BitcoinGUI::setNumBlocks(int count, const QDateTime &blockDate, | void BitcoinGUI::setNumBlocks(int count, const QDateTime &blockDate, | ||||
double nVerificationProgress, bool header) { | double nVerificationProgress, bool header) { | ||||
if (modalOverlay) { | if (modalOverlay) { | ||||
if (header) | if (header) { | ||||
modalOverlay->setKnownBestHeight(count, blockDate); | modalOverlay->setKnownBestHeight(count, blockDate); | ||||
else | } else { | ||||
modalOverlay->tipUpdate(count, blockDate, nVerificationProgress); | modalOverlay->tipUpdate(count, blockDate, nVerificationProgress); | ||||
} | } | ||||
if (!clientModel) return; | } | ||||
if (!clientModel) { | |||||
return; | |||||
} | |||||
// Prevent orphan statusbar messages (e.g. hover Quit in main menu, wait | // Prevent orphan statusbar messages (e.g. hover Quit in main menu, wait | ||||
// until chain-sync starts -> garbled text) | // until chain-sync starts -> garbled text) | ||||
statusBar()->clearMessage(); | statusBar()->clearMessage(); | ||||
// Acquire current block source | // Acquire current block source | ||||
enum BlockSource blockSource = clientModel->getBlockSource(); | enum BlockSource blockSource = clientModel->getBlockSource(); | ||||
switch (blockSource) { | switch (blockSource) { | ||||
▲ Show 20 Lines • Show All 112 Lines • ▼ Show 20 Lines | if (!title.isEmpty()) { | ||||
case CClientUIInterface::MSG_INFORMATION: | case CClientUIInterface::MSG_INFORMATION: | ||||
msgType = tr("Information"); | msgType = tr("Information"); | ||||
break; | break; | ||||
default: | default: | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
// Append title to "Bitcoin - " | // Append title to "Bitcoin - " | ||||
if (!msgType.isEmpty()) strTitle += " - " + msgType; | if (!msgType.isEmpty()) { | ||||
strTitle += " - " + msgType; | |||||
} | |||||
// Check for error/warning icon | // Check for error/warning icon | ||||
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 | // 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; | ||||
if (!(buttons = (QMessageBox::StandardButton)( | if (!(buttons = (QMessageBox::StandardButton)( | ||||
style & CClientUIInterface::BTN_MASK))) | style & CClientUIInterface::BTN_MASK))) | ||||
buttons = QMessageBox::Ok; | buttons = QMessageBox::Ok; | ||||
showNormalIfMinimized(); | showNormalIfMinimized(); | ||||
QMessageBox mBox((QMessageBox::Icon)nMBoxIcon, strTitle, message, | QMessageBox mBox((QMessageBox::Icon)nMBoxIcon, strTitle, message, | ||||
buttons, this); | buttons, this); | ||||
int r = mBox.exec(); | int r = mBox.exec(); | ||||
if (ret != nullptr) *ret = r == QMessageBox::Ok; | if (ret != nullptr) { | ||||
*ret = r == QMessageBox::Ok; | |||||
} | |||||
} else | } else | ||||
notificator->notify((Notificator::Class)nNotifyIcon, strTitle, message); | notificator->notify((Notificator::Class)nNotifyIcon, strTitle, message); | ||||
} | } | ||||
void BitcoinGUI::changeEvent(QEvent *e) { | void BitcoinGUI::changeEvent(QEvent *e) { | ||||
QMainWindow::changeEvent(e); | QMainWindow::changeEvent(e); | ||||
#ifndef Q_OS_MAC // Ignored on Mac | #ifndef Q_OS_MAC // Ignored on Mac | ||||
if (e->type() == QEvent::WindowStateChange) { | if (e->type() == QEvent::WindowStateChange) { | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | void BitcoinGUI::incomingTransaction(const QString &date, int unit, | ||||
const Amount amount, const QString &type, | const Amount amount, const QString &type, | ||||
const QString &address, | const QString &address, | ||||
const QString &label) { | const QString &label) { | ||||
// On new transaction, make an info balloon | // On new transaction, make an info balloon | ||||
QString msg = tr("Date: %1\n").arg(date) + | QString msg = tr("Date: %1\n").arg(date) + | ||||
tr("Amount: %1\n") | tr("Amount: %1\n") | ||||
.arg(BitcoinUnits::formatWithUnit(unit, amount, true)) + | .arg(BitcoinUnits::formatWithUnit(unit, amount, true)) + | ||||
tr("Type: %1\n").arg(type); | tr("Type: %1\n").arg(type); | ||||
if (!label.isEmpty()) | if (!label.isEmpty()) { | ||||
msg += tr("Label: %1\n").arg(label); | msg += tr("Label: %1\n").arg(label); | ||||
else if (!address.isEmpty()) | } else if (!address.isEmpty()) { | ||||
msg += tr("Address: %1\n").arg(address); | msg += tr("Address: %1\n").arg(address); | ||||
} | |||||
message(amount < Amount::zero() ? tr("Sent transaction") | message(amount < Amount::zero() ? tr("Sent transaction") | ||||
: tr("Incoming transaction"), | : tr("Incoming transaction"), | ||||
msg, CClientUIInterface::MSG_INFORMATION); | msg, CClientUIInterface::MSG_INFORMATION); | ||||
} | } | ||||
#endif // ENABLE_WALLET | #endif // ENABLE_WALLET | ||||
void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event) { | void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event) { | ||||
// Accept only URIs | // Accept only URIs | ||||
if (event->mimeData()->hasUrls()) event->acceptProposedAction(); | if (event->mimeData()->hasUrls()) { | ||||
event->acceptProposedAction(); | |||||
} | |||||
} | } | ||||
void BitcoinGUI::dropEvent(QDropEvent *event) { | void BitcoinGUI::dropEvent(QDropEvent *event) { | ||||
if (event->mimeData()->hasUrls()) { | if (event->mimeData()->hasUrls()) { | ||||
for (const QUrl &uri : event->mimeData()->urls()) { | for (const QUrl &uri : event->mimeData()->urls()) { | ||||
Q_EMIT receivedURI(uri.toString()); | Q_EMIT receivedURI(uri.toString()); | ||||
} | } | ||||
} | } | ||||
event->acceptProposedAction(); | event->acceptProposedAction(); | ||||
} | } | ||||
bool BitcoinGUI::eventFilter(QObject *object, QEvent *event) { | bool BitcoinGUI::eventFilter(QObject *object, QEvent *event) { | ||||
// Catch status tip events | // Catch status tip events | ||||
if (event->type() == QEvent::StatusTip) { | if (event->type() == QEvent::StatusTip) { | ||||
// Prevent adding text from setStatusTip(), if we currently use the | // Prevent adding text from setStatusTip(), if we currently use the | ||||
// status bar for displaying other stuff | // status bar for displaying other stuff | ||||
if (progressBarLabel->isVisible() || progressBar->isVisible()) | if (progressBarLabel->isVisible() || progressBar->isVisible()) { | ||||
return true; | return true; | ||||
} | } | ||||
} | |||||
return QMainWindow::eventFilter(object, event); | return QMainWindow::eventFilter(object, event); | ||||
} | } | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
bool BitcoinGUI::handlePaymentRequest(const SendCoinsRecipient &recipient) { | bool BitcoinGUI::handlePaymentRequest(const SendCoinsRecipient &recipient) { | ||||
// URI has to be valid | // URI has to be valid | ||||
if (walletFrame && walletFrame->handlePaymentRequest(recipient)) { | if (walletFrame && walletFrame->handlePaymentRequest(recipient)) { | ||||
showNormalIfMinimized(); | showNormalIfMinimized(); | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | switch (status) { | ||||
encryptWalletAction->setEnabled( | encryptWalletAction->setEnabled( | ||||
false); // TODO: decrypt currently not supported | false); // TODO: decrypt currently not supported | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
#endif // ENABLE_WALLET | #endif // ENABLE_WALLET | ||||
void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden) { | void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden) { | ||||
if (!clientModel) return; | if (!clientModel) { | ||||
return; | |||||
} | |||||
// activateWindow() (sometimes) helps with keyboard focus on Windows | // activateWindow() (sometimes) helps with keyboard focus on Windows | ||||
if (isHidden()) { | if (isHidden()) { | ||||
show(); | show(); | ||||
activateWindow(); | activateWindow(); | ||||
} else if (isMinimized()) { | } else if (isMinimized()) { | ||||
showNormal(); | showNormal(); | ||||
activateWindow(); | activateWindow(); | ||||
} else if (GUIUtil::isObscured(this)) { | } else if (GUIUtil::isObscured(this)) { | ||||
raise(); | raise(); | ||||
activateWindow(); | activateWindow(); | ||||
} else if (fToggleHidden) | } else if (fToggleHidden) { | ||||
hide(); | hide(); | ||||
} | } | ||||
} | |||||
void BitcoinGUI::toggleHidden() { | void BitcoinGUI::toggleHidden() { | ||||
showNormalIfMinimized(true); | showNormalIfMinimized(true); | ||||
} | } | ||||
void BitcoinGUI::detectShutdown() { | void BitcoinGUI::detectShutdown() { | ||||
if (ShutdownRequested()) { | if (ShutdownRequested()) { | ||||
if (rpcConsole) rpcConsole->hide(); | if (rpcConsole) { | ||||
rpcConsole->hide(); | |||||
} | |||||
qApp->quit(); | qApp->quit(); | ||||
} | } | ||||
} | } | ||||
void BitcoinGUI::showProgress(const QString &title, int nProgress) { | void BitcoinGUI::showProgress(const QString &title, int nProgress) { | ||||
if (nProgress == 0) { | if (nProgress == 0) { | ||||
progressDialog = new QProgressDialog(title, "", 0, 100); | progressDialog = new QProgressDialog(title, "", 0, 100); | ||||
progressDialog->setWindowModality(Qt::ApplicationModal); | progressDialog->setWindowModality(Qt::ApplicationModal); | ||||
progressDialog->setMinimumDuration(0); | progressDialog->setMinimumDuration(0); | ||||
progressDialog->setCancelButton(0); | progressDialog->setCancelButton(0); | ||||
progressDialog->setAutoClose(false); | progressDialog->setAutoClose(false); | ||||
progressDialog->setValue(0); | progressDialog->setValue(0); | ||||
} else if (nProgress == 100) { | } else if (progressDialog) { | ||||
if (progressDialog) { | if (nProgress == 100) { | ||||
progressDialog->close(); | progressDialog->close(); | ||||
progressDialog->deleteLater(); | progressDialog->deleteLater(); | ||||
} | } else { | ||||
} else if (progressDialog) | |||||
progressDialog->setValue(nProgress); | progressDialog->setValue(nProgress); | ||||
} | } | ||||
} | |||||
} | |||||
void BitcoinGUI::setTrayIconVisible(bool fHideTrayIcon) { | void BitcoinGUI::setTrayIconVisible(bool fHideTrayIcon) { | ||||
if (trayIcon) { | if (trayIcon) { | ||||
trayIcon->setVisible(!fHideTrayIcon); | trayIcon->setVisible(!fHideTrayIcon); | ||||
} | } | ||||
} | } | ||||
void BitcoinGUI::showModalOverlay() { | void BitcoinGUI::showModalOverlay() { | ||||
if (modalOverlay && | if (modalOverlay && | ||||
(progressBar->isVisible() || modalOverlay->isLayerVisible())) | (progressBar->isVisible() || modalOverlay->isLayerVisible())) { | ||||
modalOverlay->toggleVisibility(); | modalOverlay->toggleVisibility(); | ||||
} | } | ||||
} | |||||
static bool ThreadSafeMessageBox(BitcoinGUI *gui, const std::string &message, | static bool ThreadSafeMessageBox(BitcoinGUI *gui, const std::string &message, | ||||
const std::string &caption, | const std::string &caption, | ||||
unsigned int style) { | unsigned int style) { | ||||
bool modal = (style & CClientUIInterface::MODAL); | bool modal = (style & CClientUIInterface::MODAL); | ||||
// The SECURE flag has no effect in the Qt GUI. | // The SECURE flag has no effect in the Qt GUI. | ||||
// bool secure = (style & CClientUIInterface::SECURE); | // bool secure = (style & CClientUIInterface::SECURE); | ||||
style &= ~CClientUIInterface::SECURE; | style &= ~CClientUIInterface::SECURE; | ||||
▲ Show 20 Lines • Show All 103 Lines • Show Last 20 Lines |