4 * W.J. van der Laan 2011-2012
5 * The Bitcoin Developers 2011-2012
7 #include "bitcoingui.h"
8 #include "transactiontablemodel.h"
9 #include "addressbookpage.h"
10 #include "sendcoinsdialog.h"
11 #include "signverifymessagedialog.h"
12 #include "multisigdialog.h"
13 #include "optionsdialog.h"
14 #include "aboutdialog.h"
15 #include "clientmodel.h"
16 #include "walletmodel.h"
17 #include "editaddressdialog.h"
18 #include "optionsmodel.h"
19 #include "transactiondescdialog.h"
20 #include "addresstablemodel.h"
21 #include "transactionview.h"
22 #include "overviewpage.h"
23 #include "bitcoinunits.h"
24 #include "guiconstants.h"
25 #include "askpassphrasedialog.h"
26 #include "notificator.h"
28 #include "ui_interface.h"
29 #include "rpcconsole.h"
30 #include "mintingview.h"
33 #include "macdockiconhandler.h"
36 #include <QApplication>
37 #if QT_VERSION < 0x050000
38 #include <QMainWindow>
44 #include <QVBoxLayout>
49 #include <QPushButton>
51 #include <QMessageBox>
52 #include <QProgressBar>
53 #include <QStackedWidget>
56 #include <QFileDialog>
57 #if QT_VERSION < 0x050000
58 #include <QDesktopServices>
60 #include <QStandardPaths>
63 #include <QDragEnterEvent>
64 #if QT_VERSION < 0x050000
72 extern bool fWalletUnlockMintOnly;
74 BitcoinGUI::BitcoinGUI(QWidget *parent):
78 encryptWalletAction(0),
80 unlockWalletAction(0),
81 unlockWalletMiningAction(0),
82 changePassphraseAction(0),
90 setWindowTitle(tr("NovaCoin") + " - " + tr("Wallet"));
92 qApp->setWindowIcon(QIcon(":icons/bitcoin"));
93 setWindowIcon(QIcon(":icons/bitcoin"));
95 setUnifiedTitleAndToolBarOnMac(true);
96 QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
101 // Create actions for the toolbar, menu bar and tray/dock icon
104 // Create application menu bar
107 // Create the toolbars
110 // Create the tray icon (or setup the dock icon)
114 overviewPage = new OverviewPage();
116 transactionsPage = new QWidget(this);
117 QVBoxLayout *vbox = new QVBoxLayout();
118 transactionView = new TransactionView(this);
119 vbox->addWidget(transactionView);
120 transactionsPage->setLayout(vbox);
122 mintingPage = new QWidget(this);
123 QVBoxLayout *vboxMinting = new QVBoxLayout();
124 mintingView = new MintingView(this);
125 vboxMinting->addWidget(mintingView);
126 mintingPage->setLayout(vboxMinting);
128 addressBookPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::SendingTab);
130 receiveCoinsPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::ReceivingTab);
132 sendCoinsPage = new SendCoinsDialog(this);
134 signVerifyMessageDialog = new SignVerifyMessageDialog(this);
136 multisigPage = new MultisigDialog(this);
138 centralWidget = new QStackedWidget(this);
139 centralWidget->addWidget(overviewPage);
140 centralWidget->addWidget(transactionsPage);
141 centralWidget->addWidget(mintingPage);
142 centralWidget->addWidget(addressBookPage);
143 centralWidget->addWidget(receiveCoinsPage);
144 centralWidget->addWidget(sendCoinsPage);
145 setCentralWidget(centralWidget);
150 // Status bar notification icons
151 QFrame *frameBlocks = new QFrame();
152 frameBlocks->setContentsMargins(0,0,0,0);
153 frameBlocks->setMinimumWidth(72);
154 frameBlocks->setMaximumWidth(72);
155 QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);
156 frameBlocksLayout->setContentsMargins(3,0,3,0);
157 frameBlocksLayout->setSpacing(3);
158 labelEncryptionIcon = new QLabel();
159 labelMiningIcon = new QLabel();
160 labelConnectionsIcon = new QLabel();
161 labelBlocksIcon = new QLabel();
162 frameBlocksLayout->addStretch();
163 frameBlocksLayout->addWidget(labelEncryptionIcon);
164 frameBlocksLayout->addStretch();
165 frameBlocksLayout->addWidget(labelMiningIcon);
166 frameBlocksLayout->addStretch();
167 frameBlocksLayout->addWidget(labelConnectionsIcon);
168 frameBlocksLayout->addStretch();
169 frameBlocksLayout->addWidget(labelBlocksIcon);
170 frameBlocksLayout->addStretch();
172 // Progress bar and label for blocks download
173 progressBarLabel = new QLabel();
174 progressBarLabel->setVisible(false);
175 progressBar = new QProgressBar();
176 progressBar->setAlignment(Qt::AlignCenter);
177 progressBar->setVisible(false);
179 // Override style sheet for progress bar for styles that have a segmented progress bar,
180 // as they make the text unreadable (workaround for issue #1071)
181 // See https://qt-project.org/doc/qt-4.8/gallery.html
182 QString curStyle = qApp->style()->metaObject()->className();
183 if(curStyle == "QWindowsStyle" || curStyle == "QWindowsXPStyle")
185 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; }");
188 statusBar()->addWidget(progressBarLabel);
189 statusBar()->addWidget(progressBar);
190 statusBar()->addPermanentWidget(frameBlocks);
192 syncIconMovie = new QMovie(":/movies/update_spinner", "mng", this);
194 // Clicking on a transaction on the overview page simply sends you to transaction history page
195 connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), this, SLOT(gotoHistoryPage()));
196 connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex)));
198 // Double-clicking on a transaction on the transaction history page shows details
199 connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
201 rpcConsole = new RPCConsole(0);
202 connect(openRPCConsoleAction, SIGNAL(triggered()), rpcConsole, SLOT(show()));
204 aboutDialog = new AboutDialog(0);
206 // Clicking on "Verify Message" in the address book sends you to the verify message tab
207 connect(addressBookPage, SIGNAL(verifyMessage(QString)), this, SLOT(gotoVerifyMessageTab(QString)));
208 // Clicking on "Sign Message" in the receive coins page sends you to the sign message tab
209 connect(receiveCoinsPage, SIGNAL(signMessage(QString)), this, SLOT(gotoSignMessageTab(QString)));
214 BitcoinGUI::~BitcoinGUI()
216 if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu)
226 void BitcoinGUI::createActions()
228 QActionGroup *tabGroup = new QActionGroup(this);
230 overviewAction = new QAction(QIcon(":/icons/overview"), tr("&Overview"), this);
231 overviewAction->setToolTip(tr("Show general overview of wallet"));
232 overviewAction->setCheckable(true);
233 overviewAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_1));
234 tabGroup->addAction(overviewAction);
236 sendCoinsAction = new QAction(QIcon(":/icons/send"), tr("&Send coins"), this);
237 sendCoinsAction->setToolTip(tr("Send coins to a NovaCoin address"));
238 sendCoinsAction->setCheckable(true);
239 sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2));
240 tabGroup->addAction(sendCoinsAction);
242 receiveCoinsAction = new QAction(QIcon(":/icons/receiving_addresses"), tr("&Receive coins"), this);
243 receiveCoinsAction->setToolTip(tr("Show the list of addresses for receiving payments"));
244 receiveCoinsAction->setCheckable(true);
245 receiveCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_3));
246 tabGroup->addAction(receiveCoinsAction);
248 historyAction = new QAction(QIcon(":/icons/history"), tr("&Transactions"), this);
249 historyAction->setToolTip(tr("Browse transaction history"));
250 historyAction->setCheckable(true);
251 historyAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_4));
252 tabGroup->addAction(historyAction);
254 mintingAction = new QAction(QIcon(":/icons/history"), tr("&Minting"), this);
255 mintingAction->setToolTip(tr("Show your minting capacity"));
256 mintingAction->setCheckable(true);
257 mintingAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_5));
258 tabGroup->addAction(mintingAction);
260 addressBookAction = new QAction(QIcon(":/icons/address-book"), tr("&Address Book"), this);
261 addressBookAction->setToolTip(tr("Edit the list of stored addresses and labels"));
262 addressBookAction->setCheckable(true);
263 addressBookAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_6));
264 tabGroup->addAction(addressBookAction);
266 multisigAction = new QAction(QIcon(":/icons/send"), tr("Multisig"), this);
267 tabGroup->addAction(multisigAction);
269 connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
270 connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage()));
271 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
272 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
273 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
274 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
275 connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
276 connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage()));
277 connect(mintingAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
278 connect(mintingAction, SIGNAL(triggered()), this, SLOT(gotoMintingPage()));
279 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
280 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(gotoAddressBookPage()));
281 connect(multisigAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
282 connect(multisigAction, SIGNAL(triggered()), this, SLOT(gotoMultisigPage()));
284 quitAction = new QAction(QIcon(":/icons/quit"), tr("E&xit"), this);
285 quitAction->setToolTip(tr("Quit application"));
286 quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
287 quitAction->setMenuRole(QAction::QuitRole);
288 aboutAction = new QAction(QIcon(":/icons/bitcoin"), tr("&About NovaCoin"), this);
289 aboutAction->setToolTip(tr("Show information about NovaCoin"));
290 aboutAction->setMenuRole(QAction::AboutRole);
291 #if QT_VERSION < 0x050000
292 aboutQtAction = new QAction(QIcon(":/trolltech/qmessagebox/images/qtlogo-64.png"), tr("About &Qt"), this);
294 aboutQtAction = new QAction(QIcon(":/qt-project.org/qmessagebox/images/qtlogo-64.png"), tr("About &Qt"), this);
296 aboutQtAction->setToolTip(tr("Show information about Qt"));
297 aboutQtAction->setMenuRole(QAction::AboutQtRole);
298 optionsAction = new QAction(QIcon(":/icons/options"), tr("&Options..."), this);
299 optionsAction->setToolTip(tr("Modify configuration options for NovaCoin"));
300 optionsAction->setMenuRole(QAction::PreferencesRole);
301 toggleHideAction = new QAction(QIcon(":/icons/bitcoin"), tr("&Show / Hide"), this);
302 encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet..."), this);
303 encryptWalletAction->setToolTip(tr("Encrypt or decrypt wallet"));
304 encryptWalletAction->setCheckable(true);
305 backupWalletAction = new QAction(QIcon(":/icons/filesave"), tr("&Backup Wallet..."), this);
306 backupWalletAction->setToolTip(tr("Backup wallet to another location"));
307 dumpWalletAction = new QAction(QIcon(":/icons/dump"), tr("&Dump Wallet..."), this);
308 dumpWalletAction->setStatusTip(tr("Dump keys to a text file"));
309 importWalletAction = new QAction(QIcon(":/icons/import"), tr("&Import Wallet..."), this);
310 importWalletAction->setStatusTip(tr("Import keys into a wallet"));
311 changePassphraseAction = new QAction(QIcon(":/icons/key"), tr("&Change Passphrase..."), this);
312 changePassphraseAction->setToolTip(tr("Change the passphrase used for wallet encryption"));
313 signMessageAction = new QAction(QIcon(":/icons/edit"), tr("Sign &message..."), this);
314 verifyMessageAction = new QAction(QIcon(":/icons/transaction_0"), tr("&Verify message..."), this);
316 lockWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Lock wallet"), this);
317 lockWalletAction->setToolTip(tr("Lock wallet"));
318 lockWalletAction->setCheckable(true);
320 unlockWalletAction = new QAction(QIcon(":/icons/lock_open"), tr("Unlo&ck wallet"), this);
321 unlockWalletAction->setToolTip(tr("Unlock wallet"));
322 unlockWalletAction->setCheckable(true);
324 unlockWalletMiningAction = new QAction(QIcon(":/icons/mining_active"), tr("Unlo&ck wallet for mining"), this);
325 unlockWalletMiningAction->setToolTip(tr("Unlock wallet for mining"));
326 unlockWalletMiningAction->setCheckable(true);
328 exportAction = new QAction(QIcon(":/icons/export"), tr("&Export..."), this);
329 exportAction->setToolTip(tr("Export the data in the current tab to a file"));
330 openRPCConsoleAction = new QAction(QIcon(":/icons/debugwindow"), tr("&Debug window"), this);
331 openRPCConsoleAction->setToolTip(tr("Open debugging and diagnostic console"));
333 connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
334 connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked()));
335 connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
336 connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked()));
337 connect(toggleHideAction, SIGNAL(triggered()), this, SLOT(toggleHidden()));
338 connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool)));
339 connect(lockWalletAction, SIGNAL(triggered(bool)), this, SLOT(lockWallet()));
340 connect(unlockWalletAction, SIGNAL(triggered(bool)), this, SLOT(unlockWallet()));
341 connect(unlockWalletMiningAction, SIGNAL(triggered(bool)), this, SLOT(unlockWalletMining(bool)));
342 connect(backupWalletAction, SIGNAL(triggered()), this, SLOT(backupWallet()));
343 connect(dumpWalletAction, SIGNAL(triggered()), this, SLOT(dumpWallet()));
344 connect(importWalletAction, SIGNAL(triggered()), this, SLOT(importWallet()));
345 connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase()));
346 connect(signMessageAction, SIGNAL(triggered()), this, SLOT(gotoSignMessageTab()));
347 connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(gotoVerifyMessageTab()));
350 void BitcoinGUI::createMenuBar()
353 // Create a decoupled menu bar on Mac which stays even if the window is closed
354 appMenuBar = new QMenuBar();
356 // Get the main window's menu bar on other platforms
357 appMenuBar = menuBar();
360 // Configure the menus
361 QMenu *file = appMenuBar->addMenu(tr("&File"));
362 file->addAction(backupWalletAction);
363 file->addSeparator();
364 file->addAction(dumpWalletAction);
365 file->addAction(importWalletAction);
366 file->addAction(exportAction);
367 file->addAction(signMessageAction);
368 file->addAction(verifyMessageAction);
369 file->addAction(multisigAction);
370 file->addSeparator();
371 file->addAction(quitAction);
373 QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
374 QMenu *securityMenu = settings->addMenu(QIcon(":/icons/key"), tr("&Wallet security"));
375 securityMenu->addAction(encryptWalletAction);
376 securityMenu->addAction(changePassphraseAction);
377 securityMenu->addAction(unlockWalletAction);
378 securityMenu->addAction(unlockWalletMiningAction);
379 securityMenu->addAction(lockWalletAction);
380 settings->addAction(optionsAction);
382 QMenu *help = appMenuBar->addMenu(tr("&Help"));
383 help->addAction(openRPCConsoleAction);
384 help->addSeparator();
385 help->addAction(aboutAction);
386 help->addAction(aboutQtAction);
389 void BitcoinGUI::createToolBars()
391 QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));
392 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
393 toolbar->addAction(overviewAction);
394 toolbar->addAction(sendCoinsAction);
395 toolbar->addAction(receiveCoinsAction);
396 toolbar->addAction(historyAction);
397 toolbar->addAction(mintingAction);
398 toolbar->addAction(addressBookAction);
400 QToolBar *toolbar2 = addToolBar(tr("Actions toolbar"));
401 toolbar2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
402 toolbar2->addAction(exportAction);
403 toolbar2->setVisible(false);
407 void BitcoinGUI::setClientModel(ClientModel *clientModel)
409 this->clientModel = clientModel;
412 // Replace some strings and icons, when using the testnet
413 if(clientModel->isTestNet())
415 setWindowTitle(windowTitle() + QString(" ") + tr("[testnet]"));
417 qApp->setWindowIcon(QIcon(":icons/bitcoin_testnet"));
418 setWindowIcon(QIcon(":icons/bitcoin_testnet"));
420 MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
424 trayIcon->setToolTip(tr("NovaCoin client") + QString(" ") + tr("[testnet]"));
425 trayIcon->setIcon(QIcon(":/icons/toolbar_testnet"));
426 toggleHideAction->setIcon(QIcon(":/icons/toolbar_testnet"));
429 aboutAction->setIcon(QIcon(":/icons/toolbar_testnet"));
432 // Keep up to date with client
433 setNumConnections(clientModel->getNumConnections());
434 connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
436 setNumBlocks(clientModel->getNumBlocks(), clientModel->getNumBlocksOfPeers());
437 connect(clientModel, SIGNAL(numBlocksChanged(int,int)), this, SLOT(setNumBlocks(int,int)));
439 QTimer *timer = new QTimer(this);
440 connect(timer, SIGNAL(timeout()), this, SLOT(updateMining()));
441 timer->start(10*1000); //10 seconds
443 // Report errors from network/worker thread
444 connect(clientModel, SIGNAL(error(QString,QString,bool)), this, SLOT(error(QString,QString,bool)));
446 rpcConsole->setClientModel(clientModel);
447 addressBookPage->setOptionsModel(clientModel->getOptionsModel());
448 receiveCoinsPage->setOptionsModel(clientModel->getOptionsModel());
452 void BitcoinGUI::setWalletModel(WalletModel *walletModel)
454 this->walletModel = walletModel;
457 // Report errors from wallet thread
458 connect(walletModel, SIGNAL(error(QString,QString,bool)), this, SLOT(error(QString,QString,bool)));
460 // Put transaction list in tabs
461 transactionView->setModel(walletModel);
462 mintingView->setModel(walletModel);
464 overviewPage->setModel(walletModel);
465 addressBookPage->setModel(walletModel->getAddressTableModel());
466 receiveCoinsPage->setModel(walletModel->getAddressTableModel());
467 sendCoinsPage->setModel(walletModel);
468 signVerifyMessageDialog->setModel(walletModel);
469 multisigPage->setModel(walletModel);
471 setEncryptionStatus(walletModel->getEncryptionStatus());
472 connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));
473 connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(updateMining()));
475 // Balloon pop-up for new transaction
476 connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
477 this, SLOT(incomingTransaction(QModelIndex,int,int)));
479 // Ask for passphrase if needed
480 connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
484 void BitcoinGUI::createTrayIcon()
488 trayIcon = new QSystemTrayIcon(this);
489 trayIconMenu = new QMenu(this);
490 trayIcon->setContextMenu(trayIconMenu);
491 trayIcon->setToolTip(tr("NovaCoin client"));
492 trayIcon->setIcon(QIcon(":/icons/toolbar"));
493 connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
494 this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
497 // Note: On Mac, the dock icon is used to provide the tray's functionality.
498 MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance();
499 dockIconHandler->setMainWindow((QMainWindow *)this);
500 trayIconMenu = dockIconHandler->dockMenu();
503 // Configuration of the tray icon (or dock icon) icon menu
504 trayIconMenu->addAction(toggleHideAction);
505 trayIconMenu->addSeparator();
506 trayIconMenu->addAction(sendCoinsAction);
507 trayIconMenu->addAction(multisigAction);
508 trayIconMenu->addAction(receiveCoinsAction);
509 trayIconMenu->addSeparator();
510 trayIconMenu->addAction(signMessageAction);
511 trayIconMenu->addAction(verifyMessageAction);
512 trayIconMenu->addSeparator();
513 trayIconMenu->addAction(optionsAction);
514 trayIconMenu->addAction(openRPCConsoleAction);
516 // This is built-in on Mac
517 trayIconMenu->addSeparator();
518 trayIconMenu->addAction(quitAction);
520 notificator = new Notificator(QApplication::applicationName(), trayIcon, this);
524 void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
526 if(reason == QSystemTrayIcon::Trigger)
528 // Click on system tray icon triggers show/hide of the main window
529 toggleHideAction->trigger();
534 void BitcoinGUI::optionsClicked()
536 if(!clientModel || !clientModel->getOptionsModel())
539 dlg.setModel(clientModel->getOptionsModel());
543 void BitcoinGUI::aboutClicked()
545 aboutDialog->setModel(clientModel);
546 aboutDialog->setWindowModality(Qt::ApplicationModal);
550 void BitcoinGUI::setNumConnections(int count)
555 case 0: icon = ":/icons/connect_0"; break;
556 case 1: case 2: case 3: icon = ":/icons/connect_1"; break;
557 case 4: case 5: case 6: icon = ":/icons/connect_2"; break;
558 case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
559 default: icon = ":/icons/connect_4"; break;
561 labelConnectionsIcon->setPixmap(QIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
562 labelConnectionsIcon->setToolTip(tr("%n active connection(s) to NovaCoin network", "", count));
565 void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks)
567 // don't show / hide progress bar and its label if we have no connection to the network
568 if (!clientModel || clientModel->getNumConnections() == 0)
570 progressBarLabel->setVisible(false);
571 progressBar->setVisible(false);
576 QString strStatusBarWarnings = clientModel->getStatusBarWarnings();
579 if(count < nTotalBlocks)
581 int nRemainingBlocks = nTotalBlocks - count;
582 float nPercentageDone = count / (nTotalBlocks * 0.01f);
584 if (strStatusBarWarnings.isEmpty())
586 progressBarLabel->setText(tr("Synchronizing with network..."));
587 progressBarLabel->setVisible(true);
588 progressBar->setFormat(tr("~%n block(s) remaining", "", nRemainingBlocks));
589 progressBar->setMaximum(nTotalBlocks);
590 progressBar->setValue(count);
591 progressBar->setVisible(true);
594 tooltip = tr("Downloaded %1 of %2 blocks of transaction history (%3% done).").arg(count).arg(nTotalBlocks).arg(nPercentageDone, 0, 'f', 2);
598 if (strStatusBarWarnings.isEmpty())
599 progressBarLabel->setVisible(false);
601 progressBar->setVisible(false);
602 tooltip = tr("Downloaded %1 blocks of transaction history.").arg(count);
605 // Override progressBarLabel text and hide progress bar, when we have warnings to display
606 if (!strStatusBarWarnings.isEmpty())
608 progressBarLabel->setText(strStatusBarWarnings);
609 progressBarLabel->setVisible(true);
610 progressBar->setVisible(false);
613 QDateTime lastBlockDate = clientModel->getLastBlockDate();
614 int secs = lastBlockDate.secsTo(QDateTime::currentDateTime());
617 // Represent time from last generated block in human readable text
620 // Fully up to date. Leave text empty.
624 text = tr("%n second(s) ago","",secs);
626 else if(secs < 60*60)
628 text = tr("%n minute(s) ago","",secs/60);
630 else if(secs < 24*60*60)
632 text = tr("%n hour(s) ago","",secs/(60*60));
636 text = tr("%n day(s) ago","",secs/(60*60*24));
639 // Set icon state: spinning if catching up, tick otherwise
640 if(secs < 90*60 && count >= nTotalBlocks)
642 tooltip = tr("Up to date") + QString(".<br>") + tooltip;
643 labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
645 overviewPage->showOutOfSyncWarning(false);
649 tooltip = tr("Catching up...") + QString("<br>") + tooltip;
650 labelBlocksIcon->setMovie(syncIconMovie);
651 syncIconMovie->start();
653 overviewPage->showOutOfSyncWarning(true);
658 tooltip += QString("<br>");
659 tooltip += tr("Last received block was generated %1.").arg(text);
662 // Don't word-wrap this (fixed-width) tooltip
663 tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
665 labelBlocksIcon->setToolTip(tooltip);
666 progressBarLabel->setToolTip(tooltip);
667 progressBar->setToolTip(tooltip);
670 void BitcoinGUI::updateMining()
675 labelMiningIcon->setPixmap(QIcon(":/icons/mining_inactive").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
677 if (!clientModel->getNumConnections())
679 labelMiningIcon->setToolTip(tr("Wallet is offline"));
683 if (walletModel->getEncryptionStatus() == WalletModel::Locked)
685 labelMiningIcon->setToolTip(tr("Wallet is locked"));
689 if (clientModel->inInitialBlockDownload() || clientModel->getNumBlocksOfPeers() > clientModel->getNumBlocks())
691 labelMiningIcon->setToolTip(tr("Blockchain download is in progress"));
695 float nKernelsRate = 0, nCoinDaysRate = 0;
696 walletModel->getStakeStats(nKernelsRate, nCoinDaysRate);
698 if (nKernelsRate > 0)
700 labelMiningIcon->setPixmap(QIcon(":/icons/mining_active").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
702 uint64_t nNetworkWeight = clientModel->getPoSKernelPS();
704 double dDifficulty = clientModel->getDifficulty(true);
707 int nApproxTime = 4294967297 * dDifficulty / nTotalWeight;
709 if (nApproxTime < 60)
710 msg = tr("%n second(s)", "", nApproxTime);
711 else if (nApproxTime < 60*60)
712 msg = tr("%n minute(s)", "", nApproxTime / 60);
713 else if (nApproxTime < 24*60*60)
714 msg = tr("%n hour(s)", "", nApproxTime / 3600);
716 msg = tr("%n day(s)", "", nApproxTime / 86400);
718 labelMiningIcon->setToolTip(tr("Stake miner is active\nYour current stake weight is %1\nNetwork weight is %2\nAverage block generation time is %3").arg(nTotalWeight).arg(dNetworkWeight).arg(msg));
721 labelMiningIcon->setToolTip(QString("<nobr>")+tr("Stake miner is active<br>Kernel rate is %1 k/s<br>CD rate is %2 CD/s<br>Network weight is %3").arg(nKernelsRate).arg(nCoinDaysRate).arg(nNetworkWeight)+QString("<\nobr>"));
724 labelMiningIcon->setToolTip(tr("No suitable inputs were found"));
727 void BitcoinGUI::error(const QString &title, const QString &message, bool modal)
729 // Report errors from network/worker thread
732 QMessageBox::critical(this, title, message, QMessageBox::Ok, QMessageBox::Ok);
734 notificator->notify(Notificator::Critical, title, message);
738 void BitcoinGUI::message(const QString &title, const QString &message, unsigned int style, const QString &detail)
740 QString strTitle = tr("NovaCoin") + " - ";
741 // Default to information icon
742 int nMBoxIcon = QMessageBox::Information;
743 int nNotifyIcon = Notificator::Information;
746 // Check for usage of predefined title
748 case CClientUIInterface::MSG_ERROR:
749 strTitle += tr("Error");
751 case CClientUIInterface::MSG_WARNING:
752 strTitle += tr("Warning");
754 case CClientUIInterface::MSG_INFORMATION:
755 strTitle += tr("Information");
758 strTitle += title; // Use supplied title
761 // Check for error/warning icon
762 if (style & CClientUIInterface::ICON_ERROR) {
763 nMBoxIcon = QMessageBox::Critical;
764 nNotifyIcon = Notificator::Critical;
766 else if (style & CClientUIInterface::ICON_WARNING) {
767 nMBoxIcon = QMessageBox::Warning;
768 nNotifyIcon = Notificator::Warning;
772 if (style & CClientUIInterface::MODAL) {
773 // Check for buttons, use OK as default, if none was supplied
774 QMessageBox::StandardButton buttons;
775 buttons = QMessageBox::Ok;
777 QMessageBox mBox((QMessageBox::Icon)nMBoxIcon, strTitle, message, buttons);
779 if(!detail.isEmpty()) { mBox.setDetailedText(detail); }
784 notificator->notify((Notificator::Class)nNotifyIcon, strTitle, message);
788 void BitcoinGUI::changeEvent(QEvent *e)
790 QMainWindow::changeEvent(e);
791 #ifndef Q_OS_MAC // Ignored on Mac
792 if(e->type() == QEvent::WindowStateChange)
794 if(clientModel && clientModel->getOptionsModel()->getMinimizeToTray())
796 QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
797 if(!(wsevt->oldState() & Qt::WindowMinimized) && isMinimized())
799 QTimer::singleShot(0, this, SLOT(hide()));
807 void BitcoinGUI::closeEvent(QCloseEvent *event)
811 #ifndef Q_OS_MAC // Ignored on Mac
812 if(!clientModel->getOptionsModel()->getMinimizeOnClose())
818 // close rpcConsole in case it was open to make some space for the shutdown window
821 QMainWindow::closeEvent(event);
824 void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
827 tr("This transaction is over the size limit. You can still send it for a fee of %1, "
828 "which goes to the nodes that process your transaction and helps to support the network. "
829 "Do you want to pay the fee?").arg(
830 BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nFeeRequired));
831 QMessageBox::StandardButton retval = QMessageBox::question(
832 this, tr("Confirm transaction fee"), strMessage,
833 QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes);
834 *payFee = (retval == QMessageBox::Yes);
837 void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
839 if(!walletModel || !clientModel)
841 TransactionTableModel *ttm = walletModel->getTransactionTableModel();
842 qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
843 .data(Qt::EditRole).toULongLong();
844 if(!clientModel->inInitialBlockDownload())
846 // On new transaction, make an info balloon
847 // Unless the initial block download is in progress, to prevent balloon-spam
848 QString date = ttm->index(start, TransactionTableModel::Date, parent)
850 QString type = ttm->index(start, TransactionTableModel::Type, parent)
852 QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
854 QIcon icon = qvariant_cast<QIcon>(ttm->index(start,
855 TransactionTableModel::ToAddress, parent)
856 .data(Qt::DecorationRole));
858 notificator->notify(Notificator::Information,
859 (amount)<0 ? tr("Sent transaction") :
860 tr("Incoming transaction"),
866 .arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true))
868 .arg(address), icon);
872 void BitcoinGUI::gotoOverviewPage()
874 overviewAction->setChecked(true);
875 centralWidget->setCurrentWidget(overviewPage);
877 exportAction->setEnabled(false);
878 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
881 void BitcoinGUI::gotoHistoryPage()
883 historyAction->setChecked(true);
884 centralWidget->setCurrentWidget(transactionsPage);
886 exportAction->setEnabled(true);
887 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
888 connect(exportAction, SIGNAL(triggered()), transactionView, SLOT(exportClicked()));
891 void BitcoinGUI::gotoMintingPage()
893 mintingAction->setChecked(true);
894 centralWidget->setCurrentWidget(mintingPage);
896 exportAction->setEnabled(true);
897 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
898 connect(exportAction, SIGNAL(triggered()), mintingView, SLOT(exportClicked()));
902 void BitcoinGUI::gotoAddressBookPage()
904 addressBookAction->setChecked(true);
905 centralWidget->setCurrentWidget(addressBookPage);
907 exportAction->setEnabled(true);
908 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
909 connect(exportAction, SIGNAL(triggered()), addressBookPage, SLOT(exportClicked()));
912 void BitcoinGUI::gotoReceiveCoinsPage()
914 receiveCoinsAction->setChecked(true);
915 centralWidget->setCurrentWidget(receiveCoinsPage);
917 exportAction->setEnabled(true);
918 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
919 connect(exportAction, SIGNAL(triggered()), receiveCoinsPage, SLOT(exportClicked()));
922 void BitcoinGUI::gotoSendCoinsPage()
924 sendCoinsAction->setChecked(true);
925 centralWidget->setCurrentWidget(sendCoinsPage);
927 exportAction->setEnabled(false);
928 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
931 void BitcoinGUI::gotoSignMessageTab(QString addr)
933 // call show() in showTab_SM()
934 signVerifyMessageDialog->showTab_SM(true);
937 signVerifyMessageDialog->setAddress_SM(addr);
940 void BitcoinGUI::gotoVerifyMessageTab(QString addr)
942 // call show() in showTab_VM()
943 signVerifyMessageDialog->showTab_VM(true);
946 signVerifyMessageDialog->setAddress_VM(addr);
949 void BitcoinGUI::gotoMultisigPage()
951 multisigPage->show();
952 multisigPage->setFocus();
955 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
958 if(event->mimeData()->hasUrls())
959 event->acceptProposedAction();
962 void BitcoinGUI::dropEvent(QDropEvent *event)
964 if(event->mimeData()->hasUrls())
966 int nValidUrisFound = 0;
967 QList<QUrl> uris = event->mimeData()->urls();
968 foreach(const QUrl &uri, uris)
970 if (sendCoinsPage->handleURI(uri.toString()))
974 // if valid URIs were found
978 notificator->notify(Notificator::Warning, tr("URI handling"), tr("URI can not be parsed! This can be caused by an invalid NovaCoin address or malformed URI parameters."));
981 event->acceptProposedAction();
984 void BitcoinGUI::handleURI(QString strURI)
986 // URI has to be valid
987 if (sendCoinsPage->handleURI(strURI))
989 showNormalIfMinimized();
993 notificator->notify(Notificator::Warning, tr("URI handling"), tr("URI can not be parsed! This can be caused by an invalid NovaCoin address or malformed URI parameters."));
996 void BitcoinGUI::setEncryptionStatus(int status)
1000 case WalletModel::Unencrypted:
1001 labelEncryptionIcon->hide();
1002 encryptWalletAction->setChecked(false);
1003 changePassphraseAction->setEnabled(false);
1004 lockWalletAction->setEnabled(false);
1005 unlockWalletAction->setEnabled(false);
1006 unlockWalletMiningAction->setEnabled(false);
1007 encryptWalletAction->setEnabled(true);
1009 case WalletModel::Unlocked:
1010 labelEncryptionIcon->show();
1011 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
1012 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
1013 encryptWalletAction->setChecked(true);
1014 changePassphraseAction->setEnabled(true);
1015 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
1017 lockWalletAction->setEnabled(true);
1018 lockWalletAction->setChecked(false);
1019 unlockWalletAction->setEnabled(false);
1020 unlockWalletMiningAction->setEnabled(false);
1022 if (fWalletUnlockMintOnly)
1023 unlockWalletMiningAction->setChecked(true);
1025 unlockWalletAction->setChecked(true);
1028 case WalletModel::Locked:
1029 labelEncryptionIcon->show();
1030 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
1031 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
1032 encryptWalletAction->setChecked(true);
1033 changePassphraseAction->setEnabled(true);
1034 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
1036 lockWalletAction->setChecked(true);
1037 unlockWalletAction->setChecked(false);
1038 unlockWalletMiningAction->setChecked(false);
1040 lockWalletAction->setEnabled(false);
1041 unlockWalletAction->setEnabled(true);
1042 unlockWalletMiningAction->setEnabled(true);
1047 void BitcoinGUI::encryptWallet(bool status)
1051 AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt:
1052 AskPassphraseDialog::Decrypt, this);
1053 dlg.setModel(walletModel);
1056 setEncryptionStatus(walletModel->getEncryptionStatus());
1059 void BitcoinGUI::unlockWalletMining(bool status)
1064 // Unlock wallet when requested by wallet model
1065 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1067 AskPassphraseDialog dlg(AskPassphraseDialog::UnlockMining, this);
1068 dlg.setModel(walletModel);
1073 void BitcoinGUI::backupWallet()
1075 #if QT_VERSION < 0x050000
1076 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1078 QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1080 QString filename = QFileDialog::getSaveFileName(this, tr("Backup Wallet"), saveDir, tr("Wallet Data (*.dat)"));
1081 if(!filename.isEmpty()) {
1082 if(!walletModel->backupWallet(filename)) {
1083 QMessageBox::warning(this, tr("Backup Failed"), tr("There was an error trying to save the wallet data to the new location."));
1088 void BitcoinGUI::dumpWallet()
1093 WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1096 // Unlock wallet failed or was cancelled
1100 #if QT_VERSION < 0x050000
1101 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1103 QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1105 QString filename = QFileDialog::getSaveFileName(this, tr("Dump Wallet"), saveDir, tr("Wallet dump (*.txt)"));
1106 if(!filename.isEmpty()) {
1107 if(!walletModel->dumpWallet(filename)) {
1108 error(tr("Dump failed"),
1109 tr("An error happened while trying to save the keys to your location.\n"
1110 "Keys were not saved.")
1111 ,CClientUIInterface::MSG_ERROR);
1114 message(tr("Dump successful"),
1115 tr("Keys were saved to this file:\n%2")
1117 ,CClientUIInterface::MSG_INFORMATION);
1121 void BitcoinGUI::importWallet()
1126 WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1129 // Unlock wallet failed or was cancelled
1133 #if QT_VERSION < 0x050000
1134 QString openDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1136 QString openDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1138 QString filename = QFileDialog::getOpenFileName(this, tr("Import Wallet"), openDir, tr("Wallet dump (*.txt)"));
1139 if(!filename.isEmpty()) {
1140 if(!walletModel->importWallet(filename)) {
1141 error(tr("Import Failed"),
1142 tr("An error happened while trying to import the keys.\n"
1143 "Some or all keys from:\n %1,\n were not imported into your wallet.")
1145 ,CClientUIInterface::MSG_ERROR);
1148 message(tr("Import Successful"),
1149 tr("All keys from:\n %1,\n were imported into your wallet.")
1151 ,CClientUIInterface::MSG_INFORMATION);
1156 void BitcoinGUI::changePassphrase()
1158 AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
1159 dlg.setModel(walletModel);
1163 void BitcoinGUI::unlockWallet()
1167 // Unlock wallet when requested by wallet model
1168 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1170 AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
1171 dlg.setModel(walletModel);
1176 void BitcoinGUI::lockWallet()
1181 walletModel->setWalletLocked(true);
1184 void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden)
1186 // activateWindow() (sometimes) helps with keyboard focus on Windows
1189 // Make sure the window is not minimized
1190 setWindowState(windowState() & (~Qt::WindowMinimized | Qt::WindowActive));
1196 else if (isMinimized())
1202 else if (GUIUtil::isObscured(this))
1209 if (GUIUtil::isObscured(this))
1213 else if(fToggleHidden)
1217 void BitcoinGUI::toggleHidden()
1219 showNormalIfMinimized(true);