summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-06-29 05:35:06 (UTC)
committer ulf69 <ulf69>2004-06-29 05:35:06 (UTC)
commitb863f47dbb927a54f492b70ac59f3f99202dd7ca (patch) (unidiff)
treec5fffc44350972f0e7c963ea1ac98f2d5ce2dcfa
parented68714fca68286417778f0f5378b9f65d4acaa3 (diff)
downloadkdepimpi-b863f47dbb927a54f492b70ac59f3f99202dd7ca.zip
kdepimpi-b863f47dbb927a54f492b70ac59f3f99202dd7ca.tar.gz
kdepimpi-b863f47dbb927a54f492b70ac59f3f99202dd7ca.tar.bz2
added Qtopia as directory to search for libraries (Qtopia/libs)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdecore/kstandarddirs.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/microkde/kdecore/kstandarddirs.cpp b/microkde/kdecore/kstandarddirs.cpp
index 5abe05c..1a1e027 100644
--- a/microkde/kdecore/kstandarddirs.cpp
+++ b/microkde/kdecore/kstandarddirs.cpp
@@ -1,655 +1,658 @@
1/* This file is part of the KDE libraries 1/* This file is part of the KDE libraries
2 Copyright (C) 1999 Sirtaj Singh Kang <taj@kde.org> 2 Copyright (C) 1999 Sirtaj Singh Kang <taj@kde.org>
3 Copyright (C) 1999 Stephan Kulow <coolo@kde.org> 3 Copyright (C) 1999 Stephan Kulow <coolo@kde.org>
4 Copyright (C) 1999 Waldo Bastian <bastian@kde.org> 4 Copyright (C) 1999 Waldo Bastian <bastian@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License version 2 as published by the Free Software Foundation. 8 License version 2 as published by the Free Software Foundation.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22 * Author: Stephan Kulow <coolo@kde.org> and Sirtaj Singh Kang <taj@kde.org> 22 * Author: Stephan Kulow <coolo@kde.org> and Sirtaj Singh Kang <taj@kde.org>
23 * Version:$Id$ 23 * Version:$Id$
24 * Generated:Thu Mar 5 16:05:28 EST 1998 24 * Generated:Thu Mar 5 16:05:28 EST 1998
25 */ 25 */
26 26
27//US #include "config.h" 27//US #include "config.h"
28 28
29#include <stdlib.h> 29#include <stdlib.h>
30#include <assert.h> 30#include <assert.h>
31//US#include <errno.h> 31//US#include <errno.h>
32//US #ifdef HAVE_SYS_STAT_H 32//US #ifdef HAVE_SYS_STAT_H
33//US #include <sys/stat.h> 33//US #include <sys/stat.h>
34//US #endif 34//US #endif
35//US#include <sys/types.h> 35//US#include <sys/types.h>
36//US#include <dirent.h> 36//US#include <dirent.h>
37//US#include <pwd.h> 37//US#include <pwd.h>
38 38
39#include <qregexp.h> 39#include <qregexp.h>
40#include <qasciidict.h> 40#include <qasciidict.h>
41#include <qdict.h> 41#include <qdict.h>
42#include <qdir.h> 42#include <qdir.h>
43#include <qfileinfo.h> 43#include <qfileinfo.h>
44#include <qstring.h> 44#include <qstring.h>
45#include <qstringlist.h> 45#include <qstringlist.h>
46#include <qpe/qpeapplication.h>
46 47
47#include "kstandarddirs.h" 48#include "kstandarddirs.h"
48#include "kconfig.h" 49#include "kconfig.h"
49#include "kdebug.h" 50#include "kdebug.h"
50//US #include "kinstance.h" 51//US #include "kinstance.h"
51#include "kshell.h" 52#include "kshell.h"
52//US#include <sys/param.h> 53//US#include <sys/param.h>
53//US#include <unistd.h> 54//US#include <unistd.h>
54 55
55//US 56//US
56QString KStandardDirs::mAppDir = QString::null; 57QString KStandardDirs::mAppDir = QString::null;
57 58
58 59
59template class QDict<QStringList>; 60template class QDict<QStringList>;
60 61
61#if 0 62#if 0
62#include <qtextedit.h> 63#include <qtextedit.h>
63void ddd( QString op ) 64void ddd( QString op )
64{ 65{
65 static QTextEdit * dot = 0; 66 static QTextEdit * dot = 0;
66 if ( ! dot ) 67 if ( ! dot )
67 dot = new QTextEdit(); 68 dot = new QTextEdit();
68 69
69 dot->show(); 70 dot->show();
70 71
71 dot->append( op ); 72 dot->append( op );
72 73
73} 74}
74#endif 75#endif
75class KStandardDirs::KStandardDirsPrivate 76class KStandardDirs::KStandardDirsPrivate
76{ 77{
77public: 78public:
78 KStandardDirsPrivate() 79 KStandardDirsPrivate()
79 : restrictionsActive(false), 80 : restrictionsActive(false),
80 dataRestrictionActive(false) 81 dataRestrictionActive(false)
81 { } 82 { }
82 83
83 bool restrictionsActive; 84 bool restrictionsActive;
84 bool dataRestrictionActive; 85 bool dataRestrictionActive;
85 QAsciiDict<bool> restrictions; 86 QAsciiDict<bool> restrictions;
86 QStringList xdgdata_prefixes; 87 QStringList xdgdata_prefixes;
87 QStringList xdgconf_prefixes; 88 QStringList xdgconf_prefixes;
88}; 89};
89 90
90static const char* const types[] = {"html", "icon", "apps", "sound", 91static const char* const types[] = {"html", "icon", "apps", "sound",
91 "data", "locale", "services", "mime", 92 "data", "locale", "services", "mime",
92 "servicetypes", "config", "exe", 93 "servicetypes", "config", "exe",
93 "wallpaper", "lib", "pixmap", "templates", 94 "wallpaper", "lib", "pixmap", "templates",
94 "module", "qtplugins", 95 "module", "qtplugins",
95 "xdgdata-apps", "xdgdata-dirs", "xdgconf-menu", 0 }; 96 "xdgdata-apps", "xdgdata-dirs", "xdgconf-menu", 0 };
96 97
97static int tokenize( QStringList& token, const QString& str, 98static int tokenize( QStringList& token, const QString& str,
98 const QString& delim ); 99 const QString& delim );
99 100
100KStandardDirs::KStandardDirs( ) : addedCustoms(false) 101KStandardDirs::KStandardDirs( ) : addedCustoms(false)
101{ 102{
102 d = new KStandardDirsPrivate; 103 d = new KStandardDirsPrivate;
103 dircache.setAutoDelete(true); 104 dircache.setAutoDelete(true);
104 relatives.setAutoDelete(true); 105 relatives.setAutoDelete(true);
105 absolutes.setAutoDelete(true); 106 absolutes.setAutoDelete(true);
106 savelocations.setAutoDelete(true); 107 savelocations.setAutoDelete(true);
107 addKDEDefaults(); 108 addKDEDefaults();
108} 109}
109 110
110KStandardDirs::~KStandardDirs() 111KStandardDirs::~KStandardDirs()
111{ 112{
112 delete d; 113 delete d;
113} 114}
114 115
115bool KStandardDirs::isRestrictedResource(const char *type, const QString& relPath) const 116bool KStandardDirs::isRestrictedResource(const char *type, const QString& relPath) const
116{ 117{
117 if (!d || !d->restrictionsActive) 118 if (!d || !d->restrictionsActive)
118 return false; 119 return false;
119 120
120 if (d->restrictions[type]) 121 if (d->restrictions[type])
121 return true; 122 return true;
122 123
123 if (strcmp(type, "data")==0) 124 if (strcmp(type, "data")==0)
124 { 125 {
125 applyDataRestrictions(relPath); 126 applyDataRestrictions(relPath);
126 if (d->dataRestrictionActive) 127 if (d->dataRestrictionActive)
127 { 128 {
128 d->dataRestrictionActive = false; 129 d->dataRestrictionActive = false;
129 return true; 130 return true;
130 } 131 }
131 } 132 }
132 return false; 133 return false;
133} 134}
134 135
135void KStandardDirs::applyDataRestrictions(const QString &relPath) const 136void KStandardDirs::applyDataRestrictions(const QString &relPath) const
136{ 137{
137 QString key; 138 QString key;
138 int i = relPath.find('/'); 139 int i = relPath.find('/');
139 if (i != -1) 140 if (i != -1)
140 key = "data_"+relPath.left(i); 141 key = "data_"+relPath.left(i);
141 else 142 else
142 key = "data_"+relPath; 143 key = "data_"+relPath;
143 144
144 if (d && d->restrictions[key.latin1()]) 145 if (d && d->restrictions[key.latin1()])
145 d->dataRestrictionActive = true; 146 d->dataRestrictionActive = true;
146} 147}
147 148
148 149
149QStringList KStandardDirs::allTypes() const 150QStringList KStandardDirs::allTypes() const
150{ 151{
151 QStringList list; 152 QStringList list;
152 for (int i = 0; types[i] != 0; ++i) 153 for (int i = 0; types[i] != 0; ++i)
153 list.append(QString::fromLatin1(types[i])); 154 list.append(QString::fromLatin1(types[i]));
154 return list; 155 return list;
155} 156}
156 157
157void KStandardDirs::addPrefix( const QString& _dir ) 158void KStandardDirs::addPrefix( const QString& _dir )
158{ 159{
159 if (_dir.isNull()) 160 if (_dir.isNull())
160 return; 161 return;
161 162
162 QString dir = _dir; 163 QString dir = _dir;
163 if (dir.at(dir.length() - 1) != '/') 164 if (dir.at(dir.length() - 1) != '/')
164 dir += '/'; 165 dir += '/';
165 166
166 if (!prefixes.contains(dir)) { 167 if (!prefixes.contains(dir)) {
167 prefixes.append(dir); 168 prefixes.append(dir);
168 dircache.clear(); 169 dircache.clear();
169 } 170 }
170} 171}
171 172
172void KStandardDirs::addXdgConfigPrefix( const QString& _dir ) 173void KStandardDirs::addXdgConfigPrefix( const QString& _dir )
173{ 174{
174 if (_dir.isNull()) 175 if (_dir.isNull())
175 return; 176 return;
176 177
177 QString dir = _dir; 178 QString dir = _dir;
178 if (dir.at(dir.length() - 1) != '/') 179 if (dir.at(dir.length() - 1) != '/')
179 dir += '/'; 180 dir += '/';
180 181
181 if (!d->xdgconf_prefixes.contains(dir)) { 182 if (!d->xdgconf_prefixes.contains(dir)) {
182 d->xdgconf_prefixes.append(dir); 183 d->xdgconf_prefixes.append(dir);
183 dircache.clear(); 184 dircache.clear();
184 } 185 }
185} 186}
186 187
187void KStandardDirs::addXdgDataPrefix( const QString& _dir ) 188void KStandardDirs::addXdgDataPrefix( const QString& _dir )
188{ 189{
189 if (_dir.isNull()) 190 if (_dir.isNull())
190 return; 191 return;
191 192
192 QString dir = _dir; 193 QString dir = _dir;
193 if (dir.at(dir.length() - 1) != '/') 194 if (dir.at(dir.length() - 1) != '/')
194 dir += '/'; 195 dir += '/';
195 196
196 if (!d->xdgdata_prefixes.contains(dir)) { 197 if (!d->xdgdata_prefixes.contains(dir)) {
197 d->xdgdata_prefixes.append(dir); 198 d->xdgdata_prefixes.append(dir);
198 dircache.clear(); 199 dircache.clear();
199 } 200 }
200} 201}
201 202
202 203
203QString KStandardDirs::kfsstnd_prefixes() 204QString KStandardDirs::kfsstnd_prefixes()
204{ 205{
205 return prefixes.join(":"); 206 return prefixes.join(":");
206} 207}
207 208
208bool KStandardDirs::addResourceType( const char *type, 209bool KStandardDirs::addResourceType( const char *type,
209 const QString& relativename ) 210 const QString& relativename )
210{ 211{
211 if (relativename.isNull()) 212 if (relativename.isNull())
212 return false; 213 return false;
213 214
214 QStringList *rels = relatives.find(type); 215 QStringList *rels = relatives.find(type);
215 if (!rels) { 216 if (!rels) {
216 rels = new QStringList(); 217 rels = new QStringList();
217 relatives.insert(type, rels); 218 relatives.insert(type, rels);
218 } 219 }
219 QString copy = relativename; 220 QString copy = relativename;
220 if (copy.at(copy.length() - 1) != '/') 221 if (copy.at(copy.length() - 1) != '/')
221 copy += '/'; 222 copy += '/';
222 if (!rels->contains(copy)) { 223 if (!rels->contains(copy)) {
223 rels->prepend(copy); 224 rels->prepend(copy);
224 dircache.remove(type); // clean the cache 225 dircache.remove(type); // clean the cache
225 return true; 226 return true;
226 } 227 }
227 return false; 228 return false;
228} 229}
229 230
230bool KStandardDirs::addResourceDir( const char *type, 231bool KStandardDirs::addResourceDir( const char *type,
231 const QString& absdir) 232 const QString& absdir)
232{ 233{
233 QStringList *paths = absolutes.find(type); 234 QStringList *paths = absolutes.find(type);
234 if (!paths) { 235 if (!paths) {
235 paths = new QStringList(); 236 paths = new QStringList();
236 absolutes.insert(type, paths); 237 absolutes.insert(type, paths);
237 } 238 }
238 QString copy = absdir; 239 QString copy = absdir;
239 if (copy.at(copy.length() - 1) != '/') 240 if (copy.at(copy.length() - 1) != '/')
240 copy += '/'; 241 copy += '/';
241 242
242 if (!paths->contains(copy)) { 243 if (!paths->contains(copy)) {
243 paths->append(copy); 244 paths->append(copy);
244 dircache.remove(type); // clean the cache 245 dircache.remove(type); // clean the cache
245 return true; 246 return true;
246 } 247 }
247 return false; 248 return false;
248} 249}
249 250
250QString KStandardDirs::findResource( const char *type, 251QString KStandardDirs::findResource( const char *type,
251 const QString& filename ) const 252 const QString& filename ) const
252{ 253{
253 if (filename.at(0) == '/') 254 if (filename.at(0) == '/')
254 return filename; // absolute dirs are absolute dirs, right? :-/ 255 return filename; // absolute dirs are absolute dirs, right? :-/
255 256
256#if 0 257#if 0
257kdDebug() << "Find resource: " << type << endl; 258kdDebug() << "Find resource: " << type << endl;
258for (QStringList::ConstIterator pit = prefixes.begin(); 259for (QStringList::ConstIterator pit = prefixes.begin();
259 pit != prefixes.end(); 260 pit != prefixes.end();
260 pit++) 261 pit++)
261{ 262{
262 kdDebug() << "Prefix: " << *pit << endl; 263 kdDebug() << "Prefix: " << *pit << endl;
263} 264}
264#endif 265#endif
265 266
266 QString dir = findResourceDir(type, filename); 267 QString dir = findResourceDir(type, filename);
267 if (dir.isNull()) 268 if (dir.isNull())
268 return dir; 269 return dir;
269 else return dir + filename; 270 else return dir + filename;
270} 271}
271/*US 272/*US
272static Q_UINT32 updateHash(const QString &file, Q_UINT32 hash) 273static Q_UINT32 updateHash(const QString &file, Q_UINT32 hash)
273{ 274{
274 QCString cFile = QFile::encodeName(file); 275 QCString cFile = QFile::encodeName(file);
275//US struct stat buff; 276//US struct stat buff;
276//US if ((access(cFile, R_OK) == 0) && 277//US if ((access(cFile, R_OK) == 0) &&
277//US (stat( cFile, &buff ) == 0) && 278//US (stat( cFile, &buff ) == 0) &&
278//US (S_ISREG( buff.st_mode ))) 279//US (S_ISREG( buff.st_mode )))
279 QFileInfo pathfnInfo(cFile); 280 QFileInfo pathfnInfo(cFile);
280 if (( pathfnInfo.isReadable() == true ) && 281 if (( pathfnInfo.isReadable() == true ) &&
281 ( pathfnInfo.isFile()) ) 282 ( pathfnInfo.isFile()) )
282 { 283 {
283//US hash = hash + (Q_UINT32) buff.st_ctime; 284//US hash = hash + (Q_UINT32) buff.st_ctime;
284 hash = hash + (Q_UINT32) pathfnInfo.lastModified(); 285 hash = hash + (Q_UINT32) pathfnInfo.lastModified();
285 } 286 }
286 return hash; 287 return hash;
287} 288}
288*/ 289*/
289/*US 290/*US
290Q_UINT32 KStandardDirs::calcResourceHash( const char *type, 291Q_UINT32 KStandardDirs::calcResourceHash( const char *type,
291 const QString& filename, bool deep) const 292 const QString& filename, bool deep) const
292{ 293{
293 Q_UINT32 hash = 0; 294 Q_UINT32 hash = 0;
294 295
295 if (filename.at(0) == '/') 296 if (filename.at(0) == '/')
296 { 297 {
297 // absolute dirs are absolute dirs, right? :-/ 298 // absolute dirs are absolute dirs, right? :-/
298 return updateHash(filename, hash); 299 return updateHash(filename, hash);
299 } 300 }
300 if (d && d->restrictionsActive && (strcmp(type, "data")==0)) 301 if (d && d->restrictionsActive && (strcmp(type, "data")==0))
301 applyDataRestrictions(filename); 302 applyDataRestrictions(filename);
302 QStringList candidates = resourceDirs(type); 303 QStringList candidates = resourceDirs(type);
303 QString fullPath; 304 QString fullPath;
304 305
305 for (QStringList::ConstIterator it = candidates.begin(); 306 for (QStringList::ConstIterator it = candidates.begin();
306 it != candidates.end(); it++) 307 it != candidates.end(); it++)
307 { 308 {
308 hash = updateHash(*it + filename, hash); 309 hash = updateHash(*it + filename, hash);
309 if (!deep && hash) 310 if (!deep && hash)
310 return hash; 311 return hash;
311 } 312 }
312 return hash; 313 return hash;
313} 314}
314*/ 315*/
315 316
316QStringList KStandardDirs::findDirs( const char *type, 317QStringList KStandardDirs::findDirs( const char *type,
317 const QString& reldir ) const 318 const QString& reldir ) const
318{ 319{
319 QStringList list; 320 QStringList list;
320 321
321 checkConfig(); 322 checkConfig();
322 323
323 if (d && d->restrictionsActive && (strcmp(type, "data")==0)) 324 if (d && d->restrictionsActive && (strcmp(type, "data")==0))
324 applyDataRestrictions(reldir); 325 applyDataRestrictions(reldir);
325 QStringList candidates = resourceDirs(type); 326 QStringList candidates = resourceDirs(type);
326 QDir testdir; 327 QDir testdir;
327 328
328 for (QStringList::ConstIterator it = candidates.begin(); 329 for (QStringList::ConstIterator it = candidates.begin();
329 it != candidates.end(); it++) { 330 it != candidates.end(); it++) {
330 testdir.setPath(*it + reldir); 331 testdir.setPath(*it + reldir);
331 if (testdir.exists()) 332 if (testdir.exists())
332 list.append(testdir.absPath() + '/'); 333 list.append(testdir.absPath() + '/');
333 } 334 }
334 335
335 return list; 336 return list;
336} 337}
337 338
338QString KStandardDirs::findResourceDir( const char *type, 339QString KStandardDirs::findResourceDir( const char *type,
339 const QString& filename) const 340 const QString& filename) const
340{ 341{
341#ifndef NDEBUG 342#ifndef NDEBUG
342 if (filename.isEmpty()) { 343 if (filename.isEmpty()) {
343 kdWarning() << "filename for type " << type << " in KStandardDirs::findResourceDir is not supposed to be empty!!" << endl; 344 kdWarning() << "filename for type " << type << " in KStandardDirs::findResourceDir is not supposed to be empty!!" << endl;
344 return QString::null; 345 return QString::null;
345 } 346 }
346#endif 347#endif
347 348
348 if (d && d->restrictionsActive && (strcmp(type, "data")==0)) 349 if (d && d->restrictionsActive && (strcmp(type, "data")==0))
349 applyDataRestrictions(filename); 350 applyDataRestrictions(filename);
350 QStringList candidates = resourceDirs(type); 351 QStringList candidates = resourceDirs(type);
351 QString fullPath; 352 QString fullPath;
352 353
353 for (QStringList::ConstIterator it = candidates.begin(); 354 for (QStringList::ConstIterator it = candidates.begin(); it != candidates.end(); it++)
354 it != candidates.end(); it++) 355 {
355 if (exists(*it + filename)) 356 if (exists(*it + filename))
356 return *it; 357 return *it;
358 }
357 359
358#ifndef NDEBUG 360#ifndef NDEBUG
359 if(false && type != "locale") 361 if(false && type != "locale")
360 kdDebug() << "KStdDirs::findResDir(): can't find \"" << filename << "\" in type \"" << type << "\"." << endl; 362 kdDebug() << "KStdDirs::findResDir(): can't find \"" << filename << "\" in type \"" << type << "\"." << endl;
361#endif 363#endif
362 364
363 return QString::null; 365 return QString::null;
364} 366}
365 367
366bool KStandardDirs::exists(const QString &fullPath) 368bool KStandardDirs::exists(const QString &fullPath)
367{ 369{
368//US struct stat buff; 370//US struct stat buff;
369 QFileInfo fullPathInfo(QFile::encodeName(fullPath)); 371 QFileInfo fullPathInfo(QFile::encodeName(fullPath));
370 372
371//US if (access(QFile::encodeName(fullPath), R_OK) == 0 && fullPathInfo.isReadable()) 373//US if (access(QFile::encodeName(fullPath), R_OK) == 0 && fullPathInfo.isReadable())
372 if (fullPathInfo.isReadable()) 374 if (fullPathInfo.isReadable())
373 { 375 {
374 if (fullPath.at(fullPath.length() - 1) != '/') { 376 if (fullPath.at(fullPath.length() - 1) != '/') {
375 //US if (S_ISREG( buff.st_mode )) 377 //US if (S_ISREG( buff.st_mode ))
376 if (fullPathInfo.isFile()) 378 if (fullPathInfo.isFile())
377 return true; 379 return true;
378 } 380 }
379 else { 381 else {
380 //US if (S_ISDIR( buff.st_mode )) 382 //US if (S_ISDIR( buff.st_mode ))
381 if (fullPathInfo.isDir()) 383 if (fullPathInfo.isDir())
382 return true; 384 return true;
383 } 385 }
384 } 386 }
385 return false; 387 return false;
386} 388}
387 389
388static void lookupDirectory(const QString& path, const QString &relPart, 390static void lookupDirectory(const QString& path, const QString &relPart,
389 const QRegExp &regexp, 391 const QRegExp &regexp,
390 QStringList& list, 392 QStringList& list,
391 QStringList& relList, 393 QStringList& relList,
392 bool recursive, bool uniq) 394 bool recursive, bool uniq)
393{ 395{
394 QString pattern = regexp.pattern(); 396 QString pattern = regexp.pattern();
395 if (recursive || pattern.contains('?') || pattern.contains('*')) 397 if (recursive || pattern.contains('?') || pattern.contains('*'))
396 { 398 {
397 // We look for a set of files. 399 // We look for a set of files.
398//US DIR *dp = opendir( QFile::encodeName(path)); 400//US DIR *dp = opendir( QFile::encodeName(path));
399 QDir dp(QFile::encodeName(path)); 401 QDir dp(QFile::encodeName(path));
402
400 if (!dp.exists()) 403 if (!dp.exists())
401 return; 404 return;
402 static int iii = 0; 405 static int iii = 0;
403 ++iii; 406 ++iii;
404 if ( iii == 5 ) 407 if ( iii == 5 )
405 abort(); 408 abort();
406 assert(path.at(path.length() - 1) == '/'); 409 assert(path.at(path.length() - 1) == '/');
407 410
408//US struct dirent *ep; 411//US struct dirent *ep;
409//US struct stat buff; 412//US struct stat buff;
410 413
411 QString _dot("."); 414 QString _dot(".");
412 QString _dotdot(".."); 415 QString _dotdot("..");
413 416
414//US while( ( ep = readdir( dp ) ) != 0L ) 417//US while( ( ep = readdir( dp ) ) != 0L )
415 QStringList direntries = dp.entryList(); 418 QStringList direntries = dp.entryList();
416 QStringList::Iterator it = direntries.begin(); 419 QStringList::Iterator it = direntries.begin();
417 420
418 while ( it != list.end() ) // for each file... 421 while ( it != list.end() ) // for each file...
419 { 422 {
420 423
421//US QString fn( QFile::decodeName(ep->d_name)); 424//US QString fn( QFile::decodeName(ep->d_name));
422 QString fn = (*it); // dp.entryList already decodes 425 QString fn = (*it); // dp.entryList already decodes
423 it++; 426 it++;
424 if ( fn.isNull() ) 427 if ( fn.isNull() )
425 break; 428 break;
426 429
427 if (fn == _dot || fn == _dotdot || fn.at(fn.length() - 1).latin1() == '~' ) 430 if (fn == _dot || fn == _dotdot || fn.at(fn.length() - 1).latin1() == '~' )
428 continue; 431 continue;
429 432
430/*US 433/*US
431 if (!recursive && !regexp.exactMatch(fn)) 434 if (!recursive && !regexp.exactMatch(fn))
432 continue; // No match 435 continue; // No match
433*/ 436*/
434//US this should do the same: 437//US this should do the same:
435 int pos = regexp.match(fn); 438 int pos = regexp.match(fn);
436 if (!recursive && !pos == 0) 439 if (!recursive && !pos == 0)
437 continue; // No match 440 continue; // No match
438 441
439 QString pathfn = path + fn; 442 QString pathfn = path + fn;
440/*US 443/*US
441 if ( stat( QFile::encodeName(pathfn), &buff ) != 0 ) { 444 if ( stat( QFile::encodeName(pathfn), &buff ) != 0 ) {
442 kdDebug() << "Error stat'ing " << pathfn << " : " << perror << endl; 445 kdDebug() << "Error stat'ing " << pathfn << " : " << perror << endl;
443 continue; // Couldn't stat (e.g. no read permissions) 446 continue; // Couldn't stat (e.g. no read permissions)
444 } 447 }
445 448
446 if ( recursive ) 449 if ( recursive )
447 { 450 {
448 if ( S_ISDIR( buff.st_mode )) { 451 if ( S_ISDIR( buff.st_mode )) {
449 lookupDirectory(pathfn + '/', relPart + fn + '/', regexp, list, relList, recursive, uniq); 452 lookupDirectory(pathfn + '/', relPart + fn + '/', regexp, list, relList, recursive, uniq);
450 } 453 }
451*/ 454*/
452//US replacement: 455//US replacement:
453 QFileInfo pathfnInfo(QFile::encodeName(pathfn)); 456 QFileInfo pathfnInfo(QFile::encodeName(pathfn));
454 if ( pathfnInfo.isReadable() == false ) 457 if ( pathfnInfo.isReadable() == false )
455 { 458 {
456//US kdDebug() << "Error stat'ing " << pathfn << " : " << perror << endl; 459//US kdDebug() << "Error stat'ing " << pathfn << " : " << perror << endl;
457 continue; // Couldn't stat (e.g. no read permissions) 460 continue; // Couldn't stat (e.g. no read permissions)
458 } 461 }
459 462
460 if ( recursive ) 463 if ( recursive )
461 { 464 {
462 if ( pathfnInfo.isDir()) { 465 if ( pathfnInfo.isDir()) {
463 lookupDirectory(pathfn + '/', relPart + fn + '/', regexp, list, relList, recursive, uniq); 466 lookupDirectory(pathfn + '/', relPart + fn + '/', regexp, list, relList, recursive, uniq);
464 } 467 }
465 468
466 469
467/*US 470/*US
468 if (!regexp.exactMatch(fn)) 471 if (!regexp.exactMatch(fn))
469 continue; // No match 472 continue; // No match
470*/ 473*/
471//US this should do the same: 474//US this should do the same:
472 pos = regexp.match(fn); 475 pos = regexp.match(fn);
473 if (!pos == 0) 476 if (!pos == 0)
474 continue; // No match 477 continue; // No match
475 } 478 }
476 479
477//US if ( S_ISREG( buff.st_mode)) 480//US if ( S_ISREG( buff.st_mode))
478 if ( pathfnInfo.isFile()) 481 if ( pathfnInfo.isFile())
479 { 482 {
480 if (!uniq || !relList.contains(relPart + fn)) 483 if (!uniq || !relList.contains(relPart + fn))
481 { 484 {
482 list.append( pathfn ); 485 list.append( pathfn );
483 relList.append( relPart + fn ); 486 relList.append( relPart + fn );
484 } 487 }
485 } 488 }
486 } 489 }
487//US closedir( dp ); 490//US closedir( dp );
488 } 491 }
489 else 492 else
490 { 493 {
491 // We look for a single file. 494 // We look for a single file.
492 QString fn = pattern; 495 QString fn = pattern;
493 QString pathfn = path + fn; 496 QString pathfn = path + fn;
494//US struct stat buff; 497//US struct stat buff;
495 QFileInfo pathfnInfo(QFile::encodeName(pathfn)); 498 QFileInfo pathfnInfo(QFile::encodeName(pathfn));
496 499
497 500
498//US if ( stat( QFile::encodeName(pathfn), &buff ) != 0 ) 501//US if ( stat( QFile::encodeName(pathfn), &buff ) != 0 )
499 if ( pathfnInfo.isReadable() == false ) 502 if ( pathfnInfo.isReadable() == false )
500 return; // File not found 503 return; // File not found
501 504
502//US if ( S_ISREG( buff.st_mode)) 505//US if ( S_ISREG( buff.st_mode))
503 if ( pathfnInfo.isFile()) 506 if ( pathfnInfo.isFile())
504 { 507 {
505 if (!uniq || !relList.contains(relPart + fn)) 508 if (!uniq || !relList.contains(relPart + fn))
506 { 509 {
507 list.append( pathfn ); 510 list.append( pathfn );
508 relList.append( relPart + fn ); 511 relList.append( relPart + fn );
509 } 512 }
510 } 513 }
511 } 514 }
512} 515}
513 516
514static void lookupPrefix(const QString& prefix, const QString& relpath, 517static void lookupPrefix(const QString& prefix, const QString& relpath,
515 const QString& relPart, 518 const QString& relPart,
516 const QRegExp &regexp, 519 const QRegExp &regexp,
517 QStringList& list, 520 QStringList& list,
518 QStringList& relList, 521 QStringList& relList,
519 bool recursive, bool uniq) 522 bool recursive, bool uniq)
520{ 523{
521 if (relpath.isNull()) { 524 if (relpath.isNull()) {
522 lookupDirectory(prefix, relPart, regexp, list, 525 lookupDirectory(prefix, relPart, regexp, list,
523 relList, recursive, uniq); 526 relList, recursive, uniq);
524 return; 527 return;
525 } 528 }
526 QString path; 529 QString path;
527 QString rest; 530 QString rest;
528 531
529 if (relpath.length()) 532 if (relpath.length())
530 { 533 {
531 int slash = relpath.find('/'); 534 int slash = relpath.find('/');
532 if (slash < 0) 535 if (slash < 0)
533 rest = relpath.left(relpath.length() - 1); 536 rest = relpath.left(relpath.length() - 1);
534 else { 537 else {
535 path = relpath.left(slash); 538 path = relpath.left(slash);
536 rest = relpath.mid(slash + 1); 539 rest = relpath.mid(slash + 1);
537 } 540 }
538 } 541 }
539 assert(prefix.at(prefix.length() - 1) == '/'); 542 assert(prefix.at(prefix.length() - 1) == '/');
540 543
541//US struct stat buff; 544//US struct stat buff;
542 545
543 if (path.contains('*') || path.contains('?')) { 546 if (path.contains('*') || path.contains('?')) {
544 QRegExp pathExp(path, true, true); 547 QRegExp pathExp(path, true, true);
545 //USDIR *dp = opendir( QFile::encodeName(prefix) ); 548 //USDIR *dp = opendir( QFile::encodeName(prefix) );
546 QDir dp(QFile::encodeName(prefix)); 549 QDir dp(QFile::encodeName(prefix));
547 550
548 //USif (!dp) 551 //USif (!dp)
549 if (!dp.exists()) 552 if (!dp.exists())
550 { 553 {
551 return; 554 return;
552 } 555 }
553 556
554 //USstruct dirent *ep; 557 //USstruct dirent *ep;
555 558
556 QString _dot("."); 559 QString _dot(".");
557 QString _dotdot(".."); 560 QString _dotdot("..");
558 561
559 //USwhile( ( ep = readdir( dp ) ) != 0L ) 562 //USwhile( ( ep = readdir( dp ) ) != 0L )
560 QStringList direntries = dp.entryList(); 563 QStringList direntries = dp.entryList();
561 QStringList::Iterator it = direntries.begin(); 564 QStringList::Iterator it = direntries.begin();
562 565
563 while ( it != list.end() ) // for each file... 566 while ( it != list.end() ) // for each file...
564 { 567 {
565//US QString fn( QFile::decodeName(ep->d_name)); 568//US QString fn( QFile::decodeName(ep->d_name));
566 QString fn = (*it); // dp.entryList() already encodes the strings 569 QString fn = (*it); // dp.entryList() already encodes the strings
567 it++; 570 it++;
568 571
569 if (fn == _dot || fn == _dotdot || fn.at(fn.length() - 1) == '~') 572 if (fn == _dot || fn == _dotdot || fn.at(fn.length() - 1) == '~')
570 continue; 573 continue;
571 574
572#ifdef DESKTOP_VERSION 575#ifdef DESKTOP_VERSION
573 576
574 if (pathExp.search(fn) == -1) 577 if (pathExp.search(fn) == -1)
575 continue; // No match 578 continue; // No match
576 579
577#else 580#else
578//US this should do the same: 581//US this should do the same:
579 if (pathExp.find(fn, 0) == -1) 582 if (pathExp.find(fn, 0) == -1)
580 continue; // No match 583 continue; // No match
581#endif 584#endif
582 QString rfn = relPart+fn; 585 QString rfn = relPart+fn;
583 fn = prefix + fn; 586 fn = prefix + fn;
584//US if ( stat( QFile::encodeName(fn), &buff ) != 0 ) 587//US if ( stat( QFile::encodeName(fn), &buff ) != 0 )
585 QFileInfo fnInfo(QFile::encodeName(fn)); 588 QFileInfo fnInfo(QFile::encodeName(fn));
586 if ( fnInfo.isReadable() == false ) 589 if ( fnInfo.isReadable() == false )
587 { 590 {
588//US kdDebug() << "Error statting " << fn << " : " << perror << endl; 591//US kdDebug() << "Error statting " << fn << " : " << perror << endl;
589 continue; // Couldn't stat (e.g. no permissions) 592 continue; // Couldn't stat (e.g. no permissions)
590 } 593 }
591 //US if ( S_ISDIR( buff.st_mode )) 594 //US if ( S_ISDIR( buff.st_mode ))
592 if ( fnInfo.isDir() ) 595 if ( fnInfo.isDir() )
593 596
594 lookupPrefix(fn + '/', rest, rfn + '/', regexp, list, relList, recursive, uniq); 597 lookupPrefix(fn + '/', rest, rfn + '/', regexp, list, relList, recursive, uniq);
595 } 598 }
596 599
597 //USclosedir( dp ); 600 //USclosedir( dp );
598 } else { 601 } else {
599 // Don't stat, if the dir doesn't exist we will find out 602 // Don't stat, if the dir doesn't exist we will find out
600 // when we try to open it. 603 // when we try to open it.
601 lookupPrefix(prefix + path + '/', rest, 604 lookupPrefix(prefix + path + '/', rest,
602 relPart + path + '/', regexp, list, 605 relPart + path + '/', regexp, list,
603 relList, recursive, uniq); 606 relList, recursive, uniq);
604 } 607 }
605} 608}
606 609
607QStringList 610QStringList
608KStandardDirs::findAllResources( const char *type, 611KStandardDirs::findAllResources( const char *type,
609 const QString& filter, 612 const QString& filter,
610 bool recursive, 613 bool recursive,
611 bool uniq, 614 bool uniq,
612 QStringList &relList) const 615 QStringList &relList) const
613{ 616{
614 QStringList list; 617 QStringList list;
615 if (filter.at(0) == '/') // absolute paths we return 618 if (filter.at(0) == '/') // absolute paths we return
616 { 619 {
617 list.append( filter); 620 list.append( filter);
618 return list; 621 return list;
619 } 622 }
620 623
621 QString filterPath; 624 QString filterPath;
622 QString filterFile; 625 QString filterFile;
623 626
624 if (filter.length()) 627 if (filter.length())
625 { 628 {
626 int slash = filter.findRev('/'); 629 int slash = filter.findRev('/');
627 if (slash < 0) 630 if (slash < 0)
628 filterFile = filter; 631 filterFile = filter;
629 else { 632 else {
630 filterPath = filter.left(slash + 1); 633 filterPath = filter.left(slash + 1);
631 filterFile = filter.mid(slash + 1); 634 filterFile = filter.mid(slash + 1);
632 } 635 }
633 } 636 }
634 checkConfig(); 637 checkConfig();
635 638
636 if (d && d->restrictionsActive && (strcmp(type, "data")==0)) 639 if (d && d->restrictionsActive && (strcmp(type, "data")==0))
637 applyDataRestrictions(filter); 640 applyDataRestrictions(filter);
638 QStringList candidates = resourceDirs(type); 641 QStringList candidates = resourceDirs(type);
639 if (filterFile.isEmpty()) 642 if (filterFile.isEmpty())
640 filterFile = "*"; 643 filterFile = "*";
641 644
642 QRegExp regExp(filterFile, true, true); 645 QRegExp regExp(filterFile, true, true);
643 for (QStringList::ConstIterator it = candidates.begin(); 646 for (QStringList::ConstIterator it = candidates.begin();
644 it != candidates.end(); it++) 647 it != candidates.end(); it++)
645 { 648 {
646 lookupPrefix(*it, filterPath, "", regExp, list, 649 lookupPrefix(*it, filterPath, "", regExp, list,
647 relList, recursive, uniq); 650 relList, recursive, uniq);
648 } 651 }
649 return list; 652 return list;
650} 653}
651 654
652QStringList 655QStringList
653KStandardDirs::findAllResources( const char *type, 656KStandardDirs::findAllResources( const char *type,
654 const QString& filter, 657 const QString& filter,
655 bool recursive, 658 bool recursive,
@@ -968,512 +971,514 @@ QString KStandardDirs::kde_default(const char *type) {
968 return "bin/"; 971 return "bin/";
969 if (!strcmp(type, "lib")) 972 if (!strcmp(type, "lib"))
970 return "lib/"; 973 return "lib/";
971 if (!strcmp(type, "module")) 974 if (!strcmp(type, "module"))
972 return "lib/kde3/"; 975 return "lib/kde3/";
973 if (!strcmp(type, "qtplugins")) 976 if (!strcmp(type, "qtplugins"))
974 return "lib/kde3/plugins"; 977 return "lib/kde3/plugins";
975 if (!strcmp(type, "xdgdata-apps")) 978 if (!strcmp(type, "xdgdata-apps"))
976 return "applications/"; 979 return "applications/";
977 if (!strcmp(type, "xdgdata-dirs")) 980 if (!strcmp(type, "xdgdata-dirs"))
978 return "desktop-directories/"; 981 return "desktop-directories/";
979 if (!strcmp(type, "xdgconf-menu")) 982 if (!strcmp(type, "xdgconf-menu"))
980 return "menus/"; 983 return "menus/";
981 qFatal("unknown resource type %s", type); 984 qFatal("unknown resource type %s", type);
982 return QString::null; 985 return QString::null;
983} 986}
984 987
985QString KStandardDirs::saveLocation(const char *type, 988QString KStandardDirs::saveLocation(const char *type,
986 const QString& suffix, 989 const QString& suffix,
987 bool create) const 990 bool create) const
988{ 991{
989 //qDebug("KStandardDirs::saveLocation called %s %s", type,suffix.latin1() ); 992 //qDebug("KStandardDirs::saveLocation called %s %s", type,suffix.latin1() );
990 //return ""; 993 //return "";
991 checkConfig(); 994 checkConfig();
992 995
993 QString *pPath = savelocations.find(type); 996 QString *pPath = savelocations.find(type);
994 if (!pPath) 997 if (!pPath)
995 { 998 {
996 QStringList *dirs = relatives.find(type); 999 QStringList *dirs = relatives.find(type);
997 if (!dirs && ( 1000 if (!dirs && (
998 (strcmp(type, "socket") == 0) || 1001 (strcmp(type, "socket") == 0) ||
999 (strcmp(type, "tmp") == 0) || 1002 (strcmp(type, "tmp") == 0) ||
1000 (strcmp(type, "cache") == 0) )) 1003 (strcmp(type, "cache") == 0) ))
1001 { 1004 {
1002 (void) resourceDirs(type); // Generate socket|tmp|cache resource. 1005 (void) resourceDirs(type); // Generate socket|tmp|cache resource.
1003 dirs = relatives.find(type); // Search again. 1006 dirs = relatives.find(type); // Search again.
1004 } 1007 }
1005 if (dirs) 1008 if (dirs)
1006 { 1009 {
1007 // Check for existance of typed directory + suffix 1010 // Check for existance of typed directory + suffix
1008 if (strncmp(type, "xdgdata-", 8) == 0) 1011 if (strncmp(type, "xdgdata-", 8) == 0)
1009 pPath = new QString(realPath(localxdgdatadir() + dirs->last())); 1012 pPath = new QString(realPath(localxdgdatadir() + dirs->last()));
1010 else if (strncmp(type, "xdgconf-", 8) == 0) 1013 else if (strncmp(type, "xdgconf-", 8) == 0)
1011 pPath = new QString(realPath(localxdgconfdir() + dirs->last())); 1014 pPath = new QString(realPath(localxdgconfdir() + dirs->last()));
1012 else 1015 else
1013 pPath = new QString(realPath(localkdedir() + dirs->last())); 1016 pPath = new QString(realPath(localkdedir() + dirs->last()));
1014 } 1017 }
1015 else { 1018 else {
1016 dirs = absolutes.find(type); 1019 dirs = absolutes.find(type);
1017 if (!dirs) 1020 if (!dirs)
1018 qFatal("KStandardDirs: The resource type %s is not registered", type); 1021 qFatal("KStandardDirs: The resource type %s is not registered", type);
1019 pPath = new QString(realPath(dirs->last())); 1022 pPath = new QString(realPath(dirs->last()));
1020 } 1023 }
1021 1024
1022 savelocations.insert(type, pPath); 1025 savelocations.insert(type, pPath);
1023 } 1026 }
1024 1027
1025 QString fullPath = *pPath + suffix; 1028 QString fullPath = *pPath + suffix;
1026//US struct stat st; 1029//US struct stat st;
1027//US if (stat(QFile::encodeName(fullPath), &st) != 0 || !(S_ISDIR(st.st_mode))) 1030//US if (stat(QFile::encodeName(fullPath), &st) != 0 || !(S_ISDIR(st.st_mode)))
1028 QFileInfo fullPathInfo(QFile::encodeName(fullPath)); 1031 QFileInfo fullPathInfo(QFile::encodeName(fullPath));
1029 if (fullPathInfo.isReadable() || !fullPathInfo.isDir()) 1032 if (fullPathInfo.isReadable() || !fullPathInfo.isDir())
1030 1033
1031 1034
1032 { 1035 {
1033 if(!create) { 1036 if(!create) {
1034#ifndef NDEBUG 1037#ifndef NDEBUG
1035 qDebug("save location %s doesn't exist", fullPath.latin1()); 1038 qDebug("save location %s doesn't exist", fullPath.latin1());
1036#endif 1039#endif
1037 return fullPath; 1040 return fullPath;
1038 } 1041 }
1039 if(!makeDir(fullPath, 0700)) { 1042 if(!makeDir(fullPath, 0700)) {
1040 qWarning("failed to create %s", fullPath.latin1()); 1043 qWarning("failed to create %s", fullPath.latin1());
1041 return fullPath; 1044 return fullPath;
1042 } 1045 }
1043 dircache.remove(type); 1046 dircache.remove(type);
1044 } 1047 }
1045 return fullPath; 1048 return fullPath;
1046} 1049}
1047 1050
1048QString KStandardDirs::relativeLocation(const char *type, const QString &absPath) 1051QString KStandardDirs::relativeLocation(const char *type, const QString &absPath)
1049{ 1052{
1050 QString fullPath = absPath; 1053 QString fullPath = absPath;
1051 int i = absPath.findRev('/'); 1054 int i = absPath.findRev('/');
1052 if (i != -1) 1055 if (i != -1)
1053 { 1056 {
1054 fullPath = realPath(absPath.left(i+1))+absPath.mid(i+1); // Normalize 1057 fullPath = realPath(absPath.left(i+1))+absPath.mid(i+1); // Normalize
1055 } 1058 }
1056 1059
1057 QStringList candidates = resourceDirs(type); 1060 QStringList candidates = resourceDirs(type);
1058 1061
1059 for (QStringList::ConstIterator it = candidates.begin(); 1062 for (QStringList::ConstIterator it = candidates.begin();
1060 it != candidates.end(); it++) 1063 it != candidates.end(); it++)
1061 if (fullPath.startsWith(*it)) 1064 if (fullPath.startsWith(*it))
1062 { 1065 {
1063 return fullPath.mid((*it).length()); 1066 return fullPath.mid((*it).length());
1064 } 1067 }
1065 1068
1066 return absPath; 1069 return absPath;
1067} 1070}
1068 1071
1069 1072
1070bool KStandardDirs::makeDir(const QString& dir2, int mode) 1073bool KStandardDirs::makeDir(const QString& dir2, int mode)
1071{ 1074{
1072 QString dir = QDir::convertSeparators( dir2 ); 1075 QString dir = QDir::convertSeparators( dir2 );
1073#if 0 1076#if 0
1074 //LR 1077 //LR
1075 1078
1076 // we want an absolute path 1079 // we want an absolute path
1077 if (dir.at(0) != '/') 1080 if (dir.at(0) != '/')
1078 return false; 1081 return false;
1079 1082
1080 QString target = dir; 1083 QString target = dir;
1081 uint len = target.length(); 1084 uint len = target.length();
1082 1085
1083 // append trailing slash if missing 1086 // append trailing slash if missing
1084 if (dir.at(len - 1) != '/') 1087 if (dir.at(len - 1) != '/')
1085 target += '/'; 1088 target += '/';
1086 1089
1087 QString base(""); 1090 QString base("");
1088 uint i = 1; 1091 uint i = 1;
1089 1092
1090 while( i < len ) 1093 while( i < len )
1091 { 1094 {
1092//US struct stat st; 1095//US struct stat st;
1093 int pos = target.find('/', i); 1096 int pos = target.find('/', i);
1094 base += target.mid(i - 1, pos - i + 1); 1097 base += target.mid(i - 1, pos - i + 1);
1095 QCString baseEncoded = QFile::encodeName(base); 1098 QCString baseEncoded = QFile::encodeName(base);
1096 // bail out if we encountered a problem 1099 // bail out if we encountered a problem
1097//US if (stat(baseEncoded, &st) != 0) 1100//US if (stat(baseEncoded, &st) != 0)
1098 QFileInfo baseEncodedInfo(baseEncoded); 1101 QFileInfo baseEncodedInfo(baseEncoded);
1099 if (!baseEncodedInfo.exists()) 1102 if (!baseEncodedInfo.exists())
1100 { 1103 {
1101 // Directory does not exist.... 1104 // Directory does not exist....
1102 // Or maybe a dangling symlink ? 1105 // Or maybe a dangling symlink ?
1103//US if (lstat(baseEncoded, &st) == 0) 1106//US if (lstat(baseEncoded, &st) == 0)
1104 if (baseEncodedInfo.isSymLink()) { 1107 if (baseEncodedInfo.isSymLink()) {
1105//US (void)unlink(baseEncoded); // try removing 1108//US (void)unlink(baseEncoded); // try removing
1106 QFile(baseEncoded).remove(); 1109 QFile(baseEncoded).remove();
1107 } 1110 }
1108 1111
1109 //US if ( mkdir(baseEncoded, (mode_t) mode) != 0) 1112 //US if ( mkdir(baseEncoded, (mode_t) mode) != 0)
1110 QDir dirObj; 1113 QDir dirObj;
1111 if ( dirObj.mkdir(baseEncoded) != true ) 1114 if ( dirObj.mkdir(baseEncoded) != true )
1112 { 1115 {
1113 //US perror("trying to create local folder"); 1116 //US perror("trying to create local folder");
1114 return false; // Couldn't create it :-( 1117 return false; // Couldn't create it :-(
1115 } 1118 }
1116 } 1119 }
1117 i = pos + 1; 1120 i = pos + 1;
1118 } 1121 }
1119 return true; 1122 return true;
1120#endif 1123#endif
1121 1124
1122 // ******************************************** 1125 // ********************************************
1123 // new code for WIN32 1126 // new code for WIN32
1124 QDir dirObj; 1127 QDir dirObj;
1125 1128
1126 1129
1127 // we want an absolute path 1130 // we want an absolute path
1128#ifndef _WIN32_ 1131#ifndef _WIN32_
1129 if (dir.at(0) != '/') 1132 if (dir.at(0) != '/')
1130 return false; 1133 return false;
1131#endif 1134#endif
1132 1135
1133 QString target = dir; 1136 QString target = dir;
1134 uint len = target.length(); 1137 uint len = target.length();
1135#ifndef _WIN32_ 1138#ifndef _WIN32_
1136 // append trailing slash if missing 1139 // append trailing slash if missing
1137 if (dir.at(len - 1) != '/') 1140 if (dir.at(len - 1) != '/')
1138 target += '/'; 1141 target += '/';
1139#endif 1142#endif
1140 1143
1141 QString base(""); 1144 QString base("");
1142 uint i = 1; 1145 uint i = 1;
1143 1146
1144 while( i < len ) 1147 while( i < len )
1145 { 1148 {
1146//US struct stat st; 1149//US struct stat st;
1147#ifndef _WIN32_ 1150#ifndef _WIN32_
1148 int pos = target.find('/', i); 1151 int pos = target.find('/', i);
1149#else 1152#else
1150 int pos = target.find('\\', i); 1153 int pos = target.find('\\', i);
1151#endif 1154#endif
1152 if ( pos < 0 ) 1155 if ( pos < 0 )
1153 return true; 1156 return true;
1154 base += target.mid(i - 1, pos - i + 1); 1157 base += target.mid(i - 1, pos - i + 1);
1155 //QMessageBox::information( 0,"cap111", base, 1 ); 1158 //QMessageBox::information( 0,"cap111", base, 1 );
1156/*US 1159/*US
1157 QCString baseEncoded = QFile::encodeName(base); 1160 QCString baseEncoded = QFile::encodeName(base);
1158 // bail out if we encountered a problem 1161 // bail out if we encountered a problem
1159 if (stat(baseEncoded, &st) != 0) 1162 if (stat(baseEncoded, &st) != 0)
1160 { 1163 {
1161 // Directory does not exist.... 1164 // Directory does not exist....
1162 // Or maybe a dangling symlink ? 1165 // Or maybe a dangling symlink ?
1163 if (lstat(baseEncoded, &st) == 0) 1166 if (lstat(baseEncoded, &st) == 0)
1164 (void)unlink(baseEncoded); // try removing 1167 (void)unlink(baseEncoded); // try removing
1165 1168
1166 1169
1167 if ( mkdir(baseEncoded, (mode_t) mode) != 0) { 1170 if ( mkdir(baseEncoded, (mode_t) mode) != 0) {
1168 perror("trying to create local folder"); 1171 perror("trying to create local folder");
1169 return false; // Couldn't create it :-( 1172 return false; // Couldn't create it :-(
1170 } 1173 }
1171 } 1174 }
1172*/ 1175*/
1173 1176
1174 if (dirObj.exists(base) == false) 1177 if (dirObj.exists(base) == false)
1175 { 1178 {
1176 //qDebug("KStandardDirs::makeDir try to create : %s" , base.latin1()); 1179 //qDebug("KStandardDirs::makeDir try to create : %s" , base.latin1());
1177 if (dirObj.mkdir(base) != true) 1180 if (dirObj.mkdir(base) != true)
1178 { 1181 {
1179 qDebug("KStandardDirs::makeDir could not create: %s" , base.latin1()); 1182 qDebug("KStandardDirs::makeDir could not create: %s" , base.latin1());
1180 return false; 1183 return false;
1181 } 1184 }
1182 } 1185 }
1183 1186
1184 i = pos + 1; 1187 i = pos + 1;
1185 } 1188 }
1186 return true; 1189 return true;
1187 1190
1188} 1191}
1189 1192
1190static QString readEnvPath(const char *env) 1193static QString readEnvPath(const char *env)
1191{ 1194{
1192#ifdef _WIN32_ 1195#ifdef _WIN32_
1193 return ""; 1196 return "";
1194#else 1197#else
1195 QCString c_path = getenv(env); 1198 QCString c_path = getenv(env);
1196 if (c_path.isEmpty()) 1199 if (c_path.isEmpty())
1197 return QString::null; 1200 return QString::null;
1198 return QFile::decodeName(c_path); 1201 return QFile::decodeName(c_path);
1199#endif 1202#endif
1200} 1203}
1201 1204
1202void KStandardDirs::addKDEDefaults() 1205void KStandardDirs::addKDEDefaults()
1203{ 1206{
1204 //qDebug("ERROR: KStandardDirs::addKDEDefaults() called "); 1207 //qDebug("ERROR: KStandardDirs::addKDEDefaults() called ");
1205 //return; 1208 //return;
1206 QStringList kdedirList; 1209 QStringList kdedirList;
1207 1210
1208 // begin KDEDIRS 1211 // begin KDEDIRS
1209 QString kdedirs = readEnvPath("MICROKDEDIRS"); 1212 QString kdedirs = readEnvPath("MICROKDEDIRS");
1210 if (!kdedirs.isEmpty()) 1213 if (!kdedirs.isEmpty())
1211 { 1214 {
1212 tokenize(kdedirList, kdedirs, ":"); 1215 tokenize(kdedirList, kdedirs, ":");
1213 } 1216 }
1214 else 1217 else
1215 { 1218 {
1216 QString kdedir = readEnvPath("MICROKDEDIR"); 1219 QString kdedir = readEnvPath("MICROKDEDIR");
1217 if (!kdedir.isEmpty()) 1220 if (!kdedir.isEmpty())
1218 { 1221 {
1219 kdedir = KShell::tildeExpand(kdedir); 1222 kdedir = KShell::tildeExpand(kdedir);
1220 kdedirList.append(kdedir); 1223 kdedirList.append(kdedir);
1221 } 1224 }
1222 } 1225 }
1223//US kdedirList.append(KDEDIR); 1226//US kdedirList.append(KDEDIR);
1227//US for embedded, add qtopia dir as kdedir
1228 kdedirList.append(QPEApplication::qpeDir());
1224 1229
1225#ifdef __KDE_EXECPREFIX 1230#ifdef __KDE_EXECPREFIX
1226 QString execPrefix(__KDE_EXECPREFIX); 1231 QString execPrefix(__KDE_EXECPREFIX);
1227 if (execPrefix!="NONE") 1232 if (execPrefix!="NONE")
1228 kdedirList.append(execPrefix); 1233 kdedirList.append(execPrefix);
1229#endif 1234#endif
1230 1235
1231 QString localKdeDir; 1236 QString localKdeDir;
1232 1237
1233//US if (getuid()) 1238//US if (getuid())
1234 if (true) 1239 if (true)
1235 { 1240 {
1236 localKdeDir = readEnvPath("MICROKDEHOME"); 1241 localKdeDir = readEnvPath("MICROKDEHOME");
1237 if (!localKdeDir.isEmpty()) 1242 if (!localKdeDir.isEmpty())
1238 { 1243 {
1239 if (localKdeDir.at(localKdeDir.length()-1) != '/') 1244 if (localKdeDir.at(localKdeDir.length()-1) != '/')
1240 localKdeDir += '/'; 1245 localKdeDir += '/';
1241 } 1246 }
1242 else 1247 else
1243 { 1248 {
1244 localKdeDir = QDir::homeDirPath() + "/kdepim/"; 1249 localKdeDir = QDir::homeDirPath() + "/kdepim/";
1245 } 1250 }
1246 } 1251 }
1247 else 1252 else
1248 { 1253 {
1249 // We treat root different to prevent root messing up the 1254 // We treat root different to prevent root messing up the
1250 // file permissions in the users home directory. 1255 // file permissions in the users home directory.
1251 localKdeDir = readEnvPath("MICROKDEROOTHOME"); 1256 localKdeDir = readEnvPath("MICROKDEROOTHOME");
1252 if (!localKdeDir.isEmpty()) 1257 if (!localKdeDir.isEmpty())
1253 { 1258 {
1254 if (localKdeDir.at(localKdeDir.length()-1) != '/') 1259 if (localKdeDir.at(localKdeDir.length()-1) != '/')
1255 localKdeDir += '/'; 1260 localKdeDir += '/';
1256 } 1261 }
1257 else 1262 else
1258 { 1263 {
1259//US struct passwd *pw = getpwuid(0); 1264//US struct passwd *pw = getpwuid(0);
1260//US localKdeDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.microkde/"; 1265//US localKdeDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.microkde/";
1261 qDebug("KStandardDirs::addKDEDefaults: 1 has to be fixed"); 1266 qDebug("KStandardDirs::addKDEDefaults: 1 has to be fixed");
1262 } 1267 }
1263 1268
1264 } 1269 }
1265 1270
1266//US localKdeDir = appDir(); 1271//US localKdeDir = appDir();
1267 1272
1268//US 1273//US
1269// qDebug("KStandardDirs::addKDEDefaults: localKdeDir=%s", localKdeDir.latin1()); 1274// qDebug("KStandardDirs::addKDEDefaults: localKdeDir=%s", localKdeDir.latin1());
1270 if (localKdeDir != "-/") 1275 if (localKdeDir != "-/")
1271 { 1276 {
1272 localKdeDir = KShell::tildeExpand(localKdeDir); 1277 localKdeDir = KShell::tildeExpand(localKdeDir);
1273 addPrefix(localKdeDir); 1278 addPrefix(localKdeDir);
1274 } 1279 }
1275 1280
1276 for (QStringList::ConstIterator it = kdedirList.begin(); 1281 for (QStringList::ConstIterator it = kdedirList.begin();
1277 it != kdedirList.end(); it++) 1282 it != kdedirList.end(); it++)
1278 { 1283 {
1279 QString dir = KShell::tildeExpand(*it); 1284 QString dir = KShell::tildeExpand(*it);
1280 addPrefix(dir); 1285 addPrefix(dir);
1281 } 1286 }
1282 // end KDEDIRS 1287 // end KDEDIRS
1283 1288
1284 // begin XDG_CONFIG_XXX 1289 // begin XDG_CONFIG_XXX
1285 QStringList xdgdirList; 1290 QStringList xdgdirList;
1286 QString xdgdirs = readEnvPath("XDG_CONFIG_DIRS"); 1291 QString xdgdirs = readEnvPath("XDG_CONFIG_DIRS");
1287 if (!xdgdirs.isEmpty()) 1292 if (!xdgdirs.isEmpty())
1288 { 1293 {
1289 tokenize(xdgdirList, xdgdirs, ":"); 1294 tokenize(xdgdirList, xdgdirs, ":");
1290 } 1295 }
1291 else 1296 else
1292 { 1297 {
1293 xdgdirList.clear(); 1298 xdgdirList.clear();
1294 xdgdirList.append("/etc/xdg"); 1299 xdgdirList.append("/etc/xdg");
1295 } 1300 }
1296 1301
1297 QString localXdgDir = readEnvPath("XDG_CONFIG_HOME"); 1302 QString localXdgDir = readEnvPath("XDG_CONFIG_HOME");
1298 if (!localXdgDir.isEmpty()) 1303 if (!localXdgDir.isEmpty())
1299 { 1304 {
1300 if (localXdgDir.at(localXdgDir.length()-1) != '/') 1305 if (localXdgDir.at(localXdgDir.length()-1) != '/')
1301 localXdgDir += '/'; 1306 localXdgDir += '/';
1302 } 1307 }
1303 else 1308 else
1304 { 1309 {
1305//US if (getuid()) 1310//US if (getuid())
1306 if (true) 1311 if (true)
1307 { 1312 {
1308 localXdgDir = QDir::homeDirPath() + "/.config/"; 1313 localXdgDir = QDir::homeDirPath() + "/.config/";
1309 } 1314 }
1310 else 1315 else
1311 { 1316 {
1312//US struct passwd *pw = getpwuid(0); 1317//US struct passwd *pw = getpwuid(0);
1313//US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.config/"; 1318//US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.config/";
1314 qDebug("KStandardDirs::addKDEDefaults: 2 has to be fixed"); 1319 qDebug("KStandardDirs::addKDEDefaults: 2 has to be fixed");
1315 } 1320 }
1316 } 1321 }
1317 1322
1318 localXdgDir = KShell::tildeExpand(localXdgDir); 1323 localXdgDir = KShell::tildeExpand(localXdgDir);
1319 addXdgConfigPrefix(localXdgDir); 1324 addXdgConfigPrefix(localXdgDir);
1320 1325
1321 for (QStringList::ConstIterator it = xdgdirList.begin(); 1326 for (QStringList::ConstIterator it = xdgdirList.begin();
1322 it != xdgdirList.end(); it++) 1327 it != xdgdirList.end(); it++)
1323 { 1328 {
1324 QString dir = KShell::tildeExpand(*it); 1329 QString dir = KShell::tildeExpand(*it);
1325 addXdgConfigPrefix(dir); 1330 addXdgConfigPrefix(dir);
1326 } 1331 }
1327 // end XDG_CONFIG_XXX 1332 // end XDG_CONFIG_XXX
1328 1333
1329 // begin XDG_DATA_XXX 1334 // begin XDG_DATA_XXX
1330 xdgdirs = readEnvPath("XDG_DATA_DIRS"); 1335 xdgdirs = readEnvPath("XDG_DATA_DIRS");
1331 if (!xdgdirs.isEmpty()) 1336 if (!xdgdirs.isEmpty())
1332 { 1337 {
1333 tokenize(xdgdirList, xdgdirs, ":"); 1338 tokenize(xdgdirList, xdgdirs, ":");
1334 } 1339 }
1335 else 1340 else
1336 { 1341 {
1337 xdgdirList.clear(); 1342 xdgdirList.clear();
1338 for (QStringList::ConstIterator it = kdedirList.begin(); 1343 for (QStringList::ConstIterator it = kdedirList.begin();
1339 it != kdedirList.end(); it++) 1344 it != kdedirList.end(); it++)
1340 { 1345 {
1341 QString dir = *it; 1346 QString dir = *it;
1342 if (dir.at(dir.length()-1) != '/') 1347 if (dir.at(dir.length()-1) != '/')
1343 dir += '/'; 1348 dir += '/';
1344 xdgdirList.append(dir+"share/"); 1349 xdgdirList.append(dir+"share/");
1345 } 1350 }
1346 1351
1347 xdgdirList.append("/usr/local/share/"); 1352 xdgdirList.append("/usr/local/share/");
1348 xdgdirList.append("/usr/share/"); 1353 xdgdirList.append("/usr/share/");
1349 } 1354 }
1350 1355
1351 localXdgDir = readEnvPath("XDG_DATA_HOME"); 1356 localXdgDir = readEnvPath("XDG_DATA_HOME");
1352 if (!localXdgDir.isEmpty()) 1357 if (!localXdgDir.isEmpty())
1353 { 1358 {
1354 if (localXdgDir.at(localXdgDir.length()-1) != '/') 1359 if (localXdgDir.at(localXdgDir.length()-1) != '/')
1355 localXdgDir += '/'; 1360 localXdgDir += '/';
1356 } 1361 }
1357 else 1362 else
1358 { 1363 {
1359//US if (getuid()) 1364//US if (getuid())
1360 if (true) 1365 if (true)
1361 { 1366 {
1362 localXdgDir = QDir::homeDirPath() + "/.local/share/"; 1367 localXdgDir = QDir::homeDirPath() + "/.local/share/";
1363 } 1368 }
1364 else 1369 else
1365 { 1370 {
1366//US struct passwd *pw = getpwuid(0); 1371//US struct passwd *pw = getpwuid(0);
1367//US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.local/share/"; 1372//US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.local/share/";
1368 qDebug("KStandardDirs::addKDEDefaults: 3 has to be fixed"); 1373 qDebug("KStandardDirs::addKDEDefaults: 3 has to be fixed");
1369 } 1374 }
1370 } 1375 }
1371 1376
1372 localXdgDir = KShell::tildeExpand(localXdgDir); 1377 localXdgDir = KShell::tildeExpand(localXdgDir);
1373 addXdgDataPrefix(localXdgDir); 1378 addXdgDataPrefix(localXdgDir);
1374 1379
1375 for (QStringList::ConstIterator it = xdgdirList.begin(); 1380 for (QStringList::ConstIterator it = xdgdirList.begin();
1376 it != xdgdirList.end(); it++) 1381 it != xdgdirList.end(); it++)
1377 { 1382 {
1378 QString dir = KShell::tildeExpand(*it); 1383 QString dir = KShell::tildeExpand(*it);
1379 1384
1380 addXdgDataPrefix(dir); 1385 addXdgDataPrefix(dir);
1381 } 1386 }
1382 // end XDG_DATA_XXX 1387 // end XDG_DATA_XXX
1383 1388
1384 1389
1385 uint index = 0; 1390 uint index = 0;
1386 while (types[index] != 0) { 1391 while (types[index] != 0) {
1387 addResourceType(types[index], kde_default(types[index])); 1392 addResourceType(types[index], kde_default(types[index]));
1388 index++; 1393 index++;
1389 } 1394 }
1390 1395
1391 addResourceDir("home", QDir::homeDirPath()); 1396 addResourceDir("home", QDir::homeDirPath());
1392} 1397}
1393 1398
1394void KStandardDirs::checkConfig() const 1399void KStandardDirs::checkConfig() const
1395{ 1400{
1396/*US 1401/*US
1397 if (!addedCustoms && KGlobal::_instance && KGlobal::_instance->_config) 1402 if (!addedCustoms && KGlobal::_instance && KGlobal::_instance->_config)
1398 const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::_instance->_config); 1403 const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::_instance->_config);
1399*/ 1404*/
1400 if (!addedCustoms && KGlobal::config()) 1405 if (!addedCustoms && KGlobal::config())
1401 const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::config()); 1406 const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::config());
1402} 1407}
1403 1408
1404bool KStandardDirs::addCustomized(KConfig *config) 1409bool KStandardDirs::addCustomized(KConfig *config)
1405{ 1410{
1406 if (addedCustoms) // there are already customized entries 1411 if (addedCustoms) // there are already customized entries
1407 return false; // we just quite and hope they are the right ones 1412 return false; // we just quite and hope they are the right ones
1408 1413
1409 // save the numbers of config directories. If this changes, 1414 // save the numbers of config directories. If this changes,
1410 // we will return true to give KConfig a chance to reparse 1415 // we will return true to give KConfig a chance to reparse
1411 uint configdirs = resourceDirs("config").count(); 1416 uint configdirs = resourceDirs("config").count();
1412 1417
1413 // reading the prefixes in 1418 // reading the prefixes in
1414 QString oldGroup = config->group(); 1419 QString oldGroup = config->group();
1415 config->setGroup("Directories"); 1420 config->setGroup("Directories");
1416 1421
1417 QStringList list; 1422 QStringList list;
1418 QStringList::ConstIterator it; 1423 QStringList::ConstIterator it;
1419 list = config->readListEntry("prefixes"); 1424 list = config->readListEntry("prefixes");
1420 for (it = list.begin(); it != list.end(); it++) 1425 for (it = list.begin(); it != list.end(); it++)
1421 addPrefix(*it); 1426 addPrefix(*it);
1422 1427
1423 // iterating over all entries in the group Directories 1428 // iterating over all entries in the group Directories
1424 // to find entries that start with dir_$type 1429 // to find entries that start with dir_$type
1425/*US 1430/*US
1426 QMap<QString, QString> entries = config->entryMap("Directories"); 1431 QMap<QString, QString> entries = config->entryMap("Directories");
1427 1432
1428 QMap<QString, QString>::ConstIterator it2; 1433 QMap<QString, QString>::ConstIterator it2;
1429 for (it2 = entries.begin(); it2 != entries.end(); it2++) 1434 for (it2 = entries.begin(); it2 != entries.end(); it2++)
1430 { 1435 {
1431 QString key = it2.key(); 1436 QString key = it2.key();
1432 if (key.left(4) == "dir_") { 1437 if (key.left(4) == "dir_") {
1433 // generate directory list, there may be more than 1. 1438 // generate directory list, there may be more than 1.
1434 QStringList dirs = QStringList::split(',', *it2); 1439 QStringList dirs = QStringList::split(',', *it2);
1435 QStringList::Iterator sIt(dirs.begin()); 1440 QStringList::Iterator sIt(dirs.begin());
1436 QString resType = key.mid(4, key.length()); 1441 QString resType = key.mid(4, key.length());
1437 for (; sIt != dirs.end(); ++sIt) { 1442 for (; sIt != dirs.end(); ++sIt) {
1438 addResourceDir(resType.latin1(), *sIt); 1443 addResourceDir(resType.latin1(), *sIt);
1439 } 1444 }
1440 } 1445 }
1441 } 1446 }
1442 1447
1443 // Process KIOSK restrictions. 1448 // Process KIOSK restrictions.
1444 config->setGroup("KDE Resource Restrictions"); 1449 config->setGroup("KDE Resource Restrictions");
1445 entries = config->entryMap("KDE Resource Restrictions"); 1450 entries = config->entryMap("KDE Resource Restrictions");
1446 for (it2 = entries.begin(); it2 != entries.end(); it2++) 1451 for (it2 = entries.begin(); it2 != entries.end(); it2++)
1447 { 1452 {
1448 QString key = it2.key(); 1453 QString key = it2.key();
1449 if (!config->readBoolEntry(key, true)) 1454 if (!config->readBoolEntry(key, true))
1450 { 1455 {
1451 d->restrictionsActive = true; 1456 d->restrictionsActive = true;
1452 d->restrictions.insert(key.latin1(), &d->restrictionsActive); // Anything will do 1457 d->restrictions.insert(key.latin1(), &d->restrictionsActive); // Anything will do
1453 dircache.remove(key.latin1()); 1458 dircache.remove(key.latin1());
1454 } 1459 }
1455 } 1460 }
1456*/ 1461*/
1457 // save it for future calls - that will return 1462 // save it for future calls - that will return
1458 addedCustoms = true; 1463 addedCustoms = true;
1459 config->setGroup(oldGroup); 1464 config->setGroup(oldGroup);
1460 1465
1461 // return true if the number of config dirs changed 1466 // return true if the number of config dirs changed
1462 return (resourceDirs("config").count() != configdirs); 1467 return (resourceDirs("config").count() != configdirs);
1463} 1468}
1464 1469
1465QString KStandardDirs::localkdedir() const 1470QString KStandardDirs::localkdedir() const
1466{ 1471{
1467 // Return the prefix to use for saving 1472 // Return the prefix to use for saving
1468 return prefixes.first(); 1473 return prefixes.first();
1469} 1474}
1470 1475
1471QString KStandardDirs::localxdgdatadir() const 1476QString KStandardDirs::localxdgdatadir() const
1472{ 1477{
1473 // Return the prefix to use for saving 1478 // Return the prefix to use for saving
1474 return d->xdgdata_prefixes.first(); 1479 return d->xdgdata_prefixes.first();
1475} 1480}
1476 1481
1477QString KStandardDirs::localxdgconfdir() const 1482QString KStandardDirs::localxdgconfdir() const
1478{ 1483{
1479 // Return the prefix to use for saving 1484 // Return the prefix to use for saving