diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2013-08-29 07:37:30 -0700 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2013-08-29 07:37:30 -0700 |
commit | 1a12b3e09079c26deb48a547cdfcc7ffdd176dee (patch) | |
tree | 68c33232eb4c88d13b403231c772d178b853b413 /src | |
parent | ae6eac667baf93b39e1f06726ff5efa98b2505df (diff) | |
parent | bdd0c59ab0b412b3e8595bd95f635f975e22bb85 (diff) | |
download | bitcoin-1a12b3e09079c26deb48a547cdfcc7ffdd176dee.tar.xz |
Merge pull request #2930 from Diapolo/displayUnit
Bitcoin-Qt: fixes for using display unit from options
Diffstat (limited to 'src')
-rw-r--r-- | src/qt/bitcoin.cpp | 3 | ||||
-rw-r--r-- | src/qt/bitcoingui.cpp | 5 | ||||
-rw-r--r-- | src/qt/paymentserver.cpp | 22 | ||||
-rw-r--r-- | src/qt/paymentserver.h | 18 | ||||
-rw-r--r-- | src/qt/sendcoinsdialog.cpp | 24 | ||||
-rw-r--r-- | src/qt/test/paymentservertests.cpp | 3 | ||||
-rw-r--r-- | src/qt/transactiondesc.cpp | 26 | ||||
-rw-r--r-- | src/qt/transactiondesc.h | 2 | ||||
-rw-r--r-- | src/qt/transactiontablemodel.cpp | 14 |
9 files changed, 67 insertions, 50 deletions
diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index 9c290fa717..f2386f3cff 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -300,7 +300,8 @@ int main(int argc, char *argv[]) optionsModel.Upgrade(); // Must be done after AppInit2 PaymentServer::LoadRootCAs(); - paymentServer->initNetManager(optionsModel); + paymentServer->setOptionsModel(&optionsModel); + paymentServer->initNetManager(); if (splashref) splash.finish(&window); diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index ad32c9ea68..bb9eb60e5b 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -670,9 +670,12 @@ void BitcoinGUI::closeEvent(QCloseEvent *event) void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee) { + if (!clientModel || !clientModel->getOptionsModel()) + return; + 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(BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nFeeRequired)); + "Do you want to pay the fee?").arg(BitcoinUnits::formatWithUnit(clientModel->getOptionsModel()->getDisplayUnit(), nFeeRequired)); QMessageBox::StandardButton retval = QMessageBox::question( this, tr("Confirm transaction fee"), strMessage, QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes); diff --git a/src/qt/paymentserver.cpp b/src/qt/paymentserver.cpp index ff3c2a0981..c7c6f6706a 100644 --- a/src/qt/paymentserver.cpp +++ b/src/qt/paymentserver.cpp @@ -92,7 +92,7 @@ static void ReportInvalidCertificate(const QSslCertificate& cert) } // -// Load openSSL's list of root certificate authorities +// Load OpenSSL's list of root certificate authorities // void PaymentServer::LoadRootCAs(X509_STORE* _store) { @@ -147,7 +147,7 @@ void PaymentServer::LoadRootCAs(X509_STORE* _store) const unsigned char *data = (const unsigned char *)certData.data(); X509* x509 = d2i_X509(0, &data, certData.size()); - if (x509 && X509_STORE_add_cert( PaymentServer::certStore, x509)) + if (x509 && X509_STORE_add_cert(PaymentServer::certStore, x509)) { // Note: X509_STORE_free will free the X509* objects when // the PaymentServer is destroyed @@ -303,18 +303,20 @@ bool PaymentServer::eventFilter(QObject *, QEvent *event) return false; } -void PaymentServer::initNetManager(const OptionsModel& options) +void PaymentServer::initNetManager() { + if (!optionsModel) + return; if (netManager != NULL) delete netManager; // netManager is used to fetch paymentrequests given in bitcoin: URI's netManager = new QNetworkAccessManager(this); - // Use proxy settings from options: + // Use proxy settings from optionsModel: QString proxyIP; quint16 proxyPort; - if (options.getProxySettings(proxyIP, proxyPort)) + if (optionsModel->getProxySettings(proxyIP, proxyPort)) { QNetworkProxy proxy; proxy.setType(QNetworkProxy::Socks5Proxy); @@ -435,13 +437,16 @@ bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, QList<SendCoinsRecipient>& recipients) { + if (!optionsModel) + return false; + QList<std::pair<CScript,qint64> > sendingTos = request.getPayTo(); qint64 totalAmount = 0; foreach(const PAIRTYPE(CScript, qint64)& sendingTo, sendingTos) { CTxOut txOut(sendingTo.second, sendingTo.first); if (txOut.IsDust(CTransaction::nMinRelayTxFee)) { QString message = QObject::tr("Requested payment amount (%1) too small") - .arg(BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, sendingTo.second)); + .arg(BitcoinUnits::formatWithUnit(optionsModel->getDisplayUnit(), sendingTo.second)); qDebug() << message; emit reportError(tr("Payment request error"), message, CClientUIInterface::MODAL); return false; @@ -614,3 +619,8 @@ PaymentServer::reportSslErrors(QNetworkReply* reply, const QList<QSslError> &err } emit reportError(tr("Network request error"), errString, CClientUIInterface::MODAL); } + +void PaymentServer::setOptionsModel(OptionsModel *optionsModel) +{ + this->optionsModel = optionsModel; +} diff --git a/src/qt/paymentserver.h b/src/qt/paymentserver.h index 7c6b2eabf0..131ede518e 100644 --- a/src/qt/paymentserver.h +++ b/src/qt/paymentserver.h @@ -17,7 +17,7 @@ // received at or during startup in a list. // // When startup is finished and the main window is -// show, a signal is sent to slot uiReady(), which +// shown, a signal is sent to slot uiReady(), which // emits a receivedURL() signal for any payment // requests that happened during startup. // @@ -70,13 +70,16 @@ public: // Return certificate store static X509_STORE* getCertStore() { return certStore; } - // Setup networking (options is used to get proxy settings) - void initNetManager(const OptionsModel& options); + // Setup networking + void initNetManager(); // Constructor registers this on the parent QApplication to // receive QEvent::FileOpen events bool eventFilter(QObject *object, QEvent *event); + // OptionsModel is used for getting proxy settings and display unit + void setOptionsModel(OptionsModel *optionsModel); + signals: // Fired when a valid payment request is received void receivedPaymentRequest(SendCoinsRecipient); @@ -106,12 +109,15 @@ private: void handleURIOrFile(const QString& s); void fetchRequest(const QUrl& url); - bool saveURIs; // true during startup + bool saveURIs; // true during startup QLocalServer* uriServer; - static X509_STORE* certStore; // Trusted root certificates + + static X509_STORE* certStore; // Trusted root certificates static void freeCertStore(); - QNetworkAccessManager* netManager; // Used to fetch payment requests + QNetworkAccessManager* netManager; // Used to fetch payment requests + + OptionsModel *optionsModel; }; #endif // PAYMENTSERVER_H diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index 9086f6614e..e3fec61046 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -63,12 +63,12 @@ SendCoinsDialog::~SendCoinsDialog() void SendCoinsDialog::on_sendButton_clicked() { + if(!model || !model->getOptionsModel()) + return; + QList<SendCoinsRecipient> recipients; bool valid = true; - if(!model) - return; - for(int i = 0; i < ui->entries->count(); ++i) { SendCoinsEntry *entry = qobject_cast<SendCoinsEntry*>(ui->entries->itemAt(i)->widget()); @@ -94,7 +94,7 @@ void SendCoinsDialog::on_sendButton_clicked() QStringList formatted; foreach(const SendCoinsRecipient &rcp, recipients) { - QString amount = BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, rcp.amount); + QString amount = BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), rcp.amount); if (rcp.authenticatedMerchant.isEmpty()) { QString address = rcp.address; @@ -158,7 +158,7 @@ void SendCoinsDialog::on_sendButton_clicked() case WalletModel::AmountWithFeeExceedsBalance: QMessageBox::warning(this, tr("Send Coins"), tr("The total exceeds your balance when the %1 transaction fee is included."). - arg(BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, sendstatus.fee)), + arg(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), sendstatus.fee)), QMessageBox::Ok, QMessageBox::Ok); break; case WalletModel::DuplicateAddress: @@ -338,18 +338,14 @@ void SendCoinsDialog::setBalance(qint64 balance, qint64 unconfirmedBalance, qint { Q_UNUSED(unconfirmedBalance); Q_UNUSED(immatureBalance); - if(!model || !model->getOptionsModel()) - return; - int unit = model->getOptionsModel()->getDisplayUnit(); - ui->labelBalance->setText(BitcoinUnits::formatWithUnit(unit, balance)); + if(model && model->getOptionsModel()) + { + ui->labelBalance->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), balance)); + } } void SendCoinsDialog::updateDisplayUnit() { - if(model && model->getOptionsModel()) - { - // Update labelBalance with the current balance and the current unit - ui->labelBalance->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), model->getBalance())); - } + setBalance(model->getBalance(), 0, 0); } diff --git a/src/qt/test/paymentservertests.cpp b/src/qt/test/paymentservertests.cpp index 2e26ab0c9b..6c8ad62b2b 100644 --- a/src/qt/test/paymentservertests.cpp +++ b/src/qt/test/paymentservertests.cpp @@ -58,7 +58,8 @@ void PaymentServerTests::paymentServerTests() X509_STORE* caStore = X509_STORE_new(); X509_STORE_add_cert(caStore, parse_b64der_cert(caCert_BASE64)); PaymentServer::LoadRootCAs(caStore); - server->initNetManager(optionsModel); + server->setOptionsModel(&optionsModel); + server->initNetManager(); server->uiReady(); // Now feed PaymentRequests to server, and observe signals it produces: diff --git a/src/qt/transactiondesc.cpp b/src/qt/transactiondesc.cpp index 25ff3623c0..55875c2e46 100644 --- a/src/qt/transactiondesc.cpp +++ b/src/qt/transactiondesc.cpp @@ -32,7 +32,7 @@ QString TransactionDesc::FormatTxStatus(const CWalletTx& wtx) } } -QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) +QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, int unit) { QString strHTML; @@ -129,7 +129,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) nUnmatured += wallet->GetCredit(txout); strHTML += "<b>" + tr("Credit") + ":</b> "; if (wtx.IsInMainChain()) - strHTML += BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nUnmatured)+ " (" + tr("matures in %n more block(s)", "", wtx.GetBlocksToMaturity()) + ")"; + strHTML += BitcoinUnits::formatWithUnit(unit, nUnmatured)+ " (" + tr("matures in %n more block(s)", "", wtx.GetBlocksToMaturity()) + ")"; else strHTML += "(" + tr("not accepted") + ")"; strHTML += "<br>"; @@ -139,7 +139,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) // // Credit // - strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nNet) + "<br>"; + strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatWithUnit(unit, nNet) + "<br>"; } else { @@ -175,7 +175,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) } } - strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, -txout.nValue) + "<br>"; + strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatWithUnit(unit, -txout.nValue) + "<br>"; } if (fAllToMe) @@ -183,13 +183,13 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) // Payment to self int64 nChange = wtx.GetChange(); int64 nValue = nCredit - nChange; - strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, -nValue) + "<br>"; - strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nValue) + "<br>"; + strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatWithUnit(unit, -nValue) + "<br>"; + strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatWithUnit(unit, nValue) + "<br>"; } int64 nTxFee = nDebit - GetValueOut(wtx); if (nTxFee > 0) - strHTML += "<b>" + tr("Transaction fee") + ":</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, -nTxFee) + "<br>"; + strHTML += "<b>" + tr("Transaction fee") + ":</b> " + BitcoinUnits::formatWithUnit(unit, -nTxFee) + "<br>"; } else { @@ -198,14 +198,14 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) // BOOST_FOREACH(const CTxIn& txin, wtx.vin) if (wallet->IsMine(txin)) - strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, -wallet->GetDebit(txin)) + "<br>"; + strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatWithUnit(unit, -wallet->GetDebit(txin)) + "<br>"; BOOST_FOREACH(const CTxOut& txout, wtx.vout) if (wallet->IsMine(txout)) - strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, wallet->GetCredit(txout)) + "<br>"; + strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatWithUnit(unit, wallet->GetCredit(txout)) + "<br>"; } } - strHTML += "<b>" + tr("Net amount") + ":</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nNet, true) + "<br>"; + strHTML += "<b>" + tr("Net amount") + ":</b> " + BitcoinUnits::formatWithUnit(unit, nNet, true) + "<br>"; // // Message @@ -243,10 +243,10 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) strHTML += "<hr><br>" + tr("Debug information") + "<br><br>"; BOOST_FOREACH(const CTxIn& txin, wtx.vin) if(wallet->IsMine(txin)) - strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, -wallet->GetDebit(txin)) + "<br>"; + strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatWithUnit(unit, -wallet->GetDebit(txin)) + "<br>"; BOOST_FOREACH(const CTxOut& txout, wtx.vout) if(wallet->IsMine(txout)) - strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, wallet->GetCredit(txout)) + "<br>"; + strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatWithUnit(unit, wallet->GetCredit(txout)) + "<br>"; strHTML += "<br><b>" + tr("Transaction") + ":</b><br>"; strHTML += GUIUtil::HtmlEscape(wtx.ToString(), true); @@ -274,7 +274,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) strHTML += GUIUtil::HtmlEscape(wallet->mapAddressBook[address].name) + " "; strHTML += QString::fromStdString(CBitcoinAddress(address).ToString()); } - strHTML = strHTML + " " + tr("Amount") + "=" + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, vout.nValue); + strHTML = strHTML + " " + tr("Amount") + "=" + BitcoinUnits::formatWithUnit(unit, vout.nValue); strHTML = strHTML + " IsMine=" + (wallet->IsMine(vout) ? tr("true") : tr("false")) + "</li>"; } } diff --git a/src/qt/transactiondesc.h b/src/qt/transactiondesc.h index cb0dda5b58..a659281dd2 100644 --- a/src/qt/transactiondesc.h +++ b/src/qt/transactiondesc.h @@ -14,7 +14,7 @@ class TransactionDesc: public QObject Q_OBJECT public: - static QString toHTML(CWallet *wallet, CWalletTx &wtx); + static QString toHTML(CWallet *wallet, CWalletTx &wtx, int unit); private: TransactionDesc() {} diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp index baf1e16483..625e657295 100644 --- a/src/qt/transactiontablemodel.cpp +++ b/src/qt/transactiontablemodel.cpp @@ -48,11 +48,12 @@ struct TxLessThan class TransactionTablePriv { public: - TransactionTablePriv(CWallet *wallet, TransactionTableModel *parent): - wallet(wallet), - parent(parent) + TransactionTablePriv(CWallet *wallet, TransactionTableModel *parent) : + wallet(wallet), + parent(parent) { } + CWallet *wallet; TransactionTableModel *parent; @@ -200,19 +201,18 @@ public: } } - QString describe(TransactionRecord *rec) + QString describe(TransactionRecord *rec, int unit) { { LOCK(wallet->cs_wallet); std::map<uint256, CWalletTx>::iterator mi = wallet->mapWallet.find(rec->hash); if(mi != wallet->mapWallet.end()) { - return TransactionDesc::toHTML(wallet, mi->second); + return TransactionDesc::toHTML(wallet, mi->second, unit); } } return QString(""); } - }; TransactionTableModel::TransactionTableModel(CWallet* wallet, WalletModel *parent): @@ -561,7 +561,7 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const case DateRole: return QDateTime::fromTime_t(static_cast<uint>(rec->time)); case LongDescriptionRole: - return priv->describe(rec); + return priv->describe(rec, walletModel->getOptionsModel()->getDisplayUnit()); case AddressRole: return QString::fromStdString(rec->address); case LabelRole: |