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):
62 encryptWalletAction(0),
63 changePassphraseAction(0),
69 setWindowTitle(tr("Bitcoin Wallet"));
71 setWindowIcon(QIcon(":icons/bitcoin"));
73 setUnifiedTitleAndToolBarOnMac(true);
74 QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
79 // Create actions for the toolbar, menu bar and tray/dock icon
82 // Create application menu bar
85 // Create the toolbars
88 // Create the tray icon (or setup the dock icon)
91 // Dummy widget used when restoring window state after minimization
92 dummyWidget = new QWidget();
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()
174 void BitcoinGUI::createActions()
176 QActionGroup *tabGroup = new QActionGroup(this);
178 overviewAction = new QAction(QIcon(":/icons/overview"), tr("&Overview"), this);
179 overviewAction->setToolTip(tr("Show general overview of wallet"));
180 overviewAction->setCheckable(true);
181 overviewAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_1));
182 tabGroup->addAction(overviewAction);
184 historyAction = new QAction(QIcon(":/icons/history"), tr("&Transactions"), this);
185 historyAction->setToolTip(tr("Browse transaction history"));
186 historyAction->setCheckable(true);
187 historyAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_4));
188 tabGroup->addAction(historyAction);
190 addressBookAction = new QAction(QIcon(":/icons/address-book"), tr("&Address Book"), this);
191 addressBookAction->setToolTip(tr("Edit the list of stored addresses and labels"));
192 addressBookAction->setCheckable(true);
193 addressBookAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_5));
194 tabGroup->addAction(addressBookAction);
196 receiveCoinsAction = new QAction(QIcon(":/icons/receiving_addresses"), tr("&Receive coins"), this);
197 receiveCoinsAction->setToolTip(tr("Show the list of addresses for receiving payments"));
198 receiveCoinsAction->setCheckable(true);
199 receiveCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_3));
200 tabGroup->addAction(receiveCoinsAction);
202 sendCoinsAction = new QAction(QIcon(":/icons/send"), tr("&Send coins"), this);
203 sendCoinsAction->setToolTip(tr("Send coins to a bitcoin address"));
204 sendCoinsAction->setCheckable(true);
205 sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2));
206 tabGroup->addAction(sendCoinsAction);
208 messageAction = new QAction(QIcon(":/icons/edit"), tr("Sign &message"), this);
209 messageAction->setToolTip(tr("Prove you control an address"));
210 #ifdef FIRST_CLASS_MESSAGING
211 messageAction->setCheckable(true);
213 tabGroup->addAction(messageAction);
215 connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormal()));
216 connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage()));
217 connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormal()));
218 connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage()));
219 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(showNormal()));
220 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(gotoAddressBookPage()));
221 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(showNormal()));
222 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
223 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(showNormal()));
224 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
225 connect(messageAction, SIGNAL(triggered()), this, SLOT(showNormal()));
226 connect(messageAction, SIGNAL(triggered()), this, SLOT(gotoMessagePage()));
228 quitAction = new QAction(QIcon(":/icons/quit"), tr("E&xit"), this);
229 quitAction->setToolTip(tr("Quit application"));
230 quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
231 quitAction->setMenuRole(QAction::QuitRole);
232 aboutAction = new QAction(QIcon(":/icons/bitcoin"), tr("&About %1").arg(qApp->applicationName()), this);
233 aboutAction->setToolTip(tr("Show information about Bitcoin"));
234 aboutAction->setMenuRole(QAction::AboutRole);
235 aboutQtAction = new QAction(tr("About &Qt"), this);
236 aboutQtAction->setToolTip(tr("Show information about Qt"));
237 aboutQtAction->setMenuRole(QAction::AboutQtRole);
238 optionsAction = new QAction(QIcon(":/icons/options"), tr("&Options..."), this);
239 optionsAction->setToolTip(tr("Modify configuration options for bitcoin"));
240 optionsAction->setMenuRole(QAction::PreferencesRole);
241 openBitcoinAction = new QAction(QIcon(":/icons/bitcoin"), tr("Open &Bitcoin"), this);
242 openBitcoinAction->setToolTip(tr("Show the Bitcoin window"));
243 exportAction = new QAction(QIcon(":/icons/export"), tr("&Export..."), this);
244 exportAction->setToolTip(tr("Export the data in the current tab to a file"));
245 encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet"), this);
246 encryptWalletAction->setToolTip(tr("Encrypt or decrypt wallet"));
247 encryptWalletAction->setCheckable(true);
248 backupWalletAction = new QAction(QIcon(":/icons/filesave"), tr("&Backup Wallet"), this);
249 backupWalletAction->setToolTip(tr("Backup wallet to another location"));
250 changePassphraseAction = new QAction(QIcon(":/icons/key"), tr("&Change Passphrase"), this);
251 changePassphraseAction->setToolTip(tr("Change the passphrase used for wallet encryption"));
253 connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
254 connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked()));
255 connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked()));
256 connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
257 connect(openBitcoinAction, SIGNAL(triggered()), this, SLOT(showNormal()));
258 connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool)));
259 connect(backupWalletAction, SIGNAL(triggered()), this, SLOT(backupWallet()));
260 connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase()));
263 void BitcoinGUI::createMenuBar()
266 // Create a decoupled menu bar on Mac which stays even if the window is closed
267 appMenuBar = new QMenuBar();
269 // Get the main window's menu bar on other platforms
270 appMenuBar = menuBar();
273 // Configure the menus
274 QMenu *file = appMenuBar->addMenu(tr("&File"));
275 file->addAction(exportAction);
276 #ifndef FIRST_CLASS_MESSAGING
277 file->addAction(messageAction);
278 file->addSeparator();
280 file->addAction(quitAction);
282 QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
283 settings->addAction(encryptWalletAction);
284 settings->addAction(changePassphraseAction);
285 settings->addAction(backupWalletAction);
286 settings->addSeparator();
287 settings->addAction(optionsAction);
289 QMenu *help = appMenuBar->addMenu(tr("&Help"));
290 help->addAction(aboutAction);
291 help->addAction(aboutQtAction);
294 void BitcoinGUI::createToolBars()
296 QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));
297 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
298 toolbar->addAction(overviewAction);
299 toolbar->addAction(sendCoinsAction);
300 toolbar->addAction(receiveCoinsAction);
301 toolbar->addAction(historyAction);
302 toolbar->addAction(addressBookAction);
303 #ifdef FIRST_CLASS_MESSAGING
304 toolbar->addAction(messageAction);
307 QToolBar *toolbar2 = addToolBar(tr("Actions toolbar"));
308 toolbar2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
309 toolbar2->addAction(exportAction);
312 void BitcoinGUI::setClientModel(ClientModel *clientModel)
314 this->clientModel = clientModel;
317 if(clientModel->isTestNet())
319 QString title_testnet = windowTitle() + QString(" ") + tr("[testnet]");
320 setWindowTitle(title_testnet);
322 setWindowIcon(QIcon(":icons/bitcoin_testnet"));
324 MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
328 trayIcon->setToolTip(title_testnet);
329 trayIcon->setIcon(QIcon(":/icons/toolbar_testnet"));
333 // Keep up to date with client
334 setNumConnections(clientModel->getNumConnections());
335 connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
337 setNumBlocks(clientModel->getNumBlocks());
338 connect(clientModel, SIGNAL(numBlocksChanged(int)), this, SLOT(setNumBlocks(int)));
340 // Report errors from network/worker thread
341 connect(clientModel, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString)));
345 void BitcoinGUI::setWalletModel(WalletModel *walletModel)
347 this->walletModel = walletModel;
350 // Report errors from wallet thread
351 connect(walletModel, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString)));
353 // Put transaction list in tabs
354 transactionView->setModel(walletModel);
356 overviewPage->setModel(walletModel);
357 addressBookPage->setModel(walletModel->getAddressTableModel());
358 receiveCoinsPage->setModel(walletModel->getAddressTableModel());
359 sendCoinsPage->setModel(walletModel);
360 messagePage->setModel(walletModel);
362 setEncryptionStatus(walletModel->getEncryptionStatus());
363 connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));
365 // Balloon popup for new transaction
366 connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
367 this, SLOT(incomingTransaction(QModelIndex,int,int)));
369 // Ask for passphrase if needed
370 connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
374 void BitcoinGUI::createTrayIcon()
378 trayIcon = new QSystemTrayIcon(this);
379 trayIconMenu = new QMenu(this);
380 trayIcon->setContextMenu(trayIconMenu);
381 trayIcon->setToolTip("Bitcoin client");
382 trayIcon->setIcon(QIcon(":/icons/toolbar"));
383 connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
384 this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
387 // Note: On Mac, the dock icon is used to provide the tray's functionality.
388 MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance();
389 connect(dockIconHandler, SIGNAL(dockIconClicked()), openBitcoinAction, SLOT(trigger()));
390 trayIconMenu = dockIconHandler->dockMenu();
393 // Configuration of the tray icon (or dock icon) icon menu
394 trayIconMenu->addAction(openBitcoinAction);
395 trayIconMenu->addSeparator();
396 trayIconMenu->addAction(messageAction);
397 #ifndef FIRST_CLASS_MESSAGING
398 trayIconMenu->addSeparator();
400 trayIconMenu->addAction(receiveCoinsAction);
401 trayIconMenu->addAction(sendCoinsAction);
402 trayIconMenu->addSeparator();
403 trayIconMenu->addAction(optionsAction);
404 #ifndef Q_WS_MAC // This is built-in on Mac
405 trayIconMenu->addSeparator();
406 trayIconMenu->addAction(quitAction);
409 notificator = new Notificator(tr("bitcoin-qt"), trayIcon);
413 void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
415 if(reason == QSystemTrayIcon::Trigger)
417 // Click on system tray icon triggers "open bitcoin"
418 openBitcoinAction->trigger();
423 void BitcoinGUI::showNormal()
425 // Reparent window to the desktop (in case it was hidden on minimize)
427 setParent(NULL, Qt::Window);
428 QMainWindow::showNormal();
431 void BitcoinGUI::optionsClicked()
433 if(!clientModel || !clientModel->getOptionsModel())
436 dlg.setModel(clientModel->getOptionsModel());
440 void BitcoinGUI::aboutClicked()
443 dlg.setModel(clientModel);
447 void BitcoinGUI::setNumConnections(int count)
452 case 0: icon = ":/icons/connect_0"; break;
453 case 1: case 2: case 3: icon = ":/icons/connect_1"; break;
454 case 4: case 5: case 6: icon = ":/icons/connect_2"; break;
455 case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
456 default: icon = ":/icons/connect_4"; break;
458 labelConnectionsIcon->setPixmap(QIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
459 labelConnectionsIcon->setToolTip(tr("%n active connection(s) to Bitcoin network", "", count));
462 void BitcoinGUI::setNumBlocks(int count)
466 int total = clientModel->getNumBlocksOfPeers();
471 if (clientModel->getStatusBarWarnings() == "")
473 progressBarLabel->setVisible(true);
474 progressBarLabel->setText(tr("Synchronizing with network..."));
475 progressBar->setVisible(true);
476 progressBar->setMaximum(total);
477 progressBar->setValue(count);
481 progressBarLabel->setText(clientModel->getStatusBarWarnings());
482 progressBarLabel->setVisible(true);
483 progressBar->setVisible(false);
485 tooltip = tr("Downloaded %1 of %2 blocks of transaction history.").arg(count).arg(total);
489 if (clientModel->getStatusBarWarnings() == "")
490 progressBarLabel->setVisible(false);
493 progressBarLabel->setText(clientModel->getStatusBarWarnings());
494 progressBarLabel->setVisible(true);
496 progressBar->setVisible(false);
497 tooltip = tr("Downloaded %1 blocks of transaction history.").arg(count);
500 QDateTime now = QDateTime::currentDateTime();
501 QDateTime lastBlockDate = clientModel->getLastBlockDate();
502 int secs = lastBlockDate.secsTo(now);
505 // Represent time from last generated block in human readable text
508 text = tr("%n second(s) ago","",secs);
510 else if(secs < 60*60)
512 text = tr("%n minute(s) ago","",secs/60);
514 else if(secs < 24*60*60)
516 text = tr("%n hour(s) ago","",secs/(60*60));
520 text = tr("%n day(s) ago","",secs/(60*60*24));
523 // Set icon state: spinning if catching up, tick otherwise
526 tooltip = tr("Up to date") + QString("\n") + tooltip;
527 labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
531 tooltip = tr("Catching up...") + QString("\n") + tooltip;
532 labelBlocksIcon->setMovie(syncIconMovie);
533 syncIconMovie->start();
536 tooltip += QString("\n");
537 tooltip += tr("Last received block was generated %1.").arg(text);
539 labelBlocksIcon->setToolTip(tooltip);
540 progressBarLabel->setToolTip(tooltip);
541 progressBar->setToolTip(tooltip);
544 void BitcoinGUI::refreshStatusBar()
546 /* Might display multiple times in the case of multiple alerts
547 static QString prevStatusBar;
548 QString newStatusBar = clientModel->getStatusBarWarnings();
549 if (prevStatusBar != newStatusBar)
551 prevStatusBar = newStatusBar;
552 error(tr("Network Alert"), newStatusBar);
554 setNumBlocks(clientModel->getNumBlocks());
557 void BitcoinGUI::error(const QString &title, const QString &message)
559 // Report errors from network/worker thread
560 notificator->notify(Notificator::Critical, title, message);
563 void BitcoinGUI::changeEvent(QEvent *e)
565 #ifndef Q_WS_MAC // Ignored on Mac
566 if(e->type() == QEvent::WindowStateChange)
568 if(clientModel && clientModel->getOptionsModel()->getMinimizeToTray())
572 // Hiding the window from taskbar
573 setParent(dummyWidget, Qt::SubWindow);
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);