From b757f1d378f3b97175f206ba427a613816893a8d Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 3 Dec 2019 07:33:41 -0800 Subject: [PATCH] it compiles --- src/addresscombo.cpp | 4 +- src/balancestablemodel.cpp | 2 +- src/mainwindow.cpp | 44 ++++++++++++++++---- src/mainwindow.h | 1 + src/rpc.cpp | 6 +-- src/sendtab.cpp | 6 +-- src/senttxstore.cpp | 2 +- src/settings.cpp | 30 +++++++++++--- src/settings.h | 17 ++++++-- src/settings.ui | 82 ++++++++++++++++++++++++++++++++++++++ src/txtablemodel.cpp | 2 +- 11 files changed, 169 insertions(+), 27 deletions(-) diff --git a/src/addresscombo.cpp b/src/addresscombo.cpp index f7cbeee..9c50310 100644 --- a/src/addresscombo.cpp +++ b/src/addresscombo.cpp @@ -27,13 +27,13 @@ void AddressCombo::setCurrentText(const QString& text) { void AddressCombo::addItem(const QString& text, double bal) { QString txt = AddressBook::addLabelToAddress(text); if (bal > 0) - txt = txt % "(" % Settings::getZECDisplayFormat(bal) % ")"; + txt = txt % "(" % Settings::getDisplayFormat(bal) % ")"; QComboBox::addItem(txt); } void AddressCombo::insertItem(int index, const QString& text, double bal) { QString txt = AddressBook::addLabelToAddress(text) % - "(" % Settings::getZECDisplayFormat(bal) % ")"; + "(" % Settings::getDisplayFormat(bal) % ")"; QComboBox::insertItem(index, txt); } \ No newline at end of file diff --git a/src/balancestablemodel.cpp b/src/balancestablemodel.cpp index 4cd484e..2be4190 100644 --- a/src/balancestablemodel.cpp +++ b/src/balancestablemodel.cpp @@ -87,7 +87,7 @@ QVariant BalancesTableModel::data(const QModelIndex &index, int role) const if (role == Qt::DisplayRole) { switch (index.column()) { case 0: return AddressBook::addLabelToAddress(std::get<0>(modeldata->at(index.row()))); - case 1: return Settings::getZECDisplayFormat(std::get<1>(modeldata->at(index.row()))); + case 1: return Settings::getDisplayFormat(std::get<1>(modeldata->at(index.row()))); } } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index c32f44a..744fc11 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1,4 +1,5 @@ // Copyright 2019 The Hush Developers +// Released under the GPLv3 #include "mainwindow.h" #include "addressbook.h" #include "viewalladdresses.h" @@ -266,6 +267,15 @@ void MainWindow::setupSettingsModal() { Settings::getInstance()->setSaveZtxs(checked); }); + QString currency_name; + try { + currency_name = Settings::getInstance()->get_currency_name(); + } catch (...) { + currency_name = "USD"; + } + + this->slot_change_currency(currency_name); + // Setup clear button QObject::connect(settings.btnClearSaved, &QCheckBox::clicked, [=]() { if (QMessageBox::warning(this, "Clear saved history?", @@ -283,8 +293,16 @@ void MainWindow::setupSettingsModal() { QObject::connect(settings.comboBoxTheme, SIGNAL(currentIndexChanged(QString)), this, SLOT(slot_change_theme(QString))); QObject::connect(settings.comboBoxTheme, &QComboBox::currentTextChanged, [=] (QString theme_name) { this->slot_change_theme(theme_name); - // Tell the user to restart - QMessageBox::information(this, tr("Restart"), tr("Please restart SilentDragon to have the theme apply"), QMessageBox::Ok); + QMessageBox::information(this, tr("Theme Change"), tr("This change can take a few seconds."), QMessageBox::Ok); + }); + + // Get Currency Data + int currency_index = settings.comboBoxCurrency->findText(Settings::getInstance()->get_currency_name(), Qt::MatchExactly); + settings.comboBoxCurrency->setCurrentIndex(currency_index); + QObject::connect(settings.comboBoxCurrency, &QComboBox::currentTextChanged, [=] (QString currency_name) { + this->slot_change_currency(currency_name); + rpc->refresh(true); + QMessageBox::information(this, tr("Currency Change"), tr("This change can take a few seconds."), QMessageBox::Ok); }); // Save sent transactions @@ -1284,18 +1302,30 @@ void MainWindow::updateLabels() { updateLabelsAutoComplete(); } +void MainWindow::slot_change_currency(const QString& currency_name) +{ + Settings::getInstance()->set_currency_name(currency_name); + + // Include currency + QString saved_currency_name; + try { + saved_currency_name = Settings::getInstance()->get_currency_name(); + } catch (const std::exception& e) { + qDebug() << QString("Ignoring currency change Exception! : ") << e.what(); + saved_currency_name = "USD"; + } +} + void MainWindow::slot_change_theme(const QString& theme_name) { Settings::getInstance()->set_theme_name(theme_name); // Include css QString saved_theme_name; - try - { + try { saved_theme_name = Settings::getInstance()->get_theme_name(); - } - catch (...) - { + } catch (const std::exception& e) { + qDebug() << QString("Ignoring theme change Exception! : ") << e.what(); saved_theme_name = "default"; } diff --git a/src/mainwindow.h b/src/mainwindow.h index 5228629..3dd792a 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -84,6 +84,7 @@ private: void setupMarketTab(); void slot_change_theme(const QString& themeName); + void slot_change_currency(const QString& currencyName); void setupTurnstileDialog(); void setupSettingsModal(); void setupStatusBar(); diff --git a/src/rpc.cpp b/src/rpc.cpp index 2e654fd..cbea74c 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -801,9 +801,9 @@ void RPC::refreshBalances() { AppDataModel::getInstance()->setBalances(balT, balZ); - ui->balSheilded ->setText(Settings::getZECDisplayFormat(balZ)); - ui->balTransparent->setText(Settings::getZECDisplayFormat(balT)); - ui->balTotal ->setText(Settings::getZECDisplayFormat(balTotal)); + ui->balSheilded ->setText(Settings::getDisplayFormat(balZ)); + ui->balTransparent->setText(Settings::getDisplayFormat(balT)); + ui->balTotal ->setText(Settings::getDisplayFormat(balTotal)); ui->balSheilded ->setToolTip(Settings::getUSDFormat(balZ)); ui->balTransparent->setToolTip(Settings::getUSDFormat(balT)); diff --git a/src/sendtab.cpp b/src/sendtab.cpp index 450d34f..4c58192 100644 --- a/src/sendtab.cpp +++ b/src/sendtab.cpp @@ -196,7 +196,7 @@ void MainWindow::updateFromCombo() { void MainWindow::inputComboTextChanged(int index) { auto addr = ui->inputsCombo->itemText(index); auto bal = rpc->getAllBalances()->value(addr); - auto balFmt = Settings::getZECDisplayFormat(bal); + auto balFmt = Settings::getDisplayFormat(bal); ui->sendAddressBalance->setText(balFmt); ui->sendAddressBalanceUSD->setText(Settings::getUSDFormat(bal)); @@ -598,7 +598,7 @@ bool MainWindow::confirmTx(Tx tx) { // Amount (HUSH) auto Amt = new QLabel(confirm.sendToAddrs); Amt->setObjectName(QString("Amt") % QString::number(i + 1)); - Amt->setText(Settings::getZECDisplayFormat(toAddr.amount)); + Amt->setText(Settings::getDisplayFormat(toAddr.amount)); Amt->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter); confirm.gridLayout->addWidget(Amt, row, 1, 1, 1); totalSpending += toAddr.amount; @@ -648,7 +648,7 @@ bool MainWindow::confirmTx(Tx tx) { minerFee->setObjectName(QStringLiteral("minerFee")); minerFee->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); confirm.gridLayout->addWidget(minerFee, row, 1, 1, 1); - minerFee->setText(Settings::getZECDisplayFormat(tx.fee)); + minerFee->setText(Settings::getDisplayFormat(tx.fee)); totalSpending += tx.fee; auto minerFeeUSD = new QLabel(confirm.sendToAddrs); diff --git a/src/senttxstore.cpp b/src/senttxstore.cpp index 22a6828..a25f761 100644 --- a/src/senttxstore.cpp +++ b/src/senttxstore.cpp @@ -90,7 +90,7 @@ void SentTxStore::addToSentTx(Tx tx, QString txid) { } else { // Concatenate all the toAddresses for (auto a : tx.toAddrs) { - toAddresses += a.addr % "(" % Settings::getZECDisplayFormat(a.amount) % ") "; + toAddresses += a.addr % "(" % Settings::getDisplayFormat(a.amount) % ") "; } } diff --git a/src/settings.cpp b/src/settings.cpp index d35e5dd..18f24b0 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1,4 +1,5 @@ // Copyright 2019 The Hush developers +// Released under the GPLv3 #include "mainwindow.h" #include "settings.h" @@ -160,6 +161,15 @@ double Settings::getZECPrice() { return zecPrice; } +double Settings::get_price(std::string currency) { + auto search = prices.find(currency); + if (search != prices.end()) { + return search->second; + } else { + return -1.0; + } +} + unsigned int Settings::getBTCPrice() { // in satoshis return btcPrice; @@ -235,7 +245,7 @@ QString Settings::getDecimalString(double amt) { return f; } -QString Settings::getZECDisplayFormat(double bal) { +QString Settings::getDisplayFormat(double bal) { // This is idiotic. Why doesn't QString have a way to do this? return getDecimalString(bal) % " " % Settings::getTokenName(); } @@ -243,12 +253,12 @@ QString Settings::getZECDisplayFormat(double bal) { QString Settings::getZECUSDDisplayFormat(double bal) { auto usdFormat = getUSDFormat(bal); if (!usdFormat.isEmpty()) - return getZECDisplayFormat(bal) % " (" % getUSDFormat(bal) % ")"; + return getDisplayFormat(bal) % " (" % getUSDFormat(bal) % ")"; else - return getZECDisplayFormat(bal); + return getDisplayFormat(bal); } -const QString Settings::txidStatusMessage = QString(QObject::tr("Tx submitted (right click to copy) txid:")); +const QString Settings::txidStatusMessage = QString(QObject::tr("Transaction submitted (right click to copy) txid:")); QString Settings::getTokenName() { if (Settings::getInstance()->isTestnet()) { @@ -258,6 +268,7 @@ QString Settings::getTokenName() { } } +//TODO: this isn't used for donations QString Settings::getDonationAddr() { if (Settings::getInstance()->isTestnet()) { return "ztestsaplingXXX"; @@ -278,6 +289,15 @@ bool Settings::addToZcashConf(QString confLocation, QString line) { return true; } +QString Settings::get_currency_name() { + // Load from the QT Settings. + return QSettings().value("options/currency_name", false).toString(); +} + +void Settings::set_currency_name(QString currency_name) { + QSettings().setValue("options/currency_name", currency_name); +} + bool Settings::removeFromZcashConf(QString confLocation, QString option) { if (confLocation.isEmpty()) return false; @@ -337,7 +357,7 @@ bool Settings::isValidAddress(QString addr) { // Get a pretty string representation of this Payment URI QString Settings::paymentURIPretty(PaymentURI uri) { - return QString() + "Payment Request\n" + "Pay: " + uri.addr + "\nAmount: " + getZECDisplayFormat(uri.amt.toDouble()) + return QString() + "Payment Request\n" + "Pay: " + uri.addr + "\nAmount: " + getDisplayFormat(uri.amt.toDouble()) + "\nMemo:" + QUrl::fromPercentEncoding(uri.memo.toUtf8()); } diff --git a/src/settings.h b/src/settings.h index 9756896..48e05bf 100644 --- a/src/settings.h +++ b/src/settings.h @@ -85,13 +85,19 @@ public: QString get_theme_name(); void set_theme_name(QString theme_name); + QString get_currency_name(); + void set_currency_name(QString currency_name); + void setUsingZcashConf(QString confLocation); const QString& getZcashdConfLocation() { return _confLocation; } - void setZECPrice(double p) { zecPrice = p; } - void setBTCPrice(unsigned int p) { btcPrice = p; } + void setZECPrice(double p) { zecPrice = p; } + void set_fiat_price(double p) { fiat_price = p; } + void setBTCPrice(unsigned int p) { btcPrice = p; } double getZECPrice(); + double get_fiat_price(); unsigned int getBTCPrice(); + double get_price(std::string currency); void setPeers(int peers); int getPeers(); @@ -110,7 +116,7 @@ public: static QString getDecimalString(double amt); static QString getUSDFormat(double bal); - static QString getZECDisplayFormat(double bal); + static QString getDisplayFormat(double bal); static QString getZECUSDDisplayFormat(double bal); static QString getTokenName(); @@ -152,7 +158,10 @@ private: int _peerConnections = 0; double zecPrice = 0.0; - unsigned int btcPrice = 0.0; + double fiat_price = 0.0; + unsigned int btcPrice = 0; + std::map prices; + }; #endif // SETTINGS_H diff --git a/src/settings.ui b/src/settings.ui index 896209e..5c2c362 100644 --- a/src/settings.ui +++ b/src/settings.ui @@ -161,6 +161,88 @@ + + + + + + 0 + 0 + + + + Local Currency + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + 80 + 150 + 80 + 25 + + + + + 0 + 0 + + + + + AUD + + + + + BTC + + + + + CAD + + + + + CHF + + + + + CNY + + + + + EUR + + + + + GBP + + + + + INR + + + + + USD + + + + + diff --git a/src/txtablemodel.cpp b/src/txtablemodel.cpp index a13b31e..e7e4f96 100644 --- a/src/txtablemodel.cpp +++ b/src/txtablemodel.cpp @@ -132,7 +132,7 @@ void TxTableModel::updateAllData() { return addr; } case 2: return QDateTime::fromMSecsSinceEpoch(modeldata->at(index.row()).datetime * (qint64)1000).toLocalTime().toString(); - case 3: return Settings::getZECDisplayFormat(modeldata->at(index.row()).amount); + case 3: return Settings::getDisplayFormat(modeldata->at(index.row()).amount); } }