Bitcoin Core  26.1.0
P2P Digital Currency
bitcoingui.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2022 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <qt/bitcoingui.h>
6 
7 #include <qt/bitcoinunits.h>
8 #include <qt/clientmodel.h>
10 #include <qt/guiconstants.h>
11 #include <qt/guiutil.h>
12 #include <qt/modaloverlay.h>
13 #include <qt/networkstyle.h>
14 #include <qt/notificator.h>
15 #include <qt/openuridialog.h>
16 #include <qt/optionsdialog.h>
17 #include <qt/optionsmodel.h>
18 #include <qt/platformstyle.h>
19 #include <qt/rpcconsole.h>
20 #include <qt/utilitydialog.h>
21 
22 #ifdef ENABLE_WALLET
23 #include <qt/walletcontroller.h>
24 #include <qt/walletframe.h>
25 #include <qt/walletmodel.h>
26 #include <qt/walletview.h>
27 #endif // ENABLE_WALLET
28 
29 #ifdef Q_OS_MACOS
30 #include <qt/macdockiconhandler.h>
31 #endif
32 
33 #include <chain.h>
34 #include <chainparams.h>
35 #include <common/system.h>
36 #include <interfaces/handler.h>
37 #include <interfaces/node.h>
38 #include <node/interface_ui.h>
39 #include <util/translation.h>
40 #include <validation.h>
41 
42 #include <functional>
43 
44 #include <QAction>
45 #include <QActionGroup>
46 #include <QApplication>
47 #include <QComboBox>
48 #include <QCursor>
49 #include <QDateTime>
50 #include <QDragEnterEvent>
51 #include <QInputDialog>
52 #include <QKeySequence>
53 #include <QListWidget>
54 #include <QMenu>
55 #include <QMenuBar>
56 #include <QMessageBox>
57 #include <QMimeData>
58 #include <QProgressDialog>
59 #include <QScreen>
60 #include <QSettings>
61 #include <QShortcut>
62 #include <QStackedWidget>
63 #include <QStatusBar>
64 #include <QStyle>
65 #include <QSystemTrayIcon>
66 #include <QTimer>
67 #include <QToolBar>
68 #include <QUrlQuery>
69 #include <QVBoxLayout>
70 #include <QWindow>
71 
72 
73 const std::string BitcoinGUI::DEFAULT_UIPLATFORM =
74 #if defined(Q_OS_MACOS)
75  "macosx"
76 #elif defined(Q_OS_WIN)
77  "windows"
78 #else
79  "other"
80 #endif
81  ;
82 
83 BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformStyle, const NetworkStyle *networkStyle, QWidget *parent) :
84  QMainWindow(parent),
85  m_node(node),
86  trayIconMenu{new QMenu()},
87  platformStyle(_platformStyle),
88  m_network_style(networkStyle)
89 {
90  QSettings settings;
91  if (!restoreGeometry(settings.value("MainWindowGeometry").toByteArray())) {
92  // Restore failed (perhaps missing setting), center the window
93  move(QGuiApplication::primaryScreen()->availableGeometry().center() - frameGeometry().center());
94  }
95 
96  setContextMenuPolicy(Qt::PreventContextMenu);
97 
98 #ifdef ENABLE_WALLET
99  enableWallet = WalletModel::isWalletEnabled();
100 #endif // ENABLE_WALLET
101  QApplication::setWindowIcon(m_network_style->getTrayAndWindowIcon());
102  setWindowIcon(m_network_style->getTrayAndWindowIcon());
103  updateWindowTitle();
104 
105  rpcConsole = new RPCConsole(node, _platformStyle, nullptr);
106  helpMessageDialog = new HelpMessageDialog(this, false);
107 #ifdef ENABLE_WALLET
108  if(enableWallet)
109  {
111  walletFrame = new WalletFrame(_platformStyle, this);
113  connect(walletFrame, &WalletFrame::message, [this](const QString& title, const QString& message, unsigned int style) {
114  this->message(title, message, style);
115  });
116  connect(walletFrame, &WalletFrame::currentWalletSet, [this] { updateWalletStatus(); });
117  setCentralWidget(walletFrame);
118  } else
119 #endif // ENABLE_WALLET
120  {
121  /* When compiled without wallet or -disablewallet is provided,
122  * the central widget is the rpc console.
123  */
124  setCentralWidget(rpcConsole);
125  Q_EMIT consoleShown(rpcConsole);
126  }
127 
128  modalOverlay = new ModalOverlay(enableWallet, this->centralWidget());
129 
130  // Accept D&D of URIs
131  setAcceptDrops(true);
132 
133  // Create actions for the toolbar, menu bar and tray/dock icon
134  // Needs walletFrame to be initialized
135  createActions();
136 
137  // Create application menu bar
138  createMenuBar();
139 
140  // Create the toolbars
141  createToolBars();
142 
143  // Create system tray icon and notification
144  if (QSystemTrayIcon::isSystemTrayAvailable()) {
145  createTrayIcon();
146  }
147  notificator = new Notificator(QApplication::applicationName(), trayIcon, this);
148 
149  // Create status bar
150  statusBar();
151 
152  // Disable size grip because it looks ugly and nobody needs it
153  statusBar()->setSizeGripEnabled(false);
154 
155  // Status bar notification icons
156  QFrame *frameBlocks = new QFrame();
157  frameBlocks->setContentsMargins(0,0,0,0);
158  frameBlocks->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
159  QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);
160  frameBlocksLayout->setContentsMargins(3,0,3,0);
161  frameBlocksLayout->setSpacing(3);
162  unitDisplayControl = new UnitDisplayStatusBarControl(platformStyle);
163  labelWalletEncryptionIcon = new GUIUtil::ThemedLabel(platformStyle);
164  labelWalletHDStatusIcon = new GUIUtil::ThemedLabel(platformStyle);
165  labelProxyIcon = new GUIUtil::ClickableLabel(platformStyle);
166  connectionsControl = new GUIUtil::ClickableLabel(platformStyle);
167  labelBlocksIcon = new GUIUtil::ClickableLabel(platformStyle);
168  if(enableWallet)
169  {
170  frameBlocksLayout->addStretch();
171  frameBlocksLayout->addWidget(unitDisplayControl);
172  frameBlocksLayout->addStretch();
173  frameBlocksLayout->addWidget(labelWalletEncryptionIcon);
174  labelWalletEncryptionIcon->hide();
175  frameBlocksLayout->addWidget(labelWalletHDStatusIcon);
176  labelWalletHDStatusIcon->hide();
177  }
178  frameBlocksLayout->addWidget(labelProxyIcon);
179  frameBlocksLayout->addStretch();
180  frameBlocksLayout->addWidget(connectionsControl);
181  frameBlocksLayout->addStretch();
182  frameBlocksLayout->addWidget(labelBlocksIcon);
183  frameBlocksLayout->addStretch();
184 
185  // Progress bar and label for blocks download
186  progressBarLabel = new QLabel();
187  progressBarLabel->setVisible(false);
188  progressBar = new GUIUtil::ProgressBar();
189  progressBar->setAlignment(Qt::AlignCenter);
190  progressBar->setVisible(false);
191 
192  // Override style sheet for progress bar for styles that have a segmented progress bar,
193  // as they make the text unreadable (workaround for issue #1071)
194  // See https://doc.qt.io/qt-5/gallery.html
195  QString curStyle = QApplication::style()->metaObject()->className();
196  if(curStyle == "QWindowsStyle" || curStyle == "QWindowsXPStyle")
197  {
198  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; }");
199  }
200 
201  statusBar()->addWidget(progressBarLabel);
202  statusBar()->addWidget(progressBar);
203  statusBar()->addPermanentWidget(frameBlocks);
204 
205  // Install event filter to be able to catch status tip events (QEvent::StatusTip)
206  this->installEventFilter(this);
207 
208  // Initially wallet actions should be disabled
209  setWalletActionsEnabled(false);
210 
211  // Subscribe to notifications from core
212  subscribeToCoreSignals();
213 
214  connect(labelProxyIcon, &GUIUtil::ClickableLabel::clicked, [this] {
215  openOptionsDialogWithTab(OptionsDialog::TAB_NETWORK);
216  });
217 
218  connect(labelBlocksIcon, &GUIUtil::ClickableLabel::clicked, this, &BitcoinGUI::showModalOverlay);
220 
221 #ifdef Q_OS_MACOS
222  m_app_nap_inhibitor = new CAppNapInhibitor;
223 #endif
224 
226 }
227 
229 {
230  // Unsubscribe from notifications from core
232 
233  QSettings settings;
234  settings.setValue("MainWindowGeometry", saveGeometry());
235  if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu)
236  trayIcon->hide();
237 #ifdef Q_OS_MACOS
238  delete m_app_nap_inhibitor;
240 #endif
241 
242  delete rpcConsole;
243 }
244 
246 {
247  QActionGroup *tabGroup = new QActionGroup(this);
248  connect(modalOverlay, &ModalOverlay::triggered, tabGroup, &QActionGroup::setEnabled);
249 
250  overviewAction = new QAction(platformStyle->SingleColorIcon(":/icons/overview"), tr("&Overview"), this);
251  overviewAction->setStatusTip(tr("Show general overview of wallet"));
252  overviewAction->setToolTip(overviewAction->statusTip());
253  overviewAction->setCheckable(true);
254  overviewAction->setShortcut(QKeySequence(QStringLiteral("Alt+1")));
255  tabGroup->addAction(overviewAction);
256 
257  sendCoinsAction = new QAction(platformStyle->SingleColorIcon(":/icons/send"), tr("&Send"), this);
258  sendCoinsAction->setStatusTip(tr("Send coins to a Bitcoin address"));
259  sendCoinsAction->setToolTip(sendCoinsAction->statusTip());
260  sendCoinsAction->setCheckable(true);
261  sendCoinsAction->setShortcut(QKeySequence(QStringLiteral("Alt+2")));
262  tabGroup->addAction(sendCoinsAction);
263 
264  receiveCoinsAction = new QAction(platformStyle->SingleColorIcon(":/icons/receiving_addresses"), tr("&Receive"), this);
265  receiveCoinsAction->setStatusTip(tr("Request payments (generates QR codes and bitcoin: URIs)"));
266  receiveCoinsAction->setToolTip(receiveCoinsAction->statusTip());
267  receiveCoinsAction->setCheckable(true);
268  receiveCoinsAction->setShortcut(QKeySequence(QStringLiteral("Alt+3")));
269  tabGroup->addAction(receiveCoinsAction);
270 
271  historyAction = new QAction(platformStyle->SingleColorIcon(":/icons/history"), tr("&Transactions"), this);
272  historyAction->setStatusTip(tr("Browse transaction history"));
273  historyAction->setToolTip(historyAction->statusTip());
274  historyAction->setCheckable(true);
275  historyAction->setShortcut(QKeySequence(QStringLiteral("Alt+4")));
276  tabGroup->addAction(historyAction);
277 
278 #ifdef ENABLE_WALLET
279  // These showNormalIfMinimized are needed because Send Coins and Receive Coins
280  // can be triggered from the tray menu, and need to show the GUI to be useful.
281  connect(overviewAction, &QAction::triggered, [this]{ showNormalIfMinimized(); });
282  connect(overviewAction, &QAction::triggered, this, &BitcoinGUI::gotoOverviewPage);
283  connect(sendCoinsAction, &QAction::triggered, [this]{ showNormalIfMinimized(); });
284  connect(sendCoinsAction, &QAction::triggered, [this]{ gotoSendCoinsPage(); });
285  connect(receiveCoinsAction, &QAction::triggered, [this]{ showNormalIfMinimized(); });
286  connect(receiveCoinsAction, &QAction::triggered, this, &BitcoinGUI::gotoReceiveCoinsPage);
287  connect(historyAction, &QAction::triggered, [this]{ showNormalIfMinimized(); });
288  connect(historyAction, &QAction::triggered, this, &BitcoinGUI::gotoHistoryPage);
289 #endif // ENABLE_WALLET
290 
291  quitAction = new QAction(tr("E&xit"), this);
292  quitAction->setStatusTip(tr("Quit application"));
293  quitAction->setShortcut(QKeySequence(tr("Ctrl+Q")));
294  quitAction->setMenuRole(QAction::QuitRole);
295  aboutAction = new QAction(tr("&About %1").arg(PACKAGE_NAME), this);
296  aboutAction->setStatusTip(tr("Show information about %1").arg(PACKAGE_NAME));
297  aboutAction->setMenuRole(QAction::AboutRole);
298  aboutAction->setEnabled(false);
299  aboutQtAction = new QAction(tr("About &Qt"), this);
300  aboutQtAction->setStatusTip(tr("Show information about Qt"));
301  aboutQtAction->setMenuRole(QAction::AboutQtRole);
302  optionsAction = new QAction(tr("&Options…"), this);
303  optionsAction->setStatusTip(tr("Modify configuration options for %1").arg(PACKAGE_NAME));
304  optionsAction->setMenuRole(QAction::PreferencesRole);
305  optionsAction->setEnabled(false);
306 
307  encryptWalletAction = new QAction(tr("&Encrypt Wallet…"), this);
308  encryptWalletAction->setStatusTip(tr("Encrypt the private keys that belong to your wallet"));
309  encryptWalletAction->setCheckable(true);
310  backupWalletAction = new QAction(tr("&Backup Wallet…"), this);
311  backupWalletAction->setStatusTip(tr("Backup wallet to another location"));
312  changePassphraseAction = new QAction(tr("&Change Passphrase…"), this);
313  changePassphraseAction->setStatusTip(tr("Change the passphrase used for wallet encryption"));
314  signMessageAction = new QAction(tr("Sign &message…"), this);
315  signMessageAction->setStatusTip(tr("Sign messages with your Bitcoin addresses to prove you own them"));
316  verifyMessageAction = new QAction(tr("&Verify message…"), this);
317  verifyMessageAction->setStatusTip(tr("Verify messages to ensure they were signed with specified Bitcoin addresses"));
318  m_load_psbt_action = new QAction(tr("&Load PSBT from file…"), this);
319  m_load_psbt_action->setStatusTip(tr("Load Partially Signed Bitcoin Transaction"));
320  m_load_psbt_clipboard_action = new QAction(tr("Load PSBT from &clipboard…"), this);
321  m_load_psbt_clipboard_action->setStatusTip(tr("Load Partially Signed Bitcoin Transaction from clipboard"));
322 
323  openRPCConsoleAction = new QAction(tr("Node window"), this);
324  openRPCConsoleAction->setStatusTip(tr("Open node debugging and diagnostic console"));
325  // initially disable the debug window menu item
326  openRPCConsoleAction->setEnabled(false);
327  openRPCConsoleAction->setObjectName("openRPCConsoleAction");
328 
329  usedSendingAddressesAction = new QAction(tr("&Sending addresses"), this);
330  usedSendingAddressesAction->setStatusTip(tr("Show the list of used sending addresses and labels"));
331  usedReceivingAddressesAction = new QAction(tr("&Receiving addresses"), this);
332  usedReceivingAddressesAction->setStatusTip(tr("Show the list of used receiving addresses and labels"));
333 
334  openAction = new QAction(tr("Open &URI…"), this);
335  openAction->setStatusTip(tr("Open a bitcoin: URI"));
336 
337  m_open_wallet_action = new QAction(tr("Open Wallet"), this);
338  m_open_wallet_action->setEnabled(false);
339  m_open_wallet_action->setStatusTip(tr("Open a wallet"));
340  m_open_wallet_menu = new QMenu(this);
341 
342  m_close_wallet_action = new QAction(tr("Close Wallet…"), this);
343  m_close_wallet_action->setStatusTip(tr("Close wallet"));
344 
345  m_create_wallet_action = new QAction(tr("Create Wallet…"), this);
346  m_create_wallet_action->setEnabled(false);
347  m_create_wallet_action->setStatusTip(tr("Create a new wallet"));
348 
349  //: Name of the menu item that restores wallet from a backup file.
350  m_restore_wallet_action = new QAction(tr("Restore Wallet…"), this);
351  m_restore_wallet_action->setEnabled(false);
352  //: Status tip for Restore Wallet menu item
353  m_restore_wallet_action->setStatusTip(tr("Restore a wallet from a backup file"));
354 
355  m_close_all_wallets_action = new QAction(tr("Close All Wallets…"), this);
356  m_close_all_wallets_action->setStatusTip(tr("Close all wallets"));
357 
358  m_migrate_wallet_action = new QAction(tr("Migrate Wallet"), this);
359  m_migrate_wallet_action->setEnabled(false);
360  m_migrate_wallet_action->setStatusTip(tr("Migrate a wallet"));
361 
362  showHelpMessageAction = new QAction(tr("&Command-line options"), this);
363  showHelpMessageAction->setMenuRole(QAction::NoRole);
364  showHelpMessageAction->setStatusTip(tr("Show the %1 help message to get a list with possible Bitcoin command-line options").arg(PACKAGE_NAME));
365 
366  m_mask_values_action = new QAction(tr("&Mask values"), this);
367  m_mask_values_action->setShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_M));
368  m_mask_values_action->setStatusTip(tr("Mask the values in the Overview tab"));
369  m_mask_values_action->setCheckable(true);
370 
371  connect(quitAction, &QAction::triggered, this, &BitcoinGUI::quitRequested);
372  connect(aboutAction, &QAction::triggered, this, &BitcoinGUI::aboutClicked);
373  connect(aboutQtAction, &QAction::triggered, qApp, QApplication::aboutQt);
374  connect(optionsAction, &QAction::triggered, this, &BitcoinGUI::optionsClicked);
375  connect(showHelpMessageAction, &QAction::triggered, this, &BitcoinGUI::showHelpMessageClicked);
376  connect(openRPCConsoleAction, &QAction::triggered, this, &BitcoinGUI::showDebugWindow);
377  // prevents an open debug window from becoming stuck/unusable on client shutdown
378  connect(quitAction, &QAction::triggered, rpcConsole, &QWidget::hide);
379 
380 #ifdef ENABLE_WALLET
381  if(walletFrame)
382  {
383  connect(encryptWalletAction, &QAction::triggered, walletFrame, &WalletFrame::encryptWallet);
384  connect(backupWalletAction, &QAction::triggered, walletFrame, &WalletFrame::backupWallet);
385  connect(changePassphraseAction, &QAction::triggered, walletFrame, &WalletFrame::changePassphrase);
386  connect(signMessageAction, &QAction::triggered, [this]{ showNormalIfMinimized(); });
387  connect(signMessageAction, &QAction::triggered, [this]{ gotoSignMessageTab(); });
388  connect(m_load_psbt_action, &QAction::triggered, [this]{ gotoLoadPSBT(); });
389  connect(m_load_psbt_clipboard_action, &QAction::triggered, [this]{ gotoLoadPSBT(true); });
390  connect(verifyMessageAction, &QAction::triggered, [this]{ showNormalIfMinimized(); });
391  connect(verifyMessageAction, &QAction::triggered, [this]{ gotoVerifyMessageTab(); });
394  connect(openAction, &QAction::triggered, this, &BitcoinGUI::openClicked);
395  connect(m_open_wallet_menu, &QMenu::aboutToShow, [this] {
396  m_open_wallet_menu->clear();
397  for (const std::pair<const std::string, bool>& i : m_wallet_controller->listWalletDir()) {
398  const std::string& path = i.first;
399  QString name = path.empty() ? QString("["+tr("default wallet")+"]") : QString::fromStdString(path);
400  // Menu items remove single &. Single & are shown when && is in
401  // the string, but only the first occurrence. So replace only
402  // the first & with &&.
403  name.replace(name.indexOf(QChar('&')), 1, QString("&&"));
404  QAction* action = m_open_wallet_menu->addAction(name);
405 
406  if (i.second) {
407  // This wallet is already loaded
408  action->setEnabled(false);
409  continue;
410  }
411 
412  connect(action, &QAction::triggered, [this, path] {
413  auto activity = new OpenWalletActivity(m_wallet_controller, this);
414  connect(activity, &OpenWalletActivity::opened, this, &BitcoinGUI::setCurrentWallet, Qt::QueuedConnection);
415  connect(activity, &OpenWalletActivity::opened, rpcConsole, &RPCConsole::setCurrentWallet, Qt::QueuedConnection);
416  activity->open(path);
417  });
418  }
419  if (m_open_wallet_menu->isEmpty()) {
420  QAction* action = m_open_wallet_menu->addAction(tr("No wallets available"));
421  action->setEnabled(false);
422  }
423  });
424  connect(m_restore_wallet_action, &QAction::triggered, [this] {
425  //: Name of the wallet data file format.
426  QString name_data_file = tr("Wallet Data");
427 
428  //: The title for Restore Wallet File Windows
429  QString title_windows = tr("Load Wallet Backup");
430 
431  QString backup_file = GUIUtil::getOpenFileName(this, title_windows, QString(), name_data_file + QLatin1String(" (*.dat)"), nullptr);
432  if (backup_file.isEmpty()) return;
433 
434  bool wallet_name_ok;
435  /*: Title of pop-up window shown when the user is attempting to
436  restore a wallet. */
437  QString title = tr("Restore Wallet");
438  //: Label of the input field where the name of the wallet is entered.
439  QString label = tr("Wallet Name");
440  QString wallet_name = QInputDialog::getText(this, title, label, QLineEdit::Normal, "", &wallet_name_ok);
441  if (!wallet_name_ok || wallet_name.isEmpty()) return;
442 
443  auto activity = new RestoreWalletActivity(m_wallet_controller, this);
444  connect(activity, &RestoreWalletActivity::restored, this, &BitcoinGUI::setCurrentWallet, Qt::QueuedConnection);
445  connect(activity, &RestoreWalletActivity::restored, rpcConsole, &RPCConsole::setCurrentWallet, Qt::QueuedConnection);
446 
447  auto backup_file_path = fs::PathFromString(backup_file.toStdString());
448  activity->restore(backup_file_path, wallet_name.toStdString());
449  });
450  connect(m_close_wallet_action, &QAction::triggered, [this] {
452  });
453  connect(m_create_wallet_action, &QAction::triggered, this, &BitcoinGUI::createWallet);
454  connect(m_close_all_wallets_action, &QAction::triggered, [this] {
456  });
457  connect(m_migrate_wallet_action, &QAction::triggered, [this] {
458  auto activity = new MigrateWalletActivity(m_wallet_controller, this);
459  connect(activity, &MigrateWalletActivity::migrated, this, &BitcoinGUI::setCurrentWallet);
460  activity->migrate(walletFrame->currentWalletModel());
461  });
462  connect(m_mask_values_action, &QAction::toggled, this, &BitcoinGUI::setPrivacy);
463  connect(m_mask_values_action, &QAction::toggled, this, &BitcoinGUI::enableHistoryAction);
464  }
465 #endif // ENABLE_WALLET
466 
467  connect(new QShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_C), this), &QShortcut::activated, this, &BitcoinGUI::showDebugWindowActivateConsole);
468  connect(new QShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_D), this), &QShortcut::activated, this, &BitcoinGUI::showDebugWindow);
469 }
470 
472 {
473  appMenuBar = menuBar();
474 
475  // Configure the menus
476  QMenu *file = appMenuBar->addMenu(tr("&File"));
477  if(walletFrame)
478  {
479  file->addAction(m_create_wallet_action);
480  file->addAction(m_open_wallet_action);
481  file->addAction(m_close_wallet_action);
482  file->addAction(m_close_all_wallets_action);
483  file->addAction(m_migrate_wallet_action);
484  file->addSeparator();
485  file->addAction(backupWalletAction);
486  file->addAction(m_restore_wallet_action);
487  file->addSeparator();
488  file->addAction(openAction);
489  file->addAction(signMessageAction);
490  file->addAction(verifyMessageAction);
491  file->addAction(m_load_psbt_action);
492  file->addAction(m_load_psbt_clipboard_action);
493  file->addSeparator();
494  }
495  file->addAction(quitAction);
496 
497  QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
498  if(walletFrame)
499  {
500  settings->addAction(encryptWalletAction);
501  settings->addAction(changePassphraseAction);
502  settings->addSeparator();
503  settings->addAction(m_mask_values_action);
504  settings->addSeparator();
505  }
506  settings->addAction(optionsAction);
507 
508  QMenu* window_menu = appMenuBar->addMenu(tr("&Window"));
509 
510  QAction* minimize_action = window_menu->addAction(tr("&Minimize"));
511  minimize_action->setShortcut(QKeySequence(tr("Ctrl+M")));
512  connect(minimize_action, &QAction::triggered, [] {
513  QApplication::activeWindow()->showMinimized();
514  });
515  connect(qApp, &QApplication::focusWindowChanged, this, [minimize_action] (QWindow* window) {
516  minimize_action->setEnabled(window != nullptr && (window->flags() & Qt::Dialog) != Qt::Dialog && window->windowState() != Qt::WindowMinimized);
517  });
518 
519 #ifdef Q_OS_MACOS
520  QAction* zoom_action = window_menu->addAction(tr("Zoom"));
521  connect(zoom_action, &QAction::triggered, [] {
522  QWindow* window = qApp->focusWindow();
523  if (window->windowState() != Qt::WindowMaximized) {
524  window->showMaximized();
525  } else {
526  window->showNormal();
527  }
528  });
529 
530  connect(qApp, &QApplication::focusWindowChanged, this, [zoom_action] (QWindow* window) {
531  zoom_action->setEnabled(window != nullptr);
532  });
533 #endif
534 
535  if (walletFrame) {
536 #ifdef Q_OS_MACOS
537  window_menu->addSeparator();
538  QAction* main_window_action = window_menu->addAction(tr("Main Window"));
539  connect(main_window_action, &QAction::triggered, [this] {
540  GUIUtil::bringToFront(this);
541  });
542 #endif
543  window_menu->addSeparator();
544  window_menu->addAction(usedSendingAddressesAction);
545  window_menu->addAction(usedReceivingAddressesAction);
546  }
547 
548  window_menu->addSeparator();
549  for (RPCConsole::TabTypes tab_type : rpcConsole->tabs()) {
550  QAction* tab_action = window_menu->addAction(rpcConsole->tabTitle(tab_type));
551  tab_action->setShortcut(rpcConsole->tabShortcut(tab_type));
552  connect(tab_action, &QAction::triggered, [this, tab_type] {
553  rpcConsole->setTabFocus(tab_type);
554  showDebugWindow();
555  });
556  }
557 
558  QMenu *help = appMenuBar->addMenu(tr("&Help"));
559  help->addAction(showHelpMessageAction);
560  help->addSeparator();
561  help->addAction(aboutAction);
562  help->addAction(aboutQtAction);
563 }
564 
566 {
567  if(walletFrame)
568  {
569  QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));
570  appToolBar = toolbar;
571  toolbar->setMovable(false);
572  toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
573  toolbar->addAction(overviewAction);
574  toolbar->addAction(sendCoinsAction);
575  toolbar->addAction(receiveCoinsAction);
576  toolbar->addAction(historyAction);
577  overviewAction->setChecked(true);
578 
579 #ifdef ENABLE_WALLET
580  QWidget *spacer = new QWidget();
581  spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
582  toolbar->addWidget(spacer);
583 
584  m_wallet_selector = new QComboBox();
585  m_wallet_selector->setSizeAdjustPolicy(QComboBox::AdjustToContents);
586  connect(m_wallet_selector, qOverload<int>(&QComboBox::currentIndexChanged), this, &BitcoinGUI::setCurrentWalletBySelectorIndex);
587 
588  m_wallet_selector_label = new QLabel();
589  m_wallet_selector_label->setText(tr("Wallet:") + " ");
591 
594 
595  m_wallet_selector_label_action->setVisible(false);
596  m_wallet_selector_action->setVisible(false);
597 #endif
598  }
599 }
600 
602 {
603  this->clientModel = _clientModel;
604  if(_clientModel)
605  {
606  // Create system tray menu (or setup the dock menu) that late to prevent users from calling actions,
607  // while the client has not yet fully loaded
609 
610  // Keep up to date with client
614  });
616  connect(_clientModel, &ClientModel::networkActiveChanged, this, &BitcoinGUI::setNetworkActive);
617 
618  modalOverlay->setKnownBestHeight(tip_info->header_height, QDateTime::fromSecsSinceEpoch(tip_info->header_time), /*presync=*/false);
619  setNumBlocks(tip_info->block_height, QDateTime::fromSecsSinceEpoch(tip_info->block_time), tip_info->verification_progress, SyncType::BLOCK_SYNC, SynchronizationState::INIT_DOWNLOAD);
620  connect(_clientModel, &ClientModel::numBlocksChanged, this, &BitcoinGUI::setNumBlocks);
621 
622  // Receive and report messages from client model
623  connect(_clientModel, &ClientModel::message, [this](const QString &title, const QString &message, unsigned int style){
624  this->message(title, message, style);
625  });
626 
627  // Show progress dialog
628  connect(_clientModel, &ClientModel::showProgress, this, &BitcoinGUI::showProgress);
629 
630  rpcConsole->setClientModel(_clientModel, tip_info->block_height, tip_info->block_time, tip_info->verification_progress);
631 
632  updateProxyIcon();
633 
634 #ifdef ENABLE_WALLET
635  if(walletFrame)
636  {
637  walletFrame->setClientModel(_clientModel);
638  }
639 #endif // ENABLE_WALLET
641 
642  OptionsModel* optionsModel = _clientModel->getOptionsModel();
643  if (optionsModel && trayIcon) {
644  // be aware of the tray icon disable state change reported by the OptionsModel object.
645  connect(optionsModel, &OptionsModel::showTrayIconChanged, trayIcon, &QSystemTrayIcon::setVisible);
646 
647  // initialize the disable state of the tray icon with the current value in the model.
648  trayIcon->setVisible(optionsModel->getShowTrayIcon());
649  }
650 
651  m_mask_values_action->setChecked(_clientModel->getOptionsModel()->getOption(OptionsModel::OptionID::MaskValues).toBool());
652  } else {
653  // Shutdown requested, disable menus
654  if (trayIconMenu)
655  {
656  // Disable context menu on tray icon
657  trayIconMenu->clear();
658  }
659  // Propagate cleared model to child objects
660  rpcConsole->setClientModel(nullptr);
661 #ifdef ENABLE_WALLET
662  if (walletFrame)
663  {
664  walletFrame->setClientModel(nullptr);
665  }
666 #endif // ENABLE_WALLET
668  // Disable top bar menu actions
669  appMenuBar->clear();
670  }
671 }
672 
673 #ifdef ENABLE_WALLET
674 void BitcoinGUI::enableHistoryAction(bool privacy)
675 {
676  historyAction->setEnabled(!privacy);
677  if (historyAction->isChecked()) gotoOverviewPage();
678 }
679 
680 void BitcoinGUI::setWalletController(WalletController* wallet_controller, bool show_loading_minimized)
681 {
683  assert(wallet_controller);
684 
685  m_wallet_controller = wallet_controller;
686 
687  m_create_wallet_action->setEnabled(true);
688  m_open_wallet_action->setEnabled(true);
690  m_restore_wallet_action->setEnabled(true);
691 
692  GUIUtil::ExceptionSafeConnect(wallet_controller, &WalletController::walletAdded, this, &BitcoinGUI::addWallet);
693  connect(wallet_controller, &WalletController::walletRemoved, this, &BitcoinGUI::removeWallet);
694  connect(wallet_controller, &WalletController::destroyed, this, [this] {
695  // wallet_controller gets destroyed manually, but it leaves our member copy dangling
696  m_wallet_controller = nullptr;
697  });
698 
699  auto activity = new LoadWalletsActivity(m_wallet_controller, this);
700  activity->load(show_loading_minimized);
701 }
702 
703 WalletController* BitcoinGUI::getWalletController()
704 {
705  return m_wallet_controller;
706 }
707 
708 void BitcoinGUI::addWallet(WalletModel* walletModel)
709 {
710  if (!walletFrame || !m_wallet_controller) return;
711 
712  WalletView* wallet_view = new WalletView(walletModel, platformStyle, walletFrame);
713  if (!walletFrame->addView(wallet_view)) return;
714 
715  rpcConsole->addWallet(walletModel);
716  if (m_wallet_selector->count() == 0) {
718  } else if (m_wallet_selector->count() == 1) {
719  m_wallet_selector_label_action->setVisible(true);
720  m_wallet_selector_action->setVisible(true);
721  }
722 
724  connect(wallet_view, &WalletView::transactionClicked, this, &BitcoinGUI::gotoHistoryPage);
725  connect(wallet_view, &WalletView::coinsSent, this, &BitcoinGUI::gotoHistoryPage);
726  connect(wallet_view, &WalletView::message, [this](const QString& title, const QString& message, unsigned int style) {
727  this->message(title, message, style);
728  });
729  connect(wallet_view, &WalletView::encryptionStatusChanged, this, &BitcoinGUI::updateWalletStatus);
730  connect(wallet_view, &WalletView::incomingTransaction, this, &BitcoinGUI::incomingTransaction);
731  connect(this, &BitcoinGUI::setPrivacy, wallet_view, &WalletView::setPrivacy);
732  const bool privacy = isPrivacyModeActivated();
733  wallet_view->setPrivacy(privacy);
734  enableHistoryAction(privacy);
735  const QString display_name = walletModel->getDisplayName();
736  m_wallet_selector->addItem(display_name, QVariant::fromValue(walletModel));
737 }
738 
739 void BitcoinGUI::removeWallet(WalletModel* walletModel)
740 {
741  if (!walletFrame) return;
742 
743  labelWalletHDStatusIcon->hide();
745 
746  int index = m_wallet_selector->findData(QVariant::fromValue(walletModel));
747  m_wallet_selector->removeItem(index);
748  if (m_wallet_selector->count() == 0) {
750  overviewAction->setChecked(true);
751  } else if (m_wallet_selector->count() == 1) {
752  m_wallet_selector_label_action->setVisible(false);
753  m_wallet_selector_action->setVisible(false);
754  }
755  rpcConsole->removeWallet(walletModel);
756  walletFrame->removeWallet(walletModel);
758 }
759 
760 void BitcoinGUI::setCurrentWallet(WalletModel* wallet_model)
761 {
762  if (!walletFrame || !m_wallet_controller) return;
763  walletFrame->setCurrentWallet(wallet_model);
764  for (int index = 0; index < m_wallet_selector->count(); ++index) {
765  if (m_wallet_selector->itemData(index).value<WalletModel*>() == wallet_model) {
766  m_wallet_selector->setCurrentIndex(index);
767  break;
768  }
769  }
771  m_migrate_wallet_action->setEnabled(wallet_model->wallet().isLegacy());
772 }
773 
774 void BitcoinGUI::setCurrentWalletBySelectorIndex(int index)
775 {
776  WalletModel* wallet_model = m_wallet_selector->itemData(index).value<WalletModel*>();
777  if (wallet_model) setCurrentWallet(wallet_model);
778 }
779 
780 void BitcoinGUI::removeAllWallets()
781 {
782  if(!walletFrame)
783  return;
786 }
787 #endif // ENABLE_WALLET
788 
790 {
791  overviewAction->setEnabled(enabled);
792  sendCoinsAction->setEnabled(enabled);
793  receiveCoinsAction->setEnabled(enabled);
794  historyAction->setEnabled(enabled);
795  encryptWalletAction->setEnabled(enabled);
796  backupWalletAction->setEnabled(enabled);
797  changePassphraseAction->setEnabled(enabled);
798  signMessageAction->setEnabled(enabled);
799  verifyMessageAction->setEnabled(enabled);
800  usedSendingAddressesAction->setEnabled(enabled);
801  usedReceivingAddressesAction->setEnabled(enabled);
802  openAction->setEnabled(enabled);
803  m_close_wallet_action->setEnabled(enabled);
804  m_close_all_wallets_action->setEnabled(enabled);
805  m_migrate_wallet_action->setEnabled(enabled);
806 }
807 
809 {
810  assert(QSystemTrayIcon::isSystemTrayAvailable());
811 
812 #ifndef Q_OS_MACOS
813  if (QSystemTrayIcon::isSystemTrayAvailable()) {
814  trayIcon = new QSystemTrayIcon(m_network_style->getTrayAndWindowIcon(), this);
815  QString toolTip = tr("%1 client").arg(PACKAGE_NAME) + " " + m_network_style->getTitleAddText();
816  trayIcon->setToolTip(toolTip);
817  }
818 #endif
819 }
820 
822 {
823 #ifndef Q_OS_MACOS
824  if (!trayIcon) return;
825 #endif // Q_OS_MACOS
826 
827  // Configuration of the tray icon (or Dock icon) menu.
828  QAction* show_hide_action{nullptr};
829 #ifndef Q_OS_MACOS
830  // Note: On macOS, the Dock icon's menu already has Show / Hide action.
831  show_hide_action = trayIconMenu->addAction(QString(), this, &BitcoinGUI::toggleHidden);
832  trayIconMenu->addSeparator();
833 #endif // Q_OS_MACOS
834 
835  QAction* send_action{nullptr};
836  QAction* receive_action{nullptr};
837  QAction* sign_action{nullptr};
838  QAction* verify_action{nullptr};
839  if (enableWallet) {
840  send_action = trayIconMenu->addAction(sendCoinsAction->text(), sendCoinsAction, &QAction::trigger);
841  receive_action = trayIconMenu->addAction(receiveCoinsAction->text(), receiveCoinsAction, &QAction::trigger);
842  trayIconMenu->addSeparator();
843  sign_action = trayIconMenu->addAction(signMessageAction->text(), signMessageAction, &QAction::trigger);
844  verify_action = trayIconMenu->addAction(verifyMessageAction->text(), verifyMessageAction, &QAction::trigger);
845  trayIconMenu->addSeparator();
846  }
847  QAction* options_action = trayIconMenu->addAction(optionsAction->text(), optionsAction, &QAction::trigger);
848  options_action->setMenuRole(QAction::PreferencesRole);
849  QAction* node_window_action = trayIconMenu->addAction(openRPCConsoleAction->text(), openRPCConsoleAction, &QAction::trigger);
850  QAction* quit_action{nullptr};
851 #ifndef Q_OS_MACOS
852  // Note: On macOS, the Dock icon's menu already has Quit action.
853  trayIconMenu->addSeparator();
854  quit_action = trayIconMenu->addAction(quitAction->text(), quitAction, &QAction::trigger);
855 
856  trayIcon->setContextMenu(trayIconMenu.get());
857  connect(trayIcon, &QSystemTrayIcon::activated, [this](QSystemTrayIcon::ActivationReason reason) {
858  if (reason == QSystemTrayIcon::Trigger) {
859  // Click on system tray icon triggers show/hide of the main window
860  toggleHidden();
861  }
862  });
863 #else
864  // Note: On macOS, the Dock icon is used to provide the tray's functionality.
866  connect(dockIconHandler, &MacDockIconHandler::dockIconClicked, [this] {
867  if (m_node.shutdownRequested()) return; // nothing to show, node is shutting down.
868  show();
869  activateWindow();
870  });
871  trayIconMenu->setAsDockMenu();
872 #endif // Q_OS_MACOS
873 
874  connect(
875  // Using QSystemTrayIcon::Context is not reliable.
876  // See https://bugreports.qt.io/browse/QTBUG-91697
877  trayIconMenu.get(), &QMenu::aboutToShow,
878  [this, show_hide_action, send_action, receive_action, sign_action, verify_action, options_action, node_window_action, quit_action] {
879  if (m_node.shutdownRequested()) return; // nothing to do, node is shutting down.
880 
881  if (show_hide_action) show_hide_action->setText(
882  (!isHidden() && !isMinimized() && !GUIUtil::isObscured(this)) ?
883  tr("&Hide") :
884  tr("S&how"));
885  if (QApplication::activeModalWidget()) {
886  for (QAction* a : trayIconMenu.get()->actions()) {
887  a->setEnabled(false);
888  }
889  } else {
890  if (show_hide_action) show_hide_action->setEnabled(true);
891  if (enableWallet) {
892  send_action->setEnabled(sendCoinsAction->isEnabled());
893  receive_action->setEnabled(receiveCoinsAction->isEnabled());
894  sign_action->setEnabled(signMessageAction->isEnabled());
895  verify_action->setEnabled(verifyMessageAction->isEnabled());
896  }
897  options_action->setEnabled(optionsAction->isEnabled());
898  node_window_action->setEnabled(openRPCConsoleAction->isEnabled());
899  if (quit_action) quit_action->setEnabled(true);
900  }
901  });
902 }
903 
905 {
907 }
908 
910 {
911  if(!clientModel)
912  return;
913 
914  auto dlg = new HelpMessageDialog(this, /*about=*/true);
916 }
917 
919 {
921  Q_EMIT consoleShown(rpcConsole);
922 }
923 
925 {
927  showDebugWindow();
928 }
929 
931 {
933 }
934 
935 #ifdef ENABLE_WALLET
936 void BitcoinGUI::openClicked()
937 {
938  OpenURIDialog dlg(platformStyle, this);
939  if(dlg.exec())
940  {
941  Q_EMIT receivedURI(dlg.getURI());
942  }
943 }
944 
945 void BitcoinGUI::gotoOverviewPage()
946 {
947  overviewAction->setChecked(true);
949 }
950 
951 void BitcoinGUI::gotoHistoryPage()
952 {
953  historyAction->setChecked(true);
955 }
956 
957 void BitcoinGUI::gotoReceiveCoinsPage()
958 {
959  receiveCoinsAction->setChecked(true);
961 }
962 
963 void BitcoinGUI::gotoSendCoinsPage(QString addr)
964 {
965  sendCoinsAction->setChecked(true);
967 }
968 
969 void BitcoinGUI::gotoSignMessageTab(QString addr)
970 {
972 }
973 
974 void BitcoinGUI::gotoVerifyMessageTab(QString addr)
975 {
977 }
978 void BitcoinGUI::gotoLoadPSBT(bool from_clipboard)
979 {
980  if (walletFrame) walletFrame->gotoLoadPSBT(from_clipboard);
981 }
982 #endif // ENABLE_WALLET
983 
985 {
987  QString icon;
988  switch(count)
989  {
990  case 0: icon = ":/icons/connect_0"; break;
991  case 1: case 2: case 3: icon = ":/icons/connect_1"; break;
992  case 4: case 5: case 6: icon = ":/icons/connect_2"; break;
993  case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
994  default: icon = ":/icons/connect_4"; break;
995  }
996 
997  QString tooltip;
998 
999  if (m_node.getNetworkActive()) {
1000  //: A substring of the tooltip.
1001  tooltip = tr("%n active connection(s) to Bitcoin network.", "", count);
1002  } else {
1003  //: A substring of the tooltip.
1004  tooltip = tr("Network activity disabled.");
1005  icon = ":/icons/network_disabled";
1006  }
1007 
1008  // Don't word-wrap this (fixed-width) tooltip
1009  tooltip = QLatin1String("<nobr>") + tooltip + QLatin1String("<br>") +
1010  //: A substring of the tooltip. "More actions" are available via the context menu.
1011  tr("Click for more actions.") + QLatin1String("</nobr>");
1012  connectionsControl->setToolTip(tooltip);
1013 
1015 }
1016 
1018 {
1020 }
1021 
1022 void BitcoinGUI::setNetworkActive(bool network_active)
1023 {
1025  m_network_context_menu->clear();
1026  m_network_context_menu->addAction(
1027  //: A context menu item. The "Peers tab" is an element of the "Node window".
1028  tr("Show Peers tab"),
1029  [this] {
1031  showDebugWindow();
1032  });
1033  m_network_context_menu->addAction(
1034  network_active ?
1035  //: A context menu item.
1036  tr("Disable network activity") :
1037  //: A context menu item. The network activity was disabled previously.
1038  tr("Enable network activity"),
1039  [this, new_state = !network_active] { m_node.setNetworkActive(new_state); });
1040 }
1041 
1043 {
1044  int64_t headersTipTime = clientModel->getHeaderTipTime();
1045  int headersTipHeight = clientModel->getHeaderTipHeight();
1046  int estHeadersLeft = (GetTime() - headersTipTime) / Params().GetConsensus().nPowTargetSpacing;
1047  if (estHeadersLeft > HEADER_HEIGHT_DELTA_SYNC)
1048  progressBarLabel->setText(tr("Syncing Headers (%1%)…").arg(QString::number(100.0 / (headersTipHeight+estHeadersLeft)*headersTipHeight, 'f', 1)));
1049 }
1050 
1051 void BitcoinGUI::updateHeadersPresyncProgressLabel(int64_t height, const QDateTime& blockDate)
1052 {
1053  int estHeadersLeft = blockDate.secsTo(QDateTime::currentDateTime()) / Params().GetConsensus().nPowTargetSpacing;
1054  if (estHeadersLeft > HEADER_HEIGHT_DELTA_SYNC)
1055  progressBarLabel->setText(tr("Pre-syncing Headers (%1%)…").arg(QString::number(100.0 / (height+estHeadersLeft)*height, 'f', 1)));
1056 }
1057 
1059 {
1061  return;
1062 
1063  auto dlg = new OptionsDialog(this, enableWallet);
1065  dlg->setCurrentTab(tab);
1066  dlg->setClientModel(clientModel);
1067  dlg->setModel(clientModel->getOptionsModel());
1069 }
1070 
1071 void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, SyncType synctype, SynchronizationState sync_state)
1072 {
1073 // Disabling macOS App Nap on initial sync, disk and reindex operations.
1074 #ifdef Q_OS_MACOS
1075  if (sync_state == SynchronizationState::POST_INIT) {
1076  m_app_nap_inhibitor->enableAppNap();
1077  } else {
1078  m_app_nap_inhibitor->disableAppNap();
1079  }
1080 #endif
1081 
1082  if (modalOverlay)
1083  {
1084  if (synctype != SyncType::BLOCK_SYNC)
1086  else
1087  modalOverlay->tipUpdate(count, blockDate, nVerificationProgress);
1088  }
1089  if (!clientModel)
1090  return;
1091 
1092  // Prevent orphan statusbar messages (e.g. hover Quit in main menu, wait until chain-sync starts -> garbled text)
1093  statusBar()->clearMessage();
1094 
1095  // Acquire current block source
1096  BlockSource blockSource{clientModel->getBlockSource()};
1097  switch (blockSource) {
1098  case BlockSource::NETWORK:
1099  if (synctype == SyncType::HEADER_PRESYNC) {
1101  return;
1102  } else if (synctype == SyncType::HEADER_SYNC) {
1104  return;
1105  }
1106  progressBarLabel->setText(tr("Synchronizing with network…"));
1108  break;
1109  case BlockSource::DISK:
1110  if (synctype != SyncType::BLOCK_SYNC) {
1111  progressBarLabel->setText(tr("Indexing blocks on disk…"));
1112  } else {
1113  progressBarLabel->setText(tr("Processing blocks on disk…"));
1114  }
1115  break;
1116  case BlockSource::NONE:
1117  if (synctype != SyncType::BLOCK_SYNC) {
1118  return;
1119  }
1120  progressBarLabel->setText(tr("Connecting to peers…"));
1121  break;
1122  }
1123 
1124  QString tooltip;
1125 
1126  QDateTime currentDate = QDateTime::currentDateTime();
1127  qint64 secs = blockDate.secsTo(currentDate);
1128 
1129  tooltip = tr("Processed %n block(s) of transaction history.", "", count);
1130 
1131  // Set icon state: spinning if catching up, tick otherwise
1132  if (secs < MAX_BLOCK_TIME_GAP) {
1133  tooltip = tr("Up to date") + QString(".<br>") + tooltip;
1134  labelBlocksIcon->setThemedPixmap(QStringLiteral(":/icons/synced"), STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE);
1135 
1136 #ifdef ENABLE_WALLET
1137  if(walletFrame)
1138  {
1140  modalOverlay->showHide(true, true);
1141  }
1142 #endif // ENABLE_WALLET
1143 
1144  progressBarLabel->setVisible(false);
1145  progressBar->setVisible(false);
1146  }
1147  else
1148  {
1149  QString timeBehindText = GUIUtil::formatNiceTimeOffset(secs);
1150 
1151  progressBarLabel->setVisible(true);
1152  progressBar->setFormat(tr("%1 behind").arg(timeBehindText));
1153  progressBar->setMaximum(1000000000);
1154  progressBar->setValue(nVerificationProgress * 1000000000.0 + 0.5);
1155  progressBar->setVisible(true);
1156 
1157  tooltip = tr("Catching up…") + QString("<br>") + tooltip;
1158  if(count != prevBlocks)
1159  {
1161  QString(":/animation/spinner-%1").arg(spinnerFrame, 3, 10, QChar('0')),
1164  }
1165  prevBlocks = count;
1166 
1167 #ifdef ENABLE_WALLET
1168  if(walletFrame)
1169  {
1172  }
1173 #endif // ENABLE_WALLET
1174 
1175  tooltip += QString("<br>");
1176  tooltip += tr("Last received block was generated %1 ago.").arg(timeBehindText);
1177  tooltip += QString("<br>");
1178  tooltip += tr("Transactions after this will not yet be visible.");
1179  }
1180 
1181  // Don't word-wrap this (fixed-width) tooltip
1182  tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
1183 
1184  labelBlocksIcon->setToolTip(tooltip);
1185  progressBarLabel->setToolTip(tooltip);
1186  progressBar->setToolTip(tooltip);
1187 }
1188 
1190 {
1191 #ifdef ENABLE_WALLET
1192 #ifndef USE_SQLITE
1193  // Compiled without sqlite support (required for descriptor wallets)
1194  message(tr("Error creating wallet"), tr("Cannot create new wallet, the software was compiled without sqlite support (required for descriptor wallets)"), CClientUIInterface::MSG_ERROR);
1195  return;
1196 #endif // USE_SQLITE
1197  auto activity = new CreateWalletActivity(getWalletController(), this);
1198  connect(activity, &CreateWalletActivity::created, this, &BitcoinGUI::setCurrentWallet);
1199  connect(activity, &CreateWalletActivity::created, rpcConsole, &RPCConsole::setCurrentWallet);
1200  activity->create();
1201 #endif // ENABLE_WALLET
1202 }
1203 
1204 void BitcoinGUI::message(const QString& title, QString message, unsigned int style, bool* ret, const QString& detailed_message)
1205 {
1206  // Default title. On macOS, the window title is ignored (as required by the macOS Guidelines).
1207  QString strTitle{PACKAGE_NAME};
1208  // Default to information icon
1209  int nMBoxIcon = QMessageBox::Information;
1210  int nNotifyIcon = Notificator::Information;
1211 
1212  QString msgType;
1213  if (!title.isEmpty()) {
1214  msgType = title;
1215  } else {
1216  switch (style) {
1218  msgType = tr("Error");
1219  message = tr("Error: %1").arg(message);
1220  break;
1222  msgType = tr("Warning");
1223  message = tr("Warning: %1").arg(message);
1224  break;
1226  msgType = tr("Information");
1227  // No need to prepend the prefix here.
1228  break;
1229  default:
1230  break;
1231  }
1232  }
1233 
1234  if (!msgType.isEmpty()) {
1235  strTitle += " - " + msgType;
1236  }
1237 
1238  if (style & CClientUIInterface::ICON_ERROR) {
1239  nMBoxIcon = QMessageBox::Critical;
1240  nNotifyIcon = Notificator::Critical;
1241  } else if (style & CClientUIInterface::ICON_WARNING) {
1242  nMBoxIcon = QMessageBox::Warning;
1243  nNotifyIcon = Notificator::Warning;
1244  }
1245 
1246  if (style & CClientUIInterface::MODAL) {
1247  // Check for buttons, use OK as default, if none was supplied
1248  QMessageBox::StandardButton buttons;
1249  if (!(buttons = (QMessageBox::StandardButton)(style & CClientUIInterface::BTN_MASK)))
1250  buttons = QMessageBox::Ok;
1251 
1253  QMessageBox mBox(static_cast<QMessageBox::Icon>(nMBoxIcon), strTitle, message, buttons, this);
1254  mBox.setTextFormat(Qt::PlainText);
1255  mBox.setDetailedText(detailed_message);
1256  int r = mBox.exec();
1257  if (ret != nullptr)
1258  *ret = r == QMessageBox::Ok;
1259  } else {
1260  notificator->notify(static_cast<Notificator::Class>(nNotifyIcon), strTitle, message);
1261  }
1262 }
1263 
1265 {
1266  if (e->type() == QEvent::PaletteChange) {
1267  overviewAction->setIcon(platformStyle->SingleColorIcon(QStringLiteral(":/icons/overview")));
1268  sendCoinsAction->setIcon(platformStyle->SingleColorIcon(QStringLiteral(":/icons/send")));
1269  receiveCoinsAction->setIcon(platformStyle->SingleColorIcon(QStringLiteral(":/icons/receiving_addresses")));
1270  historyAction->setIcon(platformStyle->SingleColorIcon(QStringLiteral(":/icons/history")));
1271  }
1272 
1273  QMainWindow::changeEvent(e);
1274 
1275 #ifndef Q_OS_MACOS // Ignored on Mac
1276  if(e->type() == QEvent::WindowStateChange)
1277  {
1279  {
1280  QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
1281  if(!(wsevt->oldState() & Qt::WindowMinimized) && isMinimized())
1282  {
1283  QTimer::singleShot(0, this, &BitcoinGUI::hide);
1284  e->ignore();
1285  }
1286  else if((wsevt->oldState() & Qt::WindowMinimized) && !isMinimized())
1287  {
1288  QTimer::singleShot(0, this, &BitcoinGUI::show);
1289  e->ignore();
1290  }
1291  }
1292  }
1293 #endif
1294 }
1295 
1296 void BitcoinGUI::closeEvent(QCloseEvent *event)
1297 {
1298 #ifndef Q_OS_MACOS // Ignored on Mac
1300  {
1302  {
1303  // close rpcConsole in case it was open to make some space for the shutdown window
1304  rpcConsole->close();
1305 
1306  Q_EMIT quitRequested();
1307  }
1308  else
1309  {
1310  QMainWindow::showMinimized();
1311  event->ignore();
1312  }
1313  }
1314 #else
1315  QMainWindow::closeEvent(event);
1316 #endif
1317 }
1318 
1319 void BitcoinGUI::showEvent(QShowEvent *event)
1320 {
1321  // enable the debug window when the main window shows up
1322  openRPCConsoleAction->setEnabled(true);
1323  aboutAction->setEnabled(true);
1324  optionsAction->setEnabled(true);
1325 }
1326 
1327 #ifdef ENABLE_WALLET
1328 void BitcoinGUI::incomingTransaction(const QString& date, BitcoinUnit unit, const CAmount& amount, const QString& type, const QString& address, const QString& label, const QString& walletName)
1329 {
1330  // On new transaction, make an info balloon
1331  QString msg = tr("Date: %1\n").arg(date) +
1332  tr("Amount: %1\n").arg(BitcoinUnits::formatWithUnit(unit, amount, true));
1333  if (m_node.walletLoader().getWallets().size() > 1 && !walletName.isEmpty()) {
1334  msg += tr("Wallet: %1\n").arg(walletName);
1335  }
1336  msg += tr("Type: %1\n").arg(type);
1337  if (!label.isEmpty())
1338  msg += tr("Label: %1\n").arg(label);
1339  else if (!address.isEmpty())
1340  msg += tr("Address: %1\n").arg(address);
1341  message((amount)<0 ? tr("Sent transaction") : tr("Incoming transaction"),
1343 }
1344 #endif // ENABLE_WALLET
1345 
1346 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
1347 {
1348  // Accept only URIs
1349  if(event->mimeData()->hasUrls())
1350  event->acceptProposedAction();
1351 }
1352 
1353 void BitcoinGUI::dropEvent(QDropEvent *event)
1354 {
1355  if(event->mimeData()->hasUrls())
1356  {
1357  for (const QUrl &uri : event->mimeData()->urls())
1358  {
1359  Q_EMIT receivedURI(uri.toString());
1360  }
1361  }
1362  event->acceptProposedAction();
1363 }
1364 
1365 bool BitcoinGUI::eventFilter(QObject *object, QEvent *event)
1366 {
1367  // Catch status tip events
1368  if (event->type() == QEvent::StatusTip)
1369  {
1370  // Prevent adding text from setStatusTip(), if we currently use the status bar for displaying other stuff
1371  if (progressBarLabel->isVisible() || progressBar->isVisible())
1372  return true;
1373  }
1374  return QMainWindow::eventFilter(object, event);
1375 }
1376 
1377 #ifdef ENABLE_WALLET
1378 bool BitcoinGUI::handlePaymentRequest(const SendCoinsRecipient& recipient)
1379 {
1380  // URI has to be valid
1381  if (walletFrame && walletFrame->handlePaymentRequest(recipient))
1382  {
1384  gotoSendCoinsPage();
1385  return true;
1386  }
1387  return false;
1388 }
1389 
1390 void BitcoinGUI::setHDStatus(bool privkeyDisabled, int hdEnabled)
1391 {
1392  labelWalletHDStatusIcon->setThemedPixmap(privkeyDisabled ? QStringLiteral(":/icons/eye") : hdEnabled ? QStringLiteral(":/icons/hd_enabled") : QStringLiteral(":/icons/hd_disabled"), STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE);
1393  labelWalletHDStatusIcon->setToolTip(privkeyDisabled ? tr("Private key <b>disabled</b>") : hdEnabled ? tr("HD key generation is <b>enabled</b>") : tr("HD key generation is <b>disabled</b>"));
1394  labelWalletHDStatusIcon->show();
1395 }
1396 
1397 void BitcoinGUI::setEncryptionStatus(int status)
1398 {
1399  switch(status)
1400  {
1401  case WalletModel::NoKeys:
1402  labelWalletEncryptionIcon->hide();
1403  encryptWalletAction->setChecked(false);
1404  changePassphraseAction->setEnabled(false);
1405  encryptWalletAction->setEnabled(false);
1406  break;
1408  labelWalletEncryptionIcon->hide();
1409  encryptWalletAction->setChecked(false);
1410  changePassphraseAction->setEnabled(false);
1411  encryptWalletAction->setEnabled(true);
1412  break;
1413  case WalletModel::Unlocked:
1414  labelWalletEncryptionIcon->show();
1415  labelWalletEncryptionIcon->setThemedPixmap(QStringLiteral(":/icons/lock_open"), STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE);
1416  labelWalletEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
1417  encryptWalletAction->setChecked(true);
1418  changePassphraseAction->setEnabled(true);
1419  encryptWalletAction->setEnabled(false);
1420  break;
1421  case WalletModel::Locked:
1422  labelWalletEncryptionIcon->show();
1423  labelWalletEncryptionIcon->setThemedPixmap(QStringLiteral(":/icons/lock_closed"), STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE);
1424  labelWalletEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
1425  encryptWalletAction->setChecked(true);
1426  changePassphraseAction->setEnabled(true);
1427  encryptWalletAction->setEnabled(false);
1428  break;
1429  }
1430 }
1431 
1432 void BitcoinGUI::updateWalletStatus()
1433 {
1435 
1436  WalletView * const walletView = walletFrame->currentWalletView();
1437  if (!walletView) {
1438  return;
1439  }
1440  WalletModel * const walletModel = walletView->getWalletModel();
1441  setEncryptionStatus(walletModel->getEncryptionStatus());
1442  setHDStatus(walletModel->wallet().privateKeysDisabled(), walletModel->wallet().hdEnabled());
1443 }
1444 #endif // ENABLE_WALLET
1445 
1447 {
1448  std::string ip_port;
1449  bool proxy_enabled = clientModel->getProxyInfo(ip_port);
1450 
1451  if (proxy_enabled) {
1453  QString ip_port_q = QString::fromStdString(ip_port);
1455  labelProxyIcon->setToolTip(tr("Proxy is <b>enabled</b>: %1").arg(ip_port_q));
1456  } else {
1457  labelProxyIcon->show();
1458  }
1459  } else {
1460  labelProxyIcon->hide();
1461  }
1462 }
1463 
1465 {
1466  QString window_title = PACKAGE_NAME;
1467 #ifdef ENABLE_WALLET
1468  if (walletFrame) {
1469  WalletModel* const wallet_model = walletFrame->currentWalletModel();
1470  if (wallet_model && !wallet_model->getWalletName().isEmpty()) {
1471  window_title += " - " + wallet_model->getDisplayName();
1472  }
1473  }
1474 #endif
1475  if (!m_network_style->getTitleAddText().isEmpty()) {
1476  window_title += " - " + m_network_style->getTitleAddText();
1477  }
1478  setWindowTitle(window_title);
1479 }
1480 
1481 void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden)
1482 {
1483  if(!clientModel)
1484  return;
1485 
1486  if (!isHidden() && !isMinimized() && !GUIUtil::isObscured(this) && fToggleHidden) {
1487  hide();
1488  } else {
1489  GUIUtil::bringToFront(this);
1490  }
1491 }
1492 
1494 {
1495  showNormalIfMinimized(true);
1496 }
1497 
1499 {
1500  if (m_node.shutdownRequested())
1501  {
1502  if(rpcConsole)
1503  rpcConsole->hide();
1504  Q_EMIT quitRequested();
1505  }
1506 }
1507 
1508 void BitcoinGUI::showProgress(const QString &title, int nProgress)
1509 {
1510  if (nProgress == 0) {
1511  progressDialog = new QProgressDialog(title, QString(), 0, 100);
1513  progressDialog->setWindowModality(Qt::ApplicationModal);
1514  progressDialog->setAutoClose(false);
1515  progressDialog->setValue(0);
1516  } else if (nProgress == 100) {
1517  if (progressDialog) {
1518  progressDialog->close();
1519  progressDialog->deleteLater();
1520  progressDialog = nullptr;
1521  }
1522  } else if (progressDialog) {
1523  progressDialog->setValue(nProgress);
1524  }
1525 }
1526 
1528 {
1529  if (modalOverlay && (progressBar->isVisible() || modalOverlay->isLayerVisible()))
1531 }
1532 
1533 static bool ThreadSafeMessageBox(BitcoinGUI* gui, const bilingual_str& message, const std::string& caption, unsigned int style)
1534 {
1535  bool modal = (style & CClientUIInterface::MODAL);
1536  // The SECURE flag has no effect in the Qt GUI.
1537  // bool secure = (style & CClientUIInterface::SECURE);
1538  style &= ~CClientUIInterface::SECURE;
1539  bool ret = false;
1540 
1541  QString detailed_message; // This is original message, in English, for googling and referencing.
1542  if (message.original != message.translated) {
1543  detailed_message = BitcoinGUI::tr("Original message:") + "\n" + QString::fromStdString(message.original);
1544  }
1545 
1546  // In case of modal message, use blocking connection to wait for user to click a button
1547  bool invoked = QMetaObject::invokeMethod(gui, "message",
1548  modal ? GUIUtil::blockingGUIThreadConnection() : Qt::QueuedConnection,
1549  Q_ARG(QString, QString::fromStdString(caption)),
1550  Q_ARG(QString, QString::fromStdString(message.translated)),
1551  Q_ARG(unsigned int, style),
1552  Q_ARG(bool*, &ret),
1553  Q_ARG(QString, detailed_message));
1554  assert(invoked);
1555  return ret;
1556 }
1557 
1559 {
1560  // Connect signals to client
1561  m_handler_message_box = m_node.handleMessageBox(std::bind(ThreadSafeMessageBox, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
1562  m_handler_question = m_node.handleQuestion(std::bind(ThreadSafeMessageBox, this, std::placeholders::_1, std::placeholders::_3, std::placeholders::_4));
1563 }
1564 
1566 {
1567  // Disconnect signals from client
1568  m_handler_message_box->disconnect();
1569  m_handler_question->disconnect();
1570 }
1571 
1573 {
1575  return m_mask_values_action->isChecked();
1576 }
1577 
1579  : m_platform_style{platformStyle}
1580 {
1581  createContextMenu();
1582  setToolTip(tr("Unit to show amounts in. Click to select another unit."));
1583  QList<BitcoinUnit> units = BitcoinUnits::availableUnits();
1584  int max_width = 0;
1585  const QFontMetrics fm(font());
1586  for (const BitcoinUnit unit : units) {
1587  max_width = qMax(max_width, GUIUtil::TextWidth(fm, BitcoinUnits::longName(unit)));
1588  }
1589  setMinimumSize(max_width, 0);
1590  setAlignment(Qt::AlignRight | Qt::AlignVCenter);
1591  setStyleSheet(QString("QLabel { color : %1 }").arg(m_platform_style->SingleColor().name()));
1592 }
1593 
1596 {
1597  onDisplayUnitsClicked(event->pos());
1598 }
1599 
1601 {
1602  if (e->type() == QEvent::PaletteChange) {
1603  QString style = QString("QLabel { color : %1 }").arg(m_platform_style->SingleColor().name());
1604  if (style != styleSheet()) {
1605  setStyleSheet(style);
1606  }
1607  }
1608 
1609  QLabel::changeEvent(e);
1610 }
1611 
1614 {
1615  menu = new QMenu(this);
1616  for (const BitcoinUnit u : BitcoinUnits::availableUnits()) {
1617  menu->addAction(BitcoinUnits::longName(u))->setData(QVariant::fromValue(u));
1618  }
1619  connect(menu, &QMenu::triggered, this, &UnitDisplayStatusBarControl::onMenuSelection);
1620 }
1621 
1624 {
1625  if (_optionsModel)
1626  {
1627  this->optionsModel = _optionsModel;
1628 
1629  // be aware of a display unit change reported by the OptionsModel object.
1631 
1632  // initialize the display units label with the current value in the model.
1633  updateDisplayUnit(_optionsModel->getDisplayUnit());
1634  }
1635 }
1636 
1639 {
1640  setText(BitcoinUnits::longName(newUnits));
1641 }
1642 
1645 {
1646  QPoint globalPos = mapToGlobal(point);
1647  menu->exec(globalPos);
1648 }
1649 
1652 {
1653  if (action)
1654  {
1655  optionsModel->setDisplayUnit(action->data());
1656  }
1657 }
virtual bool privateKeysDisabled()=0
void subscribeToCoreSignals()
Connect core signals to GUI client.
void unsubscribeFromCoreSignals()
Disconnect core signals from GUI client.
void showEvent(QShowEvent *event) override
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
void message(const QString &title, const QString &message, unsigned int style)
Fired when a message should be reported to the user.
static path PathFromString(const std::string &string)
Convert byte string to path object.
Definition: fs.h:173
WalletModel * currentWalletModel() const
Predefined combinations for certain default usage cases.
Definition: interface_ui.h:65
int ret
static QList< Unit > availableUnits()
Get list of units, for drop-down box.
QAction * receiveCoinsAction
Definition: bitcoingui.h:148
UnitDisplayStatusBarControl * unitDisplayControl
Definition: bitcoingui.h:125
Local Bitcoin RPC console.
Definition: rpcconsole.h:43
QMenuBar * appMenuBar
Definition: bitcoingui.h:135
void quitRequested()
Unit
Bitcoin units.
Definition: bitcoinunits.h:42
interfaces::Wallet & wallet() const
Definition: walletmodel.h:142
QAction * m_mask_values_action
Definition: bitcoingui.h:165
QAction * signMessageAction
Definition: bitcoingui.h:143
void setThemedPixmap(const QString &image_filename, int width, int height)
Definition: guiutil.cpp:843
void receivedURI(const QString &uri)
Signal raised when a URI was entered or dragged to the GUI.
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:87
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedSuffixOut)
Get open filename, convenience wrapper for QFileDialog::getOpenFileName.
Definition: guiutil.cpp:348
virtual bool getNetworkActive()=0
Get network active.
QAction * aboutAction
Definition: bitcoingui.h:147
void updateNetworkState()
Update UI with latest network info from model.
Definition: bitcoingui.cpp:984
assert(!tx.IsCoinBase())
void showNormalIfMinimized()
Show window if hidden, unminimize when minimized, rise when obscured or show if hidden and fToggleHid...
Definition: bitcoingui.h:313
UnitDisplayStatusBarControl(const PlatformStyle *platformStyle)
void createWalletButtonClicked()
QProgressDialog * progressDialog
Definition: bitcoingui.h:133
static bool isWalletEnabled()
void consoleShown(RPCConsole *console)
Signal raised when RPC console shown.
void createTrayIcon()
Create system tray icon and notification.
Definition: bitcoingui.cpp:808
Bilingual messages:
Definition: translation.h:18
void showDebugWindow()
Show debug window.
Definition: bitcoingui.cpp:918
GUIUtil::ClickableLabel * labelProxyIcon
Definition: bitcoingui.h:128
node::NodeContext m_node
Definition: bitcoin-gui.cpp:37
void PopupMenu(QMenu *menu, const QPoint &point, QAction *at_action)
Call QMenu::popup() only on supported QT_QPA_PLATFORM.
Definition: guiutil.cpp:942
ClientModel * clientModel
Definition: bitcoingui.h:122
void createToolBars()
Create the toolbars.
Definition: bitcoingui.cpp:565
int TextWidth(const QFontMetrics &fm, const QString &text)
Returns the distance in pixels appropriate for drawing a subsequent character after text...
Definition: guiutil.cpp:904
void setCurrentWallet(WalletModel *wallet_model)
Definition: walletframe.cpp:91
QAction * m_load_psbt_action
Definition: bitcoingui.h:145
void closeAllWallets(QWidget *parent=nullptr)
void setClientModel(ClientModel *model=nullptr, int bestblock_height=0, int64_t bestblock_date=0, double verification_progress=0.0)
Definition: rpcconsole.cpp:653
ModalOverlay * modalOverlay
Definition: bitcoingui.h:177
void createTrayIconMenu()
Create system tray menu (or setup the dock menu)
Definition: bitcoingui.cpp:821
RPCConsole * rpcConsole
Definition: bitcoingui.h:175
QAction * m_wallet_selector_action
Definition: bitcoingui.h:164
QAction * m_migrate_wallet_action
Definition: bitcoingui.h:166
QAction * overviewAction
Definition: bitcoingui.h:137
void opened(WalletModel *wallet_model)
QAction * verifyMessageAction
Definition: bitcoingui.h:144
QAction * quitAction
Definition: bitcoingui.h:139
void setPrivacy(bool privacy)
static constexpr int HEADER_HEIGHT_DELTA_SYNC
The required delta of headers to the estimated number of available headers until we show the IBD prog...
Definition: modaloverlay.h:13
QAction * m_open_wallet_action
Definition: bitcoingui.h:158
void triggered(bool hidden)
void usedReceivingAddresses()
Show used receiving addresses.
QAction * m_close_wallet_action
Definition: bitcoingui.h:161
static bool ThreadSafeMessageBox(BitcoinGUI *gui, const bilingual_str &message, const std::string &caption, unsigned int style)
Mask of all available buttons in CClientUIInterface::MessageBoxFlags This needs to be updated...
Definition: interface_ui.h:55
QAction * historyAction
Definition: bitcoingui.h:138
void tipUpdate(int count, const QDateTime &blockDate, double nVerificationProgress)
Qt::ConnectionType blockingGUIThreadConnection()
Get connection type to call object slot in GUI thread with invokeMethod.
Definition: guiutil.cpp:373
void updateHeadersPresyncProgressLabel(int64_t height, const QDateTime &blockDate)
void setWalletActionsEnabled(bool enabled)
Enable or disable all wallet-related actions.
Definition: bitcoingui.cpp:789
void networkActiveChanged(bool networkActive)
BitcoinUnit getDisplayUnit() const
Definition: optionsmodel.h:94
QAction * aboutQtAction
Definition: bitcoingui.h:153
#define PACKAGE_NAME
void setClientModel(ClientModel *clientModel=nullptr, interfaces::BlockAndHeaderTipInfo *tip_info=nullptr)
Set the client model.
Definition: bitcoingui.cpp:601
Controller between interfaces::Node, WalletModel instances and the GUI.
OptionsModel * getOptionsModel()
bool getShowTrayIcon() const
Definition: optionsmodel.h:91
QIcon SingleColorIcon(const QString &filename) const
Colorize an icon (given filename) with the icon color.
std::string translated
Definition: translation.h:20
QMenu * m_open_wallet_menu
Definition: bitcoingui.h:159
macOS-specific Dock icon handler.
void outOfSyncWarningClicked()
Notify that the out of sync warning icon has been pressed.
Bitcoin GUI main class.
Definition: bitcoingui.h:69
bool isLayerVisible() const
Definition: modaloverlay.h:33
virtual bool isLegacy()=0
Return whether is a legacy wallet.
HelpMessageDialog * helpMessageDialog
Definition: bitcoingui.h:176
QLabel * progressBarLabel
Definition: bitcoingui.h:131
QSystemTrayIcon * trayIcon
Definition: bitcoingui.h:172
QAction * showHelpMessageAction
Definition: bitcoingui.h:156
void ShowModalDialogAsynchronously(QDialog *dialog)
Shows a QDialog instance asynchronously, and deletes it on close.
Definition: guiutil.cpp:998
Notify user of potential problem.
Definition: notificator.h:39
Modal overlay to display information about the chain-sync state.
Definition: modaloverlay.h:20
bool isPrivacyModeActivated() const
void changeEvent(QEvent *e) override
const QString & getTitleAddText() const
Definition: networkstyle.h:24
void changeEvent(QEvent *e) override
void numConnectionsChanged(int count)
void setNetworkActive(bool network_active)
Set network state shown in the UI.
Signals for UI communication.
Definition: interface_ui.h:24
void removeAllWallets()
GUIUtil::ClickableLabel * connectionsControl
Definition: bitcoingui.h:129
QAction * backupWalletAction
Definition: bitcoingui.h:151
QAction * m_load_psbt_clipboard_action
Definition: bitcoingui.h:146
void setOptionsModel(OptionsModel *optionsModel)
Lets the control know about the Options Model (and its signals)
void dropEvent(QDropEvent *event) override
void bringToFront(QWidget *w)
Definition: guiutil.cpp:401
std::map< std::string, bool > listWalletDir() const
Returns all wallet names in the wallet dir mapped to whether the wallet is loaded.
QString tabTitle(TabTypes tab_type) const
static QString formatWithUnit(Unit unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD)
Format as string (with unit)
Force blocking, modal message box dialog (not just OS notification)
Definition: interface_ui.h:59
void openOptionsDialogWithTab(OptionsDialog::Tab tab)
Open the OptionsDialog on the specified tab index.
EncryptionStatus getEncryptionStatus() const
virtual std::unique_ptr< Handler > handleMessageBox(MessageBoxFn fn)=0
void showOutOfSyncWarning(bool fShow)
void gotoHistoryPage()
Switch to history (transactions) page.
QAction * usedReceivingAddressesAction
Definition: bitcoingui.h:142
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
void showModalOverlay()
const NetworkStyle *const m_network_style
Definition: bitcoingui.h:190
WalletController * m_wallet_controller
Definition: bitcoingui.h:119
void gotoOverviewPage()
Switch to overview (home) page.
BlockSource getBlockSource() const
Returns the block source of the current importing/syncing state.
const PlatformStyle * platformStyle
Definition: bitcoingui.h:189
void displayUnitChanged(BitcoinUnit unit)
virtual bool hdEnabled()=0
void showProgress(const QString &title, int nProgress)
Show progress dialog e.g.
static MacDockIconHandler * instance()
void setClientModel(ClientModel *clientModel)
Definition: walletframe.cpp:60
bool isObscured(QWidget *w)
Definition: guiutil.cpp:392
QAction * m_wallet_selector_label_action
Definition: bitcoingui.h:163
int getNumConnections(unsigned int flags=CONNECTIONS_ALL) const
Return number of connections, default is in- and outbound (total)
Definition: clientmodel.cpp:77
OptionsModel * optionsModel
Definition: bitcoingui.h:342
void created(WalletModel *wallet_model)
QLabel * m_wallet_selector_label
Definition: bitcoingui.h:169
void optionsClicked()
Show configuration dialog.
Definition: bitcoingui.cpp:904
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 closeWallet(WalletModel *wallet_model, QWidget *parent=nullptr)
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
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.
bool HasPixmap(const QLabel *label)
Returns true if pixmap has been set.
Definition: guiutil.cpp:958
void handleCloseWindowShortcut(QWidget *w)
Definition: guiutil.cpp:419
void notify(Class cls, const QString &title, const QString &text, const QIcon &icon=QIcon(), int millisTimeout=10000)
Show notification message.
const char * name
Definition: rest.cpp:45
QToolBar * appToolBar
Definition: bitcoingui.h:136
BlockSource
Definition: clientmodel.h:33
WalletFrame * walletFrame
Definition: bitcoingui.h:123
WalletView * currentWalletView() const
QAction * usedSendingAddressesAction
Definition: bitcoingui.h:141
void setTabFocus(enum TabTypes tabType)
set which tab has the focus (is visible)
int64_t nPowTargetSpacing
Definition: params.h:112
BitcoinGUI(interfaces::Node &node, const PlatformStyle *platformStyle, const NetworkStyle *networkStyle, QWidget *parent=nullptr)
Definition: bitcoingui.cpp:83
void updateDisplayUnit(BitcoinUnit newUnits)
When Display Units are changed on OptionsModel it will refresh the display text of the control on the...
void message(const QString &title, const QString &message, unsigned int style)
Fired when a message should be reported to the user.
void numBlocksChanged(int count, const QDateTime &blockDate, double nVerificationProgress, SyncType header, SynchronizationState sync_state)
void toggleVisibility()
QVariant getOption(OptionID option, const std::string &suffix="") const
bool enableWallet
Definition: bitcoingui.h:97
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.html#connect-3), that guaranties that all exceptions are handled within the slot.
Definition: guiutil.h:391
QAction * openRPCConsoleAction
Definition: bitcoingui.h:154
QAction * m_close_all_wallets_action
Definition: bitcoingui.h:162
void currentWalletSet()
std::vector< TabTypes > tabs() const
Definition: rpcconsole.h:78
void detectShutdown()
called by a timer to check if ShutdownRequested() has been set
void migrated(WalletModel *wallet_model)
Cross-platform desktop notification client.
Definition: notificator.h:24
void clicked(const QPoint &point)
Emitted when the label is clicked.
Block and header tip information.
Definition: node.h:49
void setKnownBestHeight(int count, const QDateTime &blockDate, bool presync)
GUIUtil::ClickableLabel * labelBlocksIcon
Definition: bitcoingui.h:130
Informational message.
Definition: notificator.h:38
GUIUtil::ClickableProgressBar * progressBar
Definition: bitcoingui.h:132
void updateWindowTitle()
void showHelpMessageClicked()
Show help message dialog.
Definition: bitcoingui.cpp:930
QString getWalletName() const
void walletAdded(WalletModel *wallet_model)
void message(const QString &title, const QString &message, unsigned int style)
Notificator * notificator
Definition: bitcoingui.h:174
void PolishProgressDialog(QProgressDialog *dialog)
Definition: guiutil.cpp:890
void changePassphrase()
Change encrypted wallet passphrase.
Model for Bitcoin network client.
Definition: clientmodel.h:53
An error occurred.
Definition: notificator.h:40
void restored(WalletModel *wallet_model)
const QIcon & getTrayAndWindowIcon() const
Definition: networkstyle.h:23
void mousePressEvent(QMouseEvent *event) override
So that it responds to left-button clicks.
ClickableProgressBar ProgressBar
Definition: guiutil.h:300
void gotoSignMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to sign message tab.
virtual bool shutdownRequested()=0
Return whether shutdown was requested.
virtual std::vector< std::unique_ptr< Wallet > > getWallets()=0
Return interfaces for accessing wallets (if any).
QAction * sendCoinsAction
Definition: bitcoingui.h:140
void showHide(bool hide=false, bool userRequested=false)
QAction * m_create_wallet_action
Definition: bitcoingui.h:157
SyncType
Definition: clientmodel.h:39
QKeySequence tabShortcut(TabTypes tab_type) const
Definition: init.h:25
static const int STATUSBAR_ICONSIZE
Definition: guiconstants.h:23
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.
QColor SingleColor() const
void encryptionStatusChanged()
Encryption status of wallet changed.
QAction * openAction
Definition: bitcoingui.h:155
bool getMinimizeOnClose() const
Definition: optionsmodel.h:93
void updateProxyIcon()
Set the proxy-enabled icon as shown in the UI.
QAction * changePassphraseAction
Definition: bitcoingui.h:152
void gotoSendCoinsPage(QString addr="")
Switch to send coins page.
virtual std::unique_ptr< Handler > handleQuestion(QuestionFn fn)=0
void encryptWallet()
Encrypt the wallet.
void gotoReceiveCoinsPage()
Switch to receive coins page.
const std::unique_ptr< QMenu > trayIconMenu
Definition: bitcoingui.h:173
QMenu * m_network_context_menu
Definition: bitcoingui.h:179
void setPrivacy(bool privacy)
std::string original
Definition: translation.h:19
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:40
std::unique_ptr< interfaces::Handler > m_handler_question
Definition: bitcoingui.h:121
const CChainParams & Params()
Return the currently selected parameters.
bool getMinimizeToTray() const
Definition: optionsmodel.h:92
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:51
virtual WalletLoader & walletLoader()=0
Get wallet loader.
QAction * m_restore_wallet_action
Definition: bitcoingui.h:160
bool eventFilter(QObject *object, QEvent *event) override
WalletModel * getWalletModel() const noexcept
Definition: walletview.h:46
int prevBlocks
Keep track of previous number of blocks, to detect progress.
Definition: bitcoingui.h:186
void toggleHidden()
Simply calls showNormalIfMinimized(true)
interfaces::Node & m_node
Definition: bitcoingui.h:118
int spinnerFrame
Definition: bitcoingui.h:187
void walletRemoved(WalletModel *wallet_model)
GUIUtil::ThemedLabel * labelWalletEncryptionIcon
Definition: bitcoingui.h:126
static int count
void setNumConnections(int count)
Set number of connections shown in the UI.
QString getDisplayName() const
"Help message" dialog box
Definition: utilitydialog.h:20
void backupWallet()
Backup the wallet.
void closeEvent(QCloseEvent *event) override
QComboBox * m_wallet_selector
Definition: bitcoingui.h:170
bool addView(WalletView *walletView)
Definition: walletframe.cpp:69
Preferences dialog.
Definition: optionsdialog.h:36
void clicked(const QPoint &point)
Emitted when the progressbar is clicked.
QString formatNiceTimeOffset(qint64 secs)
Definition: guiutil.cpp:776
void createContextMenu()
Creates context menu, its actions, and wires up all the relevant signals for mouse events...
void showDebugWindowActivateConsole()
Show debug window and set focus to the console.
Definition: bitcoingui.cpp:924
void createActions()
Create the main UI actions.
Definition: bitcoingui.cpp:245
QAction * optionsAction
Definition: bitcoingui.h:149
QAction * encryptWalletAction
Definition: bitcoingui.h:150
void aboutClicked()
Show about dialog.
Definition: bitcoingui.cpp:909
const Consensus::Params & GetConsensus() const
Definition: chainparams.h:93
const PlatformStyle * m_platform_style
Definition: bitcoingui.h:344
void createWallet()
Launch the wallet creation modal (no-op if wallet is not compiled)
void removeWallet(WalletModel *wallet_model)
int getHeaderTipHeight() const
Definition: clientmodel.cpp:91
void updateHeadersSyncProgressLabel()
void gotoLoadPSBT(bool from_clipboard=false)
Load Partially Signed Bitcoin Transaction.
int64_t GetTime()
DEPRECATED, see GetTime.
Definition: time.cpp:97
static const std::string DEFAULT_UIPLATFORM
Definition: bitcoingui.h:74
static QString longName(Unit unit)
Long name.
virtual void setNetworkActive(bool active)=0
Set network active.
int64_t getHeaderTipTime() const
GUIUtil::ThemedLabel * labelWalletHDStatusIcon
Definition: bitcoingui.h:127
static RPCHelpMan help()
Definition: server.cpp:137
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:69
void transactionClicked()
static constexpr int64_t MAX_BLOCK_TIME_GAP
Maximum gap between node time and block time used for the "Catching up..." mode in GUI...
Definition: chain.h:40
A container for embedding all wallet-related controls into BitcoinGUI.
Definition: walletframe.h:28
void showProgress(const QString &title, int nProgress)
void usedSendingAddresses()
Show used sending addresses.
void setDisplayUnit(const QVariant &new_unit)
Updates current unit in memory, settings and emits displayUnitChanged(new_unit) signal.
void onDisplayUnitsClicked(const QPoint &point)
Shows context menu with Display Unit options by the mouse coordinates.
void createMenuBar()
Create the menu bar and sub-menus.
Definition: bitcoingui.cpp:471
void onMenuSelection(QAction *action)
Tells underlying optionsModel to update its current display unit.
std::unique_ptr< interfaces::Handler > m_handler_message_box
Definition: bitcoingui.h:120
void showTrayIconChanged(bool)
#define SPINNER_FRAMES
Definition: guiconstants.h:47
void dragEnterEvent(QDragEnterEvent *event) override
bool getProxyInfo(std::string &ip_port) const