5#include <bitcoin-build-config.h>
36#include <chainparams.h>
42#include <validation.h>
45#include <QActionGroup>
46#include <QApplication>
50#include <QDragEnterEvent>
51#include <QInputDialog>
52#include <QKeySequence>
58#include <QProgressDialog>
62#include <QStackedWidget>
65#include <QSystemTrayIcon>
82#if defined(Q_OS_MACOS)
84#elif defined(Q_OS_WIN)
152 if (QSystemTrayIcon::isSystemTrayAvailable()) {
166 frameBlocks->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
206 progressBar->setStyleSheet(
"QProgressBar { background-color: #e8e8e8; border: 1px solid grey; border-radius: 7px; padding: 1px; text-align: center; } QProgressBar::chunk { background: QLinearGradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 #FF8000, stop: 1 orange); border-radius: 7px; margin: 0px; }");
273 receiveCoinsAction->setStatusTip(
tr(
"Request payments (generates QR codes and bitcoin: URIs)"));
290 connect(
overviewAction, &QAction::triggered,
this, &BitcoinGUI::gotoOverviewPage);
292 connect(
sendCoinsAction, &QAction::triggered, [
this]{ gotoSendCoinsPage(); });
294 connect(
receiveCoinsAction, &QAction::triggered,
this, &BitcoinGUI::gotoReceiveCoinsPage);
296 connect(
historyAction, &QAction::triggered,
this, &BitcoinGUI::gotoHistoryPage);
323 signMessageAction->setStatusTip(
tr(
"Sign messages with your Bitcoin addresses to prove you own them"));
325 verifyMessageAction->setStatusTip(
tr(
"Verify messages to ensure they were signed with specified Bitcoin addresses"));
382 m_export_watchonly_action->setStatusTip(
tr(
"Export a watch-only version of the current wallet that can be restored onto another node."));
400 connect(
signMessageAction, &QAction::triggered, [
this]{ gotoSignMessageTab(); });
407 connect(
openAction, &QAction::triggered,
this, &BitcoinGUI::openClicked);
410 for (
const auto& [path, info] : m_wallet_controller->listWalletDir()) {
411 const auto& [
loaded, format] = info;
418 name +=
" (needs migration)";
424 action->setEnabled(
false);
428 connect(
action, &QAction::triggered, [
this, path] {
437 action->setEnabled(
false);
456 QString wallet_name = QInputDialog::getText(
this, title, label, QLineEdit::Normal,
"", &
wallet_name_ok);
458 if (wallet_name.isEmpty()) {
459 QMessageBox::critical(
nullptr,
tr(
"Invalid Wallet Name"),
tr(
"Wallet name cannot be empty"));
475 m_wallet_controller->closeAllWallets(
this);
479 for (
const auto& [wallet_name, info] : m_wallet_controller->listWalletDir()) {
480 const auto& [
loaded, format] = info;
482 if (format !=
"bdb") {
492 connect(
action, &QAction::triggered, [
this, wallet_name] {
500 action->setEnabled(
false);
516 QString title =
tr(
"Restore and Migrate Wallet");
519 QString wallet_name = QInputDialog::getText(
this, title, label, QLineEdit::Normal,
"", &
wallet_name_ok);
533 tr(
"Save Watch-only Wallet Export"),
QString(),
537 if (destination.isEmpty())
return;
539 if (!
Assume(model))
return;
542 QMessageBox::information(
nullptr,
tr(
"Export Successful"),
tr(
"The wallet has been exported to ") + QString::fromStdString(*
export_res));
567 file->addSeparator();
571 file->addSeparator();
577 file->addSeparator();
597 QApplication::activeWindow()->showMinimized();
600 minimize_action->setEnabled(window !=
nullptr && (window->flags() & Qt::Dialog) != Qt::Dialog && window->windowState() != Qt::WindowMinimized);
607 if (window->windowState() != Qt::WindowMaximized) {
608 window->showMaximized();
610 window->showNormal();
644 help->addSeparator();
656 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
664 QWidget *
spacer =
new QWidget();
665 spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
758void BitcoinGUI::enableHistoryAction(
bool privacy)
768 assert(!m_wallet_controller);
784 m_wallet_controller =
nullptr;
793 return m_wallet_controller;
796void BitcoinGUI::addWallet(
WalletModel* walletModel)
825void BitcoinGUI::removeWallet(
WalletModel* walletModel)
860void BitcoinGUI::setCurrentWalletBySelectorIndex(
int index)
889 assert(QSystemTrayIcon::isSystemTrayAvailable());
892 if (QSystemTrayIcon::isSystemTrayAvailable()) {
936 connect(
trayIcon, &QSystemTrayIcon::activated, [
this](QSystemTrayIcon::ActivationReason reason) {
937 if (reason == QSystemTrayIcon::Trigger) {
958 if (m_node.shutdownRequested()) return;
960 if (show_hide_action) show_hide_action->setText(
961 (!isHidden() && !isMinimized() && !GUIUtil::isObscured(this)) ?
964 if (QApplication::activeModalWidget()) {
965 for (QAction* a : trayIconMenu.get()->actions()) {
966 a->setEnabled(false);
969 if (show_hide_action) show_hide_action->setEnabled(true);
971 send_action->setEnabled(sendCoinsAction->isEnabled());
972 receive_action->setEnabled(receiveCoinsAction->isEnabled());
973 sign_action->setEnabled(signMessageAction->isEnabled());
974 verify_action->setEnabled(verifyMessageAction->isEnabled());
1015void BitcoinGUI::openClicked()
1024void BitcoinGUI::gotoOverviewPage()
1030void BitcoinGUI::gotoHistoryPage()
1036void BitcoinGUI::gotoReceiveCoinsPage()
1042void BitcoinGUI::gotoSendCoinsPage(
QString addr)
1048void BitcoinGUI::gotoSignMessageTab(
QString addr)
1053void BitcoinGUI::gotoVerifyMessageTab(
QString addr)
1070 case 0:
icon =
":/icons/connect_0";
break;
1071 case 1:
case 2:
case 3:
icon =
":/icons/connect_1";
break;
1072 case 4:
case 5:
case 6:
icon =
":/icons/connect_2";
break;
1073 case 7:
case 8:
case 9:
icon =
":/icons/connect_3";
break;
1074 default:
icon =
":/icons/connect_4";
break;
1081 tooltip =
tr(
"%n active connection(s) to Bitcoin network.",
"",
count);
1084 tooltip =
tr(
"Network activity disabled.");
1085 icon =
":/icons/network_disabled";
1108 tr(
"Show Peers tab"),
1116 tr(
"Disable network activity") :
1118 tr(
"Enable network activity"),
1145 dlg->setCurrentTab(tab);
1209 tooltip =
tr(
"Processed %n block(s) of transaction history.",
"",
count);
1258 tooltip +=
tr(
"Transactions after this will not yet be visible.");
1284 int nMBoxIcon = QMessageBox::Information;
1288 if (!title.isEmpty()) {
1323 QMessageBox::StandardButton
buttons;
1329 mBox.setTextFormat(Qt::PlainText);
1331 int r =
mBox.exec();
1333 *
ret = r == QMessageBox::Ok;
1341 if (
e->type() == QEvent::PaletteChange) {
1348 QMainWindow::changeEvent(
e);
1351 if(
e->type() == QEvent::WindowStateChange)
1358 QTimer::singleShot(0,
this, &BitcoinGUI::hide);
1363 QTimer::singleShot(0,
this, &BitcoinGUI::show);
1385 QMainWindow::showMinimized();
1390 QMainWindow::closeEvent(event);
1406 QString msg =
tr(
"Date: %1\n").arg(date) +
1409 msg +=
tr(
"Wallet: %1\n").arg(walletName);
1411 msg +=
tr(
"Type: %1\n").arg(type);
1412 if (!label.isEmpty())
1413 msg +=
tr(
"Label: %1\n").arg(label);
1414 else if (!address.isEmpty())
1415 msg +=
tr(
"Address: %1\n").arg(address);
1416 message((amount)<0 ?
tr(
"Sent transaction") :
tr(
"Incoming transaction"),
1424 if(event->mimeData()->hasUrls())
1425 event->acceptProposedAction();
1430 if(event->mimeData()->hasUrls())
1432 for (
const QUrl &uri :
event->mimeData()->urls())
1437 event->acceptProposedAction();
1443 if (event->type() == QEvent::StatusTip)
1449 return QMainWindow::eventFilter(
object, event);
1459 gotoSendCoinsPage();
1472void BitcoinGUI::setEncryptionStatus(
int status)
1507void BitcoinGUI::updateWalletStatus()
1625 bool invoked = QMetaObject::invokeMethod(
gui,
"message",
1661 : m_platform_style{platformStyle}
1664 setToolTip(
tr(
"Unit to show amounts in. Click to select another unit."));
1684 if (
e->type() == QEvent::PaletteChange) {
1691 QLabel::changeEvent(
e);
1741#include <moc_bitcoingui.cpp>
int64_t CAmount
Amount in satoshis (Can be negative)
static bool ThreadSafeMessageBox(BitcoinGUI *gui, const bilingual_str &message, unsigned int style)
static constexpr int64_t MAX_BLOCK_TIME_GAP
Maximum gap between node time and block time used for the "Catching up..." mode in GUI.
const CChainParams & Params()
Return the currently selected parameters.
#define Assume(val)
Assume is the identity function.
void updateHeadersPresyncProgressLabel(int64_t height, const QDateTime &blockDate)
GUIUtil::ClickableProgressBar * progressBar
QAction * m_close_all_wallets_action
void showEvent(QShowEvent *event) override
QLabel * progressBarLabel
QAction * m_open_wallet_action
static const std::string DEFAULT_UIPLATFORM
QAction * m_export_watchonly_action
void createWallet()
Launch the wallet creation modal (no-op if wallet is not compiled)
void setNumBlocks(int count, const QDateTime &blockDate, double nVerificationProgress, SyncType synctype, SynchronizationState sync_state)
Set number of blocks and last block date shown in the UI.
void setClientModel(ClientModel *clientModel=nullptr, interfaces::BlockAndHeaderTipInfo *tip_info=nullptr)
Set the client model.
GUIUtil::ClickableLabel * connectionsControl
void receivedURI(const QString &uri)
Signal raised when a URI was entered or dragged to the GUI.
ModalOverlay * modalOverlay
GUIUtil::ThemedLabel * labelWalletEncryptionIcon
QAction * changePassphraseAction
void openOptionsDialogWithTab(OptionsDialog::Tab tab)
Open the OptionsDialog on the specified tab index.
int prevBlocks
Keep track of previous number of blocks, to detect progress.
QAction * openRPCConsoleAction
const NetworkStyle *const m_network_style
void changeEvent(QEvent *e) override
GUIUtil::ClickableLabel * labelProxyIcon
void optionsClicked()
Show configuration dialog.
bool eventFilter(QObject *object, QEvent *event) override
QMenu * m_open_wallet_menu
void createTrayIcon()
Create system tray icon and notification.
QAction * m_load_psbt_clipboard_action
void setNetworkActive(bool network_active)
Set network state shown in the UI.
void setPrivacy(bool privacy)
QProgressDialog * progressDialog
BitcoinGUI(interfaces::Node &node, const PlatformStyle *platformStyle, const NetworkStyle *networkStyle, QWidget *parent=nullptr)
std::unique_ptr< interfaces::Handler > m_handler_message_box
WalletFrame * walletFrame
void updateProxyIcon()
Set the proxy-enabled icon as shown in the UI.
QAction * m_restore_wallet_action
QAction * receiveCoinsAction
const std::unique_ptr< QMenu > trayIconMenu
QAction * usedSendingAddressesAction
void unsubscribeFromCoreSignals()
Disconnect core signals from GUI client.
void closeEvent(QCloseEvent *event) override
QAction * verifyMessageAction
QAction * m_migrate_wallet_action
void createTrayIconMenu()
Create system tray menu (or setup the dock menu)
HelpMessageDialog * helpMessageDialog
void aboutClicked()
Show about dialog.
void toggleHidden()
Simply calls showNormalIfMinimized(true)
QAction * encryptWalletAction
void updateNetworkState()
Update UI with latest network info from model.
void createActions()
Create the main UI actions.
void showDebugWindow()
Show debug window.
QAction * m_mask_values_action
void consoleShown(RPCConsole *console)
Signal raised when RPC console shown.
bool isPrivacyModeActivated() const
QMenu * m_migrate_wallet_menu
void showDebugWindowActivateConsole()
Show debug window and set focus to the console.
void dropEvent(QDropEvent *event) override
void showProgress(const QString &title, int nProgress)
Show progress dialog e.g.
QAction * usedReceivingAddressesAction
void subscribeToCoreSignals()
Connect core signals to GUI client.
void createToolBars()
Create the toolbars.
UnitDisplayStatusBarControl * unitDisplayControl
void setWalletActionsEnabled(bool enabled)
Enable or disable all wallet-related actions.
const PlatformStyle * platformStyle
void dragEnterEvent(QDragEnterEvent *event) override
QAction * m_close_wallet_action
GUIUtil::ClickableLabel * labelBlocksIcon
interfaces::Node & m_node
QAction * m_create_wallet_action
QAction * m_load_psbt_action
void detectShutdown()
called by a timer to check if shutdown has been requested
QMenu * m_network_context_menu
QAction * backupWalletAction
QAction * showHelpMessageAction
void showNormalIfMinimized()
Show window if hidden, unminimize when minimized, rise when obscured or show if hidden and fToggleHid...
ClientModel * clientModel
void updateHeadersSyncProgressLabel()
void createMenuBar()
Create the menu bar and sub-menus.
QSystemTrayIcon * trayIcon
void message(const QString &title, QString message, unsigned int style, bool *ret=nullptr, const QString &detailed_message=QString())
Notify the user of an event from the core network or transaction handling code.
void showHelpMessageClicked()
Show help message dialog.
QAction * sendCoinsAction
void setNumConnections(int count)
Set number of connections shown in the UI.
QAction * signMessageAction
GUIUtil::ThemedLabel * labelWalletHDStatusIcon
Notificator * notificator
std::unique_ptr< interfaces::Handler > m_handler_question
static QList< Unit > availableUnits()
Get list of units, for drop-down box.
static QString longName(Unit unit)
Long name.
static QString formatWithUnit(Unit unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD)
Format as string (with unit)
const Consensus::Params & GetConsensus() const
Signals for UI communication.
@ BTN_MASK
Mask of all available buttons in CClientUIInterface::MessageBoxFlags This needs to be updated,...
@ MSG_INFORMATION
Predefined combinations for certain default usage cases.
@ MODAL
Force blocking, modal message box dialog (not just OS notification)
Model for Bitcoin network client.
void showProgress(const QString &title, int nProgress)
int getHeaderTipHeight() const
void message(const QString &title, const QString &message, unsigned int style)
Fired when a message should be reported to the user.
void numConnectionsChanged(int count)
BlockSource getBlockSource() const
Returns the block source of the current importing/syncing state.
int64_t getHeaderTipTime() const
int getNumConnections(unsigned int flags=CONNECTIONS_ALL) const
Return number of connections, default is in- and outbound (total)
void numBlocksChanged(int count, const QDateTime &blockDate, double nVerificationProgress, SyncType header, SynchronizationState sync_state)
OptionsModel * getOptionsModel()
bool getProxyInfo(std::string &ip_port) const
void networkActiveChanged(bool networkActive)
void created(WalletModel *wallet_model)
void clicked(const QPoint &point)
Emitted when the label is clicked.
void clicked(const QPoint &point)
Emitted when the progressbar is clicked.
void setThemedPixmap(const QString &image_filename, int width, int height)
"Help message" dialog box
macOS-specific Dock icon handler.
static MacDockIconHandler * instance()
void migrated(WalletModel *wallet_model)
Modal overlay to display information about the chain-sync state.
void showHide(bool hide=false, bool userRequested=false)
void tipUpdate(int count, const QDateTime &blockDate, double nVerificationProgress)
void triggered(bool hidden)
bool isLayerVisible() const
void setKnownBestHeight(int count, const QDateTime &blockDate, bool presync)
const QIcon & getTrayAndWindowIcon() const
const QString & getTitleAddText() const
Cross-platform desktop notification client.
@ Information
Informational message.
@ Critical
An error occurred.
@ Warning
Notify user of potential problem.
void notify(Class cls, const QString &title, const QString &text, const QIcon &icon=QIcon(), int millisTimeout=10000)
Show notification message.
void opened(WalletModel *wallet_model)
Interface from Qt to configuration data structure for Bitcoin client.
void displayUnitChanged(BitcoinUnit unit)
void showTrayIconChanged(bool)
bool getMinimizeToTray() const
bool getShowTrayIcon() const
bool getMinimizeOnClose() const
void setDisplayUnit(const QVariant &new_unit)
Updates current unit in memory, settings and emits displayUnitChanged(new_unit) signal.
Local Bitcoin RPC console.
std::vector< TabTypes > tabs() const
QString tabTitle(TabTypes tab_type) const
QKeySequence tabShortcut(TabTypes tab_type) const
void setClientModel(ClientModel *model=nullptr, int bestblock_height=0, int64_t bestblock_date=0, double verification_progress=0.0)
void setTabFocus(enum TabTypes tabType)
set which tab has the focus (is visible)
void restored(WalletModel *wallet_model)
void changeEvent(QEvent *e) override
void mousePressEvent(QMouseEvent *event) override
So that it responds to left-button clicks.
void createContextMenu()
Creates context menu, its actions, and wires up all the relevant signals for mouse events.
void updateDisplayUnit(BitcoinUnit newUnits)
When Display Units are changed on OptionsModel it will refresh the display text of the control on the...
OptionsModel * optionsModel
UnitDisplayStatusBarControl(const PlatformStyle *platformStyle)
void onMenuSelection(QAction *action)
Tells underlying optionsModel to update its current display unit.
const PlatformStyle * m_platform_style
void setOptionsModel(OptionsModel *optionsModel)
Lets the control know about the Options Model (and its signals)
void onDisplayUnitsClicked(const QPoint &point)
Shows context menu with Display Unit options by the mouse coordinates.
Controller between interfaces::Node, WalletModel instances and the GUI.
void walletAdded(WalletModel *wallet_model)
void walletRemoved(WalletModel *wallet_model)
A container for embedding all wallet-related controls into BitcoinGUI.
bool addView(WalletView *walletView)
void changePassphrase()
Change encrypted wallet passphrase.
WalletModel * currentWalletModel() const
void gotoHistoryPage()
Switch to history (transactions) page.
void gotoSignMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to sign message tab.
WalletView * currentWalletView() const
void gotoOverviewPage()
Switch to overview (home) page.
void gotoSendCoinsPage(QString addr="")
Switch to send coins page.
void removeWallet(WalletModel *wallet_model)
void setClientModel(ClientModel *clientModel)
void backupWallet()
Backup the wallet.
void usedSendingAddresses()
Show used sending addresses.
void createWalletButtonClicked()
void encryptWallet()
Encrypt the wallet.
void usedReceivingAddresses()
Show used receiving addresses.
void message(const QString &title, const QString &message, unsigned int style)
void setCurrentWallet(WalletModel *wallet_model)
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
void gotoLoadPSBT(bool from_clipboard=false)
Load Partially Signed Bitcoin Transaction.
void showOutOfSyncWarning(bool fShow)
void gotoReceiveCoinsPage()
Switch to receive coins page.
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
Interface to Bitcoin wallet from Qt view code.
EncryptionStatus getEncryptionStatus() const
interfaces::Wallet & wallet() const
QString getDisplayName() const
static bool isWalletEnabled()
void outOfSyncWarningClicked()
Notify that the out of sync warning icon has been pressed.
void message(const QString &title, const QString &message, unsigned int style)
Fired when a message should be reported to the user.
void incomingTransaction(const QString &date, BitcoinUnit unit, const CAmount &amount, const QString &type, const QString &address, const QString &label, const QString &walletName)
Notify that a new transaction appeared.
void transactionClicked()
void setPrivacy(bool privacy)
void encryptionStatusChanged()
Encryption status of wallet changed.
Top-level interface for a bitcoin node (bitcoind process).
virtual void setNetworkActive(bool active)=0
Set network active.
virtual std::unique_ptr< Handler > handleMessageBox(MessageBoxFn fn)=0
virtual bool getNetworkActive()=0
Get network active.
virtual std::unique_ptr< Handler > handleQuestion(QuestionFn fn)=0
virtual WalletLoader & walletLoader()=0
Get wallet loader.
virtual bool shutdownRequested()=0
Return whether shutdown was requested.
virtual util::Result< std::string > exportWatchOnlyWallet(const fs::path &destination)=0
Export a watchonly wallet file. See CWallet::ExportWatchOnlyWallet.
virtual bool hdEnabled()=0
virtual bool privateKeysDisabled()=0
virtual std::vector< std::unique_ptr< Wallet > > getWallets()=0
Return interfaces for accessing wallets (if any).
static path PathFromString(const std::string &string)
Convert byte string to path object.
constexpr int STATUSBAR_ICONSIZE
constexpr int HEADER_HEIGHT_DELTA_SYNC
The required delta of headers to the estimated number of available headers until we show the IBD prog...
bool isObscured(QWidget *w)
Qt::ConnectionType blockingGUIThreadConnection()
Get connection type to call object slot in GUI thread with invokeMethod.
QString WalletDisplayName(const QString &name)
void PopupMenu(QMenu *menu, const QPoint &point, QAction *at_action)
Call QMenu::popup() only on supported QT_QPA_PLATFORM.
void ShowModalDialogAsynchronously(QDialog *dialog)
Shows a QDialog instance asynchronously, and deletes it on close.
void handleCloseWindowShortcut(QWidget *w)
void PolishProgressDialog(QProgressDialog *dialog)
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedSuffixOut)
Get open filename, convenience wrapper for QFileDialog::getOpenFileName.
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedSuffixOut)
Get save filename, mimics QFileDialog::getSaveFileName, except that it appends a default suffix when ...
ClickableProgressBar ProgressBar
void bringToFront(QWidget *w)
bool HasPixmap(const QLabel *label)
Returns true if pixmap has been set.
QString formatNiceTimeOffset(qint64 secs)
auto ExceptionSafeConnect(Sender sender, Signal signal, Receiver receiver, Slot method, Qt::ConnectionType type=Qt::AutoConnection)
A drop-in replacement of QObject::connect function (see: https://doc.qt.io/qt-5/qobject....
int TextWidth(const QFontMetrics &fm, const QString &text)
Returns the distance in pixels appropriate for drawing a subsequent character after text.
fs::path QStringToPath(const QString &path)
Convert QString to OS specific boost path through UTF-8.
bilingual_str ErrorString(const Result< T > &result)
int64_t nPowTargetSpacing
Block and header tip information.
int64_t GetTime()
DEPRECATED Use either ClockType::now() or Now<TimePointType>() if a cast is needed.
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
SynchronizationState
Current sync state passed to tip changed callbacks.