-rw-r--r-- | microkde/kdecore/kstandarddirs.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/microkde/kdecore/kstandarddirs.cpp b/microkde/kdecore/kstandarddirs.cpp index 75205d6..500426b 100644 --- a/microkde/kdecore/kstandarddirs.cpp +++ b/microkde/kdecore/kstandarddirs.cpp | |||
@@ -1,1637 +1,1640 @@ | |||
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 |
58 | QString KStandardDirs::mAppDir = QString::null; | 58 | QString KStandardDirs::mAppDir = QString::null; |
59 | 59 | ||
60 | 60 | ||
61 | template class QDict<QStringList>; | 61 | template class QDict<QStringList>; |
62 | 62 | ||
63 | #if 0 | 63 | #if 0 |
64 | #include <qtextedit.h> | 64 | #include <qtextedit.h> |
65 | void ddd( QString op ) | 65 | void 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 |
77 | class KStandardDirs::KStandardDirsPrivate | 77 | class KStandardDirs::KStandardDirsPrivate |
78 | { | 78 | { |
79 | public: | 79 | public: |
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 | ||
92 | static const char* const types[] = {"html", "icon", "apps", "sound", | 92 | static 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 | ||
99 | static int tokenize( QStringList& token, const QString& str, | 99 | static int tokenize( QStringList& token, const QString& str, |
100 | const QString& delim ); | 100 | const QString& delim ); |
101 | 101 | ||
102 | KStandardDirs::KStandardDirs( ) : addedCustoms(false) | 102 | KStandardDirs::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 | ||
112 | KStandardDirs::~KStandardDirs() | 112 | KStandardDirs::~KStandardDirs() |
113 | { | 113 | { |
114 | delete d; | 114 | delete d; |
115 | } | 115 | } |
116 | 116 | ||
117 | bool KStandardDirs::isRestrictedResource(const char *type, const QString& relPath) const | 117 | bool 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 | ||
137 | void KStandardDirs::applyDataRestrictions(const QString &relPath) const | 137 | void 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 | ||
151 | QStringList KStandardDirs::allTypes() const | 151 | QStringList 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 | ||
159 | void KStandardDirs::addPrefix( const QString& _dir ) | 159 | void 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 | ||
174 | void KStandardDirs::addXdgConfigPrefix( const QString& _dir ) | 174 | void 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 | ||
189 | void KStandardDirs::addXdgDataPrefix( const QString& _dir ) | 189 | void 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 | ||
205 | QString KStandardDirs::kfsstnd_prefixes() | 205 | QString KStandardDirs::kfsstnd_prefixes() |
206 | { | 206 | { |
207 | return prefixes.join(":"); | 207 | return prefixes.join(":"); |
208 | } | 208 | } |
209 | 209 | ||
210 | bool KStandardDirs::addResourceType( const char *type, | 210 | bool 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 | ||
232 | bool KStandardDirs::addResourceDir( const char *type, | 232 | bool 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 | ||
252 | QString KStandardDirs::findResource( const char *type, | 252 | QString 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 |
259 | kdDebug() << "Find resource: " << type << endl; | 259 | kdDebug() << "Find resource: " << type << endl; |
260 | for (QStringList::ConstIterator pit = prefixes.begin(); | 260 | for (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 |
274 | static Q_UINT32 updateHash(const QString &file, Q_UINT32 hash) | 274 | static 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 |
292 | Q_UINT32 KStandardDirs::calcResourceHash( const char *type, | 292 | Q_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 | ||
318 | QStringList KStandardDirs::findDirs( const char *type, | 318 | QStringList 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 | ||
340 | QString KStandardDirs::findResourceDir( const char *type, | 340 | QString 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 | ||
377 | bool KStandardDirs::exists(const QString &fullPath) | 377 | bool 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 | ||
399 | static void lookupDirectory(const QString& path, const QString &relPart, | 399 | static void lookupDirectory(const QString& path, const QString &relPart, |
400 | const QRegExp ®exp, | 400 | const QRegExp ®exp, |
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 | ||
526 | static void lookupPrefix(const QString& prefix, const QString& relpath, | 526 | static void lookupPrefix(const QString& prefix, const QString& relpath, |
527 | const QString& relPart, | 527 | const QString& relPart, |
528 | const QRegExp ®exp, | 528 | const QRegExp ®exp, |
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 | ||
619 | QStringList | 619 | QStringList |
620 | KStandardDirs::findAllResources( const char *type, | 620 | KStandardDirs::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 | ||
664 | QStringList | 664 | QStringList |
665 | KStandardDirs::findAllResources( const char *type, | 665 | KStandardDirs::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 | ||
674 | QString | 674 | QString |
675 | KStandardDirs::realPath(const QString &dirname) | 675 | KStandardDirs::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 |
698 | void KStandardDirs::createSpecialResource(const char *type) | 698 | void 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 | ||
730 | QStringList KStandardDirs::resourceDirs(const char *type) const | 730 | QStringList 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 |
819 | QString KStandardDirs::findExe( const QString& appname, | 819 | QString 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 | ||
892 | int KStandardDirs::findAllExe( QStringList& list, const QString& appname, | 892 | int 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 | ||
924 | static int tokenize( QStringList& tokens, const QString& str, | 924 | static 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 | ||
950 | QString KStandardDirs::kde_default(const char *type) { | 950 | QString 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")) | ||
994 | return "tmp/"; | ||
995 | |||
993 | qFatal("unknown resource type %s", type); | 996 | qFatal("unknown resource type %s", type); |
994 | return QString::null; | 997 | return QString::null; |
995 | } | 998 | } |
996 | 999 | ||
997 | QString KStandardDirs::saveLocation(const char *type, | 1000 | QString KStandardDirs::saveLocation(const char *type, |
998 | const QString& suffix, | 1001 | const QString& suffix, |
999 | bool create) const | 1002 | bool create) const |
1000 | { | 1003 | { |
1001 | //qDebug("KStandardDirs::saveLocation called %s %s", type,suffix.latin1() ); | 1004 | //qDebug("KStandardDirs::saveLocation called %s %s", type,suffix.latin1() ); |
1002 | //return ""; | 1005 | //return ""; |
1003 | checkConfig(); | 1006 | checkConfig(); |
1004 | 1007 | ||
1005 | QString *pPath = savelocations.find(type); | 1008 | QString *pPath = savelocations.find(type); |
1006 | if (!pPath) | 1009 | if (!pPath) |
1007 | { | 1010 | { |
1008 | QStringList *dirs = relatives.find(type); | 1011 | QStringList *dirs = relatives.find(type); |
1009 | if (!dirs && ( | 1012 | if (!dirs && ( |
1010 | (strcmp(type, "socket") == 0) || | 1013 | (strcmp(type, "socket") == 0) || |
1011 | (strcmp(type, "tmp") == 0) || | 1014 | (strcmp(type, "tmp") == 0) || |
1012 | (strcmp(type, "cache") == 0) )) | 1015 | (strcmp(type, "cache") == 0) )) |
1013 | { | 1016 | { |
1014 | (void) resourceDirs(type); // Generate socket|tmp|cache resource. | 1017 | (void) resourceDirs(type); // Generate socket|tmp|cache resource. |
1015 | dirs = relatives.find(type); // Search again. | 1018 | dirs = relatives.find(type); // Search again. |
1016 | } | 1019 | } |
1017 | if (dirs) | 1020 | if (dirs) |
1018 | { | 1021 | { |
1019 | // Check for existance of typed directory + suffix | 1022 | // Check for existance of typed directory + suffix |
1020 | if (strncmp(type, "xdgdata-", 8) == 0) | 1023 | if (strncmp(type, "xdgdata-", 8) == 0) |
1021 | pPath = new QString(realPath(localxdgdatadir() + dirs->last())); | 1024 | pPath = new QString(realPath(localxdgdatadir() + dirs->last())); |
1022 | else if (strncmp(type, "xdgconf-", 8) == 0) | 1025 | else if (strncmp(type, "xdgconf-", 8) == 0) |
1023 | pPath = new QString(realPath(localxdgconfdir() + dirs->last())); | 1026 | pPath = new QString(realPath(localxdgconfdir() + dirs->last())); |
1024 | else | 1027 | else |
1025 | pPath = new QString(realPath(localkdedir() + dirs->last())); | 1028 | pPath = new QString(realPath(localkdedir() + dirs->last())); |
1026 | } | 1029 | } |
1027 | else { | 1030 | else { |
1028 | dirs = absolutes.find(type); | 1031 | dirs = absolutes.find(type); |
1029 | if (!dirs) | 1032 | if (!dirs) |
1030 | qFatal("KStandardDirs: The resource type %s is not registered", type); | 1033 | qFatal("KStandardDirs: The resource type %s is not registered", type); |
1031 | pPath = new QString(realPath(dirs->last())); | 1034 | pPath = new QString(realPath(dirs->last())); |
1032 | } | 1035 | } |
1033 | 1036 | ||
1034 | savelocations.insert(type, pPath); | 1037 | savelocations.insert(type, pPath); |
1035 | } | 1038 | } |
1036 | 1039 | ||
1037 | QString fullPath = *pPath + suffix; | 1040 | QString fullPath = *pPath + suffix; |
1038 | //US struct stat st; | 1041 | //US struct stat st; |
1039 | //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))) |
1040 | QFileInfo fullPathInfo(QFile::encodeName(fullPath)); | 1043 | QFileInfo fullPathInfo(QFile::encodeName(fullPath)); |
1041 | if (fullPathInfo.isReadable() || !fullPathInfo.isDir()) | 1044 | if (fullPathInfo.isReadable() || !fullPathInfo.isDir()) |
1042 | 1045 | ||
1043 | 1046 | ||
1044 | { | 1047 | { |
1045 | if(!create) { | 1048 | if(!create) { |
1046 | #ifndef NDEBUG | 1049 | #ifndef NDEBUG |
1047 | qDebug("save location %s doesn't exist", fullPath.latin1()); | 1050 | qDebug("save location %s doesn't exist", fullPath.latin1()); |
1048 | #endif | 1051 | #endif |
1049 | return fullPath; | 1052 | return fullPath; |
1050 | } | 1053 | } |
1051 | if(!makeDir(fullPath, 0700)) { | 1054 | if(!makeDir(fullPath, 0700)) { |
1052 | qWarning("failed to create %s", fullPath.latin1()); | 1055 | qWarning("failed to create %s", fullPath.latin1()); |
1053 | return fullPath; | 1056 | return fullPath; |
1054 | } | 1057 | } |
1055 | dircache.remove(type); | 1058 | dircache.remove(type); |
1056 | } | 1059 | } |
1057 | return fullPath; | 1060 | return fullPath; |
1058 | } | 1061 | } |
1059 | 1062 | ||
1060 | QString KStandardDirs::relativeLocation(const char *type, const QString &absPath) | 1063 | QString KStandardDirs::relativeLocation(const char *type, const QString &absPath) |
1061 | { | 1064 | { |
1062 | QString fullPath = absPath; | 1065 | QString fullPath = absPath; |
1063 | int i = absPath.findRev('/'); | 1066 | int i = absPath.findRev('/'); |
1064 | if (i != -1) | 1067 | if (i != -1) |
1065 | { | 1068 | { |
1066 | fullPath = realPath(absPath.left(i+1))+absPath.mid(i+1); // Normalize | 1069 | fullPath = realPath(absPath.left(i+1))+absPath.mid(i+1); // Normalize |
1067 | } | 1070 | } |
1068 | 1071 | ||
1069 | QStringList candidates = resourceDirs(type); | 1072 | QStringList candidates = resourceDirs(type); |
1070 | 1073 | ||
1071 | for (QStringList::ConstIterator it = candidates.begin(); | 1074 | for (QStringList::ConstIterator it = candidates.begin(); |
1072 | it != candidates.end(); it++) | 1075 | it != candidates.end(); it++) |
1073 | if (fullPath.startsWith(*it)) | 1076 | if (fullPath.startsWith(*it)) |
1074 | { | 1077 | { |
1075 | return fullPath.mid((*it).length()); | 1078 | return fullPath.mid((*it).length()); |
1076 | } | 1079 | } |
1077 | 1080 | ||
1078 | return absPath; | 1081 | return absPath; |
1079 | } | 1082 | } |
1080 | 1083 | ||
1081 | 1084 | ||
1082 | bool KStandardDirs::makeDir(const QString& dir2, int mode) | 1085 | bool KStandardDirs::makeDir(const QString& dir2, int mode) |
1083 | { | 1086 | { |
1084 | QString dir = QDir::convertSeparators( dir2 ); | 1087 | QString dir = QDir::convertSeparators( dir2 ); |
1085 | #if 0 | 1088 | #if 0 |
1086 | //LR | 1089 | //LR |
1087 | 1090 | ||
1088 | // we want an absolute path | 1091 | // we want an absolute path |
1089 | if (dir.at(0) != '/') | 1092 | if (dir.at(0) != '/') |
1090 | return false; | 1093 | return false; |
1091 | 1094 | ||
1092 | QString target = dir; | 1095 | QString target = dir; |
1093 | uint len = target.length(); | 1096 | uint len = target.length(); |
1094 | 1097 | ||
1095 | // append trailing slash if missing | 1098 | // append trailing slash if missing |
1096 | if (dir.at(len - 1) != '/') | 1099 | if (dir.at(len - 1) != '/') |
1097 | target += '/'; | 1100 | target += '/'; |
1098 | 1101 | ||
1099 | QString base(""); | 1102 | QString base(""); |
1100 | uint i = 1; | 1103 | uint i = 1; |
1101 | 1104 | ||
1102 | while( i < len ) | 1105 | while( i < len ) |
1103 | { | 1106 | { |
1104 | //US struct stat st; | 1107 | //US struct stat st; |
1105 | int pos = target.find('/', i); | 1108 | int pos = target.find('/', i); |
1106 | base += target.mid(i - 1, pos - i + 1); | 1109 | base += target.mid(i - 1, pos - i + 1); |
1107 | QCString baseEncoded = QFile::encodeName(base); | 1110 | QCString baseEncoded = QFile::encodeName(base); |
1108 | // bail out if we encountered a problem | 1111 | // bail out if we encountered a problem |
1109 | //US if (stat(baseEncoded, &st) != 0) | 1112 | //US if (stat(baseEncoded, &st) != 0) |
1110 | QFileInfo baseEncodedInfo(baseEncoded); | 1113 | QFileInfo baseEncodedInfo(baseEncoded); |
1111 | if (!baseEncodedInfo.exists()) | 1114 | if (!baseEncodedInfo.exists()) |
1112 | { | 1115 | { |
1113 | // Directory does not exist.... | 1116 | // Directory does not exist.... |
1114 | // Or maybe a dangling symlink ? | 1117 | // Or maybe a dangling symlink ? |
1115 | //US if (lstat(baseEncoded, &st) == 0) | 1118 | //US if (lstat(baseEncoded, &st) == 0) |
1116 | if (baseEncodedInfo.isSymLink()) { | 1119 | if (baseEncodedInfo.isSymLink()) { |
1117 | //US (void)unlink(baseEncoded); // try removing | 1120 | //US (void)unlink(baseEncoded); // try removing |
1118 | QFile(baseEncoded).remove(); | 1121 | QFile(baseEncoded).remove(); |
1119 | } | 1122 | } |
1120 | 1123 | ||
1121 | //US if ( mkdir(baseEncoded, (mode_t) mode) != 0) | 1124 | //US if ( mkdir(baseEncoded, (mode_t) mode) != 0) |
1122 | QDir dirObj; | 1125 | QDir dirObj; |
1123 | if ( dirObj.mkdir(baseEncoded) != true ) | 1126 | if ( dirObj.mkdir(baseEncoded) != true ) |
1124 | { | 1127 | { |
1125 | //US perror("trying to create local folder"); | 1128 | //US perror("trying to create local folder"); |
1126 | return false; // Couldn't create it :-( | 1129 | return false; // Couldn't create it :-( |
1127 | } | 1130 | } |
1128 | } | 1131 | } |
1129 | i = pos + 1; | 1132 | i = pos + 1; |
1130 | } | 1133 | } |
1131 | return true; | 1134 | return true; |
1132 | #endif | 1135 | #endif |
1133 | 1136 | ||
1134 | // ******************************************** | 1137 | // ******************************************** |
1135 | // new code for WIN32 | 1138 | // new code for WIN32 |
1136 | QDir dirObj; | 1139 | QDir dirObj; |
1137 | 1140 | ||
1138 | 1141 | ||
1139 | // we want an absolute path | 1142 | // we want an absolute path |
1140 | #ifndef _WIN32_ | 1143 | #ifndef _WIN32_ |
1141 | if (dir.at(0) != '/') | 1144 | if (dir.at(0) != '/') |
1142 | return false; | 1145 | return false; |
1143 | #endif | 1146 | #endif |
1144 | 1147 | ||
1145 | QString target = dir; | 1148 | QString target = dir; |
1146 | uint len = target.length(); | 1149 | uint len = target.length(); |
1147 | #ifndef _WIN32_ | 1150 | #ifndef _WIN32_ |
1148 | // append trailing slash if missing | 1151 | // append trailing slash if missing |
1149 | if (dir.at(len - 1) != '/') | 1152 | if (dir.at(len - 1) != '/') |
1150 | target += '/'; | 1153 | target += '/'; |
1151 | #endif | 1154 | #endif |
1152 | 1155 | ||
1153 | QString base(""); | 1156 | QString base(""); |
1154 | uint i = 1; | 1157 | uint i = 1; |
1155 | 1158 | ||
1156 | while( i < len ) | 1159 | while( i < len ) |
1157 | { | 1160 | { |
1158 | //US struct stat st; | 1161 | //US struct stat st; |
1159 | #ifndef _WIN32_ | 1162 | #ifndef _WIN32_ |
1160 | int pos = target.find('/', i); | 1163 | int pos = target.find('/', i); |
1161 | #else | 1164 | #else |
1162 | int pos = target.find('\\', i); | 1165 | int pos = target.find('\\', i); |
1163 | #endif | 1166 | #endif |
1164 | if ( pos < 0 ) | 1167 | if ( pos < 0 ) |
1165 | return true; | 1168 | return true; |
1166 | base += target.mid(i - 1, pos - i + 1); | 1169 | base += target.mid(i - 1, pos - i + 1); |
1167 | //QMessageBox::information( 0,"cap111", base, 1 ); | 1170 | //QMessageBox::information( 0,"cap111", base, 1 ); |
1168 | /*US | 1171 | /*US |
1169 | QCString baseEncoded = QFile::encodeName(base); | 1172 | QCString baseEncoded = QFile::encodeName(base); |
1170 | // bail out if we encountered a problem | 1173 | // bail out if we encountered a problem |
1171 | if (stat(baseEncoded, &st) != 0) | 1174 | if (stat(baseEncoded, &st) != 0) |
1172 | { | 1175 | { |
1173 | // Directory does not exist.... | 1176 | // Directory does not exist.... |
1174 | // Or maybe a dangling symlink ? | 1177 | // Or maybe a dangling symlink ? |
1175 | if (lstat(baseEncoded, &st) == 0) | 1178 | if (lstat(baseEncoded, &st) == 0) |
1176 | (void)unlink(baseEncoded); // try removing | 1179 | (void)unlink(baseEncoded); // try removing |
1177 | 1180 | ||
1178 | 1181 | ||
1179 | if ( mkdir(baseEncoded, (mode_t) mode) != 0) { | 1182 | if ( mkdir(baseEncoded, (mode_t) mode) != 0) { |
1180 | perror("trying to create local folder"); | 1183 | perror("trying to create local folder"); |
1181 | return false; // Couldn't create it :-( | 1184 | return false; // Couldn't create it :-( |
1182 | } | 1185 | } |
1183 | } | 1186 | } |
1184 | */ | 1187 | */ |
1185 | 1188 | ||
1186 | if (dirObj.exists(base) == false) | 1189 | if (dirObj.exists(base) == false) |
1187 | { | 1190 | { |
1188 | //qDebug("KStandardDirs::makeDir try to create : %s" , base.latin1()); | 1191 | //qDebug("KStandardDirs::makeDir try to create : %s" , base.latin1()); |
1189 | if (dirObj.mkdir(base) != true) | 1192 | if (dirObj.mkdir(base) != true) |
1190 | { | 1193 | { |
1191 | qDebug("KStandardDirs::makeDir could not create: %s" , base.latin1()); | 1194 | qDebug("KStandardDirs::makeDir could not create: %s" , base.latin1()); |
1192 | return false; | 1195 | return false; |
1193 | } | 1196 | } |
1194 | } | 1197 | } |
1195 | 1198 | ||
1196 | i = pos + 1; | 1199 | i = pos + 1; |
1197 | } | 1200 | } |
1198 | return true; | 1201 | return true; |
1199 | 1202 | ||
1200 | } | 1203 | } |
1201 | 1204 | ||
1202 | static QString readEnvPath(const char *env) | 1205 | static QString readEnvPath(const char *env) |
1203 | { | 1206 | { |
1204 | #ifdef _WIN32_ | 1207 | #ifdef _WIN32_ |
1205 | return ""; | 1208 | return ""; |
1206 | #else | 1209 | #else |
1207 | QCString c_path = getenv(env); | 1210 | QCString c_path = getenv(env); |
1208 | if (c_path.isEmpty()) | 1211 | if (c_path.isEmpty()) |
1209 | return QString::null; | 1212 | return QString::null; |
1210 | return QFile::decodeName(c_path); | 1213 | return QFile::decodeName(c_path); |
1211 | #endif | 1214 | #endif |
1212 | } | 1215 | } |
1213 | 1216 | ||
1214 | void KStandardDirs::addKDEDefaults() | 1217 | void KStandardDirs::addKDEDefaults() |
1215 | { | 1218 | { |
1216 | //qDebug("ERROR: KStandardDirs::addKDEDefaults() called "); | 1219 | //qDebug("ERROR: KStandardDirs::addKDEDefaults() called "); |
1217 | //return; | 1220 | //return; |
1218 | QStringList kdedirList; | 1221 | QStringList kdedirList; |
1219 | 1222 | ||
1220 | // begin KDEDIRS | 1223 | // begin KDEDIRS |
1221 | QString kdedirs = readEnvPath("MICROKDEDIRS"); | 1224 | QString kdedirs = readEnvPath("MICROKDEDIRS"); |
1222 | if (!kdedirs.isEmpty()) | 1225 | if (!kdedirs.isEmpty()) |
1223 | { | 1226 | { |
1224 | tokenize(kdedirList, kdedirs, ":"); | 1227 | tokenize(kdedirList, kdedirs, ":"); |
1225 | } | 1228 | } |
1226 | else | 1229 | else |
1227 | { | 1230 | { |
1228 | QString kdedir = readEnvPath("MICROKDEDIR"); | 1231 | QString kdedir = readEnvPath("MICROKDEDIR"); |
1229 | if (!kdedir.isEmpty()) | 1232 | if (!kdedir.isEmpty()) |
1230 | { | 1233 | { |
1231 | kdedir = KShell::tildeExpand(kdedir); | 1234 | kdedir = KShell::tildeExpand(kdedir); |
1232 | kdedirList.append(kdedir); | 1235 | kdedirList.append(kdedir); |
1233 | } | 1236 | } |
1234 | } | 1237 | } |
1235 | //US kdedirList.append(KDEDIR); | 1238 | //US kdedirList.append(KDEDIR); |
1236 | //US for embedded, add qtopia dir as kdedir | 1239 | //US for embedded, add qtopia dir as kdedir |
1237 | 1240 | ||
1238 | #ifndef DESKTOP_VERSION | 1241 | #ifndef DESKTOP_VERSION |
1239 | kdedirList.append(readEnvPath("QPEDIR" )); | 1242 | kdedirList.append(readEnvPath("QPEDIR" )); |
1240 | #endif | 1243 | #endif |
1241 | 1244 | ||
1242 | #ifdef __KDE_EXECPREFIX | 1245 | #ifdef __KDE_EXECPREFIX |
1243 | QString execPrefix(__KDE_EXECPREFIX); | 1246 | QString execPrefix(__KDE_EXECPREFIX); |
1244 | if (execPrefix!="NONE") | 1247 | if (execPrefix!="NONE") |
1245 | kdedirList.append(execPrefix); | 1248 | kdedirList.append(execPrefix); |
1246 | #endif | 1249 | #endif |
1247 | 1250 | ||
1248 | QString localKdeDir; | 1251 | QString localKdeDir; |
1249 | 1252 | ||
1250 | //US if (getuid()) | 1253 | //US if (getuid()) |
1251 | if (true) | 1254 | if (true) |
1252 | { | 1255 | { |
1253 | localKdeDir = readEnvPath("MICROKDEHOME"); | 1256 | localKdeDir = readEnvPath("MICROKDEHOME"); |
1254 | if (!localKdeDir.isEmpty()) | 1257 | if (!localKdeDir.isEmpty()) |
1255 | { | 1258 | { |
1256 | if (localKdeDir.at(localKdeDir.length()-1) != '/') | 1259 | if (localKdeDir.at(localKdeDir.length()-1) != '/') |
1257 | localKdeDir += '/'; | 1260 | localKdeDir += '/'; |
1258 | } | 1261 | } |
1259 | else | 1262 | else |
1260 | { | 1263 | { |
1261 | localKdeDir = QDir::homeDirPath() + "/kdepim/"; | 1264 | localKdeDir = QDir::homeDirPath() + "/kdepim/"; |
1262 | } | 1265 | } |
1263 | } | 1266 | } |
1264 | else | 1267 | else |
1265 | { | 1268 | { |
1266 | // We treat root different to prevent root messing up the | 1269 | // We treat root different to prevent root messing up the |
1267 | // file permissions in the users home directory. | 1270 | // file permissions in the users home directory. |
1268 | localKdeDir = readEnvPath("MICROKDEROOTHOME"); | 1271 | localKdeDir = readEnvPath("MICROKDEROOTHOME"); |
1269 | if (!localKdeDir.isEmpty()) | 1272 | if (!localKdeDir.isEmpty()) |
1270 | { | 1273 | { |
1271 | if (localKdeDir.at(localKdeDir.length()-1) != '/') | 1274 | if (localKdeDir.at(localKdeDir.length()-1) != '/') |
1272 | localKdeDir += '/'; | 1275 | localKdeDir += '/'; |
1273 | } | 1276 | } |
1274 | else | 1277 | else |
1275 | { | 1278 | { |
1276 | //US struct passwd *pw = getpwuid(0); | 1279 | //US struct passwd *pw = getpwuid(0); |
1277 | //US localKdeDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.microkde/"; | 1280 | //US localKdeDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.microkde/"; |
1278 | qDebug("KStandardDirs::addKDEDefaults: 1 has to be fixed"); | 1281 | qDebug("KStandardDirs::addKDEDefaults: 1 has to be fixed"); |
1279 | } | 1282 | } |
1280 | 1283 | ||
1281 | } | 1284 | } |
1282 | 1285 | ||
1283 | //US localKdeDir = appDir(); | 1286 | //US localKdeDir = appDir(); |
1284 | 1287 | ||
1285 | //US | 1288 | //US |
1286 | // qDebug("KStandardDirs::addKDEDefaults: localKdeDir=%s", localKdeDir.latin1()); | 1289 | // qDebug("KStandardDirs::addKDEDefaults: localKdeDir=%s", localKdeDir.latin1()); |
1287 | if (localKdeDir != "-/") | 1290 | if (localKdeDir != "-/") |
1288 | { | 1291 | { |
1289 | localKdeDir = KShell::tildeExpand(localKdeDir); | 1292 | localKdeDir = KShell::tildeExpand(localKdeDir); |
1290 | addPrefix(localKdeDir); | 1293 | addPrefix(localKdeDir); |
1291 | } | 1294 | } |
1292 | 1295 | ||
1293 | for (QStringList::ConstIterator it = kdedirList.begin(); | 1296 | for (QStringList::ConstIterator it = kdedirList.begin(); |
1294 | it != kdedirList.end(); it++) | 1297 | it != kdedirList.end(); it++) |
1295 | { | 1298 | { |
1296 | QString dir = KShell::tildeExpand(*it); | 1299 | QString dir = KShell::tildeExpand(*it); |
1297 | addPrefix(dir); | 1300 | addPrefix(dir); |
1298 | } | 1301 | } |
1299 | // end KDEDIRS | 1302 | // end KDEDIRS |
1300 | 1303 | ||
1301 | // begin XDG_CONFIG_XXX | 1304 | // begin XDG_CONFIG_XXX |
1302 | QStringList xdgdirList; | 1305 | QStringList xdgdirList; |
1303 | QString xdgdirs = readEnvPath("XDG_CONFIG_DIRS"); | 1306 | QString xdgdirs = readEnvPath("XDG_CONFIG_DIRS"); |
1304 | if (!xdgdirs.isEmpty()) | 1307 | if (!xdgdirs.isEmpty()) |
1305 | { | 1308 | { |
1306 | tokenize(xdgdirList, xdgdirs, ":"); | 1309 | tokenize(xdgdirList, xdgdirs, ":"); |
1307 | } | 1310 | } |
1308 | else | 1311 | else |
1309 | { | 1312 | { |
1310 | xdgdirList.clear(); | 1313 | xdgdirList.clear(); |
1311 | xdgdirList.append("/etc/xdg"); | 1314 | xdgdirList.append("/etc/xdg"); |
1312 | } | 1315 | } |
1313 | 1316 | ||
1314 | QString localXdgDir = readEnvPath("XDG_CONFIG_HOME"); | 1317 | QString localXdgDir = readEnvPath("XDG_CONFIG_HOME"); |
1315 | if (!localXdgDir.isEmpty()) | 1318 | if (!localXdgDir.isEmpty()) |
1316 | { | 1319 | { |
1317 | if (localXdgDir.at(localXdgDir.length()-1) != '/') | 1320 | if (localXdgDir.at(localXdgDir.length()-1) != '/') |
1318 | localXdgDir += '/'; | 1321 | localXdgDir += '/'; |
1319 | } | 1322 | } |
1320 | else | 1323 | else |
1321 | { | 1324 | { |
1322 | //US if (getuid()) | 1325 | //US if (getuid()) |
1323 | if (true) | 1326 | if (true) |
1324 | { | 1327 | { |
1325 | localXdgDir = QDir::homeDirPath() + "/.config/"; | 1328 | localXdgDir = QDir::homeDirPath() + "/.config/"; |
1326 | } | 1329 | } |
1327 | else | 1330 | else |
1328 | { | 1331 | { |
1329 | //US struct passwd *pw = getpwuid(0); | 1332 | //US struct passwd *pw = getpwuid(0); |
1330 | //US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.config/"; | 1333 | //US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.config/"; |
1331 | qDebug("KStandardDirs::addKDEDefaults: 2 has to be fixed"); | 1334 | qDebug("KStandardDirs::addKDEDefaults: 2 has to be fixed"); |
1332 | } | 1335 | } |
1333 | } | 1336 | } |
1334 | 1337 | ||
1335 | localXdgDir = KShell::tildeExpand(localXdgDir); | 1338 | localXdgDir = KShell::tildeExpand(localXdgDir); |
1336 | addXdgConfigPrefix(localXdgDir); | 1339 | addXdgConfigPrefix(localXdgDir); |
1337 | 1340 | ||
1338 | for (QStringList::ConstIterator it = xdgdirList.begin(); | 1341 | for (QStringList::ConstIterator it = xdgdirList.begin(); |
1339 | it != xdgdirList.end(); it++) | 1342 | it != xdgdirList.end(); it++) |
1340 | { | 1343 | { |
1341 | QString dir = KShell::tildeExpand(*it); | 1344 | QString dir = KShell::tildeExpand(*it); |
1342 | addXdgConfigPrefix(dir); | 1345 | addXdgConfigPrefix(dir); |
1343 | } | 1346 | } |
1344 | // end XDG_CONFIG_XXX | 1347 | // end XDG_CONFIG_XXX |
1345 | 1348 | ||
1346 | // begin XDG_DATA_XXX | 1349 | // begin XDG_DATA_XXX |
1347 | xdgdirs = readEnvPath("XDG_DATA_DIRS"); | 1350 | xdgdirs = readEnvPath("XDG_DATA_DIRS"); |
1348 | if (!xdgdirs.isEmpty()) | 1351 | if (!xdgdirs.isEmpty()) |
1349 | { | 1352 | { |
1350 | tokenize(xdgdirList, xdgdirs, ":"); | 1353 | tokenize(xdgdirList, xdgdirs, ":"); |
1351 | } | 1354 | } |
1352 | else | 1355 | else |
1353 | { | 1356 | { |
1354 | xdgdirList.clear(); | 1357 | xdgdirList.clear(); |
1355 | for (QStringList::ConstIterator it = kdedirList.begin(); | 1358 | for (QStringList::ConstIterator it = kdedirList.begin(); |
1356 | it != kdedirList.end(); it++) | 1359 | it != kdedirList.end(); it++) |
1357 | { | 1360 | { |
1358 | QString dir = *it; | 1361 | QString dir = *it; |
1359 | if (dir.at(dir.length()-1) != '/') | 1362 | if (dir.at(dir.length()-1) != '/') |
1360 | dir += '/'; | 1363 | dir += '/'; |
1361 | xdgdirList.append(dir+"share/"); | 1364 | xdgdirList.append(dir+"share/"); |
1362 | } | 1365 | } |
1363 | 1366 | ||
1364 | xdgdirList.append("/usr/local/share/"); | 1367 | xdgdirList.append("/usr/local/share/"); |
1365 | xdgdirList.append("/usr/share/"); | 1368 | xdgdirList.append("/usr/share/"); |
1366 | } | 1369 | } |
1367 | 1370 | ||
1368 | localXdgDir = readEnvPath("XDG_DATA_HOME"); | 1371 | localXdgDir = readEnvPath("XDG_DATA_HOME"); |
1369 | if (!localXdgDir.isEmpty()) | 1372 | if (!localXdgDir.isEmpty()) |
1370 | { | 1373 | { |
1371 | if (localXdgDir.at(localXdgDir.length()-1) != '/') | 1374 | if (localXdgDir.at(localXdgDir.length()-1) != '/') |
1372 | localXdgDir += '/'; | 1375 | localXdgDir += '/'; |
1373 | } | 1376 | } |
1374 | else | 1377 | else |
1375 | { | 1378 | { |
1376 | //US if (getuid()) | 1379 | //US if (getuid()) |
1377 | if (true) | 1380 | if (true) |
1378 | { | 1381 | { |
1379 | localXdgDir = QDir::homeDirPath() + "/.local/share/"; | 1382 | localXdgDir = QDir::homeDirPath() + "/.local/share/"; |
1380 | } | 1383 | } |
1381 | else | 1384 | else |
1382 | { | 1385 | { |
1383 | //US struct passwd *pw = getpwuid(0); | 1386 | //US struct passwd *pw = getpwuid(0); |
1384 | //US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.local/share/"; | 1387 | //US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.local/share/"; |
1385 | qDebug("KStandardDirs::addKDEDefaults: 3 has to be fixed"); | 1388 | qDebug("KStandardDirs::addKDEDefaults: 3 has to be fixed"); |
1386 | } | 1389 | } |
1387 | } | 1390 | } |
1388 | 1391 | ||
1389 | localXdgDir = KShell::tildeExpand(localXdgDir); | 1392 | localXdgDir = KShell::tildeExpand(localXdgDir); |
1390 | addXdgDataPrefix(localXdgDir); | 1393 | addXdgDataPrefix(localXdgDir); |
1391 | 1394 | ||
1392 | for (QStringList::ConstIterator it = xdgdirList.begin(); | 1395 | for (QStringList::ConstIterator it = xdgdirList.begin(); |
1393 | it != xdgdirList.end(); it++) | 1396 | it != xdgdirList.end(); it++) |
1394 | { | 1397 | { |
1395 | QString dir = KShell::tildeExpand(*it); | 1398 | QString dir = KShell::tildeExpand(*it); |
1396 | 1399 | ||
1397 | addXdgDataPrefix(dir); | 1400 | addXdgDataPrefix(dir); |
1398 | } | 1401 | } |
1399 | // end XDG_DATA_XXX | 1402 | // end XDG_DATA_XXX |
1400 | 1403 | ||
1401 | 1404 | ||
1402 | uint index = 0; | 1405 | uint index = 0; |
1403 | while (types[index] != 0) { | 1406 | while (types[index] != 0) { |
1404 | addResourceType(types[index], kde_default(types[index])); | 1407 | addResourceType(types[index], kde_default(types[index])); |
1405 | index++; | 1408 | index++; |
1406 | } | 1409 | } |
1407 | 1410 | ||
1408 | addResourceDir("home", QDir::homeDirPath()); | 1411 | addResourceDir("home", QDir::homeDirPath()); |
1409 | } | 1412 | } |
1410 | 1413 | ||
1411 | void KStandardDirs::checkConfig() const | 1414 | void KStandardDirs::checkConfig() const |
1412 | { | 1415 | { |
1413 | /*US | 1416 | /*US |
1414 | if (!addedCustoms && KGlobal::_instance && KGlobal::_instance->_config) | 1417 | if (!addedCustoms && KGlobal::_instance && KGlobal::_instance->_config) |
1415 | const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::_instance->_config); | 1418 | const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::_instance->_config); |
1416 | */ | 1419 | */ |
1417 | if (!addedCustoms && KGlobal::config()) | 1420 | if (!addedCustoms && KGlobal::config()) |
1418 | const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::config()); | 1421 | const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::config()); |
1419 | } | 1422 | } |
1420 | 1423 | ||
1421 | bool KStandardDirs::addCustomized(KConfig *config) | 1424 | bool KStandardDirs::addCustomized(KConfig *config) |
1422 | { | 1425 | { |
1423 | if (addedCustoms) // there are already customized entries | 1426 | if (addedCustoms) // there are already customized entries |
1424 | return false; // we just quite and hope they are the right ones | 1427 | return false; // we just quite and hope they are the right ones |
1425 | 1428 | ||
1426 | // save the numbers of config directories. If this changes, | 1429 | // save the numbers of config directories. If this changes, |
1427 | // we will return true to give KConfig a chance to reparse | 1430 | // we will return true to give KConfig a chance to reparse |
1428 | uint configdirs = resourceDirs("config").count(); | 1431 | uint configdirs = resourceDirs("config").count(); |
1429 | 1432 | ||
1430 | // reading the prefixes in | 1433 | // reading the prefixes in |
1431 | QString oldGroup = config->group(); | 1434 | QString oldGroup = config->group(); |
1432 | config->setGroup("Directories"); | 1435 | config->setGroup("Directories"); |
1433 | 1436 | ||
1434 | QStringList list; | 1437 | QStringList list; |
1435 | QStringList::ConstIterator it; | 1438 | QStringList::ConstIterator it; |
1436 | list = config->readListEntry("prefixes"); | 1439 | list = config->readListEntry("prefixes"); |
1437 | for (it = list.begin(); it != list.end(); it++) | 1440 | for (it = list.begin(); it != list.end(); it++) |
1438 | addPrefix(*it); | 1441 | addPrefix(*it); |
1439 | 1442 | ||
1440 | // iterating over all entries in the group Directories | 1443 | // iterating over all entries in the group Directories |
1441 | // to find entries that start with dir_$type | 1444 | // to find entries that start with dir_$type |
1442 | /*US | 1445 | /*US |
1443 | QMap<QString, QString> entries = config->entryMap("Directories"); | 1446 | QMap<QString, QString> entries = config->entryMap("Directories"); |
1444 | 1447 | ||
1445 | QMap<QString, QString>::ConstIterator it2; | 1448 | QMap<QString, QString>::ConstIterator it2; |
1446 | for (it2 = entries.begin(); it2 != entries.end(); it2++) | 1449 | for (it2 = entries.begin(); it2 != entries.end(); it2++) |
1447 | { | 1450 | { |
1448 | QString key = it2.key(); | 1451 | QString key = it2.key(); |
1449 | if (key.left(4) == "dir_") { | 1452 | if (key.left(4) == "dir_") { |
1450 | // generate directory list, there may be more than 1. | 1453 | // generate directory list, there may be more than 1. |
1451 | QStringList dirs = QStringList::split(',', *it2); | 1454 | QStringList dirs = QStringList::split(',', *it2); |
1452 | QStringList::Iterator sIt(dirs.begin()); | 1455 | QStringList::Iterator sIt(dirs.begin()); |
1453 | QString resType = key.mid(4, key.length()); | 1456 | QString resType = key.mid(4, key.length()); |
1454 | for (; sIt != dirs.end(); ++sIt) { | 1457 | for (; sIt != dirs.end(); ++sIt) { |
1455 | addResourceDir(resType.latin1(), *sIt); | 1458 | addResourceDir(resType.latin1(), *sIt); |
1456 | } | 1459 | } |
1457 | } | 1460 | } |
1458 | } | 1461 | } |
1459 | 1462 | ||
1460 | // Process KIOSK restrictions. | 1463 | // Process KIOSK restrictions. |
1461 | config->setGroup("KDE Resource Restrictions"); | 1464 | config->setGroup("KDE Resource Restrictions"); |
1462 | entries = config->entryMap("KDE Resource Restrictions"); | 1465 | entries = config->entryMap("KDE Resource Restrictions"); |
1463 | for (it2 = entries.begin(); it2 != entries.end(); it2++) | 1466 | for (it2 = entries.begin(); it2 != entries.end(); it2++) |
1464 | { | 1467 | { |
1465 | QString key = it2.key(); | 1468 | QString key = it2.key(); |
1466 | if (!config->readBoolEntry(key, true)) | 1469 | if (!config->readBoolEntry(key, true)) |
1467 | { | 1470 | { |
1468 | d->restrictionsActive = true; | 1471 | d->restrictionsActive = true; |
1469 | d->restrictions.insert(key.latin1(), &d->restrictionsActive); // Anything will do | 1472 | d->restrictions.insert(key.latin1(), &d->restrictionsActive); // Anything will do |
1470 | dircache.remove(key.latin1()); | 1473 | dircache.remove(key.latin1()); |
1471 | } | 1474 | } |
1472 | } | 1475 | } |
1473 | */ | 1476 | */ |
1474 | // save it for future calls - that will return | 1477 | // save it for future calls - that will return |
1475 | addedCustoms = true; | 1478 | addedCustoms = true; |
1476 | config->setGroup(oldGroup); | 1479 | config->setGroup(oldGroup); |
1477 | 1480 | ||
1478 | // return true if the number of config dirs changed | 1481 | // return true if the number of config dirs changed |
1479 | return (resourceDirs("config").count() != configdirs); | 1482 | return (resourceDirs("config").count() != configdirs); |
1480 | } | 1483 | } |
1481 | 1484 | ||
1482 | QString KStandardDirs::localkdedir() const | 1485 | QString KStandardDirs::localkdedir() const |
1483 | { | 1486 | { |
1484 | // Return the prefix to use for saving | 1487 | // Return the prefix to use for saving |
1485 | return prefixes.first(); | 1488 | return prefixes.first(); |
1486 | } | 1489 | } |
1487 | 1490 | ||
1488 | QString KStandardDirs::localxdgdatadir() const | 1491 | QString KStandardDirs::localxdgdatadir() const |
1489 | { | 1492 | { |
1490 | // Return the prefix to use for saving | 1493 | // Return the prefix to use for saving |
1491 | return d->xdgdata_prefixes.first(); | 1494 | return d->xdgdata_prefixes.first(); |
1492 | } | 1495 | } |
1493 | 1496 | ||
1494 | QString KStandardDirs::localxdgconfdir() const | 1497 | QString KStandardDirs::localxdgconfdir() const |
1495 | { | 1498 | { |
1496 | // Return the prefix to use for saving | 1499 | // Return the prefix to use for saving |
1497 | return d->xdgconf_prefixes.first(); | 1500 | return d->xdgconf_prefixes.first(); |
1498 | } | 1501 | } |
1499 | 1502 | ||
1500 | void KStandardDirs::setAppDir( const QString &appDir ) | 1503 | void KStandardDirs::setAppDir( const QString &appDir ) |
1501 | { | 1504 | { |
1502 | mAppDir = appDir; | 1505 | mAppDir = appDir; |
1503 | 1506 | ||
1504 | if ( mAppDir.right( 1 ) != "/" ) | 1507 | if ( mAppDir.right( 1 ) != "/" ) |
1505 | mAppDir += "/"; | 1508 | mAppDir += "/"; |
1506 | } | 1509 | } |
1507 | 1510 | ||
1508 | QString KStandardDirs::appDir() | 1511 | QString KStandardDirs::appDir() |
1509 | { | 1512 | { |
1510 | return mAppDir; | 1513 | return mAppDir; |
1511 | } | 1514 | } |
1512 | 1515 | ||
1513 | // just to make code more readable without macros | 1516 | // just to make code more readable without macros |
1514 | QString locate( const char *type, | 1517 | QString locate( const char *type, |
1515 | const QString& filename/*US , const KInstance* inst*/ ) | 1518 | const QString& filename/*US , const KInstance* inst*/ ) |
1516 | { | 1519 | { |
1517 | //US return inst->dirs()->findResource(type, filename); | 1520 | //US return inst->dirs()->findResource(type, filename); |
1518 | return KGlobal::dirs()->findResource(type, filename); | 1521 | return KGlobal::dirs()->findResource(type, filename); |
1519 | } | 1522 | } |
1520 | 1523 | ||
1521 | QString locateLocal( const char *type, | 1524 | QString locateLocal( const char *type, |
1522 | const QString& filename/*US , const KInstance* inst*/ ) | 1525 | const QString& filename/*US , const KInstance* inst*/ ) |
1523 | { | 1526 | { |
1524 | 1527 | ||
1525 | QString path = locateLocal(type, filename, true /*US, inst*/); | 1528 | QString path = locateLocal(type, filename, true /*US, inst*/); |
1526 | 1529 | ||
1527 | 1530 | ||
1528 | /* | 1531 | /* |
1529 | static int ccc = 0; | 1532 | static int ccc = 0; |
1530 | ++ccc; | 1533 | ++ccc; |
1531 | if ( ccc > 13 ) | 1534 | if ( ccc > 13 ) |
1532 | abort(); | 1535 | abort(); |
1533 | */ | 1536 | */ |
1534 | qDebug("locatelocal: %s" , path.latin1()); | 1537 | qDebug("locatelocal: %s" , path.latin1()); |
1535 | return path; | 1538 | return path; |
1536 | 1539 | ||
1537 | /*US why do we put all files into one directory. It is quit complicated. | 1540 | /*US why do we put all files into one directory. It is quit complicated. |
1538 | why not staying with the original directorystructure ? | 1541 | why not staying with the original directorystructure ? |
1539 | 1542 | ||
1540 | 1543 | ||
1541 | QString escapedFilename = filename; | 1544 | QString escapedFilename = filename; |
1542 | escapedFilename.replace( QRegExp( "/" ), "_" ); | 1545 | escapedFilename.replace( QRegExp( "/" ), "_" ); |
1543 | 1546 | ||
1544 | QString path = KStandardDirs::appDir() + type + "_" + escapedFilename; | 1547 | QString path = KStandardDirs::appDir() + type + "_" + escapedFilename; |
1545 | 1548 | ||
1546 | kdDebug() << "locate: '" << path << "'" << endl; | 1549 | kdDebug() << "locate: '" << path << "'" << endl; |
1547 | qDebug("locate: %s" , path.latin1()); | 1550 | qDebug("locate: %s" , path.latin1()); |
1548 | return path; | 1551 | return path; |
1549 | */ | 1552 | */ |
1550 | //US so my proposal is this: | 1553 | //US so my proposal is this: |
1551 | 1554 | ||
1552 | // QString escapedFilename = filename; | 1555 | // QString escapedFilename = filename; |
1553 | // escapedFilename.replace( QRegExp( "/" ), "_" ); | 1556 | // escapedFilename.replace( QRegExp( "/" ), "_" ); |
1554 | 1557 | ||
1555 | #if 0 | 1558 | #if 0 |
1556 | #ifdef _WIN32_ | 1559 | #ifdef _WIN32_ |
1557 | QString path = QDir::convertSeparators(KStandardDirs::appDir() + type + "/" + filename); | 1560 | QString path = QDir::convertSeparators(KStandardDirs::appDir() + type + "/" + filename); |
1558 | #else | 1561 | #else |
1559 | QString path = KStandardDirs::appDir() + type + "/" + filename; | 1562 | QString path = KStandardDirs::appDir() + type + "/" + filename; |
1560 | #endif | 1563 | #endif |
1561 | 1564 | ||
1562 | //US Create the containing dir if needed | 1565 | //US Create the containing dir if needed |
1563 | QFileInfo fi ( path ); | 1566 | QFileInfo fi ( path ); |
1564 | 1567 | ||
1565 | // QString dir=pathurl.directory(); | 1568 | // QString dir=pathurl.directory(); |
1566 | //QMessageBox::information( 0,"path", path, 1 ); | 1569 | //QMessageBox::information( 0,"path", path, 1 ); |
1567 | 1570 | ||
1568 | #ifdef _WIN32_ | 1571 | #ifdef _WIN32_ |
1569 | KStandardDirs::makeDir(path); | 1572 | KStandardDirs::makeDir(path); |
1570 | #else | 1573 | #else |
1571 | KStandardDirs::makeDir(fi.dirPath( true )); | 1574 | KStandardDirs::makeDir(fi.dirPath( true )); |
1572 | #endif | 1575 | #endif |
1573 | 1576 | ||
1574 | qDebug("locate22: %s" , path.latin1()); | 1577 | qDebug("locate22: %s" , path.latin1()); |
1575 | return path; | 1578 | return path; |
1576 | 1579 | ||
1577 | #endif | 1580 | #endif |
1578 | 1581 | ||
1579 | } | 1582 | } |
1580 | 1583 | ||
1581 | QString locateLocal( const char *type, | 1584 | QString locateLocal( const char *type, |
1582 | const QString& filename, bool createDir/*US , const KInstance* inst*/ ) | 1585 | const QString& filename, bool createDir/*US , const KInstance* inst*/ ) |
1583 | { | 1586 | { |
1584 | // try to find slashes. If there are some, we have to | 1587 | // try to find slashes. If there are some, we have to |
1585 | // create the subdir first | 1588 | // create the subdir first |
1586 | int slash = filename.findRev('/')+1; | 1589 | int slash = filename.findRev('/')+1; |
1587 | if (!slash) // only one filename | 1590 | if (!slash) // only one filename |
1588 | //USreturn inst->dirs()->saveLocation(type, QString::null, createDir) + filename; | 1591 | //USreturn inst->dirs()->saveLocation(type, QString::null, createDir) + filename; |
1589 | return KGlobal::dirs()->saveLocation(type, QString::null, createDir) + filename; | 1592 | return KGlobal::dirs()->saveLocation(type, QString::null, createDir) + filename; |
1590 | 1593 | ||
1591 | // split path from filename | 1594 | // split path from filename |
1592 | QString dir = filename.left(slash); | 1595 | QString dir = filename.left(slash); |
1593 | QString file = filename.mid(slash); | 1596 | QString file = filename.mid(slash); |
1594 | //US return inst->dirs()->saveLocation(type, dir, createDir) + file; | 1597 | //US return inst->dirs()->saveLocation(type, dir, createDir) + file; |
1595 | return KGlobal::dirs()->saveLocation(type, dir, createDir) + file; | 1598 | return KGlobal::dirs()->saveLocation(type, dir, createDir) + file; |
1596 | 1599 | ||
1597 | // *************************************************************** | 1600 | // *************************************************************** |
1598 | #if 0 | 1601 | #if 0 |
1599 | 1602 | ||
1600 | /*US why do we put all files into one directory. It is quit complicated. | 1603 | /*US why do we put all files into one directory. It is quit complicated. |
1601 | why not staying with the original directorystructure ? | 1604 | why not staying with the original directorystructure ? |
1602 | 1605 | ||
1603 | 1606 | ||
1604 | QString escapedFilename = filename; | 1607 | QString escapedFilename = filename; |
1605 | escapedFilename.replace( QRegExp( "/" ), "_" ); | 1608 | escapedFilename.replace( QRegExp( "/" ), "_" ); |
1606 | 1609 | ||
1607 | QString path = KStandardDirs::appDir() + type + "_" + escapedFilename; | 1610 | QString path = KStandardDirs::appDir() + type + "_" + escapedFilename; |
1608 | 1611 | ||
1609 | kdDebug() << "locate: '" << path << "'" << endl; | 1612 | kdDebug() << "locate: '" << path << "'" << endl; |
1610 | qDebug("locate: %s" , path.latin1()); | 1613 | qDebug("locate: %s" , path.latin1()); |
1611 | return path; | 1614 | return path; |
1612 | */ | 1615 | */ |
1613 | //US so my proposal is this: | 1616 | //US so my proposal is this: |
1614 | 1617 | ||
1615 | // QString escapedFilename = filename; | 1618 | // QString escapedFilename = filename; |
1616 | // escapedFilename.replace( QRegExp( "/" ), "_" ); | 1619 | // escapedFilename.replace( QRegExp( "/" ), "_" ); |
1617 | 1620 | ||
1618 | #ifdef _WIN32_ | 1621 | #ifdef _WIN32_ |
1619 | QString path = QDir::convertSeparators(KStandardDirs::appDir() + type + "/" + filename); | 1622 | QString path = QDir::convertSeparators(KStandardDirs::appDir() + type + "/" + filename); |
1620 | #else | 1623 | #else |
1621 | QString path = KStandardDirs::appDir() + type + "/" + filename; | 1624 | QString path = KStandardDirs::appDir() + type + "/" + filename; |
1622 | #endif | 1625 | #endif |
1623 | 1626 | ||
1624 | //US Create the containing dir if needed | 1627 | //US Create the containing dir if needed |
1625 | KURL pathurl; | 1628 | KURL pathurl; |
1626 | pathurl.setPath(path); | 1629 | pathurl.setPath(path); |
1627 | QString dir=pathurl.directory(); | 1630 | QString dir=pathurl.directory(); |
1628 | //QMessageBox::information( 0,"path", path, 1 ); | 1631 | //QMessageBox::information( 0,"path", path, 1 ); |
1629 | #ifdef _WIN32_ | 1632 | #ifdef _WIN32_ |
1630 | KStandardDirs::makeDir(path); | 1633 | KStandardDirs::makeDir(path); |
1631 | #else | 1634 | #else |
1632 | KStandardDirs::makeDir(dir); | 1635 | KStandardDirs::makeDir(dir); |
1633 | #endif | 1636 | #endif |
1634 | 1637 | ||
1635 | return path; | 1638 | return path; |
1636 | #endif | 1639 | #endif |
1637 | } | 1640 | } |