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>
53 #include <QDragEnterEvent>
58 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)
92 overviewPage = new OverviewPage();
94 transactionsPage = new QWidget(this);
95 QVBoxLayout *vbox = new QVBoxLayout();
96 transactionView = new TransactionView(this);
97 vbox->addWidget(transactionView);
98 transactionsPage->setLayout(vbox);
100 addressBookPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::SendingTab);
102 receiveCoinsPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::ReceivingTab);
104 sendCoinsPage = new SendCoinsDialog(this);
106 messagePage = new MessagePage(this);
108 centralWidget = new QStackedWidget(this);
109 centralWidget->addWidget(overviewPage);
110 centralWidget->addWidget(transactionsPage);
111 centralWidget->addWidget(addressBookPage);
112 centralWidget->addWidget(receiveCoinsPage);
113 centralWidget->addWidget(sendCoinsPage);
114 #ifdef FIRST_CLASS_MESSAGING
115 centralWidget->addWidget(messagePage);
117 setCentralWidget(centralWidget);
122 // Status bar notification icons
123 QFrame *frameBlocks = new QFrame();
124 frameBlocks->setContentsMargins(0,0,0,0);
125 frameBlocks->setMinimumWidth(56);
126 frameBlocks->setMaximumWidth(56);
127 QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);
128 frameBlocksLayout->setContentsMargins(3,0,3,0);
129 frameBlocksLayout->setSpacing(3);
130 labelEncryptionIcon = new QLabel();
131 labelConnectionsIcon = new QLabel();
132 labelBlocksIcon = new QLabel();
133 frameBlocksLayout->addStretch();
134 frameBlocksLayout->addWidget(labelEncryptionIcon);
135 frameBlocksLayout->addStretch();
136 frameBlocksLayout->addWidget(labelConnectionsIcon);
137 frameBlocksLayout->addStretch();
138 frameBlocksLayout->addWidget(labelBlocksIcon);
139 frameBlocksLayout->addStretch();
141 // Progress bar for blocks download
142 progressBarLabel = new QLabel(tr("Synchronizing with network..."));
143 progressBarLabel->setVisible(false);
144 progressBar = new QProgressBar();
145 progressBar->setToolTip(tr("Block chain synchronization in progress"));
146 progressBar->setVisible(false);
148 statusBar()->addWidget(progressBarLabel);
149 statusBar()->addWidget(progressBar);
150 statusBar()->addPermanentWidget(frameBlocks);
152 syncIconMovie = new QMovie(":/movies/update_spinner", "mng", this);
154 // Clicking on a transaction on the overview page simply sends you to transaction history page
155 connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), this, SLOT(gotoHistoryPage()));
157 // Doubleclicking on a transaction on the transaction history page shows details
158 connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
163 BitcoinGUI::~BitcoinGUI()
165 if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu)
172 void BitcoinGUI::createActions()
174 QActionGroup *tabGroup = new QActionGroup(this);
176 overviewAction = new QAction(QIcon(":/icons/overview"), tr("&Overview"), this);
177 overviewAction->setToolTip(tr("Show general overview of wallet"));
178 overviewAction->setCheckable(true);
179 overviewAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_1));
180 tabGroup->addAction(overviewAction);
182 historyAction = new QAction(QIcon(":/icons/history"), tr("&Transactions"), this);
183 historyAction->setToolTip(tr("Browse transaction history"));
184 historyAction->setCheckable(true);
185 historyAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_4));
186 tabGroup->addAction(historyAction);
188 addressBookAction = new QAction(QIcon(":/icons/address-book"), tr("&Address Book"), this);
189 addressBookAction->setToolTip(tr("Edit the list of stored addresses and labels"));
190 addressBookAction->setCheckable(true);
191 addressBookAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_5));
192 tabGroup->addAction(addressBookAction);
194 receiveCoinsAction = new QAction(QIcon(":/icons/receiving_addresses"), tr("&Receive coins"), this);
195 receiveCoinsAction->setToolTip(tr("Show the list of addresses for receiving payments"));
196 receiveCoinsAction->setCheckable(true);
197 receiveCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_3));
198 tabGroup->addAction(receiveCoinsAction);
200 sendCoinsAction = new QAction(QIcon(":/icons/send"), tr("&Send coins"), this);
201 sendCoinsAction->setToolTip(tr("Send coins to a bitcoin address"));
202 sendCoinsAction->setCheckable(true);
203 sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2));
204 tabGroup->addAction(sendCoinsAction);
206 messageAction = new QAction(QIcon(":/icons/edit"), tr("Sign &message"), this);
207 messageAction->setToolTip(tr("Prove you control an address"));
208 #ifdef FIRST_CLASS_MESSAGING
209 messageAction->setCheckable(true);
211 tabGroup->addAction(messageAction);
213 connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
214 connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage()));
215 connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
216 connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage()));
217 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
218 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(gotoAddressBookPage()));
219 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
220 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
221 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
222 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
223 connect(messageAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
224 connect(messageAction, SIGNAL(triggered()), this, SLOT(gotoMessagePage()));
226 quitAction = new QAction(QIcon(":/icons/quit"), tr("E&xit"), this);
227 quitAction->setToolTip(tr("Quit application"));
228 quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
229 quitAction->setMenuRole(QAction::QuitRole);
230 aboutAction = new QAction(QIcon(":/icons/bitcoin"), tr("&About %1").arg(qApp->applicationName()), this);
231 aboutAction->setToolTip(tr("Show information about Bitcoin"));
232 aboutAction->setMenuRole(QAction::AboutRole);
233 aboutQtAction = new QAction(tr("About &Qt"), this);
234 aboutQtAction->setToolTip(tr("Show information about Qt"));
235 aboutQtAction->setMenuRole(QAction::AboutQtRole);
236 optionsAction = new QAction(QIcon(":/icons/options"), tr("&Options..."), this);
237 optionsAction->setToolTip(tr("Modify configuration options for bitcoin"));
238 optionsAction->setMenuRole(QAction::PreferencesRole);
239 openBitcoinAction = new QAction(QIcon(":/icons/bitcoin"), tr("Open &Bitcoin"), this);
240 openBitcoinAction->setToolTip(tr("Show the Bitcoin window"));
241 exportAction = new QAction(QIcon(":/icons/export"), tr("&Export..."), this);
242 exportAction->setToolTip(tr("Export the data in the current tab to a file"));
243 encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet"), this);
244 encryptWalletAction->setToolTip(tr("Encrypt or decrypt wallet"));
245 encryptWalletAction->setCheckable(true);
246 backupWalletAction = new QAction(QIcon(":/icons/filesave"), tr("&Backup Wallet"), this);
247 backupWalletAction->setToolTip(tr("Backup wallet to another location"));
248 changePassphraseAction = new QAction(QIcon(":/icons/key"), tr("&Change Passphrase"), this);
249 changePassphraseAction->setToolTip(tr("Change the passphrase used for wallet encryption"));
251 connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
252 connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked()));
253 connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked()));
254 connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
255 connect(openBitcoinAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
256 connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool)));
257 connect(backupWalletAction, SIGNAL(triggered()), this, SLOT(backupWallet()));
258 connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase()));
261 void BitcoinGUI::createMenuBar()
264 // Create a decoupled menu bar on Mac which stays even if the window is closed
265 appMenuBar = new QMenuBar();
267 // Get the main window's menu bar on other platforms
268 appMenuBar = menuBar();
271 // Configure the menus
272 QMenu *file = appMenuBar->addMenu(tr("&File"));
273 file->addAction(backupWalletAction);
274 file->addAction(exportAction);
275 #ifndef FIRST_CLASS_MESSAGING
276 file->addAction(messageAction);
278 file->addSeparator();
279 file->addAction(quitAction);
281 QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
282 settings->addAction(encryptWalletAction);
283 settings->addAction(changePassphraseAction);
284 settings->addSeparator();
285 settings->addAction(optionsAction);
287 QMenu *help = appMenuBar->addMenu(tr("&Help"));
288 help->addAction(aboutAction);
289 help->addAction(aboutQtAction);
292 void BitcoinGUI::createToolBars()
294 QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));
295 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
296 toolbar->addAction(overviewAction);
297 toolbar->addAction(sendCoinsAction);
298 toolbar->addAction(receiveCoinsAction);
299 toolbar->addAction(historyAction);
300 toolbar->addAction(addressBookAction);
301 #ifdef FIRST_CLASS_MESSAGING
302 toolbar->addAction(messageAction);
305 QToolBar *toolbar2 = addToolBar(tr("Actions toolbar"));
306 toolbar2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
307 toolbar2->addAction(exportAction);
310 void BitcoinGUI::setClientModel(ClientModel *clientModel)
312 this->clientModel = clientModel;
315 if(clientModel->isTestNet())
317 QString title_testnet = windowTitle() + QString(" ") + tr("[testnet]");
318 setWindowTitle(title_testnet);
320 setWindowIcon(QIcon(":icons/bitcoin_testnet"));
322 MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
326 trayIcon->setToolTip(title_testnet);
327 trayIcon->setIcon(QIcon(":/icons/toolbar_testnet"));
331 // Keep up to date with client
332 setNumConnections(clientModel->getNumConnections());
333 connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
335 setNumBlocks(clientModel->getNumBlocks());
336 connect(clientModel, SIGNAL(numBlocksChanged(int)), this, SLOT(setNumBlocks(int)));
338 // Report errors from network/worker thread
339 connect(clientModel, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString)));
343 void BitcoinGUI::setWalletModel(WalletModel *walletModel)
345 this->walletModel = walletModel;
348 // Report errors from wallet thread
349 connect(walletModel, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString)));
351 // Put transaction list in tabs
352 transactionView->setModel(walletModel);
354 overviewPage->setModel(walletModel);
355 addressBookPage->setModel(walletModel->getAddressTableModel());
356 receiveCoinsPage->setModel(walletModel->getAddressTableModel());
357 sendCoinsPage->setModel(walletModel);
358 messagePage->setModel(walletModel);
360 setEncryptionStatus(walletModel->getEncryptionStatus());
361 connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));
363 // Balloon popup for new transaction
364 connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
365 this, SLOT(incomingTransaction(QModelIndex,int,int)));
367 // Ask for passphrase if needed
368 connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
372 void BitcoinGUI::createTrayIcon()
376 trayIcon = new QSystemTrayIcon(this);
377 trayIconMenu = new QMenu(this);
378 trayIcon->setContextMenu(trayIconMenu);
379 trayIcon->setToolTip("Bitcoin client");
380 trayIcon->setIcon(QIcon(":/icons/toolbar"));
381 connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
382 this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
385 // Note: On Mac, the dock icon is used to provide the tray's functionality.
386 MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance();
387 connect(dockIconHandler, SIGNAL(dockIconClicked()), openBitcoinAction, SLOT(trigger()));
388 trayIconMenu = dockIconHandler->dockMenu();
391 // Configuration of the tray icon (or dock icon) icon menu
392 trayIconMenu->addAction(openBitcoinAction);
393 trayIconMenu->addSeparator();
394 trayIconMenu->addAction(messageAction);
395 #ifndef FIRST_CLASS_MESSAGING
396 trayIconMenu->addSeparator();
398 trayIconMenu->addAction(receiveCoinsAction);
399 trayIconMenu->addAction(sendCoinsAction);
400 trayIconMenu->addSeparator();
401 trayIconMenu->addAction(optionsAction);
402 #ifndef Q_WS_MAC // This is built-in on Mac
403 trayIconMenu->addSeparator();
404 trayIconMenu->addAction(quitAction);
407 notificator = new Notificator(tr("bitcoin-qt"), trayIcon);
411 void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
413 if(reason == QSystemTrayIcon::Trigger)
415 // Click on system tray icon triggers "open bitcoin"
416 openBitcoinAction->trigger();
421 void BitcoinGUI::optionsClicked()
423 if(!clientModel || !clientModel->getOptionsModel())
426 dlg.setModel(clientModel->getOptionsModel());
430 void BitcoinGUI::aboutClicked()
433 dlg.setModel(clientModel);
437 void BitcoinGUI::setNumConnections(int count)
442 case 0: icon = ":/icons/connect_0"; break;
443 case 1: case 2: case 3: icon = ":/icons/connect_1"; break;
444 case 4: case 5: case 6: icon = ":/icons/connect_2"; break;
445 case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
446 default: icon = ":/icons/connect_4"; break;
448 labelConnectionsIcon->setPixmap(QIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
449 labelConnectionsIcon->setToolTip(tr("%n active connection(s) to Bitcoin network", "", count));
452 void BitcoinGUI::setNumBlocks(int count)
456 int total = clientModel->getNumBlocksOfPeers();
461 if (clientModel->getStatusBarWarnings() == "")
463 progressBarLabel->setVisible(true);
464 progressBarLabel->setText(tr("Synchronizing with network..."));
465 progressBar->setVisible(true);
466 progressBar->setMaximum(total);
467 progressBar->setValue(count);
471 progressBarLabel->setText(clientModel->getStatusBarWarnings());
472 progressBarLabel->setVisible(true);
473 progressBar->setVisible(false);
475 tooltip = tr("Downloaded %1 of %2 blocks of transaction history.").arg(count).arg(total);
479 if (clientModel->getStatusBarWarnings() == "")
480 progressBarLabel->setVisible(false);
483 progressBarLabel->setText(clientModel->getStatusBarWarnings());
484 progressBarLabel->setVisible(true);
486 progressBar->setVisible(false);
487 tooltip = tr("Downloaded %1 blocks of transaction history.").arg(count);
490 QDateTime now = QDateTime::currentDateTime();
491 QDateTime lastBlockDate = clientModel->getLastBlockDate();
492 int secs = lastBlockDate.secsTo(now);
495 // Represent time from last generated block in human readable text
498 // Fully up to date. Leave text empty.
502 text = tr("%n second(s) ago","",secs);
504 else if(secs < 60*60)
506 text = tr("%n minute(s) ago","",secs/60);
508 else if(secs < 24*60*60)
510 text = tr("%n hour(s) ago","",secs/(60*60));
514 text = tr("%n day(s) ago","",secs/(60*60*24));
517 // Set icon state: spinning if catching up, tick otherwise
520 tooltip = tr("Up to date") + QString(".\n") + tooltip;
521 labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
525 tooltip = tr("Catching up...") + QString("\n") + tooltip;
526 labelBlocksIcon->setMovie(syncIconMovie);
527 syncIconMovie->start();
532 tooltip += QString("\n");
533 tooltip += tr("Last received block was generated %1.").arg(text);
536 labelBlocksIcon->setToolTip(tooltip);
537 progressBarLabel->setToolTip(tooltip);
538 progressBar->setToolTip(tooltip);
541 void BitcoinGUI::refreshStatusBar()
543 /* Might display multiple times in the case of multiple alerts
544 static QString prevStatusBar;
545 QString newStatusBar = clientModel->getStatusBarWarnings();
546 if (prevStatusBar != newStatusBar)
548 prevStatusBar = newStatusBar;
549 error(tr("Network Alert"), newStatusBar);
551 setNumBlocks(clientModel->getNumBlocks());
554 void BitcoinGUI::error(const QString &title, const QString &message, bool modal)
556 // Report errors from network/worker thread
559 QMessageBox::critical(this, title, message, QMessageBox::Ok, QMessageBox::Ok);
561 notificator->notify(Notificator::Critical, title, message);
565 void BitcoinGUI::changeEvent(QEvent *e)
567 QMainWindow::changeEvent(e);
568 #ifndef Q_WS_MAC // Ignored on Mac
569 if(e->type() == QEvent::WindowStateChange)
571 if(clientModel && clientModel->getOptionsModel()->getMinimizeToTray())
573 QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
574 if(!(wsevt->oldState() & Qt::WindowMinimized) && isMinimized())
576 QTimer::singleShot(0, this, SLOT(hide()));
584 void BitcoinGUI::closeEvent(QCloseEvent *event)
588 #ifndef Q_WS_MAC // Ignored on Mac
589 if(!clientModel->getOptionsModel()->getMinimizeToTray() &&
590 !clientModel->getOptionsModel()->getMinimizeOnClose())
596 QMainWindow::closeEvent(event);
599 void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
602 tr("This transaction is over the size limit. You can still send it for a fee of %1, "
603 "which goes to the nodes that process your transaction and helps to support the network. "
604 "Do you want to pay the fee?").arg(
605 BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nFeeRequired));
606 QMessageBox::StandardButton retval = QMessageBox::question(
607 this, tr("Sending..."), strMessage,
608 QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes);
609 *payFee = (retval == QMessageBox::Yes);
612 void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
614 if(!walletModel || !clientModel)
616 TransactionTableModel *ttm = walletModel->getTransactionTableModel();
617 qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
618 .data(Qt::EditRole).toULongLong();
619 if(!clientModel->inInitialBlockDownload())
621 // On new transaction, make an info balloon
622 // Unless the initial block download is in progress, to prevent balloon-spam
623 QString date = ttm->index(start, TransactionTableModel::Date, parent)
625 QString type = ttm->index(start, TransactionTableModel::Type, parent)
627 QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
629 QIcon icon = qvariant_cast<QIcon>(ttm->index(start,
630 TransactionTableModel::ToAddress, parent)
631 .data(Qt::DecorationRole));
633 notificator->notify(Notificator::Information,
634 (amount)<0 ? tr("Sent transaction") :
635 tr("Incoming transaction"),
641 .arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true))
643 .arg(address), icon);
647 void BitcoinGUI::gotoOverviewPage()
649 overviewAction->setChecked(true);
650 centralWidget->setCurrentWidget(overviewPage);
652 exportAction->setEnabled(false);
653 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
656 void BitcoinGUI::gotoHistoryPage()
658 historyAction->setChecked(true);
659 centralWidget->setCurrentWidget(transactionsPage);
661 exportAction->setEnabled(true);
662 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
663 connect(exportAction, SIGNAL(triggered()), transactionView, SLOT(exportClicked()));
666 void BitcoinGUI::gotoAddressBookPage()
668 addressBookAction->setChecked(true);
669 centralWidget->setCurrentWidget(addressBookPage);
671 exportAction->setEnabled(true);
672 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
673 connect(exportAction, SIGNAL(triggered()), addressBookPage, SLOT(exportClicked()));
676 void BitcoinGUI::gotoReceiveCoinsPage()
678 receiveCoinsAction->setChecked(true);
679 centralWidget->setCurrentWidget(receiveCoinsPage);
681 exportAction->setEnabled(true);
682 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
683 connect(exportAction, SIGNAL(triggered()), receiveCoinsPage, SLOT(exportClicked()));
686 void BitcoinGUI::gotoSendCoinsPage()
688 sendCoinsAction->setChecked(true);
689 centralWidget->setCurrentWidget(sendCoinsPage);
691 exportAction->setEnabled(false);
692 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
695 void BitcoinGUI::gotoMessagePage()
697 #ifdef FIRST_CLASS_MESSAGING
698 messageAction->setChecked(true);
699 centralWidget->setCurrentWidget(messagePage);
701 exportAction->setEnabled(false);
702 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
705 messagePage->setFocus();
709 void BitcoinGUI::gotoMessagePage(QString addr)
712 messagePage->setAddress(addr);
715 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
718 if(event->mimeData()->hasUrls())
719 event->acceptProposedAction();
722 void BitcoinGUI::dropEvent(QDropEvent *event)
724 if(event->mimeData()->hasUrls())
727 QList<QUrl> urls = event->mimeData()->urls();
728 foreach(const QUrl &url, urls)
730 sendCoinsPage->handleURL(url.toString());
734 event->acceptProposedAction();
737 void BitcoinGUI::handleURL(QString strURL)
740 sendCoinsPage->handleURL(strURL);
742 if(!isActiveWindow())
745 showNormalIfMinimized();
748 void BitcoinGUI::setEncryptionStatus(int status)
752 case WalletModel::Unencrypted:
753 labelEncryptionIcon->hide();
754 encryptWalletAction->setChecked(false);
755 changePassphraseAction->setEnabled(false);
756 encryptWalletAction->setEnabled(true);
758 case WalletModel::Unlocked:
759 labelEncryptionIcon->show();
760 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
761 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
762 encryptWalletAction->setChecked(true);
763 changePassphraseAction->setEnabled(true);
764 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
766 case WalletModel::Locked:
767 labelEncryptionIcon->show();
768 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
769 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
770 encryptWalletAction->setChecked(true);
771 changePassphraseAction->setEnabled(true);
772 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
777 void BitcoinGUI::encryptWallet(bool status)
781 AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt:
782 AskPassphraseDialog::Decrypt, this);
783 dlg.setModel(walletModel);
786 setEncryptionStatus(walletModel->getEncryptionStatus());
789 void BitcoinGUI::backupWallet()
791 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
792 QString filename = QFileDialog::getSaveFileName(this, tr("Backup Wallet"), saveDir, tr("Wallet Data (*.dat)"));
793 if(!filename.isEmpty()) {
794 if(!walletModel->backupWallet(filename)) {
795 QMessageBox::warning(this, tr("Backup Failed"), tr("There was an error trying to save the wallet data to the new location."));
800 void BitcoinGUI::changePassphrase()
802 AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
803 dlg.setModel(walletModel);
807 void BitcoinGUI::unlockWallet()
811 // Unlock wallet when requested by wallet model
812 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
814 AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
815 dlg.setModel(walletModel);
820 void BitcoinGUI::showNormalIfMinimized()
822 if(!isVisible()) // Show, if hidden
824 if(isMinimized()) // Unminimize, if minimized