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 "optionsdialog.h"
13 #include "aboutdialog.h"
14 #include "clientmodel.h"
15 #include "walletmodel.h"
16 #include "editaddressdialog.h"
17 #include "optionsmodel.h"
18 #include "transactiondescdialog.h"
19 #include "addresstablemodel.h"
20 #include "transactionview.h"
21 #include "overviewpage.h"
22 #include "bitcoinunits.h"
23 #include "guiconstants.h"
24 #include "askpassphrasedialog.h"
25 #include "notificator.h"
27 #include "ui_interface.h"
28 #include "rpcconsole.h"
29 #include "mintingview.h"
32 #include "macdockiconhandler.h"
35 #include <QApplication>
36 #if QT_VERSION < 0x050000
37 #include <QMainWindow>
43 #include <QVBoxLayout>
48 #include <QPushButton>
50 #include <QMessageBox>
51 #include <QProgressBar>
52 #include <QStackedWidget>
55 #include <QFileDialog>
56 #if QT_VERSION < 0x050000
57 #include <QDesktopServices>
59 #include <QStandardPaths>
62 #include <QDragEnterEvent>
63 #if QT_VERSION < 0x050000
71 extern bool fWalletUnlockMintOnly;
73 BitcoinGUI::BitcoinGUI(QWidget *parent):
77 encryptWalletAction(0),
79 unlockWalletAction(0),
80 unlockWalletMiningAction(0),
81 changePassphraseAction(0),
88 setWindowTitle(tr("NovaCoin") + " - " + tr("Wallet"));
90 qApp->setWindowIcon(QIcon(":icons/bitcoin"));
91 setWindowIcon(QIcon(":icons/bitcoin"));
93 setUnifiedTitleAndToolBarOnMac(true);
94 QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
99 // Create actions for the toolbar, menu bar and tray/dock icon
102 // Create application menu bar
105 // Create the toolbars
108 // Create the tray icon (or setup the dock icon)
112 overviewPage = new OverviewPage();
114 transactionsPage = new QWidget(this);
115 QVBoxLayout *vbox = new QVBoxLayout();
116 transactionView = new TransactionView(this);
117 vbox->addWidget(transactionView);
118 transactionsPage->setLayout(vbox);
120 mintingPage = new QWidget(this);
121 QVBoxLayout *vboxMinting = new QVBoxLayout();
122 mintingView = new MintingView(this);
123 vboxMinting->addWidget(mintingView);
124 mintingPage->setLayout(vboxMinting);
126 addressBookPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::SendingTab);
128 receiveCoinsPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::ReceivingTab);
130 sendCoinsPage = new SendCoinsDialog(this);
132 signVerifyMessageDialog = new SignVerifyMessageDialog(this);
134 centralWidget = new QStackedWidget(this);
135 centralWidget->addWidget(overviewPage);
136 centralWidget->addWidget(transactionsPage);
137 centralWidget->addWidget(mintingPage);
138 centralWidget->addWidget(addressBookPage);
139 centralWidget->addWidget(receiveCoinsPage);
140 centralWidget->addWidget(sendCoinsPage);
141 setCentralWidget(centralWidget);
146 // Status bar notification icons
147 QFrame *frameBlocks = new QFrame();
148 frameBlocks->setContentsMargins(0,0,0,0);
149 frameBlocks->setMinimumWidth(72);
150 frameBlocks->setMaximumWidth(72);
151 QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);
152 frameBlocksLayout->setContentsMargins(3,0,3,0);
153 frameBlocksLayout->setSpacing(3);
154 labelEncryptionIcon = new QLabel();
155 labelMiningIcon = new QLabel();
156 labelConnectionsIcon = new QLabel();
157 labelBlocksIcon = new QLabel();
158 frameBlocksLayout->addStretch();
159 frameBlocksLayout->addWidget(labelEncryptionIcon);
160 frameBlocksLayout->addStretch();
161 frameBlocksLayout->addWidget(labelMiningIcon);
162 frameBlocksLayout->addStretch();
163 frameBlocksLayout->addWidget(labelConnectionsIcon);
164 frameBlocksLayout->addStretch();
165 frameBlocksLayout->addWidget(labelBlocksIcon);
166 frameBlocksLayout->addStretch();
168 // Progress bar and label for blocks download
169 progressBarLabel = new QLabel();
170 progressBarLabel->setVisible(false);
171 progressBar = new QProgressBar();
172 progressBar->setAlignment(Qt::AlignCenter);
173 progressBar->setVisible(false);
175 // Override style sheet for progress bar for styles that have a segmented progress bar,
176 // as they make the text unreadable (workaround for issue #1071)
177 // See https://qt-project.org/doc/qt-4.8/gallery.html
178 QString curStyle = qApp->style()->metaObject()->className();
179 if(curStyle == "QWindowsStyle" || curStyle == "QWindowsXPStyle")
181 progressBar->setStyleSheet("QProgressBar { background-color: #e8e8e8; border: 1px solid grey; border-radius: 7px; padding: 1px; text-align: center; } QProgressBar::chunk { background: QLinearGradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 #FF8000, stop: 1 orange); border-radius: 7px; margin: 0px; }");
184 statusBar()->addWidget(progressBarLabel);
185 statusBar()->addWidget(progressBar);
186 statusBar()->addPermanentWidget(frameBlocks);
188 syncIconMovie = new QMovie(":/movies/update_spinner", "mng", this);
190 // Clicking on a transaction on the overview page simply sends you to transaction history page
191 connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), this, SLOT(gotoHistoryPage()));
192 connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex)));
194 // Double-clicking on a transaction on the transaction history page shows details
195 connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
197 rpcConsole = new RPCConsole(this);
198 connect(openRPCConsoleAction, SIGNAL(triggered()), rpcConsole, SLOT(show()));
200 // Clicking on "Verify Message" in the address book sends you to the verify message tab
201 connect(addressBookPage, SIGNAL(verifyMessage(QString)), this, SLOT(gotoVerifyMessageTab(QString)));
202 // Clicking on "Sign Message" in the receive coins page sends you to the sign message tab
203 connect(receiveCoinsPage, SIGNAL(signMessage(QString)), this, SLOT(gotoSignMessageTab(QString)));
208 BitcoinGUI::~BitcoinGUI()
210 if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu)
217 void BitcoinGUI::createActions()
219 QActionGroup *tabGroup = new QActionGroup(this);
221 overviewAction = new QAction(QIcon(":/icons/overview"), tr("&Overview"), this);
222 overviewAction->setToolTip(tr("Show general overview of wallet"));
223 overviewAction->setCheckable(true);
224 overviewAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_1));
225 tabGroup->addAction(overviewAction);
227 sendCoinsAction = new QAction(QIcon(":/icons/send"), tr("&Send coins"), this);
228 sendCoinsAction->setToolTip(tr("Send coins to a NovaCoin address"));
229 sendCoinsAction->setCheckable(true);
230 sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2));
231 tabGroup->addAction(sendCoinsAction);
233 receiveCoinsAction = new QAction(QIcon(":/icons/receiving_addresses"), tr("&Receive coins"), this);
234 receiveCoinsAction->setToolTip(tr("Show the list of addresses for receiving payments"));
235 receiveCoinsAction->setCheckable(true);
236 receiveCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_3));
237 tabGroup->addAction(receiveCoinsAction);
239 historyAction = new QAction(QIcon(":/icons/history"), tr("&Transactions"), this);
240 historyAction->setToolTip(tr("Browse transaction history"));
241 historyAction->setCheckable(true);
242 historyAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_4));
243 tabGroup->addAction(historyAction);
245 mintingAction = new QAction(QIcon(":/icons/history"), tr("&Minting"), this);
246 mintingAction->setToolTip(tr("Show your minting capacity"));
247 mintingAction->setCheckable(true);
248 mintingAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_5));
249 tabGroup->addAction(mintingAction);
251 addressBookAction = new QAction(QIcon(":/icons/address-book"), tr("&Address Book"), this);
252 addressBookAction->setToolTip(tr("Edit the list of stored addresses and labels"));
253 addressBookAction->setCheckable(true);
254 addressBookAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_6));
255 tabGroup->addAction(addressBookAction);
257 connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
258 connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage()));
259 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
260 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
261 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
262 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
263 connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
264 connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage()));
265 connect(mintingAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
266 connect(mintingAction, SIGNAL(triggered()), this, SLOT(gotoMintingPage()));
267 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
268 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(gotoAddressBookPage()));
270 quitAction = new QAction(QIcon(":/icons/quit"), tr("E&xit"), this);
271 quitAction->setToolTip(tr("Quit application"));
272 quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
273 quitAction->setMenuRole(QAction::QuitRole);
274 aboutAction = new QAction(QIcon(":/icons/bitcoin"), tr("&About NovaCoin"), this);
275 aboutAction->setToolTip(tr("Show information about NovaCoin"));
276 aboutAction->setMenuRole(QAction::AboutRole);
277 #if QT_VERSION < 0x050000
278 aboutQtAction = new QAction(QIcon(":/trolltech/qmessagebox/images/qtlogo-64.png"), tr("About &Qt"), this);
280 aboutQtAction = new QAction(QIcon(":/qt-project.org/qmessagebox/images/qtlogo-64.png"), tr("About &Qt"), this);
282 aboutQtAction->setToolTip(tr("Show information about Qt"));
283 aboutQtAction->setMenuRole(QAction::AboutQtRole);
284 optionsAction = new QAction(QIcon(":/icons/options"), tr("&Options..."), this);
285 optionsAction->setToolTip(tr("Modify configuration options for NovaCoin"));
286 optionsAction->setMenuRole(QAction::PreferencesRole);
287 toggleHideAction = new QAction(QIcon(":/icons/bitcoin"), tr("&Show / Hide"), this);
288 encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet..."), this);
289 encryptWalletAction->setToolTip(tr("Encrypt or decrypt wallet"));
290 encryptWalletAction->setCheckable(true);
291 backupWalletAction = new QAction(QIcon(":/icons/filesave"), tr("&Backup Wallet..."), this);
292 backupWalletAction->setToolTip(tr("Backup wallet to another location"));
293 dumpWalletAction = new QAction(QIcon(":/icons/dump"), tr("&Dump Wallet..."), this);
294 dumpWalletAction->setStatusTip(tr("Dump keys to a text file"));
295 importWalletAction = new QAction(QIcon(":/icons/import"), tr("&Import Wallet..."), this);
296 importWalletAction->setStatusTip(tr("Import keys into a wallet"));
297 changePassphraseAction = new QAction(QIcon(":/icons/key"), tr("&Change Passphrase..."), this);
298 changePassphraseAction->setToolTip(tr("Change the passphrase used for wallet encryption"));
299 signMessageAction = new QAction(QIcon(":/icons/edit"), tr("Sign &message..."), this);
300 verifyMessageAction = new QAction(QIcon(":/icons/transaction_0"), tr("&Verify message..."), this);
302 lockWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Lock wallet"), this);
303 lockWalletAction->setToolTip(tr("Lock wallet"));
304 lockWalletAction->setCheckable(true);
306 unlockWalletAction = new QAction(QIcon(":/icons/lock_open"), tr("Unlo&ck wallet"), this);
307 unlockWalletAction->setToolTip(tr("Unlock wallet"));
308 unlockWalletAction->setCheckable(true);
310 unlockWalletMiningAction = new QAction(QIcon(":/icons/mining_active"), tr("Unlo&ck wallet for mining"), this);
311 unlockWalletMiningAction->setToolTip(tr("Unlock wallet for mining"));
312 unlockWalletMiningAction->setCheckable(true);
314 exportAction = new QAction(QIcon(":/icons/export"), tr("&Export..."), this);
315 exportAction->setToolTip(tr("Export the data in the current tab to a file"));
316 openRPCConsoleAction = new QAction(QIcon(":/icons/debugwindow"), tr("&Debug window"), this);
317 openRPCConsoleAction->setToolTip(tr("Open debugging and diagnostic console"));
319 connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
320 connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked()));
321 connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
322 connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked()));
323 connect(toggleHideAction, SIGNAL(triggered()), this, SLOT(toggleHidden()));
324 connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool)));
325 connect(lockWalletAction, SIGNAL(triggered(bool)), this, SLOT(lockWallet()));
326 connect(unlockWalletAction, SIGNAL(triggered(bool)), this, SLOT(unlockWallet()));
327 connect(unlockWalletMiningAction, SIGNAL(triggered(bool)), this, SLOT(unlockWalletMining(bool)));
328 connect(backupWalletAction, SIGNAL(triggered()), this, SLOT(backupWallet()));
329 connect(dumpWalletAction, SIGNAL(triggered()), this, SLOT(dumpWallet()));
330 connect(importWalletAction, SIGNAL(triggered()), this, SLOT(importWallet()));
331 connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase()));
332 connect(signMessageAction, SIGNAL(triggered()), this, SLOT(gotoSignMessageTab()));
333 connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(gotoVerifyMessageTab()));
336 void BitcoinGUI::createMenuBar()
339 // Create a decoupled menu bar on Mac which stays even if the window is closed
340 appMenuBar = new QMenuBar();
342 // Get the main window's menu bar on other platforms
343 appMenuBar = menuBar();
346 // Configure the menus
347 QMenu *file = appMenuBar->addMenu(tr("&File"));
348 file->addAction(backupWalletAction);
349 file->addSeparator();
350 file->addAction(dumpWalletAction);
351 file->addAction(importWalletAction);
352 file->addAction(exportAction);
353 file->addAction(signMessageAction);
354 file->addAction(verifyMessageAction);
355 file->addSeparator();
356 file->addAction(quitAction);
358 QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
359 QMenu *securityMenu = settings->addMenu(QIcon(":/icons/key"), tr("&Wallet security"));
360 securityMenu->addAction(encryptWalletAction);
361 securityMenu->addAction(changePassphraseAction);
362 securityMenu->addAction(unlockWalletAction);
363 securityMenu->addAction(unlockWalletMiningAction);
364 securityMenu->addAction(lockWalletAction);
365 settings->addAction(optionsAction);
367 QMenu *help = appMenuBar->addMenu(tr("&Help"));
368 help->addAction(openRPCConsoleAction);
369 help->addSeparator();
370 help->addAction(aboutAction);
371 help->addAction(aboutQtAction);
374 void BitcoinGUI::createToolBars()
376 QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));
377 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
378 toolbar->addAction(overviewAction);
379 toolbar->addAction(sendCoinsAction);
380 toolbar->addAction(receiveCoinsAction);
381 toolbar->addAction(historyAction);
382 toolbar->addAction(mintingAction);
383 toolbar->addAction(addressBookAction);
385 QToolBar *toolbar2 = addToolBar(tr("Actions toolbar"));
386 toolbar2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
387 toolbar2->addAction(exportAction);
390 void BitcoinGUI::setClientModel(ClientModel *clientModel)
392 this->clientModel = clientModel;
395 // Replace some strings and icons, when using the testnet
396 if(clientModel->isTestNet())
398 setWindowTitle(windowTitle() + QString(" ") + tr("[testnet]"));
400 qApp->setWindowIcon(QIcon(":icons/bitcoin_testnet"));
401 setWindowIcon(QIcon(":icons/bitcoin_testnet"));
403 MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
407 trayIcon->setToolTip(tr("NovaCoin client") + QString(" ") + tr("[testnet]"));
408 trayIcon->setIcon(QIcon(":/icons/toolbar_testnet"));
409 toggleHideAction->setIcon(QIcon(":/icons/toolbar_testnet"));
412 aboutAction->setIcon(QIcon(":/icons/toolbar_testnet"));
415 // Keep up to date with client
416 setNumConnections(clientModel->getNumConnections());
417 connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
419 setNumBlocks(clientModel->getNumBlocks(), clientModel->getNumBlocksOfPeers());
420 connect(clientModel, SIGNAL(numBlocksChanged(int,int)), this, SLOT(setNumBlocks(int,int)));
421 connect(clientModel, SIGNAL(numBlocksChanged(int,int)), this, SLOT(updateMining()));
423 // Report errors from network/worker thread
424 connect(clientModel, SIGNAL(error(QString,QString,bool)), this, SLOT(error(QString,QString,bool)));
426 rpcConsole->setClientModel(clientModel);
427 addressBookPage->setOptionsModel(clientModel->getOptionsModel());
428 receiveCoinsPage->setOptionsModel(clientModel->getOptionsModel());
432 void BitcoinGUI::setWalletModel(WalletModel *walletModel)
434 this->walletModel = walletModel;
437 // Report errors from wallet thread
438 connect(walletModel, SIGNAL(error(QString,QString,bool)), this, SLOT(error(QString,QString,bool)));
440 // Put transaction list in tabs
441 transactionView->setModel(walletModel);
442 mintingView->setModel(walletModel);
444 overviewPage->setModel(walletModel);
445 addressBookPage->setModel(walletModel->getAddressTableModel());
446 receiveCoinsPage->setModel(walletModel->getAddressTableModel());
447 sendCoinsPage->setModel(walletModel);
448 signVerifyMessageDialog->setModel(walletModel);
450 setEncryptionStatus(walletModel->getEncryptionStatus());
451 connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));
452 connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(updateMining()));
454 // Balloon pop-up for new transaction
455 connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
456 this, SLOT(incomingTransaction(QModelIndex,int,int)));
458 // Ask for passphrase if needed
459 connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
463 void BitcoinGUI::createTrayIcon()
467 trayIcon = new QSystemTrayIcon(this);
468 trayIconMenu = new QMenu(this);
469 trayIcon->setContextMenu(trayIconMenu);
470 trayIcon->setToolTip(tr("NovaCoin client"));
471 trayIcon->setIcon(QIcon(":/icons/toolbar"));
472 connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
473 this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
476 // Note: On Mac, the dock icon is used to provide the tray's functionality.
477 MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance();
478 dockIconHandler->setMainWindow((QMainWindow *)this);
479 trayIconMenu = dockIconHandler->dockMenu();
482 // Configuration of the tray icon (or dock icon) icon menu
483 trayIconMenu->addAction(toggleHideAction);
484 trayIconMenu->addSeparator();
485 trayIconMenu->addAction(sendCoinsAction);
486 trayIconMenu->addAction(receiveCoinsAction);
487 trayIconMenu->addSeparator();
488 trayIconMenu->addAction(signMessageAction);
489 trayIconMenu->addAction(verifyMessageAction);
490 trayIconMenu->addSeparator();
491 trayIconMenu->addAction(optionsAction);
492 trayIconMenu->addAction(openRPCConsoleAction);
494 // This is built-in on Mac
495 trayIconMenu->addSeparator();
496 trayIconMenu->addAction(quitAction);
498 notificator = new Notificator(qApp->applicationName(), trayIcon, 0);
503 void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
505 if(reason == QSystemTrayIcon::Trigger)
507 // Click on system tray icon triggers show/hide of the main window
508 toggleHideAction->trigger();
513 void BitcoinGUI::optionsClicked()
515 if(!clientModel || !clientModel->getOptionsModel())
518 dlg.setModel(clientModel->getOptionsModel());
522 void BitcoinGUI::aboutClicked()
525 dlg.setModel(clientModel);
529 void BitcoinGUI::setNumConnections(int count)
534 case 0: icon = ":/icons/connect_0"; break;
535 case 1: case 2: case 3: icon = ":/icons/connect_1"; break;
536 case 4: case 5: case 6: icon = ":/icons/connect_2"; break;
537 case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
538 default: icon = ":/icons/connect_4"; break;
540 labelConnectionsIcon->setPixmap(QIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
541 labelConnectionsIcon->setToolTip(tr("%n active connection(s) to NovaCoin network", "", count));
544 void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks)
546 // don't show / hide progress bar and its label if we have no connection to the network
547 if (!clientModel || clientModel->getNumConnections() == 0)
549 progressBarLabel->setVisible(false);
550 progressBar->setVisible(false);
555 QString strStatusBarWarnings = clientModel->getStatusBarWarnings();
558 if(count < nTotalBlocks)
560 int nRemainingBlocks = nTotalBlocks - count;
561 float nPercentageDone = count / (nTotalBlocks * 0.01f);
563 if (strStatusBarWarnings.isEmpty())
565 progressBarLabel->setText(tr("Synchronizing with network..."));
566 progressBarLabel->setVisible(true);
567 progressBar->setFormat(tr("~%n block(s) remaining", "", nRemainingBlocks));
568 progressBar->setMaximum(nTotalBlocks);
569 progressBar->setValue(count);
570 progressBar->setVisible(true);
573 tooltip = tr("Downloaded %1 of %2 blocks of transaction history (%3% done).").arg(count).arg(nTotalBlocks).arg(nPercentageDone, 0, 'f', 2);
577 if (strStatusBarWarnings.isEmpty())
578 progressBarLabel->setVisible(false);
580 progressBar->setVisible(false);
581 tooltip = tr("Downloaded %1 blocks of transaction history.").arg(count);
584 // Override progressBarLabel text and hide progress bar, when we have warnings to display
585 if (!strStatusBarWarnings.isEmpty())
587 progressBarLabel->setText(strStatusBarWarnings);
588 progressBarLabel->setVisible(true);
589 progressBar->setVisible(false);
592 QDateTime lastBlockDate = clientModel->getLastBlockDate();
593 int secs = lastBlockDate.secsTo(QDateTime::currentDateTime());
596 // Represent time from last generated block in human readable text
599 // Fully up to date. Leave text empty.
603 text = tr("%n second(s) ago","",secs);
605 else if(secs < 60*60)
607 text = tr("%n minute(s) ago","",secs/60);
609 else if(secs < 24*60*60)
611 text = tr("%n hour(s) ago","",secs/(60*60));
615 text = tr("%n day(s) ago","",secs/(60*60*24));
618 // Set icon state: spinning if catching up, tick otherwise
619 if(secs < 90*60 && count >= nTotalBlocks)
621 tooltip = tr("Up to date") + QString(".<br>") + tooltip;
622 labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
624 overviewPage->showOutOfSyncWarning(false);
628 tooltip = tr("Catching up...") + QString("<br>") + tooltip;
629 labelBlocksIcon->setMovie(syncIconMovie);
630 syncIconMovie->start();
632 overviewPage->showOutOfSyncWarning(true);
637 tooltip += QString("<br>");
638 tooltip += tr("Last received block was generated %1.").arg(text);
641 // Don't word-wrap this (fixed-width) tooltip
642 tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
644 labelBlocksIcon->setToolTip(tooltip);
645 progressBarLabel->setToolTip(tooltip);
646 progressBar->setToolTip(tooltip);
649 void BitcoinGUI::updateMining()
654 labelMiningIcon->setPixmap(QIcon(":/icons/mining_inactive").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
656 if (!clientModel->getNumConnections())
658 labelMiningIcon->setToolTip(tr("Wallet is offline"));
662 if (walletModel->getEncryptionStatus() == WalletModel::Locked)
664 labelMiningIcon->setToolTip(tr("Wallet is locked"));
668 if (clientModel->inInitialBlockDownload() || clientModel->getNumBlocksOfPeers() > clientModel->getNumBlocks())
670 labelMiningIcon->setToolTip(tr("Blockchain download is in progress"));
674 float nKernelsRate = 0, nCoinDaysRate = 0;
675 walletModel->getStakeStats(nKernelsRate, nCoinDaysRate);
677 if (nKernelsRate > 0)
679 labelMiningIcon->setPixmap(QIcon(":/icons/mining_active").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
681 uint64 nNetworkWeight = clientModel->getPoSKernelPS();
683 double dDifficulty = clientModel->getDifficulty(true);
686 int nApproxTime = 4294967297 * dDifficulty / nTotalWeight;
688 if (nApproxTime < 60)
689 msg = tr("%n second(s)", "", nApproxTime);
690 else if (nApproxTime < 60*60)
691 msg = tr("%n minute(s)", "", nApproxTime / 60);
692 else if (nApproxTime < 24*60*60)
693 msg = tr("%n hour(s)", "", nApproxTime / 3600);
695 msg = tr("%n day(s)", "", nApproxTime / 86400);
697 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));
700 labelMiningIcon->setToolTip(tr("Stake miner is active\nKernel rate is %1 k/s\nCD rate is %2 CD/s\nNetwork weight is %3").arg(nKernelsRate).arg(nCoinDaysRate).arg(nNetworkWeight));
703 labelMiningIcon->setToolTip(tr("No suitable inputs were found"));
706 void BitcoinGUI::error(const QString &title, const QString &message, bool modal)
708 // Report errors from network/worker thread
711 QMessageBox::critical(this, title, message, QMessageBox::Ok, QMessageBox::Ok);
713 notificator->notify(Notificator::Critical, title, message);
717 void BitcoinGUI::message(const QString &title, const QString &message, unsigned int style, const QString &detail)
719 QString strTitle = tr("NovaCoin") + " - ";
720 // Default to information icon
721 int nMBoxIcon = QMessageBox::Information;
722 int nNotifyIcon = Notificator::Information;
725 // Check for usage of predefined title
727 case CClientUIInterface::MSG_ERROR:
728 strTitle += tr("Error");
730 case CClientUIInterface::MSG_WARNING:
731 strTitle += tr("Warning");
733 case CClientUIInterface::MSG_INFORMATION:
734 strTitle += tr("Information");
737 strTitle += title; // Use supplied title
740 // Check for error/warning icon
741 if (style & CClientUIInterface::ICON_ERROR) {
742 nMBoxIcon = QMessageBox::Critical;
743 nNotifyIcon = Notificator::Critical;
745 else if (style & CClientUIInterface::ICON_WARNING) {
746 nMBoxIcon = QMessageBox::Warning;
747 nNotifyIcon = Notificator::Warning;
751 if (style & CClientUIInterface::MODAL) {
752 // Check for buttons, use OK as default, if none was supplied
753 QMessageBox::StandardButton buttons;
754 buttons = QMessageBox::Ok;
756 QMessageBox mBox((QMessageBox::Icon)nMBoxIcon, strTitle, message, buttons);
758 if(!detail.isEmpty()) { mBox.setDetailedText(detail); }
763 notificator->notify((Notificator::Class)nNotifyIcon, strTitle, message);
767 void BitcoinGUI::changeEvent(QEvent *e)
769 QMainWindow::changeEvent(e);
770 #ifndef Q_OS_MAC // Ignored on Mac
771 if(e->type() == QEvent::WindowStateChange)
773 if(clientModel && clientModel->getOptionsModel()->getMinimizeToTray())
775 QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
776 if(!(wsevt->oldState() & Qt::WindowMinimized) && isMinimized())
778 QTimer::singleShot(0, this, SLOT(hide()));
786 void BitcoinGUI::closeEvent(QCloseEvent *event)
790 #ifndef Q_OS_MAC // Ignored on Mac
791 if(!clientModel->getOptionsModel()->getMinimizeToTray() &&
792 !clientModel->getOptionsModel()->getMinimizeOnClose())
798 QMainWindow::closeEvent(event);
801 void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
804 tr("This transaction is over the size limit. You can still send it for a fee of %1, "
805 "which goes to the nodes that process your transaction and helps to support the network. "
806 "Do you want to pay the fee?").arg(
807 BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nFeeRequired));
808 QMessageBox::StandardButton retval = QMessageBox::question(
809 this, tr("Confirm transaction fee"), strMessage,
810 QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes);
811 *payFee = (retval == QMessageBox::Yes);
814 void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
816 if(!walletModel || !clientModel)
818 TransactionTableModel *ttm = walletModel->getTransactionTableModel();
819 qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
820 .data(Qt::EditRole).toULongLong();
821 if(!clientModel->inInitialBlockDownload())
823 // On new transaction, make an info balloon
824 // Unless the initial block download is in progress, to prevent balloon-spam
825 QString date = ttm->index(start, TransactionTableModel::Date, parent)
827 QString type = ttm->index(start, TransactionTableModel::Type, parent)
829 QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
831 QIcon icon = qvariant_cast<QIcon>(ttm->index(start,
832 TransactionTableModel::ToAddress, parent)
833 .data(Qt::DecorationRole));
835 notificator->notify(Notificator::Information,
836 (amount)<0 ? tr("Sent transaction") :
837 tr("Incoming transaction"),
843 .arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true))
845 .arg(address), icon);
849 void BitcoinGUI::gotoOverviewPage()
851 overviewAction->setChecked(true);
852 centralWidget->setCurrentWidget(overviewPage);
854 exportAction->setEnabled(false);
855 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
858 void BitcoinGUI::gotoHistoryPage()
860 historyAction->setChecked(true);
861 centralWidget->setCurrentWidget(transactionsPage);
863 exportAction->setEnabled(true);
864 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
865 connect(exportAction, SIGNAL(triggered()), transactionView, SLOT(exportClicked()));
868 void BitcoinGUI::gotoMintingPage()
870 mintingAction->setChecked(true);
871 centralWidget->setCurrentWidget(mintingPage);
873 exportAction->setEnabled(true);
874 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
875 connect(exportAction, SIGNAL(triggered()), mintingView, SLOT(exportClicked()));
879 void BitcoinGUI::gotoAddressBookPage()
881 addressBookAction->setChecked(true);
882 centralWidget->setCurrentWidget(addressBookPage);
884 exportAction->setEnabled(true);
885 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
886 connect(exportAction, SIGNAL(triggered()), addressBookPage, SLOT(exportClicked()));
889 void BitcoinGUI::gotoReceiveCoinsPage()
891 receiveCoinsAction->setChecked(true);
892 centralWidget->setCurrentWidget(receiveCoinsPage);
894 exportAction->setEnabled(true);
895 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
896 connect(exportAction, SIGNAL(triggered()), receiveCoinsPage, SLOT(exportClicked()));
899 void BitcoinGUI::gotoSendCoinsPage()
901 sendCoinsAction->setChecked(true);
902 centralWidget->setCurrentWidget(sendCoinsPage);
904 exportAction->setEnabled(false);
905 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
908 void BitcoinGUI::gotoSignMessageTab(QString addr)
910 // call show() in showTab_SM()
911 signVerifyMessageDialog->showTab_SM(true);
914 signVerifyMessageDialog->setAddress_SM(addr);
917 void BitcoinGUI::gotoVerifyMessageTab(QString addr)
919 // call show() in showTab_VM()
920 signVerifyMessageDialog->showTab_VM(true);
923 signVerifyMessageDialog->setAddress_VM(addr);
926 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
929 if(event->mimeData()->hasUrls())
930 event->acceptProposedAction();
933 void BitcoinGUI::dropEvent(QDropEvent *event)
935 if(event->mimeData()->hasUrls())
937 int nValidUrisFound = 0;
938 QList<QUrl> uris = event->mimeData()->urls();
939 foreach(const QUrl &uri, uris)
941 if (sendCoinsPage->handleURI(uri.toString()))
945 // if valid URIs were found
949 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."));
952 event->acceptProposedAction();
955 void BitcoinGUI::handleURI(QString strURI)
957 // URI has to be valid
958 if (sendCoinsPage->handleURI(strURI))
960 showNormalIfMinimized();
964 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."));
967 void BitcoinGUI::setEncryptionStatus(int status)
971 case WalletModel::Unencrypted:
972 labelEncryptionIcon->hide();
973 encryptWalletAction->setChecked(false);
974 changePassphraseAction->setEnabled(false);
975 lockWalletAction->setEnabled(false);
976 unlockWalletAction->setEnabled(false);
977 unlockWalletMiningAction->setEnabled(false);
978 encryptWalletAction->setEnabled(true);
980 case WalletModel::Unlocked:
981 labelEncryptionIcon->show();
982 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
983 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
984 encryptWalletAction->setChecked(true);
985 changePassphraseAction->setEnabled(true);
986 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
988 lockWalletAction->setEnabled(true);
989 lockWalletAction->setChecked(false);
990 unlockWalletAction->setEnabled(false);
991 unlockWalletMiningAction->setEnabled(false);
993 if (fWalletUnlockMintOnly)
994 unlockWalletMiningAction->setChecked(true);
996 unlockWalletAction->setChecked(true);
999 case WalletModel::Locked:
1000 labelEncryptionIcon->show();
1001 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
1002 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
1003 encryptWalletAction->setChecked(true);
1004 changePassphraseAction->setEnabled(true);
1005 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
1007 lockWalletAction->setChecked(true);
1008 unlockWalletAction->setChecked(false);
1009 unlockWalletMiningAction->setChecked(false);
1011 lockWalletAction->setEnabled(false);
1012 unlockWalletAction->setEnabled(true);
1013 unlockWalletMiningAction->setEnabled(true);
1018 void BitcoinGUI::encryptWallet(bool status)
1022 AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt:
1023 AskPassphraseDialog::Decrypt, this);
1024 dlg.setModel(walletModel);
1027 setEncryptionStatus(walletModel->getEncryptionStatus());
1030 void BitcoinGUI::unlockWalletMining(bool status)
1035 // Unlock wallet when requested by wallet model
1036 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1038 AskPassphraseDialog dlg(AskPassphraseDialog::UnlockMining, this);
1039 dlg.setModel(walletModel);
1044 void BitcoinGUI::backupWallet()
1046 #if QT_VERSION < 0x050000
1047 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1049 QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1051 QString filename = QFileDialog::getSaveFileName(this, tr("Backup Wallet"), saveDir, tr("Wallet Data (*.dat)"));
1052 if(!filename.isEmpty()) {
1053 if(!walletModel->backupWallet(filename)) {
1054 QMessageBox::warning(this, tr("Backup Failed"), tr("There was an error trying to save the wallet data to the new location."));
1059 void BitcoinGUI::dumpWallet()
1064 WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1067 // Unlock wallet failed or was cancelled
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("Dump Wallet"), saveDir, tr("Wallet dump (*.txt)"));
1077 if(!filename.isEmpty()) {
1078 if(!walletModel->dumpWallet(filename)) {
1079 error(tr("Dump failed"),
1080 tr("An error happened while trying to save the keys to your location.\n"
1081 "Keys were not saved.")
1082 ,CClientUIInterface::MSG_ERROR);
1085 message(tr("Dump successful"),
1086 tr("Keys were saved to this file:\n%2")
1088 ,CClientUIInterface::MSG_INFORMATION);
1092 void BitcoinGUI::importWallet()
1097 WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1100 // Unlock wallet failed or was cancelled
1104 #if QT_VERSION < 0x050000
1105 QString openDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1107 QString openDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1109 QString filename = QFileDialog::getOpenFileName(this, tr("Import Wallet"), openDir, tr("Wallet dump (*.txt)"));
1110 if(!filename.isEmpty()) {
1111 if(!walletModel->importWallet(filename)) {
1112 error(tr("Import Failed"),
1113 tr("An error happened while trying to import the keys.\n"
1114 "Some or all keys from:\n %1,\n were not imported into your wallet.")
1116 ,CClientUIInterface::MSG_ERROR);
1119 message(tr("Import Successful"),
1120 tr("All keys from:\n %1,\n were imported into your wallet.")
1122 ,CClientUIInterface::MSG_INFORMATION);
1127 void BitcoinGUI::changePassphrase()
1129 AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
1130 dlg.setModel(walletModel);
1134 void BitcoinGUI::unlockWallet()
1138 // Unlock wallet when requested by wallet model
1139 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1141 AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
1142 dlg.setModel(walletModel);
1147 void BitcoinGUI::lockWallet()
1152 walletModel->setWalletLocked(true);
1155 void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden)
1157 // activateWindow() (sometimes) helps with keyboard focus on Windows
1163 else if (isMinimized())
1168 else if (GUIUtil::isObscured(this))
1173 else if(fToggleHidden)
1177 void BitcoinGUI::toggleHidden()
1179 showNormalIfMinimized(true);