summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2020-01-12 01:21:43 +0900
committerMichele Calgaro <michele.calgaro@yahoo.it>2020-01-12 01:21:43 +0900
commit3a4f7f51cfb88ab6b34918e8f79dea027d02b411 (patch)
treec6e8a370d52f6166a2e7393d3e38c04af3793360
parentd4845ced49193b59890e010ed4821b0682c2ba44 (diff)
downloadtdelibs-3a4f7f51cfb88ab6b34918e8f79dea027d02b411.tar.gz
tdelibs-3a4f7f51cfb88ab6b34918e8f79dea027d02b411.zip
Fix handling of XDG directories in TDEConfigBase. This relates to issue #60.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
-rw-r--r--tdecore/tdeconfigbase.cpp38
1 files changed, 32 insertions, 6 deletions
diff --git a/tdecore/tdeconfigbase.cpp b/tdecore/tdeconfigbase.cpp
index 340afdfe4..c86b189bd 100644
--- a/tdecore/tdeconfigbase.cpp
+++ b/tdecore/tdeconfigbase.cpp
@@ -28,6 +28,7 @@
#include <tqtextstream.h>
#include <tdeapplication.h>
+#include <tdeglobalsettings.h>
#include <tdeglobal.h>
#include <tdelocale.h>
#include <kcharsets.h>
@@ -274,9 +275,9 @@ TQString TDEConfigBase::readEntry( const char *pKey,
// check for environment variables and make necessary translations
int nDollarPos = aValue.find( '$' );
- while( nDollarPos != -1 && nDollarPos+1 < static_cast<int>(aValue.length())) {
+ while( nDollarPos != -1 && (nDollarPos + 1) < static_cast<int>(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 TDEConfigBase::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 <corwin@micom.don.ru> !!!
// 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 = TDEGlobalSettings::desktopPath();
+ }
+ else if (aVarName == "XDG_DOCUMENTS_DIR") {
+ result = TDEGlobalSettings::documentPath();
+ }
+ else if (aVarName == "XDG_DOWNLOAD_DIR") {
+ result = TDEGlobalSettings::downloadPath();
+ }
+ else if (aVarName == "XDG_MUSIC_DIR") {
+ result = TDEGlobalSettings::musicPath();
+ }
+ else if (aVarName == "XDG_PICTURES_DIR") {
+ result = TDEGlobalSettings::picturesPath();
+ }
+ else if (aVarName == "XDG_VIDEOS_DIR") {
+ result = TDEGlobalSettings::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++;