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