Celil 14 years ago
parent
commit
29f9e4e400
  1. 4
      README.rst
  2. 11
      bitcoin-qt.pro
  3. 15
      doc/assets-attribution.txt
  4. BIN
      scripts/img/reload.xcf
  5. BIN
      scripts/img/reload_scaled.png
  6. 41
      scripts/make_spinner.py
  7. 6
      src/main.cpp
  8. 28
      src/qt/addresstablemodel.cpp
  9. 22
      src/qt/addresstablemodel.h
  10. 6
      src/qt/bitcoin.qrc
  11. 6
      src/qt/bitcoinaddressvalidator.cpp
  12. 33
      src/qt/bitcoinamountfield.cpp
  13. 10
      src/qt/bitcoinamountfield.h
  14. 93
      src/qt/bitcoingui.cpp
  15. 3
      src/qt/bitcoingui.h
  16. 18
      src/qt/clientmodel.cpp
  17. 3
      src/qt/clientmodel.h
  18. 19
      src/qt/editaddressdialog.cpp
  19. 2
      src/qt/forms/addressbookpage.ui
  20. 182
      src/qt/forms/sendcoinsdialog.ui
  21. 175
      src/qt/forms/sendcoinsentry.ui
  22. 2
      src/qt/guiconstants.h
  23. 37
      src/qt/qvalidatedlineedit.cpp
  24. 27
      src/qt/qvalidatedlineedit.h
  25. BIN
      src/qt/res/icons/editdelete.png
  26. BIN
      src/qt/res/icons/remove.png
  27. BIN
      src/qt/res/icons/synced.png
  28. BIN
      src/qt/res/movies/update_spinner.mng
  29. 176
      src/qt/sendcoinsdialog.cpp
  30. 14
      src/qt/sendcoinsdialog.h
  31. 119
      src/qt/sendcoinsentry.cpp
  32. 45
      src/qt/sendcoinsentry.h
  33. 104
      src/qt/walletmodel.cpp
  34. 35
      src/qt/walletmodel.h
  35. 1
      src/serialize.h

4
README.rst

@ -3,7 +3,7 @@ Bitcoin-qt: Qt4 based GUI replacement for Bitcoin
**Warning** **Warning** **Warning** **Warning** **Warning** **Warning**
Pre-alpha stuff! I'm using this client myself on the production network, and I haven't noticed any glitches, but remember: always backup your wallet. Alpha version! I'm using this client myself on the production network, and I haven't noticed any glitches, but remember: always backup your wallet.
Testing on the testnet is recommended. Testing on the testnet is recommended.
This has been implemented: This has been implemented:
@ -28,6 +28,8 @@ This has been implemented:
- Progress bar on initial block download - Progress bar on initial block download
- Sendmany support in UI (send to multiple recipients as well)
This has to be done: This has to be done:
- Start at system start - Start at system start

11
bitcoin-qt.pro

@ -84,7 +84,9 @@ HEADERS += src/qt/bitcoingui.h \
src/qt/overviewpage.h \ src/qt/overviewpage.h \
src/qt/csvmodelwriter.h \ src/qt/csvmodelwriter.h \
src/qt/qtwin.h \ src/qt/qtwin.h \
src/crypter.h src/crypter.h \
src/qt/sendcoinsentry.h \
src/qt/qvalidatedlineedit.h
SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \ SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \
src/qt/transactiontablemodel.cpp \ src/qt/transactiontablemodel.cpp \
src/qt/addresstablemodel.cpp \ src/qt/addresstablemodel.cpp \
@ -124,7 +126,9 @@ SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \
src/qt/overviewpage.cpp \ src/qt/overviewpage.cpp \
src/qt/csvmodelwriter.cpp \ src/qt/csvmodelwriter.cpp \
src/qt/qtwin.cpp \ src/qt/qtwin.cpp \
src/crypter.cpp src/crypter.cpp \
src/qt/sendcoinsentry.cpp \
src/qt/qvalidatedlineedit.cpp
RESOURCES += \ RESOURCES += \
src/qt/bitcoin.qrc src/qt/bitcoin.qrc
@ -135,7 +139,8 @@ FORMS += \
src/qt/forms/aboutdialog.ui \ src/qt/forms/aboutdialog.ui \
src/qt/forms/editaddressdialog.ui \ src/qt/forms/editaddressdialog.ui \
src/qt/forms/transactiondescdialog.ui \ src/qt/forms/transactiondescdialog.ui \
src/qt/forms/overviewpage.ui src/qt/forms/overviewpage.ui \
src/qt/forms/sendcoinsentry.ui
CODECFORTR = UTF-8 CODECFORTR = UTF-8
TRANSLATIONS = src/qt/locale/bitcoin_nl.ts src/qt/locale/bitcoin_de.ts TRANSLATIONS = src/qt/locale/bitcoin_nl.ts src/qt/locale/bitcoin_de.ts

15
doc/assets-attribution.txt

@ -14,7 +14,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 Icon: src/qt/res/icons/connect*.png, src/qt/res/icons/synced.png
Icon Pack: Human-O2 Icon Pack: Human-O2
Designer: schollidesign Designer: schollidesign
License: GNU/GPL License: GNU/GPL
@ -29,7 +29,7 @@ License: You are free to do with these icons as you wish, including selling,
Icon: src/qt/res/icons/configure.png, src/qt/res/icons/quit.png, Icon: src/qt/res/icons/configure.png, src/qt/res/icons/quit.png,
src/qt/res/icons/editcopy.png, src/qt/res/icons/editpaste.png, src/qt/res/icons/editcopy.png, src/qt/res/icons/editpaste.png,
src/qt/res/icons/add.png, src/qt/res/icons/edit.png, src/qt/res/icons/add.png, src/qt/res/icons/edit.png,
src/qt/res/icons/editdelete.png src/qt/res/icons/remove.png (edited)
Designer: http://www.everaldo.com Designer: http://www.everaldo.com
Icon Pack: Crystal SVG Icon Pack: Crystal SVG
License: LGPL License: LGPL
@ -52,9 +52,8 @@ Designer: Jack Cai
License: Creative Commons Attribution No Derivatives (by-nd) License: Creative Commons Attribution No Derivatives (by-nd)
Site: http://findicons.com/icon/175944/home?id=176221# Site: http://findicons.com/icon/175944/home?id=176221#
Icon: src/qt/res/icons/synced.png, Icon: scripts/img/reload.xcf (modified),src/qt/res/movies/update_spinner.mng
src/qt/res/icons/notsynced.png Icon Pack: Kids
Icon Pack: Gloss: Basic Designer: Everaldo (Everaldo Coelho)
Designer: Momenticons License: GNU/GPL
License: Creative Commons Attribution (by) Site: http://findicons.com/icon/17102/reload?id=17102
Site: http://www.momenticons.com/

BIN
scripts/img/reload.xcf

Binary file not shown.

BIN
scripts/img/reload_scaled.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 905 B

41
scripts/make_spinner.py

@ -0,0 +1,41 @@
#!/usr/bin/env python
# W.J. van der Laan, 2011
# Make spinning .mng animation from a .png
# Requires imagemagick 6.7+
from __future__ import division
from os import path
from PIL import Image
from subprocess import Popen
SRC='img/reload_scaled.png'
DST='../src/qt/res/movies/update_spinner.mng'
TMPDIR='/tmp'
TMPNAME='tmp-%03i.png'
NUMFRAMES=35
FRAMERATE=10.0
CONVERT='convert'
CLOCKWISE=True
im_src = Image.open(SRC)
if CLOCKWISE:
im_src = im_src.transpose(Image.FLIP_LEFT_RIGHT)
def frame_to_filename(frame):
return path.join(TMPDIR, TMPNAME % frame)
frame_files = []
for frame in xrange(NUMFRAMES):
rotation = (frame + 0.5) / NUMFRAMES * 360.0
if CLOCKWISE:
rotation = -rotation
im_new = im_src.rotate(rotation, Image.BICUBIC)
outfile = frame_to_filename(frame)
im_new.save(outfile, 'png')
frame_files.append(outfile)
p = Popen([CONVERT, "-delay", str(FRAMERATE), "-dispose", "2"] + frame_files + [DST])
p.communicate()

