Add raise() for MultisigPage and for RpcConsole
[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     connect(openRPCConsoleAction, SIGNAL(triggered()), rpcConsole, SLOT(raise()));
208
209     aboutDialog = new AboutDialog(0);
210     optionsDialog = new OptionsDialog(0);
211
212     // Clicking on "Verify Message" in the address book sends you to the verify message tab
213     connect(addressBookPage, SIGNAL(verifyMessage(QString)), this, SLOT(gotoVerifyMessageTab(QString)));
214     // Clicking on "Sign Message" in the receive coins page sends you to the sign message tab
215     connect(receiveCoinsPage, SIGNAL(signMessage(QString)), this, SLOT(gotoSignMessageTab(QString)));
216
217     gotoOverviewPage();
218 }
219
220 BitcoinGUI::~BitcoinGUI()
221 {
222     if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu)
223         trayIcon->hide();
224 #ifdef Q_OS_MAC
225     delete appMenuBar;
226 #endif
227
228     delete rpcConsole;
229     delete aboutDialog;
230     delete optionsDialog;
231     delete multisigPage;
232     delete signVerifyMessageDialog;
233 }
234
235 void BitcoinGUI::createActions()
236 {
237     QActionGroup *tabGroup = new QActionGroup(this);
238
239     overviewAction = new QAction(QIcon(":/icons/overview"), tr("&Overview"), this);
240     overviewAction->setToolTip(tr("Show general overview of wallet"));
241     overviewAction->setCheckable(true);
242     overviewAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_1));
243     tabGroup->addAction(overviewAction);
244
245     sendCoinsAction = new QAction(QIcon(":/icons/send"), tr("&Send coins"), this);
246     sendCoinsAction->setToolTip(tr("Send coins to a NovaCoin address"));
247     sendCoinsAction->setCheckable(true);
248     sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2));
249     tabGroup->addAction(sendCoinsAction);
250
251     receiveCoinsAction = new QAction(QIcon(":/icons/receiving_addresses"), tr("&Receive coins"), this);
252     receiveCoinsAction->setToolTip(tr("Show the list of addresses for receiving payments"));
253     receiveCoinsAction->setCheckable(true);
254     receiveCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_3));
255     tabGroup->addAction(receiveCoinsAction);
256
257     historyAction = new QAction(QIcon(":/icons/history"), tr("&Transactions"), this);
258     historyAction->setToolTip(tr("Browse transaction history"));
259     historyAction->setCheckable(true);
260     historyAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_4));
261     tabGroup->addAction(historyAction);
262
263     mintingAction = new QAction(QIcon(":/icons/history"), tr("&Minting"), this);
264     mintingAction->setToolTip(tr("Show your minting capacity"));
265     mintingAction->setCheckable(true);
266     mintingAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_5));
267     tabGroup->addAction(mintingAction);
268
269     addressBookAction = new QAction(QIcon(":/icons/address-book"), tr("&Address Book"), this);
270     addressBookAction->setToolTip(tr("Edit the list of stored addresses and labels"));
271     addressBookAction->setCheckable(true);
272     addressBookAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_6));
273     tabGroup->addAction(addressBookAction);
274
275     multisigAction = new QAction(QIcon(":/icons/send"), tr("Multisig"), this);
276     multisigAction->setStatusTip(tr("Open window for working with multisig addresses"));
277     tabGroup->addAction(multisigAction);
278
279     connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
280     connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage()));
281     connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
282     connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
283     connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
284     connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
285     connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
286     connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage()));
287     connect(mintingAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
288     connect(mintingAction, SIGNAL(triggered()), this, SLOT(gotoMintingPage()));
289     connect(addressBookAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
290     connect(addressBookAction, SIGNAL(triggered()), this, SLOT(gotoAddressBookPage()));
291     connect(multisigAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
292     connect(multisigAction, SIGNAL(triggered()), this, SLOT(gotoMultisigPage()));
293
294     quitAction = new QAction(QIcon(":/icons/quit"), tr("E&xit"), this);
295     quitAction->setStatusTip(tr("Quit application"));
296     quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
297     quitAction->setMenuRole(QAction::QuitRole);
298     aboutAction = new QAction(QIcon(":/icons/bitcoin"), tr("&About NovaCoin"), this);
299     aboutAction->setStatusTip(tr("Show information about NovaCoin"));
300     aboutAction->setMenuRole(QAction::AboutRole);
301 #if QT_VERSION < 0x050000
302     aboutQtAction = new QAction(QIcon(":/trolltech/qmessagebox/images/qtlogo-64.png"), tr("About &Qt"), this);
303 #else
304     aboutQtAction = new QAction(QIcon(":/qt-project.org/qmessagebox/images/qtlogo-64.png"), tr("About &Qt"), this);
305 #endif
306     aboutQtAction->setStatusTip(tr("Show information about Qt"));
307     aboutQtAction->setMenuRole(QAction::AboutQtRole);
308     optionsAction = new QAction(QIcon(":/icons/options"), tr("&Options..."), this);
309     optionsAction->setStatusTip(tr("Modify configuration options for NovaCoin"));
310     optionsAction->setMenuRole(QAction::PreferencesRole);
311     toggleHideAction = new QAction(QIcon(":/icons/bitcoin"), tr("&Show / Hide"), this);
312     encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet..."), this);
313     encryptWalletAction->setStatusTip(tr("Encrypt or decrypt wallet"));
314     encryptWalletAction->setCheckable(true);
315     backupWalletAction = new QAction(QIcon(":/icons/filesave"), tr("&Backup Wallet..."), this);
316     backupWalletAction->setStatusTip(tr("Backup wallet to another location"));
317     dumpWalletAction = new QAction(QIcon(":/icons/dump"), tr("&Dump Wallet..."), this);
318     dumpWalletAction->setStatusTip(tr("Dump keys to a text file"));
319     importWalletAction = new QAction(QIcon(":/icons/import"), tr("&Import Wallet..."), this);
320     importWalletAction->setStatusTip(tr("Import keys into a wallet"));
321     changePassphraseAction = new QAction(QIcon(":/icons/key"), tr("&Change Passphrase..."), this);
322     changePassphraseAction->setStatusTip(tr("Change the passphrase used for wallet encryption"));
323     signMessageAction = new QAction(QIcon(":/icons/edit"), tr("Sign &message..."), this);
324     signMessageAction->setStatusTip(tr("Sign messages with your Novacoin addresses to prove you own them"));
325     verifyMessageAction = new QAction(QIcon(":/icons/transaction_0"), tr("&Verify message..."), this);
326     verifyMessageAction->setStatusTip(tr("Verify messages to ensure they were signed with specified Novacoin addresses"));
327
328     lockWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Lock wallet"), this);
329     lockWalletAction->setStatusTip(tr("Lock wallet"));
330     lockWalletAction->setCheckable(true);
331
332     unlockWalletAction = new QAction(QIcon(":/icons/lock_open"), tr("Unlo&ck wallet"), this);
333     unlockWalletAction->setStatusTip(tr("Unlock wallet"));
334     unlockWalletAction->setCheckable(true);
335
336     unlockWalletMiningAction = new QAction(QIcon(":/icons/mining_active"), tr("Unlo&ck wallet for mining"), this);
337     unlockWalletMiningAction->setStatusTip(tr("Unlock wallet for mining"));
338     unlockWalletMiningAction->setCheckable(true);
339
340     exportAction = new QAction(QIcon(":/icons/export"), tr("&Export..."), this);
341     exportAction->setStatusTip(tr("Export the data in the current tab to a file"));
342     openRPCConsoleAction = new QAction(QIcon(":/icons/debugwindow"), tr("&Debug window"), this);
343     openRPCConsoleAction->setStatusTip(tr("Open debugging and diagnostic console"));
344
345     connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
346     connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked()));
347     connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
348     connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked()));
349     connect(toggleHideAction, SIGNAL(triggered()), this, SLOT(toggleHidden()));
350     connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool)));
351     connect(lockWalletAction, SIGNAL(triggered(bool)), this, SLOT(lockWallet()));
352     connect(unlockWalletAction, SIGNAL(triggered(bool)), this, SLOT(unlockWallet()));
353     connect(unlockWalletMiningAction, SIGNAL(triggered(bool)), this, SLOT(unlockWalletMining(bool)));
354     connect(backupWalletAction, SIGNAL(triggered()), this, SLOT(backupWallet()));
355     connect(dumpWalletAction, SIGNAL(triggered()), this, SLOT(dumpWallet()));
356     connect(importWalletAction, SIGNAL(triggered()), this, SLOT(importWallet()));
357     connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase()));
358     connect(signMessageAction, SIGNAL(triggered()), this, SLOT(gotoSignMessageTab()));
359     connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(gotoVerifyMessageTab()));
360 }
361
362 void BitcoinGUI::createMenuBar()
363 {
364 #ifdef Q_OS_MAC
365     // Create a decoupled menu bar on Mac which stays even if the window is closed
366     appMenuBar = new QMenuBar();
367 #else
368     // Get the main window's menu bar on other platforms
369     appMenuBar = menuBar();
370 #endif
371
372     // Configure the menus
373     QMenu *file = appMenuBar->addMenu(tr("&File"));
374     file->addAction(backupWalletAction);
375     file->addSeparator();
376     file->addAction(dumpWalletAction);
377     file->addAction(importWalletAction);
378     file->addAction(exportAction);
379     file->addAction(signMessageAction);
380     file->addAction(verifyMessageAction);
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->addSeparator();
397     help->addAction(aboutAction);
398     help->addAction(aboutQtAction);
399 }
400
401 void BitcoinGUI::createToolBars()
402 {
403     QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));
404     toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
405     toolbar->addAction(overviewAction);
406     toolbar->addAction(sendCoinsAction);
407     toolbar->addAction(receiveCoinsAction);
408     toolbar->addAction(historyAction);
409     toolbar->addAction(mintingAction);
410     toolbar->addAction(addressBookAction);
411
412     QToolBar *toolbar2 = addToolBar(tr("Actions toolbar"));
413     toolbar2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
414     toolbar2->addAction(exportAction);
415     toolbar2->setVisible(false);
416     
417 }
418
419 void BitcoinGUI::setClientModel(ClientModel *clientModel)
420 {
421     this->clientModel = clientModel;
422     if(clientModel)
423     {
424         // Replace some strings and icons, when using the testnet
425         if(clientModel->isTestNet())
426         {
427             setWindowTitle(windowTitle() + QString(" ") + tr("[testnet]"));
428 #ifndef Q_OS_MAC
429             qApp->setWindowIcon(QIcon(":icons/bitcoin_testnet"));
430             setWindowIcon(QIcon(":icons/bitcoin_testnet"));
431 #else
432             MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
433 #endif
434             if(trayIcon)
435             {
436                 trayIcon->setToolTip(tr("NovaCoin client") + QString(" ") + tr("[testnet]"));
437                 trayIcon->setIcon(QIcon(":/icons/toolbar_testnet"));
438                 toggleHideAction->setIcon(QIcon(":/icons/toolbar_testnet"));
439             }
440
441             aboutAction->setIcon(QIcon(":/icons/toolbar_testnet"));
442         }
443
444         // Keep up to date with client
445         setNumConnections(clientModel->getNumConnections());
446         connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
447
448         setNumBlocks(clientModel->getNumBlocks(), clientModel->getNumBlocksOfPeers());
449         connect(clientModel, SIGNAL(numBlocksChanged(int,int)), this, SLOT(setNumBlocks(int,int)));
450
451         QTimer *timer = new QTimer(this);
452         connect(timer, SIGNAL(timeout()), this, SLOT(updateMining()));
453         timer->start(10*1000); //10 seconds
454
455         // Report errors from network/worker thread
456         connect(clientModel, SIGNAL(error(QString,QString,bool)), this, SLOT(error(QString,QString,bool)));
457
458         rpcConsole->setClientModel(clientModel);
459         addressBookPage->setOptionsModel(clientModel->getOptionsModel());
460         receiveCoinsPage->setOptionsModel(clientModel->getOptionsModel());
461     }
462 }
463
464 void BitcoinGUI::setWalletModel(WalletModel *walletModel)
465 {
466     this->walletModel = walletModel;
467     if(walletModel)
468     {
469         // Report errors from wallet thread
470         connect(walletModel, SIGNAL(error(QString,QString,bool)), this, SLOT(error(QString,QString,bool)));
471
472         // Put transaction list in tabs
473         transactionView->setModel(walletModel);
474         mintingView->setModel(walletModel);
475
476         overviewPage->setModel(walletModel);
477         addressBookPage->setModel(walletModel->getAddressTableModel());
478         receiveCoinsPage->setModel(walletModel->getAddressTableModel());
479         sendCoinsPage->setModel(walletModel);
480         signVerifyMessageDialog->setModel(walletModel);
481         multisigPage->setModel(walletModel);
482
483         setEncryptionStatus(walletModel->getEncryptionStatus());
484         connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));
485         connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(updateMining()));
486
487         // Balloon pop-up for new transaction
488         connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
489                 this, SLOT(incomingTransaction(QModelIndex,int,int)));
490
491         // Ask for passphrase if needed
492         connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
493     }
494 }
495
496 void BitcoinGUI::createTrayIcon()
497 {
498     QMenu *trayIconMenu;
499 #ifndef Q_OS_MAC
500     trayIcon = new QSystemTrayIcon(this);
501     trayIconMenu = new QMenu(this);
502     trayIcon->setContextMenu(trayIconMenu);
503     trayIcon->setToolTip(tr("NovaCoin client"));
504     trayIcon->setIcon(QIcon(":/icons/toolbar"));
505     connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
506             this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
507     trayIcon->show();
508 #else
509     // Note: On Mac, the dock icon is used to provide the tray's functionality.
510     MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance();
511     dockIconHandler->setMainWindow((QMainWindow *)this);
512     trayIconMenu = dockIconHandler->dockMenu();
513 #endif
514
515     // Configuration of the tray icon (or dock icon) icon menu
516     trayIconMenu->addAction(toggleHideAction);
517     trayIconMenu->addSeparator();
518     trayIconMenu->addAction(sendCoinsAction);
519     trayIconMenu->addAction(multisigAction);
520     trayIconMenu->addAction(receiveCoinsAction);
521     trayIconMenu->addSeparator();
522     trayIconMenu->addAction(signMessageAction);
523     trayIconMenu->addAction(verifyMessageAction);
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::gotoMultisigPage()
935 {
936     multisigPage->show();
937     multisigPage->raise();
938     multisigPage->activateWindow();
939 }
940
941 void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
942 {
943     // Accept only URIs
944     if(event->mimeData()->hasUrls())
945         event->acceptProposedAction();
946 }
947
948 void BitcoinGUI::dropEvent(QDropEvent *event)
949 {
950     if(event->mimeData()->hasUrls())
951     {
952         int nValidUrisFound = 0;
953         QList<QUrl> uris = event->mimeData()->urls();
954         foreach(const QUrl &uri, uris)
955         {
956             if (sendCoinsPage->handleURI(uri.toString()))
957                 nValidUrisFound++;
958         }
959
960         // if valid URIs were found
961         if (nValidUrisFound)
962             gotoSendCoinsPage();
963         else
964             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."));
965     }
966
967     event->acceptProposedAction();
968 }
969
970 void BitcoinGUI::handleURI(QString strURI)
971 {
972     // URI has to be valid
973     if (sendCoinsPage->handleURI(strURI))
974     {
975         showNormalIfMinimized();
976         gotoSendCoinsPage();
977     }
978     else
979         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."));
980 }
981
982 void BitcoinGUI::setEncryptionStatus(int status)
983 {
984     switch(status)
985     {
986     case WalletModel::Unencrypted:
987         labelEncryptionIcon->hide();
988         encryptWalletAction->setChecked(false);
989         changePassphraseAction->setEnabled(false);
990         lockWalletAction->setEnabled(false);
991         unlockWalletAction->setEnabled(false);
992         unlockWalletMiningAction->setEnabled(false);
993         encryptWalletAction->setEnabled(true);
994         break;
995     case WalletModel::Unlocked:
996         labelEncryptionIcon->show();
997         labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
998         labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
999         encryptWalletAction->setChecked(true);
1000         changePassphraseAction->setEnabled(true);
1001         encryptWalletAction->setEnabled(true);
1002
1003         lockWalletAction->setEnabled(true);
1004         lockWalletAction->setChecked(false);
1005         unlockWalletAction->setEnabled(false);
1006         unlockWalletMiningAction->setEnabled(false);
1007
1008         if (fWalletUnlockMintOnly)
1009             unlockWalletMiningAction->setChecked(true);
1010         else
1011             unlockWalletAction->setChecked(true);
1012
1013         break;
1014     case WalletModel::Locked:
1015         labelEncryptionIcon->show();
1016         labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
1017         labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
1018         encryptWalletAction->setChecked(true);
1019         changePassphraseAction->setEnabled(true);
1020         encryptWalletAction->setEnabled(true);
1021
1022         lockWalletAction->setChecked(true);
1023         unlockWalletAction->setChecked(false);
1024         unlockWalletMiningAction->setChecked(false);
1025
1026         lockWalletAction->setEnabled(false);
1027         unlockWalletAction->setEnabled(true);
1028         unlockWalletMiningAction->setEnabled(true);
1029         break;
1030     }
1031 }
1032
1033 void BitcoinGUI::encryptWallet(bool status)
1034 {
1035     if(!walletModel)
1036         return;
1037     AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt:
1038                                      AskPassphraseDialog::Decrypt, this);
1039     dlg.setModel(walletModel);
1040     dlg.exec();
1041
1042     setEncryptionStatus(walletModel->getEncryptionStatus());
1043 }
1044
1045 void BitcoinGUI::unlockWalletMining(bool status)
1046 {
1047     if(!walletModel)
1048         return;
1049
1050     // Unlock wallet when requested by wallet model
1051     if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1052     {
1053         AskPassphraseDialog dlg(AskPassphraseDialog::UnlockMining, this);
1054         dlg.setModel(walletModel);
1055         dlg.exec();
1056     }
1057 }
1058
1059 void BitcoinGUI::backupWallet()
1060 {
1061 #if QT_VERSION < 0x050000
1062     QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1063 #else
1064     QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1065 #endif
1066     QString filename = QFileDialog::getSaveFileName(this, tr("Backup Wallet"), saveDir, tr("Wallet Data (*.dat)"));
1067     if(!filename.isEmpty()) {
1068         if(!walletModel->backupWallet(filename)) {
1069             QMessageBox::warning(this, tr("Backup Failed"), tr("There was an error trying to save the wallet data to the new location."));
1070         }
1071     }
1072 }
1073
1074 void BitcoinGUI::dumpWallet()
1075 {
1076    if(!walletModel)
1077       return;
1078
1079    WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1080    if(!ctx.isValid())
1081    {
1082        // Unlock wallet failed or was cancelled
1083        return;
1084    }
1085
1086 #if QT_VERSION < 0x050000
1087     QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1088 #else
1089     QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1090 #endif
1091     QString filename = QFileDialog::getSaveFileName(this, tr("Dump Wallet"), saveDir, tr("Wallet dump (*.txt)"));
1092     if(!filename.isEmpty()) {
1093         if(!walletModel->dumpWallet(filename)) {
1094             message(tr("Dump failed"),
1095                          tr("An error happened while trying to save the keys to your location.\n"
1096                             "Keys were not saved.")
1097                       ,CClientUIInterface::MSG_ERROR);
1098         }
1099         else
1100           message(tr("Dump successful"),
1101                        tr("Keys were saved to this file:\n%2")
1102                        .arg(filename)
1103                       ,CClientUIInterface::MSG_INFORMATION);
1104     }
1105 }
1106
1107 void BitcoinGUI::importWallet()
1108 {
1109    if(!walletModel)
1110       return;
1111
1112    WalletModel::UnlockContext ctx(walletModel->requestUnlock());
1113    if(!ctx.isValid())
1114    {
1115        // Unlock wallet failed or was cancelled
1116        return;
1117    }
1118
1119 #if QT_VERSION < 0x050000
1120     QString openDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
1121 #else
1122     QString openDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
1123 #endif
1124     QString filename = QFileDialog::getOpenFileName(this, tr("Import Wallet"), openDir, tr("Wallet dump (*.txt)"));
1125     if(!filename.isEmpty()) {
1126         if(!walletModel->importWallet(filename)) {
1127             message(tr("Import Failed"),
1128                          tr("An error happened while trying to import the keys.\n"
1129                             "Some or all keys from:\n %1,\n were not imported into your wallet.")
1130                          .arg(filename)
1131                       ,CClientUIInterface::MSG_ERROR);
1132         }
1133         else
1134           message(tr("Import Successful"),
1135                        tr("All keys from:\n %1,\n were imported into your wallet.")
1136                        .arg(filename)
1137                       ,CClientUIInterface::MSG_INFORMATION);
1138     }
1139 }
1140
1141
1142 void BitcoinGUI::changePassphrase()
1143 {
1144     AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
1145     dlg.setModel(walletModel);
1146     dlg.exec();
1147 }
1148
1149 void BitcoinGUI::unlockWallet()
1150 {
1151     if(!walletModel)
1152         return;
1153     // Unlock wallet when requested by wallet model
1154     if(walletModel->getEncryptionStatus() == WalletModel::Locked)
1155     {
1156         AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
1157         dlg.setModel(walletModel);
1158         dlg.exec();
1159     }
1160 }
1161
1162 void BitcoinGUI::lockWallet()
1163 {
1164     if(!walletModel)
1165         return;
1166
1167     walletModel->setWalletLocked(true);
1168 }
1169
1170 void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden)
1171 {
1172     // activateWindow() (sometimes) helps with keyboard focus on Windows
1173     if (isHidden())
1174     {
1175         // Make sure the window is not minimized
1176         setWindowState(windowState() & (~Qt::WindowMinimized | Qt::WindowActive));
1177         // Then show it
1178         show();
1179         raise();
1180         activateWindow();
1181     }
1182     else if (isMinimized())
1183     {
1184         showNormal();
1185         raise();
1186         activateWindow();
1187     }
1188     else if (GUIUtil::isObscured(this))
1189     {
1190         raise();
1191         activateWindow();
1192         if(fToggleHidden)
1193         {
1194             Sleep(1);
1195             if (GUIUtil::isObscured(this))
1196                 hide();
1197         }
1198     }
1199     else if(fToggleHidden)
1200         hide();
1201 }
1202
1203 void BitcoinGUI::toggleHidden()
1204 {
1205     showNormalIfMinimized(true);
1206 }
1207
1208 void BitcoinGUI::error(const QString &title, const QString &message, bool modal)
1209 {
1210     // Report errors from network/worker thread
1211     if(modal)
1212     {
1213         QMessageBox::critical(this, title, message, QMessageBox::Ok, QMessageBox::Ok);
1214     } else {
1215         notificator->notify(Notificator::Critical, title, message);
1216     }
1217 }