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>
50 #include <QDragEnterEvent>
55 BitcoinGUI::BitcoinGUI(QWidget *parent):
59 encryptWalletAction(0),
60 changePassphraseAction(0),
66 setWindowTitle(tr("Bitcoin Wallet"));
68 setWindowIcon(QIcon(":icons/bitcoin"));
70 setUnifiedTitleAndToolBarOnMac(true);
71 QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
76 // Create actions for the toolbar, menu bar and tray/dock icon
79 // Create application menu bar
82 // Create the toolbars
85 // Create the tray icon (or setup the dock icon)
89 overviewPage = new OverviewPage();
91 transactionsPage = new QWidget(this);
92 QVBoxLayout *vbox = new QVBoxLayout();
93 transactionView = new TransactionView(this);
94 vbox->addWidget(transactionView);
95 transactionsPage->setLayout(vbox);
97 addressBookPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::SendingTab);
99 receiveCoinsPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::ReceivingTab);
101 sendCoinsPage = new SendCoinsDialog(this);
103 messagePage = new MessagePage(this);
105 centralWidget = new QStackedWidget(this);
106 centralWidget->addWidget(overviewPage);
107 centralWidget->addWidget(transactionsPage);
108 centralWidget->addWidget(addressBookPage);
109 centralWidget->addWidget(receiveCoinsPage);
110 centralWidget->addWidget(sendCoinsPage);
111 #ifdef FIRST_CLASS_MESSAGING
112 centralWidget->addWidget(messagePage);
114 setCentralWidget(centralWidget);
119 // Status bar notification icons
120 QFrame *frameBlocks = new QFrame();
121 frameBlocks->setContentsMargins(0,0,0,0);
122 frameBlocks->setMinimumWidth(56);
123 frameBlocks->setMaximumWidth(56);
124 QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);
125 frameBlocksLayout->setContentsMargins(3,0,3,0);
126 frameBlocksLayout->setSpacing(3);
127 labelEncryptionIcon = new QLabel();
128 labelConnectionsIcon = new QLabel();
129 labelBlocksIcon = new QLabel();
130 frameBlocksLayout->addStretch();
131 frameBlocksLayout->addWidget(labelEncryptionIcon);
132 frameBlocksLayout->addStretch();
133 frameBlocksLayout->addWidget(labelConnectionsIcon);
134 frameBlocksLayout->addStretch();
135 frameBlocksLayout->addWidget(labelBlocksIcon);
136 frameBlocksLayout->addStretch();
138 // Progress bar for blocks download
139 progressBarLabel = new QLabel(tr("Synchronizing with network..."));
140 progressBarLabel->setVisible(false);
141 progressBar = new QProgressBar();
142 progressBar->setToolTip(tr("Block chain synchronization in progress"));
143 progressBar->setVisible(false);
145 statusBar()->addWidget(progressBarLabel);
146 statusBar()->addWidget(progressBar);
147 statusBar()->addPermanentWidget(frameBlocks);
149 syncIconMovie = new QMovie(":/movies/update_spinner", "mng", this);
151 // Clicking on a transaction on the overview page simply sends you to transaction history page
152 connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), this, SLOT(gotoHistoryPage()));
154 // Doubleclicking on a transaction on the transaction history page shows details
155 connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
160 BitcoinGUI::~BitcoinGUI()
167 void BitcoinGUI::createActions()
169 QActionGroup *tabGroup = new QActionGroup(this);
171 overviewAction = new QAction(QIcon(":/icons/overview"), tr("&Overview"), this);
172 overviewAction->setToolTip(tr("Show general overview of wallet"));
173 overviewAction->setCheckable(true);
174 overviewAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_1));
175 tabGroup->addAction(overviewAction);
177 historyAction = new QAction(QIcon(":/icons/history"), tr("&Transactions"), this);
178 historyAction->setToolTip(tr("Browse transaction history"));
179 historyAction->setCheckable(true);
180 historyAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_4));
181 tabGroup->addAction(historyAction);
183 addressBookAction = new QAction(QIcon(":/icons/address-book"), tr("&Address Book"), this);
184 addressBookAction->setToolTip(tr("Edit the list of stored addresses and labels"));
185 addressBookAction->setCheckable(true);
186 addressBookAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_5));
187 tabGroup->addAction(addressBookAction);
189 receiveCoinsAction = new QAction(QIcon(":/icons/receiving_addresses"), tr("&Receive coins"), this);
190 receiveCoinsAction->setToolTip(tr("Show the list of addresses for receiving payments"));
191 receiveCoinsAction->setCheckable(true);
192 receiveCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_3));
193 tabGroup->addAction(receiveCoinsAction);
195 sendCoinsAction = new QAction(QIcon(":/icons/send"), tr("&Send coins"), this);
196 sendCoinsAction->setToolTip(tr("Send coins to a bitcoin address"));
197 sendCoinsAction->setCheckable(true);
198 sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2));
199 tabGroup->addAction(sendCoinsAction);
201 messageAction = new QAction(QIcon(":/icons/edit"), tr("Sign &message"), this);
202 messageAction->setToolTip(tr("Prove you control an address"));
203 #ifdef FIRST_CLASS_MESSAGING
204 messageAction->setCheckable(true);
206 tabGroup->addAction(messageAction);
208 connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
209 connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage()));
210 connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
211 connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage()));
212 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
213 connect(addressBookAction, SIGNAL(triggered()), this, SLOT(gotoAddressBookPage()));
214 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
215 connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
216 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
217 connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
218 connect(messageAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
219 connect(messageAction, SIGNAL(triggered()), this, SLOT(gotoMessagePage()));
221 quitAction = new QAction(QIcon(":/icons/quit"), tr("E&xit"), this);
222 quitAction->setToolTip(tr("Quit application"));
223 quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
224 quitAction->setMenuRole(QAction::QuitRole);
225 aboutAction = new QAction(QIcon(":/icons/bitcoin"), tr("&About %1").arg(qApp->applicationName()), this);
226 aboutAction->setToolTip(tr("Show information about Bitcoin"));
227 aboutAction->setMenuRole(QAction::AboutRole);
228 aboutQtAction = new QAction(tr("About &Qt"), this);
229 aboutQtAction->setToolTip(tr("Show information about Qt"));
230 aboutQtAction->setMenuRole(QAction::AboutQtRole);
231 optionsAction = new QAction(QIcon(":/icons/options"), tr("&Options..."), this);
232 optionsAction->setToolTip(tr("Modify configuration options for bitcoin"));
233 optionsAction->setMenuRole(QAction::PreferencesRole);
234 openBitcoinAction = new QAction(QIcon(":/icons/bitcoin"), tr("Open &Bitcoin"), this);
235 openBitcoinAction->setToolTip(tr("Show the Bitcoin window"));
236 exportAction = new QAction(QIcon(":/icons/export"), tr("&Export..."), this);
237 exportAction->setToolTip(tr("Export the data in the current tab to a file"));
238 encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet"), this);
239 encryptWalletAction->setToolTip(tr("Encrypt or decrypt wallet"));
240 encryptWalletAction->setCheckable(true);
241 changePassphraseAction = new QAction(QIcon(":/icons/key"), tr("&Change Passphrase"), this);
242 changePassphraseAction->setToolTip(tr("Change the passphrase used for wallet encryption"));
244 connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
245 connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked()));
246 connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked()));
247 connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
248 connect(openBitcoinAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
249 connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool)));
250 connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase()));
253 void BitcoinGUI::createMenuBar()
256 // Create a decoupled menu bar on Mac which stays even if the window is closed
257 appMenuBar = new QMenuBar();
259 // Get the main window's menu bar on other platforms
260 appMenuBar = menuBar();
263 // Configure the menus
264 QMenu *file = appMenuBar->addMenu(tr("&File"));
265 file->addAction(exportAction);
266 #ifndef FIRST_CLASS_MESSAGING
267 file->addAction(messageAction);
268 file->addSeparator();
270 file->addAction(quitAction);
272 QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
273 settings->addAction(encryptWalletAction);
274 settings->addAction(changePassphraseAction);
275 settings->addSeparator();
276 settings->addAction(optionsAction);
278 QMenu *help = appMenuBar->addMenu(tr("&Help"));
279 help->addAction(aboutAction);
280 help->addAction(aboutQtAction);
283 void BitcoinGUI::createToolBars()
285 QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));
286 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
287 toolbar->addAction(overviewAction);
288 toolbar->addAction(sendCoinsAction);
289 toolbar->addAction(receiveCoinsAction);
290 toolbar->addAction(historyAction);
291 toolbar->addAction(addressBookAction);
292 #ifdef FIRST_CLASS_MESSAGING
293 toolbar->addAction(messageAction);
296 QToolBar *toolbar2 = addToolBar(tr("Actions toolbar"));
297 toolbar2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
298 toolbar2->addAction(exportAction);
301 void BitcoinGUI::setClientModel(ClientModel *clientModel)
303 this->clientModel = clientModel;
306 if(clientModel->isTestNet())
308 QString title_testnet = windowTitle() + QString(" ") + tr("[testnet]");
309 setWindowTitle(title_testnet);
311 setWindowIcon(QIcon(":icons/bitcoin_testnet"));
313 MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
317 trayIcon->setToolTip(title_testnet);
318 trayIcon->setIcon(QIcon(":/icons/toolbar_testnet"));
322 // Keep up to date with client
323 setNumConnections(clientModel->getNumConnections());
324 connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
326 setNumBlocks(clientModel->getNumBlocks());
327 connect(clientModel, SIGNAL(numBlocksChanged(int)), this, SLOT(setNumBlocks(int)));
329 // Report errors from network/worker thread
330 connect(clientModel, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString)));
334 void BitcoinGUI::setWalletModel(WalletModel *walletModel)
336 this->walletModel = walletModel;
339 // Report errors from wallet thread
340 connect(walletModel, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString)));
342 // Put transaction list in tabs
343 transactionView->setModel(walletModel);
345 overviewPage->setModel(walletModel);
346 addressBookPage->setModel(walletModel->getAddressTableModel());
347 receiveCoinsPage->setModel(walletModel->getAddressTableModel());
348 sendCoinsPage->setModel(walletModel);
349 messagePage->setModel(walletModel);
351 setEncryptionStatus(walletModel->getEncryptionStatus());
352 connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));
354 // Balloon popup for new transaction
355 connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
356 this, SLOT(incomingTransaction(QModelIndex,int,int)));
358 // Ask for passphrase if needed
359 connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
363 void BitcoinGUI::createTrayIcon()
367 trayIcon = new QSystemTrayIcon(this);
368 trayIconMenu = new QMenu(this);
369 trayIcon->setContextMenu(trayIconMenu);
370 trayIcon->setToolTip("Bitcoin client");
371 trayIcon->setIcon(QIcon(":/icons/toolbar"));
372 connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
373 this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
376 // Note: On Mac, the dock icon is used to provide the tray's functionality.
377 MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance();
378 connect(dockIconHandler, SIGNAL(dockIconClicked()), openBitcoinAction, SLOT(trigger()));
379 trayIconMenu = dockIconHandler->dockMenu();
382 // Configuration of the tray icon (or dock icon) icon menu
383 trayIconMenu->addAction(openBitcoinAction);
384 trayIconMenu->addSeparator();
385 trayIconMenu->addAction(messageAction);
386 #ifndef FIRST_CLASS_MESSAGING
387 trayIconMenu->addSeparator();
389 trayIconMenu->addAction(receiveCoinsAction);
390 trayIconMenu->addAction(sendCoinsAction);
391 trayIconMenu->addSeparator();
392 trayIconMenu->addAction(optionsAction);
393 #ifndef Q_WS_MAC // This is built-in on Mac
394 trayIconMenu->addSeparator();
395 trayIconMenu->addAction(quitAction);
398 notificator = new Notificator(tr("bitcoin-qt"), trayIcon);
402 void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
404 if(reason == QSystemTrayIcon::Trigger)
406 // Click on system tray icon triggers "open bitcoin"
407 openBitcoinAction->trigger();
412 void BitcoinGUI::optionsClicked()
414 if(!clientModel || !clientModel->getOptionsModel())
417 dlg.setModel(clientModel->getOptionsModel());
421 void BitcoinGUI::aboutClicked()
424 dlg.setModel(clientModel);
428 void BitcoinGUI::setNumConnections(int count)
433 case 0: icon = ":/icons/connect_0"; break;
434 case 1: case 2: case 3: icon = ":/icons/connect_1"; break;
435 case 4: case 5: case 6: icon = ":/icons/connect_2"; break;
436 case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
437 default: icon = ":/icons/connect_4"; break;
439 labelConnectionsIcon->setPixmap(QIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
440 labelConnectionsIcon->setToolTip(tr("%n active connection(s) to Bitcoin network", "", count));
443 void BitcoinGUI::setNumBlocks(int count)
447 int total = clientModel->getNumBlocksOfPeers();
452 if (clientModel->getStatusBarWarnings() == "")
454 progressBarLabel->setVisible(true);
455 progressBarLabel->setText(tr("Synchronizing with network..."));
456 progressBar->setVisible(true);
457 progressBar->setMaximum(total);
458 progressBar->setValue(count);
462 progressBarLabel->setText(clientModel->getStatusBarWarnings());
463 progressBarLabel->setVisible(true);
464 progressBar->setVisible(false);
466 tooltip = tr("Downloaded %1 of %2 blocks of transaction history.").arg(count).arg(total);
470 if (clientModel->getStatusBarWarnings() == "")
471 progressBarLabel->setVisible(false);
474 progressBarLabel->setText(clientModel->getStatusBarWarnings());
475 progressBarLabel->setVisible(true);
477 progressBar->setVisible(false);
478 tooltip = tr("Downloaded %1 blocks of transaction history.").arg(count);
481 QDateTime now = QDateTime::currentDateTime();
482 QDateTime lastBlockDate = clientModel->getLastBlockDate();
483 int secs = lastBlockDate.secsTo(now);
486 // Represent time from last generated block in human readable text
489 text = tr("%n second(s) ago","",secs);
491 else if(secs < 60*60)
493 text = tr("%n minute(s) ago","",secs/60);
495 else if(secs < 24*60*60)
497 text = tr("%n hour(s) ago","",secs/(60*60));
501 text = tr("%n day(s) ago","",secs/(60*60*24));
504 // Set icon state: spinning if catching up, tick otherwise
507 tooltip = tr("Up to date") + QString("\n") + tooltip;
508 labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
512 tooltip = tr("Catching up...") + QString("\n") + tooltip;
513 labelBlocksIcon->setMovie(syncIconMovie);
514 syncIconMovie->start();
517 tooltip += QString("\n");
518 tooltip += tr("Last received block was generated %1.").arg(text);
520 labelBlocksIcon->setToolTip(tooltip);
521 progressBarLabel->setToolTip(tooltip);
522 progressBar->setToolTip(tooltip);
525 void BitcoinGUI::refreshStatusBar()
527 /* Might display multiple times in the case of multiple alerts
528 static QString prevStatusBar;
529 QString newStatusBar = clientModel->getStatusBarWarnings();
530 if (prevStatusBar != newStatusBar)
532 prevStatusBar = newStatusBar;
533 error(tr("Network Alert"), newStatusBar);
535 setNumBlocks(clientModel->getNumBlocks());
538 void BitcoinGUI::error(const QString &title, const QString &message)
540 // Report errors from network/worker thread
541 notificator->notify(Notificator::Critical, title, message);
544 void BitcoinGUI::changeEvent(QEvent *e)
546 #ifndef Q_WS_MAC // Ignored on Mac
547 if(e->type() == QEvent::WindowStateChange)
549 if(clientModel && clientModel->getOptionsModel()->getMinimizeToTray())
551 QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
552 bool wasMinimized = wsevt->oldState() & Qt::WindowMinimized;
553 bool isMinimized = windowState() & Qt::WindowMinimized;
554 if(!wasMinimized && isMinimized)
556 // Minimized, hide the window from taskbar
557 setWindowFlags(windowFlags() | Qt::Tool);
560 else if(wasMinimized && !isMinimized)
562 // Unminimized, show the window in taskbar
563 setWindowFlags(windowFlags() &~ Qt::Tool);
568 QMainWindow::changeEvent(e);
571 void BitcoinGUI::closeEvent(QCloseEvent *event)
575 #ifndef Q_WS_MAC // Ignored on Mac
576 if(!clientModel->getOptionsModel()->getMinimizeToTray() &&
577 !clientModel->getOptionsModel()->getMinimizeOnClose())
583 QMainWindow::closeEvent(event);
586 void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
589 tr("This transaction is over the size limit. You can still send it for a fee of %1, "
590 "which goes to the nodes that process your transaction and helps to support the network. "
591 "Do you want to pay the fee?").arg(
592 BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nFeeRequired));
593 QMessageBox::StandardButton retval = QMessageBox::question(
594 this, tr("Sending..."), strMessage,
595 QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes);
596 *payFee = (retval == QMessageBox::Yes);
599 void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
601 if(!walletModel || !clientModel)
603 TransactionTableModel *ttm = walletModel->getTransactionTableModel();
604 qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
605 .data(Qt::EditRole).toULongLong();
606 if(!clientModel->inInitialBlockDownload())
608 // On new transaction, make an info balloon
609 // Unless the initial block download is in progress, to prevent balloon-spam
610 QString date = ttm->index(start, TransactionTableModel::Date, parent)
612 QString type = ttm->index(start, TransactionTableModel::Type, parent)
614 QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
616 QIcon icon = qvariant_cast<QIcon>(ttm->index(start,
617 TransactionTableModel::ToAddress, parent)
618 .data(Qt::DecorationRole));
620 notificator->notify(Notificator::Information,
621 (amount)<0 ? tr("Sent transaction") :
622 tr("Incoming transaction"),
628 .arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true))
630 .arg(address), icon);
634 void BitcoinGUI::gotoOverviewPage()
636 overviewAction->setChecked(true);
637 centralWidget->setCurrentWidget(overviewPage);
639 exportAction->setEnabled(false);
640 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
643 void BitcoinGUI::gotoHistoryPage()
645 historyAction->setChecked(true);
646 centralWidget->setCurrentWidget(transactionsPage);
648 exportAction->setEnabled(true);
649 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
650 connect(exportAction, SIGNAL(triggered()), transactionView, SLOT(exportClicked()));
653 void BitcoinGUI::gotoAddressBookPage()
655 addressBookAction->setChecked(true);
656 centralWidget->setCurrentWidget(addressBookPage);
658 exportAction->setEnabled(true);
659 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
660 connect(exportAction, SIGNAL(triggered()), addressBookPage, SLOT(exportClicked()));
663 void BitcoinGUI::gotoReceiveCoinsPage()
665 receiveCoinsAction->setChecked(true);
666 centralWidget->setCurrentWidget(receiveCoinsPage);
668 exportAction->setEnabled(true);
669 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
670 connect(exportAction, SIGNAL(triggered()), receiveCoinsPage, SLOT(exportClicked()));
673 void BitcoinGUI::gotoSendCoinsPage()
675 sendCoinsAction->setChecked(true);
676 centralWidget->setCurrentWidget(sendCoinsPage);
678 exportAction->setEnabled(false);
679 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
682 void BitcoinGUI::gotoMessagePage()
684 #ifdef FIRST_CLASS_MESSAGING
685 messageAction->setChecked(true);
686 centralWidget->setCurrentWidget(messagePage);
688 exportAction->setEnabled(false);
689 disconnect(exportAction, SIGNAL(triggered()), 0, 0);
692 messagePage->setFocus();
696 void BitcoinGUI::gotoMessagePage(QString addr)
699 messagePage->setAddress(addr);
702 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
705 if(event->mimeData()->hasUrls())
706 event->acceptProposedAction();
709 void BitcoinGUI::dropEvent(QDropEvent *event)
711 if(event->mimeData()->hasUrls())
714 QList<QUrl> urls = event->mimeData()->urls();
715 foreach(const QUrl &url, urls)
717 sendCoinsPage->handleURL(&url);
721 event->acceptProposedAction();
724 void BitcoinGUI::handleURL(QString strURL)
727 QUrl url = QUrl(strURL);
728 sendCoinsPage->handleURL(&url);
731 void BitcoinGUI::setEncryptionStatus(int status)
735 case WalletModel::Unencrypted:
736 labelEncryptionIcon->hide();
737 encryptWalletAction->setChecked(false);
738 changePassphraseAction->setEnabled(false);
739 encryptWalletAction->setEnabled(true);
741 case WalletModel::Unlocked:
742 labelEncryptionIcon->show();
743 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
744 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
745 encryptWalletAction->setChecked(true);
746 changePassphraseAction->setEnabled(true);
747 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
749 case WalletModel::Locked:
750 labelEncryptionIcon->show();
751 labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
752 labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
753 encryptWalletAction->setChecked(true);
754 changePassphraseAction->setEnabled(true);
755 encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
760 void BitcoinGUI::encryptWallet(bool status)
764 AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt:
765 AskPassphraseDialog::Decrypt, this);
766 dlg.setModel(walletModel);
769 setEncryptionStatus(walletModel->getEncryptionStatus());
772 void BitcoinGUI::changePassphrase()
774 AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
775 dlg.setModel(walletModel);
779 void BitcoinGUI::unlockWallet()
783 // Unlock wallet when requested by wallet model
784 if(walletModel->getEncryptionStatus() == WalletModel::Locked)
786 AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
787 dlg.setModel(walletModel);
792 void BitcoinGUI::showNormalIfMinimized()
794 if(!isVisible()) // Show, if hidden
796 if(isMinimized()) // Unminimize, if minimized