mirror of
https://github.com/feather-wallet/feather.git
synced 2025-01-08 20:09:43 +00:00
Settings: refactor
This commit is contained in:
parent
54140df597
commit
6eb0a05752
3 changed files with 143 additions and 195 deletions
|
@ -20,114 +20,147 @@ Settings::Settings(QSharedPointer<AppContext> ctx, QWidget *parent)
|
|||
|
||||
this->setWindowIcon(QIcon("://assets/images/appicons/64x64.png"));
|
||||
|
||||
ui->tabWidget->setTabVisible(3, false);
|
||||
ui->tabWidget->setTabVisible(6, false);
|
||||
ui->tabWidget->setTabVisible(5, false);
|
||||
ui->tabWidget->setCurrentIndex(config()->get(Config::lastSettingsPage).toInt());
|
||||
connect(ui->tabWidget, &QTabWidget::currentChanged, [this](int index){
|
||||
connect(ui->tabWidget, &QTabWidget::currentChanged, [](int index){
|
||||
config()->set(Config::lastSettingsPage, index);
|
||||
});
|
||||
|
||||
connect(ui->btnCopyToClipboard, &QPushButton::clicked, this, &Settings::copyToClipboard);
|
||||
connect(ui->checkBox_multiBroadcast, &QCheckBox::toggled, [](bool toggled){
|
||||
config()->set(Config::multiBroadcast, toggled);
|
||||
});
|
||||
connect(ui->btn_multiBroadcast, &QPushButton::clicked, [this]{
|
||||
QMessageBox::information(this, "Multibroadcasting", "Multibroadcasting relays outgoing transactions to all nodes in your selected node list. This may improve transaction relay speed and reduces the chance of your transaction failing.");
|
||||
});
|
||||
connect(ui->checkBox_externalLink, &QCheckBox::clicked, this, &Settings::checkboxExternalLinkWarn);
|
||||
connect(ui->checkBox_hideBalance, &QCheckBox::toggled, [this](bool toggled){
|
||||
config()->set(Config::hideBalance, toggled);
|
||||
m_ctx->updateBalance();
|
||||
});
|
||||
connect(ui->checkBox_disableLogging, &QCheckBox::toggled, [this](bool toggled){
|
||||
config()->set(Config::disableLogging, toggled);
|
||||
WalletManager::instance()->setLogLevel(toggled ? -1 : config()->get(Config::logLevel).toInt());
|
||||
});
|
||||
connect(ui->checkBox_inactivityLockTimeout, &QCheckBox::toggled, [](bool toggled){
|
||||
config()->set(Config::inactivityLockEnabled, toggled);
|
||||
});
|
||||
connect(ui->spinBox_inactivityLockTimeout, QOverload<int>::of(&QSpinBox::valueChanged), [](int value){
|
||||
config()->set(Config::inactivityLockTimeout, value);
|
||||
});
|
||||
connect(ui->checkBox_disableWebsocket, &QCheckBox::toggled, [this](bool checked){
|
||||
config()->set(Config::disableWebsocket, checked);
|
||||
this->enableWebsocket(checked);
|
||||
});
|
||||
connect(ui->checkBox_offlineMode, &QCheckBox::toggled, [this](bool checked){
|
||||
config()->set(Config::offlineMode, checked);
|
||||
m_ctx->wallet->setOffline(checked);
|
||||
this->enableWebsocket(checked);
|
||||
});
|
||||
this->setupGeneralTab();
|
||||
this->setupPrivacyTab();
|
||||
this->setupNodeTab();
|
||||
this->setupPathsTab();
|
||||
this->setupLinksTab();
|
||||
|
||||
connect(ui->closeButton, &QDialogButtonBox::accepted, this, &Settings::close);
|
||||
|
||||
// nodes
|
||||
ui->nodeWidget->setupUI(m_ctx);
|
||||
connect(ui->nodeWidget, &NodeWidget::nodeSourceChanged, m_ctx->nodes, &Nodes::onNodeSourceChanged);
|
||||
connect(ui->nodeWidget, &NodeWidget::connectToNode, m_ctx->nodes, QOverload<const FeatherNode&>::of(&Nodes::connectToNode));
|
||||
this->adjustSize();
|
||||
}
|
||||
|
||||
// setup checkboxes
|
||||
ui->checkBox_multiBroadcast->setChecked(config()->get(Config::multiBroadcast).toBool());
|
||||
ui->checkBox_externalLink->setChecked(config()->get(Config::warnOnExternalLink).toBool());
|
||||
ui->checkBox_hideBalance->setChecked(config()->get(Config::hideBalance).toBool());
|
||||
ui->checkBox_disableLogging->setChecked(config()->get(Config::disableLogging).toBool());
|
||||
ui->checkBox_inactivityLockTimeout->setChecked(config()->get(Config::inactivityLockEnabled).toBool());
|
||||
ui->spinBox_inactivityLockTimeout->setValue(config()->get(Config::inactivityLockTimeout).toInt());
|
||||
ui->checkBox_disableWebsocket->setChecked(config()->get(Config::disableWebsocket).toBool());
|
||||
ui->checkBox_offlineMode->setChecked(config()->get(Config::offlineMode).toBool());
|
||||
|
||||
// setup comboboxes
|
||||
this->setupSkinCombobox();
|
||||
auto settingsSkin = config()->get(Config::skin).toString();
|
||||
if (m_skins.contains(settingsSkin))
|
||||
ui->comboBox_skin->setCurrentIndex(m_skins.indexOf(settingsSkin));
|
||||
|
||||
for (int i = 0; i <= 12; i++) {
|
||||
ui->comboBox_amountPrecision->addItem(QString::number(i));
|
||||
}
|
||||
ui->comboBox_amountPrecision->setCurrentIndex(config()->get(Config::amountPrecision).toInt());
|
||||
|
||||
// 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));
|
||||
|
||||
connect(ui->comboBox_skin, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Settings::comboBox_skinChanged);
|
||||
connect(ui->comboBox_amountPrecision, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Settings::comboBox_amountPrecisionChanged);
|
||||
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);
|
||||
|
||||
// Balance display combobox
|
||||
ui->comboBox_balanceDisplay->setCurrentIndex(config()->get(Config::balanceDisplay).toInt());
|
||||
connect(ui->comboBox_balanceDisplay, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Settings::comboBox_balanceDisplayChanged);
|
||||
|
||||
// Preferred fiat currency combobox
|
||||
void Settings::setupGeneralTab() {
|
||||
// [Preferred fiat currency]
|
||||
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);
|
||||
if (!preferredFiatCurrency.isEmpty() && fiatCurrencies.contains(preferredFiatCurrency)) {
|
||||
ui->comboBox_fiatCurrency->setCurrentText(preferredFiatCurrency);
|
||||
}
|
||||
|
||||
connect(ui->comboBox_fiatCurrency, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Settings::fiatCurrencySelected);
|
||||
|
||||
// setup paths tab
|
||||
this->updatePaths();
|
||||
// [Appearance]
|
||||
this->setupSkinCombobox();
|
||||
auto settingsSkin = config()->get(Config::skin).toString();
|
||||
if (m_skins.contains(settingsSkin)) {
|
||||
ui->comboBox_skin->setCurrentIndex(m_skins.indexOf(settingsSkin));
|
||||
}
|
||||
|
||||
connect(ui->comboBox_skin, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Settings::comboBox_skinChanged);
|
||||
|
||||
// [Amount precision]
|
||||
for (int i = 0; i <= 12; i++) {
|
||||
ui->comboBox_amountPrecision->addItem(QString::number(i));
|
||||
}
|
||||
ui->comboBox_amountPrecision->setCurrentIndex(config()->get(Config::amountPrecision).toInt());
|
||||
|
||||
connect(ui->comboBox_amountPrecision, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Settings::comboBox_amountPrecisionChanged);
|
||||
|
||||
// [Date format]
|
||||
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));
|
||||
}
|
||||
|
||||
connect(ui->comboBox_dateFormat, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Settings::comboBox_dateFormatChanged);
|
||||
|
||||
// [Time format]
|
||||
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));
|
||||
}
|
||||
|
||||
connect(ui->comboBox_timeFormat, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Settings::comboBox_timeFormatChanged);
|
||||
|
||||
// [Balance display]
|
||||
ui->comboBox_balanceDisplay->setCurrentIndex(config()->get(Config::balanceDisplay).toInt());
|
||||
connect(ui->comboBox_balanceDisplay, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Settings::comboBox_balanceDisplayChanged);
|
||||
|
||||
// [Offline mode]
|
||||
ui->checkBox_offlineMode->setChecked(config()->get(Config::offlineMode).toBool());
|
||||
connect(ui->checkBox_offlineMode, &QCheckBox::toggled, [this](bool checked){
|
||||
config()->set(Config::offlineMode, checked);
|
||||
m_ctx->wallet->setOffline(checked);
|
||||
this->enableWebsocket(checked);
|
||||
});
|
||||
}
|
||||
|
||||
void Settings::setupPrivacyTab() {
|
||||
// [Multibroadcast outgoing transactions]
|
||||
ui->checkBox_multiBroadcast->setChecked(config()->get(Config::multiBroadcast).toBool());
|
||||
connect(ui->checkBox_multiBroadcast, &QCheckBox::toggled, [](bool toggled){
|
||||
config()->set(Config::multiBroadcast, toggled);
|
||||
});
|
||||
connect(ui->btn_multiBroadcast, &QPushButton::clicked, [this]{
|
||||
QMessageBox::information(this, "Multibroadcasting", "Multibroadcasting relays outgoing transactions to all nodes in your selected node list. This may improve transaction relay speed and reduces the chance of your transaction failing.");
|
||||
});
|
||||
|
||||
// [Warn before opening external link]
|
||||
ui->checkBox_externalLink->setChecked(config()->get(Config::warnOnExternalLink).toBool());
|
||||
connect(ui->checkBox_externalLink, &QCheckBox::clicked, this, &Settings::checkboxExternalLinkWarn);
|
||||
|
||||
// [Hide balance]
|
||||
ui->checkBox_hideBalance->setChecked(config()->get(Config::hideBalance).toBool());
|
||||
connect(ui->checkBox_hideBalance, &QCheckBox::toggled, [this](bool toggled){
|
||||
config()->set(Config::hideBalance, toggled);
|
||||
m_ctx->updateBalance();
|
||||
});
|
||||
|
||||
// [Disable websocket]
|
||||
ui->checkBox_disableWebsocket->setChecked(config()->get(Config::disableWebsocket).toBool());
|
||||
connect(ui->checkBox_disableWebsocket, &QCheckBox::toggled, [this](bool checked){
|
||||
config()->set(Config::disableWebsocket, checked);
|
||||
this->enableWebsocket(checked);
|
||||
});
|
||||
|
||||
// [Do not write log files to disk]
|
||||
ui->checkBox_disableLogging->setChecked(config()->get(Config::disableLogging).toBool());
|
||||
connect(ui->checkBox_disableLogging, &QCheckBox::toggled, [this](bool toggled){
|
||||
config()->set(Config::disableLogging, toggled);
|
||||
WalletManager::instance()->setLogLevel(toggled ? -1 : config()->get(Config::logLevel).toInt());
|
||||
});
|
||||
|
||||
// [Lock wallet on inactivity]
|
||||
ui->checkBox_inactivityLockTimeout->setChecked(config()->get(Config::inactivityLockEnabled).toBool());
|
||||
ui->spinBox_inactivityLockTimeout->setValue(config()->get(Config::inactivityLockTimeout).toInt());
|
||||
connect(ui->checkBox_inactivityLockTimeout, &QCheckBox::toggled, [](bool toggled){
|
||||
config()->set(Config::inactivityLockEnabled, toggled);
|
||||
});
|
||||
connect(ui->spinBox_inactivityLockTimeout, QOverload<int>::of(&QSpinBox::valueChanged), [](int value){
|
||||
config()->set(Config::inactivityLockTimeout, value);
|
||||
});
|
||||
}
|
||||
|
||||
void Settings::setupNodeTab() {
|
||||
ui->nodeWidget->setupUI(m_ctx);
|
||||
connect(ui->nodeWidget, &NodeWidget::nodeSourceChanged, m_ctx->nodes, &Nodes::onNodeSourceChanged);
|
||||
connect(ui->nodeWidget, &NodeWidget::connectToNode, m_ctx->nodes, QOverload<const FeatherNode&>::of(&Nodes::connectToNode));
|
||||
}
|
||||
|
||||
void Settings::setupPathsTab() {
|
||||
ui->lineEdit_defaultWalletDir->setText(config()->get(Config::walletDirectory).toString());
|
||||
ui->lineEdit_configDir->setText(Config::defaultConfigDir().path());
|
||||
ui->lineEdit_applicationDir->setText(QCoreApplication::applicationDirPath());
|
||||
|
||||
connect(ui->btn_browseDefaultWalletDir, &QPushButton::clicked, [this]{
|
||||
QString walletDirOld = config()->get(Config::walletDirectory).toString();
|
||||
QString walletDir = QFileDialog::getExistingDirectory(this, "Select wallet directory ", walletDirOld, QFileDialog::ShowDirsOnly);
|
||||
|
@ -136,23 +169,20 @@ Settings::Settings(QSharedPointer<AppContext> ctx, QWidget *parent)
|
|||
config()->set(Config::walletDirectory, walletDir);
|
||||
ui->lineEdit_defaultWalletDir->setText(walletDir);
|
||||
});
|
||||
|
||||
// Links tab
|
||||
this->setupLocalMoneroFrontendCombobox();
|
||||
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->adjustSize();
|
||||
}
|
||||
|
||||
void Settings::updatePaths() {
|
||||
ui->lineEdit_defaultWalletDir->setText(config()->get(Config::walletDirectory).toString());
|
||||
ui->lineEdit_configDir->setText(Config::defaultConfigDir().path());
|
||||
ui->lineEdit_applicationDir->setText(QCoreApplication::applicationDirPath());
|
||||
void Settings::setupLinksTab() {
|
||||
// [Block explorer]
|
||||
ui->combo_blockExplorer->setCurrentIndex(ui->combo_blockExplorer->findText(config()->get(Config::blockExplorer).toString()));
|
||||
connect(ui->combo_blockExplorer, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Settings::comboBox_blockExplorerChanged);
|
||||
|
||||
// [Reddit frontend]
|
||||
ui->combo_redditFrontend->setCurrentIndex(ui->combo_redditFrontend->findText(config()->get(Config::redditFrontend).toString()));
|
||||
connect(ui->combo_redditFrontend, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Settings::comboBox_redditFrontendChanged);
|
||||
|
||||
// [LocalMonero frontend]
|
||||
this->setupLocalMoneroFrontendCombobox();
|
||||
connect(ui->combo_localMoneroFrontend, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Settings::comboBox_localMoneroFrontendChanged);
|
||||
}
|
||||
|
||||
void Settings::fiatCurrencySelected(int index) {
|
||||
|
@ -200,10 +230,6 @@ void Settings::comboBox_balanceDisplayChanged(int pos) {
|
|||
m_ctx->updateBalance();
|
||||
}
|
||||
|
||||
void Settings::copyToClipboard() {
|
||||
ui->textLogs->copy();
|
||||
}
|
||||
|
||||
void Settings::checkboxExternalLinkWarn() {
|
||||
bool state = ui->checkBox_externalLink->isChecked();
|
||||
config()->set(Config::warnOnExternalLink, state);
|
||||
|
|
|
@ -24,16 +24,12 @@ public:
|
|||
~Settings() override;
|
||||
|
||||
signals:
|
||||
void closed();
|
||||
void preferredFiatCurrencyChanged(QString currency);
|
||||
void skinChanged(QString skinName);
|
||||
void showHomeCCS(bool);
|
||||
void blockExplorerChanged(QString blockExplorer);
|
||||
void amountPrecisionChanged(int precision);
|
||||
|
||||
public slots:
|
||||
void updatePaths();
|
||||
void copyToClipboard();
|
||||
void checkboxExternalLinkWarn();
|
||||
void fiatCurrencySelected(int index);
|
||||
void comboBox_skinChanged(int pos);
|
||||
|
@ -41,12 +37,17 @@ public slots:
|
|||
void comboBox_dateFormatChanged(int pos);
|
||||
void comboBox_timeFormatChanged(int pos);
|
||||
void comboBox_balanceDisplayChanged(int pos);
|
||||
|
||||
void comboBox_blockExplorerChanged(int pos);
|
||||
void comboBox_redditFrontendChanged(int pos);
|
||||
void comboBox_localMoneroFrontendChanged(int pos);
|
||||
|
||||
private:
|
||||
void setupGeneralTab();
|
||||
void setupPrivacyTab();
|
||||
void setupNodeTab();
|
||||
void setupPathsTab();
|
||||
void setupLinksTab();
|
||||
|
||||
void setupSkinCombobox();
|
||||
void setupLocalMoneroFrontendCombobox();
|
||||
void enableWebsocket(bool enabled);
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab_general">
|
||||
<attribute name="title">
|
||||
|
@ -378,85 +378,6 @@
|
|||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_network">
|
||||
<attribute name="title">
|
||||
<string>Network</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_3">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Websockets</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="0">
|
||||
<widget class="QRadioButton" name="radioButton_disableWebsocket">
|
||||
<property name="text">
|
||||
<string>Disable websocket</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QRadioButton" name="radioButton_websocketServer">
|
||||
<property name="text">
|
||||
<string>Websocket server</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLineEdit" name="lineEdit_websocketServer">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>300</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Expanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_paths">
|
||||
<attribute name="title">
|
||||
<string>Paths</string>
|
||||
|
|
Loading…
Reference in a new issue