diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2011-08-23 20:08:42 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2011-08-23 20:08:42 +0200 |
commit | ae8adeb90abb334b8e5712124e62461eca77c12f (patch) | |
tree | e35c4b1e07771c8c642bbffa65456ce309461d7e /src/qt | |
parent | adce862c2795142a5f56933584abffdbe3599472 (diff) |
Wallet encryption part 1: show wallet encryption status
Diffstat (limited to 'src/qt')
-rw-r--r-- | src/qt/bitcoin.qrc | 2 | ||||
-rw-r--r-- | src/qt/bitcoingui.cpp | 30 | ||||
-rw-r--r-- | src/qt/bitcoingui.h | 3 | ||||
-rw-r--r-- | src/qt/guiconstants.h | 5 | ||||
-rw-r--r-- | src/qt/res/icons/lock_closed.png | bin | 0 -> 1237 bytes | |||
-rw-r--r-- | src/qt/res/icons/lock_open.png | bin | 0 -> 1442 bytes | |||
-rw-r--r-- | src/qt/walletmodel.cpp | 23 | ||||
-rw-r--r-- | src/qt/walletmodel.h | 12 |
8 files changed, 70 insertions, 5 deletions
diff --git a/src/qt/bitcoin.qrc b/src/qt/bitcoin.qrc index 629349c65d..1d5a58a4af 100644 --- a/src/qt/bitcoin.qrc +++ b/src/qt/bitcoin.qrc @@ -34,6 +34,8 @@ <file alias="tx_input">res/icons/tx_input.png</file> <file alias="tx_output">res/icons/tx_output.png</file> <file alias="tx_inout">res/icons/tx_inout.png</file> + <file alias="lock_closed">res/icons/lock_closed.png</file> + <file alias="lock_open">res/icons/lock_open.png</file> </qresource> <qresource prefix="/images"> <file alias="about">res/images/about.png</file> diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index dd94652e3a..22987267ec 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -18,6 +18,7 @@ #include "transactionview.h" #include "overviewpage.h" #include "bitcoinunits.h" +#include "guiconstants.h" #include <QApplication> #include <QMainWindow> @@ -118,9 +119,12 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks); frameBlocksLayout->setContentsMargins(3,0,3,0); frameBlocksLayout->setSpacing(3); + labelEncryptionIcon = new QLabel(); labelConnectionsIcon = new QLabel(); labelBlocksIcon = new QLabel(); frameBlocksLayout->addStretch(); + frameBlocksLayout->addWidget(labelEncryptionIcon); + frameBlocksLayout->addStretch(); frameBlocksLayout->addWidget(labelConnectionsIcon); frameBlocksLayout->addStretch(); frameBlocksLayout->addWidget(labelBlocksIcon); @@ -244,6 +248,9 @@ void BitcoinGUI::setWalletModel(WalletModel *walletModel) receiveCoinsPage->setModel(walletModel->getAddressTableModel()); sendCoinsPage->setModel(walletModel); + setEncryptionStatus(walletModel->getEncryptionStatus()); + connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int))); + // Balloon popup for new transaction connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(incomingTransaction(QModelIndex,int,int))); @@ -300,7 +307,7 @@ void BitcoinGUI::setNumConnections(int count) case 7: case 8: case 9: icon = ":/icons/connect_3"; break; default: icon = ":/icons/connect_4"; break; } - labelConnectionsIcon->setPixmap(QIcon(icon).pixmap(16,16)); + labelConnectionsIcon->setPixmap(QIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE)); labelConnectionsIcon->setToolTip(tr("%n active connection(s) to Bitcoin network", "", count)); } @@ -351,7 +358,7 @@ void BitcoinGUI::setNumBlocks(int count) if(secs < 30*60) { tooltip = tr("Up to date") + QString("\n") + tooltip; - labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(16,16)); + labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE)); } else { @@ -531,3 +538,22 @@ void BitcoinGUI::dropEvent(QDropEvent *event) event->acceptProposedAction(); } +void BitcoinGUI::setEncryptionStatus(int status) +{ + switch(status) + { + case WalletModel::Unencrypted: + labelEncryptionIcon->hide(); + break; + case WalletModel::Unlocked: + labelEncryptionIcon->show(); + labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE)); + labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>")); + break; + case WalletModel::Locked: + labelEncryptionIcon->show(); + labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE)); + labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>")); + break; + } +} diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 377da72611..4b7131710c 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -57,6 +57,7 @@ private: AddressBookPage *receiveCoinsPage; SendCoinsDialog *sendCoinsPage; + QLabel *labelEncryptionIcon; QLabel *labelConnectionsIcon; QLabel *labelBlocksIcon; QLabel *progressBarLabel; @@ -85,6 +86,8 @@ private: public slots: void setNumConnections(int count); void setNumBlocks(int count); + void setEncryptionStatus(int status); + void error(const QString &title, const QString &message); /* It is currently not possible to pass a return value to another thread through BlockingQueuedConnection, so use an indirected pointer. diff --git a/src/qt/guiconstants.h b/src/qt/guiconstants.h index 7fbf7fcd3a..b7870199bb 100644 --- a/src/qt/guiconstants.h +++ b/src/qt/guiconstants.h @@ -1,9 +1,12 @@ #ifndef GUICONSTANTS_H #define GUICONSTANTS_H -/* milliseconds between model updates */ +/* Milliseconds between model updates */ static const int MODEL_UPDATE_DELAY = 500; +/* Size of icons in status bar */ +static const int STATUSBAR_ICONSIZE = 16; + /* Invalid field background style */ #define STYLE_INVALID "background:#FF8080" diff --git a/src/qt/res/icons/lock_closed.png b/src/qt/res/icons/lock_closed.png Binary files differnew file mode 100644 index 0000000000..ce8da0bec7 --- /dev/null +++ b/src/qt/res/icons/lock_closed.png diff --git a/src/qt/res/icons/lock_open.png b/src/qt/res/icons/lock_open.png Binary files differnew file mode 100644 index 0000000000..6a3a8edb23 --- /dev/null +++ b/src/qt/res/icons/lock_open.png diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 10b3738c67..9a7b56d33e 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -12,7 +12,8 @@ WalletModel::WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *parent) : QObject(parent), wallet(wallet), optionsModel(optionsModel), addressTableModel(0), transactionTableModel(0), - cachedBalance(0), cachedUnconfirmedBalance(0), cachedNumTransactions(0) + cachedBalance(0), cachedUnconfirmedBalance(0), cachedNumTransactions(0), + cachedEncryptionStatus(Unencrypted) { // Until signal notifications is built into the bitcoin core, // simply update everything after polling using a timer. @@ -49,6 +50,7 @@ void WalletModel::update() qint64 newBalance = getBalance(); qint64 newUnconfirmedBalance = getUnconfirmedBalance(); int newNumTransactions = getNumTransactions(); + EncryptionStatus newEncryptionStatus = getEncryptionStatus(); if(cachedBalance != newBalance || cachedUnconfirmedBalance != newUnconfirmedBalance) emit balanceChanged(newBalance, newUnconfirmedBalance); @@ -56,6 +58,9 @@ void WalletModel::update() if(cachedNumTransactions != newNumTransactions) emit numTransactionsChanged(newNumTransactions); + if(cachedEncryptionStatus != newEncryptionStatus) + emit encryptionStatusChanged(newEncryptionStatus); + cachedBalance = newBalance; cachedUnconfirmedBalance = newUnconfirmedBalance; cachedNumTransactions = newNumTransactions; @@ -179,4 +184,18 @@ TransactionTableModel *WalletModel::getTransactionTableModel() return transactionTableModel; } - +WalletModel::EncryptionStatus WalletModel::getEncryptionStatus() const +{ + if(!wallet->IsCrypted()) + { + return Unencrypted; + } + else if(wallet->IsLocked()) + { + return Locked; + } + else + { + return Unlocked; + } +} diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index bb1c6e85d3..a585f8d8d6 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -36,6 +36,13 @@ public: MiscError }; + enum EncryptionStatus + { + Unencrypted, // !wallet->IsCrypted() + Locked, // wallet->IsCrypted() && wallet->IsLocked() + Unlocked // wallet->IsCrypted() && !wallet->IsLocked() + }; + OptionsModel *getOptionsModel(); AddressTableModel *getAddressTableModel(); TransactionTableModel *getTransactionTableModel(); @@ -43,6 +50,9 @@ public: qint64 getBalance() const; qint64 getUnconfirmedBalance() const; int getNumTransactions() const; + EncryptionStatus getEncryptionStatus() const; + + bool isEncrypted() const; // Check address for validity bool validateAddress(const QString &address); @@ -74,10 +84,12 @@ private: qint64 cachedBalance; qint64 cachedUnconfirmedBalance; qint64 cachedNumTransactions; + EncryptionStatus cachedEncryptionStatus; signals: void balanceChanged(qint64 balance, qint64 unconfirmedBalance); void numTransactionsChanged(int count); + void encryptionStatusChanged(int status); // Asynchronous error notification void error(const QString &title, const QString &message); |