mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
Merge pull request #3347
7e195e8
[Qt] massive options/settings rework (no core changes) (Philip Kaufmann)
This commit is contained in:
commit
a036b796d1
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>540</width>
|
||||
<height>380</height>
|
||||
<width>560</width>
|
||||
<height>400</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -19,9 +19,6 @@
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="tabPosition">
|
||||
<enum>QTabWidget::North</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
@ -86,21 +83,44 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_Main">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2_Main">
|
||||
<item>
|
||||
<widget class="QLabel" name="databaseCacheLabel">
|
||||
<property name="text">
|
||||
<string>Size of &database cache</string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::PlainText</enum>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>databaseCache</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="databaseCache">
|
||||
<property name="toolTip">
|
||||
<string>Set database cache size in megabytes (default: 25)</string>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>1024</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>25</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="databaseCacheUnitLabel">
|
||||
<property name="text">
|
||||
<string>MB</string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::PlainText</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2_Main">
|
||||
<property name="orientation">
|
||||
@ -114,21 +134,64 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3_Main">
|
||||
<item>
|
||||
<widget class="QPushButton" name="resetButton">
|
||||
<property name="toolTip">
|
||||
<string>Reset all client options to default.</string>
|
||||
</property>
|
||||
<widget class="QLabel" name="threadsScriptVerifLabel">
|
||||
<property name="text">
|
||||
<string>&Reset Options</string>
|
||||
<string>Number of script &verification threads</string>
|
||||
</property>
|
||||
<property name="autoDefault">
|
||||
<bool>false</bool>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::PlainText</enum>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>threadsScriptVerif</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="threadsScriptVerif">
|
||||
<property name="toolTip">
|
||||
<string>Set the number of script verification threads (up to 16, 0 = auto, <0 = leave that many cores free, default: 0)</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>-16</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>16</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3_Main">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_Main">
|
||||
<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="tabNetwork">
|
||||
@ -149,15 +212,15 @@
|
||||
<item>
|
||||
<widget class="QCheckBox" name="connectSocks">
|
||||
<property name="toolTip">
|
||||
<string>Connect to the Bitcoin network through a SOCKS proxy (e.g. when connecting through Tor).</string>
|
||||
<string>Connect to the Bitcoin network through a SOCKS proxy.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Connect through SOCKS proxy:</string>
|
||||
<string>&Connect through SOCKS proxy (default proxy):</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_Network">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_1_Network">
|
||||
<item>
|
||||
<widget class="QLabel" name="proxyIpLabel">
|
||||
<property name="text">
|
||||
@ -173,6 +236,12 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QValidatedLineEdit" name="proxyIp">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>140</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>140</width>
|
||||
@ -180,7 +249,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>IP address of the proxy (e.g. 127.0.0.1)</string>
|
||||
<string>IP address of the proxy (e.g. IPv4: 127.0.0.1 / IPv6: ::1)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -199,6 +268,12 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="proxyPort">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>55</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>55</width>
|
||||
@ -231,7 +306,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_Network">
|
||||
<spacer name="horizontalSpacer_1_Network">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
@ -390,8 +465,67 @@
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_Bottom">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_Bottom">
|
||||
<item>
|
||||
<widget class="QLabel" name="overriddenByCommandLineInfoLabel">
|
||||
<property name="text">
|
||||
<string>Active command-line options that override above options: </string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::PlainText</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_Bottom">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="overriddenByCommandLineLabel">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::PlainText</enum>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_Buttons">
|
||||
<item>
|
||||
<widget class="QPushButton" name="resetButton">
|
||||
<property name="toolTip">
|
||||
<string>Reset all client options to default.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Reset Options</string>
|
||||
</property>
|
||||
<property name="autoDefault">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_1">
|
||||
<property name="orientation">
|
||||
@ -407,6 +541,12 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="statusLabel">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
@ -454,16 +594,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="applyButton">
|
||||
<property name="text">
|
||||
<string>&Apply</string>
|
||||
</property>
|
||||
<property name="autoDefault">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
@ -473,17 +603,18 @@
|
||||
<class>BitcoinAmountField</class>
|
||||
<extends>QLineEdit</extends>
|
||||
<header>bitcoinamountfield.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>QValueComboBox</class>
|
||||
<extends>QComboBox</extends>
|
||||
<header>qvaluecombobox.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>QValidatedLineEdit</class>
|
||||
<extends>QLineEdit</extends>
|
||||
<header>qvalidatedlineedit.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>QValueComboBox</class>
|
||||
<extends>QComboBox</extends>
|
||||
<header>qvaluecombobox.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "ui_optionsdialog.h"
|
||||
|
||||
#include "bitcoinunits.h"
|
||||
#include "guiutil.h"
|
||||
#include "monitoreddatamapper.h"
|
||||
#include "optionsmodel.h"
|
||||
|
||||
@ -19,17 +20,20 @@
|
||||
#include <QIntValidator>
|
||||
#include <QLocale>
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
|
||||
OptionsDialog::OptionsDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::OptionsDialog),
|
||||
model(0),
|
||||
mapper(0),
|
||||
fRestartWarningDisplayed_Proxy(false),
|
||||
fRestartWarningDisplayed_Lang(false),
|
||||
fProxyIpValid(true)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
GUIUtil::restoreWindowGeometry("nOptionsDialogWindow", this->size(), this);
|
||||
|
||||
/* Main elements init */
|
||||
ui->databaseCache->setMaximum(sizeof(void*) > 4 ? 4096 : 1024);
|
||||
|
||||
/* Network elements init */
|
||||
#ifndef USE_UPNP
|
||||
@ -40,6 +44,7 @@ OptionsDialog::OptionsDialog(QWidget *parent) :
|
||||
ui->proxyPort->setEnabled(false);
|
||||
ui->proxyPort->setValidator(new QIntValidator(1, 65535, this));
|
||||
|
||||
/** SOCKS version is only selectable for default proxy and is always 5 for IPv6 and Tor */
|
||||
ui->socksVersion->setEnabled(false);
|
||||
ui->socksVersion->addItem("5", 5);
|
||||
ui->socksVersion->addItem("4", 4);
|
||||
@ -95,16 +100,13 @@ OptionsDialog::OptionsDialog(QWidget *parent) :
|
||||
mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
|
||||
mapper->setOrientation(Qt::Vertical);
|
||||
|
||||
/* enable apply button when data modified */
|
||||
connect(mapper, SIGNAL(viewModified()), this, SLOT(enableApplyButton()));
|
||||
/* disable apply button when new data loaded */
|
||||
connect(mapper, SIGNAL(currentIndexChanged(int)), this, SLOT(disableApplyButton()));
|
||||
/* setup/change UI elements when proxy IP is invalid/valid */
|
||||
connect(this, SIGNAL(proxyIpValid(QValidatedLineEdit *, bool)), this, SLOT(handleProxyIpValid(QValidatedLineEdit *, bool)));
|
||||
connect(this, SIGNAL(proxyIpChecks(QValidatedLineEdit *, int)), this, SLOT(doProxyIpChecks(QValidatedLineEdit *, int)));
|
||||
}
|
||||
|
||||
OptionsDialog::~OptionsDialog()
|
||||
{
|
||||
GUIUtil::saveWindowGeometry("nOptionsDialogWindow", this);
|
||||
delete ui;
|
||||
}
|
||||
|
||||
@ -114,6 +116,15 @@ void OptionsDialog::setModel(OptionsModel *model)
|
||||
|
||||
if(model)
|
||||
{
|
||||
/* check if client restart is needed and show persistent message */
|
||||
if (model->isRestartRequired())
|
||||
showRestartWarning(true);
|
||||
|
||||
QString strLabel = model->getOverriddenByCommandLine();
|
||||
if (strLabel.isEmpty())
|
||||
strLabel = tr("none");
|
||||
ui->overriddenByCommandLineLabel->setText(strLabel);
|
||||
|
||||
connect(model, SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
|
||||
|
||||
mapper->setModel(model);
|
||||
@ -124,11 +135,15 @@ void OptionsDialog::setModel(OptionsModel *model)
|
||||
/* update the display unit, to not use the default ("BTC") */
|
||||
updateDisplayUnit();
|
||||
|
||||
/* warn only when language selection changes by user action (placed here so init via mapper doesn't trigger this) */
|
||||
connect(ui->lang, SIGNAL(valueChanged()), this, SLOT(showRestartWarning_Lang()));
|
||||
/* warn when one of the following settings changes by user action (placed here so init via mapper doesn't trigger them) */
|
||||
|
||||
/* disable apply button after settings are loaded as there is nothing to save */
|
||||
disableApplyButton();
|
||||
/* Main */
|
||||
connect(ui->databaseCache, SIGNAL(valueChanged(int)), this, SLOT(showRestartWarning()));
|
||||
connect(ui->threadsScriptVerif, SIGNAL(valueChanged(int)), this, SLOT(showRestartWarning()));
|
||||
/* Network */
|
||||
connect(ui->connectSocks, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning()));
|
||||
/* Display */
|
||||
connect(ui->lang, SIGNAL(valueChanged()), this, SLOT(showRestartWarning()));
|
||||
}
|
||||
|
||||
void OptionsDialog::setMapper()
|
||||
@ -136,6 +151,8 @@ void OptionsDialog::setMapper()
|
||||
/* Main */
|
||||
mapper->addMapping(ui->transactionFee, OptionsModel::Fee);
|
||||
mapper->addMapping(ui->bitcoinAtStartup, OptionsModel::StartAtStartup);
|
||||
mapper->addMapping(ui->threadsScriptVerif, OptionsModel::ThreadsScriptVerif);
|
||||
mapper->addMapping(ui->databaseCache, OptionsModel::DatabaseCache);
|
||||
|
||||
/* Network */
|
||||
mapper->addMapping(ui->mapPortUpnp, OptionsModel::MapPortUPnP);
|
||||
@ -158,31 +175,20 @@ void OptionsDialog::setMapper()
|
||||
mapper->addMapping(ui->coinControlFeatures, OptionsModel::CoinControlFeatures);
|
||||
}
|
||||
|
||||
void OptionsDialog::enableApplyButton()
|
||||
void OptionsDialog::enableOkButton()
|
||||
{
|
||||
ui->applyButton->setEnabled(true);
|
||||
}
|
||||
|
||||
void OptionsDialog::disableApplyButton()
|
||||
{
|
||||
ui->applyButton->setEnabled(false);
|
||||
}
|
||||
|
||||
void OptionsDialog::enableSaveButtons()
|
||||
{
|
||||
/* prevent enabling of the save buttons when data modified, if there is an invalid proxy address present */
|
||||
/* prevent enabling of the OK button when data modified, if there is an invalid proxy address present */
|
||||
if(fProxyIpValid)
|
||||
setSaveButtonState(true);
|
||||
setOkButtonState(true);
|
||||
}
|
||||
|
||||
void OptionsDialog::disableSaveButtons()
|
||||
void OptionsDialog::disableOkButton()
|
||||
{
|
||||
setSaveButtonState(false);
|
||||
setOkButtonState(false);
|
||||
}
|
||||
|
||||
void OptionsDialog::setSaveButtonState(bool fState)
|
||||
void OptionsDialog::setOkButtonState(bool fState)
|
||||
{
|
||||
ui->applyButton->setEnabled(fState);
|
||||
ui->okButton->setEnabled(fState);
|
||||
}
|
||||
|
||||
@ -192,24 +198,15 @@ void OptionsDialog::on_resetButton_clicked()
|
||||
{
|
||||
// confirmation dialog
|
||||
QMessageBox::StandardButton btnRetVal = QMessageBox::question(this, tr("Confirm options reset"),
|
||||
tr("Some settings may require a client restart to take effect.") + "<br><br>" + tr("Do you want to proceed?"),
|
||||
tr("Client restart required to activate changes.") + "<br><br>" + tr("Client will be shutdown, do you want to proceed?"),
|
||||
QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel);
|
||||
|
||||
if(btnRetVal == QMessageBox::Cancel)
|
||||
return;
|
||||
|
||||
disableApplyButton();
|
||||
|
||||
/* disable restart warning messages display */
|
||||
fRestartWarningDisplayed_Lang = fRestartWarningDisplayed_Proxy = true;
|
||||
|
||||
/* reset all options and save the default values (QSettings) */
|
||||
/* reset all options and close Bitcoin-Qt */
|
||||
model->Reset();
|
||||
mapper->toFirst();
|
||||
mapper->submit();
|
||||
|
||||
/* re-enable restart warning messages display */
|
||||
fRestartWarningDisplayed_Lang = fRestartWarningDisplayed_Proxy = false;
|
||||
QApplication::quit();
|
||||
}
|
||||
}
|
||||
|
||||
@ -224,28 +221,26 @@ void OptionsDialog::on_cancelButton_clicked()
|
||||
reject();
|
||||
}
|
||||
|
||||
void OptionsDialog::on_applyButton_clicked()
|
||||
void OptionsDialog::showRestartWarning(bool fPersistent)
|
||||
{
|
||||
mapper->submit();
|
||||
disableApplyButton();
|
||||
}
|
||||
ui->statusLabel->setStyleSheet("QLabel { color: red; }");
|
||||
|
||||
void OptionsDialog::showRestartWarning_Proxy()
|
||||
{
|
||||
if(!fRestartWarningDisplayed_Proxy)
|
||||
if(fPersistent)
|
||||
{
|
||||
QMessageBox::warning(this, tr("Warning"), tr("This setting will take effect after restarting Bitcoin."), QMessageBox::Ok);
|
||||
fRestartWarningDisplayed_Proxy = true;
|
||||
ui->statusLabel->setText(tr("Client restart required to activate changes."));
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->statusLabel->setText(tr("This change would require a client restart."));
|
||||
// clear non-persistent status label after 10 seconds
|
||||
// Todo: should perhaps be a class attribute, if we extend the use of statusLabel
|
||||
QTimer::singleShot(10000, this, SLOT(clearStatusLabel()));
|
||||
}
|
||||
}
|
||||
|
||||
void OptionsDialog::showRestartWarning_Lang()
|
||||
void OptionsDialog::clearStatusLabel()
|
||||
{
|
||||
if(!fRestartWarningDisplayed_Lang)
|
||||
{
|
||||
QMessageBox::warning(this, tr("Warning"), tr("This setting will take effect after restarting Bitcoin."), QMessageBox::Ok);
|
||||
fRestartWarningDisplayed_Lang = true;
|
||||
}
|
||||
ui->statusLabel->clear();
|
||||
}
|
||||
|
||||
void OptionsDialog::updateDisplayUnit()
|
||||
@ -257,22 +252,25 @@ void OptionsDialog::updateDisplayUnit()
|
||||
}
|
||||
}
|
||||
|
||||
void OptionsDialog::handleProxyIpValid(QValidatedLineEdit *object, bool fState)
|
||||
void OptionsDialog::doProxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPort)
|
||||
{
|
||||
// this is used in a check before re-enabling the save buttons
|
||||
fProxyIpValid = fState;
|
||||
Q_UNUSED(nProxyPort);
|
||||
|
||||
if(fProxyIpValid)
|
||||
const std::string strAddrProxy = pUiProxyIp->text().toStdString();
|
||||
CService addrProxy;
|
||||
|
||||
/* Check for a valid IPv4 / IPv6 address */
|
||||
if (!(fProxyIpValid = LookupNumeric(strAddrProxy.c_str(), addrProxy)))
|
||||
{
|
||||
enableSaveButtons();
|
||||
ui->statusLabel->clear();
|
||||
disableOkButton();
|
||||
pUiProxyIp->setValid(false);
|
||||
ui->statusLabel->setStyleSheet("QLabel { color: red; }");
|
||||
ui->statusLabel->setText(tr("The supplied proxy address is invalid."));
|
||||
}
|
||||
else
|
||||
{
|
||||
disableSaveButtons();
|
||||
object->setValid(fProxyIpValid);
|
||||
ui->statusLabel->setStyleSheet("QLabel { color: red; }");
|
||||
ui->statusLabel->setText(tr("The supplied proxy address is invalid."));
|
||||
enableOkButton();
|
||||
ui->statusLabel->clear();
|
||||
}
|
||||
}
|
||||
|
||||
@ -282,9 +280,7 @@ bool OptionsDialog::eventFilter(QObject *object, QEvent *event)
|
||||
{
|
||||
if(object == ui->proxyIp)
|
||||
{
|
||||
CService addr;
|
||||
/* Check proxyIp for a valid IPv4/IPv6 address and emit the proxyIpValid signal */
|
||||
emit proxyIpValid(ui->proxyIp, LookupNumeric(ui->proxyIp->text().toStdString().c_str(), addr));
|
||||
emit proxyIpChecks(ui->proxyIp, ui->proxyPort->text().toInt());
|
||||
}
|
||||
}
|
||||
return QDialog::eventFilter(object, event);
|
||||
|
@ -31,35 +31,28 @@ protected:
|
||||
bool eventFilter(QObject *object, QEvent *event);
|
||||
|
||||
private slots:
|
||||
/* enable only apply button */
|
||||
void enableApplyButton();
|
||||
/* disable only apply button */
|
||||
void disableApplyButton();
|
||||
/* enable apply button and OK button */
|
||||
void enableSaveButtons();
|
||||
/* disable apply button and OK button */
|
||||
void disableSaveButtons();
|
||||
/* set apply button and OK button state (enabled / disabled) */
|
||||
void setSaveButtonState(bool fState);
|
||||
/* enable OK button */
|
||||
void enableOkButton();
|
||||
/* disable OK button */
|
||||
void disableOkButton();
|
||||
/* set OK button state (enabled / disabled) */
|
||||
void setOkButtonState(bool fState);
|
||||
void on_resetButton_clicked();
|
||||
void on_okButton_clicked();
|
||||
void on_cancelButton_clicked();
|
||||
void on_applyButton_clicked();
|
||||
|
||||
void showRestartWarning_Proxy();
|
||||
void showRestartWarning_Lang();
|
||||
void showRestartWarning(bool fPersistent = false);
|
||||
void clearStatusLabel();
|
||||
void updateDisplayUnit();
|
||||
void handleProxyIpValid(QValidatedLineEdit *object, bool fState);
|
||||
void doProxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPort);
|
||||
|
||||
signals:
|
||||
void proxyIpValid(QValidatedLineEdit *object, bool fValid);
|
||||
void proxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPort);
|
||||
|
||||
private:
|
||||
Ui::OptionsDialog *ui;
|
||||
OptionsModel *model;
|
||||
MonitoredDataMapper *mapper;
|
||||
bool fRestartWarningDisplayed_Proxy;
|
||||
bool fRestartWarningDisplayed_Lang;
|
||||
bool fProxyIpValid;
|
||||
};
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "walletdb.h"
|
||||
|
||||
#include <QSettings>
|
||||
#include <QStringList>
|
||||
|
||||
OptionsModel::OptionsModel(QObject *parent) :
|
||||
QAbstractListModel(parent)
|
||||
@ -25,79 +26,114 @@ OptionsModel::OptionsModel(QObject *parent) :
|
||||
Init();
|
||||
}
|
||||
|
||||
bool static ApplyProxySettings()
|
||||
{
|
||||
QSettings settings;
|
||||
CService addrProxy(settings.value("addrProxy", "127.0.0.1:9050").toString().toStdString());
|
||||
int nSocksVersion(settings.value("nSocksVersion", 5).toInt());
|
||||
if (!settings.value("fUseProxy", false).toBool()) {
|
||||
addrProxy = CService();
|
||||
nSocksVersion = 0;
|
||||
return false;
|
||||
}
|
||||
if (nSocksVersion && !addrProxy.IsValid())
|
||||
return false;
|
||||
if (!IsLimited(NET_IPV4))
|
||||
SetProxy(NET_IPV4, addrProxy, nSocksVersion);
|
||||
if (nSocksVersion > 4) {
|
||||
#ifdef USE_IPV6
|
||||
if (!IsLimited(NET_IPV6))
|
||||
SetProxy(NET_IPV6, addrProxy, nSocksVersion);
|
||||
#endif
|
||||
SetNameProxy(addrProxy, nSocksVersion);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Writes all missing QSettings with their default values
|
||||
void OptionsModel::Init()
|
||||
{
|
||||
QSettings settings;
|
||||
|
||||
// Ensure restart flag is unset on client startup
|
||||
setRestartRequired(false);
|
||||
|
||||
// These are Qt-only settings:
|
||||
nDisplayUnit = settings.value("nDisplayUnit", BitcoinUnits::BTC).toInt();
|
||||
|
||||
// Window
|
||||
if (!settings.contains("fMinimizeToTray"))
|
||||
settings.setValue("fMinimizeToTray", false);
|
||||
fMinimizeToTray = settings.value("fMinimizeToTray").toBool();
|
||||
|
||||
if (!settings.contains("fMinimizeOnClose"))
|
||||
settings.setValue("fMinimizeOnClose", false);
|
||||
fMinimizeOnClose = settings.value("fMinimizeOnClose").toBool();
|
||||
|
||||
// Display
|
||||
if (!settings.contains("nDisplayUnit"))
|
||||
settings.setValue("nDisplayUnit", BitcoinUnits::BTC);
|
||||
nDisplayUnit = settings.value("nDisplayUnit").toInt();
|
||||
|
||||
if (!settings.contains("bDisplayAddresses"))
|
||||
settings.setValue("bDisplayAddresses", false);
|
||||
bDisplayAddresses = settings.value("bDisplayAddresses", false).toBool();
|
||||
fMinimizeToTray = settings.value("fMinimizeToTray", false).toBool();
|
||||
fMinimizeOnClose = settings.value("fMinimizeOnClose", false).toBool();
|
||||
nTransactionFee = settings.value("nTransactionFee").toLongLong();
|
||||
language = settings.value("language", "").toString();
|
||||
|
||||
if (!settings.contains("fCoinControlFeatures"))
|
||||
settings.setValue("fCoinControlFeatures", false);
|
||||
fCoinControlFeatures = settings.value("fCoinControlFeatures", false).toBool();
|
||||
|
||||
// These are shared with core Bitcoin; we want
|
||||
// command-line options to override the GUI settings:
|
||||
if (settings.contains("fUseUPnP"))
|
||||
SoftSetBoolArg("-upnp", settings.value("fUseUPnP").toBool());
|
||||
if (settings.contains("addrProxy") && settings.value("fUseProxy").toBool())
|
||||
SoftSetArg("-proxy", settings.value("addrProxy").toString().toStdString());
|
||||
if (settings.contains("nSocksVersion") && settings.value("fUseProxy").toBool())
|
||||
SoftSetArg("-socks", settings.value("nSocksVersion").toString().toStdString());
|
||||
if (!language.isEmpty())
|
||||
SoftSetArg("-lang", language.toStdString());
|
||||
// These are shared with the core or have a command-line parameter
|
||||
// and we want command-line parameters to overwrite the GUI settings.
|
||||
//
|
||||
// If setting doesn't exist create it with defaults.
|
||||
//
|
||||
// If SoftSetArg() or SoftSetBoolArg() return false we were overridden
|
||||
// by command-line and show this in the UI.
|
||||
|
||||
// Main
|
||||
if (!settings.contains("nTransactionFee"))
|
||||
settings.setValue("nTransactionFee", 0);
|
||||
|
||||
if (!settings.contains("nDatabaseCache"))
|
||||
settings.setValue("nDatabaseCache", 25);
|
||||
if (!SoftSetArg("-dbcache", settings.value("nDatabaseCache").toString().toStdString()))
|
||||
strOverriddenByCommandLine += "-dbcache ";
|
||||
|
||||
if (!settings.contains("nThreadsScriptVerif"))
|
||||
settings.setValue("nThreadsScriptVerif", 0);
|
||||
if (!SoftSetArg("-par", settings.value("nThreadsScriptVerif").toString().toStdString()))
|
||||
strOverriddenByCommandLine += "-par ";
|
||||
|
||||
// Network
|
||||
if (!settings.contains("fUseUPnP"))
|
||||
#ifdef USE_UPNP
|
||||
settings.setValue("fUseUPnP", true);
|
||||
#else
|
||||
settings.setValue("fUseUPnP", false);
|
||||
#endif
|
||||
if (!SoftSetBoolArg("-upnp", settings.value("fUseUPnP").toBool()))
|
||||
strOverriddenByCommandLine += "-upnp ";
|
||||
|
||||
if (!settings.contains("fUseProxy"))
|
||||
settings.setValue("fUseProxy", false);
|
||||
if (!settings.contains("addrProxy"))
|
||||
settings.setValue("addrProxy", "127.0.0.1:9050");
|
||||
// Only try to set -proxy, if user has enabled fUseProxy
|
||||
if (settings.value("fUseProxy").toBool() && !SoftSetArg("-proxy", settings.value("addrProxy").toString().toStdString()))
|
||||
strOverriddenByCommandLine += "-proxy ";
|
||||
if (!settings.contains("nSocksVersion"))
|
||||
settings.setValue("nSocksVersion", 5);
|
||||
// Only try to set -socks, if user has enabled fUseProxy
|
||||
if (settings.value("fUseProxy").toBool() && !SoftSetArg("-socks", settings.value("nSocksVersion").toString().toStdString()))
|
||||
strOverriddenByCommandLine += "-socks ";
|
||||
|
||||
// Display
|
||||
if (!settings.contains("language"))
|
||||
settings.setValue("language", "");
|
||||
if (!SoftSetArg("-lang", settings.value("language").toString().toStdString()))
|
||||
strOverriddenByCommandLine += "-lang";
|
||||
|
||||
language = settings.value("language").toString();
|
||||
}
|
||||
|
||||
void OptionsModel::Reset()
|
||||
{
|
||||
QSettings settings;
|
||||
|
||||
// Remove all entries in this QSettings object
|
||||
// Remove all entries from our QSettings object
|
||||
settings.clear();
|
||||
|
||||
// default setting for OptionsModel::StartAtStartup - disabled
|
||||
if (GUIUtil::GetStartOnSystemStartup())
|
||||
GUIUtil::SetStartOnSystemStartup(false);
|
||||
|
||||
// Re-Init to get default values
|
||||
Init();
|
||||
|
||||
// Ensure Upgrade() is not running again by setting the bImportFinished flag
|
||||
settings.setValue("bImportFinished", true);
|
||||
}
|
||||
|
||||
bool OptionsModel::Upgrade()
|
||||
void OptionsModel::Upgrade()
|
||||
{
|
||||
QSettings settings;
|
||||
|
||||
// Already upgraded
|
||||
if (settings.contains("bImportFinished"))
|
||||
return false; // Already upgraded
|
||||
return;
|
||||
|
||||
settings.setValue("bImportFinished", true);
|
||||
|
||||
@ -145,18 +181,16 @@ bool OptionsModel::Upgrade()
|
||||
walletdb.EraseSetting("addrProxy");
|
||||
}
|
||||
}
|
||||
ApplyProxySettings();
|
||||
|
||||
Init();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int OptionsModel::rowCount(const QModelIndex & parent) const
|
||||
{
|
||||
return OptionIDRowCount;
|
||||
}
|
||||
|
||||
// read QSettings values and return them
|
||||
QVariant OptionsModel::data(const QModelIndex & index, int role) const
|
||||
{
|
||||
if(role == Qt::EditRole)
|
||||
@ -165,52 +199,55 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
|
||||
switch(index.row())
|
||||
{
|
||||
case StartAtStartup:
|
||||
return QVariant(GUIUtil::GetStartOnSystemStartup());
|
||||
return GUIUtil::GetStartOnSystemStartup();
|
||||
case MinimizeToTray:
|
||||
return QVariant(fMinimizeToTray);
|
||||
return fMinimizeToTray;
|
||||
case MapPortUPnP:
|
||||
#ifdef USE_UPNP
|
||||
return settings.value("fUseUPnP", GetBoolArg("-upnp", true));
|
||||
return settings.value("fUseUPnP");
|
||||
#else
|
||||
return QVariant(false);
|
||||
return false;
|
||||
#endif
|
||||
case MinimizeOnClose:
|
||||
return QVariant(fMinimizeOnClose);
|
||||
case ProxyUse: {
|
||||
proxyType proxy;
|
||||
return QVariant(GetProxy(NET_IPV4, proxy));
|
||||
}
|
||||
return fMinimizeOnClose;
|
||||
|
||||
// default proxy
|
||||
case ProxyUse:
|
||||
return settings.value("fUseProxy", false);
|
||||
case ProxyIP: {
|
||||
proxyType proxy;
|
||||
if (GetProxy(NET_IPV4, proxy))
|
||||
return QVariant(QString::fromStdString(proxy.first.ToStringIP()));
|
||||
else
|
||||
return QVariant(QString::fromStdString("127.0.0.1"));
|
||||
// contains IP at index 0 and port at index 1
|
||||
QStringList strlIpPort = settings.value("addrProxy").toString().split(":", QString::SkipEmptyParts);
|
||||
return strlIpPort.at(0);
|
||||
}
|
||||
case ProxyPort: {
|
||||
proxyType proxy;
|
||||
if (GetProxy(NET_IPV4, proxy))
|
||||
return QVariant(proxy.first.GetPort());
|
||||
else
|
||||
return QVariant(9050);
|
||||
}
|
||||
case ProxySocksVersion: {
|
||||
proxyType proxy;
|
||||
if (GetProxy(NET_IPV4, proxy))
|
||||
return QVariant(proxy.second);
|
||||
else
|
||||
return QVariant(5);
|
||||
// contains IP at index 0 and port at index 1
|
||||
QStringList strlIpPort = settings.value("addrProxy").toString().split(":", QString::SkipEmptyParts);
|
||||
return strlIpPort.at(1);
|
||||
}
|
||||
case ProxySocksVersion:
|
||||
return settings.value("nSocksVersion", 5);
|
||||
|
||||
case Fee:
|
||||
return QVariant((qint64) nTransactionFee);
|
||||
// Attention: Init() is called before nTransactionFee is set in AppInit2()!
|
||||
// To ensure we can change the fee on-the-fly update our QSetting when
|
||||
// opening OptionsDialog, which queries Fee via the mapper.
|
||||
if (nTransactionFee != settings.value("nTransactionFee").toLongLong())
|
||||
settings.setValue("nTransactionFee", (qint64)nTransactionFee);
|
||||
// Todo: Consider to revert back to use just nTransactionFee here, if we don't want
|
||||
// -paytxfee to update our QSettings!
|
||||
return settings.value("nTransactionFee");
|
||||
case DisplayUnit:
|
||||
return QVariant(nDisplayUnit);
|
||||
return nDisplayUnit;
|
||||
case DisplayAddresses:
|
||||
return QVariant(bDisplayAddresses);
|
||||
return bDisplayAddresses;
|
||||
case Language:
|
||||
return settings.value("language", "");
|
||||
return settings.value("language");
|
||||
case CoinControlFeatures:
|
||||
return QVariant(fCoinControlFeatures);
|
||||
return fCoinControlFeatures;
|
||||
case DatabaseCache:
|
||||
return settings.value("nDatabaseCache");
|
||||
case ThreadsScriptVerif:
|
||||
return settings.value("nThreadsScriptVerif");
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
@ -218,6 +255,7 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
// write QSettings values
|
||||
bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, int role)
|
||||
{
|
||||
bool successful = true; /* set to false on parse error */
|
||||
@ -233,7 +271,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
|
||||
fMinimizeToTray = value.toBool();
|
||||
settings.setValue("fMinimizeToTray", fMinimizeToTray);
|
||||
break;
|
||||
case MapPortUPnP:
|
||||
case MapPortUPnP: // core option - can be changed on-the-fly
|
||||
settings.setValue("fUseUPnP", value.toBool());
|
||||
MapPort(value.toBool());
|
||||
break;
|
||||
@ -241,44 +279,50 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
|
||||
fMinimizeOnClose = value.toBool();
|
||||
settings.setValue("fMinimizeOnClose", fMinimizeOnClose);
|
||||
break;
|
||||
|
||||
// default proxy
|
||||
case ProxyUse:
|
||||
settings.setValue("fUseProxy", value.toBool());
|
||||
successful = ApplyProxySettings();
|
||||
if (settings.value("fUseProxy") != value) {
|
||||
settings.setValue("fUseProxy", value.toBool());
|
||||
setRestartRequired(true);
|
||||
}
|
||||
break;
|
||||
case ProxyIP: {
|
||||
proxyType proxy;
|
||||
proxy.first = CService("127.0.0.1", 9050);
|
||||
GetProxy(NET_IPV4, proxy);
|
||||
|
||||
CNetAddr addr(value.toString().toStdString());
|
||||
proxy.first.SetIP(addr);
|
||||
settings.setValue("addrProxy", proxy.first.ToStringIPPort().c_str());
|
||||
successful = ApplyProxySettings();
|
||||
// contains current IP at index 0 and current port at index 1
|
||||
QStringList strlIpPort = settings.value("addrProxy").toString().split(":", QString::SkipEmptyParts);
|
||||
// if that key doesn't exist or has a changed IP
|
||||
if (!settings.contains("addrProxy") || strlIpPort.at(0) != value.toString()) {
|
||||
// construct new value from new IP and current port
|
||||
QString strNewValue = value.toString() + ":" + strlIpPort.at(1);
|
||||
settings.setValue("addrProxy", strNewValue);
|
||||
setRestartRequired(true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ProxyPort: {
|
||||
proxyType proxy;
|
||||
proxy.first = CService("127.0.0.1", 9050);
|
||||
GetProxy(NET_IPV4, proxy);
|
||||
|
||||
proxy.first.SetPort(value.toInt());
|
||||
settings.setValue("addrProxy", proxy.first.ToStringIPPort().c_str());
|
||||
successful = ApplyProxySettings();
|
||||
// contains current IP at index 0 and current port at index 1
|
||||
QStringList strlIpPort = settings.value("addrProxy").toString().split(":", QString::SkipEmptyParts);
|
||||
// if that key doesn't exist or has a changed port
|
||||
if (!settings.contains("addrProxy") || strlIpPort.at(1) != value.toString()) {
|
||||
// construct new value from current IP and new port
|
||||
QString strNewValue = strlIpPort.at(0) + ":" + value.toString();
|
||||
settings.setValue("addrProxy", strNewValue);
|
||||
setRestartRequired(true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ProxySocksVersion: {
|
||||
proxyType proxy;
|
||||
proxy.second = 5;
|
||||
GetProxy(NET_IPV4, proxy);
|
||||
|
||||
proxy.second = value.toInt();
|
||||
settings.setValue("nSocksVersion", proxy.second);
|
||||
successful = ApplyProxySettings();
|
||||
if (settings.value("nSocksVersion") != value) {
|
||||
settings.setValue("nSocksVersion", value.toInt());
|
||||
setRestartRequired(true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Fee:
|
||||
|
||||
case Fee: // core option - can be changed on-the-fly
|
||||
// Todo: Add is valid check and warn via message, if not
|
||||
nTransactionFee = value.toLongLong();
|
||||
settings.setValue("nTransactionFee", (qint64) nTransactionFee);
|
||||
settings.setValue("nTransactionFee", (qint64)nTransactionFee);
|
||||
emit transactionFeeChanged(nTransactionFee);
|
||||
break;
|
||||
case DisplayUnit:
|
||||
@ -291,13 +335,28 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
|
||||
settings.setValue("bDisplayAddresses", bDisplayAddresses);
|
||||
break;
|
||||
case Language:
|
||||
settings.setValue("language", value);
|
||||
if (settings.value("language") != value) {
|
||||
settings.setValue("language", value);
|
||||
setRestartRequired(true);
|
||||
}
|
||||
break;
|
||||
case CoinControlFeatures:
|
||||
fCoinControlFeatures = value.toBool();
|
||||
settings.setValue("fCoinControlFeatures", fCoinControlFeatures);
|
||||
emit coinControlFeaturesChanged(fCoinControlFeatures);
|
||||
break;
|
||||
case DatabaseCache:
|
||||
if (settings.value("nDatabaseCache") != value) {
|
||||
settings.setValue("nDatabaseCache", value);
|
||||
setRestartRequired(true);
|
||||
}
|
||||
break;
|
||||
case ThreadsScriptVerif:
|
||||
if (settings.value("nThreadsScriptVerif") != value) {
|
||||
settings.setValue("nThreadsScriptVerif", value);
|
||||
setRestartRequired(true);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -317,3 +376,15 @@ bool OptionsModel::getProxySettings(QString& proxyIP, quint16 &proxyPort) const
|
||||
proxyPort = addrProxy.GetPort();
|
||||
return true;
|
||||
}
|
||||
|
||||
void OptionsModel::setRestartRequired(bool fRequired)
|
||||
{
|
||||
QSettings settings;
|
||||
return settings.setValue("fRestartRequired", fRequired);
|
||||
}
|
||||
|
||||
bool OptionsModel::isRestartRequired()
|
||||
{
|
||||
QSettings settings;
|
||||
return settings.value("fRestartRequired", false).toBool();
|
||||
}
|
||||
|
@ -34,6 +34,8 @@ public:
|
||||
DisplayAddresses, // bool
|
||||
Language, // QString
|
||||
CoinControlFeatures, // bool
|
||||
ThreadsScriptVerif, // int
|
||||
DatabaseCache, // int
|
||||
OptionIDRowCount,
|
||||
};
|
||||
|
||||
@ -41,7 +43,7 @@ public:
|
||||
void Reset();
|
||||
|
||||
/* Migrate settings from wallet.dat after app initialization */
|
||||
bool Upgrade(); /* returns true if settings upgraded */
|
||||
void Upgrade();
|
||||
|
||||
int rowCount(const QModelIndex & parent = QModelIndex()) const;
|
||||
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
|
||||
@ -52,17 +54,24 @@ public:
|
||||
bool getMinimizeOnClose() { return fMinimizeOnClose; }
|
||||
int getDisplayUnit() { return nDisplayUnit; }
|
||||
bool getDisplayAddresses() { return bDisplayAddresses; }
|
||||
QString getLanguage() { return language; }
|
||||
bool getProxySettings(QString& proxyIP, quint16 &proxyPort) const;
|
||||
bool getCoinControlFeatures() { return fCoinControlFeatures; }
|
||||
const QString& getOverriddenByCommandLine() { return strOverriddenByCommandLine; }
|
||||
|
||||
/* Restart flag helper */
|
||||
void setRestartRequired(bool fRequired);
|
||||
bool isRestartRequired();
|
||||
|
||||
private:
|
||||
int nDisplayUnit;
|
||||
bool bDisplayAddresses;
|
||||
/* Qt-only settings */
|
||||
bool fMinimizeToTray;
|
||||
bool fMinimizeOnClose;
|
||||
QString language;
|
||||
int nDisplayUnit;
|
||||
bool bDisplayAddresses;
|
||||
bool fCoinControlFeatures;
|
||||
/* settings that were overriden by command-line */
|
||||
QString strOverriddenByCommandLine;
|
||||
|
||||
signals:
|
||||
void displayUnitChanged(int unit);
|
||||
|
Loading…
Reference in New Issue
Block a user