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 "messagepage.h"
12 #include "optionsdialog.h"
13 #include "aboutdialog.h"
14 #include "clientmodel.h"
15 #include "walletmodel.h"
16 #include "editaddressdialog.h"
17 #include "optionsmodel.h"
18 #include "transactiondescdialog.h"
19 #include "addresstablemodel.h"
20 #include "transactionview.h"
21 #include "overviewpage.h"
22 #include "bitcoinunits.h"
23 #include "guiconstants.h"
24 #include "askpassphrasedialog.h"
25 #include "notificator.h"
29 #include "macdockiconhandler.h"
32 #include <QApplication>
33 #include <QMainWindow>
38 #include <QVBoxLayout>
43 #include <QPushButton>
45 #include <QMessageBox>
46 #include <QProgressBar>
47 #include <QStackedWidget>
50 #include <QFileDialog>
51 #include <QDesktopServices>
54 #include <QDragEnterEvent>
59 BitcoinGUI::BitcoinGUI(QWidget *parent):
63 encryptWalletAction(0),
64 changePassphraseAction(0),
70 setWindowTitle(tr("Bitcoin Wallet"));
72 setWindowIcon(QIcon(":icons/bitcoin"));
74 setUnifiedTitleAndToolBarOnMac(true);
75 QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
80 // Create actions for the toolbar, menu bar and tray/dock icon
83 // Create application menu bar
86 // Create the toolbars
89 // Create the tray icon (or setup the dock icon)
93 overviewPage = new OverviewPage();
95 transactionsPage = new QWidget(this);
96 QVBoxLayout *vbox = new QVBoxLayout();
97 transactionView = new TransactionView(this);
98 vbox->addWidget(transactionView);
99 transactionsPage->setLayout(vbox);
101 addressBookPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::SendingTab);
103 receiveCoinsPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::ReceivingTab);
105 sendCoinsPage = new SendCoinsDialog(this);
107 messagePage = new MessagePage(this);
109 centralWidget = new QStackedWidget(this);
110 centralWidget->addWidget(overviewPage);
111 centralWidget->addWidget(transactionsPage);
112 centralWidget->addWidget(addressBookPage);
113 centralWidget->addWidget(receiveCoinsPage);
114 centralWidget->addWidget(sendCoinsPage);
115 #ifdef FIRST_CLASS_MESSAGING
116 centralWidget->addWidget(messagePage);
118 setCentralWidget(centralWidget);
123 // Status bar notification icons
124 QFrame *frameBlocks = new QFrame();
125 frameBlocks->setContentsMargins(0,0,0,0);
126 frameBlocks->setMinimumWidth(56);
127 frameBlocks->setMaximumWidth(56);
128 QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);
129 frameBlocksLayout->setContentsMargins(3,0,3,0);
130 frameBlocksLayout->setSpacing(3);
131 labelEncryptionIcon = new QLabel();
132 labelConnectionsIcon = new QLabel();
133 labelBlocksIcon = new QLabel();
134 frameBlocksLayout->addStretch();
135 frameBlocksLayout->addWidget(labelEncryptionIcon);
136 frameBlocksLayout->addStretch();
137 frameBlocksLayout->addWidget(labelConnectionsIcon);
138 frameBlocksLayout->addStretch();
139 frameBlocksLayout->addWidget(labelBlocksIcon);
140 frameBlocksLayout->addStretch();
142 // Progress bar and label for blocks download
143 progressBarLabel = new QLabel();
144 progressBarLabel->setVisible(false);
145 progressBar = new QProgressBar();
146 progressBar->setAlignment(Qt::AlignCenter);
147 progressBar->setVisible(false);
149 statusBar()->addWidget(progressBarLabel);
150 statusBar()->addWidget(progressBar);
151 statusBar()->addPermanentWidget(frameBlocks);
153 syncIconMovie = new QMovie(":/movies/update_spinner", "mng", this);
155 // Clicking on a transaction on the overview page simply sends you to transaction history page
156 connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), this, SLOT(gotoHistoryPage()));
158 // Doubleclicking on a transaction on the transaction history page shows details
159 connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
164 BitcoinGUI::~BitcoinGUI()
171 void BitcoinGUI::createActions()
173 QActionGroup *tabGroup = new QActionGroup(this);
175 overviewAction = new QAction(QIcon(":/icons/overview"), tr("&Overview"), this);
176 overviewAction->setToolTip(tr("Show general overview of wallet"));
177 overviewAction->setCheckable(true);
178 overviewAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_1));
179 tabGroup->addAction(overviewAction);
181 historyAction = new QAction(QIcon(":/icons/history"), tr("&Transactions"), this);
182 historyAction->setToolTip(tr("Browse transaction history"));
183 historyAction->setCheckable(true);
184 historyAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_4));
185 tabGroup->addAction(historyAction);
187 addressBookAction = new QAction(QIcon(":/icons/address-book"), tr("&Address Book"), this);
188 addressBookAction->setToolTip(tr("Edit the list of stored addresses and labels"));
189 addressBookAction->setCheckable(true);
190 addressBookAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_5));
191 tabGroup->addAction(addressBookAction);
193 receiveCoinsAction = new QAction(QIcon(":/icons/receiving_addresses"), tr("&Receive coins"), this);
194 receiveCoinsAction->setToolTip(tr("Show the list of addresses for receiving payments"));
195 receiveCoinsAction->setCheckable(true);
196 receiveCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_3));
197 tabGroup->addAction(receiveCoinsAction);
199 sendCoinsAction = new QAction(QIcon(":/icons/send"), tr("&Send coins"), this);
200 sendCoinsAction->setToolTip(tr("Send coins to a bitcoin address"));
201 sendCoinsAction->setCheckable(true);
202 sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2));
203 tabGroup->addAction(sendCoinsAction);
205 messageAction = new QAction(QIcon(":/icons/edit"), tr("Sign &message"), this);
206 messageAction->setToolTip(tr("Prove you control an address"));
207 #ifdef FIRST_CLASS_MESSAGING
208 messageAction->setCheckable(true);
210 tabGroup->addAction(messageAction);
212 connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
213 connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage()));
214 connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
215 connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage()));
216 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
217 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(gotoAddressBookPage()));
218 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
219 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
220 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
221 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
222 connect(messageAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
223 connect(messageAction, SIGNAL(triggered()), this, SLOT(gotoMessagePage()));
225 quitAction = new QAction(QIcon(":/icons/quit"), tr("E&xit"), this);
226 quitAction->setToolTip(tr("Quit application"));
227 quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
228 quitAction->setMenuRole(QAction::QuitRole);
229 aboutAction = new QAction(QIcon(":/icons/bitcoin"), tr("&About %1").arg(qApp->applicationName()), this);
230 aboutAction->setToolTip(tr("Show information about Bitcoin"));
231 aboutAction->setMenuRole(QAction::AboutRole);
232 aboutQtAction = new QAction(tr("About &Qt"), this);
233 aboutQtAction->setToolTip(tr("Show information about Qt"));
234 aboutQtAction->setMenuRole(QAction::AboutQtRole);
235 optionsAction = new QAction(QIcon(":/icons/options"), tr("&Options..."), this);
236 optionsAction->setToolTip(tr("Modify configuration options for bitcoin"));
237 optionsAction->setMenuRole(QAction::PreferencesRole);
238 toggleHideAction = new QAction(QIcon(":/icons/bitcoin"), tr("Show/Hide &Bitcoin"), this);
239 toggleHideAction->setToolTip(tr("Show or hide the Bitcoin window"));
240 exportAction = new QAction(QIcon(":/icons/export"), tr("&Export..."), this);
241 exportAction->setToolTip(tr("Export the data in the current tab to a file"));
242 encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet"), this);
243 encryptWalletAction->setToolTip(tr("Encrypt or decrypt wallet"));
244 encryptWalletAction->setCheckable(true);
245 backupWalletAction = new QAction(QIcon(":/icons/filesave"), tr("&Backup Wallet"), this);
246 backupWalletAction->setToolTip(tr("Backup wallet to another location"));
247 changePassphraseAction = new QAction(QIcon(":/icons/key"), tr("&Change Passphrase"), this);
248 changePassphraseAction->setToolTip(tr("Change the passphrase used for wallet encryption"));
250 connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
251 connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked()));
252 connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked()));
253 connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
254 connect(toggleHideAction, SIGNAL(triggered()), this, SLOT(toggleHidden()));
255 connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool)));
256 connect(backupWalletAction, SIGNAL(triggered()), this, SLOT(backupWallet()));
257 connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase()));
260 void BitcoinGUI::createMenuBar()
263 // Create a decoupled menu bar on Mac which stays even if the window is closed
264 appMenuBar = new QMenuBar();
266 // Get the main window's menu bar on other platforms
267 appMenuBar = menuBar();
270 // Configure the menus
271 QMenu *file = appMenuBar->addMenu(tr("&File"));
272 file->addAction(backupWalletAction);
273 file->addAction(exportAction);
274 #ifndef FIRST_CLASS_MESSAGING
275 file->addAction(messageAction);
277 file->addSeparator();
278 file->addAction(quitAction);
280 QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
281 settings->addAction(encryptWalletAction);
282 settings->addAction(changePassphraseAction);
283 settings->addSeparator();
284 settings->addAction(optionsAction);
286 QMenu *help = appMenuBar->addMenu(tr("&Help"));
287 help->addAction(aboutAction);
288 help->addAction(aboutQtAction);
291 void BitcoinGUI::createToolBars()
293 QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));
294 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
295 toolbar->addAction(overviewAction);
296 toolbar->addAction(sendCoinsAction);
297 toolbar->addAction(receiveCoinsAction);
298 toolbar->addAction(historyAction);
299 toolbar->addAction(addressBookAction);
300 #ifdef FIRST_CLASS_MESSAGING
301 toolbar->addAction(messageAction);
304 QToolBar *toolbar2 = addToolBar(tr("Actions toolbar"));
305 toolbar2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
306 toolbar2->addAction(exportAction);
309 void BitcoinGUI::setClientModel(ClientModel *clientModel)
311 this->clientModel = clientModel;
314 if(clientModel->isTestNet())
316 QString title_testnet = windowTitle() + QString(" ") + tr("[testnet]");
317 setWindowTitle(title_testnet);
319 setWindowIcon(QIcon(":icons/bitcoin_testnet"));
321 MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
325 trayIcon->setToolTip(title_testnet);
326 trayIcon->setIcon(QIcon(":/icons/toolbar_testnet"));
330 // Keep up to date with client
331 setNumConnections(clientModel->getNumConnections());
332 connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
334 setNumBlocks(clientModel->getNumBlocks());
335 connect(clientModel, SIGNAL(numBlocksChanged(int)), this, SLOT(setNumBlocks(int)));
337 // Report errors from network/worker thread
338 connect(clientModel, SIGNAL(error(QString,QString, bool)), this, SLOT(error(QString,QString,bool)));
342 void BitcoinGUI::setWalletModel(WalletModel *walletModel)
344 this->walletModel = walletModel;
347 // Report errors from wallet thread
348 connect(walletModel, SIGNAL(error(QString,QString,bool)), this, SLOT(error(QString,QString,bool)));
350 // Put transaction list in tabs
351 transactionView->setModel(walletModel);
353 overviewPage->setModel(walletModel);
354 addressBookPage->setModel(walletModel->getAddressTableModel());
355 receiveCoinsPage->setModel(walletModel->getAddressTableModel());
356 sendCoinsPage->setModel(walletModel);
357 messagePage->setModel(walletModel);
359 setEncryptionStatus(walletModel->getEncryptionStatus());
360 connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));
362 // Balloon popup for new transaction
363 connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
364 this, SLOT(incomingTransaction(QModelIndex,int,int)));
366 // Ask for passphrase if needed
367 connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
371 void BitcoinGUI::createTrayIcon()
375 trayIcon = new QSystemTrayIcon(this);
376 trayIconMenu = new QMenu(this);
377 trayIcon->setContextMenu(trayIconMenu);
378 trayIcon->setToolTip(tr("Bitcoin client"));
379 trayIcon->setIcon(QIcon(":/icons/toolbar"));
380 connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
381 this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
384 // Note: On Mac, the dock icon is used to provide the tray's functionality.
385 MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance();
386 trayIconMenu = dockIconHandler->dockMenu();
389 // Configuration of the tray icon (or dock icon) icon menu
390 trayIconMenu->addAction(toggleHideAction);
391 trayIconMenu->addSeparator();
392 trayIconMenu->addAction(messageAction);
393 #ifndef FIRST_CLASS_MESSAGING
394 trayIconMenu->addSeparator();
396 trayIconMenu->addAction(receiveCoinsAction);
397 trayIconMenu->addAction(sendCoinsAction);
398 trayIconMenu->addSeparator();
399 trayIconMenu->addAction(optionsAction);
400 #ifndef Q_WS_MAC // This is built-in on Mac
401 trayIconMenu->addSeparator();
402 trayIconMenu->addAction(quitAction);
405 notificator = new Notificator(tr("bitcoin-qt"), trayIcon);
409 void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
411 if(reason == QSystemTrayIcon::Trigger)
413 // Click on system tray icon triggers "show/hide bitcoin"
414 toggleHideAction->trigger();
419 void BitcoinGUI::toggleHidden()
421 // activateWindow() (sometimes) helps with keyboard focus on Windows
427 else if (isMinimized())
432 else if (GUIUtil::isObscured(this))
441 void BitcoinGUI::optionsClicked()
443 if(!clientModel || !clientModel->getOptionsModel())
446 dlg.setModel(clientModel->getOptionsModel());
450 void BitcoinGUI::aboutClicked()
453 dlg.setModel(clientModel);
457 void BitcoinGUI::setNumConnections(int count)
462 case 0: icon = ":/icons/connect_0"; break;
463 case 1: case 2: case 3: icon = ":/icons/connect_1"; break;
464 case 4: case 5: case 6: icon = ":/icons/connect_2"; break;
465 case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
466 default: icon = ":/icons/connect_4"; break;
468 labelConnectionsIcon->setPixmap(QIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
469 labelConnectionsIcon->setToolTip(tr("%n active connection(s) to Bitcoin network", "", count));
472 void BitcoinGUI::setNumBlocks(int count)
474 // don't show / hide progressBar and it's label if we have no connection(s) to the network
475 if (!clientModel || clientModel->getNumConnections() == 0)
477 progressBarLabel->setVisible(false);
478 progressBar->setVisible(false);
483 int nTotalBlocks = clientModel->getNumBlocksOfPeers();
486 if(count < nTotalBlocks)
488 int nRemainingBlocks = nTotalBlocks - count;
489 float nPercentageDone = count / (nTotalBlocks * 0.01f);
491 if (clientModel->getStatusBarWarnings() == "")
493 progressBarLabel->setText(tr("Synchronizing with network..."));
494 progressBarLabel->setVisible(true);
495 progressBar->setFormat(tr("~%n block(s) remaining", "", nRemainingBlocks));
496 progressBar->setMaximum(nTotalBlocks);
497 progressBar->setValue(count);
498 progressBar->setVisible(true);
502 progressBarLabel->setText(clientModel->getStatusBarWarnings());
503 progressBarLabel->setVisible(true);
504 progressBar->setVisible(false);
506 tooltip = tr("Downloaded %1 of %2 blocks of transaction history (%3% done).").arg(count).arg(nTotalBlocks).arg(nPercentageDone, 0, 'f', 2);
510 if (clientModel->getStatusBarWarnings() == "")
511 progressBarLabel->setVisible(false);
514 progressBarLabel->setText(clientModel->getStatusBarWarnings());
515 progressBarLabel->setVisible(true);
517 progressBar->setVisible(false);
518 tooltip = tr("Downloaded %1 blocks of transaction history.").arg(count);
521 QDateTime now = QDateTime::currentDateTime();
522 QDateTime lastBlockDate = clientModel->getLastBlockDate();
523 int secs = lastBlockDate.secsTo(now);
526 // Represent time from last generated block in human readable text
529 // Fully up to date. Leave text empty.
533 text = tr("%n second(s) ago","",secs);
535 else if(secs < 60*60)
537 text = tr("%n minute(s) ago","",secs/60);
539 else if(secs < 24*60*60)
541 text = tr("%n hour(s) ago","",secs/(60*60));
545 text = tr("%n day(s) ago","",secs/(60*60*24));
548 // Set icon state: spinning if catching up, tick otherwise
549 if(secs < 90*60 && count >= nTotalBlocks)
551 tooltip = tr("Up to date") + QString(".\n") + tooltip;
552 labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
556 tooltip = tr("Catching up...") + QString("\n") + tooltip;
557 labelBlocksIcon->setMovie(syncIconMovie);
558 syncIconMovie->start();
563 tooltip += QString("\n");
564 tooltip += tr("Last received block was generated %1.").arg(text);
567 labelBlocksIcon->setToolTip(tooltip);
568 progressBarLabel->setToolTip(tooltip);
569 progressBar->setToolTip(tooltip);
572 void BitcoinGUI::error(const QString &title, const QString &message, bool modal)
574 // Report errors from network/worker thread
577 QMessageBox::critical(this, title, message, QMessageBox::Ok, QMessageBox::Ok);
579 notificator->notify(Notificator::Critical, title, message);
583 void BitcoinGUI::changeEvent(QEvent *e)
585 QMainWindow::changeEvent(e);
586 #ifndef Q_WS_MAC // Ignored on Mac
587 if(e->type() == QEvent::WindowStateChange)
589 if(clientModel && clientModel->getOptionsModel()->getMinimizeToTray())
591 QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
592 if(!(wsevt->oldState() & Qt::WindowMinimized) && isMinimized())
594 QTimer::singleShot(0, this, SLOT(hide()));
602 void BitcoinGUI::closeEvent(QCloseEvent *event)
606 #ifndef Q_WS_MAC // Ignored on Mac
607 if(!clientModel->getOptionsModel()->getMinimizeToTray() &&
608 !clientModel->getOptionsModel()->getMinimizeOnClose())
614 QMainWindow::closeEvent(event);
617 void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
620 tr("This transaction is over the size limit. You can still send it for a fee of %1, "
621 "which goes to the nodes that process your transaction and helps to support the network. "
622 "Do you want to pay the fee?").arg(
623 BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nFeeRequired));
624 QMessageBox::StandardButton retval = QMessageBox::question(
625 this, tr("Sending..."), strMessage,
626 QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes);
627 *payFee = (retval == QMessageBox::Yes);
630 void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
632 if(!walletModel || !clientModel)
634 TransactionTableModel *ttm = walletModel->getTransactionTableModel();
635 qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
636 .data(Qt::EditRole).toULongLong();
637 if(!clientModel->inInitialBlockDownload())
639 // On new transaction, make an info balloon
640 // Unless the initial block download is in progress, to prevent balloon-spam
641 QString date = ttm->index(start, TransactionTableModel::Date, parent)
643 QString type = ttm->index(start, TransactionTableModel::Type, parent)
645 QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
647 QIcon icon = qvariant_cast<QIcon>(ttm->index(start,
648 TransactionTableModel::ToAddress, parent)
649 .data(Qt::DecorationRole));
651 notificator->notify(Notificator::Information,
652 (amount)<0 ? tr("Sent transaction") :
653 tr("Incoming transaction"),
659 .arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true))
661 .arg(address), icon);
665 void BitcoinGUI::gotoOverviewPage()
667 overviewAction->setChecked(true);
668 centralWidget->setCurrentWidget(overviewPage);
670 exportAction->setEnabled(false);
671 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
674 void BitcoinGUI::gotoHistoryPage()
676 historyAction->setChecked(true);
677 centralWidget->setCurrentWidget(transactionsPage);
679 exportAction->setEnabled(true);
680 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
681 connect(exportAction, SIGNAL(triggered()), transactionView, SLOT(exportClicked()));
684 void BitcoinGUI::gotoAddressBookPage()
686 addressBookAction->setChecked(true);
687 centralWidget->setCurrentWidget(addressBookPage);
689 exportAction->setEnabled(true);
690 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
691 connect(exportAction, SIGNAL(triggered()), addressBookPage, SLOT(exportClicked()));
694 void BitcoinGUI::gotoReceiveCoinsPage()
696 receiveCoinsAction->setChecked(true);
697 centralWidget->setCurrentWidget(receiveCoinsPage);
699 exportAction->setEnabled(true);
700 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
701 connect(exportAction, SIGNAL(triggered()), receiveCoinsPage, SLOT(exportClicked()));
704 void BitcoinGUI::gotoSendCoinsPage()
706 sendCoinsAction->setChecked(true);
707 centralWidget->setCurrentWidget(sendCoinsPage);
709 exportAction->setEnabled(false);
710 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
713 void BitcoinGUI::gotoMessagePage()
715 #ifdef FIRST_CLASS_MESSAGING
716 messageAction->setChecked(true);
717 centralWidget->setCurrentWidget(messagePage);
719 exportAction->setEnabled(false);
720 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
723 messagePage->setFocus();
727 void BitcoinGUI::gotoMessagePage(QString addr)
730 messagePage->setAddress(addr);
733 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
736 if(event->mimeData()->hasUrls())
737 event->acceptProposedAction();
740 void BitcoinGUI::dropEvent(QDropEvent *event)
742 if(event->mimeData()->hasUrls())
745 QList<QUrl> uris = event->mimeData()->urls();
746 foreach(const QUrl &uri, uris)
748 sendCoinsPage->handleURI(uri.toString());
752 event->acceptProposedAction();
755 void BitcoinGUI::handleURI(QString strURI)
758 sendCoinsPage->handleURI(strURI);
760 if(!isActiveWindow())
763 showNormalIfMinimized();
766 void BitcoinGUI::setEncryptionStatus(int status)
770 case WalletModel::Unencrypted:
771 labelEncryptionIcon->hide();
772 encryptWalletAction->setChecked(false);
773 changePassphraseAction->setEnabled(false);
774 encryptWalletAction->setEnabled(true);
776 case WalletModel::Unlocked:
777 labelEncryptionIcon->show();
778 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
779 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
780 encryptWalletAction->setChecked(true);
781 changePassphraseAction->setEnabled(true);
782 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
784 case WalletModel::Locked:
785 labelEncryptionIcon->show();
786 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
787 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
788 encryptWalletAction->setChecked(true);
789 changePassphraseAction->setEnabled(true);
790 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
795 void BitcoinGUI::encryptWallet(bool status)
799 AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt:
800 AskPassphraseDialog::Decrypt, this);
801 dlg.setModel(walletModel);
804 setEncryptionStatus(walletModel->getEncryptionStatus());
807 void BitcoinGUI::backupWallet()
809 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
810 QString filename = QFileDialog::getSaveFileName(this, tr("Backup Wallet"), saveDir, tr("Wallet Data (*.dat)"));
811 if(!filename.isEmpty()) {
812 if(!walletModel->backupWallet(filename)) {
813 QMessageBox::warning(this, tr("Backup Failed"), tr("There was an error trying to save the wallet data to the new location."));
818 void BitcoinGUI::changePassphrase()
820 AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
821 dlg.setModel(walletModel);
825 void BitcoinGUI::unlockWallet()
829 // Unlock wallet when requested by wallet model
830 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
832 AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
833 dlg.setModel(walletModel);
838 void BitcoinGUI::showNormalIfMinimized()
840 if(!isVisible()) // Show, if hidden
842 if(isMinimized()) // Unminimize, if minimized