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),
91 setWindowTitle(tr("NovaCoin") + " - " + tr("Wallet"));
93 qApp->setWindowIcon(QIcon(":icons/bitcoin"));
94 setWindowIcon(QIcon(":icons/bitcoin"));
96 setUnifiedTitleAndToolBarOnMac(true);
97 QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
100 setAcceptDrops(true);
102 // Create actions for the toolbar, menu bar and tray/dock icon
105 // Create application menu bar
108 // Create the toolbars
111 // Create the tray icon (or setup the dock icon)
115 overviewPage = new OverviewPage();
117 transactionsPage = new QWidget(this);
118 QVBoxLayout *vbox = new QVBoxLayout();
119 transactionView = new TransactionView(this);
120 vbox->addWidget(transactionView);
121 transactionsPage->setLayout(vbox);
123 mintingPage = new QWidget(this);
124 QVBoxLayout *vboxMinting = new QVBoxLayout();
125 mintingView = new MintingView(this);
126 vboxMinting->addWidget(mintingView);
127 mintingPage->setLayout(vboxMinting);
129 addressBookPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::SendingTab);
131 receiveCoinsPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::ReceivingTab);
133 sendCoinsPage = new SendCoinsDialog(this);
135 signVerifyMessageDialog = new SignVerifyMessageDialog(this);
137 multisigPage = new MultisigDialog(this);
139 centralWidget = new QStackedWidget(this);
140 centralWidget->addWidget(overviewPage);
141 centralWidget->addWidget(transactionsPage);
142 centralWidget->addWidget(mintingPage);
143 centralWidget->addWidget(addressBookPage);
144 centralWidget->addWidget(receiveCoinsPage);
145 centralWidget->addWidget(sendCoinsPage);
146 setCentralWidget(centralWidget);
151 // Status bar notification icons
152 QFrame *frameBlocks = new QFrame();
153 frameBlocks->setContentsMargins(0,0,0,0);
154 frameBlocks->setMinimumWidth(72);
155 frameBlocks->setMaximumWidth(72);
156 QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);
157 frameBlocksLayout->setContentsMargins(3,0,3,0);
158 frameBlocksLayout->setSpacing(3);
159 labelEncryptionIcon = new QLabel();
160 labelMiningIcon = new QLabel();
161 labelConnectionsIcon = new QLabel();
162 labelBlocksIcon = new QLabel();
163 frameBlocksLayout->addStretch();
164 frameBlocksLayout->addWidget(labelEncryptionIcon);
165 frameBlocksLayout->addStretch();
166 frameBlocksLayout->addWidget(labelMiningIcon);
167 frameBlocksLayout->addStretch();
168 frameBlocksLayout->addWidget(labelConnectionsIcon);
169 frameBlocksLayout->addStretch();
170 frameBlocksLayout->addWidget(labelBlocksIcon);
171 frameBlocksLayout->addStretch();
173 // Progress bar and label for blocks download
174 progressBarLabel = new QLabel();
175 progressBarLabel->setVisible(false);
176 progressBar = new QProgressBar();
177 progressBar->setAlignment(Qt::AlignCenter);
178 progressBar->setVisible(false);
180 // Override style sheet for progress bar for styles that have a segmented progress bar,
181 // as they make the text unreadable (workaround for issue #1071)
182 // See https://qt-project.org/doc/qt-4.8/gallery.html
183 QString curStyle = qApp->style()->metaObject()->className();
184 if(curStyle == "QWindowsStyle" || curStyle == "QWindowsXPStyle")
186 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; }");
189 statusBar()->addWidget(progressBarLabel);
190 statusBar()->addWidget(progressBar);
191 statusBar()->addPermanentWidget(frameBlocks);
193 syncIconMovie = new QMovie(":/movies/update_spinner", "mng", this);
195 // Clicking on a transaction on the overview page simply sends you to transaction history page
196 connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), this, SLOT(gotoHistoryPage()));
197 connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex)));
199 // Double-clicking on a transaction on the transaction history page shows details
200 connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
202 rpcConsole = new RPCConsole(0);
203 connect(openRPCConsoleAction, SIGNAL(triggered()), rpcConsole, SLOT(show()));
205 aboutDialog = new AboutDialog(0);
206 optionsDialog = new OptionsDialog(0);
208 // Clicking on "Verify Message" in the address book sends you to the verify message tab
209 connect(addressBookPage, SIGNAL(verifyMessage(QString)), this, SLOT(gotoVerifyMessageTab(QString)));
210 // Clicking on "Sign Message" in the receive coins page sends you to the sign message tab
211 connect(receiveCoinsPage, SIGNAL(signMessage(QString)), this, SLOT(gotoSignMessageTab(QString)));
216 BitcoinGUI::~BitcoinGUI()
218 if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu)
226 delete optionsDialog;
229 void BitcoinGUI::createActions()
231 QActionGroup *tabGroup = new QActionGroup(this);
233 overviewAction = new QAction(QIcon(":/icons/overview"), tr("&Overview"), this);
234 overviewAction->setToolTip(tr("Show general overview of wallet"));
235 overviewAction->setCheckable(true);
236 overviewAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_1));
237 tabGroup->addAction(overviewAction);
239 sendCoinsAction = new QAction(QIcon(":/icons/send"), tr("&Send coins"), this);
240 sendCoinsAction->setToolTip(tr("Send coins to a NovaCoin address"));
241 sendCoinsAction->setCheckable(true);
242 sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2));
243 tabGroup->addAction(sendCoinsAction);
245 receiveCoinsAction = new QAction(QIcon(":/icons/receiving_addresses"), tr("&Receive coins"), this);
246 receiveCoinsAction->setToolTip(tr("Show the list of addresses for receiving payments"));
247 receiveCoinsAction->setCheckable(true);
248 receiveCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_3));
249 tabGroup->addAction(receiveCoinsAction);
251 historyAction = new QAction(QIcon(":/icons/history"), tr("&Transactions"), this);
252 historyAction->setToolTip(tr("Browse transaction history"));
253 historyAction->setCheckable(true);
254 historyAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_4));
255 tabGroup->addAction(historyAction);
257 mintingAction = new QAction(QIcon(":/icons/history"), tr("&Minting"), this);
258 mintingAction->setToolTip(tr("Show your minting capacity"));
259 mintingAction->setCheckable(true);
260 mintingAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_5));
261 tabGroup->addAction(mintingAction);
263 addressBookAction = new QAction(QIcon(":/icons/address-book"), tr("&Address Book"), this);
264 addressBookAction->setToolTip(tr("Edit the list of stored addresses and labels"));
265 addressBookAction->setCheckable(true);
266 addressBookAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_6));
267 tabGroup->addAction(addressBookAction);
269 multisigAction = new QAction(QIcon(":/icons/send"), tr("Multisig"), this);
270 multisigAction->setStatusTip(tr("Open window for working with multisig addresses"));
271 tabGroup->addAction(multisigAction);
273 connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
274 connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage()));
275 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
276 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
277 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
278 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
279 connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
280 connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage()));
281 connect(mintingAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
282 connect(mintingAction, SIGNAL(triggered()), this, SLOT(gotoMintingPage()));
283 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
284 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(gotoAddressBookPage()));
285 connect(multisigAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
286 connect(multisigAction, SIGNAL(triggered()), this, SLOT(gotoMultisigPage()));
288 quitAction = new QAction(QIcon(":/icons/quit"), tr("E&xit"), this);
289 quitAction->setStatusTip(tr("Quit application"));
290 quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
291 quitAction->setMenuRole(QAction::QuitRole);
292 aboutAction = new QAction(QIcon(":/icons/bitcoin"), tr("&About NovaCoin"), this);
293 aboutAction->setStatusTip(tr("Show information about NovaCoin"));
294 aboutAction->setMenuRole(QAction::AboutRole);
295 #if QT_VERSION < 0x050000
296 aboutQtAction = new QAction(QIcon(":/trolltech/qmessagebox/images/qtlogo-64.png"), tr("About &Qt"), this);
298 aboutQtAction = new QAction(QIcon(":/qt-project.org/qmessagebox/images/qtlogo-64.png"), tr("About &Qt"), this);
300 aboutQtAction->setStatusTip(tr("Show information about Qt"));
301 aboutQtAction->setMenuRole(QAction::AboutQtRole);
302 optionsAction = new QAction(QIcon(":/icons/options"), tr("&Options..."), this);
303 optionsAction->setStatusTip(tr("Modify configuration options for NovaCoin"));
304 optionsAction->setMenuRole(QAction::PreferencesRole);
305 toggleHideAction = new QAction(QIcon(":/icons/bitcoin"), tr("&Show / Hide"), this);
306 encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet..."), this);
307 encryptWalletAction->setStatusTip(tr("Encrypt or decrypt wallet"));
308 encryptWalletAction->setCheckable(true);
309 backupWalletAction = new QAction(QIcon(":/icons/filesave"), tr("&Backup Wallet..."), this);
310 backupWalletAction->setStatusTip(tr("Backup wallet to another location"));
311 dumpWalletAction = new QAction(QIcon(":/icons/dump"), tr("&Dump Wallet..."), this);
312 dumpWalletAction->setStatusTip(tr("Dump keys to a text file"));
313 importWalletAction = new QAction(QIcon(":/icons/import"), tr("&Import Wallet..."), this);
314 importWalletAction->setStatusTip(tr("Import keys into a wallet"));
315 changePassphraseAction = new QAction(QIcon(":/icons/key"), tr("&Change Passphrase..."), this);
316 changePassphraseAction->setStatusTip(tr("Change the passphrase used for wallet encryption"));
317 signMessageAction = new QAction(QIcon(":/icons/edit"), tr("Sign &message..."), this);
318 signMessageAction->setStatusTip(tr("Sign messages with your Novacoin addresses to prove you own them"));
319 verifyMessageAction = new QAction(QIcon(":/icons/transaction_0"), tr("&Verify message..."), this);
320 verifyMessageAction->setStatusTip(tr("Verify messages to ensure they were signed with specified Novacoin addresses"));
322 lockWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Lock wallet"), this);
323 lockWalletAction->setStatusTip(tr("Lock wallet"));
324 lockWalletAction->setCheckable(true);
326 unlockWalletAction = new QAction(QIcon(":/icons/lock_open"), tr("Unlo&ck wallet"), this);
327 unlockWalletAction->setStatusTip(tr("Unlock wallet"));
328 unlockWalletAction->setCheckable(true);
330 unlockWalletMiningAction = new QAction(QIcon(":/icons/mining_active"), tr("Unlo&ck wallet for mining"), this);
331 unlockWalletMiningAction->setStatusTip(tr("Unlock wallet for mining"));
332 unlockWalletMiningAction->setCheckable(true);
334 exportAction = new QAction(QIcon(":/icons/export"), tr("&Export..."), this);
335 exportAction->setStatusTip(tr("Export the data in the current tab to a file"));
336 openRPCConsoleAction = new QAction(QIcon(":/icons/debugwindow"), tr("&Debug window"), this);
337 openRPCConsoleAction->setStatusTip(tr("Open debugging and diagnostic console"));
339 connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
340 connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked()));
341 connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
342 connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked()));
343 connect(toggleHideAction, SIGNAL(triggered()), this, SLOT(toggleHidden()));
344 connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool)));
345 connect(lockWalletAction, SIGNAL(triggered(bool)), this, SLOT(lockWallet()));
346 connect(unlockWalletAction, SIGNAL(triggered(bool)), this, SLOT(unlockWallet()));
347 connect(unlockWalletMiningAction, SIGNAL(triggered(bool)), this, SLOT(unlockWalletMining(bool)));
348 connect(backupWalletAction, SIGNAL(triggered()), this, SLOT(backupWallet()));
349 connect(dumpWalletAction, SIGNAL(triggered()), this, SLOT(dumpWallet()));
350 connect(importWalletAction, SIGNAL(triggered()), this, SLOT(importWallet()));
351 connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase()));
352 connect(signMessageAction, SIGNAL(triggered()), this, SLOT(gotoSignMessageTab()));
353 connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(gotoVerifyMessageTab()));
356 void BitcoinGUI::createMenuBar()
359 // Create a decoupled menu bar on Mac which stays even if the window is closed
360 appMenuBar = new QMenuBar();
362 // Get the main window's menu bar on other platforms
363 appMenuBar = menuBar();
366 // Configure the menus
367 QMenu *file = appMenuBar->addMenu(tr("&File"));
368 file->addAction(backupWalletAction);
369 file->addSeparator();
370 file->addAction(dumpWalletAction);
371 file->addAction(importWalletAction);
372 file->addAction(exportAction);
373 file->addAction(signMessageAction);
374 file->addAction(verifyMessageAction);
375 file->addAction(multisigAction);
376 file->addSeparator();
377 file->addAction(quitAction);
379 QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
380 QMenu *securityMenu = settings->addMenu(QIcon(":/icons/key"), tr("&Wallet security"));
381 securityMenu->addAction(encryptWalletAction);
382 securityMenu->addAction(changePassphraseAction);
383 securityMenu->addAction(unlockWalletAction);
384 securityMenu->addAction(unlockWalletMiningAction);
385 securityMenu->addAction(lockWalletAction);
386 settings->addAction(optionsAction);
388 QMenu *help = appMenuBar->addMenu(tr("&Help"));
389 help->addAction(openRPCConsoleAction);
390 help->addSeparator();
391 help->addAction(aboutAction);
392 help->addAction(aboutQtAction);
395 void BitcoinGUI::createToolBars()
397 QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));
398 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
399 toolbar->addAction(overviewAction);
400 toolbar->addAction(sendCoinsAction);
401 toolbar->addAction(receiveCoinsAction);
402 toolbar->addAction(historyAction);
403 toolbar->addAction(mintingAction);
404 toolbar->addAction(addressBookAction);
406 QToolBar *toolbar2 = addToolBar(tr("Actions toolbar"));
407 toolbar2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
408 toolbar2->addAction(exportAction);
409 toolbar2->setVisible(false);
413 void BitcoinGUI::setClientModel(ClientModel *clientModel)
415 this->clientModel = clientModel;
418 // Replace some strings and icons, when using the testnet
419 if(clientModel->isTestNet())
421 setWindowTitle(windowTitle() + QString(" ") + tr("[testnet]"));
423 qApp->setWindowIcon(QIcon(":icons/bitcoin_testnet"));
424 setWindowIcon(QIcon(":icons/bitcoin_testnet"));
426 MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
430 trayIcon->setToolTip(tr("NovaCoin client") + QString(" ") + tr("[testnet]"));
431 trayIcon->setIcon(QIcon(":/icons/toolbar_testnet"));
432 toggleHideAction->setIcon(QIcon(":/icons/toolbar_testnet"));
435 aboutAction->setIcon(QIcon(":/icons/toolbar_testnet"));
438 // Keep up to date with client
439 setNumConnections(clientModel->getNumConnections());
440 connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
442 setNumBlocks(clientModel->getNumBlocks(), clientModel->getNumBlocksOfPeers());
443 connect(clientModel, SIGNAL(numBlocksChanged(int,int)), this, SLOT(setNumBlocks(int,int)));
445 QTimer *timer = new QTimer(this);
446 connect(timer, SIGNAL(timeout()), this, SLOT(updateMining()));
447 timer->start(10*1000); //10 seconds
449 // Report errors from network/worker thread
450 connect(clientModel, SIGNAL(error(QString,QString,bool)), this, SLOT(error(QString,QString,bool)));
452 rpcConsole->setClientModel(clientModel);
453 addressBookPage->setOptionsModel(clientModel->getOptionsModel());
454 receiveCoinsPage->setOptionsModel(clientModel->getOptionsModel());
458 void BitcoinGUI::setWalletModel(WalletModel *walletModel)
460 this->walletModel = walletModel;
463 // Report errors from wallet thread
464 connect(walletModel, SIGNAL(error(QString,QString,bool)), this, SLOT(error(QString,QString,bool)));
466 // Put transaction list in tabs
467 transactionView->setModel(walletModel);
468 mintingView->setModel(walletModel);
470 overviewPage->setModel(walletModel);
471 addressBookPage->setModel(walletModel->getAddressTableModel());
472 receiveCoinsPage->setModel(walletModel->getAddressTableModel());
473 sendCoinsPage->setModel(walletModel);
474 signVerifyMessageDialog->setModel(walletModel);
475 multisigPage->setModel(walletModel);
477 setEncryptionStatus(walletModel->getEncryptionStatus());
478 connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));
479 connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(updateMining()));
481 // Balloon pop-up for new transaction
482 connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
483 this, SLOT(incomingTransaction(QModelIndex,int,int)));
485 // Ask for passphrase if needed
486 connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
490 void BitcoinGUI::createTrayIcon()
494 trayIcon = new QSystemTrayIcon(this);
495 trayIconMenu = new QMenu(this);
496 trayIcon->setContextMenu(trayIconMenu);
497 trayIcon->setToolTip(tr("NovaCoin client"));
498 trayIcon->setIcon(QIcon(":/icons/toolbar"));
499 connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
500 this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
503 // Note: On Mac, the dock icon is used to provide the tray's functionality.
504 MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance();
505 dockIconHandler->setMainWindow((QMainWindow *)this);
506 trayIconMenu = dockIconHandler->dockMenu();
509 // Configuration of the tray icon (or dock icon) icon menu
510 trayIconMenu->addAction(toggleHideAction);
511 trayIconMenu->addSeparator();
512 trayIconMenu->addAction(sendCoinsAction);
513 trayIconMenu->addAction(multisigAction);
514 trayIconMenu->addAction(receiveCoinsAction);
515 trayIconMenu->addSeparator();
516 trayIconMenu->addAction(signMessageAction);
517 trayIconMenu->addAction(verifyMessageAction);
518 trayIconMenu->addSeparator();
519 trayIconMenu->addAction(optionsAction);
520 trayIconMenu->addAction(openRPCConsoleAction);
522 // This is built-in on Mac
523 trayIconMenu->addSeparator();
524 trayIconMenu->addAction(quitAction);
526 notificator = new Notificator(QApplication::applicationName(), trayIcon, this);
530 void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
532 if(reason == QSystemTrayIcon::Trigger)
534 // Click on system tray icon triggers show/hide of the main window
535 toggleHideAction->trigger();
540 void BitcoinGUI::optionsClicked()
542 if(!clientModel || !clientModel->getOptionsModel())
545 optionsDialog->setModel(clientModel->getOptionsModel());
546 optionsDialog->setWindowModality(Qt::ApplicationModal);
547 optionsDialog->show();
550 void BitcoinGUI::aboutClicked()
552 aboutDialog->setModel(clientModel);
553 aboutDialog->setWindowModality(Qt::ApplicationModal);
557 void BitcoinGUI::setNumConnections(int count)
562 case 0: icon = ":/icons/connect_0"; break;
563 case 1: case 2: case 3: icon = ":/icons/connect_1"; break;
564 case 4: case 5: case 6: icon = ":/icons/connect_2"; break;
565 case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
566 default: icon = ":/icons/connect_4"; break;
568 labelConnectionsIcon->setPixmap(QIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
569 labelConnectionsIcon->setToolTip(tr("%n active connection(s) to NovaCoin network", "", count));
572 void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks)
574 // don't show / hide progress bar and its label if we have no connection to the network
575 if (!clientModel || clientModel->getNumConnections() == 0)
577 progressBarLabel->setVisible(false);
578 progressBar->setVisible(false);
583 QString strStatusBarWarnings = clientModel->getStatusBarWarnings();
586 if(count < nTotalBlocks)
588 int nRemainingBlocks = nTotalBlocks - count;
589 float nPercentageDone = count / (nTotalBlocks * 0.01f);
591 if (strStatusBarWarnings.isEmpty())
593 progressBarLabel->setText(tr("Synchronizing with network..."));
594 progressBarLabel->setVisible(true);
595 progressBar->setFormat(tr("~%n block(s) remaining", "", nRemainingBlocks));
596 progressBar->setMaximum(nTotalBlocks);
597 progressBar->setValue(count);
598 progressBar->setVisible(true);
601 tooltip = tr("Downloaded %1 of %2 blocks of transaction history (%3% done).").arg(count).arg(nTotalBlocks).arg(nPercentageDone, 0, 'f', 2);
605 if (strStatusBarWarnings.isEmpty())
606 progressBarLabel->setVisible(false);
608 progressBar->setVisible(false);
609 tooltip = tr("Downloaded %1 blocks of transaction history.").arg(count);
612 // Override progressBarLabel text and hide progress bar, when we have warnings to display
613 if (!strStatusBarWarnings.isEmpty())
615 progressBarLabel->setText(strStatusBarWarnings);
616 progressBarLabel->setVisible(true);
617 progressBar->setVisible(false);
620 QDateTime lastBlockDate = clientModel->getLastBlockDate();
621 int secs = lastBlockDate.secsTo(QDateTime::currentDateTime());
624 // Represent time from last generated block in human readable text
627 // Fully up to date. Leave text empty.
631 text = tr("%n second(s) ago","",secs);
633 else if(secs < 60*60)
635 text = tr("%n minute(s) ago","",secs/60);
637 else if(secs < 24*60*60)
639 text = tr("%n hour(s) ago","",secs/(60*60));
643 text = tr("%n day(s) ago","",secs/(60*60*24));
646 // Set icon state: spinning if catching up, tick otherwise
647 if(secs < 90*60 && count >= nTotalBlocks)
649 tooltip = tr("Up to date") + QString(".<br>") + tooltip;
650 labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
652 overviewPage->showOutOfSyncWarning(false);
656 tooltip = tr("Catching up...") + QString("<br>") + tooltip;
657 labelBlocksIcon->setMovie(syncIconMovie);
658 syncIconMovie->start();
660 overviewPage->showOutOfSyncWarning(true);
665 tooltip += QString("<br>");
666 tooltip += tr("Last received block was generated %1.").arg(text);
669 // Don't word-wrap this (fixed-width) tooltip
670 tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
672 labelBlocksIcon->setToolTip(tooltip);
673 progressBarLabel->setToolTip(tooltip);
674 progressBar->setToolTip(tooltip);
677 void BitcoinGUI::updateMining()
682 labelMiningIcon->setPixmap(QIcon(":/icons/mining_inactive").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
684 if (!clientModel->getNumConnections())
686 labelMiningIcon->setToolTip(tr("Wallet is offline"));
690 if (walletModel->getEncryptionStatus() == WalletModel::Locked)
692 labelMiningIcon->setToolTip(tr("Wallet is locked"));
696 if (clientModel->inInitialBlockDownload() || clientModel->getNumBlocksOfPeers() > clientModel->getNumBlocks())
698 labelMiningIcon->setToolTip(tr("Blockchain download is in progress"));
702 float nKernelsRate = 0, nCoinDaysRate = 0;
703 walletModel->getStakeStats(nKernelsRate, nCoinDaysRate);
705 if (nKernelsRate > 0)
707 labelMiningIcon->setPixmap(QIcon(":/icons/mining_active").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
709 uint64_t nNetworkWeight = clientModel->getPoSKernelPS();
711 double dDifficulty = clientModel->getDifficulty(true);
714 int nApproxTime = 4294967297 * dDifficulty / nTotalWeight;
716 if (nApproxTime < 60)
717 msg = tr("%n second(s)", "", nApproxTime);
718 else if (nApproxTime < 60*60)
719 msg = tr("%n minute(s)", "", nApproxTime / 60);
720 else if (nApproxTime < 24*60*60)
721 msg = tr("%n hour(s)", "", nApproxTime / 3600);
723 msg = tr("%n day(s)", "", nApproxTime / 86400);
725 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));
728 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>"));
731 labelMiningIcon->setToolTip(tr("No suitable inputs were found"));
734 void BitcoinGUI::error(const QString &title, const QString &message, bool modal)
736 // Report errors from network/worker thread
739 QMessageBox::critical(this, title, message, QMessageBox::Ok, QMessageBox::Ok);
741 notificator->notify(Notificator::Critical, title, message);
745 void BitcoinGUI::message(const QString &title, const QString &message, unsigned int style, const QString &detail)
747 QString strTitle = tr("NovaCoin") + " - ";
748 // Default to information icon
749 int nMBoxIcon = QMessageBox::Information;
750 int nNotifyIcon = Notificator::Information;
753 // Check for usage of predefined title
755 case CClientUIInterface::MSG_ERROR:
756 strTitle += tr("Error");
758 case CClientUIInterface::MSG_WARNING:
759 strTitle += tr("Warning");
761 case CClientUIInterface::MSG_INFORMATION:
762 strTitle += tr("Information");
765 strTitle += title; // Use supplied title
768 // Check for error/warning icon
769 if (style & CClientUIInterface::ICON_ERROR) {
770 nMBoxIcon = QMessageBox::Critical;
771 nNotifyIcon = Notificator::Critical;
773 else if (style & CClientUIInterface::ICON_WARNING) {
774 nMBoxIcon = QMessageBox::Warning;
775 nNotifyIcon = Notificator::Warning;
779 if (style & CClientUIInterface::MODAL) {
780 // Check for buttons, use OK as default, if none was supplied
781 QMessageBox::StandardButton buttons;
782 buttons = QMessageBox::Ok;
784 QMessageBox mBox((QMessageBox::Icon)nMBoxIcon, strTitle, message, buttons);
786 if(!detail.isEmpty()) { mBox.setDetailedText(detail); }
791 notificator->notify((Notificator::Class)nNotifyIcon, strTitle, message);
795 void BitcoinGUI::changeEvent(QEvent *e)
797 QMainWindow::changeEvent(e);
798 #ifndef Q_OS_MAC // Ignored on Mac
799 if(e->type() == QEvent::WindowStateChange)
801 if(clientModel && clientModel->getOptionsModel()->getMinimizeToTray())
803 QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
804 if(!(wsevt->oldState() & Qt::WindowMinimized) && isMinimized())
806 QTimer::singleShot(0, this, SLOT(hide()));
814 void BitcoinGUI::closeEvent(QCloseEvent *event)
818 #ifndef Q_OS_MAC // Ignored on Mac
819 if(!clientModel->getOptionsModel()->getMinimizeOnClose())
825 // close rpcConsole in case it was open to make some space for the shutdown window
828 QMainWindow::closeEvent(event);
831 void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
834 tr("This transaction is over the size limit. You can still send it for a fee of %1, "
835 "which goes to the nodes that process your transaction and helps to support the network. "
836 "Do you want to pay the fee?").arg(
837 BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nFeeRequired));
838 QMessageBox::StandardButton retval = QMessageBox::question(
839 this, tr("Confirm transaction fee"), strMessage,
840 QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes);
841 *payFee = (retval == QMessageBox::Yes);
844 void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
846 if(!walletModel || !clientModel)
848 TransactionTableModel *ttm = walletModel->getTransactionTableModel();
849 qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
850 .data(Qt::EditRole).toULongLong();
851 if(!clientModel->inInitialBlockDownload())
853 // On new transaction, make an info balloon
854 // Unless the initial block download is in progress, to prevent balloon-spam
855 QString date = ttm->index(start, TransactionTableModel::Date, parent)
857 QString type = ttm->index(start, TransactionTableModel::Type, parent)
859 QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
861 QIcon icon = qvariant_cast<QIcon>(ttm->index(start,
862 TransactionTableModel::ToAddress, parent)
863 .data(Qt::DecorationRole));
865 notificator->notify(Notificator::Information,
866 (amount)<0 ? tr("Sent transaction") :
867 tr("Incoming transaction"),
873 .arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true))
875 .arg(address), icon);
879 void BitcoinGUI::gotoOverviewPage()
881 overviewAction->setChecked(true);
882 centralWidget->setCurrentWidget(overviewPage);
884 exportAction->setEnabled(false);
885 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
888 void BitcoinGUI::gotoHistoryPage()
890 historyAction->setChecked(true);
891 centralWidget->setCurrentWidget(transactionsPage);
893 exportAction->setEnabled(true);
894 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
895 connect(exportAction, SIGNAL(triggered()), transactionView, SLOT(exportClicked()));
898 void BitcoinGUI::gotoMintingPage()
900 mintingAction->setChecked(true);
901 centralWidget->setCurrentWidget(mintingPage);
903 exportAction->setEnabled(true);
904 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
905 connect(exportAction, SIGNAL(triggered()), mintingView, SLOT(exportClicked()));
909 void BitcoinGUI::gotoAddressBookPage()
911 addressBookAction->setChecked(true);
912 centralWidget->setCurrentWidget(addressBookPage);
914 exportAction->setEnabled(true);
915 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
916 connect(exportAction, SIGNAL(triggered()), addressBookPage, SLOT(exportClicked()));
919 void BitcoinGUI::gotoReceiveCoinsPage()
921 receiveCoinsAction->setChecked(true);
922 centralWidget->setCurrentWidget(receiveCoinsPage);
924 exportAction->setEnabled(true);
925 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
926 connect(exportAction, SIGNAL(triggered()), receiveCoinsPage, SLOT(exportClicked()));
929 void BitcoinGUI::gotoSendCoinsPage()
931 sendCoinsAction->setChecked(true);
932 centralWidget->setCurrentWidget(sendCoinsPage);
934 exportAction->setEnabled(false);
935 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
938 void BitcoinGUI::gotoSignMessageTab(QString addr)
940 // call show() in showTab_SM()
941 signVerifyMessageDialog->showTab_SM(true);
944 signVerifyMessageDialog->setAddress_SM(addr);
947 void BitcoinGUI::gotoVerifyMessageTab(QString addr)
949 // call show() in showTab_VM()
950 signVerifyMessageDialog->showTab_VM(true);
953 signVerifyMessageDialog->setAddress_VM(addr);
956 void BitcoinGUI::gotoMultisigPage()
958 multisigPage->show();
959 multisigPage->setFocus();
962 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
965 if(event->mimeData()->hasUrls())
966 event->acceptProposedAction();
969 void BitcoinGUI::dropEvent(QDropEvent *event)
971 if(event->mimeData()->hasUrls())
973 int nValidUrisFound = 0;
974 QList<QUrl> uris = event->mimeData()->urls();
975 foreach(const QUrl &uri, uris)
977 if (sendCoinsPage->handleURI(uri.toString()))
981 // if valid URIs were found
985 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."));
988 event->acceptProposedAction();
991 void BitcoinGUI::handleURI(QString strURI)
993 // URI has to be valid
994 if (sendCoinsPage->handleURI(strURI))
996 showNormalIfMinimized();
1000 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."));
1003 void BitcoinGUI::setEncryptionStatus(int status)
1007 case WalletModel::Unencrypted:
1008 labelEncryptionIcon->hide();
1009 encryptWalletAction->setChecked(false);
1010 changePassphraseAction->setEnabled(false);
1011 lockWalletAction->setEnabled(false);
1012 unlockWalletAction->setEnabled(false);
1013 unlockWalletMiningAction->setEnabled(false);
1014 encryptWalletAction->setEnabled(true);
1016 case WalletModel::Unlocked:
1017 labelEncryptionIcon->show();
1018 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
1019 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
1020 encryptWalletAction->setChecked(true);
1021 changePassphraseAction->setEnabled(true);
1022 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
1024 lockWalletAction->setEnabled(true);
1025 lockWalletAction->setChecked(false);
1026 unlockWalletAction->setEnabled(false);
1027 unlockWalletMiningAction->setEnabled(false);
1029 if (fWalletUnlockMintOnly)
1030 unlockWalletMiningAction->setChecked(true);
1032 unlockWalletAction->setChecked(true);
1035 case WalletModel::Locked:
1036 labelEncryptionIcon->show();
1037 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
1038 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
1039 encryptWalletAction->setChecked(true);
1040 changePassphraseAction->setEnabled(true);
1041 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
1043 lockWalletAction->setChecked(true);
1044 unlockWalletAction->setChecked(false);
1045 unlockWalletMiningAction->setChecked(false);
1047 lockWalletAction->setEnabled(false);
1048 unlockWalletAction->setEnabled(true);
1049 unlockWalletMiningAction->setEnabled(true);
1054 void BitcoinGUI::encryptWallet(bool status)
1058 AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt:
1059 AskPassphraseDialog::Decrypt, this);
1060 dlg.setModel(walletModel);
1063 setEncryptionStatus(walletModel->getEncryptionStatus());
1066 void BitcoinGUI::unlockWalletMining(bool status)
1071 // Unlock wallet when requested by wallet model
1072 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1074 AskPassphraseDialog dlg(AskPassphraseDialog::UnlockMining, this);
1075 dlg.setModel(walletModel);
1080 void BitcoinGUI::backupWallet()
1082 #if QT_VERSION < 0x050000
1083 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1085 QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1087 QString filename = QFileDialog::getSaveFileName(this, tr("Backup Wallet"), saveDir, tr("Wallet Data (*.dat)"));
1088 if(!filename.isEmpty()) {
1089 if(!walletModel->backupWallet(filename)) {
1090 QMessageBox::warning(this, tr("Backup Failed"), tr("There was an error trying to save the wallet data to the new location."));
1095 void BitcoinGUI::dumpWallet()
1100 WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1103 // Unlock wallet failed or was cancelled
1107 #if QT_VERSION < 0x050000
1108 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1110 QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1112 QString filename = QFileDialog::getSaveFileName(this, tr("Dump Wallet"), saveDir, tr("Wallet dump (*.txt)"));
1113 if(!filename.isEmpty()) {
1114 if(!walletModel->dumpWallet(filename)) {
1115 error(tr("Dump failed"),
1116 tr("An error happened while trying to save the keys to your location.\n"
1117 "Keys were not saved.")
1118 ,CClientUIInterface::MSG_ERROR);
1121 message(tr("Dump successful"),
1122 tr("Keys were saved to this file:\n%2")
1124 ,CClientUIInterface::MSG_INFORMATION);
1128 void BitcoinGUI::importWallet()
1133 WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1136 // Unlock wallet failed or was cancelled
1140 #if QT_VERSION < 0x050000
1141 QString openDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1143 QString openDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1145 QString filename = QFileDialog::getOpenFileName(this, tr("Import Wallet"), openDir, tr("Wallet dump (*.txt)"));
1146 if(!filename.isEmpty()) {
1147 if(!walletModel->importWallet(filename)) {
1148 error(tr("Import Failed"),
1149 tr("An error happened while trying to import the keys.\n"
1150 "Some or all keys from:\n %1,\n were not imported into your wallet.")
1152 ,CClientUIInterface::MSG_ERROR);
1155 message(tr("Import Successful"),
1156 tr("All keys from:\n %1,\n were imported into your wallet.")
1158 ,CClientUIInterface::MSG_INFORMATION);
1163 void BitcoinGUI::changePassphrase()
1165 AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
1166 dlg.setModel(walletModel);
1170 void BitcoinGUI::unlockWallet()
1174 // Unlock wallet when requested by wallet model
1175 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1177 AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
1178 dlg.setModel(walletModel);
1183 void BitcoinGUI::lockWallet()
1188 walletModel->setWalletLocked(true);
1191 void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden)
1193 // activateWindow() (sometimes) helps with keyboard focus on Windows
1196 // Make sure the window is not minimized
1197 setWindowState(windowState() & (~Qt::WindowMinimized | Qt::WindowActive));
1203 else if (isMinimized())
1209 else if (GUIUtil::isObscured(this))
1216 if (GUIUtil::isObscured(this))
1220 else if(fToggleHidden)
1224 void BitcoinGUI::toggleHidden()
1226 showNormalIfMinimized(true);