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