[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kfm-devel
Subject:    PATCH: Fix for BR#48679: Proxy options lost after switching proxy use off and on
From:       "Dawit A." <adawit () kde ! org>
Date:       2002-11-06 1:13:14
[Download RAW message or body]

Please review the first two patches that fix the bug mentioned in the subject.  
They address the core problem outlined in the bug report with the exception 
of the request to automatically select the previous proxy setting when it is 
disabled and then re-enabled again. Though easy enough to fix several ways, 
it is too late at this point.

The last two patches are not really siginficant but something I run into when 
fixing the above bug.  The KProxyDlg one is trivial and might not even be 
necessary.  The KSaveIOConfig one is a bit more significant, but it reduces 
the number of times the same config file have to be read from say the proxy 
config module (it is used by all the config dialogs in the kcontrol/kio 
module).  None of these two are really essential and can wait for post-3.1 if 
there are objections.

Regards,
Dawit A.

["kenvvarproxydlg.diff" (text/x-diff)]

Index: kenvvarproxydlg.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/kio/kenvvarproxydlg.cpp,v
retrieving revision 1.20
diff -u -p -b -B -w -r1.20 kenvvarproxydlg.cpp
--- kenvvarproxydlg.cpp	2002/08/30 00:21:14	1.20
+++ kenvvarproxydlg.cpp	2002/11/06 00:56:27
@@ -177,6 +177,7 @@ KEnvVarProxyDlg::KEnvVarProxyDlg( QWidge
   m_pbShowValue = new QPushButton( i18n("Show &Values"), m_gbHostnames,
                                     "m_pbDetect" );
   m_pbShowValue->setToggleButton ( true );
+  m_pbShowValue->setMinimumSize (m_pbShowValue->size ());
   
   QWhatsThis::add( m_pbShowValue, i18n("<qt>Click on this button to see "
                                    "the actual values associated with the "
@@ -221,26 +222,11 @@ void KEnvVarProxyDlg::init()
   connect( m_pbVerify, SIGNAL( clicked() ), SLOT( verifyPressed() ) );
   connect( m_pbDetect, SIGNAL( clicked() ), SLOT( autoDetectPressed() ) );
   connect( m_cbSameProxy, SIGNAL( toggled(bool) ), SLOT( sameProxy(bool) ) );  
+  connect( m_leEnvHttp, SIGNAL(textChanged(const QString&)), SLOT(textChanged(const QString&)) );
 }
 
 void KEnvVarProxyDlg::setProxyData( const KProxyData& data )
 {
-  if ( data.type == KProtocolManager::EnvVarProxy )
-  {
-    m_leEnvHttp->setText( data.httpProxy );
-    m_leEnvHttps->setText( data.httpsProxy );
-    m_leEnvFtp->setText( data.ftpProxy );    
-   
-    bool useSameProxy = (data.httpProxy == data.httpsProxy &&
-                         data.httpProxy == data.ftpProxy);
-    
-    m_cbSameProxy->setChecked ( useSameProxy );
-        
-    if ( useSameProxy )
-      sameProxy ( true );
-  }
-  else if ( data.type == KProtocolManager::NoProxy )
-  {
     KURL u;
     QString envVar;
        
@@ -282,7 +268,6 @@ void KEnvVarProxyDlg::setProxyData( cons
           m_leEnvFtp->setText( data.ftpProxy );
       }
     }
-  }
   
   m_gbExceptions->fillExceptions( data.noProxyFor );
   m_gbExceptions->setCheckReverseProxy( data.useReverseProxy );  
@@ -455,7 +440,7 @@ void KEnvVarProxyDlg::showValue( bool en
   else
   {
     int count = m_lstEnvVars.count ();
-    m_pbShowValue->setText ( i18n ("Show &values") );
+    m_pbShowValue->setText ( i18n ("Show &Values") );
     
     if ( count > 0 )
       m_leEnvHttp->setText( m_lstEnvVars[0] );
@@ -464,6 +449,15 @@ void KEnvVarProxyDlg::showValue( bool en
     if ( count > 2 )    
       m_leEnvFtp->setText( m_lstEnvVars[2] );
   }
+}
+
+void KEnvVarProxyDlg::textChanged(const QString& text)
+{
+    if (!m_cbSameProxy->isChecked())
+        return;
+        
+    m_leEnvFtp->setText (text);
+    m_leEnvHttps->setText (text);
 }
 
 void KEnvVarProxyDlg::sameProxy( bool enable )
Index: kenvvarproxydlg.h
===================================================================
RCS file: /home/kde/kdebase/kcontrol/kio/kenvvarproxydlg.h,v
retrieving revision 1.3
diff -u -p -b -B -w -r1.3 kenvvarproxydlg.h
--- kenvvarproxydlg.h	2002/05/17 03:50:51	1.3
+++ kenvvarproxydlg.h	2002/11/06 00:56:27
@@ -49,6 +49,7 @@ protected slots:
     
     void showValue( bool );
     void sameProxy( bool );
+    void textChanged (const QString&);
 
     void verifyPressed();
     void autoDetectPressed();

["kmanualproxy.diff" (text/x-diff)]

Index: kmanualproxydlg.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/kio/kmanualproxydlg.cpp,v
retrieving revision 1.16
diff -u -p -b -B -w -r1.16 kmanualproxydlg.cpp
--- kmanualproxydlg.cpp	2002/06/29 01:33:02	1.16
+++ kmanualproxydlg.cpp	2002/11/06 00:56:27
@@ -210,25 +210,27 @@ void KManualProxyDlg::init()
 
     connect( m_cbSameProxy, SIGNAL( toggled(bool) ), SLOT( sameProxy(bool) ) );
     connect( m_pbCopyDown, SIGNAL( clicked() ), SLOT( copyDown() ) );
+    connect( m_leHttp, SIGNAL(textChanged(const QString&)), SLOT(textChanged(const QString&)) );
+    connect( m_sbHttp, SIGNAL(valueChanged(int)), SLOT(valueChanged (int)) );
 }
 
 void KManualProxyDlg::setProxyData( const KProxyData &data )
 {
-    if ( data.type == KProtocolManager::NoProxy ||
-         data.type == KProtocolManager::ManualProxy )
-    {
         KURL u;
 
-        int port;
         QString host;
+    int port = DEFAULT_PROXY_PORT;
         
         // Set the HTTP proxy
         u = data.httpProxy;
-        if ( u.isValid() );
+    if (!u.isValid())
+        m_sbHttp->setValue(port);
+    else
         {
-            port = u.port();
-            if ( port < 1 )
-                port = DEFAULT_PROXY_PORT;
+        int p = u.port();
+        if ( p > 0 )
+            port = p;
+            
             u.setPort( 0 );
             host = u.url();
             m_leHttp->setText( host );
@@ -253,11 +255,13 @@ void KManualProxyDlg::setProxyData( cons
         {
             // Set the HTTPS proxy
             u = data.httpsProxy;
-            if ( u.isValid() )
+      if (!u.isValid())
+          m_sbHttps->setValue( DEFAULT_PROXY_PORT );
+      else
             {
-                port = u.port();
-                if ( port < 1 )
-                    port = DEFAULT_PROXY_PORT;
+          int p = u.port();
+          if ( p > 0 )
+              port = p;      
             
                 u.setPort( 0 );
                 m_leHttps->setText( u.url() );
@@ -267,10 +271,13 @@ void KManualProxyDlg::setProxyData( cons
             // Set the FTP proxy...
             u = data.ftpProxy;
             if ( u.isValid() )
+          m_sbFtp->setValue( DEFAULT_PROXY_PORT );
+      else
             {
-                port = u.port();
-                if ( port < 1 )
-                    port = DEFAULT_PROXY_PORT;
+          int p = u.port();
+          if ( p > 0 )
+              port = p;      
+          
                 u.setPort( 0 );
                 m_leFtp->setText( u.url() );
                 m_sbFtp->setValue( port );
@@ -280,13 +287,6 @@ void KManualProxyDlg::setProxyData( cons
         m_gbExceptions->fillExceptions( data.noProxyFor );
         m_gbExceptions->setCheckReverseProxy( data.useReverseProxy );
     }
-    else
-    {
-       m_sbFtp->setValue( DEFAULT_PROXY_PORT );    
-       m_sbHttp->setValue( DEFAULT_PROXY_PORT );
-       m_sbHttps->setValue( DEFAULT_PROXY_PORT );
-    }
-}
 
 const KProxyData KManualProxyDlg::data() const
 {
@@ -401,6 +401,24 @@ bool KManualProxyDlg::validate()
     }
 
     return m_bHasValidData;
+}
+
+void KManualProxyDlg::textChanged(const QString& text)
+{
+    if (!m_cbSameProxy->isChecked())
+        return;
+        
+    m_leFtp->setText (text);
+    m_leHttps->setText (text);
+}
+
+void KManualProxyDlg::valueChanged(int value)
+{
+    if (!m_cbSameProxy->isChecked())
+        return;
+        
+    m_sbFtp->setValue (value);
+    m_sbHttps->setValue (value);
 }
 
 void KManualProxyDlg::copyDown()
Index: kmanualproxydlg.h
===================================================================
RCS file: /home/kde/kdebase/kcontrol/kio/kmanualproxydlg.h,v
retrieving revision 1.3
diff -u -p -b -B -w -r1.3 kmanualproxydlg.h
--- kmanualproxydlg.h	2002/05/17 03:50:51	1.3
+++ kmanualproxydlg.h	2002/11/06 00:56:27
@@ -52,6 +52,8 @@ protected slots:
 
   void copyDown();
   void sameProxy( bool );    
+  void textChanged (const QString&);
+  void valueChanged (int value);
 
 private:
   QSpinBox* m_sbFtp;

["ksaveioconfig.diff" (text/x-diff)]

Index: ksaveioconfig.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/kio/ksaveioconfig.cpp,v
retrieving revision 1.5
diff -u -p -b -B -w -r1.5 ksaveioconfig.cpp
--- ksaveioconfig.cpp	2002/06/21 16:09:29	1.5
+++ ksaveioconfig.cpp	2002/11/06 00:56:27
@@ -21,180 +21,216 @@
 #include <klocale.h>
 #include <dcopclient.h>
 #include <kmessagebox.h>
+#include <kstaticdeleter.h>
 #include <kio/ioslave_defaults.h>
 
 #include "ksaveioconfig.h"
 
+class KSaveIOConfigPrivate
+{
+public:
+  KSaveIOConfigPrivate ();
+  ~KSaveIOConfigPrivate ();
+  
+  KConfig* config;
+};
+
+static KStaticDeleter<KSaveIOConfigPrivate> ksiocp;
+
+KSaveIOConfigPrivate::KSaveIOConfigPrivate (): config(0)
+{
+  ksiocp.setObject (this);
+}
+
+KSaveIOConfigPrivate::~KSaveIOConfigPrivate ()
+{
+  delete config;
+  ksiocp.setObject (0);
+}
+
+KSaveIOConfigPrivate* KSaveIOConfig::d = 0;
+
+KConfig* KSaveIOConfig::config()
+{
+  if (!d)
+     d = new KSaveIOConfigPrivate;
+
+  if (!d->config)
+     d->config = new KConfig("kioslaverc", false, false);
+
+  return d->config;
+}
+
+void KSaveIOConfig::reparseConfiguration ()
+{
+  delete d;
+  d = 0;
+}
+
 void KSaveIOConfig::setReadTimeout( int _timeout )
 {
-  KConfig cfg("kioslaverc", false, false);
-  cfg.setGroup( QString::null );
-  cfg.writeEntry("ReadTimeout", QMAX(MIN_TIMEOUT_VALUE,_timeout));
-  cfg.sync();
+  KConfig* cfg = config ();
+  cfg->setGroup( QString::null );
+  cfg->writeEntry("ReadTimeout", QMAX(MIN_TIMEOUT_VALUE,_timeout));
+  cfg->sync();  
 }
 
 void KSaveIOConfig::setConnectTimeout( int _timeout )
 {
-  KConfig cfg("kioslaverc", false, false);
-  cfg.setGroup( QString::null );
-  cfg.writeEntry("ConnectTimeout", QMAX(MIN_TIMEOUT_VALUE,_timeout));
-  cfg.sync();
+  KConfig* cfg = config ();
+  cfg->setGroup( QString::null );
+  cfg->writeEntry("ConnectTimeout", QMAX(MIN_TIMEOUT_VALUE,_timeout));
+  cfg->sync();
 }
 
 void KSaveIOConfig::setProxyConnectTimeout( int _timeout )
 {
-  KConfig cfg("kioslaverc", false, false);
-  cfg.setGroup( QString::null );
-  cfg.writeEntry("ProxyConnectTimeout", QMAX(MIN_TIMEOUT_VALUE,_timeout));
-  cfg.sync();
+  KConfig* cfg = config ();
+  cfg->setGroup( QString::null );
+  cfg->writeEntry("ProxyConnectTimeout", QMAX(MIN_TIMEOUT_VALUE,_timeout));
+  cfg->sync();
 }
 
 void KSaveIOConfig::setResponseTimeout( int _timeout )
 {
-  KConfig cfg("kioslaverc", false, false);
-  cfg.setGroup( QString::null );
-  cfg.writeEntry("ResponseTimeout", QMAX(MIN_TIMEOUT_VALUE,_timeout));
-  cfg.sync();
+  KConfig* cfg = config ();
+  cfg->setGroup( QString::null );
+  cfg->writeEntry("ResponseTimeout", QMAX(MIN_TIMEOUT_VALUE,_timeout));
+  cfg->sync();
 }
 
 
 void KSaveIOConfig::setMarkPartial( bool _mode )
 {
-  KConfig cfg("kioslaverc", false, false);
-  cfg.setGroup( QString::null );
-  cfg.writeEntry( "MarkPartial", _mode );
-  cfg.sync();
+  KConfig* cfg = config ();
+  cfg->setGroup( QString::null );
+  cfg->writeEntry( "MarkPartial", _mode );
+  cfg->sync();
 }
 
 void KSaveIOConfig::setMinimumKeepSize( int _size )
 {
-  KConfig cfg("kioslaverc", false, false);
-  cfg.setGroup( QString::null );
-  cfg.writeEntry( "MinimumKeepSize", _size );
-  cfg.sync();
+  KConfig* cfg = config ();
+  cfg->setGroup( QString::null );
+  cfg->writeEntry( "MinimumKeepSize", _size );
+  cfg->sync();
 }
 
 void KSaveIOConfig::setAutoResume( bool _mode )
 {
-  KConfig cfg("kioslaverc", false, false);
-  cfg.setGroup( QString::null );
-  cfg.writeEntry( "AutoResume", _mode );
-  cfg.sync();
+  KConfig* cfg = config ();
+  cfg->setGroup( QString::null );
+  cfg->writeEntry( "AutoResume", _mode );
+  cfg->sync();
 }
 
 void KSaveIOConfig::setUseCache( bool _mode )
 {
-  KConfig cfg("kio_httprc", false, false);
-  cfg.writeEntry( "UseCache", _mode );
-  cfg.sync();
+  KConfig* cfg = config ();
+  cfg->writeEntry( "UseCache", _mode );
+  cfg->sync();
 }
 
 void KSaveIOConfig::setMaxCacheSize( int cache_size )
 {
-  KConfig cfg("kio_httprc", false, false);
-  cfg.writeEntry( "MaxCacheSize", cache_size );
-  cfg.sync();
+  KConfig* cfg = config ();
+  cfg->writeEntry( "MaxCacheSize", cache_size );
+  cfg->sync();
 }
 
 void KSaveIOConfig::setCacheControl(KIO::CacheControl policy)
 {
-  KConfig cfg("kio_httprc", false, false);
+  KConfig* cfg = config ();
   QString tmp = KIO::getCacheControlString(policy);
-  cfg.writeEntry("cache", tmp);
-  cfg.sync();
+  cfg->writeEntry("cache", tmp);
+  cfg->sync();
 }
 
 void KSaveIOConfig::setMaxCacheAge( int cache_age )
 {
-  KConfig cfg("kio_httprc", false, false);
-  cfg.writeEntry( "MaxCacheAge", cache_age );
-  cfg.sync();
+  KConfig* cfg = config ();
+  cfg->writeEntry( "MaxCacheAge", cache_age );
+  cfg->sync();
 }
 
-void KSaveIOConfig::setUseProxy( bool _mode )
-{
-  if (_mode)
-    setProxyType( KProtocolManager::ManualProxy );
-  else
-    setProxyType( KProtocolManager::NoProxy );
-}
-
 void KSaveIOConfig::setUseReverseProxy( bool mode )
 {
-  KConfig cfg("kioslaverc", false, false);
-  cfg.setGroup( "Proxy Settings" );
-  cfg.writeEntry("ReversedException", mode);
-  cfg.sync();
+  KConfig* cfg = config ();
+  cfg->setGroup( "Proxy Settings" );
+  cfg->writeEntry("ReversedException", mode);
+  cfg->sync();
 }
 
 void KSaveIOConfig::setProxyType(KProtocolManager::ProxyType type)
 {
-  KConfig cfg("kioslaverc", false, false);
-  cfg.setGroup( "Proxy Settings" );
-  cfg.writeEntry( "ProxyType", static_cast<int>(type) );
-  cfg.sync();
+  KConfig* cfg = config ();
+  cfg->setGroup( "Proxy Settings" );
+  cfg->writeEntry( "ProxyType", static_cast<int>(type) );
+  cfg->sync();
 }
 
 void KSaveIOConfig::setProxyAuthMode(KProtocolManager::ProxyAuthMode mode)
 {
-  KConfig cfg("kioslaverc", false, false);
-  cfg.setGroup( "Proxy Settings" );
-  cfg.writeEntry( "AuthMode", static_cast<int>(mode) );
-  cfg.sync();
+  KConfig* cfg = config ();
+  cfg->setGroup( "Proxy Settings" );
+  cfg->writeEntry( "AuthMode", static_cast<int>(mode) );
+  cfg->sync();
 }
 
 void KSaveIOConfig::setNoProxyFor( const QString& _noproxy )
 {
-  KConfig cfg("kioslaverc", false, false);
-  cfg.setGroup( "Proxy Settings" );
-  cfg.writeEntry( "NoProxyFor", _noproxy );
-  cfg.sync();
+  KConfig* cfg = config ();
+  cfg->setGroup( "Proxy Settings" );
+  cfg->writeEntry( "NoProxyFor", _noproxy );
+  cfg->sync();
 }
 
 void KSaveIOConfig::setProxyFor( const QString& protocol,
                                     const QString& _proxy )
 {
-  KConfig cfg("kioslaverc", false, false);
-  cfg.setGroup( "Proxy Settings" );
-  cfg.writeEntry( protocol.lower() + "Proxy", _proxy );
-  cfg.sync();
+  KConfig* cfg = config ();
+  cfg->setGroup( "Proxy Settings" );
+  cfg->writeEntry( protocol.lower() + "Proxy", _proxy );
+  cfg->sync();
 }
 
 void KSaveIOConfig::setProxyConfigScript( const QString& _url )
 {
-  KConfig cfg("kioslaverc", false, false);
-  cfg.setGroup( "Proxy Settings" );
-  cfg.writeEntry( "Proxy Config Script", _url );
-  cfg.sync();
+  KConfig* cfg = config ();
+  cfg->setGroup( "Proxy Settings" );
+  cfg->writeEntry( "Proxy Config Script", _url );
+  cfg->sync();
 }
 
 void KSaveIOConfig::setPersistentProxyConnection( bool enable )
 {
-  KConfig cfg("kioslaverc", false, false);
-  cfg.setGroup( QString::null );
-  cfg.writeEntry( "PersistentProxyConnection", enable );
-  cfg.sync();
+  KConfig* cfg = config ();
+  cfg->setGroup( QString::null );
+  cfg->writeEntry( "PersistentProxyConnection", enable );
+  cfg->sync();
 }
 
 void KSaveIOConfig::setPersistentConnections( bool enable )
 {
-  KConfig cfg("kioslaverc", false, false);
-  cfg.setGroup( QString::null );
-  cfg.writeEntry( "PersistentConnections", enable );
-  cfg.sync();
+  KConfig* cfg = config ();
+  cfg->setGroup( QString::null );
+  cfg->writeEntry( "PersistentConnections", enable );
+  cfg->sync();
 }
 
 void KSaveIOConfig::updateRunningIOSlaves (QWidget *parent)
 {
-  // Inform running io-slaves about the changes...
+  // Inform all running io-slaves about the changes...
+  
+  DCOPClient client;
   bool updateSuccessful = false;
-  DCOPClient *client = new DCOPClient;
-  if (client->attach())
+  
+  if (client.attach())
   {
     QByteArray data;
     QDataStream stream( data, IO_WriteOnly );
     stream << QString::null;
-    updateSuccessful= client->send( "*", "KIO::Scheduler",
+    updateSuccessful= client.send( "*", "KIO::Scheduler",
                                     "reparseSlaveConfiguration(QString)",
                                     data );
   }
@@ -208,6 +244,4 @@ void KSaveIOConfig::updateRunningIOSlave
     KMessageBox::information (parent, message, caption);
     return;    
   }
-  
-  delete client;
 }
Index: ksaveioconfig.h
===================================================================
RCS file: /home/kde/kdebase/kcontrol/kio/ksaveioconfig.h,v
retrieving revision 1.4
diff -u -p -b -B -w -r1.4 ksaveioconfig.h
--- ksaveioconfig.h	2002/06/21 16:09:29	1.4
+++ ksaveioconfig.h	2002/11/06 00:56:28
@@ -23,10 +23,16 @@
 #include <kprotocolmanager.h>
 
 class QWidget;
+class KSaveIOConfigPrivate;
 
 class KSaveIOConfig
 {
 public:
+  
+  /* Reload config file (kioslaverc) */
+  static void reparseConfiguration();
+  
+  
   /** Timeout Settings */
   static void setReadTimeout( int );
 
@@ -48,8 +54,6 @@ public:
 
   
   /** Proxy Settings */
-  static void setUseProxy( bool );
-
   static void setUseReverseProxy( bool );
 
   static void setProxyType( KProtocolManager::ProxyType );
@@ -77,5 +81,12 @@ public:
     
   /** Update all running io-slaves */
   static void updateRunningIOSlaves (QWidget * parent = 0L);
+  
+protected:
+  static KConfig* config ();
+  KSaveIOConfig ();
+  
+private:  
+  static KSaveIOConfigPrivate* d;
 };
 #endif

["kproxydlg.diff" (text/x-diff)]

Index: kproxydlg.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/kio/kproxydlg.cpp,v
retrieving revision 1.69
diff -u -p -b -B -w -r1.69 kproxydlg.cpp
--- kproxydlg.cpp	2002/11/03 11:52:41	1.69
+++ kproxydlg.cpp	2002/11/06 00:56:27
@@ -42,7 +42,8 @@
 #include "socks.h"
 #include "kproxydlg.h"
 
-KProxyOptions::KProxyOptions( QWidget* parent, const char* /*name*/ )
+KProxyOptions::KProxyOptions (QWidget* parent, const char* name)
+              :KCModule (parent, name)
 {
   QVBoxLayout *layout = new QVBoxLayout(this);
   QTabWidget *tab = new QTabWidget(this);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic