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()));
207 connect(openRPCConsoleAction, SIGNAL(triggered()), rpcConsole, SLOT(raise()));
209 aboutDialog = new AboutDialog(0);
210 optionsDialog = new OptionsDialog(0);
212 // Clicking on "Verify Message" in the address book sends you to the verify message tab
213 connect(addressBookPage, SIGNAL(verifyMessage(QString)), this, SLOT(gotoVerifyMessageTab(QString)));
214 // Clicking on "Sign Message" in the receive coins page sends you to the sign message tab
215 connect(receiveCoinsPage, SIGNAL(signMessage(QString)), this, SLOT(gotoSignMessageTab(QString)));
220 BitcoinGUI::~BitcoinGUI()
222 if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu)
230 delete optionsDialog;
232 delete signVerifyMessageDialog;
235 void BitcoinGUI::createActions()
237 QActionGroup *tabGroup = new QActionGroup(this);
239 overviewAction = new QAction(QIcon(":/icons/overview"), tr("&Overview"), this);
240 overviewAction->setToolTip(tr("Show general overview of wallet"));
241 overviewAction->setCheckable(true);
242 overviewAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_1));
243 tabGroup->addAction(overviewAction);
245 sendCoinsAction = new QAction(QIcon(":/icons/send"), tr("&Send coins"), this);
246 sendCoinsAction->setToolTip(tr("Send coins to a NovaCoin address"));
247 sendCoinsAction->setCheckable(true);
248 sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2));
249 tabGroup->addAction(sendCoinsAction);
251 receiveCoinsAction = new QAction(QIcon(":/icons/receiving_addresses"), tr("&Receive coins"), this);
252 receiveCoinsAction->setToolTip(tr("Show the list of addresses for receiving payments"));
253 receiveCoinsAction->setCheckable(true);
254 receiveCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_3));
255 tabGroup->addAction(receiveCoinsAction);
257 historyAction = new QAction(QIcon(":/icons/history"), tr("&Transactions"), this);
258 historyAction->setToolTip(tr("Browse transaction history"));
259 historyAction->setCheckable(true);
260 historyAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_4));
261 tabGroup->addAction(historyAction);
263 mintingAction = new QAction(QIcon(":/icons/history"), tr("&Minting"), this);
264 mintingAction->setToolTip(tr("Show your minting capacity"));
265 mintingAction->setCheckable(true);
266 mintingAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_5));
267 tabGroup->addAction(mintingAction);
269 addressBookAction = new QAction(QIcon(":/icons/address-book"), tr("&Address Book"), this);
270 addressBookAction->setToolTip(tr("Edit the list of stored addresses and labels"));
271 addressBookAction->setCheckable(true);
272 addressBookAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_6));
273 tabGroup->addAction(addressBookAction);
275 multisigAction = new QAction(QIcon(":/icons/send"), tr("Multisig"), this);
276 multisigAction->setStatusTip(tr("Open window for working with multisig addresses"));
277 tabGroup->addAction(multisigAction);
279 connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
280 connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage()));
281 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
282 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
283 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
284 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
285 connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
286 connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage()));
287 connect(mintingAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
288 connect(mintingAction, SIGNAL(triggered()), this, SLOT(gotoMintingPage()));
289 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
290 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(gotoAddressBookPage()));
291 connect(multisigAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
292 connect(multisigAction, SIGNAL(triggered()), this, SLOT(gotoMultisigPage()));
294 quitAction = new QAction(QIcon(":/icons/quit"), tr("E&xit"), this);
295 quitAction->setStatusTip(tr("Quit application"));
296 quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
297 quitAction->setMenuRole(QAction::QuitRole);
298 aboutAction = new QAction(QIcon(":/icons/bitcoin"), tr("&About NovaCoin"), this);
299 aboutAction->setStatusTip(tr("Show information about NovaCoin"));
300 aboutAction->setMenuRole(QAction::AboutRole);
301 #if QT_VERSION < 0x050000
302 aboutQtAction = new QAction(QIcon(":/trolltech/qmessagebox/images/qtlogo-64.png"), tr("About &Qt"), this);
304 aboutQtAction = new QAction(QIcon(":/qt-project.org/qmessagebox/images/qtlogo-64.png"), tr("About &Qt"), this);
306 aboutQtAction->setStatusTip(tr("Show information about Qt"));
307 aboutQtAction->setMenuRole(QAction::AboutQtRole);
308 optionsAction = new QAction(QIcon(":/icons/options"), tr("&Options..."), this);
309 optionsAction->setStatusTip(tr("Modify configuration options for NovaCoin"));
310 optionsAction->setMenuRole(QAction::PreferencesRole);
311 toggleHideAction = new QAction(QIcon(":/icons/bitcoin"), tr("&Show / Hide"), this);
312 encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet..."), this);
313 encryptWalletAction->setStatusTip(tr("Encrypt or decrypt wallet"));
314 encryptWalletAction->setCheckable(true);
315 backupWalletAction = new QAction(QIcon(":/icons/filesave"), tr("&Backup Wallet..."), this);
316 backupWalletAction->setStatusTip(tr("Backup wallet to another location"));
317 dumpWalletAction = new QAction(QIcon(":/icons/dump"), tr("&Dump Wallet..."), this);
318 dumpWalletAction->setStatusTip(tr("Dump keys to a text file"));
319 importWalletAction = new QAction(QIcon(":/icons/import"), tr("&Import Wallet..."), this);
320 importWalletAction->setStatusTip(tr("Import keys into a wallet"));
321 changePassphraseAction = new QAction(QIcon(":/icons/key"), tr("&Change Passphrase..."), this);
322 changePassphraseAction->setStatusTip(tr("Change the passphrase used for wallet encryption"));
323 signMessageAction = new QAction(QIcon(":/icons/edit"), tr("Sign &message..."), this);
324 signMessageAction->setStatusTip(tr("Sign messages with your Novacoin addresses to prove you own them"));
325 verifyMessageAction = new QAction(QIcon(":/icons/transaction_0"), tr("&Verify message..."), this);
326 verifyMessageAction->setStatusTip(tr("Verify messages to ensure they were signed with specified Novacoin addresses"));
328 lockWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Lock wallet"), this);
329 lockWalletAction->setStatusTip(tr("Lock wallet"));
330 lockWalletAction->setCheckable(true);
332 unlockWalletAction = new QAction(QIcon(":/icons/lock_open"), tr("Unlo&ck wallet"), this);
333 unlockWalletAction->setStatusTip(tr("Unlock wallet"));
334 unlockWalletAction->setCheckable(true);
336 unlockWalletMiningAction = new QAction(QIcon(":/icons/mining_active"), tr("Unlo&ck wallet for mining"), this);
337 unlockWalletMiningAction->setStatusTip(tr("Unlock wallet for mining"));
338 unlockWalletMiningAction->setCheckable(true);
340 exportAction = new QAction(QIcon(":/icons/export"), tr("&Export..."), this);
341 exportAction->setStatusTip(tr("Export the data in the current tab to a file"));
342 openRPCConsoleAction = new QAction(QIcon(":/icons/debugwindow"), tr("&Debug window"), this);
343 openRPCConsoleAction->setStatusTip(tr("Open debugging and diagnostic console"));
345 connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
346 connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked()));
347 connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
348 connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked()));
349 connect(toggleHideAction, SIGNAL(triggered()), this, SLOT(toggleHidden()));
350 connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool)));
351 connect(lockWalletAction, SIGNAL(triggered(bool)), this, SLOT(lockWallet()));
352 connect(unlockWalletAction, SIGNAL(triggered(bool)), this, SLOT(unlockWallet()));
353 connect(unlockWalletMiningAction, SIGNAL(triggered(bool)), this, SLOT(unlockWalletMining(bool)));
354 connect(backupWalletAction, SIGNAL(triggered()), this, SLOT(backupWallet()));
355 connect(dumpWalletAction, SIGNAL(triggered()), this, SLOT(dumpWallet()));
356 connect(importWalletAction, SIGNAL(triggered()), this, SLOT(importWallet()));
357 connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase()));
358 connect(signMessageAction, SIGNAL(triggered()), this, SLOT(gotoSignMessageTab()));
359 connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(gotoVerifyMessageTab()));
362 void BitcoinGUI::createMenuBar()
365 // Create a decoupled menu bar on Mac which stays even if the window is closed
366 appMenuBar = new QMenuBar();
368 // Get the main window's menu bar on other platforms
369 appMenuBar = menuBar();
372 // Configure the menus
373 QMenu *file = appMenuBar->addMenu(tr("&File"));
374 file->addAction(backupWalletAction);
375 file->addSeparator();
376 file->addAction(dumpWalletAction);
377 file->addAction(importWalletAction);
378 file->addAction(exportAction);
379 file->addAction(signMessageAction);
380 file->addAction(verifyMessageAction);
381 file->addAction(multisigAction);
382 file->addSeparator();
383 file->addAction(quitAction);
385 QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
386 QMenu *securityMenu = settings->addMenu(QIcon(":/icons/key"), tr("&Wallet security"));
387 securityMenu->addAction(encryptWalletAction);
388 securityMenu->addAction(changePassphraseAction);
389 securityMenu->addAction(unlockWalletAction);
390 securityMenu->addAction(unlockWalletMiningAction);
391 securityMenu->addAction(lockWalletAction);
392 settings->addAction(optionsAction);
394 QMenu *help = appMenuBar->addMenu(tr("&Help"));
395 help->addAction(openRPCConsoleAction);
396 help->addSeparator();
397 help->addAction(aboutAction);
398 help->addAction(aboutQtAction);
401 void BitcoinGUI::createToolBars()
403 QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));
404 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
405 toolbar->addAction(overviewAction);
406 toolbar->addAction(sendCoinsAction);
407 toolbar->addAction(receiveCoinsAction);
408 toolbar->addAction(historyAction);
409 toolbar->addAction(mintingAction);
410 toolbar->addAction(addressBookAction);
412 QToolBar *toolbar2 = addToolBar(tr("Actions toolbar"));
413 toolbar2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
414 toolbar2->addAction(exportAction);
415 toolbar2->setVisible(false);
419 void BitcoinGUI::setClientModel(ClientModel *clientModel)
421 this->clientModel = clientModel;
424 // Replace some strings and icons, when using the testnet
425 if(clientModel->isTestNet())
427 setWindowTitle(windowTitle() + QString(" ") + tr("[testnet]"));
429 qApp->setWindowIcon(QIcon(":icons/bitcoin_testnet"));
430 setWindowIcon(QIcon(":icons/bitcoin_testnet"));
432 MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
436 trayIcon->setToolTip(tr("NovaCoin client") + QString(" ") + tr("[testnet]"));
437 trayIcon->setIcon(QIcon(":/icons/toolbar_testnet"));
438 toggleHideAction->setIcon(QIcon(":/icons/toolbar_testnet"));
441 aboutAction->setIcon(QIcon(":/icons/toolbar_testnet"));
444 // Keep up to date with client
445 setNumConnections(clientModel->getNumConnections());
446 connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
448 setNumBlocks(clientModel->getNumBlocks(), clientModel->getNumBlocksOfPeers());
449 connect(clientModel, SIGNAL(numBlocksChanged(int,int)), this, SLOT(setNumBlocks(int,int)));
451 QTimer *timer = new QTimer(this);
452 connect(timer, SIGNAL(timeout()), this, SLOT(updateMining()));
453 timer->start(10*1000); //10 seconds
455 // Report errors from network/worker thread
456 connect(clientModel, SIGNAL(error(QString,QString,bool)), this, SLOT(error(QString,QString,bool)));
458 rpcConsole->setClientModel(clientModel);
459 addressBookPage->setOptionsModel(clientModel->getOptionsModel());
460 receiveCoinsPage->setOptionsModel(clientModel->getOptionsModel());
464 void BitcoinGUI::setWalletModel(WalletModel *walletModel)
466 this->walletModel = walletModel;
469 // Report errors from wallet thread
470 connect(walletModel, SIGNAL(error(QString,QString,bool)), this, SLOT(error(QString,QString,bool)));
472 // Put transaction list in tabs
473 transactionView->setModel(walletModel);
474 mintingView->setModel(walletModel);
476 overviewPage->setModel(walletModel);
477 addressBookPage->setModel(walletModel->getAddressTableModel());
478 receiveCoinsPage->setModel(walletModel->getAddressTableModel());
479 sendCoinsPage->setModel(walletModel);
480 signVerifyMessageDialog->setModel(walletModel);
481 multisigPage->setModel(walletModel);
483 setEncryptionStatus(walletModel->getEncryptionStatus());
484 connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));
485 connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(updateMining()));
487 // Balloon pop-up for new transaction
488 connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
489 this, SLOT(incomingTransaction(QModelIndex,int,int)));
491 // Ask for passphrase if needed
492 connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
496 void BitcoinGUI::createTrayIcon()
500 trayIcon = new QSystemTrayIcon(this);
501 trayIconMenu = new QMenu(this);
502 trayIcon->setContextMenu(trayIconMenu);
503 trayIcon->setToolTip(tr("NovaCoin client"));
504 trayIcon->setIcon(QIcon(":/icons/toolbar"));
505 connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
506 this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
509 // Note: On Mac, the dock icon is used to provide the tray's functionality.
510 MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance();
511 dockIconHandler->setMainWindow((QMainWindow *)this);
512 trayIconMenu = dockIconHandler->dockMenu();
515 // Configuration of the tray icon (or dock icon) icon menu
516 trayIconMenu->addAction(toggleHideAction);
517 trayIconMenu->addSeparator();
518 trayIconMenu->addAction(sendCoinsAction);
519 trayIconMenu->addAction(multisigAction);
520 trayIconMenu->addAction(receiveCoinsAction);
521 trayIconMenu->addSeparator();
522 trayIconMenu->addAction(signMessageAction);
523 trayIconMenu->addAction(verifyMessageAction);
524 trayIconMenu->addSeparator();
525 trayIconMenu->addAction(optionsAction);
526 trayIconMenu->addAction(openRPCConsoleAction);
528 // This is built-in on Mac
529 trayIconMenu->addSeparator();
530 trayIconMenu->addAction(quitAction);
532 notificator = new Notificator(QApplication::applicationName(), trayIcon, this);
536 void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
538 if(reason == QSystemTrayIcon::Trigger)
540 // Click on system tray icon triggers show/hide of the main window
541 toggleHideAction->trigger();
546 void BitcoinGUI::optionsClicked()
548 if(!clientModel || !clientModel->getOptionsModel())
551 optionsDialog->setModel(clientModel->getOptionsModel());
552 optionsDialog->setWindowModality(Qt::ApplicationModal);
553 optionsDialog->show();
556 void BitcoinGUI::aboutClicked()
558 aboutDialog->setModel(clientModel);
559 aboutDialog->setWindowModality(Qt::ApplicationModal);
563 void BitcoinGUI::setNumConnections(int count)
568 case 0: icon = ":/icons/connect_0"; break;
569 case 1: case 2: case 3: icon = ":/icons/connect_1"; break;
570 case 4: case 5: case 6: icon = ":/icons/connect_2"; break;
571 case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
572 default: icon = ":/icons/connect_4"; break;
574 labelConnectionsIcon->setPixmap(QIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
575 labelConnectionsIcon->setToolTip(tr("%n active connection(s) to NovaCoin network", "", count));
578 void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks)
580 // don't show / hide progress bar and its label if we have no connection to the network
581 if (!clientModel || clientModel->getNumConnections() == 0)
583 progressBarLabel->setVisible(false);
584 progressBar->setVisible(false);
589 QString strStatusBarWarnings = clientModel->getStatusBarWarnings();
592 if(count < nTotalBlocks)
594 int nRemainingBlocks = nTotalBlocks - count;
595 float nPercentageDone = count / (nTotalBlocks * 0.01f);
597 if (strStatusBarWarnings.isEmpty())
599 progressBarLabel->setText(tr("Synchronizing with network..."));
600 progressBarLabel->setVisible(true);
601 progressBar->setFormat(tr("~%n block(s) remaining", "", nRemainingBlocks));
602 progressBar->setMaximum(nTotalBlocks);
603 progressBar->setValue(count);
604 progressBar->setVisible(true);
607 tooltip = tr("Downloaded %1 of %2 blocks of transaction history (%3% done).").arg(count).arg(nTotalBlocks).arg(nPercentageDone, 0, 'f', 2);
611 if (strStatusBarWarnings.isEmpty())
612 progressBarLabel->setVisible(false);
614 progressBar->setVisible(false);
615 tooltip = tr("Downloaded %1 blocks of transaction history.").arg(count);
618 // Override progressBarLabel text and hide progress bar, when we have warnings to display
619 if (!strStatusBarWarnings.isEmpty())
621 progressBarLabel->setText(strStatusBarWarnings);
622 progressBarLabel->setVisible(true);
623 progressBar->setVisible(false);
626 tooltip = tr("Current PoW difficulty is %1.").arg(clientModel->getDifficulty(false)) + QString("<br>") + tooltip;
627 tooltip = tr("Current PoS difficulty is %1.").arg(clientModel->getDifficulty(true)) + QString("<br>") + tooltip;
629 QDateTime lastBlockDate = clientModel->getLastBlockDate();
630 int secs = lastBlockDate.secsTo(QDateTime::currentDateTime());
633 // Represent time from last generated block in human readable text
636 // Fully up to date. Leave text empty.
640 text = tr("%n second(s) ago","",secs);
642 else if(secs < 60*60)
644 text = tr("%n minute(s) ago","",secs/60);
646 else if(secs < 24*60*60)
648 text = tr("%n hour(s) ago","",secs/(60*60));
652 text = tr("%n day(s) ago","",secs/(60*60*24));
655 // Set icon state: spinning if catching up, tick otherwise
656 if(secs < 90*60 && count >= nTotalBlocks)
658 tooltip = tr("Up to date") + QString(".<br>") + tooltip;
659 labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
661 overviewPage->showOutOfSyncWarning(false);
665 tooltip = tr("Catching up...") + QString("<br>") + tooltip;
666 labelBlocksIcon->setMovie(syncIconMovie);
667 syncIconMovie->start();
669 overviewPage->showOutOfSyncWarning(true);
674 tooltip += QString("<br>");
675 tooltip += tr("Last received block was generated %1.").arg(text);
678 // Don't word-wrap this (fixed-width) tooltip
679 tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
681 labelBlocksIcon->setToolTip(tooltip);
682 progressBarLabel->setToolTip(tooltip);
683 progressBar->setToolTip(tooltip);
686 void BitcoinGUI::updateMining()
691 labelMiningIcon->setPixmap(QIcon(":/icons/mining_inactive").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
693 if (!clientModel->getNumConnections())
695 labelMiningIcon->setToolTip(tr("Wallet is offline"));
699 if (walletModel->getEncryptionStatus() == WalletModel::Locked)
701 labelMiningIcon->setToolTip(tr("Wallet is locked"));
705 if (clientModel->inInitialBlockDownload() || clientModel->getNumBlocksOfPeers() > clientModel->getNumBlocks())
707 labelMiningIcon->setToolTip(tr("Blockchain download is in progress"));
711 if (nStakeInputsMapSize > 0)
713 labelMiningIcon->setPixmap(QIcon(":/icons/mining_active").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
715 uint64_t nNetworkWeight = clientModel->getPoSKernelPS();
717 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>"));
720 labelMiningIcon->setToolTip(tr("No suitable inputs were found"));
723 void BitcoinGUI::message(const QString &title, const QString &message, unsigned int style, const QString &detail)
725 QString strTitle = tr("NovaCoin") + " - ";
726 // Default to information icon
727 int nMBoxIcon = QMessageBox::Information;
728 int nNotifyIcon = Notificator::Information;
731 // Check for usage of predefined title
733 case CClientUIInterface::MSG_ERROR:
734 strTitle += tr("Error");
736 case CClientUIInterface::MSG_WARNING:
737 strTitle += tr("Warning");
739 case CClientUIInterface::MSG_INFORMATION:
740 strTitle += tr("Information");
743 strTitle += title; // Use supplied title
746 // Check for error/warning icon
747 if (style & CClientUIInterface::ICON_ERROR) {
748 nMBoxIcon = QMessageBox::Critical;
749 nNotifyIcon = Notificator::Critical;
751 else if (style & CClientUIInterface::ICON_WARNING) {
752 nMBoxIcon = QMessageBox::Warning;
753 nNotifyIcon = Notificator::Warning;
757 if (style & CClientUIInterface::MODAL) {
758 // Check for buttons, use OK as default, if none was supplied
759 QMessageBox::StandardButton buttons;
760 buttons = QMessageBox::Ok;
762 QMessageBox mBox((QMessageBox::Icon)nMBoxIcon, strTitle, message, buttons);
764 if(!detail.isEmpty()) { mBox.setDetailedText(detail); }
769 notificator->notify((Notificator::Class)nNotifyIcon, strTitle, message);
773 void BitcoinGUI::changeEvent(QEvent *e)
775 QMainWindow::changeEvent(e);
776 #ifndef Q_OS_MAC // Ignored on Mac
777 if(e->type() == QEvent::WindowStateChange)
779 if(clientModel && clientModel->getOptionsModel()->getMinimizeToTray())
781 QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
782 if(!(wsevt->oldState() & Qt::WindowMinimized) && isMinimized())
784 QTimer::singleShot(0, this, SLOT(hide()));
792 void BitcoinGUI::closeEvent(QCloseEvent *event)
796 #ifndef Q_OS_MAC // Ignored on Mac
797 if(!clientModel->getOptionsModel()->getMinimizeOnClose())
803 // close rpcConsole in case it was open to make some space for the shutdown window
806 QMainWindow::closeEvent(event);
809 void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
812 tr("This transaction is over the size limit. You can still send it for a fee of %1, "
813 "which goes to the nodes that process your transaction and helps to support the network. "
814 "Do you want to pay the fee?").arg(
815 BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nFeeRequired));
816 QMessageBox::StandardButton retval = QMessageBox::question(
817 this, tr("Confirm transaction fee"), strMessage,
818 QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes);
819 *payFee = (retval == QMessageBox::Yes);
822 void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
824 if(!walletModel || !clientModel)
826 TransactionTableModel *ttm = walletModel->getTransactionTableModel();
827 qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
828 .data(Qt::EditRole).toULongLong();
829 if(!clientModel->inInitialBlockDownload())
831 // On new transaction, make an info balloon
832 // Unless the initial block download is in progress, to prevent balloon-spam
833 QString date = ttm->index(start, TransactionTableModel::Date, parent)
835 QString type = ttm->index(start, TransactionTableModel::Type, parent)
837 QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
839 QIcon icon = qvariant_cast<QIcon>(ttm->index(start,
840 TransactionTableModel::ToAddress, parent)
841 .data(Qt::DecorationRole));
843 notificator->notify(Notificator::Information,
844 (amount)<0 ? tr("Sent transaction") :
845 tr("Incoming transaction"),
851 .arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true))
853 .arg(address), icon);
857 void BitcoinGUI::gotoOverviewPage()
859 overviewAction->setChecked(true);
860 centralWidget->setCurrentWidget(overviewPage);
862 exportAction->setEnabled(false);
863 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
866 void BitcoinGUI::gotoHistoryPage()
868 historyAction->setChecked(true);
869 centralWidget->setCurrentWidget(transactionsPage);
871 exportAction->setEnabled(true);
872 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
873 connect(exportAction, SIGNAL(triggered()), transactionView, SLOT(exportClicked()));
876 void BitcoinGUI::gotoMintingPage()
878 mintingAction->setChecked(true);
879 centralWidget->setCurrentWidget(mintingPage);
881 exportAction->setEnabled(true);
882 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
883 connect(exportAction, SIGNAL(triggered()), mintingView, SLOT(exportClicked()));
887 void BitcoinGUI::gotoAddressBookPage()
889 addressBookAction->setChecked(true);
890 centralWidget->setCurrentWidget(addressBookPage);
892 exportAction->setEnabled(true);
893 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
894 connect(exportAction, SIGNAL(triggered()), addressBookPage, SLOT(exportClicked()));
897 void BitcoinGUI::gotoReceiveCoinsPage()
899 receiveCoinsAction->setChecked(true);
900 centralWidget->setCurrentWidget(receiveCoinsPage);
902 exportAction->setEnabled(true);
903 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
904 connect(exportAction, SIGNAL(triggered()), receiveCoinsPage, SLOT(exportClicked()));
907 void BitcoinGUI::gotoSendCoinsPage()
909 sendCoinsAction->setChecked(true);
910 centralWidget->setCurrentWidget(sendCoinsPage);
912 exportAction->setEnabled(false);
913 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
916 void BitcoinGUI::gotoSignMessageTab(QString addr)
918 // call show() in showTab_SM()
919 signVerifyMessageDialog->showTab_SM(true);
922 signVerifyMessageDialog->setAddress_SM(addr);
925 void BitcoinGUI::gotoVerifyMessageTab(QString addr)
927 // call show() in showTab_VM()
928 signVerifyMessageDialog->showTab_VM(true);
931 signVerifyMessageDialog->setAddress_VM(addr);
934 void BitcoinGUI::gotoMultisigPage()
936 multisigPage->show();
937 multisigPage->raise();
938 multisigPage->activateWindow();
941 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
944 if(event->mimeData()->hasUrls())
945 event->acceptProposedAction();
948 void BitcoinGUI::dropEvent(QDropEvent *event)
950 if(event->mimeData()->hasUrls())
952 int nValidUrisFound = 0;
953 QList<QUrl> uris = event->mimeData()->urls();
954 foreach(const QUrl &uri, uris)
956 if (sendCoinsPage->handleURI(uri.toString()))
960 // if valid URIs were found
964 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."));
967 event->acceptProposedAction();
970 void BitcoinGUI::handleURI(QString strURI)
972 // URI has to be valid
973 if (sendCoinsPage->handleURI(strURI))
975 showNormalIfMinimized();
979 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."));
982 void BitcoinGUI::setEncryptionStatus(int status)
986 case WalletModel::Unencrypted:
987 labelEncryptionIcon->hide();
988 encryptWalletAction->setChecked(false);
989 changePassphraseAction->setEnabled(false);
990 lockWalletAction->setEnabled(false);
991 unlockWalletAction->setEnabled(false);
992 unlockWalletMiningAction->setEnabled(false);
993 encryptWalletAction->setEnabled(true);
995 case WalletModel::Unlocked:
996 labelEncryptionIcon->show();
997 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
998 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
999 encryptWalletAction->setChecked(true);
1000 changePassphraseAction->setEnabled(true);
1001 encryptWalletAction->setEnabled(true);
1003 lockWalletAction->setEnabled(true);
1004 lockWalletAction->setChecked(false);
1005 unlockWalletAction->setEnabled(false);
1006 unlockWalletMiningAction->setEnabled(false);
1008 if (fWalletUnlockMintOnly)
1009 unlockWalletMiningAction->setChecked(true);
1011 unlockWalletAction->setChecked(true);
1014 case WalletModel::Locked:
1015 labelEncryptionIcon->show();
1016 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
1017 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
1018 encryptWalletAction->setChecked(true);
1019 changePassphraseAction->setEnabled(true);
1020 encryptWalletAction->setEnabled(true);
1022 lockWalletAction->setChecked(true);
1023 unlockWalletAction->setChecked(false);
1024 unlockWalletMiningAction->setChecked(false);
1026 lockWalletAction->setEnabled(false);
1027 unlockWalletAction->setEnabled(true);
1028 unlockWalletMiningAction->setEnabled(true);
1033 void BitcoinGUI::encryptWallet(bool status)
1037 AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt:
1038 AskPassphraseDialog::Decrypt, this);
1039 dlg.setModel(walletModel);
1042 setEncryptionStatus(walletModel->getEncryptionStatus());
1045 void BitcoinGUI::unlockWalletMining(bool status)
1050 // Unlock wallet when requested by wallet model
1051 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1053 AskPassphraseDialog dlg(AskPassphraseDialog::UnlockMining, this);
1054 dlg.setModel(walletModel);
1059 void BitcoinGUI::backupWallet()
1061 #if QT_VERSION < 0x050000
1062 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1064 QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1066 QString filename = QFileDialog::getSaveFileName(this, tr("Backup Wallet"), saveDir, tr("Wallet Data (*.dat)"));
1067 if(!filename.isEmpty()) {
1068 if(!walletModel->backupWallet(filename)) {
1069 QMessageBox::warning(this, tr("Backup Failed"), tr("There was an error trying to save the wallet data to the new location."));
1074 void BitcoinGUI::dumpWallet()
1079 WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1082 // Unlock wallet failed or was cancelled
1086 #if QT_VERSION < 0x050000
1087 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1089 QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1091 QString filename = QFileDialog::getSaveFileName(this, tr("Dump Wallet"), saveDir, tr("Wallet dump (*.txt)"));
1092 if(!filename.isEmpty()) {
1093 if(!walletModel->dumpWallet(filename)) {
1094 message(tr("Dump failed"),
1095 tr("An error happened while trying to save the keys to your location.\n"
1096 "Keys were not saved.")
1097 ,CClientUIInterface::MSG_ERROR);
1100 message(tr("Dump successful"),
1101 tr("Keys were saved to this file:\n%2")
1103 ,CClientUIInterface::MSG_INFORMATION);
1107 void BitcoinGUI::importWallet()
1112 WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1115 // Unlock wallet failed or was cancelled
1119 #if QT_VERSION < 0x050000
1120 QString openDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1122 QString openDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1124 QString filename = QFileDialog::getOpenFileName(this, tr("Import Wallet"), openDir, tr("Wallet dump (*.txt)"));
1125 if(!filename.isEmpty()) {
1126 if(!walletModel->importWallet(filename)) {
1127 message(tr("Import Failed"),
1128 tr("An error happened while trying to import the keys.\n"
1129 "Some or all keys from:\n %1,\n were not imported into your wallet.")
1131 ,CClientUIInterface::MSG_ERROR);
1134 message(tr("Import Successful"),
1135 tr("All keys from:\n %1,\n were imported into your wallet.")
1137 ,CClientUIInterface::MSG_INFORMATION);
1142 void BitcoinGUI::changePassphrase()
1144 AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
1145 dlg.setModel(walletModel);
1149 void BitcoinGUI::unlockWallet()
1153 // Unlock wallet when requested by wallet model
1154 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1156 AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
1157 dlg.setModel(walletModel);
1162 void BitcoinGUI::lockWallet()
1167 walletModel->setWalletLocked(true);
1170 void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden)
1172 // activateWindow() (sometimes) helps with keyboard focus on Windows
1175 // Make sure the window is not minimized
1176 setWindowState(windowState() & (~Qt::WindowMinimized | Qt::WindowActive));
1182 else if (isMinimized())
1188 else if (GUIUtil::isObscured(this))
1195 if (GUIUtil::isObscured(this))
1199 else if(fToggleHidden)
1203 void BitcoinGUI::toggleHidden()
1205 showNormalIfMinimized(true);
1208 void BitcoinGUI::error(const QString &title, const QString &message, bool modal)
1210 // Report errors from network/worker thread
1213 QMessageBox::critical(this, title, message, QMessageBox::Ok, QMessageBox::Ok);
1215 notificator->notify(Notificator::Critical, title, message);