6
src/main.cpp

@ -32,7 +32,7 @@ map<COutPoint, CInPoint> mapNextTx;
map<uint256, CBlockIndex*> mapBlockIndex; map<uint256, CBlockIndex*> mapBlockIndex;
uint256 hashGenesisBlock("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"); uint256 hashGenesisBlock("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f");
CBigNum bnProofOfWorkLimit(~uint256(0) >> 32); CBigNum bnProofOfWorkLimit(~uint256(0) >> 32);
const int nTotalBlocksEstimate = 134444; // Conservative estimate of total nr of blocks on main chain int nTotalBlocksEstimate = 134444; // Conservative estimate of total nr of blocks on main chain
const int nInitialBlockThreshold = 120; // Regard blocks up until N-threshold as "initial download" const int nInitialBlockThreshold = 120; // Regard blocks up until N-threshold as "initial download"
CBlockIndex* pindexGenesisBlock = NULL; CBlockIndex* pindexGenesisBlock = NULL;
int nBestHeight = -1; int nBestHeight = -1;
@ -1869,6 +1869,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
pfrom->fSuccessfullyConnected = true; pfrom->fSuccessfullyConnected = true;
printf("version message: version %d, blocks=%d\n", pfrom->nVersion, pfrom->nStartingHeight); printf("version message: version %d, blocks=%d\n", pfrom->nVersion, pfrom->nStartingHeight);
if(pfrom->nStartingHeight > nTotalBlocksEstimate)
{
nTotalBlocksEstimate = pfrom->nStartingHeight;
}
} }

28
src/qt/addresstablemodel.cpp

@ -1,5 +1,6 @@
#include "addresstablemodel.h" #include "addresstablemodel.h"
#include "guiutil.h" #include "guiutil.h"
#include "walletmodel.h"
#include "headers.h" #include "headers.h"
@ -72,8 +73,8 @@ struct AddressTablePriv
} }
}; };
AddressTableModel::AddressTableModel(CWallet *wallet, QObject *parent) : AddressTableModel::AddressTableModel(CWallet *wallet, WalletModel *parent) :
QAbstractTableModel(parent),wallet(wallet),priv(0) QAbstractTableModel(parent),walletModel(parent),wallet(wallet),priv(0)
{ {
columns << tr("Label") << tr("Address"); columns << tr("Label") << tr("Address");
priv = new AddressTablePriv(wallet); priv = new AddressTablePriv(wallet);
@ -150,6 +151,8 @@ bool AddressTableModel::setData(const QModelIndex & index, const QVariant & valu
return false; return false;
AddressTableEntry *rec = static_cast<AddressTableEntry*>(index.internalPointer()); AddressTableEntry *rec = static_cast<AddressTableEntry*>(index.internalPointer());
editStatus = OK;
if(role == Qt::EditRole) if(role == Qt::EditRole)
{ {
switch(index.column()) switch(index.column())
@ -160,8 +163,11 @@ bool AddressTableModel::setData(const QModelIndex & index, const QVariant & valu
break; break;
case Address: case Address:
// Refuse to set invalid address // Refuse to set invalid address
if(!validateAddress(value.toString())) if(!walletModel->validateAddress(value.toString()))
{
editStatus = INVALID_ADDRESS;
return false; return false;
}
// Double-check that we're not overwriting receiving address // Double-check that we're not overwriting receiving address
if(rec->type == AddressTableEntry::Sending) if(rec->type == AddressTableEntry::Sending)
{ {
@ -240,13 +246,22 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
std::string strLabel = label.toStdString(); std::string strLabel = label.toStdString();
std::string strAddress = address.toStdString(); std::string strAddress = address.toStdString();
editStatus = OK;
if(type == Send) if(type == Send)
{ {
if(!walletModel->validateAddress(address))
{
editStatus = INVALID_ADDRESS;
return QString();
}
// Check for duplicate // Check for duplicate
CRITICAL_BLOCK(wallet->cs_mapAddressBook) CRITICAL_BLOCK(wallet->cs_mapAddressBook)
{ {
if(wallet->mapAddressBook.count(strAddress)) if(wallet->mapAddressBook.count(strAddress))
{ {
editStatus = DUPLICATE_ADDRESS;
return QString(); return QString();
} }
} }
@ -291,13 +306,6 @@ void AddressTableModel::update()
} }
bool AddressTableModel::validateAddress(const QString &address)
{
uint160 hash160 = 0;
return AddressToHash160(address.toStdString(), hash160);
}
/* Look up label for address in address book, if not found return empty string. /* Look up label for address in address book, if not found return empty string.
*/ */
QString AddressTableModel::labelForAddress(const QString &address) const QString AddressTableModel::labelForAddress(const QString &address) const

22
src/qt/addresstablemodel.h

@ -6,12 +6,13 @@
class AddressTablePriv; class AddressTablePriv;
class CWallet; class CWallet;
class WalletModel;
class AddressTableModel : public QAbstractTableModel class AddressTableModel : public QAbstractTableModel
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit AddressTableModel(CWallet *wallet, QObject *parent = 0); explicit AddressTableModel(CWallet *wallet, WalletModel *parent = 0);
~AddressTableModel(); ~AddressTableModel();
enum ColumnIndex { enum ColumnIndex {
@ -19,9 +20,16 @@ public:
Address = 1 /* Bitcoin address */ Address = 1 /* Bitcoin address */
}; };
enum { enum RoleIndex {
TypeRole = Qt::UserRole TypeRole = Qt::UserRole
} RoleIndex; };
// Return status of last edit/insert operation
enum EditStatus {
OK = 0,
INVALID_ADDRESS = 1,
DUPLICATE_ADDRESS = 2
};
static const QString Send; /* Send addres */ static const QString Send; /* Send addres */
static const QString Receive; /* Receive address */ static const QString Receive; /* Receive address */
@ -45,10 +53,6 @@ public:
*/ */
void updateList(); void updateList();
/* Check address for validity
*/
bool validateAddress(const QString &address);
/* Look up label for address in address book, if not found return empty string. /* Look up label for address in address book, if not found return empty string.
*/ */
QString labelForAddress(const QString &address) const; QString labelForAddress(const QString &address) const;
@ -58,10 +62,14 @@ public:
*/ */
int lookupAddress(const QString &address) const; int lookupAddress(const QString &address) const;
EditStatus getEditStatus() const { return editStatus; }
private: private:
WalletModel *walletModel;
CWallet *wallet; CWallet *wallet;
AddressTablePriv *priv; AddressTablePriv *priv;
QStringList columns; QStringList columns;
EditStatus editStatus;
signals: signals:
void defaultAddressChanged(const QString &address); void defaultAddressChanged(const QString &address);

6
src/qt/bitcoin.qrc

@ -25,14 +25,16 @@
<file alias="bitcoin_testnet">res/icons/bitcoin_testnet.png</file> <file alias="bitcoin_testnet">res/icons/bitcoin_testnet.png</file>
<file alias="toolbar_testnet">res/icons/toolbar_testnet.png</file> <file alias="toolbar_testnet">res/icons/toolbar_testnet.png</file>
<file alias="edit">res/icons/edit.png</file> <file alias="edit">res/icons/edit.png</file>
<file alias="editdelete">res/icons/editdelete.png</file>
<file alias="history">res/icons/history.png</file> <file alias="history">res/icons/history.png</file>
<file alias="overview">res/icons/overview.png</file> <file alias="overview">res/icons/overview.png</file>
<file alias="export">res/icons/export.png</file> <file alias="export">res/icons/export.png</file>
<file alias="synced">res/icons/synced.png</file> <file alias="synced">res/icons/synced.png</file>
<file alias="notsynced">res/icons/notsynced.png</file> <file alias="remove">res/icons/remove.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>
</qresource> </qresource>
<qresource prefix="/movies">
<file alias="update_spinner">res/movies/update_spinner.mng</file>
</qresource>
</RCC> </RCC>

6
src/qt/bitcoinaddressvalidator.cpp

@ -57,5 +57,11 @@ QValidator::State BitcoinAddressValidator::validate(QString &input, int &pos) co
} }
} }
// Empty address is "intermediate" input
if(input.isEmpty())
{
state = QValidator::Intermediate;
}
return state; return state;
} }

33
src/qt/bitcoinamountfield.cpp

@ -1,4 +1,5 @@
#include "bitcoinamountfield.h" #include "bitcoinamountfield.h"
#include "qvalidatedlineedit.h"
#include <QLabel> #include <QLabel>
#include <QLineEdit> #include <QLineEdit>
@ -9,12 +10,12 @@
BitcoinAmountField::BitcoinAmountField(QWidget *parent): BitcoinAmountField::BitcoinAmountField(QWidget *parent):
QWidget(parent), amount(0), decimals(0) QWidget(parent), amount(0), decimals(0)
{ {
amount = new QLineEdit(this); amount = new QValidatedLineEdit(this);
amount->setValidator(new QRegExpValidator(QRegExp("[0-9]+"), this)); amount->setValidator(new QRegExpValidator(QRegExp("[0-9]+"), this));
amount->setAlignment(Qt::AlignRight|Qt::AlignVCenter); amount->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
amount->installEventFilter(this); amount->installEventFilter(this);
amount->setMaximumWidth(100); amount->setMaximumWidth(100);
decimals = new QLineEdit(this); decimals = new QValidatedLineEdit(this);
decimals->setValidator(new QRegExpValidator(QRegExp("[0-9]+"), this)); decimals->setValidator(new QRegExpValidator(QRegExp("[0-9]+"), this));
decimals->setMaxLength(8); decimals->setMaxLength(8);
decimals->setAlignment(Qt::AlignLeft|Qt::AlignVCenter); decimals->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
@ -29,8 +30,9 @@ BitcoinAmountField::BitcoinAmountField(QWidget *parent):
layout->addStretch(1); layout->addStretch(1);
layout->setContentsMargins(0,0,0,0); layout->setContentsMargins(0,0,0,0);
setFocusPolicy(Qt::TabFocus);
setLayout(layout); setLayout(layout);
setFocusPolicy(Qt::TabFocus);
setFocusProxy(amount); setFocusProxy(amount);
// If one if the widgets changes, the combined content changes as well // If one if the widgets changes, the combined content changes as well
@ -53,10 +55,28 @@ void BitcoinAmountField::setText(const QString &text)
} }
} }
bool BitcoinAmountField::validate()
{
bool valid = true;
if(amount->text().isEmpty())
{
amount->setValid(false);
valid = false;
}
if(decimals->text().isEmpty())
{
decimals->setValid(false);
valid = false;
}
return valid;
}
QString BitcoinAmountField::text() const QString BitcoinAmountField::text() const
{ {
if(amount->text().isEmpty() || decimals->text().isEmpty()) if(amount->text().isEmpty() || decimals->text().isEmpty())
{
return QString(); return QString();
}
return amount->text() + QString(".") + decimals->text(); return amount->text() + QString(".") + decimals->text();
} }
@ -75,3 +95,10 @@ bool BitcoinAmountField::eventFilter(QObject *object, QEvent *event)
} }
return false; return false;
} }
QWidget *BitcoinAmountField::setupTabChain(QWidget *prev)
{
QWidget::setTabOrder(prev, amount);
QWidget::setTabOrder(amount, decimals);
return decimals;
}

