From e5457590671bbfa68d3f8fb2a9abb3ab8eac3050 Mon Sep 17 00:00:00 2001 From: Bzlcoin Date: Fri, 2 Feb 2018 19:47:00 -0300 Subject: [PATCH] Add Market Browser Add BTC price Add USD price Add BRL price More Portuguese translation --- src/qt/bitcoingui.cpp | 2 +- src/qt/forms/aboutdialog.ui | 2 +- src/qt/forms/overviewpage.ui | 92 ++++++- src/qt/locale/bitcoin_pt_BR.ts | 56 ++--- src/qt/marketbrowser.cpp | 38 ++- src/qt/marketbrowser.h | 1 + src/qt/overviewpage.cpp | 430 +++++++++++++++++---------------- 7 files changed, 364 insertions(+), 257 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 509c5ba..dc2a3c9 100755 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -484,7 +484,7 @@ void BitcoinGUI::createToolBars() mainToolbar->addAction(messageAction); mainToolbar->addAction(statisticsAction); mainToolbar->addAction(blockAction); - //mainToolbar->addAction(marketAction); + mainToolbar->addAction(marketAction); //mainToolbar->addAction(chatAction); Next release secondaryToolbar = addToolBar(tr("Actions toolbar")); diff --git a/src/qt/forms/aboutdialog.ui b/src/qt/forms/aboutdialog.ui index e135367..34ea817 100755 --- a/src/qt/forms/aboutdialog.ui +++ b/src/qt/forms/aboutdialog.ui @@ -128,7 +128,7 @@ This product includes software developed by the OpenSSL Project for use in the O - Join us on the forums at <a href="https://bzlcointalk.org" style="color: #FFF;">https://bzlcointalk.org</a> + Join us on the forums at <a href="https://forum.bzlcoin.org" style="color: #FFF;">https://forum.bzlcoin.org</a> diff --git a/src/qt/forms/overviewpage.ui b/src/qt/forms/overviewpage.ui index 34628f1..d2527f0 100755 --- a/src/qt/forms/overviewpage.ui +++ b/src/qt/forms/overviewpage.ui @@ -227,7 +227,6 @@ - 11 75 true @@ -245,6 +244,84 @@ Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + USD Total: + + + + + + + + 75 + true + + + + IBeamCursor + + + Your current total balance in USD, Rate is not updated often + + + 0 USD + + + + + + + BRL Total: + + + + + + + + 75 + true + + + + IBeamCursor + + + Your current total balance in BRL, Rate is not updated often + + + 0 BRL + + + + + + + BTC Total: + + + + + + + + 75 + true + + + + IBeamCursor + + + Your current total balance in BTC, Rate is not updated often + + + 0 BTC + + @@ -270,7 +347,7 @@ - :/icons/bzlcoin + :/icons/denarius @@ -291,20 +368,15 @@ - - - 11 - - - <b>Recent Transactions</b> + <b>Recent transactions</b> - The displayed information may be out of date. Your wallet automatically synchronizes with the BZLCoin network after a connection is established, but this process has not completed yet. + The displayed information may be out of date. Your wallet automatically synchronizes with the Denarius network after a connection is established, but this process has not completed yet. QLabel { color: red; } @@ -375,4 +447,4 @@ - + \ No newline at end of file diff --git a/src/qt/locale/bitcoin_pt_BR.ts b/src/qt/locale/bitcoin_pt_BR.ts index 86baa7b..bd43a55 100755 --- a/src/qt/locale/bitcoin_pt_BR.ts +++ b/src/qt/locale/bitcoin_pt_BR.ts @@ -549,7 +549,7 @@ Este produto inclui software desenvolvido pelo Projeto OpenSSL para uso no OpenS Downloaded %1 blocks of transaction history. - + Baixando %1 blocos de histórico de transações @@ -559,22 +559,22 @@ Este produto inclui software desenvolvido pelo Projeto OpenSSL para uso no OpenS Not staking because wallet is locked - + Não estacando porque a carteira está bloqueada Not staking because wallet is offline - + Não estacando porque a carteira está sem conexão Not staking because wallet is syncing - + Não apostando porque a carteira está sincronizando Not staking because you don't have mature coins - + Não estacando porque você não tem moedas maduras @@ -614,17 +614,17 @@ Este produto inclui software desenvolvido pelo Projeto OpenSSL para uso no OpenS Last received block was generated %1. - + O último bloco recebido foi gerado %1 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? - + Essa transação excede o limite de tamanho. Você ainda pode enviá-lo para uma taxa de %1, que vai para os nós que processam sua transação e ajuda a suportar a rede. Você quer pagar a taxa? Confirm transaction fee - + Confirmar taxa de transação @@ -658,7 +658,7 @@ Endereço: %4 URI can not be parsed! This can be caused by an invalid ShadowCoin address or malformed URI parameters. - + URI não pode ser analisado! Isso pode ser causado por um endereço inválido do ShadowCoin ou por parâmetros URI malformados @@ -673,12 +673,12 @@ Endereço: %4 Backup Wallet - + Backup Carteira Wallet Data (*.dat) - + Carteira Data(*.dat) @@ -713,12 +713,12 @@ Endereço: %4 Not staking - + Não apostando A fatal error occurred. ShadowCoin can no longer continue safely and will quit. - + Ocorreu um erro fatal. ShadowCoin não pode continuar com segurança e vai fechar. @@ -998,7 +998,7 @@ This label turns red, if the priority is smaller than "medium". The label associated with this address book entry - + A etiqueta associado a esta entrada do catálogo de endereços @@ -1008,7 +1008,7 @@ This label turns red, if the priority is smaller than "medium". The address associated with this address book entry. This can only be modified for sending addresses. - + O endereço associado a esta entrada do catálogo de endereços. Isso só pode ser modificado para enviar endereços @@ -1038,7 +1038,7 @@ This label turns red, if the priority is smaller than "medium". The entered address "%1" is not a valid ShadowCoin address. - + O endereço introduzido "%1" não é um endereço ShadowCoin válido. @@ -1072,7 +1072,7 @@ This label turns red, if the priority is smaller than "medium". command-line options - + Opção de linha de comando @@ -1082,12 +1082,12 @@ This label turns red, if the priority is smaller than "medium". Set language, for example "de_DE" (default: system locale) - + Definir idioma (default: system locale) Start minimized - + Iniciar Minimizado @@ -1110,7 +1110,7 @@ This label turns red, if the priority is smaller than "medium". Optional transaction fee per kB that helps make sure your transactions are processed quickly. Most transactions are 1 kB. Fee 0.01 recommended. - + Taxa de transação opcional por kB que ajuda a garantir que suas transações sejam processadas rapidamente. A maioria das transações são de 1 kB. Taxa 0.01 recomendada. @@ -1120,7 +1120,7 @@ This label turns red, if the priority is smaller than "medium". Reserved amount does not participate in staking and is therefore spendable at any time. - + O valor reservado não participa em aposta e, portanto, pode ser gasto a qualquer momento @@ -1326,12 +1326,12 @@ This label turns red, if the priority is smaller than "medium". Stake: - + Aposta: Unconfirmed: - + Não confirmado @@ -1341,12 +1341,12 @@ This label turns red, if the priority is smaller than "medium". Spendable: - + Disponível: Your current spendable balance - Seu saldo atual spendable + Seu saldo atual disponível @@ -1376,12 +1376,12 @@ This label turns red, if the priority is smaller than "medium". Total of transactions that have yet to be confirmed, and do not yet count toward the current balance - + Total of coins that was staked, and do not yet count toward the current balance - + Total de moedas que foram apostadas e ainda não contam para o saldo atual @@ -2685,7 +2685,7 @@ This label turns red, if the priority is smaller than "medium". Stake your coins to support network and gain reward (default: 1) - + Aposte suas moedas para da suporte a rede e ganhar recompensas diff --git a/src/qt/marketbrowser.cpp b/src/qt/marketbrowser.cpp index f278d73..5e5b00f 100755 --- a/src/qt/marketbrowser.cpp +++ b/src/qt/marketbrowser.cpp @@ -12,22 +12,26 @@ using namespace json_spirit; -const QString kBaseUrl = "http://bzlcoin.io/dnrusd.php"; -const QString kBaseUrl1 = "http://blockchain.info/tobtc?currency=USD&value=1"; -const QString kBaseUrl2 = "http://bzlcoin.io/dnrmc.php"; -const QString kBaseUrl3 = "http://bzlcoin.io/dnrbtc.php"; +const QString kBaseUrl = "https://bzlcoin.org/marketbzl.php?market=market.usd"; +const QString kBaseUrl0 = "https://bzlcoin.org/marketbzl.php?market=market.brl"; +const QString kBaseUrl1 = "https://blockchain.info/tobtc?currency=USD&value=1"; +const QString kBaseUrl2 = "https://bzlcoin.org/marketbzl.php?market=bzl.capbzl.usd"; +const QString kBaseUrl3 = "https://bzlcoin.org/marketbzl.php?market=market.btc"; QString bitcoinp = ""; QString bzlcoinp = ""; +QString bzlcoinp2 = ""; QString dnrmcp = ""; QString dnrbtcp = ""; double bitcoin2; double bzlcoin2; +double bzlcoin3; double dnrmc2; double dnrbtc2; QString bitcoing; QString dnrmarket; QString dollarg; +QString realarg; int mode=1; int o = 0; @@ -51,6 +55,7 @@ void MarketBrowser::update() { QString temps = ui->egals->text(); double totald = dollarg.toDouble() * temps.toDouble(); + double totaldb = realarg.toDouble() * temps.toDouble(); double totaldq = bitcoing.toDouble() * temps.toDouble(); ui->egald->setText("$ "+QString::number(totald)+" USD or "+QString::number(totaldq)+" BTC"); @@ -59,6 +64,7 @@ void MarketBrowser::update() void MarketBrowser::requests() { getRequest(kBaseUrl); + getRequest(kBaseUrl0); getRequest(kBaseUrl1); getRequest(kBaseUrl2); getRequest(kBaseUrl3); @@ -92,7 +98,7 @@ if (what == kBaseUrl) // BZLCoin Price bzlcoin2 = (bzlcoin.toDouble()); bzlcoin = QString::number(bzlcoin2, 'f', 2); - if(bzlcoin > bzlcoinp) + if(bzlcoin > bzlcoinp) { ui->bzlcoin->setText("$" + bzlcoin + ""); } else if (bzlcoin < bzlcoinp) { @@ -105,6 +111,28 @@ if (what == kBaseUrl) // BZLCoin Price dollarg = bzlcoin; } +if (what == kBaseUrl0) // BZLCoin Price BRL +{ + + // QNetworkReply is a QIODevice. So we read from it just like it was a file + QString bzlcoinz = finished->readAll(); + bzlcoin3 = (bzlcoinz.toDouble()); + bzlcoinz = QString::number(bzlcoin3, 'f', 2); + + /* + if(bzlcoinz > bzlcoinp2) + { + ui->bzlcoinz->setText("$" + bzlcoinz + ""); + } else if (bzlcoinz < bzlcoinp) { + ui->bzlcoinz->setText("$" + bzlcoinz + ""); + } else { + ui->bzlcoin->setText("$"+bzlcoinz+" BRL"); + } */ + + bzlcoinp2 = bzlcoinz; + realarg = bzlcoinz; +} + if (what == kBaseUrl1) // Bitcoin Price { diff --git a/src/qt/marketbrowser.h b/src/qt/marketbrowser.h index 4226fd6..57e9289 100755 --- a/src/qt/marketbrowser.h +++ b/src/qt/marketbrowser.h @@ -14,6 +14,7 @@ extern QString bitcoing; extern QString dollarg; extern QString dnrmarket; +extern QString realarg; namespace Ui { class MarketBrowser; diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index fa59522..bc5f0a3 100755 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -1,212 +1,218 @@ -#include "overviewpage.h" -#include "ui_overviewpage.h" - -#include "walletmodel.h" -#include "bitcoinunits.h" -#include "optionsmodel.h" -#include "transactiontablemodel.h" -#include "transactionfilterproxy.h" -#include "guiutil.h" -#include "guiconstants.h" -#include "marketbrowser.h" - -#include -#include - -#define DECORATION_SIZE 64 -#define NUM_ITEMS 3 - -class TxViewDelegate : public QAbstractItemDelegate -{ - Q_OBJECT -public: - TxViewDelegate(): QAbstractItemDelegate(), unit(BitcoinUnits::BTC), unitUSD(BitcoinUnits::USD) - { - - } - - inline void paint(QPainter *painter, const QStyleOptionViewItem &option, - const QModelIndex &index ) const - { - painter->save(); - - QIcon icon = qvariant_cast(index.data(Qt::DecorationRole)); - QRect mainRect = option.rect; - QRect decorationRect(mainRect.topLeft(), QSize(DECORATION_SIZE, DECORATION_SIZE)); - int xspace = DECORATION_SIZE + 8; - int ypad = 6; - int halfheight = (mainRect.height() - 2*ypad)/2; - QRect amountRect(mainRect.left() + xspace, mainRect.top()+ypad, mainRect.width() - xspace, halfheight); - QRect addressRect(mainRect.left() + xspace, mainRect.top()+ypad+halfheight, mainRect.width() - xspace, halfheight); - icon.paint(painter, decorationRect); - - QDateTime date = index.data(TransactionTableModel::DateRole).toDateTime(); - QString address = index.data(Qt::DisplayRole).toString(); - qint64 amount = index.data(TransactionTableModel::AmountRole).toLongLong(); - bool confirmed = index.data(TransactionTableModel::ConfirmedRole).toBool(); - QVariant value = index.data(Qt::ForegroundRole); - QColor foreground = option.palette.color(QPalette::Text); - if(qVariantCanConvert(value)) - { - foreground = qvariant_cast(value); - } - - painter->setPen(foreground); - painter->drawText(addressRect, Qt::AlignLeft|Qt::AlignVCenter, address); - - if(amount < 0) - { - foreground = COLOR_NEGATIVE; - } - else if(!confirmed) - { - foreground = COLOR_UNCONFIRMED; - } - else - { - foreground = option.palette.color(QPalette::Text); - } - painter->setPen(foreground); - QString amountText = BitcoinUnits::formatWithUnit(unit, amount, true); - if(!confirmed) - { - amountText = QString("[") + amountText + QString("]"); - } - painter->drawText(amountRect, Qt::AlignRight|Qt::AlignVCenter, amountText); - - painter->setPen(option.palette.color(QPalette::Text)); - painter->drawText(amountRect, Qt::AlignLeft|Qt::AlignVCenter, GUIUtil::dateTimeStr(date)); - - painter->restore(); - } - - inline QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const - { - return QSize(DECORATION_SIZE, DECORATION_SIZE); - } - - int unit; - int unitUSD; - -}; -#include "overviewpage.moc" - -OverviewPage::OverviewPage(QWidget *parent) : - QWidget(parent), - ui(new Ui::OverviewPage), - currentBalance(-1), - currentStake(0), - currentUnconfirmedBalance(-1), - currentImmatureBalance(-1), - txdelegate(new TxViewDelegate()), - filter(0) -{ - ui->setupUi(this); - - // Recent transactions - ui->listTransactions->setItemDelegate(txdelegate); - ui->listTransactions->setIconSize(QSize(DECORATION_SIZE, DECORATION_SIZE)); - ui->listTransactions->setMinimumHeight(NUM_ITEMS * (DECORATION_SIZE + 2)); - ui->listTransactions->setAttribute(Qt::WA_MacShowFocusRect, false); - - connect(ui->listTransactions, SIGNAL(clicked(QModelIndex)), this, SLOT(handleTransactionClicked(QModelIndex))); - - // init "out of sync" warning labels - ui->labelWalletStatus->setText("(" + tr("Out of Sync!") + ")"); - ui->labelTransactionsStatus->setText("(" + tr("Out of Sync!") + ")"); - - // start with displaying the "out of sync" warnings - showOutOfSyncWarning(true); -} - -void OverviewPage::handleTransactionClicked(const QModelIndex &index) -{ - if(filter) - emit transactionClicked(filter->mapToSource(index)); -} - -OverviewPage::~OverviewPage() -{ - delete ui; -} - -void OverviewPage::setBalance(qint64 balance, qint64 stake, qint64 unconfirmedBalance, qint64 immatureBalance) -{ - int unit = model->getOptionsModel()->getDisplayUnit(); - //int unitUSD = BitcoinUnits::USD; - //int unitdBTC = BitcoinUnits::dBTC; - currentBalance = balance; - currentStake = stake; - currentUnconfirmedBalance = unconfirmedBalance; - currentImmatureBalance = immatureBalance; - ui->labelBalance->setText(BitcoinUnits::formatWithUnit(unit, balance)); - ui->labelStake->setText(BitcoinUnits::formatWithUnit(unit, stake)); - ui->labelUnconfirmed->setText(BitcoinUnits::formatWithUnit(unit, unconfirmedBalance)); - ui->labelImmature->setText(BitcoinUnits::formatWithUnit(unit, immatureBalance)); - ui->labelTotal->setText(BitcoinUnits::formatWithUnit(unit, balance + stake + unconfirmedBalance + immatureBalance)); - //ui->labelUSDTotal->setText(BitcoinUnits::formatWithUnit(unitUSD, dollarg.toDouble() * (balance + stake + unconfirmedBalance + immatureBalance))); - - //QString total; - //double dollarg2 = (dollarg.toDouble() * (balance + stake + unconfirmedBalance + immatureBalance) / 100000000); - //total = QString::number(dollarg2, 'f', 2); - //ui->labelUSDTotal->setText("$" + total + " USD"); - - //ui->labelBTCTotal->setText(BitcoinUnits::formatWithUnit(unitdBTC, bitcoing.toDouble() * (balance + stake + unconfirmedBalance + immatureBalance))); - ui->labelTradeLink->setTextFormat(Qt::RichText); - ui->labelTradeLink->setTextInteractionFlags(Qt::TextBrowserInteraction); - ui->labelTradeLink->setOpenExternalLinks(true); - - // only show immature (newly mined) balance if it's non-zero, so as not to complicate things - // for the non-mining users - bool showImmature = immatureBalance != 0; - ui->labelImmature->setVisible(showImmature); - ui->labelImmatureText->setVisible(showImmature); -} - -void OverviewPage::setModel(WalletModel *model) -{ - this->model = model; - if(model && model->getOptionsModel()) - { - // Set up transaction list - filter = new TransactionFilterProxy(); - filter->setSourceModel(model->getTransactionTableModel()); - filter->setLimit(NUM_ITEMS); - filter->setDynamicSortFilter(true); - filter->setSortRole(Qt::EditRole); - filter->setShowInactive(false); - filter->sort(TransactionTableModel::Status, Qt::DescendingOrder); - - ui->listTransactions->setModel(filter); - ui->listTransactions->setModelColumn(TransactionTableModel::ToAddress); - - // Keep up to date with wallet - setBalance(model->getBalance(), model->getStake(), model->getUnconfirmedBalance(), model->getImmatureBalance()); - connect(model, SIGNAL(balanceChanged(qint64, qint64, qint64, qint64)), this, SLOT(setBalance(qint64, qint64, qint64, qint64))); - - connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit())); - } - - // update the display unit, to not use the default ("BTC") - updateDisplayUnit(); -} - -void OverviewPage::updateDisplayUnit() -{ - if(model && model->getOptionsModel()) - { - if(currentBalance != -1) - setBalance(currentBalance, model->getStake(), currentUnconfirmedBalance, currentImmatureBalance); - - // Update txdelegate->unit with the current unit - txdelegate->unit = model->getOptionsModel()->getDisplayUnit(); - - ui->listTransactions->update(); - } -} - -void OverviewPage::showOutOfSyncWarning(bool fShow) -{ - ui->labelWalletStatus->setVisible(fShow); - ui->labelTransactionsStatus->setVisible(fShow); -} +#include "overviewpage.h" +#include "ui_overviewpage.h" + +#include "walletmodel.h" +#include "bitcoinunits.h" +#include "optionsmodel.h" +#include "transactiontablemodel.h" +#include "transactionfilterproxy.h" +#include "guiutil.h" +#include "guiconstants.h" +#include "marketbrowser.h" + +#include +#include + +#define DECORATION_SIZE 64 +#define NUM_ITEMS 3 + +class TxViewDelegate : public QAbstractItemDelegate +{ + Q_OBJECT +public: + TxViewDelegate(): QAbstractItemDelegate(), unit(BitcoinUnits::BTC), unitUSD(BitcoinUnits::USD) + { + + } + + inline void paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index ) const + { + painter->save(); + + QIcon icon = qvariant_cast(index.data(Qt::DecorationRole)); + QRect mainRect = option.rect; + QRect decorationRect(mainRect.topLeft(), QSize(DECORATION_SIZE, DECORATION_SIZE)); + int xspace = DECORATION_SIZE + 8; + int ypad = 6; + int halfheight = (mainRect.height() - 2*ypad)/2; + QRect amountRect(mainRect.left() + xspace, mainRect.top()+ypad, mainRect.width() - xspace, halfheight); + QRect addressRect(mainRect.left() + xspace, mainRect.top()+ypad+halfheight, mainRect.width() - xspace, halfheight); + icon.paint(painter, decorationRect); + + QDateTime date = index.data(TransactionTableModel::DateRole).toDateTime(); + QString address = index.data(Qt::DisplayRole).toString(); + qint64 amount = index.data(TransactionTableModel::AmountRole).toLongLong(); + bool confirmed = index.data(TransactionTableModel::ConfirmedRole).toBool(); + QVariant value = index.data(Qt::ForegroundRole); + QColor foreground = option.palette.color(QPalette::Text); + if(qVariantCanConvert(value)) + { + foreground = qvariant_cast(value); + } + + painter->setPen(foreground); + painter->drawText(addressRect, Qt::AlignLeft|Qt::AlignVCenter, address); + + if(amount < 0) + { + foreground = COLOR_NEGATIVE; + } + else if(!confirmed) + { + foreground = COLOR_UNCONFIRMED; + } + else + { + foreground = option.palette.color(QPalette::Text); + } + painter->setPen(foreground); + QString amountText = BitcoinUnits::formatWithUnit(unit, amount, true); + if(!confirmed) + { + amountText = QString("[") + amountText + QString("]"); + } + painter->drawText(amountRect, Qt::AlignRight|Qt::AlignVCenter, amountText); + + painter->setPen(option.palette.color(QPalette::Text)); + painter->drawText(amountRect, Qt::AlignLeft|Qt::AlignVCenter, GUIUtil::dateTimeStr(date)); + + painter->restore(); + } + + inline QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const + { + return QSize(DECORATION_SIZE, DECORATION_SIZE); + } + + int unit; + int unitUSD; + +}; +#include "overviewpage.moc" + +OverviewPage::OverviewPage(QWidget *parent) : + QWidget(parent), + ui(new Ui::OverviewPage), + currentBalance(-1), + currentStake(0), + currentUnconfirmedBalance(-1), + currentImmatureBalance(-1), + txdelegate(new TxViewDelegate()), + filter(0) +{ + ui->setupUi(this); + + // Recent transactions + ui->listTransactions->setItemDelegate(txdelegate); + ui->listTransactions->setIconSize(QSize(DECORATION_SIZE, DECORATION_SIZE)); + ui->listTransactions->setMinimumHeight(NUM_ITEMS * (DECORATION_SIZE + 2)); + ui->listTransactions->setAttribute(Qt::WA_MacShowFocusRect, false); + + connect(ui->listTransactions, SIGNAL(clicked(QModelIndex)), this, SLOT(handleTransactionClicked(QModelIndex))); + + // init "out of sync" warning labels + ui->labelWalletStatus->setText("(" + tr("Out of Sync!") + ")"); + ui->labelTransactionsStatus->setText("(" + tr("Out of Sync!") + ")"); + + // start with displaying the "out of sync" warnings + showOutOfSyncWarning(true); +} + +void OverviewPage::handleTransactionClicked(const QModelIndex &index) +{ + if(filter) + emit transactionClicked(filter->mapToSource(index)); +} + +OverviewPage::~OverviewPage() +{ + delete ui; +} + +void OverviewPage::setBalance(qint64 balance, qint64 stake, qint64 unconfirmedBalance, qint64 immatureBalance) +{ + int unit = model->getOptionsModel()->getDisplayUnit(); + //int unitUSD = BitcoinUnits::USD; + int unitdBTC = BitcoinUnits::dBTC; + currentBalance = balance; + currentStake = stake; + currentUnconfirmedBalance = unconfirmedBalance; + currentImmatureBalance = immatureBalance; + ui->labelBalance->setText(BitcoinUnits::formatWithUnit(unit, balance)); + ui->labelStake->setText(BitcoinUnits::formatWithUnit(unit, stake)); + ui->labelUnconfirmed->setText(BitcoinUnits::formatWithUnit(unit, unconfirmedBalance)); + ui->labelImmature->setText(BitcoinUnits::formatWithUnit(unit, immatureBalance)); + ui->labelTotal->setText(BitcoinUnits::formatWithUnit(unit, balance + stake + unconfirmedBalance + immatureBalance)); + //ui->labelUSDTotal->setText(BitcoinUnits::formatWithUnit(unitUSD, dollarg.toDouble() * (balance + stake + unconfirmedBalance + immatureBalance))); + + QString total; + double dollarg2 = (dollarg.toDouble() * (balance + stake + unconfirmedBalance + immatureBalance) / 100000000); + total = QString::number(dollarg2, 'f', 2); + ui->labelUSDTotal->setText("$" + total + " USD"); + + //preço em Real + QString totalbrl; + double realarg2 = (realarg.toDouble() * (balance + stake + unconfirmedBalance + immatureBalance) / 100000000); + totalbrl = QString::number(realarg2, 'f', 2); + ui->labelBRLTotal->setText("R$" + totalbrl + " BRL"); + + ui->labelBTCTotal->setText(BitcoinUnits::formatWithUnit(unitdBTC, bitcoing.toDouble() * (balance + stake + unconfirmedBalance + immatureBalance))); + ui->labelTradeLink->setTextFormat(Qt::RichText); + ui->labelTradeLink->setTextInteractionFlags(Qt::TextBrowserInteraction); + ui->labelTradeLink->setOpenExternalLinks(true); + + // only show immature (newly mined) balance if it's non-zero, so as not to complicate things + // for the non-mining users + bool showImmature = immatureBalance != 0; + ui->labelImmature->setVisible(showImmature); + ui->labelImmatureText->setVisible(showImmature); +} + +void OverviewPage::setModel(WalletModel *model) +{ + this->model = model; + if(model && model->getOptionsModel()) + { + // Set up transaction list + filter = new TransactionFilterProxy(); + filter->setSourceModel(model->getTransactionTableModel()); + filter->setLimit(NUM_ITEMS); + filter->setDynamicSortFilter(true); + filter->setSortRole(Qt::EditRole); + filter->setShowInactive(false); + filter->sort(TransactionTableModel::Status, Qt::DescendingOrder); + + ui->listTransactions->setModel(filter); + ui->listTransactions->setModelColumn(TransactionTableModel::ToAddress); + + // Keep up to date with wallet + setBalance(model->getBalance(), model->getStake(), model->getUnconfirmedBalance(), model->getImmatureBalance()); + connect(model, SIGNAL(balanceChanged(qint64, qint64, qint64, qint64)), this, SLOT(setBalance(qint64, qint64, qint64, qint64))); + + connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit())); + } + + // update the display unit, to not use the default ("BTC") + updateDisplayUnit(); +} + +void OverviewPage::updateDisplayUnit() +{ + if(model && model->getOptionsModel()) + { + if(currentBalance != -1) + setBalance(currentBalance, model->getStake(), currentUnconfirmedBalance, currentImmatureBalance); + + // Update txdelegate->unit with the current unit + txdelegate->unit = model->getOptionsModel()->getDisplayUnit(); + + ui->listTransactions->update(); + } +} + +void OverviewPage::showOutOfSyncWarning(bool fShow) +{ + ui->labelWalletStatus->setVisible(fShow); + ui->labelTransactionsStatus->setVisible(fShow); +}