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;
73 extern uint64_t nStakeInputsMapSize;
75 BitcoinGUI::BitcoinGUI(QWidget *parent):
79 signVerifyMessageDialog(0),
81 encryptWalletAction(0),
83 unlockWalletAction(0),
84 unlockWalletMiningAction(0),
85 changePassphraseAction(0),
94 setWindowTitle(tr("NovaCoin") + " - " + tr("Wallet"));
96 qApp->setWindowIcon(QIcon(":icons/bitcoin"));
97 setWindowIcon(QIcon(":icons/bitcoin"));
99 setUnifiedTitleAndToolBarOnMac(true);
100 QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
102 // Accept D&D of URIs
103 setAcceptDrops(true);
105 // Create actions for the toolbar, menu bar and tray/dock icon
108 // Create application menu bar
111 // Create the toolbars
114 // Create the tray icon (or setup the dock icon)
118 overviewPage = new OverviewPage();
120 transactionsPage = new QWidget(this);
121 QVBoxLayout *vbox = new QVBoxLayout();
122 transactionView = new TransactionView(this);
123 vbox->addWidget(transactionView);
124 transactionsPage->setLayout(vbox);
126 mintingPage = new QWidget(this);
127 QVBoxLayout *vboxMinting = new QVBoxLayout();
128 mintingView = new MintingView(this);
129 vboxMinting->addWidget(mintingView);
130 mintingPage->setLayout(vboxMinting);
132 addressBookPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::SendingTab);
134 receiveCoinsPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::ReceivingTab);
136 sendCoinsPage = new SendCoinsDialog(this);
138 signVerifyMessageDialog = new SignVerifyMessageDialog(0);
140 multisigPage = new MultisigDialog(0);
142 centralWidget = new QStackedWidget(this);
143 centralWidget->addWidget(overviewPage);
144 centralWidget->addWidget(transactionsPage);
145 centralWidget->addWidget(mintingPage);
146 centralWidget->addWidget(addressBookPage);
147 centralWidget->addWidget(receiveCoinsPage);
148 centralWidget->addWidget(sendCoinsPage);
149 setCentralWidget(centralWidget);
154 // Status bar notification icons
155 QFrame *frameBlocks = new QFrame();
156 frameBlocks->setContentsMargins(0,0,0,0);
157 frameBlocks->setMinimumWidth(72);
158 frameBlocks->setMaximumWidth(72);
159 QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);
160 frameBlocksLayout->setContentsMargins(3,0,3,0);
161 frameBlocksLayout->setSpacing(3);
162 labelEncryptionIcon = new QLabel();
163 labelMiningIcon = new QLabel();
164 labelConnectionsIcon = new QLabel();
165 labelBlocksIcon = new QLabel();
166 frameBlocksLayout->addStretch();
167 frameBlocksLayout->addWidget(labelEncryptionIcon);
168 frameBlocksLayout->addStretch();
169 frameBlocksLayout->addWidget(labelMiningIcon);
170 frameBlocksLayout->addStretch();
171 frameBlocksLayout->addWidget(labelConnectionsIcon);
172 frameBlocksLayout->addStretch();
173 frameBlocksLayout->addWidget(labelBlocksIcon);
174 frameBlocksLayout->addStretch();
176 // Progress bar and label for blocks download
177 progressBarLabel = new QLabel();
178 progressBarLabel->setVisible(false);
179 progressBar = new QProgressBar();
180 progressBar->setAlignment(Qt::AlignCenter);
181 progressBar->setVisible(false);
183 // Override style sheet for progress bar for styles that have a segmented progress bar,
184 // as they make the text unreadable (workaround for issue #1071)
185 // See https://qt-project.org/doc/qt-4.8/gallery.html
186 QString curStyle = qApp->style()->metaObject()->className();
187 if(curStyle == "QWindowsStyle" || curStyle == "QWindowsXPStyle")
189 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; }");
192 statusBar()->addWidget(progressBarLabel);
193 statusBar()->addWidget(progressBar);
194 statusBar()->addPermanentWidget(frameBlocks);
196 syncIconMovie = new QMovie(":/movies/update_spinner", "mng", this);
198 // Clicking on a transaction on the overview page simply sends you to transaction history page
199 connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), this, SLOT(gotoHistoryPage()));
200 connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex)));
202 // Double-clicking on a transaction on the transaction history page shows details
203 connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
205 rpcConsole = new RPCConsole(0);
206 connect(openRPCConsoleAction, SIGNAL(triggered()), rpcConsole, SLOT(show()));
208 aboutDialog = new AboutDialog(0);
209 optionsDialog = new OptionsDialog(0);
211 // Clicking on "Verify Message" in the address book sends you to the verify message tab
212 connect(addressBookPage, SIGNAL(verifyMessage(QString)), this, SLOT(gotoVerifyMessageTab(QString)));
213 // Clicking on "Sign Message" in the receive coins page sends you to the sign message tab
214 connect(receiveCoinsPage, SIGNAL(signMessage(QString)), this, SLOT(gotoSignMessageTab(QString)));
219 BitcoinGUI::~BitcoinGUI()
221 if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu)
229 delete optionsDialog;
231 delete signVerifyMessageDialog;
234 void BitcoinGUI::createActions()
236 QActionGroup *tabGroup = new QActionGroup(this);
238 overviewAction = new QAction(QIcon(":/icons/overview"), tr("&Overview"), this);
239 overviewAction->setToolTip(tr("Show general overview of wallet"));
240 overviewAction->setCheckable(true);
241 overviewAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_1));
242 tabGroup->addAction(overviewAction);
244 sendCoinsAction = new QAction(QIcon(":/icons/send"), tr("&Send coins"), this);
245 sendCoinsAction->setToolTip(tr("Send coins to a NovaCoin address"));
246 sendCoinsAction->setCheckable(true);
247 sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2));
248 tabGroup->addAction(sendCoinsAction);
250 receiveCoinsAction = new QAction(QIcon(":/icons/receiving_addresses"), tr("&Receive coins"), this);
251 receiveCoinsAction->setToolTip(tr("Show the list of addresses for receiving payments"));
252 receiveCoinsAction->setCheckable(true);
253 receiveCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_3));
254 tabGroup->addAction(receiveCoinsAction);
256 historyAction = new QAction(QIcon(":/icons/history"), tr("&Transactions"), this);
257 historyAction->setToolTip(tr("Browse transaction history"));
258 historyAction->setCheckable(true);
259 historyAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_4));
260 tabGroup->addAction(historyAction);
262 mintingAction = new QAction(QIcon(":/icons/history"), tr("&Minting"), this);
263 mintingAction->setToolTip(tr("Show your minting capacity"));
264 mintingAction->setCheckable(true);
265 mintingAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_5));
266 tabGroup->addAction(mintingAction);
268 addressBookAction = new QAction(QIcon(":/icons/address-book"), tr("&Address Book"), this);
269 addressBookAction->setToolTip(tr("Edit the list of stored addresses and labels"));
270 addressBookAction->setCheckable(true);
271 addressBookAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_6));
272 tabGroup->addAction(addressBookAction);
274 multisigAction = new QAction(QIcon(":/icons/send"), tr("Multisig"), this);
275 multisigAction->setStatusTip(tr("Open window for working with multisig addresses"));
276 tabGroup->addAction(multisigAction);
278 connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
279 connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage()));
280 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
281 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
282 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
283 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
284 connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
285 connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage()));
286 connect(mintingAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
287 connect(mintingAction, SIGNAL(triggered()), this, SLOT(gotoMintingPage()));
288 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
289 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(gotoAddressBookPage()));
290 connect(multisigAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
291 connect(multisigAction, SIGNAL(triggered()), this, SLOT(gotoMultisigPage()));
293 quitAction = new QAction(QIcon(":/icons/quit"), tr("E&xit"), this);
294 quitAction->setStatusTip(tr("Quit application"));
295 quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
296 quitAction->setMenuRole(QAction::QuitRole);
297 aboutAction = new QAction(QIcon(":/icons/bitcoin"), tr("&About NovaCoin"), this);
298 aboutAction->setStatusTip(tr("Show information about NovaCoin"));
299 aboutAction->setMenuRole(QAction::AboutRole);
300 #if QT_VERSION < 0x050000
301 aboutQtAction = new QAction(QIcon(":/trolltech/qmessagebox/images/qtlogo-64.png"), tr("About &Qt"), this);
303 aboutQtAction = new QAction(QIcon(":/qt-project.org/qmessagebox/images/qtlogo-64.png"), tr("About &Qt"), this);
305 aboutQtAction->setStatusTip(tr("Show information about Qt"));
306 aboutQtAction->setMenuRole(QAction::AboutQtRole);
307 optionsAction = new QAction(QIcon(":/icons/options"), tr("&Options..."), this);
308 optionsAction->setStatusTip(tr("Modify configuration options for NovaCoin"));
309 optionsAction->setMenuRole(QAction::PreferencesRole);
310 toggleHideAction = new QAction(QIcon(":/icons/bitcoin"), tr("&Show / Hide"), this);
311 encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet..."), this);
312 encryptWalletAction->setStatusTip(tr("Encrypt or decrypt wallet"));
313 encryptWalletAction->setCheckable(true);
314 backupWalletAction = new QAction(QIcon(":/icons/filesave"), tr("&Backup Wallet..."), this);
315 backupWalletAction->setStatusTip(tr("Backup wallet to another location"));
316 dumpWalletAction = new QAction(QIcon(":/icons/dump"), tr("&Dump Wallet..."), this);
317 dumpWalletAction->setStatusTip(tr("Dump keys to a text file"));
318 importWalletAction = new QAction(QIcon(":/icons/import"), tr("&Import Wallet..."), this);
319 importWalletAction->setStatusTip(tr("Import keys into a wallet"));
320 changePassphraseAction = new QAction(QIcon(":/icons/key"), tr("&Change Passphrase..."), this);
321 changePassphraseAction->setStatusTip(tr("Change the passphrase used for wallet encryption"));
322 signMessageAction = new QAction(QIcon(":/icons/edit"), tr("Sign &message..."), this);
323 signMessageAction->setStatusTip(tr("Sign messages with your Novacoin addresses to prove you own them"));
324 verifyMessageAction = new QAction(QIcon(":/icons/transaction_0"), tr("&Verify message..."), this);
325 verifyMessageAction->setStatusTip(tr("Verify messages to ensure they were signed with specified Novacoin addresses"));
327 lockWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Lock wallet"), this);
328 lockWalletAction->setStatusTip(tr("Lock wallet"));
329 lockWalletAction->setCheckable(true);
331 unlockWalletAction = new QAction(QIcon(":/icons/lock_open"), tr("Unlo&ck wallet"), this);
332 unlockWalletAction->setStatusTip(tr("Unlock wallet"));
333 unlockWalletAction->setCheckable(true);
335 unlockWalletMiningAction = new QAction(QIcon(":/icons/mining_active"), tr("Unlo&ck wallet for mining"), this);
336 unlockWalletMiningAction->setStatusTip(tr("Unlock wallet for mining"));
337 unlockWalletMiningAction->setCheckable(true);
339 exportAction = new QAction(QIcon(":/icons/export"), tr("&Export..."), this);
340 exportAction->setStatusTip(tr("Export the data in the current tab to a file"));
341 openRPCConsoleAction = new QAction(QIcon(":/icons/debugwindow"), tr("&Debug window"), this);
342 openRPCConsoleAction->setStatusTip(tr("Open debugging and diagnostic console"));
344 connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
345 connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked()));
346 connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
347 connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked()));
348 connect(toggleHideAction, SIGNAL(triggered()), this, SLOT(toggleHidden()));
349 connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool)));
350 connect(lockWalletAction, SIGNAL(triggered(bool)), this, SLOT(lockWallet()));
351 connect(unlockWalletAction, SIGNAL(triggered(bool)), this, SLOT(unlockWallet()));
352 connect(unlockWalletMiningAction, SIGNAL(triggered(bool)), this, SLOT(unlockWalletMining(bool)));
353 connect(backupWalletAction, SIGNAL(triggered()), this, SLOT(backupWallet()));
354 connect(dumpWalletAction, SIGNAL(triggered()), this, SLOT(dumpWallet()));
355 connect(importWalletAction, SIGNAL(triggered()), this, SLOT(importWallet()));
356 connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase()));
357 connect(signMessageAction, SIGNAL(triggered()), this, SLOT(gotoSignMessageTab()));
358 connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(gotoVerifyMessageTab()));
361 void BitcoinGUI::createMenuBar()
364 // Create a decoupled menu bar on Mac which stays even if the window is closed
365 appMenuBar = new QMenuBar();
367 // Get the main window's menu bar on other platforms
368 appMenuBar = menuBar();
371 // Configure the menus
372 QMenu *file = appMenuBar->addMenu(tr("&File"));
373 file->addAction(backupWalletAction);
374 file->addSeparator();
375 file->addAction(dumpWalletAction);
376 file->addAction(importWalletAction);
377 file->addAction(exportAction);
378 file->addAction(signMessageAction);
379 file->addAction(verifyMessageAction);
380 file->addAction(multisigAction);
381 file->addSeparator();
382 file->addAction(quitAction);
384 QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
385 QMenu *securityMenu = settings->addMenu(QIcon(":/icons/key"), tr("&Wallet security"));
386 securityMenu->addAction(encryptWalletAction);
387 securityMenu->addAction(changePassphraseAction);
388 securityMenu->addAction(unlockWalletAction);
389 securityMenu->addAction(unlockWalletMiningAction);
390 securityMenu->addAction(lockWalletAction);
391 settings->addAction(optionsAction);
393 QMenu *help = appMenuBar->addMenu(tr("&Help"));
394 help->addAction(openRPCConsoleAction);
395 help->addSeparator();
396 help->addAction(aboutAction);
397 help->addAction(aboutQtAction);
400 void BitcoinGUI::createToolBars()
402 QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));
403 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
404 toolbar->addAction(overviewAction);
405 toolbar->addAction(sendCoinsAction);
406 toolbar->addAction(receiveCoinsAction);
407 toolbar->addAction(historyAction);
408 toolbar->addAction(mintingAction);
409 toolbar->addAction(addressBookAction);
411 QToolBar *toolbar2 = addToolBar(tr("Actions toolbar"));
412 toolbar2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
413 toolbar2->addAction(exportAction);
414 toolbar2->setVisible(false);
418 void BitcoinGUI::setClientModel(ClientModel *clientModel)
420 this->clientModel = clientModel;
423 // Replace some strings and icons, when using the testnet
424 if(clientModel->isTestNet())
426 setWindowTitle(windowTitle() + QString(" ") + tr("[testnet]"));
428 qApp->setWindowIcon(QIcon(":icons/bitcoin_testnet"));
429 setWindowIcon(QIcon(":icons/bitcoin_testnet"));
431 MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
435 trayIcon->setToolTip(tr("NovaCoin client") + QString(" ") + tr("[testnet]"));
436 trayIcon->setIcon(QIcon(":/icons/toolbar_testnet"));
437 toggleHideAction->setIcon(QIcon(":/icons/toolbar_testnet"));
440 aboutAction->setIcon(QIcon(":/icons/toolbar_testnet"));
443 // Keep up to date with client
444 setNumConnections(clientModel->getNumConnections());
445 connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
447 setNumBlocks(clientModel->getNumBlocks(), clientModel->getNumBlocksOfPeers());
448 connect(clientModel, SIGNAL(numBlocksChanged(int,int)), this, SLOT(setNumBlocks(int,int)));
450 QTimer *timer = new QTimer(this);
451 connect(timer, SIGNAL(timeout()), this, SLOT(updateMining()));
452 timer->start(10*1000); //10 seconds
454 // Report errors from network/worker thread
455 connect(clientModel, SIGNAL(error(QString,QString,bool)), this, SLOT(error(QString,QString,bool)));
457 rpcConsole->setClientModel(clientModel);
458 addressBookPage->setOptionsModel(clientModel->getOptionsModel());
459 receiveCoinsPage->setOptionsModel(clientModel->getOptionsModel());
463 void BitcoinGUI::setWalletModel(WalletModel *walletModel)
465 this->walletModel = walletModel;
468 // Report errors from wallet thread
469 connect(walletModel, SIGNAL(error(QString,QString,bool)), this, SLOT(error(QString,QString,bool)));
471 // Put transaction list in tabs
472 transactionView->setModel(walletModel);
473 mintingView->setModel(walletModel);
475 overviewPage->setModel(walletModel);
476 addressBookPage->setModel(walletModel->getAddressTableModel());
477 receiveCoinsPage->setModel(walletModel->getAddressTableModel());
478 sendCoinsPage->setModel(walletModel);
479 signVerifyMessageDialog->setModel(walletModel);
480 multisigPage->setModel(walletModel);
482 setEncryptionStatus(walletModel->getEncryptionStatus());
483 connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));
484 connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(updateMining()));
486 // Balloon pop-up for new transaction
487 connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
488 this, SLOT(incomingTransaction(QModelIndex,int,int)));
490 // Ask for passphrase if needed
491 connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
495 void BitcoinGUI::createTrayIcon()
499 trayIcon = new QSystemTrayIcon(this);
500 trayIconMenu = new QMenu(this);
501 trayIcon->setContextMenu(trayIconMenu);
502 trayIcon->setToolTip(tr("NovaCoin client"));
503 trayIcon->setIcon(QIcon(":/icons/toolbar"));
504 connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
505 this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
508 // Note: On Mac, the dock icon is used to provide the tray's functionality.
509 MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance();
510 dockIconHandler->setMainWindow((QMainWindow *)this);
511 trayIconMenu = dockIconHandler->dockMenu();
514 // Configuration of the tray icon (or dock icon) icon menu
515 trayIconMenu->addAction(toggleHideAction);
516 trayIconMenu->addSeparator();
517 trayIconMenu->addAction(sendCoinsAction);
518 trayIconMenu->addAction(multisigAction);
519 trayIconMenu->addAction(receiveCoinsAction);
520 trayIconMenu->addSeparator();
521 trayIconMenu->addAction(signMessageAction);
522 trayIconMenu->addAction(verifyMessageAction);
523 trayIconMenu->addSeparator();
524 trayIconMenu->addAction(optionsAction);
525 trayIconMenu->addAction(openRPCConsoleAction);
527 // This is built-in on Mac
528 trayIconMenu->addSeparator();
529 trayIconMenu->addAction(quitAction);
531 notificator = new Notificator(QApplication::applicationName(), trayIcon, this);
535 void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
537 if(reason == QSystemTrayIcon::Trigger)
539 // Click on system tray icon triggers show/hide of the main window
540 toggleHideAction->trigger();
545 void BitcoinGUI::optionsClicked()
547 if(!clientModel || !clientModel->getOptionsModel())
550 optionsDialog->setModel(clientModel->getOptionsModel());
551 optionsDialog->setWindowModality(Qt::ApplicationModal);
552 optionsDialog->show();
555 void BitcoinGUI::aboutClicked()
557 aboutDialog->setModel(clientModel);
558 aboutDialog->setWindowModality(Qt::ApplicationModal);
562 void BitcoinGUI::setNumConnections(int count)
567 case 0: icon = ":/icons/connect_0"; break;
568 case 1: case 2: case 3: icon = ":/icons/connect_1"; break;
569 case 4: case 5: case 6: icon = ":/icons/connect_2"; break;
570 case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
571 default: icon = ":/icons/connect_4"; break;
573 labelConnectionsIcon->setPixmap(QIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
574 labelConnectionsIcon->setToolTip(tr("%n active connection(s) to NovaCoin network", "", count));
577 void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks)
579 // don't show / hide progress bar and its label if we have no connection to the network
580 if (!clientModel || clientModel->getNumConnections() == 0)
582 progressBarLabel->setVisible(false);
583 progressBar->setVisible(false);
588 QString strStatusBarWarnings = clientModel->getStatusBarWarnings();
591 if(count < nTotalBlocks)
593 int nRemainingBlocks = nTotalBlocks - count;
594 float nPercentageDone = count / (nTotalBlocks * 0.01f);
596 if (strStatusBarWarnings.isEmpty())
598 progressBarLabel->setText(tr("Synchronizing with network..."));
599 progressBarLabel->setVisible(true);
600 progressBar->setFormat(tr("~%n block(s) remaining", "", nRemainingBlocks));
601 progressBar->setMaximum(nTotalBlocks);
602 progressBar->setValue(count);
603 progressBar->setVisible(true);
606 tooltip = tr("Downloaded %1 of %2 blocks of transaction history (%3% done).").arg(count).arg(nTotalBlocks).arg(nPercentageDone, 0, 'f', 2);
610 if (strStatusBarWarnings.isEmpty())
611 progressBarLabel->setVisible(false);
613 progressBar->setVisible(false);
614 tooltip = tr("Downloaded %1 blocks of transaction history.").arg(count);
617 // Override progressBarLabel text and hide progress bar, when we have warnings to display
618 if (!strStatusBarWarnings.isEmpty())
620 progressBarLabel->setText(strStatusBarWarnings);
621 progressBarLabel->setVisible(true);
622 progressBar->setVisible(false);
625 tooltip = tr("Current PoW difficulty is %1.").arg(clientModel->getDifficulty(false)) + QString("<br>") + tooltip;
626 tooltip = tr("Current PoS difficulty is %1.").arg(clientModel->getDifficulty(true)) + QString("<br>") + tooltip;
628 QDateTime lastBlockDate = clientModel->getLastBlockDate();
629 int secs = lastBlockDate.secsTo(QDateTime::currentDateTime());
632 // Represent time from last generated block in human readable text
635 // Fully up to date. Leave text empty.
639 text = tr("%n second(s) ago","",secs);
641 else if(secs < 60*60)
643 text = tr("%n minute(s) ago","",secs/60);
645 else if(secs < 24*60*60)
647 text = tr("%n hour(s) ago","",secs/(60*60));
651 text = tr("%n day(s) ago","",secs/(60*60*24));
654 // Set icon state: spinning if catching up, tick otherwise
655 if(secs < 90*60 && count >= nTotalBlocks)
657 tooltip = tr("Up to date") + QString(".<br>") + tooltip;
658 labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
660 overviewPage->showOutOfSyncWarning(false);
664 tooltip = tr("Catching up...") + QString("<br>") + tooltip;
665 labelBlocksIcon->setMovie(syncIconMovie);
666 syncIconMovie->start();
668 overviewPage->showOutOfSyncWarning(true);
673 tooltip += QString("<br>");
674 tooltip += tr("Last received block was generated %1.").arg(text);
677 // Don't word-wrap this (fixed-width) tooltip
678 tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
680 labelBlocksIcon->setToolTip(tooltip);
681 progressBarLabel->setToolTip(tooltip);
682 progressBar->setToolTip(tooltip);
685 void BitcoinGUI::updateMining()
690 labelMiningIcon->setPixmap(QIcon(":/icons/mining_inactive").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
692 if (!clientModel->getNumConnections())
694 labelMiningIcon->setToolTip(tr("Wallet is offline"));
698 if (walletModel->getEncryptionStatus() == WalletModel::Locked)
700 labelMiningIcon->setToolTip(tr("Wallet is locked"));
704 if (clientModel->inInitialBlockDownload() || clientModel->getNumBlocksOfPeers() > clientModel->getNumBlocks())
706 labelMiningIcon->setToolTip(tr("Blockchain download is in progress"));
710 if (nStakeInputsMapSize > 0)
712 labelMiningIcon->setPixmap(QIcon(":/icons/mining_active").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
714 uint64_t nNetworkWeight = clientModel->getPoSKernelPS();
716 labelMiningIcon->setToolTip(QString("<nobr>")+tr("Stake miner is active<br>%1 inputs being used for mining<br>Network weight is %3").arg(nStakeInputsMapSize).arg(nNetworkWeight)+QString("<\nobr>"));
719 labelMiningIcon->setToolTip(tr("No suitable inputs were found"));
722 void BitcoinGUI::message(const QString &title, const QString &message, unsigned int style, const QString &detail)
724 QString strTitle = tr("NovaCoin") + " - ";
725 // Default to information icon
726 int nMBoxIcon = QMessageBox::Information;
727 int nNotifyIcon = Notificator::Information;
730 // Check for usage of predefined title
732 case CClientUIInterface::MSG_ERROR:
733 strTitle += tr("Error");
735 case CClientUIInterface::MSG_WARNING:
736 strTitle += tr("Warning");
738 case CClientUIInterface::MSG_INFORMATION:
739 strTitle += tr("Information");
742 strTitle += title; // Use supplied title
745 // Check for error/warning icon
746 if (style & CClientUIInterface::ICON_ERROR) {
747 nMBoxIcon = QMessageBox::Critical;
748 nNotifyIcon = Notificator::Critical;
750 else if (style & CClientUIInterface::ICON_WARNING) {
751 nMBoxIcon = QMessageBox::Warning;
752 nNotifyIcon = Notificator::Warning;
756 if (style & CClientUIInterface::MODAL) {
757 // Check for buttons, use OK as default, if none was supplied
758 QMessageBox::StandardButton buttons;
759 buttons = QMessageBox::Ok;
761 QMessageBox mBox((QMessageBox::Icon)nMBoxIcon, strTitle, message, buttons);
763 if(!detail.isEmpty()) { mBox.setDetailedText(detail); }
768 notificator->notify((Notificator::Class)nNotifyIcon, strTitle, message);
772 void BitcoinGUI::changeEvent(QEvent *e)
774 QMainWindow::changeEvent(e);
775 #ifndef Q_OS_MAC // Ignored on Mac
776 if(e->type() == QEvent::WindowStateChange)
778 if(clientModel && clientModel->getOptionsModel()->getMinimizeToTray())
780 QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
781 if(!(wsevt->oldState() & Qt::WindowMinimized) && isMinimized())
783 QTimer::singleShot(0, this, SLOT(hide()));
791 void BitcoinGUI::closeEvent(QCloseEvent *event)
795 #ifndef Q_OS_MAC // Ignored on Mac
796 if(!clientModel->getOptionsModel()->getMinimizeOnClose())
802 // close rpcConsole in case it was open to make some space for the shutdown window
805 QMainWindow::closeEvent(event);
808 void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
811 tr("This transaction is over the size limit. You can still send it for a fee of %1, "
812 "which goes to the nodes that process your transaction and helps to support the network. "
813 "Do you want to pay the fee?").arg(
814 BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nFeeRequired));
815 QMessageBox::StandardButton retval = QMessageBox::question(
816 this, tr("Confirm transaction fee"), strMessage,
817 QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes);
818 *payFee = (retval == QMessageBox::Yes);
821 void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
823 if(!walletModel || !clientModel)
825 TransactionTableModel *ttm = walletModel->getTransactionTableModel();
826 qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
827 .data(Qt::EditRole).toULongLong();
828 if(!clientModel->inInitialBlockDownload())
830 // On new transaction, make an info balloon
831 // Unless the initial block download is in progress, to prevent balloon-spam
832 QString date = ttm->index(start, TransactionTableModel::Date, parent)
834 QString type = ttm->index(start, TransactionTableModel::Type, parent)
836 QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
838 QIcon icon = qvariant_cast<QIcon>(ttm->index(start,
839 TransactionTableModel::ToAddress, parent)
840 .data(Qt::DecorationRole));
842 notificator->notify(Notificator::Information,
843 (amount)<0 ? tr("Sent transaction") :
844 tr("Incoming transaction"),
850 .arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true))
852 .arg(address), icon);
856 void BitcoinGUI::gotoOverviewPage()
858 overviewAction->setChecked(true);
859 centralWidget->setCurrentWidget(overviewPage);
861 exportAction->setEnabled(false);
862 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
865 void BitcoinGUI::gotoHistoryPage()
867 historyAction->setChecked(true);
868 centralWidget->setCurrentWidget(transactionsPage);
870 exportAction->setEnabled(true);
871 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
872 connect(exportAction, SIGNAL(triggered()), transactionView, SLOT(exportClicked()));
875 void BitcoinGUI::gotoMintingPage()
877 mintingAction->setChecked(true);
878 centralWidget->setCurrentWidget(mintingPage);
880 exportAction->setEnabled(true);
881 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
882 connect(exportAction, SIGNAL(triggered()), mintingView, SLOT(exportClicked()));
886 void BitcoinGUI::gotoAddressBookPage()
888 addressBookAction->setChecked(true);
889 centralWidget->setCurrentWidget(addressBookPage);
891 exportAction->setEnabled(true);
892 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
893 connect(exportAction, SIGNAL(triggered()), addressBookPage, SLOT(exportClicked()));
896 void BitcoinGUI::gotoReceiveCoinsPage()
898 receiveCoinsAction->setChecked(true);
899 centralWidget->setCurrentWidget(receiveCoinsPage);
901 exportAction->setEnabled(true);
902 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
903 connect(exportAction, SIGNAL(triggered()), receiveCoinsPage, SLOT(exportClicked()));
906 void BitcoinGUI::gotoSendCoinsPage()
908 sendCoinsAction->setChecked(true);
909 centralWidget->setCurrentWidget(sendCoinsPage);
911 exportAction->setEnabled(false);
912 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
915 void BitcoinGUI::gotoSignMessageTab(QString addr)
917 // call show() in showTab_SM()
918 signVerifyMessageDialog->showTab_SM(true);
921 signVerifyMessageDialog->setAddress_SM(addr);
924 void BitcoinGUI::gotoVerifyMessageTab(QString addr)
926 // call show() in showTab_VM()
927 signVerifyMessageDialog->showTab_VM(true);
930 signVerifyMessageDialog->setAddress_VM(addr);
933 void BitcoinGUI::gotoMultisigPage()
935 multisigPage->show();
936 multisigPage->setFocus();
939 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
942 if(event->mimeData()->hasUrls())
943 event->acceptProposedAction();
946 void BitcoinGUI::dropEvent(QDropEvent *event)
948 if(event->mimeData()->hasUrls())
950 int nValidUrisFound = 0;
951 QList<QUrl> uris = event->mimeData()->urls();
952 foreach(const QUrl &uri, uris)
954 if (sendCoinsPage->handleURI(uri.toString()))
958 // if valid URIs were found
962 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."));
965 event->acceptProposedAction();
968 void BitcoinGUI::handleURI(QString strURI)
970 // URI has to be valid
971 if (sendCoinsPage->handleURI(strURI))
973 showNormalIfMinimized();
977 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."));
980 void BitcoinGUI::setEncryptionStatus(int status)
984 case WalletModel::Unencrypted:
985 labelEncryptionIcon->hide();
986 encryptWalletAction->setChecked(false);
987 changePassphraseAction->setEnabled(false);
988 lockWalletAction->setEnabled(false);
989 unlockWalletAction->setEnabled(false);
990 unlockWalletMiningAction->setEnabled(false);
991 encryptWalletAction->setEnabled(true);
993 case WalletModel::Unlocked:
994 labelEncryptionIcon->show();
995 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
996 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
997 encryptWalletAction->setChecked(true);
998 changePassphraseAction->setEnabled(true);
999 encryptWalletAction->setEnabled(true);
1001 lockWalletAction->setEnabled(true);
1002 lockWalletAction->setChecked(false);
1003 unlockWalletAction->setEnabled(false);
1004 unlockWalletMiningAction->setEnabled(false);
1006 if (fWalletUnlockMintOnly)
1007 unlockWalletMiningAction->setChecked(true);
1009 unlockWalletAction->setChecked(true);
1012 case WalletModel::Locked:
1013 labelEncryptionIcon->show();
1014 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
1015 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
1016 encryptWalletAction->setChecked(true);
1017 changePassphraseAction->setEnabled(true);
1018 encryptWalletAction->setEnabled(true);
1020 lockWalletAction->setChecked(true);
1021 unlockWalletAction->setChecked(false);
1022 unlockWalletMiningAction->setChecked(false);
1024 lockWalletAction->setEnabled(false);
1025 unlockWalletAction->setEnabled(true);
1026 unlockWalletMiningAction->setEnabled(true);
1031 void BitcoinGUI::encryptWallet(bool status)
1035 AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt:
1036 AskPassphraseDialog::Decrypt, this);
1037 dlg.setModel(walletModel);
1040 setEncryptionStatus(walletModel->getEncryptionStatus());
1043 void BitcoinGUI::unlockWalletMining(bool status)
1048 // Unlock wallet when requested by wallet model
1049 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1051 AskPassphraseDialog dlg(AskPassphraseDialog::UnlockMining, this);
1052 dlg.setModel(walletModel);
1057 void BitcoinGUI::backupWallet()
1059 #if QT_VERSION < 0x050000
1060 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1062 QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1064 QString filename = QFileDialog::getSaveFileName(this, tr("Backup Wallet"), saveDir, tr("Wallet Data (*.dat)"));
1065 if(!filename.isEmpty()) {
1066 if(!walletModel->backupWallet(filename)) {
1067 QMessageBox::warning(this, tr("Backup Failed"), tr("There was an error trying to save the wallet data to the new location."));
1072 void BitcoinGUI::dumpWallet()
1077 WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1080 // Unlock wallet failed or was cancelled
1084 #if QT_VERSION < 0x050000
1085 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1087 QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1089 QString filename = QFileDialog::getSaveFileName(this, tr("Dump Wallet"), saveDir, tr("Wallet dump (*.txt)"));
1090 if(!filename.isEmpty()) {
1091 if(!walletModel->dumpWallet(filename)) {
1092 message(tr("Dump failed"),
1093 tr("An error happened while trying to save the keys to your location.\n"
1094 "Keys were not saved.")
1095 ,CClientUIInterface::MSG_ERROR);
1098 message(tr("Dump successful"),
1099 tr("Keys were saved to this file:\n%2")
1101 ,CClientUIInterface::MSG_INFORMATION);
1105 void BitcoinGUI::importWallet()
1110 WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1113 // Unlock wallet failed or was cancelled
1117 #if QT_VERSION < 0x050000
1118 QString openDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1120 QString openDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1122 QString filename = QFileDialog::getOpenFileName(this, tr("Import Wallet"), openDir, tr("Wallet dump (*.txt)"));
1123 if(!filename.isEmpty()) {
1124 if(!walletModel->importWallet(filename)) {
1125 message(tr("Import Failed"),
1126 tr("An error happened while trying to import the keys.\n"
1127 "Some or all keys from:\n %1,\n were not imported into your wallet.")
1129 ,CClientUIInterface::MSG_ERROR);
1132 message(tr("Import Successful"),
1133 tr("All keys from:\n %1,\n were imported into your wallet.")
1135 ,CClientUIInterface::MSG_INFORMATION);
1140 void BitcoinGUI::changePassphrase()
1142 AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
1143 dlg.setModel(walletModel);
1147 void BitcoinGUI::unlockWallet()
1151 // Unlock wallet when requested by wallet model
1152 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1154 AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
1155 dlg.setModel(walletModel);
1160 void BitcoinGUI::lockWallet()
1165 walletModel->setWalletLocked(true);
1168 void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden)
1170 // activateWindow() (sometimes) helps with keyboard focus on Windows
1173 // Make sure the window is not minimized
1174 setWindowState(windowState() & (~Qt::WindowMinimized | Qt::WindowActive));
1180 else if (isMinimized())
1186 else if (GUIUtil::isObscured(this))
1193 if (GUIUtil::isObscured(this))
1197 else if(fToggleHidden)
1201 void BitcoinGUI::toggleHidden()
1203 showNormalIfMinimized(true);
1206 void BitcoinGUI::error(const QString &title, const QString &message, bool modal)
1208 // Report errors from network/worker thread
1211 QMessageBox::critical(this, title, message, QMessageBox::Ok, QMessageBox::Ok);
1213 notificator->notify(Notificator::Critical, title, message);