Browse Source

Wallet encryption part 1: show wallet encryption status

pull/145/head
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)
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

2
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>

30
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;
}
}

3
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.

5
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"

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) :
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;
}
}

12
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);

Loading…
Cancel
Save