Fix status bar not displaying Alerts.
[novacoin.git] / src / qt / bitcoingui.cpp
1 /*
2  * Qt4 bitcoin GUI.
3  *
4  * W.J. van der Laan 2011
5  * The Bitcoin Developers 2011
6  */
7 #include "bitcoingui.h"
8 #include "transactiontablemodel.h"
9 #include "addressbookpage.h"
10 #include "sendcoinsdialog.h"
11 #include "optionsdialog.h"
12 #include "aboutdialog.h"
13 #include "clientmodel.h"
14 #include "walletmodel.h"
15 #include "editaddressdialog.h"
16 #include "optionsmodel.h"
17 #include "transactiondescdialog.h"
18 #include "addresstablemodel.h"
19 #include "transactionview.h"
20 #include "overviewpage.h"
21 #include "bitcoinunits.h"
22 #include "guiconstants.h"
23 #include "askpassphrasedialog.h"
24 #include "notificator.h"
25
26 #ifdef Q_WS_MAC
27 #include "macdockiconhandler.h"
28 #endif
29
30 #include <QApplication>
31 #include <QMainWindow>
32 #include <QMenuBar>
33 #include <QMenu>
34 #include <QIcon>
35 #include <QTabWidget>
36 #include <QVBoxLayout>
37 #include <QToolBar>
38 #include <QStatusBar>
39 #include <QLabel>
40 #include <QLineEdit>
41 #include <QPushButton>
42 #include <QLocale>
43 #include <QMessageBox>
44 #include <QProgressBar>
45 #include <QStackedWidget>
46 #include <QDateTime>
47 #include <QMovie>
48
49 #include <QDragEnterEvent>
50 #include <QUrl>
51
52 #include <iostream>
53
54 BitcoinGUI::BitcoinGUI(QWidget *parent):
55     QMainWindow(parent),
56     clientModel(0),
57     walletModel(0),
58     encryptWalletAction(0),
59     changePassphraseAction(0),
60     trayIcon(0),
61     notificator(0)
62 {
63     resize(850, 550);
64     setWindowTitle(tr("Bitcoin Wallet"));
65 #ifndef Q_WS_MAC
66     setWindowIcon(QIcon(":icons/bitcoin"));
67 #else
68     setUnifiedTitleAndToolBarOnMac(true);
69     QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
70 #endif
71     // Accept D&D of URIs
72     setAcceptDrops(true);
73
74     // Create actions for the toolbar, menu bar and tray/dock icon
75     createActions();
76
77     // Create application menu bar
78     createMenuBar();
79
80     // Create the toolbars
81     createToolBars();
82
83     // Create the tray icon (or setup the dock icon)
84     createTrayIcon();
85
86     // Create tabs
87     overviewPage = new OverviewPage();
88
89     transactionsPage = new QWidget(this);
90     QVBoxLayout *vbox = new QVBoxLayout();
91     transactionView = new TransactionView(this);
92     vbox->addWidget(transactionView);
93     transactionsPage->setLayout(vbox);
94
95     addressBookPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::SendingTab);
96
97     receiveCoinsPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::ReceivingTab);
98
99     sendCoinsPage = new SendCoinsDialog(this);
100
101     centralWidget = new QStackedWidget(this);
102     centralWidget->addWidget(overviewPage);
103     centralWidget->addWidget(transactionsPage);
104     centralWidget->addWidget(addressBookPage);
105     centralWidget->addWidget(receiveCoinsPage);
106     centralWidget->addWidget(sendCoinsPage);
107     setCentralWidget(centralWidget);
108
109     // Create status bar
110     statusBar();
111
112     // Status bar notification icons
113     QFrame *frameBlocks = new QFrame();
114     //frameBlocks->setFrameStyle(QFrame::Panel | QFrame::Sunken);
115     frameBlocks->setContentsMargins(0,0,0,0);
116     frameBlocks->setMinimumWidth(56);
117     frameBlocks->setMaximumWidth(56);
118     QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);
119     frameBlocksLayout->setContentsMargins(3,0,3,0);
120     frameBlocksLayout->setSpacing(3);
121     labelEncryptionIcon = new QLabel();
122     labelConnectionsIcon = new QLabel();
123     labelBlocksIcon = new QLabel();
124     frameBlocksLayout->addStretch();
125     frameBlocksLayout->addWidget(labelEncryptionIcon);
126     frameBlocksLayout->addStretch();
127     frameBlocksLayout->addWidget(labelConnectionsIcon);
128     frameBlocksLayout->addStretch();
129     frameBlocksLayout->addWidget(labelBlocksIcon);
130     frameBlocksLayout->addStretch();
131
132     // Progress bar for blocks download
133     progressBarLabel = new QLabel(tr("Synchronizing with network..."));
134     progressBarLabel->setVisible(false);
135     progressBar = new QProgressBar();
136     progressBar->setToolTip(tr("Block chain synchronization in progress"));
137     progressBar->setVisible(false);
138
139     statusBar()->addWidget(progressBarLabel);
140     statusBar()->addWidget(progressBar);
141     statusBar()->addPermanentWidget(frameBlocks);
142
143     syncIconMovie = new QMovie(":/movies/update_spinner", "mng", this);
144
145     // Clicking on a transaction on the overview page simply sends you to transaction history page
146     connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), this, SLOT(gotoHistoryPage()));
147
148     // Doubleclicking on a transaction on the transaction history page shows details
149     connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
150
151     gotoOverviewPage();
152 }
153
154 BitcoinGUI::~BitcoinGUI()
155 {
156 #ifdef Q_WS_MAC
157     delete appMenuBar;
158 #endif
159 }
160
161 void BitcoinGUI::createActions()
162 {
163     QActionGroup *tabGroup = new QActionGroup(this);
164
165     overviewAction = new QAction(QIcon(":/icons/overview"), tr("&Overview"), this);
166     overviewAction->setToolTip(tr("Show general overview of wallet"));
167     overviewAction->setCheckable(true);
168     overviewAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_1));
169     tabGroup->addAction(overviewAction);
170
171     historyAction = new QAction(QIcon(":/icons/history"), tr("&Transactions"), this);
172     historyAction->setToolTip(tr("Browse transaction history"));
173     historyAction->setCheckable(true);
174     historyAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_4));
175     tabGroup->addAction(historyAction);
176
177     addressBookAction = new QAction(QIcon(":/icons/address-book"), tr("&Address Book"), this);
178     addressBookAction->setToolTip(tr("Edit the list of stored addresses and labels"));
179     addressBookAction->setCheckable(true);
180     addressBookAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_5));
181     tabGroup->addAction(addressBookAction);
182
183     receiveCoinsAction = new QAction(QIcon(":/icons/receiving_addresses"), tr("&Receive coins"), this);
184     receiveCoinsAction->setToolTip(tr("Show the list of addresses for receiving payments"));
185     receiveCoinsAction->setCheckable(true);
186     receiveCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_3));
187     tabGroup->addAction(receiveCoinsAction);
188
189     sendCoinsAction = new QAction(QIcon(":/icons/send"), tr("&Send coins"), this);
190     sendCoinsAction->setToolTip(tr("Send coins to a bitcoin address"));
191     sendCoinsAction->setCheckable(true);
192     sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2));
193     tabGroup->addAction(sendCoinsAction);
194
195     connect(overviewAction, SIGNAL(triggered()), this, SLOT(show()));
196     connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage()));
197     connect(historyAction, SIGNAL(triggered()), this, SLOT(show()));
198     connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage()));
199     connect(addressBookAction, SIGNAL(triggered()), this, SLOT(show()));
200     connect(addressBookAction, SIGNAL(triggered()), this, SLOT(gotoAddressBookPage()));
201     connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(show()));
202     connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
203     connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(show()));
204     connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
205
206     quitAction = new QAction(QIcon(":/icons/quit"), tr("E&xit"), this);
207     quitAction->setToolTip(tr("Quit application"));
208     quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
209     quitAction->setMenuRole(QAction::QuitRole);
210     aboutAction = new QAction(QIcon(":/icons/bitcoin"), tr("&About %1").arg(qApp->applicationName()), this);
211     aboutAction->setToolTip(tr("Show information about Bitcoin"));
212     aboutAction->setMenuRole(QAction::AboutQtRole);
213     optionsAction = new QAction(QIcon(":/icons/options"), tr("&Options..."), this);
214     optionsAction->setToolTip(tr("Modify configuration options for bitcoin"));
215     optionsAction->setMenuRole(QAction::PreferencesRole);
216     openBitcoinAction = new QAction(QIcon(":/icons/bitcoin"), tr("Open &Bitcoin"), this);
217     openBitcoinAction->setToolTip(tr("Show the Bitcoin window"));
218     exportAction = new QAction(QIcon(":/icons/export"), tr("&Export..."), this);
219     exportAction->setToolTip(tr("Export the current view to a file"));
220     encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet"), this);
221     encryptWalletAction->setToolTip(tr("Encrypt or decrypt wallet"));
222     encryptWalletAction->setCheckable(true);
223     changePassphraseAction = new QAction(QIcon(":/icons/key"), tr("&Change Passphrase"), this);
224     changePassphraseAction->setToolTip(tr("Change the passphrase used for wallet encryption"));
225
226     connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
227     connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked()));
228     connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked()));
229     connect(openBitcoinAction, SIGNAL(triggered()), this, SLOT(showNormal()));
230     connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool)));
231     connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase()));
232 }
233
234 void BitcoinGUI::createMenuBar()
235 {
236 #ifdef Q_WS_MAC
237     // Create a decoupled menu bar on Mac which stays even if the window is closed
238     appMenuBar = new QMenuBar();
239 #else
240     // Get the main window's menu bar on other platforms
241     appMenuBar = menuBar();
242 #endif
243
244     // Configure the menus
245     QMenu *file = appMenuBar->addMenu(tr("&File"));
246     file->addAction(quitAction);
247
248     QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
249     settings->addAction(encryptWalletAction);
250     settings->addAction(changePassphraseAction);
251     settings->addSeparator();
252     settings->addAction(optionsAction);
253
254     QMenu *help = appMenuBar->addMenu(tr("&Help"));
255     help->addAction(aboutAction);
256 }
257
258 void BitcoinGUI::createToolBars()
259 {
260     QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));
261     toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
262     toolbar->addAction(overviewAction);
263     toolbar->addAction(sendCoinsAction);
264     toolbar->addAction(receiveCoinsAction);
265     toolbar->addAction(historyAction);
266     toolbar->addAction(addressBookAction);
267
268     QToolBar *toolbar2 = addToolBar(tr("Actions toolbar"));
269     toolbar2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
270     toolbar2->addAction(exportAction);
271 }
272
273 void BitcoinGUI::setClientModel(ClientModel *clientModel)
274 {
275     this->clientModel = clientModel;
276     if(clientModel)
277     {
278         if(clientModel->isTestNet())
279         {
280             QString title_testnet = windowTitle() + QString(" ") + tr("[testnet]");
281             setWindowTitle(title_testnet);
282 #ifndef Q_WS_MAC
283             setWindowIcon(QIcon(":icons/bitcoin_testnet"));
284 #else
285             MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
286 #endif
287             if(trayIcon)
288             {
289                 trayIcon->setToolTip(title_testnet);
290                 trayIcon->setIcon(QIcon(":/icons/toolbar_testnet"));
291             }
292         }
293
294         // Keep up to date with client
295         setNumConnections(clientModel->getNumConnections());
296         connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
297
298         setNumBlocks(clientModel->getNumBlocks());
299         connect(clientModel, SIGNAL(numBlocksChanged(int)), this, SLOT(setNumBlocks(int)));
300
301         // Report errors from network/worker thread
302         connect(clientModel, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString)));
303     }
304 }
305
306 void BitcoinGUI::setWalletModel(WalletModel *walletModel)
307 {
308     this->walletModel = walletModel;
309     if(walletModel)
310     {
311         // Report errors from wallet thread
312         connect(walletModel, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString)));
313
314         // Put transaction list in tabs
315         transactionView->setModel(walletModel);
316
317         overviewPage->setModel(walletModel);
318         addressBookPage->setModel(walletModel->getAddressTableModel());
319         receiveCoinsPage->setModel(walletModel->getAddressTableModel());
320         sendCoinsPage->setModel(walletModel);
321
322         setEncryptionStatus(walletModel->getEncryptionStatus());
323         connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));
324
325         // Balloon popup for new transaction
326         connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
327                 this, SLOT(incomingTransaction(QModelIndex,int,int)));
328
329         // Ask for passphrase if needed
330         connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
331     }
332 }
333
334 void BitcoinGUI::createTrayIcon()
335 {
336     QMenu *trayIconMenu;
337 #ifndef Q_WS_MAC
338     trayIcon = new QSystemTrayIcon(this);
339     trayIconMenu = new QMenu(this);
340     trayIcon->setContextMenu(trayIconMenu);
341     trayIcon->setToolTip("Bitcoin client");
342     trayIcon->setIcon(QIcon(":/icons/toolbar"));
343     connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
344             this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
345     trayIcon->show();
346 #else
347     // Note: On Mac, the dock icon is used to provide the tray's functionality.
348     MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance();
349     connect(dockIconHandler, SIGNAL(dockIconClicked()), openBitcoinAction, SLOT(trigger()));
350     trayIconMenu = dockIconHandler->dockMenu();
351 #endif
352
353     // Configuration of the tray icon (or dock icon) icon menu
354     trayIconMenu->addAction(openBitcoinAction);
355     trayIconMenu->addSeparator();
356     trayIconMenu->addAction(receiveCoinsAction);
357     trayIconMenu->addAction(sendCoinsAction);
358     trayIconMenu->addSeparator();
359     trayIconMenu->addAction(optionsAction);
360 #ifndef Q_WS_MAC // This is built-in on Mac
361     trayIconMenu->addSeparator();
362     trayIconMenu->addAction(quitAction);
363 #endif
364
365     notificator = new Notificator(tr("bitcoin-qt"), trayIcon);
366 }
367
368 #ifndef Q_WS_MAC
369 void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
370 {
371     if(reason == QSystemTrayIcon::Trigger)
372     {
373         // Click on system tray icon triggers "open bitcoin"
374         openBitcoinAction->trigger();
375     }
376
377 }
378 #endif
379
380 void BitcoinGUI::optionsClicked()
381 {
382     if(!clientModel || !clientModel->getOptionsModel())
383         return;
384     OptionsDialog dlg;
385     dlg.setModel(clientModel->getOptionsModel());
386     dlg.exec();
387 }
388
389 void BitcoinGUI::aboutClicked()
390 {
391     AboutDialog dlg;
392     dlg.setModel(clientModel);
393     dlg.exec();
394 }
395
396 void BitcoinGUI::setNumConnections(int count)
397 {
398     QString icon;
399     switch(count)
400     {
401     case 0: icon = ":/icons/connect_0"; break;
402     case 1: case 2: case 3: icon = ":/icons/connect_1"; break;
403     case 4: case 5: case 6: icon = ":/icons/connect_2"; break;
404     case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
405     default: icon = ":/icons/connect_4"; break;
406     }
407     labelConnectionsIcon->setPixmap(QIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
408     labelConnectionsIcon->setToolTip(tr("%n active connection(s) to Bitcoin network", "", count));
409 }
410
411 void BitcoinGUI::setNumBlocks(int count)
412 {
413     if(!clientModel)
414         return;
415     int initTotal = clientModel->getNumBlocksAtStartup();
416     int total = clientModel->getNumBlocksOfPeers();
417     QString tooltip;
418
419     if(count < total)
420     {
421         if (clientModel->getStatusBarWarnings() == "")
422         {
423             progressBarLabel->setVisible(true);
424             progressBarLabel->setText(tr("Synchronizing with network..."));
425             progressBar->setVisible(true);
426             progressBar->setMaximum(total - initTotal);
427             progressBar->setValue(count - initTotal);
428         }
429         else
430         {
431             progressBarLabel->setText(clientModel->getStatusBarWarnings());
432             progressBarLabel->setVisible(true);
433             progressBar->setVisible(false);
434         }
435         tooltip = tr("Downloaded %1 of %2 blocks of transaction history.").arg(count).arg(total);
436     }
437     else
438     {
439         if (clientModel->getStatusBarWarnings() == "")
440             progressBarLabel->setVisible(false);
441         else
442         {
443             progressBarLabel->setText(clientModel->getStatusBarWarnings());
444             progressBarLabel->setVisible(true);
445         }
446         progressBar->setVisible(false);
447         tooltip = tr("Downloaded %1 blocks of transaction history.").arg(count);
448     }
449
450     QDateTime now = QDateTime::currentDateTime();
451     QDateTime lastBlockDate = clientModel->getLastBlockDate();
452     int secs = lastBlockDate.secsTo(now);
453     QString text;
454
455     // Represent time from last generated block in human readable text
456     if(secs < 60)
457     {
458         text = tr("%n second(s) ago","",secs);
459     }
460     else if(secs < 60*60)
461     {
462         text = tr("%n minute(s) ago","",secs/60);
463     }
464     else if(secs < 24*60*60)
465     {
466         text = tr("%n hour(s) ago","",secs/(60*60));
467     }
468     else
469     {
470         text = tr("%n day(s) ago","",secs/(60*60*24));
471     }
472
473     // Set icon state: spinning if catching up, tick otherwise
474     if(secs < 30*60)
475     {
476         tooltip = tr("Up to date") + QString("\n") + tooltip;
477         labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
478     }
479     else
480     {
481         tooltip = tr("Catching up...") + QString("\n") + tooltip;
482         labelBlocksIcon->setMovie(syncIconMovie);
483         syncIconMovie->start();
484     }
485
486     tooltip += QString("\n");
487     tooltip += tr("Last received block was generated %1.").arg(text);
488
489     labelBlocksIcon->setToolTip(tooltip);
490     progressBarLabel->setToolTip(tooltip);
491     progressBar->setToolTip(tooltip);
492 }
493
494 void BitcoinGUI::refreshStatusBar()
495 {
496     /* Might display multiple times in the case of multiple alerts
497     static QString prevStatusBar;
498     QString newStatusBar = clientModel->getStatusBarWarnings();
499     if (prevStatusBar != newStatusBar)
500     {
501         prevStatusBar = newStatusBar;
502         error(tr("Network Alert"), newStatusBar);
503     }*/
504     setNumBlocks(clientModel->getNumBlocks());
505 }
506
507 void BitcoinGUI::error(const QString &title, const QString &message)
508 {
509     // Report errors from network/worker thread
510     notificator->notify(Notificator::Critical, title, message);
511 }
512
513 void BitcoinGUI::changeEvent(QEvent *e)
514 {
515 #ifndef Q_WS_MAC // Ignored on Mac
516     if(e->type() == QEvent::WindowStateChange)
517     {
518         if(clientModel && clientModel->getOptionsModel()->getMinimizeToTray())
519         {
520             if(isMinimized())
521             {
522                 hide();
523                 e->ignore();
524             }
525             else
526             {
527                 show();
528                 e->accept();
529             }
530         }
531     }
532 #endif
533     QMainWindow::changeEvent(e);
534 }
535
536 void BitcoinGUI::closeEvent(QCloseEvent *event)
537 {
538     if(clientModel)
539     {
540 #ifndef Q_WS_MAC // Ignored on Mac
541         if(!clientModel->getOptionsModel()->getMinimizeToTray() &&
542            !clientModel->getOptionsModel()->getMinimizeOnClose())
543         {
544             qApp->quit();
545         }
546 #endif
547     }
548     QMainWindow::closeEvent(event);
549 }
550
551 void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
552 {
553     QString strMessage =
554         tr("This transaction is over the size limit.  You can still send it for a fee of %1, "
555           "which goes to the nodes that process your transaction and helps to support the network.  "
556           "Do you want to pay the fee?").arg(
557                 BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nFeeRequired));
558     QMessageBox::StandardButton retval = QMessageBox::question(
559           this, tr("Sending..."), strMessage,
560           QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes);
561     *payFee = (retval == QMessageBox::Yes);
562 }
563
564 void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
565 {
566     if(!walletModel || !clientModel)
567         return;
568     TransactionTableModel *ttm = walletModel->getTransactionTableModel();
569     qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
570                     .data(Qt::EditRole).toULongLong();
571     if(!clientModel->inInitialBlockDownload())
572     {
573         // On new transaction, make an info balloon
574         // Unless the initial block download is in progress, to prevent balloon-spam
575         QString date = ttm->index(start, TransactionTableModel::Date, parent)
576                         .data().toString();
577         QString type = ttm->index(start, TransactionTableModel::Type, parent)
578                         .data().toString();
579         QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
580                         .data().toString();
581         QIcon icon = qvariant_cast<QIcon>(ttm->index(start,
582                             TransactionTableModel::ToAddress, parent)
583                         .data(Qt::DecorationRole));
584
585         notificator->notify(Notificator::Information,
586                             (amount)<0 ? tr("Sent transaction") :
587                                          tr("Incoming transaction"),
588                               tr("Date: %1\n"
589                                  "Amount: %2\n"
590                                  "Type: %3\n"
591                                  "Address: %4\n")
592                               .arg(date)
593                               .arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true))
594                               .arg(type)
595                               .arg(address), icon);
596     }
597 }
598
599 void BitcoinGUI::gotoOverviewPage()
600 {
601     overviewAction->setChecked(true);
602     centralWidget->setCurrentWidget(overviewPage);
603
604     exportAction->setEnabled(false);
605     disconnect(exportAction, SIGNAL(triggered()), 0, 0);
606 }
607
608 void BitcoinGUI::gotoHistoryPage()
609 {
610     historyAction->setChecked(true);
611     centralWidget->setCurrentWidget(transactionsPage);
612
613     exportAction->setEnabled(true);
614     disconnect(exportAction, SIGNAL(triggered()), 0, 0);
615     connect(exportAction, SIGNAL(triggered()), transactionView, SLOT(exportClicked()));
616 }
617
618 void BitcoinGUI::gotoAddressBookPage()
619 {
620     addressBookAction->setChecked(true);
621     centralWidget->setCurrentWidget(addressBookPage);
622
623     exportAction->setEnabled(true);
624     disconnect(exportAction, SIGNAL(triggered()), 0, 0);
625     connect(exportAction, SIGNAL(triggered()), addressBookPage, SLOT(exportClicked()));
626 }
627
628 void BitcoinGUI::gotoReceiveCoinsPage()
629 {
630     receiveCoinsAction->setChecked(true);
631     centralWidget->setCurrentWidget(receiveCoinsPage);
632
633     exportAction->setEnabled(true);
634     disconnect(exportAction, SIGNAL(triggered()), 0, 0);
635     connect(exportAction, SIGNAL(triggered()), receiveCoinsPage, SLOT(exportClicked()));
636 }
637
638 void BitcoinGUI::gotoSendCoinsPage()
639 {
640     sendCoinsAction->setChecked(true);
641     centralWidget->setCurrentWidget(sendCoinsPage);
642
643     exportAction->setEnabled(false);
644     disconnect(exportAction, SIGNAL(triggered()), 0, 0);
645 }
646
647 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
648 {
649     // Accept only URLs
650     if(event->mimeData()->hasUrls())
651         event->acceptProposedAction();
652 }
653
654 void BitcoinGUI::dropEvent(QDropEvent *event)
655 {
656     if(event->mimeData()->hasUrls())
657     {
658         gotoSendCoinsPage();
659         QList<QUrl> urls = event->mimeData()->urls();
660         foreach(const QUrl &url, urls)
661         {
662             sendCoinsPage->handleURL(&url);
663         }
664     }
665
666     event->acceptProposedAction();
667 }
668
669 void BitcoinGUI::setEncryptionStatus(int status)
670 {
671     switch(status)
672     {
673     case WalletModel::Unencrypted:
674         labelEncryptionIcon->hide();
675         encryptWalletAction->setChecked(false);
676         changePassphraseAction->setEnabled(false);
677         encryptWalletAction->setEnabled(true);
678         break;
679     case WalletModel::Unlocked:
680         labelEncryptionIcon->show();
681         labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
682         labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
683         encryptWalletAction->setChecked(true);
684         changePassphraseAction->setEnabled(true);
685         encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
686         break;
687     case WalletModel::Locked:
688         labelEncryptionIcon->show();
689         labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
690         labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
691         encryptWalletAction->setChecked(true);
692         changePassphraseAction->setEnabled(true);
693         encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
694         break;
695     }
696 }
697
698 void BitcoinGUI::encryptWallet(bool status)
699 {
700     if(!walletModel)
701         return;
702     AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt:
703                                      AskPassphraseDialog::Decrypt, this);
704     dlg.setModel(walletModel);
705     dlg.exec();
706
707     setEncryptionStatus(walletModel->getEncryptionStatus());
708 }
709
710 void BitcoinGUI::changePassphrase()
711 {
712     AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
713     dlg.setModel(walletModel);
714     dlg.exec();
715 }
716
717 void BitcoinGUI::unlockWallet()
718 {
719     if(!walletModel)
720         return;
721     // Unlock wallet when requested by wallet model
722     if(walletModel->getEncryptionStatus() == WalletModel::Locked)
723     {
724         AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
725         dlg.setModel(walletModel);
726         dlg.exec();
727     }
728 }