• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kio/kio
 

kio/kio

  • kio
  • kio
slaveconfig.cpp
1 // -*- c++ -*-
2 /*
3  * This file is part of the KDE libraries
4  * Copyright (c) 2001 Waldo Bastian <bastian@kde.org>
5  *
6  * $Id$
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License version 2 as published by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  **/
22 
23 #include <assert.h>
24 
25 #include <tqdict.h>
26 
27 #include <kconfig.h>
28 #include <kstaticdeleter.h>
29 #include <kprotocolinfo.h>
30 #include <kprotocolmanager.h>
31 
32 #include "slaveconfig.h"
33 
34 using namespace KIO;
35 
36 namespace KIO {
37 
38 class SlaveConfigProtocol
39 {
40 public:
41  SlaveConfigProtocol() { host.setAutoDelete(true); }
42  ~SlaveConfigProtocol()
43  {
44  delete configFile;
45  }
46 
47 public:
48  MetaData global;
49  TQDict<MetaData> host;
50  KConfig *configFile;
51 };
52 
53 static void readConfig(KConfig *config, const TQString & group, MetaData *metaData)
54 {
55  *metaData += config->entryMap(group);
56 }
57 
58 class SlaveConfigPrivate
59 {
60  public:
61  void readGlobalConfig();
62  SlaveConfigProtocol *readProtocolConfig(const TQString &_protocol);
63  SlaveConfigProtocol *findProtocolConfig(const TQString &_protocol);
64  void readConfigProtocolHost(const TQString &_protocol, SlaveConfigProtocol *scp, const TQString &host);
65  public:
66  MetaData global;
67  TQDict<SlaveConfigProtocol> protocol;
68 };
69 
70 void SlaveConfigPrivate::readGlobalConfig()
71 {
72  global.clear();
73  // Read stuff...
74  KConfig *config = KProtocolManager::config();
75  readConfig(KGlobal::config(), "Socks", &global); // Socks settings.
76  if ( config )
77  readConfig(config, "<default>", &global);
78 }
79 
80 SlaveConfigProtocol* SlaveConfigPrivate::readProtocolConfig(const TQString &_protocol)
81 {
82  SlaveConfigProtocol *scp = protocol.find(_protocol);
83  if (!scp)
84  {
85  TQString filename = KProtocolInfo::config(_protocol);
86  scp = new SlaveConfigProtocol;
87  scp->configFile = new KConfig(filename, true, false);
88  protocol.insert(_protocol, scp);
89  }
90  // Read global stuff...
91  readConfig(scp->configFile, "<default>", &(scp->global));
92  return scp;
93 }
94 
95 SlaveConfigProtocol* SlaveConfigPrivate::findProtocolConfig(const TQString &_protocol)
96 {
97  SlaveConfigProtocol *scp = protocol.find(_protocol);
98  if (!scp)
99  scp = readProtocolConfig(_protocol);
100  return scp;
101 }
102 
103 void SlaveConfigPrivate::readConfigProtocolHost(const TQString &, SlaveConfigProtocol *scp, const TQString &host)
104 {
105  MetaData *metaData = new MetaData;
106  scp->host.replace(host, metaData);
107 
108  // Read stuff
109  // Break host into domains
110  TQString domain = host;
111 
112  if (!domain.contains('.'))
113  {
114  // Host without domain.
115  if (scp->configFile->hasGroup("<local>"))
116  readConfig(scp->configFile, "<local>", metaData);
117  }
118 
119  int pos = 0;
120  do
121  {
122  pos = host.findRev('.', pos-1);
123 
124  if (pos < 0)
125  domain = host;
126  else
127  domain = host.mid(pos+1);
128 
129  if (scp->configFile->hasGroup(domain))
130  readConfig(scp->configFile, domain.lower(), metaData);
131  }
132  while (pos > 0);
133 }
134 
135 
136 SlaveConfig *SlaveConfig::_self = 0;
137 static KStaticDeleter<SlaveConfig> slaveconfigsd;
138 
139 SlaveConfig *SlaveConfig::self()
140 {
141  if (!_self)
142  _self = slaveconfigsd.setObject(_self, new SlaveConfig);
143  return _self;
144 }
145 
146 SlaveConfig::SlaveConfig()
147 {
148  d = new SlaveConfigPrivate;
149  d->protocol.setAutoDelete(true);
150  d->readGlobalConfig();
151 }
152 
153 SlaveConfig::~SlaveConfig()
154 {
155  delete d; d = 0;
156  _self = 0;
157 }
158 
159 void SlaveConfig::setConfigData(const TQString &protocol,
160  const TQString &host,
161  const TQString &key,
162  const TQString &value )
163 {
164  MetaData config;
165  config.insert(key, value);
166  setConfigData(protocol, host, config);
167 }
168 
169 void SlaveConfig::setConfigData(const TQString &protocol, const TQString &host, const MetaData &config )
170 {
171  if (protocol.isEmpty())
172  d->global += config;
173  else {
174  SlaveConfigProtocol *scp = d->findProtocolConfig(protocol);
175  if (host.isEmpty())
176  {
177  scp->global += config;
178  }
179  else
180  {
181  MetaData *hostConfig = scp->host.find(host);
182  if (!hostConfig)
183  {
184  d->readConfigProtocolHost(protocol, scp, host);
185  hostConfig = scp->host.find(host);
186  assert(hostConfig);
187  }
188  *hostConfig += config;
189  }
190  }
191 }
192 
193 MetaData SlaveConfig::configData(const TQString &protocol, const TQString &host)
194 {
195  MetaData config = d->global;
196  SlaveConfigProtocol *scp = d->findProtocolConfig(protocol);
197  config += scp->global;
198  if (host.isEmpty())
199  return config;
200  MetaData *hostConfig = scp->host.find(host);
201  if (!hostConfig)
202  {
203  d->readConfigProtocolHost(protocol, scp, host);
204  emit configNeeded(protocol, host);
205  hostConfig = scp->host.find(host);
206  assert(hostConfig);
207  }
208  config += *hostConfig;
209  return config;
210 }
211 
212 TQString SlaveConfig::configData(const TQString &protocol, const TQString &host, const TQString &key)
213 {
214  return configData(protocol, host)[key];
215 }
216 
217 void SlaveConfig::reset()
218 {
219  d->protocol.clear();
220  d->readGlobalConfig();
221 }
222 
223 }
224 
225 #include "slaveconfig.moc"
KIO::MetaData
MetaData is a simple map of key/value strings.
Definition: global.h:515
KIO::SlaveConfig
SlaveConfig.
Definition: slaveconfig.h:48
KIO::SlaveConfig::configNeeded
void configNeeded(const TQString &protocol, const TQString &host)
This signal is raised when a slave of type protocol deals with host for the first time.
KIO::SlaveConfig::configData
MetaData configData(const TQString &protocol, const TQString &host)
Query slave configuration for slaves of type protocol when dealing with host.
Definition: slaveconfig.cpp:193
KIO::SlaveConfig::setConfigData
void setConfigData(const TQString &protocol, const TQString &host, const TQString &key, const TQString &value)
Configure slaves of type protocol by setting key to value.
Definition: slaveconfig.cpp:159
KIO::SlaveConfig::reset
void reset()
Undo any changes made by calls to setConfigData.
Definition: slaveconfig.cpp:217
KProtocolInfo::config
static TQString config(const TQString &protocol)
Returns the name of the config file associated with the specified protocol.
KIO
A namespace for KIO globals.
Definition: authinfo.h:29

kio/kio

Skip menu "kio/kio"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kio/kio

Skip menu "kio/kio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kio/kio by doxygen 1.9.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |