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