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