You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
304 lines
9.1 KiB
304 lines
9.1 KiB
15 years ago
|
/*
|
||
|
kenvvarproxydlg.cpp - Proxy configuration dialog
|
||
|
|
||
|
Copyright (C) 2001- Dawit Alemayehu <adawit@kde.org>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU General Public
|
||
|
License (GPL) version 2 as published by the Free Software
|
||
|
Foundation.
|
||
|
|
||
|
This library 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
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include <stdlib.h>
|
||
|
|
||
15 years ago
|
#include <tqlabel.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
15 years ago
|
#include <tqcheckbox.h>
|
||
|
#include <tqwhatsthis.h>
|
||
|
#include <tqpushbutton.h>
|
||
15 years ago
|
|
||
|
#include <kdebug.h>
|
||
|
#include <klocale.h>
|
||
|
#include <klineedit.h>
|
||
|
#include <kmessagebox.h>
|
||
|
|
||
|
#include "envvarproxy_ui.h"
|
||
|
#include "kenvvarproxydlg.h"
|
||
|
|
||
|
|
||
|
#define ENV_FTP_PROXY "FTP_PROXY,ftp_proxy,FTPPROXY,ftpproxy,PROXY,proxy"
|
||
|
#define ENV_HTTP_PROXY "HTTP_PROXY,http_proxy,HTTPPROXY,httpproxy,PROXY,proxy"
|
||
|
#define ENV_HTTPS_PROXY "HTTPS_PROXY,https_proxy,HTTPSPROXY,httpsproxy,PROXY,proxy"
|
||
|
#define NO_PROXY "NO_PROXY,no_proxy"
|
||
|
|
||
|
|
||
15 years ago
|
static TQString getProxyEnv(const TQString& var)
|
||
15 years ago
|
{
|
||
15 years ago
|
return TQString::fromLocal8Bit(::getenv(var.local8Bit().data()));
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
static bool autoDetectProxySetting(const TQString& type, TQString& proxyEnv)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQStringList list = TQStringList::split( ',', type);
|
||
|
TQStringList::ConstIterator it = list.begin();
|
||
|
TQStringList::ConstIterator end = list.end();
|
||
15 years ago
|
|
||
|
for(; it != end; ++it)
|
||
|
{
|
||
|
if(!getProxyEnv(*it).isEmpty())
|
||
|
{
|
||
|
proxyEnv = *it;
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
15 years ago
|
KEnvVarProxyDlg::KEnvVarProxyDlg( TQWidget* parent, const char* name )
|
||
15 years ago
|
:KProxyDialogBase( parent, name, true,
|
||
|
i18n( "Variable Proxy Configuration" ) )
|
||
|
{
|
||
|
mDlg = new EnvVarProxyDlgUI( this );
|
||
|
setMainWidget( mDlg );
|
||
|
mDlg->leHttp->setMinimumWidth( mDlg->leHttp->fontMetrics().maxWidth() * 20 );
|
||
|
init();
|
||
|
}
|
||
|
|
||
|
KEnvVarProxyDlg::~KEnvVarProxyDlg ()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void KEnvVarProxyDlg::init()
|
||
|
{
|
||
|
m_bHasValidData = false;
|
||
|
|
||
15 years ago
|
connect( mDlg->cbShowValue, TQT_SIGNAL( clicked() ), TQT_SLOT( showValuePressed() ) );
|
||
|
connect( mDlg->pbVerify, TQT_SIGNAL( clicked() ), TQT_SLOT( verifyPressed() ) );
|
||
|
connect( mDlg->pbDetect, TQT_SIGNAL( clicked() ), TQT_SLOT( autoDetectPressed() ) );
|
||
15 years ago
|
}
|
||
|
|
||
|
void KEnvVarProxyDlg::setProxyData( const KProxyData& data )
|
||
|
{
|
||
|
// Setup HTTP Proxy...
|
||
|
if (!getProxyEnv(data.proxyList["http"]).isEmpty())
|
||
|
mEnvVarsMap["http"] = data.proxyList["http"];
|
||
|
|
||
|
// Setup HTTPS Proxy...
|
||
|
if (!getProxyEnv(data.proxyList["https"]).isEmpty())
|
||
|
mEnvVarsMap["https"] = data.proxyList["https"];
|
||
|
|
||
|
// Setup FTP Proxy...
|
||
|
if (!getProxyEnv(data.proxyList["ftp"]).isEmpty())
|
||
|
mEnvVarsMap["ftp"] = data.proxyList["ftp"];
|
||
|
|
||
|
// Setup NO Proxy For...
|
||
15 years ago
|
TQString noProxyFor = data.noProxyFor.join("");
|
||
15 years ago
|
if (!getProxyEnv(noProxyFor).isEmpty())
|
||
|
mEnvVarsMap["noProxy"] = noProxyFor;
|
||
|
|
||
|
mDlg->cbShowValue->setChecked( data.showEnvVarValue );
|
||
|
showValue();
|
||
|
}
|
||
|
|
||
|
const KProxyData KEnvVarProxyDlg::data() const
|
||
|
{
|
||
|
KProxyData data;
|
||
|
|
||
|
if (m_bHasValidData)
|
||
|
{
|
||
|
data.proxyList["http"] = mEnvVarsMap["http"];
|
||
|
data.proxyList["https"] = mEnvVarsMap["https"];
|
||
|
data.proxyList["ftp"] = mEnvVarsMap["ftp"];
|
||
|
data.noProxyFor = mEnvVarsMap["noProxy"];
|
||
|
data.type = KProtocolManager::EnvVarProxy;
|
||
|
data.showEnvVarValue = mDlg->cbShowValue->isChecked();
|
||
|
}
|
||
|
|
||
|
return data;
|
||
|
}
|
||
|
|
||
|
|
||
|
void KEnvVarProxyDlg::verifyPressed()
|
||
|
{
|
||
|
if ( !validate() )
|
||
|
{
|
||
15 years ago
|
TQString msg = i18n("You must specify at least one valid proxy "
|
||
15 years ago
|
"environment variable.");
|
||
|
|
||
15 years ago
|
TQString details = i18n("<qt>Make sure you entered the actual environment "
|
||
15 years ago
|
"variable name rather than its value. For "
|
||
|
"example, if the environment variable is <br><b>"
|
||
|
"HTTP_PROXY=http://localhost:3128</b><br> you need "
|
||
|
"to enter <b>HTTP_PROXY</b> here instead of the "
|
||
|
"actual value http://localhost:3128.</qt>");
|
||
|
|
||
|
KMessageBox::detailedSorry( this, msg, details,
|
||
|
i18n("Invalid Proxy Setup") );
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
KMessageBox::information( this, i18n("Successfully verified."),
|
||
|
i18n("Proxy Setup") );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KEnvVarProxyDlg::autoDetectPressed()
|
||
|
{
|
||
|
bool found = false;
|
||
|
|
||
|
setHighLight (mDlg->lbHttp, false);
|
||
|
setHighLight (mDlg->lbHttps, false);
|
||
|
setHighLight (mDlg->lbFtp, false);
|
||
|
setHighLight (mDlg->lbNoProxy, false);
|
||
|
|
||
|
// Detect HTTP proxy settings...
|
||
13 years ago
|
found |= autoDetectProxySetting (TQString::fromLatin1(ENV_HTTP_PROXY), mEnvVarsMap["http"]);
|
||
15 years ago
|
|
||
|
// Detect HTTPS proxy settings...
|
||
13 years ago
|
found |= autoDetectProxySetting (TQString::fromLatin1(ENV_HTTPS_PROXY), mEnvVarsMap["https"]);
|
||
15 years ago
|
|
||
|
// Detect FTP proxy settings...
|
||
13 years ago
|
found |= autoDetectProxySetting (TQString::fromLatin1(ENV_FTP_PROXY), mEnvVarsMap["ftp"]);
|
||
15 years ago
|
|
||
|
// Detect the NO_PROXY settings...
|
||
13 years ago
|
found |= autoDetectProxySetting (TQString::fromLatin1(NO_PROXY), mEnvVarsMap["noProxy"]);
|
||
15 years ago
|
|
||
|
if ( !found )
|
||
|
{
|
||
15 years ago
|
TQString msg = i18n("Did not detect any environment variables "
|
||
15 years ago
|
"commonly used to set system wide proxy "
|
||
|
"information.");
|
||
|
|
||
15 years ago
|
TQString details = i18n("<qt>To learn about the variable names the "
|
||
15 years ago
|
"automatic detection process searches for, "
|
||
|
"press OK, click on the quick help button "
|
||
|
"on the window title bar of the "
|
||
|
"previous dialog and then click on the "
|
||
|
"\"<b>Auto Detect</b>\" button.</qt>");
|
||
|
|
||
|
KMessageBox::detailedSorry( this, msg, details,
|
||
|
i18n("Automatic Proxy Variable Detection") );
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
showValue();
|
||
|
}
|
||
|
|
||
|
void KEnvVarProxyDlg::updateVariables()
|
||
|
{
|
||
15 years ago
|
TQString text = mDlg->leHttp->text();
|
||
15 years ago
|
if (mEnvVarsMap["http"] != text)
|
||
|
mEnvVarsMap["http"] = text;
|
||
|
|
||
|
text = mDlg->leHttps->text();
|
||
|
if (mEnvVarsMap["https"] != text)
|
||
|
mEnvVarsMap["https"] = text;
|
||
|
|
||
|
text = mDlg->leFtp->text();
|
||
|
if (mEnvVarsMap["ftp"] != text)
|
||
|
mEnvVarsMap["ftp"] = text;
|
||
|
|
||
|
text = mDlg->leNoProxy->text();
|
||
|
if (mEnvVarsMap["noProxy"] != text)
|
||
|
mEnvVarsMap["noProxy"] = text;
|
||
|
}
|
||
|
|
||
|
void KEnvVarProxyDlg::showValuePressed()
|
||
|
{
|
||
|
// Only update the variables whenever
|
||
|
if (mDlg->cbShowValue->isChecked())
|
||
|
updateVariables();
|
||
|
|
||
|
showValue();
|
||
|
}
|
||
|
|
||
|
void KEnvVarProxyDlg::showValue()
|
||
|
{
|
||
|
bool enable = mDlg->cbShowValue->isChecked();
|
||
|
|
||
|
mDlg->leHttp->setReadOnly (enable);
|
||
|
mDlg->leHttps->setReadOnly (enable);
|
||
|
mDlg->leFtp->setReadOnly (enable);
|
||
|
mDlg->leNoProxy->setReadOnly (enable);
|
||
|
|
||
|
if (enable)
|
||
|
{
|
||
|
mDlg->leHttp->setText(getProxyEnv(mEnvVarsMap["http"]));
|
||
|
mDlg->leHttps->setText(getProxyEnv(mEnvVarsMap["https"]));
|
||
|
mDlg->leFtp->setText(getProxyEnv(mEnvVarsMap["ftp"]));
|
||
|
mDlg->leNoProxy->setText(getProxyEnv(mEnvVarsMap["noProxy"]));
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
mDlg->leHttp->setText(mEnvVarsMap["http"]);
|
||
|
mDlg->leHttps->setText(mEnvVarsMap["https"]);
|
||
|
mDlg->leFtp->setText(mEnvVarsMap["ftp"]);
|
||
|
mDlg->leNoProxy->setText(mEnvVarsMap["noProxy"]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
bool KEnvVarProxyDlg::validate(bool erase)
|
||
|
{
|
||
|
m_bHasValidData = false;
|
||
|
|
||
|
if(!mDlg->cbShowValue->isChecked())
|
||
|
updateVariables();
|
||
|
|
||
|
bool notFound = getProxyEnv(mEnvVarsMap["http"]).isEmpty();
|
||
|
m_bHasValidData |= !notFound;
|
||
|
setHighLight (mDlg->lbHttp, notFound);
|
||
15 years ago
|
if(notFound && erase) mEnvVarsMap["http"] = TQString::null;
|
||
15 years ago
|
|
||
|
notFound = getProxyEnv(mEnvVarsMap["https"]).isEmpty();
|
||
|
m_bHasValidData |= !notFound;
|
||
|
setHighLight (mDlg->lbHttps, notFound);
|
||
15 years ago
|
if(notFound && erase) mEnvVarsMap["https"] = TQString::null;
|
||
15 years ago
|
|
||
|
notFound = getProxyEnv(mEnvVarsMap["ftp"]).isEmpty();
|
||
|
m_bHasValidData |= !notFound;
|
||
|
setHighLight (mDlg->lbFtp, notFound);
|
||
15 years ago
|
if(notFound && erase) mEnvVarsMap["ftp"] = TQString::null;
|
||
15 years ago
|
|
||
|
notFound = getProxyEnv(mEnvVarsMap["noProxy"]).isEmpty();
|
||
|
m_bHasValidData |= !notFound;
|
||
|
setHighLight (mDlg->lbNoProxy, notFound);
|
||
15 years ago
|
if(notFound && erase) mEnvVarsMap["noProxy"] = TQString::null;
|
||
15 years ago
|
|
||
|
return m_bHasValidData;
|
||
|
}
|
||
|
|
||
|
void KEnvVarProxyDlg::slotOk()
|
||
|
{
|
||
|
if(!validate(true))
|
||
|
{
|
||
15 years ago
|
TQString msg = i18n("You must specify at least one valid proxy "
|
||
15 years ago
|
"environment variable.");
|
||
|
|
||
15 years ago
|
TQString details = i18n("<qt>Make sure you entered the actual environment "
|
||
15 years ago
|
"variable name rather than its value. For "
|
||
|
"example, if the environment variable is <br><b>"
|
||
|
"HTTP_PROXY=http://localhost:3128</b><br> you need "
|
||
|
"to enter <b>HTTP_PROXY</b> here instead of the "
|
||
|
"actual value http://localhost:3128.</qt>");
|
||
|
|
||
|
KMessageBox::detailedError( this, msg, details,
|
||
|
i18n("Invalid Proxy Setup") );
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
KDialogBase::slotOk ();
|
||
|
}
|
||
|
|
||
|
#include "kenvvarproxydlg.moc"
|