Bugfix: nTotalBlocks wasn't in 0.5.0, so need to replace it with equivalent function...
[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 bool HACK_SHUTDOWN = false;
523
524 void BitcoinGUI::error(const QString &title, const QString &message, bool modal)
525 {
526     // Report errors from network/worker thread
527     if (modal)
528     {
529         QMessageBox::critical(this, title, message, QMessageBox::Ok, QMessageBox::Ok);
530         if (HACK_SHUTDOWN)
531             QMetaObject::invokeMethod(QCoreApplication::instance(), "quit", Qt::QueuedConnection);
532     } else {
533         notificator->notify(Notificator::Critical, title, message);
534     }
535 }
536
537 void BitcoinGUI::changeEvent(QEvent *e)
538 {
539     QMainWindow::changeEvent(e);
540 #ifndef Q_WS_MAC // Ignored on Mac
541     if(e->type() == QEvent::WindowStateChange)
542     {
543         if(clientModel && clientModel->getOptionsModel()->getMinimizeToTray())
544         {
545             QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
546             if(!(wsevt->oldState() & Qt::WindowMinimized) && isMinimized())
547             {
548                 QTimer::singleShot(0, this, SLOT(hide()));
549                 e->ignore();
550             }
551         }
552     }
553 #endif
554 }
555
556 void BitcoinGUI::closeEvent(QCloseEvent *event)
557 {
558     if(clientModel)
559     {
560 #ifndef Q_WS_MAC // Ignored on Mac
561         if(!clientModel->getOptionsModel()->getMinimizeToTray() &&
562            !clientModel->getOptionsModel()->getMinimizeOnClose())
563         {
564             qApp->quit();
565         }
566 #endif
567     }
568     QMainWindow::closeEvent(event);
569 }
570
571 void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
572 {
573     QString strMessage =
574         tr("This transaction is over the size limit.  You can still send it for a fee of %1, "
575           "which goes to the nodes that process your transaction and helps to support the network.  "
576           "Do you want to pay the fee?").arg(
577                 BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nFeeRequired));
578     QMessageBox::StandardButton retval = QMessageBox::question(
579           this, tr("Sending..."), strMessage,
580           QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes);
581     *payFee = (retval == QMessageBox::Yes);
582 }
583
584 void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
585 {
586     if(!walletModel || !clientModel)
587         return;
588     TransactionTableModel *ttm = walletModel->getTransactionTableModel();
589     qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
590                     .data(Qt::EditRole).toULongLong();
591     if(!clientModel->inInitialBlockDownload())
592     {
593         // On new transaction, make an info balloon
594         // Unless the initial block download is in progress, to prevent balloon-spam
595         QString date = ttm->index(start, TransactionTableModel::Date, parent)
596                         .data().toString();
597         QString type = ttm->index(start, TransactionTableModel::Type, parent)
598                         .data().toString();
599         QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
600                         .data().toString();
601         QIcon icon = qvariant_cast<QIcon>(ttm->index(start,
602                             TransactionTableModel::ToAddress, parent)
603                         .data(Qt::DecorationRole));
604
605         notificator->notify(Notificator::Information,
606                             (amount)<0 ? tr("Sent transaction") :
607                                          tr("Incoming transaction"),
608                               tr("Date: %1\n"
609                                  "Amount: %2\n"
610                                  "Type: %3\n"
611                                  "Address: %4\n")
612                               .arg(date)
613                               .arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true))
614                               .arg(type)
615                               .arg(address), icon);
616     }
617 }
618
619 void BitcoinGUI::gotoOverviewPage()
620 {
621     overviewAction->setChecked(true);
622     centralWidget->setCurrentWidget(overviewPage);
623
624     exportAction->setEnabled(false);
625     disconnect(exportAction, SIGNAL(triggered()), 0, 0);
626 }
627
628 void BitcoinGUI::gotoHistoryPage()
629 {
630     historyAction->setChecked(true);
631     centralWidget->setCurrentWidget(transactionsPage);
632
633     exportAction->setEnabled(true);
634     disconnect(exportAction, SIGNAL(triggered()), 0, 0);
635     connect(exportAction, SIGNAL(triggered()), transactionView, SLOT(exportClicked()));
636 }
637
638 void BitcoinGUI::gotoAddressBookPage()
639 {
640     addressBookAction->setChecked(true);
641     centralWidget->setCurrentWidget(addressBookPage);
642
643     exportAction->setEnabled(true);
644     disconnect(exportAction, SIGNAL(triggered()), 0, 0);
645     connect(exportAction, SIGNAL(triggered()), addressBookPage, SLOT(exportClicked()));
646 }
647
648 void BitcoinGUI::gotoReceiveCoinsPage()
649 {
650     receiveCoinsAction->setChecked(true);
651     centralWidget->setCurrentWidget(receiveCoinsPage);
652
653     exportAction->setEnabled(true);
654     disconnect(exportAction, SIGNAL(triggered()), 0, 0);
655     connect(exportAction, SIGNAL(triggered()), receiveCoinsPage, SLOT(exportClicked()));
656 }
657
658 void BitcoinGUI::gotoSendCoinsPage()
659 {
660     sendCoinsAction->setChecked(true);
661     centralWidget->setCurrentWidget(sendCoinsPage);
662
663     exportAction->setEnabled(false);
664     disconnect(exportAction, SIGNAL(triggered()), 0, 0);
665 }
666
667 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
668 {
669     // Accept only URIs
670     if(event->mimeData()->hasUrls())
671         event->acceptProposedAction();
672 }
673
674 void BitcoinGUI::dropEvent(QDropEvent *event)
675 {
676     if(event->mimeData()->hasUrls())
677     {
678         gotoSendCoinsPage();
679         QList<QUrl> uris = event->mimeData()->urls();
680         foreach(const QUrl &uri, uris)
681         {
682             sendCoinsPage->handleURI(&uri);
683         }
684     }
685
686     event->acceptProposedAction();
687 }
688
689 void BitcoinGUI::setEncryptionStatus(int status)
690 {
691     switch(status)
692     {
693     case WalletModel::Unencrypted:
694         labelEncryptionIcon->hide();
695         encryptWalletAction->setChecked(false);
696         changePassphraseAction->setEnabled(false);
697         encryptWalletAction->setEnabled(true);
698         break;
699     case WalletModel::Unlocked:
700         labelEncryptionIcon->show();
701         labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
702         labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
703         encryptWalletAction->setChecked(true);
704         changePassphraseAction->setEnabled(true);
705         encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
706         break;
707     case WalletModel::Locked:
708         labelEncryptionIcon->show();
709         labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
710         labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
711         encryptWalletAction->setChecked(true);
712         changePassphraseAction->setEnabled(true);
713         encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
714         break;
715     }
716 }
717
718 void BitcoinGUI::encryptWallet(bool status)
719 {
720     if(!walletModel)
721         return;
722     AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt:
723                                      AskPassphraseDialog::Decrypt, this);
724     dlg.setModel(walletModel);
725     dlg.exec();
726
727     setEncryptionStatus(walletModel->getEncryptionStatus());
728 }
729
730 void BitcoinGUI::changePassphrase()
731 {
732     AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
733     dlg.setModel(walletModel);
734     dlg.exec();
735 }
736
737 void BitcoinGUI::unlockWallet()
738 {
739     if(!walletModel)
740         return;
741     // Unlock wallet when requested by wallet model
742     if(walletModel->getEncryptionStatus() == WalletModel::Locked)
743     {
744         AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
745         dlg.setModel(walletModel);
746         dlg.exec();
747     }
748 }