diff options
Diffstat (limited to 'src/qt')
-rw-r--r-- | src/qt/addresstablemodel.cpp | 20 | ||||
-rw-r--r-- | src/qt/bitcoinamountfield.cpp | 79 | ||||
-rw-r--r-- | src/qt/bitcoinamountfield.h | 24 | ||||
-rw-r--r-- | src/qt/bitcoingui.cpp | 7 | ||||
-rw-r--r-- | src/qt/bitcoinunits.cpp | 165 | ||||
-rw-r--r-- | src/qt/bitcoinunits.h | 56 | ||||
-rw-r--r-- | src/qt/guiconstants.h | 8 | ||||
-rw-r--r-- | src/qt/guiutil.cpp | 10 | ||||
-rw-r--r-- | src/qt/guiutil.h | 6 | ||||
-rw-r--r-- | src/qt/optionsdialog.cpp | 63 | ||||
-rw-r--r-- | src/qt/optionsdialog.h | 9 | ||||
-rw-r--r-- | src/qt/optionsmodel.cpp | 14 | ||||
-rw-r--r-- | src/qt/optionsmodel.h | 16 | ||||
-rw-r--r-- | src/qt/overviewpage.cpp | 6 | ||||
-rw-r--r-- | src/qt/qvalidatedlineedit.cpp | 4 | ||||
-rw-r--r-- | src/qt/sendcoinsdialog.cpp | 6 | ||||
-rw-r--r-- | src/qt/sendcoinsentry.cpp | 13 | ||||
-rw-r--r-- | src/qt/transactiondesc.cpp | 24 | ||||
-rw-r--r-- | src/qt/transactionrecord.cpp | 14 | ||||
-rw-r--r-- | src/qt/transactiontablemodel.cpp | 7 | ||||
-rw-r--r-- | src/qt/transactionview.cpp | 4 | ||||
-rw-r--r-- | src/qt/walletmodel.cpp | 7 |
22 files changed, 454 insertions, 108 deletions
diff --git a/src/qt/addresstablemodel.cpp b/src/qt/addresstablemodel.cpp index 125ceebb33..da086b2784 100644 --- a/src/qt/addresstablemodel.cpp +++ b/src/qt/addresstablemodel.cpp @@ -39,18 +39,18 @@ struct AddressTablePriv { cachedAddressTable.clear(); - CRITICAL_BLOCK(cs_mapPubKeys) + CRITICAL_BLOCK(wallet->cs_KeyStore) CRITICAL_BLOCK(wallet->cs_mapAddressBook) { - BOOST_FOREACH(const PAIRTYPE(std::string, std::string)& item, wallet->mapAddressBook) + BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, std::string)& item, wallet->mapAddressBook) { - std::string strAddress = item.first; - std::string strName = item.second; + const CBitcoinAddress& address = item.first; + const std::string& strName = item.second; uint160 hash160; - bool fMine = (AddressToHash160(strAddress, hash160) && mapPubKeys.count(hash160)); + bool fMine = wallet->HaveKey(address); cachedAddressTable.append(AddressTableEntry(fMine ? AddressTableEntry::Receiving : AddressTableEntry::Sending, QString::fromStdString(strName), - QString::fromStdString(strAddress))); + QString::fromStdString(address.ToString()))); } } } @@ -268,9 +268,8 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con } else if(type == Receive) { - // Generate a new address to associate with given label, optionally - // set as default receiving address. - strAddress = PubKeyToAddress(wallet->GetOrReuseKeyFromPool()); + // Generate a new address to associate with given label + strAddress = CBitcoinAddress(wallet->GetOrReuseKeyFromPool()).ToString(); } else { @@ -312,7 +311,8 @@ QString AddressTableModel::labelForAddress(const QString &address) const { CRITICAL_BLOCK(wallet->cs_mapAddressBook) { - std::map<std::string, std::string>::iterator mi = wallet->mapAddressBook.find(address.toStdString()); + CBitcoinAddress address_parsed(address.toStdString()); + std::map<CBitcoinAddress, std::string>::iterator mi = wallet->mapAddressBook.find(address_parsed); if (mi != wallet->mapAddressBook.end()) { return QString::fromStdString(mi->second); diff --git a/src/qt/bitcoinamountfield.cpp b/src/qt/bitcoinamountfield.cpp index b312b9792e..f1b4e9fdc3 100644 --- a/src/qt/bitcoinamountfield.cpp +++ b/src/qt/bitcoinamountfield.cpp @@ -1,23 +1,24 @@ #include "bitcoinamountfield.h" #include "qvalidatedlineedit.h" +#include "bitcoinunits.h" #include <QLabel> #include <QLineEdit> #include <QRegExpValidator> #include <QHBoxLayout> #include <QKeyEvent> +#include <QComboBox> BitcoinAmountField::BitcoinAmountField(QWidget *parent): - QWidget(parent), amount(0), decimals(0) + QWidget(parent), amount(0), decimals(0), currentUnit(-1) { 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->installEventFilter(this); amount->setMaximumWidth(100); decimals = new QValidatedLineEdit(this); decimals->setValidator(new QRegExpValidator(QRegExp("[0-9]+"), this)); - decimals->setMaxLength(8); decimals->setAlignment(Qt::AlignLeft|Qt::AlignVCenter); decimals->setMaximumWidth(75); @@ -26,7 +27,9 @@ BitcoinAmountField::BitcoinAmountField(QWidget *parent): layout->addWidget(amount); layout->addWidget(new QLabel(QString("."))); layout->addWidget(decimals); - layout->addWidget(new QLabel(QString(" BTC"))); + unit = new QComboBox(this); + unit->setModel(new BitcoinUnits(this)); + layout->addWidget(unit); layout->addStretch(1); layout->setContentsMargins(0,0,0,0); @@ -38,6 +41,10 @@ BitcoinAmountField::BitcoinAmountField(QWidget *parent): // If one if the widgets changes, the combined content changes as well connect(amount, SIGNAL(textChanged(QString)), this, SIGNAL(textChanged())); connect(decimals, SIGNAL(textChanged(QString)), this, SIGNAL(textChanged())); + connect(unit, SIGNAL(currentIndexChanged(int)), this, SLOT(unitChanged(int))); + + // TODO: set default based on configuration + unitChanged(unit->currentIndex()); } void BitcoinAmountField::setText(const QString &text) @@ -59,6 +66,8 @@ void BitcoinAmountField::clear() { amount->clear(); decimals->clear(); + // TODO: set default based on configuration + unit->setCurrentIndex(0); } bool BitcoinAmountField::validate() @@ -69,12 +78,24 @@ bool BitcoinAmountField::validate() decimals->setValid(false); valid = false; } + if(!BitcoinUnits::parse(BitcoinUnits::BTC, text(), 0)) + { + setValid(false); + valid = false; + } + return valid; } +void BitcoinAmountField::setValid(bool valid) +{ + amount->setValid(valid); + decimals->setValid(valid); +} + QString BitcoinAmountField::text() const { - if(decimals->text().isEmpty()) + if(decimals->text().isEmpty() && amount->text().isEmpty()) { return QString(); } @@ -103,3 +124,51 @@ QWidget *BitcoinAmountField::setupTabChain(QWidget *prev) QWidget::setTabOrder(amount, decimals); return decimals; } + +qint64 BitcoinAmountField::value(bool *valid_out) const +{ + qint64 val_out = 0; + bool valid = BitcoinUnits::parse(currentUnit, text(), &val_out); + if(valid_out) + { + *valid_out = valid; + } + return val_out; +} + +void BitcoinAmountField::setValue(qint64 value) +{ + setText(BitcoinUnits::format(currentUnit, value)); +} + +void BitcoinAmountField::unitChanged(int idx) +{ + // Use description tooltip for current unit for the combobox + unit->setToolTip(unit->itemData(idx, Qt::ToolTipRole).toString()); + + // Determine new unit ID + int newUnit = unit->itemData(idx, BitcoinUnits::UnitRole).toInt(); + + // Parse current value and convert to new unit + bool valid = false; + qint64 currentValue = value(&valid); + + currentUnit = newUnit; + + // Set max length after retrieving the value, to prevent truncation + amount->setMaxLength(BitcoinUnits::amountDigits(currentUnit)); + decimals->setMaxLength(BitcoinUnits::decimals(currentUnit)); + + if(valid) + { + setValue(currentValue); + } + else + { + // If current value is invalid, just clear field + setText(""); + } + setValid(true); + + +} diff --git a/src/qt/bitcoinamountfield.h b/src/qt/bitcoinamountfield.h index fd09ab2c9b..6e724d06ae 100644 --- a/src/qt/bitcoinamountfield.h +++ b/src/qt/bitcoinamountfield.h @@ -5,6 +5,7 @@ QT_BEGIN_NAMESPACE class QValidatedLineEdit; +class QComboBox; QT_END_NAMESPACE // Coin amount entry widget with separate parts for whole @@ -12,15 +13,21 @@ QT_END_NAMESPACE class BitcoinAmountField: public QWidget { Q_OBJECT - Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged USER true); + //Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged USER true); + Q_PROPERTY(qint64 value READ value WRITE setValue NOTIFY textChanged USER true); public: explicit BitcoinAmountField(QWidget *parent = 0); - void setText(const QString &text); - QString text() const; + qint64 value(bool *valid=0) const; + void setValue(qint64 value); - void clear(); + // Mark current valid as invalid in UI + void setValid(bool valid); bool validate(); + + // Make field empty and ready for new input + void clear(); + // 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); @@ -35,6 +42,15 @@ protected: private: QValidatedLineEdit *amount; QValidatedLineEdit *decimals; + QComboBox *unit; + int currentUnit; + + void setText(const QString &text); + QString text() const; + +private slots: + void unitChanged(int idx); + }; diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 938d030d25..bd80e42d03 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -11,13 +11,13 @@ #include "aboutdialog.h" #include "clientmodel.h" #include "walletmodel.h" -#include "guiutil.h" #include "editaddressdialog.h" #include "optionsmodel.h" #include "transactiondescdialog.h" #include "addresstablemodel.h" #include "transactionview.h" #include "overviewpage.h" +#include "bitcoinunits.h" #include <QApplication> #include <QMainWindow> @@ -436,7 +436,8 @@ void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee) QString strMessage = tr("This transaction is over the size limit. You can still send it for a fee of %1, " "which goes to the nodes that process your transaction and helps to support the network. " - "Do you want to pay the fee?").arg(GUIUtil::formatMoney(nFeeRequired)); + "Do you want to pay the fee?").arg( + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nFeeRequired)); QMessageBox::StandardButton retval = QMessageBox::question( this, tr("Sending..."), strMessage, QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes); @@ -462,7 +463,7 @@ void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int trayIcon->showMessage((amount)<0 ? tr("Sent transaction") : tr("Incoming transaction"), tr("Date: ") + date + "\n" + - tr("Amount: ") + GUIUtil::formatMoney(amount, true) + "\n" + + tr("Amount: ") + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, amount, true) + "\n" + tr("Type: ") + type + "\n" + tr("Address: ") + address + "\n", QSystemTrayIcon::Information); diff --git a/src/qt/bitcoinunits.cpp b/src/qt/bitcoinunits.cpp new file mode 100644 index 0000000000..7cd50232dd --- /dev/null +++ b/src/qt/bitcoinunits.cpp @@ -0,0 +1,165 @@ +#include "bitcoinunits.h" + +#include <QStringList> + +BitcoinUnits::BitcoinUnits(QObject *parent): + QAbstractListModel(parent), + unitlist(availableUnits()) +{ +} + +QList<BitcoinUnits::Unit> BitcoinUnits::availableUnits() +{ + QList<BitcoinUnits::Unit> unitlist; + unitlist.append(BTC); + unitlist.append(mBTC); + unitlist.append(uBTC); + return unitlist; +} + +bool BitcoinUnits::valid(int unit) +{ + switch(unit) + { + case BTC: + case mBTC: + case uBTC: + return true; + default: + return false; + } +} + +QString BitcoinUnits::name(int unit) +{ + switch(unit) + { + case BTC: return QString("BTC"); + case mBTC: return QString("mBTC"); + case uBTC: return QString::fromUtf8("μBTC"); + default: return QString("???"); + } +} + +QString BitcoinUnits::description(int unit) +{ + switch(unit) + { + case BTC: return QString("Bitcoins"); + case mBTC: return QString("Milli-Bitcoins (1 / 1,000)"); + case uBTC: return QString("Micro-Bitcoins (1 / 1,000,000)"); + default: return QString("???"); + } +} + +qint64 BitcoinUnits::factor(int unit) +{ + switch(unit) + { + case BTC: return 100000000; + case mBTC: return 100000; + case uBTC: return 100; + default: return 100000000; + } +} + +int BitcoinUnits::amountDigits(int unit) +{ + switch(unit) + { + case BTC: return 8; // 21,000,000 (# digits, without commas) + case mBTC: return 11; // 21,000,000,000 + case uBTC: return 14; // 21,000,000,000,000 + default: return 0; + } +} + +int BitcoinUnits::decimals(int unit) +{ + switch(unit) + { + case BTC: return 8; + case mBTC: return 5; + case uBTC: return 2; + default: return 0; + } +} + +QString BitcoinUnits::format(int unit, qint64 n, bool fPlus) +{ + // Note: not using straight sprintf here because we do NOT want + // localized number formatting. + if(!valid(unit)) + return QString(); // Refuse to format invalid unit + qint64 coin = factor(unit); + int num_decimals = decimals(unit); + qint64 n_abs = (n > 0 ? n : -n); + qint64 quotient = n_abs / coin; + qint64 remainder = n_abs % coin; + QString quotient_str = QString::number(quotient); + QString remainder_str = QString::number(remainder).rightJustified(num_decimals, '0'); + + // Right-trim excess 0's after the decimal point + int nTrim = 0; + for (int i = remainder_str.size()-1; i>=2 && (remainder_str.at(i) == '0'); --i) + ++nTrim; + remainder_str.chop(nTrim); + + if (n < 0) + quotient_str.insert(0, '-'); + else if (fPlus && n > 0) + quotient_str.insert(0, '+'); + return quotient_str + QString(".") + remainder_str; +} + +QString BitcoinUnits::formatWithUnit(int unit, qint64 amount, bool plussign) +{ + return format(unit, amount, plussign) + QString(" ") + name(unit); +} + +bool BitcoinUnits::parse(int unit, const QString &value, qint64 *val_out) +{ + if(!valid(unit)) + return false; // Refuse to parse invalid unit + int num_decimals = decimals(unit); + QStringList parts = value.split("."); + if(parts.size() != 2 || parts.at(1).size() > num_decimals) + return false; // Max num decimals + bool ok = false; + QString str = parts[0] + parts[1].leftJustified(num_decimals, '0'); + if(str.size()>18) + return false; // Bounds check + + qint64 retvalue = str.toLongLong(&ok); + if(val_out) + { + *val_out = retvalue; + } + return ok; +} + +int BitcoinUnits::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + return unitlist.size(); +} + +QVariant BitcoinUnits::data(const QModelIndex &index, int role) const +{ + int row = index.row(); + if(row >= 0 && row < unitlist.size()) + { + Unit unit = unitlist.at(row); + switch(role) + { + case Qt::EditRole: + case Qt::DisplayRole: + return QVariant(name(unit)); + case Qt::ToolTipRole: + return QVariant(description(unit)); + case UnitRole: + return QVariant(static_cast<int>(unit)); + } + } + return QVariant(); +} diff --git a/src/qt/bitcoinunits.h b/src/qt/bitcoinunits.h new file mode 100644 index 0000000000..4dfdbea044 --- /dev/null +++ b/src/qt/bitcoinunits.h @@ -0,0 +1,56 @@ +#ifndef BITCOINUNITS_H +#define BITCOINUNITS_H + +#include <QString> +#include <QAbstractListModel> + +// Bitcoin unit definitions +class BitcoinUnits: public QAbstractListModel +{ +public: + explicit BitcoinUnits(QObject *parent); + + enum Unit + { + // Source: https://en.bitcoin.it/wiki/Units + // Please add only sensible ones + BTC, + mBTC, + uBTC + }; + + /// Static API + // Get list of units, for dropdown box + static QList<Unit> availableUnits(); + // Is unit ID valid? + static bool valid(int unit); + // Short name + static QString name(int unit); + // Longer description + static QString description(int unit); + // Number of satoshis / unit + static qint64 factor(int unit); + // Number of amount digits (to represent max number of coins) + static int amountDigits(int unit); + // Number of decimals left + static int decimals(int unit); + // Format as string + static QString format(int unit, qint64 amount, bool plussign=false); + // Format as string (with unit) + static QString formatWithUnit(int unit, qint64 amount, bool plussign=false); + // Parse string to coin amount + static bool parse(int unit, const QString &value, qint64 *val_out); + + /// AbstractListModel implementation + enum { + // Unit identifier + UnitRole = Qt::UserRole + } RoleIndex; + int rowCount(const QModelIndex &parent) const; + QVariant data(const QModelIndex &index, int role) const; +private: + QList<BitcoinUnits::Unit> unitlist; +}; +typedef BitcoinUnits::Unit BitcoinUnit; + +#endif // BITCOINUNITS_H diff --git a/src/qt/guiconstants.h b/src/qt/guiconstants.h index 59f49625bd..deef3e3484 100644 --- a/src/qt/guiconstants.h +++ b/src/qt/guiconstants.h @@ -4,8 +4,12 @@ /* milliseconds between model updates */ static const int MODEL_UPDATE_DELAY = 500; -/* size of cache */ -static const unsigned int WALLET_CACHE_SIZE = 100; +/* Invalid field background style */ +#define STYLE_INVALID "background:#FF8080" +/* Transaction list -- unconfirmed transaction */ +#define COLOR_UNCONFIRMED QColor(128, 128, 128) +/* Transaction list -- negative amount */ +#define COLOR_NEGATIVE QColor(255, 0, 0) #endif // GUICONSTANTS_H diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 31b28024df..308a6ba9bc 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -37,13 +37,3 @@ void GUIUtil::setupAmountWidget(QLineEdit *widget, QWidget *parent) widget->setValidator(amountValidator); widget->setAlignment(Qt::AlignRight|Qt::AlignVCenter); } - -bool GUIUtil::parseMoney(const QString &amount, qint64 *val_out) -{ - return ParseMoney(amount.toStdString(), *val_out); -} - -QString GUIUtil::formatMoney(qint64 amount, bool plussign) -{ - return QString::fromStdString(FormatMoney(amount, plussign)); -} diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index 58f8979511..26a1a03712 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -20,12 +20,6 @@ public: static void setupAddressWidget(QLineEdit *widget, QWidget *parent); static void setupAmountWidget(QLineEdit *widget, QWidget *parent); - - // Convenience wrapper around ParseMoney that takes QString - static bool parseMoney(const QString &amount, qint64 *val_out); - - // Convenience wrapper around FormatMoney that returns QString - static QString formatMoney(qint64 amount, bool plussign=false); }; #endif // GUIUTIL_H diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index 3697b9fe41..94f7abacf2 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -17,8 +17,9 @@ #include <QDoubleValidator> #include <QRegExpValidator> #include <QDialogButtonBox> +#include <QDebug> -/* First (currently only) page of options */ +/* First page of options */ class MainOptionsPage : public QWidget { public: @@ -41,9 +42,23 @@ public slots: }; +class DisplayOptionsPage : public QWidget +{ +public: + explicit DisplayOptionsPage(QWidget *parent=0); + + void setMapper(MonitoredDataMapper *mapper); +private: + QLineEdit *unit; +signals: + +public slots: + +}; + OptionsDialog::OptionsDialog(QWidget *parent): QDialog(parent), contents_widget(0), pages_widget(0), - main_options_page(0), model(0) + model(0), main_page(0), display_page(0) { contents_widget = new QListWidget(); contents_widget->setMaximumWidth(128); @@ -53,8 +68,13 @@ OptionsDialog::OptionsDialog(QWidget *parent): QListWidgetItem *item_main = new QListWidgetItem(tr("Main")); contents_widget->addItem(item_main); - main_options_page = new MainOptionsPage(this); - pages_widget->addWidget(main_options_page); + main_page = new MainOptionsPage(this); + pages_widget->addWidget(main_page); + + QListWidgetItem *item_display = new QListWidgetItem(tr("Display")); + //contents_widget->addItem(item_display); + display_page = new DisplayOptionsPage(this); + pages_widget->addWidget(display_page); contents_widget->setCurrentRow(0); @@ -83,6 +103,7 @@ OptionsDialog::OptionsDialog(QWidget *parent): connect(mapper, SIGNAL(currentIndexChanged(int)), this, SLOT(disableApply())); /* Event bindings */ + connect(contents_widget, SIGNAL(currentRowChanged(int)), this, SLOT(changePage(int))); connect(buttonbox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(okClicked())); connect(buttonbox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(cancelClicked())); connect(buttonbox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(applyClicked())); @@ -93,18 +114,16 @@ void OptionsDialog::setModel(OptionsModel *model) this->model = model; mapper->setModel(model); - main_options_page->setMapper(mapper); + main_page->setMapper(mapper); + display_page->setMapper(mapper); mapper->toFirst(); } -void OptionsDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous) +void OptionsDialog::changePage(int index) { - Q_UNUSED(previous); - if(current) - { - pages_widget->setCurrentIndex(contents_widget->row(current)); - } + qDebug() << "page" << index; + pages_widget->setCurrentIndex(index); } void OptionsDialog::okClicked() @@ -224,3 +243,25 @@ void MainOptionsPage::setMapper(MonitoredDataMapper *mapper) mapper->addMapping(fee_edit, OptionsModel::Fee); } +DisplayOptionsPage::DisplayOptionsPage(QWidget *parent): + QWidget(parent) +{ + QVBoxLayout *layout = new QVBoxLayout(); + QHBoxLayout *unit_hbox = new QHBoxLayout(); + unit_hbox->addSpacing(18); + QLabel *unit_label = new QLabel(tr("&Unit: ")); + unit_hbox->addWidget(unit_label); + unit = new QLineEdit(); + + unit_label->setBuddy(unit); + unit_hbox->addWidget(unit); + + layout->addLayout(unit_hbox); + layout->addStretch(); + + setLayout(layout); +} + +void DisplayOptionsPage::setMapper(MonitoredDataMapper *mapper) +{ +} diff --git a/src/qt/optionsdialog.h b/src/qt/optionsdialog.h index 07e85297d5..d5238a3664 100644 --- a/src/qt/optionsdialog.h +++ b/src/qt/optionsdialog.h @@ -11,6 +11,7 @@ class QPushButton; QT_END_NAMESPACE class OptionsModel; class MainOptionsPage; +class DisplayOptionsPage; class MonitoredDataMapper; class OptionsDialog : public QDialog @@ -24,7 +25,8 @@ public: signals: public slots: - void changePage(QListWidgetItem *current, QListWidgetItem *previous); + void changePage(int index); + private slots: void okClicked(); void cancelClicked(); @@ -34,11 +36,14 @@ private slots: private: QListWidget *contents_widget; QStackedWidget *pages_widget; - MainOptionsPage *main_options_page; OptionsModel *model; MonitoredDataMapper *mapper; QPushButton *apply_button; + // Pages + MainOptionsPage *main_page; + DisplayOptionsPage *display_page; + void setupMainPage(); }; diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index 8f285c6446..896170975e 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -36,7 +36,7 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const case ProxyPort: return QVariant(QString::fromStdString(addrProxy.ToStringPort())); case Fee: - return QVariant(QString::fromStdString(FormatMoney(nTransactionFee))); + return QVariant(nTransactionFee); default: return QVariant(); } @@ -104,16 +104,8 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in } break; case Fee: { - int64 retval; - if(ParseMoney(value.toString().toStdString(), retval)) - { - nTransactionFee = retval; - walletdb.WriteSetting("nTransactionFee", nTransactionFee); - } - else - { - successful = false; // Parse error - } + nTransactionFee = value.toLongLong(); + walletdb.WriteSetting("nTransactionFee", nTransactionFee); } break; default: diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h index bdb797a2de..4ba44dc23f 100644 --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -18,14 +18,14 @@ public: explicit OptionsModel(CWallet *wallet, QObject *parent = 0); enum OptionID { - StartAtStartup, - MinimizeToTray, - MapPortUPnP, - MinimizeOnClose, - ConnectSOCKS4, - ProxyIP, - ProxyPort, - Fee, + StartAtStartup, // bool + MinimizeToTray, // bool + MapPortUPnP, // bool + MinimizeOnClose, // bool + ConnectSOCKS4, // bool + ProxyIP, // QString + ProxyPort, // QString + Fee, // qint64 OptionIDRowCount }; diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index d991f0d7ba..9515117c21 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -2,7 +2,7 @@ #include "ui_overviewpage.h" #include "walletmodel.h" -#include "guiutil.h" +#include "bitcoinunits.h" OverviewPage::OverviewPage(QWidget *parent) : QWidget(parent), @@ -34,8 +34,8 @@ OverviewPage::~OverviewPage() void OverviewPage::setBalance(qint64 balance, qint64 unconfirmedBalance) { - ui->labelBalance->setText(GUIUtil::formatMoney(balance) + QString(" BTC")); - ui->labelUnconfirmed->setText(GUIUtil::formatMoney(unconfirmedBalance) + QString(" BTC")); + ui->labelBalance->setText(BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, balance)); + ui->labelUnconfirmed->setText(BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, unconfirmedBalance)); } void OverviewPage::setNumTransactions(int count) diff --git a/src/qt/qvalidatedlineedit.cpp b/src/qt/qvalidatedlineedit.cpp index 2430cc9fb5..8ca230c9d7 100644 --- a/src/qt/qvalidatedlineedit.cpp +++ b/src/qt/qvalidatedlineedit.cpp @@ -1,5 +1,7 @@ #include "qvalidatedlineedit.h" +#include "guiconstants.h" + QValidatedLineEdit::QValidatedLineEdit(QWidget *parent) : QLineEdit(parent), valid(true) { @@ -19,7 +21,7 @@ void QValidatedLineEdit::setValid(bool valid) } else { - setStyleSheet("background:#FF8080"); + setStyleSheet(STYLE_INVALID); } this->valid = valid; } diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index 38a0a65520..58f9422b27 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -1,7 +1,7 @@ #include "sendcoinsdialog.h" #include "ui_sendcoinsdialog.h" #include "walletmodel.h" -#include "guiutil.h" +#include "bitcoinunits.h" #include "addressbookpage.h" #include "optionsmodel.h" #include "sendcoinsentry.h" @@ -71,7 +71,7 @@ void SendCoinsDialog::on_sendButton_clicked() QStringList formatted; foreach(const SendCoinsRecipient &rcp, recipients) { - formatted.append(tr("%1 BTC to %2 (%3)").arg(GUIUtil::formatMoney(rcp.amount), rcp.label, rcp.address)); + formatted.append(tr("%1 to %2 (%3)").arg(BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, rcp.amount), rcp.label, rcp.address)); } QMessageBox::StandardButton retval = QMessageBox::question(this, tr("Confirm send coins"), @@ -105,7 +105,7 @@ void SendCoinsDialog::on_sendButton_clicked() case WalletModel::AmountWithFeeExceedsBalance: QMessageBox::warning(this, tr("Send Coins"), tr("Total exceeds your balance when the %1 transaction fee is included"). - arg(GUIUtil::formatMoney(sendstatus.fee)), + arg(BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, sendstatus.fee)), QMessageBox::Ok, QMessageBox::Ok); break; case WalletModel::DuplicateAddress: diff --git a/src/qt/sendcoinsentry.cpp b/src/qt/sendcoinsentry.cpp index 2d4fe9b123..f3847f1693 100644 --- a/src/qt/sendcoinsentry.cpp +++ b/src/qt/sendcoinsentry.cpp @@ -1,6 +1,7 @@ #include "sendcoinsentry.h" #include "ui_sendcoinsentry.h" #include "guiutil.h" +#include "bitcoinunits.h" #include "addressbookpage.h" #include "walletmodel.h" #include "addresstablemodel.h" @@ -86,6 +87,16 @@ bool SendCoinsEntry::validate() { retval = false; } + else + { + if(ui->payAmount->value() <= 0) + { + // Cannot send 0 coins or less + ui->payAmount->setValid(false); + retval = false; + } + } + if(!ui->payTo->hasAcceptableInput() || (model && !model->validateAddress(ui->payTo->text()))) @@ -103,7 +114,7 @@ SendCoinsRecipient SendCoinsEntry::getValue() rv.address = ui->payTo->text(); rv.label = ui->addAsLabel->text(); - GUIUtil::parseMoney(ui->payAmount->text(), &rv.amount); + rv.amount = ui->payAmount->value(); return rv; } diff --git a/src/qt/transactiondesc.cpp b/src/qt/transactiondesc.cpp index 809e473060..7f4bebb3fb 100644 --- a/src/qt/transactiondesc.cpp +++ b/src/qt/transactiondesc.cpp @@ -125,17 +125,16 @@ string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) { if (wallet->IsMine(txout)) { - vector<unsigned char> vchPubKey; - if (ExtractPubKey(txout.scriptPubKey, wallet, vchPubKey)) + CBitcoinAddress address; + if (ExtractAddress(txout.scriptPubKey, wallet, address)) { - string strAddress = PubKeyToAddress(vchPubKey); - if (wallet->mapAddressBook.count(strAddress)) + if (wallet->mapAddressBook.count(address)) { strHTML += string() + _("<b>From:</b> ") + _("unknown") + "<br>"; strHTML += _("<b>To:</b> "); - strHTML += HtmlEscape(strAddress); - if (!wallet->mapAddressBook[strAddress].empty()) - strHTML += _(" (yours, label: ") + wallet->mapAddressBook[strAddress] + ")"; + strHTML += HtmlEscape(address.ToString()); + if (!wallet->mapAddressBook[address].empty()) + strHTML += _(" (yours, label: ") + wallet->mapAddressBook[address] + ")"; else strHTML += _(" (yours)"); strHTML += "<br>"; @@ -211,14 +210,13 @@ string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) if (wtx.mapValue["to"].empty()) { // Offline transaction - uint160 hash160; - if (ExtractHash160(txout.scriptPubKey, hash160)) + CBitcoinAddress address; + if (ExtractAddress(txout.scriptPubKey, wallet, address)) { - string strAddress = Hash160ToAddress(hash160); strHTML += _("<b>To:</b> "); - if (wallet->mapAddressBook.count(strAddress) && !wallet->mapAddressBook[strAddress].empty()) - strHTML += wallet->mapAddressBook[strAddress] + " "; - strHTML += strAddress; + if (wallet->mapAddressBook.count(address) && !wallet->mapAddressBook[address].empty()) + strHTML += wallet->mapAddressBook[address] + " "; + strHTML += address.ToString(); strHTML += "<br>"; } } diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp index c74b48bd61..50767d30fe 100644 --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -79,10 +79,10 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet * { if(wallet->IsMine(txout)) { - std::vector<unsigned char> vchPubKey; - if (ExtractPubKey(txout.scriptPubKey, wallet, vchPubKey)) + CBitcoinAddress address; + if (ExtractAddress(txout.scriptPubKey, wallet, address)) { - sub.address = PubKeyToAddress(vchPubKey); + sub.address = address.ToString(); } break; } @@ -137,9 +137,11 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet * { // Sent to Bitcoin Address sub.type = TransactionRecord::SendToAddress; - uint160 hash160; - if (ExtractHash160(txout.scriptPubKey, hash160)) - sub.address = Hash160ToAddress(hash160); + CBitcoinAddress address; + if (ExtractAddress(txout.scriptPubKey, wallet, address)) + { + sub.address = address.ToString(); + } } int64 nValue = txout.nValue; diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp index 17622e07fa..2b8fe0b471 100644 --- a/src/qt/transactiontablemodel.cpp +++ b/src/qt/transactiontablemodel.cpp @@ -5,6 +5,7 @@ #include "transactiondesc.h" #include "walletmodel.h" #include "addresstablemodel.h" +#include "bitcoinunits.h" #include "headers.h" @@ -397,7 +398,7 @@ QVariant TransactionTableModel::formatTxToAddress(const TransactionRecord *wtx) QVariant TransactionTableModel::formatTxAmount(const TransactionRecord *wtx, bool showUnconfirmed) const { - QString str = QString::fromStdString(FormatMoney(wtx->credit + wtx->debit)); + QString str = BitcoinUnits::format(BitcoinUnits::BTC, wtx->credit + wtx->debit); if(showUnconfirmed) { if(!wtx->status.confirmed || wtx->status.maturity != TransactionStatus::Mature) @@ -514,11 +515,11 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const /* Non-confirmed transactions are grey */ if(!rec->status.confirmed) { - return QColor(128, 128, 128); + return COLOR_UNCONFIRMED; } if(index.column() == Amount && (rec->credit+rec->debit) < 0) { - return QColor(255, 0, 0); + return COLOR_NEGATIVE; } } else if (role == TypeRole) diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp index 50291fea42..f88b6fc123 100644 --- a/src/qt/transactionview.cpp +++ b/src/qt/transactionview.cpp @@ -5,7 +5,7 @@ #include "walletmodel.h" #include "addresstablemodel.h" #include "transactiontablemodel.h" -#include "guiutil.h" +#include "bitcoinunits.h" #include "csvmodelwriter.h" #include "transactiondescdialog.h" #include "editaddressdialog.h" @@ -227,7 +227,7 @@ void TransactionView::changedPrefix(const QString &prefix) void TransactionView::changedAmount(const QString &amount) { qint64 amount_parsed = 0; - if(GUIUtil::parseMoney(amount, &amount_parsed)) + if(BitcoinUnits::parse(BitcoinUnits::BTC, amount, &amount_parsed)) { transactionProxyModel->setMinAmount(amount_parsed); } diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 4ff2e0ab15..732472c1a9 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -66,9 +66,8 @@ void WalletModel::update() bool WalletModel::validateAddress(const QString &address) { - uint160 hash160 = 0; - - return AddressToHash160(address.toStdString(), hash160); + CBitcoinAddress addressParsed(address.toStdString()); + return addressParsed.IsValid(); } WalletModel::SendCoinsReturn WalletModel::sendCoins(const QList<SendCoinsRecipient> &recipients) @@ -87,7 +86,7 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(const QList<SendCoinsRecipie { uint160 hash160 = 0; - if(!AddressToHash160(rcp.address.toUtf8().constData(), hash160)) + if(!validateAddress(rcp.address)) { return InvalidAddress; } |