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