author | ulf69 <ulf69> | 2004-08-05 21:42:29 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-08-05 21:42:29 (UTC) |
commit | 6ee7d4f5119837f89ec534c8c5c73845d521e135 (patch) (side-by-side diff) | |
tree | 265d25e37da63a00ae3302059c2c628efb57b570 | |
parent | c3a704f5acda9cf9fee66e5c0b1b864f3b7dd852 (diff) | |
download | kdepimpi-6ee7d4f5119837f89ec534c8c5c73845d521e135.zip kdepimpi-6ee7d4f5119837f89ec534c8c5c73845d521e135.tar.gz kdepimpi-6ee7d4f5119837f89ec534c8c5c73845d521e135.tar.bz2 |
added tmp as a resourcetype. KDE handled tmp differently, but we do not need
the special handling. So i simply added it as standard resource type
-rw-r--r-- | microkde/kdecore/kstandarddirs.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/microkde/kdecore/kstandarddirs.cpp b/microkde/kdecore/kstandarddirs.cpp index e1c78f6..75205d6 100644 --- a/microkde/kdecore/kstandarddirs.cpp +++ b/microkde/kdecore/kstandarddirs.cpp @@ -1,606 +1,606 @@ /* This file is part of the KDE libraries Copyright (C) 1999 Sirtaj Singh Kang <taj@kde.org> Copyright (C) 1999 Stephan Kulow <coolo@kde.org> Copyright (C) 1999 Waldo Bastian <bastian@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Author: Stephan Kulow <coolo@kde.org> and Sirtaj Singh Kang <taj@kde.org> * Version: $Id$ * Generated: Thu Mar 5 16:05:28 EST 1998 */ //US #include "config.h" #include <stdlib.h> #include <assert.h> //US#include <errno.h> //US #ifdef HAVE_SYS_STAT_H //US #include <sys/stat.h> //US #endif //US#include <sys/types.h> //US#include <dirent.h> //US#include <pwd.h> #include <qregexp.h> #include <qasciidict.h> #include <qdict.h> #include <qdir.h> #include <qfileinfo.h> #include <qstring.h> #include <qapplication.h> #include <qstringlist.h> #include "kstandarddirs.h" #include "kconfig.h" #include "kdebug.h" //US #include "kinstance.h" #include "kshell.h" //US#include <sys/param.h> //US#include <unistd.h> //US QString KStandardDirs::mAppDir = QString::null; template class QDict<QStringList>; #if 0 #include <qtextedit.h> void ddd( QString op ) { static QTextEdit * dot = 0; if ( ! dot ) dot = new QTextEdit(); dot->show(); dot->append( op ); } #endif class KStandardDirs::KStandardDirsPrivate { public: KStandardDirsPrivate() : restrictionsActive(false), dataRestrictionActive(false) { } bool restrictionsActive; bool dataRestrictionActive; QAsciiDict<bool> restrictions; QStringList xdgdata_prefixes; QStringList xdgconf_prefixes; }; static const char* const types[] = {"html", "icon", "apps", "sound", "data", "locale", "services", "mime", - "servicetypes", "config", "exe", + "servicetypes", "config", "exe", "tmp", "wallpaper", "lib", "pixmap", "templates", "module", "qtplugins", "xdgdata-apps", "xdgdata-dirs", "xdgconf-menu", 0 }; static int tokenize( QStringList& token, const QString& str, const QString& delim ); KStandardDirs::KStandardDirs( ) : addedCustoms(false) { d = new KStandardDirsPrivate; dircache.setAutoDelete(true); relatives.setAutoDelete(true); absolutes.setAutoDelete(true); savelocations.setAutoDelete(true); addKDEDefaults(); } KStandardDirs::~KStandardDirs() { delete d; } bool KStandardDirs::isRestrictedResource(const char *type, const QString& relPath) const { if (!d || !d->restrictionsActive) return false; if (d->restrictions[type]) return true; if (strcmp(type, "data")==0) { applyDataRestrictions(relPath); if (d->dataRestrictionActive) { d->dataRestrictionActive = false; return true; } } return false; } void KStandardDirs::applyDataRestrictions(const QString &relPath) const { QString key; int i = relPath.find('/'); if (i != -1) key = "data_"+relPath.left(i); else key = "data_"+relPath; if (d && d->restrictions[key.latin1()]) d->dataRestrictionActive = true; } QStringList KStandardDirs::allTypes() const { QStringList list; for (int i = 0; types[i] != 0; ++i) list.append(QString::fromLatin1(types[i])); return list; } void KStandardDirs::addPrefix( const QString& _dir ) { if (_dir.isNull()) return; QString dir = _dir; if (dir.at(dir.length() - 1) != '/') dir += '/'; if (!prefixes.contains(dir)) { prefixes.append(dir); dircache.clear(); } } void KStandardDirs::addXdgConfigPrefix( const QString& _dir ) { if (_dir.isNull()) return; QString dir = _dir; if (dir.at(dir.length() - 1) != '/') dir += '/'; if (!d->xdgconf_prefixes.contains(dir)) { d->xdgconf_prefixes.append(dir); dircache.clear(); } } void KStandardDirs::addXdgDataPrefix( const QString& _dir ) { if (_dir.isNull()) return; QString dir = _dir; if (dir.at(dir.length() - 1) != '/') dir += '/'; if (!d->xdgdata_prefixes.contains(dir)) { d->xdgdata_prefixes.append(dir); dircache.clear(); } } QString KStandardDirs::kfsstnd_prefixes() { return prefixes.join(":"); } bool KStandardDirs::addResourceType( const char *type, const QString& relativename ) { if (relativename.isNull()) return false; QStringList *rels = relatives.find(type); if (!rels) { rels = new QStringList(); relatives.insert(type, rels); } QString copy = relativename; if (copy.at(copy.length() - 1) != '/') copy += '/'; if (!rels->contains(copy)) { rels->prepend(copy); dircache.remove(type); // clean the cache return true; } return false; } bool KStandardDirs::addResourceDir( const char *type, const QString& absdir) { QStringList *paths = absolutes.find(type); if (!paths) { paths = new QStringList(); absolutes.insert(type, paths); } QString copy = absdir; if (copy.at(copy.length() - 1) != '/') copy += '/'; if (!paths->contains(copy)) { paths->append(copy); dircache.remove(type); // clean the cache return true; } return false; } QString KStandardDirs::findResource( const char *type, const QString& filename ) const { if (filename.at(0) == '/') return filename; // absolute dirs are absolute dirs, right? :-/ #if 0 kdDebug() << "Find resource: " << type << endl; for (QStringList::ConstIterator pit = prefixes.begin(); pit != prefixes.end(); pit++) { kdDebug() << "Prefix: " << *pit << endl; } #endif QString dir = findResourceDir(type, filename); if (dir.isNull()) return dir; else return dir + filename; } /*US static Q_UINT32 updateHash(const QString &file, Q_UINT32 hash) { QCString cFile = QFile::encodeName(file); //US struct stat buff; //US if ((access(cFile, R_OK) == 0) && //US (stat( cFile, &buff ) == 0) && //US (S_ISREG( buff.st_mode ))) QFileInfo pathfnInfo(cFile); if (( pathfnInfo.isReadable() == true ) && ( pathfnInfo.isFile()) ) { //US hash = hash + (Q_UINT32) buff.st_ctime; hash = hash + (Q_UINT32) pathfnInfo.lastModified(); } return hash; } */ /*US Q_UINT32 KStandardDirs::calcResourceHash( const char *type, const QString& filename, bool deep) const { Q_UINT32 hash = 0; if (filename.at(0) == '/') { // absolute dirs are absolute dirs, right? :-/ return updateHash(filename, hash); } if (d && d->restrictionsActive && (strcmp(type, "data")==0)) applyDataRestrictions(filename); QStringList candidates = resourceDirs(type); QString fullPath; for (QStringList::ConstIterator it = candidates.begin(); it != candidates.end(); it++) { hash = updateHash(*it + filename, hash); if (!deep && hash) return hash; } return hash; } */ QStringList KStandardDirs::findDirs( const char *type, const QString& reldir ) const { QStringList list; checkConfig(); if (d && d->restrictionsActive && (strcmp(type, "data")==0)) applyDataRestrictions(reldir); QStringList candidates = resourceDirs(type); QDir testdir; for (QStringList::ConstIterator it = candidates.begin(); it != candidates.end(); it++) { testdir.setPath(*it + reldir); if (testdir.exists()) list.append(testdir.absPath() + '/'); } return list; } QString KStandardDirs::findResourceDir( const char *type, const QString& filename) const { #ifndef NDEBUG if (filename.isEmpty()) { kdWarning() << "filename for type " << type << " in KStandardDirs::findResourceDir is not supposed to be empty!!" << endl; return QString::null; } #endif if (d && d->restrictionsActive && (strcmp(type, "data")==0)) applyDataRestrictions(filename); QStringList candidates = resourceDirs(type); QString fullPath; #ifdef DESKTOP_VERSION #ifdef _WIN32_ candidates.prepend( qApp->applicationDirPath () +"\\"); #else candidates.prepend( qApp->applicationDirPath () +"/"); #endif #endif for (QStringList::ConstIterator it = candidates.begin(); it != candidates.end(); it++) { //qDebug("looking for dir %s - file %s", (*it).latin1(), filename.latin1()); if (exists(*it + filename)) return *it; } #ifndef NDEBUG if(false && type != "locale") qDebug("KStdDirs::findResDir(): can't find %s ", filename.latin1()); #endif return QString::null; } bool KStandardDirs::exists(const QString &fullPath) { //US struct stat buff; QFileInfo fullPathInfo(QFile::encodeName(fullPath)); //US if (access(QFile::encodeName(fullPath), R_OK) == 0 && fullPathInfo.isReadable()) if (fullPathInfo.isReadable()) { if (fullPath.at(fullPath.length() - 1) != '/') { //US if (S_ISREG( buff.st_mode )) if (fullPathInfo.isFile()) return true; } else { //US if (S_ISDIR( buff.st_mode )) if (fullPathInfo.isDir()) return true; } } return false; } static void lookupDirectory(const QString& path, const QString &relPart, const QRegExp ®exp, QStringList& list, QStringList& relList, bool recursive, bool uniq) { QString pattern = regexp.pattern(); if (recursive || pattern.contains('?') || pattern.contains('*')) { // We look for a set of files. //US DIR *dp = opendir( QFile::encodeName(path)); QDir dp(QFile::encodeName(path)); if (!dp.exists()) return; static int iii = 0; ++iii; if ( iii == 5 ) abort(); assert(path.at(path.length() - 1) == '/'); //US struct dirent *ep; //US struct stat buff; QString _dot("."); QString _dotdot(".."); //US while( ( ep = readdir( dp ) ) != 0L ) QStringList direntries = dp.entryList(); QStringList::Iterator it = direntries.begin(); while ( it != list.end() ) // for each file... { //US QString fn( QFile::decodeName(ep->d_name)); QString fn = (*it); // dp.entryList already decodes it++; if ( fn.isNull() ) break; if (fn == _dot || fn == _dotdot || fn.at(fn.length() - 1).latin1() == '~' ) continue; /*US if (!recursive && !regexp.exactMatch(fn)) continue; // No match */ //US this should do the same: int pos = regexp.match(fn); if (!recursive && !pos == 0) continue; // No match QString pathfn = path + fn; /*US if ( stat( QFile::encodeName(pathfn), &buff ) != 0 ) { kdDebug() << "Error stat'ing " << pathfn << " : " << perror << endl; continue; // Couldn't stat (e.g. no read permissions) } if ( recursive ) { if ( S_ISDIR( buff.st_mode )) { lookupDirectory(pathfn + '/', relPart + fn + '/', regexp, list, relList, recursive, uniq); } */ //US replacement: QFileInfo pathfnInfo(QFile::encodeName(pathfn)); if ( pathfnInfo.isReadable() == false ) { //US kdDebug() << "Error stat'ing " << pathfn << " : " << perror << endl; continue; // Couldn't stat (e.g. no read permissions) } if ( recursive ) { if ( pathfnInfo.isDir()) { lookupDirectory(pathfn + '/', relPart + fn + '/', regexp, list, relList, recursive, uniq); } /*US if (!regexp.exactMatch(fn)) continue; // No match */ //US this should do the same: pos = regexp.match(fn); if (!pos == 0) continue; // No match } //US if ( S_ISREG( buff.st_mode)) if ( pathfnInfo.isFile()) { if (!uniq || !relList.contains(relPart + fn)) { list.append( pathfn ); relList.append( relPart + fn ); } } } //US closedir( dp ); } else { // We look for a single file. QString fn = pattern; QString pathfn = path + fn; //US struct stat buff; QFileInfo pathfnInfo(QFile::encodeName(pathfn)); //US if ( stat( QFile::encodeName(pathfn), &buff ) != 0 ) if ( pathfnInfo.isReadable() == false ) return; // File not found //US if ( S_ISREG( buff.st_mode)) if ( pathfnInfo.isFile()) { if (!uniq || !relList.contains(relPart + fn)) { list.append( pathfn ); relList.append( relPart + fn ); } } } } static void lookupPrefix(const QString& prefix, const QString& relpath, const QString& relPart, const QRegExp ®exp, QStringList& list, QStringList& relList, bool recursive, bool uniq) { if (relpath.isNull()) { lookupDirectory(prefix, relPart, regexp, list, relList, recursive, uniq); return; } QString path; QString rest; if (relpath.length()) { int slash = relpath.find('/'); if (slash < 0) rest = relpath.left(relpath.length() - 1); else { path = relpath.left(slash); rest = relpath.mid(slash + 1); } } assert(prefix.at(prefix.length() - 1) == '/'); //US struct stat buff; if (path.contains('*') || path.contains('?')) { QRegExp pathExp(path, true, true); //US DIR *dp = opendir( QFile::encodeName(prefix) ); QDir dp(QFile::encodeName(prefix)); //US if (!dp) if (!dp.exists()) { return; } //US struct dirent *ep; QString _dot("."); QString _dotdot(".."); //US while( ( ep = readdir( dp ) ) != 0L ) QStringList direntries = dp.entryList(); QStringList::Iterator it = direntries.begin(); while ( it != list.end() ) // for each file... { //US QString fn( QFile::decodeName(ep->d_name)); QString fn = (*it); // dp.entryList() already encodes the strings it++; if (fn == _dot || fn == _dotdot || fn.at(fn.length() - 1) == '~') continue; #ifdef DESKTOP_VERSION if (pathExp.search(fn) == -1) continue; // No match #else //US this should do the same: if (pathExp.find(fn, 0) == -1) continue; // No match #endif QString rfn = relPart+fn; fn = prefix + fn; //US if ( stat( QFile::encodeName(fn), &buff ) != 0 ) QFileInfo fnInfo(QFile::encodeName(fn)); if ( fnInfo.isReadable() == false ) { //US kdDebug() << "Error statting " << fn << " : " << perror << endl; continue; // Couldn't stat (e.g. no permissions) } //US if ( S_ISDIR( buff.st_mode )) if ( fnInfo.isDir() ) lookupPrefix(fn + '/', rest, rfn + '/', regexp, list, relList, recursive, uniq); |