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"
31 #include "macdockiconhandler.h"
34 #include <QApplication>
35 #if QT_VERSION < 0x050000
36 #include <QMainWindow>
42 #include <QVBoxLayout>
47 #include <QPushButton>
49 #include <QMessageBox>
50 #include <QProgressBar>
51 #include <QStackedWidget>
54 #include <QFileDialog>
55 #if QT_VERSION < 0x050000
56 #include <QDesktopServices>
58 #include <QStandardPaths>
61 #include <QDragEnterEvent>
62 #if QT_VERSION < 0x050000
70 extern bool fWalletUnlockMintOnly;
72 BitcoinGUI::BitcoinGUI(QWidget *parent):
76 encryptWalletAction(0),
78 unlockWalletAction(0),
79 unlockWalletMiningAction(0),
80 changePassphraseAction(0),
87 setWindowTitle(tr("NovaCoin") + " - " + tr("Wallet"));
89 qApp->setWindowIcon(QIcon(":icons/bitcoin"));
90 setWindowIcon(QIcon(":icons/bitcoin"));
92 setUnifiedTitleAndToolBarOnMac(true);
93 QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
98 // Create actions for the toolbar, menu bar and tray/dock icon
101 // Create application menu bar
104 // Create the toolbars
107 // Create the tray icon (or setup the dock icon)
111 overviewPage = new OverviewPage();
113 transactionsPage = new QWidget(this);
114 QVBoxLayout *vbox = new QVBoxLayout();
115 transactionView = new TransactionView(this);
116 vbox->addWidget(transactionView);
117 transactionsPage->setLayout(vbox);
119 addressBookPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::SendingTab);
121 receiveCoinsPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::ReceivingTab);
123 sendCoinsPage = new SendCoinsDialog(this);
125 signVerifyMessageDialog = new SignVerifyMessageDialog(this);
127 centralWidget = new QStackedWidget(this);
128 centralWidget->addWidget(overviewPage);
129 centralWidget->addWidget(transactionsPage);
130 centralWidget->addWidget(addressBookPage);
131 centralWidget->addWidget(receiveCoinsPage);
132 centralWidget->addWidget(sendCoinsPage);
133 setCentralWidget(centralWidget);
138 // Status bar notification icons
139 QFrame *frameBlocks = new QFrame();
140 frameBlocks->setContentsMargins(0,0,0,0);
141 frameBlocks->setMinimumWidth(72);
142 frameBlocks->setMaximumWidth(72);
143 QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);
144 frameBlocksLayout->setContentsMargins(3,0,3,0);
145 frameBlocksLayout->setSpacing(3);
146 labelEncryptionIcon = new QLabel();
147 labelMiningIcon = new QLabel();
148 labelConnectionsIcon = new QLabel();
149 labelBlocksIcon = new QLabel();
150 frameBlocksLayout->addStretch();
151 frameBlocksLayout->addWidget(labelEncryptionIcon);
152 frameBlocksLayout->addStretch();
153 frameBlocksLayout->addWidget(labelMiningIcon);
154 frameBlocksLayout->addStretch();
155 frameBlocksLayout->addWidget(labelConnectionsIcon);
156 frameBlocksLayout->addStretch();
157 frameBlocksLayout->addWidget(labelBlocksIcon);
158 frameBlocksLayout->addStretch();
160 // Progress bar and label for blocks download
161 progressBarLabel = new QLabel();
162 progressBarLabel->setVisible(false);
163 progressBar = new QProgressBar();
164 progressBar->setAlignment(Qt::AlignCenter);
165 progressBar->setVisible(false);
167 // Override style sheet for progress bar for styles that have a segmented progress bar,
168 // as they make the text unreadable (workaround for issue #1071)
169 // See https://qt-project.org/doc/qt-4.8/gallery.html
170 QString curStyle = qApp->style()->metaObject()->className();
171 if(curStyle == "QWindowsStyle" || curStyle == "QWindowsXPStyle")
173 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; }");
176 statusBar()->addWidget(progressBarLabel);
177 statusBar()->addWidget(progressBar);
178 statusBar()->addPermanentWidget(frameBlocks);
180 syncIconMovie = new QMovie(":/movies/update_spinner", "mng", this);
182 // Clicking on a transaction on the overview page simply sends you to transaction history page
183 connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), this, SLOT(gotoHistoryPage()));
184 connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex)));
186 // Double-clicking on a transaction on the transaction history page shows details
187 connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
189 rpcConsole = new RPCConsole(this);
190 connect(openRPCConsoleAction, SIGNAL(triggered()), rpcConsole, SLOT(show()));
192 // Clicking on "Verify Message" in the address book sends you to the verify message tab
193 connect(addressBookPage, SIGNAL(verifyMessage(QString)), this, SLOT(gotoVerifyMessageTab(QString)));
194 // Clicking on "Sign Message" in the receive coins page sends you to the sign message tab
195 connect(receiveCoinsPage, SIGNAL(signMessage(QString)), this, SLOT(gotoSignMessageTab(QString)));
200 BitcoinGUI::~BitcoinGUI()
202 if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu)
209 void BitcoinGUI::createActions()
211 QActionGroup *tabGroup = new QActionGroup(this);
213 overviewAction = new QAction(QIcon(":/icons/overview"), tr("&Overview"), this);
214 overviewAction->setToolTip(tr("Show general overview of wallet"));
215 overviewAction->setCheckable(true);
216 overviewAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_1));
217 tabGroup->addAction(overviewAction);
219 sendCoinsAction = new QAction(QIcon(":/icons/send"), tr("&Send coins"), this);
220 sendCoinsAction->setToolTip(tr("Send coins to a NovaCoin address"));
221 sendCoinsAction->setCheckable(true);
222 sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2));
223 tabGroup->addAction(sendCoinsAction);
225 receiveCoinsAction = new QAction(QIcon(":/icons/receiving_addresses"), tr("&Receive coins"), this);
226 receiveCoinsAction->setToolTip(tr("Show the list of addresses for receiving payments"));
227 receiveCoinsAction->setCheckable(true);
228 receiveCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_3));
229 tabGroup->addAction(receiveCoinsAction);
231 historyAction = new QAction(QIcon(":/icons/history"), tr("&Transactions"), this);
232 historyAction->setToolTip(tr("Browse transaction history"));
233 historyAction->setCheckable(true);
234 historyAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_4));
235 tabGroup->addAction(historyAction);
237 addressBookAction = new QAction(QIcon(":/icons/address-book"), tr("&Address Book"), this);
238 addressBookAction->setToolTip(tr("Edit the list of stored addresses and labels"));
239 addressBookAction->setCheckable(true);
240 addressBookAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_5));
241 tabGroup->addAction(addressBookAction);
243 connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
244 connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage()));
245 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
246 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
247 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
248 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
249 connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
250 connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage()));
251 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
252 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(gotoAddressBookPage()));
254 quitAction = new QAction(QIcon(":/icons/quit"), tr("E&xit"), this);
255 quitAction->setToolTip(tr("Quit application"));
256 quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
257 quitAction->setMenuRole(QAction::QuitRole);
258 aboutAction = new QAction(QIcon(":/icons/bitcoin"), tr("&About NovaCoin"), this);
259 aboutAction->setToolTip(tr("Show information about NovaCoin"));
260 aboutAction->setMenuRole(QAction::AboutRole);
261 #if QT_VERSION < 0x050000
262 aboutQtAction = new QAction(QIcon(":/trolltech/qmessagebox/images/qtlogo-64.png"), tr("About &Qt"), this);
264 aboutQtAction = new QAction(QIcon(":/qt-project.org/qmessagebox/images/qtlogo-64.png"), tr("About &Qt"), this);
266 aboutQtAction->setToolTip(tr("Show information about Qt"));
267 aboutQtAction->setMenuRole(QAction::AboutQtRole);
268 optionsAction = new QAction(QIcon(":/icons/options"), tr("&Options..."), this);
269 optionsAction->setToolTip(tr("Modify configuration options for NovaCoin"));
270 optionsAction->setMenuRole(QAction::PreferencesRole);
271 toggleHideAction = new QAction(QIcon(":/icons/bitcoin"), tr("&Show / Hide"), this);
272 encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet..."), this);
273 encryptWalletAction->setToolTip(tr("Encrypt or decrypt wallet"));
274 encryptWalletAction->setCheckable(true);
275 backupWalletAction = new QAction(QIcon(":/icons/filesave"), tr("&Backup Wallet..."), this);
276 backupWalletAction->setToolTip(tr("Backup wallet to another location"));
277 dumpWalletAction = new QAction(QIcon(":/icons/dump"), tr("&Dump Wallet..."), this);
278 dumpWalletAction->setStatusTip(tr("Dump keys to a text file"));
279 importWalletAction = new QAction(QIcon(":/icons/import"), tr("&Import Wallet..."), this);
280 importWalletAction->setStatusTip(tr("Import keys into a wallet"));
281 changePassphraseAction = new QAction(QIcon(":/icons/key"), tr("&Change Passphrase..."), this);
282 changePassphraseAction->setToolTip(tr("Change the passphrase used for wallet encryption"));
283 signMessageAction = new QAction(QIcon(":/icons/edit"), tr("Sign &message..."), this);
284 verifyMessageAction = new QAction(QIcon(":/icons/transaction_0"), tr("&Verify message..."), this);
286 lockWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Lock wallet"), this);
287 lockWalletAction->setToolTip(tr("Lock wallet"));
288 lockWalletAction->setCheckable(true);
290 unlockWalletAction = new QAction(QIcon(":/icons/lock_open"), tr("Unlo&ck wallet"), this);
291 unlockWalletAction->setToolTip(tr("Unlock wallet"));
292 unlockWalletAction->setCheckable(true);
294 unlockWalletMiningAction = new QAction(QIcon(":/icons/mining_active"), tr("Unlo&ck wallet for mining"), this);
295 unlockWalletMiningAction->setToolTip(tr("Unlock wallet for mining"));
296 unlockWalletMiningAction->setCheckable(true);
298 exportAction = new QAction(QIcon(":/icons/export"), tr("&Export..."), this);
299 exportAction->setToolTip(tr("Export the data in the current tab to a file"));
300 openRPCConsoleAction = new QAction(QIcon(":/icons/debugwindow"), tr("&Debug window"), this);
301 openRPCConsoleAction->setToolTip(tr("Open debugging and diagnostic console"));
303 connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
304 connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked()));
305 connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
306 connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked()));
307 connect(toggleHideAction, SIGNAL(triggered()), this, SLOT(toggleHidden()));
308 connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool)));
309 connect(lockWalletAction, SIGNAL(triggered(bool)), this, SLOT(lockWallet()));
310 connect(unlockWalletAction, SIGNAL(triggered(bool)), this, SLOT(unlockWallet()));
311 connect(unlockWalletMiningAction, SIGNAL(triggered(bool)), this, SLOT(unlockWalletMining(bool)));
312 connect(backupWalletAction, SIGNAL(triggered()), this, SLOT(backupWallet()));
313 connect(dumpWalletAction, SIGNAL(triggered()), this, SLOT(dumpWallet()));
314 connect(importWalletAction, SIGNAL(triggered()), this, SLOT(importWallet()));
315 connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase()));
316 connect(signMessageAction, SIGNAL(triggered()), this, SLOT(gotoSignMessageTab()));
317 connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(gotoVerifyMessageTab()));
320 void BitcoinGUI::createMenuBar()
323 // Create a decoupled menu bar on Mac which stays even if the window is closed
324 appMenuBar = new QMenuBar();
326 // Get the main window's menu bar on other platforms
327 appMenuBar = menuBar();
330 // Configure the menus
331 QMenu *file = appMenuBar->addMenu(tr("&File"));
332 file->addAction(backupWalletAction);
333 file->addSeparator();
334 file->addAction(dumpWalletAction);
335 file->addAction(importWalletAction);
336 file->addAction(exportAction);
337 file->addAction(signMessageAction);
338 file->addAction(verifyMessageAction);
339 file->addSeparator();
340 file->addAction(quitAction);
342 QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
343 QMenu *securityMenu = settings->addMenu(QIcon(":/icons/key"), tr("&Wallet security"));
344 securityMenu->addAction(encryptWalletAction);
345 securityMenu->addAction(changePassphraseAction);
346 securityMenu->addAction(unlockWalletAction);
347 securityMenu->addAction(unlockWalletMiningAction);
348 securityMenu->addAction(lockWalletAction);
349 settings->addAction(optionsAction);
351 QMenu *help = appMenuBar->addMenu(tr("&Help"));
352 help->addAction(openRPCConsoleAction);
353 help->addSeparator();
354 help->addAction(aboutAction);
355 help->addAction(aboutQtAction);
358 void BitcoinGUI::createToolBars()
360 QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));
361 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
362 toolbar->addAction(overviewAction);
363 toolbar->addAction(sendCoinsAction);
364 toolbar->addAction(receiveCoinsAction);
365 toolbar->addAction(historyAction);
366 toolbar->addAction(addressBookAction);
368 QToolBar *toolbar2 = addToolBar(tr("Actions toolbar"));
369 toolbar2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
370 toolbar2->addAction(exportAction);
373 void BitcoinGUI::setClientModel(ClientModel *clientModel)
375 this->clientModel = clientModel;
378 // Replace some strings and icons, when using the testnet
379 if(clientModel->isTestNet())
381 setWindowTitle(windowTitle() + QString(" ") + tr("[testnet]"));
383 qApp->setWindowIcon(QIcon(":icons/bitcoin_testnet"));
384 setWindowIcon(QIcon(":icons/bitcoin_testnet"));
386 MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
390 trayIcon->setToolTip(tr("NovaCoin client") + QString(" ") + tr("[testnet]"));
391 trayIcon->setIcon(QIcon(":/icons/toolbar_testnet"));
392 toggleHideAction->setIcon(QIcon(":/icons/toolbar_testnet"));
395 aboutAction->setIcon(QIcon(":/icons/toolbar_testnet"));
398 // Keep up to date with client
399 setNumConnections(clientModel->getNumConnections());
400 connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
402 setNumBlocks(clientModel->getNumBlocks(), clientModel->getNumBlocksOfPeers());
403 connect(clientModel, SIGNAL(numBlocksChanged(int,int)), this, SLOT(setNumBlocks(int,int)));
404 connect(clientModel, SIGNAL(numBlocksChanged(int,int)), this, SLOT(updateMining()));
406 // Report errors from network/worker thread
407 connect(clientModel, SIGNAL(error(QString,QString,bool)), this, SLOT(error(QString,QString,bool)));
409 rpcConsole->setClientModel(clientModel);
410 addressBookPage->setOptionsModel(clientModel->getOptionsModel());
411 receiveCoinsPage->setOptionsModel(clientModel->getOptionsModel());
415 void BitcoinGUI::setWalletModel(WalletModel *walletModel)
417 this->walletModel = walletModel;
420 // Report errors from wallet thread
421 connect(walletModel, SIGNAL(error(QString,QString,bool)), this, SLOT(error(QString,QString,bool)));
423 // Put transaction list in tabs
424 transactionView->setModel(walletModel);
426 overviewPage->setModel(walletModel);
427 addressBookPage->setModel(walletModel->getAddressTableModel());
428 receiveCoinsPage->setModel(walletModel->getAddressTableModel());
429 sendCoinsPage->setModel(walletModel);
430 signVerifyMessageDialog->setModel(walletModel);
432 setEncryptionStatus(walletModel->getEncryptionStatus());
433 connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));
434 connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(updateMining()));
436 // Balloon pop-up for new transaction
437 connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
438 this, SLOT(incomingTransaction(QModelIndex,int,int)));
440 // Ask for passphrase if needed
441 connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
445 void BitcoinGUI::createTrayIcon()
449 trayIcon = new QSystemTrayIcon(this);
450 trayIconMenu = new QMenu(this);
451 trayIcon->setContextMenu(trayIconMenu);
452 trayIcon->setToolTip(tr("NovaCoin client"));
453 trayIcon->setIcon(QIcon(":/icons/toolbar"));
454 connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
455 this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
458 // Note: On Mac, the dock icon is used to provide the tray's functionality.
459 MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance();
460 trayIconMenu = dockIconHandler->dockMenu();
463 // Configuration of the tray icon (or dock icon) icon menu
464 trayIconMenu->addAction(toggleHideAction);
465 trayIconMenu->addSeparator();
466 trayIconMenu->addAction(sendCoinsAction);
467 trayIconMenu->addAction(receiveCoinsAction);
468 trayIconMenu->addSeparator();
469 trayIconMenu->addAction(signMessageAction);
470 trayIconMenu->addAction(verifyMessageAction);
471 trayIconMenu->addSeparator();
472 trayIconMenu->addAction(optionsAction);
473 trayIconMenu->addAction(openRPCConsoleAction);
474 #ifndef Q_OS_MAC // This is built-in on Mac
475 trayIconMenu->addSeparator();
476 trayIconMenu->addAction(quitAction);
479 notificator = new Notificator(qApp->applicationName(), trayIcon);
483 void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
485 if(reason == QSystemTrayIcon::Trigger)
487 // Click on system tray icon triggers show/hide of the main window
488 toggleHideAction->trigger();
493 void BitcoinGUI::optionsClicked()
495 if(!clientModel || !clientModel->getOptionsModel())
498 dlg.setModel(clientModel->getOptionsModel());
502 void BitcoinGUI::aboutClicked()
505 dlg.setModel(clientModel);
509 void BitcoinGUI::setNumConnections(int count)
514 case 0: icon = ":/icons/connect_0"; break;
515 case 1: case 2: case 3: icon = ":/icons/connect_1"; break;
516 case 4: case 5: case 6: icon = ":/icons/connect_2"; break;
517 case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
518 default: icon = ":/icons/connect_4"; break;
520 labelConnectionsIcon->setPixmap(QIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
521 labelConnectionsIcon->setToolTip(tr("%n active connection(s) to NovaCoin network", "", count));
524 void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks)
526 // don't show / hide progress bar and its label if we have no connection to the network
527 if (!clientModel || clientModel->getNumConnections() == 0)
529 progressBarLabel->setVisible(false);
530 progressBar->setVisible(false);
535 QString strStatusBarWarnings = clientModel->getStatusBarWarnings();
538 if(count < nTotalBlocks)
540 int nRemainingBlocks = nTotalBlocks - count;
541 float nPercentageDone = count / (nTotalBlocks * 0.01f);
543 if (strStatusBarWarnings.isEmpty())
545 progressBarLabel->setText(tr("Synchronizing with network..."));
546 progressBarLabel->setVisible(true);
547 progressBar->setFormat(tr("~%n block(s) remaining", "", nRemainingBlocks));
548 progressBar->setMaximum(nTotalBlocks);
549 progressBar->setValue(count);
550 progressBar->setVisible(true);
553 tooltip = tr("Downloaded %1 of %2 blocks of transaction history (%3% done).").arg(count).arg(nTotalBlocks).arg(nPercentageDone, 0, 'f', 2);
557 if (strStatusBarWarnings.isEmpty())
558 progressBarLabel->setVisible(false);
560 progressBar->setVisible(false);
561 tooltip = tr("Downloaded %1 blocks of transaction history.").arg(count);
564 // Override progressBarLabel text and hide progress bar, when we have warnings to display
565 if (!strStatusBarWarnings.isEmpty())
567 progressBarLabel->setText(strStatusBarWarnings);
568 progressBarLabel->setVisible(true);
569 progressBar->setVisible(false);
572 QDateTime lastBlockDate = clientModel->getLastBlockDate();
573 int secs = lastBlockDate.secsTo(QDateTime::currentDateTime());
576 // Represent time from last generated block in human readable text
579 // Fully up to date. Leave text empty.
583 text = tr("%n second(s) ago","",secs);
585 else if(secs < 60*60)
587 text = tr("%n minute(s) ago","",secs/60);
589 else if(secs < 24*60*60)
591 text = tr("%n hour(s) ago","",secs/(60*60));
595 text = tr("%n day(s) ago","",secs/(60*60*24));
598 // Set icon state: spinning if catching up, tick otherwise
599 if(secs < 90*60 && count >= nTotalBlocks)
601 tooltip = tr("Up to date") + QString(".<br>") + tooltip;
602 labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
604 overviewPage->showOutOfSyncWarning(false);
608 tooltip = tr("Catching up...") + QString("<br>") + tooltip;
609 labelBlocksIcon->setMovie(syncIconMovie);
610 syncIconMovie->start();
612 overviewPage->showOutOfSyncWarning(true);
617 tooltip += QString("<br>");
618 tooltip += tr("Last received block was generated %1.").arg(text);
621 // Don't word-wrap this (fixed-width) tooltip
622 tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
624 labelBlocksIcon->setToolTip(tooltip);
625 progressBarLabel->setToolTip(tooltip);
626 progressBar->setToolTip(tooltip);
629 void BitcoinGUI::updateMining()
634 labelMiningIcon->setPixmap(QIcon(":/icons/mining_inactive").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
636 if (!clientModel->getNumConnections())
638 labelMiningIcon->setToolTip(tr("Wallet is offline"));
642 if (walletModel->getEncryptionStatus() == WalletModel::Locked)
644 labelMiningIcon->setToolTip(tr("Wallet is locked"));
648 if (clientModel->inInitialBlockDownload() || clientModel->getNumBlocksOfPeers() > clientModel->getNumBlocks())
650 labelMiningIcon->setToolTip(tr("Blockchain download is in progress"));
654 uint64 nMinWeight = 0, nMaxWeight = 0, nTotalWeight = 0;
655 walletModel->getStakeWeight(nMinWeight, nMaxWeight, nTotalWeight);
657 if (nTotalWeight > 0)
659 labelMiningIcon->setPixmap(QIcon(":/icons/mining_active").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
661 uint64 nNetworkWeight = clientModel->getPoSKernelPS();
663 double dDifficulty = clientModel->getDifficulty(true);
666 int nApproxTime = 4294967297 * dDifficulty / nTotalWeight;
668 if (nApproxTime < 60)
669 msg = tr("%n second(s)", "", nApproxTime);
670 else if (nApproxTime < 60*60)
671 msg = tr("%n minute(s)", "", nApproxTime / 60);
672 else if (nApproxTime < 24*60*60)
673 msg = tr("%n hour(s)", "", nApproxTime / 3600);
675 msg = tr("%n day(s)", "", nApproxTime / 86400);
677 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));
680 labelMiningIcon->setToolTip(tr("Stake miner is active\nYour current stake weight is %1\nNetwork weight is %2").arg(nTotalWeight).arg(nNetworkWeight));
683 labelMiningIcon->setToolTip(tr("No suitable inputs were found"));
686 void BitcoinGUI::error(const QString &title, const QString &message, bool modal)
688 // Report errors from network/worker thread
691 QMessageBox::critical(this, title, message, QMessageBox::Ok, QMessageBox::Ok);
693 notificator->notify(Notificator::Critical, title, message);
697 void BitcoinGUI::message(const QString &title, const QString &message, unsigned int style, const QString &detail)
699 QString strTitle = tr("NovaCoin") + " - ";
700 // Default to information icon
701 int nMBoxIcon = QMessageBox::Information;
702 int nNotifyIcon = Notificator::Information;
705 // Check for usage of predefined title
707 case CClientUIInterface::MSG_ERROR:
708 strTitle += tr("Error");
710 case CClientUIInterface::MSG_WARNING:
711 strTitle += tr("Warning");
713 case CClientUIInterface::MSG_INFORMATION:
714 strTitle += tr("Information");
717 strTitle += title; // Use supplied title
720 // Check for error/warning icon
721 if (style & CClientUIInterface::ICON_ERROR) {
722 nMBoxIcon = QMessageBox::Critical;
723 nNotifyIcon = Notificator::Critical;
725 else if (style & CClientUIInterface::ICON_WARNING) {
726 nMBoxIcon = QMessageBox::Warning;
727 nNotifyIcon = Notificator::Warning;
731 if (style & CClientUIInterface::MODAL) {
732 // Check for buttons, use OK as default, if none was supplied
733 QMessageBox::StandardButton buttons;
734 buttons = QMessageBox::Ok;
736 QMessageBox mBox((QMessageBox::Icon)nMBoxIcon, strTitle, message, buttons);
738 if(!detail.isEmpty()) { mBox.setDetailedText(detail); }
743 notificator->notify((Notificator::Class)nNotifyIcon, strTitle, message);
747 void BitcoinGUI::changeEvent(QEvent *e)
749 QMainWindow::changeEvent(e);
750 #ifndef Q_OS_MAC // Ignored on Mac
751 if(e->type() == QEvent::WindowStateChange)
753 if(clientModel && clientModel->getOptionsModel()->getMinimizeToTray())
755 QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
756 if(!(wsevt->oldState() & Qt::WindowMinimized) && isMinimized())
758 QTimer::singleShot(0, this, SLOT(hide()));
766 void BitcoinGUI::closeEvent(QCloseEvent *event)
770 #ifndef Q_OS_MAC // Ignored on Mac
771 if(!clientModel->getOptionsModel()->getMinimizeToTray() &&
772 !clientModel->getOptionsModel()->getMinimizeOnClose())
778 QMainWindow::closeEvent(event);
781 void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
784 tr("This transaction is over the size limit. You can still send it for a fee of %1, "
785 "which goes to the nodes that process your transaction and helps to support the network. "
786 "Do you want to pay the fee?").arg(
787 BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nFeeRequired));
788 QMessageBox::StandardButton retval = QMessageBox::question(
789 this, tr("Confirm transaction fee"), strMessage,
790 QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes);
791 *payFee = (retval == QMessageBox::Yes);
794 void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
796 if(!walletModel || !clientModel)
798 TransactionTableModel *ttm = walletModel->getTransactionTableModel();
799 qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
800 .data(Qt::EditRole).toULongLong();
801 if(!clientModel->inInitialBlockDownload())
803 // On new transaction, make an info balloon
804 // Unless the initial block download is in progress, to prevent balloon-spam
805 QString date = ttm->index(start, TransactionTableModel::Date, parent)
807 QString type = ttm->index(start, TransactionTableModel::Type, parent)
809 QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
811 QIcon icon = qvariant_cast<QIcon>(ttm->index(start,
812 TransactionTableModel::ToAddress, parent)
813 .data(Qt::DecorationRole));
815 notificator->notify(Notificator::Information,
816 (amount)<0 ? tr("Sent transaction") :
817 tr("Incoming transaction"),
823 .arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true))
825 .arg(address), icon);
829 void BitcoinGUI::gotoOverviewPage()
831 overviewAction->setChecked(true);
832 centralWidget->setCurrentWidget(overviewPage);
834 exportAction->setEnabled(false);
835 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
838 void BitcoinGUI::gotoHistoryPage()
840 historyAction->setChecked(true);
841 centralWidget->setCurrentWidget(transactionsPage);
843 exportAction->setEnabled(true);
844 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
845 connect(exportAction, SIGNAL(triggered()), transactionView, SLOT(exportClicked()));
848 void BitcoinGUI::gotoAddressBookPage()
850 addressBookAction->setChecked(true);
851 centralWidget->setCurrentWidget(addressBookPage);
853 exportAction->setEnabled(true);
854 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
855 connect(exportAction, SIGNAL(triggered()), addressBookPage, SLOT(exportClicked()));
858 void BitcoinGUI::gotoReceiveCoinsPage()
860 receiveCoinsAction->setChecked(true);
861 centralWidget->setCurrentWidget(receiveCoinsPage);
863 exportAction->setEnabled(true);
864 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
865 connect(exportAction, SIGNAL(triggered()), receiveCoinsPage, SLOT(exportClicked()));
868 void BitcoinGUI::gotoSendCoinsPage()
870 sendCoinsAction->setChecked(true);
871 centralWidget->setCurrentWidget(sendCoinsPage);
873 exportAction->setEnabled(false);
874 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
877 void BitcoinGUI::gotoSignMessageTab(QString addr)
879 // call show() in showTab_SM()
880 signVerifyMessageDialog->showTab_SM(true);
883 signVerifyMessageDialog->setAddress_SM(addr);
886 void BitcoinGUI::gotoVerifyMessageTab(QString addr)
888 // call show() in showTab_VM()
889 signVerifyMessageDialog->showTab_VM(true);
892 signVerifyMessageDialog->setAddress_VM(addr);
895 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
898 if(event->mimeData()->hasUrls())
899 event->acceptProposedAction();
902 void BitcoinGUI::dropEvent(QDropEvent *event)
904 if(event->mimeData()->hasUrls())
906 int nValidUrisFound = 0;
907 QList<QUrl> uris = event->mimeData()->urls();
908 foreach(const QUrl &uri, uris)
910 if (sendCoinsPage->handleURI(uri.toString()))
914 // if valid URIs were found
918 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."));
921 event->acceptProposedAction();
924 void BitcoinGUI::handleURI(QString strURI)
926 // URI has to be valid
927 if (sendCoinsPage->handleURI(strURI))
929 showNormalIfMinimized();
933 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."));
936 void BitcoinGUI::setEncryptionStatus(int status)
940 case WalletModel::Unencrypted:
941 labelEncryptionIcon->hide();
942 encryptWalletAction->setChecked(false);
943 changePassphraseAction->setEnabled(false);
944 lockWalletAction->setEnabled(false);
945 unlockWalletAction->setEnabled(false);
946 unlockWalletMiningAction->setEnabled(false);
947 encryptWalletAction->setEnabled(true);
949 case WalletModel::Unlocked:
950 labelEncryptionIcon->show();
951 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
952 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
953 encryptWalletAction->setChecked(true);
954 changePassphraseAction->setEnabled(true);
955 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
957 lockWalletAction->setEnabled(true);
958 lockWalletAction->setChecked(false);
959 unlockWalletAction->setEnabled(false);
960 unlockWalletMiningAction->setEnabled(false);
962 if (fWalletUnlockMintOnly)
963 unlockWalletMiningAction->setChecked(true);
965 unlockWalletAction->setChecked(true);
968 case WalletModel::Locked:
969 labelEncryptionIcon->show();
970 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
971 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
972 encryptWalletAction->setChecked(true);
973 changePassphraseAction->setEnabled(true);
974 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
976 lockWalletAction->setChecked(true);
977 unlockWalletAction->setChecked(false);
978 unlockWalletMiningAction->setChecked(false);
980 lockWalletAction->setEnabled(false);
981 unlockWalletAction->setEnabled(true);
982 unlockWalletMiningAction->setEnabled(true);
987 void BitcoinGUI::encryptWallet(bool status)
991 AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt:
992 AskPassphraseDialog::Decrypt, this);
993 dlg.setModel(walletModel);
996 setEncryptionStatus(walletModel->getEncryptionStatus());
999 void BitcoinGUI::unlockWalletMining(bool status)
1004 // Unlock wallet when requested by wallet model
1005 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1007 AskPassphraseDialog dlg(AskPassphraseDialog::UnlockMining, this);
1008 dlg.setModel(walletModel);
1013 void BitcoinGUI::backupWallet()
1015 #if QT_VERSION < 0x050000
1016 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1018 QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1020 QString filename = QFileDialog::getSaveFileName(this, tr("Backup Wallet"), saveDir, tr("Wallet Data (*.dat)"));
1021 if(!filename.isEmpty()) {
1022 if(!walletModel->backupWallet(filename)) {
1023 QMessageBox::warning(this, tr("Backup Failed"), tr("There was an error trying to save the wallet data to the new location."));
1028 void BitcoinGUI::dumpWallet()
1033 WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1036 // Unlock wallet failed or was cancelled
1040 #if QT_VERSION < 0x050000
1041 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1043 QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1045 QString filename = QFileDialog::getSaveFileName(this, tr("Dump Wallet"), saveDir, tr("Wallet dump (*.txt)"));
1046 if(!filename.isEmpty()) {
1047 if(!walletModel->dumpWallet(filename)) {
1048 error(tr("Dump failed"),
1049 tr("An error happened while trying to save the keys to your location.\n"
1050 "Keys were not saved.")
1051 ,CClientUIInterface::MSG_ERROR);
1054 message(tr("Dump successful"),
1055 tr("Keys were saved to this file:\n%2")
1057 ,CClientUIInterface::MSG_INFORMATION);
1061 void BitcoinGUI::importWallet()
1066 WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1069 // Unlock wallet failed or was cancelled
1073 #if QT_VERSION < 0x050000
1074 QString openDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1076 QString openDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1078 QString filename = QFileDialog::getOpenFileName(this, tr("Import Wallet"), openDir, tr("Wallet dump (*.txt)"));
1079 if(!filename.isEmpty()) {
1080 if(!walletModel->importWallet(filename)) {
1081 error(tr("Import Failed"),
1082 tr("An error happened while trying to import the keys.\n"
1083 "Some or all keys from:\n %1,\n were not imported into your wallet.")
1085 ,CClientUIInterface::MSG_ERROR);
1088 message(tr("Import Successful"),
1089 tr("All keys from:\n %1,\n were imported into your wallet.")
1091 ,CClientUIInterface::MSG_INFORMATION);
1096 void BitcoinGUI::changePassphrase()
1098 AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
1099 dlg.setModel(walletModel);
1103 void BitcoinGUI::unlockWallet()
1107 // Unlock wallet when requested by wallet model
1108 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1110 AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
1111 dlg.setModel(walletModel);
1116 void BitcoinGUI::lockWallet()
1121 walletModel->setWalletLocked(true);
1124 void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden)
1126 // activateWindow() (sometimes) helps with keyboard focus on Windows
1132 else if (isMinimized())
1137 else if (GUIUtil::isObscured(this))
1142 else if(fToggleHidden)
1146 void BitcoinGUI::toggleHidden()
1148 showNormalIfMinimized(true);