2011-05-12 14:49:42 +02:00
|
|
|
#include "optionsdialog.h"
|
2012-06-08 15:21:55 +02:00
|
|
|
#include "ui_optionsdialog.h"
|
|
|
|
|
2011-06-20 21:31:42 +02:00
|
|
|
#include "bitcoinamountfield.h"
|
2011-07-29 14:36:35 +02:00
|
|
|
#include "bitcoinunits.h"
|
2012-06-08 15:21:55 +02:00
|
|
|
#include "monitoreddatamapper.h"
|
|
|
|
#include "netbase.h"
|
|
|
|
#include "optionsmodel.h"
|
|
|
|
#include "qvalidatedlineedit.h"
|
2011-07-29 14:36:35 +02:00
|
|
|
#include "qvaluecombobox.h"
|
2011-05-12 14:44:52 +02:00
|
|
|
|
2011-06-01 14:40:06 +02:00
|
|
|
#include <QCheckBox>
|
2012-06-08 15:21:55 +02:00
|
|
|
#include <QDir>
|
|
|
|
#include <QIntValidator>
|
2011-06-01 14:40:06 +02:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
2012-06-25 22:36:16 +02:00
|
|
|
#include <QLocale>
|
2012-05-08 23:03:41 +02:00
|
|
|
#include <QMessageBox>
|
2012-06-08 15:21:55 +02:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QRegExp>
|
|
|
|
#include <QRegExpValidator>
|
|
|
|
#include <QTabWidget>
|
|
|
|
#include <QWidget>
|
2011-06-01 14:40:06 +02:00
|
|
|
|
2012-06-08 15:21:55 +02:00
|
|
|
OptionsDialog::OptionsDialog(QWidget *parent) :
|
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::OptionsDialog),
|
|
|
|
model(0),
|
|
|
|
mapper(0),
|
|
|
|
fRestartWarningDisplayed_Proxy(false),
|
|
|
|
fRestartWarningDisplayed_Lang(false),
|
|
|
|
fProxyIpValid(true)
|
2012-05-07 21:49:22 +02:00
|
|
|
{
|
2012-06-08 15:21:55 +02:00
|
|
|
ui->setupUi(this);
|
2012-05-07 21:49:22 +02:00
|
|
|
|
2012-06-08 15:21:55 +02:00
|
|
|
/* Network elements init */
|
|
|
|
#ifndef USE_UPNP
|
|
|
|
ui->mapPortUpnp->setEnabled(false);
|
2011-10-07 13:21:45 +02:00
|
|
|
#endif
|
2011-07-25 21:35:45 +02:00
|
|
|
|
2012-06-08 15:21:55 +02:00
|
|
|
ui->socksVersion->setEnabled(false);
|
|
|
|
ui->socksVersion->addItem("5", 5);
|
|
|
|
ui->socksVersion->addItem("4", 4);
|
|
|
|
ui->socksVersion->setCurrentIndex(0);
|
2012-05-07 21:49:22 +02:00
|
|
|
|
2012-06-08 15:21:55 +02:00
|
|
|
ui->proxyIp->setEnabled(false);
|
|
|
|
ui->proxyPort->setEnabled(false);
|
|
|
|
ui->proxyPort->setValidator(new QIntValidator(0, 65535, this));
|
2011-09-19 12:40:23 +02:00
|
|
|
|
2012-06-08 15:21:55 +02:00
|
|
|
connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->socksVersion, SLOT(setEnabled(bool)));
|
|
|
|
connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->proxyIp, SLOT(setEnabled(bool)));
|
|
|
|
connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->proxyPort, SLOT(setEnabled(bool)));
|
2011-05-12 14:44:52 +02:00
|
|
|
|
2012-06-08 15:21:55 +02:00
|
|
|
ui->proxyIp->installEventFilter(this);
|
2011-05-12 14:44:52 +02:00
|
|
|
|
2012-06-08 15:21:55 +02:00
|
|
|
/* Window elements init */
|
|
|
|
#ifdef Q_WS_MAC
|
|
|
|
ui->tabWindow->setVisible(false);
|
2012-05-10 15:33:01 +02:00
|
|
|
#endif
|
2011-07-25 21:35:45 +02:00
|
|
|
|
2012-06-08 15:21:55 +02:00
|
|
|
/* Display elements init */
|
|
|
|
QDir translations(":translations");
|
|
|
|
ui->lang->addItem(QString("(") + tr("default") + QString(")"), QVariant(""));
|
|
|
|
foreach(const QString &langStr, translations.entryList())
|
2012-05-07 21:49:22 +02:00
|
|
|
{
|
2012-06-25 22:36:16 +02:00
|
|
|
QLocale locale(langStr);
|
|
|
|
|
|
|
|
/** check if the locale name consists of 2 parts (language_country) */
|
|
|
|
if(langStr.contains("_"))
|
|
|
|
{
|
2012-07-13 07:43:41 +02:00
|
|
|
#if QT_VERSION >= 0x040800
|
|
|
|
/** display language strings as "native language - native country (locale name)", e.g. "Deutsch - Deutschland (de)" */
|
|
|
|
ui->lang->addItem(locale.nativeLanguageName() + QString(" - ") + locale.nativeCountryName() + QString(" (") + langStr + QString(")"), QVariant(langStr));
|
|
|
|
#else
|
2012-06-25 22:36:16 +02:00
|
|
|
/** display language strings as "language - country (locale name)", e.g. "German - Germany (de)" */
|
|
|
|
ui->lang->addItem(QLocale::languageToString(locale.language()) + QString(" - ") + QLocale::countryToString(locale.country()) + QString(" (") + langStr + QString(")"), QVariant(langStr));
|
2012-07-13 07:43:41 +02:00
|
|
|
#endif
|
2012-06-25 22:36:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-13 07:43:41 +02:00
|
|
|
#if QT_VERSION >= 0x040800
|
|
|
|
/** display language strings as "native language (locale name)", e.g. "Deutsch (de)" */
|
|
|
|
ui->lang->addItem(locale.nativeLanguageName() + QString(" (") + langStr + QString(")"), QVariant(langStr));
|
|
|
|
#else
|
2012-06-25 22:36:16 +02:00
|
|
|
/** display language strings as "language (locale name)", e.g. "German (de)" */
|
|
|
|
ui->lang->addItem(QLocale::languageToString(locale.language()) + QString(" (") + langStr + QString(")"), QVariant(langStr));
|
2012-07-13 07:43:41 +02:00
|
|
|
#endif
|
2012-06-25 22:36:16 +02:00
|
|
|
}
|
2012-05-07 21:49:22 +02:00
|
|
|
}
|
2011-05-12 14:44:52 +02:00
|
|
|
|
2012-06-08 15:21:55 +02:00
|
|
|
ui->unit->setModel(new BitcoinUnits(this));
|
2011-05-12 14:44:52 +02:00
|
|
|
|
2012-06-08 15:21:55 +02:00
|
|
|
connect(ui->connectSocks, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning_Proxy()));
|
|
|
|
connect(ui->lang, SIGNAL(activated(int)), this, SLOT(showRestartWarning_Lang()));
|
2011-05-12 14:44:52 +02:00
|
|
|
|
2011-06-01 09:33:48 +02:00
|
|
|
/* Widget-to-option mapper */
|
2011-06-01 14:40:06 +02:00
|
|
|
mapper = new MonitoredDataMapper(this);
|
2011-05-31 22:24:53 +02:00
|
|
|
mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
|
|
|
|
mapper->setOrientation(Qt::Vertical);
|
2012-06-08 15:21:55 +02:00
|
|
|
|
|
|
|
/* enable save buttons when data modified */
|
|
|
|
connect(mapper, SIGNAL(viewModified()), this, SLOT(enableSaveButtons()));
|
|
|
|
/* disable save buttons when new data loaded */
|
|
|
|
connect(mapper, SIGNAL(currentIndexChanged(int)), this, SLOT(disableSaveButtons()));
|
|
|
|
/* disable/enable save buttons when proxy IP is invalid/valid */
|
|
|
|
connect(this, SIGNAL(proxyIpValid(bool)), this, SLOT(setSaveButtonState(bool)));
|
|
|
|
}
|
|
|
|
|
|
|
|
OptionsDialog::~OptionsDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
2011-05-31 22:24:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void OptionsDialog::setModel(OptionsModel *model)
|
|
|
|
{
|
|
|
|
this->model = model;
|
|
|
|
|
2012-06-08 15:21:55 +02:00
|
|
|
if(model)
|
2012-05-07 21:49:22 +02:00
|
|
|
{
|
2012-06-08 15:21:55 +02:00
|
|
|
connect(model, SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
|
|
|
|
|
|
|
|
mapper->setModel(model);
|
|
|
|
setMapper();
|
|
|
|
mapper->toFirst();
|
2012-05-07 21:49:22 +02:00
|
|
|
}
|
2011-05-12 14:44:52 +02:00
|
|
|
|
2012-06-08 15:21:55 +02:00
|
|
|
// update the display unit, to not use the default ("BTC")
|
|
|
|
updateDisplayUnit();
|
2011-05-12 14:44:52 +02:00
|
|
|
}
|
|
|
|
|
2012-06-08 15:21:55 +02:00
|
|
|
void OptionsDialog::setMapper()
|
2011-05-12 14:44:52 +02:00
|
|
|
{
|
2012-06-08 15:21:55 +02:00
|
|
|
/* Main */
|
|
|
|
mapper->addMapping(ui->transactionFee, OptionsModel::Fee);
|
|
|
|
mapper->addMapping(ui->bitcoinAtStartup, OptionsModel::StartAtStartup);
|
|
|
|
mapper->addMapping(ui->detachDatabases, OptionsModel::DetachDatabases);
|
2011-06-01 09:33:48 +02:00
|
|
|
|
2012-06-08 15:21:55 +02:00
|
|
|
/* Network */
|
|
|
|
mapper->addMapping(ui->mapPortUpnp, OptionsModel::MapPortUPnP);
|
|
|
|
mapper->addMapping(ui->connectSocks, OptionsModel::ProxyUse);
|
|
|
|
mapper->addMapping(ui->socksVersion, OptionsModel::ProxySocksVersion);
|
|
|
|
mapper->addMapping(ui->proxyIp, OptionsModel::ProxyIP);
|
|
|
|
mapper->addMapping(ui->proxyPort, OptionsModel::ProxyPort);
|
2011-06-01 09:33:48 +02:00
|
|
|
|
2012-06-08 15:21:55 +02:00
|
|
|
/* Window */
|
|
|
|
#ifndef Q_WS_MAC
|
|
|
|
mapper->addMapping(ui->minimizeToTray, OptionsModel::MinimizeToTray);
|
|
|
|
mapper->addMapping(ui->minimizeOnClose, OptionsModel::MinimizeOnClose);
|
|
|
|
#endif
|
2011-06-01 09:33:48 +02:00
|
|
|
|
2012-06-08 15:21:55 +02:00
|
|
|
/* Display */
|
|
|
|
mapper->addMapping(ui->lang, OptionsModel::Language);
|
|
|
|
mapper->addMapping(ui->unit, OptionsModel::DisplayUnit);
|
|
|
|
mapper->addMapping(ui->displayAddresses, OptionsModel::DisplayAddresses);
|
2011-06-01 09:33:48 +02:00
|
|
|
}
|
|
|
|
|
2012-06-08 15:21:55 +02:00
|
|
|
void OptionsDialog::enableSaveButtons()
|
2011-06-01 09:33:48 +02:00
|
|
|
{
|
2012-06-08 15:21:55 +02:00
|
|
|
// prevent enabling of the save buttons when data modified, if there is an invalid proxy address present
|
|
|
|
if(fProxyIpValid)
|
|
|
|
setSaveButtonState(true);
|
2011-06-01 09:33:48 +02:00
|
|
|
}
|
2011-06-01 14:40:06 +02:00
|
|
|
|
2012-06-08 15:21:55 +02:00
|
|
|
void OptionsDialog::disableSaveButtons()
|
2011-06-01 14:40:06 +02:00
|
|
|
{
|
2012-06-08 15:21:55 +02:00
|
|
|
setSaveButtonState(false);
|
2011-06-01 14:40:06 +02:00
|
|
|
}
|
|
|
|
|
2012-06-08 15:21:55 +02:00
|
|
|
void OptionsDialog::setSaveButtonState(bool fState)
|
2012-05-07 21:49:22 +02:00
|
|
|
{
|
2012-06-08 15:21:55 +02:00
|
|
|
ui->applyButton->setEnabled(fState);
|
|
|
|
ui->okButton->setEnabled(fState);
|
2012-05-07 21:49:22 +02:00
|
|
|
}
|
|
|
|
|
2012-06-08 15:21:55 +02:00
|
|
|
void OptionsDialog::on_okButton_clicked()
|
2012-05-07 21:49:22 +02:00
|
|
|
{
|
2012-06-08 15:21:55 +02:00
|
|
|
mapper->submit();
|
|
|
|
accept();
|
2012-05-07 21:49:22 +02:00
|
|
|
}
|
|
|
|
|
2012-06-08 15:21:55 +02:00
|
|
|
void OptionsDialog::on_cancelButton_clicked()
|
2011-06-01 14:40:06 +02:00
|
|
|
{
|
2012-06-08 15:21:55 +02:00
|
|
|
reject();
|
2012-05-07 21:49:22 +02:00
|
|
|
}
|
|
|
|
|
2012-06-08 15:21:55 +02:00
|
|
|
void OptionsDialog::on_applyButton_clicked()
|
2012-05-07 21:49:22 +02:00
|
|
|
{
|
2012-06-08 15:21:55 +02:00
|
|
|
mapper->submit();
|
|
|
|
ui->applyButton->setEnabled(false);
|
2012-05-07 21:49:22 +02:00
|
|
|
}
|
|
|
|
|
2012-06-08 15:21:55 +02:00
|
|
|
void OptionsDialog::showRestartWarning_Proxy()
|
2012-05-08 23:03:41 +02:00
|
|
|
{
|
2012-06-08 15:21:55 +02:00
|
|
|
if(!fRestartWarningDisplayed_Proxy)
|
2012-05-08 23:03:41 +02:00
|
|
|
{
|
|
|
|
QMessageBox::warning(this, tr("Warning"), tr("This setting will take effect after restarting Bitcoin."), QMessageBox::Ok);
|
2012-06-08 15:21:55 +02:00
|
|
|
fRestartWarningDisplayed_Proxy = true;
|
2012-05-08 23:03:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-08 15:21:55 +02:00
|
|
|
void OptionsDialog::showRestartWarning_Lang()
|
2012-05-07 21:49:22 +02:00
|
|
|
{
|
2012-06-08 15:21:55 +02:00
|
|
|
if(!fRestartWarningDisplayed_Lang)
|
|
|
|
{
|
|
|
|
QMessageBox::warning(this, tr("Warning"), tr("This setting will take effect after restarting Bitcoin."), QMessageBox::Ok);
|
|
|
|
fRestartWarningDisplayed_Lang = true;
|
|
|
|
}
|
2012-05-07 21:49:22 +02:00
|
|
|
}
|
|
|
|
|
2012-06-08 15:21:55 +02:00
|
|
|
void OptionsDialog::updateDisplayUnit()
|
2012-05-07 21:49:22 +02:00
|
|
|
{
|
2012-06-08 15:21:55 +02:00
|
|
|
if(model)
|
|
|
|
{
|
|
|
|
// Update transactionFee with the current unit
|
|
|
|
ui->transactionFee->setDisplayUnit(model->getDisplayUnit());
|
|
|
|
}
|
2011-06-01 14:40:06 +02:00
|
|
|
}
|
|
|
|
|
2012-06-08 15:21:55 +02:00
|
|
|
bool OptionsDialog::eventFilter(QObject *object, QEvent *event)
|
2011-06-01 14:40:06 +02:00
|
|
|
{
|
2012-06-08 15:21:55 +02:00
|
|
|
if(object == ui->proxyIp && event->type() == QEvent::FocusOut)
|
|
|
|
{
|
|
|
|
// Check proxyIP for a valid IPv4/IPv6 address
|
|
|
|
CService addr;
|
|
|
|
if(!LookupNumeric(ui->proxyIp->text().toStdString().c_str(), addr))
|
|
|
|
{
|
|
|
|
ui->proxyIp->setValid(false);
|
|
|
|
fProxyIpValid = false;
|
|
|
|
ui->statusLabel->setStyleSheet("QLabel { color: red; }");
|
|
|
|
ui->statusLabel->setText(tr("The supplied proxy address is invalid."));
|
|
|
|
emit proxyIpValid(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fProxyIpValid = true;
|
|
|
|
ui->statusLabel->clear();
|
|
|
|
emit proxyIpValid(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QDialog::eventFilter(object, event);
|
2011-07-25 21:35:45 +02:00
|
|
|
}
|