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 and label for blocks download
142 progressBarLabel = new QLabel();
143 progressBarLabel->setVisible(false);
144 progressBar = new QProgressBar();
145 progressBar->setVisible(false);
147 statusBar()->addWidget(progressBarLabel);
148 statusBar()->addWidget(progressBar);
149 statusBar()->addPermanentWidget(frameBlocks);
151 // define progress bar format
152 progressBar->setFormat(tr("~%m blocks remaining"));
153 // define OS independent progress bar style (has to be after addWidget(), otherwise we crash)
154 progressBar->setStyleSheet("QProgressBar { background-color: transparent; border: 1px solid grey; border-radius: 5px; text-align: center; } QProgressBar::chunk { background: QLinearGradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 #FF8000, stop: 1 orange); margin: 0px; }");
156 syncIconMovie = new QMovie(":/movies/update_spinner", "mng", this);
158 // Clicking on a transaction on the overview page simply sends you to transaction history page
159 connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), this, SLOT(gotoHistoryPage()));
161 // Doubleclicking on a transaction on the transaction history page shows details
162 connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
167 BitcoinGUI::~BitcoinGUI()
169 if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu)
176 void BitcoinGUI::createActions()
178 QActionGroup *tabGroup = new QActionGroup(this);
180 overviewAction = new QAction(QIcon(":/icons/overview"), tr("&Overview"), this);
181 overviewAction->setToolTip(tr("Show general overview of wallet"));
182 overviewAction->setCheckable(true);
183 overviewAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_1));
184 tabGroup->addAction(overviewAction);
186 historyAction = new QAction(QIcon(":/icons/history"), tr("&Transactions"), this);
187 historyAction->setToolTip(tr("Browse transaction history"));
188 historyAction->setCheckable(true);
189 historyAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_4));
190 tabGroup->addAction(historyAction);
192 addressBookAction = new QAction(QIcon(":/icons/address-book"), tr("&Address Book"), this);
193 addressBookAction->setToolTip(tr("Edit the list of stored addresses and labels"));
194 addressBookAction->setCheckable(true);
195 addressBookAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_5));
196 tabGroup->addAction(addressBookAction);
198 receiveCoinsAction = new QAction(QIcon(":/icons/receiving_addresses"), tr("&Receive coins"), this);
199 receiveCoinsAction->setToolTip(tr("Show the list of addresses for receiving payments"));
200 receiveCoinsAction->setCheckable(true);
201 receiveCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_3));
202 tabGroup->addAction(receiveCoinsAction);
204 sendCoinsAction = new QAction(QIcon(":/icons/send"), tr("&Send coins"), this);
205 sendCoinsAction->setToolTip(tr("Send coins to a bitcoin address"));
206 sendCoinsAction->setCheckable(true);
207 sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2));
208 tabGroup->addAction(sendCoinsAction);
210 messageAction = new QAction(QIcon(":/icons/edit"), tr("Sign &message"), this);
211 messageAction->setToolTip(tr("Prove you control an address"));
212 #ifdef FIRST_CLASS_MESSAGING
213 messageAction->setCheckable(true);
215 tabGroup->addAction(messageAction);
217 connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
218 connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage()));
219 connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
220 connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage()));
221 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
222 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(gotoAddressBookPage()));
223 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
224 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
225 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
226 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
227 connect(messageAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
228 connect(messageAction, SIGNAL(triggered()), this, SLOT(gotoMessagePage()));
230 quitAction = new QAction(QIcon(":/icons/quit"), tr("E&xit"), this);
231 quitAction->setToolTip(tr("Quit application"));
232 quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
233 quitAction->setMenuRole(QAction::QuitRole);
234 aboutAction = new QAction(QIcon(":/icons/bitcoin"), tr("&About %1").arg(qApp->applicationName()), this);
235 aboutAction->setToolTip(tr("Show information about Bitcoin"));
236 aboutAction->setMenuRole(QAction::AboutRole);
237 aboutQtAction = new QAction(tr("About &Qt"), this);
238 aboutQtAction->setToolTip(tr("Show information about Qt"));
239 aboutQtAction->setMenuRole(QAction::AboutQtRole);
240 optionsAction = new QAction(QIcon(":/icons/options"), tr("&Options..."), this);
241 optionsAction->setToolTip(tr("Modify configuration options for bitcoin"));
242 optionsAction->setMenuRole(QAction::PreferencesRole);
243 openBitcoinAction = new QAction(QIcon(":/icons/bitcoin"), tr("Open &Bitcoin"), this);
244 openBitcoinAction->setToolTip(tr("Show the Bitcoin window"));
245 exportAction = new QAction(QIcon(":/icons/export"), tr("&Export..."), this);
246 exportAction->setToolTip(tr("Export the data in the current tab to a file"));
247 encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet"), this);
248 encryptWalletAction->setToolTip(tr("Encrypt or decrypt wallet"));
249 encryptWalletAction->setCheckable(true);
250 backupWalletAction = new QAction(QIcon(":/icons/filesave"), tr("&Backup Wallet"), this);
251 backupWalletAction->setToolTip(tr("Backup wallet to another location"));
252 changePassphraseAction = new QAction(QIcon(":/icons/key"), tr("&Change Passphrase"), this);
253 changePassphraseAction->setToolTip(tr("Change the passphrase used for wallet encryption"));
255 connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
256 connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked()));
257 connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked()));
258 connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
259 connect(openBitcoinAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
260 connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool)));
261 connect(backupWalletAction, SIGNAL(triggered()), this, SLOT(backupWallet()));
262 connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase()));
265 void BitcoinGUI::createMenuBar()
268 // Create a decoupled menu bar on Mac which stays even if the window is closed
269 appMenuBar = new QMenuBar();
271 // Get the main window's menu bar on other platforms
272 appMenuBar = menuBar();
275 // Configure the menus
276 QMenu *file = appMenuBar->addMenu(tr("&File"));
277 file->addAction(backupWalletAction);
278 file->addAction(exportAction);
279 #ifndef FIRST_CLASS_MESSAGING
280 file->addAction(messageAction);
282 file->addSeparator();
283 file->addAction(quitAction);
285 QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
286 settings->addAction(encryptWalletAction);
287 settings->addAction(changePassphraseAction);
288 settings->addSeparator();
289 settings->addAction(optionsAction);
291 QMenu *help = appMenuBar->addMenu(tr("&Help"));
292 help->addAction(aboutAction);
293 help->addAction(aboutQtAction);
296 void BitcoinGUI::createToolBars()
298 QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));
299 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
300 toolbar->addAction(overviewAction);
301 toolbar->addAction(sendCoinsAction);
302 toolbar->addAction(receiveCoinsAction);
303 toolbar->addAction(historyAction);
304 toolbar->addAction(addressBookAction);
305 #ifdef FIRST_CLASS_MESSAGING
306 toolbar->addAction(messageAction);
309 QToolBar *toolbar2 = addToolBar(tr("Actions toolbar"));
310 toolbar2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
311 toolbar2->addAction(exportAction);
314 void BitcoinGUI::setClientModel(ClientModel *clientModel)
316 this->clientModel = clientModel;
319 if(clientModel->isTestNet())
321 QString title_testnet = windowTitle() + QString(" ") + tr("[testnet]");
322 setWindowTitle(title_testnet);
324 setWindowIcon(QIcon(":icons/bitcoin_testnet"));
326 MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
330 trayIcon->setToolTip(title_testnet);
331 trayIcon->setIcon(QIcon(":/icons/toolbar_testnet"));
335 // Keep up to date with client
336 setNumConnections(clientModel->getNumConnections());
337 connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
339 setNumBlocks(clientModel->getNumBlocks());
340 connect(clientModel, SIGNAL(numBlocksChanged(int)), this, SLOT(setNumBlocks(int)));
342 // Report errors from network/worker thread
343 connect(clientModel, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString)));
347 void BitcoinGUI::setWalletModel(WalletModel *walletModel)
349 this->walletModel = walletModel;
352 // Report errors from wallet thread
353 connect(walletModel, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString)));
355 // Put transaction list in tabs
356 transactionView->setModel(walletModel);
358 overviewPage->setModel(walletModel);
359 addressBookPage->setModel(walletModel->getAddressTableModel());
360 receiveCoinsPage->setModel(walletModel->getAddressTableModel());
361 sendCoinsPage->setModel(walletModel);
362 messagePage->setModel(walletModel);
364 setEncryptionStatus(walletModel->getEncryptionStatus());
365 connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));
367 // Balloon popup for new transaction
368 connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
369 this, SLOT(incomingTransaction(QModelIndex,int,int)));
371 // Ask for passphrase if needed
372 connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
376 void BitcoinGUI::createTrayIcon()
380 trayIcon = new QSystemTrayIcon(this);
381 trayIconMenu = new QMenu(this);
382 trayIcon->setContextMenu(trayIconMenu);
383 trayIcon->setToolTip(tr("Bitcoin client"));
384 trayIcon->setIcon(QIcon(":/icons/toolbar"));
385 connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
386 this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
389 // Note: On Mac, the dock icon is used to provide the tray's functionality.
390 MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance();
391 connect(dockIconHandler, SIGNAL(dockIconClicked()), openBitcoinAction, SLOT(trigger()));
392 trayIconMenu = dockIconHandler->dockMenu();
395 // Configuration of the tray icon (or dock icon) icon menu
396 trayIconMenu->addAction(openBitcoinAction);
397 trayIconMenu->addSeparator();
398 trayIconMenu->addAction(messageAction);
399 #ifndef FIRST_CLASS_MESSAGING
400 trayIconMenu->addSeparator();
402 trayIconMenu->addAction(receiveCoinsAction);
403 trayIconMenu->addAction(sendCoinsAction);
404 trayIconMenu->addSeparator();
405 trayIconMenu->addAction(optionsAction);
406 #ifndef Q_WS_MAC // This is built-in on Mac
407 trayIconMenu->addSeparator();
408 trayIconMenu->addAction(quitAction);
411 notificator = new Notificator(tr("bitcoin-qt"), trayIcon);
415 void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
417 if(reason == QSystemTrayIcon::Trigger)
419 // Click on system tray icon triggers "open bitcoin"
420 openBitcoinAction->trigger();
425 void BitcoinGUI::optionsClicked()
427 if(!clientModel || !clientModel->getOptionsModel())
430 dlg.setModel(clientModel->getOptionsModel());
434 void BitcoinGUI::aboutClicked()
437 dlg.setModel(clientModel);
441 void BitcoinGUI::setNumConnections(int count)
446 case 0: icon = ":/icons/connect_0"; break;
447 case 1: case 2: case 3: icon = ":/icons/connect_1"; break;
448 case 4: case 5: case 6: icon = ":/icons/connect_2"; break;
449 case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
450 default: icon = ":/icons/connect_4"; break;
452 labelConnectionsIcon->setPixmap(QIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
453 labelConnectionsIcon->setToolTip(tr("%n active connection(s) to Bitcoin network", "", count));
456 void BitcoinGUI::setNumBlocks(int count)
458 // don't show / hide progressBar and it's label if we have no connection(s) to the network
459 if (!clientModel || clientModel->getNumConnections() == 0)
461 progressBarLabel->setVisible(false);
462 progressBar->setVisible(false);
467 int nTotal = clientModel->getNumBlocksOfPeers();
472 int nCurMax = nTotal - count;
473 int nOnePercentCurMax = nCurMax / 100;
474 int nPercentageDone = (count / (nTotal / 100));
476 if (clientModel->getStatusBarWarnings() == "")
478 progressBarLabel->setText(tr("Synchronizing with network..."));
479 progressBarLabel->setVisible(true);
480 progressBar->setMaximum(nCurMax);
481 progressBar->setValue(nOnePercentCurMax * nPercentageDone);
482 progressBar->setVisible(true);
486 progressBarLabel->setText(clientModel->getStatusBarWarnings());
487 progressBarLabel->setVisible(true);
488 progressBar->setVisible(false);
490 tooltip = tr("Downloaded %1 of %2 blocks of transaction history (%3% done).").arg(count).arg(nTotal).arg(nPercentageDone);
494 if (clientModel->getStatusBarWarnings() == "")
495 progressBarLabel->setVisible(false);
498 progressBarLabel->setText(clientModel->getStatusBarWarnings());
499 progressBarLabel->setVisible(true);
501 progressBar->setVisible(false);
502 tooltip = tr("Downloaded %1 blocks of transaction history.").arg(count);
505 QDateTime now = QDateTime::currentDateTime();
506 QDateTime lastBlockDate = clientModel->getLastBlockDate();
507 int secs = lastBlockDate.secsTo(now);
510 // Represent time from last generated block in human readable text
513 // Fully up to date. Leave text empty.
517 text = tr("%n second(s) ago","",secs);
519 else if(secs < 60*60)
521 text = tr("%n minute(s) ago","",secs/60);
523 else if(secs < 24*60*60)
525 text = tr("%n hour(s) ago","",secs/(60*60));
529 text = tr("%n day(s) ago","",secs/(60*60*24));
532 // Set icon state: spinning if catching up, tick otherwise
535 tooltip = tr("Up to date") + QString(".\n") + tooltip;
536 labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
540 tooltip = tr("Catching up...") + QString("\n") + tooltip;
541 labelBlocksIcon->setMovie(syncIconMovie);
542 syncIconMovie->start();
547 tooltip += QString("\n");
548 tooltip += tr("Last received block was generated %1.").arg(text);
551 labelBlocksIcon->setToolTip(tooltip);
552 progressBarLabel->setToolTip(tooltip);
553 progressBar->setToolTip(tooltip);
556 void BitcoinGUI::refreshStatusBar()
558 /* Might display multiple times in the case of multiple alerts
559 static QString prevStatusBar;
560 QString newStatusBar = clientModel->getStatusBarWarnings();
561 if (prevStatusBar != newStatusBar)
563 prevStatusBar = newStatusBar;
564 error(tr("Network Alert"), newStatusBar);
566 setNumBlocks(clientModel->getNumBlocks());
569 void BitcoinGUI::error(const QString &title, const QString &message)
571 // Report errors from network/worker thread
572 notificator->notify(Notificator::Critical, title, message);
575 void BitcoinGUI::changeEvent(QEvent *e)
577 QMainWindow::changeEvent(e);
578 #ifndef Q_WS_MAC // Ignored on Mac
579 if(e->type() == QEvent::WindowStateChange)
581 if(clientModel && clientModel->getOptionsModel()->getMinimizeToTray())
583 QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
584 if(!(wsevt->oldState() & Qt::WindowMinimized) && isMinimized())
586 QTimer::singleShot(0, this, SLOT(hide()));
594 void BitcoinGUI::closeEvent(QCloseEvent *event)
598 #ifndef Q_WS_MAC // Ignored on Mac
599 if(!clientModel->getOptionsModel()->getMinimizeToTray() &&
600 !clientModel->getOptionsModel()->getMinimizeOnClose())
606 QMainWindow::closeEvent(event);
609 void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
612 tr("This transaction is over the size limit. You can still send it for a fee of %1, "
613 "which goes to the nodes that process your transaction and helps to support the network. "
614 "Do you want to pay the fee?").arg(
615 BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nFeeRequired));
616 QMessageBox::StandardButton retval = QMessageBox::question(
617 this, tr("Sending..."), strMessage,
618 QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes);
619 *payFee = (retval == QMessageBox::Yes);
622 void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
624 if(!walletModel || !clientModel)
626 TransactionTableModel *ttm = walletModel->getTransactionTableModel();
627 qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
628 .data(Qt::EditRole).toULongLong();
629 if(!clientModel->inInitialBlockDownload())
631 // On new transaction, make an info balloon
632 // Unless the initial block download is in progress, to prevent balloon-spam
633 QString date = ttm->index(start, TransactionTableModel::Date, parent)
635 QString type = ttm->index(start, TransactionTableModel::Type, parent)
637 QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
639 QIcon icon = qvariant_cast<QIcon>(ttm->index(start,
640 TransactionTableModel::ToAddress, parent)
641 .data(Qt::DecorationRole));
643 notificator->notify(Notificator::Information,
644 (amount)<0 ? tr("Sent transaction") :
645 tr("Incoming transaction"),
651 .arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true))
653 .arg(address), icon);
657 void BitcoinGUI::gotoOverviewPage()
659 overviewAction->setChecked(true);
660 centralWidget->setCurrentWidget(overviewPage);
662 exportAction->setEnabled(false);
663 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
666 void BitcoinGUI::gotoHistoryPage()
668 historyAction->setChecked(true);
669 centralWidget->setCurrentWidget(transactionsPage);
671 exportAction->setEnabled(true);
672 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
673 connect(exportAction, SIGNAL(triggered()), transactionView, SLOT(exportClicked()));
676 void BitcoinGUI::gotoAddressBookPage()
678 addressBookAction->setChecked(true);
679 centralWidget->setCurrentWidget(addressBookPage);
681 exportAction->setEnabled(true);
682 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
683 connect(exportAction, SIGNAL(triggered()), addressBookPage, SLOT(exportClicked()));
686 void BitcoinGUI::gotoReceiveCoinsPage()
688 receiveCoinsAction->setChecked(true);
689 centralWidget->setCurrentWidget(receiveCoinsPage);
691 exportAction->setEnabled(true);
692 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
693 connect(exportAction, SIGNAL(triggered()), receiveCoinsPage, SLOT(exportClicked()));
696 void BitcoinGUI::gotoSendCoinsPage()
698 sendCoinsAction->setChecked(true);
699 centralWidget->setCurrentWidget(sendCoinsPage);
701 exportAction->setEnabled(false);
702 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
705 void BitcoinGUI::gotoMessagePage()
707 #ifdef FIRST_CLASS_MESSAGING
708 messageAction->setChecked(true);
709 centralWidget->setCurrentWidget(messagePage);
711 exportAction->setEnabled(false);
712 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
715 messagePage->setFocus();
719 void BitcoinGUI::gotoMessagePage(QString addr)
722 messagePage->setAddress(addr);
725 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
728 if(event->mimeData()->hasUrls())
729 event->acceptProposedAction();
732 void BitcoinGUI::dropEvent(QDropEvent *event)
734 if(event->mimeData()->hasUrls())
737 QList<QUrl> urls = event->mimeData()->urls();
738 foreach(const QUrl &url, urls)
740 sendCoinsPage->handleURL(url.toString());
744 event->acceptProposedAction();
747 void BitcoinGUI::handleURL(QString strURL)
750 sendCoinsPage->handleURL(strURL);
752 if(!isActiveWindow())
755 showNormalIfMinimized();
758 void BitcoinGUI::setEncryptionStatus(int status)
762 case WalletModel::Unencrypted:
763 labelEncryptionIcon->hide();
764 encryptWalletAction->setChecked(false);
765 changePassphraseAction->setEnabled(false);
766 encryptWalletAction->setEnabled(true);
768 case WalletModel::Unlocked:
769 labelEncryptionIcon->show();
770 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
771 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
772 encryptWalletAction->setChecked(true);
773 changePassphraseAction->setEnabled(true);
774 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
776 case WalletModel::Locked:
777 labelEncryptionIcon->show();
778 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
779 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
780 encryptWalletAction->setChecked(true);
781 changePassphraseAction->setEnabled(true);
782 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
787 void BitcoinGUI::encryptWallet(bool status)
791 AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt:
792 AskPassphraseDialog::Decrypt, this);
793 dlg.setModel(walletModel);
796 setEncryptionStatus(walletModel->getEncryptionStatus());
799 void BitcoinGUI::backupWallet()
801 QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
802 QString filename = QFileDialog::getSaveFileName(this, tr("Backup Wallet"), saveDir, tr("Wallet Data (*.dat)"));
803 if(!filename.isEmpty()) {
804 if(!walletModel->backupWallet(filename)) {
805 QMessageBox::warning(this, tr("Backup Failed"), tr("There was an error trying to save the wallet data to the new location."));
810 void BitcoinGUI::changePassphrase()
812 AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
813 dlg.setModel(walletModel);
817 void BitcoinGUI::unlockWallet()
821 // Unlock wallet when requested by wallet model
822 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
824 AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
825 dlg.setModel(walletModel);
830 void BitcoinGUI::showNormalIfMinimized()
832 if(!isVisible()) // Show, if hidden
834 if(isMinimized()) // Unminimize, if minimized