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