2 Copyright (C) 2001 Dawit Alemayehu <adawit@kde.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
21 #include "ksaveioconfig.h"
24 #include <QtDBus/QtDBus>
29 #include <kmessagebox.h>
30 #include <k3staticdeleter.h>
31 #include <kio/ioslave_defaults.h>
32 #include <kconfiggroup.h>
34 class KSaveIOConfigPrivate
37 KSaveIOConfigPrivate ();
38 ~KSaveIOConfigPrivate ();
44 static KSaveIOConfigPrivate
*ksiocpref
= 0;
45 static K3StaticDeleter
<KSaveIOConfigPrivate
> ksiocp
;
47 KSaveIOConfigPrivate::KSaveIOConfigPrivate (): config(0), http_config(0)
49 ksiocp
.setObject (ksiocpref
, this);
52 KSaveIOConfigPrivate::~KSaveIOConfigPrivate ()
57 KSaveIOConfigPrivate
* KSaveIOConfig::d
= 0;
59 KConfig
* KSaveIOConfig::config()
62 d
= new KSaveIOConfigPrivate
;
65 d
->config
= new KConfig("kioslaverc", KConfig::NoGlobals
);
70 KConfig
* KSaveIOConfig::http_config()
73 d
= new KSaveIOConfigPrivate
;
76 d
->http_config
= new KConfig("kio_httprc", KConfig::NoGlobals
);
78 return d
->http_config
;
81 void KSaveIOConfig::reparseConfiguration ()
87 void KSaveIOConfig::setReadTimeout( int _timeout
)
89 KConfig
* cfg
= config ();
90 cfg
->group("").writeEntry("ReadTimeout", qMax(MIN_TIMEOUT_VALUE
,_timeout
));
94 void KSaveIOConfig::setConnectTimeout( int _timeout
)
96 KConfig
* cfg
= config ();
97 cfg
->group("").writeEntry("ConnectTimeout", qMax(MIN_TIMEOUT_VALUE
,_timeout
));
101 void KSaveIOConfig::setProxyConnectTimeout( int _timeout
)
103 KConfig
* cfg
= config ();
104 cfg
->group("").writeEntry("ProxyConnectTimeout", qMax(MIN_TIMEOUT_VALUE
,_timeout
));
108 void KSaveIOConfig::setResponseTimeout( int _timeout
)
110 KConfig
* cfg
= config ();
111 cfg
->group("").writeEntry("ResponseTimeout", qMax(MIN_TIMEOUT_VALUE
,_timeout
));
116 void KSaveIOConfig::setMarkPartial( bool _mode
)
118 KConfig
* cfg
= config ();
119 cfg
->group("").writeEntry( "MarkPartial", _mode
);
123 void KSaveIOConfig::setMinimumKeepSize( int _size
)
125 KConfig
* cfg
= config ();
126 cfg
->group("").writeEntry( "MinimumKeepSize", _size
);
130 void KSaveIOConfig::setAutoResume( bool _mode
)
132 KConfig
* cfg
= config ();
133 cfg
->group("").writeEntry( "AutoResume", _mode
);
137 void KSaveIOConfig::setUseCache( bool _mode
)
139 KConfig
* cfg
= http_config ();
140 cfg
->group("").writeEntry( "UseCache", _mode
);
144 void KSaveIOConfig::setMaxCacheSize( int cache_size
)
146 KConfig
* cfg
= http_config ();
147 cfg
->group("").writeEntry( "MaxCacheSize", cache_size
);
151 void KSaveIOConfig::setCacheControl(KIO::CacheControl policy
)
153 KConfig
* cfg
= http_config ();
154 QString tmp
= KIO::getCacheControlString(policy
);
155 cfg
->group("").writeEntry("cache", tmp
);
159 void KSaveIOConfig::setMaxCacheAge( int cache_age
)
161 KConfig
* cfg
= http_config ();
162 cfg
->group("").writeEntry( "MaxCacheAge", cache_age
);
166 void KSaveIOConfig::setUseReverseProxy( bool mode
)
168 KConfig
* cfg
= config ();
169 cfg
->group("Proxy Settings").writeEntry("ReversedException", mode
);
173 void KSaveIOConfig::setProxyType(KProtocolManager::ProxyType type
)
175 KConfig
* cfg
= config ();
176 cfg
->group("Proxy Settings").writeEntry( "ProxyType", static_cast<int>(type
) );
180 void KSaveIOConfig::setProxyAuthMode(KProtocolManager::ProxyAuthMode mode
)
182 KConfig
* cfg
= config ();
183 cfg
->group("Proxy Settings").writeEntry( "AuthMode", static_cast<int>(mode
) );
187 void KSaveIOConfig::setNoProxyFor( const QString
& _noproxy
)
189 KConfig
* cfg
= config ();
190 cfg
->group("Proxy Settings").writeEntry( "NoProxyFor", _noproxy
);
194 void KSaveIOConfig::setProxyFor( const QString
& protocol
,
195 const QString
& _proxy
)
197 KConfig
* cfg
= config ();
198 cfg
->group("Proxy Settings").writeEntry( protocol
.toLower() + "Proxy", _proxy
);
202 void KSaveIOConfig::setProxyConfigScript( const QString
& _url
)
204 KConfig
* cfg
= config ();
205 cfg
->group("Proxy Settings").writeEntry( "Proxy Config Script", _url
);
209 void KSaveIOConfig::setPersistentProxyConnection( bool enable
)
211 KConfig
* cfg
= config ();
212 cfg
->group("").writeEntry( "PersistentProxyConnection", enable
);
216 void KSaveIOConfig::setPersistentConnections( bool enable
)
218 KConfig
* cfg
= config ();
219 cfg
->group("").writeEntry( "PersistentConnections", enable
);
223 void KSaveIOConfig::updateRunningIOSlaves (QWidget
*parent
)
225 // Inform all running io-slaves about the changes...
226 // if we cannot update, ioslaves inform the end user...
227 QDBusMessage message
=
228 QDBusMessage::createSignal("/KIO/Scheduler", "org.kde.KIO.Scheduler", "reparseSlaveConfiguration");
229 message
<< QString();
230 if (!QDBusConnection::sessionBus().send(message
))
232 QString caption
= i18n("Update Failed");
233 QString message
= i18n("You have to restart the running applications "
234 "for these changes to take effect.");
235 KMessageBox::information (parent
, message
, caption
);
240 void KSaveIOConfig::updateProxyScout( QWidget
* parent
)
242 // Inform the proxyscout kded module about changes
243 // if we cannot update, ioslaves inform the end user...
244 QDBusInterface
kded("org.kde.kded", "/modules/proxyscout", "org.kde.kded.ProxyScout");
245 QDBusReply
<void> reply
= kded
.call( "reset" );
246 if (!reply
.isValid())
248 QString caption
= i18n("Update Failed");
249 QString message
= i18n("You have to restart KDE "
250 "for these changes to take effect.");
251 KMessageBox::information (parent
, message
, caption
);