Browse Source

Wallet encryption part 1: show wallet encryption status

0.8
Wladimir J. van der Laan 13 years ago
parent
commit
ae8adeb90a
  1. 2
      doc/assets-attribution.txt
  2. 2
      src/qt/bitcoin.qrc
  3. 30
      src/qt/bitcoingui.cpp
  4. 3
      src/qt/bitcoingui.h
  5. 5
      src/qt/guiconstants.h
  6. BIN
      src/qt/res/icons/lock_closed.png
  7. BIN
      src/qt/res/icons/lock_open.png
  8. 23
      src/qt/walletmodel.cpp
  9. 12
      src/qt/walletmodel.h

2
doc/assets-attribution.txt

@ -15,7 +15,7 @@ Designer: FatCow Web Hosting
License: Creative Commons Attribution (by) License: Creative Commons Attribution (by)
Site: http://findicons.com/icon/163938/book_open 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 Icon Pack: Human-O2
Designer: schollidesign Designer: schollidesign
License: GNU/GPL License: GNU/GPL

2
src/qt/bitcoin.qrc

@ -34,6 +34,8 @@
<file alias="tx_input">res/icons/tx_input.png</file> <file alias="tx_input">res/icons/tx_input.png</file>
<file alias="tx_output">res/icons/tx_output.png</file> <file alias="tx_output">res/icons/tx_output.png</file>
<file alias="tx_inout">res/icons/tx_inout.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>
<qresource prefix="/images"> <qresource prefix="/images">
<file alias="about">res/images/about.png</file> <file alias="about">res/images/about.png</file>

30
src/qt/bitcoingui.cpp

@ -18,6 +18,7 @@
#include "transactionview.h" #include "transactionview.h"
#include "overviewpage.h" #include "overviewpage.h"
#include "bitcoinunits.h" #include "bitcoinunits.h"
#include "guiconstants.h"
#include <QApplication> #include <QApplication>
#include <QMainWindow> #include <QMainWindow>
@ -118,9 +119,12 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks); QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);
frameBlocksLayout->setContentsMargins(3,0,3,0); frameBlocksLayout->setContentsMargins(3,0,3,0);
frameBlocksLayout->setSpacing(3); frameBlocksLayout->setSpacing(3);
labelEncryptionIcon = new QLabel();
labelConnectionsIcon = new QLabel(); labelConnectionsIcon = new QLabel();
labelBlocksIcon = new QLabel(); labelBlocksIcon = new QLabel();
frameBlocksLayout->addStretch(); frameBlocksLayout->addStretch();
frameBlocksLayout->addWidget(labelEncryptionIcon);
frameBlocksLayout->addStretch();
frameBlocksLayout->addWidget(labelConnectionsIcon); frameBlocksLayout->addWidget(labelConnectionsIcon);
frameBlocksLayout->addStretch(); frameBlocksLayout->addStretch();
frameBlocksLayout->addWidget(labelBlocksIcon); frameBlocksLayout->addWidget(labelBlocksIcon);
@ -244,6 +248,9 @@ void BitcoinGUI::setWalletModel(WalletModel *walletModel)
receiveCoinsPage->setModel(walletModel->getAddressTableModel()); receiveCoinsPage->setModel(walletModel->getAddressTableModel());
sendCoinsPage->setModel(walletModel); sendCoinsPage->setModel(walletModel);
setEncryptionStatus(walletModel->getEncryptionStatus());
connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));
// Balloon popup for new transaction // Balloon popup for new transaction
connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)), connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
this, SLOT(incomingTransaction(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; case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
default: icon = ":/icons/connect_4"; 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)); labelConnectionsIcon->setToolTip(tr("%n active connection(s) to Bitcoin network", "", count));
} }
@ -351,7 +358,7 @@ void BitcoinGUI::setNumBlocks(int count)
if(secs < 30*60) if(secs < 30*60)
{ {
tooltip = tr("Up to date") + QString("\n") + tooltip; 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 else
{ {
@ -531,3 +538,22 @@ void BitcoinGUI::dropEvent(QDropEvent *event)
event->acceptProposedAction(); 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;
}
}

3
src/qt/bitcoingui.h

@ -57,6 +57,7 @@ private:
AddressBookPage *receiveCoinsPage; AddressBookPage *receiveCoinsPage;
SendCoinsDialog *sendCoinsPage; SendCoinsDialog *sendCoinsPage;
QLabel *labelEncryptionIcon;
QLabel *labelConnectionsIcon; QLabel *labelConnectionsIcon;
QLabel *labelBlocksIcon; QLabel *labelBlocksIcon;
QLabel *progressBarLabel; QLabel *progressBarLabel;
@ -85,6 +86,8 @@ private:
public slots: public slots:
void setNumConnections(int count); void setNumConnections(int count);
void setNumBlocks(int count); void setNumBlocks(int count);
void setEncryptionStatus(int status);
void error(const QString &title, const QString &message); void error(const QString &title, const QString &message);
/* It is currently not possible to pass a return value to another thread through /* It is currently not possible to pass a return value to another thread through
BlockingQueuedConnection, so use an indirected pointer. BlockingQueuedConnection, so use an indirected pointer.

5
src/qt/guiconstants.h

@ -1,9 +1,12 @@
#ifndef GUICONSTANTS_H #ifndef GUICONSTANTS_H
#define GUICONSTANTS_H #define GUICONSTANTS_H
/* milliseconds between model updates */ /* Milliseconds between model updates */
static const int MODEL_UPDATE_DELAY = 500; static const int MODEL_UPDATE_DELAY = 500;
/* Size of icons in status bar */
static const int STATUSBAR_ICONSIZE = 16;
/* Invalid field background style */ /* Invalid field background style */
#define STYLE_INVALID "background:#FF8080" #define STYLE_INVALID "background:#FF8080"

BIN
src/qt/res/icons/lock_closed.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
src/qt/res/icons/lock_open.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

23
src/qt/walletmodel.cpp

@ -12,7 +12,8 @@
WalletModel::WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *parent) : WalletModel::WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *parent) :
QObject(parent), wallet(wallet), optionsModel(optionsModel), addressTableModel(0), QObject(parent), wallet(wallet), optionsModel(optionsModel), addressTableModel(0),
transactionTableModel(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, // Until signal notifications is built into the bitcoin core,
// simply update everything after polling using a timer. // simply update everything after polling using a timer.
@ -49,6 +50,7 @@ void WalletModel::update()
qint64 newBalance = getBalance(); qint64 newBalance = getBalance();
qint64 newUnconfirmedBalance = getUnconfirmedBalance(); qint64 newUnconfirmedBalance = getUnconfirmedBalance();
int newNumTransactions = getNumTransactions(); int newNumTransactions = getNumTransactions();
EncryptionStatus newEncryptionStatus = getEncryptionStatus();
if(cachedBalance != newBalance || cachedUnconfirmedBalance != newUnconfirmedBalance) if(cachedBalance != newBalance || cachedUnconfirmedBalance != newUnconfirmedBalance)
emit balanceChanged(newBalance, newUnconfirmedBalance); emit balanceChanged(newBalance, newUnconfirmedBalance);
@ -56,6 +58,9 @@ void WalletModel::update()
if(cachedNumTransactions != newNumTransactions) if(cachedNumTransactions != newNumTransactions)
emit numTransactionsChanged(newNumTransactions); emit numTransactionsChanged(newNumTransactions);
if(cachedEncryptionStatus != newEncryptionStatus)
emit encryptionStatusChanged(newEncryptionStatus);
cachedBalance = newBalance; cachedBalance = newBalance;
cachedUnconfirmedBalance = newUnconfirmedBalance; cachedUnconfirmedBalance = newUnconfirmedBalance;
cachedNumTransactions = newNumTransactions; cachedNumTransactions = newNumTransactions;
@ -179,4 +184,18 @@ TransactionTableModel *WalletModel::getTransactionTableModel()
return transactionTableModel; return transactionTableModel;
} }
WalletModel::EncryptionStatus WalletModel::getEncryptionStatus() const
{
if(!wallet->IsCrypted())
{
return Unencrypted;
}
else if(wallet->IsLocked())
{
return Locked;
}
else
{
return Unlocked;
}
}

