nextcloud-desktop/src/mirall/proxydialog.cpp

105 lines
3.1 KiB
C++
Raw Normal View History

/*
* Copyright (C) by Thomas Mueller <thomas.mueller@tmit.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include <QNetworkProxy>
#include "proxydialog.h"
#include "mirallconfigfile.h"
Mirall::ProxyDialog::ProxyDialog( QWidget* parent )
: QDialog(parent)
{
setupUi(this);
2012-07-31 12:43:38 +04:00
// designer is buggy, so do it programmatically
manualSettings->setEnabled(false);
2012-07-31 12:43:38 +04:00
#if QT_VERSION >= 0x040700
hostLineEdit->setPlaceholderText(tr("Hostname of proxy server"));
userLineEdit->setPlaceholderText(tr("Username for proxy server"));
passwordLineEdit->setPlaceholderText(tr("Password for proxy server"));
2012-07-31 12:43:38 +04:00
#endif
// load current proxy settings
Mirall::MirallConfigFile cfgFile;
if (cfgFile.proxyType() == QNetworkProxy::NoProxy)
noProxyRadioButton->setChecked(true);
if (cfgFile.proxyType() == QNetworkProxy::DefaultProxy)
systemProxyRadioButton->setChecked(true);
if (cfgFile.proxyType() == QNetworkProxy::Socks5Proxy)
{
manualProxyRadioButton->setChecked(true);
hostLineEdit->setText(cfgFile.proxyHostName());
portSpinBox->setValue(cfgFile.proxyPort());
if (!cfgFile.proxyUser().isEmpty())
{
authRequiredcheckBox->setChecked(true);
userLineEdit->setText(cfgFile.proxyUser());
passwordLineEdit->setText(cfgFile.proxyPassword());
}
}
}
void Mirall::ProxyDialog::saveSettings()
{
Mirall::MirallConfigFile cfgFile;
if (noProxyRadioButton->isChecked())
{
cfgFile.setProxyType(QNetworkProxy::NoProxy);
}
if (systemProxyRadioButton->isChecked())
{
cfgFile.setProxyType(QNetworkProxy::DefaultProxy);
}
if (manualProxyRadioButton->isChecked())
{
if (authRequiredcheckBox->isChecked())
{
QString user = userLineEdit->text();
QString pass = passwordLineEdit->text();
2012-08-17 19:13:17 +04:00
cfgFile.setProxyType(QNetworkProxy::Socks5Proxy, hostLineEdit->text(),
portSpinBox->value(), user, pass);
}
else
{
2012-08-17 19:13:17 +04:00
cfgFile.setProxyType(QNetworkProxy::Socks5Proxy, hostLineEdit->text(),
portSpinBox->value(), QString::null, QString::null);
}
}
}
void Mirall::ProxyDialog::on_authRequiredcheckBox_stateChanged(int state)
{
bool e = (state == Qt::Checked);
userLineEdit->setEnabled(e);
passwordLineEdit->setEnabled(e);
proxyUserLabel->setEnabled(e);
proxyPasswordLabel->setEnabled(e);
}
void Mirall::ProxyDialog::on_manualProxyRadioButton_toggled(bool checked)
{
manualSettings->setEnabled(checked);
}
void Mirall::ProxyDialog::on_buttonBox_accepted()
{
saveSettings();
}