00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "config.h"
00028
00029 #include <stdlib.h>
00030 #include <assert.h>
00031 #include <errno.h>
00032 #ifdef HAVE_SYS_STAT_H
00033 #include <sys/stat.h>
00034 #endif
00035 #include <sys/types.h>
00036 #include <dirent.h>
00037 #include <pwd.h>
00038 #include <grp.h>
00039
00040 #include <qregexp.h>
00041 #include <qasciidict.h>
00042 #include <qdict.h>
00043 #include <qdir.h>
00044 #include <qfileinfo.h>
00045 #include <qstring.h>
00046 #include <qstringlist.h>
00047
00048 #include "kstandarddirs.h"
00049 #include "kconfig.h"
00050 #include "kdebug.h"
00051 #include "kinstance.h"
00052 #include "kshell.h"
00053 #include "ksimpleconfig.h"
00054 #include "kuser.h"
00055 #include <sys/param.h>
00056 #include <unistd.h>
00057
00058 template class QDict<QStringList>;
00059
00060
00061 #if defined(__powerpc64__) || defined(__sparc64__) || defined(__s390x__) || defined(__x86_64__)
00062 # define LIB_NAME "lib64"
00063 #else
00064 # define LIB_NAME "lib"
00065 #endif
00066
00067 class KStandardDirs::KStandardDirsPrivate
00068 {
00069 public:
00070 KStandardDirsPrivate()
00071 : restrictionsActive(false),
00072 dataRestrictionActive(false)
00073 { }
00074
00075 bool restrictionsActive;
00076 bool dataRestrictionActive;
00077 QAsciiDict<bool> restrictions;
00078 QStringList xdgdata_prefixes;
00079 QStringList xdgconf_prefixes;
00080 };
00081
00082 static const char* const types[] = {"html", "icon", "apps", "sound",
00083 "data", "locale", "services", "mime",
00084 "servicetypes", "config", "exe",
00085 "wallpaper", "lib", "pixmap", "templates",
00086 "module", "qtplugins",
00087 "xdgdata-apps", "xdgdata-dirs", "xdgconf-menu",
00088 "kcfg", 0 };
00089
00090 static int tokenize( QStringList& token, const QString& str,
00091 const QString& delim );
00092
00093 KStandardDirs::KStandardDirs( ) : addedCustoms(false)
00094 {
00095 d = new KStandardDirsPrivate;
00096 dircache.setAutoDelete(true);
00097 relatives.setAutoDelete(true);
00098 absolutes.setAutoDelete(true);
00099 savelocations.setAutoDelete(true);
00100 addKDEDefaults();
00101 }
00102
00103 KStandardDirs::~KStandardDirs()
00104 {
00105 delete d;
00106 }
00107
00108 bool KStandardDirs::isRestrictedResource(const char *type, const QString& relPath) const
00109 {
00110 if (!d || !d->restrictionsActive)
00111 return false;
00112
00113 if (d->restrictions[type])
00114 return true;
00115
00116 if (strcmp(type, "data")==0)
00117 {
00118 applyDataRestrictions(relPath);
00119 if (d->dataRestrictionActive)
00120 {
00121 d->dataRestrictionActive = false;
00122 return true;
00123 }
00124 }
00125 return false;
00126 }
00127
00128 void KStandardDirs::applyDataRestrictions(const QString &relPath) const
00129 {
00130 QString key;
00131 int i = relPath.find('/');
00132 if (i != -1)
00133 key = "data_"+relPath.left(i);
00134 else
00135 key = "data_"+relPath;
00136
00137 if (d && d->restrictions[key.latin1()])
00138 d->dataRestrictionActive = true;
00139 }
00140
00141
00142 QStringList KStandardDirs::allTypes() const
00143 {
00144 QStringList list;
00145 for (int i = 0; types[i] != 0; ++i)
00146 list.append(QString::fromLatin1(types[i]));
00147 return list;
00148 }
00149
00150 static void priorityAdd(QStringList &prefixes, const QString& dir, bool priority)
00151 {
00152 if (priority && !prefixes.isEmpty())
00153 {
00154
00155 QStringList::iterator it = prefixes.begin();
00156 it++;
00157 prefixes.insert(it, 1, dir);
00158 }
00159 else
00160 {
00161 prefixes.append(dir);
00162 }
00163 }
00164
00165 void KStandardDirs::addPrefix( const QString& _dir )
00166 {
00167 addPrefix(_dir, false);
00168 }
00169
00170 void KStandardDirs::addPrefix( const QString& _dir, bool priority )
00171 {
00172 if (_dir.isEmpty())
00173 return;
00174
00175 QString dir = _dir;
00176 if (dir.at(dir.length() - 1) != '/')
00177 dir += '/';
00178
00179 if (!prefixes.contains(dir)) {
00180 priorityAdd(prefixes, dir, priority);
00181 dircache.clear();
00182 }
00183 }
00184
00185 void KStandardDirs::addXdgConfigPrefix( const QString& _dir )
00186 {
00187 addXdgConfigPrefix(_dir, false);
00188 }
00189
00190 void KStandardDirs::addXdgConfigPrefix( const QString& _dir, bool priority )
00191 {
00192 if (_dir.isEmpty())
00193 return;
00194
00195 QString dir = _dir;
00196 if (dir.at(dir.length() - 1) != '/')
00197 dir += '/';
00198
00199 if (!d->xdgconf_prefixes.contains(dir)) {
00200 priorityAdd(d->xdgconf_prefixes, dir, priority);
00201 dircache.clear();
00202 }
00203 }
00204
00205 void KStandardDirs::addXdgDataPrefix( const QString& _dir )
00206 {
00207 addXdgDataPrefix(_dir, false);
00208 }
00209
00210 void KStandardDirs::addXdgDataPrefix( const QString& _dir, bool priority )
00211 {
00212 if (_dir.isEmpty())
00213 return;
00214
00215 QString dir = _dir;
00216 if (dir.at(dir.length() - 1) != '/')
00217 dir += '/';
00218
00219 if (!d->xdgdata_prefixes.contains(dir)) {
00220 priorityAdd(d->xdgdata_prefixes, dir, priority);
00221 dircache.clear();
00222 }
00223 }
00224
00225 QString KStandardDirs::kfsstnd_prefixes()
00226 {
00227 return prefixes.join(":");
00228 }
00229
00230 bool KStandardDirs::addResourceType( const char *type,
00231 const QString& relativename )
00232 {
00233 return addResourceType(type, relativename, true);
00234 }
00235 bool KStandardDirs::addResourceType( const char *type,
00236 const QString& relativename,
00237 bool priority )
00238 {
00239 if (relativename.isEmpty())
00240 return false;
00241
00242 QStringList *rels = relatives.find(type);
00243 if (!rels) {
00244 rels = new QStringList();
00245 relatives.insert(type, rels);
00246 }
00247 QString copy = relativename;
00248 if (copy.at(copy.length() - 1) != '/')
00249 copy += '/';
00250 if (!rels->contains(copy)) {
00251 if (priority)
00252 rels->prepend(copy);
00253 else
00254 rels->append(copy);
00255 dircache.remove(type);
00256 return true;
00257 }
00258 return false;
00259 }
00260
00261 bool KStandardDirs::addResourceDir( const char *type,
00262 const QString& absdir)
00263 {
00264
00265 return addResourceDir(type, absdir, false);
00266 }
00267
00268 bool KStandardDirs::addResourceDir( const char *type,
00269 const QString& absdir,
00270 bool priority)
00271 {
00272 QStringList *paths = absolutes.find(type);
00273 if (!paths) {
00274 paths = new QStringList();
00275 absolutes.insert(type, paths);
00276 }
00277 QString copy = absdir;
00278 if (copy.at(copy.length() - 1) != '/')
00279 copy += '/';
00280
00281 if (!paths->contains(copy)) {
00282 if (priority)
00283 paths->prepend(copy);
00284 else
00285 paths->append(copy);
00286 dircache.remove(type);
00287 return true;
00288 }
00289 return false;
00290 }
00291
00292 QString KStandardDirs::findResource( const char *type,
00293 const QString& filename ) const
00294 {
00295 if (filename.at(0) == '/')
00296 return filename;
00297
00298 #if 0
00299 kdDebug() << "Find resource: " << type << endl;
00300 for (QStringList::ConstIterator pit = prefixes.begin();
00301 pit != prefixes.end();
00302 pit++)
00303 {
00304 kdDebug() << "Prefix: " << *pit << endl;
00305 }
00306 #endif
00307
00308 QString dir = findResourceDir(type, filename);
00309 if (dir.isEmpty())
00310 return dir;
00311 else return dir + filename;
00312 }
00313
00314 static Q_UINT32 updateHash(const QString &file, Q_UINT32 hash)
00315 {
00316 QCString cFile = QFile::encodeName(file);
00317 struct stat buff;
00318 if ((access(cFile, R_OK) == 0) &&
00319 (stat( cFile, &buff ) == 0) &&
00320 (S_ISREG( buff.st_mode )))
00321 {
00322 hash = hash + (Q_UINT32) buff.st_ctime;
00323 }
00324 return hash;
00325 }
00326
00327 Q_UINT32 KStandardDirs::calcResourceHash( const char *type,
00328 const QString& filename, bool deep) const
00329 {
00330 Q_UINT32 hash = 0;
00331
00332 if (filename.at(0) == '/')
00333 {
00334
00335 return updateHash(filename, hash);
00336 }
00337 if (d && d->restrictionsActive && (strcmp(type, "data")==0))
00338 applyDataRestrictions(filename);
00339 QStringList candidates = resourceDirs(type);
00340 QString fullPath;
00341
00342 for (QStringList::ConstIterator it = candidates.begin();
00343 it != candidates.end(); it++)
00344 {
00345 hash = updateHash(*it + filename, hash);
00346 if (!deep && hash)
00347 return hash;
00348 }
00349 return hash;
00350 }
00351
00352
00353 QStringList KStandardDirs::findDirs( const char *type,
00354 const QString& reldir ) const
00355 {
00356 QDir testdir;
00357 QStringList list;
00358 if (reldir.startsWith("/"))
00359 {
00360 testdir.setPath(reldir);
00361 if (testdir.exists())
00362 {
00363 if (reldir.endsWith("/"))
00364 list.append(reldir);
00365 else
00366 list.append(reldir+'/');
00367 }
00368 return list;
00369 }
00370
00371 checkConfig();
00372
00373 if (d && d->restrictionsActive && (strcmp(type, "data")==0))
00374 applyDataRestrictions(reldir);
00375 QStringList candidates = resourceDirs(type);
00376
00377 for (QStringList::ConstIterator it = candidates.begin();
00378 it != candidates.end(); it++) {
00379 testdir.setPath(*it + reldir);
00380 if (testdir.exists())
00381 list.append(testdir.absPath() + '/');
00382 }
00383
00384 return list;
00385 }
00386
00387 QString KStandardDirs::findResourceDir( const char *type,
00388 const QString& filename) const
00389 {
00390 #ifndef NDEBUG
00391 if (filename.isEmpty()) {
00392 kdWarning() << "filename for type " << type << " in KStandardDirs::findResourceDir is not supposed to be empty!!" << endl;
00393 return QString::null;
00394 }
00395 #endif
00396
00397 if (d && d->restrictionsActive && (strcmp(type, "data")==0))
00398 applyDataRestrictions(filename);
00399 QStringList candidates = resourceDirs(type);
00400 QString fullPath;
00401
00402 for (QStringList::ConstIterator it = candidates.begin();
00403 it != candidates.end(); it++)
00404 if (exists(*it + filename))
00405 return *it;
00406
00407 #ifndef NDEBUG
00408 if(false && type != "locale")
00409 kdDebug() << "KStdDirs::findResDir(): can't find \"" << filename << "\" in type \"" << type << "\"." << endl;
00410 #endif
00411
00412 return QString::null;
00413 }
00414
00415 bool KStandardDirs::exists(const QString &fullPath)
00416 {
00417 struct stat buff;
00418 if (access(QFile::encodeName(fullPath), R_OK) == 0 && stat( QFile::encodeName(fullPath), &buff ) == 0)
00419 if (fullPath.at(fullPath.length() - 1) != '/') {
00420 if (S_ISREG( buff.st_mode ))
00421 return true;
00422 } else
00423 if (S_ISDIR( buff.st_mode ))
00424 return true;
00425 return false;
00426 }
00427
00428 static void lookupDirectory(const QString& path, const QString &relPart,
00429 const QRegExp ®exp,
00430 QStringList& list,
00431 QStringList& relList,
00432 bool recursive, bool unique)
00433 {
00434 QString pattern = regexp.pattern();
00435 if (recursive || pattern.contains('?') || pattern.contains('*'))
00436 {
00437
00438 DIR *dp = opendir( QFile::encodeName(path));
00439 if (!dp)
00440 return;
00441
00442 assert(path.at(path.length() - 1) == '/');
00443
00444 struct dirent *ep;
00445 struct stat buff;
00446
00447 QString _dot(".");
00448 QString _dotdot("..");
00449
00450 while( ( ep = readdir( dp ) ) != 0L )
00451 {
00452 QString fn( QFile::decodeName(ep->d_name));
00453 if (fn == _dot || fn == _dotdot || fn.at(fn.length() - 1).latin1() == '~')
00454 continue;
00455
00456 if (!recursive && !regexp.exactMatch(fn))
00457 continue;
00458
00459 QString pathfn = path + fn;
00460 if ( stat( QFile::encodeName(pathfn), &buff ) != 0 ) {
00461 kdDebug() << "Error stat'ing " << pathfn << " : " << perror << endl;
00462 continue;
00463 }
00464 if ( recursive ) {
00465 if ( S_ISDIR( buff.st_mode )) {
00466 lookupDirectory(pathfn + '/', relPart + fn + '/', regexp, list, relList, recursive, unique);
00467 }
00468 if (!regexp.exactMatch(fn))
00469 continue;
00470 }
00471 if ( S_ISREG( buff.st_mode))
00472 {
00473 if (!unique || !relList.contains(relPart + fn))
00474 {
00475 list.append( pathfn );
00476 relList.append( relPart + fn );
00477 }
00478 }
00479 }
00480 closedir( dp );
00481 }
00482 else
00483 {
00484
00485 QString fn = pattern;
00486 QString pathfn = path + fn;
00487 struct stat buff;
00488 if ( stat( QFile::encodeName(pathfn), &buff ) != 0 )
00489 return;
00490 if ( S_ISREG( buff.st_mode))
00491 {
00492 if (!unique || !relList.contains(relPart + fn))
00493 {
00494 list.append( pathfn );
00495 relList.append( relPart + fn );
00496 }
00497 }
00498 }
00499 }
00500
00501 static void lookupPrefix(const QString& prefix, const QString& relpath,
00502 const QString& relPart,
00503 const QRegExp ®exp,
00504 QStringList& list,
00505 QStringList& relList,
00506 bool recursive, bool unique)
00507 {
00508 if (relpath.isEmpty()) {
00509 lookupDirectory(prefix, relPart, regexp, list,
00510 relList, recursive, unique);
00511 return;
00512 }
00513 QString path;
00514 QString rest;
00515
00516 if (relpath.length())
00517 {
00518 int slash = relpath.find('/');
00519 if (slash < 0)
00520 rest = relpath.left(relpath.length() - 1);
00521 else {
00522 path = relpath.left(slash);
00523 rest = relpath.mid(slash + 1);
00524 }
00525 }
00526
00527 assert(prefix.at(prefix.length() - 1) == '/');
00528
00529 struct stat buff;
00530
00531 if (path.contains('*') || path.contains('?')) {
00532
00533 QRegExp pathExp(path, true, true);
00534 DIR *dp = opendir( QFile::encodeName(prefix) );
00535 if (!dp) {
00536 return;
00537 }
00538
00539 struct dirent *ep;
00540
00541 QString _dot(".");
00542 QString _dotdot("..");
00543
00544 while( ( ep = readdir( dp ) ) != 0L )
00545 {
00546 QString fn( QFile::decodeName(ep->d_name));
00547 if (fn == _dot || fn == _dotdot || fn.at(fn.length() - 1) == '~')
00548 continue;
00549
00550 if ( !pathExp.exactMatch(fn) )
00551 continue;
00552 QString rfn = relPart+fn;
00553 fn = prefix + fn;
00554 if ( stat( QFile::encodeName(fn), &buff ) != 0 ) {
00555 kdDebug() << "Error statting " << fn << " : " << perror << endl;
00556 continue;
00557 }
00558 if ( S_ISDIR( buff.st_mode ))
00559 lookupPrefix(fn + '/', rest, rfn + '/', regexp, list, relList, recursive, unique);
00560 }
00561
00562 closedir( dp );
00563 } else {
00564
00565
00566 lookupPrefix(prefix + path + '/', rest,
00567 relPart + path + '/', regexp, list,
00568 relList, recursive, unique);
00569 }
00570 }
00571
00572 QStringList
00573 KStandardDirs::findAllResources( const char *type,
00574 const QString& filter,
00575 bool recursive,
00576 bool unique,
00577 QStringList &relList) const
00578 {
00579 QStringList list;
00580 QString filterPath;
00581 QString filterFile;
00582
00583 if (filter.length())
00584 {
00585 int slash = filter.findRev('/');
00586 if (slash < 0)
00587 filterFile = filter;
00588 else {
00589 filterPath = filter.left(slash + 1);
00590 filterFile = filter.mid(slash + 1);
00591 }
00592 }
00593
00594 checkConfig();
00595
00596 QStringList candidates;
00597 if (filterPath.startsWith("/"))
00598 {
00599 filterPath = filterPath.mid(1);
00600 candidates << "/";
00601 }
00602 else
00603 {
00604 if (d && d->restrictionsActive && (strcmp(type, "data")==0))
00605 applyDataRestrictions(filter);
00606 candidates = resourceDirs(type);
00607 }
00608 if (filterFile.isEmpty())
00609 filterFile = "*";
00610
00611 QRegExp regExp(filterFile, true, true);
00612
00613 for (QStringList::ConstIterator it = candidates.begin();
00614 it != candidates.end(); it++)
00615 {
00616 lookupPrefix(*it, filterPath, "", regExp, list,
00617 relList, recursive, unique);
00618 }
00619
00620 return list;
00621 }
00622
00623 QStringList
00624 KStandardDirs::findAllResources( const char *type,
00625 const QString& filter,
00626 bool recursive,
00627 bool unique) const
00628 {
00629 QStringList relList;
00630 return findAllResources(type, filter, recursive, unique, relList);
00631 }
00632
00633 QString
00634 KStandardDirs::realPath(const QString &dirname)
00635 {
00636 char realpath_buffer[MAXPATHLEN + 1];
00637 memset(realpath_buffer, 0, MAXPATHLEN + 1);
00638
00639
00640 if (realpath( QFile::encodeName(dirname).data(), realpath_buffer) != 0) {
00641
00642 int len = strlen(realpath_buffer);
00643 realpath_buffer[len] = '/';
00644 realpath_buffer[len+1] = 0;
00645 return QFile::decodeName(realpath_buffer);
00646 }
00647
00648 return dirname;
00649 }
00650
00651 void KStandardDirs::createSpecialResource(const char *type)
00652 {
00653 char hostname[256];
00654 hostname[0] = 0;
00655 gethostname(hostname, 255);
00656 QString dir = QString("%1%2-%3").arg(localkdedir()).arg(type).arg(hostname);
00657 char link[1024];
00658 link[1023] = 0;
00659 int result = readlink(QFile::encodeName(dir).data(), link, 1023);
00660 bool relink = (result == -1) && (errno == ENOENT);
00661 if ((result > 0) && (link[0] == '/'))
00662 {
00663 link[result] = 0;
00664 struct stat stat_buf;
00665 int res = lstat(link, &stat_buf);
00666 if ((res == -1) && (errno == ENOENT))
00667 {
00668 relink = true;
00669 }
00670 else if ((res == -1) || (!S_ISDIR(stat_buf.st_mode)))
00671 {
00672 fprintf(stderr, "Error: \"%s\" is not a directory.\n", link);
00673 relink = true;
00674 }
00675 else if (stat_buf.st_uid != getuid())
00676 {
00677 fprintf(stderr, "Error: \"%s\" is owned by uid %d instead of uid %d.\n", link, stat_buf.st_uid, getuid());
00678 relink = true;
00679 }
00680 }
00681 if (relink)
00682 {
00683 QString srv = findExe(QString::fromLatin1("lnusertemp"), KDEDIR+QString::fromLatin1("/bin"));
00684 if (srv.isEmpty())
00685 srv = findExe(QString::fromLatin1("lnusertemp"));
00686 if (!srv.isEmpty())
00687 {
00688 system(QFile::encodeName(srv)+" "+type);
00689 result = readlink(QFile::encodeName(dir).data(), link, 1023);
00690 }
00691 }
00692 if (result > 0)
00693 {
00694 link[result] = 0;
00695 if (link[0] == '/')
00696 dir = QFile::decodeName(link);
00697 else
00698 dir = QDir::cleanDirPath(dir+QFile::decodeName(link));
00699 }
00700 addResourceDir(type, dir+'/');
00701 }
00702
00703 QStringList KStandardDirs::resourceDirs(const char *type) const
00704 {
00705 QStringList *candidates = dircache.find(type);
00706
00707 if (!candidates) {
00708 if (strcmp(type, "socket") == 0)
00709 const_cast<KStandardDirs *>(this)->createSpecialResource(type);
00710 else if (strcmp(type, "tmp") == 0)
00711 const_cast<KStandardDirs *>(this)->createSpecialResource(type);
00712 else if (strcmp(type, "cache") == 0)
00713 const_cast<KStandardDirs *>(this)->createSpecialResource(type);
00714
00715 QDir testdir;
00716
00717 candidates = new QStringList();
00718 QStringList *dirs;
00719
00720 bool restrictionActive = false;
00721 if (d && d->restrictionsActive)
00722 {
00723 if (d->dataRestrictionActive)
00724 restrictionActive = true;
00725 else if (d->restrictions["all"])
00726 restrictionActive = true;
00727 else if (d->restrictions[type])
00728 restrictionActive = true;
00729 d->dataRestrictionActive = false;
00730 }
00731
00732 dirs = relatives.find(type);
00733 if (dirs)
00734 {
00735 bool local = true;
00736 const QStringList *prefixList = 0;
00737 if (strncmp(type, "xdgdata-", 8) == 0)
00738 prefixList = &(d->xdgdata_prefixes);
00739 else if (strncmp(type, "xdgconf-", 8) == 0)
00740 prefixList = &(d->xdgconf_prefixes);
00741 else
00742 prefixList = &prefixes;
00743
00744 for (QStringList::ConstIterator pit = prefixList->begin();
00745 pit != prefixList->end();
00746 pit++)
00747 {
00748 for (QStringList::ConstIterator it = dirs->begin();
00749 it != dirs->end(); ++it) {
00750 QString path = realPath(*pit + *it);
00751 testdir.setPath(path);
00752 if (local && restrictionActive)
00753 continue;
00754 if ((local || testdir.exists()) && !candidates->contains(path))
00755 candidates->append(path);
00756 }
00757 local = false;
00758 }
00759 }
00760 dirs = absolutes.find(type);
00761 if (dirs)
00762 for (QStringList::ConstIterator it = dirs->begin();
00763 it != dirs->end(); ++it)
00764 {
00765 testdir.setPath(*it);
00766 if (testdir.exists())
00767 {
00768 QString filename = realPath(*it);
00769 if (!candidates->contains(filename))
00770 candidates->append(filename);
00771 }
00772 }
00773 dircache.insert(type, candidates);
00774 }
00775
00776 #if 0
00777 kdDebug() << "found dirs for resource " << type << ":" << endl;
00778 for (QStringList::ConstIterator pit = candidates->begin();
00779 pit != candidates->end();
00780 pit++)
00781 {
00782 fprintf(stderr, "%s\n", (*pit).latin1());
00783 }
00784 #endif
00785
00786
00787 return *candidates;
00788 }
00789
00790 QStringList KStandardDirs::systemPaths( const QString& pstr )
00791 {
00792 QStringList tokens;
00793 QString p = pstr;
00794
00795 if( p.isNull() )
00796 {
00797 p = getenv( "PATH" );
00798 }
00799
00800 tokenize( tokens, p, ":\b" );
00801
00802 QStringList exePaths;
00803
00804
00805 for( unsigned i = 0; i < tokens.count(); i++ )
00806 {
00807 p = tokens[ i ];
00808
00809 if ( p[ 0 ] == '~' )
00810 {
00811 int len = p.find( '/' );
00812 if ( len == -1 )
00813 len = p.length();
00814 if ( len == 1 )
00815 {
00816 p.replace( 0, 1, QDir::homeDirPath() );
00817 }
00818 else
00819 {
00820 QString user = p.mid( 1, len - 1 );
00821 struct passwd *dir = getpwnam( user.local8Bit().data() );
00822 if ( dir && strlen( dir->pw_dir ) )
00823 p.replace( 0, len, QString::fromLocal8Bit( dir->pw_dir ) );
00824 }
00825 }
00826
00827 exePaths << p;
00828 }
00829
00830 return exePaths;
00831 }
00832
00833
00834 QString KStandardDirs::findExe( const QString& appname,
00835 const QString& pstr, bool ignore)
00836 {
00837 QFileInfo info;
00838
00839
00840 if (appname.startsWith(QString::fromLatin1("/")))
00841 {
00842 info.setFile( appname );
00843 if( info.exists() && ( ignore || info.isExecutable() )
00844 && info.isFile() ) {
00845 return appname;
00846 }
00847 return QString::null;
00848 }
00849
00850 QString p = QString("%1/%2").arg(__KDE_BINDIR).arg(appname);
00851 info.setFile( p );
00852 if( info.exists() && ( ignore || info.isExecutable() )
00853 && ( info.isFile() || info.isSymLink() ) ) {
00854 return p;
00855 }
00856
00857 QStringList exePaths = systemPaths( pstr );
00858 for (QStringList::ConstIterator it = exePaths.begin(); it != exePaths.end(); it++)
00859 {
00860 p = (*it) + "/";
00861 p += appname;
00862
00863
00864 info.setFile( p );
00865
00866 if( info.exists() && ( ignore || info.isExecutable() )
00867 && ( info.isFile() || info.isSymLink() ) ) {
00868 return p;
00869 }
00870 }
00871
00872
00873
00874
00875 return QString::null;
00876 }
00877
00878 int KStandardDirs::findAllExe( QStringList& list, const QString& appname,
00879 const QString& pstr, bool ignore )
00880 {
00881 QFileInfo info;
00882 QString p;
00883 list.clear();
00884
00885 QStringList exePaths = systemPaths( pstr );
00886 for (QStringList::ConstIterator it = exePaths.begin(); it != exePaths.end(); it++)
00887 {
00888 p = (*it) + "/";
00889 p += appname;
00890
00891 info.setFile( p );
00892
00893 if( info.exists() && (ignore || info.isExecutable())
00894 && info.isFile() ) {
00895 list.append( p );
00896 }
00897 }
00898
00899 return list.count();
00900 }
00901
00902 static int tokenize( QStringList& tokens, const QString& str,
00903 const QString& delim )
00904 {
00905 int len = str.length();
00906 QString token = "";
00907
00908 for( int index = 0; index < len; index++)
00909 {
00910 if ( delim.find( str[ index ] ) >= 0 )
00911 {
00912 tokens.append( token );
00913 token = "";
00914 }
00915 else
00916 {
00917 token += str[ index ];
00918 }
00919 }
00920 if ( token.length() > 0 )
00921 {
00922 tokens.append( token );
00923 }
00924
00925 return tokens.count();
00926 }
00927
00928 QString KStandardDirs::kde_default(const char *type) {
00929 QString typeMenu = menu_type_by_version();
00930 if (!strcmp(type, "data"))
00931 return "share/apps/";
00932 if (!strcmp(type, "html"))
00933 return "share/doc/HTML/";
00934 if (!strcmp(type, "icon"))
00935 return "share/icons/";
00936 if (!strcmp(type, "config"))
00937 return "share/config/";
00938 if (!strcmp(type, "pixmap"))
00939 return "share/pixmaps/";
00940 if (!strcmp(type, "apps"))
00941 return "share/applnk/";
00942 if (!strcmp(type, "sound"))
00943 return "share/sounds/";
00944 if (!strcmp(type, "locale"))
00945 return "share/locale/";
00946 if (!strcmp(type, "services"))
00947 return "share/services/";
00948 if (!strcmp(type, "servicetypes"))
00949 return "share/servicetypes/";
00950 if (!strcmp(type, "mime"))
00951 return "share/mimelnk/";
00952 if (!strcmp(type, "cgi"))
00953 return "cgi-bin/";
00954 if (!strcmp(type, "wallpaper"))
00955 return "share/wallpapers/";
00956 if (!strcmp(type, "templates"))
00957 return "share/templates/";
00958 if (!strcmp(type, "exe"))
00959 return "bin/";
00960 if (!strcmp(type, "lib"))
00961 return LIB_NAME "/";
00962 if (!strcmp(type, "module"))
00963 return LIB_NAME "/kde3/";
00964 if (!strcmp(type, "qtplugins"))
00965 return LIB_NAME "/kde3/plugins";
00966 if (!strcmp(type, "xdgdata-apps"))
00967 {
00968 {
00969 if( typeMenu == "kde" )
00970 return "applications/";
00971 else if( typeMenu == "mdk" )
00972 return "applications/";
00973 else if( typeMenu == "mdk-simplified")
00974 return "simplified/applications/";
00975 else
00976 return "applications/";
00977 }
00978 }
00979 if (!strcmp(type, "xdgdata-dirs"))
00980 {
00981 if( typeMenu == "kde" )
00982 return "desktop-directories/";
00983 else if( typeMenu == "mdk" )
00984 return "desktop-directories/";
00985 else if( typeMenu == "mdk-simplified")
00986 return "simplified/desktop-directories/";
00987 else
00988 return "desktop-directories/";
00989 }
00990 if (!strcmp(type, "xdgconf-menu"))
00991 return "menus/";
00992 if (!strcmp(type, "kcfg"))
00993 return "share/config.kcfg";
00994 qFatal("unknown resource type %s", type);
00995 return QString::null;
00996 }
00997
00998 QString KStandardDirs::saveLocation(const char *type,
00999 const QString& suffix,
01000 bool create) const
01001 {
01002 checkConfig();
01003
01004 QString *pPath = savelocations.find(type);
01005 if (!pPath)
01006 {
01007 QStringList *dirs = relatives.find(type);
01008 if (!dirs && (
01009 (strcmp(type, "socket") == 0) ||
01010 (strcmp(type, "tmp") == 0) ||
01011 (strcmp(type, "cache") == 0) ))
01012 {
01013 (void) resourceDirs(type);
01014 dirs = relatives.find(type);
01015 }
01016 if (dirs)
01017 {
01018
01019 if (strncmp(type, "xdgdata-", 8) == 0)
01020 pPath = new QString(realPath(localxdgdatadir() + dirs->last()));
01021 else if (strncmp(type, "xdgconf-", 8) == 0)
01022 pPath = new QString(realPath(localxdgconfdir() + dirs->last()));
01023 else
01024 pPath = new QString(realPath(localkdedir() + dirs->last()));
01025 }
01026 else {
01027 dirs = absolutes.find(type);
01028 if (!dirs)
01029 qFatal("KStandardDirs: The resource type %s is not registered", type);
01030 pPath = new QString(realPath(dirs->last()));
01031 }
01032
01033 savelocations.insert(type, pPath);
01034 }
01035 QString fullPath = *pPath + suffix;
01036
01037 struct stat st;
01038 if (stat(QFile::encodeName(fullPath), &st) != 0 || !(S_ISDIR(st.st_mode))) {
01039 if(!create) {
01040 #ifndef NDEBUG
01041 qDebug("save location %s doesn't exist", fullPath.latin1());
01042 #endif
01043 return fullPath;
01044 }
01045 if(!makeDir(fullPath, 0700)) {
01046 qWarning("failed to create %s", fullPath.latin1());
01047 return fullPath;
01048 }
01049 dircache.remove(type);
01050 }
01051 return fullPath;
01052 }
01053
01054 QString KStandardDirs::relativeLocation(const char *type, const QString &absPath)
01055 {
01056 QString fullPath = absPath;
01057 int i = absPath.findRev('/');
01058 if (i != -1)
01059 {
01060 fullPath = realPath(absPath.left(i+1))+absPath.mid(i+1);
01061 }
01062
01063 QStringList candidates = resourceDirs(type);
01064
01065 for (QStringList::ConstIterator it = candidates.begin();
01066 it != candidates.end(); it++)
01067 if (fullPath.startsWith(*it))
01068 {
01069 return fullPath.mid((*it).length());
01070 }
01071
01072 return absPath;
01073 }
01074
01075
01076 bool KStandardDirs::makeDir(const QString& dir, int mode)
01077 {
01078
01079 if (dir.at(0) != '/')
01080 return false;
01081
01082 QString target = dir;
01083 uint len = target.length();
01084
01085
01086 if (dir.at(len - 1) != '/')
01087 target += '/';
01088
01089 QString base("");
01090 uint i = 1;
01091
01092 while( i < len )
01093 {
01094 struct stat st;
01095 int pos = target.find('/', i);
01096 base += target.mid(i - 1, pos - i + 1);
01097 QCString baseEncoded = QFile::encodeName(base);
01098
01099 if (stat(baseEncoded, &st) != 0)
01100 {
01101
01102
01103 if (lstat(baseEncoded, &st) == 0)
01104 (void)unlink(baseEncoded);
01105
01106 if ( mkdir(baseEncoded, (mode_t) mode) != 0) {
01107 perror("trying to create local folder");
01108 return false;
01109 }
01110 }
01111 i = pos + 1;
01112 }
01113 return true;
01114 }
01115
01116 static QString readEnvPath(const char *env)
01117 {
01118 QCString c_path = getenv(env);
01119 if (c_path.isEmpty())
01120 return QString::null;
01121 return QFile::decodeName(c_path);
01122 }
01123
01124 #ifdef __linux__
01125 static QString executablePrefix()
01126 {
01127 char path_buffer[MAXPATHLEN + 1];
01128 path_buffer[MAXPATHLEN] = 0;
01129 int length = readlink ("/proc/self/exe", path_buffer, MAXPATHLEN);
01130 if (length == -1)
01131 return QString::null;
01132
01133 path_buffer[length] = '\0';
01134
01135 QString path = QFile::decodeName(path_buffer);
01136
01137 if(path.isEmpty())
01138 return QString::null;
01139
01140 int pos = path.findRev('/');
01141 if(pos <= 0)
01142 return QString::null;
01143 pos = path.findRev('/', pos - 1);
01144 if(pos <= 0)
01145 return QString::null;
01146
01147 return path.left(pos);
01148 }
01149 #endif
01150
01151 void KStandardDirs::addKDEDefaults()
01152 {
01153 QStringList kdedirList;
01154
01155
01156 QString kdedirs = readEnvPath("KDEDIRS");
01157 if (!kdedirs.isEmpty())
01158 {
01159 tokenize(kdedirList, kdedirs, ":");
01160 }
01161 else
01162 {
01163 QString kdedir = readEnvPath("KDEDIR");
01164 if (!kdedir.isEmpty())
01165 {
01166 kdedir = KShell::tildeExpand(kdedir);
01167 kdedirList.append(kdedir);
01168 }
01169 }
01170 kdedirList.append(KDEDIR);
01171
01172 #ifdef __KDE_EXECPREFIX
01173 QString execPrefix(__KDE_EXECPREFIX);
01174 if (execPrefix!="NONE")
01175 kdedirList.append(execPrefix);
01176 #endif
01177 #ifdef __linux__
01178 kdedirList.append(executablePrefix());
01179 #endif
01180
01181
01182
01183 QString localKdeDir = readEnvPath(getuid() ? "KDEHOME" : "KDEROOTHOME");
01184 if (!localKdeDir.isEmpty())
01185 {
01186 if (localKdeDir[localKdeDir.length()-1] != '/')
01187 localKdeDir += '/';
01188 }
01189 else
01190 {
01191 localKdeDir = QDir::homeDirPath() + "/.kde/";
01192 }
01193
01194 if (localKdeDir != "-/")
01195 {
01196 localKdeDir = KShell::tildeExpand(localKdeDir);
01197 addPrefix(localKdeDir);
01198 }
01199
01200 for (QStringList::ConstIterator it = kdedirList.begin();
01201 it != kdedirList.end(); it++)
01202 {
01203 QString dir = KShell::tildeExpand(*it);
01204 addPrefix(dir);
01205 }
01206
01207
01208
01209 QStringList xdgdirList;
01210 QString xdgdirs = readEnvPath("XDG_CONFIG_DIRS");
01211 if (!xdgdirs.isEmpty())
01212 {
01213 tokenize(xdgdirList, xdgdirs, ":");
01214 }
01215 else
01216 {
01217 xdgdirList.clear();
01218 xdgdirList.append("/etc/xdg");
01219 xdgdirList.append(KDESYSCONFDIR "/xdg");
01220 }
01221
01222 QString localXdgDir = readEnvPath("XDG_CONFIG_HOME");
01223 if (!localXdgDir.isEmpty())
01224 {
01225 if (localXdgDir[localXdgDir.length()-1] != '/')
01226 localXdgDir += '/';
01227 }
01228 else
01229 {
01230 localXdgDir = QDir::homeDirPath() + "/.config/";
01231 }
01232
01233 localXdgDir = KShell::tildeExpand(localXdgDir);
01234 addXdgConfigPrefix(localXdgDir);
01235
01236 for (QStringList::ConstIterator it = xdgdirList.begin();
01237 it != xdgdirList.end(); it++)
01238 {
01239 QString dir = KShell::tildeExpand(*it);
01240 addXdgConfigPrefix(dir);
01241 }
01242
01243
01244
01245 xdgdirs = readEnvPath("XDG_DATA_DIRS");
01246 if (!xdgdirs.isEmpty())
01247 {
01248 tokenize(xdgdirList, xdgdirs, ":");
01249 }
01250 else
01251 {
01252 xdgdirList.clear();
01253 for (QStringList::ConstIterator it = kdedirList.begin();
01254 it != kdedirList.end(); it++)
01255 {
01256 QString dir = *it;
01257 if (dir[dir.length()-1] != '/')
01258 dir += '/';
01259 xdgdirList.append(dir+"share/");
01260 }
01261
01262 xdgdirList.append("/usr/local/share/");
01263 xdgdirList.append("/usr/share/");
01264 }
01265
01266 localXdgDir = readEnvPath("XDG_DATA_HOME");
01267 if (!localXdgDir.isEmpty())
01268 {
01269 if (localXdgDir[localXdgDir.length()-1] != '/')
01270 localXdgDir += '/';
01271 }
01272 else
01273 {
01274 localXdgDir = QDir::homeDirPath() + "/.local/share/";
01275 }
01276
01277 localXdgDir = KShell::tildeExpand(localXdgDir);
01278 addXdgDataPrefix(localXdgDir);
01279
01280 for (QStringList::ConstIterator it = xdgdirList.begin();
01281 it != xdgdirList.end(); it++)
01282 {
01283 QString dir = KShell::tildeExpand(*it);
01284 addXdgDataPrefix(dir);
01285 }
01286
01287
01288
01289 uint index = 0;
01290 while (types[index] != 0) {
01291 addResourceType(types[index], kde_default(types[index]));
01292 index++;
01293 }
01294
01295 addResourceDir("home", QDir::homeDirPath());
01296 }
01297
01298 void KStandardDirs::checkConfig() const
01299 {
01300 if (!addedCustoms && KGlobal::_instance && KGlobal::_instance->_config)
01301 const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::_instance->_config);
01302 }
01303
01304 static QStringList lookupProfiles(const QString &mapFile)
01305 {
01306 QStringList profiles;
01307
01308 if (mapFile.isEmpty() || !QFile::exists(mapFile))
01309 {
01310 profiles << "default";
01311 return profiles;
01312 }
01313
01314 struct passwd *pw = getpwuid(geteuid());
01315 if (!pw)
01316 {
01317 profiles << "default";
01318 return profiles;
01319 }
01320
01321 QCString user = pw->pw_name;
01322
01323 gid_t sup_gids[512];
01324 int sup_gids_nr = getgroups(512, sup_gids);
01325
01326 KSimpleConfig mapCfg(mapFile, true);
01327 mapCfg.setGroup("Users");
01328 if (mapCfg.hasKey(user.data()))
01329 {
01330 profiles = mapCfg.readListEntry(user.data());
01331 return profiles;
01332 }
01333
01334 mapCfg.setGroup("General");
01335 QStringList groups = mapCfg.readListEntry("groups");
01336
01337 mapCfg.setGroup("Groups");
01338
01339 for( QStringList::ConstIterator it = groups.begin();
01340 it != groups.end(); ++it )
01341 {
01342 QCString grp = (*it).utf8();
01343
01344 struct group *grp_ent = getgrnam(grp);
01345 if (!grp_ent) continue;
01346 gid_t gid = grp_ent->gr_gid;
01347 if (pw->pw_gid == gid)
01348 {
01349
01350 profiles += mapCfg.readListEntry(*it);
01351 }
01352 else
01353 {
01354 for(int i = 0; i < sup_gids_nr; i++)
01355 {
01356 if (sup_gids[i] == gid)
01357 {
01358
01359 profiles += mapCfg.readListEntry(*it);
01360 break;
01361 }
01362 }
01363 }
01364 }
01365
01366 if (profiles.isEmpty())
01367 profiles << "default";
01368 return profiles;
01369 }
01370
01371 extern bool kde_kiosk_admin;
01372
01373 bool KStandardDirs::addCustomized(KConfig *config)
01374 {
01375 if (addedCustoms)
01376 return false;
01377
01378
01379 addedCustoms = true;
01380
01381
01382
01383 uint configdirs = resourceDirs("config").count();
01384
01385
01386 QString oldGroup = config->group();
01387 QString group = QString::fromLatin1("Directories");
01388 config->setGroup(group);
01389
01390 QString kioskAdmin = config->readEntry("kioskAdmin");
01391 if (!kioskAdmin.isEmpty() && !kde_kiosk_admin)
01392 {
01393 int i = kioskAdmin.find(':');
01394 QString user = kioskAdmin.left(i);
01395 QString host = kioskAdmin.mid(i+1);
01396
01397 KUser thisUser;
01398 char hostname[ 256 ];
01399 hostname[ 0 ] = '\0';
01400 if (!gethostname( hostname, 255 ))
01401 hostname[sizeof(hostname)-1] = '\0';
01402
01403 if ((user == thisUser.loginName()) &&
01404 (host.isEmpty() || (host == hostname)))
01405 {
01406 kde_kiosk_admin = true;
01407 }
01408 }
01409
01410 bool readProfiles = true;
01411
01412 if (kde_kiosk_admin && !QCString(getenv("KDE_KIOSK_NO_PROFILES")).isEmpty())
01413 readProfiles = false;
01414
01415 QString userMapFile = config->readEntry("userProfileMapFile");
01416 QString profileDirsPrefix = config->readEntry("profileDirsPrefix");
01417 if (!profileDirsPrefix.isEmpty() && !profileDirsPrefix.endsWith("/"))
01418 profileDirsPrefix.append('/');
01419
01420 QStringList profiles;
01421 if (readProfiles)
01422 profiles = lookupProfiles(userMapFile);
01423 QString profile;
01424
01425 bool priority = false;
01426 while(true)
01427 {
01428 config->setGroup(group);
01429 QStringList list = config->readListEntry("prefixes");
01430 for (QStringList::ConstIterator it = list.begin(); it != list.end(); it++)
01431 {
01432 addPrefix(*it, priority);
01433 addXdgConfigPrefix(*it+"/etc/xdg", priority);
01434 addXdgDataPrefix(*it+"/share", priority);
01435 }
01436
01437
01438 if (list.isEmpty() && !profile.isEmpty() && !profileDirsPrefix.isEmpty())
01439 {
01440 QString dir = profileDirsPrefix + profile;
01441 addPrefix(dir, priority);
01442 addXdgConfigPrefix(dir+"/etc/xdg", priority);
01443 addXdgDataPrefix(dir+"/share", priority);
01444 }
01445
01446
01447
01448 QMap<QString, QString> entries = config->entryMap(group);
01449 for (QMap<QString, QString>::ConstIterator it2 = entries.begin();
01450 it2 != entries.end(); it2++)
01451 {
01452 QString key = it2.key();
01453 if (key.startsWith("dir_")) {
01454
01455 QStringList dirs = QStringList::split(',',
01456 *it2);
01457 QStringList::Iterator sIt(dirs.begin());
01458 QString resType = key.mid(4, key.length());
01459 for (; sIt != dirs.end(); ++sIt) {
01460 addResourceDir(resType.latin1(), *sIt, priority);
01461 }
01462 }
01463 }
01464 if (profiles.isEmpty())
01465 break;
01466 profile = profiles.back();
01467 group = QString::fromLatin1("Directories-%1").arg(profile);
01468 profiles.pop_back();
01469 priority = true;
01470 }
01471
01472
01473 if (!kde_kiosk_admin || QCString(getenv("KDE_KIOSK_NO_RESTRICTIONS")).isEmpty())
01474 {
01475 config->setGroup("KDE Resource Restrictions");
01476 QMap<QString, QString> entries = config->entryMap("KDE Resource Restrictions");
01477 for (QMap<QString, QString>::ConstIterator it2 = entries.begin();
01478 it2 != entries.end(); it2++)
01479 {
01480 QString key = it2.key();
01481 if (!config->readBoolEntry(key, true))
01482 {
01483 d->restrictionsActive = true;
01484 d->restrictions.insert(key.latin1(), &d->restrictionsActive);
01485 dircache.remove(key.latin1());
01486 }
01487 }
01488 }
01489
01490 config->setGroup(oldGroup);
01491
01492
01493 return (resourceDirs("config").count() != configdirs);
01494 }
01495
01496 QString KStandardDirs::localkdedir() const
01497 {
01498
01499 return prefixes.first();
01500 }
01501
01502 QString KStandardDirs::localxdgdatadir() const
01503 {
01504
01505 return d->xdgdata_prefixes.first();
01506 }
01507
01508 QString KStandardDirs::localxdgconfdir() const
01509 {
01510
01511 return d->xdgconf_prefixes.first();
01512 }
01513
01514
01515
01516 QString locate( const char *type,
01517 const QString& filename, const KInstance* inst )
01518 {
01519 return inst->dirs()->findResource(type, filename);
01520 }
01521
01522 QString locateLocal( const char *type,
01523 const QString& filename, const KInstance* inst )
01524 {
01525 return locateLocal(type, filename, true, inst);
01526 }
01527
01528 QString locateLocal( const char *type,
01529 const QString& filename, bool createDir, const KInstance* inst )
01530 {
01531
01532
01533 int slash = filename.findRev('/')+1;
01534 if (!slash)
01535 return inst->dirs()->saveLocation(type, QString::null, createDir) + filename;
01536
01537
01538 QString dir = filename.left(slash);
01539 QString file = filename.mid(slash);
01540 return inst->dirs()->saveLocation(type, dir, createDir) + file;
01541 }
01542
01543
01544 QString KStandardDirs::menu_type_by_version()
01545 {
01546 QString kde_menu;
01547 kde_menu=QString("/etc/menu/disable_mdk_customization");
01548
01549 QString mdk_menu_simplified;
01550 mdk_menu_simplified=QString("/etc/menu/enable_simplified");
01551
01552 QString mdk_kde_menu_users=QDir::homeDirPath ()+"/"+".menu/"+QString("enable_mdk_customization");
01553 QString kde_menu_users=QDir::homeDirPath ()+"/"+".menu/"+QString("disable_mdk_customization");
01554 QString mdk_menu_simplified_users=QDir::homeDirPath ()+"/"+".menu/"+QString("enable_simplified");
01555
01556 if( getuid()==0)
01557 {
01558 if( QFile(kde_menu_users).exists())
01559 return "kde";
01560 else if(QFile(mdk_kde_menu_users).exists())
01561 return "mdk";
01562 else if(QFile(mdk_menu_simplified_users).exists())
01563 return "mdk-simplified";
01564 else
01565 {
01566 if (QFile(kde_menu).exists())
01567 return "kde";
01568 else if(QFile(mdk_menu_simplified).exists())
01569 return "mdk-simplified";
01570 else
01571 return default_menu_type_by_version();
01572 }
01573 }
01574 else
01575 {
01576 QString path;
01577 if( QFile(kde_menu_users).exists())
01578 path="kde";
01579 else if(QFile(mdk_kde_menu_users).exists())
01580 path="mdk";
01581 else if(QFile(mdk_menu_simplified_users).exists())
01582 path="mdk-simplified";
01583 else if(QFile(kde_menu).exists())
01584 path="kde";
01585 else if(QFile(mdk_menu_simplified).exists())
01586 path="mdk-simplified";
01587 else
01588 path=default_menu_type_by_version();
01589 return path;
01590 }
01591 return QString("mdk");
01592 }
01593
01594 QString KStandardDirs::default_menu_type_by_version()
01595 {
01596 QFile file( "/etc/sysconfig/system" );
01597 if( file.exists())
01598 {
01599 QString menuType("mdk");
01600 if ( file.open( IO_ReadOnly ) ) {
01601 QTextStream stream( &file );
01602 QString line;
01603 while ( !stream.atEnd() )
01604 {
01605 line = stream.readLine();
01606 if( line.contains("META_CLASS=PowerPack")!=0)
01607 {
01608 menuType = "mdk";
01609 break;
01610 }
01611 else if( line.contains("META_CLASS=desktop")!=0)
01612 {
01613 menuType = "mdk-simplified";
01614 break;
01615 }
01616 else if( line.contains("META_CLASS=server")!=0)
01617 {
01618 menuType = "mdk";
01619 break;
01620 }
01621 }
01622 file.close();
01623 return menuType;
01624 }
01625 }
01626 return QString("kde");
01627 }
01628
01629
01630 KStandardDirs::distroVersionType KStandardDirs::mandrake_distro_version()
01631 {
01632 QFile file( "/etc/sysconfig/system" );
01633 if( file.exists())
01634 {
01635 KStandardDirs::distroVersionType type=DOWNLOAD;
01636 if ( file.open( IO_ReadOnly ) ) {
01637 QTextStream stream( &file );
01638 QString line;
01639 while ( !stream.atEnd() )
01640 {
01641 line = stream.readLine();
01642 if( (line.contains("META_CLASS=PowerPack")!=0) || (line.contains("META_CLASS=powerpack")!=0))
01643 {
01644 type = POWERPACK;
01645 break;
01646 }
01647 else if( line.contains("META_CLASS=desktop")!=0)
01648 {
01649 type = DISCOVERY;
01650 break;
01651 }
01652 else if( line.contains("META_CLASS=server")!=0)
01653 {
01654 type = POWERPACKPLUS;
01655 break;
01656 }
01657 }
01658 file.close();
01659 return type;
01660 }
01661 }
01662 return DOWNLOAD;
01663 }
01664
01665 QString KStandardDirs::mandrake_merge_directory()
01666 {
01667 return QDir::homeDirPath() + "/.kde/DESKTOP_ENTRY/";
01668 }