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(QApplication::applicationName(), trayIcon, this);
518 void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
520 if(reason == QSystemTrayIcon::Trigger)
522 // Click on system tray icon triggers show/hide of the main window
523 toggleHideAction->trigger();
528 void BitcoinGUI::optionsClicked()
530 if(!clientModel || !clientModel->getOptionsModel())
533 dlg.setModel(clientModel->getOptionsModel());
537 void BitcoinGUI::aboutClicked()
540 dlg.setModel(clientModel);
544 void BitcoinGUI::setNumConnections(int count)
549 case 0: icon = ":/icons/connect_0"; break;
550 case 1: case 2: case 3: icon = ":/icons/connect_1"; break;
551 case 4: case 5: case 6: icon = ":/icons/connect_2"; break;
552 case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
553 default: icon = ":/icons/connect_4"; break;
555 labelConnectionsIcon->setPixmap(QIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
556 labelConnectionsIcon->setToolTip(tr("%n active connection(s) to NovaCoin network", "", count));
559 void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks)
561 // don't show / hide progress bar and its label if we have no connection to the network
562 if (!clientModel || clientModel->getNumConnections() == 0)
564 progressBarLabel->setVisible(false);
565 progressBar->setVisible(false);
570 QString strStatusBarWarnings = clientModel->getStatusBarWarnings();
573 if(count < nTotalBlocks)
575 int nRemainingBlocks = nTotalBlocks - count;
576 float nPercentageDone = count / (nTotalBlocks * 0.01f);
578 if (strStatusBarWarnings.isEmpty())
580 progressBarLabel->setText(tr("Synchronizing with network..."));
581 progressBarLabel->setVisible(true);
582 progressBar->setFormat(tr("~%n block(s) remaining", "", nRemainingBlocks));
583 progressBar->setMaximum(nTotalBlocks);
584 progressBar->setValue(count);
585 progressBar->setVisible(true);
588 tooltip = tr("Downloaded %1 of %2 blocks of transaction history (%3% done).").arg(count).arg(nTotalBlocks).arg(nPercentageDone, 0, 'f', 2);
592 if (strStatusBarWarnings.isEmpty())
593 progressBarLabel->setVisible(false);
595 progressBar->setVisible(false);
596 tooltip = tr("Downloaded %1 blocks of transaction history.").arg(count);
599 // Override progressBarLabel text and hide progress bar, when we have warnings to display
600 if (!strStatusBarWarnings.isEmpty())
602 progressBarLabel->setText(strStatusBarWarnings);
603 progressBarLabel->setVisible(true);
604 progressBar->setVisible(false);
607 QDateTime lastBlockDate = clientModel->getLastBlockDate();
608 int secs = lastBlockDate.secsTo(QDateTime::currentDateTime());
611 // Represent time from last generated block in human readable text
614 // Fully up to date. Leave text empty.
618 text = tr("%n second(s) ago","",secs);
620 else if(secs < 60*60)
622 text = tr("%n minute(s) ago","",secs/60);
624 else if(secs < 24*60*60)
626 text = tr("%n hour(s) ago","",secs/(60*60));
630 text = tr("%n day(s) ago","",secs/(60*60*24));
633 // Set icon state: spinning if catching up, tick otherwise
634 if(secs < 90*60 && count >= nTotalBlocks)
636 tooltip = tr("Up to date") + QString(".<br>") + tooltip;
637 labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
639 overviewPage->showOutOfSyncWarning(false);
643 tooltip = tr("Catching up...") + QString("<br>") + tooltip;
644 labelBlocksIcon->setMovie(syncIconMovie);
645 syncIconMovie->start();
647 overviewPage->showOutOfSyncWarning(true);
652 tooltip += QString("<br>");
653 tooltip += tr("Last received block was generated %1.").arg(text);
656 // Don't word-wrap this (fixed-width) tooltip
657 tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
659 labelBlocksIcon->setToolTip(tooltip);
660 progressBarLabel->setToolTip(tooltip);
661 progressBar->setToolTip(tooltip);
664 void BitcoinGUI::updateMining()
669 labelMiningIcon->setPixmap(QIcon(":/icons/mining_inactive").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
671 if (!clientModel->getNumConnections())
673 labelMiningIcon->setToolTip(tr("Wallet is offline"));
677 if (walletModel->getEncryptionStatus() == WalletModel::Locked)
679 labelMiningIcon->setToolTip(tr("Wallet is locked"));
683 if (clientModel->inInitialBlockDownload() || clientModel->getNumBlocksOfPeers() > clientModel->getNumBlocks())
685 labelMiningIcon->setToolTip(tr("Blockchain download is in progress"));
689 float nKernelsRate = 0, nCoinDaysRate = 0;
690 walletModel->getStakeStats(nKernelsRate, nCoinDaysRate);
692 if (nKernelsRate > 0)
694 labelMiningIcon->setPixmap(QIcon(":/icons/mining_active").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
696 uint64_t nNetworkWeight = clientModel->getPoSKernelPS();
698 double dDifficulty = clientModel->getDifficulty(true);
701 int nApproxTime = 4294967297 * dDifficulty / nTotalWeight;
703 if (nApproxTime < 60)
704 msg = tr("%n second(s)", "", nApproxTime);
705 else if (nApproxTime < 60*60)
706 msg = tr("%n minute(s)", "", nApproxTime / 60);
707 else if (nApproxTime < 24*60*60)
708 msg = tr("%n hour(s)", "", nApproxTime / 3600);
710 msg = tr("%n day(s)", "", nApproxTime / 86400);
712 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));
715 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>"));
718 labelMiningIcon->setToolTip(tr("No suitable inputs were found"));
721 void BitcoinGUI::error(const QString &title, const QString &message, bool modal)
723 // Report errors from network/worker thread
726 QMessageBox::critical(this, title, message, QMessageBox::Ok, QMessageBox::Ok);
728 notificator->notify(Notificator::Critical, title, message);
732 void BitcoinGUI::message(const QString &title, const QString &message, unsigned int style, const QString &detail)
734 QString strTitle = tr("NovaCoin") + " - ";
735 // Default to information icon
736 int nMBoxIcon = QMessageBox::Information;
737 int nNotifyIcon = Notificator::Information;
740 // Check for usage of predefined title
742 case CClientUIInterface::MSG_ERROR:
743 strTitle += tr("Error");
745 case CClientUIInterface::MSG_WARNING:
746 strTitle += tr("Warning");
748 case CClientUIInterface::MSG_INFORMATION:
749 strTitle += tr("Information");
752 strTitle += title; // Use supplied title
755 // Check for error/warning icon
756 if (style & CClientUIInterface::ICON_ERROR) {
757 nMBoxIcon = QMessageBox::Critical;
758 nNotifyIcon = Notificator::Critical;
760 else if (style & CClientUIInterface::ICON_WARNING) {
761 nMBoxIcon = QMessageBox::Warning;
762 nNotifyIcon = Notificator::Warning;
766 if (style & CClientUIInterface::MODAL) {
767 // Check for buttons, use OK as default, if none was supplied
768 QMessageBox::StandardButton buttons;
769 buttons = QMessageBox::Ok;
771 QMessageBox mBox((QMessageBox::Icon)nMBoxIcon, strTitle, message, buttons);
773 if(!detail.isEmpty()) { mBox.setDetailedText(detail); }
778 notificator->notify((Notificator::Class)nNotifyIcon, strTitle, message);
782 void BitcoinGUI::changeEvent(QEvent *e)
784 QMainWindow::changeEvent(e);
785 #ifndef Q_OS_MAC // Ignored on Mac
786 if(e->type() == QEvent::WindowStateChange)
788 if(clientModel && clientModel->getOptionsModel()->getMinimizeToTray())
790 QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
791 if(!(wsevt->oldState() & Qt::WindowMinimized) && isMinimized())
793 QTimer::singleShot(0, this, SLOT(hide()));
801 void BitcoinGUI::closeEvent(QCloseEvent *event)
805 #ifndef Q_OS_MAC // Ignored on Mac
806 if(!clientModel->getOptionsModel()->getMinimizeOnClose())
812 QMainWindow::closeEvent(event);
815 void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
818 tr("This transaction is over the size limit. You can still send it for a fee of %1, "
819 "which goes to the nodes that process your transaction and helps to support the network. "
820 "Do you want to pay the fee?").arg(
821 BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nFeeRequired));
822 QMessageBox::StandardButton retval = QMessageBox::question(
823 this, tr("Confirm transaction fee"), strMessage,
824 QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes);
825 *payFee = (retval == QMessageBox::Yes);
828 void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
830 if(!walletModel || !clientModel)
832 TransactionTableModel *ttm = walletModel->getTransactionTableModel();
833 qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
834 .data(Qt::EditRole).toULongLong();
835 if(!clientModel->inInitialBlockDownload())
837 // On new transaction, make an info balloon
838 // Unless the initial block download is in progress, to prevent balloon-spam
839 QString date = ttm->index(start, TransactionTableModel::Date, parent)
841 QString type = ttm->index(start, TransactionTableModel::Type, parent)
843 QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
845 QIcon icon = qvariant_cast<QIcon>(ttm->index(start,
846 TransactionTableModel::ToAddress, parent)
847 .data(Qt::DecorationRole));
849 notificator->notify(Notificator::Information,
850 (amount)<0 ? tr("Sent transaction") :
851 tr("Incoming transaction"),
857 .arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true))
859 .arg(address), icon);
863 void BitcoinGUI::gotoOverviewPage()
865 overviewAction->setChecked(true);
866 centralWidget->setCurrentWidget(overviewPage);
868 exportAction->setEnabled(false);
869 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
872 void BitcoinGUI::gotoHistoryPage()
874 historyAction->setChecked(true);
875 centralWidget->setCurrentWidget(transactionsPage);
877 exportAction->setEnabled(true);
878 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
879 connect(exportAction, SIGNAL(triggered()), transactionView, SLOT(exportClicked()));
882 void BitcoinGUI::gotoMintingPage()
884 mintingAction->setChecked(true);
885 centralWidget->setCurrentWidget(mintingPage);
887 exportAction->setEnabled(true);
888 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
889 connect(exportAction, SIGNAL(triggered()), mintingView, SLOT(exportClicked()));
893 void BitcoinGUI::gotoAddressBookPage()
895 addressBookAction->setChecked(true);
896 centralWidget->setCurrentWidget(addressBookPage);
898 exportAction->setEnabled(true);
899 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
900 connect(exportAction, SIGNAL(triggered()), addressBookPage, SLOT(exportClicked()));
903 void BitcoinGUI::gotoReceiveCoinsPage()
905 receiveCoinsAction->setChecked(true);
906 centralWidget->setCurrentWidget(receiveCoinsPage);
908 exportAction->setEnabled(true);
909 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
910 connect(exportAction, SIGNAL(triggered()), receiveCoinsPage, SLOT(exportClicked()));
913 void BitcoinGUI::gotoSendCoinsPage()
915 sendCoinsAction->setChecked(true);
916 centralWidget->setCurrentWidget(sendCoinsPage);
918 exportAction->setEnabled(false);
919 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
922 void BitcoinGUI::gotoSignMessageTab(QString addr)
924 // call show() in showTab_SM()
925 signVerifyMessageDialog->showTab_SM(true);
928 signVerifyMessageDialog->setAddress_SM(addr);
931 void BitcoinGUI::gotoVerifyMessageTab(QString addr)
933 // call show() in showTab_VM()
934 signVerifyMessageDialog->showTab_VM(true);
937 signVerifyMessageDialog->setAddress_VM(addr);
940 void BitcoinGUI::gotoMultisigPage()
942 multisigPage->show();
943 multisigPage->setFocus();
946 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
949 if(event->mimeData()->hasUrls())
950 event->acceptProposedAction();
953 void BitcoinGUI::dropEvent(QDropEvent *event)
955 if(event->mimeData()->hasUrls())
957 int nValidUrisFound = 0;
958 QList<QUrl> uris = event->mimeData()->urls();
959 foreach(const QUrl &uri, uris)
961 if (sendCoinsPage->handleURI(uri.toString()))
965 // if valid URIs were found
969 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."));
972 event->acceptProposedAction();
975 void BitcoinGUI::handleURI(QString strURI)
977 // URI has to be valid
978 if (sendCoinsPage->handleURI(strURI))
980 showNormalIfMinimized();
984 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."));
987 void BitcoinGUI::setEncryptionStatus(int status)
991 case WalletModel::Unencrypted:
992 labelEncryptionIcon->hide();
993 encryptWalletAction->setChecked(false);
994 changePassphraseAction->setEnabled(false);
995 lockWalletAction->setEnabled(false);
996 unlockWalletAction->setEnabled(false);
997 unlockWalletMiningAction->setEnabled(false);
998 encryptWalletAction->setEnabled(true);
1000 case WalletModel::Unlocked:
1001 labelEncryptionIcon->show();
1002 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
1003 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
1004 encryptWalletAction->setChecked(true);
1005 changePassphraseAction->setEnabled(true);
1006 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
1008 lockWalletAction->setEnabled(true);
1009 lockWalletAction->setChecked(false);
1010 unlockWalletAction->setEnabled(false);
1011 unlockWalletMiningAction->setEnabled(false);
1013 if (fWalletUnlockMintOnly)
1014 unlockWalletMiningAction->setChecked(true);
1016 unlockWalletAction->setChecked(true);
1019 case WalletModel::Locked:
1020 labelEncryptionIcon->show();
1021 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
1022 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
1023 encryptWalletAction->setChecked(true);
1024 changePassphraseAction->setEnabled(true);
1025 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
1027 lockWalletAction->setChecked(true);
1028 unlockWalletAction->setChecked(false);
1029 unlockWalletMiningAction->setChecked(false);
1031 lockWalletAction->setEnabled(false);
1032 unlockWalletAction->setEnabled(true);
1033 unlockWalletMiningAction->setEnabled(true);
1038 void BitcoinGUI::encryptWallet(bool status)
1042 AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt:
1043 AskPassphraseDialog::Decrypt, this);
1044 dlg.setModel(walletModel);
1047 setEncryptionStatus(walletModel->getEncryptionStatus());
1050 void BitcoinGUI::unlockWalletMining(bool status)
1055 // Unlock wallet when requested by wallet model
1056 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1058 AskPassphraseDialog dlg(AskPassphraseDialog::UnlockMining, this);
1059 dlg.setModel(walletModel);
1064 void BitcoinGUI::backupWallet()
1066 #if QT_VERSION < 0x050000
1067 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1069 QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1071 QString filename = QFileDialog::getSaveFileName(this, tr("Backup Wallet"), saveDir, tr("Wallet Data (*.dat)"));
1072 if(!filename.isEmpty()) {
1073 if(!walletModel->backupWallet(filename)) {
1074 QMessageBox::warning(this, tr("Backup Failed"), tr("There was an error trying to save the wallet data to the new location."));
1079 void BitcoinGUI::dumpWallet()
1084 WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1087 // Unlock wallet failed or was cancelled
1091 #if QT_VERSION < 0x050000
1092 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1094 QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1096 QString filename = QFileDialog::getSaveFileName(this, tr("Dump Wallet"), saveDir, tr("Wallet dump (*.txt)"));
1097 if(!filename.isEmpty()) {
1098 if(!walletModel->dumpWallet(filename)) {
1099 error(tr("Dump failed"),
1100 tr("An error happened while trying to save the keys to your location.\n"
1101 "Keys were not saved.")
1102 ,CClientUIInterface::MSG_ERROR);
1105 message(tr("Dump successful"),
1106 tr("Keys were saved to this file:\n%2")
1108 ,CClientUIInterface::MSG_INFORMATION);
1112 void BitcoinGUI::importWallet()
1117 WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1120 // Unlock wallet failed or was cancelled
1124 #if QT_VERSION < 0x050000
1125 QString openDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1127 QString openDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1129 QString filename = QFileDialog::getOpenFileName(this, tr("Import Wallet"), openDir, tr("Wallet dump (*.txt)"));
1130 if(!filename.isEmpty()) {
1131 if(!walletModel->importWallet(filename)) {
1132 error(tr("Import Failed"),
1133 tr("An error happened while trying to import the keys.\n"
1134 "Some or all keys from:\n %1,\n were not imported into your wallet.")
1136 ,CClientUIInterface::MSG_ERROR);
1139 message(tr("Import Successful"),
1140 tr("All keys from:\n %1,\n were imported into your wallet.")
1142 ,CClientUIInterface::MSG_INFORMATION);
1147 void BitcoinGUI::changePassphrase()
1149 AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
1150 dlg.setModel(walletModel);
1154 void BitcoinGUI::unlockWallet()
1158 // Unlock wallet when requested by wallet model
1159 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1161 AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
1162 dlg.setModel(walletModel);
1167 void BitcoinGUI::lockWallet()
1172 walletModel->setWalletLocked(true);
1175 void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden)
1177 // activateWindow() (sometimes) helps with keyboard focus on Windows
1180 // Make sure the window is not minimized
1181 setWindowState(windowState() & (~Qt::WindowMinimized | Qt::WindowActive));
1187 else if (isMinimized())
1193 else if (GUIUtil::isObscured(this))
1200 if (GUIUtil::isObscured(this))
1204 else if(fToggleHidden)
1208 void BitcoinGUI::toggleHidden()
1210 showNormalIfMinimized(true);