summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-10-01 18:10:17 (UTC)
committer ulf69 <ulf69>2004-10-01 18:10:17 (UTC)
commit7810fe355bd75c83bcdaed646cd1dde8d3c94fcb (patch) (unidiff)
tree7f425b9d7ba5109a289414c2903fff7c5182f700
parentae6aaaf2ec81317d275ebaabba2de188279b58cd (diff)
downloadkdepimpi-7810fe355bd75c83bcdaed646cd1dde8d3c94fcb.zip
kdepimpi-7810fe355bd75c83bcdaed646cd1dde8d3c94fcb.tar.gz
kdepimpi-7810fe355bd75c83bcdaed646cd1dde8d3c94fcb.tar.bz2
added env variables QTDIR and OPIEDIR to search for libraries.
This is a fix for pdaXROM users that have not set QPEDIR
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdecore/kstandarddirs.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/microkde/kdecore/kstandarddirs.cpp b/microkde/kdecore/kstandarddirs.cpp
index 500426b..7f2a326 100644
--- a/microkde/kdecore/kstandarddirs.cpp
+++ b/microkde/kdecore/kstandarddirs.cpp
@@ -1,1640 +1,1651 @@
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 <qapplication.h> 45#include <qapplication.h>
46 46
47#include <qstringlist.h> 47#include <qstringlist.h>
48 48
49#include "kstandarddirs.h" 49#include "kstandarddirs.h"
50#include "kconfig.h" 50#include "kconfig.h"
51#include "kdebug.h" 51#include "kdebug.h"
52//US #include "kinstance.h" 52//US #include "kinstance.h"
53#include "kshell.h" 53#include "kshell.h"
54//US#include <sys/param.h> 54//US#include <sys/param.h>
55//US#include <unistd.h> 55//US#include <unistd.h>
56 56
57//US 57//US
58QString KStandardDirs::mAppDir = QString::null; 58QString KStandardDirs::mAppDir = QString::null;
59 59
60 60
61template class QDict<QStringList>; 61template class QDict<QStringList>;
62 62
63#if 0 63#if 0
64#include <qtextedit.h> 64#include <qtextedit.h>
65void ddd( QString op ) 65void ddd( QString op )
66{ 66{
67 static QTextEdit * dot = 0; 67 static QTextEdit * dot = 0;
68 if ( ! dot ) 68 if ( ! dot )
69 dot = new QTextEdit(); 69 dot = new QTextEdit();
70 70
71 dot->show(); 71 dot->show();
72 72
73 dot->append( op ); 73 dot->append( op );
74 74
75} 75}
76#endif 76#endif
77class KStandardDirs::KStandardDirsPrivate 77class KStandardDirs::KStandardDirsPrivate
78{ 78{
79public: 79public:
80 KStandardDirsPrivate() 80 KStandardDirsPrivate()
81 : restrictionsActive(false), 81 : restrictionsActive(false),
82 dataRestrictionActive(false) 82 dataRestrictionActive(false)
83 { } 83 { }
84 84
85 bool restrictionsActive; 85 bool restrictionsActive;
86 bool dataRestrictionActive; 86 bool dataRestrictionActive;
87 QAsciiDict<bool> restrictions; 87 QAsciiDict<bool> restrictions;
88 QStringList xdgdata_prefixes; 88 QStringList xdgdata_prefixes;
89 QStringList xdgconf_prefixes; 89 QStringList xdgconf_prefixes;
90}; 90};
91 91
92static const char* const types[] = {"html", "icon", "apps", "sound", 92static const char* const types[] = {"html", "icon", "apps", "sound",
93 "data", "locale", "services", "mime", 93 "data", "locale", "services", "mime",
94 "servicetypes", "config", "exe", "tmp", 94 "servicetypes", "config", "exe", "tmp",
95 "wallpaper", "lib", "pixmap", "templates", 95 "wallpaper", "lib", "pixmap", "templates",
96 "module", "qtplugins", 96 "module", "qtplugins",
97 "xdgdata-apps", "xdgdata-dirs", "xdgconf-menu", 0 }; 97 "xdgdata-apps", "xdgdata-dirs", "xdgconf-menu", 0 };
98 98
99static int tokenize( QStringList& token, const QString& str, 99static int tokenize( QStringList& token, const QString& str,
100 const QString& delim ); 100 const QString& delim );
101 101
102KStandardDirs::KStandardDirs( ) : addedCustoms(false) 102KStandardDirs::KStandardDirs( ) : addedCustoms(false)
103{ 103{
104 d = new KStandardDirsPrivate; 104 d = new KStandardDirsPrivate;
105 dircache.setAutoDelete(true); 105 dircache.setAutoDelete(true);
106 relatives.setAutoDelete(true); 106 relatives.setAutoDelete(true);
107 absolutes.setAutoDelete(true); 107 absolutes.setAutoDelete(true);
108 savelocations.setAutoDelete(true); 108 savelocations.setAutoDelete(true);
109 addKDEDefaults(); 109 addKDEDefaults();
110} 110}
111 111
112KStandardDirs::~KStandardDirs() 112KStandardDirs::~KStandardDirs()
113{ 113{
114 delete d; 114 delete d;
115} 115}
116 116
117bool KStandardDirs::isRestrictedResource(const char *type, const QString& relPath) const 117bool KStandardDirs::isRestrictedResource(const char *type, const QString& relPath) const
118{ 118{
119 if (!d || !d->restrictionsActive) 119 if (!d || !d->restrictionsActive)
120 return false; 120 return false;
121 121
122 if (d->restrictions[type]) 122 if (d->restrictions[type])
123 return true; 123 return true;
124 124
125 if (strcmp(type, "data")==0) 125 if (strcmp(type, "data")==0)
126 { 126 {
127 applyDataRestrictions(relPath); 127 applyDataRestrictions(relPath);
128 if (d->dataRestrictionActive) 128 if (d->dataRestrictionActive)
129 { 129 {
130 d->dataRestrictionActive = false; 130 d->dataRestrictionActive = false;
131 return true; 131 return true;
132 } 132 }
133 } 133 }
134 return false; 134 return false;
135} 135}
136 136
137void KStandardDirs::applyDataRestrictions(const QString &relPath) const 137void KStandardDirs::applyDataRestrictions(const QString &relPath) const
138{ 138{
139 QString key; 139 QString key;
140 int i = relPath.find('/'); 140 int i = relPath.find('/');
141 if (i != -1) 141 if (i != -1)
142 key = "data_"+relPath.left(i); 142 key = "data_"+relPath.left(i);
143 else 143 else
144 key = "data_"+relPath; 144 key = "data_"+relPath;
145 145
146 if (d && d->restrictions[key.latin1()]) 146 if (d && d->restrictions[key.latin1()])
147 d->dataRestrictionActive = true; 147 d->dataRestrictionActive = true;
148} 148}
149 149
150 150
151QStringList KStandardDirs::allTypes() const 151QStringList KStandardDirs::allTypes() const
152{ 152{
153 QStringList list; 153 QStringList list;
154 for (int i = 0; types[i] != 0; ++i) 154 for (int i = 0; types[i] != 0; ++i)
155 list.append(QString::fromLatin1(types[i])); 155 list.append(QString::fromLatin1(types[i]));
156 return list; 156 return list;
157} 157}
158 158
159void KStandardDirs::addPrefix( const QString& _dir ) 159void KStandardDirs::addPrefix( const QString& _dir )
160{ 160{
161 if (_dir.isNull()) 161 if (_dir.isNull())
162 return; 162 return;
163 163
164 QString dir = _dir; 164 QString dir = _dir;
165 if (dir.at(dir.length() - 1) != '/') 165 if (dir.at(dir.length() - 1) != '/')
166 dir += '/'; 166 dir += '/';
167 167
168 if (!prefixes.contains(dir)) { 168 if (!prefixes.contains(dir)) {
169 prefixes.append(dir); 169 prefixes.append(dir);
170 dircache.clear(); 170 dircache.clear();
171 } 171 }
172} 172}
173 173
174void KStandardDirs::addXdgConfigPrefix( const QString& _dir ) 174void KStandardDirs::addXdgConfigPrefix( const QString& _dir )
175{ 175{
176 if (_dir.isNull()) 176 if (_dir.isNull())
177 return; 177 return;
178 178
179 QString dir = _dir; 179 QString dir = _dir;
180 if (dir.at(dir.length() - 1) != '/') 180 if (dir.at(dir.length() - 1) != '/')
181 dir += '/'; 181 dir += '/';
182 182
183 if (!d->xdgconf_prefixes.contains(dir)) { 183 if (!d->xdgconf_prefixes.contains(dir)) {
184 d->xdgconf_prefixes.append(dir); 184 d->xdgconf_prefixes.append(dir);
185 dircache.clear(); 185 dircache.clear();
186 } 186 }
187} 187}
188 188
189void KStandardDirs::addXdgDataPrefix( const QString& _dir ) 189void KStandardDirs::addXdgDataPrefix( const QString& _dir )
190{ 190{
191 if (_dir.isNull()) 191 if (_dir.isNull())
192 return; 192 return;
193 193
194 QString dir = _dir; 194 QString dir = _dir;
195 if (dir.at(dir.length() - 1) != '/') 195 if (dir.at(dir.length() - 1) != '/')
196 dir += '/'; 196 dir += '/';
197 197
198 if (!d->xdgdata_prefixes.contains(dir)) { 198 if (!d->xdgdata_prefixes.contains(dir)) {
199 d->xdgdata_prefixes.append(dir); 199 d->xdgdata_prefixes.append(dir);
200 dircache.clear(); 200 dircache.clear();
201 } 201 }
202} 202}
203 203
204 204
205QString KStandardDirs::kfsstnd_prefixes() 205QString KStandardDirs::kfsstnd_prefixes()
206{ 206{
207 return prefixes.join(":"); 207 return prefixes.join(":");
208} 208}
209 209
210bool KStandardDirs::addResourceType( const char *type, 210bool KStandardDirs::addResourceType( const char *type,
211 const QString& relativename ) 211 const QString& relativename )
212{ 212{
213 if (relativename.isNull()) 213 if (relativename.isNull())
214 return false; 214 return false;
215 215
216 QStringList *rels = relatives.find(type); 216 QStringList *rels = relatives.find(type);
217 if (!rels) { 217 if (!rels) {
218 rels = new QStringList(); 218 rels = new QStringList();
219 relatives.insert(type, rels); 219 relatives.insert(type, rels);
220 } 220 }
221 QString copy = relativename; 221 QString copy = relativename;
222 if (copy.at(copy.length() - 1) != '/') 222 if (copy.at(copy.length() - 1) != '/')
223 copy += '/'; 223 copy += '/';
224 if (!rels->contains(copy)) { 224 if (!rels->contains(copy)) {
225 rels->prepend(copy); 225 rels->prepend(copy);
226 dircache.remove(type); // clean the cache 226 dircache.remove(type); // clean the cache
227 return true; 227 return true;
228 } 228 }
229 return false; 229 return false;
230} 230}
231 231
232bool KStandardDirs::addResourceDir( const char *type, 232bool KStandardDirs::addResourceDir( const char *type,
233 const QString& absdir) 233 const QString& absdir)
234{ 234{
235 QStringList *paths = absolutes.find(type); 235 QStringList *paths = absolutes.find(type);
236 if (!paths) { 236 if (!paths) {
237 paths = new QStringList(); 237 paths = new QStringList();
238 absolutes.insert(type, paths); 238 absolutes.insert(type, paths);
239 } 239 }
240 QString copy = absdir; 240 QString copy = absdir;
241 if (copy.at(copy.length() - 1) != '/') 241 if (copy.at(copy.length() - 1) != '/')
242 copy += '/'; 242 copy += '/';
243 243
244 if (!paths->contains(copy)) { 244 if (!paths->contains(copy)) {
245 paths->append(copy); 245 paths->append(copy);
246 dircache.remove(type); // clean the cache 246 dircache.remove(type); // clean the cache
247 return true; 247 return true;
248 } 248 }
249 return false; 249 return false;
250} 250}
251 251
252QString KStandardDirs::findResource( const char *type, 252QString KStandardDirs::findResource( const char *type,
253 const QString& filename ) const 253 const QString& filename ) const
254{ 254{
255 if (filename.at(0) == '/') 255 if (filename.at(0) == '/')
256 return filename; // absolute dirs are absolute dirs, right? :-/ 256 return filename; // absolute dirs are absolute dirs, right? :-/
257 257
258#if 0 258#if 0
259kdDebug() << "Find resource: " << type << endl; 259kdDebug() << "Find resource: " << type << endl;
260for (QStringList::ConstIterator pit = prefixes.begin(); 260for (QStringList::ConstIterator pit = prefixes.begin();
261 pit != prefixes.end(); 261 pit != prefixes.end();
262 pit++) 262 pit++)
263{ 263{
264 kdDebug() << "Prefix: " << *pit << endl; 264 kdDebug() << "Prefix: " << *pit << endl;
265} 265}
266#endif 266#endif
267 267
268 QString dir = findResourceDir(type, filename); 268 QString dir = findResourceDir(type, filename);
269 if (dir.isNull()) 269 if (dir.isNull())
270 return dir; 270 return dir;
271 else return dir + filename; 271 else return dir + filename;
272} 272}
273/*US 273/*US
274static Q_UINT32 updateHash(const QString &file, Q_UINT32 hash) 274static Q_UINT32 updateHash(const QString &file, Q_UINT32 hash)
275{ 275{
276 QCString cFile = QFile::encodeName(file); 276 QCString cFile = QFile::encodeName(file);
277//US struct stat buff; 277//US struct stat buff;
278//US if ((access(cFile, R_OK) == 0) && 278//US if ((access(cFile, R_OK) == 0) &&
279//US (stat( cFile, &buff ) == 0) && 279//US (stat( cFile, &buff ) == 0) &&
280//US (S_ISREG( buff.st_mode ))) 280//US (S_ISREG( buff.st_mode )))
281 QFileInfo pathfnInfo(cFile); 281 QFileInfo pathfnInfo(cFile);
282 if (( pathfnInfo.isReadable() == true ) && 282 if (( pathfnInfo.isReadable() == true ) &&
283 ( pathfnInfo.isFile()) ) 283 ( pathfnInfo.isFile()) )
284 { 284 {
285//US hash = hash + (Q_UINT32) buff.st_ctime; 285//US hash = hash + (Q_UINT32) buff.st_ctime;
286 hash = hash + (Q_UINT32) pathfnInfo.lastModified(); 286 hash = hash + (Q_UINT32) pathfnInfo.lastModified();
287 } 287 }
288 return hash; 288 return hash;
289} 289}
290*/ 290*/
291/*US 291/*US
292Q_UINT32 KStandardDirs::calcResourceHash( const char *type, 292Q_UINT32 KStandardDirs::calcResourceHash( const char *type,
293 const QString& filename, bool deep) const 293 const QString& filename, bool deep) const
294{ 294{
295 Q_UINT32 hash = 0; 295 Q_UINT32 hash = 0;
296 296
297 if (filename.at(0) == '/') 297 if (filename.at(0) == '/')
298 { 298 {
299 // absolute dirs are absolute dirs, right? :-/ 299 // absolute dirs are absolute dirs, right? :-/
300 return updateHash(filename, hash); 300 return updateHash(filename, hash);
301 } 301 }
302 if (d && d->restrictionsActive && (strcmp(type, "data")==0)) 302 if (d && d->restrictionsActive && (strcmp(type, "data")==0))
303 applyDataRestrictions(filename); 303 applyDataRestrictions(filename);
304 QStringList candidates = resourceDirs(type); 304 QStringList candidates = resourceDirs(type);
305 QString fullPath; 305 QString fullPath;
306 306
307 for (QStringList::ConstIterator it = candidates.begin(); 307 for (QStringList::ConstIterator it = candidates.begin();
308 it != candidates.end(); it++) 308 it != candidates.end(); it++)
309 { 309 {
310 hash = updateHash(*it + filename, hash); 310 hash = updateHash(*it + filename, hash);
311 if (!deep && hash) 311 if (!deep && hash)
312 return hash; 312 return hash;
313 } 313 }
314 return hash; 314 return hash;
315} 315}
316*/ 316*/
317 317
318QStringList KStandardDirs::findDirs( const char *type, 318QStringList KStandardDirs::findDirs( const char *type,
319 const QString& reldir ) const 319 const QString& reldir ) const
320{ 320{
321 QStringList list; 321 QStringList list;
322 322
323 checkConfig(); 323 checkConfig();
324 324
325 if (d && d->restrictionsActive && (strcmp(type, "data")==0)) 325 if (d && d->restrictionsActive && (strcmp(type, "data")==0))
326 applyDataRestrictions(reldir); 326 applyDataRestrictions(reldir);
327 QStringList candidates = resourceDirs(type); 327 QStringList candidates = resourceDirs(type);
328 QDir testdir; 328 QDir testdir;
329 329
330 for (QStringList::ConstIterator it = candidates.begin(); 330 for (QStringList::ConstIterator it = candidates.begin();
331 it != candidates.end(); it++) { 331 it != candidates.end(); it++) {
332 testdir.setPath(*it + reldir); 332 testdir.setPath(*it + reldir);
333 if (testdir.exists()) 333 if (testdir.exists())
334 list.append(testdir.absPath() + '/'); 334 list.append(testdir.absPath() + '/');
335 } 335 }
336 336
337 return list; 337 return list;
338} 338}
339 339
340QString KStandardDirs::findResourceDir( const char *type, 340QString KStandardDirs::findResourceDir( const char *type,
341 const QString& filename) const 341 const QString& filename) const
342{ 342{
343#ifndef NDEBUG 343#ifndef NDEBUG
344 if (filename.isEmpty()) { 344 if (filename.isEmpty()) {
345 kdWarning() << "filename for type " << type << " in KStandardDirs::findResourceDir is not supposed to be empty!!" << endl; 345 kdWarning() << "filename for type " << type << " in KStandardDirs::findResourceDir is not supposed to be empty!!" << endl;
346 return QString::null; 346 return QString::null;
347 } 347 }
348#endif 348#endif
349 349
350 if (d && d->restrictionsActive && (strcmp(type, "data")==0)) 350 if (d && d->restrictionsActive && (strcmp(type, "data")==0))
351 applyDataRestrictions(filename); 351 applyDataRestrictions(filename);
352 QStringList candidates = resourceDirs(type); 352 QStringList candidates = resourceDirs(type);
353 QString fullPath; 353 QString fullPath;
354#ifdef DESKTOP_VERSION 354#ifdef DESKTOP_VERSION
355#ifdef _WIN32_ 355#ifdef _WIN32_
356 candidates.prepend( qApp->applicationDirPath () +"\\"); 356 candidates.prepend( qApp->applicationDirPath () +"\\");
357#else 357#else
358 candidates.prepend( qApp->applicationDirPath () +"/"); 358 candidates.prepend( qApp->applicationDirPath () +"/");
359#endif 359#endif
360#endif 360#endif
361 for (QStringList::ConstIterator it = candidates.begin(); it != candidates.end(); it++) 361 for (QStringList::ConstIterator it = candidates.begin(); it != candidates.end(); it++)
362 { 362 {
363 //qDebug("looking for dir %s - file %s", (*it).latin1(), filename.latin1()); 363 //qDebug("looking for dir %s - file %s", (*it).latin1(), filename.latin1());
364 if (exists(*it + filename)) 364 if (exists(*it + filename))
365 return *it; 365 return *it;
366 } 366 }
367 367
368#ifndef NDEBUG 368#ifndef NDEBUG
369 if(false && type != "locale") 369 if(false && type != "locale")
370 qDebug("KStdDirs::findResDir(): can't find %s ", filename.latin1()); 370 qDebug("KStdDirs::findResDir(): can't find %s ", filename.latin1());
371 371
372#endif 372#endif
373 373
374 return QString::null; 374 return QString::null;
375} 375}
376 376
377bool KStandardDirs::exists(const QString &fullPath) 377bool KStandardDirs::exists(const QString &fullPath)
378{ 378{
379//US struct stat buff; 379//US struct stat buff;
380 QFileInfo fullPathInfo(QFile::encodeName(fullPath)); 380 QFileInfo fullPathInfo(QFile::encodeName(fullPath));
381 381
382//US if (access(QFile::encodeName(fullPath), R_OK) == 0 && fullPathInfo.isReadable()) 382//US if (access(QFile::encodeName(fullPath), R_OK) == 0 && fullPathInfo.isReadable())
383 if (fullPathInfo.isReadable()) 383 if (fullPathInfo.isReadable())
384 { 384 {
385 if (fullPath.at(fullPath.length() - 1) != '/') { 385 if (fullPath.at(fullPath.length() - 1) != '/') {
386 //US if (S_ISREG( buff.st_mode )) 386 //US if (S_ISREG( buff.st_mode ))
387 if (fullPathInfo.isFile()) 387 if (fullPathInfo.isFile())
388 return true; 388 return true;
389 } 389 }
390 else { 390 else {
391 //US if (S_ISDIR( buff.st_mode )) 391 //US if (S_ISDIR( buff.st_mode ))
392 if (fullPathInfo.isDir()) 392 if (fullPathInfo.isDir())
393 return true; 393 return true;
394 } 394 }
395 } 395 }
396 return false; 396 return false;
397} 397}
398 398
399static void lookupDirectory(const QString& path, const QString &relPart, 399static void lookupDirectory(const QString& path, const QString &relPart,
400 const QRegExp &regexp, 400 const QRegExp &regexp,
401 QStringList& list, 401 QStringList& list,
402 QStringList& relList, 402 QStringList& relList,
403 bool recursive, bool uniq) 403 bool recursive, bool uniq)
404{ 404{
405 QString pattern = regexp.pattern(); 405 QString pattern = regexp.pattern();
406 if (recursive || pattern.contains('?') || pattern.contains('*')) 406 if (recursive || pattern.contains('?') || pattern.contains('*'))
407 { 407 {
408 // We look for a set of files. 408 // We look for a set of files.
409//US DIR *dp = opendir( QFile::encodeName(path)); 409//US DIR *dp = opendir( QFile::encodeName(path));
410 QDir dp(QFile::encodeName(path)); 410 QDir dp(QFile::encodeName(path));
411 411
412 if (!dp.exists()) 412 if (!dp.exists())
413 return; 413 return;
414 static int iii = 0; 414 static int iii = 0;
415 ++iii; 415 ++iii;
416 if ( iii == 5 ) 416 if ( iii == 5 )
417 abort(); 417 abort();
418 assert(path.at(path.length() - 1) == '/'); 418 assert(path.at(path.length() - 1) == '/');
419 419
420//US struct dirent *ep; 420//US struct dirent *ep;
421//US struct stat buff; 421//US struct stat buff;
422 422
423 QString _dot("."); 423 QString _dot(".");
424 QString _dotdot(".."); 424 QString _dotdot("..");
425 425
426//US while( ( ep = readdir( dp ) ) != 0L ) 426//US while( ( ep = readdir( dp ) ) != 0L )
427 QStringList direntries = dp.entryList(); 427 QStringList direntries = dp.entryList();
428 QStringList::Iterator it = direntries.begin(); 428 QStringList::Iterator it = direntries.begin();
429 429
430 while ( it != list.end() ) // for each file... 430 while ( it != list.end() ) // for each file...
431 { 431 {
432 432
433//US QString fn( QFile::decodeName(ep->d_name)); 433//US QString fn( QFile::decodeName(ep->d_name));
434 QString fn = (*it); // dp.entryList already decodes 434 QString fn = (*it); // dp.entryList already decodes
435 it++; 435 it++;
436 if ( fn.isNull() ) 436 if ( fn.isNull() )
437 break; 437 break;
438 438
439 if (fn == _dot || fn == _dotdot || fn.at(fn.length() - 1).latin1() == '~' ) 439 if (fn == _dot || fn == _dotdot || fn.at(fn.length() - 1).latin1() == '~' )
440 continue; 440 continue;
441 441
442/*US 442/*US
443 if (!recursive && !regexp.exactMatch(fn)) 443 if (!recursive && !regexp.exactMatch(fn))
444 continue; // No match 444 continue; // No match
445*/ 445*/
446//US this should do the same: 446//US this should do the same:
447 int pos = regexp.match(fn); 447 int pos = regexp.match(fn);
448 if (!recursive && !pos == 0) 448 if (!recursive && !pos == 0)
449 continue; // No match 449 continue; // No match
450 450
451 QString pathfn = path + fn; 451 QString pathfn = path + fn;
452/*US 452/*US
453 if ( stat( QFile::encodeName(pathfn), &buff ) != 0 ) { 453 if ( stat( QFile::encodeName(pathfn), &buff ) != 0 ) {
454 kdDebug() << "Error stat'ing " << pathfn << " : " << perror << endl; 454 kdDebug() << "Error stat'ing " << pathfn << " : " << perror << endl;
455 continue; // Couldn't stat (e.g. no read permissions) 455 continue; // Couldn't stat (e.g. no read permissions)
456 } 456 }
457 457
458 if ( recursive ) 458 if ( recursive )
459 { 459 {
460 if ( S_ISDIR( buff.st_mode )) { 460 if ( S_ISDIR( buff.st_mode )) {
461 lookupDirectory(pathfn + '/', relPart + fn + '/', regexp, list, relList, recursive, uniq); 461 lookupDirectory(pathfn + '/', relPart + fn + '/', regexp, list, relList, recursive, uniq);
462 } 462 }
463*/ 463*/
464//US replacement: 464//US replacement:
465 QFileInfo pathfnInfo(QFile::encodeName(pathfn)); 465 QFileInfo pathfnInfo(QFile::encodeName(pathfn));
466 if ( pathfnInfo.isReadable() == false ) 466 if ( pathfnInfo.isReadable() == false )
467 { 467 {
468//US kdDebug() << "Error stat'ing " << pathfn << " : " << perror << endl; 468//US kdDebug() << "Error stat'ing " << pathfn << " : " << perror << endl;
469 continue; // Couldn't stat (e.g. no read permissions) 469 continue; // Couldn't stat (e.g. no read permissions)
470 } 470 }
471 471
472 if ( recursive ) 472 if ( recursive )
473 { 473 {
474 if ( pathfnInfo.isDir()) { 474 if ( pathfnInfo.isDir()) {
475 lookupDirectory(pathfn + '/', relPart + fn + '/', regexp, list, relList, recursive, uniq); 475 lookupDirectory(pathfn + '/', relPart + fn + '/', regexp, list, relList, recursive, uniq);
476 } 476 }
477 477
478 478
479/*US 479/*US
480 if (!regexp.exactMatch(fn)) 480 if (!regexp.exactMatch(fn))
481 continue; // No match 481 continue; // No match
482*/ 482*/
483//US this should do the same: 483//US this should do the same:
484 pos = regexp.match(fn); 484 pos = regexp.match(fn);
485 if (!pos == 0) 485 if (!pos == 0)
486 continue; // No match 486 continue; // No match
487 } 487 }
488 488
489//US if ( S_ISREG( buff.st_mode)) 489//US if ( S_ISREG( buff.st_mode))
490 if ( pathfnInfo.isFile()) 490 if ( pathfnInfo.isFile())
491 { 491 {
492 if (!uniq || !relList.contains(relPart + fn)) 492 if (!uniq || !relList.contains(relPart + fn))
493 { 493 {
494 list.append( pathfn ); 494 list.append( pathfn );
495 relList.append( relPart + fn ); 495 relList.append( relPart + fn );
496 } 496 }
497 } 497 }
498 } 498 }
499//US closedir( dp ); 499//US closedir( dp );
500 } 500 }
501 else 501 else
502 { 502 {
503 // We look for a single file. 503 // We look for a single file.
504 QString fn = pattern; 504 QString fn = pattern;
505 QString pathfn = path + fn; 505 QString pathfn = path + fn;
506//US struct stat buff; 506//US struct stat buff;
507 QFileInfo pathfnInfo(QFile::encodeName(pathfn)); 507 QFileInfo pathfnInfo(QFile::encodeName(pathfn));
508 508
509 509
510//US if ( stat( QFile::encodeName(pathfn), &buff ) != 0 ) 510//US if ( stat( QFile::encodeName(pathfn), &buff ) != 0 )
511 if ( pathfnInfo.isReadable() == false ) 511 if ( pathfnInfo.isReadable() == false )
512 return; // File not found 512 return; // File not found
513 513
514//US if ( S_ISREG( buff.st_mode)) 514//US if ( S_ISREG( buff.st_mode))
515 if ( pathfnInfo.isFile()) 515 if ( pathfnInfo.isFile())
516 { 516 {
517 if (!uniq || !relList.contains(relPart + fn)) 517 if (!uniq || !relList.contains(relPart + fn))
518 { 518 {
519 list.append( pathfn ); 519 list.append( pathfn );
520 relList.append( relPart + fn ); 520 relList.append( relPart + fn );
521 } 521 }
522 } 522 }
523 } 523 }
524} 524}
525 525
526static void lookupPrefix(const QString& prefix, const QString& relpath, 526static void lookupPrefix(const QString& prefix, const QString& relpath,
527 const QString& relPart, 527 const QString& relPart,
528 const QRegExp &regexp, 528 const QRegExp &regexp,
529 QStringList& list, 529 QStringList& list,
530 QStringList& relList, 530 QStringList& relList,
531 bool recursive, bool uniq) 531 bool recursive, bool uniq)
532{ 532{
533 if (relpath.isNull()) { 533 if (relpath.isNull()) {
534 lookupDirectory(prefix, relPart, regexp, list, 534 lookupDirectory(prefix, relPart, regexp, list,
535 relList, recursive, uniq); 535 relList, recursive, uniq);
536 return; 536 return;
537 } 537 }
538 QString path; 538 QString path;
539 QString rest; 539 QString rest;
540 540
541 if (relpath.length()) 541 if (relpath.length())
542 { 542 {
543 int slash = relpath.find('/'); 543 int slash = relpath.find('/');
544 if (slash < 0) 544 if (slash < 0)
545 rest = relpath.left(relpath.length() - 1); 545 rest = relpath.left(relpath.length() - 1);
546 else { 546 else {
547 path = relpath.left(slash); 547 path = relpath.left(slash);
548 rest = relpath.mid(slash + 1); 548 rest = relpath.mid(slash + 1);
549 } 549 }
550 } 550 }
551 assert(prefix.at(prefix.length() - 1) == '/'); 551 assert(prefix.at(prefix.length() - 1) == '/');
552 552
553//US struct stat buff; 553//US struct stat buff;
554 554
555 if (path.contains('*') || path.contains('?')) { 555 if (path.contains('*') || path.contains('?')) {
556 QRegExp pathExp(path, true, true); 556 QRegExp pathExp(path, true, true);
557 //USDIR *dp = opendir( QFile::encodeName(prefix) ); 557 //USDIR *dp = opendir( QFile::encodeName(prefix) );
558 QDir dp(QFile::encodeName(prefix)); 558 QDir dp(QFile::encodeName(prefix));
559 559
560 //USif (!dp) 560 //USif (!dp)
561 if (!dp.exists()) 561 if (!dp.exists())
562 { 562 {
563 return; 563 return;
564 } 564 }
565 565
566 //USstruct dirent *ep; 566 //USstruct dirent *ep;
567 567
568 QString _dot("."); 568 QString _dot(".");
569 QString _dotdot(".."); 569 QString _dotdot("..");
570 570
571 //USwhile( ( ep = readdir( dp ) ) != 0L ) 571 //USwhile( ( ep = readdir( dp ) ) != 0L )
572 QStringList direntries = dp.entryList(); 572 QStringList direntries = dp.entryList();
573 QStringList::Iterator it = direntries.begin(); 573 QStringList::Iterator it = direntries.begin();
574 574
575 while ( it != list.end() ) // for each file... 575 while ( it != list.end() ) // for each file...
576 { 576 {
577//US QString fn( QFile::decodeName(ep->d_name)); 577//US QString fn( QFile::decodeName(ep->d_name));
578 QString fn = (*it); // dp.entryList() already encodes the strings 578 QString fn = (*it); // dp.entryList() already encodes the strings
579 it++; 579 it++;
580 580
581 if (fn == _dot || fn == _dotdot || fn.at(fn.length() - 1) == '~') 581 if (fn == _dot || fn == _dotdot || fn.at(fn.length() - 1) == '~')
582 continue; 582 continue;
583 583
584#ifdef DESKTOP_VERSION 584#ifdef DESKTOP_VERSION
585 585
586 if (pathExp.search(fn) == -1) 586 if (pathExp.search(fn) == -1)
587 continue; // No match 587 continue; // No match
588 588
589#else 589#else
590//US this should do the same: 590//US this should do the same:
591 if (pathExp.find(fn, 0) == -1) 591 if (pathExp.find(fn, 0) == -1)
592 continue; // No match 592 continue; // No match
593#endif 593#endif
594 QString rfn = relPart+fn; 594 QString rfn = relPart+fn;
595 fn = prefix + fn; 595 fn = prefix + fn;
596//US if ( stat( QFile::encodeName(fn), &buff ) != 0 ) 596//US if ( stat( QFile::encodeName(fn), &buff ) != 0 )
597 QFileInfo fnInfo(QFile::encodeName(fn)); 597 QFileInfo fnInfo(QFile::encodeName(fn));
598 if ( fnInfo.isReadable() == false ) 598 if ( fnInfo.isReadable() == false )
599 { 599 {
600//US kdDebug() << "Error statting " << fn << " : " << perror << endl; 600//US kdDebug() << "Error statting " << fn << " : " << perror << endl;
601 continue; // Couldn't stat (e.g. no permissions) 601 continue; // Couldn't stat (e.g. no permissions)
602 } 602 }
603 //US if ( S_ISDIR( buff.st_mode )) 603 //US if ( S_ISDIR( buff.st_mode ))
604 if ( fnInfo.isDir() ) 604 if ( fnInfo.isDir() )
605 605
606 lookupPrefix(fn + '/', rest, rfn + '/', regexp, list, relList, recursive, uniq); 606 lookupPrefix(fn + '/', rest, rfn + '/', regexp, list, relList, recursive, uniq);
607 } 607 }
608 608
609 //USclosedir( dp ); 609 //USclosedir( dp );
610 } else { 610 } else {
611 // Don't stat, if the dir doesn't exist we will find out 611 // Don't stat, if the dir doesn't exist we will find out
612 // when we try to open it. 612 // when we try to open it.
613 lookupPrefix(prefix + path + '/', rest, 613 lookupPrefix(prefix + path + '/', rest,
614 relPart + path + '/', regexp, list, 614 relPart + path + '/', regexp, list,
615 relList, recursive, uniq); 615 relList, recursive, uniq);
616 } 616 }
617} 617}
618 618
619QStringList 619QStringList
620KStandardDirs::findAllResources( const char *type, 620KStandardDirs::findAllResources( const char *type,
621 const QString& filter, 621 const QString& filter,
622 bool recursive, 622 bool recursive,
623 bool uniq, 623 bool uniq,
624 QStringList &relList) const 624 QStringList &relList) const
625{ 625{
626 QStringList list; 626 QStringList list;
627 if (filter.at(0) == '/') // absolute paths we return 627 if (filter.at(0) == '/') // absolute paths we return
628 { 628 {
629 list.append( filter); 629 list.append( filter);
630 return list; 630 return list;
631 } 631 }
632 632
633 QString filterPath; 633 QString filterPath;
634 QString filterFile; 634 QString filterFile;
635 635
636 if (filter.length()) 636 if (filter.length())
637 { 637 {
638 int slash = filter.findRev('/'); 638 int slash = filter.findRev('/');
639 if (slash < 0) 639 if (slash < 0)
640 filterFile = filter; 640 filterFile = filter;
641 else { 641 else {
642 filterPath = filter.left(slash + 1); 642 filterPath = filter.left(slash + 1);
643 filterFile = filter.mid(slash + 1); 643 filterFile = filter.mid(slash + 1);
644 } 644 }
645 } 645 }
646 checkConfig(); 646 checkConfig();
647 647
648 if (d && d->restrictionsActive && (strcmp(type, "data")==0)) 648 if (d && d->restrictionsActive && (strcmp(type, "data")==0))
649 applyDataRestrictions(filter); 649 applyDataRestrictions(filter);
650 QStringList candidates = resourceDirs(type); 650 QStringList candidates = resourceDirs(type);
651 if (filterFile.isEmpty()) 651 if (filterFile.isEmpty())
652 filterFile = "*"; 652 filterFile = "*";
653 653
654 QRegExp regExp(filterFile, true, true); 654 QRegExp regExp(filterFile, true, true);
655 for (QStringList::ConstIterator it = candidates.begin(); 655 for (QStringList::ConstIterator it = candidates.begin();
656 it != candidates.end(); it++) 656 it != candidates.end(); it++)
657 { 657 {
658 lookupPrefix(*it, filterPath, "", regExp, list, 658 lookupPrefix(*it, filterPath, "", regExp, list,
659 relList, recursive, uniq); 659 relList, recursive, uniq);
660 } 660 }
661 return list; 661 return list;
662} 662}
663 663
664QStringList 664QStringList
665KStandardDirs::findAllResources( const char *type, 665KStandardDirs::findAllResources( const char *type,
666 const QString& filter, 666 const QString& filter,
667 bool recursive, 667 bool recursive,
668 bool uniq) const 668 bool uniq) const
669{ 669{
670 QStringList relList; 670 QStringList relList;
671 return findAllResources(type, filter, recursive, uniq, relList); 671 return findAllResources(type, filter, recursive, uniq, relList);
672} 672}
673 673
674QString 674QString
675KStandardDirs::realPath(const QString &dirname) 675KStandardDirs::realPath(const QString &dirname)
676{ 676{
677#ifdef _WIN32_ 677#ifdef _WIN32_
678 return dirname; 678 return dirname;
679#else 679#else
680//US char realpath_buffer[MAXPATHLEN + 1]; 680//US char realpath_buffer[MAXPATHLEN + 1];
681//US memset(realpath_buffer, 0, MAXPATHLEN + 1); 681//US memset(realpath_buffer, 0, MAXPATHLEN + 1);
682 char realpath_buffer[250 + 1]; 682 char realpath_buffer[250 + 1];
683 memset(realpath_buffer, 0, 250 + 1); 683 memset(realpath_buffer, 0, 250 + 1);
684 684
685 /* If the path contains symlinks, get the real name */ 685 /* If the path contains symlinks, get the real name */
686 if (realpath( QFile::encodeName(dirname).data(), realpath_buffer) != 0) { 686 if (realpath( QFile::encodeName(dirname).data(), realpath_buffer) != 0) {
687 // succes, use result from realpath 687 // succes, use result from realpath
688 int len = strlen(realpath_buffer); 688 int len = strlen(realpath_buffer);
689 realpath_buffer[len] = '/'; 689 realpath_buffer[len] = '/';
690 realpath_buffer[len+1] = 0; 690 realpath_buffer[len+1] = 0;
691 return QFile::decodeName(realpath_buffer); 691 return QFile::decodeName(realpath_buffer);
692 } 692 }
693 693
694 return dirname; 694 return dirname;
695#endif 695#endif
696} 696}
697/*US 697/*US
698void KStandardDirs::createSpecialResource(const char *type) 698void KStandardDirs::createSpecialResource(const char *type)
699{ 699{
700 char hostname[256]; 700 char hostname[256];
701 hostname[0] = 0; 701 hostname[0] = 0;
702 gethostname(hostname, 255); 702 gethostname(hostname, 255);
703 QString dir = QString("%1%2-%3").arg(localkdedir()).arg(type).arg(hostname); 703 QString dir = QString("%1%2-%3").arg(localkdedir()).arg(type).arg(hostname);
704 char link[1024]; 704 char link[1024];
705 link[1023] = 0; 705 link[1023] = 0;
706 int result = readlink(QFile::encodeName(dir).data(), link, 1023); 706 int result = readlink(QFile::encodeName(dir).data(), link, 1023);
707 if ((result == -1) && (errno == ENOENT)) 707 if ((result == -1) && (errno == ENOENT))
708 { 708 {
709 QString srv = findExe(QString::fromLatin1("lnusertemp"), KDEDIR+QString::fromLatin1("/bin")); 709 QString srv = findExe(QString::fromLatin1("lnusertemp"), KDEDIR+QString::fromLatin1("/bin"));
710 if (srv.isEmpty()) 710 if (srv.isEmpty())
711 srv = findExe(QString::fromLatin1("lnusertemp")); 711 srv = findExe(QString::fromLatin1("lnusertemp"));
712 if (!srv.isEmpty()) 712 if (!srv.isEmpty())
713 { 713 {
714 system(QFile::encodeName(srv)+" "+type); 714 system(QFile::encodeName(srv)+" "+type);
715 result = readlink(QFile::encodeName(dir).data(), link, 1023); 715 result = readlink(QFile::encodeName(dir).data(), link, 1023);
716 } 716 }
717 } 717 }
718 if (result > 0) 718 if (result > 0)
719 { 719 {
720 link[result] = 0; 720 link[result] = 0;
721 if (link[0] == '/') 721 if (link[0] == '/')
722 dir = QFile::decodeName(link); 722 dir = QFile::decodeName(link);
723 else 723 else
724 dir = QDir::cleanDirPath(dir+QFile::decodeName(link)); 724 dir = QDir::cleanDirPath(dir+QFile::decodeName(link));
725 } 725 }
726 addResourceDir(type, dir+'/'); 726 addResourceDir(type, dir+'/');
727} 727}
728*/ 728*/
729 729
730QStringList KStandardDirs::resourceDirs(const char *type) const 730QStringList KStandardDirs::resourceDirs(const char *type) const
731{ 731{
732 QStringList *candidates = dircache.find(type); 732 QStringList *candidates = dircache.find(type);
733 733
734 if (!candidates) { // filling cache 734 if (!candidates) { // filling cache
735/*US 735/*US
736 if (strcmp(type, "socket") == 0) 736 if (strcmp(type, "socket") == 0)
737 const_cast<KStandardDirs *>(this)->createSpecialResource(type); 737 const_cast<KStandardDirs *>(this)->createSpecialResource(type);
738 else if (strcmp(type, "tmp") == 0) 738 else if (strcmp(type, "tmp") == 0)
739 const_cast<KStandardDirs *>(this)->createSpecialResource(type); 739 const_cast<KStandardDirs *>(this)->createSpecialResource(type);
740 else if (strcmp(type, "cache") == 0) 740 else if (strcmp(type, "cache") == 0)
741 const_cast<KStandardDirs *>(this)->createSpecialResource(type); 741 const_cast<KStandardDirs *>(this)->createSpecialResource(type);
742*/ 742*/
743 QDir testdir; 743 QDir testdir;
744 744
745 candidates = new QStringList(); 745 candidates = new QStringList();
746 QStringList *dirs; 746 QStringList *dirs;
747 747
748 bool restrictionActive = false; 748 bool restrictionActive = false;
749 if (d && d->restrictionsActive) 749 if (d && d->restrictionsActive)
750 { 750 {
751 if (d->dataRestrictionActive) 751 if (d->dataRestrictionActive)
752 restrictionActive = true; 752 restrictionActive = true;
753 else if (d->restrictions["all"]) 753 else if (d->restrictions["all"])
754 restrictionActive = true; 754 restrictionActive = true;
755 else if (d->restrictions[type]) 755 else if (d->restrictions[type])
756 restrictionActive = true; 756 restrictionActive = true;
757 d->dataRestrictionActive = false; // Reset 757 d->dataRestrictionActive = false; // Reset
758 } 758 }
759 759
760 dirs = relatives.find(type); 760 dirs = relatives.find(type);
761 if (dirs) 761 if (dirs)
762 { 762 {
763 bool local = true; 763 bool local = true;
764 const QStringList *prefixList = 0; 764 const QStringList *prefixList = 0;
765 if (strncmp(type, "xdgdata-", 8) == 0) 765 if (strncmp(type, "xdgdata-", 8) == 0)
766 prefixList = &(d->xdgdata_prefixes); 766 prefixList = &(d->xdgdata_prefixes);
767 else if (strncmp(type, "xdgconf-", 8) == 0) 767 else if (strncmp(type, "xdgconf-", 8) == 0)
768 prefixList = &(d->xdgconf_prefixes); 768 prefixList = &(d->xdgconf_prefixes);
769 else 769 else
770 prefixList = &prefixes; 770 prefixList = &prefixes;
771 771
772 for (QStringList::ConstIterator pit = prefixList->begin(); 772 for (QStringList::ConstIterator pit = prefixList->begin();
773 pit != prefixList->end(); 773 pit != prefixList->end();
774 pit++) 774 pit++)
775 { 775 {
776 for (QStringList::ConstIterator it = dirs->begin(); 776 for (QStringList::ConstIterator it = dirs->begin();
777 it != dirs->end(); ++it) { 777 it != dirs->end(); ++it) {
778 QString path = realPath(*pit + *it); 778 QString path = realPath(*pit + *it);
779 testdir.setPath(path); 779 testdir.setPath(path);
780 if (local && restrictionActive) 780 if (local && restrictionActive)
781 continue; 781 continue;
782 if ((local || testdir.exists()) && !candidates->contains(path)) 782 if ((local || testdir.exists()) && !candidates->contains(path))
783 candidates->append(path); 783 candidates->append(path);
784 } 784 }
785 local = false; 785 local = false;
786 } 786 }
787 } 787 }
788 dirs = absolutes.find(type); 788 dirs = absolutes.find(type);
789 if (dirs) 789 if (dirs)
790 for (QStringList::ConstIterator it = dirs->begin(); 790 for (QStringList::ConstIterator it = dirs->begin();
791 it != dirs->end(); ++it) 791 it != dirs->end(); ++it)
792 { 792 {
793 testdir.setPath(*it); 793 testdir.setPath(*it);
794 if (testdir.exists()) 794 if (testdir.exists())
795 { 795 {
796 QString filename = realPath(*it); 796 QString filename = realPath(*it);
797 if (!candidates->contains(filename)) 797 if (!candidates->contains(filename))
798 candidates->append(filename); 798 candidates->append(filename);
799 } 799 }
800 } 800 }
801 dircache.insert(type, candidates); 801 dircache.insert(type, candidates);
802 } 802 }
803 803
804#if 0 804#if 0
805 kdDebug() << "found dirs for resource " << type << ":" << endl; 805 kdDebug() << "found dirs for resource " << type << ":" << endl;
806 for (QStringList::ConstIterator pit = candidates->begin(); 806 for (QStringList::ConstIterator pit = candidates->begin();
807 pit != candidates->end(); 807 pit != candidates->end();
808 pit++) 808 pit++)
809 { 809 {
810 fprintf(stderr, "%s\n", (*pit).latin1()); 810 fprintf(stderr, "%s\n", (*pit).latin1());
811 } 811 }
812#endif 812#endif
813 813
814 814
815 return *candidates; 815 return *candidates;
816} 816}
817 817
818/*US 818/*US
819QString KStandardDirs::findExe( const QString& appname, 819QString KStandardDirs::findExe( const QString& appname,
820 const QString& pstr, bool ignore) 820 const QString& pstr, bool ignore)
821{ 821{
822 QFileInfo info; 822 QFileInfo info;
823 823
824 // absolute path ? 824 // absolute path ?
825 if (appname.startsWith(QString::fromLatin1("/"))) 825 if (appname.startsWith(QString::fromLatin1("/")))
826 { 826 {
827 info.setFile( appname ); 827 info.setFile( appname );
828 if( info.exists() && ( ignore || info.isExecutable() ) 828 if( info.exists() && ( ignore || info.isExecutable() )
829 && info.isFile() ) { 829 && info.isFile() ) {
830 return appname; 830 return appname;
831 } 831 }
832 return QString::null; 832 return QString::null;
833 } 833 }
834 834
835//US QString p = QString("%1/%2").arg(__KDE_BINDIR).arg(appname); 835//US QString p = QString("%1/%2").arg(__KDE_BINDIR).arg(appname);
836 QString p = QString("%1/%2").arg(appname).arg(appname); 836 QString p = QString("%1/%2").arg(appname).arg(appname);
837 qDebug("KStandardDirs::findExe this is probably wrong"); 837 qDebug("KStandardDirs::findExe this is probably wrong");
838 838
839 info.setFile( p ); 839 info.setFile( p );
840 if( info.exists() && ( ignore || info.isExecutable() ) 840 if( info.exists() && ( ignore || info.isExecutable() )
841 && ( info.isFile() || info.isSymLink() ) ) { 841 && ( info.isFile() || info.isSymLink() ) ) {
842 return p; 842 return p;
843 } 843 }
844 844
845 QStringList tokens; 845 QStringList tokens;
846 p = pstr; 846 p = pstr;
847 847
848 if( p.isNull() ) { 848 if( p.isNull() ) {
849 p = getenv( "PATH" ); 849 p = getenv( "PATH" );
850 } 850 }
851 851
852 tokenize( tokens, p, ":\b" ); 852 tokenize( tokens, p, ":\b" );
853 853
854 // split path using : or \b as delimiters 854 // split path using : or \b as delimiters
855 for( unsigned i = 0; i < tokens.count(); i++ ) { 855 for( unsigned i = 0; i < tokens.count(); i++ ) {
856 p = tokens[ i ]; 856 p = tokens[ i ];
857 857
858 if ( p[ 0 ] == '~' ) 858 if ( p[ 0 ] == '~' )
859 { 859 {
860 int len = p.find( '/' ); 860 int len = p.find( '/' );
861 if ( len == -1 ) 861 if ( len == -1 )
862 len = p.length(); 862 len = p.length();
863 if ( len == 1 ) 863 if ( len == 1 )
864 p.replace( 0, 1, QDir::homeDirPath() ); 864 p.replace( 0, 1, QDir::homeDirPath() );
865 else 865 else
866 { 866 {
867 QString user = p.mid( 1, len - 1 ); 867 QString user = p.mid( 1, len - 1 );
868 struct passwd *dir = getpwnam( user.local8Bit().data() ); 868 struct passwd *dir = getpwnam( user.local8Bit().data() );
869 if ( dir && strlen( dir->pw_dir ) ) 869 if ( dir && strlen( dir->pw_dir ) )
870 p.replace( 0, len, QString::fromLocal8Bit( dir->pw_dir ) ); 870 p.replace( 0, len, QString::fromLocal8Bit( dir->pw_dir ) );
871 } 871 }
872 } 872 }
873 873
874 p += "/"; 874 p += "/";
875 p += appname; 875 p += appname;
876 876
877 // Check for executable in this tokenized path 877 // Check for executable in this tokenized path
878 info.setFile( p ); 878 info.setFile( p );
879 879
880 if( info.exists() && ( ignore || info.isExecutable() ) 880 if( info.exists() && ( ignore || info.isExecutable() )
881 && ( info.isFile() || info.isSymLink() ) ) { 881 && ( info.isFile() || info.isSymLink() ) ) {
882 return p; 882 return p;
883 } 883 }
884 } 884 }
885 885
886 // If we reach here, the executable wasn't found. 886 // If we reach here, the executable wasn't found.
887 // So return empty string. 887 // So return empty string.
888 888
889 return QString::null; 889 return QString::null;
890} 890}
891 891
892int KStandardDirs::findAllExe( QStringList& list, const QString& appname, 892int KStandardDirs::findAllExe( QStringList& list, const QString& appname,
893 const QString& pstr, bool ignore ) 893 const QString& pstr, bool ignore )
894{ 894{
895 QString p = pstr; 895 QString p = pstr;
896 QFileInfo info; 896 QFileInfo info;
897 QStringList tokens; 897 QStringList tokens;
898 898
899 if( p.isNull() ) { 899 if( p.isNull() ) {
900 p = getenv( "PATH" ); 900 p = getenv( "PATH" );
901 } 901 }
902 902
903 list.clear(); 903 list.clear();
904 tokenize( tokens, p, ":\b" ); 904 tokenize( tokens, p, ":\b" );
905 905
906 for ( unsigned i = 0; i < tokens.count(); i++ ) { 906 for ( unsigned i = 0; i < tokens.count(); i++ ) {
907 p = tokens[ i ]; 907 p = tokens[ i ];
908 p += "/"; 908 p += "/";
909 p += appname; 909 p += appname;
910 910
911 info.setFile( p ); 911 info.setFile( p );
912 912
913 if( info.exists() && (ignore || info.isExecutable()) 913 if( info.exists() && (ignore || info.isExecutable())
914 && info.isFile() ) { 914 && info.isFile() ) {
915 list.append( p ); 915 list.append( p );
916 } 916 }
917 917
918 } 918 }
919 919
920 return list.count(); 920 return list.count();
921} 921}
922*/ 922*/
923 923
924static int tokenize( QStringList& tokens, const QString& str, 924static int tokenize( QStringList& tokens, const QString& str,
925 const QString& delim ) 925 const QString& delim )
926{ 926{
927 int len = str.length(); 927 int len = str.length();
928 QString token = ""; 928 QString token = "";
929 929
930 for( int index = 0; index < len; index++) 930 for( int index = 0; index < len; index++)
931 { 931 {
932 if ( delim.find( str[ index ] ) >= 0 ) 932 if ( delim.find( str[ index ] ) >= 0 )
933 { 933 {
934 tokens.append( token ); 934 tokens.append( token );
935 token = ""; 935 token = "";
936 } 936 }
937 else 937 else
938 { 938 {
939 token += str[ index ]; 939 token += str[ index ];
940 } 940 }
941 } 941 }
942 if ( token.length() > 0 ) 942 if ( token.length() > 0 )
943 { 943 {
944 tokens.append( token ); 944 tokens.append( token );
945 } 945 }
946 946
947 return tokens.count(); 947 return tokens.count();
948} 948}
949 949
950QString KStandardDirs::kde_default(const char *type) { 950QString KStandardDirs::kde_default(const char *type) {
951 if (!strcmp(type, "data")) 951 if (!strcmp(type, "data"))
952 return "apps/"; 952 return "apps/";
953 if (!strcmp(type, "html")) 953 if (!strcmp(type, "html"))
954 return "share/doc/HTML/"; 954 return "share/doc/HTML/";
955 if (!strcmp(type, "icon")) 955 if (!strcmp(type, "icon"))
956 return "share/icons/"; 956 return "share/icons/";
957 if (!strcmp(type, "config")) 957 if (!strcmp(type, "config"))
958 return "config/"; 958 return "config/";
959 if (!strcmp(type, "pixmap")) 959 if (!strcmp(type, "pixmap"))
960 return "share/pixmaps/"; 960 return "share/pixmaps/";
961 if (!strcmp(type, "apps")) 961 if (!strcmp(type, "apps"))
962 return "share/applnk/"; 962 return "share/applnk/";
963 if (!strcmp(type, "sound")) 963 if (!strcmp(type, "sound"))
964 return "share/sounds/"; 964 return "share/sounds/";
965 if (!strcmp(type, "locale")) 965 if (!strcmp(type, "locale"))
966 return "share/locale/"; 966 return "share/locale/";
967 if (!strcmp(type, "services")) 967 if (!strcmp(type, "services"))
968 return "share/services/"; 968 return "share/services/";
969 if (!strcmp(type, "servicetypes")) 969 if (!strcmp(type, "servicetypes"))
970 return "share/servicetypes/"; 970 return "share/servicetypes/";
971 if (!strcmp(type, "mime")) 971 if (!strcmp(type, "mime"))
972 return "share/mimelnk/"; 972 return "share/mimelnk/";
973 if (!strcmp(type, "cgi")) 973 if (!strcmp(type, "cgi"))
974 return "cgi-bin/"; 974 return "cgi-bin/";
975 if (!strcmp(type, "wallpaper")) 975 if (!strcmp(type, "wallpaper"))
976 return "share/wallpapers/"; 976 return "share/wallpapers/";
977 if (!strcmp(type, "templates")) 977 if (!strcmp(type, "templates"))
978 return "share/templates/"; 978 return "share/templates/";
979 if (!strcmp(type, "exe")) 979 if (!strcmp(type, "exe"))
980 return "bin/"; 980 return "bin/";
981 if (!strcmp(type, "lib")) 981 if (!strcmp(type, "lib"))
982 return "lib/"; 982 return "lib/";
983 if (!strcmp(type, "module")) 983 if (!strcmp(type, "module"))
984 return "lib/kde3/"; 984 return "lib/kde3/";
985 if (!strcmp(type, "qtplugins")) 985 if (!strcmp(type, "qtplugins"))
986 return "lib/kde3/plugins"; 986 return "lib/kde3/plugins";
987 if (!strcmp(type, "xdgdata-apps")) 987 if (!strcmp(type, "xdgdata-apps"))
988 return "applications/"; 988 return "applications/";
989 if (!strcmp(type, "xdgdata-dirs")) 989 if (!strcmp(type, "xdgdata-dirs"))
990 return "desktop-directories/"; 990 return "desktop-directories/";
991 if (!strcmp(type, "xdgconf-menu")) 991 if (!strcmp(type, "xdgconf-menu"))
992 return "menus/"; 992 return "menus/";
993 if (!strcmp(type, "tmp")) 993 if (!strcmp(type, "tmp"))
994 return "tmp/"; 994 return "tmp/";
995 995
996 qFatal("unknown resource type %s", type); 996 qFatal("unknown resource type %s", type);
997 return QString::null; 997 return QString::null;
998} 998}
999 999
1000QString KStandardDirs::saveLocation(const char *type, 1000QString KStandardDirs::saveLocation(const char *type,
1001 const QString& suffix, 1001 const QString& suffix,
1002 bool create) const 1002 bool create) const
1003{ 1003{
1004 //qDebug("KStandardDirs::saveLocation called %s %s", type,suffix.latin1() ); 1004 //qDebug("KStandardDirs::saveLocation called %s %s", type,suffix.latin1() );
1005 //return ""; 1005 //return "";
1006 checkConfig(); 1006 checkConfig();
1007 1007
1008 QString *pPath = savelocations.find(type); 1008 QString *pPath = savelocations.find(type);
1009 if (!pPath) 1009 if (!pPath)
1010 { 1010 {
1011 QStringList *dirs = relatives.find(type); 1011 QStringList *dirs = relatives.find(type);
1012 if (!dirs && ( 1012 if (!dirs && (
1013 (strcmp(type, "socket") == 0) || 1013 (strcmp(type, "socket") == 0) ||
1014 (strcmp(type, "tmp") == 0) || 1014 (strcmp(type, "tmp") == 0) ||
1015 (strcmp(type, "cache") == 0) )) 1015 (strcmp(type, "cache") == 0) ))
1016 { 1016 {
1017 (void) resourceDirs(type); // Generate socket|tmp|cache resource. 1017 (void) resourceDirs(type); // Generate socket|tmp|cache resource.
1018 dirs = relatives.find(type); // Search again. 1018 dirs = relatives.find(type); // Search again.
1019 } 1019 }
1020 if (dirs) 1020 if (dirs)
1021 { 1021 {
1022 // Check for existance of typed directory + suffix 1022 // Check for existance of typed directory + suffix
1023 if (strncmp(type, "xdgdata-", 8) == 0) 1023 if (strncmp(type, "xdgdata-", 8) == 0)
1024 pPath = new QString(realPath(localxdgdatadir() + dirs->last())); 1024 pPath = new QString(realPath(localxdgdatadir() + dirs->last()));
1025 else if (strncmp(type, "xdgconf-", 8) == 0) 1025 else if (strncmp(type, "xdgconf-", 8) == 0)
1026 pPath = new QString(realPath(localxdgconfdir() + dirs->last())); 1026 pPath = new QString(realPath(localxdgconfdir() + dirs->last()));
1027 else 1027 else
1028 pPath = new QString(realPath(localkdedir() + dirs->last())); 1028 pPath = new QString(realPath(localkdedir() + dirs->last()));
1029 } 1029 }
1030 else { 1030 else {
1031 dirs = absolutes.find(type); 1031 dirs = absolutes.find(type);
1032 if (!dirs) 1032 if (!dirs)
1033 qFatal("KStandardDirs: The resource type %s is not registered", type); 1033 qFatal("KStandardDirs: The resource type %s is not registered", type);
1034 pPath = new QString(realPath(dirs->last())); 1034 pPath = new QString(realPath(dirs->last()));
1035 } 1035 }
1036 1036
1037 savelocations.insert(type, pPath); 1037 savelocations.insert(type, pPath);
1038 } 1038 }
1039 1039
1040 QString fullPath = *pPath + suffix; 1040 QString fullPath = *pPath + suffix;
1041//US struct stat st; 1041//US struct stat st;
1042//US if (stat(QFile::encodeName(fullPath), &st) != 0 || !(S_ISDIR(st.st_mode))) 1042//US if (stat(QFile::encodeName(fullPath), &st) != 0 || !(S_ISDIR(st.st_mode)))
1043 QFileInfo fullPathInfo(QFile::encodeName(fullPath)); 1043 QFileInfo fullPathInfo(QFile::encodeName(fullPath));
1044 if (fullPathInfo.isReadable() || !fullPathInfo.isDir()) 1044 if (fullPathInfo.isReadable() || !fullPathInfo.isDir())
1045 1045
1046 1046
1047 { 1047 {
1048 if(!create) { 1048 if(!create) {
1049#ifndef NDEBUG 1049#ifndef NDEBUG
1050 qDebug("save location %s doesn't exist", fullPath.latin1()); 1050 qDebug("save location %s doesn't exist", fullPath.latin1());
1051#endif 1051#endif
1052 return fullPath; 1052 return fullPath;
1053 } 1053 }
1054 if(!makeDir(fullPath, 0700)) { 1054 if(!makeDir(fullPath, 0700)) {
1055 qWarning("failed to create %s", fullPath.latin1()); 1055 qWarning("failed to create %s", fullPath.latin1());
1056 return fullPath; 1056 return fullPath;
1057 } 1057 }
1058 dircache.remove(type); 1058 dircache.remove(type);
1059 } 1059 }
1060 return fullPath; 1060 return fullPath;
1061} 1061}
1062 1062
1063QString KStandardDirs::relativeLocation(const char *type, const QString &absPath) 1063QString KStandardDirs::relativeLocation(const char *type, const QString &absPath)
1064{ 1064{
1065 QString fullPath = absPath; 1065 QString fullPath = absPath;
1066 int i = absPath.findRev('/'); 1066 int i = absPath.findRev('/');
1067 if (i != -1) 1067 if (i != -1)
1068 { 1068 {
1069 fullPath = realPath(absPath.left(i+1))+absPath.mid(i+1); // Normalize 1069 fullPath = realPath(absPath.left(i+1))+absPath.mid(i+1); // Normalize
1070 } 1070 }
1071 1071
1072 QStringList candidates = resourceDirs(type); 1072 QStringList candidates = resourceDirs(type);
1073 1073
1074 for (QStringList::ConstIterator it = candidates.begin(); 1074 for (QStringList::ConstIterator it = candidates.begin();
1075 it != candidates.end(); it++) 1075 it != candidates.end(); it++)
1076 if (fullPath.startsWith(*it)) 1076 if (fullPath.startsWith(*it))
1077 { 1077 {
1078 return fullPath.mid((*it).length()); 1078 return fullPath.mid((*it).length());
1079 } 1079 }
1080 1080
1081 return absPath; 1081 return absPath;
1082} 1082}
1083 1083
1084 1084
1085bool KStandardDirs::makeDir(const QString& dir2, int mode) 1085bool KStandardDirs::makeDir(const QString& dir2, int mode)
1086{ 1086{
1087 QString dir = QDir::convertSeparators( dir2 ); 1087 QString dir = QDir::convertSeparators( dir2 );
1088#if 0 1088#if 0
1089 //LR 1089 //LR
1090 1090
1091 // we want an absolute path 1091 // we want an absolute path
1092 if (dir.at(0) != '/') 1092 if (dir.at(0) != '/')
1093 return false; 1093 return false;
1094 1094
1095 QString target = dir; 1095 QString target = dir;
1096 uint len = target.length(); 1096 uint len = target.length();
1097 1097
1098 // append trailing slash if missing 1098 // append trailing slash if missing
1099 if (dir.at(len - 1) != '/') 1099 if (dir.at(len - 1) != '/')
1100 target += '/'; 1100 target += '/';
1101 1101
1102 QString base(""); 1102 QString base("");
1103 uint i = 1; 1103 uint i = 1;
1104 1104
1105 while( i < len ) 1105 while( i < len )
1106 { 1106 {
1107//US struct stat st; 1107//US struct stat st;
1108 int pos = target.find('/', i); 1108 int pos = target.find('/', i);
1109 base += target.mid(i - 1, pos - i + 1); 1109 base += target.mid(i - 1, pos - i + 1);
1110 QCString baseEncoded = QFile::encodeName(base); 1110 QCString baseEncoded = QFile::encodeName(base);
1111 // bail out if we encountered a problem 1111 // bail out if we encountered a problem
1112//US if (stat(baseEncoded, &st) != 0) 1112//US if (stat(baseEncoded, &st) != 0)
1113 QFileInfo baseEncodedInfo(baseEncoded); 1113 QFileInfo baseEncodedInfo(baseEncoded);
1114 if (!baseEncodedInfo.exists()) 1114 if (!baseEncodedInfo.exists())
1115 { 1115 {
1116 // Directory does not exist.... 1116 // Directory does not exist....
1117 // Or maybe a dangling symlink ? 1117 // Or maybe a dangling symlink ?
1118//US if (lstat(baseEncoded, &st) == 0) 1118//US if (lstat(baseEncoded, &st) == 0)
1119 if (baseEncodedInfo.isSymLink()) { 1119 if (baseEncodedInfo.isSymLink()) {
1120//US (void)unlink(baseEncoded); // try removing 1120//US (void)unlink(baseEncoded); // try removing
1121 QFile(baseEncoded).remove(); 1121 QFile(baseEncoded).remove();
1122 } 1122 }
1123 1123
1124 //US if ( mkdir(baseEncoded, (mode_t) mode) != 0) 1124 //US if ( mkdir(baseEncoded, (mode_t) mode) != 0)
1125 QDir dirObj; 1125 QDir dirObj;
1126 if ( dirObj.mkdir(baseEncoded) != true ) 1126 if ( dirObj.mkdir(baseEncoded) != true )
1127 { 1127 {
1128 //US perror("trying to create local folder"); 1128 //US perror("trying to create local folder");
1129 return false; // Couldn't create it :-( 1129 return false; // Couldn't create it :-(
1130 } 1130 }
1131 } 1131 }
1132 i = pos + 1; 1132 i = pos + 1;
1133 } 1133 }
1134 return true; 1134 return true;
1135#endif 1135#endif
1136 1136
1137 // ******************************************** 1137 // ********************************************
1138 // new code for WIN32 1138 // new code for WIN32
1139 QDir dirObj; 1139 QDir dirObj;
1140 1140
1141 1141
1142 // we want an absolute path 1142 // we want an absolute path
1143#ifndef _WIN32_ 1143#ifndef _WIN32_
1144 if (dir.at(0) != '/') 1144 if (dir.at(0) != '/')
1145 return false; 1145 return false;
1146#endif 1146#endif
1147 1147
1148 QString target = dir; 1148 QString target = dir;
1149 uint len = target.length(); 1149 uint len = target.length();
1150#ifndef _WIN32_ 1150#ifndef _WIN32_
1151 // append trailing slash if missing 1151 // append trailing slash if missing
1152 if (dir.at(len - 1) != '/') 1152 if (dir.at(len - 1) != '/')
1153 target += '/'; 1153 target += '/';
1154#endif 1154#endif
1155 1155
1156 QString base(""); 1156 QString base("");
1157 uint i = 1; 1157 uint i = 1;
1158 1158
1159 while( i < len ) 1159 while( i < len )
1160 { 1160 {
1161//US struct stat st; 1161//US struct stat st;
1162#ifndef _WIN32_ 1162#ifndef _WIN32_
1163 int pos = target.find('/', i); 1163 int pos = target.find('/', i);
1164#else 1164#else
1165 int pos = target.find('\\', i); 1165 int pos = target.find('\\', i);
1166#endif 1166#endif
1167 if ( pos < 0 ) 1167 if ( pos < 0 )
1168 return true; 1168 return true;
1169 base += target.mid(i - 1, pos - i + 1); 1169 base += target.mid(i - 1, pos - i + 1);
1170 //QMessageBox::information( 0,"cap111", base, 1 ); 1170 //QMessageBox::information( 0,"cap111", base, 1 );
1171/*US 1171/*US
1172 QCString baseEncoded = QFile::encodeName(base); 1172 QCString baseEncoded = QFile::encodeName(base);
1173 // bail out if we encountered a problem 1173 // bail out if we encountered a problem
1174 if (stat(baseEncoded, &st) != 0) 1174 if (stat(baseEncoded, &st) != 0)
1175 { 1175 {
1176 // Directory does not exist.... 1176 // Directory does not exist....
1177 // Or maybe a dangling symlink ? 1177 // Or maybe a dangling symlink ?
1178 if (lstat(baseEncoded, &st) == 0) 1178 if (lstat(baseEncoded, &st) == 0)
1179 (void)unlink(baseEncoded); // try removing 1179 (void)unlink(baseEncoded); // try removing
1180 1180
1181 1181
1182 if ( mkdir(baseEncoded, (mode_t) mode) != 0) { 1182 if ( mkdir(baseEncoded, (mode_t) mode) != 0) {
1183 perror("trying to create local folder"); 1183 perror("trying to create local folder");
1184 return false; // Couldn't create it :-( 1184 return false; // Couldn't create it :-(
1185 } 1185 }
1186 } 1186 }
1187*/ 1187*/
1188 1188
1189 if (dirObj.exists(base) == false) 1189 if (dirObj.exists(base) == false)
1190 { 1190 {
1191 //qDebug("KStandardDirs::makeDir try to create : %s" , base.latin1()); 1191 //qDebug("KStandardDirs::makeDir try to create : %s" , base.latin1());
1192 if (dirObj.mkdir(base) != true) 1192 if (dirObj.mkdir(base) != true)
1193 { 1193 {
1194 qDebug("KStandardDirs::makeDir could not create: %s" , base.latin1()); 1194 qDebug("KStandardDirs::makeDir could not create: %s" , base.latin1());
1195 return false; 1195 return false;
1196 } 1196 }
1197 } 1197 }
1198 1198
1199 i = pos + 1; 1199 i = pos + 1;
1200 } 1200 }
1201 return true; 1201 return true;
1202 1202
1203} 1203}
1204 1204
1205static QString readEnvPath(const char *env) 1205static QString readEnvPath(const char *env)
1206{ 1206{
1207#ifdef _WIN32_ 1207#ifdef _WIN32_
1208 return ""; 1208 return "";
1209#else 1209#else
1210 QCString c_path = getenv(env); 1210 QCString c_path = getenv(env);
1211 if (c_path.isEmpty()) 1211 if (c_path.isEmpty())
1212 return QString::null; 1212 return QString::null;
1213 return QFile::decodeName(c_path); 1213 return QFile::decodeName(c_path);
1214#endif 1214#endif
1215} 1215}
1216 1216
1217void KStandardDirs::addKDEDefaults() 1217void KStandardDirs::addKDEDefaults()
1218{ 1218{
1219 //qDebug("ERROR: KStandardDirs::addKDEDefaults() called "); 1219 //qDebug("ERROR: KStandardDirs::addKDEDefaults() called ");
1220 //return; 1220 //return;
1221 QStringList kdedirList; 1221 QStringList kdedirList;
1222 1222
1223 // begin KDEDIRS 1223 // begin KDEDIRS
1224 QString kdedirs = readEnvPath("MICROKDEDIRS"); 1224 QString kdedirs = readEnvPath("MICROKDEDIRS");
1225 if (!kdedirs.isEmpty()) 1225 if (!kdedirs.isEmpty())
1226 { 1226 {
1227 tokenize(kdedirList, kdedirs, ":"); 1227 tokenize(kdedirList, kdedirs, ":");
1228 } 1228 }
1229 else 1229 else
1230 { 1230 {
1231 QString kdedir = readEnvPath("MICROKDEDIR"); 1231 QString kdedir = readEnvPath("MICROKDEDIR");
1232 if (!kdedir.isEmpty()) 1232 if (!kdedir.isEmpty())
1233 { 1233 {
1234 kdedir = KShell::tildeExpand(kdedir); 1234 kdedir = KShell::tildeExpand(kdedir);
1235 kdedirList.append(kdedir); 1235 kdedirList.append(kdedir);
1236 } 1236 }
1237 } 1237 }
1238//US kdedirList.append(KDEDIR); 1238//US kdedirList.append(KDEDIR);
1239//US for embedded, add qtopia dir as kdedir 1239//US for embedded, add qtopia dir as kdedir
1240 1240
1241#ifndef DESKTOP_VERSION 1241#ifndef DESKTOP_VERSION
1242 kdedirList.append(readEnvPath("QPEDIR" )); 1242 QString tmp = readEnvPath("QPEDIR");
1243 if (!tmp.isEmpty())
1244 kdedirList.append(tmp);
1245
1246 tmp = readEnvPath("QTDIR");
1247 if (!tmp.isEmpty())
1248 kdedirList.append(tmp);
1249
1250 tmp = readEnvPath("OPIEDIR");
1251 if (!tmp.isEmpty())
1252 kdedirList.append(tmp);
1253
1243#endif 1254#endif
1244 1255
1245#ifdef __KDE_EXECPREFIX 1256#ifdef __KDE_EXECPREFIX
1246 QString execPrefix(__KDE_EXECPREFIX); 1257 QString execPrefix(__KDE_EXECPREFIX);
1247 if (execPrefix!="NONE") 1258 if (execPrefix!="NONE")
1248 kdedirList.append(execPrefix); 1259 kdedirList.append(execPrefix);
1249#endif 1260#endif
1250 1261
1251 QString localKdeDir; 1262 QString localKdeDir;
1252 1263
1253//US if (getuid()) 1264//US if (getuid())
1254 if (true) 1265 if (true)
1255 { 1266 {
1256 localKdeDir = readEnvPath("MICROKDEHOME"); 1267 localKdeDir = readEnvPath("MICROKDEHOME");
1257 if (!localKdeDir.isEmpty()) 1268 if (!localKdeDir.isEmpty())
1258 { 1269 {
1259 if (localKdeDir.at(localKdeDir.length()-1) != '/') 1270 if (localKdeDir.at(localKdeDir.length()-1) != '/')
1260 localKdeDir += '/'; 1271 localKdeDir += '/';
1261 } 1272 }
1262 else 1273 else
1263 { 1274 {
1264 localKdeDir = QDir::homeDirPath() + "/kdepim/"; 1275 localKdeDir = QDir::homeDirPath() + "/kdepim/";
1265 } 1276 }
1266 } 1277 }
1267 else 1278 else
1268 { 1279 {
1269 // We treat root different to prevent root messing up the 1280 // We treat root different to prevent root messing up the
1270 // file permissions in the users home directory. 1281 // file permissions in the users home directory.
1271 localKdeDir = readEnvPath("MICROKDEROOTHOME"); 1282 localKdeDir = readEnvPath("MICROKDEROOTHOME");
1272 if (!localKdeDir.isEmpty()) 1283 if (!localKdeDir.isEmpty())
1273 { 1284 {
1274 if (localKdeDir.at(localKdeDir.length()-1) != '/') 1285 if (localKdeDir.at(localKdeDir.length()-1) != '/')
1275 localKdeDir += '/'; 1286 localKdeDir += '/';
1276 } 1287 }
1277 else 1288 else
1278 { 1289 {
1279//US struct passwd *pw = getpwuid(0); 1290//US struct passwd *pw = getpwuid(0);
1280//US localKdeDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.microkde/"; 1291//US localKdeDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.microkde/";
1281 qDebug("KStandardDirs::addKDEDefaults: 1 has to be fixed"); 1292 qDebug("KStandardDirs::addKDEDefaults: 1 has to be fixed");
1282 } 1293 }
1283 1294
1284 } 1295 }
1285 1296
1286//US localKdeDir = appDir(); 1297//US localKdeDir = appDir();
1287 1298
1288//US 1299//US
1289// qDebug("KStandardDirs::addKDEDefaults: localKdeDir=%s", localKdeDir.latin1()); 1300// qDebug("KStandardDirs::addKDEDefaults: localKdeDir=%s", localKdeDir.latin1());
1290 if (localKdeDir != "-/") 1301 if (localKdeDir != "-/")
1291 { 1302 {
1292 localKdeDir = KShell::tildeExpand(localKdeDir); 1303 localKdeDir = KShell::tildeExpand(localKdeDir);
1293 addPrefix(localKdeDir); 1304 addPrefix(localKdeDir);
1294 } 1305 }
1295 1306
1296 for (QStringList::ConstIterator it = kdedirList.begin(); 1307 for (QStringList::ConstIterator it = kdedirList.begin();
1297 it != kdedirList.end(); it++) 1308 it != kdedirList.end(); it++)
1298 { 1309 {
1299 QString dir = KShell::tildeExpand(*it); 1310 QString dir = KShell::tildeExpand(*it);
1300 addPrefix(dir); 1311 addPrefix(dir);
1301 } 1312 }
1302 // end KDEDIRS 1313 // end KDEDIRS
1303 1314
1304 // begin XDG_CONFIG_XXX 1315 // begin XDG_CONFIG_XXX
1305 QStringList xdgdirList; 1316 QStringList xdgdirList;
1306 QString xdgdirs = readEnvPath("XDG_CONFIG_DIRS"); 1317 QString xdgdirs = readEnvPath("XDG_CONFIG_DIRS");
1307 if (!xdgdirs.isEmpty()) 1318 if (!xdgdirs.isEmpty())
1308 { 1319 {
1309 tokenize(xdgdirList, xdgdirs, ":"); 1320 tokenize(xdgdirList, xdgdirs, ":");
1310 } 1321 }
1311 else 1322 else
1312 { 1323 {
1313 xdgdirList.clear(); 1324 xdgdirList.clear();
1314 xdgdirList.append("/etc/xdg"); 1325 xdgdirList.append("/etc/xdg");
1315 } 1326 }
1316 1327
1317 QString localXdgDir = readEnvPath("XDG_CONFIG_HOME"); 1328 QString localXdgDir = readEnvPath("XDG_CONFIG_HOME");
1318 if (!localXdgDir.isEmpty()) 1329 if (!localXdgDir.isEmpty())
1319 { 1330 {
1320 if (localXdgDir.at(localXdgDir.length()-1) != '/') 1331 if (localXdgDir.at(localXdgDir.length()-1) != '/')
1321 localXdgDir += '/'; 1332 localXdgDir += '/';
1322 } 1333 }
1323 else 1334 else
1324 { 1335 {
1325//US if (getuid()) 1336//US if (getuid())
1326 if (true) 1337 if (true)
1327 { 1338 {
1328 localXdgDir = QDir::homeDirPath() + "/.config/"; 1339 localXdgDir = QDir::homeDirPath() + "/.config/";
1329 } 1340 }
1330 else 1341 else
1331 { 1342 {
1332//US struct passwd *pw = getpwuid(0); 1343//US struct passwd *pw = getpwuid(0);
1333//US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.config/"; 1344//US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.config/";
1334 qDebug("KStandardDirs::addKDEDefaults: 2 has to be fixed"); 1345 qDebug("KStandardDirs::addKDEDefaults: 2 has to be fixed");
1335 } 1346 }
1336 } 1347 }
1337 1348
1338 localXdgDir = KShell::tildeExpand(localXdgDir); 1349 localXdgDir = KShell::tildeExpand(localXdgDir);
1339 addXdgConfigPrefix(localXdgDir); 1350 addXdgConfigPrefix(localXdgDir);
1340 1351
1341 for (QStringList::ConstIterator it = xdgdirList.begin(); 1352 for (QStringList::ConstIterator it = xdgdirList.begin();
1342 it != xdgdirList.end(); it++) 1353 it != xdgdirList.end(); it++)
1343 { 1354 {
1344 QString dir = KShell::tildeExpand(*it); 1355 QString dir = KShell::tildeExpand(*it);
1345 addXdgConfigPrefix(dir); 1356 addXdgConfigPrefix(dir);
1346 } 1357 }
1347 // end XDG_CONFIG_XXX 1358 // end XDG_CONFIG_XXX
1348 1359
1349 // begin XDG_DATA_XXX 1360 // begin XDG_DATA_XXX
1350 xdgdirs = readEnvPath("XDG_DATA_DIRS"); 1361 xdgdirs = readEnvPath("XDG_DATA_DIRS");
1351 if (!xdgdirs.isEmpty()) 1362 if (!xdgdirs.isEmpty())
1352 { 1363 {
1353 tokenize(xdgdirList, xdgdirs, ":"); 1364 tokenize(xdgdirList, xdgdirs, ":");
1354 } 1365 }
1355 else 1366 else
1356 { 1367 {
1357 xdgdirList.clear(); 1368 xdgdirList.clear();
1358 for (QStringList::ConstIterator it = kdedirList.begin(); 1369 for (QStringList::ConstIterator it = kdedirList.begin();
1359 it != kdedirList.end(); it++) 1370 it != kdedirList.end(); it++)
1360 { 1371 {
1361 QString dir = *it; 1372 QString dir = *it;
1362 if (dir.at(dir.length()-1) != '/') 1373 if (dir.at(dir.length()-1) != '/')
1363 dir += '/'; 1374 dir += '/';
1364 xdgdirList.append(dir+"share/"); 1375 xdgdirList.append(dir+"share/");
1365 } 1376 }
1366 1377
1367 xdgdirList.append("/usr/local/share/"); 1378 xdgdirList.append("/usr/local/share/");
1368 xdgdirList.append("/usr/share/"); 1379 xdgdirList.append("/usr/share/");
1369 } 1380 }
1370 1381
1371 localXdgDir = readEnvPath("XDG_DATA_HOME"); 1382 localXdgDir = readEnvPath("XDG_DATA_HOME");
1372 if (!localXdgDir.isEmpty()) 1383 if (!localXdgDir.isEmpty())
1373 { 1384 {
1374 if (localXdgDir.at(localXdgDir.length()-1) != '/') 1385 if (localXdgDir.at(localXdgDir.length()-1) != '/')
1375 localXdgDir += '/'; 1386 localXdgDir += '/';
1376 } 1387 }
1377 else 1388 else
1378 { 1389 {
1379//US if (getuid()) 1390//US if (getuid())
1380 if (true) 1391 if (true)
1381 { 1392 {
1382 localXdgDir = QDir::homeDirPath() + "/.local/share/"; 1393 localXdgDir = QDir::homeDirPath() + "/.local/share/";
1383 } 1394 }
1384 else 1395 else
1385 { 1396 {
1386//US struct passwd *pw = getpwuid(0); 1397//US struct passwd *pw = getpwuid(0);
1387//US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.local/share/"; 1398//US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.local/share/";
1388 qDebug("KStandardDirs::addKDEDefaults: 3 has to be fixed"); 1399 qDebug("KStandardDirs::addKDEDefaults: 3 has to be fixed");
1389 } 1400 }
1390 } 1401 }
1391 1402
1392 localXdgDir = KShell::tildeExpand(localXdgDir); 1403 localXdgDir = KShell::tildeExpand(localXdgDir);
1393 addXdgDataPrefix(localXdgDir); 1404 addXdgDataPrefix(localXdgDir);
1394 1405
1395 for (QStringList::ConstIterator it = xdgdirList.begin(); 1406 for (QStringList::ConstIterator it = xdgdirList.begin();
1396 it != xdgdirList.end(); it++) 1407 it != xdgdirList.end(); it++)
1397 { 1408 {
1398 QString dir = KShell::tildeExpand(*it); 1409 QString dir = KShell::tildeExpand(*it);
1399 1410
1400 addXdgDataPrefix(dir); 1411 addXdgDataPrefix(dir);
1401 } 1412 }
1402 // end XDG_DATA_XXX 1413 // end XDG_DATA_XXX
1403 1414
1404 1415
1405 uint index = 0; 1416 uint index = 0;
1406 while (types[index] != 0) { 1417 while (types[index] != 0) {
1407 addResourceType(types[index], kde_default(types[index])); 1418 addResourceType(types[index], kde_default(types[index]));
1408 index++; 1419 index++;
1409 } 1420 }
1410 1421
1411 addResourceDir("home", QDir::homeDirPath()); 1422 addResourceDir("home", QDir::homeDirPath());
1412} 1423}
1413 1424
1414void KStandardDirs::checkConfig() const 1425void KStandardDirs::checkConfig() const
1415{ 1426{
1416/*US 1427/*US
1417 if (!addedCustoms && KGlobal::_instance && KGlobal::_instance->_config) 1428 if (!addedCustoms && KGlobal::_instance && KGlobal::_instance->_config)
1418 const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::_instance->_config); 1429 const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::_instance->_config);
1419*/ 1430*/
1420 if (!addedCustoms && KGlobal::config()) 1431 if (!addedCustoms && KGlobal::config())
1421 const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::config()); 1432 const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::config());
1422} 1433}
1423 1434
1424bool KStandardDirs::addCustomized(KConfig *config) 1435bool KStandardDirs::addCustomized(KConfig *config)
1425{ 1436{
1426 if (addedCustoms) // there are already customized entries 1437 if (addedCustoms) // there are already customized entries
1427 return false; // we just quite and hope they are the right ones 1438 return false; // we just quite and hope they are the right ones
1428 1439
1429 // save the numbers of config directories. If this changes, 1440 // save the numbers of config directories. If this changes,
1430 // we will return true to give KConfig a chance to reparse 1441 // we will return true to give KConfig a chance to reparse
1431 uint configdirs = resourceDirs("config").count(); 1442 uint configdirs = resourceDirs("config").count();
1432 1443
1433 // reading the prefixes in 1444 // reading the prefixes in
1434 QString oldGroup = config->group(); 1445 QString oldGroup = config->group();
1435 config->setGroup("Directories"); 1446 config->setGroup("Directories");
1436 1447
1437 QStringList list; 1448 QStringList list;
1438 QStringList::ConstIterator it; 1449 QStringList::ConstIterator it;
1439 list = config->readListEntry("prefixes"); 1450 list = config->readListEntry("prefixes");
1440 for (it = list.begin(); it != list.end(); it++) 1451 for (it = list.begin(); it != list.end(); it++)
1441 addPrefix(*it); 1452 addPrefix(*it);
1442 1453
1443 // iterating over all entries in the group Directories 1454 // iterating over all entries in the group Directories
1444 // to find entries that start with dir_$type 1455 // to find entries that start with dir_$type
1445/*US 1456/*US
1446 QMap<QString, QString> entries = config->entryMap("Directories"); 1457 QMap<QString, QString> entries = config->entryMap("Directories");
1447 1458
1448 QMap<QString, QString>::ConstIterator it2; 1459 QMap<QString, QString>::ConstIterator it2;
1449 for (it2 = entries.begin(); it2 != entries.end(); it2++) 1460 for (it2 = entries.begin(); it2 != entries.end(); it2++)
1450 { 1461 {
1451 QString key = it2.key(); 1462 QString key = it2.key();
1452 if (key.left(4) == "dir_") { 1463 if (key.left(4) == "dir_") {
1453 // generate directory list, there may be more than 1. 1464 // generate directory list, there may be more than 1.
1454 QStringList dirs = QStringList::split(',', *it2); 1465 QStringList dirs = QStringList::split(',', *it2);
1455 QStringList::Iterator sIt(dirs.begin()); 1466 QStringList::Iterator sIt(dirs.begin());
1456 QString resType = key.mid(4, key.length()); 1467 QString resType = key.mid(4, key.length());
1457 for (; sIt != dirs.end(); ++sIt) { 1468 for (; sIt != dirs.end(); ++sIt) {
1458 addResourceDir(resType.latin1(), *sIt); 1469 addResourceDir(resType.latin1(), *sIt);
1459 } 1470 }
1460 } 1471 }
1461 } 1472 }
1462 1473
1463 // Process KIOSK restrictions. 1474 // Process KIOSK restrictions.
1464 config->setGroup("KDE Resource Restrictions"); 1475 config->setGroup("KDE Resource Restrictions");
1465 entries = config->entryMap("KDE Resource Restrictions"); 1476 entries = config->entryMap("KDE Resource Restrictions");
1466 for (it2 = entries.begin(); it2 != entries.end(); it2++) 1477 for (it2 = entries.begin(); it2 != entries.end(); it2++)
1467 { 1478 {
1468 QString key = it2.key(); 1479 QString key = it2.key();
1469 if (!config->readBoolEntry(key, true)) 1480 if (!config->readBoolEntry(key, true))
1470 { 1481 {
1471 d->restrictionsActive = true; 1482 d->restrictionsActive = true;
1472 d->restrictions.insert(key.latin1(), &d->restrictionsActive); // Anything will do 1483 d->restrictions.insert(key.latin1(), &d->restrictionsActive); // Anything will do
1473 dircache.remove(key.latin1()); 1484 dircache.remove(key.latin1());
1474 } 1485 }
1475 } 1486 }
1476*/ 1487*/
1477 // save it for future calls - that will return 1488 // save it for future calls - that will return
1478 addedCustoms = true; 1489 addedCustoms = true;
1479 config->setGroup(oldGroup); 1490 config->setGroup(oldGroup);
1480 1491
1481 // return true if the number of config dirs changed 1492 // return true if the number of config dirs changed
1482 return (resourceDirs("config").count() != configdirs); 1493 return (resourceDirs("config").count() != configdirs);
1483} 1494}
1484 1495
1485QString KStandardDirs::localkdedir() const 1496QString KStandardDirs::localkdedir() const
1486{ 1497{
1487 // Return the prefix to use for saving 1498 // Return the prefix to use for saving
1488 return prefixes.first(); 1499 return prefixes.first();
1489} 1500}
1490 1501
1491QString KStandardDirs::localxdgdatadir() const 1502QString KStandardDirs::localxdgdatadir() const
1492{ 1503{
1493 // Return the prefix to use for saving 1504 // Return the prefix to use for saving
1494 return d->xdgdata_prefixes.first(); 1505 return d->xdgdata_prefixes.first();
1495} 1506}
1496 1507
1497QString KStandardDirs::localxdgconfdir() const 1508QString KStandardDirs::localxdgconfdir() const
1498{ 1509{
1499 // Return the prefix to use for saving 1510 // Return the prefix to use for saving
1500 return d->xdgconf_prefixes.first(); 1511 return d->xdgconf_prefixes.first();
1501} 1512}
1502 1513
1503void KStandardDirs::setAppDir( const QString &appDir ) 1514void KStandardDirs::setAppDir( const QString &appDir )
1504{ 1515{
1505 mAppDir = appDir; 1516 mAppDir = appDir;
1506 1517
1507 if ( mAppDir.right( 1 ) != "/" ) 1518 if ( mAppDir.right( 1 ) != "/" )
1508 mAppDir += "/"; 1519 mAppDir += "/";
1509} 1520}
1510 1521
1511QString KStandardDirs::appDir() 1522QString KStandardDirs::appDir()
1512{ 1523{
1513 return mAppDir; 1524 return mAppDir;
1514} 1525}
1515 1526
1516// just to make code more readable without macros 1527// just to make code more readable without macros
1517QString locate( const char *type, 1528QString locate( const char *type,
1518 const QString& filename/*US , const KInstance* inst*/ ) 1529 const QString& filename/*US , const KInstance* inst*/ )
1519{ 1530{
1520//US return inst->dirs()->findResource(type, filename); 1531//US return inst->dirs()->findResource(type, filename);
1521 return KGlobal::dirs()->findResource(type, filename); 1532 return KGlobal::dirs()->findResource(type, filename);
1522} 1533}
1523 1534
1524QString locateLocal( const char *type, 1535QString locateLocal( const char *type,
1525 const QString& filename/*US , const KInstance* inst*/ ) 1536 const QString& filename/*US , const KInstance* inst*/ )
1526{ 1537{
1527 1538
1528 QString path = locateLocal(type, filename, true /*US, inst*/); 1539 QString path = locateLocal(type, filename, true /*US, inst*/);
1529 1540
1530 1541
1531/* 1542/*
1532 static int ccc = 0; 1543 static int ccc = 0;
1533 ++ccc; 1544 ++ccc;
1534 if ( ccc > 13 ) 1545 if ( ccc > 13 )
1535 abort(); 1546 abort();
1536*/ 1547*/
1537 qDebug("locatelocal: %s" , path.latin1()); 1548 qDebug("locatelocal: %s" , path.latin1());
1538 return path; 1549 return path;
1539 1550
1540/*US why do we put all files into one directory. It is quit complicated. 1551/*US why do we put all files into one directory. It is quit complicated.
1541why not staying with the original directorystructure ? 1552why not staying with the original directorystructure ?
1542 1553
1543 1554
1544 QString escapedFilename = filename; 1555 QString escapedFilename = filename;
1545 escapedFilename.replace( QRegExp( "/" ), "_" ); 1556 escapedFilename.replace( QRegExp( "/" ), "_" );
1546 1557
1547 QString path = KStandardDirs::appDir() + type + "_" + escapedFilename; 1558 QString path = KStandardDirs::appDir() + type + "_" + escapedFilename;
1548 1559
1549 kdDebug() << "locate: '" << path << "'" << endl; 1560 kdDebug() << "locate: '" << path << "'" << endl;
1550 qDebug("locate: %s" , path.latin1()); 1561 qDebug("locate: %s" , path.latin1());
1551 return path; 1562 return path;
1552*/ 1563*/
1553//US so my proposal is this: 1564//US so my proposal is this:
1554 1565
1555// QString escapedFilename = filename; 1566// QString escapedFilename = filename;
1556// escapedFilename.replace( QRegExp( "/" ), "_" ); 1567// escapedFilename.replace( QRegExp( "/" ), "_" );
1557 1568
1558#if 0 1569#if 0
1559#ifdef _WIN32_ 1570#ifdef _WIN32_
1560 QString path = QDir::convertSeparators(KStandardDirs::appDir() + type + "/" + filename); 1571 QString path = QDir::convertSeparators(KStandardDirs::appDir() + type + "/" + filename);
1561#else 1572#else
1562 QString path = KStandardDirs::appDir() + type + "/" + filename; 1573 QString path = KStandardDirs::appDir() + type + "/" + filename;
1563#endif 1574#endif
1564 1575
1565 //US Create the containing dir if needed 1576 //US Create the containing dir if needed
1566 QFileInfo fi ( path ); 1577 QFileInfo fi ( path );
1567 1578
1568 // QString dir=pathurl.directory(); 1579 // QString dir=pathurl.directory();
1569 //QMessageBox::information( 0,"path", path, 1 ); 1580 //QMessageBox::information( 0,"path", path, 1 );
1570 1581
1571#ifdef _WIN32_ 1582#ifdef _WIN32_
1572 KStandardDirs::makeDir(path); 1583 KStandardDirs::makeDir(path);
1573#else 1584#else
1574 KStandardDirs::makeDir(fi.dirPath( true )); 1585 KStandardDirs::makeDir(fi.dirPath( true ));
1575#endif 1586#endif
1576 1587
1577 qDebug("locate22: %s" , path.latin1()); 1588 qDebug("locate22: %s" , path.latin1());
1578 return path; 1589 return path;
1579 1590
1580#endif 1591#endif
1581 1592
1582} 1593}
1583 1594
1584QString locateLocal( const char *type, 1595QString locateLocal( const char *type,
1585 const QString& filename, bool createDir/*US , const KInstance* inst*/ ) 1596 const QString& filename, bool createDir/*US , const KInstance* inst*/ )
1586{ 1597{
1587 // try to find slashes. If there are some, we have to 1598 // try to find slashes. If there are some, we have to
1588 // create the subdir first 1599 // create the subdir first
1589 int slash = filename.findRev('/')+1; 1600 int slash = filename.findRev('/')+1;
1590 if (!slash) // only one filename 1601 if (!slash) // only one filename
1591 //USreturn inst->dirs()->saveLocation(type, QString::null, createDir) + filename; 1602 //USreturn inst->dirs()->saveLocation(type, QString::null, createDir) + filename;
1592 return KGlobal::dirs()->saveLocation(type, QString::null, createDir) + filename; 1603 return KGlobal::dirs()->saveLocation(type, QString::null, createDir) + filename;
1593 1604
1594 // split path from filename 1605 // split path from filename
1595 QString dir = filename.left(slash); 1606 QString dir = filename.left(slash);
1596 QString file = filename.mid(slash); 1607 QString file = filename.mid(slash);
1597//US return inst->dirs()->saveLocation(type, dir, createDir) + file; 1608//US return inst->dirs()->saveLocation(type, dir, createDir) + file;
1598 return KGlobal::dirs()->saveLocation(type, dir, createDir) + file; 1609 return KGlobal::dirs()->saveLocation(type, dir, createDir) + file;
1599 1610
1600 // *************************************************************** 1611 // ***************************************************************
1601#if 0 1612#if 0
1602 1613
1603/*US why do we put all files into one directory. It is quit complicated. 1614/*US why do we put all files into one directory. It is quit complicated.
1604why not staying with the original directorystructure ? 1615why not staying with the original directorystructure ?
1605 1616
1606 1617
1607 QString escapedFilename = filename; 1618 QString escapedFilename = filename;
1608 escapedFilename.replace( QRegExp( "/" ), "_" ); 1619 escapedFilename.replace( QRegExp( "/" ), "_" );
1609 1620
1610 QString path = KStandardDirs::appDir() + type + "_" + escapedFilename; 1621 QString path = KStandardDirs::appDir() + type + "_" + escapedFilename;
1611 1622
1612 kdDebug() << "locate: '" << path << "'" << endl; 1623 kdDebug() << "locate: '" << path << "'" << endl;
1613 qDebug("locate: %s" , path.latin1()); 1624 qDebug("locate: %s" , path.latin1());
1614 return path; 1625 return path;
1615*/ 1626*/
1616//US so my proposal is this: 1627//US so my proposal is this:
1617 1628
1618// QString escapedFilename = filename; 1629// QString escapedFilename = filename;
1619// escapedFilename.replace( QRegExp( "/" ), "_" ); 1630// escapedFilename.replace( QRegExp( "/" ), "_" );
1620 1631
1621#ifdef _WIN32_ 1632#ifdef _WIN32_
1622 QString path = QDir::convertSeparators(KStandardDirs::appDir() + type + "/" + filename); 1633 QString path = QDir::convertSeparators(KStandardDirs::appDir() + type + "/" + filename);
1623#else 1634#else
1624 QString path = KStandardDirs::appDir() + type + "/" + filename; 1635 QString path = KStandardDirs::appDir() + type + "/" + filename;
1625#endif 1636#endif
1626 1637
1627 //US Create the containing dir if needed 1638 //US Create the containing dir if needed
1628 KURL pathurl; 1639 KURL pathurl;
1629 pathurl.setPath(path); 1640 pathurl.setPath(path);
1630 QString dir=pathurl.directory(); 1641 QString dir=pathurl.directory();
1631 //QMessageBox::information( 0,"path", path, 1 ); 1642 //QMessageBox::information( 0,"path", path, 1 );
1632#ifdef _WIN32_ 1643#ifdef _WIN32_
1633 KStandardDirs::makeDir(path); 1644 KStandardDirs::makeDir(path);
1634#else 1645#else
1635 KStandardDirs::makeDir(dir); 1646 KStandardDirs::makeDir(dir);
1636#endif 1647#endif
1637 1648
1638 return path; 1649 return path;
1639#endif 1650#endif
1640} 1651}