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),
89 setWindowTitle(tr("NovaCoin") + " - " + tr("Wallet"));
91 qApp->setWindowIcon(QIcon(":icons/bitcoin"));
92 setWindowIcon(QIcon(":icons/bitcoin"));
94 setUnifiedTitleAndToolBarOnMac(true);
95 QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
100 // Create actions for the toolbar, menu bar and tray/dock icon
103 // Create application menu bar
106 // Create the toolbars
109 // Create the tray icon (or setup the dock icon)
113 overviewPage = new OverviewPage();
115 transactionsPage = new QWidget(this);
116 QVBoxLayout *vbox = new QVBoxLayout();
117 transactionView = new TransactionView(this);
118 vbox->addWidget(transactionView);
119 transactionsPage->setLayout(vbox);
121 mintingPage = new QWidget(this);
122 QVBoxLayout *vboxMinting = new QVBoxLayout();
123 mintingView = new MintingView(this);
124 vboxMinting->addWidget(mintingView);
125 mintingPage->setLayout(vboxMinting);
127 addressBookPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::SendingTab);
129 receiveCoinsPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::ReceivingTab);
131 sendCoinsPage = new SendCoinsDialog(this);
133 signVerifyMessageDialog = new SignVerifyMessageDialog(this);
135 multisigPage = new MultisigDialog(this);
137 centralWidget = new QStackedWidget(this);
138 centralWidget->addWidget(overviewPage);
139 centralWidget->addWidget(transactionsPage);
140 centralWidget->addWidget(mintingPage);
141 centralWidget->addWidget(addressBookPage);
142 centralWidget->addWidget(receiveCoinsPage);
143 centralWidget->addWidget(sendCoinsPage);
144 setCentralWidget(centralWidget);
149 // Status bar notification icons
150 QFrame *frameBlocks = new QFrame();
151 frameBlocks->setContentsMargins(0,0,0,0);
152 frameBlocks->setMinimumWidth(72);
153 frameBlocks->setMaximumWidth(72);
154 QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);
155 frameBlocksLayout->setContentsMargins(3,0,3,0);
156 frameBlocksLayout->setSpacing(3);
157 labelEncryptionIcon = new QLabel();
158 labelMiningIcon = new QLabel();
159 labelConnectionsIcon = new QLabel();
160 labelBlocksIcon = new QLabel();
161 frameBlocksLayout->addStretch();
162 frameBlocksLayout->addWidget(labelEncryptionIcon);
163 frameBlocksLayout->addStretch();
164 frameBlocksLayout->addWidget(labelMiningIcon);
165 frameBlocksLayout->addStretch();
166 frameBlocksLayout->addWidget(labelConnectionsIcon);
167 frameBlocksLayout->addStretch();
168 frameBlocksLayout->addWidget(labelBlocksIcon);
169 frameBlocksLayout->addStretch();
171 // Progress bar and label for blocks download
172 progressBarLabel = new QLabel();
173 progressBarLabel->setVisible(false);
174 progressBar = new QProgressBar();
175 progressBar->setAlignment(Qt::AlignCenter);
176 progressBar->setVisible(false);
178 // Override style sheet for progress bar for styles that have a segmented progress bar,
179 // as they make the text unreadable (workaround for issue #1071)
180 // See https://qt-project.org/doc/qt-4.8/gallery.html
181 QString curStyle = qApp->style()->metaObject()->className();
182 if(curStyle == "QWindowsStyle" || curStyle == "QWindowsXPStyle")
184 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; }");
187 statusBar()->addWidget(progressBarLabel);
188 statusBar()->addWidget(progressBar);
189 statusBar()->addPermanentWidget(frameBlocks);
191 syncIconMovie = new QMovie(":/movies/update_spinner", "mng", this);
193 // Clicking on a transaction on the overview page simply sends you to transaction history page
194 connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), this, SLOT(gotoHistoryPage()));
195 connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex)));
197 // Double-clicking on a transaction on the transaction history page shows details
198 connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
200 rpcConsole = new RPCConsole(this);
201 connect(openRPCConsoleAction, SIGNAL(triggered()), rpcConsole, SLOT(show()));
203 // Clicking on "Verify Message" in the address book sends you to the verify message tab
204 connect(addressBookPage, SIGNAL(verifyMessage(QString)), this, SLOT(gotoVerifyMessageTab(QString)));
205 // Clicking on "Sign Message" in the receive coins page sends you to the sign message tab
206 connect(receiveCoinsPage, SIGNAL(signMessage(QString)), this, SLOT(gotoSignMessageTab(QString)));
211 BitcoinGUI::~BitcoinGUI()
213 if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu)
220 void BitcoinGUI::createActions()
222 QActionGroup *tabGroup = new QActionGroup(this);
224 overviewAction = new QAction(QIcon(":/icons/overview"), tr("&Overview"), this);
225 overviewAction->setToolTip(tr("Show general overview of wallet"));
226 overviewAction->setCheckable(true);
227 overviewAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_1));
228 tabGroup->addAction(overviewAction);
230 sendCoinsAction = new QAction(QIcon(":/icons/send"), tr("&Send coins"), this);
231 sendCoinsAction->setToolTip(tr("Send coins to a NovaCoin address"));
232 sendCoinsAction->setCheckable(true);
233 sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2));
234 tabGroup->addAction(sendCoinsAction);
236 receiveCoinsAction = new QAction(QIcon(":/icons/receiving_addresses"), tr("&Receive coins"), this);
237 receiveCoinsAction->setToolTip(tr("Show the list of addresses for receiving payments"));
238 receiveCoinsAction->setCheckable(true);
239 receiveCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_3));
240 tabGroup->addAction(receiveCoinsAction);
242 historyAction = new QAction(QIcon(":/icons/history"), tr("&Transactions"), this);
243 historyAction->setToolTip(tr("Browse transaction history"));
244 historyAction->setCheckable(true);
245 historyAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_4));
246 tabGroup->addAction(historyAction);
248 mintingAction = new QAction(QIcon(":/icons/history"), tr("&Minting"), this);
249 mintingAction->setToolTip(tr("Show your minting capacity"));
250 mintingAction->setCheckable(true);
251 mintingAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_5));
252 tabGroup->addAction(mintingAction);
254 addressBookAction = new QAction(QIcon(":/icons/address-book"), tr("&Address Book"), this);
255 addressBookAction->setToolTip(tr("Edit the list of stored addresses and labels"));
256 addressBookAction->setCheckable(true);
257 addressBookAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_6));
258 tabGroup->addAction(addressBookAction);
260 multisigAction = new QAction(QIcon(":/icons/send"), tr("Multisig"), this);
261 tabGroup->addAction(multisigAction);
263 connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
264 connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage()));
265 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
266 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
267 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
268 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
269 connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
270 connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage()));
271 connect(mintingAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
272 connect(mintingAction, SIGNAL(triggered()), this, SLOT(gotoMintingPage()));
273 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
274 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(gotoAddressBookPage()));
275 connect(multisigAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
276 connect(multisigAction, SIGNAL(triggered()), this, SLOT(gotoMultisigPage()));
278 quitAction = new QAction(QIcon(":/icons/quit"), tr("E&xit"), this);
279 quitAction->setToolTip(tr("Quit application"));
280 quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
281 quitAction->setMenuRole(QAction::QuitRole);
282 aboutAction = new QAction(QIcon(":/icons/bitcoin"), tr("&About NovaCoin"), this);
283 aboutAction->setToolTip(tr("Show information about NovaCoin"));
284 aboutAction->setMenuRole(QAction::AboutRole);
285 #if QT_VERSION < 0x050000
286 aboutQtAction = new QAction(QIcon(":/trolltech/qmessagebox/images/qtlogo-64.png"), tr("About &Qt"), this);
288 aboutQtAction = new QAction(QIcon(":/qt-project.org/qmessagebox/images/qtlogo-64.png"), tr("About &Qt"), this);
290 aboutQtAction->setToolTip(tr("Show information about Qt"));
291 aboutQtAction->setMenuRole(QAction::AboutQtRole);
292 optionsAction = new QAction(QIcon(":/icons/options"), tr("&Options..."), this);
293 optionsAction->setToolTip(tr("Modify configuration options for NovaCoin"));
294 optionsAction->setMenuRole(QAction::PreferencesRole);
295 toggleHideAction = new QAction(QIcon(":/icons/bitcoin"), tr("&Show / Hide"), this);
296 encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet..."), this);
297 encryptWalletAction->setToolTip(tr("Encrypt or decrypt wallet"));
298 encryptWalletAction->setCheckable(true);
299 backupWalletAction = new QAction(QIcon(":/icons/filesave"), tr("&Backup Wallet..."), this);
300 backupWalletAction->setToolTip(tr("Backup wallet to another location"));
301 dumpWalletAction = new QAction(QIcon(":/icons/dump"), tr("&Dump Wallet..."), this);
302 dumpWalletAction->setStatusTip(tr("Dump keys to a text file"));
303 importWalletAction = new QAction(QIcon(":/icons/import"), tr("&Import Wallet..."), this);
304 importWalletAction->setStatusTip(tr("Import keys into a wallet"));
305 changePassphraseAction = new QAction(QIcon(":/icons/key"), tr("&Change Passphrase..."), this);
306 changePassphraseAction->setToolTip(tr("Change the passphrase used for wallet encryption"));
307 signMessageAction = new QAction(QIcon(":/icons/edit"), tr("Sign &message..."), this);
308 verifyMessageAction = new QAction(QIcon(":/icons/transaction_0"), tr("&Verify message..."), this);
310 lockWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Lock wallet"), this);
311 lockWalletAction->setToolTip(tr("Lock wallet"));
312 lockWalletAction->setCheckable(true);
314 unlockWalletAction = new QAction(QIcon(":/icons/lock_open"), tr("Unlo&ck wallet"), this);
315 unlockWalletAction->setToolTip(tr("Unlock wallet"));
316 unlockWalletAction->setCheckable(true);
318 unlockWalletMiningAction = new QAction(QIcon(":/icons/mining_active"), tr("Unlo&ck wallet for mining"), this);
319 unlockWalletMiningAction->setToolTip(tr("Unlock wallet for mining"));
320 unlockWalletMiningAction->setCheckable(true);
322 exportAction = new QAction(QIcon(":/icons/export"), tr("&Export..."), this);
323 exportAction->setToolTip(tr("Export the data in the current tab to a file"));
324 openRPCConsoleAction = new QAction(QIcon(":/icons/debugwindow"), tr("&Debug window"), this);
325 openRPCConsoleAction->setToolTip(tr("Open debugging and diagnostic console"));
327 connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
328 connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked()));
329 connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
330 connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked()));
331 connect(toggleHideAction, SIGNAL(triggered()), this, SLOT(toggleHidden()));
332 connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool)));
333 connect(lockWalletAction, SIGNAL(triggered(bool)), this, SLOT(lockWallet()));
334 connect(unlockWalletAction, SIGNAL(triggered(bool)), this, SLOT(unlockWallet()));
335 connect(unlockWalletMiningAction, SIGNAL(triggered(bool)), this, SLOT(unlockWalletMining(bool)));
336 connect(backupWalletAction, SIGNAL(triggered()), this, SLOT(backupWallet()));
337 connect(dumpWalletAction, SIGNAL(triggered()), this, SLOT(dumpWallet()));
338 connect(importWalletAction, SIGNAL(triggered()), this, SLOT(importWallet()));
339 connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase()));
340 connect(signMessageAction, SIGNAL(triggered()), this, SLOT(gotoSignMessageTab()));
341 connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(gotoVerifyMessageTab()));
344 void BitcoinGUI::createMenuBar()
347 // Create a decoupled menu bar on Mac which stays even if the window is closed
348 appMenuBar = new QMenuBar();
350 // Get the main window's menu bar on other platforms
351 appMenuBar = menuBar();
354 // Configure the menus
355 QMenu *file = appMenuBar->addMenu(tr("&File"));
356 file->addAction(backupWalletAction);
357 file->addSeparator();
358 file->addAction(dumpWalletAction);
359 file->addAction(importWalletAction);
360 file->addAction(exportAction);
361 file->addAction(signMessageAction);
362 file->addAction(verifyMessageAction);
363 file->addAction(multisigAction);
364 file->addSeparator();
365 file->addAction(quitAction);
367 QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
368 QMenu *securityMenu = settings->addMenu(QIcon(":/icons/key"), tr("&Wallet security"));
369 securityMenu->addAction(encryptWalletAction);
370 securityMenu->addAction(changePassphraseAction);
371 securityMenu->addAction(unlockWalletAction);
372 securityMenu->addAction(unlockWalletMiningAction);
373 securityMenu->addAction(lockWalletAction);
374 settings->addAction(optionsAction);
376 QMenu *help = appMenuBar->addMenu(tr("&Help"));
377 help->addAction(openRPCConsoleAction);
378 help->addSeparator();
379 help->addAction(aboutAction);
380 help->addAction(aboutQtAction);
383 void BitcoinGUI::createToolBars()
385 QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));
386 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
387 toolbar->addAction(overviewAction);
388 toolbar->addAction(sendCoinsAction);
389 toolbar->addAction(receiveCoinsAction);
390 toolbar->addAction(historyAction);
391 toolbar->addAction(mintingAction);
392 toolbar->addAction(addressBookAction);
394 QToolBar *toolbar2 = addToolBar(tr("Actions toolbar"));
395 toolbar2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
396 toolbar2->addAction(exportAction);
397 toolbar2->setVisible(false);
401 void BitcoinGUI::setClientModel(ClientModel *clientModel)
403 this->clientModel = clientModel;
406 // Replace some strings and icons, when using the testnet
407 if(clientModel->isTestNet())
409 setWindowTitle(windowTitle() + QString(" ") + tr("[testnet]"));
411 qApp->setWindowIcon(QIcon(":icons/bitcoin_testnet"));
412 setWindowIcon(QIcon(":icons/bitcoin_testnet"));
414 MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
418 trayIcon->setToolTip(tr("NovaCoin client") + QString(" ") + tr("[testnet]"));
419 trayIcon->setIcon(QIcon(":/icons/toolbar_testnet"));
420 toggleHideAction->setIcon(QIcon(":/icons/toolbar_testnet"));
423 aboutAction->setIcon(QIcon(":/icons/toolbar_testnet"));
426 // Keep up to date with client
427 setNumConnections(clientModel->getNumConnections());
428 connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
430 setNumBlocks(clientModel->getNumBlocks(), clientModel->getNumBlocksOfPeers());
431 connect(clientModel, SIGNAL(numBlocksChanged(int,int)), this, SLOT(setNumBlocks(int,int)));
433 QTimer *timer = new QTimer(this);
434 connect(timer, SIGNAL(timeout()), this, SLOT(updateMining()));
435 timer->start(10*1000); //10 seconds
437 // Report errors from network/worker thread
438 connect(clientModel, SIGNAL(error(QString,QString,bool)), this, SLOT(error(QString,QString,bool)));
440 rpcConsole->setClientModel(clientModel);
441 addressBookPage->setOptionsModel(clientModel->getOptionsModel());
442 receiveCoinsPage->setOptionsModel(clientModel->getOptionsModel());
446 void BitcoinGUI::setWalletModel(WalletModel *walletModel)
448 this->walletModel = walletModel;
451 // Report errors from wallet thread
452 connect(walletModel, SIGNAL(error(QString,QString,bool)), this, SLOT(error(QString,QString,bool)));
454 // Put transaction list in tabs
455 transactionView->setModel(walletModel);
456 mintingView->setModel(walletModel);
458 overviewPage->setModel(walletModel);
459 addressBookPage->setModel(walletModel->getAddressTableModel());
460 receiveCoinsPage->setModel(walletModel->getAddressTableModel());
461 sendCoinsPage->setModel(walletModel);
462 signVerifyMessageDialog->setModel(walletModel);
463 multisigPage->setModel(walletModel);
465 setEncryptionStatus(walletModel->getEncryptionStatus());
466 connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));
467 connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(updateMining()));
469 // Balloon pop-up for new transaction
470 connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
471 this, SLOT(incomingTransaction(QModelIndex,int,int)));
473 // Ask for passphrase if needed
474 connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
478 void BitcoinGUI::createTrayIcon()
482 trayIcon = new QSystemTrayIcon(this);
483 trayIconMenu = new QMenu(this);
484 trayIcon->setContextMenu(trayIconMenu);
485 trayIcon->setToolTip(tr("NovaCoin client"));
486 trayIcon->setIcon(QIcon(":/icons/toolbar"));
487 connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
488 this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
491 // Note: On Mac, the dock icon is used to provide the tray's functionality.
492 MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance();
493 dockIconHandler->setMainWindow((QMainWindow *)this);
494 trayIconMenu = dockIconHandler->dockMenu();
497 // Configuration of the tray icon (or dock icon) icon menu
498 trayIconMenu->addAction(toggleHideAction);
499 trayIconMenu->addSeparator();
500 trayIconMenu->addAction(sendCoinsAction);
501 trayIconMenu->addAction(multisigAction);
502 trayIconMenu->addAction(receiveCoinsAction);
503 trayIconMenu->addSeparator();
504 trayIconMenu->addAction(signMessageAction);
505 trayIconMenu->addAction(verifyMessageAction);
506 trayIconMenu->addSeparator();
507 trayIconMenu->addAction(optionsAction);
508 trayIconMenu->addAction(openRPCConsoleAction);
510 // This is built-in on Mac
511 trayIconMenu->addSeparator();
512 trayIconMenu->addAction(quitAction);
514 notificator = new Notificator(qApp->applicationName(), trayIcon, 0);
519 void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
521 if(reason == QSystemTrayIcon::Trigger)
523 // Click on system tray icon triggers show/hide of the main window
524 toggleHideAction->trigger();
529 void BitcoinGUI::optionsClicked()
531 if(!clientModel || !clientModel->getOptionsModel())
534 dlg.setModel(clientModel->getOptionsModel());
538 void BitcoinGUI::aboutClicked()
541 dlg.setModel(clientModel);
545 void BitcoinGUI::setNumConnections(int count)
550 case 0: icon = ":/icons/connect_0"; break;
551 case 1: case 2: case 3: icon = ":/icons/connect_1"; break;
552 case 4: case 5: case 6: icon = ":/icons/connect_2"; break;
553 case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
554 default: icon = ":/icons/connect_4"; break;
556 labelConnectionsIcon->setPixmap(QIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
557 labelConnectionsIcon->setToolTip(tr("%n active connection(s) to NovaCoin network", "", count));
560 void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks)
562 // don't show / hide progress bar and its label if we have no connection to the network
563 if (!clientModel || clientModel->getNumConnections() == 0)
565 progressBarLabel->setVisible(false);
566 progressBar->setVisible(false);
571 QString strStatusBarWarnings = clientModel->getStatusBarWarnings();
574 if(count < nTotalBlocks)
576 int nRemainingBlocks = nTotalBlocks - count;
577 float nPercentageDone = count / (nTotalBlocks * 0.01f);
579 if (strStatusBarWarnings.isEmpty())
581 progressBarLabel->setText(tr("Synchronizing with network..."));
582 progressBarLabel->setVisible(true);
583 progressBar->setFormat(tr("~%n block(s) remaining", "", nRemainingBlocks));
584 progressBar->setMaximum(nTotalBlocks);
585 progressBar->setValue(count);
586 progressBar->setVisible(true);
589 tooltip = tr("Downloaded %1 of %2 blocks of transaction history (%3% done).").arg(count).arg(nTotalBlocks).arg(nPercentageDone, 0, 'f', 2);
593 if (strStatusBarWarnings.isEmpty())
594 progressBarLabel->setVisible(false);
596 progressBar->setVisible(false);
597 tooltip = tr("Downloaded %1 blocks of transaction history.").arg(count);
600 // Override progressBarLabel text and hide progress bar, when we have warnings to display
601 if (!strStatusBarWarnings.isEmpty())
603 progressBarLabel->setText(strStatusBarWarnings);
604 progressBarLabel->setVisible(true);
605 progressBar->setVisible(false);
608 QDateTime lastBlockDate = clientModel->getLastBlockDate();
609 int secs = lastBlockDate.secsTo(QDateTime::currentDateTime());
612 // Represent time from last generated block in human readable text
615 // Fully up to date. Leave text empty.
619 text = tr("%n second(s) ago","",secs);
621 else if(secs < 60*60)
623 text = tr("%n minute(s) ago","",secs/60);
625 else if(secs < 24*60*60)
627 text = tr("%n hour(s) ago","",secs/(60*60));
631 text = tr("%n day(s) ago","",secs/(60*60*24));
634 // Set icon state: spinning if catching up, tick otherwise
635 if(secs < 90*60 && count >= nTotalBlocks)
637 tooltip = tr("Up to date") + QString(".<br>") + tooltip;
638 labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
640 overviewPage->showOutOfSyncWarning(false);
644 tooltip = tr("Catching up...") + QString("<br>") + tooltip;
645 labelBlocksIcon->setMovie(syncIconMovie);
646 syncIconMovie->start();
648 overviewPage->showOutOfSyncWarning(true);
653 tooltip += QString("<br>");
654 tooltip += tr("Last received block was generated %1.").arg(text);
657 // Don't word-wrap this (fixed-width) tooltip
658 tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
660 labelBlocksIcon->setToolTip(tooltip);
661 progressBarLabel->setToolTip(tooltip);
662 progressBar->setToolTip(tooltip);
665 void BitcoinGUI::updateMining()
670 labelMiningIcon->setPixmap(QIcon(":/icons/mining_inactive").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
672 if (!clientModel->getNumConnections())
674 labelMiningIcon->setToolTip(tr("Wallet is offline"));
678 if (walletModel->getEncryptionStatus() == WalletModel::Locked)
680 labelMiningIcon->setToolTip(tr("Wallet is locked"));
684 if (clientModel->inInitialBlockDownload() || clientModel->getNumBlocksOfPeers() > clientModel->getNumBlocks())
686 labelMiningIcon->setToolTip(tr("Blockchain download is in progress"));
690 float nKernelsRate = 0, nCoinDaysRate = 0;
691 walletModel->getStakeStats(nKernelsRate, nCoinDaysRate);
693 if (nKernelsRate > 0)
695 labelMiningIcon->setPixmap(QIcon(":/icons/mining_active").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
697 uint64 nNetworkWeight = clientModel->getPoSKernelPS();
699 double dDifficulty = clientModel->getDifficulty(true);
702 int nApproxTime = 4294967297 * dDifficulty / nTotalWeight;
704 if (nApproxTime < 60)
705 msg = tr("%n second(s)", "", nApproxTime);
706 else if (nApproxTime < 60*60)
707 msg = tr("%n minute(s)", "", nApproxTime / 60);
708 else if (nApproxTime < 24*60*60)
709 msg = tr("%n hour(s)", "", nApproxTime / 3600);
711 msg = tr("%n day(s)", "", nApproxTime / 86400);
713 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));
716 labelMiningIcon->setToolTip(tr("Stake miner is active\nKernel rate is %1 k/s\nCD rate is %2 CD/s\nNetwork weight is %3").arg(nKernelsRate).arg(nCoinDaysRate).arg(nNetworkWeight));
719 labelMiningIcon->setToolTip(tr("No suitable inputs were found"));
722 void BitcoinGUI::error(const QString &title, const QString &message, bool modal)
724 // Report errors from network/worker thread
727 QMessageBox::critical(this, title, message, QMessageBox::Ok, QMessageBox::Ok);
729 notificator->notify(Notificator::Critical, title, message);
733 void BitcoinGUI::message(const QString &title, const QString &message, unsigned int style, const QString &detail)
735 QString strTitle = tr("NovaCoin") + " - ";
736 // Default to information icon
737 int nMBoxIcon = QMessageBox::Information;
738 int nNotifyIcon = Notificator::Information;
741 // Check for usage of predefined title
743 case CClientUIInterface::MSG_ERROR:
744 strTitle += tr("Error");
746 case CClientUIInterface::MSG_WARNING:
747 strTitle += tr("Warning");
749 case CClientUIInterface::MSG_INFORMATION:
750 strTitle += tr("Information");
753 strTitle += title; // Use supplied title
756 // Check for error/warning icon
757 if (style & CClientUIInterface::ICON_ERROR) {
758 nMBoxIcon = QMessageBox::Critical;
759 nNotifyIcon = Notificator::Critical;
761 else if (style & CClientUIInterface::ICON_WARNING) {
762 nMBoxIcon = QMessageBox::Warning;
763 nNotifyIcon = Notificator::Warning;
767 if (style & CClientUIInterface::MODAL) {
768 // Check for buttons, use OK as default, if none was supplied
769 QMessageBox::StandardButton buttons;
770 buttons = QMessageBox::Ok;
772 QMessageBox mBox((QMessageBox::Icon)nMBoxIcon, strTitle, message, buttons);
774 if(!detail.isEmpty()) { mBox.setDetailedText(detail); }
779 notificator->notify((Notificator::Class)nNotifyIcon, strTitle, message);
783 void BitcoinGUI::changeEvent(QEvent *e)
785 QMainWindow::changeEvent(e);
786 #ifndef Q_OS_MAC // Ignored on Mac
787 if(e->type() == QEvent::WindowStateChange)
789 if(clientModel && clientModel->getOptionsModel()->getMinimizeToTray())
791 QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
792 if(!(wsevt->oldState() & Qt::WindowMinimized) && isMinimized())
794 QTimer::singleShot(0, this, SLOT(hide()));
802 void BitcoinGUI::closeEvent(QCloseEvent *event)
806 #ifndef Q_OS_MAC // Ignored on Mac
807 if(!clientModel->getOptionsModel()->getMinimizeOnClose())
813 QMainWindow::closeEvent(event);
816 void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
819 tr("This transaction is over the size limit. You can still send it for a fee of %1, "
820 "which goes to the nodes that process your transaction and helps to support the network. "
821 "Do you want to pay the fee?").arg(
822 BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nFeeRequired));
823 QMessageBox::StandardButton retval = QMessageBox::question(
824 this, tr("Confirm transaction fee"), strMessage,
825 QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes);
826 *payFee = (retval == QMessageBox::Yes);
829 void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
831 if(!walletModel || !clientModel)
833 TransactionTableModel *ttm = walletModel->getTransactionTableModel();
834 qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
835 .data(Qt::EditRole).toULongLong();
836 if(!clientModel->inInitialBlockDownload())
838 // On new transaction, make an info balloon
839 // Unless the initial block download is in progress, to prevent balloon-spam
840 QString date = ttm->index(start, TransactionTableModel::Date, parent)
842 QString type = ttm->index(start, TransactionTableModel::Type, parent)
844 QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
846 QIcon icon = qvariant_cast<QIcon>(ttm->index(start,
847 TransactionTableModel::ToAddress, parent)
848 .data(Qt::DecorationRole));
850 notificator->notify(Notificator::Information,
851 (amount)<0 ? tr("Sent transaction") :
852 tr("Incoming transaction"),
858 .arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true))
860 .arg(address), icon);
864 void BitcoinGUI::gotoOverviewPage()
866 overviewAction->setChecked(true);
867 centralWidget->setCurrentWidget(overviewPage);
869 exportAction->setEnabled(false);
870 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
873 void BitcoinGUI::gotoHistoryPage()
875 historyAction->setChecked(true);
876 centralWidget->setCurrentWidget(transactionsPage);
878 exportAction->setEnabled(true);
879 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
880 connect(exportAction, SIGNAL(triggered()), transactionView, SLOT(exportClicked()));
883 void BitcoinGUI::gotoMintingPage()
885 mintingAction->setChecked(true);
886 centralWidget->setCurrentWidget(mintingPage);
888 exportAction->setEnabled(true);
889 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
890 connect(exportAction, SIGNAL(triggered()), mintingView, SLOT(exportClicked()));
894 void BitcoinGUI::gotoAddressBookPage()
896 addressBookAction->setChecked(true);
897 centralWidget->setCurrentWidget(addressBookPage);
899 exportAction->setEnabled(true);
900 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
901 connect(exportAction, SIGNAL(triggered()), addressBookPage, SLOT(exportClicked()));
904 void BitcoinGUI::gotoReceiveCoinsPage()
906 receiveCoinsAction->setChecked(true);
907 centralWidget->setCurrentWidget(receiveCoinsPage);
909 exportAction->setEnabled(true);
910 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
911 connect(exportAction, SIGNAL(triggered()), receiveCoinsPage, SLOT(exportClicked()));
914 void BitcoinGUI::gotoSendCoinsPage()
916 sendCoinsAction->setChecked(true);
917 centralWidget->setCurrentWidget(sendCoinsPage);
919 exportAction->setEnabled(false);
920 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
923 void BitcoinGUI::gotoSignMessageTab(QString addr)
925 // call show() in showTab_SM()
926 signVerifyMessageDialog->showTab_SM(true);
929 signVerifyMessageDialog->setAddress_SM(addr);
932 void BitcoinGUI::gotoVerifyMessageTab(QString addr)
934 // call show() in showTab_VM()
935 signVerifyMessageDialog->showTab_VM(true);
938 signVerifyMessageDialog->setAddress_VM(addr);
941 void BitcoinGUI::gotoMultisigPage()
943 multisigPage->show();
944 multisigPage->setFocus();
947 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
950 if(event->mimeData()->hasUrls())
951 event->acceptProposedAction();
954 void BitcoinGUI::dropEvent(QDropEvent *event)
956 if(event->mimeData()->hasUrls())
958 int nValidUrisFound = 0;
959 QList<QUrl> uris = event->mimeData()->urls();
960 foreach(const QUrl &uri, uris)
962 if (sendCoinsPage->handleURI(uri.toString()))
966 // if valid URIs were found
970 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."));
973 event->acceptProposedAction();
976 void BitcoinGUI::handleURI(QString strURI)
978 // URI has to be valid
979 if (sendCoinsPage->handleURI(strURI))
981 showNormalIfMinimized();
985 notificator->notify(Notificator::Warning, tr("URI handling"), tr("URI can not be parsed! This can be caused by an invalid NovaCoin address or malformed URI parameters."));
988 void BitcoinGUI::setEncryptionStatus(int status)
992 case WalletModel::Unencrypted:
993 labelEncryptionIcon->hide();
994 encryptWalletAction->setChecked(false);
995 changePassphraseAction->setEnabled(false);
996 lockWalletAction->setEnabled(false);
997 unlockWalletAction->setEnabled(false);
998 unlockWalletMiningAction->setEnabled(false);
999 encryptWalletAction->setEnabled(true);
1001 case WalletModel::Unlocked:
1002 labelEncryptionIcon->show();
1003 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
1004 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
1005 encryptWalletAction->setChecked(true);
1006 changePassphraseAction->setEnabled(true);
1007 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
1009 lockWalletAction->setEnabled(true);
1010 lockWalletAction->setChecked(false);
1011 unlockWalletAction->setEnabled(false);
1012 unlockWalletMiningAction->setEnabled(false);
1014 if (fWalletUnlockMintOnly)
1015 unlockWalletMiningAction->setChecked(true);
1017 unlockWalletAction->setChecked(true);
1020 case WalletModel::Locked:
1021 labelEncryptionIcon->show();
1022 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
1023 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
1024 encryptWalletAction->setChecked(true);
1025 changePassphraseAction->setEnabled(true);
1026 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
1028 lockWalletAction->setChecked(true);
1029 unlockWalletAction->setChecked(false);
1030 unlockWalletMiningAction->setChecked(false);
1032 lockWalletAction->setEnabled(false);
1033 unlockWalletAction->setEnabled(true);
1034 unlockWalletMiningAction->setEnabled(true);
1039 void BitcoinGUI::encryptWallet(bool status)
1043 AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt:
1044 AskPassphraseDialog::Decrypt, this);
1045 dlg.setModel(walletModel);
1048 setEncryptionStatus(walletModel->getEncryptionStatus());
1051 void BitcoinGUI::unlockWalletMining(bool status)
1056 // Unlock wallet when requested by wallet model
1057 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1059 AskPassphraseDialog dlg(AskPassphraseDialog::UnlockMining, this);
1060 dlg.setModel(walletModel);
1065 void BitcoinGUI::backupWallet()
1067 #if QT_VERSION < 0x050000
1068 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1070 QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1072 QString filename = QFileDialog::getSaveFileName(this, tr("Backup Wallet"), saveDir, tr("Wallet Data (*.dat)"));
1073 if(!filename.isEmpty()) {
1074 if(!walletModel->backupWallet(filename)) {
1075 QMessageBox::warning(this, tr("Backup Failed"), tr("There was an error trying to save the wallet data to the new location."));
1080 void BitcoinGUI::dumpWallet()
1085 WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1088 // Unlock wallet failed or was cancelled
1092 #if QT_VERSION < 0x050000
1093 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1095 QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1097 QString filename = QFileDialog::getSaveFileName(this, tr("Dump Wallet"), saveDir, tr("Wallet dump (*.txt)"));
1098 if(!filename.isEmpty()) {
1099 if(!walletModel->dumpWallet(filename)) {
1100 error(tr("Dump failed"),
1101 tr("An error happened while trying to save the keys to your location.\n"
1102 "Keys were not saved.")
1103 ,CClientUIInterface::MSG_ERROR);
1106 message(tr("Dump successful"),
1107 tr("Keys were saved to this file:\n%2")
1109 ,CClientUIInterface::MSG_INFORMATION);
1113 void BitcoinGUI::importWallet()
1118 WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1121 // Unlock wallet failed or was cancelled
1125 #if QT_VERSION < 0x050000
1126 QString openDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1128 QString openDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1130 QString filename = QFileDialog::getOpenFileName(this, tr("Import Wallet"), openDir, tr("Wallet dump (*.txt)"));
1131 if(!filename.isEmpty()) {
1132 if(!walletModel->importWallet(filename)) {
1133 error(tr("Import Failed"),
1134 tr("An error happened while trying to import the keys.\n"
1135 "Some or all keys from:\n %1,\n were not imported into your wallet.")
1137 ,CClientUIInterface::MSG_ERROR);
1140 message(tr("Import Successful"),
1141 tr("All keys from:\n %1,\n were imported into your wallet.")
1143 ,CClientUIInterface::MSG_INFORMATION);
1148 void BitcoinGUI::changePassphrase()
1150 AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
1151 dlg.setModel(walletModel);
1155 void BitcoinGUI::unlockWallet()
1159 // Unlock wallet when requested by wallet model
1160 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1162 AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
1163 dlg.setModel(walletModel);
1168 void BitcoinGUI::lockWallet()
1173 walletModel->setWalletLocked(true);
1176 void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden)
1178 // activateWindow() (sometimes) helps with keyboard focus on Windows
1184 else if (isMinimized())
1189 else if (GUIUtil::isObscured(this))
1194 else if(fToggleHidden)
1198 void BitcoinGUI::toggleHidden()
1200 showNormalIfMinimized(true);