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