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