summaryrefslogtreecommitdiffabout
path: root/microkde
Unidiff
Diffstat (limited to 'microkde') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdecore/kstandarddirs.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/microkde/kdecore/kstandarddirs.cpp b/microkde/kdecore/kstandarddirs.cpp
index 5abe05c..1a1e027 100644
--- a/microkde/kdecore/kstandarddirs.cpp
+++ b/microkde/kdecore/kstandarddirs.cpp
@@ -1,93 +1,94 @@
1/* This file is part of the KDE libraries 1/* This file is part of the KDE libraries
2 Copyright (C) 1999 Sirtaj Singh Kang <taj@kde.org> 2 Copyright (C) 1999 Sirtaj Singh Kang <taj@kde.org>
3 Copyright (C) 1999 Stephan Kulow <coolo@kde.org> 3 Copyright (C) 1999 Stephan Kulow <coolo@kde.org>
4 Copyright (C) 1999 Waldo Bastian <bastian@kde.org> 4 Copyright (C) 1999 Waldo Bastian <bastian@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License version 2 as published by the Free Software Foundation. 8 License version 2 as published by the Free Software Foundation.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22 * Author: Stephan Kulow <coolo@kde.org> and Sirtaj Singh Kang <taj@kde.org> 22 * Author: Stephan Kulow <coolo@kde.org> and Sirtaj Singh Kang <taj@kde.org>
23 * Version:$Id$ 23 * Version:$Id$
24 * Generated:Thu Mar 5 16:05:28 EST 1998 24 * Generated:Thu Mar 5 16:05:28 EST 1998
25 */ 25 */
26 26
27//US #include "config.h" 27//US #include "config.h"
28 28
29#include <stdlib.h> 29#include <stdlib.h>
30#include <assert.h> 30#include <assert.h>
31//US#include <errno.h> 31//US#include <errno.h>
32//US #ifdef HAVE_SYS_STAT_H 32//US #ifdef HAVE_SYS_STAT_H
33//US #include <sys/stat.h> 33//US #include <sys/stat.h>
34//US #endif 34//US #endif
35//US#include <sys/types.h> 35//US#include <sys/types.h>
36//US#include <dirent.h> 36//US#include <dirent.h>
37//US#include <pwd.h> 37//US#include <pwd.h>
38 38
39#include <qregexp.h> 39#include <qregexp.h>
40#include <qasciidict.h> 40#include <qasciidict.h>
41#include <qdict.h> 41#include <qdict.h>
42#include <qdir.h> 42#include <qdir.h>
43#include <qfileinfo.h> 43#include <qfileinfo.h>
44#include <qstring.h> 44#include <qstring.h>
45#include <qstringlist.h> 45#include <qstringlist.h>
46#include <qpe/qpeapplication.h>
46 47
47#include "kstandarddirs.h" 48#include "kstandarddirs.h"
48#include "kconfig.h" 49#include "kconfig.h"
49#include "kdebug.h" 50#include "kdebug.h"
50//US #include "kinstance.h" 51//US #include "kinstance.h"
51#include "kshell.h" 52#include "kshell.h"
52//US#include <sys/param.h> 53//US#include <sys/param.h>
53//US#include <unistd.h> 54//US#include <unistd.h>
54 55
55//US 56//US
56QString KStandardDirs::mAppDir = QString::null; 57QString KStandardDirs::mAppDir = QString::null;
57 58
58 59
59template class QDict<QStringList>; 60template class QDict<QStringList>;
60 61
61#if 0 62#if 0
62#include <qtextedit.h> 63#include <qtextedit.h>
63void ddd( QString op ) 64void ddd( QString op )
64{ 65{
65 static QTextEdit * dot = 0; 66 static QTextEdit * dot = 0;
66 if ( ! dot ) 67 if ( ! dot )
67 dot = new QTextEdit(); 68 dot = new QTextEdit();
68 69
69 dot->show(); 70 dot->show();
70 71
71 dot->append( op ); 72 dot->append( op );
72 73
73} 74}
74#endif 75#endif
75class KStandardDirs::KStandardDirsPrivate 76class KStandardDirs::KStandardDirsPrivate
76{ 77{
77public: 78public:
78 KStandardDirsPrivate() 79 KStandardDirsPrivate()
79 : restrictionsActive(false), 80 : restrictionsActive(false),
80 dataRestrictionActive(false) 81 dataRestrictionActive(false)
81 { } 82 { }
82 83
83 bool restrictionsActive; 84 bool restrictionsActive;
84 bool dataRestrictionActive; 85 bool dataRestrictionActive;
85 QAsciiDict<bool> restrictions; 86 QAsciiDict<bool> restrictions;
86 QStringList xdgdata_prefixes; 87 QStringList xdgdata_prefixes;
87 QStringList xdgconf_prefixes; 88 QStringList xdgconf_prefixes;
88}; 89};
89 90
90static const char* const types[] = {"html", "icon", "apps", "sound", 91static const char* const types[] = {"html", "icon", "apps", "sound",
91 "data", "locale", "services", "mime", 92 "data", "locale", "services", "mime",
92 "servicetypes", "config", "exe", 93 "servicetypes", "config", "exe",
93 "wallpaper", "lib", "pixmap", "templates", 94 "wallpaper", "lib", "pixmap", "templates",
@@ -305,143 +306,145 @@ Q_UINT32 KStandardDirs::calcResourceHash( const char *type,
305 for (QStringList::ConstIterator it = candidates.begin(); 306 for (QStringList::ConstIterator it = candidates.begin();
306 it != candidates.end(); it++) 307 it != candidates.end(); it++)
307 { 308 {
308 hash = updateHash(*it + filename, hash); 309 hash = updateHash(*it + filename, hash);
309 if (!deep && hash) 310 if (!deep && hash)
310 return hash; 311 return hash;
311 } 312 }
312 return hash; 313 return hash;
313} 314}
314*/ 315*/
315 316
316QStringList KStandardDirs::findDirs( const char *type, 317QStringList KStandardDirs::findDirs( const char *type,
317 const QString& reldir ) const 318 const QString& reldir ) const
318{ 319{
319 QStringList list; 320 QStringList list;
320 321
321 checkConfig(); 322 checkConfig();
322 323
323 if (d && d->restrictionsActive && (strcmp(type, "data")==0)) 324 if (d && d->restrictionsActive && (strcmp(type, "data")==0))
324 applyDataRestrictions(reldir); 325 applyDataRestrictions(reldir);
325 QStringList candidates = resourceDirs(type); 326 QStringList candidates = resourceDirs(type);
326 QDir testdir; 327 QDir testdir;
327 328
328 for (QStringList::ConstIterator it = candidates.begin(); 329 for (QStringList::ConstIterator it = candidates.begin();
329 it != candidates.end(); it++) { 330 it != candidates.end(); it++) {
330 testdir.setPath(*it + reldir); 331 testdir.setPath(*it + reldir);
331 if (testdir.exists()) 332 if (testdir.exists())
332 list.append(testdir.absPath() + '/'); 333 list.append(testdir.absPath() + '/');
333 } 334 }
334 335
335 return list; 336 return list;
336} 337}
337 338
338QString KStandardDirs::findResourceDir( const char *type, 339QString KStandardDirs::findResourceDir( const char *type,
339 const QString& filename) const 340 const QString& filename) const
340{ 341{
341#ifndef NDEBUG 342#ifndef NDEBUG
342 if (filename.isEmpty()) { 343 if (filename.isEmpty()) {
343 kdWarning() << "filename for type " << type << " in KStandardDirs::findResourceDir is not supposed to be empty!!" << endl; 344 kdWarning() << "filename for type " << type << " in KStandardDirs::findResourceDir is not supposed to be empty!!" << endl;
344 return QString::null; 345 return QString::null;
345 } 346 }
346#endif 347#endif
347 348
348 if (d && d->restrictionsActive && (strcmp(type, "data")==0)) 349 if (d && d->restrictionsActive && (strcmp(type, "data")==0))
349 applyDataRestrictions(filename); 350 applyDataRestrictions(filename);
350 QStringList candidates = resourceDirs(type); 351 QStringList candidates = resourceDirs(type);
351 QString fullPath; 352 QString fullPath;
352 353
353 for (QStringList::ConstIterator it = candidates.begin(); 354 for (QStringList::ConstIterator it = candidates.begin(); it != candidates.end(); it++)
354 it != candidates.end(); it++) 355 {
355 if (exists(*it + filename)) 356 if (exists(*it + filename))
356 return *it; 357 return *it;
358 }
357 359
358#ifndef NDEBUG 360#ifndef NDEBUG
359 if(false && type != "locale") 361 if(false && type != "locale")
360 kdDebug() << "KStdDirs::findResDir(): can't find \"" << filename << "\" in type \"" << type << "\"." << endl; 362 kdDebug() << "KStdDirs::findResDir(): can't find \"" << filename << "\" in type \"" << type << "\"." << endl;
361#endif 363#endif
362 364
363 return QString::null; 365 return QString::null;
364} 366}
365 367
366bool KStandardDirs::exists(const QString &fullPath) 368bool KStandardDirs::exists(const QString &fullPath)
367{ 369{
368//US struct stat buff; 370//US struct stat buff;
369 QFileInfo fullPathInfo(QFile::encodeName(fullPath)); 371 QFileInfo fullPathInfo(QFile::encodeName(fullPath));
370 372
371//US if (access(QFile::encodeName(fullPath), R_OK) == 0 && fullPathInfo.isReadable()) 373//US if (access(QFile::encodeName(fullPath), R_OK) == 0 && fullPathInfo.isReadable())
372 if (fullPathInfo.isReadable()) 374 if (fullPathInfo.isReadable())
373 { 375 {
374 if (fullPath.at(fullPath.length() - 1) != '/') { 376 if (fullPath.at(fullPath.length() - 1) != '/') {
375 //US if (S_ISREG( buff.st_mode )) 377 //US if (S_ISREG( buff.st_mode ))
376 if (fullPathInfo.isFile()) 378 if (fullPathInfo.isFile())
377 return true; 379 return true;
378 } 380 }
379 else { 381 else {
380 //US if (S_ISDIR( buff.st_mode )) 382 //US if (S_ISDIR( buff.st_mode ))
381 if (fullPathInfo.isDir()) 383 if (fullPathInfo.isDir())
382 return true; 384 return true;
383 } 385 }
384 } 386 }
385 return false; 387 return false;
386} 388}
387 389
388static void lookupDirectory(const QString& path, const QString &relPart, 390static void lookupDirectory(const QString& path, const QString &relPart,
389 const QRegExp &regexp, 391 const QRegExp &regexp,
390 QStringList& list, 392 QStringList& list,
391 QStringList& relList, 393 QStringList& relList,
392 bool recursive, bool uniq) 394 bool recursive, bool uniq)
393{ 395{
394 QString pattern = regexp.pattern(); 396 QString pattern = regexp.pattern();
395 if (recursive || pattern.contains('?') || pattern.contains('*')) 397 if (recursive || pattern.contains('?') || pattern.contains('*'))
396 { 398 {
397 // We look for a set of files. 399 // We look for a set of files.
398//US DIR *dp = opendir( QFile::encodeName(path)); 400//US DIR *dp = opendir( QFile::encodeName(path));
399 QDir dp(QFile::encodeName(path)); 401 QDir dp(QFile::encodeName(path));
402
400 if (!dp.exists()) 403 if (!dp.exists())
401 return; 404 return;
402 static int iii = 0; 405 static int iii = 0;
403 ++iii; 406 ++iii;
404 if ( iii == 5 ) 407 if ( iii == 5 )
405 abort(); 408 abort();
406 assert(path.at(path.length() - 1) == '/'); 409 assert(path.at(path.length() - 1) == '/');
407 410
408//US struct dirent *ep; 411//US struct dirent *ep;
409//US struct stat buff; 412//US struct stat buff;
410 413
411 QString _dot("."); 414 QString _dot(".");
412 QString _dotdot(".."); 415 QString _dotdot("..");
413 416
414//US while( ( ep = readdir( dp ) ) != 0L ) 417//US while( ( ep = readdir( dp ) ) != 0L )
415 QStringList direntries = dp.entryList(); 418 QStringList direntries = dp.entryList();
416 QStringList::Iterator it = direntries.begin(); 419 QStringList::Iterator it = direntries.begin();
417 420
418 while ( it != list.end() ) // for each file... 421 while ( it != list.end() ) // for each file...
419 { 422 {
420 423
421//US QString fn( QFile::decodeName(ep->d_name)); 424//US QString fn( QFile::decodeName(ep->d_name));
422 QString fn = (*it); // dp.entryList already decodes 425 QString fn = (*it); // dp.entryList already decodes
423 it++; 426 it++;
424 if ( fn.isNull() ) 427 if ( fn.isNull() )
425 break; 428 break;
426 429
427 if (fn == _dot || fn == _dotdot || fn.at(fn.length() - 1).latin1() == '~' ) 430 if (fn == _dot || fn == _dotdot || fn.at(fn.length() - 1).latin1() == '~' )
428 continue; 431 continue;
429 432
430/*US 433/*US
431 if (!recursive && !regexp.exactMatch(fn)) 434 if (!recursive && !regexp.exactMatch(fn))
432 continue; // No match 435 continue; // No match
433*/ 436*/
434//US this should do the same: 437//US this should do the same:
435 int pos = regexp.match(fn); 438 int pos = regexp.match(fn);
436 if (!recursive && !pos == 0) 439 if (!recursive && !pos == 0)
437 continue; // No match 440 continue; // No match
438 441
439 QString pathfn = path + fn; 442 QString pathfn = path + fn;
440/*US 443/*US
441 if ( stat( QFile::encodeName(pathfn), &buff ) != 0 ) { 444 if ( stat( QFile::encodeName(pathfn), &buff ) != 0 ) {
442 kdDebug() << "Error stat'ing " << pathfn << " : " << perror << endl; 445 kdDebug() << "Error stat'ing " << pathfn << " : " << perror << endl;
443 continue; // Couldn't stat (e.g. no read permissions) 446 continue; // Couldn't stat (e.g. no read permissions)
444 } 447 }
445 448
446 if ( recursive ) 449 if ( recursive )
447 { 450 {
@@ -1176,96 +1179,98 @@ bool KStandardDirs::makeDir(const QString& dir2, int mode)
1176 //qDebug("KStandardDirs::makeDir try to create : %s" , base.latin1()); 1179 //qDebug("KStandardDirs::makeDir try to create : %s" , base.latin1());
1177 if (dirObj.mkdir(base) != true) 1180 if (dirObj.mkdir(base) != true)
1178 { 1181 {
1179 qDebug("KStandardDirs::makeDir could not create: %s" , base.latin1()); 1182 qDebug("KStandardDirs::makeDir could not create: %s" , base.latin1());
1180 return false; 1183 return false;
1181 } 1184 }
1182 } 1185 }
1183 1186
1184 i = pos + 1; 1187 i = pos + 1;
1185 } 1188 }
1186 return true; 1189 return true;
1187 1190
1188} 1191}
1189 1192
1190static QString readEnvPath(const char *env) 1193static QString readEnvPath(const char *env)
1191{ 1194{
1192#ifdef _WIN32_ 1195#ifdef _WIN32_
1193 return ""; 1196 return "";
1194#else 1197#else
1195 QCString c_path = getenv(env); 1198 QCString c_path = getenv(env);
1196 if (c_path.isEmpty()) 1199 if (c_path.isEmpty())
1197 return QString::null; 1200 return QString::null;
1198 return QFile::decodeName(c_path); 1201 return QFile::decodeName(c_path);
1199#endif 1202#endif
1200} 1203}
1201 1204
1202void KStandardDirs::addKDEDefaults() 1205void KStandardDirs::addKDEDefaults()
1203{ 1206{
1204 //qDebug("ERROR: KStandardDirs::addKDEDefaults() called "); 1207 //qDebug("ERROR: KStandardDirs::addKDEDefaults() called ");
1205 //return; 1208 //return;
1206 QStringList kdedirList; 1209 QStringList kdedirList;
1207 1210
1208 // begin KDEDIRS 1211 // begin KDEDIRS
1209 QString kdedirs = readEnvPath("MICROKDEDIRS"); 1212 QString kdedirs = readEnvPath("MICROKDEDIRS");
1210 if (!kdedirs.isEmpty()) 1213 if (!kdedirs.isEmpty())
1211 { 1214 {
1212 tokenize(kdedirList, kdedirs, ":"); 1215 tokenize(kdedirList, kdedirs, ":");
1213 } 1216 }
1214 else 1217 else
1215 { 1218 {
1216 QString kdedir = readEnvPath("MICROKDEDIR"); 1219 QString kdedir = readEnvPath("MICROKDEDIR");
1217 if (!kdedir.isEmpty()) 1220 if (!kdedir.isEmpty())
1218 { 1221 {
1219 kdedir = KShell::tildeExpand(kdedir); 1222 kdedir = KShell::tildeExpand(kdedir);
1220 kdedirList.append(kdedir); 1223 kdedirList.append(kdedir);
1221 } 1224 }
1222 } 1225 }
1223//US kdedirList.append(KDEDIR); 1226//US kdedirList.append(KDEDIR);
1227//US for embedded, add qtopia dir as kdedir
1228 kdedirList.append(QPEApplication::qpeDir());
1224 1229
1225#ifdef __KDE_EXECPREFIX 1230#ifdef __KDE_EXECPREFIX
1226 QString execPrefix(__KDE_EXECPREFIX); 1231 QString execPrefix(__KDE_EXECPREFIX);
1227 if (execPrefix!="NONE") 1232 if (execPrefix!="NONE")
1228 kdedirList.append(execPrefix); 1233 kdedirList.append(execPrefix);
1229#endif 1234#endif
1230 1235
1231 QString localKdeDir; 1236 QString localKdeDir;
1232 1237
1233//US if (getuid()) 1238//US if (getuid())
1234 if (true) 1239 if (true)
1235 { 1240 {
1236 localKdeDir = readEnvPath("MICROKDEHOME"); 1241 localKdeDir = readEnvPath("MICROKDEHOME");
1237 if (!localKdeDir.isEmpty()) 1242 if (!localKdeDir.isEmpty())
1238 { 1243 {
1239 if (localKdeDir.at(localKdeDir.length()-1) != '/') 1244 if (localKdeDir.at(localKdeDir.length()-1) != '/')
1240 localKdeDir += '/'; 1245 localKdeDir += '/';
1241 } 1246 }
1242 else 1247 else
1243 { 1248 {
1244 localKdeDir = QDir::homeDirPath() + "/kdepim/"; 1249 localKdeDir = QDir::homeDirPath() + "/kdepim/";
1245 } 1250 }
1246 } 1251 }
1247 else 1252 else
1248 { 1253 {
1249 // We treat root different to prevent root messing up the 1254 // We treat root different to prevent root messing up the
1250 // file permissions in the users home directory. 1255 // file permissions in the users home directory.
1251 localKdeDir = readEnvPath("MICROKDEROOTHOME"); 1256 localKdeDir = readEnvPath("MICROKDEROOTHOME");
1252 if (!localKdeDir.isEmpty()) 1257 if (!localKdeDir.isEmpty())
1253 { 1258 {
1254 if (localKdeDir.at(localKdeDir.length()-1) != '/') 1259 if (localKdeDir.at(localKdeDir.length()-1) != '/')
1255 localKdeDir += '/'; 1260 localKdeDir += '/';
1256 } 1261 }
1257 else 1262 else
1258 { 1263 {
1259//US struct passwd *pw = getpwuid(0); 1264//US struct passwd *pw = getpwuid(0);
1260//US localKdeDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.microkde/"; 1265//US localKdeDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.microkde/";
1261 qDebug("KStandardDirs::addKDEDefaults: 1 has to be fixed"); 1266 qDebug("KStandardDirs::addKDEDefaults: 1 has to be fixed");
1262 } 1267 }
1263 1268
1264 } 1269 }
1265 1270
1266//US localKdeDir = appDir(); 1271//US localKdeDir = appDir();
1267 1272
1268//US 1273//US
1269// qDebug("KStandardDirs::addKDEDefaults: localKdeDir=%s", localKdeDir.latin1()); 1274// qDebug("KStandardDirs::addKDEDefaults: localKdeDir=%s", localKdeDir.latin1());
1270 if (localKdeDir != "-/") 1275 if (localKdeDir != "-/")
1271 { 1276 {