From ae8adeb90abb334b8e5712124e62461eca77c12f Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Tue, 23 Aug 2011 20:08:42 +0200 Subject: [PATCH] Wallet encryption part 1: show wallet encryption status --- doc/assets-attribution.txt | 2 +- src/qt/bitcoin.qrc | 2 ++ src/qt/bitcoingui.cpp | 30 ++++++++++++++++++++++++++++-- src/qt/bitcoingui.h | 3 +++ src/qt/guiconstants.h | 5 ++++- src/qt/res/icons/lock_closed.png | Bin 0 -> 1237 bytes src/qt/res/icons/lock_open.png | Bin 0 -> 1442 bytes src/qt/walletmodel.cpp | 23 +++++++++++++++++++++-- src/qt/walletmodel.h | 12 ++++++++++++ 9 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 src/qt/res/icons/lock_closed.png create mode 100644 src/qt/res/icons/lock_open.png diff --git a/doc/assets-attribution.txt b/doc/assets-attribution.txt index e4a00fa8..d498e8b4 100644 --- a/doc/assets-attribution.txt +++ b/doc/assets-attribution.txt @@ -15,7 +15,7 @@ Designer: FatCow Web Hosting License: Creative Commons Attribution (by) Site: http://findicons.com/icon/163938/book_open -Icon: src/qt/res/icons/connect*.png, src/qt/res/icons/synced.png +Icon: src/qt/res/icons/connect*.png, src/qt/res/icons/synced.png, src/qt/res/icons/lock_*.png Icon Pack: Human-O2 Designer: schollidesign License: GNU/GPL diff --git a/src/qt/bitcoin.qrc b/src/qt/bitcoin.qrc index 629349c6..1d5a58a4 100644 --- a/src/qt/bitcoin.qrc +++ b/src/qt/bitcoin.qrc @@ -34,6 +34,8 @@ res/icons/tx_input.png res/icons/tx_output.png res/icons/tx_inout.png + res/icons/lock_closed.png + res/icons/lock_open.png res/images/about.png diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index dd94652e..22987267 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 #include @@ -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 encrypted and currently unlocked")); + break; + case WalletModel::Locked: + labelEncryptionIcon->show(); + labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE)); + labelEncryptionIcon->setToolTip(tr("Wallet is encrypted and currently locked")); + break; + } +} diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 377da726..4b713171 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 7fbf7fcd..b7870199 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 new file mode 100644 index 0000000000000000000000000000000000000000..ce8da0bec7df7b25f2eded2ff7e5be5995c55f7b GIT binary patch literal 1237 zcmV;`1Skd5(y@-EOx{p64tqEa>v`@>eHLocL~*xMmioTeof<6OqMMt0kM8 zo78Hx>mh_gXV0EJa_-!@Bde>cheYIhqtW2@?b~wTz=6d_j~*SHCAOQzDTHu2%QD~T zbeNl)`{vA3r1o&ccaq+Kewfc3l+4S@C^Ou27r^TLHfg3k&)PPfIngT4< zYPBole6uXOVvJc@T3VuBub;Yq|9N~MCx^nL3;1yI%L0iDCSnZxe975}*S*?aGQ z)c?7gKCM4|u$rVDZxJJ?=0Fe;N;AeF0@gab_xL0cpCm4+cx}9v<;)TR3bB&C~ z{yuNKwa%VHAN#!VVYRig+F;Cz7+Wh<$a5hZSgeD6^P7n6QLhNyE(A4LBRC7zLE^wU zrLtG4)fJUMKeLdBiBmTgKm@E&yvq?gAh$VHE2snYkmq0ooE5B5oB=0-qiEZJvw>h_ zqIf4(Kvf7q2xBosgq zG^#nomsCN^#uS2y03vajm^e->rD(Bsq!=s?p9e6eWKc8|Xj4}1o;TnG$ zj_4;YqwSgKa2FePm%>$HYl?PwbtZr!)2MM7w#sbE!A0Vimb4Iss-s>nC_)Mml|l;& z8X`gKJ>`T8L7H*+#f%R?4aYqQ&0v0u>kqkrA^d z23OU%ClprpkFd}5w`)g$r>*s0*HR7!?aBJnfo!x@);dUg4YRQh-AyFRVsh3-t9Uf= zuxBqiw;!E<9c?`C2DiVhYinJ7^6dGuG5HNad|}D9`}Vdg%oYa4`2-9K%eGm6s6llBUg|Get^IH6RWVu+U00000NkvXXu0mjfxUEVa literal 0 HcmV?d00001 diff --git a/src/qt/res/icons/lock_open.png b/src/qt/res/icons/lock_open.png new file mode 100644 index 0000000000000000000000000000000000000000..6a3a8edb2377721e37e0a0b6d9d52b4ee7b97b6e GIT binary patch literal 1442 zcmV;T1zq}yP)4}1uYl0!hqVpq8&rwzJ+A% z8Luqu?5?7M=DpWbUGJ-}zN#S{z;52WiMp=QG!4fXix^|kG!0aB#LT0jC~R?Y@gN~V z2XS6rUY5G9&$#=q^F04~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>7J9+5i9m literal 0 HcmV?d00001 diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 10b3738c..9a7b56d3 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 bb1c6e85..a585f8d8 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);