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 "secondauthdialog.h"
13 #include "multisigdialog.h"
14 #include "optionsdialog.h"
15 #include "aboutdialog.h"
16 #include "clientmodel.h"
17 #include "walletmodel.h"
18 #include "editaddressdialog.h"
19 #include "optionsmodel.h"
20 #include "transactiondescdialog.h"
21 #include "addresstablemodel.h"
22 #include "transactionview.h"
23 #include "overviewpage.h"
24 #include "bitcoinunits.h"
25 #include "guiconstants.h"
26 #include "askpassphrasedialog.h"
27 #include "notificator.h"
29 #include "ui_interface.h"
30 #include "rpcconsole.h"
31 #include "mintingview.h"
34 #include "macdockiconhandler.h"
37 #include <QApplication>
38 #if QT_VERSION < 0x050000
39 #include <QMainWindow>
45 #include <QVBoxLayout>
50 #include <QPushButton>
52 #include <QMessageBox>
53 #include <QProgressBar>
54 #include <QStackedWidget>
57 #include <QFileDialog>
58 #if QT_VERSION < 0x050000
59 #include <QDesktopServices>
61 #include <QStandardPaths>
64 #include <QDragEnterEvent>
65 #if QT_VERSION < 0x050000
73 extern bool fWalletUnlockMintOnly;
74 extern uint64_t nStakeInputsMapSize;
76 BitcoinGUI::BitcoinGUI(QWidget *parent):
80 signVerifyMessageDialog(0),
83 encryptWalletAction(0),
85 unlockWalletAction(0),
86 unlockWalletMiningAction(0),
87 changePassphraseAction(0),
96 setWindowTitle(tr("NovaCoin") + " - " + tr("Wallet"));
98 qApp->setWindowIcon(QIcon(":icons/bitcoin"));
99 setWindowIcon(QIcon(":icons/bitcoin"));
101 setUnifiedTitleAndToolBarOnMac(true);
102 QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
104 // Accept D&D of URIs
105 setAcceptDrops(true);
107 // Create actions for the toolbar, menu bar and tray/dock icon
110 // Create application menu bar
113 // Create the toolbars
116 // Create the tray icon (or setup the dock icon)
120 overviewPage = new OverviewPage();
122 transactionsPage = new QWidget(this);
123 QVBoxLayout *vbox = new QVBoxLayout();
124 transactionView = new TransactionView(this);
125 vbox->addWidget(transactionView);
126 transactionsPage->setLayout(vbox);
128 mintingPage = new QWidget(this);
129 QVBoxLayout *vboxMinting = new QVBoxLayout();
130 mintingView = new MintingView(this);
131 vboxMinting->addWidget(mintingView);
132 mintingPage->setLayout(vboxMinting);
134 addressBookPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::SendingTab);
136 receiveCoinsPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::ReceivingTab);
138 sendCoinsPage = new SendCoinsDialog(this);
140 signVerifyMessageDialog = new SignVerifyMessageDialog(0);
142 secondAuthDialog = new SecondAuthDialog(0);
144 multisigPage = new MultisigDialog(0);
146 centralWidget = new QStackedWidget(this);
147 centralWidget->addWidget(overviewPage);
148 centralWidget->addWidget(transactionsPage);
149 centralWidget->addWidget(mintingPage);
150 centralWidget->addWidget(addressBookPage);
151 centralWidget->addWidget(receiveCoinsPage);
152 centralWidget->addWidget(sendCoinsPage);
153 setCentralWidget(centralWidget);
158 // Status bar notification icons
159 QFrame *frameBlocks = new QFrame();
160 frameBlocks->setContentsMargins(0,0,0,0);
161 frameBlocks->setMinimumWidth(72);
162 frameBlocks->setMaximumWidth(72);
163 QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);
164 frameBlocksLayout->setContentsMargins(3,0,3,0);
165 frameBlocksLayout->setSpacing(3);
166 labelEncryptionIcon = new QLabel();
167 labelMiningIcon = new QLabel();
168 labelConnectionsIcon = new QLabel();
169 labelBlocksIcon = new QLabel();
170 frameBlocksLayout->addStretch();
171 frameBlocksLayout->addWidget(labelEncryptionIcon);
172 frameBlocksLayout->addStretch();
173 frameBlocksLayout->addWidget(labelMiningIcon);
174 frameBlocksLayout->addStretch();
175 frameBlocksLayout->addWidget(labelConnectionsIcon);
176 frameBlocksLayout->addStretch();
177 frameBlocksLayout->addWidget(labelBlocksIcon);
178 frameBlocksLayout->addStretch();
180 // Progress bar and label for blocks download
181 progressBarLabel = new QLabel();
182 progressBarLabel->setVisible(false);
183 progressBar = new QProgressBar();
184 progressBar->setAlignment(Qt::AlignCenter);
185 progressBar->setVisible(false);
187 // Override style sheet for progress bar for styles that have a segmented progress bar,
188 // as they make the text unreadable (workaround for issue #1071)
189 // See https://qt-project.org/doc/qt-4.8/gallery.html
190 QString curStyle = qApp->style()->metaObject()->className();
191 if(curStyle == "QWindowsStyle" || curStyle == "QWindowsXPStyle")
193 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; }");
196 statusBar()->addWidget(progressBarLabel);
197 statusBar()->addWidget(progressBar);
198 statusBar()->addPermanentWidget(frameBlocks);
200 syncIconMovie = new QMovie(":/movies/update_spinner", "mng", this);
202 // Clicking on a transaction on the overview page simply sends you to transaction history page
203 connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), this, SLOT(gotoHistoryPage()));
204 connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex)));
206 // Double-clicking on a transaction on the transaction history page shows details
207 connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
209 rpcConsole = new RPCConsole(0);
210 connect(openRPCConsoleAction, SIGNAL(triggered()), rpcConsole, SLOT(show()));
211 connect(openRPCConsoleAction, SIGNAL(triggered()), rpcConsole, SLOT(raise()));
213 aboutDialog = new AboutDialog(0);
214 optionsDialog = new OptionsDialog(0);
216 // Clicking on "Verify Message" in the address book sends you to the verify message tab
217 connect(addressBookPage, SIGNAL(verifyMessage(QString)), this, SLOT(gotoVerifyMessageTab(QString)));
218 // Clicking on "Sign Message" in the receive coins page sends you to the sign message tab
219 connect(receiveCoinsPage, SIGNAL(signMessage(QString)), this, SLOT(gotoSignMessageTab(QString)));
224 BitcoinGUI::~BitcoinGUI()
226 if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu)
234 delete optionsDialog;
236 delete secondAuthDialog;
237 delete signVerifyMessageDialog;
240 void BitcoinGUI::createActions()
242 QActionGroup *tabGroup = new QActionGroup(this);
244 overviewAction = new QAction(QIcon(":/icons/overview"), tr("&Overview"), this);
245 overviewAction->setToolTip(tr("Show general overview of wallet"));
246 overviewAction->setCheckable(true);
247 overviewAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_1));
248 tabGroup->addAction(overviewAction);
250 sendCoinsAction = new QAction(QIcon(":/icons/send"), tr("&Send coins"), this);
251 sendCoinsAction->setToolTip(tr("Send coins to a NovaCoin address"));
252 sendCoinsAction->setCheckable(true);
253 sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2));
254 tabGroup->addAction(sendCoinsAction);
256 receiveCoinsAction = new QAction(QIcon(":/icons/receiving_addresses"), tr("&Receive coins"), this);
257 receiveCoinsAction->setToolTip(tr("Show the list of addresses for receiving payments"));
258 receiveCoinsAction->setCheckable(true);
259 receiveCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_3));
260 tabGroup->addAction(receiveCoinsAction);
262 historyAction = new QAction(QIcon(":/icons/history"), tr("&Transactions"), this);
263 historyAction->setToolTip(tr("Browse transaction history"));
264 historyAction->setCheckable(true);
265 historyAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_4));
266 tabGroup->addAction(historyAction);
268 mintingAction = new QAction(QIcon(":/icons/history"), tr("&Minting"), this);
269 mintingAction->setToolTip(tr("Show your minting capacity"));
270 mintingAction->setCheckable(true);
271 mintingAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_5));
272 tabGroup->addAction(mintingAction);
274 addressBookAction = new QAction(QIcon(":/icons/address-book"), tr("&Address Book"), this);
275 addressBookAction->setToolTip(tr("Edit the list of stored addresses and labels"));
276 addressBookAction->setCheckable(true);
277 addressBookAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_6));
278 tabGroup->addAction(addressBookAction);
280 multisigAction = new QAction(QIcon(":/icons/send"), tr("Multisig"), this);
281 multisigAction->setStatusTip(tr("Open window for working with multisig addresses"));
282 tabGroup->addAction(multisigAction);
284 connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
285 connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage()));
286 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
287 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
288 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
289 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
290 connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
291 connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage()));
292 connect(mintingAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
293 connect(mintingAction, SIGNAL(triggered()), this, SLOT(gotoMintingPage()));
294 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
295 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(gotoAddressBookPage()));
296 connect(multisigAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
297 connect(multisigAction, SIGNAL(triggered()), this, SLOT(gotoMultisigPage()));
299 quitAction = new QAction(QIcon(":/icons/quit"), tr("E&xit"), this);
300 quitAction->setStatusTip(tr("Quit application"));
301 quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
302 quitAction->setMenuRole(QAction::QuitRole);
303 aboutAction = new QAction(QIcon(":/icons/bitcoin"), tr("&About NovaCoin"), this);
304 aboutAction->setStatusTip(tr("Show information about NovaCoin"));
305 aboutAction->setMenuRole(QAction::AboutRole);
306 #if QT_VERSION < 0x050000
307 aboutQtAction = new QAction(QIcon(":/trolltech/qmessagebox/images/qtlogo-64.png"), tr("About &Qt"), this);
309 aboutQtAction = new QAction(QIcon(":/qt-project.org/qmessagebox/images/qtlogo-64.png"), tr("About &Qt"), this);
311 aboutQtAction->setStatusTip(tr("Show information about Qt"));
312 aboutQtAction->setMenuRole(QAction::AboutQtRole);
313 optionsAction = new QAction(QIcon(":/icons/options"), tr("&Options..."), this);
314 optionsAction->setStatusTip(tr("Modify configuration options for NovaCoin"));
315 optionsAction->setMenuRole(QAction::PreferencesRole);
316 toggleHideAction = new QAction(QIcon(":/icons/bitcoin"), tr("&Show / Hide"), this);
317 encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet..."), this);
318 encryptWalletAction->setStatusTip(tr("Encrypt or decrypt wallet"));
319 encryptWalletAction->setCheckable(true);
320 backupWalletAction = new QAction(QIcon(":/icons/filesave"), tr("&Backup Wallet..."), this);
321 backupWalletAction->setStatusTip(tr("Backup wallet to another location"));
322 dumpWalletAction = new QAction(QIcon(":/icons/dump"), tr("&Dump Wallet..."), this);
323 dumpWalletAction->setStatusTip(tr("Dump keys to a text file"));
324 importWalletAction = new QAction(QIcon(":/icons/import"), tr("&Import Wallet..."), this);
325 importWalletAction->setStatusTip(tr("Import keys into a wallet"));
326 changePassphraseAction = new QAction(QIcon(":/icons/key"), tr("&Change Passphrase..."), this);
327 changePassphraseAction->setStatusTip(tr("Change the passphrase used for wallet encryption"));
328 signMessageAction = new QAction(QIcon(":/icons/edit"), tr("Sign &message..."), this);
329 signMessageAction->setStatusTip(tr("Sign messages with your Novacoin addresses to prove you own them"));
330 verifyMessageAction = new QAction(QIcon(":/icons/transaction_0"), tr("&Verify message..."), this);
331 verifyMessageAction->setStatusTip(tr("Verify messages to ensure they were signed with specified Novacoin addresses"));
332 secondAuthAction = new QAction(QIcon(":/icons/key"), tr("Second &auth..."), this);
333 secondAuthAction->setStatusTip(tr("Second auth with your Novacoin addresses"));
335 lockWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Lock wallet"), this);
336 lockWalletAction->setStatusTip(tr("Lock wallet"));
337 lockWalletAction->setCheckable(true);
339 unlockWalletAction = new QAction(QIcon(":/icons/lock_open"), tr("Unlo&ck wallet"), this);
340 unlockWalletAction->setStatusTip(tr("Unlock wallet"));
341 unlockWalletAction->setCheckable(true);
343 unlockWalletMiningAction = new QAction(QIcon(":/icons/mining_active"), tr("Unlo&ck wallet for mining"), this);
344 unlockWalletMiningAction->setStatusTip(tr("Unlock wallet for mining"));
345 unlockWalletMiningAction->setCheckable(true);
347 exportAction = new QAction(QIcon(":/icons/export"), tr("&Export..."), this);
348 exportAction->setStatusTip(tr("Export the data in the current tab to a file"));
349 openRPCConsoleAction = new QAction(QIcon(":/icons/debugwindow"), tr("&Debug window"), this);
350 openRPCConsoleAction->setStatusTip(tr("Open debugging and diagnostic console"));
352 connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
353 connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked()));
354 connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
355 connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked()));
356 connect(toggleHideAction, SIGNAL(triggered()), this, SLOT(toggleHidden()));
357 connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool)));
358 connect(lockWalletAction, SIGNAL(triggered(bool)), this, SLOT(lockWallet()));
359 connect(unlockWalletAction, SIGNAL(triggered(bool)), this, SLOT(unlockWallet()));
360 connect(unlockWalletMiningAction, SIGNAL(triggered(bool)), this, SLOT(unlockWalletMining(bool)));
361 connect(backupWalletAction, SIGNAL(triggered()), this, SLOT(backupWallet()));
362 connect(dumpWalletAction, SIGNAL(triggered()), this, SLOT(dumpWallet()));
363 connect(importWalletAction, SIGNAL(triggered()), this, SLOT(importWallet()));
364 connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase()));
365 connect(signMessageAction, SIGNAL(triggered()), this, SLOT(gotoSignMessageTab()));
366 connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(gotoVerifyMessageTab()));
367 connect(secondAuthAction, SIGNAL(triggered()), this, SLOT(gotoSecondAuthPage()));
370 void BitcoinGUI::createMenuBar()
373 // Create a decoupled menu bar on Mac which stays even if the window is closed
374 appMenuBar = new QMenuBar();
376 // Get the main window's menu bar on other platforms
377 appMenuBar = menuBar();
380 // Configure the menus
381 QMenu *file = appMenuBar->addMenu(tr("&File"));
382 file->addAction(backupWalletAction);
383 file->addSeparator();
384 file->addAction(dumpWalletAction);
385 file->addAction(importWalletAction);
386 file->addAction(exportAction);
387 file->addAction(signMessageAction);
388 file->addAction(verifyMessageAction);
389 file->addAction(secondAuthAction);
390 file->addAction(multisigAction);
391 file->addSeparator();
392 file->addAction(quitAction);
394 QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
395 QMenu *securityMenu = settings->addMenu(QIcon(":/icons/key"), tr("&Wallet security"));
396 securityMenu->addAction(encryptWalletAction);
397 securityMenu->addAction(changePassphraseAction);
398 securityMenu->addAction(unlockWalletAction);
399 securityMenu->addAction(unlockWalletMiningAction);
400 securityMenu->addAction(lockWalletAction);
401 settings->addAction(optionsAction);
403 QMenu *help = appMenuBar->addMenu(tr("&Help"));
404 help->addAction(openRPCConsoleAction);
405 help->addSeparator();
406 help->addAction(aboutAction);
407 help->addAction(aboutQtAction);
410 void BitcoinGUI::createToolBars()
412 QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));
413 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
414 toolbar->addAction(overviewAction);
415 toolbar->addAction(sendCoinsAction);
416 toolbar->addAction(receiveCoinsAction);
417 toolbar->addAction(historyAction);
418 toolbar->addAction(mintingAction);
419 toolbar->addAction(addressBookAction);
421 QToolBar *toolbar2 = addToolBar(tr("Actions toolbar"));
422 toolbar2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
423 toolbar2->addAction(exportAction);
424 toolbar2->setVisible(false);
428 void BitcoinGUI::setClientModel(ClientModel *clientModel)
430 this->clientModel = clientModel;
433 // Replace some strings and icons, when using the testnet
434 if(clientModel->isTestNet())
436 setWindowTitle(windowTitle() + QString(" ") + tr("[testnet]"));
438 qApp->setWindowIcon(QIcon(":icons/bitcoin_testnet"));
439 setWindowIcon(QIcon(":icons/bitcoin_testnet"));
441 MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
445 trayIcon->setToolTip(tr("NovaCoin client") + QString(" ") + tr("[testnet]"));
446 trayIcon->setIcon(QIcon(":/icons/toolbar_testnet"));
447 toggleHideAction->setIcon(QIcon(":/icons/toolbar_testnet"));
450 aboutAction->setIcon(QIcon(":/icons/toolbar_testnet"));
453 // Keep up to date with client
454 setNumConnections(clientModel->getNumConnections());
455 connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
457 setNumBlocks(clientModel->getNumBlocks(), clientModel->getNumBlocksOfPeers());
458 connect(clientModel, SIGNAL(numBlocksChanged(int,int)), this, SLOT(setNumBlocks(int,int)));
460 QTimer *timer = new QTimer(this);
461 connect(timer, SIGNAL(timeout()), this, SLOT(updateMining()));
462 timer->start(10*1000); //10 seconds
464 // Report errors from network/worker thread
465 connect(clientModel, SIGNAL(error(QString,QString,bool)), this, SLOT(error(QString,QString,bool)));
467 rpcConsole->setClientModel(clientModel);
468 addressBookPage->setOptionsModel(clientModel->getOptionsModel());
469 receiveCoinsPage->setOptionsModel(clientModel->getOptionsModel());
473 void BitcoinGUI::setWalletModel(WalletModel *walletModel)
475 this->walletModel = walletModel;
478 // Report errors from wallet thread
479 connect(walletModel, SIGNAL(error(QString,QString,bool)), this, SLOT(error(QString,QString,bool)));
481 // Put transaction list in tabs
482 transactionView->setModel(walletModel);
483 mintingView->setModel(walletModel);
485 overviewPage->setModel(walletModel);
486 addressBookPage->setModel(walletModel->getAddressTableModel());
487 receiveCoinsPage->setModel(walletModel->getAddressTableModel());
488 sendCoinsPage->setModel(walletModel);
489 signVerifyMessageDialog->setModel(walletModel);
490 secondAuthDialog->setModel(walletModel);
491 multisigPage->setModel(walletModel);
493 setEncryptionStatus(walletModel->getEncryptionStatus());
494 connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));
495 connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(updateMining()));
497 // Balloon pop-up for new transaction
498 connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
499 this, SLOT(incomingTransaction(QModelIndex,int,int)));
501 // Ask for passphrase if needed
502 connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
506 void BitcoinGUI::createTrayIcon()
510 trayIcon = new QSystemTrayIcon(this);
511 trayIconMenu = new QMenu(this);
512 trayIcon->setContextMenu(trayIconMenu);
513 trayIcon->setToolTip(tr("NovaCoin client"));
514 trayIcon->setIcon(QIcon(":/icons/toolbar"));
515 connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
516 this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
519 // Note: On Mac, the dock icon is used to provide the tray's functionality.
520 MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance();
521 dockIconHandler->setMainWindow((QMainWindow *)this);
522 trayIconMenu = dockIconHandler->dockMenu();
525 // Configuration of the tray icon (or dock icon) icon menu
526 trayIconMenu->addAction(toggleHideAction);
527 trayIconMenu->addSeparator();
528 trayIconMenu->addAction(sendCoinsAction);
529 trayIconMenu->addAction(multisigAction);
530 trayIconMenu->addAction(receiveCoinsAction);
531 trayIconMenu->addSeparator();
532 trayIconMenu->addAction(signMessageAction);
533 trayIconMenu->addAction(verifyMessageAction);
534 trayIconMenu->addAction(secondAuthAction);
535 trayIconMenu->addSeparator();
536 trayIconMenu->addAction(optionsAction);
537 trayIconMenu->addAction(openRPCConsoleAction);
539 // This is built-in on Mac
540 trayIconMenu->addSeparator();
541 trayIconMenu->addAction(quitAction);
543 notificator = new Notificator(QApplication::applicationName(), trayIcon, this);
547 void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
549 if(reason == QSystemTrayIcon::Trigger)
551 // Click on system tray icon triggers show/hide of the main window
552 toggleHideAction->trigger();
557 void BitcoinGUI::optionsClicked()
559 if(!clientModel || !clientModel->getOptionsModel())
562 optionsDialog->setModel(clientModel->getOptionsModel());
563 optionsDialog->setWindowModality(Qt::ApplicationModal);
564 optionsDialog->show();
567 void BitcoinGUI::aboutClicked()
569 aboutDialog->setModel(clientModel);
570 aboutDialog->setWindowModality(Qt::ApplicationModal);
574 void BitcoinGUI::setNumConnections(int count)
579 case 0: icon = ":/icons/connect_0"; break;
580 case 1: case 2: case 3: icon = ":/icons/connect_1"; break;
581 case 4: case 5: case 6: icon = ":/icons/connect_2"; break;
582 case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
583 default: icon = ":/icons/connect_4"; break;
585 labelConnectionsIcon->setPixmap(QIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
586 labelConnectionsIcon->setToolTip(tr("%n active connection(s) to NovaCoin network", "", count));
589 void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks)
591 // don't show / hide progress bar and its label if we have no connection to the network
592 if (!clientModel || clientModel->getNumConnections() == 0)
594 progressBarLabel->setVisible(false);
595 progressBar->setVisible(false);
600 QString strStatusBarWarnings = clientModel->getStatusBarWarnings();
603 if(count < nTotalBlocks)
605 int nRemainingBlocks = nTotalBlocks - count;
606 float nPercentageDone = count / (nTotalBlocks * 0.01f);
608 if (strStatusBarWarnings.isEmpty())
610 progressBarLabel->setText(tr("Synchronizing with network..."));
611 progressBarLabel->setVisible(true);
612 progressBar->setFormat(tr("~%n block(s) remaining", "", nRemainingBlocks));
613 progressBar->setMaximum(nTotalBlocks);
614 progressBar->setValue(count);
615 progressBar->setVisible(true);
618 tooltip = tr("Downloaded %1 of %2 blocks of transaction history (%3% done).").arg(count).arg(nTotalBlocks).arg(nPercentageDone, 0, 'f', 2);
622 if (strStatusBarWarnings.isEmpty())
623 progressBarLabel->setVisible(false);
625 progressBar->setVisible(false);
626 tooltip = tr("Downloaded %1 blocks of transaction history.").arg(count);
629 // Override progressBarLabel text and hide progress bar, when we have warnings to display
630 if (!strStatusBarWarnings.isEmpty())
632 progressBarLabel->setText(strStatusBarWarnings);
633 progressBarLabel->setVisible(true);
634 progressBar->setVisible(false);
637 tooltip = tr("Current PoW difficulty is %1.").arg(clientModel->getDifficulty(false)) + QString("<br>") + tooltip;
638 tooltip = tr("Current PoS difficulty is %1.").arg(clientModel->getDifficulty(true)) + QString("<br>") + tooltip;
640 QDateTime lastBlockDate = clientModel->getLastBlockDate();
641 int secs = lastBlockDate.secsTo(QDateTime::currentDateTime());
644 // Represent time from last generated block in human readable text
647 // Fully up to date. Leave text empty.
651 text = tr("%n second(s) ago","",secs);
653 else if(secs < 60*60)
655 text = tr("%n minute(s) ago","",secs/60);
657 else if(secs < 24*60*60)
659 text = tr("%n hour(s) ago","",secs/(60*60));
663 text = tr("%n day(s) ago","",secs/(60*60*24));
666 // Set icon state: spinning if catching up, tick otherwise
667 if(secs < 90*60 && count >= nTotalBlocks)
669 tooltip = tr("Up to date") + QString(".<br>") + tooltip;
670 labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
672 overviewPage->showOutOfSyncWarning(false);
676 tooltip = tr("Catching up...") + QString("<br>") + tooltip;
677 labelBlocksIcon->setMovie(syncIconMovie);
678 syncIconMovie->start();
680 overviewPage->showOutOfSyncWarning(true);
685 tooltip += QString("<br>");
686 tooltip += tr("Last received block was generated %1.").arg(text);
689 // Don't word-wrap this (fixed-width) tooltip
690 tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
692 labelBlocksIcon->setToolTip(tooltip);
693 progressBarLabel->setToolTip(tooltip);
694 progressBar->setToolTip(tooltip);
697 void BitcoinGUI::updateMining()
702 labelMiningIcon->setPixmap(QIcon(":/icons/mining_inactive").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
704 if (!clientModel->getNumConnections())
706 labelMiningIcon->setToolTip(tr("Wallet is offline"));
710 if (walletModel->getEncryptionStatus() == WalletModel::Locked)
712 labelMiningIcon->setToolTip(tr("Wallet is locked"));
716 if (clientModel->inInitialBlockDownload() || clientModel->getNumBlocksOfPeers() > clientModel->getNumBlocks())
718 labelMiningIcon->setToolTip(tr("Blockchain download is in progress"));
722 if (nStakeInputsMapSize > 0)
724 labelMiningIcon->setPixmap(QIcon(":/icons/mining_active").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
726 uint64_t nNetworkWeight = clientModel->getPoSKernelPS();
728 labelMiningIcon->setToolTip(QString("<nobr>")+tr("Stake miner is active<br>%1 inputs being used for mining<br>Network weight is %3").arg(nStakeInputsMapSize).arg(nNetworkWeight)+QString("<\nobr>"));
731 labelMiningIcon->setToolTip(tr("No suitable inputs were found"));
734 void BitcoinGUI::message(const QString &title, const QString &message, unsigned int style, const QString &detail)
736 QString strTitle = tr("NovaCoin") + " - ";
737 // Default to information icon
738 int nMBoxIcon = QMessageBox::Information;
739 int nNotifyIcon = Notificator::Information;
742 // Check for usage of predefined title
744 case CClientUIInterface::MSG_ERROR:
745 strTitle += tr("Error");
747 case CClientUIInterface::MSG_WARNING:
748 strTitle += tr("Warning");
750 case CClientUIInterface::MSG_INFORMATION:
751 strTitle += tr("Information");
754 strTitle += title; // Use supplied title
757 // Check for error/warning icon
758 if (style & CClientUIInterface::ICON_ERROR) {
759 nMBoxIcon = QMessageBox::Critical;
760 nNotifyIcon = Notificator::Critical;
762 else if (style & CClientUIInterface::ICON_WARNING) {
763 nMBoxIcon = QMessageBox::Warning;
764 nNotifyIcon = Notificator::Warning;
768 if (style & CClientUIInterface::MODAL) {
769 // Check for buttons, use OK as default, if none was supplied
770 QMessageBox::StandardButton buttons;
771 buttons = QMessageBox::Ok;
773 QMessageBox mBox((QMessageBox::Icon)nMBoxIcon, strTitle, message, buttons);
775 if(!detail.isEmpty()) { mBox.setDetailedText(detail); }
780 notificator->notify((Notificator::Class)nNotifyIcon, strTitle, message);
784 void BitcoinGUI::changeEvent(QEvent *e)
786 QMainWindow::changeEvent(e);
787 #ifndef Q_OS_MAC // Ignored on Mac
788 if(e->type() == QEvent::WindowStateChange)
790 if(clientModel && clientModel->getOptionsModel()->getMinimizeToTray())
792 QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
793 if(!(wsevt->oldState() & Qt::WindowMinimized) && isMinimized())
795 QTimer::singleShot(0, this, SLOT(hide()));
803 void BitcoinGUI::closeEvent(QCloseEvent *event)
807 #ifndef Q_OS_MAC // Ignored on Mac
808 if(!clientModel->getOptionsModel()->getMinimizeOnClose())
814 // close rpcConsole in case it was open to make some space for the shutdown window
817 QMainWindow::closeEvent(event);
820 void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
823 tr("This transaction is over the size limit. You can still send it for a fee of %1, "
824 "which goes to the nodes that process your transaction and helps to support the network. "
825 "Do you want to pay the fee?").arg(
826 BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nFeeRequired));
827 QMessageBox::StandardButton retval = QMessageBox::question(
828 this, tr("Confirm transaction fee"), strMessage,
829 QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes);
830 *payFee = (retval == QMessageBox::Yes);
833 void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
835 if(!walletModel || !clientModel)
837 TransactionTableModel *ttm = walletModel->getTransactionTableModel();
838 qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
839 .data(Qt::EditRole).toULongLong();
840 if(!clientModel->inInitialBlockDownload())
842 // On new transaction, make an info balloon
843 // Unless the initial block download is in progress, to prevent balloon-spam
844 QString date = ttm->index(start, TransactionTableModel::Date, parent)
846 QString type = ttm->index(start, TransactionTableModel::Type, parent)
848 QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
850 QIcon icon = qvariant_cast<QIcon>(ttm->index(start,
851 TransactionTableModel::ToAddress, parent)
852 .data(Qt::DecorationRole));
854 notificator->notify(Notificator::Information,
855 (amount)<0 ? tr("Sent transaction") :
856 tr("Incoming transaction"),
862 .arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true))
864 .arg(address), icon);
868 void BitcoinGUI::gotoOverviewPage()
870 overviewAction->setChecked(true);
871 centralWidget->setCurrentWidget(overviewPage);
873 exportAction->setEnabled(false);
874 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
877 void BitcoinGUI::gotoHistoryPage()
879 historyAction->setChecked(true);
880 centralWidget->setCurrentWidget(transactionsPage);
882 exportAction->setEnabled(true);
883 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
884 connect(exportAction, SIGNAL(triggered()), transactionView, SLOT(exportClicked()));
887 void BitcoinGUI::gotoMintingPage()
889 mintingAction->setChecked(true);
890 centralWidget->setCurrentWidget(mintingPage);
892 exportAction->setEnabled(true);
893 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
894 connect(exportAction, SIGNAL(triggered()), mintingView, SLOT(exportClicked()));
898 void BitcoinGUI::gotoAddressBookPage()
900 addressBookAction->setChecked(true);
901 centralWidget->setCurrentWidget(addressBookPage);
903 exportAction->setEnabled(true);
904 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
905 connect(exportAction, SIGNAL(triggered()), addressBookPage, SLOT(exportClicked()));
908 void BitcoinGUI::gotoReceiveCoinsPage()
910 receiveCoinsAction->setChecked(true);
911 centralWidget->setCurrentWidget(receiveCoinsPage);
913 exportAction->setEnabled(true);
914 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
915 connect(exportAction, SIGNAL(triggered()), receiveCoinsPage, SLOT(exportClicked()));
918 void BitcoinGUI::gotoSendCoinsPage()
920 sendCoinsAction->setChecked(true);
921 centralWidget->setCurrentWidget(sendCoinsPage);
923 exportAction->setEnabled(false);
924 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
927 void BitcoinGUI::gotoSignMessageTab(QString addr)
929 // call show() in showTab_SM()
930 signVerifyMessageDialog->showTab_SM(true);
933 signVerifyMessageDialog->setAddress_SM(addr);
936 void BitcoinGUI::gotoVerifyMessageTab(QString addr)
938 // call show() in showTab_VM()
939 signVerifyMessageDialog->showTab_VM(true);
942 signVerifyMessageDialog->setAddress_VM(addr);
945 void BitcoinGUI::gotoSecondAuthPage(QString addr)
947 secondAuthDialog->show();
948 secondAuthDialog->raise();
949 secondAuthDialog->activateWindow();
952 void BitcoinGUI::gotoMultisigPage()
954 multisigPage->show();
955 multisigPage->raise();
956 multisigPage->activateWindow();
959 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
962 if(event->mimeData()->hasUrls())
963 event->acceptProposedAction();
966 void BitcoinGUI::dropEvent(QDropEvent *event)
968 if(event->mimeData()->hasUrls())
970 int nValidUrisFound = 0;
971 QList<QUrl> uris = event->mimeData()->urls();
972 foreach(const QUrl &uri, uris)
974 if (sendCoinsPage->handleURI(uri.toString()))
978 // if valid URIs were found
982 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."));
985 event->acceptProposedAction();
988 void BitcoinGUI::handleURI(QString strURI)
990 // URI has to be valid
991 if (sendCoinsPage->handleURI(strURI))
993 showNormalIfMinimized();
997 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."));
1000 void BitcoinGUI::setEncryptionStatus(int status)
1004 case WalletModel::Unencrypted:
1005 labelEncryptionIcon->hide();
1006 encryptWalletAction->setChecked(false);
1007 changePassphraseAction->setEnabled(false);
1008 lockWalletAction->setEnabled(false);
1009 unlockWalletAction->setEnabled(false);
1010 unlockWalletMiningAction->setEnabled(false);
1011 encryptWalletAction->setEnabled(true);
1013 case WalletModel::Unlocked:
1014 labelEncryptionIcon->show();
1015 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
1016 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
1017 encryptWalletAction->setChecked(true);
1018 changePassphraseAction->setEnabled(true);
1019 encryptWalletAction->setEnabled(true);
1021 lockWalletAction->setEnabled(true);
1022 lockWalletAction->setChecked(false);
1023 unlockWalletAction->setEnabled(false);
1024 unlockWalletMiningAction->setEnabled(false);
1026 if (fWalletUnlockMintOnly)
1027 unlockWalletMiningAction->setChecked(true);
1029 unlockWalletAction->setChecked(true);
1032 case WalletModel::Locked:
1033 labelEncryptionIcon->show();
1034 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
1035 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
1036 encryptWalletAction->setChecked(true);
1037 changePassphraseAction->setEnabled(true);
1038 encryptWalletAction->setEnabled(true);
1040 lockWalletAction->setChecked(true);
1041 unlockWalletAction->setChecked(false);
1042 unlockWalletMiningAction->setChecked(false);
1044 lockWalletAction->setEnabled(false);
1045 unlockWalletAction->setEnabled(true);
1046 unlockWalletMiningAction->setEnabled(true);
1051 void BitcoinGUI::encryptWallet(bool status)
1055 AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt:
1056 AskPassphraseDialog::Decrypt, this);
1057 dlg.setModel(walletModel);
1060 setEncryptionStatus(walletModel->getEncryptionStatus());
1063 void BitcoinGUI::unlockWalletMining(bool status)
1068 // Unlock wallet when requested by wallet model
1069 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1071 AskPassphraseDialog dlg(AskPassphraseDialog::UnlockMining, this);
1072 dlg.setModel(walletModel);
1077 void BitcoinGUI::backupWallet()
1079 #if QT_VERSION < 0x050000
1080 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1082 QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1084 QString filename = QFileDialog::getSaveFileName(this, tr("Backup Wallet"), saveDir, tr("Wallet Data (*.dat)"));
1085 if(!filename.isEmpty()) {
1086 if(!walletModel->backupWallet(filename)) {
1087 QMessageBox::warning(this, tr("Backup Failed"), tr("There was an error trying to save the wallet data to the new location."));
1092 void BitcoinGUI::dumpWallet()
1097 WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1100 // Unlock wallet failed or was cancelled
1104 #if QT_VERSION < 0x050000
1105 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1107 QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1109 QString filename = QFileDialog::getSaveFileName(this, tr("Dump Wallet"), saveDir, tr("Wallet dump (*.txt)"));
1110 if(!filename.isEmpty()) {
1111 if(!walletModel->dumpWallet(filename)) {
1112 message(tr("Dump failed"),
1113 tr("An error happened while trying to save the keys to your location.\n"
1114 "Keys were not saved.")
1115 ,CClientUIInterface::MSG_ERROR);
1118 message(tr("Dump successful"),
1119 tr("Keys were saved to this file:\n%2")
1121 ,CClientUIInterface::MSG_INFORMATION);
1125 void BitcoinGUI::importWallet()
1130 WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1133 // Unlock wallet failed or was cancelled
1137 #if QT_VERSION < 0x050000
1138 QString openDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1140 QString openDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1142 QString filename = QFileDialog::getOpenFileName(this, tr("Import Wallet"), openDir, tr("Wallet dump (*.txt)"));
1143 if(!filename.isEmpty()) {
1144 if(!walletModel->importWallet(filename)) {
1145 message(tr("Import Failed"),
1146 tr("An error happened while trying to import the keys.\n"
1147 "Some or all keys from:\n %1,\n were not imported into your wallet.")
1149 ,CClientUIInterface::MSG_ERROR);
1152 message(tr("Import Successful"),
1153 tr("All keys from:\n %1,\n were imported into your wallet.")
1155 ,CClientUIInterface::MSG_INFORMATION);
1160 void BitcoinGUI::changePassphrase()
1162 AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
1163 dlg.setModel(walletModel);
1167 void BitcoinGUI::unlockWallet()
1171 // Unlock wallet when requested by wallet model
1172 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1174 AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
1175 dlg.setModel(walletModel);
1180 void BitcoinGUI::lockWallet()
1185 walletModel->setWalletLocked(true);
1188 void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden)
1190 // activateWindow() (sometimes) helps with keyboard focus on Windows
1193 // Make sure the window is not minimized
1194 setWindowState(windowState() & (~Qt::WindowMinimized | Qt::WindowActive));
1200 else if (isMinimized())
1206 else if (GUIUtil::isObscured(this))
1213 if (GUIUtil::isObscured(this))
1217 else if(fToggleHidden)
1221 void BitcoinGUI::toggleHidden()
1223 showNormalIfMinimized(true);
1226 void BitcoinGUI::error(const QString &title, const QString &message, bool modal)
1228 // Report errors from network/worker thread
1231 QMessageBox::critical(this, title, message, QMessageBox::Ok, QMessageBox::Ok);
1233 notificator->notify(Notificator::Critical, title, message);