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(), clientModel->getNumBlocksOfPeers());
447 connect(clientModel, SIGNAL(numBlocksChanged(int,int)), this, SLOT(setNumBlocks(int,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, int nTotalBlocks)
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(count < nTotalBlocks)
594 int nRemainingBlocks = nTotalBlocks - count;
595 float nPercentageDone = count / (nTotalBlocks * 0.01f);
597 if (strStatusBarWarnings.isEmpty())
599 progressBarLabel->setText(tr("Synchronizing with network..."));
600 progressBarLabel->setVisible(true);
601 progressBar->setFormat(tr("~%n block(s) remaining", "", nRemainingBlocks));
602 progressBar->setMaximum(nTotalBlocks);
603 progressBar->setValue(count);
604 progressBar->setVisible(true);
607 tooltip = tr("Downloaded %1 of %2 blocks of transaction history (%3% done).").arg(count).arg(nTotalBlocks).arg(nPercentageDone, 0, 'f', 2);
611 if (strStatusBarWarnings.isEmpty())
612 progressBarLabel->setVisible(false);
614 progressBar->setVisible(false);
615 tooltip = tr("Downloaded %1 blocks of transaction history.").arg(count);
618 // Override progressBarLabel text and hide progress bar, when we have warnings to display
619 if (!strStatusBarWarnings.isEmpty())
621 progressBarLabel->setText(strStatusBarWarnings);
622 progressBarLabel->setVisible(true);
623 progressBar->setVisible(false);
626 tooltip = tr("Current PoW difficulty is %1.").arg(clientModel->getDifficulty(false)) + QString("<br>") + tooltip;
627 tooltip = tr("Current PoS difficulty is %1.").arg(clientModel->getDifficulty(true)) + QString("<br>") + tooltip;
629 QDateTime lastBlockDate = clientModel->getLastBlockDate();
630 int secs = lastBlockDate.secsTo(QDateTime::currentDateTime());
633 // Represent time from last generated block in human readable text
636 // Fully up to date. Leave text empty.
640 text = tr("%n second(s) ago","",secs);
642 else if(secs < 60*60)
644 text = tr("%n minute(s) ago","",secs/60);
646 else if(secs < 24*60*60)
648 text = tr("%n hour(s) ago","",secs/(60*60));
652 text = tr("%n day(s) ago","",secs/(60*60*24));
655 // Set icon state: spinning if catching up, tick otherwise
656 if(secs < 90*60 && count >= nTotalBlocks)
658 tooltip = tr("Up to date") + QString(".<br>") + tooltip;
659 labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
661 overviewPage->showOutOfSyncWarning(false);
665 tooltip = tr("Catching up...") + QString("<br>") + tooltip;
666 labelBlocksIcon->setMovie(syncIconMovie);
667 syncIconMovie->start();
669 overviewPage->showOutOfSyncWarning(true);
674 tooltip += QString("<br>");
675 tooltip += tr("Last received block was generated %1.").arg(text);
678 // Don't word-wrap this (fixed-width) tooltip
679 tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
681 labelBlocksIcon->setToolTip(tooltip);
682 progressBarLabel->setToolTip(tooltip);
683 progressBar->setToolTip(tooltip);
686 void BitcoinGUI::updateMining()
691 labelMiningIcon->setPixmap(QIcon(":/icons/mining_inactive").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
693 if (!clientModel->getNumConnections())
695 labelMiningIcon->setToolTip(tr("Wallet is offline"));
699 if (walletModel->getEncryptionStatus() == WalletModel::Locked)
701 labelMiningIcon->setToolTip(tr("Wallet is locked"));
705 if (clientModel->inInitialBlockDownload() || clientModel->getNumBlocksOfPeers() > clientModel->getNumBlocks())
707 labelMiningIcon->setToolTip(tr("Blockchain download is in progress"));
711 if (nStakeInputsMapSize > 0)
713 labelMiningIcon->setPixmap(QIcon(":/icons/mining_active").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
715 uint64_t nNetworkWeight = clientModel->getPoSKernelPS();
717 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>"));
720 labelMiningIcon->setToolTip(tr("No suitable inputs were found"));
723 void BitcoinGUI::message(const QString &title, const QString &message, unsigned int style, const QString &detail)
725 QString strTitle = tr("NovaCoin") + " - ";
726 // Default to information icon
727 int nMBoxIcon = QMessageBox::Information;
728 int nNotifyIcon = Notificator::Information;
731 // Check for usage of predefined title
733 case CClientUIInterface::MSG_ERROR:
734 strTitle += tr("Error");
736 case CClientUIInterface::MSG_WARNING:
737 strTitle += tr("Warning");
739 case CClientUIInterface::MSG_INFORMATION:
740 strTitle += tr("Information");
743 strTitle += title; // Use supplied title
746 // Check for error/warning icon
747 if (style & CClientUIInterface::ICON_ERROR) {
748 nMBoxIcon = QMessageBox::Critical;
749 nNotifyIcon = Notificator::Critical;
751 else if (style & CClientUIInterface::ICON_WARNING) {
752 nMBoxIcon = QMessageBox::Warning;
753 nNotifyIcon = Notificator::Warning;
757 if (style & CClientUIInterface::MODAL) {
758 // Check for buttons, use OK as default, if none was supplied
759 QMessageBox::StandardButton buttons;
760 buttons = QMessageBox::Ok;
762 QMessageBox mBox((QMessageBox::Icon)nMBoxIcon, strTitle, message, buttons);
764 if(!detail.isEmpty()) { mBox.setDetailedText(detail); }
769 notificator->notify((Notificator::Class)nNotifyIcon, strTitle, message);
773 void BitcoinGUI::changeEvent(QEvent *e)
775 QMainWindow::changeEvent(e);
776 #ifndef Q_OS_MAC // Ignored on Mac
777 if(e->type() == QEvent::WindowStateChange)
779 if(clientModel && clientModel->getOptionsModel()->getMinimizeToTray())
781 QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
782 if(!(wsevt->oldState() & Qt::WindowMinimized) && isMinimized())
784 QTimer::singleShot(0, this, SLOT(hide()));
792 void BitcoinGUI::closeEvent(QCloseEvent *event)
796 #ifndef Q_OS_MAC // Ignored on Mac
797 if(!clientModel->getOptionsModel()->getMinimizeOnClose())
803 // close rpcConsole in case it was open to make some space for the shutdown window
806 QMainWindow::closeEvent(event);
809 void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
812 tr("This transaction is over the size limit. You can still send it for a fee of %1, "
813 "which goes to the nodes that process your transaction and helps to support the network. "
814 "Do you want to pay the fee?").arg(
815 BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nFeeRequired));
816 QMessageBox::StandardButton retval = QMessageBox::question(
817 this, tr("Confirm transaction fee"), strMessage,
818 QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes);
819 *payFee = (retval == QMessageBox::Yes);
822 void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
824 if(!walletModel || !clientModel)
826 TransactionTableModel *ttm = walletModel->getTransactionTableModel();
827 qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
828 .data(Qt::EditRole).toULongLong();
829 if(!clientModel->inInitialBlockDownload())
831 // On new transaction, make an info balloon
832 // Unless the initial block download is in progress, to prevent balloon-spam
833 QString date = ttm->index(start, TransactionTableModel::Date, parent)
835 QString type = ttm->index(start, TransactionTableModel::Type, parent)
837 QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
839 QIcon icon = qvariant_cast<QIcon>(ttm->index(start,
840 TransactionTableModel::ToAddress, parent)
841 .data(Qt::DecorationRole));
843 notificator->notify(Notificator::Information,
844 (amount)<0 ? tr("Sent transaction") :
845 tr("Incoming transaction"),
851 .arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true))
853 .arg(address), icon);
857 void BitcoinGUI::gotoOverviewPage()
859 overviewAction->setChecked(true);
860 centralWidget->setCurrentWidget(overviewPage);
862 exportAction->setEnabled(false);
863 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
866 void BitcoinGUI::gotoHistoryPage()
868 historyAction->setChecked(true);
869 centralWidget->setCurrentWidget(transactionsPage);
871 exportAction->setEnabled(true);
872 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
873 connect(exportAction, SIGNAL(triggered()), transactionView, SLOT(exportClicked()));
876 void BitcoinGUI::gotoMintingPage()
878 mintingAction->setChecked(true);
879 centralWidget->setCurrentWidget(mintingPage);
881 exportAction->setEnabled(true);
882 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
883 connect(exportAction, SIGNAL(triggered()), mintingView, SLOT(exportClicked()));
887 void BitcoinGUI::gotoAddressBookPage()
889 addressBookAction->setChecked(true);
890 centralWidget->setCurrentWidget(addressBookPage);
892 exportAction->setEnabled(true);
893 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
894 connect(exportAction, SIGNAL(triggered()), addressBookPage, SLOT(exportClicked()));
897 void BitcoinGUI::gotoReceiveCoinsPage()
899 receiveCoinsAction->setChecked(true);
900 centralWidget->setCurrentWidget(receiveCoinsPage);
902 exportAction->setEnabled(true);
903 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
904 connect(exportAction, SIGNAL(triggered()), receiveCoinsPage, SLOT(exportClicked()));
907 void BitcoinGUI::gotoSendCoinsPage()
909 sendCoinsAction->setChecked(true);
910 centralWidget->setCurrentWidget(sendCoinsPage);
912 exportAction->setEnabled(false);
913 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
916 void BitcoinGUI::gotoSignMessageTab(QString addr)
918 // call show() in showTab_SM()
919 signVerifyMessageDialog->showTab_SM(true);
922 signVerifyMessageDialog->setAddress_SM(addr);
925 void BitcoinGUI::gotoVerifyMessageTab(QString addr)
927 // call show() in showTab_VM()
928 signVerifyMessageDialog->showTab_VM(true);
931 signVerifyMessageDialog->setAddress_VM(addr);
934 void BitcoinGUI::gotoSecondAuthPage(QString addr)
936 secondAuthDialog->show();
937 secondAuthDialog->raise();
938 secondAuthDialog->activateWindow();
941 void BitcoinGUI::gotoMultisigPage()
943 multisigPage->show();
944 multisigPage->raise();
945 multisigPage->activateWindow();
948 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
951 if(event->mimeData()->hasUrls())
952 event->acceptProposedAction();
955 void BitcoinGUI::dropEvent(QDropEvent *event)
957 if(event->mimeData()->hasUrls())
959 int nValidUrisFound = 0;
960 QList<QUrl> uris = event->mimeData()->urls();
961 foreach(const QUrl &uri, uris)
963 if (sendCoinsPage->handleURI(uri.toString()))
967 // if valid URIs were found
971 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."));
974 event->acceptProposedAction();
977 void BitcoinGUI::handleURI(QString strURI)
979 // URI has to be valid
980 if (sendCoinsPage->handleURI(strURI))
982 showNormalIfMinimized();
986 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."));
989 void BitcoinGUI::setEncryptionStatus(int status)
993 case WalletModel::Unencrypted:
994 labelEncryptionIcon->hide();
995 encryptWalletAction->setChecked(false);
996 changePassphraseAction->setEnabled(false);
997 lockWalletAction->setEnabled(false);
998 unlockWalletAction->setEnabled(false);
999 unlockWalletMiningAction->setEnabled(false);
1000 encryptWalletAction->setEnabled(true);
1002 case WalletModel::Unlocked:
1003 labelEncryptionIcon->show();
1004 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
1005 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
1006 encryptWalletAction->setChecked(true);
1007 changePassphraseAction->setEnabled(true);
1008 encryptWalletAction->setEnabled(true);
1010 lockWalletAction->setEnabled(true);
1011 lockWalletAction->setChecked(false);
1012 unlockWalletAction->setEnabled(false);
1013 unlockWalletMiningAction->setEnabled(false);
1015 if (fWalletUnlockMintOnly)
1016 unlockWalletMiningAction->setChecked(true);
1018 unlockWalletAction->setChecked(true);
1021 case WalletModel::Locked:
1022 labelEncryptionIcon->show();
1023 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
1024 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
1025 encryptWalletAction->setChecked(true);
1026 changePassphraseAction->setEnabled(true);
1027 encryptWalletAction->setEnabled(true);
1029 lockWalletAction->setChecked(true);
1030 unlockWalletAction->setChecked(false);
1031 unlockWalletMiningAction->setChecked(false);
1033 lockWalletAction->setEnabled(false);
1034 unlockWalletAction->setEnabled(true);
1035 unlockWalletMiningAction->setEnabled(true);
1040 void BitcoinGUI::encryptWallet(bool status)
1044 AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt:
1045 AskPassphraseDialog::Decrypt, this);
1046 dlg.setModel(walletModel);
1049 setEncryptionStatus(walletModel->getEncryptionStatus());
1052 void BitcoinGUI::unlockWalletMining(bool status)
1057 // Unlock wallet when requested by wallet model
1058 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1060 AskPassphraseDialog dlg(AskPassphraseDialog::UnlockMining, this);
1061 dlg.setModel(walletModel);
1066 void BitcoinGUI::backupWallet()
1068 #if QT_VERSION < 0x050000
1069 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1071 QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1073 QString filename = QFileDialog::getSaveFileName(this, tr("Backup Wallet"), saveDir, tr("Wallet Data (*.dat)"));
1074 if(!filename.isEmpty()) {
1075 if(!walletModel->backupWallet(filename)) {
1076 QMessageBox::warning(this, tr("Backup Failed"), tr("There was an error trying to save the wallet data to the new location."));
1081 void BitcoinGUI::dumpWallet()
1086 WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1089 // Unlock wallet failed or was cancelled
1093 #if QT_VERSION < 0x050000
1094 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1096 QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1098 QString filename = QFileDialog::getSaveFileName(this, tr("Dump Wallet"), saveDir, tr("Wallet dump (*.txt)"));
1099 if(!filename.isEmpty()) {
1100 if(!walletModel->dumpWallet(filename)) {
1101 message(tr("Dump failed"),
1102 tr("An error happened while trying to save the keys to your location.\n"
1103 "Keys were not saved.")
1104 ,CClientUIInterface::MSG_ERROR);
1107 message(tr("Dump successful"),
1108 tr("Keys were saved to this file:\n%2")
1110 ,CClientUIInterface::MSG_INFORMATION);
1114 void BitcoinGUI::importWallet()
1119 WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1122 // Unlock wallet failed or was cancelled
1126 #if QT_VERSION < 0x050000
1127 QString openDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1129 QString openDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1131 QString filename = QFileDialog::getOpenFileName(this, tr("Import Wallet"), openDir, tr("Wallet dump (*.txt)"));
1132 if(!filename.isEmpty()) {
1133 if(!walletModel->importWallet(filename)) {
1134 message(tr("Import Failed"),
1135 tr("An error happened while trying to import the keys.\n"
1136 "Some or all keys from:\n %1,\n were not imported into your wallet.")
1138 ,CClientUIInterface::MSG_ERROR);
1141 message(tr("Import Successful"),
1142 tr("All keys from:\n %1,\n were imported into your wallet.")
1144 ,CClientUIInterface::MSG_INFORMATION);
1149 void BitcoinGUI::changePassphrase()
1151 AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
1152 dlg.setModel(walletModel);
1156 void BitcoinGUI::unlockWallet()
1160 // Unlock wallet when requested by wallet model
1161 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1163 AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
1164 dlg.setModel(walletModel);
1169 void BitcoinGUI::lockWallet()
1174 walletModel->setWalletLocked(true);
1177 void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden)
1179 // activateWindow() (sometimes) helps with keyboard focus on Windows
1182 // Make sure the window is not minimized
1183 setWindowState(windowState() & (~Qt::WindowMinimized | Qt::WindowActive));
1189 else if (isMinimized())
1195 else if (GUIUtil::isObscured(this))
1202 if (GUIUtil::isObscured(this))
1206 else if(fToggleHidden)
1210 void BitcoinGUI::toggleHidden()
1212 showNormalIfMinimized(true);
1215 void BitcoinGUI::error(const QString &title, const QString &message, bool modal)
1217 // Report errors from network/worker thread
1220 QMessageBox::critical(this, title, message, QMessageBox::Ok, QMessageBox::Ok);
1222 notificator->notify(Notificator::Critical, title, message);