Bitcoin Core  24.1.0
P2P Digital Currency
bitcoingui.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2021 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 <functional>
34 #include <chain.h>
35 #include <chainparams.h>
36 #include <interfaces/handler.h>
37 #include <interfaces/node.h>
38 #include <node/interface_ui.h>
39 #include <util/system.h>
40 #include <util/translation.h>
41 #include <validation.h>
42 
43 #include <QAction>
44 #include <QActionGroup>
45 #include <QApplication>
46 #include <QComboBox>
47 #include <QCursor>
48 #include <QDateTime>
49 #include <QDragEnterEvent>
50 #include <QInputDialog>
51 #include <QKeySequence>
52 #include <QListWidget>
53 #include <QMenu>
54 #include <QMenuBar>
55 #include <QMessageBox>
56 #include <QMimeData>
57 #include <QProgressDialog>
58 #include <QScreen>
59 #include <QSettings>
60 #include <QShortcut>
61 #include <QStackedWidget>
62 #include <QStatusBar>
63 #include <QStyle>
64 #include <QSystemTrayIcon>
65 #include <QTimer>
66 #include <QToolBar>
67 #include <QUrlQuery>
68 #include <QVBoxLayout>
69 #include <QWindow>
70 
71 
72 const std::string BitcoinGUI::DEFAULT_UIPLATFORM =
73 #if defined(Q_OS_MACOS)
74  "macosx"
75 #elif defined(Q_OS_WIN)
76  "windows"
77 #else
78  "other"
79 #endif
80  ;
81 
82 BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformStyle, const NetworkStyle *networkStyle, QWidget *parent) :
83  QMainWindow(parent),
84  m_node(node),
85  trayIconMenu{new QMenu()},
86  platformStyle(_platformStyle),
87  m_network_style(networkStyle)
88 {
89  QSettings settings;
90  if (!restoreGeometry(settings.value("MainWindowGeometry").toByteArray())) {
91  // Restore failed (perhaps missing setting), center the window
92  move(QGuiApplication::primaryScreen()->availableGeometry().center() - frameGeometry().center());
93  }
94 
95  setContextMenuPolicy(Qt::PreventContextMenu);
96 
97 #ifdef ENABLE_WALLET
98  enableWallet = WalletModel::isWalletEnabled();
99 #endif // ENABLE_WALLET
100  QApplication::setWindowIcon(m_network_style->getTrayAndWindowIcon());
101  setWindowIcon(m_network_style->getTrayAndWindowIcon());
102  updateWindowTitle();
103 
104  rpcConsole = new RPCConsole(node, _platformStyle, nullptr);
105  helpMessageDialog = new HelpMessageDialog(this, false);
106 #ifdef ENABLE_WALLET
107  if(enableWallet)
108  {
110  walletFrame = new WalletFrame(_platformStyle, this);
111  connect(walletFrame, &WalletFrame::createWalletButtonClicked, [this] {
112  auto activity = new CreateWalletActivity(getWalletController(), this);
113  activity->create();
114  });
115  connect(walletFrame, &WalletFrame::message, [this](const QString& title, const QString& message, unsigned int style) {
116  this->message(title, message, style);
117  });
118  connect(walletFrame, &WalletFrame::currentWalletSet, [this] { updateWalletStatus(); });
119  setCentralWidget(walletFrame);
120  } else
121 #endif // ENABLE_WALLET
122  {
123  /* When compiled without wallet or -disablewallet is provided,
124  * the central widget is the rpc console.
125  */
126  setCentralWidget(rpcConsole);
127  Q_EMIT consoleShown(rpcConsole);
128  }
129 
130  modalOverlay = new ModalOverlay(enableWallet, this->centralWidget());
131 
132  // Accept D&D of URIs
133  setAcceptDrops(true);
134 
135  // Create actions for the toolbar, menu bar and tray/dock icon
136  // Needs walletFrame to be initialized
137  createActions();
138 
139  // Create application menu bar
140  createMenuBar();
141 
142  // Create the toolbars
143  createToolBars();
144 
145  // Create system tray icon and notification
146  if (QSystemTrayIcon::isSystemTrayAvailable()) {
147  createTrayIcon();
148  }
149  notificator = new Notificator(QApplication::applicationName(), trayIcon, this);
150 
151  // Create status bar
152  statusBar();
153 
154  // Disable size grip because it looks ugly and nobody needs it
155  statusBar()->setSizeGripEnabled(false);
156 
157  // Status bar notification icons
158  QFrame *frameBlocks = new QFrame();
159  frameBlocks->setContentsMargins(0,0,0,0);
160  frameBlocks->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
161  QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);
162  frameBlocksLayout->setContentsMargins(3,0,3,0);
163  frameBlocksLayout->setSpacing(3);
164  unitDisplayControl = new UnitDisplayStatusBarControl(platformStyle);
165  labelWalletEncryptionIcon = new GUIUtil::ThemedLabel(platformStyle);
166  labelWalletHDStatusIcon = new GUIUtil::ThemedLabel(platformStyle);
167  labelProxyIcon = new GUIUtil::ClickableLabel(platformStyle);
168  connectionsControl = new GUIUtil::ClickableLabel(platformStyle);
169  labelBlocksIcon = new GUIUtil::ClickableLabel(platformStyle);
170  if(enableWallet)
171  {
172  frameBlocksLayout->addStretch();
173  frameBlocksLayout->addWidget(unitDisplayControl);
174  frameBlocksLayout->addStretch();
175  frameBlocksLayout->addWidget(labelWalletEncryptionIcon);
176  labelWalletEncryptionIcon->hide();
177  frameBlocksLayout->addWidget(labelWalletHDStatusIcon);
178  labelWalletHDStatusIcon->hide();
179  }
180  frameBlocksLayout->addWidget(labelProxyIcon);
181  frameBlocksLayout->addStretch();
182  frameBlocksLayout->addWidget(connectionsControl);
183  frameBlocksLayout->addStretch();
184  frameBlocksLayout->addWidget(labelBlocksIcon);
185  frameBlocksLayout->addStretch();
186 
187  // Progress bar and label for blocks download
188  progressBarLabel = new QLabel();
189  progressBarLabel->setVisible(false);
190  progressBar = new GUIUtil::ProgressBar();
191  progressBar->setAlignment(Qt::AlignCenter);
192  progressBar->setVisible(false);
193 
194  // Override style sheet for progress bar for styles that have a segmented progress bar,
195  // as they make the text unreadable (workaround for issue #1071)
196  // See https://doc.qt.io/qt-5/gallery.html
197  QString curStyle = QApplication::style()->metaObject()->className();
198  if(curStyle == "QWindowsStyle" || curStyle == "QWindowsXPStyle")
199  {
200  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; }");
201  }
202 
203  statusBar()->addWidget(progressBarLabel);
204  statusBar()->addWidget(progressBar);
205  statusBar()->addPermanentWidget(frameBlocks);
206 
207  // Install event filter to be able to catch status tip events (QEvent::StatusTip)
208  this->installEventFilter(this);
209 
210  // Initially wallet actions should be disabled
211  setWalletActionsEnabled(false);
212 
213  // Subscribe to notifications from core
214  subscribeToCoreSignals();
215 
216  connect(labelProxyIcon, &GUIUtil::ClickableLabel::clicked, [this] {
217  openOptionsDialogWithTab(OptionsDialog::TAB_NETWORK);
218  });
219 
220  connect(labelBlocksIcon, &GUIUtil::ClickableLabel::clicked, this, &BitcoinGUI::showModalOverlay);
222 
223 #ifdef Q_OS_MACOS
224  m_app_nap_inhibitor = new CAppNapInhibitor;
225 #endif
226 
228 }
229 
231 {
232  // Unsubscribe from notifications from core
234 
235  QSettings settings;
236  settings.setValue("MainWindowGeometry", saveGeometry());
237  if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu)
238  trayIcon->hide();
239 #ifdef Q_OS_MACOS
240  delete m_app_nap_inhibitor;
241  delete appMenuBar;
243 #endif
244 
245  delete rpcConsole;
246 }
247 
249 {
250  QActionGroup *tabGroup = new QActionGroup(this);
251  connect(modalOverlay, &ModalOverlay::triggered, tabGroup, &QActionGroup::setEnabled);
252 
253  overviewAction = new QAction(platformStyle->SingleColorIcon(":/icons/overview"), tr("&Overview"), this);
254  overviewAction->setStatusTip(tr("Show general overview of wallet"));
255  overviewAction->setToolTip(overviewAction->statusTip());
256  overviewAction->setCheckable(true);
257  overviewAction->setShortcut(QKeySequence(QStringLiteral("Alt+1")));
258  tabGroup->addAction(overviewAction);
259 
260  sendCoinsAction = new QAction(platformStyle->SingleColorIcon(":/icons/send"), tr("&Send"), this);
261  sendCoinsAction->setStatusTip(tr("Send coins to a Bitcoin address"));
262  sendCoinsAction->setToolTip(sendCoinsAction->statusTip());
263  sendCoinsAction->setCheckable(true);
264  sendCoinsAction->setShortcut(QKeySequence(QStringLiteral("Alt+2")));
265  tabGroup->addAction(sendCoinsAction);
266 
267  receiveCoinsAction = new QAction(platformStyle->SingleColorIcon(":/icons/receiving_addresses"), tr("&Receive"), this);
268  receiveCoinsAction->setStatusTip(tr("Request payments (generates QR codes and bitcoin: URIs)"));
269  receiveCoinsAction->setToolTip(receiveCoinsAction->statusTip());
270  receiveCoinsAction->setCheckable(true);
271  receiveCoinsAction->setShortcut(QKeySequence(QStringLiteral("Alt+3")));
272  tabGroup->addAction(receiveCoinsAction);
273 
274  historyAction = new QAction(platformStyle->SingleColorIcon(":/icons/history"), tr("&Transactions"), this);
275  historyAction->setStatusTip(tr("Browse transaction history"));
276  historyAction->setToolTip(historyAction->statusTip());
277  historyAction->setCheckable(true);
278  historyAction->setShortcut(QKeySequence(QStringLiteral("Alt+4")));
279  tabGroup->addAction(historyAction);
280 
281 #ifdef ENABLE_WALLET
282  // These showNormalIfMinimized are needed because Send Coins and Receive Coins
283  // can be triggered from the tray menu, and need to show the GUI to be useful.
284  connect(overviewAction, &QAction::triggered, [this]{ showNormalIfMinimized(); });
285  connect(overviewAction, &QAction::triggered, this, &BitcoinGUI::gotoOverviewPage);
286  connect(sendCoinsAction, &QAction::triggered, [this]{ showNormalIfMinimized(); });
287  connect(sendCoinsAction, &QAction::triggered, [this]{ gotoSendCoinsPage(); });
288  connect(receiveCoinsAction, &QAction::triggered, [this]{ showNormalIfMinimized(); });
289  connect(receiveCoinsAction, &QAction::triggered, this, &BitcoinGUI::gotoReceiveCoinsPage);
290  connect(historyAction, &QAction::triggered, [this]{ showNormalIfMinimized(); });
291  connect(historyAction, &QAction::triggered, this, &BitcoinGUI::gotoHistoryPage);
292 #endif // ENABLE_WALLET
293 
294  quitAction = new QAction(tr("E&xit"), this);
295  quitAction->setStatusTip(tr("Quit application"));
296  quitAction->setShortcut(QKeySequence(tr("Ctrl+Q")));
297  quitAction->setMenuRole(QAction::QuitRole);
298  aboutAction = new QAction(tr("&About %1").arg(PACKAGE_NAME), this);
299  aboutAction->setStatusTip(tr("Show information about %1").arg(PACKAGE_NAME));
300  aboutAction->setMenuRole(QAction::AboutRole);
301  aboutAction->setEnabled(false);
302  aboutQtAction = new QAction(tr("About &Qt"), this);
303  aboutQtAction->setStatusTip(tr("Show information about Qt"));
304  aboutQtAction->setMenuRole(QAction::AboutQtRole);
305  optionsAction = new QAction(tr("&Options…"), this);
306  optionsAction->setStatusTip(tr("Modify configuration options for %1").arg(PACKAGE_NAME));
307  optionsAction->setMenuRole(QAction::PreferencesRole);
308  optionsAction->setEnabled(false);
309 
310  encryptWalletAction = new QAction(tr("&Encrypt Wallet…"), this);
311  encryptWalletAction->setStatusTip(tr("Encrypt the private keys that belong to your wallet"));
312  encryptWalletAction->setCheckable(true);
313  backupWalletAction = new QAction(tr("&Backup Wallet…"), this);
314  backupWalletAction->setStatusTip(tr("Backup wallet to another location"));
315  changePassphraseAction = new QAction(tr("&Change Passphrase…"), this);
316  changePassphraseAction->setStatusTip(tr("Change the passphrase used for wallet encryption"));
317  signMessageAction = new QAction(tr("Sign &message…"), this);
318  signMessageAction->setStatusTip(tr("Sign messages with your Bitcoin addresses to prove you own them"));
319  verifyMessageAction = new QAction(tr("&Verify message…"), this);
320  verifyMessageAction->setStatusTip(tr("Verify messages to ensure they were signed with specified Bitcoin addresses"));
321  m_load_psbt_action = new QAction(tr("&Load PSBT from file…"), this);
322  m_load_psbt_action->setStatusTip(tr("Load Partially Signed Bitcoin Transaction"));
323  m_load_psbt_clipboard_action = new QAction(tr("Load PSBT from &clipboard…"), this);
324  m_load_psbt_clipboard_action->setStatusTip(tr("Load Partially Signed Bitcoin Transaction from clipboard"));
325 
326  openRPCConsoleAction = new QAction(tr("Node window"), this);
327  openRPCConsoleAction->setStatusTip(tr("Open node debugging and diagnostic console"));
328  // initially disable the debug window menu item
329  openRPCConsoleAction->setEnabled(false);
330  openRPCConsoleAction->setObjectName("openRPCConsoleAction");
331 
332  usedSendingAddressesAction = new QAction(tr("&Sending addresses"), this);
333  usedSendingAddressesAction->setStatusTip(tr("Show the list of used sending addresses and labels"));
334  usedReceivingAddressesAction = new QAction(tr("&Receiving addresses"), this);
335  usedReceivingAddressesAction->setStatusTip(tr("Show the list of used receiving addresses and labels"));
336 
337  openAction = new QAction(tr("Open &URI…"), this);
338  openAction->setStatusTip(tr("Open a bitcoin: URI"));
339 
340  m_open_wallet_action = new QAction(tr("Open Wallet"), this);
341  m_open_wallet_action->setEnabled(false);
342  m_open_wallet_action->setStatusTip(tr("Open a wallet"));
343  m_open_wallet_menu = new QMenu(this);
344 
345  m_close_wallet_action = new QAction(tr("Close Wallet…"), this);
346  m_close_wallet_action->setStatusTip(tr("Close wallet"));
347 
348  m_create_wallet_action = new QAction(tr("Create Wallet…"), this);
349  m_create_wallet_action->setEnabled(false);
350  m_create_wallet_action->setStatusTip(tr("Create a new wallet"));
351 
352  //: Name of the menu item that restores wallet from a backup file.
353  m_restore_wallet_action = new QAction(tr("Restore Wallet…"), this);
354  m_restore_wallet_action->setEnabled(false);
355  //: Status tip for Restore Wallet menu item
356  m_restore_wallet_action->setStatusTip(tr("Restore a wallet from a backup file"));
357 
358  m_close_all_wallets_action = new QAction(tr("Close All Wallets…"), this);
359  m_close_all_wallets_action->setStatusTip(tr("Close all wallets"));
360 
361  showHelpMessageAction = new QAction(tr("&Command-line options"), this);
362  showHelpMessageAction->setMenuRole(QAction::NoRole);
363  showHelpMessageAction->setStatusTip(tr("Show the %1 help message to get a list with possible Bitcoin command-line options").arg(PACKAGE_NAME));
364 
365  m_mask_values_action = new QAction(tr("&Mask values"), this);
366  m_mask_values_action->setShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_M));
367  m_mask_values_action->setStatusTip(tr("Mask the values in the Overview tab"));
368  m_mask_values_action->setCheckable(true);
369 
370  connect(quitAction, &QAction::triggered, this, &BitcoinGUI::quitRequested);
371  connect(aboutAction, &QAction::triggered, this, &BitcoinGUI::aboutClicked);
372  connect(aboutQtAction, &QAction::triggered, qApp, QApplication::aboutQt);
373  connect(optionsAction, &QAction::triggered, this, &BitcoinGUI::optionsClicked);
374  connect(showHelpMessageAction, &QAction::triggered, this, &BitcoinGUI::showHelpMessageClicked);
375  connect(openRPCConsoleAction, &QAction::triggered, this, &BitcoinGUI::showDebugWindow);
376  // prevents an open debug window from becoming stuck/unusable on client shutdown
377  connect(quitAction, &QAction::triggered, rpcConsole, &QWidget::hide);
378 
379 #ifdef ENABLE_WALLET
380  if(walletFrame)
381  {
382  connect(encryptWalletAction, &QAction::triggered, walletFrame, &WalletFrame::encryptWallet);
383  connect(backupWalletAction, &QAction::triggered, walletFrame, &WalletFrame::backupWallet);
384  connect(changePassphraseAction, &QAction::triggered, walletFrame, &WalletFrame::changePassphrase);
385  connect(signMessageAction, &QAction::triggered, [this]{ showNormalIfMinimized(); });
386  connect(signMessageAction, &QAction::triggered, [this]{ gotoSignMessageTab(); });
387  connect(m_load_psbt_action, &QAction::triggered, [this]{ gotoLoadPSBT(); });
388  connect(m_load_psbt_clipboard_action, &QAction::triggered, [this]{ gotoLoadPSBT(true); });
389  connect(verifyMessageAction, &QAction::triggered, [this]{ showNormalIfMinimized(); });
390  connect(verifyMessageAction, &QAction::triggered, [this]{ gotoVerifyMessageTab(); });
393  connect(openAction, &QAction::triggered, this, &BitcoinGUI::openClicked);
394  connect(m_open_wallet_menu, &QMenu::aboutToShow, [this] {
395  m_open_wallet_menu->clear();
396  for (const std::pair<const std::string, bool>& i : m_wallet_controller->listWalletDir()) {
397  const std::string& path = i.first;
398  QString name = path.empty() ? QString("["+tr("default wallet")+"]") : QString::fromStdString(path);
399  // Menu items remove single &. Single & are shown when && is in
400  // the string, but only the first occurrence. So replace only
401  // the first & with &&.
402  name.replace(name.indexOf(QChar('&')), 1, QString("&&"));
403  QAction* action = m_open_wallet_menu->addAction(name);
404 
405  if (i.second) {
406  // This wallet is already loaded
407  action->setEnabled(false);
408  continue;
409  }
410 
411  connect(action, &QAction::triggered, [this, path] {
412  auto activity = new OpenWalletActivity(m_wallet_controller, this);
413  connect(activity, &OpenWalletActivity::opened, this, &BitcoinGUI::setCurrentWallet);
414  activity->open(path);
415  });
416  }
417  if (m_open_wallet_menu->isEmpty()) {
418  QAction* action = m_open_wallet_menu->addAction(tr("No wallets available"));
419  action->setEnabled(false);
420  }
421  });
422  connect(m_restore_wallet_action, &QAction::triggered, [this] {
423  //: Name of the wallet data file format.
424  QString name_data_file = tr("Wallet Data");
425 
426  //: The title for Restore Wallet File Windows
427  QString title_windows = tr("Load Wallet Backup");
428 
429  QString backup_file = GUIUtil::getOpenFileName(this, title_windows, QString(), name_data_file + QLatin1String(" (*.dat)"), nullptr);
430  if (backup_file.isEmpty()) return;
431 
432  bool wallet_name_ok;
433  /*: Title of pop-up window shown when the user is attempting to
434  restore a wallet. */
435  QString title = tr("Restore Wallet");
436  //: Label of the input field where the name of the wallet is entered.
437  QString label = tr("Wallet Name");
438  QString wallet_name = QInputDialog::getText(this, title, label, QLineEdit::Normal, "", &wallet_name_ok);
439  if (!wallet_name_ok || wallet_name.isEmpty()) return;
440 
441  auto activity = new RestoreWalletActivity(m_wallet_controller, this);
442  connect(activity, &RestoreWalletActivity::restored, this, &BitcoinGUI::setCurrentWallet, Qt::QueuedConnection);
443 
444  auto backup_file_path = fs::PathFromString(backup_file.toStdString());
445  activity->restore(backup_file_path, wallet_name.toStdString());
446  });
447  connect(m_close_wallet_action, &QAction::triggered, [this] {
449  });
450  connect(m_create_wallet_action, &QAction::triggered, [this] {
451  auto activity = new CreateWalletActivity(m_wallet_controller, this);
452  connect(activity, &CreateWalletActivity::created, this, &BitcoinGUI::setCurrentWallet);
453  activity->create();
454  });
455  connect(m_close_all_wallets_action, &QAction::triggered, [this] {
457  });
458  connect(m_mask_values_action, &QAction::toggled, this, &BitcoinGUI::setPrivacy);
459  }
460 #endif // ENABLE_WALLET
461 
462  connect(new QShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_C), this), &QShortcut::activated, this, &BitcoinGUI::showDebugWindowActivateConsole);
463  connect(new QShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_D), this), &QShortcut::activated, this, &BitcoinGUI::showDebugWindow);
464 }
465 
467 {
468 #ifdef Q_OS_MACOS
469  // Create a decoupled menu bar on Mac which stays even if the window is closed
470  appMenuBar = new QMenuBar();
471 #else
472  // Get the main window's menu bar on other platforms
473  appMenuBar = menuBar();
474 #endif
475 
476  // Configure the menus
477  QMenu *file = appMenuBar->addMenu(tr("&File"));
478  if(walletFrame)
479  {
480  file->addAction(m_create_wallet_action);
481  file->addAction(m_open_wallet_action);
482  file->addAction(m_close_wallet_action);
483  file->addAction(m_close_all_wallets_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  } else {
651  if(trayIconMenu)
652  {
653  // Disable context menu on tray icon
654  trayIconMenu->clear();
655  }
656  // Propagate cleared model to child objects
657  rpcConsole->setClientModel(nullptr);
658 #ifdef ENABLE_WALLET
659  if (walletFrame)
660  {
661  walletFrame->setClientModel(nullptr);
662  }
663 #endif // ENABLE_WALLET
665  }
666 }
667 
668 #ifdef ENABLE_WALLET
669 void BitcoinGUI::setWalletController(WalletController* wallet_controller)
670 {
672  assert(wallet_controller);
673 
674  m_wallet_controller = wallet_controller;
675 
676  m_create_wallet_action->setEnabled(true);
677  m_open_wallet_action->setEnabled(true);
679  m_restore_wallet_action->setEnabled(true);
680 
681  GUIUtil::ExceptionSafeConnect(wallet_controller, &WalletController::walletAdded, this, &BitcoinGUI::addWallet);
682  connect(wallet_controller, &WalletController::walletRemoved, this, &BitcoinGUI::removeWallet);
683 
684  auto activity = new LoadWalletsActivity(m_wallet_controller, this);
685  activity->load();
686 }
687 
688 WalletController* BitcoinGUI::getWalletController()
689 {
690  return m_wallet_controller;
691 }
692 
693 void BitcoinGUI::addWallet(WalletModel* walletModel)
694 {
695  if (!walletFrame) return;
696 
697  WalletView* wallet_view = new WalletView(walletModel, platformStyle, walletFrame);
698  if (!walletFrame->addView(wallet_view)) return;
699 
700  rpcConsole->addWallet(walletModel);
701  if (m_wallet_selector->count() == 0) {
703  } else if (m_wallet_selector->count() == 1) {
704  m_wallet_selector_label_action->setVisible(true);
705  m_wallet_selector_action->setVisible(true);
706  }
707 
709  connect(wallet_view, &WalletView::transactionClicked, this, &BitcoinGUI::gotoHistoryPage);
710  connect(wallet_view, &WalletView::coinsSent, this, &BitcoinGUI::gotoHistoryPage);
711  connect(wallet_view, &WalletView::message, [this](const QString& title, const QString& message, unsigned int style) {
712  this->message(title, message, style);
713  });
714  connect(wallet_view, &WalletView::encryptionStatusChanged, this, &BitcoinGUI::updateWalletStatus);
715  connect(wallet_view, &WalletView::incomingTransaction, this, &BitcoinGUI::incomingTransaction);
716  connect(this, &BitcoinGUI::setPrivacy, wallet_view, &WalletView::setPrivacy);
717  wallet_view->setPrivacy(isPrivacyModeActivated());
718  const QString display_name = walletModel->getDisplayName();
719  m_wallet_selector->addItem(display_name, QVariant::fromValue(walletModel));
720 }
721 
722 void BitcoinGUI::removeWallet(WalletModel* walletModel)
723 {
724  if (!walletFrame) return;
725 
726  labelWalletHDStatusIcon->hide();
728 
729  int index = m_wallet_selector->findData(QVariant::fromValue(walletModel));
730  m_wallet_selector->removeItem(index);
731  if (m_wallet_selector->count() == 0) {
733  overviewAction->setChecked(true);
734  } else if (m_wallet_selector->count() == 1) {
735  m_wallet_selector_label_action->setVisible(false);
736  m_wallet_selector_action->setVisible(false);
737  }
738  rpcConsole->removeWallet(walletModel);
739  walletFrame->removeWallet(walletModel);
741 }
742 
743 void BitcoinGUI::setCurrentWallet(WalletModel* wallet_model)
744 {
745  if (!walletFrame) return;
746  walletFrame->setCurrentWallet(wallet_model);
747  for (int index = 0; index < m_wallet_selector->count(); ++index) {
748  if (m_wallet_selector->itemData(index).value<WalletModel*>() == wallet_model) {
749  m_wallet_selector->setCurrentIndex(index);
750  break;
751  }
752  }
754 }
755 
756 void BitcoinGUI::setCurrentWalletBySelectorIndex(int index)
757 {
758  WalletModel* wallet_model = m_wallet_selector->itemData(index).value<WalletModel*>();
759  if (wallet_model) setCurrentWallet(wallet_model);
760 }
761 
762 void BitcoinGUI::removeAllWallets()
763 {
764  if(!walletFrame)
765  return;
768 }
769 #endif // ENABLE_WALLET
770 
772 {
773  overviewAction->setEnabled(enabled);
774  sendCoinsAction->setEnabled(enabled);
775  receiveCoinsAction->setEnabled(enabled);
776  historyAction->setEnabled(enabled);
777  encryptWalletAction->setEnabled(enabled);
778  backupWalletAction->setEnabled(enabled);
779  changePassphraseAction->setEnabled(enabled);
780  signMessageAction->setEnabled(enabled);
781  verifyMessageAction->setEnabled(enabled);
782  usedSendingAddressesAction->setEnabled(enabled);
783  usedReceivingAddressesAction->setEnabled(enabled);
784  openAction->setEnabled(enabled);
785  m_close_wallet_action->setEnabled(enabled);
786  m_close_all_wallets_action->setEnabled(enabled);
787 }
788 
790 {
791  assert(QSystemTrayIcon::isSystemTrayAvailable());
792 
793 #ifndef Q_OS_MACOS
794  if (QSystemTrayIcon::isSystemTrayAvailable()) {
795  trayIcon = new QSystemTrayIcon(m_network_style->getTrayAndWindowIcon(), this);
796  QString toolTip = tr("%1 client").arg(PACKAGE_NAME) + " " + m_network_style->getTitleAddText();
797  trayIcon->setToolTip(toolTip);
798  }
799 #endif
800 }
801 
803 {
804 #ifndef Q_OS_MACOS
805  if (!trayIcon) return;
806 #endif // Q_OS_MACOS
807 
808  // Configuration of the tray icon (or Dock icon) menu.
809  QAction* show_hide_action{nullptr};
810 #ifndef Q_OS_MACOS
811  // Note: On macOS, the Dock icon's menu already has Show / Hide action.
812  show_hide_action = trayIconMenu->addAction(QString(), this, &BitcoinGUI::toggleHidden);
813  trayIconMenu->addSeparator();
814 #endif // Q_OS_MACOS
815 
816  QAction* send_action{nullptr};
817  QAction* receive_action{nullptr};
818  QAction* sign_action{nullptr};
819  QAction* verify_action{nullptr};
820  if (enableWallet) {
821  send_action = trayIconMenu->addAction(sendCoinsAction->text(), sendCoinsAction, &QAction::trigger);
822  receive_action = trayIconMenu->addAction(receiveCoinsAction->text(), receiveCoinsAction, &QAction::trigger);
823  trayIconMenu->addSeparator();
824  sign_action = trayIconMenu->addAction(signMessageAction->text(), signMessageAction, &QAction::trigger);
825  verify_action = trayIconMenu->addAction(verifyMessageAction->text(), verifyMessageAction, &QAction::trigger);
826  trayIconMenu->addSeparator();
827  }
828  QAction* options_action = trayIconMenu->addAction(optionsAction->text(), optionsAction, &QAction::trigger);
829  options_action->setMenuRole(QAction::PreferencesRole);
830  QAction* node_window_action = trayIconMenu->addAction(openRPCConsoleAction->text(), openRPCConsoleAction, &QAction::trigger);
831  QAction* quit_action{nullptr};
832 #ifndef Q_OS_MACOS
833  // Note: On macOS, the Dock icon's menu already has Quit action.
834  trayIconMenu->addSeparator();
835  quit_action = trayIconMenu->addAction(quitAction->text(), quitAction, &QAction::trigger);
836 
837  trayIcon->setContextMenu(trayIconMenu.get());
838  connect(trayIcon, &QSystemTrayIcon::activated, [this](QSystemTrayIcon::ActivationReason reason) {
839  if (reason == QSystemTrayIcon::Trigger) {
840  // Click on system tray icon triggers show/hide of the main window
841  toggleHidden();
842  }
843  });
844 #else
845  // Note: On macOS, the Dock icon is used to provide the tray's functionality.
847  connect(dockIconHandler, &MacDockIconHandler::dockIconClicked, [this] {
848  show();
849  activateWindow();
850  });
851  trayIconMenu->setAsDockMenu();
852 #endif // Q_OS_MACOS
853 
854  connect(
855  // Using QSystemTrayIcon::Context is not reliable.
856  // See https://bugreports.qt.io/browse/QTBUG-91697
857  trayIconMenu.get(), &QMenu::aboutToShow,
858  [this, show_hide_action, send_action, receive_action, sign_action, verify_action, options_action, node_window_action, quit_action] {
859  if (show_hide_action) show_hide_action->setText(
860  (!isHidden() && !isMinimized() && !GUIUtil::isObscured(this)) ?
861  tr("&Hide") :
862  tr("S&how"));
863  if (QApplication::activeModalWidget()) {
864  for (QAction* a : trayIconMenu.get()->actions()) {
865  a->setEnabled(false);
866  }
867  } else {
868  if (show_hide_action) show_hide_action->setEnabled(true);
869  if (enableWallet) {
870  send_action->setEnabled(sendCoinsAction->isEnabled());
871  receive_action->setEnabled(receiveCoinsAction->isEnabled());
872  sign_action->setEnabled(signMessageAction->isEnabled());
873  verify_action->setEnabled(verifyMessageAction->isEnabled());
874  }
875  options_action->setEnabled(optionsAction->isEnabled());
876  node_window_action->setEnabled(openRPCConsoleAction->isEnabled());
877  if (quit_action) quit_action->setEnabled(true);
878  }
879  });
880 }
881 
883 {
885 }
886 
888 {
889  if(!clientModel)
890  return;
891 
892  auto dlg = new HelpMessageDialog(this, /*about=*/true);
894 }
895 
897 {
899  Q_EMIT consoleShown(rpcConsole);
900 }
901 
903 {
905  showDebugWindow();
906 }
907 
909 {
911 }
912 
913 #ifdef ENABLE_WALLET
914 void BitcoinGUI::openClicked()
915 {
916  OpenURIDialog dlg(platformStyle, this);
917  if(dlg.exec())
918  {
919  Q_EMIT receivedURI(dlg.getURI());
920  }
921 }
922 
923 void BitcoinGUI::gotoOverviewPage()
924 {
925  overviewAction->setChecked(true);
927 }
928 
929 void BitcoinGUI::gotoHistoryPage()
930 {
931  historyAction->setChecked(true);
933 }
934 
935 void BitcoinGUI::gotoReceiveCoinsPage()
936 {
937  receiveCoinsAction->setChecked(true);
939 }
940 
941 void BitcoinGUI::gotoSendCoinsPage(QString addr)
942 {
943  sendCoinsAction->setChecked(true);
945 }
946 
947 void BitcoinGUI::gotoSignMessageTab(QString addr)
948 {
950 }
951 
952 void BitcoinGUI::gotoVerifyMessageTab(QString addr)
953 {
955 }
956 void BitcoinGUI::gotoLoadPSBT(bool from_clipboard)
957 {
958  if (walletFrame) walletFrame->gotoLoadPSBT(from_clipboard);
959 }
960 #endif // ENABLE_WALLET
961 
963 {
965  QString icon;
966  switch(count)
967  {
968  case 0: icon = ":/icons/connect_0"; break;
969  case 1: case 2: case 3: icon = ":/icons/connect_1"; break;
970  case 4: case 5: case 6: icon = ":/icons/connect_2"; break;
971  case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
972  default: icon = ":/icons/connect_4"; break;
973  }
974 
975  QString tooltip;
976 
977  if (m_node.getNetworkActive()) {
978  //: A substring of the tooltip.
979  tooltip = tr("%n active connection(s) to Bitcoin network.", "", count);
980  } else {
981  //: A substring of the tooltip.
982  tooltip = tr("Network activity disabled.");
983  icon = ":/icons/network_disabled";
984  }
985 
986  // Don't word-wrap this (fixed-width) tooltip
987  tooltip = QLatin1String("<nobr>") + tooltip + QLatin1String("<br>") +
988  //: A substring of the tooltip. "More actions" are available via the context menu.
989  tr("Click for more actions.") + QLatin1String("</nobr>");
990  connectionsControl->setToolTip(tooltip);
991 
993 }
994 
996 {
998 }
999 
1000 void BitcoinGUI::setNetworkActive(bool network_active)
1001 {
1003  m_network_context_menu->clear();
1004  m_network_context_menu->addAction(
1005  //: A context menu item. The "Peers tab" is an element of the "Node window".
1006  tr("Show Peers tab"),
1007  [this] {
1009  showDebugWindow();
1010  });
1011  m_network_context_menu->addAction(
1012  network_active ?
1013  //: A context menu item.
1014  tr("Disable network activity") :
1015  //: A context menu item. The network activity was disabled previously.
1016  tr("Enable network activity"),
1017  [this, new_state = !network_active] { m_node.setNetworkActive(new_state); });
1018 }
1019 
1021 {
1022  int64_t headersTipTime = clientModel->getHeaderTipTime();
1023  int headersTipHeight = clientModel->getHeaderTipHeight();
1024  int estHeadersLeft = (GetTime() - headersTipTime) / Params().GetConsensus().nPowTargetSpacing;
1025  if (estHeadersLeft > HEADER_HEIGHT_DELTA_SYNC)
1026  progressBarLabel->setText(tr("Syncing Headers (%1%)…").arg(QString::number(100.0 / (headersTipHeight+estHeadersLeft)*headersTipHeight, 'f', 1)));
1027 }
1028 
1029 void BitcoinGUI::updateHeadersPresyncProgressLabel(int64_t height, const QDateTime& blockDate)
1030 {
1031  int estHeadersLeft = blockDate.secsTo(QDateTime::currentDateTime()) / Params().GetConsensus().nPowTargetSpacing;
1032  if (estHeadersLeft > HEADER_HEIGHT_DELTA_SYNC)
1033  progressBarLabel->setText(tr("Pre-syncing Headers (%1%)…").arg(QString::number(100.0 / (height+estHeadersLeft)*height, 'f', 1)));
1034 }
1035 
1037 {
1039  return;
1040 
1041  auto dlg = new OptionsDialog(this, enableWallet);
1043  dlg->setCurrentTab(tab);
1044  dlg->setClientModel(clientModel);
1045  dlg->setModel(clientModel->getOptionsModel());
1047 }
1048 
1049 void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, SyncType synctype, SynchronizationState sync_state)
1050 {
1051 // Disabling macOS App Nap on initial sync, disk and reindex operations.
1052 #ifdef Q_OS_MACOS
1053  if (sync_state == SynchronizationState::POST_INIT) {
1054  m_app_nap_inhibitor->enableAppNap();
1055  } else {
1056  m_app_nap_inhibitor->disableAppNap();
1057  }
1058 #endif
1059 
1060  if (modalOverlay)
1061  {
1062  if (synctype != SyncType::BLOCK_SYNC)
1064  else
1065  modalOverlay->tipUpdate(count, blockDate, nVerificationProgress);
1066  }
1067  if (!clientModel)
1068  return;
1069 
1070  // Prevent orphan statusbar messages (e.g. hover Quit in main menu, wait until chain-sync starts -> garbled text)
1071  statusBar()->clearMessage();
1072 
1073  // Acquire current block source
1074  enum BlockSource blockSource = clientModel->getBlockSource();
1075  switch (blockSource) {
1076  case BlockSource::NETWORK:
1077  if (synctype == SyncType::HEADER_PRESYNC) {
1079  return;
1080  } else if (synctype == SyncType::HEADER_SYNC) {
1082  return;
1083  }
1084  progressBarLabel->setText(tr("Synchronizing with network…"));
1086  break;
1087  case BlockSource::DISK:
1088  if (synctype != SyncType::BLOCK_SYNC) {
1089  progressBarLabel->setText(tr("Indexing blocks on disk…"));
1090  } else {
1091  progressBarLabel->setText(tr("Processing blocks on disk…"));
1092  }
1093  break;
1094  case BlockSource::REINDEX:
1095  progressBarLabel->setText(tr("Reindexing blocks on disk…"));
1096  break;
1097  case BlockSource::NONE:
1098  if (synctype != SyncType::BLOCK_SYNC) {
1099  return;
1100  }
1101  progressBarLabel->setText(tr("Connecting to peers…"));
1102  break;
1103  }
1104 
1105  QString tooltip;
1106 
1107  QDateTime currentDate = QDateTime::currentDateTime();
1108  qint64 secs = blockDate.secsTo(currentDate);
1109 
1110  tooltip = tr("Processed %n block(s) of transaction history.", "", count);
1111 
1112  // Set icon state: spinning if catching up, tick otherwise
1113  if (secs < MAX_BLOCK_TIME_GAP) {
1114  tooltip = tr("Up to date") + QString(".<br>") + tooltip;
1115  labelBlocksIcon->setThemedPixmap(QStringLiteral(":/icons/synced"), STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE);
1116 
1117 #ifdef ENABLE_WALLET
1118  if(walletFrame)
1119  {
1121  modalOverlay->showHide(true, true);
1122  }
1123 #endif // ENABLE_WALLET
1124 
1125  progressBarLabel->setVisible(false);
1126  progressBar->setVisible(false);
1127  }
1128  else
1129  {
1130  QString timeBehindText = GUIUtil::formatNiceTimeOffset(secs);
1131 
1132  progressBarLabel->setVisible(true);
1133  progressBar->setFormat(tr("%1 behind").arg(timeBehindText));
1134  progressBar->setMaximum(1000000000);
1135  progressBar->setValue(nVerificationProgress * 1000000000.0 + 0.5);
1136  progressBar->setVisible(true);
1137 
1138  tooltip = tr("Catching up…") + QString("<br>") + tooltip;
1139  if(count != prevBlocks)
1140  {
1142  QString(":/animation/spinner-%1").arg(spinnerFrame, 3, 10, QChar('0')),
1145  }
1146  prevBlocks = count;
1147 
1148 #ifdef ENABLE_WALLET
1149  if(walletFrame)
1150  {
1153  }
1154 #endif // ENABLE_WALLET
1155 
1156  tooltip += QString("<br>");
1157  tooltip += tr("Last received block was generated %1 ago.").arg(timeBehindText);
1158  tooltip += QString("<br>");
1159  tooltip += tr("Transactions after this will not yet be visible.");
1160  }
1161 
1162  // Don't word-wrap this (fixed-width) tooltip
1163  tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
1164 
1165  labelBlocksIcon->setToolTip(tooltip);
1166  progressBarLabel->setToolTip(tooltip);
1167  progressBar->setToolTip(tooltip);
1168 }
1169 
1170 void BitcoinGUI::message(const QString& title, QString message, unsigned int style, bool* ret, const QString& detailed_message)
1171 {
1172  // Default title. On macOS, the window title is ignored (as required by the macOS Guidelines).
1173  QString strTitle{PACKAGE_NAME};
1174  // Default to information icon
1175  int nMBoxIcon = QMessageBox::Information;
1176  int nNotifyIcon = Notificator::Information;
1177 
1178  QString msgType;
1179  if (!title.isEmpty()) {
1180  msgType = title;
1181  } else {
1182  switch (style) {
1184  msgType = tr("Error");
1185  message = tr("Error: %1").arg(message);
1186  break;
1188  msgType = tr("Warning");
1189  message = tr("Warning: %1").arg(message);
1190  break;
1192  msgType = tr("Information");
1193  // No need to prepend the prefix here.
1194  break;
1195  default:
1196  break;
1197  }
1198  }
1199 
1200  if (!msgType.isEmpty()) {
1201  strTitle += " - " + msgType;
1202  }
1203 
1204  if (style & CClientUIInterface::ICON_ERROR) {
1205  nMBoxIcon = QMessageBox::Critical;
1206  nNotifyIcon = Notificator::Critical;
1207  } else if (style & CClientUIInterface::ICON_WARNING) {
1208  nMBoxIcon = QMessageBox::Warning;
1209  nNotifyIcon = Notificator::Warning;
1210  }
1211 
1212  if (style & CClientUIInterface::MODAL) {
1213  // Check for buttons, use OK as default, if none was supplied
1214  QMessageBox::StandardButton buttons;
1215  if (!(buttons = (QMessageBox::StandardButton)(style & CClientUIInterface::BTN_MASK)))
1216  buttons = QMessageBox::Ok;
1217 
1219  QMessageBox mBox(static_cast<QMessageBox::Icon>(nMBoxIcon), strTitle, message, buttons, this);
1220  mBox.setTextFormat(Qt::PlainText);
1221  mBox.setDetailedText(detailed_message);
1222  int r = mBox.exec();
1223  if (ret != nullptr)
1224  *ret = r == QMessageBox::Ok;
1225  } else {
1226  notificator->notify(static_cast<Notificator::Class>(nNotifyIcon), strTitle, message);
1227  }
1228 }
1229 
1231 {
1232  if (e->type() == QEvent::PaletteChange) {
1233  overviewAction->setIcon(platformStyle->SingleColorIcon(QStringLiteral(":/icons/overview")));
1234  sendCoinsAction->setIcon(platformStyle->SingleColorIcon(QStringLiteral(":/icons/send")));
1235  receiveCoinsAction->setIcon(platformStyle->SingleColorIcon(QStringLiteral(":/icons/receiving_addresses")));
1236  historyAction->setIcon(platformStyle->SingleColorIcon(QStringLiteral(":/icons/history")));
1237  }
1238 
1239  QMainWindow::changeEvent(e);
1240 
1241 #ifndef Q_OS_MACOS // Ignored on Mac
1242  if(e->type() == QEvent::WindowStateChange)
1243  {
1245  {
1246  QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
1247  if(!(wsevt->oldState() & Qt::WindowMinimized) && isMinimized())
1248  {
1249  QTimer::singleShot(0, this, &BitcoinGUI::hide);
1250  e->ignore();
1251  }
1252  else if((wsevt->oldState() & Qt::WindowMinimized) && !isMinimized())
1253  {
1254  QTimer::singleShot(0, this, &BitcoinGUI::show);
1255  e->ignore();
1256  }
1257  }
1258  }
1259 #endif
1260 }
1261 
1262 void BitcoinGUI::closeEvent(QCloseEvent *event)
1263 {
1264 #ifndef Q_OS_MACOS // Ignored on Mac
1266  {
1268  {
1269  // close rpcConsole in case it was open to make some space for the shutdown window
1270  rpcConsole->close();
1271 
1272  Q_EMIT quitRequested();
1273  }
1274  else
1275  {
1276  QMainWindow::showMinimized();
1277  event->ignore();
1278  }
1279  }
1280 #else
1281  QMainWindow::closeEvent(event);
1282 #endif
1283 }
1284 
1285 void BitcoinGUI::showEvent(QShowEvent *event)
1286 {
1287  // enable the debug window when the main window shows up
1288  openRPCConsoleAction->setEnabled(true);
1289  aboutAction->setEnabled(true);
1290  optionsAction->setEnabled(true);
1291 }
1292 
1293 #ifdef ENABLE_WALLET
1294 void BitcoinGUI::incomingTransaction(const QString& date, BitcoinUnit unit, const CAmount& amount, const QString& type, const QString& address, const QString& label, const QString& walletName)
1295 {
1296  // On new transaction, make an info balloon
1297  QString msg = tr("Date: %1\n").arg(date) +
1298  tr("Amount: %1\n").arg(BitcoinUnits::formatWithUnit(unit, amount, true));
1299  if (m_node.walletLoader().getWallets().size() > 1 && !walletName.isEmpty()) {
1300  msg += tr("Wallet: %1\n").arg(walletName);
1301  }
1302  msg += tr("Type: %1\n").arg(type);
1303  if (!label.isEmpty())
1304  msg += tr("Label: %1\n").arg(label);
1305  else if (!address.isEmpty())
1306  msg += tr("Address: %1\n").arg(address);
1307  message((amount)<0 ? tr("Sent transaction") : tr("Incoming transaction"),
1309 }
1310 #endif // ENABLE_WALLET
1311 
1312 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
1313 {
1314  // Accept only URIs
1315  if(event->mimeData()->hasUrls())
1316  event->acceptProposedAction();
1317 }
1318 
1319 void BitcoinGUI::dropEvent(QDropEvent *event)
1320 {
1321  if(event->mimeData()->hasUrls())
1322  {
1323  for (const QUrl &uri : event->mimeData()->urls())
1324  {
1325  Q_EMIT receivedURI(uri.toString());
1326  }
1327  }
1328  event->acceptProposedAction();
1329 }
1330 
1331 bool BitcoinGUI::eventFilter(QObject *object, QEvent *event)
1332 {
1333  // Catch status tip events
1334  if (event->type() == QEvent::StatusTip)
1335  {
1336  // Prevent adding text from setStatusTip(), if we currently use the status bar for displaying other stuff
1337  if (progressBarLabel->isVisible() || progressBar->isVisible())
1338  return true;
1339  }
1340  return QMainWindow::eventFilter(object, event);
1341 }
1342 
1343 #ifdef ENABLE_WALLET
1344 bool BitcoinGUI::handlePaymentRequest(const SendCoinsRecipient& recipient)
1345 {
1346  // URI has to be valid
1347  if (walletFrame && walletFrame->handlePaymentRequest(recipient))
1348  {
1350  gotoSendCoinsPage();
1351  return true;
1352  }
1353  return false;
1354 }
1355 
1356 void BitcoinGUI::setHDStatus(bool privkeyDisabled, int hdEnabled)
1357 {
1358  labelWalletHDStatusIcon->setThemedPixmap(privkeyDisabled ? QStringLiteral(":/icons/eye") : hdEnabled ? QStringLiteral(":/icons/hd_enabled") : QStringLiteral(":/icons/hd_disabled"), STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE);
1359  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>"));
1360  labelWalletHDStatusIcon->show();
1361 }
1362 
1363 void BitcoinGUI::setEncryptionStatus(int status)
1364 {
1365  switch(status)
1366  {
1367  case WalletModel::NoKeys:
1368  labelWalletEncryptionIcon->hide();
1369  encryptWalletAction->setChecked(false);
1370  changePassphraseAction->setEnabled(false);
1371  encryptWalletAction->setEnabled(false);
1372  break;
1374  labelWalletEncryptionIcon->hide();
1375  encryptWalletAction->setChecked(false);
1376  changePassphraseAction->setEnabled(false);
1377  encryptWalletAction->setEnabled(true);
1378  break;
1379  case WalletModel::Unlocked:
1380  labelWalletEncryptionIcon->show();
1381  labelWalletEncryptionIcon->setThemedPixmap(QStringLiteral(":/icons/lock_open"), STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE);
1382  labelWalletEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
1383  encryptWalletAction->setChecked(true);
1384  changePassphraseAction->setEnabled(true);
1385  encryptWalletAction->setEnabled(false);
1386  break;
1387  case WalletModel::Locked:
1388  labelWalletEncryptionIcon->show();
1389  labelWalletEncryptionIcon->setThemedPixmap(QStringLiteral(":/icons/lock_closed"), STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE);
1390  labelWalletEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
1391  encryptWalletAction->setChecked(true);
1392  changePassphraseAction->setEnabled(true);
1393  encryptWalletAction->setEnabled(false);
1394  break;
1395  }
1396 }
1397 
1398 void BitcoinGUI::updateWalletStatus()
1399 {
1401 
1402  WalletView * const walletView = walletFrame->currentWalletView();
1403  if (!walletView) {
1404  return;
1405  }
1406  WalletModel * const walletModel = walletView->getWalletModel();
1407  setEncryptionStatus(walletModel->getEncryptionStatus());
1408  setHDStatus(walletModel->wallet().privateKeysDisabled(), walletModel->wallet().hdEnabled());
1409 }
1410 #endif // ENABLE_WALLET
1411 
1413 {
1414  std::string ip_port;
1415  bool proxy_enabled = clientModel->getProxyInfo(ip_port);
1416 
1417  if (proxy_enabled) {
1419  QString ip_port_q = QString::fromStdString(ip_port);
1421  labelProxyIcon->setToolTip(tr("Proxy is <b>enabled</b>: %1").arg(ip_port_q));
1422  } else {
1423  labelProxyIcon->show();
1424  }
1425  } else {
1426  labelProxyIcon->hide();
1427  }
1428 }
1429 
1431 {
1432  QString window_title = PACKAGE_NAME;
1433 #ifdef ENABLE_WALLET
1434  if (walletFrame) {
1435  WalletModel* const wallet_model = walletFrame->currentWalletModel();
1436  if (wallet_model && !wallet_model->getWalletName().isEmpty()) {
1437  window_title += " - " + wallet_model->getDisplayName();
1438  }
1439  }
1440 #endif
1441  if (!m_network_style->getTitleAddText().isEmpty()) {
1442  window_title += " - " + m_network_style->getTitleAddText();
1443  }
1444  setWindowTitle(window_title);
1445 }
1446 
1447 void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden)
1448 {
1449  if(!clientModel)
1450  return;
1451 
1452  if (!isHidden() && !isMinimized() && !GUIUtil::isObscured(this) && fToggleHidden) {
1453  hide();
1454  } else {
1455  GUIUtil::bringToFront(this);
1456  }
1457 }
1458 
1460 {
1461  showNormalIfMinimized(true);
1462 }
1463 
1465 {
1466  if (m_node.shutdownRequested())
1467  {
1468  if(rpcConsole)
1469  rpcConsole->hide();
1470  Q_EMIT quitRequested();
1471  }
1472 }
1473 
1474 void BitcoinGUI::showProgress(const QString &title, int nProgress)
1475 {
1476  if (nProgress == 0) {
1477  progressDialog = new QProgressDialog(title, QString(), 0, 100);
1479  progressDialog->setWindowModality(Qt::ApplicationModal);
1480  progressDialog->setAutoClose(false);
1481  progressDialog->setValue(0);
1482  } else if (nProgress == 100) {
1483  if (progressDialog) {
1484  progressDialog->close();
1485  progressDialog->deleteLater();
1486  progressDialog = nullptr;
1487  }
1488  } else if (progressDialog) {
1489  progressDialog->setValue(nProgress);
1490  }
1491 }
1492 
1494 {
1495  if (modalOverlay && (progressBar->isVisible() || modalOverlay->isLayerVisible()))
1497 }
1498 
1499 static bool ThreadSafeMessageBox(BitcoinGUI* gui, const bilingual_str& message, const std::string& caption, unsigned int style)
1500 {
1501  bool modal = (style & CClientUIInterface::MODAL);
1502  // The SECURE flag has no effect in the Qt GUI.
1503  // bool secure = (style & CClientUIInterface::SECURE);
1504  style &= ~CClientUIInterface::SECURE;
1505  bool ret = false;
1506 
1507  QString detailed_message; // This is original message, in English, for googling and referencing.
1508  if (message.original != message.translated) {
1509  detailed_message = BitcoinGUI::tr("Original message:") + "\n" + QString::fromStdString(message.original);
1510  }
1511 
1512  // In case of modal message, use blocking connection to wait for user to click a button
1513  bool invoked = QMetaObject::invokeMethod(gui, "message",
1514  modal ? GUIUtil::blockingGUIThreadConnection() : Qt::QueuedConnection,
1515  Q_ARG(QString, QString::fromStdString(caption)),
1516  Q_ARG(QString, QString::fromStdString(message.translated)),
1517  Q_ARG(unsigned int, style),
1518  Q_ARG(bool*, &ret),
1519  Q_ARG(QString, detailed_message));
1520  assert(invoked);
1521  return ret;
1522 }
1523 
1525 {
1526  // Connect signals to client
1527  m_handler_message_box = m_node.handleMessageBox(std::bind(ThreadSafeMessageBox, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
1528  m_handler_question = m_node.handleQuestion(std::bind(ThreadSafeMessageBox, this, std::placeholders::_1, std::placeholders::_3, std::placeholders::_4));
1529 }
1530 
1532 {
1533  // Disconnect signals from client
1534  m_handler_message_box->disconnect();
1535  m_handler_question->disconnect();
1536 }
1537 
1539 {
1541  return m_mask_values_action->isChecked();
1542 }
1543 
1545  : optionsModel(nullptr),
1546  menu(nullptr),
1547  m_platform_style{platformStyle}
1548 {
1549  createContextMenu();
1550  setToolTip(tr("Unit to show amounts in. Click to select another unit."));
1551  QList<BitcoinUnit> units = BitcoinUnits::availableUnits();
1552  int max_width = 0;
1553  const QFontMetrics fm(font());
1554  for (const BitcoinUnit unit : units) {
1555  max_width = qMax(max_width, GUIUtil::TextWidth(fm, BitcoinUnits::longName(unit)));
1556  }
1557  setMinimumSize(max_width, 0);
1558  setAlignment(Qt::AlignRight | Qt::AlignVCenter);
1559  setStyleSheet(QString("QLabel { color : %1 }").arg(m_platform_style->SingleColor().name()));
1560 }
1561 
1564 {
1565  onDisplayUnitsClicked(event->pos());
1566 }
1567 
1569 {
1570  if (e->type() == QEvent::PaletteChange) {
1571  QString style = QString("QLabel { color : %1 }").arg(m_platform_style->SingleColor().name());
1572  if (style != styleSheet()) {
1573  setStyleSheet(style);
1574  }
1575  }
1576 
1577  QLabel::changeEvent(e);
1578 }
1579 
1582 {
1583  menu = new QMenu(this);
1584  for (const BitcoinUnit u : BitcoinUnits::availableUnits()) {
1585  menu->addAction(BitcoinUnits::longName(u))->setData(QVariant::fromValue(u));
1586  }
1587  connect(menu, &QMenu::triggered, this, &UnitDisplayStatusBarControl::onMenuSelection);
1588 }
1589 
1592 {
1593  if (_optionsModel)
1594  {
1595  this->optionsModel = _optionsModel;
1596 
1597  // be aware of a display unit change reported by the OptionsModel object.
1599 
1600  // initialize the display units label with the current value in the model.
1601  updateDisplayUnit(_optionsModel->getDisplayUnit());
1602  }
1603 }
1604 
1607 {
1608  setText(BitcoinUnits::longName(newUnits));
1609 }
1610 
1613 {
1614  QPoint globalPos = mapToGlobal(point);
1615  menu->exec(globalPos);
1616 }
1617 
1620 {
1621  if (action)
1622  {
1623  optionsModel->setDisplayUnit(action->data());
1624  }
1625 }
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:145
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:834
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:88
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:344
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:962
assert(!tx.IsCoinBase())
void showNormalIfMinimized()
Show window if hidden, unminimize when minimized, rise when obscured or show if hidden and fToggleHid...
Definition: bitcoingui.h:307
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:789
Bilingual messages:
Definition: translation.h:18
void showDebugWindow()
Show debug window.
Definition: bitcoingui.cpp:896
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:933
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:895
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:644
ModalOverlay * modalOverlay
Definition: bitcoingui.h:175
void createTrayIconMenu()
Create system tray menu (or setup the dock menu)
Definition: bitcoingui.cpp:802
RPCConsole * rpcConsole
Definition: bitcoingui.h:173
QAction * m_wallet_selector_action
Definition: bitcoingui.h:164
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:369
void updateHeadersPresyncProgressLabel(int64_t height, const QDateTime &blockDate)
void setWalletActionsEnabled(bool enabled)
Enable or disable all wallet-related actions.
Definition: bitcoingui.cpp:771
void networkActiveChanged(bool networkActive)
BitcoinUnit getDisplayUnit() const
Definition: optionsmodel.h:93
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:90
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
HelpMessageDialog * helpMessageDialog
Definition: bitcoingui.h:174
QLabel * progressBarLabel
Definition: bitcoingui.h:131
QSystemTrayIcon * trayIcon
Definition: bitcoingui.h:170
QAction * showHelpMessageAction
Definition: bitcoingui.h:156
void ShowModalDialogAsynchronously(QDialog *dialog)
Shows a QDialog instance asynchronously, and deletes it on close.
Definition: guiutil.cpp:989
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:22
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:397
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:188
WalletController * m_wallet_controller
Definition: bitcoingui.h:119
void gotoOverviewPage()
Switch to overview (home) page.
const PlatformStyle * platformStyle
Definition: bitcoingui.h:187
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:388
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:78
OptionsModel * optionsModel
Definition: bitcoingui.h:336
void created(WalletModel *wallet_model)
QLabel * m_wallet_selector_label
Definition: bitcoingui.h:167
enum BlockSource getBlockSource() const
Returns enum BlockSource of the current importing/syncing state.
void optionsClicked()
Show configuration dialog.
Definition: bitcoingui.cpp:882
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:949
void handleCloseWindowShortcut(QWidget *w)
Definition: guiutil.cpp:415
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:46
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:111
BitcoinGUI(interfaces::Node &node, const PlatformStyle *platformStyle, const NetworkStyle *networkStyle, QWidget *parent=nullptr)
Definition: bitcoingui.cpp:82
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()
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
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:908
QString getWalletName() const
void walletAdded(WalletModel *wallet_model)
void message(const QString &title, const QString &message, unsigned int style)
Notificator * notificator
Definition: bitcoingui.h:172
void PolishProgressDialog(QProgressDialog *dialog)
Definition: guiutil.cpp:881
void changePassphrase()
Change encrypted wallet passphrase.
Model for Bitcoin network client.
Definition: clientmodel.h:54
An error occurred.
Definition: notificator.h:40
void restored(WalletModel *wallet_model)
const QIcon & getTrayAndWindowIcon() const
Definition: networkstyle.h:21
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:40
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:92
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:171
QMenu * m_network_context_menu
Definition: bitcoingui.h:177
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:91
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:52
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:184
void toggleHidden()
Simply calls showNormalIfMinimized(true)
interfaces::Node & m_node
Definition: bitcoingui.h:118
int spinnerFrame
Definition: bitcoingui.h:185
void walletRemoved(WalletModel *wallet_model)
GUIUtil::ThemedLabel * labelWalletEncryptionIcon
Definition: bitcoingui.h:126
static int count
Definition: tests.c:33
void setNumConnections(int count)
Set number of connections shown in the UI.
Definition: bitcoingui.cpp:995
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:168
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:767
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:902
void createActions()
Create the main UI actions.
Definition: bitcoingui.cpp:248
QAction * optionsAction
Definition: bitcoingui.h:149
QAction * encryptWalletAction
Definition: bitcoingui.h:150
void aboutClicked()
Show about dialog.
Definition: bitcoingui.cpp:887
const Consensus::Params & GetConsensus() const
Definition: chainparams.h:82
const PlatformStyle * m_platform_style
Definition: bitcoingui.h:338
void removeWallet(WalletModel *wallet_model)
int getHeaderTipHeight() const
Definition: clientmodel.cpp:92
void updateHeadersSyncProgressLabel()
void gotoLoadPSBT(bool from_clipboard=false)
Load Partially Signed Bitcoin Transaction.
int64_t GetTime()
DEPRECATED, see GetTime.
Definition: time.cpp:117
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:134
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:39
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:466
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