#include <iostream>
+extern bool fWalletUnlockMintOnly;
+
BitcoinGUI::BitcoinGUI(QWidget *parent):
QMainWindow(parent),
clientModel(0),
walletModel(0),
encryptWalletAction(0),
+ lockWalletAction(0),
+ unlockWalletAction(0),
+ unlockWalletMiningAction(0),
changePassphraseAction(0),
aboutQtAction(0),
trayIcon(0),
// Status bar notification icons
QFrame *frameBlocks = new QFrame();
frameBlocks->setContentsMargins(0,0,0,0);
- frameBlocks->setMinimumWidth(56);
- frameBlocks->setMaximumWidth(56);
+ frameBlocks->setMinimumWidth(72);
+ frameBlocks->setMaximumWidth(72);
QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);
frameBlocksLayout->setContentsMargins(3,0,3,0);
frameBlocksLayout->setSpacing(3);
labelEncryptionIcon = new QLabel();
+ labelMiningIcon = new QLabel();
labelConnectionsIcon = new QLabel();
labelBlocksIcon = new QLabel();
frameBlocksLayout->addStretch();
frameBlocksLayout->addWidget(labelEncryptionIcon);
frameBlocksLayout->addStretch();
+ frameBlocksLayout->addWidget(labelMiningIcon);
+ frameBlocksLayout->addStretch();
frameBlocksLayout->addWidget(labelConnectionsIcon);
frameBlocksLayout->addStretch();
frameBlocksLayout->addWidget(labelBlocksIcon);
backupWalletAction = new QAction(QIcon(":/icons/filesave"), tr("&Backup Wallet..."), this);
backupWalletAction->setToolTip(tr("Backup wallet to another location"));
dumpWalletAction = new QAction(QIcon(":/icons/dump"), tr("&Dump Wallet..."), this);
- dumpWalletAction->setStatusTip(tr("Export wallet's keys to a text file"));
+ dumpWalletAction->setStatusTip(tr("Dump keys to a text file"));
importWalletAction = new QAction(QIcon(":/icons/import"), tr("&Import Wallet..."), this);
- importWalletAction->setStatusTip(tr("Import a file's keys into a wallet"));
+ importWalletAction->setStatusTip(tr("Import keys into a wallet"));
changePassphraseAction = new QAction(QIcon(":/icons/key"), tr("&Change Passphrase..."), this);
changePassphraseAction->setToolTip(tr("Change the passphrase used for wallet encryption"));
signMessageAction = new QAction(QIcon(":/icons/edit"), tr("Sign &message..."), this);
verifyMessageAction = new QAction(QIcon(":/icons/transaction_0"), tr("&Verify message..."), this);
+ lockWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Lock wallet"), this);
+ lockWalletAction->setToolTip(tr("Lock wallet"));
+ lockWalletAction->setCheckable(true);
+
+ unlockWalletAction = new QAction(QIcon(":/icons/lock_open"), tr("Unlo&ck wallet"), this);
+ unlockWalletAction->setToolTip(tr("Unlock wallet"));
+ unlockWalletAction->setCheckable(true);
+
+ unlockWalletMiningAction = new QAction(QIcon(":/icons/mining_active"), tr("Unlo&ck wallet for mining"), this);
+ unlockWalletMiningAction->setToolTip(tr("Unlock wallet for mining"));
+ unlockWalletMiningAction->setCheckable(true);
+
exportAction = new QAction(QIcon(":/icons/export"), tr("&Export..."), this);
exportAction->setToolTip(tr("Export the data in the current tab to a file"));
openRPCConsoleAction = new QAction(QIcon(":/icons/debugwindow"), tr("&Debug window"), this);
connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked()));
connect(toggleHideAction, SIGNAL(triggered()), this, SLOT(toggleHidden()));
connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool)));
+ connect(lockWalletAction, SIGNAL(triggered(bool)), this, SLOT(lockWallet()));
+ connect(unlockWalletAction, SIGNAL(triggered(bool)), this, SLOT(unlockWallet()));
+ connect(unlockWalletMiningAction, SIGNAL(triggered(bool)), this, SLOT(unlockWalletMining(bool)));
connect(backupWalletAction, SIGNAL(triggered()), this, SLOT(backupWallet()));
connect(dumpWalletAction, SIGNAL(triggered()), this, SLOT(dumpWallet()));
connect(importWalletAction, SIGNAL(triggered()), this, SLOT(importWallet()));
file->addAction(quitAction);
QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
- settings->addAction(encryptWalletAction);
- settings->addAction(changePassphraseAction);
+ QMenu *securityMenu = settings->addMenu(QIcon(":/icons/key"), tr("&Wallet security"));
+ securityMenu->addAction(encryptWalletAction);
+ securityMenu->addAction(changePassphraseAction);
+ securityMenu->addAction(unlockWalletAction);
+ securityMenu->addAction(unlockWalletMiningAction);
+ securityMenu->addAction(lockWalletAction);
settings->addSeparator();
settings->addAction(optionsAction);
setNumBlocks(clientModel->getNumBlocks(), clientModel->getNumBlocksOfPeers());
connect(clientModel, SIGNAL(numBlocksChanged(int,int)), this, SLOT(setNumBlocks(int,int)));
+ connect(clientModel, SIGNAL(numBlocksChanged(int,int)), this, SLOT(updateMining()));
// Report errors from network/worker thread
connect(clientModel, SIGNAL(error(QString,QString,bool)), this, SLOT(error(QString,QString,bool)));
setEncryptionStatus(walletModel->getEncryptionStatus());
connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));
+ connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(updateMining()));
// Balloon pop-up for new transaction
connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
progressBar->setToolTip(tooltip);
}
+void BitcoinGUI::updateMining()
+{
+ if(!walletModel)
+ return;
+
+ labelMiningIcon->setPixmap(QIcon(":/icons/mining_inactive").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
+
+ if (!clientModel->getNumConnections())
+ {
+ labelMiningIcon->setToolTip(tr("Wallet is offline"));
+ return;
+ }
+
+ if (walletModel->getEncryptionStatus() == WalletModel::Locked)
+ {
+ labelMiningIcon->setToolTip(tr("Wallet is locked"));
+ return;
+ }
+
+ if (clientModel->inInitialBlockDownload() || clientModel->getNumBlocksOfPeers() > clientModel->getNumBlocks())
+ {
+ labelMiningIcon->setToolTip(tr("Blockchain download is in progress"));
+ return;
+ }
+
+ uint64 nMinWeight = 0, nMaxWeight = 0, nTotalWeight = 0;
+ walletModel->getStakeWeight(nMinWeight, nMaxWeight, nTotalWeight);
+
+ if (nTotalWeight > 0)
+ {
+ labelMiningIcon->setPixmap(QIcon(":/icons/mining_active").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
+
+ double dNetworkWeight = clientModel->getPoSKernelPS();
+/*
+ double dDifficulty = clientModel->getDifficulty(true);
+ QString msg;
+
+ int nApproxTime = 4294967297 * dDifficulty / nTotalWeight;
+
+ if (nApproxTime < 60)
+ msg = tr("%n second(s)", "", nApproxTime);
+ else if (nApproxTime < 60*60)
+ msg = tr("%n minute(s)", "", nApproxTime / 60);
+ else if (nApproxTime < 24*60*60)
+ msg = tr("%n hour(s)", "", nApproxTime / 3600);
+ else
+ msg = tr("%n day(s)", "", nApproxTime / 86400);
+
+ 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));
+*/
+
+ labelMiningIcon->setToolTip(tr("Stake miner is active\nYour current stake weight is %1\nNetwork weight is %2").arg(nTotalWeight).arg(dNetworkWeight));
+ }
+ else
+ labelMiningIcon->setToolTip(tr("No suitable inputs were found"));
+}
+
void BitcoinGUI::error(const QString &title, const QString &message, bool modal)
{
// Report errors from network/worker thread
labelEncryptionIcon->hide();
encryptWalletAction->setChecked(false);
changePassphraseAction->setEnabled(false);
+ lockWalletAction->setEnabled(false);
+ unlockWalletAction->setEnabled(false);
+ unlockWalletMiningAction->setEnabled(false);
encryptWalletAction->setEnabled(true);
break;
case WalletModel::Unlocked:
encryptWalletAction->setChecked(true);
changePassphraseAction->setEnabled(true);
encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
+
+ lockWalletAction->setEnabled(true);
+ lockWalletAction->setChecked(false);
+ unlockWalletAction->setEnabled(false);
+ unlockWalletMiningAction->setEnabled(false);
+
+ if (fWalletUnlockMintOnly)
+ unlockWalletMiningAction->setEnabled(true);
+ else
+ unlockWalletAction->setChecked(true);
+
break;
case WalletModel::Locked:
labelEncryptionIcon->show();
encryptWalletAction->setChecked(true);
changePassphraseAction->setEnabled(true);
encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
+
+ lockWalletAction->setChecked(true);
+ unlockWalletAction->setChecked(false);
+ unlockWalletMiningAction->setChecked(false);
+
+ lockWalletAction->setEnabled(false);
+ unlockWalletAction->setEnabled(true);
+ unlockWalletMiningAction->setEnabled(true);
break;
}
}
setEncryptionStatus(walletModel->getEncryptionStatus());
}
+void BitcoinGUI::unlockWalletMining(bool status)
+{
+ if(!walletModel)
+ return;
+
+ // Unlock wallet when requested by wallet model
+ if(walletModel->getEncryptionStatus() == WalletModel::Locked)
+ {
+ AskPassphraseDialog dlg(AskPassphraseDialog::UnlockMining, this);
+ dlg.setModel(walletModel);
+ dlg.exec();
+ }
+}
+
void BitcoinGUI::backupWallet()
{
QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
#else
QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
#endif
- QString filename = QFileDialog::getSaveFileName(this, tr("Export Wallet"), saveDir, tr("Wallet Text (*.txt)"));
+ QString filename = QFileDialog::getSaveFileName(this, tr("Dump Wallet"), saveDir, tr("Wallet dump (*.txt)"));
if(!filename.isEmpty()) {
if(!walletModel->dumpWallet(filename)) {
- error(tr("DumpWallet Failed"),
+ error(tr("Dump failed"),
tr("An error happened while trying to save the keys to your location.\n"
- "Keys were not saved")
+ "Keys were not saved.")
,CClientUIInterface::MSG_ERROR);
}
else
- message(tr("DumpWallet Successful"),
+ message(tr("Dump successful"),
tr("Keys were saved to this file:\n%2")
.arg(filename)
,CClientUIInterface::MSG_INFORMATION);
#else
QString openDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
#endif
- QString filename = QFileDialog::getOpenFileName(this, tr("Import Wallet"), openDir, tr("Wallet Text (*.txt)"));
+ QString filename = QFileDialog::getOpenFileName(this, tr("Import Wallet"), openDir, tr("Wallet dump (*.txt)"));
if(!filename.isEmpty()) {
if(!walletModel->importWallet(filename)) {
error(tr("Import Failed"),
}
}
+void BitcoinGUI::lockWallet()
+{
+ if(!walletModel)
+ return;
+
+ walletModel->setWalletLocked(true);
+}
+
void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden)
{
// activateWindow() (sometimes) helps with keyboard focus on Windows