diff --git a/kdecore/kconfigbase.cpp b/kdecore/kconfigbase.cpp index add2d6a6d..130e35148 100644 --- a/kdecore/kconfigbase.cpp +++ b/kdecore/kconfigbase.cpp @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -274,9 +275,9 @@ TQString KConfigBase::readEntry( const char *pKey, // check for environment variables and make necessary translations int nDollarPos = aValue.find( '$' ); - while( nDollarPos != -1 && nDollarPos+1 < static_cast(aValue.length())) { + while( nDollarPos != -1 && (nDollarPos + 1) < static_cast(aValue.length())) { // there is at least one $ - if( (aValue)[nDollarPos+1] != '$' ) { + if( aValue[nDollarPos+1] != '$' ) { uint nEndPos = nDollarPos+1; // the next character is no $ TQString aVarName; @@ -294,17 +295,42 @@ TQString KConfigBase::readEntry( const char *pKey, nEndPos++; aVarName = aValue.mid( nDollarPos+1, nEndPos-nDollarPos-1 ); } - const char* pEnv = 0; + const char *pEnv = 0; if (!aVarName.isEmpty()) pEnv = getenv( aVarName.ascii() ); - if( pEnv ) { + if (pEnv) { // !!! Sergey A. Sukiyazov !!! // A environment variables may contain values in 8bit // locale cpecified encoding or in UTF8 encoding. aValue.replace( nDollarPos, nEndPos-nDollarPos, KStringHandler::from8Bit( pEnv ) ); - } else + } + else if (aVarName.length() > 8 && aVarName.startsWith("XDG_") && aVarName.endsWith("_DIR")) { + TQString result; + if (aVarName == "XDG_DESKTOP_DIR") { + result = KGlobalSettings::desktopPath(); + } + else if (aVarName == "XDG_DOCUMENTS_DIR") { + result = KGlobalSettings::documentPath(); + } + else if (aVarName == "XDG_DOWNLOAD_DIR") { + result = KGlobalSettings::downloadPath(); + } + else if (aVarName == "XDG_MUSIC_DIR") { + result = KGlobalSettings::musicPath(); + } + else if (aVarName == "XDG_PICTURES_DIR") { + result = KGlobalSettings::picturesPath(); + } + else if (aVarName == "XDG_VIDEOS_DIR") { + result = KGlobalSettings::videosPath(); + } + aValue.replace( nDollarPos, nEndPos-nDollarPos, result ); + } + else { aValue.remove( nDollarPos, nEndPos-nDollarPos ); - } else { + } + } + else { // remove one of the dollar signs aValue.remove( nDollarPos, 1 ); nDollarPos++;