4 * W.J. van der Laan 20011-2012
5 * The Bitcoin Developers 20011-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"
28 #include "macdockiconhandler.h"
31 #include <QApplication>
32 #include <QMainWindow>
37 #include <QVBoxLayout>
42 #include <QPushButton>
44 #include <QMessageBox>
45 #include <QProgressBar>
46 #include <QStackedWidget>
49 #include <QFileDialog>
50 #include <QDesktopServices>
52 #include <QDragEnterEvent>
57 BitcoinGUI::BitcoinGUI(QWidget *parent):
61 encryptWalletAction(0),
62 changePassphraseAction(0),
68 setWindowTitle(tr("Bitcoin Wallet"));
70 setWindowIcon(QIcon(":icons/bitcoin"));
72 setUnifiedTitleAndToolBarOnMac(true);
73 QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
78 // Create actions for the toolbar, menu bar and tray/dock icon
81 // Create application menu bar
84 // Create the toolbars
87 // Create the tray icon (or setup the dock icon)
91 overviewPage = new OverviewPage();
93 transactionsPage = new QWidget(this);
94 QVBoxLayout *vbox = new QVBoxLayout();
95 transactionView = new TransactionView(this);
96 vbox->addWidget(transactionView);
97 transactionsPage->setLayout(vbox);
99 addressBookPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::SendingTab);
101 receiveCoinsPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::ReceivingTab);
103 sendCoinsPage = new SendCoinsDialog(this);
105 messagePage = new MessagePage(this);
107 centralWidget = new QStackedWidget(this);
108 centralWidget->addWidget(overviewPage);
109 centralWidget->addWidget(transactionsPage);
110 centralWidget->addWidget(addressBookPage);
111 centralWidget->addWidget(receiveCoinsPage);
112 centralWidget->addWidget(sendCoinsPage);
113 #ifdef FIRST_CLASS_MESSAGING
114 centralWidget->addWidget(messagePage);
116 setCentralWidget(centralWidget);
121 // Status bar notification icons
122 QFrame *frameBlocks = new QFrame();
123 frameBlocks->setContentsMargins(0,0,0,0);
124 frameBlocks->setMinimumWidth(56);
125 frameBlocks->setMaximumWidth(56);
126 QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);
127 frameBlocksLayout->setContentsMargins(3,0,3,0);
128 frameBlocksLayout->setSpacing(3);
129 labelEncryptionIcon = new QLabel();
130 labelConnectionsIcon = new QLabel();
131 labelBlocksIcon = new QLabel();
132 frameBlocksLayout->addStretch();
133 frameBlocksLayout->addWidget(labelEncryptionIcon);
134 frameBlocksLayout->addStretch();
135 frameBlocksLayout->addWidget(labelConnectionsIcon);
136 frameBlocksLayout->addStretch();
137 frameBlocksLayout->addWidget(labelBlocksIcon);
138 frameBlocksLayout->addStretch();
140 // Progress bar for blocks download
141 progressBarLabel = new QLabel(tr("Synchronizing with network..."));
142 progressBarLabel->setVisible(false);
143 progressBar = new QProgressBar();
144 progressBar->setToolTip(tr("Block chain synchronization in progress"));
145 progressBar->setVisible(false);
147 statusBar()->addWidget(progressBarLabel);
148 statusBar()->addWidget(progressBar);
149 statusBar()->addPermanentWidget(frameBlocks);
151 syncIconMovie = new QMovie(":/movies/update_spinner", "mng", this);
153 // Clicking on a transaction on the overview page simply sends you to transaction history page
154 connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), this, SLOT(gotoHistoryPage()));
156 // Doubleclicking on a transaction on the transaction history page shows details
157 connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
162 BitcoinGUI::~BitcoinGUI()
164 if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu)
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 openBitcoinAction = new QAction(QIcon(":/icons/bitcoin"), tr("Open &Bitcoin"), this);
239 openBitcoinAction->setToolTip(tr("Show 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(openBitcoinAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
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)), this, SLOT(error(QString,QString)));
342 void BitcoinGUI::setWalletModel(WalletModel *walletModel)
344 this->walletModel = walletModel;
347 // Report errors from wallet thread
348 connect(walletModel, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString)));
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("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 connect(dockIconHandler, SIGNAL(dockIconClicked()), openBitcoinAction, SLOT(trigger()));
387 trayIconMenu = dockIconHandler->dockMenu();
390 // Configuration of the tray icon (or dock icon) icon menu
391 trayIconMenu->addAction(openBitcoinAction);
392 trayIconMenu->addSeparator();
393 trayIconMenu->addAction(messageAction);
394 #ifndef FIRST_CLASS_MESSAGING
395 trayIconMenu->addSeparator();
397 trayIconMenu->addAction(receiveCoinsAction);
398 trayIconMenu->addAction(sendCoinsAction);
399 trayIconMenu->addSeparator();
400 trayIconMenu->addAction(optionsAction);
401 #ifndef Q_WS_MAC // This is built-in on Mac
402 trayIconMenu->addSeparator();
403 trayIconMenu->addAction(quitAction);
406 notificator = new Notificator(tr("bitcoin-qt"), trayIcon);
410 void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
412 if(reason == QSystemTrayIcon::Trigger)
414 // Click on system tray icon triggers "open bitcoin"
415 openBitcoinAction->trigger();
420 void BitcoinGUI::optionsClicked()
422 if(!clientModel || !clientModel->getOptionsModel())
425 dlg.setModel(clientModel->getOptionsModel());
429 void BitcoinGUI::aboutClicked()
432 dlg.setModel(clientModel);
436 void BitcoinGUI::setNumConnections(int count)
441 case 0: icon = ":/icons/connect_0"; break;
442 case 1: case 2: case 3: icon = ":/icons/connect_1"; break;
443 case 4: case 5: case 6: icon = ":/icons/connect_2"; break;
444 case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
445 default: icon = ":/icons/connect_4"; break;
447 labelConnectionsIcon->setPixmap(QIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
448 labelConnectionsIcon->setToolTip(tr("%n active connection(s) to Bitcoin network", "", count));
451 void BitcoinGUI::setNumBlocks(int count)
455 int total = clientModel->getNumBlocksOfPeers();
460 if (clientModel->getStatusBarWarnings() == "")
462 progressBarLabel->setVisible(true);
463 progressBarLabel->setText(tr("Synchronizing with network..."));
464 progressBar->setVisible(true);
465 progressBar->setMaximum(total);
466 progressBar->setValue(count);
470 progressBarLabel->setText(clientModel->getStatusBarWarnings());
471 progressBarLabel->setVisible(true);
472 progressBar->setVisible(false);
474 tooltip = tr("Downloaded %1 of %2 blocks of transaction history.").arg(count).arg(total);
478 if (clientModel->getStatusBarWarnings() == "")
479 progressBarLabel->setVisible(false);
482 progressBarLabel->setText(clientModel->getStatusBarWarnings());
483 progressBarLabel->setVisible(true);
485 progressBar->setVisible(false);
486 tooltip = tr("Downloaded %1 blocks of transaction history.").arg(count);
489 QDateTime now = QDateTime::currentDateTime();
490 QDateTime lastBlockDate = clientModel->getLastBlockDate();
491 int secs = lastBlockDate.secsTo(now);
494 // Represent time from last generated block in human readable text
497 // Fully up to date. Leave text empty.
501 text = tr("%n second(s) ago","",secs);
503 else if(secs < 60*60)
505 text = tr("%n minute(s) ago","",secs/60);
507 else if(secs < 24*60*60)
509 text = tr("%n hour(s) ago","",secs/(60*60));
513 text = tr("%n day(s) ago","",secs/(60*60*24));
516 // Set icon state: spinning if catching up, tick otherwise
519 tooltip = tr("Up to date") + QString(".\n") + tooltip;
520 labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
524 tooltip = tr("Catching up...") + QString("\n") + tooltip;
525 labelBlocksIcon->setMovie(syncIconMovie);
526 syncIconMovie->start();
531 tooltip += QString("\n");
532 tooltip += tr("Last received block was generated %1.").arg(text);
535 labelBlocksIcon->setToolTip(tooltip);
536 progressBarLabel->setToolTip(tooltip);
537 progressBar->setToolTip(tooltip);
540 void BitcoinGUI::refreshStatusBar()
542 /* Might display multiple times in the case of multiple alerts
543 static QString prevStatusBar;
544 QString newStatusBar = clientModel->getStatusBarWarnings();
545 if (prevStatusBar != newStatusBar)
547 prevStatusBar = newStatusBar;
548 error(tr("Network Alert"), newStatusBar);
550 setNumBlocks(clientModel->getNumBlocks());
553 void BitcoinGUI::error(const QString &title, const QString &message)
555 // Report errors from network/worker thread
556 notificator->notify(Notificator::Critical, title, message);
559 void BitcoinGUI::changeEvent(QEvent *e)
561 #ifndef Q_WS_MAC // Ignored on Mac
562 if(e->type() == QEvent::WindowStateChange)
564 if(clientModel && clientModel->getOptionsModel()->getMinimizeToTray())
566 QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
567 bool wasMinimized = wsevt->oldState() & Qt::WindowMinimized;
568 bool isMinimized = windowState() & Qt::WindowMinimized;
569 if(!wasMinimized && isMinimized)
571 // Minimized, hide the window from taskbar
572 setWindowFlags(windowFlags() | Qt::Tool);
575 else if(wasMinimized && !isMinimized)
577 // Unminimized, show the window in taskbar
578 setWindowFlags(windowFlags() &~ Qt::Tool);
583 QMainWindow::changeEvent(e);
586 void BitcoinGUI::closeEvent(QCloseEvent *event)
590 #ifndef Q_WS_MAC // Ignored on Mac
591 if(!clientModel->getOptionsModel()->getMinimizeToTray() &&
592 !clientModel->getOptionsModel()->getMinimizeOnClose())
598 QMainWindow::closeEvent(event);
601 void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
604 tr("This transaction is over the size limit. You can still send it for a fee of %1, "
605 "which goes to the nodes that process your transaction and helps to support the network. "
606 "Do you want to pay the fee?").arg(
607 BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nFeeRequired));
608 QMessageBox::StandardButton retval = QMessageBox::question(
609 this, tr("Sending..."), strMessage,
610 QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes);
611 *payFee = (retval == QMessageBox::Yes);
614 void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
616 if(!walletModel || !clientModel)
618 TransactionTableModel *ttm = walletModel->getTransactionTableModel();
619 qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
620 .data(Qt::EditRole).toULongLong();
621 if(!clientModel->inInitialBlockDownload())
623 // On new transaction, make an info balloon
624 // Unless the initial block download is in progress, to prevent balloon-spam
625 QString date = ttm->index(start, TransactionTableModel::Date, parent)
627 QString type = ttm->index(start, TransactionTableModel::Type, parent)
629 QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
631 QIcon icon = qvariant_cast<QIcon>(ttm->index(start,
632 TransactionTableModel::ToAddress, parent)
633 .data(Qt::DecorationRole));
635 notificator->notify(Notificator::Information,
636 (amount)<0 ? tr("Sent transaction") :
637 tr("Incoming transaction"),
643 .arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true))
645 .arg(address), icon);
649 void BitcoinGUI::gotoOverviewPage()
651 overviewAction->setChecked(true);
652 centralWidget->setCurrentWidget(overviewPage);
654 exportAction->setEnabled(false);
655 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
658 void BitcoinGUI::gotoHistoryPage()
660 historyAction->setChecked(true);
661 centralWidget->setCurrentWidget(transactionsPage);
663 exportAction->setEnabled(true);
664 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
665 connect(exportAction, SIGNAL(triggered()), transactionView, SLOT(exportClicked()));
668 void BitcoinGUI::gotoAddressBookPage()
670 addressBookAction->setChecked(true);
671 centralWidget->setCurrentWidget(addressBookPage);
673 exportAction->setEnabled(true);
674 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
675 connect(exportAction, SIGNAL(triggered()), addressBookPage, SLOT(exportClicked()));
678 void BitcoinGUI::gotoReceiveCoinsPage()
680 receiveCoinsAction->setChecked(true);
681 centralWidget->setCurrentWidget(receiveCoinsPage);
683 exportAction->setEnabled(true);
684 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
685 connect(exportAction, SIGNAL(triggered()), receiveCoinsPage, SLOT(exportClicked()));
688 void BitcoinGUI::gotoSendCoinsPage()
690 sendCoinsAction->setChecked(true);
691 centralWidget->setCurrentWidget(sendCoinsPage);
693 exportAction->setEnabled(false);
694 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
697 void BitcoinGUI::gotoMessagePage()
699 #ifdef FIRST_CLASS_MESSAGING
700 messageAction->setChecked(true);
701 centralWidget->setCurrentWidget(messagePage);
703 exportAction->setEnabled(false);
704 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
707 messagePage->setFocus();
711 void BitcoinGUI::gotoMessagePage(QString addr)
714 messagePage->setAddress(addr);
717 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
720 if(event->mimeData()->hasUrls())
721 event->acceptProposedAction();
724 void BitcoinGUI::dropEvent(QDropEvent *event)
726 if(event->mimeData()->hasUrls())
729 QList<QUrl> urls = event->mimeData()->urls();
730 foreach(const QUrl &url, urls)
732 sendCoinsPage->handleURL(url.toString());
736 event->acceptProposedAction();
739 void BitcoinGUI::handleURL(QString strURL)
742 sendCoinsPage->handleURL(strURL);
745 void BitcoinGUI::setEncryptionStatus(int status)
749 case WalletModel::Unencrypted:
750 labelEncryptionIcon->hide();
751 encryptWalletAction->setChecked(false);
752 changePassphraseAction->setEnabled(false);
753 encryptWalletAction->setEnabled(true);
755 case WalletModel::Unlocked:
756 labelEncryptionIcon->show();
757 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
758 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
759 encryptWalletAction->setChecked(true);
760 changePassphraseAction->setEnabled(true);
761 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
763 case WalletModel::Locked:
764 labelEncryptionIcon->show();
765 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
766 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
767 encryptWalletAction->setChecked(true);
768 changePassphraseAction->setEnabled(true);
769 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
774 void BitcoinGUI::encryptWallet(bool status)
778 AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt:
779 AskPassphraseDialog::Decrypt, this);
780 dlg.setModel(walletModel);
783 setEncryptionStatus(walletModel->getEncryptionStatus());
786 void BitcoinGUI::backupWallet()
788 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
789 QString filename = QFileDialog::getSaveFileName(this, tr("Backup Wallet"), saveDir, tr("Wallet Data (*.dat)"));
790 if(!filename.isEmpty()) {
791 if(!walletModel->backupWallet(filename)) {
792 QMessageBox::warning(this, tr("Backup Failed"), tr("There was an error trying to save the wallet data to the new location."));
797 void BitcoinGUI::changePassphrase()
799 AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
800 dlg.setModel(walletModel);
804 void BitcoinGUI::unlockWallet()
808 // Unlock wallet when requested by wallet model
809 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
811 AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
812 dlg.setModel(walletModel);
817 void BitcoinGUI::showNormalIfMinimized()
819 if(!isVisible()) // Show, if hidden
821 if(isMinimized()) // Unminimize, if minimized