summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdecore/kstandarddirs.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/microkde/kdecore/kstandarddirs.cpp b/microkde/kdecore/kstandarddirs.cpp
index 75205d6..500426b 100644
--- a/microkde/kdecore/kstandarddirs.cpp
+++ b/microkde/kdecore/kstandarddirs.cpp
@@ -737,512 +737,515 @@ QStringList KStandardDirs::resourceDirs(const char *type) const
const_cast<KStandardDirs *>(this)->createSpecialResource(type);
else if (strcmp(type, "tmp") == 0)
const_cast<KStandardDirs *>(this)->createSpecialResource(type);
else if (strcmp(type, "cache") == 0)
const_cast<KStandardDirs *>(this)->createSpecialResource(type);
*/
QDir testdir;
candidates = new QStringList();
QStringList *dirs;
bool restrictionActive = false;
if (d && d->restrictionsActive)
{
if (d->dataRestrictionActive)
restrictionActive = true;
else if (d->restrictions["all"])
restrictionActive = true;
else if (d->restrictions[type])
restrictionActive = true;
d->dataRestrictionActive = false; // Reset
}
dirs = relatives.find(type);
if (dirs)
{
bool local = true;
const QStringList *prefixList = 0;
if (strncmp(type, "xdgdata-", 8) == 0)
prefixList = &(d->xdgdata_prefixes);
else if (strncmp(type, "xdgconf-", 8) == 0)
prefixList = &(d->xdgconf_prefixes);
else
prefixList = &prefixes;
for (QStringList::ConstIterator pit = prefixList->begin();
pit != prefixList->end();
pit++)
{
for (QStringList::ConstIterator it = dirs->begin();
it != dirs->end(); ++it) {
QString path = realPath(*pit + *it);
testdir.setPath(path);
if (local && restrictionActive)
continue;
if ((local || testdir.exists()) && !candidates->contains(path))
candidates->append(path);
}
local = false;
}
}
dirs = absolutes.find(type);
if (dirs)
for (QStringList::ConstIterator it = dirs->begin();
it != dirs->end(); ++it)
{
testdir.setPath(*it);
if (testdir.exists())
{
QString filename = realPath(*it);
if (!candidates->contains(filename))
candidates->append(filename);
}
}
dircache.insert(type, candidates);
}
#if 0
kdDebug() << "found dirs for resource " << type << ":" << endl;
for (QStringList::ConstIterator pit = candidates->begin();
pit != candidates->end();
pit++)
{
fprintf(stderr, "%s\n", (*pit).latin1());
}
#endif
return *candidates;
}
/*US
QString KStandardDirs::findExe( const QString& appname,
const QString& pstr, bool ignore)
{
QFileInfo info;
// absolute path ?
if (appname.startsWith(QString::fromLatin1("/")))
{
info.setFile( appname );
if( info.exists() && ( ignore || info.isExecutable() )
&& info.isFile() ) {
return appname;
}
return QString::null;
}
//US QString p = QString("%1/%2").arg(__KDE_BINDIR).arg(appname);
QString p = QString("%1/%2").arg(appname).arg(appname);
qDebug("KStandardDirs::findExe this is probably wrong");
info.setFile( p );
if( info.exists() && ( ignore || info.isExecutable() )
&& ( info.isFile() || info.isSymLink() ) ) {
return p;
}
QStringList tokens;
p = pstr;
if( p.isNull() ) {
p = getenv( "PATH" );
}
tokenize( tokens, p, ":\b" );
// split path using : or \b as delimiters
for( unsigned i = 0; i < tokens.count(); i++ ) {
p = tokens[ i ];
if ( p[ 0 ] == '~' )
{
int len = p.find( '/' );
if ( len == -1 )
len = p.length();
if ( len == 1 )
p.replace( 0, 1, QDir::homeDirPath() );
else
{
QString user = p.mid( 1, len - 1 );
struct passwd *dir = getpwnam( user.local8Bit().data() );
if ( dir && strlen( dir->pw_dir ) )
p.replace( 0, len, QString::fromLocal8Bit( dir->pw_dir ) );
}
}
p += "/";
p += appname;
// Check for executable in this tokenized path
info.setFile( p );
if( info.exists() && ( ignore || info.isExecutable() )
&& ( info.isFile() || info.isSymLink() ) ) {
return p;
}
}
// If we reach here, the executable wasn't found.
// So return empty string.
return QString::null;
}
int KStandardDirs::findAllExe( QStringList& list, const QString& appname,
const QString& pstr, bool ignore )
{
QString p = pstr;
QFileInfo info;
QStringList tokens;
if( p.isNull() ) {
p = getenv( "PATH" );
}
list.clear();
tokenize( tokens, p, ":\b" );
for ( unsigned i = 0; i < tokens.count(); i++ ) {
p = tokens[ i ];
p += "/";
p += appname;
info.setFile( p );
if( info.exists() && (ignore || info.isExecutable())
&& info.isFile() ) {
list.append( p );
}
}
return list.count();
}
*/
static int tokenize( QStringList& tokens, const QString& str,
const QString& delim )
{
int len = str.length();
QString token = "";
for( int index = 0; index < len; index++)
{
if ( delim.find( str[ index ] ) >= 0 )
{
tokens.append( token );
token = "";
}
else
{
token += str[ index ];
}
}
if ( token.length() > 0 )
{
tokens.append( token );
}
return tokens.count();
}
QString KStandardDirs::kde_default(const char *type) {
if (!strcmp(type, "data"))
return "apps/";
if (!strcmp(type, "html"))
return "share/doc/HTML/";
if (!strcmp(type, "icon"))
return "share/icons/";
if (!strcmp(type, "config"))
return "config/";
if (!strcmp(type, "pixmap"))
return "share/pixmaps/";
if (!strcmp(type, "apps"))
return "share/applnk/";
if (!strcmp(type, "sound"))
return "share/sounds/";
if (!strcmp(type, "locale"))
return "share/locale/";
if (!strcmp(type, "services"))
return "share/services/";
if (!strcmp(type, "servicetypes"))
return "share/servicetypes/";
if (!strcmp(type, "mime"))
return "share/mimelnk/";
if (!strcmp(type, "cgi"))
return "cgi-bin/";
if (!strcmp(type, "wallpaper"))
return "share/wallpapers/";
if (!strcmp(type, "templates"))
return "share/templates/";
if (!strcmp(type, "exe"))
return "bin/";
if (!strcmp(type, "lib"))
return "lib/";
if (!strcmp(type, "module"))
return "lib/kde3/";
if (!strcmp(type, "qtplugins"))
return "lib/kde3/plugins";
if (!strcmp(type, "xdgdata-apps"))
return "applications/";
if (!strcmp(type, "xdgdata-dirs"))
return "desktop-directories/";
if (!strcmp(type, "xdgconf-menu"))
return "menus/";
+ if (!strcmp(type, "tmp"))
+ return "tmp/";
+
qFatal("unknown resource type %s", type);
return QString::null;
}
QString KStandardDirs::saveLocation(const char *type,
const QString& suffix,
bool create) const
{
//qDebug("KStandardDirs::saveLocation called %s %s", type,suffix.latin1() );
//return "";
checkConfig();
QString *pPath = savelocations.find(type);
if (!pPath)
{
QStringList *dirs = relatives.find(type);
if (!dirs && (
(strcmp(type, "socket") == 0) ||
(strcmp(type, "tmp") == 0) ||
(strcmp(type, "cache") == 0) ))
{
(void) resourceDirs(type); // Generate socket|tmp|cache resource.
dirs = relatives.find(type); // Search again.
}
if (dirs)
{
// Check for existance of typed directory + suffix
if (strncmp(type, "xdgdata-", 8) == 0)
pPath = new QString(realPath(localxdgdatadir() + dirs->last()));
else if (strncmp(type, "xdgconf-", 8) == 0)
pPath = new QString(realPath(localxdgconfdir() + dirs->last()));
else
pPath = new QString(realPath(localkdedir() + dirs->last()));
}
else {
dirs = absolutes.find(type);
if (!dirs)
qFatal("KStandardDirs: The resource type %s is not registered", type);
pPath = new QString(realPath(dirs->last()));
}
savelocations.insert(type, pPath);
}
QString fullPath = *pPath + suffix;
//US struct stat st;
//US if (stat(QFile::encodeName(fullPath), &st) != 0 || !(S_ISDIR(st.st_mode)))
QFileInfo fullPathInfo(QFile::encodeName(fullPath));
if (fullPathInfo.isReadable() || !fullPathInfo.isDir())
{
if(!create) {
#ifndef NDEBUG
qDebug("save location %s doesn't exist", fullPath.latin1());
#endif
return fullPath;
}
if(!makeDir(fullPath, 0700)) {
qWarning("failed to create %s", fullPath.latin1());
return fullPath;
}
dircache.remove(type);
}
return fullPath;
}
QString KStandardDirs::relativeLocation(const char *type, const QString &absPath)
{
QString fullPath = absPath;
int i = absPath.findRev('/');
if (i != -1)
{
fullPath = realPath(absPath.left(i+1))+absPath.mid(i+1); // Normalize
}
QStringList candidates = resourceDirs(type);
for (QStringList::ConstIterator it = candidates.begin();
it != candidates.end(); it++)
if (fullPath.startsWith(*it))
{
return fullPath.mid((*it).length());
}
return absPath;
}
bool KStandardDirs::makeDir(const QString& dir2, int mode)
{
QString dir = QDir::convertSeparators( dir2 );
#if 0
//LR
// we want an absolute path
if (dir.at(0) != '/')
return false;
QString target = dir;
uint len = target.length();
// append trailing slash if missing
if (dir.at(len - 1) != '/')
target += '/';
QString base("");
uint i = 1;
while( i < len )
{
//US struct stat st;
int pos = target.find('/', i);
base += target.mid(i - 1, pos - i + 1);
QCString baseEncoded = QFile::encodeName(base);
// bail out if we encountered a problem
//US if (stat(baseEncoded, &st) != 0)
QFileInfo baseEncodedInfo(baseEncoded);
if (!baseEncodedInfo.exists())
{
// Directory does not exist....
// Or maybe a dangling symlink ?
//US if (lstat(baseEncoded, &st) == 0)
if (baseEncodedInfo.isSymLink()) {
//US (void)unlink(baseEncoded); // try removing
QFile(baseEncoded).remove();
}
//US if ( mkdir(baseEncoded, (mode_t) mode) != 0)
QDir dirObj;
if ( dirObj.mkdir(baseEncoded) != true )
{
//US perror("trying to create local folder");
return false; // Couldn't create it :-(
}
}
i = pos + 1;
}
return true;
#endif
// ********************************************
// new code for WIN32
QDir dirObj;
// we want an absolute path
#ifndef _WIN32_
if (dir.at(0) != '/')
return false;
#endif
QString target = dir;
uint len = target.length();
#ifndef _WIN32_
// append trailing slash if missing
if (dir.at(len - 1) != '/')
target += '/';
#endif
QString base("");
uint i = 1;
while( i < len )
{
//US struct stat st;
#ifndef _WIN32_
int pos = target.find('/', i);
#else
int pos = target.find('\\', i);
#endif
if ( pos < 0 )
return true;
base += target.mid(i - 1, pos - i + 1);
//QMessageBox::information( 0,"cap111", base, 1 );
/*US
QCString baseEncoded = QFile::encodeName(base);
// bail out if we encountered a problem
if (stat(baseEncoded, &st) != 0)
{
// Directory does not exist....
// Or maybe a dangling symlink ?
if (lstat(baseEncoded, &st) == 0)
(void)unlink(baseEncoded); // try removing
if ( mkdir(baseEncoded, (mode_t) mode) != 0) {
perror("trying to create local folder");
return false; // Couldn't create it :-(
}
}
*/
if (dirObj.exists(base) == false)
{
//qDebug("KStandardDirs::makeDir try to create : %s" , base.latin1());
if (dirObj.mkdir(base) != true)
{
qDebug("KStandardDirs::makeDir could not create: %s" , base.latin1());
return false;
}
}
i = pos + 1;
}
return true;
}
static QString readEnvPath(const char *env)
{
#ifdef _WIN32_
return "";
#else
QCString c_path = getenv(env);
if (c_path.isEmpty())
return QString::null;
return QFile::decodeName(c_path);
#endif
}
void KStandardDirs::addKDEDefaults()
{
//qDebug("ERROR: KStandardDirs::addKDEDefaults() called ");
//return;
QStringList kdedirList;
// begin KDEDIRS
QString kdedirs = readEnvPath("MICROKDEDIRS");
if (!kdedirs.isEmpty())
{
tokenize(kdedirList, kdedirs, ":");
}
else
{
QString kdedir = readEnvPath("MICROKDEDIR");
if (!kdedir.isEmpty())
{
kdedir = KShell::tildeExpand(kdedir);
kdedirList.append(kdedir);
}
}
//US kdedirList.append(KDEDIR);
//US for embedded, add qtopia dir as kdedir
#ifndef DESKTOP_VERSION
kdedirList.append(readEnvPath("QPEDIR" ));
#endif
#ifdef __KDE_EXECPREFIX
QString execPrefix(__KDE_EXECPREFIX);
if (execPrefix!="NONE")
kdedirList.append(execPrefix);
#endif
QString localKdeDir;