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