From b0c12948c71bbee11b080c9c5c616956e7d84b9d Mon Sep 17 00:00:00 2001 From: Denio Date: Sun, 17 Nov 2019 22:41:37 +0100 Subject: [PATCH] add the option to choose between usd,eur,btc as currency for mainwindow Pricecheck --- src/controller.cpp | 39 +++++-- src/mainwindow.cpp | 61 ++++++++++ src/mainwindow.h | 4 +- src/settings.cpp | 19 ++++ src/settings.h | 10 ++ src/settings.ui | 272 +++++++++++++++++++++++++++++---------------- 6 files changed, 299 insertions(+), 106 deletions(-) diff --git a/src/controller.cpp b/src/controller.cpp index ffc6520..b2f59e3 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -58,7 +58,6 @@ Controller::~Controller() { delete zrpc; } - // Called when a connection to hushd is available. void Controller::setConnection(Connection* c) { if (c == nullptr) return; @@ -80,7 +79,6 @@ void Controller::setConnection(Connection* c) { refresh(true); } - // Build the RPC JSON Parameters for this tx void Controller::fillTxJsonParams(json& allRecepients, Tx tx) { Q_ASSERT(allRecepients.is_array()); @@ -100,7 +98,6 @@ void Controller::fillTxJsonParams(json& allRecepients, Tx tx) { } } - void Controller::noConnection() { QIcon i = QApplication::style()->standardIcon(QStyle::SP_MessageBoxCritical); main->statusIcon->setPixmap(i.pixmap(16, 16)); @@ -166,7 +163,18 @@ void Controller::getInfoThenRefresh(bool force) { auto tooltip = Settings::getInstance()->getSettings().server + "\n" + QString::fromStdString(reply.dump()); QIcon i(":/icons/res/connected.gif"); main->statusLabel->setText(chainName + "(" + QString::number(curBlock) + ")"); + + // use currency ComboBox as input + + if (Settings::getInstance()->get_currency_name() == "USD") { main->statusLabel->setText(" HUSH/USD=$" + QString::number( (double) Settings::getInstance()->getZECPrice() )); + } else if (Settings::getInstance()->get_currency_name() == "EUR") { + main->statusLabel->setText(" HUSH/EUR=€" + QString::number( (double) Settings::getInstance()->getEURPrice() )); + } else if (Settings::getInstance()->get_currency_name() == "BTC") { + main->statusLabel->setText(" HUSH/BTC=BTC" + QString::number( (double) Settings::getInstance()->getBTCPrice() )); + } else { + main->statusLabel->setText(" Fehler=KACKE" + QString::number( (double) Settings::getInstance()->getEURPrice() )); + } main->statusLabel->setToolTip(tooltip); main->statusIcon->setPixmap(i.pixmap(16, 16)); main->statusIcon->setToolTip(tooltip); @@ -176,10 +184,7 @@ void Controller::getInfoThenRefresh(bool force) { Settings::getInstance()->sethushdVersion(version); ui->Version->setText(QString::fromStdString(reply["version"].get())); ui->Vendor->setText(QString::fromStdString(reply["vendor"].get())); - - - - + // See if recurring payments needs anything Recurring::getInstance()->processPending(main); @@ -659,14 +664,28 @@ void Controller::refreshZECPrice() { const json& item = parsed.get(); const json& hush = item["hush"].get(); - if (hush["usd"] >= 0) { + if (hush["usd"] >= 0) { qDebug() << "Found hush key in price json"; // TODO: support BTC/EUR prices as well //QString price = QString::fromStdString(hush["usd"].get()); qDebug() << "HUSH = $" << QString::number((double)hush["usd"]); Settings::getInstance()->setZECPrice( hush["usd"] ); - return; } + if (hush["eur"] >= 0) + { + // TODO: support BTC/EUR prices as well + //QString price = QString::fromStdString(hush["usd"].get()); + qDebug() << "HUSH = €" << QString::number((double)hush["eur"]); + Settings::getInstance()->setEURPrice(hush["eur"]); + } + if (hush["btc"] >= 0) + { + // TODO: support BTC/EUR prices as well + //QString price = QString::fromStdString(hush["usd"].get()); + qDebug() << "HUSH = BTC" << QString::number((double)hush["btc"]); + Settings::getInstance()->setBTCPrice( hush["btc"]); + } + return; } catch (const std::exception& e) { // If anything at all goes wrong, just set the price to 0 and move on. qDebug() << QString("Caught something nasty: ") << e.what(); @@ -674,6 +693,8 @@ void Controller::refreshZECPrice() { // If nothing, then set the price to 0; Settings::getInstance()->setZECPrice(0); + Settings::getInstance()->setEURPrice(0); + Settings::getInstance()->setBTCPrice(0); }); } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 862d7e1..a1f422d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -36,6 +36,7 @@ MainWindow::MainWindow(QWidget *parent) : this->slot_change_theme(theme_name); + ui->setupUi(this); logger = new Logger(this, QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)).filePath("silentdragonlite-wallet.log")); @@ -393,6 +394,21 @@ void MainWindow::setupSettingsModal() { Ui_Settings settings; settings.setupUi(&settingsDialog); Settings::saveRestore(&settingsDialog); + + // Include currencies + + QString currency_name; + try + { + currency_name = Settings::getInstance()->get_currency_name(); + } + catch (...) + { + currency_name = "USD"; + } + + this->slot_change_currency(currency_name); + // Setup theme combo int theme_index = settings.comboBoxTheme->findText(Settings::getInstance()->get_theme_name(), Qt::MatchExactly); @@ -404,6 +420,19 @@ void MainWindow::setupSettingsModal() { QMessageBox::information(this, tr("Restart"), tr("Please restart Silentdragonlite to have the theme apply"), 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); + + + }); + // Check for updates settings.chkCheckUpdates->setChecked(Settings::getInstance()->getCheckForUpdates()); @@ -1235,9 +1264,41 @@ 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 (...) + { + 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; diff --git a/src/mainwindow.h b/src/mainwindow.h index 0af7ad3..08aac98 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -78,7 +78,9 @@ public: public slots: void slot_change_theme(const QString& themeName); - + void slot_change_currency(const QString& currencyName); + + private: void closeEvent(QCloseEvent* event); diff --git a/src/settings.cpp b/src/settings.cpp index e21eddc..17689c9 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -105,6 +105,12 @@ bool Settings::isSaplingActive() { double Settings::getZECPrice() { return ZECPrice; } +double Settings::getEURPrice() { + return EURPrice; +} +double Settings::getBTCPrice() { + return BTCPrice; +} bool Settings::getCheckForUpdates() { return QSettings().value("options/allowcheckupdates", true).toBool(); @@ -122,6 +128,19 @@ void Settings::setAllowFetchPrices(bool allow) { QSettings().setValue("options/allowfetchprices", allow); } +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); + + + +} + + QString Settings::get_theme_name() { // Load from the QT Settings. return QSettings().value("options/theme_name", false).toString(); diff --git a/src/settings.h b/src/settings.h index b4253d2..c9c9a4d 100644 --- a/src/settings.h +++ b/src/settings.h @@ -63,10 +63,18 @@ public: QString get_theme_name(); void set_theme_name(QString theme_name); + QString get_currency_name(); + void set_currency_name(QString currency_name); + + bool isSaplingActive(); void setZECPrice(double p) { ZECPrice = p; } + void setEURPrice(double p) { EURPrice = p; } + void setBTCPrice(double p) { BTCPrice = p; } double getZECPrice(); + double getEURPrice(); + double getBTCPrice(); // Static stuff static const QString txidStatusMessage; @@ -119,6 +127,8 @@ private: bool _headless = false; double ZECPrice = 0.0; + double BTCPrice = 0.0; + double EURPrice = 0.0; }; diff --git a/src/settings.ui b/src/settings.ui index 8a749da..da611f4 100644 --- a/src/settings.ui +++ b/src/settings.ui @@ -26,7 +26,7 @@ - 0 + 1 @@ -85,108 +85,188 @@ Options - - - - - - 0 - 0 - - - - - default - - - - - blue - - - - - light - - - - - dark - - - - - - - - Fetch hush / USD prices - - + + + + 80 + 110 + 80 + 25 + + + + + 0 + 0 + + + + + default + - - - - Check github for updates at startup - - + + + blue + - - - - Connect to github on startup to check for updates - - + + + light + - - - - - 0 - 0 - - - - Theme - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + dark + - - - - Qt::Vertical - - - - 20 - 40 - - - + + + + + 9 + 61 + 184 + 23 + + + + Fetch hush / USD prices + + + + + + 9 + 9 + 267 + 23 + + + + Check github for updates at startup + + + + + + 9 + 38 + 340 + 17 + + + + Connect to github on startup to check for updates + + + + + + 9 + 113 + 47 + 17 + + + + + 0 + 0 + + + + Theme + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 10 + 180 + 500 + 16 + + + + + 0 + 0 + + + + Qt::Horizontal + + + + + + 9 + 90 + 297 + 17 + + + + Connect to the internet to fetch hush prices + + + + + + 10 + 150 + 61 + 20 + + + + + 0 + 0 + + + + Currency + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 80 + 150 + 80 + 25 + + + + + 0 + 0 + + + + + USD + - - - - - 0 - 0 - - - - Qt::Horizontal - - + + + EUR + - - - - Connect to the internet to fetch hush prices - - + + + BTC + - +