10
src/qt/bitcoinamountfield.h

@ -4,7 +4,7 @@
#include <QWidget> #include <QWidget>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QLineEdit; class QValidatedLineEdit;
QT_END_NAMESPACE QT_END_NAMESPACE
// Coin amount entry widget with separate parts for whole // Coin amount entry widget with separate parts for whole
@ -18,6 +18,10 @@ public:
void setText(const QString &text); void setText(const QString &text);
QString text() const; QString text() const;
bool validate();
// Qt messes up the tab chain by default in some cases (issue http://bugreports.qt.nokia.com/browse/QTBUG-10907)
// Hence we have to set it up manually
QWidget *setupTabChain(QWidget *prev);
signals: signals:
void textChanged(); void textChanged();
@ -27,8 +31,8 @@ protected:
bool eventFilter(QObject *object, QEvent *event); bool eventFilter(QObject *object, QEvent *event);
private: private:
QLineEdit *amount; QValidatedLineEdit *amount;
QLineEdit *decimals; QValidatedLineEdit *decimals;
}; };

93
src/qt/bitcoingui.cpp

@ -36,6 +36,7 @@
#include <QProgressBar> #include <QProgressBar>
#include <QStackedWidget> #include <QStackedWidget>
#include <QDateTime> #include <QDateTime>
#include <QMovie>
#include <QDebug> #include <QDebug>
@ -55,10 +56,14 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
// Menus // Menus
QMenu *file = menuBar()->addMenu("&File"); QMenu *file = menuBar()->addMenu("&File");
file->addAction(optionsAction); file->addAction(sendCoinsAction);
file->addAction(receiveCoinsAction);
file->addSeparator(); file->addSeparator();
file->addAction(quitAction); file->addAction(quitAction);
QMenu *settings = menuBar()->addMenu("&Settings");
settings->addAction(optionsAction);
QMenu *help = menuBar()->addMenu("&Help"); QMenu *help = menuBar()->addMenu("&Help");
help->addAction(aboutAction); help->addAction(aboutAction);
@ -103,17 +108,35 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
// Create status bar // Create status bar
statusBar(); statusBar();
// Status bar "Connections" notification
QFrame *frameConnections = new QFrame();
frameConnections->setFrameStyle(QFrame::Panel | QFrame::Sunken);
frameConnections->setMinimumWidth(150);
frameConnections->setMaximumWidth(150);
QHBoxLayout *frameConnectionsLayout = new QHBoxLayout(frameConnections);
frameConnectionsLayout->setContentsMargins(3,0,3,0);
frameConnectionsLayout->setSpacing(3);
labelConnectionsIcon = new QLabel();
labelConnectionsIcon->setToolTip(tr("Number of connections to other clients"));
frameConnectionsLayout->addWidget(labelConnectionsIcon);
labelConnections = new QLabel(); labelConnections = new QLabel();
labelConnections->setFrameStyle(QFrame::Panel | QFrame::Sunken);
labelConnections->setMinimumWidth(150);
labelConnections->setMaximumWidth(150);
labelConnections->setToolTip(tr("Number of connections to other clients")); labelConnections->setToolTip(tr("Number of connections to other clients"));
frameConnectionsLayout->addWidget(labelConnections);
frameConnectionsLayout->addStretch();
// Status bar "Blocks" notification
QFrame *frameBlocks = new QFrame();
frameBlocks->setFrameStyle(QFrame::Panel | QFrame::Sunken);
frameBlocks->setMinimumWidth(150);
frameBlocks->setMaximumWidth(150);
QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);
frameBlocksLayout->setContentsMargins(3,0,3,0);
frameBlocksLayout->setSpacing(3);
labelBlocksIcon = new QLabel();
frameBlocksLayout->addWidget(labelBlocksIcon);
labelBlocks = new QLabel(); labelBlocks = new QLabel();
labelBlocks->setFrameStyle(QFrame::Panel | QFrame::Sunken); frameBlocksLayout->addWidget(labelBlocks);
labelBlocks->setMinimumWidth(150); frameBlocksLayout->addStretch();
labelBlocks->setMaximumWidth(150);
labelBlocks->setToolTip(tr("Number of blocks in the block chain"));
// Progress bar for blocks download // Progress bar for blocks download
progressBarLabel = new QLabel(tr("Synchronizing with network...")); progressBarLabel = new QLabel(tr("Synchronizing with network..."));
@ -124,11 +147,13 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
statusBar()->addWidget(progressBarLabel); statusBar()->addWidget(progressBarLabel);
statusBar()->addWidget(progressBar); statusBar()->addWidget(progressBar);
statusBar()->addPermanentWidget(labelConnections); statusBar()->addPermanentWidget(frameConnections);
statusBar()->addPermanentWidget(labelBlocks); statusBar()->addPermanentWidget(frameBlocks);
createTrayIcon(); createTrayIcon();
syncIconMovie = new QMovie(":/movies/update_spinner", "mng", this);
gotoOverviewPage(); gotoOverviewPage();
} }
@ -281,37 +306,39 @@ 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;
} }
labelConnections->setTextFormat(Qt::RichText); labelConnectionsIcon->setPixmap(QIcon(icon).pixmap(16,16));
labelConnections->setText("<img src=\""+icon+"\"> " + tr("%n connection(s)", "", count)); labelConnections->setText(tr("%n connection(s)", "", count));
} }
void BitcoinGUI::setNumBlocks(int count) void BitcoinGUI::setNumBlocks(int count)
{ {
int total = clientModel->getTotalBlocksEstimate(); int total = clientModel->getTotalBlocksEstimate();
QString tooltip;
if(count < total) if(count < total)
{ {
progressBarLabel->setVisible(true); progressBarLabel->setVisible(true);
progressBar->setVisible(true); progressBar->setVisible(true);
progressBar->setMaximum(total); progressBar->setMaximum(total);
progressBar->setValue(count); progressBar->setValue(count);
tooltip = tr("Downloaded %1 of %2 blocks of transaction history.").arg(count).arg(total);
} }
else else
{ {
progressBarLabel->setVisible(false); progressBarLabel->setVisible(false);
progressBar->setVisible(false); progressBar->setVisible(false);
tooltip = tr("Downloaded %1 blocks of transaction history.").arg(count);
} }
QDateTime now = QDateTime::currentDateTime(); QDateTime now = QDateTime::currentDateTime();
QDateTime lastBlockDate = clientModel->getLastBlockDate(); QDateTime lastBlockDate = clientModel->getLastBlockDate();
int secs = lastBlockDate.secsTo(now); int secs = lastBlockDate.secsTo(now);
QString text; QString text;
QString icon = ":/icons/notsynced";
// "Up to date" icon, and outdated icon // Represent time from last generated block in human readable text
if(secs < 30*60) if(secs < 60)
{ {
text = "Up to date"; text = tr("%n second(s) ago","",secs);
icon = ":/icons/synced";
} }
else if(secs < 60*60) else if(secs < 60*60)
{ {
@ -326,9 +353,33 @@ void BitcoinGUI::setNumBlocks(int count)
text = tr("%n day(s) ago","",secs/(60*60*24)); text = tr("%n day(s) ago","",secs/(60*60*24));
} }
labelBlocks->setText("<img src=\""+icon+"\"> " + text); // In the label we want to be less specific
labelBlocks->setToolTip(tr("Downloaded %n block(s) of transaction history. Last block was generated %1.", "", count) QString labelText = text;
.arg(QLocale::system().toString(lastBlockDate))); bool spinning = true;
if(secs < 30*60)
{
labelText = "Up to date";
spinning = false;
}
tooltip += QString("\n");
tooltip += tr("Last received block was generated %1.").arg(text);
if(spinning)
{
labelBlocksIcon->setMovie(syncIconMovie);
syncIconMovie->start();
}
else
{
labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(16,16));
}
labelBlocks->setText(labelText);
labelBlocksIcon->setToolTip(tooltip);
labelBlocks->setToolTip(tooltip);
progressBarLabel->setToolTip(tooltip);
progressBar->setToolTip(tooltip);
} }
void BitcoinGUI::error(const QString &title, const QString &message) void BitcoinGUI::error(const QString &title, const QString &message)

