BSHA3  0.17.99
P2P Blockchain, based on Bitcoin
bitcoingui.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2018 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>
9 #include <qt/guiconstants.h>
10 #include <qt/guiutil.h>
11 #include <qt/modaloverlay.h>
12 #include <qt/networkstyle.h>
13 #include <qt/notificator.h>
14 #include <qt/openuridialog.h>
15 #include <qt/optionsdialog.h>
16 #include <qt/optionsmodel.h>
17 #include <qt/platformstyle.h>
18 #include <qt/rpcconsole.h>
19 #include <qt/utilitydialog.h>
20 
21 #ifdef ENABLE_WALLET
22 #include <qt/walletframe.h>
23 #include <qt/walletmodel.h>
24 #include <qt/walletview.h>
25 #endif // ENABLE_WALLET
26 
27 #ifdef Q_OS_MAC
28 #include <qt/macdockiconhandler.h>
29 #endif
30 
31 #include <chainparams.h>
32 #include <interfaces/handler.h>
33 #include <interfaces/node.h>
34 #include <noui.h>
35 #include <ui_interface.h>
36 #include <util.h>
37 
38 #include <iostream>
39 
40 #include <QAction>
41 #include <QApplication>
42 #include <QComboBox>
43 #include <QDateTime>
44 #include <QDesktopWidget>
45 #include <QDragEnterEvent>
46 #include <QListWidget>
47 #include <QMenuBar>
48 #include <QMessageBox>
49 #include <QMimeData>
50 #include <QProgressDialog>
51 #include <QSettings>
52 #include <QShortcut>
53 #include <QStackedWidget>
54 #include <QStatusBar>
55 #include <QStyle>
56 #include <QTimer>
57 #include <QToolBar>
58 #include <QUrlQuery>
59 #include <QVBoxLayout>
60 
61 #include <boost/bind.hpp>
62 
63 const std::string BitcoinGUI::DEFAULT_UIPLATFORM =
64 #if defined(Q_OS_MAC)
65  "macosx"
66 #elif defined(Q_OS_WIN)
67  "windows"
68 #else
69  "other"
70 #endif
71  ;
72 
73 BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformStyle, const NetworkStyle *networkStyle, QWidget *parent) :
74  QMainWindow(parent),
75  m_node(node),
76  platformStyle(_platformStyle)
77 {
78  QSettings settings;
79  if (!restoreGeometry(settings.value("MainWindowGeometry").toByteArray())) {
80  // Restore failed (perhaps missing setting), center the window
81  move(QApplication::desktop()->availableGeometry().center() - frameGeometry().center());
82  }
83 
84  QString windowTitle = tr(PACKAGE_NAME) + " - ";
85 #ifdef ENABLE_WALLET
87 #endif // ENABLE_WALLET
88  if(enableWallet)
89  {
90  windowTitle += tr("Wallet");
91  } else {
92  windowTitle += tr("Node");
93  }
94  windowTitle += " " + networkStyle->getTitleAddText();
95 #ifndef Q_OS_MAC
96  QApplication::setWindowIcon(networkStyle->getTrayAndWindowIcon());
97  setWindowIcon(networkStyle->getTrayAndWindowIcon());
98 #else
100 #endif
101  setWindowTitle(windowTitle);
102 
103  rpcConsole = new RPCConsole(node, _platformStyle, 0);
104  helpMessageDialog = new HelpMessageDialog(node, this, false);
105 #ifdef ENABLE_WALLET
106  if(enableWallet)
107  {
109  walletFrame = new WalletFrame(_platformStyle, this);
110  setCentralWidget(walletFrame);
111  } else
112 #endif // ENABLE_WALLET
113  {
114  /* When compiled without wallet or -disablewallet is provided,
115  * the central widget is the rpc console.
116  */
117  setCentralWidget(rpcConsole);
118  }
119 
120  // Accept D&D of URIs
121  setAcceptDrops(true);
122 
123  // Create actions for the toolbar, menu bar and tray/dock icon
124  // Needs walletFrame to be initialized
125  createActions();
126 
127  // Create application menu bar
128  createMenuBar();
129 
130  // Create the toolbars
131  createToolBars();
132 
133  // Create system tray icon and notification
134  createTrayIcon(networkStyle);
135 
136  // Create status bar
137  statusBar();
138 
139  // Disable size grip because it looks ugly and nobody needs it
140  statusBar()->setSizeGripEnabled(false);
141 
142  // Status bar notification icons
143  QFrame *frameBlocks = new QFrame();
144  frameBlocks->setContentsMargins(0,0,0,0);
145  frameBlocks->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
146  QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);
147  frameBlocksLayout->setContentsMargins(3,0,3,0);
148  frameBlocksLayout->setSpacing(3);
150  labelWalletEncryptionIcon = new QLabel();
151  labelWalletHDStatusIcon = new QLabel();
155  if(enableWallet)
156  {
157  frameBlocksLayout->addStretch();
158  frameBlocksLayout->addWidget(unitDisplayControl);
159  frameBlocksLayout->addStretch();
160  frameBlocksLayout->addWidget(labelWalletEncryptionIcon);
161  frameBlocksLayout->addWidget(labelWalletHDStatusIcon);
162  }
163  frameBlocksLayout->addWidget(labelProxyIcon);
164  frameBlocksLayout->addStretch();
165  frameBlocksLayout->addWidget(connectionsControl);
166  frameBlocksLayout->addStretch();
167  frameBlocksLayout->addWidget(labelBlocksIcon);
168  frameBlocksLayout->addStretch();
169 
170  // Progress bar and label for blocks download
171  progressBarLabel = new QLabel();
172  progressBarLabel->setVisible(false);
174  progressBar->setAlignment(Qt::AlignCenter);
175  progressBar->setVisible(false);
176 
177  // Override style sheet for progress bar for styles that have a segmented progress bar,
178  // as they make the text unreadable (workaround for issue #1071)
179  // See https://doc.qt.io/qt-5/gallery.html
180  QString curStyle = QApplication::style()->metaObject()->className();
181  if(curStyle == "QWindowsStyle" || curStyle == "QWindowsXPStyle")
182  {
183  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; }");
184  }
185 
186  statusBar()->addWidget(progressBarLabel);
187  statusBar()->addWidget(progressBar);
188  statusBar()->addPermanentWidget(frameBlocks);
189 
190  // Install event filter to be able to catch status tip events (QEvent::StatusTip)
191  this->installEventFilter(this);
192 
193  // Initially wallet actions should be disabled
195 
196  // Subscribe to notifications from core
198 
201  });
204  });
205 
206  modalOverlay = new ModalOverlay(this->centralWidget());
207 #ifdef ENABLE_WALLET
208  if(enableWallet) {
212  }
213 #endif
214 }
215 
217 {
218  // Unsubscribe from notifications from core
220 
221  QSettings settings;
222  settings.setValue("MainWindowGeometry", saveGeometry());
223  if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu)
224  trayIcon->hide();
225 #ifdef Q_OS_MAC
226  delete appMenuBar;
228 #endif
229 
230  delete rpcConsole;
231 }
232 
234 {
235  QActionGroup *tabGroup = new QActionGroup(this);
236 
237  overviewAction = new QAction(platformStyle->SingleColorIcon(":/icons/overview"), tr("&Overview"), this);
238  overviewAction->setStatusTip(tr("Show general overview of wallet"));
239  overviewAction->setToolTip(overviewAction->statusTip());
240  overviewAction->setCheckable(true);
241  overviewAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_1));
242  tabGroup->addAction(overviewAction);
243 
244  sendCoinsAction = new QAction(platformStyle->SingleColorIcon(":/icons/send"), tr("&Send"), this);
245  sendCoinsAction->setStatusTip(tr("Send coins to a BSHA3 address"));
246  sendCoinsAction->setToolTip(sendCoinsAction->statusTip());
247  sendCoinsAction->setCheckable(true);
248  sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2));
249  tabGroup->addAction(sendCoinsAction);
250 
251  sendCoinsMenuAction = new QAction(platformStyle->TextColorIcon(":/icons/send"), sendCoinsAction->text(), this);
252  sendCoinsMenuAction->setStatusTip(sendCoinsAction->statusTip());
253  sendCoinsMenuAction->setToolTip(sendCoinsMenuAction->statusTip());
254 
255  receiveCoinsAction = new QAction(platformStyle->SingleColorIcon(":/icons/receiving_addresses"), tr("&Receive"), this);
256  receiveCoinsAction->setStatusTip(tr("Request payments (generates QR codes and bitcoin: URIs)"));
257  receiveCoinsAction->setToolTip(receiveCoinsAction->statusTip());
258  receiveCoinsAction->setCheckable(true);
259  receiveCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_3));
260  tabGroup->addAction(receiveCoinsAction);
261 
262  receiveCoinsMenuAction = new QAction(platformStyle->TextColorIcon(":/icons/receiving_addresses"), receiveCoinsAction->text(), this);
263  receiveCoinsMenuAction->setStatusTip(receiveCoinsAction->statusTip());
264  receiveCoinsMenuAction->setToolTip(receiveCoinsMenuAction->statusTip());
265 
266  historyAction = new QAction(platformStyle->SingleColorIcon(":/icons/history"), tr("&Transactions"), this);
267  historyAction->setStatusTip(tr("Browse transaction history"));
268  historyAction->setToolTip(historyAction->statusTip());
269  historyAction->setCheckable(true);
270  historyAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_4));
271  tabGroup->addAction(historyAction);
272 
273 #ifdef ENABLE_WALLET
274  // These showNormalIfMinimized are needed because Send Coins and Receive Coins
275  // can be triggered from the tray menu, and need to show the GUI to be useful.
276  connect(overviewAction, &QAction::triggered, this, static_cast<void (BitcoinGUI::*)()>(&BitcoinGUI::showNormalIfMinimized));
277  connect(overviewAction, &QAction::triggered, this, &BitcoinGUI::gotoOverviewPage);
278  connect(sendCoinsAction, &QAction::triggered, this, static_cast<void (BitcoinGUI::*)()>(&BitcoinGUI::showNormalIfMinimized));
279  connect(sendCoinsAction, &QAction::triggered, [this]{ gotoSendCoinsPage(); });
280  connect(sendCoinsMenuAction, &QAction::triggered, this, static_cast<void (BitcoinGUI::*)()>(&BitcoinGUI::showNormalIfMinimized));
281  connect(sendCoinsMenuAction, &QAction::triggered, [this]{ gotoSendCoinsPage(); });
282  connect(receiveCoinsAction, &QAction::triggered, this, static_cast<void (BitcoinGUI::*)()>(&BitcoinGUI::showNormalIfMinimized));
283  connect(receiveCoinsAction, &QAction::triggered, this, &BitcoinGUI::gotoReceiveCoinsPage);
284  connect(receiveCoinsMenuAction, &QAction::triggered, this, static_cast<void (BitcoinGUI::*)()>(&BitcoinGUI::showNormalIfMinimized));
285  connect(receiveCoinsMenuAction, &QAction::triggered, this, &BitcoinGUI::gotoReceiveCoinsPage);
286  connect(historyAction, &QAction::triggered, this, static_cast<void (BitcoinGUI::*)()>(&BitcoinGUI::showNormalIfMinimized));
287  connect(historyAction, &QAction::triggered, this, &BitcoinGUI::gotoHistoryPage);
288 #endif // ENABLE_WALLET
289 
290  quitAction = new QAction(platformStyle->TextColorIcon(":/icons/quit"), tr("E&xit"), this);
291  quitAction->setStatusTip(tr("Quit application"));
292  quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
293  quitAction->setMenuRole(QAction::QuitRole);
294  aboutAction = new QAction(platformStyle->TextColorIcon(":/icons/about"), tr("&About %1").arg(tr(PACKAGE_NAME)), this);
295  aboutAction->setStatusTip(tr("Show information about %1").arg(tr(PACKAGE_NAME)));
296  aboutAction->setMenuRole(QAction::AboutRole);
297  aboutAction->setEnabled(false);
298  aboutQtAction = new QAction(platformStyle->TextColorIcon(":/icons/about_qt"), tr("About &Qt"), this);
299  aboutQtAction->setStatusTip(tr("Show information about Qt"));
300  aboutQtAction->setMenuRole(QAction::AboutQtRole);
301  optionsAction = new QAction(platformStyle->TextColorIcon(":/icons/options"), tr("&Options..."), this);
302  optionsAction->setStatusTip(tr("Modify configuration options for %1").arg(tr(PACKAGE_NAME)));
303  optionsAction->setMenuRole(QAction::PreferencesRole);
304  optionsAction->setEnabled(false);
305  toggleHideAction = new QAction(platformStyle->TextColorIcon(":/icons/about"), tr("&Show / Hide"), this);
306  toggleHideAction->setStatusTip(tr("Show or hide the main Window"));
307 
308  encryptWalletAction = new QAction(platformStyle->TextColorIcon(":/icons/lock_closed"), tr("&Encrypt Wallet..."), this);
309  encryptWalletAction->setStatusTip(tr("Encrypt the private keys that belong to your wallet"));
310  encryptWalletAction->setCheckable(true);
311  backupWalletAction = new QAction(platformStyle->TextColorIcon(":/icons/filesave"), tr("&Backup Wallet..."), this);
312  backupWalletAction->setStatusTip(tr("Backup wallet to another location"));
313  changePassphraseAction = new QAction(platformStyle->TextColorIcon(":/icons/key"), tr("&Change Passphrase..."), this);
314  changePassphraseAction->setStatusTip(tr("Change the passphrase used for wallet encryption"));
315  signMessageAction = new QAction(platformStyle->TextColorIcon(":/icons/edit"), tr("Sign &message..."), this);
316  signMessageAction->setStatusTip(tr("Sign messages with your BSHA3 addresses to prove you own them"));
317  verifyMessageAction = new QAction(platformStyle->TextColorIcon(":/icons/verify"), tr("&Verify message..."), this);
318  verifyMessageAction->setStatusTip(tr("Verify messages to ensure they were signed with specified BSHA3 addresses"));
319 
320  openRPCConsoleAction = new QAction(platformStyle->TextColorIcon(":/icons/debugwindow"), tr("&Debug window"), this);
321  openRPCConsoleAction->setStatusTip(tr("Open debugging and diagnostic console"));
322  // initially disable the debug window menu item
323  openRPCConsoleAction->setEnabled(false);
324 
325  usedSendingAddressesAction = new QAction(platformStyle->TextColorIcon(":/icons/address-book"), tr("&Sending addresses..."), this);
326  usedSendingAddressesAction->setStatusTip(tr("Show the list of used sending addresses and labels"));
327  usedReceivingAddressesAction = new QAction(platformStyle->TextColorIcon(":/icons/address-book"), tr("&Receiving addresses..."), this);
328  usedReceivingAddressesAction->setStatusTip(tr("Show the list of used receiving addresses and labels"));
329 
330  openAction = new QAction(platformStyle->TextColorIcon(":/icons/open"), tr("Open &URI..."), this);
331  openAction->setStatusTip(tr("Open a bitcoin: URI or payment request"));
332 
333  showHelpMessageAction = new QAction(platformStyle->TextColorIcon(":/icons/info"), tr("&Command-line options"), this);
334  showHelpMessageAction->setMenuRole(QAction::NoRole);
335  showHelpMessageAction->setStatusTip(tr("Show the %1 help message to get a list with possible Bitcoin command-line options").arg(tr(PACKAGE_NAME)));
336 
337  connect(quitAction, &QAction::triggered, qApp, QApplication::quit);
338  connect(aboutAction, &QAction::triggered, this, &BitcoinGUI::aboutClicked);
339  connect(aboutQtAction, &QAction::triggered, qApp, QApplication::aboutQt);
340  connect(optionsAction, &QAction::triggered, this, &BitcoinGUI::optionsClicked);
341  connect(toggleHideAction, &QAction::triggered, this, &BitcoinGUI::toggleHidden);
342  connect(showHelpMessageAction, &QAction::triggered, this, &BitcoinGUI::showHelpMessageClicked);
343  connect(openRPCConsoleAction, &QAction::triggered, this, &BitcoinGUI::showDebugWindow);
344  // prevents an open debug window from becoming stuck/unusable on client shutdown
345  connect(quitAction, &QAction::triggered, rpcConsole, &QWidget::hide);
346 
347 #ifdef ENABLE_WALLET
348  if(walletFrame)
349  {
350  connect(encryptWalletAction, &QAction::triggered, walletFrame, &WalletFrame::encryptWallet);
351  connect(backupWalletAction, &QAction::triggered, walletFrame, &WalletFrame::backupWallet);
352  connect(changePassphraseAction, &QAction::triggered, walletFrame, &WalletFrame::changePassphrase);
353  connect(signMessageAction, &QAction::triggered, [this]{ gotoSignMessageTab(); });
354  connect(verifyMessageAction, &QAction::triggered, [this]{ gotoVerifyMessageTab(); });
357  connect(openAction, &QAction::triggered, this, &BitcoinGUI::openClicked);
358  }
359 #endif // ENABLE_WALLET
360 
361  connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_C), this), &QShortcut::activated, this, &BitcoinGUI::showDebugWindowActivateConsole);
362  connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_D), this), &QShortcut::activated, this, &BitcoinGUI::showDebugWindow);
363 }
364 
366 {
367 #ifdef Q_OS_MAC
368  // Create a decoupled menu bar on Mac which stays even if the window is closed
369  appMenuBar = new QMenuBar();
370 #else
371  // Get the main window's menu bar on other platforms
372  appMenuBar = menuBar();
373 #endif
374 
375  // Configure the menus
376  QMenu *file = appMenuBar->addMenu(tr("&File"));
377  if(walletFrame)
378  {
379  file->addAction(openAction);
380  file->addAction(backupWalletAction);
381  file->addAction(signMessageAction);
382  file->addAction(verifyMessageAction);
383  file->addSeparator();
384  file->addAction(usedSendingAddressesAction);
385  file->addAction(usedReceivingAddressesAction);
386  file->addSeparator();
387  }
388  file->addAction(quitAction);
389 
390  QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
391  if(walletFrame)
392  {
393  settings->addAction(encryptWalletAction);
394  settings->addAction(changePassphraseAction);
395  settings->addSeparator();
396  }
397  settings->addAction(optionsAction);
398 
399  QMenu *help = appMenuBar->addMenu(tr("&Help"));
400  if(walletFrame)
401  {
402  help->addAction(openRPCConsoleAction);
403  }
404  help->addAction(showHelpMessageAction);
405  help->addSeparator();
406  help->addAction(aboutAction);
407  help->addAction(aboutQtAction);
408 }
409 
411 {
412  if(walletFrame)
413  {
414  QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));
415  appToolBar = toolbar;
416  toolbar->setContextMenuPolicy(Qt::PreventContextMenu);
417  toolbar->setMovable(false);
418  toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
419  toolbar->addAction(overviewAction);
420  toolbar->addAction(sendCoinsAction);
421  toolbar->addAction(receiveCoinsAction);
422  toolbar->addAction(historyAction);
423  overviewAction->setChecked(true);
424 
425 #ifdef ENABLE_WALLET
426  QWidget *spacer = new QWidget();
427  spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
428  toolbar->addWidget(spacer);
429 
430  m_wallet_selector = new QComboBox();
431  connect(m_wallet_selector, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &BitcoinGUI::setCurrentWalletBySelectorIndex);
432 
433  m_wallet_selector_label = new QLabel();
434  m_wallet_selector_label->setText(tr("Wallet:") + " ");
436 
439 
440  m_wallet_selector_label_action->setVisible(false);
441  m_wallet_selector_action->setVisible(false);
442 #endif
443  }
444 }
445 
447 {
448  this->clientModel = _clientModel;
449  if(_clientModel)
450  {
451  // Create system tray menu (or setup the dock menu) that late to prevent users from calling actions,
452  // while the client has not yet fully loaded
454 
455  // Keep up to date with client
458  connect(_clientModel, &ClientModel::networkActiveChanged, this, &BitcoinGUI::setNetworkActive);
459 
460  modalOverlay->setKnownBestHeight(_clientModel->getHeaderTipHeight(), QDateTime::fromTime_t(_clientModel->getHeaderTipTime()));
462  connect(_clientModel, &ClientModel::numBlocksChanged, this, &BitcoinGUI::setNumBlocks);
463 
464  // Receive and report messages from client model
465  connect(_clientModel, &ClientModel::message, [this](const QString &title, const QString &message, unsigned int style){
466  this->message(title, message, style);
467  });
468 
469  // Show progress dialog
470  connect(_clientModel, &ClientModel::showProgress, this, &BitcoinGUI::showProgress);
471 
472  rpcConsole->setClientModel(_clientModel);
473 
474  updateProxyIcon();
475 
476 #ifdef ENABLE_WALLET
477  if(walletFrame)
478  {
479  walletFrame->setClientModel(_clientModel);
480  }
481 #endif // ENABLE_WALLET
483 
484  OptionsModel* optionsModel = _clientModel->getOptionsModel();
485  if(optionsModel)
486  {
487  // be aware of the tray icon disable state change reported by the OptionsModel object.
489 
490  // initialize the disable state of the tray icon with the current value in the model.
491  setTrayIconVisible(optionsModel->getHideTrayIcon());
492  }
493  } else {
494  // Disable possibility to show main window via action
495  toggleHideAction->setEnabled(false);
496  if(trayIconMenu)
497  {
498  // Disable context menu on tray icon
499  trayIconMenu->clear();
500  }
501  // Propagate cleared model to child objects
502  rpcConsole->setClientModel(nullptr);
503 #ifdef ENABLE_WALLET
504  if (walletFrame)
505  {
506  walletFrame->setClientModel(nullptr);
507  }
508 #endif // ENABLE_WALLET
510  }
511 }
512 
513 #ifdef ENABLE_WALLET
514 bool BitcoinGUI::addWallet(WalletModel *walletModel)
515 {
516  if(!walletFrame)
517  return false;
518  const QString name = walletModel->getWalletName();
519  QString display_name = name.isEmpty() ? "["+tr("default wallet")+"]" : name;
521  m_wallet_selector->addItem(display_name, name);
522  if (m_wallet_selector->count() == 2) {
523  m_wallet_selector_label_action->setVisible(true);
524  m_wallet_selector_action->setVisible(true);
525  }
526  rpcConsole->addWallet(walletModel);
527  return walletFrame->addWallet(walletModel);
528 }
529 
530 bool BitcoinGUI::removeWallet(WalletModel* walletModel)
531 {
532  if (!walletFrame) return false;
533  QString name = walletModel->getWalletName();
534  int index = m_wallet_selector->findData(name);
535  m_wallet_selector->removeItem(index);
536  if (m_wallet_selector->count() == 0) {
538  } else if (m_wallet_selector->count() == 1) {
539  m_wallet_selector_label_action->setVisible(false);
540  m_wallet_selector_action->setVisible(false);
541  }
542  rpcConsole->removeWallet(walletModel);
543  return walletFrame->removeWallet(name);
544 }
545 
546 bool BitcoinGUI::setCurrentWallet(const QString& name)
547 {
548  if(!walletFrame)
549  return false;
551 }
552 
553 bool BitcoinGUI::setCurrentWalletBySelectorIndex(int index)
554 {
555  QString internal_name = m_wallet_selector->itemData(index).toString();
556  return setCurrentWallet(internal_name);
557 }
558 
559 void BitcoinGUI::removeAllWallets()
560 {
561  if(!walletFrame)
562  return;
565 }
566 #endif // ENABLE_WALLET
567 
569 {
570  overviewAction->setEnabled(enabled);
571  sendCoinsAction->setEnabled(enabled);
572  sendCoinsMenuAction->setEnabled(enabled);
573  receiveCoinsAction->setEnabled(enabled);
574  receiveCoinsMenuAction->setEnabled(enabled);
575  historyAction->setEnabled(enabled);
576  encryptWalletAction->setEnabled(enabled);
577  backupWalletAction->setEnabled(enabled);
578  changePassphraseAction->setEnabled(enabled);
579  signMessageAction->setEnabled(enabled);
580  verifyMessageAction->setEnabled(enabled);
581  usedSendingAddressesAction->setEnabled(enabled);
582  usedReceivingAddressesAction->setEnabled(enabled);
583  openAction->setEnabled(enabled);
584 }
585 
586 void BitcoinGUI::createTrayIcon(const NetworkStyle *networkStyle)
587 {
588 #ifndef Q_OS_MAC
589  trayIcon = new QSystemTrayIcon(this);
590  QString toolTip = tr("%1 client").arg(tr(PACKAGE_NAME)) + " " + networkStyle->getTitleAddText();
591  trayIcon->setToolTip(toolTip);
592  trayIcon->setIcon(networkStyle->getTrayAndWindowIcon());
593  trayIcon->hide();
594 #endif
595 
596  notificator = new Notificator(QApplication::applicationName(), trayIcon, this);
597 }
598 
600 {
601 #ifndef Q_OS_MAC
602  // return if trayIcon is unset (only on non-Mac OSes)
603  if (!trayIcon)
604  return;
605 
606  trayIconMenu = new QMenu(this);
607  trayIcon->setContextMenu(trayIconMenu);
608 
609  connect(trayIcon, &QSystemTrayIcon::activated, this, &BitcoinGUI::trayIconActivated);
610 #else
611  // Note: On Mac, the dock icon is used to provide the tray's functionality.
613  dockIconHandler->setMainWindow(static_cast<QMainWindow*>(this));
614  trayIconMenu = dockIconHandler->dockMenu();
615 #endif
616 
617  // Configuration of the tray icon (or dock icon) icon menu
618 #ifndef Q_OS_MAC
619  // Note: On Mac, the dock icon's menu already has show / hide action.
620  trayIconMenu->addAction(toggleHideAction);
621  trayIconMenu->addSeparator();
622 #endif
623  if (enableWallet) {
624  trayIconMenu->addAction(sendCoinsMenuAction);
626  trayIconMenu->addSeparator();
627  trayIconMenu->addAction(signMessageAction);
628  trayIconMenu->addAction(verifyMessageAction);
629  trayIconMenu->addSeparator();
631  }
632  trayIconMenu->addAction(optionsAction);
633 #ifndef Q_OS_MAC // This is built-in on Mac
634  trayIconMenu->addSeparator();
635  trayIconMenu->addAction(quitAction);
636 #endif
637 }
638 
639 #ifndef Q_OS_MAC
640 void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
641 {
642  if(reason == QSystemTrayIcon::Trigger)
643  {
644  // Click on system tray icon triggers show/hide of the main window
645  toggleHidden();
646  }
647 }
648 #endif
649 
651 {
653 }
654 
656 {
657  if(!clientModel)
658  return;
659 
660  HelpMessageDialog dlg(m_node, this, true);
661  dlg.exec();
662 }
663 
665 {
666  rpcConsole->showNormal();
667  rpcConsole->show();
668  rpcConsole->raise();
669  rpcConsole->activateWindow();
670 }
671 
673 {
675  showDebugWindow();
676 }
677 
679 {
680  helpMessageDialog->show();
681 }
682 
683 #ifdef ENABLE_WALLET
684 void BitcoinGUI::openClicked()
685 {
686  OpenURIDialog dlg(this);
687  if(dlg.exec())
688  {
689  Q_EMIT receivedURI(dlg.getURI());
690  }
691 }
692 
693 void BitcoinGUI::gotoOverviewPage()
694 {
695  overviewAction->setChecked(true);
697 }
698 
699 void BitcoinGUI::gotoHistoryPage()
700 {
701  historyAction->setChecked(true);
703 }
704 
705 void BitcoinGUI::gotoReceiveCoinsPage()
706 {
707  receiveCoinsAction->setChecked(true);
709 }
710 
711 void BitcoinGUI::gotoSendCoinsPage(QString addr)
712 {
713  sendCoinsAction->setChecked(true);
715 }
716 
717 void BitcoinGUI::gotoSignMessageTab(QString addr)
718 {
720 }
721 
722 void BitcoinGUI::gotoVerifyMessageTab(QString addr)
723 {
725 }
726 #endif // ENABLE_WALLET
727 
729 {
730  int count = clientModel->getNumConnections();
731  QString icon;
732  switch(count)
733  {
734  case 0: icon = ":/icons/connect_0"; break;
735  case 1: case 2: case 3: icon = ":/icons/connect_1"; break;
736  case 4: case 5: case 6: icon = ":/icons/connect_2"; break;
737  case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
738  default: icon = ":/icons/connect_4"; break;
739  }
740 
741  QString tooltip;
742 
743  if (m_node.getNetworkActive()) {
744  tooltip = tr("%n active connection(s) to Bitcoin network", "", count) + QString(".<br>") + tr("Click to disable network activity.");
745  } else {
746  tooltip = tr("Network activity disabled.") + QString("<br>") + tr("Click to enable network activity again.");
747  icon = ":/icons/network_disabled";
748  }
749 
750  // Don't word-wrap this (fixed-width) tooltip
751  tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
752  connectionsControl->setToolTip(tooltip);
753 
754  connectionsControl->setPixmap(platformStyle->SingleColorIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
755 }
756 
758 {
760 }
761 
762 void BitcoinGUI::setNetworkActive(bool networkActive)
763 {
765 }
766 
768 {
769  int64_t headersTipTime = clientModel->getHeaderTipTime();
770  int headersTipHeight = clientModel->getHeaderTipHeight();
771  int estHeadersLeft = (GetTime() - headersTipTime) / Params().GetConsensus().nPowTargetSpacing;
772  if (estHeadersLeft > HEADER_HEIGHT_DELTA_SYNC)
773  progressBarLabel->setText(tr("Syncing Headers (%1%)...").arg(QString::number(100.0 / (headersTipHeight+estHeadersLeft)*headersTipHeight, 'f', 1)));
774 }
775 
777 {
779  return;
780 
781  OptionsDialog dlg(this, enableWallet);
782  dlg.setCurrentTab(tab);
784  dlg.exec();
785 }
786 
787 void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool header)
788 {
789  if (modalOverlay)
790  {
791  if (header)
792  modalOverlay->setKnownBestHeight(count, blockDate);
793  else
794  modalOverlay->tipUpdate(count, blockDate, nVerificationProgress);
795  }
796  if (!clientModel)
797  return;
798 
799  // Prevent orphan statusbar messages (e.g. hover Quit in main menu, wait until chain-sync starts -> garbled text)
800  statusBar()->clearMessage();
801 
802  // Acquire current block source
803  enum BlockSource blockSource = clientModel->getBlockSource();
804  switch (blockSource) {
806  if (header) {
808  return;
809  }
810  progressBarLabel->setText(tr("Synchronizing with network..."));
812  break;
813  case BlockSource::DISK:
814  if (header) {
815  progressBarLabel->setText(tr("Indexing blocks on disk..."));
816  } else {
817  progressBarLabel->setText(tr("Processing blocks on disk..."));
818  }
819  break;
821  progressBarLabel->setText(tr("Reindexing blocks on disk..."));
822  break;
823  case BlockSource::NONE:
824  if (header) {
825  return;
826  }
827  progressBarLabel->setText(tr("Connecting to peers..."));
828  break;
829  }
830 
831  QString tooltip;
832 
833  QDateTime currentDate = QDateTime::currentDateTime();
834  qint64 secs = blockDate.secsTo(currentDate);
835 
836  tooltip = tr("Processed %n block(s) of transaction history.", "", count);
837 
838  // Set icon state: spinning if catching up, tick otherwise
839  if(secs < 90*60)
840  {
841  tooltip = tr("Up to date") + QString(".<br>") + tooltip;
842  labelBlocksIcon->setPixmap(platformStyle->SingleColorIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
843 
844 #ifdef ENABLE_WALLET
845  if(walletFrame)
846  {
848  modalOverlay->showHide(true, true);
849  }
850 #endif // ENABLE_WALLET
851 
852  progressBarLabel->setVisible(false);
853  progressBar->setVisible(false);
854  }
855  else
856  {
857  QString timeBehindText = GUIUtil::formatNiceTimeOffset(secs);
858 
859  progressBarLabel->setVisible(true);
860  progressBar->setFormat(tr("%1 behind").arg(timeBehindText));
861  progressBar->setMaximum(1000000000);
862  progressBar->setValue(nVerificationProgress * 1000000000.0 + 0.5);
863  progressBar->setVisible(true);
864 
865  tooltip = tr("Catching up...") + QString("<br>") + tooltip;
866  if(count != prevBlocks)
867  {
868  labelBlocksIcon->setPixmap(platformStyle->SingleColorIcon(QString(
869  ":/movies/spinner-%1").arg(spinnerFrame, 3, 10, QChar('0')))
870  .pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
872  }
873  prevBlocks = count;
874 
875 #ifdef ENABLE_WALLET
876  if(walletFrame)
877  {
880  }
881 #endif // ENABLE_WALLET
882 
883  tooltip += QString("<br>");
884  tooltip += tr("Last received block was generated %1 ago.").arg(timeBehindText);
885  tooltip += QString("<br>");
886  tooltip += tr("Transactions after this will not yet be visible.");
887  }
888 
889  // Don't word-wrap this (fixed-width) tooltip
890  tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
891 
892  labelBlocksIcon->setToolTip(tooltip);
893  progressBarLabel->setToolTip(tooltip);
894  progressBar->setToolTip(tooltip);
895 }
896 
897 void BitcoinGUI::message(const QString &title, const QString &message, unsigned int style, bool *ret)
898 {
899  QString strTitle = tr("BSHA3"); // default title
900  // Default to information icon
901  int nMBoxIcon = QMessageBox::Information;
902  int nNotifyIcon = Notificator::Information;
903 
904  QString msgType;
905 
906  // Prefer supplied title over style based title
907  if (!title.isEmpty()) {
908  msgType = title;
909  }
910  else {
911  switch (style) {
913  msgType = tr("Error");
914  break;
916  msgType = tr("Warning");
917  break;
919  msgType = tr("Information");
920  break;
921  default:
922  break;
923  }
924  }
925  // Append title to "BSHA3 - "
926  if (!msgType.isEmpty())
927  strTitle += " - " + msgType;
928 
929  // Check for error/warning icon
930  if (style & CClientUIInterface::ICON_ERROR) {
931  nMBoxIcon = QMessageBox::Critical;
932  nNotifyIcon = Notificator::Critical;
933  }
934  else if (style & CClientUIInterface::ICON_WARNING) {
935  nMBoxIcon = QMessageBox::Warning;
936  nNotifyIcon = Notificator::Warning;
937  }
938 
939  // Display message
940  if (style & CClientUIInterface::MODAL) {
941  // Check for buttons, use OK as default, if none was supplied
942  QMessageBox::StandardButton buttons;
943  if (!(buttons = (QMessageBox::StandardButton)(style & CClientUIInterface::BTN_MASK)))
944  buttons = QMessageBox::Ok;
945 
947  QMessageBox mBox(static_cast<QMessageBox::Icon>(nMBoxIcon), strTitle, message, buttons, this);
948  mBox.setTextFormat(Qt::PlainText);
949  int r = mBox.exec();
950  if (ret != nullptr)
951  *ret = r == QMessageBox::Ok;
952  }
953  else
954  notificator->notify(static_cast<Notificator::Class>(nNotifyIcon), strTitle, message);
955 }
956 
957 void BitcoinGUI::changeEvent(QEvent *e)
958 {
959  QMainWindow::changeEvent(e);
960 #ifndef Q_OS_MAC // Ignored on Mac
961  if(e->type() == QEvent::WindowStateChange)
962  {
964  {
965  QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
966  if(!(wsevt->oldState() & Qt::WindowMinimized) && isMinimized())
967  {
968  QTimer::singleShot(0, this, &BitcoinGUI::hide);
969  e->ignore();
970  }
971  else if((wsevt->oldState() & Qt::WindowMinimized) && !isMinimized())
972  {
973  QTimer::singleShot(0, this, &BitcoinGUI::show);
974  e->ignore();
975  }
976  }
977  }
978 #endif
979 }
980 
981 void BitcoinGUI::closeEvent(QCloseEvent *event)
982 {
983 #ifndef Q_OS_MAC // Ignored on Mac
985  {
987  {
988  // close rpcConsole in case it was open to make some space for the shutdown window
989  rpcConsole->close();
990 
991  QApplication::quit();
992  }
993  else
994  {
995  QMainWindow::showMinimized();
996  event->ignore();
997  }
998  }
999 #else
1000  QMainWindow::closeEvent(event);
1001 #endif
1002 }
1003 
1004 void BitcoinGUI::showEvent(QShowEvent *event)
1005 {
1006  // enable the debug window when the main window shows up
1007  openRPCConsoleAction->setEnabled(true);
1008  aboutAction->setEnabled(true);
1009  optionsAction->setEnabled(true);
1010 }
1011 
1012 #ifdef ENABLE_WALLET
1013 void BitcoinGUI::incomingTransaction(const QString& date, int unit, const CAmount& amount, const QString& type, const QString& address, const QString& label, const QString& walletName)
1014 {
1015  // On new transaction, make an info balloon
1016  QString msg = tr("Date: %1\n").arg(date) +
1017  tr("Amount: %1\n").arg(BitcoinUnits::formatWithUnit(unit, amount, true));
1018  if (m_node.getWallets().size() > 1 && !walletName.isEmpty()) {
1019  msg += tr("Wallet: %1\n").arg(walletName);
1020  }
1021  msg += tr("Type: %1\n").arg(type);
1022  if (!label.isEmpty())
1023  msg += tr("Label: %1\n").arg(label);
1024  else if (!address.isEmpty())
1025  msg += tr("Address: %1\n").arg(address);
1026  message((amount)<0 ? tr("Sent transaction") : tr("Incoming transaction"),
1028 }
1029 #endif // ENABLE_WALLET
1030 
1031 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
1032 {
1033  // Accept only URIs
1034  if(event->mimeData()->hasUrls())
1035  event->acceptProposedAction();
1036 }
1037 
1038 void BitcoinGUI::dropEvent(QDropEvent *event)
1039 {
1040  if(event->mimeData()->hasUrls())
1041  {
1042  for (const QUrl &uri : event->mimeData()->urls())
1043  {
1044  Q_EMIT receivedURI(uri.toString());
1045  }
1046  }
1047  event->acceptProposedAction();
1048 }
1049 
1050 bool BitcoinGUI::eventFilter(QObject *object, QEvent *event)
1051 {
1052  // Catch status tip events
1053  if (event->type() == QEvent::StatusTip)
1054  {
1055  // Prevent adding text from setStatusTip(), if we currently use the status bar for displaying other stuff
1056  if (progressBarLabel->isVisible() || progressBar->isVisible())
1057  return true;
1058  }
1059  return QMainWindow::eventFilter(object, event);
1060 }
1061 
1062 #ifdef ENABLE_WALLET
1063 bool BitcoinGUI::handlePaymentRequest(const SendCoinsRecipient& recipient)
1064 {
1065  // URI has to be valid
1066  if (walletFrame && walletFrame->handlePaymentRequest(recipient))
1067  {
1069  gotoSendCoinsPage();
1070  return true;
1071  }
1072  return false;
1073 }
1074 
1075 void BitcoinGUI::setHDStatus(int hdEnabled)
1076 {
1077  labelWalletHDStatusIcon->setPixmap(platformStyle->SingleColorIcon(hdEnabled ? ":/icons/hd_enabled" : ":/icons/hd_disabled").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
1078  labelWalletHDStatusIcon->setToolTip(hdEnabled ? tr("HD key generation is <b>enabled</b>") : tr("HD key generation is <b>disabled</b>"));
1079 
1080  // eventually disable the QLabel to set its opacity to 50%
1081  labelWalletHDStatusIcon->setEnabled(hdEnabled);
1082 }
1083 
1084 void BitcoinGUI::setEncryptionStatus(int status)
1085 {
1086  switch(status)
1087  {
1089  labelWalletEncryptionIcon->hide();
1090  encryptWalletAction->setChecked(false);
1091  changePassphraseAction->setEnabled(false);
1092  encryptWalletAction->setEnabled(true);
1093  break;
1094  case WalletModel::Unlocked:
1095  labelWalletEncryptionIcon->show();
1096  labelWalletEncryptionIcon->setPixmap(platformStyle->SingleColorIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
1097  labelWalletEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
1098  encryptWalletAction->setChecked(true);
1099  changePassphraseAction->setEnabled(true);
1100  encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
1101  break;
1102  case WalletModel::Locked:
1103  labelWalletEncryptionIcon->show();
1104  labelWalletEncryptionIcon->setPixmap(platformStyle->SingleColorIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
1105  labelWalletEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
1106  encryptWalletAction->setChecked(true);
1107  changePassphraseAction->setEnabled(true);
1108  encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
1109  break;
1110  }
1111 }
1112 
1113 void BitcoinGUI::updateWalletStatus()
1114 {
1115  if (!walletFrame) {
1116  return;
1117  }
1118  WalletView * const walletView = walletFrame->currentWalletView();
1119  if (!walletView) {
1120  return;
1121  }
1122  WalletModel * const walletModel = walletView->getWalletModel();
1123  setEncryptionStatus(walletModel->getEncryptionStatus());
1124  setHDStatus(walletModel->wallet().hdEnabled());
1125 }
1126 #endif // ENABLE_WALLET
1127 
1129 {
1130  std::string ip_port;
1131  bool proxy_enabled = clientModel->getProxyInfo(ip_port);
1132 
1133  if (proxy_enabled) {
1134  if (labelProxyIcon->pixmap() == 0) {
1135  QString ip_port_q = QString::fromStdString(ip_port);
1136  labelProxyIcon->setPixmap(platformStyle->SingleColorIcon(":/icons/proxy").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
1137  labelProxyIcon->setToolTip(tr("Proxy is <b>enabled</b>: %1").arg(ip_port_q));
1138  } else {
1139  labelProxyIcon->show();
1140  }
1141  } else {
1142  labelProxyIcon->hide();
1143  }
1144 }
1145 
1146 void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden)
1147 {
1148  if(!clientModel)
1149  return;
1150 
1151  // activateWindow() (sometimes) helps with keyboard focus on Windows
1152  if (isHidden())
1153  {
1154  show();
1155  activateWindow();
1156  }
1157  else if (isMinimized())
1158  {
1159  showNormal();
1160  activateWindow();
1161  }
1162  else if (GUIUtil::isObscured(this))
1163  {
1164  raise();
1165  activateWindow();
1166  }
1167  else if(fToggleHidden)
1168  hide();
1169 }
1170 
1172 {
1173  showNormalIfMinimized(true);
1174 }
1175 
1177 {
1178  if (m_node.shutdownRequested())
1179  {
1180  if(rpcConsole)
1181  rpcConsole->hide();
1182  qApp->quit();
1183  }
1184 }
1185 
1186 void BitcoinGUI::showProgress(const QString &title, int nProgress)
1187 {
1188  if (nProgress == 0)
1189  {
1190  progressDialog = new QProgressDialog(title, "", 0, 100);
1191  progressDialog->setWindowModality(Qt::ApplicationModal);
1192  progressDialog->setMinimumDuration(0);
1193  progressDialog->setCancelButton(0);
1194  progressDialog->setAutoClose(false);
1195  progressDialog->setValue(0);
1196  }
1197  else if (nProgress == 100)
1198  {
1199  if (progressDialog)
1200  {
1201  progressDialog->close();
1202  progressDialog->deleteLater();
1203  }
1204  }
1205  else if (progressDialog)
1206  progressDialog->setValue(nProgress);
1207 }
1208 
1209 void BitcoinGUI::setTrayIconVisible(bool fHideTrayIcon)
1210 {
1211  if (trayIcon)
1212  {
1213  trayIcon->setVisible(!fHideTrayIcon);
1214  }
1215 }
1216 
1218 {
1219  if (modalOverlay && (progressBar->isVisible() || modalOverlay->isLayerVisible()))
1221 }
1222 
1223 static bool ThreadSafeMessageBox(BitcoinGUI* gui, const std::string& message, const std::string& caption, unsigned int style)
1224 {
1225  // Redundantly log and print message in non-gui fashion
1226  noui_ThreadSafeMessageBox(message, caption, style);
1227 
1228  bool modal = (style & CClientUIInterface::MODAL);
1229  // The SECURE flag has no effect in the Qt GUI.
1230  // bool secure = (style & CClientUIInterface::SECURE);
1231  style &= ~CClientUIInterface::SECURE;
1232  bool ret = false;
1233  // In case of modal message, use blocking connection to wait for user to click a button
1234  QMetaObject::invokeMethod(gui, "message",
1235  modal ? GUIUtil::blockingGUIThreadConnection() : Qt::QueuedConnection,
1236  Q_ARG(QString, QString::fromStdString(caption)),
1237  Q_ARG(QString, QString::fromStdString(message)),
1238  Q_ARG(unsigned int, style),
1239  Q_ARG(bool*, &ret));
1240  return ret;
1241 }
1242 
1244 {
1245  // Connect signals to client
1246  m_handler_message_box = m_node.handleMessageBox(boost::bind(ThreadSafeMessageBox, this, _1, _2, _3));
1247  m_handler_question = m_node.handleQuestion(boost::bind(ThreadSafeMessageBox, this, _1, _3, _4));
1248 }
1249 
1251 {
1252  // Disconnect signals from client
1253  m_handler_message_box->disconnect();
1254  m_handler_question->disconnect();
1255 }
1256 
1258  optionsModel(0),
1259  menu(0)
1260 {
1262  setToolTip(tr("Unit to show amounts in. Click to select another unit."));
1263  QList<BitcoinUnits::Unit> units = BitcoinUnits::availableUnits();
1264  int max_width = 0;
1265  const QFontMetrics fm(font());
1266  for (const BitcoinUnits::Unit unit : units)
1267  {
1268  max_width = qMax(max_width, fm.width(BitcoinUnits::longName(unit)));
1269  }
1270  setMinimumSize(max_width, 0);
1271  setAlignment(Qt::AlignRight | Qt::AlignVCenter);
1272  setStyleSheet(QString("QLabel { color : %1 }").arg(platformStyle->SingleColor().name()));
1273 }
1274 
1277 {
1278  onDisplayUnitsClicked(event->pos());
1279 }
1280 
1283 {
1284  menu = new QMenu(this);
1286  {
1287  QAction *menuAction = new QAction(QString(BitcoinUnits::longName(u)), this);
1288  menuAction->setData(QVariant(u));
1289  menu->addAction(menuAction);
1290  }
1291  connect(menu, &QMenu::triggered, this, &UnitDisplayStatusBarControl::onMenuSelection);
1292 }
1293 
1296 {
1297  if (_optionsModel)
1298  {
1299  this->optionsModel = _optionsModel;
1300 
1301  // be aware of a display unit change reported by the OptionsModel object.
1303 
1304  // initialize the display units label with the current value in the model.
1305  updateDisplayUnit(_optionsModel->getDisplayUnit());
1306  }
1307 }
1308 
1311 {
1312  setText(BitcoinUnits::longName(newUnits));
1313 }
1314 
1317 {
1318  QPoint globalPos = mapToGlobal(point);
1319  menu->exec(globalPos);
1320 }
1321 
1324 {
1325  if (action)
1326  {
1327  optionsModel->setDisplayUnit(action->data());
1328  }
1329 }
void subscribeToCoreSignals()
Connect core signals to GUI client.
void unsubscribeFromCoreSignals()
Disconnect core signals from GUI client.
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
bool setCurrentWallet(const QString &name)
Definition: walletframe.cpp:80
void message(const QString &title, const QString &message, unsigned int style)
Fired when a message should be reported to the user.
void setNetworkActive(bool networkActive)
Set network state shown in the UI.
Definition: bitcoingui.cpp:762
void addWallet(WalletModel *const walletModel)
QAction * receiveCoinsAction
Definition: bitcoingui.h:122
UnitDisplayStatusBarControl * unitDisplayControl
Definition: bitcoingui.h:100
Local Bitcoin RPC console.
Definition: rpcconsole.h:36
QMenuBar * appMenuBar
Definition: bitcoingui.h:110
void message(const QString &title, const QString &message, unsigned int style, bool *ret=nullptr)
Notify the user of an event from the core network or transaction handling code.
Definition: bitcoingui.cpp:897
Unit
Bitcoin units.
Definition: bitcoinunits.h:57
interfaces::Wallet & wallet() const
Definition: walletmodel.h:219
QAction * signMessageAction
Definition: bitcoingui.h:119
void receivedURI(const QString &uri)
Signal raised when a URI was entered or dragged to the GUI.
QAction * aboutAction
Definition: bitcoingui.h:121
virtual bool getNetworkActive()=0
Get network active.
void updateNetworkState()
Update UI with latest network info from model.
Definition: bitcoingui.cpp:728
QLabel * labelWalletHDStatusIcon
Definition: bitcoingui.h:102
void mousePressEvent(QMouseEvent *event)
So that it responds to left-button clicks.
void showNormalIfMinimized()
Show window if hidden, unminimize when minimized, rise when obscured or show if hidden and fToggleHid...
Definition: bitcoingui.h:266
UnitDisplayStatusBarControl(const PlatformStyle *platformStyle)
QProgressDialog * progressDialog
Definition: bitcoingui.h:108
static bool isWalletEnabled()
void hideTrayIconChanged(bool)
QMenu * trayIconMenu
Definition: bitcoingui.h:140
void showDebugWindow()
Show debug window.
Definition: bitcoingui.cpp:664
GUIUtil::ClickableLabel * labelProxyIcon
Definition: bitcoingui.h:103
virtual double getVerificationProgress()=0
Get verification progress.
ClientModel * clientModel
Definition: bitcoingui.h:97
WalletView * currentWalletView()
void createToolBars()
Create the toolbars.
Definition: bitcoingui.cpp:410
ModalOverlay * modalOverlay
Definition: bitcoingui.h:144
void createTrayIconMenu()
Create system tray menu (or setup the dock menu)
Definition: bitcoingui.cpp:599
RPCConsole * rpcConsole
Definition: bitcoingui.h:142
QAction * m_wallet_selector_action
Definition: bitcoingui.h:134
QAction * overviewAction
Definition: bitcoingui.h:112
UniValue ret(UniValue::VARR)
Definition: rpcwallet.cpp:1140
QAction * verifyMessageAction
Definition: bitcoingui.h:120
QAction * quitAction
Definition: bitcoingui.h:114
void dropEvent(QDropEvent *event)
void usedReceivingAddresses()
Show used receiving addresses.
QAction * historyAction
Definition: bitcoingui.h:113
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:328
void setWalletActionsEnabled(bool enabled)
Enable or disable all wallet-related actions.
Definition: bitcoingui.cpp:568
const QIcon & getAppIcon() const
Definition: networkstyle.h:20
void networkActiveChanged(bool networkActive)
QAction * aboutQtAction
Definition: bitcoingui.h:129
#define PACKAGE_NAME
OptionsModel * getOptionsModel()
QIcon SingleColorIcon(const QString &filename) const
Colorize an icon (given filename) with the icon color.
void encryptWallet(bool status)
Encrypt the wallet.
Macintosh-specific dock icon handler.
Mask of all available buttons in CClientUIInterface::MessageBoxFlags This needs to be updated...
Definition: ui_interface.h:63
Bitcoin GUI main class.
Definition: bitcoingui.h:59
bool isLayerVisible() const
Definition: modaloverlay.h:35
HelpMessageDialog * helpMessageDialog
Definition: bitcoingui.h:143
QLabel * progressBarLabel
Definition: bitcoingui.h:106
QSystemTrayIcon * trayIcon
Definition: bitcoingui.h:139
virtual std::vector< std::unique_ptr< Wallet > > getWallets()=0
Return interfaces for accessing wallets (if any).
QAction * showHelpMessageAction
Definition: bitcoingui.h:132
Notify user of potential problem.
Definition: notificator.h:39
Modal overlay to display information about the chain-sync state.
Definition: modaloverlay.h:19
const QString & getTitleAddText() const
Definition: networkstyle.h:22
static QString longName(int unit)
Long name.
void numConnectionsChanged(int count)
Signals for UI communication.
Definition: ui_interface.h:31
void removeAllWallets()
GUIUtil::ClickableLabel * connectionsControl
Definition: bitcoingui.h:104
QAction * backupWalletAction
Definition: bitcoingui.h:127
void setOptionsModel(OptionsModel *optionsModel)
Lets the control know about the Options Model (and its signals)
void openOptionsDialogWithTab(OptionsDialog::Tab tab)
Open the OptionsDialog on the specified tab index.
Definition: bitcoingui.cpp:776
EncryptionStatus getEncryptionStatus() const
int getDisplayUnit() const
Definition: optionsmodel.h:74
virtual std::unique_ptr< Handler > handleMessageBox(MessageBoxFn fn)=0
Force blocking, modal message box dialog (not just OS notification)
Definition: ui_interface.h:67
void showOutOfSyncWarning(bool fShow)
QIcon TextColorIcon(const QString &filename) const
Colorize an icon (given filename) with the text color.
void setIcon(const QIcon &icon)
void setClientModel(ClientModel *model)
Definition: rpcconsole.cpp:563
void gotoHistoryPage()
Switch to history (transactions) page.
QAction * usedReceivingAddressesAction
Definition: bitcoingui.h:118
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
BitcoinGUI(interfaces::Node &node, const PlatformStyle *platformStyle, const NetworkStyle *networkStyle, QWidget *parent=0)
Definition: bitcoingui.cpp:73
void setClientModel(ClientModel *clientModel)
Set the client model.
Definition: bitcoingui.cpp:446
WalletModel * getWalletModel()
Definition: walletview.h:47
void showModalOverlay()
void gotoOverviewPage()
Switch to overview (home) page.
const PlatformStyle * platformStyle
Definition: bitcoingui.h:150
QAction * toggleHideAction
Definition: bitcoingui.h:125
virtual bool hdEnabled()=0
void showProgress(const QString &title, int nProgress)
Show progress dialog e.g.
static MacDockIconHandler * instance()
void setDisplayUnit(const QVariant &value)
Updates current unit in memory, settings and emits displayUnitChanged(newUnit) signal.
void setClientModel(ClientModel *clientModel)
Definition: walletframe.cpp:38
void setMainWindow(QMainWindow *window)
bool isObscured(QWidget *w)
Definition: guiutil.cpp:347
QAction * m_wallet_selector_label_action
Definition: bitcoingui.h:133
int getNumConnections(unsigned int flags=CONNECTIONS_ALL) const
Return number of connections, default is in- and outbound (total)
Definition: clientmodel.cpp:58
OptionsModel * optionsModel
Definition: bitcoingui.h:297
QLabel * m_wallet_selector_label
Definition: bitcoingui.h:136
enum BlockSource getBlockSource() const
Returns enum BlockSource of the current importing/syncing state.
void setKnownBestHeight(int count, const QDateTime &blockDate)
void optionsClicked()
Show configuration dialog.
Definition: bitcoingui.cpp:650
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
void notify(Class cls, const QString &title, const QString &text, const QIcon &icon=QIcon(), int millisTimeout=10000)
Show notification message.
bool eventFilter(QObject *object, QEvent *event)
const char * name
Definition: rest.cpp:37
QToolBar * appToolBar
Definition: bitcoingui.h:111
BlockSource
Definition: clientmodel.h:29
WalletFrame * walletFrame
Definition: bitcoingui.h:98
void updateDisplayUnit(int newUnits)
When Display Units are changed on OptionsModel it will refresh the display text of the control on the...
QAction * usedSendingAddressesAction
Definition: bitcoingui.h:117
void setTabFocus(enum TabTypes tabType)
set which tab has the focus (is visible)
int64_t nPowTargetSpacing
Definition: params.h:60
void setTrayIconVisible(bool)
When hideTrayIcon setting is changed in OptionsModel hide or show the icon accordingly.
void toggleVisibility()
bool enableWallet
Definition: bitcoingui.h:83
void setModel(OptionsModel *model)
QAction * openRPCConsoleAction
Definition: bitcoingui.h:130
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.
QLabel * labelWalletEncryptionIcon
Definition: bitcoingui.h:101
GUIUtil::ClickableLabel * labelBlocksIcon
Definition: bitcoingui.h:105
void setCurrentTab(OptionsDialog::Tab tab)
Informational message.
Definition: notificator.h:38
GUIUtil::ClickableProgressBar * progressBar
Definition: bitcoingui.h:107
void numBlocksChanged(int count, const QDateTime &blockDate, double nVerificationProgress, bool header)
UniValue help(const JSONRPCRequest &jsonRequest)
Definition: server.cpp:202
void showHelpMessageClicked()
Show help message dialog.
Definition: bitcoingui.cpp:678
QString getWalletName() const
void dragEnterEvent(QDragEnterEvent *event)
Notificator * notificator
Definition: bitcoingui.h:141
void displayUnitChanged(int unit)
void changePassphrase()
Change encrypted wallet passphrase.
Model for Bitcoin network client.
Definition: clientmodel.h:44
An error occurred.
Definition: notificator.h:40
const QIcon & getTrayAndWindowIcon() const
Definition: networkstyle.h:21
QAction * receiveCoinsMenuAction
Definition: bitcoingui.h:123
ClickableProgressBar ProgressBar
Definition: guiutil.h:234
void gotoSignMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to sign message tab.
virtual bool shutdownRequested()=0
Return whether shutdown was requested.
QAction * sendCoinsAction
Definition: bitcoingui.h:115
void showHide(bool hide=false, bool userRequested=false)
QColor SingleColor() const
Definition: platformstyle.h:25
void requestedSyncWarningInfo()
Notify that the user has requested more information about the out-of-sync warning.
QAction * openAction
Definition: bitcoingui.h:131
static QList< Unit > availableUnits()
Get list of units, for drop-down box.
void trayIconActivated(QSystemTrayIcon::ActivationReason reason)
Handle tray icon clicked.
Definition: bitcoingui.cpp:640
bool getMinimizeOnClose() const
Definition: optionsmodel.h:73
void updateProxyIcon()
Set the proxy-enabled icon as shown in the UI.
QAction * changePassphraseAction
Definition: bitcoingui.h:128
virtual int64_t getLastBlockTime()=0
Get last block time.
void gotoSendCoinsPage(QString addr="")
Switch to send coins page.
virtual std::unique_ptr< Handler > handleQuestion(QuestionFn fn)=0
void gotoReceiveCoinsPage()
Switch to receive coins page.
void closeEvent(QCloseEvent *event)
Definition: bitcoingui.cpp:981
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:29
std::unique_ptr< interfaces::Handler > m_handler_question
Definition: bitcoingui.h:96
const CChainParams & Params()
Return the currently selected parameters.
bool getMinimizeToTray() const
Definition: optionsmodel.h:72
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:125
QAction * sendCoinsMenuAction
Definition: bitcoingui.h:116
void changeEvent(QEvent *e)
Definition: bitcoingui.cpp:957
int prevBlocks
Keep track of previous number of blocks, to detect progress.
Definition: bitcoingui.h:147
void toggleHidden()
Simply calls showNormalIfMinimized(true) for use in SLOT() macro.
interfaces::Node & m_node
Definition: bitcoingui.h:94
bool removeWallet(const QString &name)
Definition: walletframe.cpp:92
int spinnerFrame
Definition: bitcoingui.h:148
void removeWallet(WalletModel *const walletModel)
void showEvent(QShowEvent *event)
bool addWallet(WalletModel *walletModel)
Definition: walletframe.cpp:43
void setNumConnections(int count)
Set number of connections shown in the UI.
Definition: bitcoingui.cpp:757
"Help message" dialog box
Definition: utilitydialog.h:22
void backupWallet()
Backup the wallet.
bool noui_ThreadSafeMessageBox(const std::string &message, const std::string &caption, unsigned int style)
Non-GUI handler, which logs and prints messages.
Definition: noui.cpp:17
QComboBox * m_wallet_selector
Definition: bitcoingui.h:137
Preferences dialog.
Definition: optionsdialog.h:35
void clicked(const QPoint &point)
Emitted when the progressbar is clicked.
virtual int getNumBlocks()=0
Get num blocks.
QString formatNiceTimeOffset(qint64 secs)
Definition: guiutil.cpp:841
static QString formatWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as string (with unit)
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:672
void createActions()
Create the main UI actions.
Definition: bitcoingui.cpp:233
int64_t GetTime()
GetTimeMicros() and GetTimeMillis() both return the system time, but in different units...
Definition: utiltime.cpp:20
QAction * optionsAction
Definition: bitcoingui.h:124
QAction * encryptWalletAction
Definition: bitcoingui.h:126
void aboutClicked()
Show about dialog.
Definition: bitcoingui.cpp:655
const Consensus::Params & GetConsensus() const
Definition: chainparams.h:60
int getHeaderTipHeight() const
Definition: clientmodel.cpp:72
void updateHeadersSyncProgressLabel()
Definition: bitcoingui.cpp:767
static const std::string DEFAULT_UIPLATFORM
Definition: bitcoingui.h:64
virtual void setNetworkActive(bool active)=0
Set network active.
int64_t getHeaderTipTime() const
Definition: clientmodel.cpp:87
Top-level interface for a bitcoin node (bsha3d process).
Definition: node.h:35
A container for embedding all wallet-related controls into BitcoinGUI.
Definition: walletframe.h:29
void showProgress(const QString &title, int nProgress)
void usedSendingAddresses()
Show used sending addresses.
void setNumBlocks(int count, const QDateTime &blockDate, double nVerificationProgress, bool headers)
Set number of blocks and last block date shown in the UI.
Definition: bitcoingui.cpp:787
bool getHideTrayIcon() const
Definition: optionsmodel.h:71
void onDisplayUnitsClicked(const QPoint &point)
Shows context menu with Display Unit options by the mouse coordinates.
void createTrayIcon(const NetworkStyle *networkStyle)
Create system tray icon and notification.
Definition: bitcoingui.cpp:586
void createMenuBar()
Create the menu bar and sub-menus.
Definition: bitcoingui.cpp:365
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:95
Predefined combinations for certain default usage cases.
Definition: ui_interface.h:73
#define SPINNER_FRAMES
Definition: guiconstants.h:47
bool getProxyInfo(std::string &ip_port) const