QStringList KStandardDirs::findDirs( const char *type, const QString& reldir ) const { QDir testdir; QStringList list; if (!QDir::isRelativePath(reldir)) { testdir.setPath(reldir); if (testdir.exists()) { if (reldir.endsWith("/")) list.append(reldir); else list.append(reldir+'/'); } return list; } checkConfig(); if (d && d->restrictionsActive && (strcmp(type, "data")==0)) applyDataRestrictions(reldir); QStringList candidates = resourceDirs(type); 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; for(QStringList::ConstIterator it = candidates.begin(); it != candidates.end(); ++it) { if(exists(*it + filename)) { return *it; } } #ifndef NDEBUG if(false && strcmp(type, "locale")) kdDebug() << "KStdDirs::findResDir(): can't find \"" << filename << "\" in type \"" << type << "\"." << endl; #endif return QString::null; }
QStringList KStandardDirs::findAllResources( const char *type, const QString& filter, bool recursive, bool unique, QStringList &relList) const { QStringList list; QString filterPath; QString filterFile; if (filter.length()) { int slash = filter.findRev('/'); if (slash < 0) filterFile = filter; else { filterPath = filter.left(slash + 1); filterFile = filter.mid(slash + 1); } } checkConfig(); QStringList candidates; if (!QDir::isRelativePath(filter)) // absolute path { #ifdef Q_OS_WIN candidates << filterPath.left(3); //e.g. "C:\" filterPath = filterPath.mid(3); #else candidates << "/"; filterPath = filterPath.mid(1); #endif } else { if (d && d->restrictionsActive && (strcmp(type, "data")==0)) applyDataRestrictions(filter); candidates = resourceDirs(type); } if (filterFile.isEmpty()) filterFile = "*"; QRegExp regExp(filterFile, true, true); for (QStringList::ConstIterator it = candidates.begin(); it != candidates.end(); ++it) { lookupPrefix(*it, filterPath, "", regExp, list, relList, recursive, unique); } return list; }
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; }
Q_UINT32 KStandardDirs::calcResourceHash(const char *type, const QString &filename, bool deep) const { Q_UINT32 hash = 0; if(!QDir::isRelativePath(filename)) { // 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; }
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; for (QStringList::ConstIterator it = candidates.begin(); it != candidates.end(); ++it) { if (exists(*it + filename)) { #ifdef Q_WS_WIN //this ensures we're using installed .la files if ((*it).isEmpty() && filename.right(3)==".la") { #ifndef NDEBUG kdDebug() << "KStandardDirs::findResourceDir() found .la in cwd: skipping. (fname=" << filename << ")" << endl; #endif continue; } #endif //Q_WS_WIN return *it; } } #ifndef NDEBUG if(false && strcmp(type, "locale")) kdDebug() << "KStdDirs::findResDir(): can't find \"" << filename << "\" in type \"" << type << "\"." << endl; #endif return QString::null; }