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