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 QDateTime lastBlockDate = clientModel->getLastBlockDate();
626 int secs = lastBlockDate.secsTo(QDateTime::currentDateTime());
629 // Represent time from last generated block in human readable text
632 // Fully up to date. Leave text empty.
636 text = tr("%n second(s) ago","",secs);
638 else if(secs < 60*60)
640 text = tr("%n minute(s) ago","",secs/60);
642 else if(secs < 24*60*60)
644 text = tr("%n hour(s) ago","",secs/(60*60));
648 text = tr("%n day(s) ago","",secs/(60*60*24));
651 // Set icon state: spinning if catching up, tick otherwise
652 if(secs < 90*60 && count >= nTotalBlocks)
654 tooltip = tr("Up to date") + QString(".<br>") + tooltip;
655 labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
657 overviewPage->showOutOfSyncWarning(false);
661 tooltip = tr("Catching up...") + QString("<br>") + tooltip;
662 labelBlocksIcon->setMovie(syncIconMovie);
663 syncIconMovie->start();
665 overviewPage->showOutOfSyncWarning(true);
670 tooltip += QString("<br>");
671 tooltip += tr("Last received block was generated %1.").arg(text);
674 // Don't word-wrap this (fixed-width) tooltip
675 tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
677 labelBlocksIcon->setToolTip(tooltip);
678 progressBarLabel->setToolTip(tooltip);
679 progressBar->setToolTip(tooltip);
682 void BitcoinGUI::updateMining()
687 labelMiningIcon->setPixmap(QIcon(":/icons/mining_inactive").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
689 if (!clientModel->getNumConnections())
691 labelMiningIcon->setToolTip(tr("Wallet is offline"));
695 if (walletModel->getEncryptionStatus() == WalletModel::Locked)
697 labelMiningIcon->setToolTip(tr("Wallet is locked"));
701 if (clientModel->inInitialBlockDownload() || clientModel->getNumBlocksOfPeers() > clientModel->getNumBlocks())
703 labelMiningIcon->setToolTip(tr("Blockchain download is in progress"));
707 if (nStakeInputsMapSize > 0)
709 labelMiningIcon->setPixmap(QIcon(":/icons/mining_active").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
711 uint64_t nNetworkWeight = clientModel->getPoSKernelPS();
713 labelMiningIcon->setToolTip(QString("<nobr>")+tr("Stake miner is active<br>%1 inputs used the mining<br>Network weight is %3").arg(nStakeInputsMapSize).arg(nNetworkWeight)+QString("<\nobr>"));
716 labelMiningIcon->setToolTip(tr("No suitable inputs were found"));
719 void BitcoinGUI::message(const QString &title, const QString &message, unsigned int style, const QString &detail)
721 QString strTitle = tr("NovaCoin") + " - ";
722 // Default to information icon
723 int nMBoxIcon = QMessageBox::Information;
724 int nNotifyIcon = Notificator::Information;
727 // Check for usage of predefined title
729 case CClientUIInterface::MSG_ERROR:
730 strTitle += tr("Error");
732 case CClientUIInterface::MSG_WARNING:
733 strTitle += tr("Warning");
735 case CClientUIInterface::MSG_INFORMATION:
736 strTitle += tr("Information");
739 strTitle += title; // Use supplied title
742 // Check for error/warning icon
743 if (style & CClientUIInterface::ICON_ERROR) {
744 nMBoxIcon = QMessageBox::Critical;
745 nNotifyIcon = Notificator::Critical;
747 else if (style & CClientUIInterface::ICON_WARNING) {
748 nMBoxIcon = QMessageBox::Warning;
749 nNotifyIcon = Notificator::Warning;
753 if (style & CClientUIInterface::MODAL) {
754 // Check for buttons, use OK as default, if none was supplied
755 QMessageBox::StandardButton buttons;
756 buttons = QMessageBox::Ok;
758 QMessageBox mBox((QMessageBox::Icon)nMBoxIcon, strTitle, message, buttons);
760 if(!detail.isEmpty()) { mBox.setDetailedText(detail); }
765 notificator->notify((Notificator::Class)nNotifyIcon, strTitle, message);
769 void BitcoinGUI::changeEvent(QEvent *e)
771 QMainWindow::changeEvent(e);
772 #ifndef Q_OS_MAC // Ignored on Mac
773 if(e->type() == QEvent::WindowStateChange)
775 if(clientModel && clientModel->getOptionsModel()->getMinimizeToTray())
777 QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
778 if(!(wsevt->oldState() & Qt::WindowMinimized) && isMinimized())
780 QTimer::singleShot(0, this, SLOT(hide()));
788 void BitcoinGUI::closeEvent(QCloseEvent *event)
792 #ifndef Q_OS_MAC // Ignored on Mac
793 if(!clientModel->getOptionsModel()->getMinimizeOnClose())
799 // close rpcConsole in case it was open to make some space for the shutdown window
802 QMainWindow::closeEvent(event);
805 void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
808 tr("This transaction is over the size limit. You can still send it for a fee of %1, "
809 "which goes to the nodes that process your transaction and helps to support the network. "
810 "Do you want to pay the fee?").arg(
811 BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nFeeRequired));
812 QMessageBox::StandardButton retval = QMessageBox::question(
813 this, tr("Confirm transaction fee"), strMessage,
814 QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes);
815 *payFee = (retval == QMessageBox::Yes);
818 void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
820 if(!walletModel || !clientModel)
822 TransactionTableModel *ttm = walletModel->getTransactionTableModel();
823 qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
824 .data(Qt::EditRole).toULongLong();
825 if(!clientModel->inInitialBlockDownload())
827 // On new transaction, make an info balloon
828 // Unless the initial block download is in progress, to prevent balloon-spam
829 QString date = ttm->index(start, TransactionTableModel::Date, parent)
831 QString type = ttm->index(start, TransactionTableModel::Type, parent)
833 QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
835 QIcon icon = qvariant_cast<QIcon>(ttm->index(start,
836 TransactionTableModel::ToAddress, parent)
837 .data(Qt::DecorationRole));
839 notificator->notify(Notificator::Information,
840 (amount)<0 ? tr("Sent transaction") :
841 tr("Incoming transaction"),
847 .arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true))
849 .arg(address), icon);
853 void BitcoinGUI::gotoOverviewPage()
855 overviewAction->setChecked(true);
856 centralWidget->setCurrentWidget(overviewPage);
858 exportAction->setEnabled(false);
859 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
862 void BitcoinGUI::gotoHistoryPage()
864 historyAction->setChecked(true);
865 centralWidget->setCurrentWidget(transactionsPage);
867 exportAction->setEnabled(true);
868 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
869 connect(exportAction, SIGNAL(triggered()), transactionView, SLOT(exportClicked()));
872 void BitcoinGUI::gotoMintingPage()
874 mintingAction->setChecked(true);
875 centralWidget->setCurrentWidget(mintingPage);
877 exportAction->setEnabled(true);
878 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
879 connect(exportAction, SIGNAL(triggered()), mintingView, SLOT(exportClicked()));
883 void BitcoinGUI::gotoAddressBookPage()
885 addressBookAction->setChecked(true);
886 centralWidget->setCurrentWidget(addressBookPage);
888 exportAction->setEnabled(true);
889 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
890 connect(exportAction, SIGNAL(triggered()), addressBookPage, SLOT(exportClicked()));
893 void BitcoinGUI::gotoReceiveCoinsPage()
895 receiveCoinsAction->setChecked(true);
896 centralWidget->setCurrentWidget(receiveCoinsPage);
898 exportAction->setEnabled(true);
899 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
900 connect(exportAction, SIGNAL(triggered()), receiveCoinsPage, SLOT(exportClicked()));
903 void BitcoinGUI::gotoSendCoinsPage()
905 sendCoinsAction->setChecked(true);
906 centralWidget->setCurrentWidget(sendCoinsPage);
908 exportAction->setEnabled(false);
909 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
912 void BitcoinGUI::gotoSignMessageTab(QString addr)
914 // call show() in showTab_SM()
915 signVerifyMessageDialog->showTab_SM(true);
918 signVerifyMessageDialog->setAddress_SM(addr);
921 void BitcoinGUI::gotoVerifyMessageTab(QString addr)
923 // call show() in showTab_VM()
924 signVerifyMessageDialog->showTab_VM(true);
927 signVerifyMessageDialog->setAddress_VM(addr);
930 void BitcoinGUI::gotoMultisigPage()
932 multisigPage->show();
933 multisigPage->setFocus();
936 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
939 if(event->mimeData()->hasUrls())
940 event->acceptProposedAction();
943 void BitcoinGUI::dropEvent(QDropEvent *event)
945 if(event->mimeData()->hasUrls())
947 int nValidUrisFound = 0;
948 QList<QUrl> uris = event->mimeData()->urls();
949 foreach(const QUrl &uri, uris)
951 if (sendCoinsPage->handleURI(uri.toString()))
955 // if valid URIs were found
959 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."));
962 event->acceptProposedAction();
965 void BitcoinGUI::handleURI(QString strURI)
967 // URI has to be valid
968 if (sendCoinsPage->handleURI(strURI))
970 showNormalIfMinimized();
974 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."));
977 void BitcoinGUI::setEncryptionStatus(int status)
981 case WalletModel::Unencrypted:
982 labelEncryptionIcon->hide();
983 encryptWalletAction->setChecked(false);
984 changePassphraseAction->setEnabled(false);
985 lockWalletAction->setEnabled(false);
986 unlockWalletAction->setEnabled(false);
987 unlockWalletMiningAction->setEnabled(false);
988 encryptWalletAction->setEnabled(true);
990 case WalletModel::Unlocked:
991 labelEncryptionIcon->show();
992 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
993 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
994 encryptWalletAction->setChecked(true);
995 changePassphraseAction->setEnabled(true);
996 encryptWalletAction->setEnabled(true);
998 lockWalletAction->setEnabled(true);
999 lockWalletAction->setChecked(false);
1000 unlockWalletAction->setEnabled(false);
1001 unlockWalletMiningAction->setEnabled(false);
1003 if (fWalletUnlockMintOnly)
1004 unlockWalletMiningAction->setChecked(true);
1006 unlockWalletAction->setChecked(true);
1009 case WalletModel::Locked:
1010 labelEncryptionIcon->show();
1011 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
1012 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
1013 encryptWalletAction->setChecked(true);
1014 changePassphraseAction->setEnabled(true);
1015 encryptWalletAction->setEnabled(true);
1017 lockWalletAction->setChecked(true);
1018 unlockWalletAction->setChecked(false);
1019 unlockWalletMiningAction->setChecked(false);
1021 lockWalletAction->setEnabled(false);
1022 unlockWalletAction->setEnabled(true);
1023 unlockWalletMiningAction->setEnabled(true);
1028 void BitcoinGUI::encryptWallet(bool status)
1032 AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt:
1033 AskPassphraseDialog::Decrypt, this);
1034 dlg.setModel(walletModel);
1037 setEncryptionStatus(walletModel->getEncryptionStatus());
1040 void BitcoinGUI::unlockWalletMining(bool status)
1045 // Unlock wallet when requested by wallet model
1046 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1048 AskPassphraseDialog dlg(AskPassphraseDialog::UnlockMining, this);
1049 dlg.setModel(walletModel);
1054 void BitcoinGUI::backupWallet()
1056 #if QT_VERSION < 0x050000
1057 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1059 QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1061 QString filename = QFileDialog::getSaveFileName(this, tr("Backup Wallet"), saveDir, tr("Wallet Data (*.dat)"));
1062 if(!filename.isEmpty()) {
1063 if(!walletModel->backupWallet(filename)) {
1064 QMessageBox::warning(this, tr("Backup Failed"), tr("There was an error trying to save the wallet data to the new location."));
1069 void BitcoinGUI::dumpWallet()
1074 WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1077 // Unlock wallet failed or was cancelled
1081 #if QT_VERSION < 0x050000
1082 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1084 QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1086 QString filename = QFileDialog::getSaveFileName(this, tr("Dump Wallet"), saveDir, tr("Wallet dump (*.txt)"));
1087 if(!filename.isEmpty()) {
1088 if(!walletModel->dumpWallet(filename)) {
1089 message(tr("Dump failed"),
1090 tr("An error happened while trying to save the keys to your location.\n"
1091 "Keys were not saved.")
1092 ,CClientUIInterface::MSG_ERROR);
1095 message(tr("Dump successful"),
1096 tr("Keys were saved to this file:\n%2")
1098 ,CClientUIInterface::MSG_INFORMATION);
1102 void BitcoinGUI::importWallet()
1107 WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1110 // Unlock wallet failed or was cancelled
1114 #if QT_VERSION < 0x050000
1115 QString openDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1117 QString openDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1119 QString filename = QFileDialog::getOpenFileName(this, tr("Import Wallet"), openDir, tr("Wallet dump (*.txt)"));
1120 if(!filename.isEmpty()) {
1121 if(!walletModel->importWallet(filename)) {
1122 message(tr("Import Failed"),
1123 tr("An error happened while trying to import the keys.\n"
1124 "Some or all keys from:\n %1,\n were not imported into your wallet.")
1126 ,CClientUIInterface::MSG_ERROR);
1129 message(tr("Import Successful"),
1130 tr("All keys from:\n %1,\n were imported into your wallet.")
1132 ,CClientUIInterface::MSG_INFORMATION);
1137 void BitcoinGUI::changePassphrase()
1139 AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
1140 dlg.setModel(walletModel);
1144 void BitcoinGUI::unlockWallet()
1148 // Unlock wallet when requested by wallet model
1149 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1151 AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
1152 dlg.setModel(walletModel);
1157 void BitcoinGUI::lockWallet()
1162 walletModel->setWalletLocked(true);
1165 void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden)
1167 // activateWindow() (sometimes) helps with keyboard focus on Windows
1170 // Make sure the window is not minimized
1171 setWindowState(windowState() & (~Qt::WindowMinimized | Qt::WindowActive));
1177 else if (isMinimized())
1183 else if (GUIUtil::isObscured(this))
1190 if (GUIUtil::isObscured(this))
1194 else if(fToggleHidden)
1198 void BitcoinGUI::toggleHidden()
1200 showNormalIfMinimized(true);
1203 void BitcoinGUI::error(const QString &title, const QString &message, bool modal)
1205 // Report errors from network/worker thread
1208 QMessageBox::critical(this, title, message, QMessageBox::Ok, QMessageBox::Ok);
1210 notificator->notify(Notificator::Critical, title, message);