3
src/qt/bitcoingui.h

@ -57,6 +57,7 @@ private:
QLabel *labelConnections; QLabel *labelConnections;
QLabel *labelConnectionsIcon; QLabel *labelConnectionsIcon;
QLabel *labelBlocks; QLabel *labelBlocks;
QLabel *labelBlocksIcon;
QLabel *progressBarLabel; QLabel *progressBarLabel;
QProgressBar *progressBar; QProgressBar *progressBar;
@ -74,6 +75,8 @@ private:
QSystemTrayIcon *trayIcon; QSystemTrayIcon *trayIcon;
TransactionView *transactionView; TransactionView *transactionView;
QMovie *syncIconMovie;
void createActions(); void createActions();
QWidget *createTabs(); QWidget *createTabs();
void createTrayIcon(); void createTrayIcon();

18
src/qt/clientmodel.cpp

@ -10,7 +10,8 @@
#include <QDateTime> #include <QDateTime>
ClientModel::ClientModel(CWallet *wallet, QObject *parent) : ClientModel::ClientModel(CWallet *wallet, QObject *parent) :
QObject(parent), wallet(wallet), optionsModel(0) QObject(parent), wallet(wallet), optionsModel(0),
cachedNumConnections(0), cachedNumBlocks(0)
{ {
// 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.
@ -38,11 +39,16 @@ QDateTime ClientModel::getLastBlockDate() const
void ClientModel::update() void ClientModel::update()
{ {
// Plainly emit all signals for now. To be more efficient this should check int newNumConnections = getNumConnections();
// whether the values actually changed first, although it'd be even better if these int newNumBlocks = getNumBlocks();
// were events coming in from the bitcoin core.
emit numConnectionsChanged(getNumConnections()); if(cachedNumConnections != newNumConnections)
emit numBlocksChanged(getNumBlocks()); emit numConnectionsChanged(newNumConnections);
if(cachedNumBlocks != newNumBlocks)
emit numBlocksChanged(newNumBlocks);
cachedNumConnections = newNumConnections;
cachedNumBlocks = newNumBlocks;
} }
bool ClientModel::isTestNet() const bool ClientModel::isTestNet() const

3
src/qt/clientmodel.h

@ -42,6 +42,9 @@ private:
OptionsModel *optionsModel; OptionsModel *optionsModel;
int cachedNumConnections;
int cachedNumBlocks;
signals: signals:
void numConnectionsChanged(int count); void numConnectionsChanged(int count);
void numBlocksChanged(int count); void numBlocksChanged(int count);

19
src/qt/editaddressdialog.cpp

@ -79,23 +79,22 @@ QString EditAddressDialog::saveCurrentRow()
void EditAddressDialog::accept() void EditAddressDialog::accept()
{ {
if(mode == NewSendingAddress || mode == EditSendingAddress) if(saveCurrentRow().isEmpty())
{ {
// For sending addresses, check validity switch(model->getEditStatus())
// Not needed for receiving addresses, as those are generated
if(!model->validateAddress(ui->addressEdit->text()))
{ {
case AddressTableModel::DUPLICATE_ADDRESS:
QMessageBox::warning(this, windowTitle(),
tr("The entered address \"%1\" is already in the address book.").arg(ui->addressEdit->text()),
QMessageBox::Ok, QMessageBox::Ok);
break;
case AddressTableModel::INVALID_ADDRESS:
QMessageBox::warning(this, windowTitle(), QMessageBox::warning(this, windowTitle(),
tr("The entered address \"%1\" is not a valid bitcoin address.").arg(ui->addressEdit->text()), tr("The entered address \"%1\" is not a valid bitcoin address.").arg(ui->addressEdit->text()),
QMessageBox::Ok, QMessageBox::Ok); QMessageBox::Ok, QMessageBox::Ok);
return; return;
} }
}
if(saveCurrentRow().isEmpty())
{
QMessageBox::warning(this, windowTitle(),
tr("The entered address \"%1\" is already in the address book.").arg(ui->addressEdit->text()),
QMessageBox::Ok, QMessageBox::Ok);
return; return;
} }
QDialog::accept(); QDialog::accept();

2
src/qt/forms/addressbookpage.ui

@ -89,7 +89,7 @@
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="../bitcoin.qrc"> <iconset resource="../bitcoin.qrc">
<normaloff>:/icons/editdelete</normaloff>:/icons/editdelete</iconset> <normaloff>:/icons/remove</normaloff>:/icons/remove</iconset>
</property> </property>
</widget> </widget>
</item> </item>

182
src/qt/forms/sendcoinsdialog.ui

@ -15,152 +15,63 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<spacer name="verticalSpacer_2"> <widget class="QScrollArea" name="scrollArea">
<property name="orientation"> <property name="widgetResizable">
<enum>Qt::Vertical</enum> <bool>true</bool>
</property> </property>
<property name="sizeType"> <widget class="QWidget" name="scrollAreaWidgetContents">
<enum>QSizePolicy::Preferred</enum> <property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>666</width>
<height>162</height>
</rect>
</property> </property>
<property name="sizeHint" stdset="0"> <layout class="QVBoxLayout" name="verticalLayout_2">
<size> <property name="margin">
<width>20</width> <number>0</number>
<height>12</height>
</size>
</property> </property>
</spacer>
</item>
<item> <item>
<layout class="QGridLayout" name="gridLayout"> <layout class="QVBoxLayout" name="entries">
<property name="spacing"> <property name="spacing">
<number>12</number> <number>6</number>
</property>
<item row="5" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>A&amp;mount:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>payAmount</cstring>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Pay &amp;To:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
<property name="buddy"> </layout>
<cstring>payTo</cstring>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="BitcoinAmountField" name="payAmount"/>
</item> </item>
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<item> <item>
<widget class="QLineEdit" name="addAsLabel"> <spacer name="verticalSpacer">
<property name="enabled"> <property name="orientation">
<bool>true</bool> <enum>Qt::Vertical</enum>
</property> </property>
<property name="toolTip"> <property name="sizeHint" stdset="0">
<string>Enter a label for this address to add it to your address book</string> <size>
<width>20</width>
<height>40</height>
</size>
</property> </property>
</widget> </spacer>
</item> </item>
</layout> </layout>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>&amp;Label:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>addAsLabel</cstring>
</property>
</widget> </widget>
</item>
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="payTo">
<property name="toolTip">
<string>The address to send the payment to (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)</string>
</property>
<property name="maxLength">
<number>34</number>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="addressBookButton"> <layout class="QHBoxLayout" name="horizontalLayout">
<property name="toolTip"> <property name="spacing">
<string>Look up adress in address book</string> <number>12</number>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/address-book</normaloff>:/icons/address-book</iconset>
</property>
<property name="shortcut">
<string>Alt+A</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="flat">
<bool>false</bool>
</property> </property>
</widget>
</item>
<item> <item>
<widget class="QPushButton" name="pasteButton"> <widget class="QPushButton" name="addButton">
<property name="toolTip">
<string>Paste address from system clipboard</string>
</property>
<property name="text"> <property name="text">
<string/> <string>&amp;Add recipient...</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="../bitcoin.qrc"> <iconset resource="../bitcoin.qrc">
<normaloff>:/icons/editpaste</normaloff>:/icons/editpaste</iconset> <normaloff>:/icons/add</normaloff>:/icons/add</iconset>
</property>
<property name="shortcut">
<string>Alt+P</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property> </property>
</widget> </widget>
</item> </item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>12</number>
</property>
<item> <item>
<spacer name="horizontalSpacer"> <spacer name="horizontalSpacer">
<property name="orientation"> <property name="orientation">
@ -199,37 +110,8 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</widget> </widget>
<customwidgets>
<customwidget>
<class>BitcoinAmountField</class>
<extends>QLineEdit</extends>
<header>bitcoinamountfield.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>payTo</tabstop>
<tabstop>addressBookButton</tabstop>
<tabstop>pasteButton</tabstop>
<tabstop>addAsLabel</tabstop>
<tabstop>payAmount</tabstop>
<tabstop>sendButton</tabstop>
</tabstops>
<resources> <resources>
<include location="../bitcoin.qrc"/> <include location="../bitcoin.qrc"/>
</resources> </resources>

175
src/qt/forms/sendcoinsentry.ui

@ -0,0 +1,175 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SendCoinsEntry</class>
<widget class="QFrame" name="SendCoinsEntry">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>729</width>
<height>136</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="spacing">
<number>12</number>
</property>
<item row="5" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>A&amp;mount:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>payAmount</cstring>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Pay &amp;To:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>payTo</cstring>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="BitcoinAmountField" name="payAmount"/>
</item>
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QValidatedLineEdit" name="addAsLabel">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>Enter a label for this address to add it to your address book</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>&amp;Label:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>addAsLabel</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QValidatedLineEdit" name="payTo">
<property name="toolTip">
<string>The address to send the payment to (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)</string>
</property>
<property name="maxLength">
<number>34</number>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="addressBookButton">
<property name="toolTip">
<string>Look up adress in address book</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/address-book</normaloff>:/icons/address-book</iconset>
</property>
<property name="shortcut">
<string>Alt+A</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pasteButton">
<property name="toolTip">
<string>Paste address from system clipboard</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/editpaste</normaloff>:/icons/editpaste</iconset>
</property>
<property name="shortcut">
<string>Alt+P</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="deleteButton">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/remove</normaloff>:/icons/remove</iconset>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>BitcoinAmountField</class>
<extends>QLineEdit</extends>
<header>bitcoinamountfield.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QValidatedLineEdit</class>
<extends>QLineEdit</extends>
<header>qvalidatedlineedit.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../bitcoin.qrc"/>
</resources>
<connections/>
</ui>

2
src/qt/guiconstants.h

@ -2,7 +2,7 @@
#define GUICONSTANTS_H #define GUICONSTANTS_H
/* milliseconds between model updates */ /* milliseconds between model updates */
static const int MODEL_UPDATE_DELAY = 250; static const int MODEL_UPDATE_DELAY = 500;
/* size of cache */ /* size of cache */
static const unsigned int WALLET_CACHE_SIZE = 100; static const unsigned int WALLET_CACHE_SIZE = 100;

37
src/qt/qvalidatedlineedit.cpp

@ -0,0 +1,37 @@
#include "qvalidatedlineedit.h"
QValidatedLineEdit::QValidatedLineEdit(QWidget *parent) :
QLineEdit(parent), valid(true)
{
connect(this, SIGNAL(textChanged(QString)), this, SLOT(markValid()));
}
void QValidatedLineEdit::setValid(bool valid)
{
if(valid == this->valid)
{
return;
}
if(valid)
{
setStyleSheet("");
}
else
{
setStyleSheet("background:#FF8080");
}
this->valid = valid;
}
void QValidatedLineEdit::focusInEvent(QFocusEvent *evt)
{
// Clear invalid flag on focus
setValid(true);
QLineEdit::focusInEvent(evt);
}
void QValidatedLineEdit::markValid()
{
setValid(true);
}

27
src/qt/qvalidatedlineedit.h

@ -0,0 +1,27 @@
#ifndef QVALIDATEDLINEEDIT_H
#define QVALIDATEDLINEEDIT_H
#include <QLineEdit>
// Line edit that can be marked as "invalid". When marked as invalid,
// it will get a red background until it is focused.
class QValidatedLineEdit : public QLineEdit
{
Q_OBJECT
public:
explicit QValidatedLineEdit(QWidget *parent = 0);
protected:
void focusInEvent(QFocusEvent *evt);
private:
bool valid;
public slots:
void setValid(bool valid);
private slots:
void markValid();
};
#endif // QVALIDATEDLINEEDIT_H

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 698 B

BIN
src/qt/res/movies/update_spinner.mng

Binary file not shown.

176
src/qt/sendcoinsdialog.cpp

@ -1,43 +1,40 @@
#include "sendcoinsdialog.h" #include "sendcoinsdialog.h"
#include "ui_sendcoinsdialog.h" #include "ui_sendcoinsdialog.h"
#include "walletmodel.h" #include "walletmodel.h"
#include "addresstablemodel.h"
#include "guiutil.h" #include "guiutil.h"
#include "addressbookpage.h" #include "addressbookpage.h"
#include "optionsmodel.h" #include "optionsmodel.h"
#include "sendcoinsentry.h"
#include <QApplication>
#include <QClipboard>
#include <QMessageBox> #include <QMessageBox>
#include <QLocale> #include <QLocale>
#include <QDebug> #include <QDebug>
#include <QMessageBox>
SendCoinsDialog::SendCoinsDialog(QWidget *parent, const QString &address) : SendCoinsDialog::SendCoinsDialog(QWidget *parent) :
QDialog(parent), QDialog(parent),
ui(new Ui::SendCoinsDialog), ui(new Ui::SendCoinsDialog),
model(0) model(0)
{ {
ui->setupUi(this); ui->setupUi(this);
#if QT_VERSION >= 0x040700
ui->payTo->setPlaceholderText(tr("Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)"));
ui->addAsLabel->setPlaceholderText(tr("Enter a label for this address to add it to your address book"));
#endif
GUIUtil::setupAddressWidget(ui->payTo, this); addEntry();
// Set initial send-to address if provided connect(ui->addButton, SIGNAL(clicked()), this, SLOT(addEntry()));
if(!address.isEmpty())
{
ui->payTo->setText(address);
ui->payAmount->setFocus();
}
} }
void SendCoinsDialog::setModel(WalletModel *model) void SendCoinsDialog::setModel(WalletModel *model)
{ {
this->model = model; this->model = model;
for(int i = 0; i < ui->entries->count(); ++i)
{
SendCoinsEntry *entry = qobject_cast<SendCoinsEntry*>(ui->entries->itemAt(i)->widget());
if(entry)
{
entry->setModel(model);
}
}
} }
SendCoinsDialog::~SendCoinsDialog() SendCoinsDialog::~SendCoinsDialog()
@ -47,26 +44,38 @@ SendCoinsDialog::~SendCoinsDialog()
void SendCoinsDialog::on_sendButton_clicked() void SendCoinsDialog::on_sendButton_clicked()
{ {
bool valid; QList<SendCoinsRecipient> recipients;
QString payAmount = ui->payAmount->text(); bool valid = true;
QString label; for(int i = 0; i < ui->entries->count(); ++i)
qint64 payAmountParsed; {
SendCoinsEntry *entry = qobject_cast<SendCoinsEntry*>(ui->entries->itemAt(i)->widget());
valid = GUIUtil::parseMoney(payAmount, &payAmountParsed); if(entry)
{
if(entry->validate())
{
recipients.append(entry->getValue());
}
else
{
valid = false;
}
}
}
if(!valid || payAmount.isEmpty()) if(!valid || recipients.isEmpty())
{ {
QMessageBox::warning(this, tr("Send Coins"),
tr("Must fill in an amount to pay."),
QMessageBox::Ok, QMessageBox::Ok);
return; return;
} }
// Add address to address book under label, if specified // Format confirmation message
label = ui->addAsLabel->text(); QStringList formatted;
foreach(const SendCoinsRecipient &rcp, recipients)
{
formatted.append(tr("%1 BTC to %2 (%3)").arg(GUIUtil::formatMoney(rcp.amount), rcp.label, rcp.address));
}
QMessageBox::StandardButton retval = QMessageBox::question(this, tr("Confirm send coins"), QMessageBox::StandardButton retval = QMessageBox::question(this, tr("Confirm send coins"),
tr("Are you sure you want to send %1 BTC to %2 (%3)?").arg(GUIUtil::formatMoney(payAmountParsed), label, ui->payTo->text()), tr("Are you sure you want to send %1?").arg(formatted.join(tr(" and "))),
QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes|QMessageBox::Cancel,
QMessageBox::Cancel); QMessageBox::Cancel);
@ -75,32 +84,45 @@ void SendCoinsDialog::on_sendButton_clicked()
return; return;
} }
switch(model->sendCoins(ui->payTo->text(), payAmountParsed, label)) WalletModel::SendCoinsReturn sendstatus = model->sendCoins(recipients);
switch(sendstatus.status)
{ {
case WalletModel::InvalidAddress: case WalletModel::InvalidAddress:
QMessageBox::warning(this, tr("Send Coins"), QMessageBox::warning(this, tr("Send Coins"),
tr("The recepient address is not valid, please recheck."), tr("The recepient address is not valid, please recheck."),
QMessageBox::Ok, QMessageBox::Ok); QMessageBox::Ok, QMessageBox::Ok);
ui->payTo->setFocus();
break; break;
case WalletModel::InvalidAmount: case WalletModel::InvalidAmount:
QMessageBox::warning(this, tr("Send Coins"), QMessageBox::warning(this, tr("Send Coins"),
tr("The amount to pay must be larger than 0."), tr("The amount to pay must be larger than 0."),
QMessageBox::Ok, QMessageBox::Ok); QMessageBox::Ok, QMessageBox::Ok);
ui->payAmount->setFocus();
break; break;
case WalletModel::AmountExceedsBalance: case WalletModel::AmountExceedsBalance:
QMessageBox::warning(this, tr("Send Coins"), QMessageBox::warning(this, tr("Send Coins"),
tr("Amount exceeds your balance"), tr("Amount exceeds your balance"),
QMessageBox::Ok, QMessageBox::Ok); QMessageBox::Ok, QMessageBox::Ok);
ui->payAmount->setFocus();
break; break;
case WalletModel::AmountWithFeeExceedsBalance: case WalletModel::AmountWithFeeExceedsBalance:
QMessageBox::warning(this, tr("Send Coins"), QMessageBox::warning(this, tr("Send Coins"),
tr("Total exceeds your balance when the %1 transaction fee is included"). tr("Total exceeds your balance when the %1 transaction fee is included").
arg(GUIUtil::formatMoney(model->getOptionsModel()->getTransactionFee())), arg(GUIUtil::formatMoney(sendstatus.fee)),
QMessageBox::Ok, QMessageBox::Ok);
break;
case WalletModel::DuplicateAddress:
QMessageBox::warning(this, tr("Send Coins"),
tr("Duplicate address found, can only send to each address once in one send operation"),
QMessageBox::Ok, QMessageBox::Ok);
break;
case WalletModel::TransactionCreationFailed:
QMessageBox::warning(this, tr("Send Coins"),
tr("Error: Transaction creation failed "),
QMessageBox::Ok, QMessageBox::Ok);
break;
break;
case WalletModel::TransactionCommitFailed:
QMessageBox::warning(this, tr("Send Coins"),
tr("Error: The transaction was rejected. This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here."),
QMessageBox::Ok, QMessageBox::Ok); QMessageBox::Ok, QMessageBox::Ok);
ui->payAmount->setFocus();
break; break;
case WalletModel::OK: case WalletModel::OK:
accept(); accept();
@ -108,34 +130,23 @@ void SendCoinsDialog::on_sendButton_clicked()
} }
} }
void SendCoinsDialog::on_pasteButton_clicked() void SendCoinsDialog::clear()
{ {
// Paste text from clipboard into recipient field // Remove entries until only one left
ui->payTo->setText(QApplication::clipboard()->text()); while(ui->entries->count() > 1)
} {
delete ui->entries->takeAt(0)->widget();
}
void SendCoinsDialog::on_addressBookButton_clicked() // Reset the entry that is left to empty
{ SendCoinsEntry *entry = qobject_cast<SendCoinsEntry*>(ui->entries->itemAt(0)->widget());
AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::SendingTab, this); if(entry)
dlg.setModel(model->getAddressTableModel());
if(dlg.exec())
{ {
ui->payTo->setText(dlg.getReturnValue()); entry->clear();
ui->payAmount->setFocus();
} }
}
void SendCoinsDialog::on_payTo_textChanged(const QString &address) updateRemoveEnabled();
{
ui->addAsLabel->setText(model->getAddressTableModel()->labelForAddress(address));
}
void SendCoinsDialog::clear()
{
ui->payTo->setText(QString());
ui->addAsLabel->setText(QString());
ui->payAmount->setText(QString());
ui->payTo->setFocus();
ui->sendButton->setDefault(true); ui->sendButton->setDefault(true);
} }
@ -148,3 +159,52 @@ void SendCoinsDialog::accept()
{ {
clear(); clear();
} }
void SendCoinsDialog::addEntry()
{
SendCoinsEntry *entry = new SendCoinsEntry(this);
entry->setModel(model);
ui->entries->addWidget(entry);
connect(entry, SIGNAL(removeEntry(SendCoinsEntry*)), this, SLOT(removeEntry(SendCoinsEntry*)));
updateRemoveEnabled();
// Focus the field, so that entry can start immediately
entry->clear();
}
void SendCoinsDialog::updateRemoveEnabled()
{
// Remove buttons are enabled as soon as there is more than one send-entry
bool enabled = (ui->entries->count() > 1);
for(int i = 0; i < ui->entries->count(); ++i)
{
SendCoinsEntry *entry = qobject_cast<SendCoinsEntry*>(ui->entries->itemAt(i)->widget());
if(entry)
{
entry->setRemoveEnabled(enabled);
}
}
setupTabChain(0);
}
void SendCoinsDialog::removeEntry(SendCoinsEntry* entry)
{
delete entry;
updateRemoveEnabled();
}
QWidget *SendCoinsDialog::setupTabChain(QWidget *prev)
{
for(int i = 0; i < ui->entries->count(); ++i)
{
SendCoinsEntry *entry = qobject_cast<SendCoinsEntry*>(ui->entries->itemAt(i)->widget());
if(entry)
{
prev = entry->setupTabChain(prev);
}
}
QWidget::setTabOrder(prev, ui->addButton);
QWidget::setTabOrder(ui->addButton, ui->sendButton);
return ui->sendButton;
}

14
src/qt/sendcoinsdialog.h

@ -7,31 +7,37 @@ namespace Ui {
class SendCoinsDialog; class SendCoinsDialog;
} }
class WalletModel; class WalletModel;
class SendCoinsEntry;
class SendCoinsDialog : public QDialog class SendCoinsDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit SendCoinsDialog(QWidget *parent = 0, const QString &address = ""); explicit SendCoinsDialog(QWidget *parent = 0);
~SendCoinsDialog(); ~SendCoinsDialog();
void setModel(WalletModel *model); void setModel(WalletModel *model);
// Qt messes up the tab chain by default in some cases (issue http://bugreports.qt.nokia.com/browse/QTBUG-10907)
// Hence we have to set it up manually
QWidget *setupTabChain(QWidget *prev);
public slots: public slots:
void clear(); void clear();
void reject(); void reject();
void accept(); void accept();
void addEntry();
void updateRemoveEnabled();
private: private:
Ui::SendCoinsDialog *ui; Ui::SendCoinsDialog *ui;
WalletModel *model; WalletModel *model;
private slots: private slots:
void on_payTo_textChanged(const QString &address);
void on_addressBookButton_clicked();
void on_pasteButton_clicked();
void on_sendButton_clicked(); void on_sendButton_clicked();
void removeEntry(SendCoinsEntry* entry);
}; };
#endif // SENDCOINSDIALOG_H #endif // SENDCOINSDIALOG_H

