4 * W.J. van der Laan 2011-2012
5 * The Bitcoin Developers 2011-2012
7 #include "bitcoingui.h"
8 #include "transactiontablemodel.h"
9 #include "addressbookpage.h"
10 #include "sendcoinsdialog.h"
11 #include "signverifymessagedialog.h"
12 #include "multisigdialog.h"
13 #include "optionsdialog.h"
14 #include "aboutdialog.h"
15 #include "clientmodel.h"
16 #include "walletmodel.h"
17 #include "editaddressdialog.h"
18 #include "optionsmodel.h"
19 #include "transactiondescdialog.h"
20 #include "addresstablemodel.h"
21 #include "transactionview.h"
22 #include "overviewpage.h"
23 #include "bitcoinunits.h"
24 #include "guiconstants.h"
25 #include "askpassphrasedialog.h"
26 #include "notificator.h"
28 #include "ui_interface.h"
29 #include "rpcconsole.h"
30 #include "mintingview.h"
33 #include "macdockiconhandler.h"
36 #include <QApplication>
37 #if QT_VERSION < 0x050000
38 #include <QMainWindow>
44 #include <QVBoxLayout>
49 #include <QPushButton>
51 #include <QMessageBox>
52 #include <QProgressBar>
53 #include <QStackedWidget>
56 #include <QFileDialog>
57 #if QT_VERSION < 0x050000
58 #include <QDesktopServices>
60 #include <QStandardPaths>
63 #include <QDragEnterEvent>
64 #if QT_VERSION < 0x050000
72 extern bool fWalletUnlockMintOnly;
74 BitcoinGUI::BitcoinGUI(QWidget *parent):
78 encryptWalletAction(0),
80 unlockWalletAction(0),
81 unlockWalletMiningAction(0),
82 changePassphraseAction(0),
90 signVerifyMessageDialog(0)
93 setWindowTitle(tr("NovaCoin") + " - " + tr("Wallet"));
95 qApp->setWindowIcon(QIcon(":icons/bitcoin"));
96 setWindowIcon(QIcon(":icons/bitcoin"));
98 setUnifiedTitleAndToolBarOnMac(true);
99 QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
101 // Accept D&D of URIs
102 setAcceptDrops(true);
104 // Create actions for the toolbar, menu bar and tray/dock icon
107 // Create application menu bar
110 // Create the toolbars
113 // Create the tray icon (or setup the dock icon)
117 overviewPage = new OverviewPage();
119 transactionsPage = new QWidget(this);
120 QVBoxLayout *vbox = new QVBoxLayout();
121 transactionView = new TransactionView(this);
122 vbox->addWidget(transactionView);
123 transactionsPage->setLayout(vbox);
125 mintingPage = new QWidget(this);
126 QVBoxLayout *vboxMinting = new QVBoxLayout();
127 mintingView = new MintingView(this);
128 vboxMinting->addWidget(mintingView);
129 mintingPage->setLayout(vboxMinting);
131 addressBookPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::SendingTab);
133 receiveCoinsPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::ReceivingTab);
135 sendCoinsPage = new SendCoinsDialog(this);
137 signVerifyMessageDialog = new SignVerifyMessageDialog(0);
139 multisigPage = new MultisigDialog(0);
141 centralWidget = new QStackedWidget(this);
142 centralWidget->addWidget(overviewPage);
143 centralWidget->addWidget(transactionsPage);
144 centralWidget->addWidget(mintingPage);
145 centralWidget->addWidget(addressBookPage);
146 centralWidget->addWidget(receiveCoinsPage);
147 centralWidget->addWidget(sendCoinsPage);
148 setCentralWidget(centralWidget);
153 // Status bar notification icons
154 QFrame *frameBlocks = new QFrame();
155 frameBlocks->setContentsMargins(0,0,0,0);
156 frameBlocks->setMinimumWidth(72);
157 frameBlocks->setMaximumWidth(72);
158 QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);
159 frameBlocksLayout->setContentsMargins(3,0,3,0);
160 frameBlocksLayout->setSpacing(3);
161 labelEncryptionIcon = new QLabel();
162 labelMiningIcon = new QLabel();
163 labelConnectionsIcon = new QLabel();
164 labelBlocksIcon = new QLabel();
165 frameBlocksLayout->addStretch();
166 frameBlocksLayout->addWidget(labelEncryptionIcon);
167 frameBlocksLayout->addStretch();
168 frameBlocksLayout->addWidget(labelMiningIcon);
169 frameBlocksLayout->addStretch();
170 frameBlocksLayout->addWidget(labelConnectionsIcon);
171 frameBlocksLayout->addStretch();
172 frameBlocksLayout->addWidget(labelBlocksIcon);
173 frameBlocksLayout->addStretch();
175 // Progress bar and label for blocks download
176 progressBarLabel = new QLabel();
177 progressBarLabel->setVisible(false);
178 progressBar = new QProgressBar();
179 progressBar->setAlignment(Qt::AlignCenter);
180 progressBar->setVisible(false);
182 // Override style sheet for progress bar for styles that have a segmented progress bar,
183 // as they make the text unreadable (workaround for issue #1071)
184 // See https://qt-project.org/doc/qt-4.8/gallery.html
185 QString curStyle = qApp->style()->metaObject()->className();
186 if(curStyle == "QWindowsStyle" || curStyle == "QWindowsXPStyle")
188 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; }");
191 statusBar()->addWidget(progressBarLabel);
192 statusBar()->addWidget(progressBar);
193 statusBar()->addPermanentWidget(frameBlocks);
195 syncIconMovie = new QMovie(":/movies/update_spinner", "mng", this);
197 // Clicking on a transaction on the overview page simply sends you to transaction history page
198 connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), this, SLOT(gotoHistoryPage()));
199 connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex)));
201 // Double-clicking on a transaction on the transaction history page shows details
202 connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
204 rpcConsole = new RPCConsole(0);
205 connect(openRPCConsoleAction, SIGNAL(triggered()), rpcConsole, SLOT(show()));
207 aboutDialog = new AboutDialog(0);
208 optionsDialog = new OptionsDialog(0);
210 // Clicking on "Verify Message" in the address book sends you to the verify message tab
211 connect(addressBookPage, SIGNAL(verifyMessage(QString)), this, SLOT(gotoVerifyMessageTab(QString)));
212 // Clicking on "Sign Message" in the receive coins page sends you to the sign message tab
213 connect(receiveCoinsPage, SIGNAL(signMessage(QString)), this, SLOT(gotoSignMessageTab(QString)));
218 BitcoinGUI::~BitcoinGUI()
220 if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu)
228 delete optionsDialog;
230 delete signVerifyMessageDialog;
233 void BitcoinGUI::createActions()
235 QActionGroup *tabGroup = new QActionGroup(this);
237 overviewAction = new QAction(QIcon(":/icons/overview"), tr("&Overview"), this);
238 overviewAction->setToolTip(tr("Show general overview of wallet"));
239 overviewAction->setCheckable(true);
240 overviewAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_1));
241 tabGroup->addAction(overviewAction);
243 sendCoinsAction = new QAction(QIcon(":/icons/send"), tr("&Send coins"), this);
244 sendCoinsAction->setToolTip(tr("Send coins to a NovaCoin address"));
245 sendCoinsAction->setCheckable(true);
246 sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2));
247 tabGroup->addAction(sendCoinsAction);
249 receiveCoinsAction = new QAction(QIcon(":/icons/receiving_addresses"), tr("&Receive coins"), this);
250 receiveCoinsAction->setToolTip(tr("Show the list of addresses for receiving payments"));
251 receiveCoinsAction->setCheckable(true);
252 receiveCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_3));
253 tabGroup->addAction(receiveCoinsAction);
255 historyAction = new QAction(QIcon(":/icons/history"), tr("&Transactions"), this);
256 historyAction->setToolTip(tr("Browse transaction history"));
257 historyAction->setCheckable(true);
258 historyAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_4));
259 tabGroup->addAction(historyAction);
261 mintingAction = new QAction(QIcon(":/icons/history"), tr("&Minting"), this);
262 mintingAction->setToolTip(tr("Show your minting capacity"));
263 mintingAction->setCheckable(true);
264 mintingAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_5));
265 tabGroup->addAction(mintingAction);
267 addressBookAction = new QAction(QIcon(":/icons/address-book"), tr("&Address Book"), this);
268 addressBookAction->setToolTip(tr("Edit the list of stored addresses and labels"));
269 addressBookAction->setCheckable(true);
270 addressBookAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_6));
271 tabGroup->addAction(addressBookAction);
273 multisigAction = new QAction(QIcon(":/icons/send"), tr("Multisig"), this);
274 multisigAction->setStatusTip(tr("Open window for working with multisig addresses"));
275 tabGroup->addAction(multisigAction);
277 connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
278 connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage()));
279 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
280 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
281 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
282 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
283 connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
284 connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage()));
285 connect(mintingAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
286 connect(mintingAction, SIGNAL(triggered()), this, SLOT(gotoMintingPage()));
287 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
288 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(gotoAddressBookPage()));
289 connect(multisigAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
290 connect(multisigAction, SIGNAL(triggered()), this, SLOT(gotoMultisigPage()));
292 quitAction = new QAction(QIcon(":/icons/quit"), tr("E&xit"), this);
293 quitAction->setStatusTip(tr("Quit application"));
294 quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
295 quitAction->setMenuRole(QAction::QuitRole);
296 aboutAction = new QAction(QIcon(":/icons/bitcoin"), tr("&About NovaCoin"), this);
297 aboutAction->setStatusTip(tr("Show information about NovaCoin"));
298 aboutAction->setMenuRole(QAction::AboutRole);
299 #if QT_VERSION < 0x050000
300 aboutQtAction = new QAction(QIcon(":/trolltech/qmessagebox/images/qtlogo-64.png"), tr("About &Qt"), this);
302 aboutQtAction = new QAction(QIcon(":/qt-project.org/qmessagebox/images/qtlogo-64.png"), tr("About &Qt"), this);
304 aboutQtAction->setStatusTip(tr("Show information about Qt"));
305 aboutQtAction->setMenuRole(QAction::AboutQtRole);
306 optionsAction = new QAction(QIcon(":/icons/options"), tr("&Options..."), this);
307 optionsAction->setStatusTip(tr("Modify configuration options for NovaCoin"));
308 optionsAction->setMenuRole(QAction::PreferencesRole);
309 toggleHideAction = new QAction(QIcon(":/icons/bitcoin"), tr("&Show / Hide"), this);
310 encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet..."), this);
311 encryptWalletAction->setStatusTip(tr("Encrypt or decrypt wallet"));
312 encryptWalletAction->setCheckable(true);
313 backupWalletAction = new QAction(QIcon(":/icons/filesave"), tr("&Backup Wallet..."), this);
314 backupWalletAction->setStatusTip(tr("Backup wallet to another location"));
315 dumpWalletAction = new QAction(QIcon(":/icons/dump"), tr("&Dump Wallet..."), this);
316 dumpWalletAction->setStatusTip(tr("Dump keys to a text file"));
317 importWalletAction = new QAction(QIcon(":/icons/import"), tr("&Import Wallet..."), this);
318 importWalletAction->setStatusTip(tr("Import keys into a wallet"));
319 changePassphraseAction = new QAction(QIcon(":/icons/key"), tr("&Change Passphrase..."), this);
320 changePassphraseAction->setStatusTip(tr("Change the passphrase used for wallet encryption"));
321 signMessageAction = new QAction(QIcon(":/icons/edit"), tr("Sign &message..."), this);
322 signMessageAction->setStatusTip(tr("Sign messages with your Novacoin addresses to prove you own them"));
323 verifyMessageAction = new QAction(QIcon(":/icons/transaction_0"), tr("&Verify message..."), this);
324 verifyMessageAction->setStatusTip(tr("Verify messages to ensure they were signed with specified Novacoin addresses"));
326 lockWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Lock wallet"), this);
327 lockWalletAction->setStatusTip(tr("Lock wallet"));
328 lockWalletAction->setCheckable(true);
330 unlockWalletAction = new QAction(QIcon(":/icons/lock_open"), tr("Unlo&ck wallet"), this);
331 unlockWalletAction->setStatusTip(tr("Unlock wallet"));
332 unlockWalletAction->setCheckable(true);
334 unlockWalletMiningAction = new QAction(QIcon(":/icons/mining_active"), tr("Unlo&ck wallet for mining"), this);
335 unlockWalletMiningAction->setStatusTip(tr("Unlock wallet for mining"));
336 unlockWalletMiningAction->setCheckable(true);
338 exportAction = new QAction(QIcon(":/icons/export"), tr("&Export..."), this);
339 exportAction->setStatusTip(tr("Export the data in the current tab to a file"));
340 openRPCConsoleAction = new QAction(QIcon(":/icons/debugwindow"), tr("&Debug window"), this);
341 openRPCConsoleAction->setStatusTip(tr("Open debugging and diagnostic console"));
343 connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
344 connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked()));
345 connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
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()));
360 void BitcoinGUI::createMenuBar()
363 // Create a decoupled menu bar on Mac which stays even if the window is closed
364 appMenuBar = new QMenuBar();
366 // Get the main window's menu bar on other platforms
367 appMenuBar = menuBar();
370 // Configure the menus
371 QMenu *file = appMenuBar->addMenu(tr("&File"));
372 file->addAction(backupWalletAction);
373 file->addSeparator();
374 file->addAction(dumpWalletAction);
375 file->addAction(importWalletAction);
376 file->addAction(exportAction);
377 file->addAction(signMessageAction);
378 file->addAction(verifyMessageAction);
379 file->addAction(multisigAction);
380 file->addSeparator();
381 file->addAction(quitAction);
383 QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
384 QMenu *securityMenu = settings->addMenu(QIcon(":/icons/key"), tr("&Wallet security"));
385 securityMenu->addAction(encryptWalletAction);
386 securityMenu->addAction(changePassphraseAction);
387 securityMenu->addAction(unlockWalletAction);
388 securityMenu->addAction(unlockWalletMiningAction);
389 securityMenu->addAction(lockWalletAction);
390 settings->addAction(optionsAction);
392 QMenu *help = appMenuBar->addMenu(tr("&Help"));
393 help->addAction(openRPCConsoleAction);
394 help->addSeparator();
395 help->addAction(aboutAction);
396 help->addAction(aboutQtAction);
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 multisigPage->setModel(walletModel);
481 setEncryptionStatus(walletModel->getEncryptionStatus());
482 connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));
483 connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(updateMining()));
485 // Balloon pop-up for new transaction
486 connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
487 this, SLOT(incomingTransaction(QModelIndex,int,int)));
489 // Ask for passphrase if needed
490 connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
494 void BitcoinGUI::createTrayIcon()
498 trayIcon = new QSystemTrayIcon(this);
499 trayIconMenu = new QMenu(this);
500 trayIcon->setContextMenu(trayIconMenu);
501 trayIcon->setToolTip(tr("NovaCoin client"));
502 trayIcon->setIcon(QIcon(":/icons/toolbar"));
503 connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
504 this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
507 // Note: On Mac, the dock icon is used to provide the tray's functionality.
508 MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance();
509 dockIconHandler->setMainWindow((QMainWindow *)this);
510 trayIconMenu = dockIconHandler->dockMenu();
513 // Configuration of the tray icon (or dock icon) icon menu
514 trayIconMenu->addAction(toggleHideAction);
515 trayIconMenu->addSeparator();
516 trayIconMenu->addAction(sendCoinsAction);
517 trayIconMenu->addAction(multisigAction);
518 trayIconMenu->addAction(receiveCoinsAction);
519 trayIconMenu->addSeparator();
520 trayIconMenu->addAction(signMessageAction);
521 trayIconMenu->addAction(verifyMessageAction);
522 trayIconMenu->addSeparator();
523 trayIconMenu->addAction(optionsAction);
524 trayIconMenu->addAction(openRPCConsoleAction);
526 // This is built-in on Mac
527 trayIconMenu->addSeparator();
528 trayIconMenu->addAction(quitAction);
530 notificator = new Notificator(QApplication::applicationName(), trayIcon, this);
534 void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
536 if(reason == QSystemTrayIcon::Trigger)
538 // Click on system tray icon triggers show/hide of the main window
539 toggleHideAction->trigger();
544 void BitcoinGUI::optionsClicked()
546 if(!clientModel || !clientModel->getOptionsModel())
549 optionsDialog->setModel(clientModel->getOptionsModel());
550 optionsDialog->setWindowModality(Qt::ApplicationModal);
551 optionsDialog->show();
554 void BitcoinGUI::aboutClicked()
556 aboutDialog->setModel(clientModel);
557 aboutDialog->setWindowModality(Qt::ApplicationModal);
561 void BitcoinGUI::setNumConnections(int count)
566 case 0: icon = ":/icons/connect_0"; break;
567 case 1: case 2: case 3: icon = ":/icons/connect_1"; break;
568 case 4: case 5: case 6: icon = ":/icons/connect_2"; break;
569 case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
570 default: icon = ":/icons/connect_4"; break;
572 labelConnectionsIcon->setPixmap(QIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
573 labelConnectionsIcon->setToolTip(tr("%n active connection(s) to NovaCoin network", "", count));
576 void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks)
578 // don't show / hide progress bar and its label if we have no connection to the network
579 if (!clientModel || clientModel->getNumConnections() == 0)
581 progressBarLabel->setVisible(false);
582 progressBar->setVisible(false);
587 QString strStatusBarWarnings = clientModel->getStatusBarWarnings();
590 if(count < nTotalBlocks)
592 int nRemainingBlocks = nTotalBlocks - count;
593 float nPercentageDone = count / (nTotalBlocks * 0.01f);
595 if (strStatusBarWarnings.isEmpty())
597 progressBarLabel->setText(tr("Synchronizing with network..."));
598 progressBarLabel->setVisible(true);
599 progressBar->setFormat(tr("~%n block(s) remaining", "", nRemainingBlocks));
600 progressBar->setMaximum(nTotalBlocks);
601 progressBar->setValue(count);
602 progressBar->setVisible(true);
605 tooltip = tr("Downloaded %1 of %2 blocks of transaction history (%3% done).").arg(count).arg(nTotalBlocks).arg(nPercentageDone, 0, 'f', 2);
609 if (strStatusBarWarnings.isEmpty())
610 progressBarLabel->setVisible(false);
612 progressBar->setVisible(false);
613 tooltip = tr("Downloaded %1 blocks of transaction history.").arg(count);
616 // Override progressBarLabel text and hide progress bar, when we have warnings to display
617 if (!strStatusBarWarnings.isEmpty())
619 progressBarLabel->setText(strStatusBarWarnings);
620 progressBarLabel->setVisible(true);
621 progressBar->setVisible(false);
624 QDateTime lastBlockDate = clientModel->getLastBlockDate();
625 int secs = lastBlockDate.secsTo(QDateTime::currentDateTime());
628 // Represent time from last generated block in human readable text
631 // Fully up to date. Leave text empty.
635 text = tr("%n second(s) ago","",secs);
637 else if(secs < 60*60)
639 text = tr("%n minute(s) ago","",secs/60);
641 else if(secs < 24*60*60)
643 text = tr("%n hour(s) ago","",secs/(60*60));
647 text = tr("%n day(s) ago","",secs/(60*60*24));
650 // Set icon state: spinning if catching up, tick otherwise
651 if(secs < 90*60 && count >= nTotalBlocks)
653 tooltip = tr("Up to date") + QString(".<br>") + tooltip;
654 labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
656 overviewPage->showOutOfSyncWarning(false);
660 tooltip = tr("Catching up...") + QString("<br>") + tooltip;
661 labelBlocksIcon->setMovie(syncIconMovie);
662 syncIconMovie->start();
664 overviewPage->showOutOfSyncWarning(true);
669 tooltip += QString("<br>");
670 tooltip += tr("Last received block was generated %1.").arg(text);
673 // Don't word-wrap this (fixed-width) tooltip
674 tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
676 labelBlocksIcon->setToolTip(tooltip);
677 progressBarLabel->setToolTip(tooltip);
678 progressBar->setToolTip(tooltip);
681 void BitcoinGUI::updateMining()
686 labelMiningIcon->setPixmap(QIcon(":/icons/mining_inactive").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
688 if (!clientModel->getNumConnections())
690 labelMiningIcon->setToolTip(tr("Wallet is offline"));
694 if (walletModel->getEncryptionStatus() == WalletModel::Locked)
696 labelMiningIcon->setToolTip(tr("Wallet is locked"));
700 if (clientModel->inInitialBlockDownload() || clientModel->getNumBlocksOfPeers() > clientModel->getNumBlocks())
702 labelMiningIcon->setToolTip(tr("Blockchain download is in progress"));
706 float nKernelsRate = 0, nCoinDaysRate = 0;
707 walletModel->getStakeStats(nKernelsRate, nCoinDaysRate);
709 if (nKernelsRate > 0)
711 labelMiningIcon->setPixmap(QIcon(":/icons/mining_active").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
713 uint64_t nNetworkWeight = clientModel->getPoSKernelPS();
715 double dDifficulty = clientModel->getDifficulty(true);
718 int nApproxTime = 4294967297 * dDifficulty / nTotalWeight;
720 if (nApproxTime < 60)
721 msg = tr("%n second(s)", "", nApproxTime);
722 else if (nApproxTime < 60*60)
723 msg = tr("%n minute(s)", "", nApproxTime / 60);
724 else if (nApproxTime < 24*60*60)
725 msg = tr("%n hour(s)", "", nApproxTime / 3600);
727 msg = tr("%n day(s)", "", nApproxTime / 86400);
729 labelMiningIcon->setToolTip(tr("Stake miner is active\nYour current stake weight is %1\nNetwork weight is %2\nAverage block generation time is %3").arg(nTotalWeight).arg(dNetworkWeight).arg(msg));
732 labelMiningIcon->setToolTip(QString("<nobr>")+tr("Stake miner is active<br>Kernel rate is %1 k/s<br>CD rate is %2 CD/s<br>Network weight is %3").arg(nKernelsRate).arg(nCoinDaysRate).arg(nNetworkWeight)+QString("<\nobr>"));
735 labelMiningIcon->setToolTip(tr("No suitable inputs were found"));
738 void BitcoinGUI::error(const QString &title, const QString &message, bool modal)
740 // Report errors from network/worker thread
743 QMessageBox::critical(this, title, message, QMessageBox::Ok, QMessageBox::Ok);
745 notificator->notify(Notificator::Critical, title, message);
749 void BitcoinGUI::message(const QString &title, const QString &message, unsigned int style, const QString &detail)
751 QString strTitle = tr("NovaCoin") + " - ";
752 // Default to information icon
753 int nMBoxIcon = QMessageBox::Information;
754 int nNotifyIcon = Notificator::Information;
757 // Check for usage of predefined title
759 case CClientUIInterface::MSG_ERROR:
760 strTitle += tr("Error");
762 case CClientUIInterface::MSG_WARNING:
763 strTitle += tr("Warning");
765 case CClientUIInterface::MSG_INFORMATION:
766 strTitle += tr("Information");
769 strTitle += title; // Use supplied title
772 // Check for error/warning icon
773 if (style & CClientUIInterface::ICON_ERROR) {
774 nMBoxIcon = QMessageBox::Critical;
775 nNotifyIcon = Notificator::Critical;
777 else if (style & CClientUIInterface::ICON_WARNING) {
778 nMBoxIcon = QMessageBox::Warning;
779 nNotifyIcon = Notificator::Warning;
783 if (style & CClientUIInterface::MODAL) {
784 // Check for buttons, use OK as default, if none was supplied
785 QMessageBox::StandardButton buttons;
786 buttons = QMessageBox::Ok;
788 QMessageBox mBox((QMessageBox::Icon)nMBoxIcon, strTitle, message, buttons);
790 if(!detail.isEmpty()) { mBox.setDetailedText(detail); }
795 notificator->notify((Notificator::Class)nNotifyIcon, strTitle, message);
799 void BitcoinGUI::changeEvent(QEvent *e)
801 QMainWindow::changeEvent(e);
802 #ifndef Q_OS_MAC // Ignored on Mac
803 if(e->type() == QEvent::WindowStateChange)
805 if(clientModel && clientModel->getOptionsModel()->getMinimizeToTray())
807 QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
808 if(!(wsevt->oldState() & Qt::WindowMinimized) && isMinimized())
810 QTimer::singleShot(0, this, SLOT(hide()));
818 void BitcoinGUI::closeEvent(QCloseEvent *event)
822 #ifndef Q_OS_MAC // Ignored on Mac
823 if(!clientModel->getOptionsModel()->getMinimizeOnClose())
829 // close rpcConsole in case it was open to make some space for the shutdown window
832 QMainWindow::closeEvent(event);
835 void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
838 tr("This transaction is over the size limit. You can still send it for a fee of %1, "
839 "which goes to the nodes that process your transaction and helps to support the network. "
840 "Do you want to pay the fee?").arg(
841 BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nFeeRequired));
842 QMessageBox::StandardButton retval = QMessageBox::question(
843 this, tr("Confirm transaction fee"), strMessage,
844 QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes);
845 *payFee = (retval == QMessageBox::Yes);
848 void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
850 if(!walletModel || !clientModel)
852 TransactionTableModel *ttm = walletModel->getTransactionTableModel();
853 qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
854 .data(Qt::EditRole).toULongLong();
855 if(!clientModel->inInitialBlockDownload())
857 // On new transaction, make an info balloon
858 // Unless the initial block download is in progress, to prevent balloon-spam
859 QString date = ttm->index(start, TransactionTableModel::Date, parent)
861 QString type = ttm->index(start, TransactionTableModel::Type, parent)
863 QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
865 QIcon icon = qvariant_cast<QIcon>(ttm->index(start,
866 TransactionTableModel::ToAddress, parent)
867 .data(Qt::DecorationRole));
869 notificator->notify(Notificator::Information,
870 (amount)<0 ? tr("Sent transaction") :
871 tr("Incoming transaction"),
877 .arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true))
879 .arg(address), icon);
883 void BitcoinGUI::gotoOverviewPage()
885 overviewAction->setChecked(true);
886 centralWidget->setCurrentWidget(overviewPage);
888 exportAction->setEnabled(false);
889 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
892 void BitcoinGUI::gotoHistoryPage()
894 historyAction->setChecked(true);
895 centralWidget->setCurrentWidget(transactionsPage);
897 exportAction->setEnabled(true);
898 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
899 connect(exportAction, SIGNAL(triggered()), transactionView, SLOT(exportClicked()));
902 void BitcoinGUI::gotoMintingPage()
904 mintingAction->setChecked(true);
905 centralWidget->setCurrentWidget(mintingPage);
907 exportAction->setEnabled(true);
908 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
909 connect(exportAction, SIGNAL(triggered()), mintingView, SLOT(exportClicked()));
913 void BitcoinGUI::gotoAddressBookPage()
915 addressBookAction->setChecked(true);
916 centralWidget->setCurrentWidget(addressBookPage);
918 exportAction->setEnabled(true);
919 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
920 connect(exportAction, SIGNAL(triggered()), addressBookPage, SLOT(exportClicked()));
923 void BitcoinGUI::gotoReceiveCoinsPage()
925 receiveCoinsAction->setChecked(true);
926 centralWidget->setCurrentWidget(receiveCoinsPage);
928 exportAction->setEnabled(true);
929 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
930 connect(exportAction, SIGNAL(triggered()), receiveCoinsPage, SLOT(exportClicked()));
933 void BitcoinGUI::gotoSendCoinsPage()
935 sendCoinsAction->setChecked(true);
936 centralWidget->setCurrentWidget(sendCoinsPage);
938 exportAction->setEnabled(false);
939 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
942 void BitcoinGUI::gotoSignMessageTab(QString addr)
944 // call show() in showTab_SM()
945 signVerifyMessageDialog->showTab_SM(true);
948 signVerifyMessageDialog->setAddress_SM(addr);
951 void BitcoinGUI::gotoVerifyMessageTab(QString addr)
953 // call show() in showTab_VM()
954 signVerifyMessageDialog->showTab_VM(true);
957 signVerifyMessageDialog->setAddress_VM(addr);
960 void BitcoinGUI::gotoMultisigPage()
962 multisigPage->show();
963 multisigPage->setFocus();
966 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
969 if(event->mimeData()->hasUrls())
970 event->acceptProposedAction();
973 void BitcoinGUI::dropEvent(QDropEvent *event)
975 if(event->mimeData()->hasUrls())
977 int nValidUrisFound = 0;
978 QList<QUrl> uris = event->mimeData()->urls();
979 foreach(const QUrl &uri, uris)
981 if (sendCoinsPage->handleURI(uri.toString()))
985 // if valid URIs were found
989 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."));
992 event->acceptProposedAction();
995 void BitcoinGUI::handleURI(QString strURI)
997 // URI has to be valid
998 if (sendCoinsPage->handleURI(strURI))
1000 showNormalIfMinimized();
1001 gotoSendCoinsPage();
1004 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."));
1007 void BitcoinGUI::setEncryptionStatus(int status)
1011 case WalletModel::Unencrypted:
1012 labelEncryptionIcon->hide();
1013 encryptWalletAction->setChecked(false);
1014 changePassphraseAction->setEnabled(false);
1015 lockWalletAction->setEnabled(false);
1016 unlockWalletAction->setEnabled(false);
1017 unlockWalletMiningAction->setEnabled(false);
1018 encryptWalletAction->setEnabled(true);
1020 case WalletModel::Unlocked:
1021 labelEncryptionIcon->show();
1022 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
1023 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
1024 encryptWalletAction->setChecked(true);
1025 changePassphraseAction->setEnabled(true);
1026 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
1028 lockWalletAction->setEnabled(true);
1029 lockWalletAction->setChecked(false);
1030 unlockWalletAction->setEnabled(false);
1031 unlockWalletMiningAction->setEnabled(false);
1033 if (fWalletUnlockMintOnly)
1034 unlockWalletMiningAction->setChecked(true);
1036 unlockWalletAction->setChecked(true);
1039 case WalletModel::Locked:
1040 labelEncryptionIcon->show();
1041 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
1042 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
1043 encryptWalletAction->setChecked(true);
1044 changePassphraseAction->setEnabled(true);
1045 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
1047 lockWalletAction->setChecked(true);
1048 unlockWalletAction->setChecked(false);
1049 unlockWalletMiningAction->setChecked(false);
1051 lockWalletAction->setEnabled(false);
1052 unlockWalletAction->setEnabled(true);
1053 unlockWalletMiningAction->setEnabled(true);
1058 void BitcoinGUI::encryptWallet(bool status)
1062 AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt:
1063 AskPassphraseDialog::Decrypt, this);
1064 dlg.setModel(walletModel);
1067 setEncryptionStatus(walletModel->getEncryptionStatus());
1070 void BitcoinGUI::unlockWalletMining(bool status)
1075 // Unlock wallet when requested by wallet model
1076 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1078 AskPassphraseDialog dlg(AskPassphraseDialog::UnlockMining, this);
1079 dlg.setModel(walletModel);
1084 void BitcoinGUI::backupWallet()
1086 #if QT_VERSION < 0x050000
1087 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1089 QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1091 QString filename = QFileDialog::getSaveFileName(this, tr("Backup Wallet"), saveDir, tr("Wallet Data (*.dat)"));
1092 if(!filename.isEmpty()) {
1093 if(!walletModel->backupWallet(filename)) {
1094 QMessageBox::warning(this, tr("Backup Failed"), tr("There was an error trying to save the wallet data to the new location."));
1099 void BitcoinGUI::dumpWallet()
1104 WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1107 // Unlock wallet failed or was cancelled
1111 #if QT_VERSION < 0x050000
1112 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1114 QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1116 QString filename = QFileDialog::getSaveFileName(this, tr("Dump Wallet"), saveDir, tr("Wallet dump (*.txt)"));
1117 if(!filename.isEmpty()) {
1118 if(!walletModel->dumpWallet(filename)) {
1119 error(tr("Dump failed"),
1120 tr("An error happened while trying to save the keys to your location.\n"
1121 "Keys were not saved.")
1122 ,CClientUIInterface::MSG_ERROR);
1125 message(tr("Dump successful"),
1126 tr("Keys were saved to this file:\n%2")
1128 ,CClientUIInterface::MSG_INFORMATION);
1132 void BitcoinGUI::importWallet()
1137 WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1140 // Unlock wallet failed or was cancelled
1144 #if QT_VERSION < 0x050000
1145 QString openDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1147 QString openDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1149 QString filename = QFileDialog::getOpenFileName(this, tr("Import Wallet"), openDir, tr("Wallet dump (*.txt)"));
1150 if(!filename.isEmpty()) {
1151 if(!walletModel->importWallet(filename)) {
1152 error(tr("Import Failed"),
1153 tr("An error happened while trying to import the keys.\n"
1154 "Some or all keys from:\n %1,\n were not imported into your wallet.")
1156 ,CClientUIInterface::MSG_ERROR);
1159 message(tr("Import Successful"),
1160 tr("All keys from:\n %1,\n were imported into your wallet.")
1162 ,CClientUIInterface::MSG_INFORMATION);
1167 void BitcoinGUI::changePassphrase()
1169 AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
1170 dlg.setModel(walletModel);
1174 void BitcoinGUI::unlockWallet()
1178 // Unlock wallet when requested by wallet model
1179 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1181 AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
1182 dlg.setModel(walletModel);
1187 void BitcoinGUI::lockWallet()
1192 walletModel->setWalletLocked(true);
1195 void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden)
1197 // activateWindow() (sometimes) helps with keyboard focus on Windows
1200 // Make sure the window is not minimized
1201 setWindowState(windowState() & (~Qt::WindowMinimized | Qt::WindowActive));
1207 else if (isMinimized())
1213 else if (GUIUtil::isObscured(this))
1220 if (GUIUtil::isObscured(this))
1224 else if(fToggleHidden)
1228 void BitcoinGUI::toggleHidden()
1230 showNormalIfMinimized(true);