148720da5927e1da123497af679ec9e35fd8439c
[novacoin.git] / src / qt / bitcoingui.cpp
1 /*
2  * Qt4 bitcoin GUI.
3  *
4  * W.J. van der Laan 2011-2012
5  * The Bitcoin Developers 2011-2012
6  */
7 #include "bitcoingui.h"
8 #include "transactiontablemodel.h"
9 #include "addressbookpage.h"
10 #include "sendcoinsdialog.h"
11 #include "signverifymessagedialog.h"
12 #include "secondauthdialog.h"
13 #include "multisigdialog.h"
14 #include "optionsdialog.h"
15 #include "aboutdialog.h"
16 #include "clientmodel.h"
17 #include "walletmodel.h"
18 #include "editaddressdialog.h"
19 #include "optionsmodel.h"
20 #include "transactiondescdialog.h"
21 #include "addresstablemodel.h"
22 #include "transactionview.h"
23 #include "overviewpage.h"
24 #include "bitcoinunits.h"
25 #include "guiconstants.h"
26 #include "askpassphrasedialog.h"
27 #include "notificator.h"
28 #include "guiutil.h"
29 #include "ui_interface.h"
30 #include "rpcconsole.h"
31 #include "mintingview.h"
32
33 #ifdef Q_OS_MAC
34 #include "macdockiconhandler.h"
35 #endif
36
37 #include <QApplication>
38 #if QT_VERSION < 0x050000
39 #include <QMainWindow>
40 #endif
41 #include <QMenuBar>
42 #include <QMenu>
43 #include <QIcon>
44 #include <QTabWidget>
45 #include <QVBoxLayout>
46 #include <QToolBar>
47 #include <QStatusBar>
48 #include <QLabel>
49 #include <QLineEdit>
50 #include <QPushButton>
51 #include <QLocale>
52 #include <QMessageBox>
53 #include <QProgressBar>
54 #include <QStackedWidget>
55 #include <QDateTime>
56 #include <QMovie>
57 #include <QFileDialog>
58 #if QT_VERSION < 0x050000
59 #include <QDesktopServices>
60 #else
61 #include <QStandardPaths>
62 #endif
63 #include <QTimer>
64 #include <QDragEnterEvent>
65 #if QT_VERSION < 0x050000
66 #include <QUrl>
67 #endif
68 #include <QStyle>
69 #include <QMimeData>
70
71 #include <iostream>
72
73 extern bool fWalletUnlockMintOnly;
74 extern uint64_t nStakeInputsMapSize;
75
76 BitcoinGUI::BitcoinGUI(QWidget *parent):
77     QMainWindow(parent),
78     clientModel(0),
79     walletModel(0),
80     signVerifyMessageDialog(0),
81     secondAuthDialog(0),
82     multisigPage(0),
83     encryptWalletAction(0),
84     lockWalletAction(0),
85     unlockWalletAction(0),
86     unlockWalletMiningAction(0),
87     changePassphraseAction(0),
88     trayIcon(0),
89     notificator(0),
90     rpcConsole(0),
91     aboutDialog(0),
92     optionsDialog(0)
93 {
94     resize(850, 550);
95     setWindowTitle(tr("NovaCoin") + " - " + tr("Wallet"));
96 #ifndef Q_OS_MAC
97     qApp->setWindowIcon(QIcon(":icons/bitcoin"));
98     setWindowIcon(QIcon(":icons/bitcoin"));
99 #else
100     setUnifiedTitleAndToolBarOnMac(true);
101     QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
102 #endif
103     // Accept D&D of URIs
104     setAcceptDrops(true);
105
106     // Create actions for the toolbar, menu bar and tray/dock icon
107     createActions();
108
109     // Create application menu bar
110     createMenuBar();
111
112     // Create the toolbars
113     createToolBars();
114
115     // Create the tray icon (or setup the dock icon)
116     createTrayIcon();
117
118     // Create tabs
119     overviewPage = new OverviewPage();
120
121     transactionsPage = new QWidget(this);
122     QVBoxLayout *vbox = new QVBoxLayout();
123     transactionView = new TransactionView(this);
124     vbox->addWidget(transactionView);
125     transactionsPage->setLayout(vbox);
126
127     mintingPage = new QWidget(this);
128     QVBoxLayout *vboxMinting = new QVBoxLayout();
129     mintingView = new MintingView(this);
130     vboxMinting->addWidget(mintingView);
131     mintingPage->setLayout(vboxMinting);
132
133     addressBookPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::SendingTab);
134
135     receiveCoinsPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::ReceivingTab);
136
137     sendCoinsPage = new SendCoinsDialog(this);
138
139     signVerifyMessageDialog = new SignVerifyMessageDialog(0);
140
141     secondAuthDialog = new SecondAuthDialog(0);
142
143     multisigPage = new MultisigDialog(0);
144
145     centralWidget = new QStackedWidget(this);
146     centralWidget->addWidget(overviewPage);
147     centralWidget->addWidget(transactionsPage);
148     centralWidget->addWidget(mintingPage);
149     centralWidget->addWidget(addressBookPage);
150     centralWidget->addWidget(receiveCoinsPage);
151     centralWidget->addWidget(sendCoinsPage);
152     setCentralWidget(centralWidget);
153
154     // Create status bar
155     statusBar();
156
157     // Status bar notification icons
158     QFrame *frameBlocks = new QFrame();
159     frameBlocks->setContentsMargins(0,0,0,0);
160     frameBlocks->setMinimumWidth(72);
161     frameBlocks->setMaximumWidth(72);
162     QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);
163     frameBlocksLayout->setContentsMargins(3,0,3,0);
164     frameBlocksLayout->setSpacing(3);
165     labelEncryptionIcon = new QLabel();
166     labelMiningIcon = new QLabel();
167     labelConnectionsIcon = new QLabel();
168     labelBlocksIcon = new QLabel();
169     frameBlocksLayout->addStretch();
170     frameBlocksLayout->addWidget(labelEncryptionIcon);
171     frameBlocksLayout->addStretch();
172     frameBlocksLayout->addWidget(labelMiningIcon);
173     frameBlocksLayout->addStretch();
174     frameBlocksLayout->addWidget(labelConnectionsIcon);
175     frameBlocksLayout->addStretch();
176     frameBlocksLayout->addWidget(labelBlocksIcon);
177     frameBlocksLayout->addStretch();
178
179     // Progress bar and label for blocks download
180     progressBarLabel = new QLabel();
181     progressBarLabel->setVisible(false);
182     progressBar = new QProgressBar();
183     progressBar->setAlignment(Qt::AlignCenter);
184     progressBar->setVisible(false);
185
186     // Override style sheet for progress bar for styles that have a segmented progress bar,
187     // as they make the text unreadable (workaround for issue #1071)
188     // See https://qt-project.org/doc/qt-4.8/gallery.html
189     QString curStyle = qApp->style()->metaObject()->className();
190     if(curStyle == "QWindowsStyle" || curStyle == "QWindowsXPStyle")
191     {
192         progressBar->setStyleSheet("QProgressBar { background-color: #e8e8e8; border: 1px solid grey; border-radius: 7px; padding: 1px; text-align: center; } QProgressBar::chunk { background: QLinearGradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 #FF8000, stop: 1 orange); border-radius: 7px; margin: 0px; }");
193     }
194
195     statusBar()->addWidget(progressBarLabel);
196     statusBar()->addWidget(progressBar);
197     statusBar()->addPermanentWidget(frameBlocks);
198
199     syncIconMovie = new QMovie(":/movies/update_spinner", "mng", this);
200
201     // Clicking on a transaction on the overview page simply sends you to transaction history page
202     connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), this, SLOT(gotoHistoryPage()));
203     connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex)));
204
205     // Double-clicking on a transaction on the transaction history page shows details
206     connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
207
208     rpcConsole = new RPCConsole(0);
209     connect(openRPCConsoleAction, SIGNAL(triggered()), rpcConsole, SLOT(show()));
210     connect(openRPCConsoleAction, SIGNAL(triggered()), rpcConsole, SLOT(raise()));
211
212     aboutDialog = new AboutDialog(0);
213     optionsDialog = new OptionsDialog(0);
214
215     // Clicking on "Verify Message" in the address book sends you to the verify message tab
216     connect(addressBookPage, SIGNAL(verifyMessage(QString)), this, SLOT(gotoVerifyMessageTab(QString)));
217     // Clicking on "Sign Message" in the receive coins page sends you to the sign message tab
218     connect(receiveCoinsPage, SIGNAL(signMessage(QString)), this, SLOT(gotoSignMessageTab(QString)));
219
220     gotoOverviewPage();
221 }
222
223 BitcoinGUI::~BitcoinGUI()
224 {
225     if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu)
226         trayIcon->hide();
227 #ifdef Q_OS_MAC
228     delete appMenuBar;
229 #endif
230
231     delete rpcConsole;
232     delete aboutDialog;
233     delete optionsDialog;
234     delete multisigPage;
235     delete secondAuthDialog;
236     delete signVerifyMessageDialog;
237 }
238
239 void BitcoinGUI::createActions()
240 {
241     QActionGroup *tabGroup = new QActionGroup(this);
242
243     overviewAction = new QAction(QIcon(":/icons/overview"), tr("&Overview"), this);
244     overviewAction->setToolTip(tr("Show general overview of wallet"));
245     overviewAction->setCheckable(true);
246     overviewAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_1));
247     tabGroup->addAction(overviewAction);
248
249     sendCoinsAction = new QAction(QIcon(":/icons/send"), tr("&Send coins"), this);
250     sendCoinsAction->setToolTip(tr("Send coins to a NovaCoin address"));
251     sendCoinsAction->setCheckable(true);
252     sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2));
253     tabGroup->addAction(sendCoinsAction);
254
255     receiveCoinsAction = new QAction(QIcon(":/icons/receiving_addresses"), tr("&Receive coins"), this);
256     receiveCoinsAction->setToolTip(tr("Show the list of addresses for receiving payments"));
257     receiveCoinsAction->setCheckable(true);
258     receiveCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_3));
259     tabGroup->addAction(receiveCoinsAction);
260
261     historyAction = new QAction(QIcon(":/icons/history"), tr("&Transactions"), this);
262     historyAction->setToolTip(tr("Browse transaction history"));
263     historyAction->setCheckable(true);
264     historyAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_4));
265     tabGroup->addAction(historyAction);
266
267     mintingAction = new QAction(QIcon(":/icons/history"), tr("&Minting"), this);
268     mintingAction->setToolTip(tr("Show your minting capacity"));
269     mintingAction->setCheckable(true);
270     mintingAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_5));
271     tabGroup->addAction(mintingAction);
272
273     addressBookAction = new QAction(QIcon(":/icons/address-book"), tr("&Address Book"), this);
274     addressBookAction->setToolTip(tr("Edit the list of stored addresses and labels"));
275     addressBookAction->setCheckable(true);
276     addressBookAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_6));
277     tabGroup->addAction(addressBookAction);
278
279     multisigAction = new QAction(QIcon(":/icons/send"), tr("Multisig"), this);
280     multisigAction->setStatusTip(tr("Open window for working with multisig addresses"));
281     tabGroup->addAction(multisigAction);
282
283     connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
284     connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage()));
285     connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
286     connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
287     connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
288     connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
289     connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
290     connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage()));
291     connect(mintingAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
292     connect(mintingAction, SIGNAL(triggered()), this, SLOT(gotoMintingPage()));
293     connect(addressBookAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
294     connect(addressBookAction, SIGNAL(triggered()), this, SLOT(gotoAddressBookPage()));
295     connect(multisigAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
296     connect(multisigAction, SIGNAL(triggered()), this, SLOT(gotoMultisigPage()));
297
298     quitAction = new QAction(QIcon(":/icons/quit"), tr("E&xit"), this);
299     quitAction->setStatusTip(tr("Quit application"));
300     quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
301     quitAction->setMenuRole(QAction::QuitRole);
302     aboutAction = new QAction(QIcon(":/icons/bitcoin"), tr("&About NovaCoin"), this);
303     aboutAction->setStatusTip(tr("Show information about NovaCoin"));
304     aboutAction->setMenuRole(QAction::AboutRole);
305     optionsAction = new QAction(QIcon(":/icons/options"), tr("&Options..."), this);
306     optionsAction->setStatusTip(tr("Modify configuration options for NovaCoin"));
307     optionsAction->setMenuRole(QAction::PreferencesRole);
308     toggleHideAction = new QAction(QIcon(":/icons/bitcoin"), tr("&Show / Hide"), this);
309     encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet..."), this);
310     encryptWalletAction->setStatusTip(tr("Encrypt or decrypt wallet"));
311     encryptWalletAction->setCheckable(true);
312     backupWalletAction = new QAction(QIcon(":/icons/filesave"), tr("&Backup Wallet..."), this);
313     backupWalletAction->setStatusTip(tr("Backup wallet to another location"));
314     dumpWalletAction = new QAction(QIcon(":/icons/dump"), tr("&Dump Wallet..."), this);
315     dumpWalletAction->setStatusTip(tr("Dump keys to a text file"));
316     importWalletAction = new QAction(QIcon(":/icons/import"), tr("&Import Wallet..."), this);
317     importWalletAction->setStatusTip(tr("Import keys into a wallet"));
318     changePassphraseAction = new QAction(QIcon(":/icons/key"), tr("&Change Passphrase..."), this);
319     changePassphraseAction->setStatusTip(tr("Change the passphrase used for wallet encryption"));
320     signMessageAction = new QAction(QIcon(":/icons/edit"), tr("Sign &message..."), this);
321     signMessageAction->setStatusTip(tr("Sign messages with your Novacoin addresses to prove you own them"));
322     verifyMessageAction = new QAction(QIcon(":/icons/transaction_0"), tr("&Verify message..."), this);
323     verifyMessageAction->setStatusTip(tr("Verify messages to ensure they were signed with specified Novacoin addresses"));
324     secondAuthAction = new QAction(QIcon(":/icons/key"), tr("Second &auth..."), this);
325     secondAuthAction->setStatusTip(tr("Second auth with your Novacoin addresses"));
326
327     lockWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Lock wallet"), this);
328     lockWalletAction->setStatusTip(tr("Lock wallet"));
329     lockWalletAction->setCheckable(true);
330
331     unlockWalletAction = new QAction(QIcon(":/icons/lock_open"), tr("Unlo&ck wallet"), this);
332     unlockWalletAction->setStatusTip(tr("Unlock wallet"));
333     unlockWalletAction->setCheckable(true);
334
335     unlockWalletMiningAction = new QAction(QIcon(":/icons/mining_active"), tr("Unlo&ck wallet for mining"), this);
336     unlockWalletMiningAction->setStatusTip(tr("Unlock wallet for mining"));
337     unlockWalletMiningAction->setCheckable(true);
338
339     exportAction = new QAction(QIcon(":/icons/export"), tr("&Export..."), this);
340     exportAction->setStatusTip(tr("Export the data in the current tab to a file"));
341     openRPCConsoleAction = new QAction(QIcon(":/icons/debugwindow"), tr("&Debug window"), this);
342     openRPCConsoleAction->setStatusTip(tr("Open debugging and diagnostic console"));
343
344     connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
345     connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked()));
346     connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked()));
347     connect(toggleHideAction, SIGNAL(triggered()), this, SLOT(toggleHidden()));
348     connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool)));
349     connect(lockWalletAction, SIGNAL(triggered(bool)), this, SLOT(lockWallet()));
350     connect(unlockWalletAction, SIGNAL(triggered(bool)), this, SLOT(unlockWallet()));
351     connect(unlockWalletMiningAction, SIGNAL(triggered(bool)), this, SLOT(unlockWalletMining(bool)));
352     connect(backupWalletAction, SIGNAL(triggered()), this, SLOT(backupWallet()));
353     connect(dumpWalletAction, SIGNAL(triggered()), this, SLOT(dumpWallet()));
354     connect(importWalletAction, SIGNAL(triggered()), this, SLOT(importWallet()));
355     connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase()));
356     connect(signMessageAction, SIGNAL(triggered()), this, SLOT(gotoSignMessageTab()));
357     connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(gotoVerifyMessageTab()));
358     connect(secondAuthAction, SIGNAL(triggered()), this, SLOT(gotoSecondAuthPage()));
359 }
360
361 void BitcoinGUI::createMenuBar()
362 {
363 #ifdef Q_OS_MAC
364     // Create a decoupled menu bar on Mac which stays even if the window is closed
365     appMenuBar = new QMenuBar();
366 #else
367     // Get the main window's menu bar on other platforms
368     appMenuBar = menuBar();
369 #endif
370
371     // Configure the menus
372     QMenu *file = appMenuBar->addMenu(tr("&File"));
373     file->addAction(backupWalletAction);
374     file->addSeparator();
375     file->addAction(dumpWalletAction);
376     file->addAction(importWalletAction);
377     file->addAction(exportAction);
378     file->addAction(signMessageAction);
379     file->addAction(verifyMessageAction);
380     file->addAction(secondAuthAction);
381     file->addAction(multisigAction);
382     file->addSeparator();
383     file->addAction(quitAction);
384
385     QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
386     QMenu *securityMenu = settings->addMenu(QIcon(":/icons/key"), tr("&Wallet security"));
387     securityMenu->addAction(encryptWalletAction);
388     securityMenu->addAction(changePassphraseAction);
389     securityMenu->addAction(unlockWalletAction);
390     securityMenu->addAction(unlockWalletMiningAction);
391     securityMenu->addAction(lockWalletAction);
392     settings->addAction(optionsAction);
393
394     QMenu *help = appMenuBar->addMenu(tr("&Help"));
395     help->addAction(openRPCConsoleAction);
396     help->addAction(aboutAction);
397 }
398
399 void BitcoinGUI::createToolBars()
400 {
401     QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));
402     toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
403     toolbar->addAction(overviewAction);
404     toolbar->addAction(sendCoinsAction);
405     toolbar->addAction(receiveCoinsAction);
406     toolbar->addAction(historyAction);
407     toolbar->addAction(mintingAction);
408     toolbar->addAction(addressBookAction);
409
410     QToolBar *toolbar2 = addToolBar(tr("Actions toolbar"));
411     toolbar2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
412     toolbar2->addAction(exportAction);
413     toolbar2->setVisible(false);
414     
415 }
416
417 void BitcoinGUI::setClientModel(ClientModel *clientModel)
418 {
419     this->clientModel = clientModel;
420     if(clientModel)
421     {
422         // Replace some strings and icons, when using the testnet
423         if(clientModel->isTestNet())
424         {
425             setWindowTitle(windowTitle() + QString(" ") + tr("[testnet]"));
426 #ifndef Q_OS_MAC
427             qApp->setWindowIcon(QIcon(":icons/bitcoin_testnet"));
428             setWindowIcon(QIcon(":icons/bitcoin_testnet"));
429 #else
430             MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
431 #endif
432             if(trayIcon)
433             {
434                 trayIcon->setToolTip(tr("NovaCoin client") + QString(" ") + tr("[testnet]"));
435                 trayIcon->setIcon(QIcon(":/icons/toolbar_testnet"));
436                 toggleHideAction->setIcon(QIcon(":/icons/toolbar_testnet"));
437             }
438
439             aboutAction->setIcon(QIcon(":/icons/toolbar_testnet"));
440         }
441
442         // Keep up to date with client
443         setNumConnections(clientModel->getNumConnections());
444         connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
445
446         setNumBlocks(clientModel->getNumBlocks());
447         connect(clientModel, SIGNAL(numBlocksChanged(int)), this, SLOT(setNumBlocks(int)));
448
449         QTimer *timer = new QTimer(this);
450         connect(timer, SIGNAL(timeout()), this, SLOT(updateMining()));
451         timer->start(10*1000); //10 seconds
452
453         // Report errors from network/worker thread
454         connect(clientModel, SIGNAL(error(QString,QString,bool)), this, SLOT(error(QString,QString,bool)));
455
456         rpcConsole->setClientModel(clientModel);
457         addressBookPage->setOptionsModel(clientModel->getOptionsModel());
458         receiveCoinsPage->setOptionsModel(clientModel->getOptionsModel());
459     }
460 }
461
462 void BitcoinGUI::setWalletModel(WalletModel *walletModel)
463 {
464     this->walletModel = walletModel;
465     if(walletModel)
466     {
467         // Report errors from wallet thread
468         connect(walletModel, SIGNAL(error(QString,QString,bool)), this, SLOT(error(QString,QString,bool)));
469
470         // Put transaction list in tabs
471         transactionView->setModel(walletModel);
472         mintingView->setModel(walletModel);
473
474         overviewPage->setModel(walletModel);
475         addressBookPage->setModel(walletModel->getAddressTableModel());
476         receiveCoinsPage->setModel(walletModel->getAddressTableModel());
477         sendCoinsPage->setModel(walletModel);
478         signVerifyMessageDialog->setModel(walletModel);
479         secondAuthDialog->setModel(walletModel);
480         multisigPage->setModel(walletModel);
481
482         setEncryptionStatus(walletModel->getEncryptionStatus());
483         connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));
484         connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(updateMining()));
485
486         // Balloon pop-up for new transaction
487         connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
488                 this, SLOT(incomingTransaction(QModelIndex,int,int)));
489
490         // Ask for passphrase if needed
491         connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
492     }
493 }
494
495 void BitcoinGUI::createTrayIcon()
496 {
497     QMenu *trayIconMenu;
498 #ifndef Q_OS_MAC
499     trayIcon = new QSystemTrayIcon(this);
500     trayIconMenu = new QMenu(this);
501     trayIcon->setContextMenu(trayIconMenu);
502     trayIcon->setToolTip(tr("NovaCoin client"));
503     trayIcon->setIcon(QIcon(":/icons/toolbar"));
504     connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
505             this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
506     trayIcon->show();
507 #else
508     // Note: On Mac, the dock icon is used to provide the tray's functionality.
509     MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance();
510     dockIconHandler->setMainWindow((QMainWindow *)this);
511     trayIconMenu = dockIconHandler->dockMenu();
512 #endif
513
514     // Configuration of the tray icon (or dock icon) icon menu
515     trayIconMenu->addAction(toggleHideAction);
516     trayIconMenu->addSeparator();
517     trayIconMenu->addAction(sendCoinsAction);
518     trayIconMenu->addAction(multisigAction);
519     trayIconMenu->addAction(receiveCoinsAction);
520     trayIconMenu->addSeparator();
521     trayIconMenu->addAction(signMessageAction);
522     trayIconMenu->addAction(verifyMessageAction);
523     trayIconMenu->addAction(secondAuthAction);
524     trayIconMenu->addSeparator();
525     trayIconMenu->addAction(optionsAction);
526     trayIconMenu->addAction(openRPCConsoleAction);
527 #ifndef Q_OS_MAC
528     // This is built-in on Mac
529     trayIconMenu->addSeparator();
530     trayIconMenu->addAction(quitAction);    
531 #endif
532     notificator = new Notificator(QApplication::applicationName(), trayIcon, this);
533 }
534
535 #ifndef Q_OS_MAC
536 void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
537 {
538     if(reason == QSystemTrayIcon::Trigger)
539     {
540         // Click on system tray icon triggers show/hide of the main window
541         toggleHideAction->trigger();
542     }
543 }
544 #endif
545
546 void BitcoinGUI::optionsClicked()
547 {
548     if(!clientModel || !clientModel->getOptionsModel())
549         return;
550
551     optionsDialog->setModel(clientModel->getOptionsModel());
552     optionsDialog->setWindowModality(Qt::ApplicationModal);
553     optionsDialog->show();
554 }
555
556 void BitcoinGUI::aboutClicked()
557 {
558     aboutDialog->setModel(clientModel);
559     aboutDialog->setWindowModality(Qt::ApplicationModal);
560     aboutDialog->show();
561 }
562
563 void BitcoinGUI::setNumConnections(int count)
564 {
565     QString icon;
566     switch(count)
567     {
568     case 0: icon = ":/icons/connect_0"; break;
569     case 1: case 2: case 3: icon = ":/icons/connect_1"; break;
570     case 4: case 5: case 6: icon = ":/icons/connect_2"; break;
571     case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
572     default: icon = ":/icons/connect_4"; break;
573     }
574     labelConnectionsIcon->setPixmap(QIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
575     labelConnectionsIcon->setToolTip(tr("%n active connection(s) to NovaCoin network", "", count));
576 }
577
578 void BitcoinGUI::setNumBlocks(int count)
579 {
580     // don't show / hide progress bar and its label if we have no connection to the network
581     if (!clientModel || clientModel->getNumConnections() == 0)
582     {
583         progressBarLabel->setVisible(false);
584         progressBar->setVisible(false);
585
586         return;
587     }
588
589     QString strStatusBarWarnings = clientModel->getStatusBarWarnings();
590     QString tooltip;
591
592     if (strStatusBarWarnings.isEmpty())
593         progressBarLabel->setVisible(false);
594
595     progressBar->setVisible(false);
596     tooltip = tr("Downloaded %1 blocks of transaction history.").arg(count);
597
598     // Override progressBarLabel text and hide progress bar, when we have warnings to display
599     if (!strStatusBarWarnings.isEmpty())
600     {
601         progressBarLabel->setText(strStatusBarWarnings);
602         progressBarLabel->setVisible(true);
603         progressBar->setVisible(false);
604     }
605
606     tooltip = tr("Current PoW difficulty is %1.").arg(clientModel->getDifficulty(false)) + QString("<br>") + tooltip;
607     tooltip = tr("Current PoS difficulty is %1.").arg(clientModel->getDifficulty(true)) + QString("<br>") + tooltip;
608
609     QDateTime lastBlockDate = clientModel->getLastBlockDate();
610     int secs = lastBlockDate.secsTo(QDateTime::currentDateTime());
611     QString text;
612
613     // Represent time from last generated block in human readable text
614     if(secs <= 0)
615     {
616         // Fully up to date. Leave text empty.
617     }
618     else if(secs < 60)
619     {
620         text = tr("%n second(s) ago","",secs);
621     }
622     else if(secs < 60*60)
623     {
624         text = tr("%n minute(s) ago","",secs/60);
625     }
626     else if(secs < 24*60*60)
627     {
628         text = tr("%n hour(s) ago","",secs/(60*60));
629     }
630     else
631     {
632         text = tr("%n day(s) ago","",secs/(60*60*24));
633     }
634
635     // Set icon state: spinning if catching up, tick otherwise
636     if(secs < 90*60)
637     {
638         tooltip = tr("Up to date") + QString(".<br>") + tooltip;
639         labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
640
641         overviewPage->showOutOfSyncWarning(false);
642     }
643     else
644     {
645         tooltip = tr("Catching up...") + QString("<br>") + tooltip;
646         labelBlocksIcon->setMovie(syncIconMovie);
647         syncIconMovie->start();
648
649         overviewPage->showOutOfSyncWarning(true);
650     }
651
652     if(!text.isEmpty())
653     {
654         tooltip += QString("<br>");
655         tooltip += tr("Last received block was generated %1.").arg(text);
656     }
657
658     // Don't word-wrap this (fixed-width) tooltip
659     tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
660
661     labelBlocksIcon->setToolTip(tooltip);
662     progressBarLabel->setToolTip(tooltip);
663     progressBar->setToolTip(tooltip);
664 }
665
666 void BitcoinGUI::updateMining()
667 {
668    if(!walletModel)
669       return;
670
671     labelMiningIcon->setPixmap(QIcon(":/icons/mining_inactive").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
672
673     if (!clientModel->getNumConnections())
674     {
675         labelMiningIcon->setToolTip(tr("Wallet is offline"));
676         return;
677     }
678
679     if (walletModel->getEncryptionStatus() == WalletModel::Locked)
680     {
681         labelMiningIcon->setToolTip(tr("Wallet is locked"));
682         return;
683     }
684
685     if (clientModel->inInitialBlockDownload())
686     {
687         labelMiningIcon->setToolTip(tr("Blockchain download is in progress"));
688         return;
689     }
690
691     if (nStakeInputsMapSize > 0)
692     {
693         labelMiningIcon->setPixmap(QIcon(":/icons/mining_active").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
694
695         uint64_t nNetworkWeight = clientModel->getPoSKernelPS();
696
697         labelMiningIcon->setToolTip(QString("<nobr>")+tr("Stake miner is active<br>%1 inputs being used for mining<br>Network weight is %3").arg(nStakeInputsMapSize).arg(nNetworkWeight)+QString("<\nobr>"));
698     }
699     else
700         labelMiningIcon->setToolTip(tr("No suitable inputs were found"));
701 }
702
703 void BitcoinGUI::message(const QString &title, const QString &message, unsigned int style, const QString &detail)
704 {
705     QString strTitle = tr("NovaCoin") + " - ";
706     // Default to information icon
707     int nMBoxIcon = QMessageBox::Information;
708     int nNotifyIcon = Notificator::Information;
709
710
711     // Check for usage of predefined title
712     switch (style) {
713     case CClientUIInterface::MSG_ERROR:
714         strTitle += tr("Error");
715         break;
716     case CClientUIInterface::MSG_WARNING:
717         strTitle += tr("Warning");
718         break;
719     case CClientUIInterface::MSG_INFORMATION:
720         strTitle += tr("Information");
721         break;
722     default:
723         strTitle += title; // Use supplied title
724     }
725
726     // Check for error/warning icon
727     if (style & CClientUIInterface::ICON_ERROR) {
728         nMBoxIcon = QMessageBox::Critical;
729         nNotifyIcon = Notificator::Critical;
730     }
731     else if (style & CClientUIInterface::ICON_WARNING) {
732         nMBoxIcon = QMessageBox::Warning;
733         nNotifyIcon = Notificator::Warning;
734     }
735
736     // Display message
737     if (style & CClientUIInterface::MODAL) {
738         // Check for buttons, use OK as default, if none was supplied
739         QMessageBox::StandardButton buttons;
740         buttons = QMessageBox::Ok;
741
742         QMessageBox mBox((QMessageBox::Icon)nMBoxIcon, strTitle, message, buttons);
743
744         if(!detail.isEmpty()) { mBox.setDetailedText(detail); }
745
746         mBox.exec();
747     }
748     else
749         notificator->notify((Notificator::Class)nNotifyIcon, strTitle, message);
750 }
751
752
753 void BitcoinGUI::changeEvent(QEvent *e)
754 {
755     QMainWindow::changeEvent(e);
756 #ifndef Q_OS_MAC // Ignored on Mac
757     if(e->type() == QEvent::WindowStateChange)
758     {
759         if(clientModel && clientModel->getOptionsModel()->getMinimizeToTray())
760         {
761             QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
762             if(!(wsevt->oldState() & Qt::WindowMinimized) && isMinimized())
763             {
764                 QTimer::singleShot(0, this, SLOT(hide()));
765                 e->ignore();
766             }
767         }
768     }
769 #endif
770 }
771
772 void BitcoinGUI::closeEvent(QCloseEvent *event)
773 {
774     if(clientModel)
775     {
776 #ifndef Q_OS_MAC // Ignored on Mac
777         if(!clientModel->getOptionsModel()->getMinimizeOnClose())
778         {
779             qApp->quit();
780         }
781 #endif
782     }
783     // close rpcConsole in case it was open to make some space for the shutdown window
784     rpcConsole->close();
785
786     QMainWindow::closeEvent(event);
787 }
788
789 void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
790 {
791     QString strMessage =
792         tr("This transaction is over the size limit.  You can still send it for a fee of %1, "
793           "which goes to the nodes that process your transaction and helps to support the network.  "
794           "Do you want to pay the fee?").arg(
795                 BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nFeeRequired));
796     QMessageBox::StandardButton retval = QMessageBox::question(
797           this, tr("Confirm transaction fee"), strMessage,
798           QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes);
799     *payFee = (retval == QMessageBox::Yes);
800 }
801
802 void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
803 {
804     if(!walletModel || !clientModel)
805         return;
806     TransactionTableModel *ttm = walletModel->getTransactionTableModel();
807     qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
808                     .data(Qt::EditRole).toULongLong();
809     if(!clientModel->inInitialBlockDownload())
810     {
811         // On new transaction, make an info balloon
812         // Unless the initial block download is in progress, to prevent balloon-spam
813         QString date = ttm->index(start, TransactionTableModel::Date, parent)
814                         .data().toString();
815         QString type = ttm->index(start, TransactionTableModel::Type, parent)
816                         .data().toString();
817         QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
818                         .data().toString();
819         QIcon icon = qvariant_cast<QIcon>(ttm->index(start,
820                             TransactionTableModel::ToAddress, parent)
821                         .data(Qt::DecorationRole));
822
823         notificator->notify(Notificator::Information,
824                             (amount)<0 ? tr("Sent transaction") :
825                                          tr("Incoming transaction"),
826                               tr("Date: %1\n"
827                                  "Amount: %2\n"
828                                  "Type: %3\n"
829                                  "Address: %4\n")
830                               .arg(date)
831                               .arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true))
832                               .arg(type)
833                               .arg(address), icon);
834     }
835 }
836
837 void BitcoinGUI::gotoOverviewPage()
838 {
839     overviewAction->setChecked(true);
840     centralWidget->setCurrentWidget(overviewPage);
841
842     exportAction->setEnabled(false);
843     disconnect(exportAction, SIGNAL(triggered()), 0, 0);
844 }
845
846 void BitcoinGUI::gotoHistoryPage()
847 {
848     historyAction->setChecked(true);
849     centralWidget->setCurrentWidget(transactionsPage);
850
851     exportAction->setEnabled(true);
852     disconnect(exportAction, SIGNAL(triggered()), 0, 0);
853     connect(exportAction, SIGNAL(triggered()), transactionView, SLOT(exportClicked()));
854 }
855
856 void BitcoinGUI::gotoMintingPage()
857 {
858     mintingAction->setChecked(true);
859     centralWidget->setCurrentWidget(mintingPage);
860
861     exportAction->setEnabled(true);
862     disconnect(exportAction, SIGNAL(triggered()), 0, 0);
863     connect(exportAction, SIGNAL(triggered()), mintingView, SLOT(exportClicked()));
864 }
865
866
867 void BitcoinGUI::gotoAddressBookPage()
868 {
869     addressBookAction->setChecked(true);
870     centralWidget->setCurrentWidget(addressBookPage);
871
872     exportAction->setEnabled(true);
873     disconnect(exportAction, SIGNAL(triggered()), 0, 0);
874     connect(exportAction, SIGNAL(triggered()), addressBookPage, SLOT(exportClicked()));
875 }
876
877 void BitcoinGUI::gotoReceiveCoinsPage()
878 {
879     receiveCoinsAction->setChecked(true);
880     centralWidget->setCurrentWidget(receiveCoinsPage);
881
882     exportAction->setEnabled(true);
883     disconnect(exportAction, SIGNAL(triggered()), 0, 0);
884     connect(exportAction, SIGNAL(triggered()), receiveCoinsPage, SLOT(exportClicked()));
885 }
886
887 void BitcoinGUI::gotoSendCoinsPage()
888 {
889     sendCoinsAction->setChecked(true);
890     centralWidget->setCurrentWidget(sendCoinsPage);
891
892     exportAction->setEnabled(false);
893     disconnect(exportAction, SIGNAL(triggered()), 0, 0);
894 }
895
896 void BitcoinGUI::gotoSignMessageTab(QString addr)
897 {
898     // call show() in showTab_SM()
899     signVerifyMessageDialog->showTab_SM(true);
900
901     if(!addr.isEmpty())
902         signVerifyMessageDialog->setAddress_SM(addr);
903 }
904
905 void BitcoinGUI::gotoVerifyMessageTab(QString addr)
906 {
907     // call show() in showTab_VM()
908     signVerifyMessageDialog->showTab_VM(true);
909
910     if(!addr.isEmpty())
911         signVerifyMessageDialog->setAddress_VM(addr);
912 }
913
914 void BitcoinGUI::gotoSecondAuthPage(QString addr)
915 {
916     secondAuthDialog->show();
917     secondAuthDialog->raise();
918     secondAuthDialog->activateWindow();
919 }
920
921 void BitcoinGUI::gotoMultisigPage()
922 {
923     multisigPage->show();
924     multisigPage->raise();
925     multisigPage->activateWindow();
926 }
927
928 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
929 {
930     // Accept only URIs
931     if(event->mimeData()->hasUrls())
932         event->acceptProposedAction();
933 }
934
935 void BitcoinGUI::dropEvent(QDropEvent *event)
936 {
937     if(event->mimeData()->hasUrls())
938     {
939         int nValidUrisFound = 0;
940         QList<QUrl> uris = event->mimeData()->urls();
941         foreach(const QUrl &uri, uris)
942         {
943             if (sendCoinsPage->handleURI(uri.toString()))
944                 nValidUrisFound++;
945         }
946
947         // if valid URIs were found
948         if (nValidUrisFound)
949             gotoSendCoinsPage();
950         else
951             notificator->notify(Notificator::Warning, tr("URI handling"), tr("URI can not be parsed! This can be caused by an invalid NovaCoin address or malformed URI parameters."));
952     }
953
954     event->acceptProposedAction();
955 }
956
957 void BitcoinGUI::handleURI(QString strURI)
958 {
959     // URI has to be valid
960     if (sendCoinsPage->handleURI(strURI))
961     {
962         showNormalIfMinimized();
963         gotoSendCoinsPage();
964     }
965     else
966         notificator->notify(Notificator::Warning, tr("URI handling"), tr("URI can not be parsed! This can be caused by an invalid NovaCoin address or malformed URI parameters."));
967 }
968
969 void BitcoinGUI::setEncryptionStatus(int status)
970 {
971     switch(status)
972     {
973     case WalletModel::Unencrypted:
974         labelEncryptionIcon->hide();
975         encryptWalletAction->setChecked(false);
976         changePassphraseAction->setEnabled(false);
977         lockWalletAction->setEnabled(false);
978         unlockWalletAction->setEnabled(false);
979         unlockWalletMiningAction->setEnabled(false);
980         encryptWalletAction->setEnabled(true);
981         break;
982     case WalletModel::Unlocked:
983         labelEncryptionIcon->show();
984         labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
985         labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
986         encryptWalletAction->setChecked(true);
987         changePassphraseAction->setEnabled(true);
988         encryptWalletAction->setEnabled(true);
989
990         lockWalletAction->setEnabled(true);
991         lockWalletAction->setChecked(false);
992         unlockWalletAction->setEnabled(false);
993         unlockWalletMiningAction->setEnabled(false);
994
995         if (fWalletUnlockMintOnly)
996             unlockWalletMiningAction->setChecked(true);
997         else
998             unlockWalletAction->setChecked(true);
999
1000         break;
1001     case WalletModel::Locked:
1002         labelEncryptionIcon->show();
1003         labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
1004         labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
1005         encryptWalletAction->setChecked(true);
1006         changePassphraseAction->setEnabled(true);
1007         encryptWalletAction->setEnabled(true);
1008
1009         lockWalletAction->setChecked(true);
1010         unlockWalletAction->setChecked(false);
1011         unlockWalletMiningAction->setChecked(false);
1012
1013         lockWalletAction->setEnabled(false);
1014         unlockWalletAction->setEnabled(true);
1015         unlockWalletMiningAction->setEnabled(true);
1016         break;
1017     }
1018 }
1019
1020 void BitcoinGUI::encryptWallet(bool status)
1021 {
1022     if(!walletModel)
1023         return;
1024     AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt:
1025                                      AskPassphraseDialog::Decrypt, this);
1026     dlg.setModel(walletModel);
1027     dlg.exec();
1028
1029     setEncryptionStatus(walletModel->getEncryptionStatus());
1030 }
1031
1032 void BitcoinGUI::unlockWalletMining(bool status)
1033 {
1034     if(!walletModel)
1035         return;
1036
1037     // Unlock wallet when requested by wallet model
1038     if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1039     {
1040         AskPassphraseDialog dlg(AskPassphraseDialog::UnlockMining, this);
1041         dlg.setModel(walletModel);
1042         dlg.exec();
1043     }
1044 }
1045
1046 void BitcoinGUI::backupWallet()
1047 {
1048 #if QT_VERSION < 0x050000
1049     QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1050 #else
1051     QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1052 #endif
1053     QString filename = QFileDialog::getSaveFileName(this, tr("Backup Wallet"), saveDir, tr("Wallet Data (*.dat)"));
1054     if(!filename.isEmpty()) {
1055         if(!walletModel->backupWallet(filename)) {
1056             QMessageBox::warning(this, tr("Backup Failed"), tr("There was an error trying to save the wallet data to the new location."));
1057         }
1058     }
1059 }
1060
1061 void BitcoinGUI::dumpWallet()
1062 {
1063    if(!walletModel)
1064       return;
1065
1066    WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1067    if(!ctx.isValid())
1068    {
1069        // Unlock wallet failed or was cancelled
1070        return;
1071    }
1072
1073 #if QT_VERSION < 0x050000
1074     QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1075 #else
1076     QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1077 #endif
1078     QString filename = QFileDialog::getSaveFileName(this, tr("Dump Wallet"), saveDir, tr("Wallet dump (*.txt)"));
1079     if(!filename.isEmpty()) {
1080         if(!walletModel->dumpWallet(filename)) {
1081             message(tr("Dump failed"),
1082                          tr("An error happened while trying to save the keys to your location.\n"
1083                             "Keys were not saved.")
1084                       ,CClientUIInterface::MSG_ERROR);
1085         }
1086         else
1087           message(tr("Dump successful"),
1088                        tr("Keys were saved to this file:\n%2")
1089                        .arg(filename)
1090                       ,CClientUIInterface::MSG_INFORMATION);
1091     }
1092 }
1093
1094 void BitcoinGUI::importWallet()
1095 {
1096    if(!walletModel)
1097       return;
1098
1099    WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1100    if(!ctx.isValid())
1101    {
1102        // Unlock wallet failed or was cancelled
1103        return;
1104    }
1105
1106 #if QT_VERSION < 0x050000
1107     QString openDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1108 #else
1109     QString openDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1110 #endif
1111     QString filename = QFileDialog::getOpenFileName(this, tr("Import Wallet"), openDir, tr("Wallet dump (*.txt)"));
1112     if(!filename.isEmpty()) {
1113         if(!walletModel->importWallet(filename)) {
1114             message(tr("Import Failed"),
1115                          tr("An error happened while trying to import the keys.\n"
1116                             "Some or all keys from:\n %1,\n were not imported into your wallet.")
1117                          .arg(filename)
1118                       ,CClientUIInterface::MSG_ERROR);
1119         }
1120         else
1121           message(tr("Import Successful"),
1122                        tr("All keys from:\n %1,\n were imported into your wallet.")
1123                        .arg(filename)
1124                       ,CClientUIInterface::MSG_INFORMATION);
1125     }
1126 }
1127
1128
1129 void BitcoinGUI::changePassphrase()
1130 {
1131     AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
1132     dlg.setModel(walletModel);
1133     dlg.exec();
1134 }
1135
1136 void BitcoinGUI::unlockWallet()
1137 {
1138     if(!walletModel)
1139         return;
1140     // Unlock wallet when requested by wallet model
1141     if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1142     {
1143         AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
1144         dlg.setModel(walletModel);
1145         dlg.exec();
1146     }
1147 }
1148
1149 void BitcoinGUI::lockWallet()
1150 {
1151     if(!walletModel)
1152         return;
1153
1154     walletModel->setWalletLocked(true);
1155 }
1156
1157 void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden)
1158 {
1159     // activateWindow() (sometimes) helps with keyboard focus on Windows
1160     if (isHidden())
1161     {
1162         // Make sure the window is not minimized
1163         setWindowState(windowState() & (~Qt::WindowMinimized | Qt::WindowActive));
1164         // Then show it
1165         show();
1166         raise();
1167         activateWindow();
1168     }
1169     else if (isMinimized())
1170     {
1171         showNormal();
1172         raise();
1173         activateWindow();
1174     }
1175     else if (GUIUtil::isObscured(this))
1176     {
1177         raise();
1178         activateWindow();
1179         if(fToggleHidden)
1180         {
1181             Sleep(1);
1182             if (GUIUtil::isObscured(this))
1183                 hide();
1184         }
1185     }
1186     else if(fToggleHidden)
1187         hide();
1188 }
1189
1190 void BitcoinGUI::toggleHidden()
1191 {
1192     showNormalIfMinimized(true);
1193 }
1194
1195 void BitcoinGUI::error(const QString &title, const QString &message, bool modal)
1196 {
1197     // Report errors from network/worker thread
1198     if(modal)
1199     {
1200         QMessageBox::critical(this, title, message, QMessageBox::Ok, QMessageBox::Ok);
1201     } else {
1202         notificator->notify(Notificator::Critical, title, message);
1203     }
1204 }