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