Browse Source

it compiles

deadstrip
Jonathan "Duke" Leto 5 years ago
parent
commit
b757f1d378
  1. 4
      src/addresscombo.cpp
  2. 2
      src/balancestablemodel.cpp
  3. 44
      src/mainwindow.cpp
  4. 1
      src/mainwindow.h
  5. 6
      src/rpc.cpp
  6. 6
      src/sendtab.cpp
  7. 2
      src/senttxstore.cpp
  8. 30
      src/settings.cpp
  9. 17
      src/settings.h
  10. 82
      src/settings.ui
  11. 2
      src/txtablemodel.cpp

4
src/addresscombo.cpp

@ -27,13 +27,13 @@ void AddressCombo::setCurrentText(const QString& text) {
void AddressCombo::addItem(const QString& text, double bal) { void AddressCombo::addItem(const QString& text, double bal) {
QString txt = AddressBook::addLabelToAddress(text); QString txt = AddressBook::addLabelToAddress(text);
if (bal > 0) if (bal > 0)
txt = txt % "(" % Settings::getZECDisplayFormat(bal) % ")"; txt = txt % "(" % Settings::getDisplayFormat(bal) % ")";
QComboBox::addItem(txt); QComboBox::addItem(txt);
} }
void AddressCombo::insertItem(int index, const QString& text, double bal) { void AddressCombo::insertItem(int index, const QString& text, double bal) {
QString txt = AddressBook::addLabelToAddress(text) % QString txt = AddressBook::addLabelToAddress(text) %
"(" % Settings::getZECDisplayFormat(bal) % ")"; "(" % Settings::getDisplayFormat(bal) % ")";
QComboBox::insertItem(index, txt); QComboBox::insertItem(index, txt);
} }

2
src/balancestablemodel.cpp

@ -87,7 +87,7 @@ QVariant BalancesTableModel::data(const QModelIndex &index, int role) const
if (role == Qt::DisplayRole) { if (role == Qt::DisplayRole) {
switch (index.column()) { switch (index.column()) {
case 0: return AddressBook::addLabelToAddress(std::get<0>(modeldata->at(index.row()))); 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())));
} }
} }

44
src/mainwindow.cpp

