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