4 * W.J. van der Laan 20011-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()
168 if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu)
175 void BitcoinGUI::createActions()
177 QActionGroup *tabGroup = new QActionGroup(this);
179 overviewAction = new QAction(QIcon(":/icons/overview"), tr("&Overview"), this);
180 overviewAction->setToolTip(tr("Show general overview of wallet"));
181 overviewAction->setCheckable(true);
182 overviewAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_1));
183 tabGroup->addAction(overviewAction);
185 historyAction = new QAction(QIcon(":/icons/history"), tr("&Transactions"), this);
186 historyAction->setToolTip(tr("Browse transaction history"));
187 historyAction->setCheckable(true);
188 historyAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_4));
189 tabGroup->addAction(historyAction);
191 addressBookAction = new QAction(QIcon(":/icons/address-book"), tr("&Address Book"), this);
192 addressBookAction->setToolTip(tr("Edit the list of stored addresses and labels"));
193 addressBookAction->setCheckable(true);
194 addressBookAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_5));
195 tabGroup->addAction(addressBookAction);
197 receiveCoinsAction = new QAction(QIcon(":/icons/receiving_addresses"), tr("&Receive coins"), this);
198 receiveCoinsAction->setToolTip(tr("Show the list of addresses for receiving payments"));
199 receiveCoinsAction->setCheckable(true);
200 receiveCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_3));
201 tabGroup->addAction(receiveCoinsAction);
203 sendCoinsAction = new QAction(QIcon(":/icons/send"), tr("&Send coins"), this);
204 sendCoinsAction->setToolTip(tr("Send coins to a bitcoin address"));
205 sendCoinsAction->setCheckable(true);
206 sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2));
207 tabGroup->addAction(sendCoinsAction);
209 messageAction = new QAction(QIcon(":/icons/edit"), tr("Sign &message"), this);
210 messageAction->setToolTip(tr("Prove you control an address"));
211 #ifdef FIRST_CLASS_MESSAGING
212 messageAction->setCheckable(true);
214 tabGroup->addAction(messageAction);
216 connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
217 connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage()));
218 connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
219 connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage()));
220 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
221 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(gotoAddressBookPage()));
222 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
223 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
224 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
225 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
226 connect(messageAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
227 connect(messageAction, SIGNAL(triggered()), this, SLOT(gotoMessagePage()));
229 quitAction = new QAction(QIcon(":/icons/quit"), tr("E&xit"), this);
230 quitAction->setToolTip(tr("Quit application"));
231 quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
232 quitAction->setMenuRole(QAction::QuitRole);
233 aboutAction = new QAction(QIcon(":/icons/bitcoin"), tr("&About %1").arg(qApp->applicationName()), this);
234 aboutAction->setToolTip(tr("Show information about Bitcoin"));
235 aboutAction->setMenuRole(QAction::AboutRole);
236 aboutQtAction = new QAction(tr("About &Qt"), this);
237 aboutQtAction->setToolTip(tr("Show information about Qt"));
238 aboutQtAction->setMenuRole(QAction::AboutQtRole);
239 optionsAction = new QAction(QIcon(":/icons/options"), tr("&Options..."), this);
240 optionsAction->setToolTip(tr("Modify configuration options for bitcoin"));
241 optionsAction->setMenuRole(QAction::PreferencesRole);
242 openBitcoinAction = new QAction(QIcon(":/icons/bitcoin"), tr("Open &Bitcoin"), this);
243 openBitcoinAction->setToolTip(tr("Show the Bitcoin window"));
244 exportAction = new QAction(QIcon(":/icons/export"), tr("&Export..."), this);
245 exportAction->setToolTip(tr("Export the data in the current tab to a file"));
246 encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet"), this);
247 encryptWalletAction->setToolTip(tr("Encrypt or decrypt wallet"));
248 encryptWalletAction->setCheckable(true);
249 backupWalletAction = new QAction(QIcon(":/icons/filesave"), tr("&Backup Wallet"), this);
250 backupWalletAction->setToolTip(tr("Backup wallet to another location"));
251 changePassphraseAction = new QAction(QIcon(":/icons/key"), tr("&Change Passphrase"), this);
252 changePassphraseAction->setToolTip(tr("Change the passphrase used for wallet encryption"));
254 connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
255 connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked()));
256 connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked()));
257 connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
258 connect(openBitcoinAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
259 connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool)));
260 connect(backupWalletAction, SIGNAL(triggered()), this, SLOT(backupWallet()));
261 connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase()));
264 void BitcoinGUI::createMenuBar()
267 // Create a decoupled menu bar on Mac which stays even if the window is closed
268 appMenuBar = new QMenuBar();
270 // Get the main window's menu bar on other platforms
271 appMenuBar = menuBar();
274 // Configure the menus
275 QMenu *file = appMenuBar->addMenu(tr("&File"));
276 file->addAction(backupWalletAction);
277 file->addAction(exportAction);
278 #ifndef FIRST_CLASS_MESSAGING
279 file->addAction(messageAction);
281 file->addSeparator();
282 file->addAction(quitAction);
284 QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
285 settings->addAction(encryptWalletAction);
286 settings->addAction(changePassphraseAction);
287 settings->addSeparator();
288 settings->addAction(optionsAction);
290 QMenu *help = appMenuBar->addMenu(tr("&Help"));
291 help->addAction(aboutAction);
292 help->addAction(aboutQtAction);
295 void BitcoinGUI::createToolBars()
297 QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));
298 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
299 toolbar->addAction(overviewAction);
300 toolbar->addAction(sendCoinsAction);
301 toolbar->addAction(receiveCoinsAction);
302 toolbar->addAction(historyAction);
303 toolbar->addAction(addressBookAction);
304 #ifdef FIRST_CLASS_MESSAGING
305 toolbar->addAction(messageAction);
308 QToolBar *toolbar2 = addToolBar(tr("Actions toolbar"));
309 toolbar2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
310 toolbar2->addAction(exportAction);
313 void BitcoinGUI::setClientModel(ClientModel *clientModel)
315 this->clientModel = clientModel;
318 if(clientModel->isTestNet())
320 QString title_testnet = windowTitle() + QString(" ") + tr("[testnet]");
321 setWindowTitle(title_testnet);
323 setWindowIcon(QIcon(":icons/bitcoin_testnet"));
325 MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
329 trayIcon->setToolTip(title_testnet);
330 trayIcon->setIcon(QIcon(":/icons/toolbar_testnet"));
334 // Keep up to date with client
335 setNumConnections(clientModel->getNumConnections());
336 connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
338 setNumBlocks(clientModel->getNumBlocks());
339 connect(clientModel, SIGNAL(numBlocksChanged(int)), this, SLOT(setNumBlocks(int)));
341 // Report errors from network/worker thread
342 connect(clientModel, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString)));
346 void BitcoinGUI::setWalletModel(WalletModel *walletModel)
348 this->walletModel = walletModel;
351 // Report errors from wallet thread
352 connect(walletModel, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString)));
354 // Put transaction list in tabs
355 transactionView->setModel(walletModel);
357 overviewPage->setModel(walletModel);
358 addressBookPage->setModel(walletModel->getAddressTableModel());
359 receiveCoinsPage->setModel(walletModel->getAddressTableModel());
360 sendCoinsPage->setModel(walletModel);
361 messagePage->setModel(walletModel);
363 setEncryptionStatus(walletModel->getEncryptionStatus());
364 connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));
366 // Balloon popup for new transaction
367 connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
368 this, SLOT(incomingTransaction(QModelIndex,int,int)));
370 // Ask for passphrase if needed
371 connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
375 void BitcoinGUI::createTrayIcon()
379 trayIcon = new QSystemTrayIcon(this);
380 trayIconMenu = new QMenu(this);
381 trayIcon->setContextMenu(trayIconMenu);
382 trayIcon->setToolTip("Bitcoin client");
383 trayIcon->setIcon(QIcon(":/icons/toolbar"));
384 connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
385 this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
388 // Note: On Mac, the dock icon is used to provide the tray's functionality.
389 MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance();
390 connect(dockIconHandler, SIGNAL(dockIconClicked()), openBitcoinAction, SLOT(trigger()));
391 trayIconMenu = dockIconHandler->dockMenu();
394 // Configuration of the tray icon (or dock icon) icon menu
395 trayIconMenu->addAction(openBitcoinAction);
396 trayIconMenu->addSeparator();
397 trayIconMenu->addAction(messageAction);
398 #ifndef FIRST_CLASS_MESSAGING
399 trayIconMenu->addSeparator();
401 trayIconMenu->addAction(receiveCoinsAction);
402 trayIconMenu->addAction(sendCoinsAction);
403 trayIconMenu->addSeparator();
404 trayIconMenu->addAction(optionsAction);
405 #ifndef Q_WS_MAC // This is built-in on Mac
406 trayIconMenu->addSeparator();
407 trayIconMenu->addAction(quitAction);
410 notificator = new Notificator(tr("bitcoin-qt"), trayIcon);
414 void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
416 if(reason == QSystemTrayIcon::Trigger)
418 // Click on system tray icon triggers "open bitcoin"
419 openBitcoinAction->trigger();
424 void BitcoinGUI::optionsClicked()
426 if(!clientModel || !clientModel->getOptionsModel())
429 dlg.setModel(clientModel->getOptionsModel());
433 void BitcoinGUI::aboutClicked()
436 dlg.setModel(clientModel);
440 void BitcoinGUI::setNumConnections(int count)
445 case 0: icon = ":/icons/connect_0"; break;
446 case 1: case 2: case 3: icon = ":/icons/connect_1"; break;
447 case 4: case 5: case 6: icon = ":/icons/connect_2"; break;
448 case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
449 default: icon = ":/icons/connect_4"; break;
451 labelConnectionsIcon->setPixmap(QIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
452 labelConnectionsIcon->setToolTip(tr("%n active connection(s) to Bitcoin network", "", count));
455 void BitcoinGUI::setNumBlocks(int count)
459 int total = clientModel->getNumBlocksOfPeers();
464 if (clientModel->getStatusBarWarnings() == "")
466 progressBarLabel->setVisible(true);
467 progressBarLabel->setText(tr("Synchronizing with network..."));
468 progressBar->setVisible(true);
469 progressBar->setMaximum(total);
470 progressBar->setValue(count);
474 progressBarLabel->setText(clientModel->getStatusBarWarnings());
475 progressBarLabel->setVisible(true);
476 progressBar->setVisible(false);
478 tooltip = tr("Downloaded %1 of %2 blocks of transaction history.").arg(count).arg(total);
482 if (clientModel->getStatusBarWarnings() == "")
483 progressBarLabel->setVisible(false);
486 progressBarLabel->setText(clientModel->getStatusBarWarnings());
487 progressBarLabel->setVisible(true);
489 progressBar->setVisible(false);
490 tooltip = tr("Downloaded %1 blocks of transaction history.").arg(count);
493 QDateTime now = QDateTime::currentDateTime();
494 QDateTime lastBlockDate = clientModel->getLastBlockDate();
495 int secs = lastBlockDate.secsTo(now);
498 // Represent time from last generated block in human readable text
501 // Fully up to date. Leave text empty.
505 text = tr("%n second(s) ago","",secs);
507 else if(secs < 60*60)
509 text = tr("%n minute(s) ago","",secs/60);
511 else if(secs < 24*60*60)
513 text = tr("%n hour(s) ago","",secs/(60*60));
517 text = tr("%n day(s) ago","",secs/(60*60*24));
520 // Set icon state: spinning if catching up, tick otherwise
521 if(secs < 90*60 && count >= Checkpoints::GetTotalBlocksEstimate())
523 tooltip = tr("Up to date") + QString(".\n") + tooltip;
524 labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
528 tooltip = tr("Catching up...") + QString("\n") + tooltip;
529 labelBlocksIcon->setMovie(syncIconMovie);
530 syncIconMovie->start();
535 tooltip += QString("\n");
536 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 bool HACK_SHUTDOWN = false;
559 void BitcoinGUI::error(const QString &title, const QString &message, bool modal)
561 // Report errors from network/worker thread
564 QMessageBox::critical(this, title, message, QMessageBox::Ok, QMessageBox::Ok);
566 QMetaObject::invokeMethod(QCoreApplication::instance(), "quit", Qt::QueuedConnection);
568 notificator->notify(Notificator::Critical, title, message);
572 void BitcoinGUI::changeEvent(QEvent *e)
574 QMainWindow::changeEvent(e);
575 #ifndef Q_WS_MAC // Ignored on Mac
576 if(e->type() == QEvent::WindowStateChange)
578 if(clientModel && clientModel->getOptionsModel()->getMinimizeToTray())
580 QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
581 if(!(wsevt->oldState() & Qt::WindowMinimized) && isMinimized())
583 QTimer::singleShot(0, this, SLOT(hide()));
591 void BitcoinGUI::closeEvent(QCloseEvent *event)
595 #ifndef Q_WS_MAC // Ignored on Mac
596 if(!clientModel->getOptionsModel()->getMinimizeToTray() &&
597 !clientModel->getOptionsModel()->getMinimizeOnClose())
603 QMainWindow::closeEvent(event);
606 void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
609 tr("This transaction is over the size limit. You can still send it for a fee of %1, "
610 "which goes to the nodes that process your transaction and helps to support the network. "
611 "Do you want to pay the fee?").arg(
612 BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nFeeRequired));
613 QMessageBox::StandardButton retval = QMessageBox::question(
614 this, tr("Sending..."), strMessage,
615 QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes);
616 *payFee = (retval == QMessageBox::Yes);
619 void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
621 if(!walletModel || !clientModel)
623 TransactionTableModel *ttm = walletModel->getTransactionTableModel();
624 qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
625 .data(Qt::EditRole).toULongLong();
626 if(!clientModel->inInitialBlockDownload())
628 // On new transaction, make an info balloon
629 // Unless the initial block download is in progress, to prevent balloon-spam
630 QString date = ttm->index(start, TransactionTableModel::Date, parent)
632 QString type = ttm->index(start, TransactionTableModel::Type, parent)
634 QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
636 QIcon icon = qvariant_cast<QIcon>(ttm->index(start,
637 TransactionTableModel::ToAddress, parent)
638 .data(Qt::DecorationRole));
640 notificator->notify(Notificator::Information,
641 (amount)<0 ? tr("Sent transaction") :
642 tr("Incoming transaction"),
648 .arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true))
650 .arg(address), icon);
654 void BitcoinGUI::gotoOverviewPage()
656 overviewAction->setChecked(true);
657 centralWidget->setCurrentWidget(overviewPage);
659 exportAction->setEnabled(false);
660 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
663 void BitcoinGUI::gotoHistoryPage()
665 historyAction->setChecked(true);
666 centralWidget->setCurrentWidget(transactionsPage);
668 exportAction->setEnabled(true);
669 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
670 connect(exportAction, SIGNAL(triggered()), transactionView, SLOT(exportClicked()));
673 void BitcoinGUI::gotoAddressBookPage()
675 addressBookAction->setChecked(true);
676 centralWidget->setCurrentWidget(addressBookPage);
678 exportAction->setEnabled(true);
679 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
680 connect(exportAction, SIGNAL(triggered()), addressBookPage, SLOT(exportClicked()));
683 void BitcoinGUI::gotoReceiveCoinsPage()
685 receiveCoinsAction->setChecked(true);
686 centralWidget->setCurrentWidget(receiveCoinsPage);
688 exportAction->setEnabled(true);
689 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
690 connect(exportAction, SIGNAL(triggered()), receiveCoinsPage, SLOT(exportClicked()));
693 void BitcoinGUI::gotoSendCoinsPage()
695 sendCoinsAction->setChecked(true);
696 centralWidget->setCurrentWidget(sendCoinsPage);
698 exportAction->setEnabled(false);
699 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
702 void BitcoinGUI::gotoMessagePage()
704 #ifdef FIRST_CLASS_MESSAGING
705 messageAction->setChecked(true);
706 centralWidget->setCurrentWidget(messagePage);
708 exportAction->setEnabled(false);
709 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
712 messagePage->setFocus();
716 void BitcoinGUI::gotoMessagePage(QString addr)
719 messagePage->setAddress(addr);
722 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
725 if(event->mimeData()->hasUrls())
726 event->acceptProposedAction();
729 void BitcoinGUI::dropEvent(QDropEvent *event)
731 if(event->mimeData()->hasUrls())
734 QList<QUrl> uris = event->mimeData()->urls();
735 foreach(const QUrl &uri, uris)
737 sendCoinsPage->handleURI(uri.toString());
741 event->acceptProposedAction();
744 void BitcoinGUI::handleURI(QString strURI)
747 sendCoinsPage->handleURI(strURI);
749 if(!isActiveWindow())
752 showNormalIfMinimized();
755 void BitcoinGUI::setEncryptionStatus(int status)
759 case WalletModel::Unencrypted:
760 labelEncryptionIcon->hide();
761 encryptWalletAction->setChecked(false);
762 changePassphraseAction->setEnabled(false);
763 encryptWalletAction->setEnabled(true);
765 case WalletModel::Unlocked:
766 labelEncryptionIcon->show();
767 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
768 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
769 encryptWalletAction->setChecked(true);
770 changePassphraseAction->setEnabled(true);
771 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
773 case WalletModel::Locked:
774 labelEncryptionIcon->show();
775 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
776 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
777 encryptWalletAction->setChecked(true);
778 changePassphraseAction->setEnabled(true);
779 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
784 void BitcoinGUI::encryptWallet(bool status)
788 AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt:
789 AskPassphraseDialog::Decrypt, this);
790 dlg.setModel(walletModel);
793 setEncryptionStatus(walletModel->getEncryptionStatus());
796 void BitcoinGUI::backupWallet()
798 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
799 QString filename = QFileDialog::getSaveFileName(this, tr("Backup Wallet"), saveDir, tr("Wallet Data (*.dat)"));
800 if(!filename.isEmpty()) {
801 if(!walletModel->backupWallet(filename)) {
802 QMessageBox::warning(this, tr("Backup Failed"), tr("There was an error trying to save the wallet data to the new location."));
807 void BitcoinGUI::changePassphrase()
809 AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
810 dlg.setModel(walletModel);
814 void BitcoinGUI::unlockWallet()
818 // Unlock wallet when requested by wallet model
819 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
821 AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
822 dlg.setModel(walletModel);
827 void BitcoinGUI::showNormalIfMinimized()
829 if(!isVisible()) // Show, if hidden
831 if(isMinimized()) // Unminimize, if minimized