12
src/qt/walletmodel.h

@ -36,6 +36,13 @@ public:
MiscError MiscError
}; };
enum EncryptionStatus
{
Unencrypted, // !wallet->IsCrypted()
Locked, // wallet->IsCrypted() && wallet->IsLocked()
Unlocked // wallet->IsCrypted() && !wallet->IsLocked()
};
OptionsModel *getOptionsModel(); OptionsModel *getOptionsModel();
AddressTableModel *getAddressTableModel(); AddressTableModel *getAddressTableModel();
TransactionTableModel *getTransactionTableModel(); TransactionTableModel *getTransactionTableModel();
@ -43,6 +50,9 @@ public:
qint64 getBalance() const; qint64 getBalance() const;
qint64 getUnconfirmedBalance() const; qint64 getUnconfirmedBalance() const;
int getNumTransactions() const; int getNumTransactions() const;
EncryptionStatus getEncryptionStatus() const;
bool isEncrypted() const;
// Check address for validity // Check address for validity
bool validateAddress(const QString &address); bool validateAddress(const QString &address);
@ -74,10 +84,12 @@ private:
qint64 cachedBalance; qint64 cachedBalance;
qint64 cachedUnconfirmedBalance; qint64 cachedUnconfirmedBalance;
qint64 cachedNumTransactions; qint64 cachedNumTransactions;
EncryptionStatus cachedEncryptionStatus;
signals: signals:
void balanceChanged(qint64 balance, qint64 unconfirmedBalance); void balanceChanged(qint64 balance, qint64 unconfirmedBalance);
void numTransactionsChanged(int count); void numTransactionsChanged(int count);
void encryptionStatusChanged(int status);
// Asynchronous error notification // Asynchronous error notification
void error(const QString &title, const QString &message); void error(const QString &title, const QString &message);

Loading…
Cancel
Save