119
src/qt/sendcoinsentry.cpp

@ -0,0 +1,119 @@
#include "sendcoinsentry.h"
#include "ui_sendcoinsentry.h"
#include "guiutil.h"
#include "addressbookpage.h"
#include "walletmodel.h"
#include "addresstablemodel.h"
#include "qapplication.h"
#include "qclipboard.h"
#include <QDebug>
SendCoinsEntry::SendCoinsEntry(QWidget *parent) :
QFrame(parent),
ui(new Ui::SendCoinsEntry),
model(0)
{
ui->setupUi(this);
#if QT_VERSION >= 0x040700
ui->payTo->setPlaceholderText(tr("Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)"));
ui->addAsLabel->setPlaceholderText(tr("Enter a label for this address to add it to your address book"));
#endif
setFocusPolicy(Qt::TabFocus);
setFocusProxy(ui->payTo);
GUIUtil::setupAddressWidget(ui->payTo, this);
}
SendCoinsEntry::~SendCoinsEntry()
{
delete ui;
}
void SendCoinsEntry::on_pasteButton_clicked()
{
// Paste text from clipboard into recipient field
ui->payTo->setText(QApplication::clipboard()->text());
}
void SendCoinsEntry::on_addressBookButton_clicked()
{
AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::SendingTab, this);
dlg.setModel(model->getAddressTableModel());
if(dlg.exec())
{
ui->payTo->setText(dlg.getReturnValue());
ui->payAmount->setFocus();
}
}
void SendCoinsEntry::on_payTo_textChanged(const QString &address)
{
ui->addAsLabel->setText(model->getAddressTableModel()->labelForAddress(address));
}
void SendCoinsEntry::setModel(WalletModel *model)
{
this->model = model;
}
void SendCoinsEntry::setRemoveEnabled(bool enabled)
{
ui->deleteButton->setEnabled(enabled);
}
void SendCoinsEntry::clear()
{
ui->payTo->clear();
ui->addAsLabel->clear();
ui->payAmount->setText(QString());
ui->payTo->setFocus();
}
void SendCoinsEntry::on_deleteButton_clicked()
{
emit removeEntry(this);
}
bool SendCoinsEntry::validate()
{
// Check input validity
bool retval = true;
if(!ui->payAmount->validate())
{
retval = false;
}
if(!ui->payTo->hasAcceptableInput() ||
(model && !model->validateAddress(ui->payTo->text())))
{
ui->payTo->setValid(false);
retval = false;
}
return retval;
}
SendCoinsRecipient SendCoinsEntry::getValue()
{
SendCoinsRecipient rv;
rv.address = ui->payTo->text();
rv.label = ui->addAsLabel->text();
GUIUtil::parseMoney(ui->payAmount->text(), &rv.amount);
return rv;
}
QWidget *SendCoinsEntry::setupTabChain(QWidget *prev)
{
QWidget::setTabOrder(prev, ui->payTo);
QWidget::setTabOrder(ui->payTo, ui->addressBookButton);
QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton);
QWidget::setTabOrder(ui->pasteButton, ui->deleteButton);
QWidget::setTabOrder(ui->deleteButton, ui->addAsLabel);
return ui->payAmount->setupTabChain(ui->addAsLabel);
}

