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