b51fd729cb119f397e96b7346e41d298c37ad409
[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(this);
168         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 initTotal = clientModel->getNumBlocksAtStartup();
349     int total = clientModel->getNumBlocksOfPeers();
350     QString tooltip;
351
352     if(count < total)
353     {
354         progressBarLabel->setVisible(true);
355         progressBar->setVisible(true);
356         progressBar->setMaximum(total - initTotal);
357         progressBar->setValue(count - initTotal);
358         tooltip = tr("Downloaded %1 of %2 blocks of transaction history.").arg(count).arg(total);
359     }
360     else
361     {
362         progressBarLabel->setVisible(false);
363         progressBar->setVisible(false);
364         tooltip = tr("Downloaded %1 blocks of transaction history.").arg(count);
365     }
366
367     QDateTime now = QDateTime::currentDateTime();
368     QDateTime lastBlockDate = clientModel->getLastBlockDate();
369     int secs = lastBlockDate.secsTo(now);
370     QString text;
371
372     // Represent time from last generated block in human readable text
373     if(secs < 60)
374     {
375         text = tr("%n second(s) ago","",secs);
376     }
377     else if(secs < 60*60)
378     {
379         text = tr("%n minute(s) ago","",secs/60);
380     }
381     else if(secs < 24*60*60)
382     {
383         text = tr("%n hour(s) ago","",secs/(60*60));
384     }
385     else
386     {
387         text = tr("%n day(s) ago","",secs/(60*60*24));
388     }
389
390     // Set icon state: spinning if catching up, tick otherwise
391     if(secs < 30*60)
392     {
393         tooltip = tr("Up to date") + QString("\n") + tooltip;
394         labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
395     }
396     else
397     {
398         tooltip = tr("Catching up...") + QString("\n") + tooltip;
399         labelBlocksIcon->setMovie(syncIconMovie);
400         syncIconMovie->start();
401     }
402
403     tooltip += QString("\n");
404     tooltip += tr("Last received block was generated %1.").arg(text);
405
406     labelBlocksIcon->setToolTip(tooltip);
407     progressBarLabel->setToolTip(tooltip);
408     progressBar->setToolTip(tooltip);
409 }
410
411 void BitcoinGUI::error(const QString &title, const QString &message)
412 {
413     // Report errors from network/worker thread
414     notificator->notify(Notificator::Critical, title, message);
415 }
416
417 void BitcoinGUI::changeEvent(QEvent *e)
418 {
419     if (e->type() == QEvent::WindowStateChange)
420     {
421         if(clientModel->getOptionsModel()->getMinimizeToTray())
422         {
423             if (isMinimized())
424             {
425                 hide();
426                 e->ignore();
427             }
428             else
429             {
430                 show();
431                 e->accept();
432             }
433         }
434     }
435     setWindowComposition();
436     QMainWindow::changeEvent(e);
437 }
438
439 void BitcoinGUI::closeEvent(QCloseEvent *event)
440 {
441     if(!clientModel->getOptionsModel()->getMinimizeToTray() &&
442        !clientModel->getOptionsModel()->getMinimizeOnClose())
443     {
444         qApp->quit();
445     }
446     QMainWindow::closeEvent(event);
447 }
448
449 void BitcoinGUI::setWindowComposition()
450 {
451 #ifdef Q_OS_WIN
452     // Make the background transparent on Windows Vista or 7, except when maximized
453     // Otherwise text becomes hard to read
454     if (QtWin::isCompositionEnabled())
455     {
456         QPalette pal = palette();
457         QColor bg = pal.window().color();
458         if(isMaximized())
459         {
460             setAttribute(Qt::WA_TranslucentBackground, false);
461             setAttribute(Qt::WA_StyledBackground, true);
462             QBrush wb = pal.window();
463             bg = wb.color();
464             bg.setAlpha(255);
465             pal.setColor(QPalette::Window, bg);
466             setPalette(pal);
467
468         }
469         else
470         {
471             setAttribute(Qt::WA_TranslucentBackground);
472             setAttribute(Qt::WA_StyledBackground, false);
473             bg.setAlpha(0);
474             pal.setColor(QPalette::Window, bg);
475             setPalette(pal);
476             setAttribute(Qt::WA_NoSystemBackground, false);
477             ensurePolished();
478             setAttribute(Qt::WA_StyledBackground, false);
479         }
480     }
481 #endif
482 }
483
484 void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
485 {
486     QString strMessage =
487         tr("This transaction is over the size limit.  You can still send it for a fee of %1, "
488           "which goes to the nodes that process your transaction and helps to support the network.  "
489           "Do you want to pay the fee?").arg(
490                 BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nFeeRequired));
491     QMessageBox::StandardButton retval = QMessageBox::question(
492           this, tr("Sending..."), strMessage,
493           QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes);
494     *payFee = (retval == QMessageBox::Yes);
495 }
496
497 void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
498 {
499     TransactionTableModel *ttm = walletModel->getTransactionTableModel();
500     qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
501                     .data(Qt::EditRole).toULongLong();
502     if(!clientModel->inInitialBlockDownload())
503     {
504         // On new transaction, make an info balloon
505         // Unless the initial block download is in progress, to prevent balloon-spam
506         QString date = ttm->index(start, TransactionTableModel::Date, parent)
507                         .data().toString();
508         QString type = ttm->index(start, TransactionTableModel::Type, parent)
509                         .data().toString();
510         QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
511                         .data().toString();
512         QIcon icon = qvariant_cast<QIcon>(ttm->index(start,
513                             TransactionTableModel::ToAddress, parent)
514                         .data(Qt::DecorationRole));
515
516         notificator->notify(Notificator::Information,
517                             (amount)<0 ? tr("Sent transaction") :
518                                          tr("Incoming transaction"),
519                               tr("Date: %1\n"
520                                  "Amount: %2\n"
521                                  "Type: %3\n"
522                                  "Address: %4\n")
523                               .arg(date)
524                               .arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true))
525                               .arg(type)
526                               .arg(address), icon);
527     }
528 }
529
530 void BitcoinGUI::gotoOverviewPage()
531 {
532     overviewAction->setChecked(true);
533     centralWidget->setCurrentWidget(overviewPage);
534
535     exportAction->setEnabled(false);
536     disconnect(exportAction, SIGNAL(triggered()), 0, 0);
537 }
538
539 void BitcoinGUI::gotoHistoryPage()
540 {
541     historyAction->setChecked(true);
542     centralWidget->setCurrentWidget(transactionsPage);
543
544     exportAction->setEnabled(true);
545     disconnect(exportAction, SIGNAL(triggered()), 0, 0);
546     connect(exportAction, SIGNAL(triggered()), transactionView, SLOT(exportClicked()));
547 }
548
549 void BitcoinGUI::gotoAddressBookPage()
550 {
551     addressBookAction->setChecked(true);
552     centralWidget->setCurrentWidget(addressBookPage);
553
554     exportAction->setEnabled(true);
555     disconnect(exportAction, SIGNAL(triggered()), 0, 0);
556     connect(exportAction, SIGNAL(triggered()), addressBookPage, SLOT(exportClicked()));
557 }
558
559 void BitcoinGUI::gotoReceiveCoinsPage()
560 {
561     receiveCoinsAction->setChecked(true);
562     centralWidget->setCurrentWidget(receiveCoinsPage);
563
564     exportAction->setEnabled(true);
565     disconnect(exportAction, SIGNAL(triggered()), 0, 0);
566     connect(exportAction, SIGNAL(triggered()), receiveCoinsPage, SLOT(exportClicked()));
567 }
568
569 void BitcoinGUI::gotoSendCoinsPage()
570 {
571     sendCoinsAction->setChecked(true);
572     if(centralWidget->currentWidget() != sendCoinsPage)
573     {
574         // Clear the current contents if we arrived from another tab
575         sendCoinsPage->clear();
576     }
577     centralWidget->setCurrentWidget(sendCoinsPage);
578
579     exportAction->setEnabled(false);
580     disconnect(exportAction, SIGNAL(triggered()), 0, 0);
581 }
582
583 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
584 {
585     // Accept only URLs
586     if(event->mimeData()->hasUrls())
587         event->acceptProposedAction();
588 }
589
590 void BitcoinGUI::dropEvent(QDropEvent *event)
591 {
592     if(event->mimeData()->hasUrls())
593     {
594         gotoSendCoinsPage();
595         QList<QUrl> urls = event->mimeData()->urls();
596         foreach(const QUrl &url, urls)
597         {
598             sendCoinsPage->handleURL(&url);
599         }
600     }
601
602     event->acceptProposedAction();
603 }
604
605 void BitcoinGUI::setEncryptionStatus(int status)
606 {
607     switch(status)
608     {
609     case WalletModel::Unencrypted:
610         labelEncryptionIcon->hide();
611         encryptWalletAction->setChecked(false);
612         changePassphraseAction->setEnabled(false);
613         encryptWalletAction->setEnabled(true);
614         break;
615     case WalletModel::Unlocked:
616         labelEncryptionIcon->show();
617         labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
618         labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
619         encryptWalletAction->setChecked(true);
620         changePassphraseAction->setEnabled(true);
621         encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
622         break;
623     case WalletModel::Locked:
624         labelEncryptionIcon->show();
625         labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
626         labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
627         encryptWalletAction->setChecked(true);
628         changePassphraseAction->setEnabled(true);
629         encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
630         break;
631     }
632 }
633
634 void BitcoinGUI::encryptWallet(bool status)
635 {
636     AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt:
637                                      AskPassphraseDialog::Decrypt, this);
638     dlg.setModel(walletModel);
639     dlg.exec();
640
641     setEncryptionStatus(walletModel->getEncryptionStatus());
642 }
643
644 void BitcoinGUI::changePassphrase()
645 {
646     AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
647     dlg.setModel(walletModel);
648     dlg.exec();
649 }
650
651 void BitcoinGUI::unlockWallet()
652 {
653     // Unlock wallet when requested by wallet model
654     if(walletModel->getEncryptionStatus() == WalletModel::Locked)
655     {
656         AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
657         dlg.setModel(walletModel);
658         dlg.exec();
659     }
660 }