#include <QMessageBox>
#include <QRegExp>
#include <QRegExpValidator>
+#include <QKeyEvent>
+#include <QFileDialog>
+
+#if QT_VERSION < 0x050000
+#include <QDesktopServices>
+#else
+#include <QStandardPaths>
+#endif
OptionsDialog::OptionsDialog(QWidget *parent) :
- QDialog(parent, DIALOGWINDOWHINTS),
+ QWidget(parent, DIALOGWINDOWHINTS),
ui(new Ui::OptionsDialog),
model(0),
mapper(0),
fRestartWarningDisplayed_Proxy(false),
+ fRestartWarningDisplayed_Tor(false),
fRestartWarningDisplayed_Lang(false),
fRestartWarningDisplayed_URL(false),
- fProxyIpValid(true)
+ fProxyIpValid(true),
+ fTorIpValid(true)
{
ui->setupUi(this);
/* Network elements init */
-#ifndef USE_UPNP
- ui->mapPortUpnp->setEnabled(false);
-#endif
-
ui->proxyIp->setEnabled(false);
ui->proxyPort->setEnabled(false);
ui->proxyPort->setValidator(new QIntValidator(1, 65535, this));
+ ui->torIp->setEnabled(false);
+ ui->torPort->setEnabled(false);
+ ui->torPort->setValidator(new QIntValidator(1, 65535, this));
+ ui->TorOnly->setEnabled(false);
+ ui->torName->setEnabled(false);
+
ui->socksVersion->setEnabled(false);
ui->socksVersion->addItem("5", 5);
ui->socksVersion->addItem("4", 4);
connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->socksVersion, SLOT(setEnabled(bool)));
connect(ui->connectSocks, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning_Proxy()));
+ connect(ui->connectTor, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning_Tor()));
+ connect(ui->connectTor, SIGNAL(toggled(bool)), ui->torIp, SLOT(setEnabled(bool)));
+ connect(ui->connectTor, SIGNAL(toggled(bool)), ui->torPort, SLOT(setEnabled(bool)));
+ connect(ui->connectTor, SIGNAL(toggled(bool)), ui->TorOnly, SLOT(setEnabled(bool)));
+ connect(ui->connectTor, SIGNAL(toggled(bool)), ui->torName, SLOT(setEnabled(bool)));
+ connect(ui->TorOnly, SIGNAL(toggled(bool)), ui->connectSocks, SLOT(setDisabled(bool)));
+
ui->proxyIp->installEventFilter(this);
+ ui->torIp->installEventFilter(this);
/* Window elements init */
#ifdef Q_OS_MAC
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)));
+ /* setup/change UI elements when Tor IP is invalid/valid */
+ connect(this, SIGNAL(torIpValid(QValidatedLineEdit *, bool)), this, SLOT(handleTorIpValid(QValidatedLineEdit *, bool)));
}
OptionsDialog::~OptionsDialog()
mapper->addMapping(ui->detachDatabases, OptionsModel::DetachDatabases);
/* Network */
- mapper->addMapping(ui->mapPortUpnp, OptionsModel::MapPortUPnP);
-
mapper->addMapping(ui->connectSocks, OptionsModel::ProxyUse);
mapper->addMapping(ui->proxyIp, OptionsModel::ProxyIP);
mapper->addMapping(ui->proxyPort, OptionsModel::ProxyPort);
mapper->addMapping(ui->socksVersion, OptionsModel::ProxySocksVersion);
+ mapper->addMapping(ui->connectTor, OptionsModel::TorUse);
+ mapper->addMapping(ui->torIp, OptionsModel::TorIP);
+ mapper->addMapping(ui->torPort, OptionsModel::TorPort);
+ mapper->addMapping(ui->TorOnly, OptionsModel::TorOnly);
+ mapper->addMapping(ui->torName, OptionsModel::TorName);
+ mapper->addMapping(ui->externalSeederCommand, OptionsModel::ExternalSeeder);
+
+
/* Window */
#ifndef Q_OS_MAC
mapper->addMapping(ui->minimizeToTray, OptionsModel::MinimizeToTray);
void OptionsDialog::enableSaveButtons()
{
/* prevent enabling of the save buttons when data modified, if there is an invalid proxy address present */
- if(fProxyIpValid)
+ if(fProxyIpValid && fTorIpValid)
setSaveButtonState(true);
}
void OptionsDialog::on_okButton_clicked()
{
mapper->submit();
- accept();
+// accept();
+ close();
}
void OptionsDialog::on_cancelButton_clicked()
{
- reject();
+// reject();
+ close();
}
void OptionsDialog::on_applyButton_clicked()
}
}
+void OptionsDialog::showRestartWarning_Tor()
+{
+ if(!fRestartWarningDisplayed_Proxy)
+ {
+ QMessageBox::warning(this, tr("Warning"), tr("This setting will take effect after restarting NovaCoin."), QMessageBox::Ok);
+ fRestartWarningDisplayed_Tor = true;
+ }
+}
+
void OptionsDialog::showRestartWarning_Lang()
{
if(!fRestartWarningDisplayed_Lang)
}
}
+void OptionsDialog::handleTorIpValid(QValidatedLineEdit *object, bool fState)
+{
+ // this is used in a check before re-enabling the save buttons
+ fTorIpValid = fState;
+
+ if(fTorIpValid)
+ {
+ enableSaveButtons();
+ ui->statusLabel->clear();
+ }
+ else
+ {
+ disableSaveButtons();
+ object->setValid(fTorIpValid);
+ ui->statusLabel->setStyleSheet("QLabel { color: red; }");
+ ui->statusLabel->setText(tr("The supplied tor address is invalid."));
+ }
+}
+
bool OptionsDialog::eventFilter(QObject *object, QEvent *event)
{
if(event->type() == QEvent::FocusOut)
/* 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));
}
+
+ if(object == ui->torIp)
+ {
+ CService addr;
+ /* Check proxyIp for a valid IPv4/IPv6 address and emit the torIpValid signal */
+ emit torIpValid(ui->torIp, LookupNumeric(ui->torIp->text().toStdString().c_str(), addr));
+ }
+ }
+ return QWidget::eventFilter(object, event);
+}
+
+void OptionsDialog::keyPressEvent(QKeyEvent *event)
+{
+#ifdef ANDROID
+ if(windowType() != Qt::Widget && event->key() == Qt::Key_Back)
+ {
+ close();
+ }
+#else
+ if(windowType() != Qt::Widget && event->key() == Qt::Key_Escape)
+ {
+ close();
+ }
+#endif
+}
+void OptionsDialog::on_chooseSeeder_clicked()
+{
+#if QT_VERSION < 0x050000
+ QString openDir = QDesktopServices::storageLocation(QDesktopServices::ApplicationsLocation);
+#else
+ QString openDir = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation);
+#endif
+
+ QString filename = QFileDialog::getOpenFileName(this, tr("Choose peer collector application"), openDir, tr("Applications (*.*)"));
+ if(!filename.isEmpty()) {
+ ui->externalSeederCommand->setText(filename);
}
- return QDialog::eventFilter(object, event);
}