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