45
src/qt/sendcoinsentry.h

@ -0,0 +1,45 @@
#ifndef SENDCOINSENTRY_H
#define SENDCOINSENTRY_H
#include <QFrame>
namespace Ui {
class SendCoinsEntry;
}
class WalletModel;
class SendCoinsRecipient;
class SendCoinsEntry : public QFrame
{
Q_OBJECT
public:
explicit SendCoinsEntry(QWidget *parent = 0);
~SendCoinsEntry();
void setModel(WalletModel *model);
bool validate();
SendCoinsRecipient getValue();
// Qt messes up the tab chain by default in some cases (issue http://bugreports.qt.nokia.com/browse/QTBUG-10907)
// Hence we have to set it up manually
QWidget *setupTabChain(QWidget *prev);
public slots:
void setRemoveEnabled(bool enabled);
void clear();
signals:
void removeEntry(SendCoinsEntry *entry);
private slots:
void on_deleteButton_clicked();
void on_payTo_textChanged(const QString &address);
void on_addressBookButton_clicked();
void on_pasteButton_clicked();
private:
Ui::SendCoinsEntry *ui;
WalletModel *model;
};
#endif // SENDCOINSENTRY_H

104
src/qt/walletmodel.cpp

@ -7,10 +7,12 @@
#include "headers.h" #include "headers.h"
#include <QTimer> #include <QTimer>
#include <QSet>
WalletModel::WalletModel(CWallet *wallet, QObject *parent) : WalletModel::WalletModel(CWallet *wallet, QObject *parent) :
QObject(parent), wallet(wallet), optionsModel(0), addressTableModel(0), QObject(parent), wallet(wallet), optionsModel(0), addressTableModel(0),
transactionTableModel(0) transactionTableModel(0),
cachedBalance(0), cachedUnconfirmedBalance(0), cachedNumTransactions(0)
{ {
// 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.
@ -45,72 +47,122 @@ int WalletModel::getNumTransactions() const
void WalletModel::update() void WalletModel::update()
{ {
// Plainly emit all signals for now. To be more efficient this should check qint64 newBalance = getBalance();
// whether the values actually changed first, although it'd be even better if these qint64 newUnconfirmedBalance = getUnconfirmedBalance();
// were events coming in from the bitcoin core. int newNumTransactions = getNumTransactions();
emit balanceChanged(getBalance(), wallet->GetUnconfirmedBalance());
emit numTransactionsChanged(getNumTransactions()); if(cachedBalance != newBalance || cachedUnconfirmedBalance != newUnconfirmedBalance)
emit balanceChanged(newBalance, newUnconfirmedBalance);
if(cachedNumTransactions != newNumTransactions)
emit numTransactionsChanged(newNumTransactions);
cachedBalance = newBalance;
cachedUnconfirmedBalance = newUnconfirmedBalance;
cachedNumTransactions = newNumTransactions;
addressTableModel->update(); addressTableModel->update();
} }
WalletModel::StatusCode WalletModel::sendCoins(const QString &payTo, qint64 payAmount, const QString &addToAddressBookAs) bool WalletModel::validateAddress(const QString &address)
{ {
uint160 hash160 = 0; uint160 hash160 = 0;
bool valid = false;
if(!AddressToHash160(payTo.toUtf8().constData(), hash160)) return AddressToHash160(address.toStdString(), hash160);
}
WalletModel::SendCoinsReturn WalletModel::sendCoins(const QList<SendCoinsRecipient> &recipients)
{
qint64 total = 0;
QSet<QString> setAddress;
QString hex;
if(recipients.empty())
{
return OK;
}
// Pre-check input data for validity
foreach(const SendCoinsRecipient &rcp, recipients)
{
uint160 hash160 = 0;
if(!AddressToHash160(rcp.address.toUtf8().constData(), hash160))
{ {
return InvalidAddress; return InvalidAddress;
} }
setAddress.insert(rcp.address);
if(payAmount <= 0) if(rcp.amount <= 0)
{ {
return InvalidAmount; return InvalidAmount;
} }
total += rcp.amount;
}
if(payAmount > getBalance()) if(recipients.size() > setAddress.size())
{
return DuplicateAddress;
}
if(total > getBalance())
{ {
return AmountExceedsBalance; return AmountExceedsBalance;
} }
if((payAmount + nTransactionFee) > getBalance()) if((total + nTransactionFee) > getBalance())
{ {
return AmountWithFeeExceedsBalance; return SendCoinsReturn(AmountWithFeeExceedsBalance, nTransactionFee);
} }
CRITICAL_BLOCK(cs_main) CRITICAL_BLOCK(cs_main)
CRITICAL_BLOCK(wallet->cs_mapWallet)
{
// Sendmany
std::vector<std::pair<CScript, int64> > vecSend;
foreach(const SendCoinsRecipient &rcp, recipients)
{ {
// Send to bitcoin address
CWalletTx wtx;
CScript scriptPubKey; CScript scriptPubKey;
scriptPubKey << OP_DUP << OP_HASH160 << hash160 << OP_EQUALVERIFY << OP_CHECKSIG; scriptPubKey.SetBitcoinAddress(rcp.address.toStdString());
vecSend.push_back(make_pair(scriptPubKey, rcp.amount));
}
std::string strError = wallet->SendMoney(scriptPubKey, payAmount, wtx, true); CWalletTx wtx;
if (strError == "") CReserveKey keyChange(wallet);
int64 nFeeRequired = 0;
bool fCreated = wallet->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired);
if(!fCreated)
{ {
// OK if((total + nFeeRequired) > wallet->GetBalance())
{
return SendCoinsReturn(AmountWithFeeExceedsBalance, nFeeRequired);
}
return TransactionCreationFailed;
} }
else if (strError == "ABORTED") if(!ThreadSafeAskFee(nFeeRequired, tr("Sending...").toStdString(), NULL))
{ {
return Aborted; return Aborted;
} }
else if(!wallet->CommitTransaction(wtx, keyChange))
{ {
emit error(tr("Sending..."), QString::fromStdString(strError)); return TransactionCommitFailed;
return MiscError;
} }
hex = QString::fromStdString(wtx.GetHash().GetHex());
} }
// Add addresses that we've sent to to the address book // Add addresses that we've sent to to the address book
std::string strAddress = payTo.toStdString(); foreach(const SendCoinsRecipient &rcp, recipients)
{
std::string strAddress = rcp.address.toStdString();
CRITICAL_BLOCK(wallet->cs_mapAddressBook) CRITICAL_BLOCK(wallet->cs_mapAddressBook)
{ {
if (!wallet->mapAddressBook.count(strAddress)) if (!wallet->mapAddressBook.count(strAddress))
wallet->SetAddressBookName(strAddress, addToAddressBookAs.toStdString()); wallet->SetAddressBookName(strAddress, rcp.label.toStdString());
}
} }
return OK; return SendCoinsReturn(OK, 0, hex);
} }
OptionsModel *WalletModel::getOptionsModel() OptionsModel *WalletModel::getOptionsModel()

35
src/qt/walletmodel.h

@ -8,6 +8,13 @@ class AddressTableModel;
class TransactionTableModel; class TransactionTableModel;
class CWallet; class CWallet;
struct SendCoinsRecipient
{
QString address;
QString label;
qint64 amount;
};
// Interface to a Bitcoin wallet // Interface to a Bitcoin wallet
class WalletModel : public QObject class WalletModel : public QObject
{ {
@ -22,6 +29,9 @@ public:
InvalidAddress, InvalidAddress,
AmountExceedsBalance, AmountExceedsBalance,
AmountWithFeeExceedsBalance, AmountWithFeeExceedsBalance,
DuplicateAddress,
TransactionCreationFailed,
TransactionCommitFailed,
Aborted, Aborted,
MiscError MiscError
}; };
@ -34,8 +44,25 @@ public:
qint64 getUnconfirmedBalance() const; qint64 getUnconfirmedBalance() const;
int getNumTransactions() const; int getNumTransactions() const;
/* Send coins */ // Check address for validity
StatusCode sendCoins(const QString &payTo, qint64 payAmount, const QString &addToAddressBookAs=QString()); bool validateAddress(const QString &address);
// Return status record for SendCoins
// fee is used in case status is "AmountWithFeeExceedsBalance"
// hex is filled with the transaction hash if status is "OK"
struct SendCoinsReturn
{
SendCoinsReturn(StatusCode status,
qint64 fee=0,
QString hex=QString()):
status(status), fee(fee), hex(hex) {}
StatusCode status;
qint64 fee;
QString hex;
};
// Send coins to list of recipients
SendCoinsReturn sendCoins(const QList<SendCoinsRecipient> &recipients);
private: private:
CWallet *wallet; CWallet *wallet;
@ -46,6 +73,10 @@ private:
AddressTableModel *addressTableModel; AddressTableModel *addressTableModel;
TransactionTableModel *transactionTableModel; TransactionTableModel *transactionTableModel;
qint64 cachedBalance;
qint64 cachedUnconfirmedBalance;
qint64 cachedNumTransactions;
signals: signals:
void balanceChanged(qint64 balance, qint64 unconfirmedBalance); void balanceChanged(qint64 balance, qint64 unconfirmedBalance);
void numTransactionsChanged(int count); void numTransactionsChanged(int count);

1
src/serialize.h

@ -30,6 +30,7 @@ typedef unsigned long long uint64;
#endif #endif
#ifdef __WXMSW__ #ifdef __WXMSW__
#include <windows.h>
// This is used to attempt to keep keying material out of swap // This is used to attempt to keep keying material out of swap
// Note that VirtualLock does not provide this as a guarantee on Windows, // Note that VirtualLock does not provide this as a guarantee on Windows,
// but, in practice, memory that has been VirtualLock'd almost never gets written to // but, in practice, memory that has been VirtualLock'd almost never gets written to

Loading…
Cancel
Save