4 * W.J. van der Laan 2011-2012
5 * The Bitcoin Developers 2011-2012
8 #include "checkpoints.h"
10 #include "bitcoingui.h"
11 #include "transactiontablemodel.h"
12 #include "addressbookpage.h"
13 #include "sendcoinsdialog.h"
14 #include "messagepage.h"
15 #include "optionsdialog.h"
16 #include "aboutdialog.h"
17 #include "clientmodel.h"
18 #include "walletmodel.h"
19 #include "editaddressdialog.h"
20 #include "optionsmodel.h"
21 #include "transactiondescdialog.h"
22 #include "addresstablemodel.h"
23 #include "transactionview.h"
24 #include "overviewpage.h"
25 #include "bitcoinunits.h"
26 #include "guiconstants.h"
27 #include "askpassphrasedialog.h"
28 #include "notificator.h"
31 #include "macdockiconhandler.h"
34 #include <QApplication>
35 #include <QMainWindow>
40 #include <QVBoxLayout>
45 #include <QPushButton>
47 #include <QMessageBox>
48 #include <QProgressBar>
49 #include <QStackedWidget>
52 #include <QFileDialog>
53 #include <QDesktopServices>
56 #include <QDragEnterEvent>
61 BitcoinGUI::BitcoinGUI(QWidget *parent):
65 encryptWalletAction(0),
66 changePassphraseAction(0),
72 setWindowTitle(tr("Bitcoin Wallet"));
74 setWindowIcon(QIcon(":icons/bitcoin"));
76 setUnifiedTitleAndToolBarOnMac(true);
77 QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
82 // Create actions for the toolbar, menu bar and tray/dock icon
85 // Create application menu bar
88 // Create the toolbars
91 // Create the tray icon (or setup the dock icon)
95 overviewPage = new OverviewPage();
97 transactionsPage = new QWidget(this);
98 QVBoxLayout *vbox = new QVBoxLayout();
99 transactionView = new TransactionView(this);
100 vbox->addWidget(transactionView);
101 transactionsPage->setLayout(vbox);
103 addressBookPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::SendingTab);
105 receiveCoinsPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::ReceivingTab);
107 sendCoinsPage = new SendCoinsDialog(this);
109 messagePage = new MessagePage(this);
111 centralWidget = new QStackedWidget(this);
112 centralWidget->addWidget(overviewPage);
113 centralWidget->addWidget(transactionsPage);
114 centralWidget->addWidget(addressBookPage);
115 centralWidget->addWidget(receiveCoinsPage);
116 centralWidget->addWidget(sendCoinsPage);
117 #ifdef FIRST_CLASS_MESSAGING
118 centralWidget->addWidget(messagePage);
120 setCentralWidget(centralWidget);
125 // Status bar notification icons
126 QFrame *frameBlocks = new QFrame();
127 frameBlocks->setContentsMargins(0,0,0,0);
128 frameBlocks->setMinimumWidth(56);
129 frameBlocks->setMaximumWidth(56);
130 QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);
131 frameBlocksLayout->setContentsMargins(3,0,3,0);
132 frameBlocksLayout->setSpacing(3);
133 labelEncryptionIcon = new QLabel();
134 labelConnectionsIcon = new QLabel();
135 labelBlocksIcon = new QLabel();
136 frameBlocksLayout->addStretch();
137 frameBlocksLayout->addWidget(labelEncryptionIcon);
138 frameBlocksLayout->addStretch();
139 frameBlocksLayout->addWidget(labelConnectionsIcon);
140 frameBlocksLayout->addStretch();
141 frameBlocksLayout->addWidget(labelBlocksIcon);
142 frameBlocksLayout->addStretch();
144 // Progress bar for blocks download
145 progressBarLabel = new QLabel(tr("Synchronizing with network..."));
146 progressBarLabel->setVisible(false);
147 progressBar = new QProgressBar();
148 progressBar->setToolTip(tr("Block chain synchronization in progress"));
149 progressBar->setVisible(false);
151 statusBar()->addWidget(progressBarLabel);
152 statusBar()->addWidget(progressBar);
153 statusBar()->addPermanentWidget(frameBlocks);
155 syncIconMovie = new QMovie(":/movies/update_spinner", "mng", this);
157 // Clicking on a transaction on the overview page simply sends you to transaction history page
158 connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), this, SLOT(gotoHistoryPage()));
160 // Doubleclicking on a transaction on the transaction history page shows details
161 connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
166 BitcoinGUI::~BitcoinGUI()
173 void BitcoinGUI::createActions()
175 QActionGroup *tabGroup = new QActionGroup(this);
177 overviewAction = new QAction(QIcon(":/icons/overview"), tr("&Overview"), this);
178 overviewAction->setToolTip(tr("Show general overview of wallet"));
179 overviewAction->setCheckable(true);
180 overviewAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_1));
181 tabGroup->addAction(overviewAction);
183 historyAction = new QAction(QIcon(":/icons/history"), tr("&Transactions"), this);
184 historyAction->setToolTip(tr("Browse transaction history"));
185 historyAction->setCheckable(true);
186 historyAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_4));
187 tabGroup->addAction(historyAction);
189 addressBookAction = new QAction(QIcon(":/icons/address-book"), tr("&Address Book"), this);
190 addressBookAction->setToolTip(tr("Edit the list of stored addresses and labels"));
191 addressBookAction->setCheckable(true);
192 addressBookAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_5));
193 tabGroup->addAction(addressBookAction);
195 receiveCoinsAction = new QAction(QIcon(":/icons/receiving_addresses"), tr("&Receive coins"), this);
196 receiveCoinsAction->setToolTip(tr("Show the list of addresses for receiving payments"));
197 receiveCoinsAction->setCheckable(true);
198 receiveCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_3));
199 tabGroup->addAction(receiveCoinsAction);
201 sendCoinsAction = new QAction(QIcon(":/icons/send"), tr("&Send coins"), this);
202 sendCoinsAction->setToolTip(tr("Send coins to a bitcoin address"));
203 sendCoinsAction->setCheckable(true);
204 sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2));
205 tabGroup->addAction(sendCoinsAction);
207 messageAction = new QAction(QIcon(":/icons/edit"), tr("Sign &message"), this);
208 messageAction->setToolTip(tr("Prove you control an address"));
209 #ifdef FIRST_CLASS_MESSAGING
210 messageAction->setCheckable(true);
212 tabGroup->addAction(messageAction);
214 connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
215 connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage()));
216 connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
217 connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage()));
218 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
219 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(gotoAddressBookPage()));
220 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
221 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
222 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
223 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
224 connect(messageAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
225 connect(messageAction, SIGNAL(triggered()), this, SLOT(gotoMessagePage()));
227 quitAction = new QAction(QIcon(":/icons/quit"), tr("E&xit"), this);
228 quitAction->setToolTip(tr("Quit application"));
229 quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
230 quitAction->setMenuRole(QAction::QuitRole);
231 aboutAction = new QAction(QIcon(":/icons/bitcoin"), tr("&About %1").arg(qApp->applicationName()), this);
232 aboutAction->setToolTip(tr("Show information about Bitcoin"));
233 aboutAction->setMenuRole(QAction::AboutRole);
234 aboutQtAction = new QAction(tr("About &Qt"), this);
235 aboutQtAction->setToolTip(tr("Show information about Qt"));
236 aboutQtAction->setMenuRole(QAction::AboutQtRole);
237 optionsAction = new QAction(QIcon(":/icons/options"), tr("&Options..."), this);
238 optionsAction->setToolTip(tr("Modify configuration options for bitcoin"));
239 optionsAction->setMenuRole(QAction::PreferencesRole);
240 openBitcoinAction = new QAction(QIcon(":/icons/bitcoin"), tr("Open &Bitcoin"), this);
241 openBitcoinAction->setToolTip(tr("Show the Bitcoin window"));
242 exportAction = new QAction(QIcon(":/icons/export"), tr("&Export..."), this);
243 exportAction->setToolTip(tr("Export the data in the current tab to a file"));
244 encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet"), this);
245 encryptWalletAction->setToolTip(tr("Encrypt or decrypt wallet"));
246 encryptWalletAction->setCheckable(true);
247 backupWalletAction = new QAction(QIcon(":/icons/filesave"), tr("&Backup Wallet"), this);
248 backupWalletAction->setToolTip(tr("Backup wallet to another location"));
249 changePassphraseAction = new QAction(QIcon(":/icons/key"), tr("&Change Passphrase"), this);
250 changePassphraseAction->setToolTip(tr("Change the passphrase used for wallet encryption"));
252 connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
253 connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked()));
254 connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked()));
255 connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
256 connect(openBitcoinAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
257 connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool)));
258 connect(backupWalletAction, SIGNAL(triggered()), this, SLOT(backupWallet()));
259 connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase()));
262 void BitcoinGUI::createMenuBar()
265 // Create a decoupled menu bar on Mac which stays even if the window is closed
266 appMenuBar = new QMenuBar();
268 // Get the main window's menu bar on other platforms
269 appMenuBar = menuBar();
272 // Configure the menus
273 QMenu *file = appMenuBar->addMenu(tr("&File"));
274 file->addAction(backupWalletAction);
275 file->addAction(exportAction);
276 #ifndef FIRST_CLASS_MESSAGING
277 file->addAction(messageAction);
279 file->addSeparator();
280 file->addAction(quitAction);
282 QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
283 settings->addAction(encryptWalletAction);
284 settings->addAction(changePassphraseAction);
285 settings->addSeparator();
286 settings->addAction(optionsAction);
288 QMenu *help = appMenuBar->addMenu(tr("&Help"));
289 help->addAction(aboutAction);
290 help->addAction(aboutQtAction);
293 void BitcoinGUI::createToolBars()
295 QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));
296 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
297 toolbar->addAction(overviewAction);
298 toolbar->addAction(sendCoinsAction);
299 toolbar->addAction(receiveCoinsAction);
300 toolbar->addAction(historyAction);
301 toolbar->addAction(addressBookAction);
302 #ifdef FIRST_CLASS_MESSAGING
303 toolbar->addAction(messageAction);
306 QToolBar *toolbar2 = addToolBar(tr("Actions toolbar"));
307 toolbar2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
308 toolbar2->addAction(exportAction);
311 void BitcoinGUI::setClientModel(ClientModel *clientModel)
313 this->clientModel = clientModel;
316 if(clientModel->isTestNet())
318 QString title_testnet = windowTitle() + QString(" ") + tr("[testnet]");
319 setWindowTitle(title_testnet);
321 setWindowIcon(QIcon(":icons/bitcoin_testnet"));
323 MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
327 trayIcon->setToolTip(title_testnet);
328 trayIcon->setIcon(QIcon(":/icons/toolbar_testnet"));
332 // Keep up to date with client
333 setNumConnections(clientModel->getNumConnections());
334 connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
336 setNumBlocks(clientModel->getNumBlocks());
337 connect(clientModel, SIGNAL(numBlocksChanged(int)), this, SLOT(setNumBlocks(int)));
339 // Report errors from network/worker thread
340 connect(clientModel, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString)));
344 void BitcoinGUI::setWalletModel(WalletModel *walletModel)
346 this->walletModel = walletModel;
349 // Report errors from wallet thread
350 connect(walletModel, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString)));
352 // Put transaction list in tabs
353 transactionView->setModel(walletModel);
355 overviewPage->setModel(walletModel);
356 addressBookPage->setModel(walletModel->getAddressTableModel());
357 receiveCoinsPage->setModel(walletModel->getAddressTableModel());
358 sendCoinsPage->setModel(walletModel);
359 messagePage->setModel(walletModel);
361 setEncryptionStatus(walletModel->getEncryptionStatus());
362 connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));
364 // Balloon popup for new transaction
365 connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
366 this, SLOT(incomingTransaction(QModelIndex,int,int)));
368 // Ask for passphrase if needed
369 connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
373 void BitcoinGUI::createTrayIcon()
377 trayIcon = new QSystemTrayIcon(this);
378 trayIconMenu = new QMenu(this);
379 trayIcon->setContextMenu(trayIconMenu);
380 trayIcon->setToolTip("Bitcoin client");
381 trayIcon->setIcon(QIcon(":/icons/toolbar"));
382 connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
383 this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
386 // Note: On Mac, the dock icon is used to provide the tray's functionality.
387 MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance();
388 connect(dockIconHandler, SIGNAL(dockIconClicked()), openBitcoinAction, SLOT(trigger()));
389 trayIconMenu = dockIconHandler->dockMenu();
392 // Configuration of the tray icon (or dock icon) icon menu
393 trayIconMenu->addAction(openBitcoinAction);
394 trayIconMenu->addSeparator();
395 trayIconMenu->addAction(messageAction);
396 #ifndef FIRST_CLASS_MESSAGING
397 trayIconMenu->addSeparator();
399 trayIconMenu->addAction(receiveCoinsAction);
400 trayIconMenu->addAction(sendCoinsAction);
401 trayIconMenu->addSeparator();
402 trayIconMenu->addAction(optionsAction);
403 #ifndef Q_WS_MAC // This is built-in on Mac
404 trayIconMenu->addSeparator();
405 trayIconMenu->addAction(quitAction);
408 notificator = new Notificator(tr("bitcoin-qt"), trayIcon);
412 void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
414 if(reason == QSystemTrayIcon::Trigger)
416 // Click on system tray icon triggers "open bitcoin"
417 openBitcoinAction->trigger();
422 void BitcoinGUI::optionsClicked()
424 if(!clientModel || !clientModel->getOptionsModel())
427 dlg.setModel(clientModel->getOptionsModel());
431 void BitcoinGUI::aboutClicked()
434 dlg.setModel(clientModel);
438 void BitcoinGUI::setNumConnections(int count)
443 case 0: icon = ":/icons/connect_0"; break;
444 case 1: case 2: case 3: icon = ":/icons/connect_1"; break;
445 case 4: case 5: case 6: icon = ":/icons/connect_2"; break;
446 case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
447 default: icon = ":/icons/connect_4"; break;
449 labelConnectionsIcon->setPixmap(QIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
450 labelConnectionsIcon->setToolTip(tr("%n active connection(s) to Bitcoin network", "", count));
453 void BitcoinGUI::setNumBlocks(int count)
457 int total = clientModel->getNumBlocksOfPeers();
462 if (clientModel->getStatusBarWarnings() == "")
464 progressBarLabel->setVisible(true);
465 progressBarLabel->setText(tr("Synchronizing with network..."));
466 progressBar->setVisible(true);
467 progressBar->setMaximum(total);
468 progressBar->setValue(count);
472 progressBarLabel->setText(clientModel->getStatusBarWarnings());
473 progressBarLabel->setVisible(true);
474 progressBar->setVisible(false);
476 tooltip = tr("Downloaded %1 of %2 blocks of transaction history.").arg(count).arg(total);
480 if (clientModel->getStatusBarWarnings() == "")
481 progressBarLabel->setVisible(false);
484 progressBarLabel->setText(clientModel->getStatusBarWarnings());
485 progressBarLabel->setVisible(true);
487 progressBar->setVisible(false);
488 tooltip = tr("Downloaded %1 blocks of transaction history.").arg(count);
491 QDateTime now = QDateTime::currentDateTime();
492 QDateTime lastBlockDate = clientModel->getLastBlockDate();
493 int secs = lastBlockDate.secsTo(now);
496 // Represent time from last generated block in human readable text
499 // Fully up to date. Leave text empty.
503 text = tr("%n second(s) ago","",secs);
505 else if(secs < 60*60)
507 text = tr("%n minute(s) ago","",secs/60);
509 else if(secs < 24*60*60)
511 text = tr("%n hour(s) ago","",secs/(60*60));
515 text = tr("%n day(s) ago","",secs/(60*60*24));
518 // Set icon state: spinning if catching up, tick otherwise
519 if(secs < 90*60 && count >= Checkpoints::GetTotalBlocksEstimate())
521 tooltip = tr("Up to date") + QString(".\n") + tooltip;
522 labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
526 tooltip = tr("Catching up...") + QString("\n") + tooltip;
527 labelBlocksIcon->setMovie(syncIconMovie);
528 syncIconMovie->start();
533 tooltip += QString("\n");
534 tooltip += tr("Last received block was generated %1.").arg(text);
537 labelBlocksIcon->setToolTip(tooltip);
538 progressBarLabel->setToolTip(tooltip);
539 progressBar->setToolTip(tooltip);
542 void BitcoinGUI::refreshStatusBar()
544 /* Might display multiple times in the case of multiple alerts
545 static QString prevStatusBar;
546 QString newStatusBar = clientModel->getStatusBarWarnings();
547 if (prevStatusBar != newStatusBar)
549 prevStatusBar = newStatusBar;
550 error(tr("Network Alert"), newStatusBar);
552 setNumBlocks(clientModel->getNumBlocks());
555 void BitcoinGUI::error(const QString &title, const QString &message, bool modal)
557 // Report errors from network/worker thread
560 QMessageBox::critical(this, title, message, QMessageBox::Ok, QMessageBox::Ok);
562 notificator->notify(Notificator::Critical, title, message);
566 void BitcoinGUI::changeEvent(QEvent *e)
568 QMainWindow::changeEvent(e);
569 #ifndef Q_WS_MAC // Ignored on Mac
570 if(e->type() == QEvent::WindowStateChange)
572 if(clientModel && clientModel->getOptionsModel()->getMinimizeToTray())
574 QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
575 if(!(wsevt->oldState() & Qt::WindowMinimized) && isMinimized())
577 QTimer::singleShot(0, this, SLOT(hide()));
585 void BitcoinGUI::closeEvent(QCloseEvent *event)
589 #ifndef Q_WS_MAC // Ignored on Mac
590 if(!clientModel->getOptionsModel()->getMinimizeToTray() &&
591 !clientModel->getOptionsModel()->getMinimizeOnClose())
597 QMainWindow::closeEvent(event);
600 void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
603 tr("This transaction is over the size limit. You can still send it for a fee of %1, "
604 "which goes to the nodes that process your transaction and helps to support the network. "
605 "Do you want to pay the fee?").arg(
606 BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nFeeRequired));
607 QMessageBox::StandardButton retval = QMessageBox::question(
608 this, tr("Sending..."), strMessage,
609 QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes);
610 *payFee = (retval == QMessageBox::Yes);
613 void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
615 if(!walletModel || !clientModel)
617 TransactionTableModel *ttm = walletModel->getTransactionTableModel();
618 qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
619 .data(Qt::EditRole).toULongLong();
620 if(!clientModel->inInitialBlockDownload())
622 // On new transaction, make an info balloon
623 // Unless the initial block download is in progress, to prevent balloon-spam
624 QString date = ttm->index(start, TransactionTableModel::Date, parent)
626 QString type = ttm->index(start, TransactionTableModel::Type, parent)
628 QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
630 QIcon icon = qvariant_cast<QIcon>(ttm->index(start,
631 TransactionTableModel::ToAddress, parent)
632 .data(Qt::DecorationRole));
634 notificator->notify(Notificator::Information,
635 (amount)<0 ? tr("Sent transaction") :
636 tr("Incoming transaction"),
642 .arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true))
644 .arg(address), icon);
648 void BitcoinGUI::gotoOverviewPage()
650 overviewAction->setChecked(true);
651 centralWidget->setCurrentWidget(overviewPage);
653 exportAction->setEnabled(false);
654 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
657 void BitcoinGUI::gotoHistoryPage()
659 historyAction->setChecked(true);
660 centralWidget->setCurrentWidget(transactionsPage);
662 exportAction->setEnabled(true);
663 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
664 connect(exportAction, SIGNAL(triggered()), transactionView, SLOT(exportClicked()));
667 void BitcoinGUI::gotoAddressBookPage()
669 addressBookAction->setChecked(true);
670 centralWidget->setCurrentWidget(addressBookPage);
672 exportAction->setEnabled(true);
673 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
674 connect(exportAction, SIGNAL(triggered()), addressBookPage, SLOT(exportClicked()));
677 void BitcoinGUI::gotoReceiveCoinsPage()
679 receiveCoinsAction->setChecked(true);
680 centralWidget->setCurrentWidget(receiveCoinsPage);
682 exportAction->setEnabled(true);
683 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
684 connect(exportAction, SIGNAL(triggered()), receiveCoinsPage, SLOT(exportClicked()));
687 void BitcoinGUI::gotoSendCoinsPage()
689 sendCoinsAction->setChecked(true);
690 centralWidget->setCurrentWidget(sendCoinsPage);
692 exportAction->setEnabled(false);
693 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
696 void BitcoinGUI::gotoMessagePage()
698 #ifdef FIRST_CLASS_MESSAGING
699 messageAction->setChecked(true);
700 centralWidget->setCurrentWidget(messagePage);
702 exportAction->setEnabled(false);
703 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
706 messagePage->setFocus();
710 void BitcoinGUI::gotoMessagePage(QString addr)
713 messagePage->setAddress(addr);
716 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
719 if(event->mimeData()->hasUrls())
720 event->acceptProposedAction();
723 void BitcoinGUI::dropEvent(QDropEvent *event)
725 if(event->mimeData()->hasUrls())
728 QList<QUrl> uris = event->mimeData()->urls();
729 foreach(const QUrl &uri, uris)
731 sendCoinsPage->handleURI(uri.toString());
735 event->acceptProposedAction();
738 void BitcoinGUI::handleURI(QString strURI)
741 sendCoinsPage->handleURI(strURI);
743 if(!isActiveWindow())
746 showNormalIfMinimized();
749 void BitcoinGUI::setEncryptionStatus(int status)
753 case WalletModel::Unencrypted:
754 labelEncryptionIcon->hide();
755 encryptWalletAction->setChecked(false);
756 changePassphraseAction->setEnabled(false);
757 encryptWalletAction->setEnabled(true);
759 case WalletModel::Unlocked:
760 labelEncryptionIcon->show();
761 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
762 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
763 encryptWalletAction->setChecked(true);
764 changePassphraseAction->setEnabled(true);
765 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
767 case WalletModel::Locked:
768 labelEncryptionIcon->show();
769 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
770 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
771 encryptWalletAction->setChecked(true);
772 changePassphraseAction->setEnabled(true);
773 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
778 void BitcoinGUI::encryptWallet(bool status)
782 AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt:
783 AskPassphraseDialog::Decrypt, this);
784 dlg.setModel(walletModel);
787 setEncryptionStatus(walletModel->getEncryptionStatus());
790 void BitcoinGUI::backupWallet()
792 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
793 QString filename = QFileDialog::getSaveFileName(this, tr("Backup Wallet"), saveDir, tr("Wallet Data (*.dat)"));
794 if(!filename.isEmpty()) {
795 if(!walletModel->backupWallet(filename)) {
796 QMessageBox::warning(this, tr("Backup Failed"), tr("There was an error trying to save the wallet data to the new location."));
801 void BitcoinGUI::changePassphrase()
803 AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
804 dlg.setModel(walletModel);
808 void BitcoinGUI::unlockWallet()
812 // Unlock wallet when requested by wallet model
813 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
815 AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
816 dlg.setModel(walletModel);
821 void BitcoinGUI::showNormalIfMinimized()
823 if(!isVisible()) // Show, if hidden
825 if(isMinimized()) // Unminimize, if minimized