2020-10-07 10:36:04 +00:00
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2020-12-26 19:56:06 +00:00
|
|
|
// Copyright (c) 2020-2021, The Monero Project.
|
2020-10-07 10:36:04 +00:00
|
|
|
|
|
|
|
#include "settings.h"
|
|
|
|
#include "ui_settings.h"
|
|
|
|
#include "mainwindow.h"
|
|
|
|
|
2020-12-25 21:07:48 +00:00
|
|
|
#include <QFileDialog>
|
|
|
|
|
2020-10-07 10:36:04 +00:00
|
|
|
Settings::Settings(QWidget *parent) :
|
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::Settings)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2020-10-11 17:15:21 +00:00
|
|
|
m_ctx = MainWindow::getContext();
|
2020-10-07 10:36:04 +00:00
|
|
|
|
2020-10-11 17:15:21 +00:00
|
|
|
this->setWindowIcon(QIcon("://assets/images/appicons/64x64.png"));
|
2020-10-07 10:36:04 +00:00
|
|
|
|
|
|
|
ui->tabWidget->setTabVisible(2, false);
|
2021-05-02 18:22:38 +00:00
|
|
|
ui->tabWidget->setTabVisible(5, false);
|
2020-10-07 10:36:04 +00:00
|
|
|
|
|
|
|
connect(ui->btnCopyToClipboard, &QPushButton::clicked, this, &Settings::copyToClipboard);
|
2021-03-16 03:17:01 +00:00
|
|
|
connect(ui->checkBox_multiBroadcast, &QCheckBox::toggled, [](bool toggled){
|
|
|
|
config()->set(Config::multiBroadcast, toggled);
|
|
|
|
});
|
2020-10-07 10:36:04 +00:00
|
|
|
connect(ui->checkBox_externalLink, &QCheckBox::clicked, this, &Settings::checkboxExternalLinkWarn);
|
2020-11-02 09:37:36 +00:00
|
|
|
connect(ui->checkBox_hideBalance, &QCheckBox::toggled, [this](bool toggled){
|
|
|
|
config()->set(Config::hideBalance, toggled);
|
|
|
|
m_ctx->updateBalance();
|
|
|
|
});
|
|
|
|
|
2020-10-07 10:36:04 +00:00
|
|
|
connect(ui->closeButton, &QDialogButtonBox::accepted, this, &Settings::close);
|
|
|
|
|
|
|
|
// nodes
|
|
|
|
ui->nodeWidget->setupUI(m_ctx);
|
|
|
|
connect(ui->nodeWidget, &NodeWidget::nodeSourceChanged, m_ctx->nodes, &Nodes::onNodeSourceChanged);
|
2020-11-23 16:57:38 +00:00
|
|
|
connect(ui->nodeWidget, &NodeWidget::connectToNode, m_ctx->nodes, QOverload<const FeatherNode&>::of(&Nodes::connectToNode));
|
2020-10-07 10:36:04 +00:00
|
|
|
|
|
|
|
// setup checkboxes
|
2021-03-16 03:17:01 +00:00
|
|
|
ui->checkBox_multiBroadcast->setChecked(config()->get(Config::multiBroadcast).toBool());
|
2020-10-07 10:36:04 +00:00
|
|
|
ui->checkBox_externalLink->setChecked(config()->get(Config::warnOnExternalLink).toBool());
|
2020-11-02 09:37:36 +00:00
|
|
|
ui->checkBox_hideBalance->setChecked(config()->get(Config::hideBalance).toBool());
|
2020-10-07 10:36:04 +00:00
|
|
|
|
|
|
|
// setup comboboxes
|
|
|
|
this->setupSkinCombobox();
|
|
|
|
auto settingsSkin = config()->get(Config::skin).toString();
|
|
|
|
if (m_skins.contains(settingsSkin))
|
|
|
|
ui->comboBox_skin->setCurrentIndex(m_skins.indexOf(settingsSkin));
|
|
|
|
|
2021-03-08 20:03:20 +00:00
|
|
|
for (int i = 0; i <= 12; i++) {
|
|
|
|
ui->comboBox_amountPrecision->addItem(QString::number(i));
|
|
|
|
}
|
|
|
|
ui->comboBox_amountPrecision->setCurrentIndex(config()->get(Config::amountPrecision).toInt());
|
|
|
|
|
2021-03-14 21:12:02 +00:00
|
|
|
// Date format combobox
|
|
|
|
QDateTime now = QDateTime::currentDateTime();
|
|
|
|
for (const auto & format : m_dateFormats) {
|
|
|
|
ui->comboBox_dateFormat->addItem(now.toString(format));
|
|
|
|
}
|
|
|
|
QString dateFormatSetting = config()->get(Config::dateFormat).toString();
|
|
|
|
if (m_dateFormats.contains(dateFormatSetting))
|
|
|
|
ui->comboBox_dateFormat->setCurrentIndex(m_dateFormats.indexOf(dateFormatSetting));
|
|
|
|
|
|
|
|
// Time format combobox
|
|
|
|
for (const auto & format : m_timeFormats) {
|
|
|
|
ui->comboBox_timeFormat->addItem(now.toString(format));
|
|
|
|
}
|
|
|
|
QString timeFormatSetting = config()->get(Config::timeFormat).toString();
|
|
|
|
if (m_timeFormats.contains(timeFormatSetting))
|
|
|
|
ui->comboBox_timeFormat->setCurrentIndex(m_timeFormats.indexOf(timeFormatSetting));
|
|
|
|
|
2020-10-07 10:36:04 +00:00
|
|
|
connect(ui->comboBox_skin, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Settings::comboBox_skinChanged);
|
2021-03-08 20:03:20 +00:00
|
|
|
connect(ui->comboBox_amountPrecision, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Settings::comboBox_amountPrecisionChanged);
|
2021-03-14 21:12:02 +00:00
|
|
|
connect(ui->comboBox_dateFormat, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Settings::comboBox_dateFormatChanged);
|
|
|
|
connect(ui->comboBox_timeFormat, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Settings::comboBox_timeFormatChanged);
|
2020-10-07 10:36:04 +00:00
|
|
|
|
|
|
|
// setup preferred fiat currency combobox
|
|
|
|
QStringList fiatCurrencies;
|
|
|
|
for (int index = 0; index < ui->comboBox_fiatCurrency->count(); index++)
|
|
|
|
fiatCurrencies << ui->comboBox_fiatCurrency->itemText(index);
|
|
|
|
|
|
|
|
auto preferredFiatCurrency = config()->get(Config::preferredFiatCurrency).toString();
|
|
|
|
if(!preferredFiatCurrency.isEmpty())
|
|
|
|
if(fiatCurrencies.contains(preferredFiatCurrency))
|
|
|
|
ui->comboBox_fiatCurrency->setCurrentText(preferredFiatCurrency);
|
|
|
|
|
|
|
|
connect(ui->comboBox_fiatCurrency, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Settings::fiatCurrencySelected);
|
|
|
|
|
2020-12-25 21:07:48 +00:00
|
|
|
// setup paths tab
|
|
|
|
this->updatePaths();
|
|
|
|
connect(ui->btn_browseDefaultWalletDir, &QPushButton::clicked, [this]{
|
|
|
|
QString walletDir = QFileDialog::getExistingDirectory(this, "Select wallet directory ", m_ctx->defaultWalletDir, QFileDialog::ShowDirsOnly);
|
|
|
|
if (walletDir.isEmpty()) return;
|
|
|
|
m_ctx->defaultWalletDir = walletDir;
|
|
|
|
config()->set(Config::walletDirectory, walletDir);
|
|
|
|
ui->lineEdit_defaultWalletDir->setText(m_ctx->defaultWalletDir);
|
|
|
|
});
|
2020-10-07 10:36:04 +00:00
|
|
|
|
2021-05-02 18:22:38 +00:00
|
|
|
// Links tab
|
|
|
|
connect(ui->combo_blockExplorer, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Settings::comboBox_blockExplorerChanged);
|
|
|
|
connect(ui->combo_redditFrontend, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Settings::comboBox_redditFrontendChanged);
|
|
|
|
connect(ui->combo_localMoneroFrontend, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Settings::comboBox_localMoneroFrontendChanged);
|
|
|
|
|
|
|
|
ui->combo_blockExplorer->setCurrentIndex(ui->combo_blockExplorer->findText(config()->get(Config::blockExplorer).toString()));
|
|
|
|
ui->combo_redditFrontend->setCurrentIndex(ui->combo_redditFrontend->findText(config()->get(Config::redditFrontend).toString()));
|
|
|
|
|
|
|
|
this->setupLocalMoneroFrontendCombobox();
|
|
|
|
|
2020-10-07 10:36:04 +00:00
|
|
|
this->adjustSize();
|
|
|
|
}
|
|
|
|
|
2020-12-25 21:07:48 +00:00
|
|
|
void Settings::updatePaths() {
|
|
|
|
ui->lineEdit_defaultWalletDir->setText(m_ctx->defaultWalletDir);
|
2021-03-12 18:26:48 +00:00
|
|
|
ui->lineEdit_configDir->setText(Config::defaultConfigDir().path());
|
|
|
|
ui->lineEdit_applicationDir->setText(QCoreApplication::applicationDirPath());
|
2020-12-25 21:07:48 +00:00
|
|
|
}
|
|
|
|
|
2020-10-07 10:36:04 +00:00
|
|
|
void Settings::fiatCurrencySelected(int index) {
|
|
|
|
QString selection = ui->comboBox_fiatCurrency->itemText(index);
|
|
|
|
config()->set(Config::preferredFiatCurrency, selection);
|
|
|
|
emit preferredFiatCurrencyChanged(selection);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::comboBox_skinChanged(int pos) {
|
|
|
|
emit skinChanged(m_skins.at(pos));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::comboBox_blockExplorerChanged(int pos) {
|
2021-05-02 18:22:38 +00:00
|
|
|
QString blockExplorer = ui->combo_blockExplorer->currentText();
|
2020-10-07 10:36:04 +00:00
|
|
|
config()->set(Config::blockExplorer, blockExplorer);
|
|
|
|
emit blockExplorerChanged(blockExplorer);
|
|
|
|
}
|
|
|
|
|
2020-12-30 02:48:10 +00:00
|
|
|
void Settings::comboBox_redditFrontendChanged(int pos) {
|
2021-05-02 18:22:38 +00:00
|
|
|
QString redditFrontend = ui->combo_redditFrontend->currentText();
|
2020-12-30 02:48:10 +00:00
|
|
|
config()->set(Config::redditFrontend, redditFrontend);
|
|
|
|
}
|
|
|
|
|
2021-05-02 18:22:38 +00:00
|
|
|
void Settings::comboBox_localMoneroFrontendChanged(int pos) {
|
|
|
|
QString localMoneroFrontend = ui->combo_localMoneroFrontend->currentData().toString();
|
|
|
|
config()->set(Config::localMoneroFrontend, localMoneroFrontend);
|
|
|
|
}
|
|
|
|
|
2021-03-08 20:03:20 +00:00
|
|
|
void Settings::comboBox_amountPrecisionChanged(int pos) {
|
|
|
|
config()->set(Config::amountPrecision, pos);
|
|
|
|
emit amountPrecisionChanged(pos);
|
|
|
|
}
|
|
|
|
|
2021-03-14 21:12:02 +00:00
|
|
|
void Settings::comboBox_dateFormatChanged(int pos) {
|
|
|
|
config()->set(Config::dateFormat, m_dateFormats.at(pos));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::comboBox_timeFormatChanged(int pos) {
|
|
|
|
config()->set(Config::timeFormat, m_timeFormats.at(pos));
|
|
|
|
}
|
|
|
|
|
2020-10-07 10:36:04 +00:00
|
|
|
void Settings::copyToClipboard() {
|
|
|
|
ui->textLogs->copy();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::checkboxExternalLinkWarn() {
|
|
|
|
bool state = ui->checkBox_externalLink->isChecked();
|
|
|
|
config()->set(Config::warnOnExternalLink, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::setupSkinCombobox() {
|
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
m_skins.removeOne("Breeze/Dark");
|
|
|
|
m_skins.removeOne("Breeze/Light");
|
|
|
|
#elif defined(Q_OS_MAC)
|
|
|
|
m_skins.removeOne("QDarkStyle");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ui->comboBox_skin->insertItems(0, m_skins);
|
|
|
|
}
|
|
|
|
|
2021-05-02 18:22:38 +00:00
|
|
|
void Settings::setupLocalMoneroFrontendCombobox() {
|
|
|
|
ui->combo_localMoneroFrontend->addItem("localmonero.co", "https://localmonero.co");
|
|
|
|
ui->combo_localMoneroFrontend->addItem("localmonero.co/nojs", "https://localmonero.co/nojs");
|
|
|
|
ui->combo_localMoneroFrontend->addItem("nehdddktmhvqklsnkjqcbpmb63htee2iznpcbs5tgzctipxykpj6yrid.onion",
|
|
|
|
"http://nehdddktmhvqklsnkjqcbpmb63htee2iznpcbs5tgzctipxykpj6yrid.onion");
|
|
|
|
|
|
|
|
ui->combo_localMoneroFrontend->setCurrentIndex(ui->combo_localMoneroFrontend->findData(config()->get(Config::localMoneroFrontend).toString()));
|
|
|
|
}
|
|
|
|
|
2020-10-07 10:36:04 +00:00
|
|
|
Settings::~Settings() {
|
|
|
|
delete ui;
|
|
|
|
}
|