[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE_3_1_BRANCH: kdelibs/kdecore
From:       Helge Deller <deller () kde ! org>
Date:       2003-06-27 22:12:08
[Download RAW message or body]

CVS commit by deller: 

backport from HEAD: next try to get roaming home directory right


  M +26 -9     kconfigbase.cpp   1.148.2.11


--- kdelibs/kdecore/kconfigbase.cpp  #1.148.2.10:1.148.2.11
@@ -1075,4 +1075,19 @@ void KConfigBase::writePathEntry( const 
 }
 
+
+static bool cleanHomeDirPath( QString &path, const QString &homeDir )
+{
+   if (!path.startsWith(homeDir))
+        return false;
+
+   unsigned int len = homeDir.length();
+   // replace by "$HOME" if possible
+   if (path.length() == len || path[len] == '/') {
+        path = path.replace(0, len, QString::fromLatin1("$HOME"));
+        return true;
+   } else 
+        return false;
+}
+
 static QString translatePath( QString path )
 {
@@ -1091,13 +1106,15 @@ static QString translatePath( QString pa
         path.remove(0,5); // strip leading "file:/" off the string
 
-   // we can not use KGlobal::dirs()->relativeLocation("home", path)
-   // here, since it would not recognize paths without a trailing '/' 
-   QString homeDir = QDir::homeDirPath();
-   if (path.startsWith(homeDir)) {
-        unsigned int len = homeDir.length();
-        // replace by $HOME if possible
-        if (path.length() == len || path[len] == '/') {
-             path = path.replace(0, len, QString::fromLatin1("$HOME"));
-        }
+   // we can not use KGlobal::dirs()->relativeLocation("home", path) here,
+   // since it would not recognize paths without a trailing '/'.
+   // All of the 3 following functions to return the user's home directory
+   // can return different paths. We have to test all them.
+   QString homeDir0 = QFile::decodeName(getenv("HOME"));
+   QString homeDir1 = QDir::homeDirPath();
+   QString homeDir2 = QDir(homeDir1).canonicalPath();
+   if (cleanHomeDirPath(path, homeDir0) || 
+       cleanHomeDirPath(path, homeDir1) ||
+       cleanHomeDirPath(path, homeDir2) ) {
+     // kdDebug() << "Path was replaced\n";
    }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic