add the option to choose between usd,eur,btc as currency for mainwindow Pricecheck
This commit is contained in:
@@ -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<json::string_t>()));
|
||||
ui->Vendor->setText(QString::fromStdString(reply["vendor"].get<json::string_t>()));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// See if recurring payments needs anything
|
||||
Recurring::getInstance()->processPending(main);
|
||||
|
||||
@@ -659,14 +664,28 @@ void Controller::refreshZECPrice() {
|
||||
const json& item = parsed.get<json::object_t>();
|
||||
const json& hush = item["hush"].get<json::object_t>();
|
||||
|
||||
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<json::string_t>());
|
||||
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<json::string_t>());
|
||||
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<json::string_t>());
|
||||
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);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
272
src/settings.ui
272
src/settings.ui
@@ -26,7 +26,7 @@
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
@@ -85,108 +85,188 @@
|
||||
<attribute name="title">
|
||||
<string>Options</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="6" column="1">
|
||||
<widget class="QComboBox" name="comboBoxTheme">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>default</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>blue</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>light</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>dark</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
<widget class="QComboBox" name="comboBoxTheme">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>80</x>
|
||||
<y>110</y>
|
||||
<width>80</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>default</string>
|
||||
</property>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="chkFetchPrices">
|
||||
<property name="text">
|
||||
<string>Fetch hush / USD prices</string>
|
||||
</property>
|
||||
</widget>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>blue</string>
|
||||
</property>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="chkCheckUpdates">
|
||||
<property name="text">
|
||||
<string>Check github for updates at startup</string>
|
||||
</property>
|
||||
</widget>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>light</string>
|
||||
</property>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="text">
|
||||
<string>Connect to github on startup to check for updates</string>
|
||||
</property>
|
||||
</widget>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>dark</string>
|
||||
</property>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="label_20">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Theme</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QCheckBox" name="chkFetchPrices">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>9</x>
|
||||
<y>61</y>
|
||||
<width>184</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Fetch hush / USD prices</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QCheckBox" name="chkCheckUpdates">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>9</x>
|
||||
<y>9</y>
|
||||
<width>267</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Check github for updates at startup</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>9</x>
|
||||
<y>38</y>
|
||||
<width>340</width>
|
||||
<height>17</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Connect to github on startup to check for updates</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_20">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>9</x>
|
||||
<y>113</y>
|
||||
<width>47</width>
|
||||
<height>17</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Theme</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="Line" name="line_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>180</y>
|
||||
<width>500</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_10">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>9</x>
|
||||
<y>90</y>
|
||||
<width>297</width>
|
||||
<height>17</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Connect to the internet to fetch hush prices</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_21">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>150</y>
|
||||
<width>61</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Currency</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QComboBox" name="comboBoxCurrency">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>80</x>
|
||||
<y>150</y>
|
||||
<width>80</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>USD</string>
|
||||
</property>
|
||||
</item>
|
||||
<item row="8" column="0" colspan="2">
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>EUR</string>
|
||||
</property>
|
||||
</item>
|
||||
<item row="7" column="0" colspan="2">
|
||||
<widget class="Line" name="line_2">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>BTC</string>
|
||||
</property>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QLabel" name="label_10">
|
||||
<property name="text">
|
||||
<string>Connect to the internet to fetch hush prices</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_3">
|
||||
<attribute name="title">
|
||||
|
||||
Reference in New Issue
Block a user