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),
89 setWindowTitle(tr("NovaCoin") + " - " + tr("Wallet"));
91 qApp->setWindowIcon(QIcon(":icons/bitcoin"));
92 setWindowIcon(QIcon(":icons/bitcoin"));
94 setUnifiedTitleAndToolBarOnMac(true);
95 QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
100 // Create actions for the toolbar, menu bar and tray/dock icon
103 // Create application menu bar
106 // Create the toolbars
109 // Create the tray icon (or setup the dock icon)
113 overviewPage = new OverviewPage();
115 transactionsPage = new QWidget(this);
116 QVBoxLayout *vbox = new QVBoxLayout();
117 transactionView = new TransactionView(this);
118 vbox->addWidget(transactionView);
119 transactionsPage->setLayout(vbox);
121 mintingPage = new QWidget(this);
122 QVBoxLayout *vboxMinting = new QVBoxLayout();
123 mintingView = new MintingView(this);
124 vboxMinting->addWidget(mintingView);
125 mintingPage->setLayout(vboxMinting);
127 addressBookPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::SendingTab);
129 receiveCoinsPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::ReceivingTab);
131 sendCoinsPage = new SendCoinsDialog(this);
133 signVerifyMessageDialog = new SignVerifyMessageDialog(this);
135 multisigPage = new MultisigDialog(this);
137 centralWidget = new QStackedWidget(this);
138 centralWidget->addWidget(overviewPage);
139 centralWidget->addWidget(transactionsPage);
140 centralWidget->addWidget(mintingPage);
141 centralWidget->addWidget(addressBookPage);
142 centralWidget->addWidget(receiveCoinsPage);
143 centralWidget->addWidget(sendCoinsPage);
144 setCentralWidget(centralWidget);
149 // Status bar notification icons
150 QFrame *frameBlocks = new QFrame();
151 frameBlocks->setContentsMargins(0,0,0,0);
152 frameBlocks->setMinimumWidth(72);
153 frameBlocks->setMaximumWidth(72);
154 QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);
155 frameBlocksLayout->setContentsMargins(3,0,3,0);
156 frameBlocksLayout->setSpacing(3);
157 labelEncryptionIcon = new QLabel();
158 labelMiningIcon = new QLabel();
159 labelConnectionsIcon = new QLabel();
160 labelBlocksIcon = new QLabel();
161 frameBlocksLayout->addStretch();
162 frameBlocksLayout->addWidget(labelEncryptionIcon);
163 frameBlocksLayout->addStretch();
164 frameBlocksLayout->addWidget(labelMiningIcon);
165 frameBlocksLayout->addStretch();
166 frameBlocksLayout->addWidget(labelConnectionsIcon);
167 frameBlocksLayout->addStretch();
168 frameBlocksLayout->addWidget(labelBlocksIcon);
169 frameBlocksLayout->addStretch();
171 // Progress bar and label for blocks download
172 progressBarLabel = new QLabel();
173 progressBarLabel->setVisible(false);
174 progressBar = new QProgressBar();
175 progressBar->setAlignment(Qt::AlignCenter);
176 progressBar->setVisible(false);
178 // Override style sheet for progress bar for styles that have a segmented progress bar,
179 // as they make the text unreadable (workaround for issue #1071)
180 // See https://qt-project.org/doc/qt-4.8/gallery.html
181 QString curStyle = qApp->style()->metaObject()->className();
182 if(curStyle == "QWindowsStyle" || curStyle == "QWindowsXPStyle")
184 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; }");
187 statusBar()->addWidget(progressBarLabel);
188 statusBar()->addWidget(progressBar);
189 statusBar()->addPermanentWidget(frameBlocks);
191 syncIconMovie = new QMovie(":/movies/update_spinner", "mng", this);
193 // Clicking on a transaction on the overview page simply sends you to transaction history page
194 connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), this, SLOT(gotoHistoryPage()));
195 connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex)));
197 // Double-clicking on a transaction on the transaction history page shows details
198 connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
200 rpcConsole = new RPCConsole(0);
201 connect(openRPCConsoleAction, SIGNAL(triggered()), rpcConsole, SLOT(show()));
203 // Clicking on "Verify Message" in the address book sends you to the verify message tab
204 connect(addressBookPage, SIGNAL(verifyMessage(QString)), this, SLOT(gotoVerifyMessageTab(QString)));
205 // Clicking on "Sign Message" in the receive coins page sends you to the sign message tab
206 connect(receiveCoinsPage, SIGNAL(signMessage(QString)), this, SLOT(gotoSignMessageTab(QString)));
211 BitcoinGUI::~BitcoinGUI()
213 if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu)
222 void BitcoinGUI::createActions()
224 QActionGroup *tabGroup = new QActionGroup(this);
226 overviewAction = new QAction(QIcon(":/icons/overview"), tr("&Overview"), this);
227 overviewAction->setToolTip(tr("Show general overview of wallet"));
228 overviewAction->setCheckable(true);
229 overviewAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_1));
230 tabGroup->addAction(overviewAction);
232 sendCoinsAction = new QAction(QIcon(":/icons/send"), tr("&Send coins"), this);
233 sendCoinsAction->setToolTip(tr("Send coins to a NovaCoin address"));
234 sendCoinsAction->setCheckable(true);
235 sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2));
236 tabGroup->addAction(sendCoinsAction);
238 receiveCoinsAction = new QAction(QIcon(":/icons/receiving_addresses"), tr("&Receive coins"), this);
239 receiveCoinsAction->setToolTip(tr("Show the list of addresses for receiving payments"));
240 receiveCoinsAction->setCheckable(true);
241 receiveCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_3));
242 tabGroup->addAction(receiveCoinsAction);
244 historyAction = new QAction(QIcon(":/icons/history"), tr("&Transactions"), this);
245 historyAction->setToolTip(tr("Browse transaction history"));
246 historyAction->setCheckable(true);
247 historyAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_4));
248 tabGroup->addAction(historyAction);
250 mintingAction = new QAction(QIcon(":/icons/history"), tr("&Minting"), this);
251 mintingAction->setToolTip(tr("Show your minting capacity"));
252 mintingAction->setCheckable(true);
253 mintingAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_5));
254 tabGroup->addAction(mintingAction);
256 addressBookAction = new QAction(QIcon(":/icons/address-book"), tr("&Address Book"), this);
257 addressBookAction->setToolTip(tr("Edit the list of stored addresses and labels"));
258 addressBookAction->setCheckable(true);
259 addressBookAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_6));
260 tabGroup->addAction(addressBookAction);
262 multisigAction = new QAction(QIcon(":/icons/send"), tr("Multisig"), this);
263 tabGroup->addAction(multisigAction);
265 connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
266 connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage()));
267 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
268 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
269 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
270 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
271 connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
272 connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage()));
273 connect(mintingAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
274 connect(mintingAction, SIGNAL(triggered()), this, SLOT(gotoMintingPage()));
275 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
276 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(gotoAddressBookPage()));
277 connect(multisigAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
278 connect(multisigAction, SIGNAL(triggered()), this, SLOT(gotoMultisigPage()));
280 quitAction = new QAction(QIcon(":/icons/quit"), tr("E&xit"), this);
281 quitAction->setToolTip(tr("Quit application"));
282 quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
283 quitAction->setMenuRole(QAction::QuitRole);
284 aboutAction = new QAction(QIcon(":/icons/bitcoin"), tr("&About NovaCoin"), this);
285 aboutAction->setToolTip(tr("Show information about NovaCoin"));
286 aboutAction->setMenuRole(QAction::AboutRole);
287 #if QT_VERSION < 0x050000
288 aboutQtAction = new QAction(QIcon(":/trolltech/qmessagebox/images/qtlogo-64.png"), tr("About &Qt"), this);
290 aboutQtAction = new QAction(QIcon(":/qt-project.org/qmessagebox/images/qtlogo-64.png"), tr("About &Qt"), this);
292 aboutQtAction->setToolTip(tr("Show information about Qt"));
293 aboutQtAction->setMenuRole(QAction::AboutQtRole);
294 optionsAction = new QAction(QIcon(":/icons/options"), tr("&Options..."), this);
295 optionsAction->setToolTip(tr("Modify configuration options for NovaCoin"));
296 optionsAction->setMenuRole(QAction::PreferencesRole);
297 toggleHideAction = new QAction(QIcon(":/icons/bitcoin"), tr("&Show / Hide"), this);
298 encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet..."), this);
299 encryptWalletAction->setToolTip(tr("Encrypt or decrypt wallet"));
300 encryptWalletAction->setCheckable(true);
301 backupWalletAction = new QAction(QIcon(":/icons/filesave"), tr("&Backup Wallet..."), this);
302 backupWalletAction->setToolTip(tr("Backup wallet to another location"));
303 dumpWalletAction = new QAction(QIcon(":/icons/dump"), tr("&Dump Wallet..."), this);
304 dumpWalletAction->setStatusTip(tr("Dump keys to a text file"));
305 importWalletAction = new QAction(QIcon(":/icons/import"), tr("&Import Wallet..."), this);
306 importWalletAction->setStatusTip(tr("Import keys into a wallet"));
307 changePassphraseAction = new QAction(QIcon(":/icons/key"), tr("&Change Passphrase..."), this);
308 changePassphraseAction->setToolTip(tr("Change the passphrase used for wallet encryption"));
309 signMessageAction = new QAction(QIcon(":/icons/edit"), tr("Sign &message..."), this);
310 verifyMessageAction = new QAction(QIcon(":/icons/transaction_0"), tr("&Verify message..."), this);
312 lockWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Lock wallet"), this);
313 lockWalletAction->setToolTip(tr("Lock wallet"));
314 lockWalletAction->setCheckable(true);
316 unlockWalletAction = new QAction(QIcon(":/icons/lock_open"), tr("Unlo&ck wallet"), this);
317 unlockWalletAction->setToolTip(tr("Unlock wallet"));
318 unlockWalletAction->setCheckable(true);
320 unlockWalletMiningAction = new QAction(QIcon(":/icons/mining_active"), tr("Unlo&ck wallet for mining"), this);
321 unlockWalletMiningAction->setToolTip(tr("Unlock wallet for mining"));
322 unlockWalletMiningAction->setCheckable(true);
324 exportAction = new QAction(QIcon(":/icons/export"), tr("&Export..."), this);
325 exportAction->setToolTip(tr("Export the data in the current tab to a file"));
326 openRPCConsoleAction = new QAction(QIcon(":/icons/debugwindow"), tr("&Debug window"), this);
327 openRPCConsoleAction->setToolTip(tr("Open debugging and diagnostic console"));
329 connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
330 connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked()));
331 connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
332 connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked()));
333 connect(toggleHideAction, SIGNAL(triggered()), this, SLOT(toggleHidden()));
334 connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool)));
335 connect(lockWalletAction, SIGNAL(triggered(bool)), this, SLOT(lockWallet()));
336 connect(unlockWalletAction, SIGNAL(triggered(bool)), this, SLOT(unlockWallet()));
337 connect(unlockWalletMiningAction, SIGNAL(triggered(bool)), this, SLOT(unlockWalletMining(bool)));
338 connect(backupWalletAction, SIGNAL(triggered()), this, SLOT(backupWallet()));
339 connect(dumpWalletAction, SIGNAL(triggered()), this, SLOT(dumpWallet()));
340 connect(importWalletAction, SIGNAL(triggered()), this, SLOT(importWallet()));
341 connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase()));
342 connect(signMessageAction, SIGNAL(triggered()), this, SLOT(gotoSignMessageTab()));
343 connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(gotoVerifyMessageTab()));
346 void BitcoinGUI::createMenuBar()
349 // Create a decoupled menu bar on Mac which stays even if the window is closed
350 appMenuBar = new QMenuBar();
352 // Get the main window's menu bar on other platforms
353 appMenuBar = menuBar();
356 // Configure the menus
357 QMenu *file = appMenuBar->addMenu(tr("&File"));
358 file->addAction(backupWalletAction);
359 file->addSeparator();
360 file->addAction(dumpWalletAction);
361 file->addAction(importWalletAction);
362 file->addAction(exportAction);
363 file->addAction(signMessageAction);
364 file->addAction(verifyMessageAction);
365 file->addAction(multisigAction);
366 file->addSeparator();
367 file->addAction(quitAction);
369 QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
370 QMenu *securityMenu = settings->addMenu(QIcon(":/icons/key"), tr("&Wallet security"));
371 securityMenu->addAction(encryptWalletAction);
372 securityMenu->addAction(changePassphraseAction);
373 securityMenu->addAction(unlockWalletAction);
374 securityMenu->addAction(unlockWalletMiningAction);
375 securityMenu->addAction(lockWalletAction);
376 settings->addAction(optionsAction);
378 QMenu *help = appMenuBar->addMenu(tr("&Help"));
379 help->addAction(openRPCConsoleAction);
380 help->addSeparator();
381 help->addAction(aboutAction);
382 help->addAction(aboutQtAction);
385 void BitcoinGUI::createToolBars()
387 QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));
388 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
389 toolbar->addAction(overviewAction);
390 toolbar->addAction(sendCoinsAction);
391 toolbar->addAction(receiveCoinsAction);
392 toolbar->addAction(historyAction);
393 toolbar->addAction(mintingAction);
394 toolbar->addAction(addressBookAction);
396 QToolBar *toolbar2 = addToolBar(tr("Actions toolbar"));
397 toolbar2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
398 toolbar2->addAction(exportAction);
399 toolbar2->setVisible(false);
403 void BitcoinGUI::setClientModel(ClientModel *clientModel)
405 this->clientModel = clientModel;
408 // Replace some strings and icons, when using the testnet
409 if(clientModel->isTestNet())
411 setWindowTitle(windowTitle() + QString(" ") + tr("[testnet]"));
413 qApp->setWindowIcon(QIcon(":icons/bitcoin_testnet"));
414 setWindowIcon(QIcon(":icons/bitcoin_testnet"));
416 MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
420 trayIcon->setToolTip(tr("NovaCoin client") + QString(" ") + tr("[testnet]"));
421 trayIcon->setIcon(QIcon(":/icons/toolbar_testnet"));
422 toggleHideAction->setIcon(QIcon(":/icons/toolbar_testnet"));
425 aboutAction->setIcon(QIcon(":/icons/toolbar_testnet"));
428 // Keep up to date with client
429 setNumConnections(clientModel->getNumConnections());
430 connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
432 setNumBlocks(clientModel->getNumBlocks(), clientModel->getNumBlocksOfPeers());
433 connect(clientModel, SIGNAL(numBlocksChanged(int,int)), this, SLOT(setNumBlocks(int,int)));
435 QTimer *timer = new QTimer(this);
436 connect(timer, SIGNAL(timeout()), this, SLOT(updateMining()));
437 timer->start(10*1000); //10 seconds
439 // Report errors from network/worker thread
440 connect(clientModel, SIGNAL(error(QString,QString,bool)), this, SLOT(error(QString,QString,bool)));
442 rpcConsole->setClientModel(clientModel);
443 addressBookPage->setOptionsModel(clientModel->getOptionsModel());
444 receiveCoinsPage->setOptionsModel(clientModel->getOptionsModel());
448 void BitcoinGUI::setWalletModel(WalletModel *walletModel)
450 this->walletModel = walletModel;
453 // Report errors from wallet thread
454 connect(walletModel, SIGNAL(error(QString,QString,bool)), this, SLOT(error(QString,QString,bool)));
456 // Put transaction list in tabs
457 transactionView->setModel(walletModel);
458 mintingView->setModel(walletModel);
460 overviewPage->setModel(walletModel);
461 addressBookPage->setModel(walletModel->getAddressTableModel());
462 receiveCoinsPage->setModel(walletModel->getAddressTableModel());
463 sendCoinsPage->setModel(walletModel);
464 signVerifyMessageDialog->setModel(walletModel);
465 multisigPage->setModel(walletModel);
467 setEncryptionStatus(walletModel->getEncryptionStatus());
468 connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));
469 connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(updateMining()));
471 // Balloon pop-up for new transaction
472 connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
473 this, SLOT(incomingTransaction(QModelIndex,int,int)));
475 // Ask for passphrase if needed
476 connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
480 void BitcoinGUI::createTrayIcon()
484 trayIcon = new QSystemTrayIcon(this);
485 trayIconMenu = new QMenu(this);
486 trayIcon->setContextMenu(trayIconMenu);
487 trayIcon->setToolTip(tr("NovaCoin client"));
488 trayIcon->setIcon(QIcon(":/icons/toolbar"));
489 connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
490 this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
493 // Note: On Mac, the dock icon is used to provide the tray's functionality.
494 MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance();
495 dockIconHandler->setMainWindow((QMainWindow *)this);
496 trayIconMenu = dockIconHandler->dockMenu();
499 // Configuration of the tray icon (or dock icon) icon menu
500 trayIconMenu->addAction(toggleHideAction);
501 trayIconMenu->addSeparator();
502 trayIconMenu->addAction(sendCoinsAction);
503 trayIconMenu->addAction(multisigAction);
504 trayIconMenu->addAction(receiveCoinsAction);
505 trayIconMenu->addSeparator();
506 trayIconMenu->addAction(signMessageAction);
507 trayIconMenu->addAction(verifyMessageAction);
508 trayIconMenu->addSeparator();
509 trayIconMenu->addAction(optionsAction);
510 trayIconMenu->addAction(openRPCConsoleAction);
512 // This is built-in on Mac
513 trayIconMenu->addSeparator();
514 trayIconMenu->addAction(quitAction);
516 notificator = new Notificator(QApplication::applicationName(), trayIcon, this);
520 void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
522 if(reason == QSystemTrayIcon::Trigger)
524 // Click on system tray icon triggers show/hide of the main window
525 toggleHideAction->trigger();
530 void BitcoinGUI::optionsClicked()
532 if(!clientModel || !clientModel->getOptionsModel())
535 dlg.setModel(clientModel->getOptionsModel());
539 void BitcoinGUI::aboutClicked()
542 dlg.setModel(clientModel);
546 void BitcoinGUI::setNumConnections(int count)
551 case 0: icon = ":/icons/connect_0"; break;
552 case 1: case 2: case 3: icon = ":/icons/connect_1"; break;
553 case 4: case 5: case 6: icon = ":/icons/connect_2"; break;
554 case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
555 default: icon = ":/icons/connect_4"; break;
557 labelConnectionsIcon->setPixmap(QIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
558 labelConnectionsIcon->setToolTip(tr("%n active connection(s) to NovaCoin network", "", count));
561 void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks)
563 // don't show / hide progress bar and its label if we have no connection to the network
564 if (!clientModel || clientModel->getNumConnections() == 0)
566 progressBarLabel->setVisible(false);
567 progressBar->setVisible(false);
572 QString strStatusBarWarnings = clientModel->getStatusBarWarnings();
575 if(count < nTotalBlocks)
577 int nRemainingBlocks = nTotalBlocks - count;
578 float nPercentageDone = count / (nTotalBlocks * 0.01f);
580 if (strStatusBarWarnings.isEmpty())
582 progressBarLabel->setText(tr("Synchronizing with network..."));
583 progressBarLabel->setVisible(true);
584 progressBar->setFormat(tr("~%n block(s) remaining", "", nRemainingBlocks));
585 progressBar->setMaximum(nTotalBlocks);
586 progressBar->setValue(count);
587 progressBar->setVisible(true);
590 tooltip = tr("Downloaded %1 of %2 blocks of transaction history (%3% done).").arg(count).arg(nTotalBlocks).arg(nPercentageDone, 0, 'f', 2);
594 if (strStatusBarWarnings.isEmpty())
595 progressBarLabel->setVisible(false);
597 progressBar->setVisible(false);
598 tooltip = tr("Downloaded %1 blocks of transaction history.").arg(count);
601 // Override progressBarLabel text and hide progress bar, when we have warnings to display
602 if (!strStatusBarWarnings.isEmpty())
604 progressBarLabel->setText(strStatusBarWarnings);
605 progressBarLabel->setVisible(true);
606 progressBar->setVisible(false);
609 QDateTime lastBlockDate = clientModel->getLastBlockDate();
610 int secs = lastBlockDate.secsTo(QDateTime::currentDateTime());
613 // Represent time from last generated block in human readable text
616 // Fully up to date. Leave text empty.
620 text = tr("%n second(s) ago","",secs);
622 else if(secs < 60*60)
624 text = tr("%n minute(s) ago","",secs/60);
626 else if(secs < 24*60*60)
628 text = tr("%n hour(s) ago","",secs/(60*60));
632 text = tr("%n day(s) ago","",secs/(60*60*24));
635 // Set icon state: spinning if catching up, tick otherwise
636 if(secs < 90*60 && count >= nTotalBlocks)
638 tooltip = tr("Up to date") + QString(".<br>") + tooltip;
639 labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
641 overviewPage->showOutOfSyncWarning(false);
645 tooltip = tr("Catching up...") + QString("<br>") + tooltip;
646 labelBlocksIcon->setMovie(syncIconMovie);
647 syncIconMovie->start();
649 overviewPage->showOutOfSyncWarning(true);
654 tooltip += QString("<br>");
655 tooltip += tr("Last received block was generated %1.").arg(text);
658 // Don't word-wrap this (fixed-width) tooltip
659 tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
661 labelBlocksIcon->setToolTip(tooltip);
662 progressBarLabel->setToolTip(tooltip);
663 progressBar->setToolTip(tooltip);
666 void BitcoinGUI::updateMining()
671 labelMiningIcon->setPixmap(QIcon(":/icons/mining_inactive").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
673 if (!clientModel->getNumConnections())
675 labelMiningIcon->setToolTip(tr("Wallet is offline"));
679 if (walletModel->getEncryptionStatus() == WalletModel::Locked)
681 labelMiningIcon->setToolTip(tr("Wallet is locked"));
685 if (clientModel->inInitialBlockDownload() || clientModel->getNumBlocksOfPeers() > clientModel->getNumBlocks())
687 labelMiningIcon->setToolTip(tr("Blockchain download is in progress"));
691 float nKernelsRate = 0, nCoinDaysRate = 0;
692 walletModel->getStakeStats(nKernelsRate, nCoinDaysRate);
694 if (nKernelsRate > 0)
696 labelMiningIcon->setPixmap(QIcon(":/icons/mining_active").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
698 uint64_t nNetworkWeight = clientModel->getPoSKernelPS();
700 double dDifficulty = clientModel->getDifficulty(true);
703 int nApproxTime = 4294967297 * dDifficulty / nTotalWeight;
705 if (nApproxTime < 60)
706 msg = tr("%n second(s)", "", nApproxTime);
707 else if (nApproxTime < 60*60)
708 msg = tr("%n minute(s)", "", nApproxTime / 60);
709 else if (nApproxTime < 24*60*60)
710 msg = tr("%n hour(s)", "", nApproxTime / 3600);
712 msg = tr("%n day(s)", "", nApproxTime / 86400);
714 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));
717 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>"));
720 labelMiningIcon->setToolTip(tr("No suitable inputs were found"));
723 void BitcoinGUI::error(const QString &title, const QString &message, bool modal)
725 // Report errors from network/worker thread
728 QMessageBox::critical(this, title, message, QMessageBox::Ok, QMessageBox::Ok);
730 notificator->notify(Notificator::Critical, title, message);
734 void BitcoinGUI::message(const QString &title, const QString &message, unsigned int style, const QString &detail)
736 QString strTitle = tr("NovaCoin") + " - ";
737 // Default to information icon
738 int nMBoxIcon = QMessageBox::Information;
739 int nNotifyIcon = Notificator::Information;
742 // Check for usage of predefined title
744 case CClientUIInterface::MSG_ERROR:
745 strTitle += tr("Error");
747 case CClientUIInterface::MSG_WARNING:
748 strTitle += tr("Warning");
750 case CClientUIInterface::MSG_INFORMATION:
751 strTitle += tr("Information");
754 strTitle += title; // Use supplied title
757 // Check for error/warning icon
758 if (style & CClientUIInterface::ICON_ERROR) {
759 nMBoxIcon = QMessageBox::Critical;
760 nNotifyIcon = Notificator::Critical;
762 else if (style & CClientUIInterface::ICON_WARNING) {
763 nMBoxIcon = QMessageBox::Warning;
764 nNotifyIcon = Notificator::Warning;
768 if (style & CClientUIInterface::MODAL) {
769 // Check for buttons, use OK as default, if none was supplied
770 QMessageBox::StandardButton buttons;
771 buttons = QMessageBox::Ok;
773 QMessageBox mBox((QMessageBox::Icon)nMBoxIcon, strTitle, message, buttons);
775 if(!detail.isEmpty()) { mBox.setDetailedText(detail); }
780 notificator->notify((Notificator::Class)nNotifyIcon, strTitle, message);
784 void BitcoinGUI::changeEvent(QEvent *e)
786 QMainWindow::changeEvent(e);
787 #ifndef Q_OS_MAC // Ignored on Mac
788 if(e->type() == QEvent::WindowStateChange)
790 if(clientModel && clientModel->getOptionsModel()->getMinimizeToTray())
792 QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
793 if(!(wsevt->oldState() & Qt::WindowMinimized) && isMinimized())
795 QTimer::singleShot(0, this, SLOT(hide()));
803 void BitcoinGUI::closeEvent(QCloseEvent *event)
807 #ifndef Q_OS_MAC // Ignored on Mac
808 if(!clientModel->getOptionsModel()->getMinimizeOnClose())
814 // close rpcConsole in case it was open to make some space for the shutdown window
817 QMainWindow::closeEvent(event);
820 void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
823 tr("This transaction is over the size limit. You can still send it for a fee of %1, "
824 "which goes to the nodes that process your transaction and helps to support the network. "
825 "Do you want to pay the fee?").arg(
826 BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nFeeRequired));
827 QMessageBox::StandardButton retval = QMessageBox::question(
828 this, tr("Confirm transaction fee"), strMessage,
829 QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes);
830 *payFee = (retval == QMessageBox::Yes);
833 void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
835 if(!walletModel || !clientModel)
837 TransactionTableModel *ttm = walletModel->getTransactionTableModel();
838 qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
839 .data(Qt::EditRole).toULongLong();
840 if(!clientModel->inInitialBlockDownload())
842 // On new transaction, make an info balloon
843 // Unless the initial block download is in progress, to prevent balloon-spam
844 QString date = ttm->index(start, TransactionTableModel::Date, parent)
846 QString type = ttm->index(start, TransactionTableModel::Type, parent)
848 QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
850 QIcon icon = qvariant_cast<QIcon>(ttm->index(start,
851 TransactionTableModel::ToAddress, parent)
852 .data(Qt::DecorationRole));
854 notificator->notify(Notificator::Information,
855 (amount)<0 ? tr("Sent transaction") :
856 tr("Incoming transaction"),
862 .arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true))
864 .arg(address), icon);
868 void BitcoinGUI::gotoOverviewPage()
870 overviewAction->setChecked(true);
871 centralWidget->setCurrentWidget(overviewPage);
873 exportAction->setEnabled(false);
874 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
877 void BitcoinGUI::gotoHistoryPage()
879 historyAction->setChecked(true);
880 centralWidget->setCurrentWidget(transactionsPage);
882 exportAction->setEnabled(true);
883 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
884 connect(exportAction, SIGNAL(triggered()), transactionView, SLOT(exportClicked()));
887 void BitcoinGUI::gotoMintingPage()
889 mintingAction->setChecked(true);
890 centralWidget->setCurrentWidget(mintingPage);
892 exportAction->setEnabled(true);
893 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
894 connect(exportAction, SIGNAL(triggered()), mintingView, SLOT(exportClicked()));
898 void BitcoinGUI::gotoAddressBookPage()
900 addressBookAction->setChecked(true);
901 centralWidget->setCurrentWidget(addressBookPage);
903 exportAction->setEnabled(true);
904 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
905 connect(exportAction, SIGNAL(triggered()), addressBookPage, SLOT(exportClicked()));
908 void BitcoinGUI::gotoReceiveCoinsPage()
910 receiveCoinsAction->setChecked(true);
911 centralWidget->setCurrentWidget(receiveCoinsPage);
913 exportAction->setEnabled(true);
914 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
915 connect(exportAction, SIGNAL(triggered()), receiveCoinsPage, SLOT(exportClicked()));
918 void BitcoinGUI::gotoSendCoinsPage()
920 sendCoinsAction->setChecked(true);
921 centralWidget->setCurrentWidget(sendCoinsPage);
923 exportAction->setEnabled(false);
924 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
927 void BitcoinGUI::gotoSignMessageTab(QString addr)
929 // call show() in showTab_SM()
930 signVerifyMessageDialog->showTab_SM(true);
933 signVerifyMessageDialog->setAddress_SM(addr);
936 void BitcoinGUI::gotoVerifyMessageTab(QString addr)
938 // call show() in showTab_VM()
939 signVerifyMessageDialog->showTab_VM(true);
942 signVerifyMessageDialog->setAddress_VM(addr);
945 void BitcoinGUI::gotoMultisigPage()
947 multisigPage->show();
948 multisigPage->setFocus();
951 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
954 if(event->mimeData()->hasUrls())
955 event->acceptProposedAction();
958 void BitcoinGUI::dropEvent(QDropEvent *event)
960 if(event->mimeData()->hasUrls())
962 int nValidUrisFound = 0;
963 QList<QUrl> uris = event->mimeData()->urls();
964 foreach(const QUrl &uri, uris)
966 if (sendCoinsPage->handleURI(uri.toString()))
970 // if valid URIs were found
974 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."));
977 event->acceptProposedAction();
980 void BitcoinGUI::handleURI(QString strURI)
982 // URI has to be valid
983 if (sendCoinsPage->handleURI(strURI))
985 showNormalIfMinimized();
989 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."));
992 void BitcoinGUI::setEncryptionStatus(int status)
996 case WalletModel::Unencrypted:
997 labelEncryptionIcon->hide();
998 encryptWalletAction->setChecked(false);
999 changePassphraseAction->setEnabled(false);
1000 lockWalletAction->setEnabled(false);
1001 unlockWalletAction->setEnabled(false);
1002 unlockWalletMiningAction->setEnabled(false);
1003 encryptWalletAction->setEnabled(true);
1005 case WalletModel::Unlocked:
1006 labelEncryptionIcon->show();
1007 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
1008 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
1009 encryptWalletAction->setChecked(true);
1010 changePassphraseAction->setEnabled(true);
1011 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
1013 lockWalletAction->setEnabled(true);
1014 lockWalletAction->setChecked(false);
1015 unlockWalletAction->setEnabled(false);
1016 unlockWalletMiningAction->setEnabled(false);
1018 if (fWalletUnlockMintOnly)
1019 unlockWalletMiningAction->setChecked(true);
1021 unlockWalletAction->setChecked(true);
1024 case WalletModel::Locked:
1025 labelEncryptionIcon->show();
1026 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
1027 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
1028 encryptWalletAction->setChecked(true);
1029 changePassphraseAction->setEnabled(true);
1030 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
1032 lockWalletAction->setChecked(true);
1033 unlockWalletAction->setChecked(false);
1034 unlockWalletMiningAction->setChecked(false);
1036 lockWalletAction->setEnabled(false);
1037 unlockWalletAction->setEnabled(true);
1038 unlockWalletMiningAction->setEnabled(true);
1043 void BitcoinGUI::encryptWallet(bool status)
1047 AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt:
1048 AskPassphraseDialog::Decrypt, this);
1049 dlg.setModel(walletModel);
1052 setEncryptionStatus(walletModel->getEncryptionStatus());
1055 void BitcoinGUI::unlockWalletMining(bool status)
1060 // Unlock wallet when requested by wallet model
1061 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1063 AskPassphraseDialog dlg(AskPassphraseDialog::UnlockMining, this);
1064 dlg.setModel(walletModel);
1069 void BitcoinGUI::backupWallet()
1071 #if QT_VERSION < 0x050000
1072 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1074 QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1076 QString filename = QFileDialog::getSaveFileName(this, tr("Backup Wallet"), saveDir, tr("Wallet Data (*.dat)"));
1077 if(!filename.isEmpty()) {
1078 if(!walletModel->backupWallet(filename)) {
1079 QMessageBox::warning(this, tr("Backup Failed"), tr("There was an error trying to save the wallet data to the new location."));
1084 void BitcoinGUI::dumpWallet()
1089 WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1092 // Unlock wallet failed or was cancelled
1096 #if QT_VERSION < 0x050000
1097 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1099 QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1101 QString filename = QFileDialog::getSaveFileName(this, tr("Dump Wallet"), saveDir, tr("Wallet dump (*.txt)"));
1102 if(!filename.isEmpty()) {
1103 if(!walletModel->dumpWallet(filename)) {
1104 error(tr("Dump failed"),
1105 tr("An error happened while trying to save the keys to your location.\n"
1106 "Keys were not saved.")
1107 ,CClientUIInterface::MSG_ERROR);
1110 message(tr("Dump successful"),
1111 tr("Keys were saved to this file:\n%2")
1113 ,CClientUIInterface::MSG_INFORMATION);
1117 void BitcoinGUI::importWallet()
1122 WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1125 // Unlock wallet failed or was cancelled
1129 #if QT_VERSION < 0x050000
1130 QString openDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1132 QString openDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1134 QString filename = QFileDialog::getOpenFileName(this, tr("Import Wallet"), openDir, tr("Wallet dump (*.txt)"));
1135 if(!filename.isEmpty()) {
1136 if(!walletModel->importWallet(filename)) {
1137 error(tr("Import Failed"),
1138 tr("An error happened while trying to import the keys.\n"
1139 "Some or all keys from:\n %1,\n were not imported into your wallet.")
1141 ,CClientUIInterface::MSG_ERROR);
1144 message(tr("Import Successful"),
1145 tr("All keys from:\n %1,\n were imported into your wallet.")
1147 ,CClientUIInterface::MSG_INFORMATION);
1152 void BitcoinGUI::changePassphrase()
1154 AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
1155 dlg.setModel(walletModel);
1159 void BitcoinGUI::unlockWallet()
1163 // Unlock wallet when requested by wallet model
1164 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1166 AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
1167 dlg.setModel(walletModel);
1172 void BitcoinGUI::lockWallet()
1177 walletModel->setWalletLocked(true);
1180 void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden)
1182 // activateWindow() (sometimes) helps with keyboard focus on Windows
1185 // Make sure the window is not minimized
1186 setWindowState(windowState() & (~Qt::WindowMinimized | Qt::WindowActive));
1192 else if (isMinimized())
1198 else if (GUIUtil::isObscured(this))
1205 if (GUIUtil::isObscured(this))
1209 else if(fToggleHidden)
1213 void BitcoinGUI::toggleHidden()
1215 showNormalIfMinimized(true);