File indexing completed on 2025-01-05 04:36:04
0001 /* 0002 kproxydlg.cpp - Proxy configuration dialog 0003 SPDX-FileCopyrightText: 2001, 2011 Dawit Alemayehu <adawit@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-only 0006 */ 0007 0008 // Own 0009 #include "kproxydlg.h" 0010 0011 // Local 0012 #include "../ksaveioconfig.h" 0013 0014 // KDE 0015 #include <KConfigGroup> 0016 #include <KLineEdit> // Needed for KUrlRequester::lineEdit() 0017 #include <KLocalizedString> 0018 #include <KPluginFactory> 0019 #include <kurifilter.h> 0020 0021 // Qt 0022 #include <QSpinBox> 0023 #include <QUrl> 0024 0025 K_PLUGIN_CLASS_WITH_JSON(KProxyDialog, "kcm_proxy.json") 0026 0027 class InputValidator : public QValidator 0028 { 0029 public: 0030 State validate(QString &input, int &pos) const override 0031 { 0032 if (input.isEmpty()) { 0033 return Acceptable; 0034 } 0035 0036 const QChar ch = input.at((pos > 0 ? pos - 1 : pos)); 0037 if (ch.isSpace()) { 0038 return Invalid; 0039 } 0040 0041 return Acceptable; 0042 } 0043 }; 0044 0045 static QString manualProxyToText(const QLineEdit *edit, const QSpinBox *spinBox, const QChar &separator) 0046 { 0047 const QString value = edit->text() + separator + QString::number(spinBox->value()); 0048 0049 return value; 0050 } 0051 0052 static void setManualProxyFromText(const QString &value, QLineEdit *edit, QSpinBox *spinBox) 0053 { 0054 if (value.isEmpty()) { 0055 return; 0056 } 0057 0058 const QStringList values = value.split(QLatin1Char(' ')); 0059 edit->setText(values.at(0)); 0060 bool ok = false; 0061 const int num = values.at(1).toInt(&ok); 0062 if (ok) { 0063 spinBox->setValue(num); 0064 } 0065 } 0066 0067 static void showSystemProxyUrl(QLineEdit *edit, QString *value) 0068 { 0069 Q_ASSERT(edit); 0070 Q_ASSERT(value); 0071 0072 *value = edit->text(); 0073 edit->setEnabled(false); 0074 const QByteArray envVar(edit->text().toUtf8()); 0075 edit->setText(QString::fromUtf8(qgetenv(envVar.constData()))); 0076 } 0077 0078 static QString proxyUrlFromInput(KProxyDialog::DisplayUrlFlags *flags, 0079 const QLineEdit *edit, 0080 const QSpinBox *spinBox, 0081 const QString &defaultScheme = QString(), 0082 KProxyDialog::DisplayUrlFlag flag = KProxyDialog::HideNone) 0083 { 0084 Q_ASSERT(edit); 0085 Q_ASSERT(spinBox); 0086 0087 QString proxyStr; 0088 0089 if (edit->text().isEmpty()) { 0090 return proxyStr; 0091 } 0092 0093 if (flags && !edit->text().contains(QLatin1String("://"))) { 0094 *flags |= flag; 0095 } 0096 0097 KUriFilterData data; 0098 data.setData(edit->text()); 0099 data.setCheckForExecutables(false); 0100 if (!defaultScheme.isEmpty()) { 0101 data.setDefaultUrlScheme(defaultScheme); 0102 } 0103 0104 if (KUriFilter::self()->filterUri(data, QStringList{QStringLiteral("kshorturifilter")})) { 0105 QUrl url = data.uri(); 0106 const int portNum = (spinBox->value() > 0 ? spinBox->value() : url.port()); 0107 url.setPort(-1); 0108 0109 proxyStr = url.url(); 0110 if (portNum > -1) { 0111 proxyStr += QLatin1Char(' ') + QString::number(portNum); 0112 } 0113 } else { 0114 proxyStr = edit->text(); 0115 if (spinBox->value() > 0) { 0116 proxyStr += QLatin1Char(' ') + QString::number(spinBox->value()); 0117 } 0118 } 0119 0120 return proxyStr; 0121 } 0122 0123 static void setProxyInformation(const QString &value, 0124 KSaveIOConfig::ProxyType proxyType, 0125 QLineEdit *manEdit, 0126 QLineEdit *sysEdit, 0127 QSpinBox *spinBox, 0128 const QString &defaultScheme, 0129 KProxyDialog::DisplayUrlFlag flag) 0130 { 0131 const bool isSysProxy = 0132 !value.contains(QLatin1Char(' ')) && !value.contains(QLatin1Char('.')) && !value.contains(QLatin1Char(',')) && !value.contains(QLatin1Char(':')); 0133 0134 if (proxyType == KSaveIOConfig::EnvVarProxy || isSysProxy) { 0135 #if defined(Q_OS_LINUX) || defined(Q_OS_UNIX) 0136 sysEdit->setText(value); 0137 #endif 0138 return; 0139 } 0140 0141 if (spinBox) { 0142 KUriFilterData data; 0143 data.setData(value); 0144 data.setCheckForExecutables(false); 0145 if (!defaultScheme.isEmpty()) { 0146 data.setDefaultUrlScheme(defaultScheme); 0147 } 0148 0149 QUrl url; 0150 if (KUriFilter::self()->filterUri(data, QStringList{QStringLiteral("kshorturifilter")})) { 0151 url = QUrl(data.uri()); 0152 url.setUserName(QString()); 0153 url.setPassword(QString()); 0154 url.setPath(QString()); 0155 } else { 0156 url = QUrl(value); 0157 } 0158 0159 if (url.port() > -1) { 0160 spinBox->setValue(url.port()); 0161 } 0162 url.setPort(-1); 0163 manEdit->setText((KSaveIOConfig::proxyDisplayUrlFlags() & flag) ? url.host() : url.url()); 0164 return; 0165 } 0166 0167 manEdit->setText(value); // Manual proxy exception... 0168 } 0169 0170 KProxyDialog::KProxyDialog(QObject *parent, const KPluginMetaData &data) 0171 : KCModule(parent, data) 0172 { 0173 mConfig = KSharedConfig::openConfig(QStringLiteral("kioslaverc"), KConfig::NoGlobals); 0174 0175 mUi.setupUi(widget()); 0176 0177 connect(mUi.autoDetectButton, &QPushButton::clicked, this, &KProxyDialog::autoDetect); 0178 connect(mUi.showEnvValueCheckBox, &QAbstractButton::toggled, this, &KProxyDialog::showEnvValue); 0179 connect(mUi.useSameProxyCheckBox, &QPushButton::clicked, this, &KProxyDialog::setUseSameProxy); 0180 connect(mUi.manualProxyHttpEdit, &QLineEdit::textChanged, this, [this](const QString &text) { 0181 mUi.useSameProxyCheckBox->setEnabled(!text.isEmpty()); 0182 }); 0183 connect(mUi.manualNoProxyEdit, &QLineEdit::textChanged, this, [this](const QString &text) { 0184 mUi.useReverseProxyCheckBox->setEnabled(!text.isEmpty()); 0185 }); 0186 connect(mUi.manualProxyHttpEdit, &QLineEdit::textEdited, this, &KProxyDialog::syncProxies); 0187 connect(mUi.manualProxyHttpSpinBox, qOverload<int>(&QSpinBox::valueChanged), this, &KProxyDialog::syncProxyPorts); 0188 0189 mUi.systemProxyGroupBox->setVisible(false); 0190 mUi.manualProxyGroupBox->setVisible(false); 0191 mUi.autoDetectButton->setVisible(false); 0192 mUi.proxyConfigScriptGroupBox->setVisible(false); 0193 0194 mUi.infoMessageWidget->setIcon(QIcon::fromTheme(QStringLiteral("dialog-warning"))); 0195 mUi.infoMessageWidget->setText(xi18nc("@info", 0196 "Not all applications will use this proxy setting. \ 0197 In particular, <application>Firefox</application> and <application>Chromium</application> or \ 0198 anything derived from them, or anything using <application>QtWebEngine</application> - which \ 0199 includes <application>Konqueror</application> using the <application>WebEnginePart</application>, \ 0200 <application>Akregator</application> and <application>Falkon</application> - will not use \ 0201 these settings. Some applications may allow the proxy to be configured in their own settings.")); 0202 0203 InputValidator *v = new InputValidator; 0204 mUi.proxyScriptUrlRequester->lineEdit()->setValidator(v); 0205 mUi.manualProxyHttpEdit->setValidator(v); 0206 mUi.manualProxyHttpsEdit->setValidator(v); 0207 mUi.manualProxyFtpEdit->setValidator(v); 0208 mUi.manualProxySocksEdit->setValidator(v); 0209 mUi.manualNoProxyEdit->setValidator(v); 0210 0211 // Signals and slots connections 0212 connect(mUi.noProxyRadioButton, &QPushButton::clicked, this, &KProxyDialog::slotChanged); 0213 connect(mUi.autoDiscoverProxyRadioButton, &QPushButton::clicked, this, &KProxyDialog::slotChanged); 0214 connect(mUi.autoScriptProxyRadioButton, &QPushButton::clicked, this, &KProxyDialog::slotChanged); 0215 connect(mUi.manualProxyRadioButton, &QPushButton::clicked, this, &KProxyDialog::slotChanged); 0216 connect(mUi.noProxyRadioButton, &QPushButton::clicked, this, &KProxyDialog::slotChanged); 0217 connect(mUi.useReverseProxyCheckBox, &QPushButton::clicked, this, &KProxyDialog::slotChanged); 0218 connect(mUi.useSameProxyCheckBox, &QPushButton::clicked, this, &KProxyDialog::slotChanged); 0219 0220 connect(mUi.proxyScriptUrlRequester, &KUrlRequester::textChanged, this, &KProxyDialog::slotChanged); 0221 0222 connect(mUi.manualProxyHttpEdit, &QLineEdit::textChanged, this, &KProxyDialog::slotChanged); 0223 connect(mUi.manualProxyHttpsEdit, &QLineEdit::textChanged, this, &KProxyDialog::slotChanged); 0224 connect(mUi.manualProxyFtpEdit, &QLineEdit::textChanged, this, &KProxyDialog::slotChanged); 0225 connect(mUi.manualProxySocksEdit, &QLineEdit::textChanged, this, &KProxyDialog::slotChanged); 0226 connect(mUi.manualNoProxyEdit, &QLineEdit::textChanged, this, &KProxyDialog::slotChanged); 0227 0228 connect(mUi.manualProxyHttpSpinBox, qOverload<int>(&QSpinBox::valueChanged), this, &KProxyDialog::slotChanged); 0229 connect(mUi.manualProxyHttpsSpinBox, qOverload<int>(&QSpinBox::valueChanged), this, &KProxyDialog::slotChanged); 0230 connect(mUi.manualProxyFtpSpinBox, qOverload<int>(&QSpinBox::valueChanged), this, &KProxyDialog::slotChanged); 0231 connect(mUi.manualProxySocksSpinBox, qOverload<int>(&QSpinBox::valueChanged), this, &KProxyDialog::slotChanged); 0232 0233 connect(mUi.systemProxyHttpEdit, &QLineEdit::textEdited, this, &KProxyDialog::slotChanged); 0234 connect(mUi.systemProxyHttpsEdit, &QLineEdit::textEdited, this, &KProxyDialog::slotChanged); 0235 connect(mUi.systemProxyFtpEdit, &QLineEdit::textEdited, this, &KProxyDialog::slotChanged); 0236 connect(mUi.systemProxySocksEdit, &QLineEdit::textEdited, this, &KProxyDialog::slotChanged); 0237 connect(mUi.systemNoProxyEdit, &QLineEdit::textEdited, this, &KProxyDialog::slotChanged); 0238 0239 #if defined(Q_OS_LINUX) || defined(Q_OS_UNIX) 0240 connect(mUi.systemProxyRadioButton, &QAbstractButton::toggled, mUi.systemProxyGroupBox, &QWidget::setVisible); 0241 #else 0242 mUi.autoDetectButton->setVisible(false); 0243 #endif 0244 connect(mUi.systemProxyRadioButton, &QPushButton::clicked, this, &KProxyDialog::slotChanged); 0245 } 0246 0247 KProxyDialog::~KProxyDialog() 0248 { 0249 } 0250 0251 QString KProxyDialog::proxyFor(const QString &protocol) const 0252 { 0253 const QString key = protocol + QLatin1String("Proxy"); 0254 QString proxyStr(mConfig->group(QStringLiteral("Proxy Settings")).readEntry(key)); 0255 const int index = proxyStr.lastIndexOf(QLatin1Char(' ')); 0256 0257 if (index > -1) { 0258 const QStringView portStr = QStringView(proxyStr).right(proxyStr.length() - index - 1); 0259 const bool isDigits = std::all_of(portStr.cbegin(), portStr.cend(), [](const QChar c) { 0260 return c.isDigit(); 0261 }); 0262 0263 if (isDigits) { 0264 proxyStr = QStringView(proxyStr).left(index).toString() + QLatin1Char(':') + portStr; 0265 } else { 0266 proxyStr.clear(); 0267 } 0268 } 0269 0270 return proxyStr; 0271 } 0272 0273 QString KProxyDialog::proxyConfigScript() const 0274 { 0275 return mConfig->group(QStringLiteral("Proxy Settings")).readEntry("Proxy Config Script"); 0276 } 0277 0278 bool KProxyDialog::useReverseProxy() const 0279 { 0280 return mConfig->group(QStringLiteral("Proxy Settings")).readEntry("ReversedException", false); 0281 } 0282 0283 KSaveIOConfig::ProxyType KProxyDialog::proxyType() const 0284 { 0285 return static_cast<KSaveIOConfig::ProxyType>(mConfig->group(QStringLiteral("Proxy Settings")).readEntry("ProxyType", 0)); 0286 } 0287 0288 void KProxyDialog::load() 0289 { 0290 mProxyMap.insert(QStringLiteral("HttpProxy"), proxyFor(QStringLiteral("http"))); 0291 mProxyMap.insert(QStringLiteral("HttpsProxy"), proxyFor(QStringLiteral("https"))); 0292 mProxyMap.insert(QStringLiteral("FtpProxy"), proxyFor(QStringLiteral("ftp"))); 0293 mProxyMap.insert(QStringLiteral("SocksProxy"), proxyFor(QStringLiteral("socks"))); 0294 mProxyMap.insert(QStringLiteral("ProxyScript"), proxyConfigScript()); 0295 mProxyMap.insert(QStringLiteral("NoProxy"), KSaveIOConfig::noProxyFor()); 0296 0297 const KSaveIOConfig::ProxyType type = proxyType(); 0298 0299 // Make sure showEnvValueCheckBox is unchecked before setting proxy env var names 0300 mUi.showEnvValueCheckBox->setChecked(false); 0301 0302 setProxyInformation(mProxyMap.value(QStringLiteral("HttpProxy")), 0303 type, 0304 mUi.manualProxyHttpEdit, 0305 mUi.systemProxyHttpEdit, 0306 mUi.manualProxyHttpSpinBox, 0307 QStringLiteral("http"), 0308 HideHttpUrlScheme); 0309 setProxyInformation(mProxyMap.value(QStringLiteral("HttpsProxy")), 0310 type, 0311 mUi.manualProxyHttpsEdit, 0312 mUi.systemProxyHttpsEdit, 0313 mUi.manualProxyHttpsSpinBox, 0314 QStringLiteral("http"), 0315 HideHttpsUrlScheme); 0316 setProxyInformation(mProxyMap.value(QStringLiteral("FtpProxy")), 0317 type, 0318 mUi.manualProxyFtpEdit, 0319 mUi.systemProxyFtpEdit, 0320 mUi.manualProxyFtpSpinBox, 0321 QStringLiteral("ftp"), 0322 HideFtpUrlScheme); 0323 setProxyInformation(mProxyMap.value(QStringLiteral("SocksProxy")), 0324 type, 0325 mUi.manualProxySocksEdit, 0326 mUi.systemProxySocksEdit, 0327 mUi.manualProxySocksSpinBox, 0328 QStringLiteral("socks"), 0329 HideSocksUrlScheme); 0330 setProxyInformation(mProxyMap.value(QStringLiteral("NoProxy")), type, mUi.manualNoProxyEdit, mUi.systemNoProxyEdit, nullptr, QString(), HideNone); 0331 0332 // Check the "Use this proxy server for all protocols" if all the proxy URLs are the same... 0333 const QString httpProxy(mUi.manualProxyHttpEdit->text()); 0334 if (!httpProxy.isEmpty()) { 0335 const int httpProxyPort = mUi.manualProxyHttpSpinBox->value(); 0336 mUi.useSameProxyCheckBox->setChecked(httpProxy == mUi.manualProxyHttpsEdit->text() /* clang-format off */ 0337 && httpProxy == mUi.manualProxyFtpEdit->text() 0338 && httpProxy == mUi.manualProxySocksEdit->text() 0339 && httpProxyPort == mUi.manualProxyHttpsSpinBox->value() 0340 && httpProxyPort == mUi.manualProxyFtpSpinBox->value() 0341 && httpProxyPort == mUi.manualProxySocksSpinBox->value()); /* clang-format on */ 0342 } 0343 0344 // Validate and Set the automatic proxy configuration script url. 0345 QUrl u(mProxyMap.value(QStringLiteral("ProxyScript"))); 0346 if (u.isValid() && !u.isEmpty()) { 0347 u.setUserName(QString()); 0348 u.setPassword(QString()); 0349 mUi.proxyScriptUrlRequester->setUrl(u); 0350 } 0351 0352 // Set use reverse proxy checkbox... 0353 mUi.useReverseProxyCheckBox->setChecked((!mProxyMap.value(QStringLiteral("NoProxy")).isEmpty() && useReverseProxy())); 0354 0355 switch (type) { 0356 case KSaveIOConfig::WPADProxy: 0357 mUi.autoDiscoverProxyRadioButton->setChecked(true); 0358 break; 0359 case KSaveIOConfig::PACProxy: 0360 mUi.autoScriptProxyRadioButton->setChecked(true); 0361 break; 0362 case KSaveIOConfig::ManualProxy: 0363 mUi.manualProxyRadioButton->setChecked(true); 0364 break; 0365 case KSaveIOConfig::EnvVarProxy: 0366 mUi.systemProxyRadioButton->setChecked(true); 0367 break; 0368 case KSaveIOConfig::NoProxy: 0369 default: 0370 mUi.noProxyRadioButton->setChecked(true); 0371 break; 0372 } 0373 } 0374 0375 void KProxyDialog::save() 0376 { 0377 KSaveIOConfig::ProxyType proxyType = KSaveIOConfig::NoProxy; 0378 DisplayUrlFlags displayUrlFlags = static_cast<DisplayUrlFlags>(KSaveIOConfig::proxyDisplayUrlFlags()); 0379 0380 if (mUi.manualProxyRadioButton->isChecked()) { 0381 DisplayUrlFlags flags = HideNone; 0382 proxyType = KSaveIOConfig::ManualProxy; 0383 mProxyMap[QStringLiteral("HttpProxy")] = 0384 proxyUrlFromInput(&flags, mUi.manualProxyHttpEdit, mUi.manualProxyHttpSpinBox, QStringLiteral("http"), HideHttpUrlScheme); 0385 mProxyMap[QStringLiteral("HttpsProxy")] = 0386 proxyUrlFromInput(&flags, mUi.manualProxyHttpsEdit, mUi.manualProxyHttpsSpinBox, QStringLiteral("http"), HideHttpsUrlScheme); 0387 mProxyMap[QStringLiteral("FtpProxy")] = 0388 proxyUrlFromInput(&flags, mUi.manualProxyFtpEdit, mUi.manualProxyFtpSpinBox, QStringLiteral("ftp"), HideFtpUrlScheme); 0389 mProxyMap[QStringLiteral("SocksProxy")] = 0390 proxyUrlFromInput(&flags, mUi.manualProxySocksEdit, mUi.manualProxySocksSpinBox, QStringLiteral("socks"), HideSocksUrlScheme); 0391 mProxyMap[QStringLiteral("NoProxy")] = mUi.manualNoProxyEdit->text(); 0392 displayUrlFlags = flags; 0393 } else if (mUi.systemProxyRadioButton->isChecked()) { 0394 proxyType = KSaveIOConfig::EnvVarProxy; 0395 if (!mUi.showEnvValueCheckBox->isChecked()) { 0396 mProxyMap[QStringLiteral("HttpProxy")] = mUi.systemProxyHttpEdit->text(); 0397 mProxyMap[QStringLiteral("HttpsProxy")] = mUi.systemProxyHttpsEdit->text(); 0398 mProxyMap[QStringLiteral("FtpProxy")] = mUi.systemProxyFtpEdit->text(); 0399 mProxyMap[QStringLiteral("SocksProxy")] = mUi.systemProxySocksEdit->text(); 0400 mProxyMap[QStringLiteral("NoProxy")] = mUi.systemNoProxyEdit->text(); 0401 } else { 0402 mProxyMap[QStringLiteral("HttpProxy")] = mProxyMap.take(mUi.systemProxyHttpEdit->objectName()); 0403 mProxyMap[QStringLiteral("HttpsProxy")] = mProxyMap.take(mUi.systemProxyHttpsEdit->objectName()); 0404 mProxyMap[QStringLiteral("FtpProxy")] = mProxyMap.take(mUi.systemProxyFtpEdit->objectName()); 0405 mProxyMap[QStringLiteral("SocksProxy")] = mProxyMap.take(mUi.systemProxySocksEdit->objectName()); 0406 mProxyMap[QStringLiteral("NoProxy")] = mProxyMap.take(mUi.systemNoProxyEdit->objectName()); 0407 } 0408 } else if (mUi.autoScriptProxyRadioButton->isChecked()) { 0409 proxyType = KSaveIOConfig::PACProxy; 0410 mProxyMap[QStringLiteral("ProxyScript")] = mUi.proxyScriptUrlRequester->text(); 0411 } else if (mUi.autoDiscoverProxyRadioButton->isChecked()) { 0412 proxyType = KSaveIOConfig::WPADProxy; 0413 } 0414 0415 KSaveIOConfig::setProxyType(proxyType); 0416 KSaveIOConfig::setProxyDisplayUrlFlags(displayUrlFlags); 0417 KSaveIOConfig::setUseReverseProxy(mUi.useReverseProxyCheckBox->isChecked()); 0418 0419 // Save the common proxy setting... 0420 KSaveIOConfig::setProxyFor(QStringLiteral("http"), mProxyMap.value(QStringLiteral("HttpProxy"))); 0421 KSaveIOConfig::setProxyFor(QStringLiteral("https"), mProxyMap.value(QStringLiteral("HttpsProxy"))); 0422 KSaveIOConfig::setProxyFor(QStringLiteral("ftp"), mProxyMap.value(QStringLiteral("FtpProxy"))); 0423 KSaveIOConfig::setProxyFor(QStringLiteral("socks"), mProxyMap.value(QStringLiteral("SocksProxy"))); 0424 0425 KSaveIOConfig::setProxyConfigScript(mProxyMap.value(QStringLiteral("ProxyScript"))); 0426 KSaveIOConfig::setNoProxyFor(mProxyMap.value(QStringLiteral("NoProxy"))); 0427 0428 KSaveIOConfig::updateRunningWorkers(widget()); 0429 0430 setNeedsSave(false); 0431 } 0432 0433 void KProxyDialog::defaults() 0434 { 0435 mUi.noProxyRadioButton->setChecked(true); 0436 mUi.proxyScriptUrlRequester->clear(); 0437 0438 mUi.manualProxyHttpEdit->clear(); 0439 mUi.manualProxyHttpsEdit->clear(); 0440 mUi.manualProxyFtpEdit->clear(); 0441 mUi.manualProxySocksEdit->clear(); 0442 mUi.manualNoProxyEdit->clear(); 0443 0444 mUi.manualProxyHttpSpinBox->setValue(0); 0445 mUi.manualProxyHttpsSpinBox->setValue(0); 0446 mUi.manualProxyFtpSpinBox->setValue(0); 0447 mUi.manualProxySocksSpinBox->setValue(0); 0448 0449 mUi.systemProxyHttpEdit->clear(); 0450 mUi.systemProxyHttpsEdit->clear(); 0451 mUi.systemProxyFtpEdit->clear(); 0452 mUi.systemProxySocksEdit->clear(); 0453 0454 setNeedsSave(true); 0455 } 0456 0457 bool KProxyDialog::autoDetectSystemProxy(QLineEdit *edit, const QString &envVarStr, bool showValue) 0458 { 0459 const QStringList envVars = envVarStr.split(QLatin1Char(','), Qt::SkipEmptyParts); 0460 for (const QString &envVar : envVars) { 0461 const QByteArray envVarUtf8(envVar.toUtf8()); 0462 const QByteArray envVarValue = qgetenv(envVarUtf8.constData()); 0463 if (!envVarValue.isEmpty()) { 0464 if (showValue) { 0465 mProxyMap[edit->objectName()] = envVar; 0466 edit->setText(QString::fromUtf8(envVarValue)); 0467 } else { 0468 edit->setText(envVar); 0469 } 0470 edit->setEnabled(!showValue); 0471 return true; 0472 } 0473 } 0474 return false; 0475 } 0476 0477 void KProxyDialog::autoDetect() 0478 { 0479 const bool showValue = mUi.showEnvValueCheckBox->isChecked(); 0480 bool wasChanged = false; 0481 0482 wasChanged |= autoDetectSystemProxy(mUi.systemProxyHttpEdit, QStringLiteral("HTTP_PROXY,http_proxy,HTTPPROXY,httpproxy,PROXY,proxy"), showValue); 0483 wasChanged |= autoDetectSystemProxy(mUi.systemProxyHttpsEdit, QStringLiteral("HTTPS_PROXY,https_proxy,HTTPSPROXY,httpsproxy,PROXY,proxy"), showValue); 0484 wasChanged |= autoDetectSystemProxy(mUi.systemProxyFtpEdit, QStringLiteral("FTP_PROXY,ftp_proxy,FTPPROXY,ftpproxy,PROXY,proxy"), showValue); 0485 wasChanged |= autoDetectSystemProxy(mUi.systemProxySocksEdit, QStringLiteral("SOCKS_PROXY,socks_proxy,SOCKSPROXY,socksproxy,PROXY,proxy"), showValue); 0486 wasChanged |= autoDetectSystemProxy(mUi.systemNoProxyEdit, QStringLiteral("NO_PROXY,no_proxy"), showValue); 0487 0488 if (wasChanged) { 0489 setNeedsSave(true); 0490 } 0491 } 0492 0493 void KProxyDialog::syncProxies(const QString &text) 0494 { 0495 if (!mUi.useSameProxyCheckBox->isChecked()) { 0496 return; 0497 } 0498 0499 mUi.manualProxyHttpsEdit->setText(text); 0500 mUi.manualProxyFtpEdit->setText(text); 0501 mUi.manualProxySocksEdit->setText(text); 0502 } 0503 0504 void KProxyDialog::syncProxyPorts(int value) 0505 { 0506 if (!mUi.useSameProxyCheckBox->isChecked()) { 0507 return; 0508 } 0509 0510 mUi.manualProxyHttpsSpinBox->setValue(value); 0511 mUi.manualProxyFtpSpinBox->setValue(value); 0512 mUi.manualProxySocksSpinBox->setValue(value); 0513 } 0514 0515 void KProxyDialog::showEnvValue(bool on) 0516 { 0517 if (on) { 0518 showSystemProxyUrl(mUi.systemProxyHttpEdit, &mProxyMap[mUi.systemProxyHttpEdit->objectName()]); 0519 showSystemProxyUrl(mUi.systemProxyHttpsEdit, &mProxyMap[mUi.systemProxyHttpsEdit->objectName()]); 0520 showSystemProxyUrl(mUi.systemProxyFtpEdit, &mProxyMap[mUi.systemProxyFtpEdit->objectName()]); 0521 showSystemProxyUrl(mUi.systemProxySocksEdit, &mProxyMap[mUi.systemProxySocksEdit->objectName()]); 0522 showSystemProxyUrl(mUi.systemNoProxyEdit, &mProxyMap[mUi.systemNoProxyEdit->objectName()]); 0523 return; 0524 } 0525 0526 mUi.systemProxyHttpEdit->setText(mProxyMap.take(mUi.systemProxyHttpEdit->objectName())); 0527 mUi.systemProxyHttpEdit->setEnabled(true); 0528 mUi.systemProxyHttpsEdit->setText(mProxyMap.take(mUi.systemProxyHttpsEdit->objectName())); 0529 mUi.systemProxyHttpsEdit->setEnabled(true); 0530 mUi.systemProxyFtpEdit->setText(mProxyMap.take(mUi.systemProxyFtpEdit->objectName())); 0531 mUi.systemProxyFtpEdit->setEnabled(true); 0532 mUi.systemProxySocksEdit->setText(mProxyMap.take(mUi.systemProxySocksEdit->objectName())); 0533 mUi.systemProxySocksEdit->setEnabled(true); 0534 mUi.systemNoProxyEdit->setText(mProxyMap.take(mUi.systemNoProxyEdit->objectName())); 0535 mUi.systemNoProxyEdit->setEnabled(true); 0536 } 0537 0538 void KProxyDialog::setUseSameProxy(bool on) 0539 { 0540 if (on) { 0541 mProxyMap[QStringLiteral("ManProxyHttps")] = manualProxyToText(mUi.manualProxyHttpsEdit, mUi.manualProxyHttpsSpinBox, QLatin1Char(' ')); 0542 mProxyMap[QStringLiteral("ManProxyFtp")] = manualProxyToText(mUi.manualProxyFtpEdit, mUi.manualProxyFtpSpinBox, QLatin1Char(' ')); 0543 mProxyMap[QStringLiteral("ManProxySocks")] = manualProxyToText(mUi.manualProxySocksEdit, mUi.manualProxySocksSpinBox, QLatin1Char(' ')); 0544 0545 const QString &httpProxy = mUi.manualProxyHttpEdit->text(); 0546 if (!httpProxy.isEmpty()) { 0547 mUi.manualProxyHttpsEdit->setText(httpProxy); 0548 mUi.manualProxyFtpEdit->setText(httpProxy); 0549 mUi.manualProxySocksEdit->setText(httpProxy); 0550 } 0551 const int httpProxyPort = mUi.manualProxyHttpSpinBox->value(); 0552 if (httpProxyPort > 0) { 0553 mUi.manualProxyHttpsSpinBox->setValue(httpProxyPort); 0554 mUi.manualProxyFtpSpinBox->setValue(httpProxyPort); 0555 mUi.manualProxySocksSpinBox->setValue(httpProxyPort); 0556 } 0557 return; 0558 } 0559 0560 setManualProxyFromText(mProxyMap.take(QStringLiteral("ManProxyHttps")), mUi.manualProxyHttpsEdit, mUi.manualProxyHttpsSpinBox); 0561 setManualProxyFromText(mProxyMap.take(QStringLiteral("ManProxyFtp")), mUi.manualProxyFtpEdit, mUi.manualProxyFtpSpinBox); 0562 setManualProxyFromText(mProxyMap.take(QStringLiteral("ManProxySocks")), mUi.manualProxySocksEdit, mUi.manualProxySocksSpinBox); 0563 } 0564 0565 void KProxyDialog::slotChanged() 0566 { 0567 const bool proxyWarning = mUi.autoScriptProxyRadioButton->isChecked() || mUi.manualProxyRadioButton->isChecked(); 0568 mUi.infoMessageWidget->setVisible(proxyWarning); 0569 0570 setNeedsSave(true); 0571 } 0572 0573 #include "kproxydlg.moc"