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),
95 setWindowTitle(tr("NovaCoin") + " - " + tr("Wallet"));
97 qApp->setWindowIcon(QIcon(":icons/bitcoin"));
98 setWindowIcon(QIcon(":icons/bitcoin"));
100 setUnifiedTitleAndToolBarOnMac(true);
101 QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
103 // Accept D&D of URIs
104 setAcceptDrops(true);
106 // Create actions for the toolbar, menu bar and tray/dock icon
109 // Create application menu bar
112 // Create the toolbars
115 // Create the tray icon (or setup the dock icon)
119 overviewPage = new OverviewPage();
121 transactionsPage = new QWidget(this);
122 QVBoxLayout *vbox = new QVBoxLayout();
123 transactionView = new TransactionView(this);
124 vbox->addWidget(transactionView);
125 transactionsPage->setLayout(vbox);
127 mintingPage = new QWidget(this);
128 QVBoxLayout *vboxMinting = new QVBoxLayout();
129 mintingView = new MintingView(this);
130 vboxMinting->addWidget(mintingView);
131 mintingPage->setLayout(vboxMinting);
133 addressBookPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::SendingTab);
135 receiveCoinsPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::ReceivingTab);
137 sendCoinsPage = new SendCoinsDialog(this);
139 signVerifyMessageDialog = new SignVerifyMessageDialog(0);
141 secondAuthDialog = new SecondAuthDialog(0);
143 multisigPage = new MultisigDialog(0);
145 centralWidget = new QStackedWidget(this);
146 centralWidget->addWidget(overviewPage);
147 centralWidget->addWidget(transactionsPage);
148 centralWidget->addWidget(mintingPage);
149 centralWidget->addWidget(addressBookPage);
150 centralWidget->addWidget(receiveCoinsPage);
151 centralWidget->addWidget(sendCoinsPage);
152 setCentralWidget(centralWidget);
157 // Status bar notification icons
158 QFrame *frameBlocks = new QFrame();
159 frameBlocks->setContentsMargins(0,0,0,0);
160 frameBlocks->setMinimumWidth(72);
161 frameBlocks->setMaximumWidth(72);
162 QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);
163 frameBlocksLayout->setContentsMargins(3,0,3,0);
164 frameBlocksLayout->setSpacing(3);
165 labelEncryptionIcon = new QLabel();
166 labelMiningIcon = new QLabel();
167 labelConnectionsIcon = new QLabel();
168 labelBlocksIcon = new QLabel();
169 frameBlocksLayout->addStretch();
170 frameBlocksLayout->addWidget(labelEncryptionIcon);
171 frameBlocksLayout->addStretch();
172 frameBlocksLayout->addWidget(labelMiningIcon);
173 frameBlocksLayout->addStretch();
174 frameBlocksLayout->addWidget(labelConnectionsIcon);
175 frameBlocksLayout->addStretch();
176 frameBlocksLayout->addWidget(labelBlocksIcon);
177 frameBlocksLayout->addStretch();
179 // Progress bar and label for blocks download
180 progressBarLabel = new QLabel();
181 progressBarLabel->setVisible(false);
182 progressBar = new QProgressBar();
183 progressBar->setAlignment(Qt::AlignCenter);
184 progressBar->setVisible(false);
186 // Override style sheet for progress bar for styles that have a segmented progress bar,
187 // as they make the text unreadable (workaround for issue #1071)
188 // See https://qt-project.org/doc/qt-4.8/gallery.html
189 QString curStyle = qApp->style()->metaObject()->className();
190 if(curStyle == "QWindowsStyle" || curStyle == "QWindowsXPStyle")
192 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; }");
195 statusBar()->addWidget(progressBarLabel);
196 statusBar()->addWidget(progressBar);
197 statusBar()->addPermanentWidget(frameBlocks);
199 syncIconMovie = new QMovie(":/movies/update_spinner", "mng", this);
201 // Clicking on a transaction on the overview page simply sends you to transaction history page
202 connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), this, SLOT(gotoHistoryPage()));
203 connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex)));
205 // Double-clicking on a transaction on the transaction history page shows details
206 connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
208 rpcConsole = new RPCConsole(0);
209 connect(openRPCConsoleAction, SIGNAL(triggered()), rpcConsole, SLOT(show()));
210 connect(openRPCConsoleAction, SIGNAL(triggered()), rpcConsole, SLOT(raise()));
212 aboutDialog = new AboutDialog(0);
213 optionsDialog = new OptionsDialog(0);
215 // Clicking on "Verify Message" in the address book sends you to the verify message tab
216 connect(addressBookPage, SIGNAL(verifyMessage(QString)), this, SLOT(gotoVerifyMessageTab(QString)));
217 // Clicking on "Sign Message" in the receive coins page sends you to the sign message tab
218 connect(receiveCoinsPage, SIGNAL(signMessage(QString)), this, SLOT(gotoSignMessageTab(QString)));
223 BitcoinGUI::~BitcoinGUI()
225 if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu)
233 delete optionsDialog;
235 delete secondAuthDialog;
236 delete signVerifyMessageDialog;
239 void BitcoinGUI::createActions()
241 QActionGroup *tabGroup = new QActionGroup(this);
243 overviewAction = new QAction(QIcon(":/icons/overview"), tr("&Overview"), this);
244 overviewAction->setToolTip(tr("Show general overview of wallet"));
245 overviewAction->setCheckable(true);
246 overviewAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_1));
247 tabGroup->addAction(overviewAction);
249 sendCoinsAction = new QAction(QIcon(":/icons/send"), tr("&Send coins"), this);
250 sendCoinsAction->setToolTip(tr("Send coins to a NovaCoin address"));
251 sendCoinsAction->setCheckable(true);
252 sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2));
253 tabGroup->addAction(sendCoinsAction);
255 receiveCoinsAction = new QAction(QIcon(":/icons/receiving_addresses"), tr("&Receive coins"), this);
256 receiveCoinsAction->setToolTip(tr("Show the list of addresses for receiving payments"));
257 receiveCoinsAction->setCheckable(true);
258 receiveCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_3));
259 tabGroup->addAction(receiveCoinsAction);
261 historyAction = new QAction(QIcon(":/icons/history"), tr("&Transactions"), this);
262 historyAction->setToolTip(tr("Browse transaction history"));
263 historyAction->setCheckable(true);
264 historyAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_4));
265 tabGroup->addAction(historyAction);
267 mintingAction = new QAction(QIcon(":/icons/history"), tr("&Minting"), this);
268 mintingAction->setToolTip(tr("Show your minting capacity"));
269 mintingAction->setCheckable(true);
270 mintingAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_5));
271 tabGroup->addAction(mintingAction);
273 addressBookAction = new QAction(QIcon(":/icons/address-book"), tr("&Address Book"), this);
274 addressBookAction->setToolTip(tr("Edit the list of stored addresses and labels"));
275 addressBookAction->setCheckable(true);
276 addressBookAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_6));
277 tabGroup->addAction(addressBookAction);
279 multisigAction = new QAction(QIcon(":/icons/send"), tr("Multisig"), this);
280 multisigAction->setStatusTip(tr("Open window for working with multisig addresses"));
281 tabGroup->addAction(multisigAction);
283 connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
284 connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage()));
285 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
286 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
287 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
288 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
289 connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
290 connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage()));
291 connect(mintingAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
292 connect(mintingAction, SIGNAL(triggered()), this, SLOT(gotoMintingPage()));
293 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
294 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(gotoAddressBookPage()));
295 connect(multisigAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
296 connect(multisigAction, SIGNAL(triggered()), this, SLOT(gotoMultisigPage()));
298 quitAction = new QAction(QIcon(":/icons/quit"), tr("E&xit"), this);
299 quitAction->setStatusTip(tr("Quit application"));
300 quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
301 quitAction->setMenuRole(QAction::QuitRole);
302 aboutAction = new QAction(QIcon(":/icons/bitcoin"), tr("&About NovaCoin"), this);
303 aboutAction->setStatusTip(tr("Show information about NovaCoin"));
304 aboutAction->setMenuRole(QAction::AboutRole);
305 optionsAction = new QAction(QIcon(":/icons/options"), tr("&Options..."), this);
306 optionsAction->setStatusTip(tr("Modify configuration options for NovaCoin"));
307 optionsAction->setMenuRole(QAction::PreferencesRole);
308 toggleHideAction = new QAction(QIcon(":/icons/bitcoin"), tr("&Show / Hide"), this);
309 encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet..."), this);
310 encryptWalletAction->setStatusTip(tr("Encrypt or decrypt wallet"));
311 encryptWalletAction->setCheckable(true);
312 backupWalletAction = new QAction(QIcon(":/icons/filesave"), tr("&Backup Wallet..."), this);
313 backupWalletAction->setStatusTip(tr("Backup wallet to another location"));
314 dumpWalletAction = new QAction(QIcon(":/icons/dump"), tr("&Dump Wallet..."), this);
315 dumpWalletAction->setStatusTip(tr("Dump keys to a text file"));
316 importWalletAction = new QAction(QIcon(":/icons/import"), tr("&Import Wallet..."), this);
317 importWalletAction->setStatusTip(tr("Import keys into a wallet"));
318 changePassphraseAction = new QAction(QIcon(":/icons/key"), tr("&Change Passphrase..."), this);
319 changePassphraseAction->setStatusTip(tr("Change the passphrase used for wallet encryption"));
320 signMessageAction = new QAction(QIcon(":/icons/edit"), tr("Sign &message..."), this);
321 signMessageAction->setStatusTip(tr("Sign messages with your Novacoin addresses to prove you own them"));
322 verifyMessageAction = new QAction(QIcon(":/icons/transaction_0"), tr("&Verify message..."), this);
323 verifyMessageAction->setStatusTip(tr("Verify messages to ensure they were signed with specified Novacoin addresses"));
324 secondAuthAction = new QAction(QIcon(":/icons/key"), tr("Second &auth..."), this);
325 secondAuthAction->setStatusTip(tr("Second auth with your Novacoin addresses"));
327 lockWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Lock wallet"), this);
328 lockWalletAction->setStatusTip(tr("Lock wallet"));
329 lockWalletAction->setCheckable(true);
331 unlockWalletAction = new QAction(QIcon(":/icons/lock_open"), tr("Unlo&ck wallet"), this);
332 unlockWalletAction->setStatusTip(tr("Unlock wallet"));
333 unlockWalletAction->setCheckable(true);
335 unlockWalletMiningAction = new QAction(QIcon(":/icons/mining_active"), tr("Unlo&ck wallet for mining"), this);
336 unlockWalletMiningAction->setStatusTip(tr("Unlock wallet for mining"));
337 unlockWalletMiningAction->setCheckable(true);
339 exportAction = new QAction(QIcon(":/icons/export"), tr("&Export..."), this);
340 exportAction->setStatusTip(tr("Export the data in the current tab to a file"));
341 openRPCConsoleAction = new QAction(QIcon(":/icons/debugwindow"), tr("&Debug window"), this);
342 openRPCConsoleAction->setStatusTip(tr("Open debugging and diagnostic console"));
344 connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
345 connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked()));
346 connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked()));
347 connect(toggleHideAction, SIGNAL(triggered()), this, SLOT(toggleHidden()));
348 connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool)));
349 connect(lockWalletAction, SIGNAL(triggered(bool)), this, SLOT(lockWallet()));
350 connect(unlockWalletAction, SIGNAL(triggered(bool)), this, SLOT(unlockWallet()));
351 connect(unlockWalletMiningAction, SIGNAL(triggered(bool)), this, SLOT(unlockWalletMining(bool)));
352 connect(backupWalletAction, SIGNAL(triggered()), this, SLOT(backupWallet()));
353 connect(dumpWalletAction, SIGNAL(triggered()), this, SLOT(dumpWallet()));
354 connect(importWalletAction, SIGNAL(triggered()), this, SLOT(importWallet()));
355 connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase()));
356 connect(signMessageAction, SIGNAL(triggered()), this, SLOT(gotoSignMessageTab()));
357 connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(gotoVerifyMessageTab()));
358 connect(secondAuthAction, SIGNAL(triggered()), this, SLOT(gotoSecondAuthPage()));
361 void BitcoinGUI::createMenuBar()
364 // Create a decoupled menu bar on Mac which stays even if the window is closed
365 appMenuBar = new QMenuBar();
367 // Get the main window's menu bar on other platforms
368 appMenuBar = menuBar();
371 // Configure the menus
372 QMenu *file = appMenuBar->addMenu(tr("&File"));
373 file->addAction(backupWalletAction);
374 file->addSeparator();
375 file->addAction(dumpWalletAction);
376 file->addAction(importWalletAction);
377 file->addAction(exportAction);
378 file->addAction(signMessageAction);
379 file->addAction(verifyMessageAction);
380 file->addAction(secondAuthAction);
381 file->addAction(multisigAction);
382 file->addSeparator();
383 file->addAction(quitAction);
385 QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
386 QMenu *securityMenu = settings->addMenu(QIcon(":/icons/key"), tr("&Wallet security"));
387 securityMenu->addAction(encryptWalletAction);
388 securityMenu->addAction(changePassphraseAction);
389 securityMenu->addAction(unlockWalletAction);
390 securityMenu->addAction(unlockWalletMiningAction);
391 securityMenu->addAction(lockWalletAction);
392 settings->addAction(optionsAction);
394 QMenu *help = appMenuBar->addMenu(tr("&Help"));
395 help->addAction(openRPCConsoleAction);
396 help->addAction(aboutAction);
399 void BitcoinGUI::createToolBars()
401 QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));
402 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
403 toolbar->addAction(overviewAction);
404 toolbar->addAction(sendCoinsAction);
405 toolbar->addAction(receiveCoinsAction);
406 toolbar->addAction(historyAction);
407 toolbar->addAction(mintingAction);
408 toolbar->addAction(addressBookAction);
410 QToolBar *toolbar2 = addToolBar(tr("Actions toolbar"));
411 toolbar2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
412 toolbar2->addAction(exportAction);
413 toolbar2->setVisible(false);
417 void BitcoinGUI::setClientModel(ClientModel *clientModel)
419 this->clientModel = clientModel;
422 // Replace some strings and icons, when using the testnet
423 if(clientModel->isTestNet())
425 setWindowTitle(windowTitle() + QString(" ") + tr("[testnet]"));
427 qApp->setWindowIcon(QIcon(":icons/bitcoin_testnet"));
428 setWindowIcon(QIcon(":icons/bitcoin_testnet"));
430 MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
434 trayIcon->setToolTip(tr("NovaCoin client") + QString(" ") + tr("[testnet]"));
435 trayIcon->setIcon(QIcon(":/icons/toolbar_testnet"));
436 toggleHideAction->setIcon(QIcon(":/icons/toolbar_testnet"));
439 aboutAction->setIcon(QIcon(":/icons/toolbar_testnet"));
442 // Keep up to date with client
443 setNumConnections(clientModel->getNumConnections());
444 connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
446 setNumBlocks(clientModel->getNumBlocks());
447 connect(clientModel, SIGNAL(numBlocksChanged(int)), this, SLOT(setNumBlocks(int)));
449 QTimer *timer = new QTimer(this);
450 connect(timer, SIGNAL(timeout()), this, SLOT(updateMining()));
451 timer->start(10*1000); //10 seconds
453 // Report errors from network/worker thread
454 connect(clientModel, SIGNAL(error(QString,QString,bool)), this, SLOT(error(QString,QString,bool)));
456 rpcConsole->setClientModel(clientModel);
457 addressBookPage->setOptionsModel(clientModel->getOptionsModel());
458 receiveCoinsPage->setOptionsModel(clientModel->getOptionsModel());
462 void BitcoinGUI::setWalletModel(WalletModel *walletModel)
464 this->walletModel = walletModel;
467 // Report errors from wallet thread
468 connect(walletModel, SIGNAL(error(QString,QString,bool)), this, SLOT(error(QString,QString,bool)));
470 // Put transaction list in tabs
471 transactionView->setModel(walletModel);
472 mintingView->setModel(walletModel);
474 overviewPage->setModel(walletModel);
475 addressBookPage->setModel(walletModel->getAddressTableModel());
476 receiveCoinsPage->setModel(walletModel->getAddressTableModel());
477 sendCoinsPage->setModel(walletModel);
478 signVerifyMessageDialog->setModel(walletModel);
479 secondAuthDialog->setModel(walletModel);
480 multisigPage->setModel(walletModel);
482 setEncryptionStatus(walletModel->getEncryptionStatus());
483 connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));
484 connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(updateMining()));
486 // Balloon pop-up for new transaction
487 connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
488 this, SLOT(incomingTransaction(QModelIndex,int,int)));
490 // Ask for passphrase if needed
491 connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
495 void BitcoinGUI::createTrayIcon()
499 trayIcon = new QSystemTrayIcon(this);
500 trayIconMenu = new QMenu(this);
501 trayIcon->setContextMenu(trayIconMenu);
502 trayIcon->setToolTip(tr("NovaCoin client"));
503 trayIcon->setIcon(QIcon(":/icons/toolbar"));
504 connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
505 this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
508 // Note: On Mac, the dock icon is used to provide the tray's functionality.
509 MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance();
510 dockIconHandler->setMainWindow((QMainWindow *)this);
511 trayIconMenu = dockIconHandler->dockMenu();
514 // Configuration of the tray icon (or dock icon) icon menu
515 trayIconMenu->addAction(toggleHideAction);
516 trayIconMenu->addSeparator();
517 trayIconMenu->addAction(sendCoinsAction);
518 trayIconMenu->addAction(multisigAction);
519 trayIconMenu->addAction(receiveCoinsAction);
520 trayIconMenu->addSeparator();
521 trayIconMenu->addAction(signMessageAction);
522 trayIconMenu->addAction(verifyMessageAction);
523 trayIconMenu->addAction(secondAuthAction);
524 trayIconMenu->addSeparator();
525 trayIconMenu->addAction(optionsAction);
526 trayIconMenu->addAction(openRPCConsoleAction);
528 // This is built-in on Mac
529 trayIconMenu->addSeparator();
530 trayIconMenu->addAction(quitAction);
532 notificator = new Notificator(QApplication::applicationName(), trayIcon, this);
536 void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
538 if(reason == QSystemTrayIcon::Trigger)
540 // Click on system tray icon triggers show/hide of the main window
541 toggleHideAction->trigger();
546 void BitcoinGUI::optionsClicked()
548 if(!clientModel || !clientModel->getOptionsModel())
551 optionsDialog->setModel(clientModel->getOptionsModel());
552 optionsDialog->setWindowModality(Qt::ApplicationModal);
553 optionsDialog->show();
556 void BitcoinGUI::aboutClicked()
558 aboutDialog->setModel(clientModel);
559 aboutDialog->setWindowModality(Qt::ApplicationModal);
563 void BitcoinGUI::setNumConnections(int count)
568 case 0: icon = ":/icons/connect_0"; break;
569 case 1: case 2: case 3: icon = ":/icons/connect_1"; break;
570 case 4: case 5: case 6: icon = ":/icons/connect_2"; break;
571 case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
572 default: icon = ":/icons/connect_4"; break;
574 labelConnectionsIcon->setPixmap(QIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
575 labelConnectionsIcon->setToolTip(tr("%n active connection(s) to NovaCoin network", "", count));
578 void BitcoinGUI::setNumBlocks(int count)
580 // don't show / hide progress bar and its label if we have no connection to the network
581 if (!clientModel || clientModel->getNumConnections() == 0)
583 progressBarLabel->setVisible(false);
584 progressBar->setVisible(false);
589 QString strStatusBarWarnings = clientModel->getStatusBarWarnings();
592 if (strStatusBarWarnings.isEmpty())
593 progressBarLabel->setVisible(false);
595 progressBar->setVisible(false);
596 tooltip = tr("Downloaded %1 blocks of transaction history.").arg(count);
598 // Override progressBarLabel text and hide progress bar, when we have warnings to display
599 if (!strStatusBarWarnings.isEmpty())
601 progressBarLabel->setText(strStatusBarWarnings);
602 progressBarLabel->setVisible(true);
603 progressBar->setVisible(false);
606 tooltip = tr("Current PoW difficulty is %1.").arg(clientModel->getDifficulty(false)) + QString("<br>") + tooltip;
607 tooltip = tr("Current PoS difficulty is %1.").arg(clientModel->getDifficulty(true)) + QString("<br>") + tooltip;
609 QDateTime lastBlockDate = clientModel->getLastBlockDate();
610 int secs = lastBlockDate.secsTo(QDateTime::currentDateTime());
613 // Represent time from last generated block in human readable text
616 // Fully up to date. Leave text empty.
620 text = tr("%n second(s) ago","",secs);
622 else if(secs < 60*60)
624 text = tr("%n minute(s) ago","",secs/60);
626 else if(secs < 24*60*60)
628 text = tr("%n hour(s) ago","",secs/(60*60));
632 text = tr("%n day(s) ago","",secs/(60*60*24));
635 // Set icon state: spinning if catching up, tick otherwise
638 tooltip = tr("Up to date") + QString(".<br>") + tooltip;
639 labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
641 overviewPage->showOutOfSyncWarning(false);
645 tooltip = tr("Catching up...") + QString("<br>") + tooltip;
646 labelBlocksIcon->setMovie(syncIconMovie);
647 syncIconMovie->start();
649 overviewPage->showOutOfSyncWarning(true);
654 tooltip += QString("<br>");
655 tooltip += tr("Last received block was generated %1.").arg(text);
658 // Don't word-wrap this (fixed-width) tooltip
659 tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
661 labelBlocksIcon->setToolTip(tooltip);
662 progressBarLabel->setToolTip(tooltip);
663 progressBar->setToolTip(tooltip);
666 void BitcoinGUI::updateMining()
671 labelMiningIcon->setPixmap(QIcon(":/icons/mining_inactive").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
673 if (!clientModel->getNumConnections())
675 labelMiningIcon->setToolTip(tr("Wallet is offline"));
679 if (walletModel->getEncryptionStatus() == WalletModel::Locked)
681 labelMiningIcon->setToolTip(tr("Wallet is locked"));
685 if (clientModel->inInitialBlockDownload())
687 labelMiningIcon->setToolTip(tr("Blockchain download is in progress"));
691 if (nStakeInputsMapSize > 0)
693 labelMiningIcon->setPixmap(QIcon(":/icons/mining_active").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
695 uint64_t nNetworkWeight = clientModel->getPoSKernelPS();
697 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>"));
700 labelMiningIcon->setToolTip(tr("No suitable inputs were found"));
703 void BitcoinGUI::message(const QString &title, const QString &message, unsigned int style, const QString &detail)
705 QString strTitle = tr("NovaCoin") + " - ";
706 // Default to information icon
707 int nMBoxIcon = QMessageBox::Information;
708 int nNotifyIcon = Notificator::Information;
711 // Check for usage of predefined title
713 case CClientUIInterface::MSG_ERROR:
714 strTitle += tr("Error");
716 case CClientUIInterface::MSG_WARNING:
717 strTitle += tr("Warning");
719 case CClientUIInterface::MSG_INFORMATION:
720 strTitle += tr("Information");
723 strTitle += title; // Use supplied title
726 // Check for error/warning icon
727 if (style & CClientUIInterface::ICON_ERROR) {
728 nMBoxIcon = QMessageBox::Critical;
729 nNotifyIcon = Notificator::Critical;
731 else if (style & CClientUIInterface::ICON_WARNING) {
732 nMBoxIcon = QMessageBox::Warning;
733 nNotifyIcon = Notificator::Warning;
737 if (style & CClientUIInterface::MODAL) {
738 // Check for buttons, use OK as default, if none was supplied
739 QMessageBox::StandardButton buttons;
740 buttons = QMessageBox::Ok;
742 QMessageBox mBox((QMessageBox::Icon)nMBoxIcon, strTitle, message, buttons);
744 if(!detail.isEmpty()) { mBox.setDetailedText(detail); }
749 notificator->notify((Notificator::Class)nNotifyIcon, strTitle, message);
753 void BitcoinGUI::changeEvent(QEvent *e)
755 QMainWindow::changeEvent(e);
756 #ifndef Q_OS_MAC // Ignored on Mac
757 if(e->type() == QEvent::WindowStateChange)
759 if(clientModel && clientModel->getOptionsModel()->getMinimizeToTray())
761 QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
762 if(!(wsevt->oldState() & Qt::WindowMinimized) && isMinimized())
764 QTimer::singleShot(0, this, SLOT(hide()));
772 void BitcoinGUI::closeEvent(QCloseEvent *event)
776 #ifndef Q_OS_MAC // Ignored on Mac
777 if(!clientModel->getOptionsModel()->getMinimizeOnClose())
783 // close rpcConsole in case it was open to make some space for the shutdown window
786 QMainWindow::closeEvent(event);
789 void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
792 tr("This transaction is over the size limit. You can still send it for a fee of %1, "
793 "which goes to the nodes that process your transaction and helps to support the network. "
794 "Do you want to pay the fee?").arg(
795 BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nFeeRequired));
796 QMessageBox::StandardButton retval = QMessageBox::question(
797 this, tr("Confirm transaction fee"), strMessage,
798 QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes);
799 *payFee = (retval == QMessageBox::Yes);
802 void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
804 if(!walletModel || !clientModel)
806 TransactionTableModel *ttm = walletModel->getTransactionTableModel();
807 qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
808 .data(Qt::EditRole).toULongLong();
809 if(!clientModel->inInitialBlockDownload())
811 // On new transaction, make an info balloon
812 // Unless the initial block download is in progress, to prevent balloon-spam
813 QString date = ttm->index(start, TransactionTableModel::Date, parent)
815 QString type = ttm->index(start, TransactionTableModel::Type, parent)
817 QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
819 QIcon icon = qvariant_cast<QIcon>(ttm->index(start,
820 TransactionTableModel::ToAddress, parent)
821 .data(Qt::DecorationRole));
823 notificator->notify(Notificator::Information,
824 (amount)<0 ? tr("Sent transaction") :
825 tr("Incoming transaction"),
831 .arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true))
833 .arg(address), icon);
837 void BitcoinGUI::gotoOverviewPage()
839 overviewAction->setChecked(true);
840 centralWidget->setCurrentWidget(overviewPage);
842 exportAction->setEnabled(false);
843 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
846 void BitcoinGUI::gotoHistoryPage()
848 historyAction->setChecked(true);
849 centralWidget->setCurrentWidget(transactionsPage);
851 exportAction->setEnabled(true);
852 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
853 connect(exportAction, SIGNAL(triggered()), transactionView, SLOT(exportClicked()));
856 void BitcoinGUI::gotoMintingPage()
858 mintingAction->setChecked(true);
859 centralWidget->setCurrentWidget(mintingPage);
861 exportAction->setEnabled(true);
862 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
863 connect(exportAction, SIGNAL(triggered()), mintingView, SLOT(exportClicked()));
867 void BitcoinGUI::gotoAddressBookPage()
869 addressBookAction->setChecked(true);
870 centralWidget->setCurrentWidget(addressBookPage);
872 exportAction->setEnabled(true);
873 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
874 connect(exportAction, SIGNAL(triggered()), addressBookPage, SLOT(exportClicked()));
877 void BitcoinGUI::gotoReceiveCoinsPage()
879 receiveCoinsAction->setChecked(true);
880 centralWidget->setCurrentWidget(receiveCoinsPage);
882 exportAction->setEnabled(true);
883 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
884 connect(exportAction, SIGNAL(triggered()), receiveCoinsPage, SLOT(exportClicked()));
887 void BitcoinGUI::gotoSendCoinsPage()
889 sendCoinsAction->setChecked(true);
890 centralWidget->setCurrentWidget(sendCoinsPage);
892 exportAction->setEnabled(false);
893 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
896 void BitcoinGUI::gotoSignMessageTab(QString addr)
898 // call show() in showTab_SM()
899 signVerifyMessageDialog->showTab_SM(true);
902 signVerifyMessageDialog->setAddress_SM(addr);
905 void BitcoinGUI::gotoVerifyMessageTab(QString addr)
907 // call show() in showTab_VM()
908 signVerifyMessageDialog->showTab_VM(true);
911 signVerifyMessageDialog->setAddress_VM(addr);
914 void BitcoinGUI::gotoSecondAuthPage(QString addr)
916 secondAuthDialog->show();
917 secondAuthDialog->raise();
918 secondAuthDialog->activateWindow();
921 void BitcoinGUI::gotoMultisigPage()
923 multisigPage->show();
924 multisigPage->raise();
925 multisigPage->activateWindow();
928 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
931 if(event->mimeData()->hasUrls())
932 event->acceptProposedAction();
935 void BitcoinGUI::dropEvent(QDropEvent *event)
937 if(event->mimeData()->hasUrls())
939 int nValidUrisFound = 0;
940 QList<QUrl> uris = event->mimeData()->urls();
941 foreach(const QUrl &uri, uris)
943 if (sendCoinsPage->handleURI(uri.toString()))
947 // if valid URIs were found
951 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."));
954 event->acceptProposedAction();
957 void BitcoinGUI::handleURI(QString strURI)
959 // URI has to be valid
960 if (sendCoinsPage->handleURI(strURI))
962 showNormalIfMinimized();
966 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."));
969 void BitcoinGUI::setEncryptionStatus(int status)
973 case WalletModel::Unencrypted:
974 labelEncryptionIcon->hide();
975 encryptWalletAction->setChecked(false);
976 changePassphraseAction->setEnabled(false);
977 lockWalletAction->setEnabled(false);
978 unlockWalletAction->setEnabled(false);
979 unlockWalletMiningAction->setEnabled(false);
980 encryptWalletAction->setEnabled(true);
982 case WalletModel::Unlocked:
983 labelEncryptionIcon->show();
984 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
985 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
986 encryptWalletAction->setChecked(true);
987 changePassphraseAction->setEnabled(true);
988 encryptWalletAction->setEnabled(true);
990 lockWalletAction->setEnabled(true);
991 lockWalletAction->setChecked(false);
992 unlockWalletAction->setEnabled(false);
993 unlockWalletMiningAction->setEnabled(false);
995 if (fWalletUnlockMintOnly)
996 unlockWalletMiningAction->setChecked(true);
998 unlockWalletAction->setChecked(true);
1001 case WalletModel::Locked:
1002 labelEncryptionIcon->show();
1003 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
1004 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
1005 encryptWalletAction->setChecked(true);
1006 changePassphraseAction->setEnabled(true);
1007 encryptWalletAction->setEnabled(true);
1009 lockWalletAction->setChecked(true);
1010 unlockWalletAction->setChecked(false);
1011 unlockWalletMiningAction->setChecked(false);
1013 lockWalletAction->setEnabled(false);
1014 unlockWalletAction->setEnabled(true);
1015 unlockWalletMiningAction->setEnabled(true);
1020 void BitcoinGUI::encryptWallet(bool status)
1024 AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt:
1025 AskPassphraseDialog::Decrypt, this);
1026 dlg.setModel(walletModel);
1029 setEncryptionStatus(walletModel->getEncryptionStatus());
1032 void BitcoinGUI::unlockWalletMining(bool status)
1037 // Unlock wallet when requested by wallet model
1038 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1040 AskPassphraseDialog dlg(AskPassphraseDialog::UnlockMining, this);
1041 dlg.setModel(walletModel);
1046 void BitcoinGUI::backupWallet()
1048 #if QT_VERSION < 0x050000
1049 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1051 QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1053 QString filename = QFileDialog::getSaveFileName(this, tr("Backup Wallet"), saveDir, tr("Wallet Data (*.dat)"));
1054 if(!filename.isEmpty()) {
1055 if(!walletModel->backupWallet(filename)) {
1056 QMessageBox::warning(this, tr("Backup Failed"), tr("There was an error trying to save the wallet data to the new location."));
1061 void BitcoinGUI::dumpWallet()
1066 WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1069 // Unlock wallet failed or was cancelled
1073 #if QT_VERSION < 0x050000
1074 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1076 QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1078 QString filename = QFileDialog::getSaveFileName(this, tr("Dump Wallet"), saveDir, tr("Wallet dump (*.txt)"));
1079 if(!filename.isEmpty()) {
1080 if(!walletModel->dumpWallet(filename)) {
1081 message(tr("Dump failed"),
1082 tr("An error happened while trying to save the keys to your location.\n"
1083 "Keys were not saved.")
1084 ,CClientUIInterface::MSG_ERROR);
1087 message(tr("Dump successful"),
1088 tr("Keys were saved to this file:\n%2")
1090 ,CClientUIInterface::MSG_INFORMATION);
1094 void BitcoinGUI::importWallet()
1099 WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1102 // Unlock wallet failed or was cancelled
1106 #if QT_VERSION < 0x050000
1107 QString openDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1109 QString openDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1111 QString filename = QFileDialog::getOpenFileName(this, tr("Import Wallet"), openDir, tr("Wallet dump (*.txt)"));
1112 if(!filename.isEmpty()) {
1113 if(!walletModel->importWallet(filename)) {
1114 message(tr("Import Failed"),
1115 tr("An error happened while trying to import the keys.\n"
1116 "Some or all keys from:\n %1,\n were not imported into your wallet.")
1118 ,CClientUIInterface::MSG_ERROR);
1121 message(tr("Import Successful"),
1122 tr("All keys from:\n %1,\n were imported into your wallet.")
1124 ,CClientUIInterface::MSG_INFORMATION);
1129 void BitcoinGUI::changePassphrase()
1131 AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
1132 dlg.setModel(walletModel);
1136 void BitcoinGUI::unlockWallet()
1140 // Unlock wallet when requested by wallet model
1141 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1143 AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
1144 dlg.setModel(walletModel);
1149 void BitcoinGUI::lockWallet()
1154 walletModel->setWalletLocked(true);
1157 void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden)
1159 // activateWindow() (sometimes) helps with keyboard focus on Windows
1162 // Make sure the window is not minimized
1163 setWindowState(windowState() & (~Qt::WindowMinimized | Qt::WindowActive));
1169 else if (isMinimized())
1175 else if (GUIUtil::isObscured(this))
1182 if (GUIUtil::isObscured(this))
1186 else if(fToggleHidden)
1190 void BitcoinGUI::toggleHidden()
1192 showNormalIfMinimized(true);
1195 void BitcoinGUI::error(const QString &title, const QString &message, bool modal)
1197 // Report errors from network/worker thread
1200 QMessageBox::critical(this, title, message, QMessageBox::Ok, QMessageBox::Ok);
1202 notificator->notify(Notificator::Critical, title, message);