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