diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index e4944a2..b3d9189 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -116,6 +116,9 @@ MainWindow::MainWindow(WindowManager *windowManager, Wallet *wallet, QWidget *pa this->onWalletOpened(); + connect(&appData()->prices, &Prices::fiatPricesUpdated, this, &MainWindow::updateBalance); + connect(&appData()->prices, &Prices::cryptoPricesUpdated, this, &MainWindow::updateBalance); + #ifdef DONATE_BEG this->donationNag(); #endif @@ -581,6 +584,10 @@ void MainWindow::onWalletOpened() { } } +void MainWindow::updateBalance() { + this->onBalanceUpdated(m_wallet->balance(), m_wallet->unlockedBalance()); +} + void MainWindow::onBalanceUpdated(quint64 balance, quint64 spendable) { bool hide = conf()->get(Config::hideBalance).toBool(); int displaySetting = conf()->get(Config::balanceDisplay).toInt(); @@ -601,6 +608,12 @@ void MainWindow::onBalanceUpdated(quint64 balance, quint64 spendable) { } } + if (conf()->get(Config::balanceShowFiat).toBool()) { + QString fiatCurrency = conf()->get(Config::preferredFiatCurrency).toString(); + double balanceFiatAmount = appData()->prices.convert("XMR", fiatCurrency, balance / constants::cdiv); + balance_str += QString(" (%1)").arg(Utils::amountToCurrencyString(balanceFiatAmount, fiatCurrency)); + } + m_statusLabelBalance->setToolTip("Click for details"); m_statusLabelBalance->setText(balance_str); } diff --git a/src/MainWindow.h b/src/MainWindow.h index bab68a3..9e15b0c 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -131,6 +131,7 @@ private slots: void onTxPoolBacklog(const QVector &backlog, quint64 originalFeeLevel, quint64 automaticFeeLevel); // libwalletqt + void updateBalance(); void onBalanceUpdated(quint64 balance, quint64 spendable); void onSyncStatus(quint64 height, quint64 target, bool daemonSync); void onWalletOpened(); diff --git a/src/SettingsDialog.cpp b/src/SettingsDialog.cpp index 3ad8c75..f84058e 100644 --- a/src/SettingsDialog.cpp +++ b/src/SettingsDialog.cpp @@ -131,10 +131,18 @@ void Settings::setupAppearanceTab() { emit updateBalance(); }); + // [Balance show fiat] + ui->checkBox_balanceShowFiat->setChecked(conf()->get(Config::balanceShowFiat).toBool()); + connect(ui->checkBox_balanceShowFiat, &QCheckBox::toggled, [this](bool toggled){ + conf()->set(Config::balanceShowFiat, toggled); + emit updateBalance(); + }); + // [Preferred fiat currency] QStringList availableFiatCurrencies = appData()->prices.rates.keys(); for (const auto ¤cy : availableFiatCurrencies) { ui->comboBox_fiatCurrency->addItem(currency); + emit updateBalance(); } QStringList fiatCurrencies; @@ -151,6 +159,7 @@ void Settings::setupAppearanceTab() { QString selection = ui->comboBox_fiatCurrency->itemText(index); conf()->set(Config::preferredFiatCurrency, selection); emit preferredFiatCurrencyChanged(selection); + emit updateBalance(); }); } diff --git a/src/SettingsDialog.ui b/src/SettingsDialog.ui index 578dfa7..df2c05a 100644 --- a/src/SettingsDialog.ui +++ b/src/SettingsDialog.ui @@ -129,17 +129,17 @@ - + Fiat currency: - + - + Qt::Vertical @@ -152,6 +152,13 @@ + + + + Show fiat balance in statusbar + + + diff --git a/src/utils/Utils.cpp b/src/utils/Utils.cpp index ed26b42..dc22888 100644 --- a/src/utils/Utils.cpp +++ b/src/utils/Utils.cpp @@ -439,6 +439,7 @@ QLocale getCurrencyLocale(const QString ¤cyCode) { for (const auto& locale_: allLocales) { if (locale_.currencySymbol(QLocale::CurrencyIsoCode) == currencyCode) { locale = locale_; + break; } } localeCache[currencyCode] = locale; diff --git a/src/utils/config.cpp b/src/utils/config.cpp index a17addf..e204807 100644 --- a/src/utils/config.cpp +++ b/src/utils/config.cpp @@ -80,6 +80,7 @@ static const QHash configStrings = { {Config::dateFormat, {QS("dateFormat"), "yyyy-MM-dd"}}, {Config::timeFormat, {QS("timeFormat"), "HH:mm"}}, {Config::balanceDisplay, {QS("balanceDisplay"), Config::BalanceDisplay::spendablePlusUnconfirmed}}, + {Config::balanceShowFiat, {QS("balanceShowFiat"), false}}, {Config::inactivityLockEnabled, {QS("inactivityLockEnabled"), false}}, {Config::inactivityLockTimeout, {QS("inactivityLockTimeout"), 10}}, {Config::lockOnMinimize, {QS("lockOnMinimize"), false}}, diff --git a/src/utils/config.h b/src/utils/config.h index 215ec6b..b83b4f4 100644 --- a/src/utils/config.h +++ b/src/utils/config.h @@ -80,6 +80,7 @@ public: dateFormat, timeFormat, balanceDisplay, + balanceShowFiat, preferredFiatCurrency, // Network -> Proxy diff --git a/src/widgets/TickerWidget.cpp b/src/widgets/TickerWidget.cpp index cecd7e9..86dfe58 100644 --- a/src/widgets/TickerWidget.cpp +++ b/src/widgets/TickerWidget.cpp @@ -67,7 +67,7 @@ BalanceTickerWidget::BalanceTickerWidget(QWidget *parent, Wallet *wallet, bool t connect(m_wallet, &Wallet::balanceUpdated, this, &BalanceTickerWidget::updateDisplay); connect(&appData()->prices, &Prices::fiatPricesUpdated, this, &BalanceTickerWidget::updateDisplay); - connect(&appData()->prices, &Prices::fiatPricesUpdated, this, &BalanceTickerWidget::updateDisplay); + connect(&appData()->prices, &Prices::cryptoPricesUpdated, this, &BalanceTickerWidget::updateDisplay); } void BalanceTickerWidget::updateDisplay() {