@ -1,4 +1,5 @@
// Copyright 2019 The Hush Developers // Copyright 2019 The Hush Developers
// Released under the GPLv3
#include "mainwindow.h" #include "mainwindow.h"
#include "addressbook.h" #include "addressbook.h"
#include "viewalladdresses.h" #include "viewalladdresses.h"
@ -266,6 +267,15 @@ void MainWindow::setupSettingsModal() {
Settings::getInstance()->setSaveZtxs(checked); 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 // Setup clear button
QObject::connect(settings.btnClearSaved, &QCheckBox::clicked, [=]() { QObject::connect(settings.btnClearSaved, &QCheckBox::clicked, [=]() {
if (QMessageBox::warning(this, "Clear saved history?", 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, SIGNAL(currentIndexChanged(QString)), this, SLOT(slot_change_theme(QString)));
QObject::connect(settings.comboBoxTheme, &QComboBox::currentTextChanged, [=] (QString theme_name) { QObject::connect(settings.comboBoxTheme, &QComboBox::currentTextChanged, [=] (QString theme_name) {
this->slot_change_theme(theme_name); this->slot_change_theme(theme_name);
// Tell the user to restart QMessageBox::information(this, tr("Theme Change"), tr("This change can take a few seconds."), QMessageBox::Ok);
QMessageBox::information(this, tr("Restart"), tr("Please restart SilentDragon 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);
rpc->refresh(true);
QMessageBox::information(this, tr("Currency Change"), tr("This change can take a few seconds."), QMessageBox::Ok);
}); });
// Save sent transactions // Save sent transactions
@ -1284,18 +1302,30 @@ void MainWindow::updateLabels() {
updateLabelsAutoComplete(); 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) void MainWindow::slot_change_theme(const QString& theme_name)
{ {
Settings::getInstance()->set_theme_name(theme_name); Settings::getInstance()->set_theme_name(theme_name);
// Include css // Include css
QString saved_theme_name; QString saved_theme_name;
try try {
{
saved_theme_name = Settings::getInstance()->get_theme_name(); saved_theme_name = Settings::getInstance()->get_theme_name();
} } catch (const std::exception& e) {
catch (...) qDebug() << QString("Ignoring theme change Exception! : ") << e.what();
{
saved_theme_name = "default"; saved_theme_name = "default";
} }

1
src/mainwindow.h

@ -84,6 +84,7 @@ private:
void setupMarketTab(); void setupMarketTab();
void slot_change_theme(const QString& themeName); void slot_change_theme(const QString& themeName);
void slot_change_currency(const QString& currencyName);
void setupTurnstileDialog(); void setupTurnstileDialog();
void setupSettingsModal(); void setupSettingsModal();
void setupStatusBar(); void setupStatusBar();

6
src/rpc.cpp

@ -801,9 +801,9 @@ void RPC::refreshBalances() {
AppDataModel::getInstance()->setBalances(balT, balZ); AppDataModel::getInstance()->setBalances(balT, balZ);
ui->balSheilded ->setText(Settings::getZECDisplayFormat(balZ)); ui->balSheilded ->setText(Settings::getDisplayFormat(balZ));
ui->balTransparent->setText(Settings::getZECDisplayFormat(balT)); ui->balTransparent->setText(Settings::getDisplayFormat(balT));
ui->balTotal ->setText(Settings::getZECDisplayFormat(balTotal)); ui->balTotal ->setText(Settings::getDisplayFormat(balTotal));
ui->balSheilded ->setToolTip(Settings::getUSDFormat(balZ)); ui->balSheilded ->setToolTip(Settings::getUSDFormat(balZ));
ui->balTransparent->setToolTip(Settings::getUSDFormat(balT)); ui->balTransparent->setToolTip(Settings::getUSDFormat(balT));

6
src/sendtab.cpp

@ -196,7 +196,7 @@ void MainWindow::updateFromCombo() {
void MainWindow::inputComboTextChanged(int index) { void MainWindow::inputComboTextChanged(int index) {
auto addr = ui->inputsCombo->itemText(index); auto addr = ui->inputsCombo->itemText(index);
auto bal = rpc->getAllBalances()->value(addr); auto bal = rpc->getAllBalances()->value(addr);
auto balFmt = Settings::getZECDisplayFormat(bal); auto balFmt = Settings::getDisplayFormat(bal);
ui->sendAddressBalance->setText(balFmt); ui->sendAddressBalance->setText(balFmt);
ui->sendAddressBalanceUSD->setText(Settings::getUSDFormat(bal)); ui->sendAddressBalanceUSD->setText(Settings::getUSDFormat(bal));
@ -598,7 +598,7 @@ bool MainWindow::confirmTx(Tx tx) {
// Amount (HUSH) // Amount (HUSH)
auto Amt = new QLabel(confirm.sendToAddrs); auto Amt = new QLabel(confirm.sendToAddrs);
Amt->setObjectName(QString("Amt") % QString::number(i + 1)); 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); Amt->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
confirm.gridLayout->addWidget(Amt, row, 1, 1, 1); confirm.gridLayout->addWidget(Amt, row, 1, 1, 1);
totalSpending += toAddr.amount; totalSpending += toAddr.amount;
@ -648,7 +648,7 @@ bool MainWindow::confirmTx(Tx tx) {
minerFee->setObjectName(QStringLiteral("minerFee")); minerFee->setObjectName(QStringLiteral("minerFee"));
minerFee->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); minerFee->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
confirm.gridLayout->addWidget(minerFee, row, 1, 1, 1); confirm.gridLayout->addWidget(minerFee, row, 1, 1, 1);
minerFee->setText(Settings::getZECDisplayFormat(tx.fee)); minerFee->setText(Settings::getDisplayFormat(tx.fee));
totalSpending += tx.fee; totalSpending += tx.fee;
auto minerFeeUSD = new QLabel(confirm.sendToAddrs); auto minerFeeUSD = new QLabel(confirm.sendToAddrs);

2
src/senttxstore.cpp

@ -90,7 +90,7 @@ void SentTxStore::addToSentTx(Tx tx, QString txid) {
} else { } else {
// Concatenate all the toAddresses // Concatenate all the toAddresses
for (auto a : tx.toAddrs) { for (auto a : tx.toAddrs) {
toAddresses += a.addr % "(" % Settings::getZECDisplayFormat(a.amount) % ") "; toAddresses += a.addr % "(" % Settings::getDisplayFormat(a.amount) % ") ";
} }
} }

30
src/settings.cpp

@ -1,4 +1,5 @@
// Copyright 2019 The Hush developers // Copyright 2019 The Hush developers
// Released under the GPLv3
#include "mainwindow.h" #include "mainwindow.h"
#include "settings.h" #include "settings.h"
@ -160,6 +161,15 @@ double Settings::getZECPrice() {
return zecPrice; 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() { unsigned int Settings::getBTCPrice() {
// in satoshis // in satoshis
return btcPrice; return btcPrice;
@ -235,7 +245,7 @@ QString Settings::getDecimalString(double amt) {
return f; 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? // This is idiotic. Why doesn't QString have a way to do this?
return getDecimalString(bal) % " " % Settings::getTokenName(); return getDecimalString(bal) % " " % Settings::getTokenName();
} }
@ -243,12 +253,12 @@ QString Settings::getZECDisplayFormat(double bal) {
QString Settings::getZECUSDDisplayFormat(double bal) { QString Settings::getZECUSDDisplayFormat(double bal) {
auto usdFormat = getUSDFormat(bal); auto usdFormat = getUSDFormat(bal);
if (!usdFormat.isEmpty()) if (!usdFormat.isEmpty())
return getZECDisplayFormat(bal) % " (" % getUSDFormat(bal) % ")"; return getDisplayFormat(bal) % " (" % getUSDFormat(bal) % ")";
else 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() { QString Settings::getTokenName() {
if (Settings::getInstance()->isTestnet()) { if (Settings::getInstance()->isTestnet()) {
@ -258,6 +268,7 @@ QString Settings::getTokenName() {
} }
} }
//TODO: this isn't used for donations
QString Settings::getDonationAddr() { QString Settings::getDonationAddr() {
if (Settings::getInstance()->isTestnet()) { if (Settings::getInstance()->isTestnet()) {
return "ztestsaplingXXX"; return "ztestsaplingXXX";
@ -278,6 +289,15 @@ bool Settings::addToZcashConf(QString confLocation, QString line) {
return true; 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) { bool Settings::removeFromZcashConf(QString confLocation, QString option) {
if (confLocation.isEmpty()) if (confLocation.isEmpty())
return false; return false;
@ -337,7 +357,7 @@ bool Settings::isValidAddress(QString addr) {
// Get a pretty string representation of this Payment URI // Get a pretty string representation of this Payment URI
QString Settings::paymentURIPretty(PaymentURI 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()); + "\nMemo:" + QUrl::fromPercentEncoding(uri.memo.toUtf8());
} }

17
src/settings.h

@ -85,13 +85,19 @@ public:
QString get_theme_name(); QString get_theme_name();
void set_theme_name(QString theme_name); void set_theme_name(QString theme_name);
QString get_currency_name();
void set_currency_name(QString currency_name);
void setUsingZcashConf(QString confLocation); void setUsingZcashConf(QString confLocation);
const QString& getZcashdConfLocation() { return _confLocation; } const QString& getZcashdConfLocation() { return _confLocation; }
void setZECPrice(double p) { zecPrice = p; } void setZECPrice(double p) { zecPrice = p; }
void setBTCPrice(unsigned int p) { btcPrice = p; } void set_fiat_price(double p) { fiat_price = p; }
void setBTCPrice(unsigned int p) { btcPrice = p; }
double getZECPrice(); double getZECPrice();
double get_fiat_price();
unsigned int getBTCPrice(); unsigned int getBTCPrice();
double get_price(std::string currency);
void setPeers(int peers); void setPeers(int peers);
int getPeers(); int getPeers();
@ -110,7 +116,7 @@ public:
static QString getDecimalString(double amt); static QString getDecimalString(double amt);
static QString getUSDFormat(double bal); static QString getUSDFormat(double bal);
static QString getZECDisplayFormat(double bal); static QString getDisplayFormat(double bal);
static QString getZECUSDDisplayFormat(double bal); static QString getZECUSDDisplayFormat(double bal);
static QString getTokenName(); static QString getTokenName();
@ -152,7 +158,10 @@ private:
int _peerConnections = 0; int _peerConnections = 0;
double zecPrice = 0.0; double zecPrice = 0.0;
unsigned int btcPrice = 0.0; double fiat_price = 0.0;
unsigned int btcPrice = 0;
std::map<std::string, double> prices;
}; };
#endif // SETTINGS_H #endif // SETTINGS_H

82
src/settings.ui

@ -161,6 +161,88 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="16" 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>Local Currency</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="16" column="1">
<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>AUD</string>
</property>
</item>
<item>
<property name="text">
<string>BTC</string>
</property>
</item>
<item>
<property name="text">
<string>CAD</string>
</property>
</item>
<item>
<property name="text">
<string>CHF</string>
</property>
</item>
<item>
<property name="text">
<string>CNY</string>
</property>
</item>
<item>
<property name="text">
<string>EUR</string>
</property>
</item>
<item>
<property name="text">
<string>GBP</string>
</property>
</item>
<item>
<property name="text">
<string>INR</string>
</property>
</item>
<item>
<property name="text">
<string>USD</string>
</property>
</item>
</widget>
</item>
<item row="15" column="1"> <item row="15" column="1">
<widget class="QComboBox" name="comboBoxTheme"> <widget class="QComboBox" name="comboBoxTheme">
<property name="sizePolicy"> <property name="sizePolicy">

2
src/txtablemodel.cpp

@ -132,7 +132,7 @@ void TxTableModel::updateAllData() {
return addr; return addr;
} }
case 2: return QDateTime::fromMSecsSinceEpoch(modeldata->at(index.row()).datetime * (qint64)1000).toLocalTime().toString(); 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);
} }
} }

Loading…
Cancel
Save