add PoS and PoW difficulty to tooltip
[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     tooltip = tr("Current PoW difficulty is %1.").arg(clientModel->getDifficulty(false)) + QString("<br>") + tooltip;
626     tooltip = tr("Current PoS difficulty is %1.").arg(clientModel->getDifficulty(true)) + QString("<br>") + tooltip;
627
628     QDateTime lastBlockDate = clientModel->getLastBlockDate();
629     int secs = lastBlockDate.secsTo(QDateTime::currentDateTime());
630     QString text;
631
632     // Represent time from last generated block in human readable text
633     if(secs <= 0)
634     {
635         // Fully up to date. Leave text empty.
636     }
637     else if(secs < 60)
638     {
639         text = tr("%n second(s) ago","",secs);
640     }
641     else if(secs < 60*60)
642     {
643         text = tr("%n minute(s) ago","",secs/60);
644     }
645     else if(secs < 24*60*60)
646     {
647         text = tr("%n hour(s) ago","",secs/(60*60));
648     }
649     else
650     {
651         text = tr("%n day(s) ago","",secs/(60*60*24));
652     }
653
654     // Set icon state: spinning if catching up, tick otherwise
655     if(secs < 90*60 && count >= nTotalBlocks)
656     {
657         tooltip = tr("Up to date") + QString(".<br>") + tooltip;
658         labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
659
660         overviewPage->showOutOfSyncWarning(false);
661     }
662     else
663     {
664         tooltip = tr("Catching up...") + QString("<br>") + tooltip;
665         labelBlocksIcon->setMovie(syncIconMovie);
666         syncIconMovie->start();
667
668         overviewPage->showOutOfSyncWarning(true);
669     }
670
671     if(!text.isEmpty())
672     {
673         tooltip += QString("<br>");
674         tooltip += tr("Last received block was generated %1.").arg(text);
675     }
676
677     // Don't word-wrap this (fixed-width) tooltip
678     tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
679
680     labelBlocksIcon->setToolTip(tooltip);
681     progressBarLabel->setToolTip(tooltip);
682     progressBar->setToolTip(tooltip);
683 }
684
685 void BitcoinGUI::updateMining()
686 {
687    if(!walletModel)
688       return;
689
690     labelMiningIcon->setPixmap(QIcon(":/icons/mining_inactive").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
691
692     if (!clientModel->getNumConnections())
693     {
694         labelMiningIcon->setToolTip(tr("Wallet is offline"));
695         return;
696     }
697
698     if (walletModel->getEncryptionStatus() == WalletModel::Locked)
699     {
700         labelMiningIcon->setToolTip(tr("Wallet is locked"));
701         return;
702     }
703
704     if (clientModel->inInitialBlockDownload() || clientModel->getNumBlocksOfPeers() > clientModel->getNumBlocks())
705     {
706         labelMiningIcon->setToolTip(tr("Blockchain download is in progress"));
707         return;
708     }
709
710     if (nStakeInputsMapSize > 0)
711     {
712         labelMiningIcon->setPixmap(QIcon(":/icons/mining_active").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
713
714         uint64_t nNetworkWeight = clientModel->getPoSKernelPS();
715
716         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>"));
717     }
718     else
719         labelMiningIcon->setToolTip(tr("No suitable inputs were found"));
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     // close rpcConsole in case it was open to make some space for the shutdown window
803     rpcConsole->close();
804
805     QMainWindow::closeEvent(event);
806 }
807
808 void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
809 {
810     QString strMessage =
811         tr("This transaction is over the size limit.  You can still send it for a fee of %1, "
812           "which goes to the nodes that process your transaction and helps to support the network.  "
813           "Do you want to pay the fee?").arg(
814                 BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nFeeRequired));
815     QMessageBox::StandardButton retval = QMessageBox::question(
816           this, tr("Confirm transaction fee"), strMessage,
817           QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes);
818     *payFee = (retval == QMessageBox::Yes);
819 }
820
821 void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
822 {
823     if(!walletModel || !clientModel)
824         return;
825     TransactionTableModel *ttm = walletModel->getTransactionTableModel();
826     qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
827                     .data(Qt::EditRole).toULongLong();
828     if(!clientModel->inInitialBlockDownload())
829     {
830         // On new transaction, make an info balloon
831         // Unless the initial block download is in progress, to prevent balloon-spam
832         QString date = ttm->index(start, TransactionTableModel::Date, parent)
833                         .data().toString();
834         QString type = ttm->index(start, TransactionTableModel::Type, parent)
835                         .data().toString();
836         QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
837                         .data().toString();
838         QIcon icon = qvariant_cast<QIcon>(ttm->index(start,
839                             TransactionTableModel::ToAddress, parent)
840                         .data(Qt::DecorationRole));
841
842         notificator->notify(Notificator::Information,
843                             (amount)<0 ? tr("Sent transaction") :
844                                          tr("Incoming transaction"),
845                               tr("Date: %1\n"
846                                  "Amount: %2\n"
847                                  "Type: %3\n"
848                                  "Address: %4\n")
849                               .arg(date)
850                               .arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true))
851                               .arg(type)
852                               .arg(address), icon);
853     }
854 }
855
856 void BitcoinGUI::gotoOverviewPage()
857 {
858     overviewAction->setChecked(true);
859     centralWidget->setCurrentWidget(overviewPage);
860
861     exportAction->setEnabled(false);
862     disconnect(exportAction, SIGNAL(triggered()), 0, 0);
863 }
864
865 void BitcoinGUI::gotoHistoryPage()
866 {
867     historyAction->setChecked(true);
868     centralWidget->setCurrentWidget(transactionsPage);
869
870     exportAction->setEnabled(true);
871     disconnect(exportAction, SIGNAL(triggered()), 0, 0);
872     connect(exportAction, SIGNAL(triggered()), transactionView, SLOT(exportClicked()));
873 }
874
875 void BitcoinGUI::gotoMintingPage()
876 {
877     mintingAction->setChecked(true);
878     centralWidget->setCurrentWidget(mintingPage);
879
880     exportAction->setEnabled(true);
881     disconnect(exportAction, SIGNAL(triggered()), 0, 0);
882     connect(exportAction, SIGNAL(triggered()), mintingView, SLOT(exportClicked()));
883 }
884
885
886 void BitcoinGUI::gotoAddressBookPage()
887 {
888     addressBookAction->setChecked(true);
889     centralWidget->setCurrentWidget(addressBookPage);
890
891     exportAction->setEnabled(true);
892     disconnect(exportAction, SIGNAL(triggered()), 0, 0);
893     connect(exportAction, SIGNAL(triggered()), addressBookPage, SLOT(exportClicked()));
894 }
895
896 void BitcoinGUI::gotoReceiveCoinsPage()
897 {
898     receiveCoinsAction->setChecked(true);
899     centralWidget->setCurrentWidget(receiveCoinsPage);
900
901     exportAction->setEnabled(true);
902     disconnect(exportAction, SIGNAL(triggered()), 0, 0);
903     connect(exportAction, SIGNAL(triggered()), receiveCoinsPage, SLOT(exportClicked()));
904 }
905
906 void BitcoinGUI::gotoSendCoinsPage()
907 {
908     sendCoinsAction->setChecked(true);
909     centralWidget->setCurrentWidget(sendCoinsPage);
910
911     exportAction->setEnabled(false);
912     disconnect(exportAction, SIGNAL(triggered()), 0, 0);
913 }
914
915 void BitcoinGUI::gotoSignMessageTab(QString addr)
916 {
917     // call show() in showTab_SM()
918     signVerifyMessageDialog->showTab_SM(true);
919
920     if(!addr.isEmpty())
921         signVerifyMessageDialog->setAddress_SM(addr);
922 }
923
924 void BitcoinGUI::gotoVerifyMessageTab(QString addr)
925 {
926     // call show() in showTab_VM()
927     signVerifyMessageDialog->showTab_VM(true);
928
929     if(!addr.isEmpty())
930         signVerifyMessageDialog->setAddress_VM(addr);
931 }
932
933 void BitcoinGUI::gotoMultisigPage()
934 {
935     multisigPage->show();
936     multisigPage->setFocus();
937 }
938
939 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
940 {
941     // Accept only URIs
942     if(event->mimeData()->hasUrls())
943         event->acceptProposedAction();
944 }
945
946 void BitcoinGUI::dropEvent(QDropEvent *event)
947 {
948     if(event->mimeData()->hasUrls())
949     {
950         int nValidUrisFound = 0;
951         QList<QUrl> uris = event->mimeData()->urls();
952         foreach(const QUrl &uri, uris)
953         {
954             if (sendCoinsPage->handleURI(uri.toString()))
955                 nValidUrisFound++;
956         }
957
958         // if valid URIs were found
959         if (nValidUrisFound)
960             gotoSendCoinsPage();
961         else
962             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."));
963     }
964
965     event->acceptProposedAction();
966 }
967
968 void BitcoinGUI::handleURI(QString strURI)
969 {
970     // URI has to be valid
971     if (sendCoinsPage->handleURI(strURI))
972     {
973         showNormalIfMinimized();
974         gotoSendCoinsPage();
975     }
976     else
977         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."));
978 }
979
980 void BitcoinGUI::setEncryptionStatus(int status)
981 {
982     switch(status)
983     {
984     case WalletModel::Unencrypted:
985         labelEncryptionIcon->hide();
986         encryptWalletAction->setChecked(false);
987         changePassphraseAction->setEnabled(false);
988         lockWalletAction->setEnabled(false);
989         unlockWalletAction->setEnabled(false);
990         unlockWalletMiningAction->setEnabled(false);
991         encryptWalletAction->setEnabled(true);
992         break;
993     case WalletModel::Unlocked:
994         labelEncryptionIcon->show();
995         labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
996         labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
997         encryptWalletAction->setChecked(true);
998         changePassphraseAction->setEnabled(true);
999         encryptWalletAction->setEnabled(true);
1000
1001         lockWalletAction->setEnabled(true);
1002         lockWalletAction->setChecked(false);
1003         unlockWalletAction->setEnabled(false);
1004         unlockWalletMiningAction->setEnabled(false);
1005
1006         if (fWalletUnlockMintOnly)
1007             unlockWalletMiningAction->setChecked(true);
1008         else
1009             unlockWalletAction->setChecked(true);
1010
1011         break;
1012     case WalletModel::Locked:
1013         labelEncryptionIcon->show();
1014         labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
1015         labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
1016         encryptWalletAction->setChecked(true);
1017         changePassphraseAction->setEnabled(true);
1018         encryptWalletAction->setEnabled(true);
1019
1020         lockWalletAction->setChecked(true);
1021         unlockWalletAction->setChecked(false);
1022         unlockWalletMiningAction->setChecked(false);
1023
1024         lockWalletAction->setEnabled(false);
1025         unlockWalletAction->setEnabled(true);
1026         unlockWalletMiningAction->setEnabled(true);
1027         break;
1028     }
1029 }
1030
1031 void BitcoinGUI::encryptWallet(bool status)
1032 {
1033     if(!walletModel)
1034         return;
1035     AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt:
1036                                      AskPassphraseDialog::Decrypt, this);
1037     dlg.setModel(walletModel);
1038     dlg.exec();
1039
1040     setEncryptionStatus(walletModel->getEncryptionStatus());
1041 }
1042
1043 void BitcoinGUI::unlockWalletMining(bool status)
1044 {
1045     if(!walletModel)
1046         return;
1047
1048     // Unlock wallet when requested by wallet model
1049     if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1050     {
1051         AskPassphraseDialog dlg(AskPassphraseDialog::UnlockMining, this);
1052         dlg.setModel(walletModel);
1053         dlg.exec();
1054     }
1055 }
1056
1057 void BitcoinGUI::backupWallet()
1058 {
1059 #if QT_VERSION < 0x050000
1060     QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1061 #else
1062     QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1063 #endif
1064     QString filename = QFileDialog::getSaveFileName(this, tr("Backup Wallet"), saveDir, tr("Wallet Data (*.dat)"));
1065     if(!filename.isEmpty()) {
1066         if(!walletModel->backupWallet(filename)) {
1067             QMessageBox::warning(this, tr("Backup Failed"), tr("There was an error trying to save the wallet data to the new location."));
1068         }
1069     }
1070 }
1071
1072 void BitcoinGUI::dumpWallet()
1073 {
1074    if(!walletModel)
1075       return;
1076
1077    WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1078    if(!ctx.isValid())
1079    {
1080        // Unlock wallet failed or was cancelled
1081        return;
1082    }
1083
1084 #if QT_VERSION < 0x050000
1085     QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1086 #else
1087     QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1088 #endif
1089     QString filename = QFileDialog::getSaveFileName(this, tr("Dump Wallet"), saveDir, tr("Wallet dump (*.txt)"));
1090     if(!filename.isEmpty()) {
1091         if(!walletModel->dumpWallet(filename)) {
1092             message(tr("Dump failed"),
1093                          tr("An error happened while trying to save the keys to your location.\n"
1094                             "Keys were not saved.")
1095                       ,CClientUIInterface::MSG_ERROR);
1096         }
1097         else
1098           message(tr("Dump successful"),
1099                        tr("Keys were saved to this file:\n%2")
1100                        .arg(filename)
1101                       ,CClientUIInterface::MSG_INFORMATION);
1102     }
1103 }
1104
1105 void BitcoinGUI::importWallet()
1106 {
1107    if(!walletModel)
1108       return;
1109
1110    WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1111    if(!ctx.isValid())
1112    {
1113        // Unlock wallet failed or was cancelled
1114        return;
1115    }
1116
1117 #if QT_VERSION < 0x050000
1118     QString openDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1119 #else
1120     QString openDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1121 #endif
1122     QString filename = QFileDialog::getOpenFileName(this, tr("Import Wallet"), openDir, tr("Wallet dump (*.txt)"));
1123     if(!filename.isEmpty()) {
1124         if(!walletModel->importWallet(filename)) {
1125             message(tr("Import Failed"),
1126                          tr("An error happened while trying to import the keys.\n"
1127                             "Some or all keys from:\n %1,\n were not imported into your wallet.")
1128                          .arg(filename)
1129                       ,CClientUIInterface::MSG_ERROR);
1130         }
1131         else
1132           message(tr("Import Successful"),
1133                        tr("All keys from:\n %1,\n were imported into your wallet.")
1134                        .arg(filename)
1135                       ,CClientUIInterface::MSG_INFORMATION);
1136     }
1137 }
1138
1139
1140 void BitcoinGUI::changePassphrase()
1141 {
1142     AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
1143     dlg.setModel(walletModel);
1144     dlg.exec();
1145 }
1146
1147 void BitcoinGUI::unlockWallet()
1148 {
1149     if(!walletModel)
1150         return;
1151     // Unlock wallet when requested by wallet model
1152     if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1153     {
1154         AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
1155         dlg.setModel(walletModel);
1156         dlg.exec();
1157     }
1158 }
1159
1160 void BitcoinGUI::lockWallet()
1161 {
1162     if(!walletModel)
1163         return;
1164
1165     walletModel->setWalletLocked(true);
1166 }
1167
1168 void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden)
1169 {
1170     // activateWindow() (sometimes) helps with keyboard focus on Windows
1171     if (isHidden())
1172     {
1173         // Make sure the window is not minimized
1174         setWindowState(windowState() & (~Qt::WindowMinimized | Qt::WindowActive));
1175         // Then show it
1176         show();
1177         raise();
1178         activateWindow();
1179     }
1180     else if (isMinimized())
1181     {
1182         showNormal();
1183         raise();
1184         activateWindow();
1185     }
1186     else if (GUIUtil::isObscured(this))
1187     {
1188         raise();
1189         activateWindow();
1190         if(fToggleHidden)
1191         {
1192             Sleep(1);
1193             if (GUIUtil::isObscured(this))
1194                 hide();
1195         }
1196     }
1197     else if(fToggleHidden)
1198         hide();
1199 }
1200
1201 void BitcoinGUI::toggleHidden()
1202 {
1203     showNormalIfMinimized(true);
1204 }
1205
1206 void BitcoinGUI::error(const QString &title, const QString &message, bool modal)
1207 {
1208     // Report errors from network/worker thread
1209     if(modal)
1210     {
1211         QMessageBox::critical(this, title, message, QMessageBox::Ok, QMessageBox::Ok);
1212     } else {
1213         notificator->notify(Notificator::Critical, title, message);
1214     }
1215 }