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